From 15b91dcc20839493a17672e6ef697724f06528d5 Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Mon, 14 Mar 2022 22:20:15 -0500 Subject: [PATCH] Add conio Also removes print statements from the interrupt handler (except for the button interrupt) --- sw/conio.s | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ sw/irq.c | 16 ++++++--------- sw/main.c | 26 ++++++++++------------- 3 files changed, 77 insertions(+), 25 deletions(-) create mode 100644 sw/conio.s diff --git a/sw/conio.s b/sw/conio.s new file mode 100644 index 0000000..30b4d6a --- /dev/null +++ b/sw/conio.s @@ -0,0 +1,60 @@ +.importzp sp, sreg + +.import _uart_txb_block +.import _lastchar + +.export _cputc +.export gotoxy +.export _clrscr +.export _cgetc + +.autoimport on + +.code + +; void __fastcall__ cputc (char c); +_cputc: + jsr _uart_txb_block + cmp #$0a + bne @1 + lda #$0d + jsr _uart_txb_block +@1: rts + +; void __fastcall__ gotoxy (unsigned char x, unsigned char y); +gotoxy: + phx + phy + tay ; Move y position to y + lda (sp) + tax ; Move x position to x + lda #$1b + jsr _uart_txb_block + lda #'[' + jsr _uart_txb_block + tya + jsr _uart_txb_block + lda #';' + jsr _uart_txb_block + txa + jsr _uart_txb_block + lda #'H' + jsr _uart_txb_block + ply + plx + rts + +_clrscr: + phx + lda #$1b + jsr _uart_txb_block + lda #'c' + jsr _uart_txb_block + pla + rts + +_cgetc: +@2: lda _lastchar + beq @2 + stz _lastchar + rts \ No newline at end of file diff --git a/sw/irq.c b/sw/irq.c index 3608879..04708a0 100644 --- a/sw/irq.c +++ b/sw/irq.c @@ -1,30 +1,26 @@ #include +#include #include "interrupt.h" #include "uart.h" +#include "sevenseg.h" + +char lastchar; -// This is defined in main.c -void puts(const char* s); void handle_irq() { uint8_t status; char c; - puts("Interrupt Detected!\n"); - status = irq_get_status(); if (status & BUTTON) { - puts("Button Interrupt!\n"); + cputs("Button Interrupt!\n"); irq_set_status(status & ~BUTTON); } if (status & UART) { - puts("UART Interrupt!\n"); - c = uart_rxb(); - puts("Received: "); - puts(&c); - puts("\n"); + lastchar = uart_rxb(); irq_set_status(status & ~UART); } } \ No newline at end of file diff --git a/sw/main.c b/sw/main.c index b72826f..00fb9d4 100644 --- a/sw/main.c +++ b/sw/main.c @@ -1,24 +1,20 @@ #include +#include #include "sevenseg.h" #include "uart.h" -void puts(const char* s) -{ - while (*s) { - uart_txb_block(*s); - if (*s == '\n') - uart_txb_block('\r'); - - s++; - } -} - int main() { - hex_enable(0x3f); - hex_set_24(0xabcdef); + char s[16]; + + clrscr(); + cprintf("Hello, world!\n"); + + while (1) { + cscanf("%15s", s); + cprintf("Read string: %s\n", s); + } + - puts("Hello, World!\n"); - while(1); return 0; }