From 0b5ccf48b8ea9804016d77fe072820ac7ccb7c33 Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Mon, 14 Mar 2022 00:24:08 -0500 Subject: [PATCH] Add basic UART driver This didn't have a chance to get tested so I hope it works. There is not fancy stuff here, just write to the register and wait till it is done. --- sw/io.inc65 | 7 ++++++- sw/uart.h | 11 +++++++++++ sw/uart.s | 29 +++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 sw/uart.h create mode 100644 sw/uart.s diff --git a/sw/io.inc65 b/sw/io.inc65 index 4bf4736..9192cff 100644 --- a/sw/io.inc65 +++ b/sw/io.inc65 @@ -1 +1,6 @@ -SEVEN_SEG = $7ff0 +SEVEN_SEG = $7ff0 + +UART = $7ff4 +UART_TXB = UART +UART_RXB = UART +UART_STATUS = UART + 1 diff --git a/sw/uart.h b/sw/uart.h new file mode 100644 index 0000000..c96b48c --- /dev/null +++ b/sw/uart.h @@ -0,0 +1,11 @@ +#ifndef _UART_H +#define _UART_H + +#include + +void uart_txb(uint8_t val); +void uart_txb_block(uint8_t val); + +uint8_t uart_status(); + +#endif \ No newline at end of file diff --git a/sw/uart.s b/sw/uart.s new file mode 100644 index 0000000..80b5563 --- /dev/null +++ b/sw/uart.s @@ -0,0 +1,29 @@ +.include "io.inc65" + +.importzp sp, sreg + +.export _uart_txb +.export _uart_txb_block +.export _uart_status + +.autoimport on + +.code + +; @in A: byte to transmit +; Transmits a byte over the UART +_uart_txb: + sta UART_TXB ; Just write value, don't wait + rts + +_uart_txb_block: + sta UART_TXB ; Write value +@1: lda UART_STATUS ; Wait for status[0] to be 0 + bit #$01 + bne @1 + rts + +_uart_status: + lda UART_STATUS + ldx #$00 + rts