From 99aeb3caa874ceb29415c47f442393ed062d9279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20L=C3=B6fgren?= Date: Mon, 9 Sep 2024 18:21:30 +0200 Subject: [PATCH 1/3] Updates to serial driver. Added baudrate selection utility --- src/arch/nano6502/build.py | 1 + src/arch/nano6502/nano6502.S | 16 +++ src/arch/nano6502/nano6502.ld | 2 +- src/arch/nano6502/utils/baudrate.S | 190 +++++++++++++++++++++++++++++ src/arch/nano6502/utils/build.py | 8 ++ 5 files changed, 216 insertions(+), 1 deletion(-) create mode 100644 src/arch/nano6502/utils/baudrate.S diff --git a/src/arch/nano6502/build.py b/src/arch/nano6502/build.py index 7ae2b35d..7783412c 100644 --- a/src/arch/nano6502/build.py +++ b/src/arch/nano6502/build.py @@ -25,6 +25,7 @@ "1:colorfg.com": "src/arch/nano6502/utils+colorfg", "1:colorbg.com": "src/arch/nano6502/utils+colorbg", "1:ledtest.com": "src/arch/nano6502/utils+ledtest", + "1:baudrate.com": "src/arch/nano6502/utils+baudrate", } | MINIMAL_APPS | MINIMAL_APPS_SRCS diff --git a/src/arch/nano6502/nano6502.S b/src/arch/nano6502/nano6502.S index eeb2efe1..2830726c 100644 --- a/src/arch/nano6502/nano6502.S +++ b/src/arch/nano6502/nano6502.S @@ -344,6 +344,7 @@ zproc tty_conout zendif jsr video_init sta tty_write + clc rts zendproc @@ -586,6 +587,10 @@ zproc serial_inp lda uart_b_rx_avail zif_eq ; No data available + + ; Short delay to prevent premature timeout in applications + jsr serial_delay + sec rts zendif @@ -639,6 +644,17 @@ wait_serial_in: rts zendproc +zproc serial_delay + sta ptr + lda #$ff + sta ptr1 + zrepeat + dec ptr1 + zuntil_eq + lda ptr + rts +zendproc + ; -- Rest of the BIOS --- ; Sets the current DMA address. diff --git a/src/arch/nano6502/nano6502.ld b/src/arch/nano6502/nano6502.ld index 485e39c9..eaea0104 100644 --- a/src/arch/nano6502/nano6502.ld +++ b/src/arch/nano6502/nano6502.ld @@ -1,6 +1,6 @@ MEMORY { zp : ORIGIN = 0x10, LENGTH = 0xf0 - ram (rw) : ORIGIN = 0x0300, LENGTH = 0x0E00 + ram (rw) : ORIGIN = 0x0300, LENGTH = 0x0F00 } SECTIONS { diff --git a/src/arch/nano6502/utils/baudrate.S b/src/arch/nano6502/utils/baudrate.S new file mode 100644 index 00000000..31d4b12a --- /dev/null +++ b/src/arch/nano6502/utils/baudrate.S @@ -0,0 +1,190 @@ +; --------------------------------------------------------------------------- +; +; nano6502 baudrate utility +; +; Copyright (C) 2024 Henrik Löfgren +; This file is licensed under the terms of the 2-cluse BSD license. Please +; see the COPYING file in the root project directory for the full test. +; +; --------------------------------------------------------------------------- + +#include "zif.inc" +#include "cpm65.inc" + +; UART IO bank addresses +IO_page_reg = $00 +IO_page_UART = $01 +uart_b_baudrate = $fe08 + +zproc main + lda #banner + ldy #BDOS_WRITE_STRING + jsr BDOS + + jsr print_baudrate + + lda #query + ldy #BDOS_WRITE_STRING + jsr BDOS + +get_selection: + ldy #BDOS_CONSOLE_INPUT + jsr BDOS + + cmp #$2F + zif_cs + cmp #$36 + bcc ok_selection + + lda #br_invalid + ldy #BDOS_WRITE_STRING + jsr BDOS + + lda #crlf + ldy #BDOS_WRITE_STRING + jsr BDOS + zendif + jmp get_selection +ok_selection: + sec + sbc #$30 + + ldx #IO_page_UART + stx IO_page_reg + + sta uart_b_baudrate + + lda #updated + ldy #BDOS_WRITE_STRING + jsr BDOS + + jsr print_baudrate + + rts +zendproc + +zproc print_baudrate + lda #current + ldy #BDOS_WRITE_STRING + jsr BDOS + + lda #IO_page_UART + sta IO_page_reg + + lda uart_b_baudrate + cmp #0 + zif_eq + lda #br_4800 + jmp print_br + zendif + + cmp #1 + zif_eq + lda #br_9600 + jmp print_br + zendif + + cmp #2 + zif_eq + lda #br_19200 + jmp print_br + zendif + + cmp #3 + zif_eq + lda #br_38400 + jmp print_br + zendif + + cmp #4 + zif_eq + lda #br_57600 + jmp print_br + zendif + + cmp #5 + zif_eq + lda #br_115200 + jmp print_br + zendif + + lda #br_invalid + +print_br: + ldy #BDOS_WRITE_STRING + jsr BDOS + + lda #crlf + ldy #BDOS_WRITE_STRING + jsr BDOS + + rts +zendproc + + .data +banner: + .ascii "nano6502 baudrate utility" + .byte 13,10 + .ascii "-------------------------" + .byte 13,10,0 + +current: + .ascii "Current UART B baudrate: " + .byte 0 + +br_4800: + .ascii "4800" + .byte 0 + +br_9600: + .ascii "9600" + .byte 0 + +br_19200: + .ascii "19200" + .byte 0 + +br_38400: + .ascii "38400" + .byte 0 + +br_57600: + .ascii "57600" + .byte 0 + +br_115200: + .ascii "115200" + .byte 0 + +br_invalid: + .ascii "Invalid setting" + .byte 0 + +crlf: + .byte 13, 10, 0 + +query: + .byte 13, 10 + .ascii "Select new baudrate: " + .byte 13, 10 + .ascii "[0] 4800, [1] 9600, [2] 19200, [3] 38400, [4] 57600, [5] 115200" + .byte 13, 10, 0 + +updated: + .byte 13, 10 + .ascii "Baudrate setting updated." + .byte 13,10,0 diff --git a/src/arch/nano6502/utils/build.py b/src/arch/nano6502/utils/build.py index e0d40f1e..9baa0bf0 100644 --- a/src/arch/nano6502/utils/build.py +++ b/src/arch/nano6502/utils/build.py @@ -23,3 +23,11 @@ "include", ], ) + +llvmprogram( + name="baudrate", + srcs=["./baudrate.S"], + deps=[ + "include", + ], +) From 0ffad27f56435dd2f5f6ece85d0f7f83761eadf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20L=C3=B6fgren?= <106430829+venomix666@users.noreply.github.com> Date: Mon, 9 Sep 2024 18:27:23 +0200 Subject: [PATCH 2/3] Update README.md with info on settable baudrate --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e537ba1a..e7cdc4c4 100644 --- a/README.md +++ b/README.md @@ -335,8 +335,8 @@ the same time. - To use, write the `nano6502.img` file into the SD-card using `dd` or your preferred SD-card image writer. If you are updating the image and want to preserve the data on all drives except `A`, write the `nano6502_sysonly.img` instead. - - User area 1 on drive `A` contains utilities for setting the text and background colors, and a demo application which blinks the onboard LEDs. - - A SERIAL driver is available for the second UART, connected to pin 25 (RX) and 26 (TX) of the FPGA (and the UART header on the nanoComp carrier board). The baudrate is currently fixed to 115200. + - User area 1 on drive `A` contains utilities for setting the text and background colors, setting the baudrate on on the second UART and a demo application which blinks the onboard LEDs. + - A SERIAL driver is available for the second UART, connected to pin 25 (RX) and 26 (TX) of the FPGA (and the UART header on the nanoComp carrier board). The baudrate defaults to 9600 baud but can be configured by the utility in user area 1. ### KIM-1 with K-1013 FDC notes From 8b0f6d012c9ae998f168074a4aea2ebbf55f9d1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20L=C3=B6fgren?= Date: Thu, 12 Sep 2024 08:09:07 +0200 Subject: [PATCH 3/3] Clear the UART RX buffer on open/close --- src/arch/nano6502/nano6502.S | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/arch/nano6502/nano6502.S b/src/arch/nano6502/nano6502.S index 2830726c..201db298 100644 --- a/src/arch/nano6502/nano6502.S +++ b/src/arch/nano6502/nano6502.S @@ -614,7 +614,11 @@ zendproc serial_open: serial_close: -rts + ; Perform a read to clear the buffer + lda #IO_page_uart + sta IO_page_reg + lda uart_b_rx_data + rts zproc serial_outp sta ptr @@ -646,7 +650,7 @@ zendproc zproc serial_delay sta ptr - lda #$ff + lda #$20 sta ptr1 zrepeat dec ptr1