From 597d15e2341f2a99ba8e699584cef4731583599b Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Wed, 29 Nov 2023 17:19:18 -0800 Subject: [PATCH] Add terminal write as well, use it in kernel --- sw/kernel/devices/terminal.s | 24 ++++++++++++++++++++++-- sw/kernel/kernel.c | 18 ++++++++++++------ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/sw/kernel/devices/terminal.s b/sw/kernel/devices/terminal.s index 8afec0f..ea1f0d0 100644 --- a/sw/kernel/devices/terminal.s +++ b/sw/kernel/devices/terminal.s @@ -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 diff --git a/sw/kernel/kernel.c b/sw/kernel/kernel.c index 6c67395..bbdc685 100644 --- a/sw/kernel/kernel.c +++ b/sw/kernel/kernel.c @@ -1,10 +1,14 @@ #include +#include + #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;