Add terminal write as well, use it in kernel

This commit is contained in:
Byron Lathi
2023-11-29 17:19:18 -08:00
parent b25d0e9bdb
commit 597d15e234
2 changed files with 34 additions and 8 deletions

View File

@@ -27,7 +27,7 @@ terminal_buf: .res 128
bge FAIL
sta tmp1 ; Store nbytes in tmp1
jsr pushax ; Check that buf != NULL
jsr popax ; Check that buf != NULL
cmp #$00
bne L1
cpx #$00
@@ -90,14 +90,34 @@ FAIL: lda #$ff ; return -1 on fail
rts
.endproc
; terminal_write
; int8_t terminal_write(uint8_t fd, const void* buf, uint8_t nbytes);
; write characters to the terminal
; Inputs: int8_t* buf - buffer of characters to write
; uint8_t n - number of characters to write
; Return Value: 0 on success, -1 on failure
; Writes to screen. Only stops after n chars written.
; This seems to not care about null termination?
.proc _terminal_write
sta tmp1 ; put nbytes in tmp1
jsr popax ; check that buf is not null
cmp #$00
bne L1
cpx #$00
bne L1
bra FAIL
L1:
ldy #$00
LOOP: lda (ptr1),y ; Loop through buffer and print
jsr _serial_putc
iny
cmp tmp1
blt LOOP
lda #$00
rts
FAIL: lda #$ff ; old code didn't fail, but new code does.
rts
.endproc
; terminal_open

View File

@@ -1,10 +1,14 @@
#include <conio.h>
#include <string.h>
#include "devices/interrupt_controller.h"
#include "interrupts/interrupt.h"
#include "devices/mapper.h"
#include "devices/rtc.h"
#include "devices/serial.h"
#include "devices/terminal.h"
void handle_rtc_interrupt() {
// cputs("In IRQ interrupt!\n");
@@ -13,9 +17,9 @@ void handle_rtc_interrupt() {
asm volatile ("rti");
}
int main() {
char buf[128];
uint8_t c;
int main() {
cputs("Kernel\n");
@@ -40,11 +44,13 @@ int main() {
serial_puts("Hello from serial!\n");
terminal_open(NULL);
terminal_write(0, "Terminal Write\n", 15);
while(1) {
c = serial_getc();
serial_puts("Got a character!: ");
serial_putc(c);
serial_putc('\n');
terminal_read(0, buf, 128);
terminal_write(0, "Got: ", 5);
terminal_write(0, buf, strlen(buf));
}
return 0;