From 039ed9a16b9ba879e81bcc65c2aec4fffb23f6b4 Mon Sep 17 00:00:00 2001 From: "Matthias@Dell" Date: Sat, 11 Nov 2023 12:13:47 +0100 Subject: [PATCH] use .res for ram variables --- main.s65 | 12 ++++++------ programs/printer.s65 | 2 +- programs/sleep.s65 | 8 +++++--- system/buffer.s65 | 5 +++-- system/keypad.s65 | 27 +++++++++++++++------------ system/spi.s65 | 13 +++++++------ 6 files changed, 37 insertions(+), 30 deletions(-) diff --git a/main.s65 b/main.s65 index 2bac2f6..bde877d 100644 --- a/main.s65 +++ b/main.s65 @@ -1,5 +1,5 @@ -.segment "CODE" -.include "system/system.h65" +.include "system/system.s65" +.code .macro DEBUG_LED_OFF nr lda IO1 + IO::RA @@ -44,6 +44,7 @@ SPI_IO = IO2 ;******************************************************************************** ; Interrupts ;******************************************************************************** +.code nmi: lda #'%' jsr lcd_char @@ -145,11 +146,11 @@ print_2: PrintSlow message_2,10 jmp home -.segment "RODATA" +.rodata message_1: .asciiz " Powered by ......6502...... **** www.quintern.xyz" message_2: - .byte " Hallo " - .byte " Clara " + .byte " Hello " + .byte " there " .byte " <3 " .asciiz "================" message_menu: @@ -163,7 +164,6 @@ str_irq: str_irq_unknown: .asciiz "Unknown IRQ src!" -.segment "CODE" ;******************************************************************************** ; reset vector ;******************************************************************************** diff --git a/programs/printer.s65 b/programs/printer.s65 index 25aa2ec..1b90cb5 100644 --- a/programs/printer.s65 +++ b/programs/printer.s65 @@ -3,7 +3,7 @@ ;******************************************************************************** .ifndef INCLUDE_PRINTER INCLUDE_PRINTER = 1 - +.code printer: jsr lcd_clear @printer_loop: diff --git a/programs/sleep.s65 b/programs/sleep.s65 index 5a78336..f274ac6 100644 --- a/programs/sleep.s65 +++ b/programs/sleep.s65 @@ -1,5 +1,6 @@ .ifndef INCLUDE_SLEEP INCLUDE_SLEEP = 1 +.code ;******************************************************************************** ; @macro Sleep ; @param time_cs: Time to sleep in centiseconds (10^-2s = 10ms) @@ -19,15 +20,16 @@ INCLUDE_SLEEP = 1 ; @details ; Interrupts might change the actual time to finish ; To be exact, time_cs is in units of 0.010244s +; @modifies: ARG2 ;******************************************************************************** .proc sleep -VAR_1 = 0 - stz VAR_1 +_VAR_1 = ARG2 + stz _VAR_1 @loop: .repeat 17 nop ; 2 - i .endrepeat - inc VAR_1 ; 3 - zp + inc _VAR_1 ; 3 - zp bne @loop ; 2/3 - r (2 if not taken, but here most of the time its 3) ; reaching this takes 256 * (X * 2(nop) + 3(inc) + 3(bne)) - 1(last bne) cycles ; with X = 17: T1 = (256×(17×2 + 3 +3) − 1) × (1/1MHz) = 0,010 239 s diff --git a/system/buffer.s65 b/system/buffer.s65 index 599dc30..68468e2 100644 --- a/system/buffer.s65 +++ b/system/buffer.s65 @@ -7,10 +7,11 @@ ; The RBUF_NAME variable must be defined, the functions will then be exported ; as rb__ where = init, read or write ; @requires -; RBUF_MEM_START: Start address of ringbuffer memory space -; RBUF_MEM_END: End address of ringbuffer memory space +; RBUF_MEM_START: First address of ringbuffer memory space +; RBUF_MEM_END: Last address of ringbuffer memory space ; RBUF_NAME: Name of the ringbuffer ;******************************************************************************** +.code .ifndef RBUF_MEM_START .fatal "RBUF_MEM_START not defined" diff --git a/system/keypad.s65 b/system/keypad.s65 index 67f0b18..ea9d628 100644 --- a/system/keypad.s65 +++ b/system/keypad.s65 @@ -16,14 +16,17 @@ INCLUDE_KEYPAD = 1 .fatal "KP_IO is not defined: set it to the base address of the IO chip of the Keypad" .endif +.zeropage +_KP_COLUMN: .res 1 ; for storing stuff -RBUF_MEM_START = $200 -RBUF_MEM_END = $208 +.bss ; reserve space or ringbuffer +KP_BUF_SIZE = 10 +RBUF_MEM_START: .res KP_BUF_SIZE +RBUF_MEM_END = RBUF_MEM_START + KP_BUF_SIZE - 1 .define RBUF_NAME "keypad" .include "buffer.s65" -KB_VAR = $05 ; any free zp address - +.code .proc kp_init ; todo remove later and test lda #$ff @@ -74,23 +77,23 @@ KB_VAR = $05 ; any free zp address @kp_read_column: sta KP_IO+IO::RB lda KP_IO+IO::RB - sta KB_VAR ; store result in zeropage so that bbr can be used - bbr4 KB_VAR,@kp_write + sta _KP_COLUMN ; store result in zeropage so that bbr can be used + bbr4 _KP_COLUMN,@kp_write inx - bbr5 KB_VAR,@kp_write + bbr5 _KP_COLUMN,@kp_write inx - bbr6 KB_VAR,@kp_write + bbr6 _KP_COLUMN,@kp_write inx - bbr7 KB_VAR,@kp_write + bbr7 _KP_COLUMN,@kp_write rts @kp_write: - lda kp_VALUES,x + lda _KP_VALUES,x jsr rb_keypad_write rts .endproc -.segment "RODATA" -kp_VALUES: +.rodata +_KP_VALUES: ; TODO change to literal .byte "123A", "456B", "789C", "*0#D" .endif diff --git a/system/spi.s65 b/system/spi.s65 index e634bc8..60df03a 100644 --- a/system/spi.s65 +++ b/system/spi.s65 @@ -5,17 +5,18 @@ ; @depends IO-W65C22N ;******************************************************************************** -.include "system/system.h65" +.include "system/system.s65" .ifndef INCLUDE_SPI INCLUDE_SPI = 1 -.segment "CODE" - -SPI_CODE_START = $3000 -SPI_PAGES_WRITTEN = $2fff -SPI_BYTES_WRITTEN = $2ffe +.bss +SPI_PAGES_WRITTEN: .res 1 +SPI_BYTES_WRITTEN: .res 1 +SPI_CODE_START: .res $1000 + +.code .struct SPI_P_Pins ; VIA addresses DDR_a .word ; address of the data direction register