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 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..201db298 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 @@ -609,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 @@ -639,6 +648,17 @@ wait_serial_in: rts zendproc +zproc serial_delay + sta ptr + lda #$20 + 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", + ], +)