diff --git a/main.s65 b/main.s65 index fbcd708..3cc7688 100644 --- a/main.s65 +++ b/main.s65 @@ -54,7 +54,7 @@ ; Interrupts ;******************************************************************************** .zeropage -IRQ_VAR: .res 1 +irq_via_ifr: .res 1 .code nmi: lda #'%' @@ -62,26 +62,22 @@ nmi: rti irq: ; read IRFs, while bit 7 ist set handle interrupts -; @irq_io1: -; lda SPI_IO+IO::IFR -; sta IRQ_VAR - ; bbr7 IRQ_VAR,@irq_io2 +@irq_io1: + lda IO1 + IO::IFR + sta irq_via_ifr + bbr7 irq_via_ifr,@irq_io1 ; skip + bbs2 irq_via_ifr,@irq_kb1 ; shit reg -> first 8 bits + bbs5 irq_via_ifr,@irq_kb2 ; timer -> last 3 bits @irq_io2: - lda IO2+IO::IFR - sta IRQ_VAR - bbr7 IRQ_VAR,@irq_return - bbs2 IRQ_VAR,@irq_spi_p ; check SR - bbs1 IRQ_VAR,@irq_keypad ; check CA1 + lda IO2 + IO::IFR + sta irq_via_ifr + bbr7 irq_via_ifr,@irq_return ; skip + bbs2 irq_via_ifr,@irq_spi_p ; check SR + bbs1 irq_via_ifr,@irq_keypad ; check CA1 - ; - lda IO1+IO::IFR - sta IRQ_VAR - bbr7 IRQ_VAR,@irq_return - bbs2 IRQ_VAR,@irq_kb1 ; shit reg -> first 8 bits - bbs5 IRQ_VAR,@irq_kb2 ; timer -> last 3 bits ; this SHOULD never be reached jsr lcd::clear - Print str_irq_unknown + Print "Unknown IRQ" ; force reset interrupt flags lda #$ff sta IO1 + IO::IFR @@ -234,10 +230,6 @@ str_spi_begin: .asciiz "---BEGIN SPI---" str_spi_start: .asciiz "---START SPI---" -str_irq: - .asciiz "IRQ detected! " -str_irq_unknown: - .asciiz "Unknown IRQ src!" str_io2: .asciiz "IO2::RB='" diff --git a/spicode.s65 b/spicode.s65 index 6fe433c..c759579 100644 --- a/spicode.s65 +++ b/spicode.s65 @@ -106,9 +106,6 @@ CODE_START: jsr lcd::print_char bra @loop - -; .out .sprintf("SPI: CODE_START at %x", *) - kbinit: lda #'[' @@ -122,6 +119,8 @@ kbinit: ; the 3 last bits take about 230us, at @1MHz => wait 230 cycles and then the shift register lda #230 sta kb::KB_IO + IO::T2CL + stz key_read + stz key_read+1 ; enable SR interrupts lda #(IO::IRQ::IRQ | IO::IRQ::SR) @@ -137,7 +136,7 @@ irq_on_shift_reg: lda #'{' jsr lcd::print_char lda kb::KB_IO + IO::SR - sta keycode + sta key_read stz kb::KB_IO + IO::SR ; disable SR interrupts @@ -159,7 +158,7 @@ irq_on_timer: lda #'<' jsr lcd::print_char lda kb::KB_IO + IO::SR - sta keycode + 1 + sta key_read + 1 lda kb::KB_IO + IO::T2CL ; clear interrupt flag @@ -173,25 +172,29 @@ irq_on_timer: stz kb::KB_IO + IO::SR ; lda #'|' - lda keycode + lda key_read jsr lcd::print_char - lda keycode + 1 + lda key_read + 1 jsr lcd::print_char ; rotate bit 2 (last bit of keycode) into the carry ror ror ror - lda keycode ; not affecting carry + lda key_read ; not affecting carry rol ; rotate carry into byte, rotate startbit into carry ; TODO byte is inverted, maybe consider wasting 256 bytes for a bit reverse lookup table? - sta keycode + 1 + sta keycode jsr lcd::print_char + stz key_read + stz key_read+1 + lda #'>' jsr lcd::print_char rts -keycode: .res 3 +key_read: .res 2 +keycode: .res 1 kb_irq1: lda #'!' jsr lcd::print_char diff --git a/system/io_W65C22.h65 b/system/io_W65C22.h65 index 4662454..4fc01eb 100644 --- a/system/io_W65C22.h65 +++ b/system/io_W65C22.h65 @@ -10,6 +10,8 @@ INCLUDE_IOW65C22 = 1 .scope IO +; not using a struct for this since the syntax for access would be the same, +; ie label+IO::RA .enum ; IO-CHIPS OFFSETS FOR PINS FROM BASE ADDRESS RB = $0 ; Register B (ORB/IRB) diff --git a/system/lcd.h65 b/system/lcd.h65 index eba5bcb..465b992 100644 --- a/system/lcd.h65 +++ b/system/lcd.h65 @@ -22,44 +22,54 @@ LCD_IO = IO1 Import lcd,init,clear,print,print_char,set_position,set_custom_char Import lcd,_cmd,_wait_nbusy,_write_ram,_read_ram -;******************************************************************************** -; @macro Clear the screen and print a null-terminated string -; @param message: Address of the message -;******************************************************************************** +;;******************************************************************************** +;; @macro Clear the screen and print a null-terminated string +;; @param message: Address of the message or string literal +;; @details +;; If message is a string literal, it will be stored in rodata +;; and the address of this segment will be used +;;******************************************************************************** .macro Print message - ; .out .sprintf("message is a string literal: '%s' len=%x", message, .strlen(message)) - .if .match(message, "") - .pushseg - .rodata -: .asciiz message - .popseg - .out .sprintf("message is a string literal: '%s' len=%x", message, .strlen(message)) jsr lcd::clear - lda #<:- - sta ARG0 - lda #>:- - sta ARG1 - .else - .out "message is a n0t string" - jsr lcd::clear - lda #message - sta ARG1 + .if .match(message, "") ; message is a string literal -> store in rodata + .pushseg + .rodata +: .asciiz message + .popseg + lda #<:- + sta ARG0 + lda #>:- + sta ARG1 + .else ; message is not a string + lda #message + sta ARG1 .endif jsr lcd::print .endmacro -;******************************************************************************** -; @macro Print a null-terminated string -; @param message: Address of the message -;******************************************************************************** +;;******************************************************************************** +;; @macro Print a null-terminated string +;; @param message: Address of the message or string literal +;;******************************************************************************** .macro PrintNC message - lda #message - sta ARG1 + .if .match(message, "") ; message is a string literal -> store in rodata + .pushseg + .rodata +: .asciiz message + .popseg + lda #<:- + sta ARG0 + lda #>:- + sta ARG1 + .else ; message is not a string + lda #message + sta ARG1 + .endif jsr lcd::print .endmacro diff --git a/util/string.h65 b/util/string.h65 index c5da36e..286f55f 100644 --- a/util/string.h65 +++ b/util/string.h65 @@ -31,19 +31,30 @@ Import str, hex_char_to_uint8, hex_str_to_uint, uint8_to_hex_str ;******************************************************************************** ; @function Macro for passing arguments to strf -; @param fmt: Format string address +; @param fmt: Format string address or string literal ; @param out: Output string address ; @param x0-x9: Additional parameters -; @warning Addresses as additional paramteres must be passed like this `#addr` +; @warning Addresses as additional paramters must be passed like this `#addr` ; @modifies: A, X, Y ; @see strf ;******************************************************************************** .macro Strf fmt,out,x0,x1,x2,x3,x4,x5,x6,x7,x8,x9 @N_ARGS .set 0 ; @ so that it doesnt break cheap labels - lda #fmt - sta ARG1 + .if .match(fmt, "") ; fmt is a string literal -> store in rodata + .pushseg + .rodata +: .asciiz fmt + .popseg + lda #<:- + sta ARG0 + lda #>:- + sta ARG1 + .else ; message is not a string + lda #fmt + sta ARG1 + .endif lda #out @@ -56,8 +67,10 @@ Import str, hex_char_to_uint8, hex_str_to_uint, uint8_to_hex_str _StrfStoreArg x5 _StrfStoreArg x6 _StrfStoreArg x7 + _StrfStoreArg x8 + _StrfStoreArg x9 jsr str::strf - .out .sprintf("info: Strf: called with %d arguments", @N_ARGS) + ; .out .sprintf("info: Strf: called with %d arguments", @N_ARGS) .endmacro ; TODO allocate zp memory