Compare commits

...

2 Commits

Author SHA1 Message Date
Matthias@Dell
03221c5fb4 wip: irq 2023-12-21 17:28:02 +01:00
Matthias@Dell
0e774c5c86 wip: kb 2023-12-21 17:27:54 +01:00
7 changed files with 143 additions and 68 deletions

View File

@ -54,7 +54,7 @@
; Interrupts ; Interrupts
;******************************************************************************** ;********************************************************************************
.zeropage .zeropage
IRQ_VAR: .res 1 irq_via_ifr: .res 1
.code .code
nmi: nmi:
lda #'%' lda #'%'
@ -62,26 +62,22 @@ nmi:
rti rti
irq: irq:
; read IRFs, while bit 7 ist set handle interrupts ; read IRFs, while bit 7 ist set handle interrupts
; @irq_io1: @irq_io1:
; lda SPI_IO+IO::IFR lda IO1 + IO::IFR
; sta IRQ_VAR sta irq_via_ifr
; bbr7 IRQ_VAR,@irq_io2 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: @irq_io2:
lda IO2+IO::IFR lda IO2 + IO::IFR
sta IRQ_VAR sta irq_via_ifr
bbr7 IRQ_VAR,@irq_return bbr7 irq_via_ifr,@irq_return ; skip
bbs2 IRQ_VAR,@irq_spi_p ; check SR bbs2 irq_via_ifr,@irq_spi_p ; check SR
bbs1 IRQ_VAR,@irq_keypad ; check CA1 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 ; this SHOULD never be reached
jsr lcd::clear jsr lcd::clear
Print str_irq_unknown Print "Unknown IRQ"
; force reset interrupt flags ; force reset interrupt flags
lda #$ff lda #$ff
sta IO1 + IO::IFR sta IO1 + IO::IFR
@ -234,10 +230,6 @@ str_spi_begin:
.asciiz "---BEGIN SPI---" .asciiz "---BEGIN SPI---"
str_spi_start: str_spi_start:
.asciiz "---START SPI---" .asciiz "---START SPI---"
str_irq:
.asciiz "IRQ detected! "
str_irq_unknown:
.asciiz "Unknown IRQ src!"
str_io2: str_io2:
.asciiz "IO2::RB='" .asciiz "IO2::RB='"

View File

@ -106,9 +106,6 @@ CODE_START:
jsr lcd::print_char jsr lcd::print_char
bra @loop bra @loop
; .out .sprintf("SPI: CODE_START at %x", *)
kbinit: kbinit:
lda #'[' lda #'['
@ -122,6 +119,8 @@ kbinit:
; the 3 last bits take about 230us, at @1MHz => wait 230 cycles and then the shift register ; the 3 last bits take about 230us, at @1MHz => wait 230 cycles and then the shift register
lda #230 lda #230
sta kb::KB_IO + IO::T2CL sta kb::KB_IO + IO::T2CL
stz key_read
stz key_read+1
; enable SR interrupts ; enable SR interrupts
lda #(IO::IRQ::IRQ | IO::IRQ::SR) lda #(IO::IRQ::IRQ | IO::IRQ::SR)
@ -137,7 +136,7 @@ irq_on_shift_reg:
lda #'{' lda #'{'
jsr lcd::print_char jsr lcd::print_char
lda kb::KB_IO + IO::SR lda kb::KB_IO + IO::SR
sta keycode sta key_read
stz kb::KB_IO + IO::SR stz kb::KB_IO + IO::SR
; disable SR interrupts ; disable SR interrupts
@ -159,7 +158,7 @@ irq_on_timer:
lda #'<' lda #'<'
jsr lcd::print_char jsr lcd::print_char
lda kb::KB_IO + IO::SR lda kb::KB_IO + IO::SR
sta keycode + 1 sta key_read + 1
lda kb::KB_IO + IO::T2CL ; clear interrupt flag lda kb::KB_IO + IO::T2CL ; clear interrupt flag
@ -173,25 +172,29 @@ irq_on_timer:
stz kb::KB_IO + IO::SR stz kb::KB_IO + IO::SR
; lda #'|' ; lda #'|'
lda keycode lda key_read
jsr lcd::print_char jsr lcd::print_char
lda keycode + 1 lda key_read + 1
jsr lcd::print_char jsr lcd::print_char
; rotate bit 2 (last bit of keycode) into the carry ; rotate bit 2 (last bit of keycode) into the carry
ror ror
ror ror
ror ror
lda keycode ; not affecting carry lda key_read ; not affecting carry
rol ; rotate carry into byte, rotate startbit into 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? ; TODO byte is inverted, maybe consider wasting 256 bytes for a bit reverse lookup table?
sta keycode + 1 sta keycode
jsr lcd::print_char jsr lcd::print_char
stz key_read
stz key_read+1
lda #'>' lda #'>'
jsr lcd::print_char jsr lcd::print_char
rts rts
keycode: .res 3 key_read: .res 2
keycode: .res 1
kb_irq1: kb_irq1:
lda #'!' lda #'!'
jsr lcd::print_char jsr lcd::print_char

View File

@ -10,6 +10,8 @@ INCLUDE_IOW65C22 = 1
.scope IO .scope IO
; not using a struct for this since the syntax for access would be the same,
; ie label+IO::RA
.enum .enum
; IO-CHIPS OFFSETS FOR PINS FROM BASE ADDRESS ; IO-CHIPS OFFSETS FOR PINS FROM BASE ADDRESS
RB = $0 ; Register B (ORB/IRB) RB = $0 ; Register B (ORB/IRB)

12
system/irq_handler.h65 Normal file
View File

@ -0,0 +1,12 @@
;********************************************************************************
; @module irq_handler
; @type system
;********************************************************************************
.ifndef INCLUDE_IRQ_HANDLER
INCLUDE_IRQ_HANDLER = 1
.scope irq
.endscope
.endif

43
system/irq_handler.s65 Normal file
View File

@ -0,0 +1,43 @@
.include "irq_handler.h65"
.bss
.code
.proc register_via_handler
.endproc
.proc remove_via_handler
.endproc
.proc main_handler
Print "Unknown IRQ"
rti
.endproc
.zeropage
tmp: .res 1
.macro VIAHandler via_addr, via_handlers_table
lda via_addr + IO::IFR
sta tmp
bbr7 tmp,@rts ; irq
bbs0 tmp,@ca2
bbs1 tmp,@ca1
bbs2 tmp,@sr
bbs3 tmp,@cb2
bbs4 tmp,@cb1
bbs5 tmp,@t2
bbs6 tmp,@t1
; TODO error, one should have been true
stp
@rts:
rts
@ca2: jmp (via_handlers_table)
@ca1: jmp (via_handlers_table+2)
@sr: jmp (via_handlers_table+4)
@cb2: jmp (via_handlers_table+6)
@cb1: jmp (via_handlers_table+8)
@t2: jmp (via_handlers_table+10)
@t1: jmp (via_handlers_table+12)
.endmacro

View File

@ -22,44 +22,54 @@ LCD_IO = IO1
Import lcd,init,clear,print,print_char,set_position,set_custom_char Import lcd,init,clear,print,print_char,set_position,set_custom_char
Import lcd,_cmd,_wait_nbusy,_write_ram,_read_ram Import lcd,_cmd,_wait_nbusy,_write_ram,_read_ram
;******************************************************************************** ;;********************************************************************************
; @macro Clear the screen and print a null-terminated string ;; @macro Clear the screen and print a null-terminated string
; @param message: Address of the message ;; @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 .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 jsr lcd::clear
lda #<:- .if .match(message, "") ; message is a string literal -> store in rodata
sta ARG0 .pushseg
lda #>:- .rodata
sta ARG1 : .asciiz message
.else .popseg
.out "message is a n0t string" lda #<:-
jsr lcd::clear sta ARG0
lda #<message lda #>:-
sta ARG0 sta ARG1
lda #>message .else ; message is not a string
sta ARG1 lda #<message
sta ARG0
lda #>message
sta ARG1
.endif .endif
jsr lcd::print jsr lcd::print
.endmacro .endmacro
;******************************************************************************** ;;********************************************************************************
; @macro Print a null-terminated string ;; @macro Print a null-terminated string
; @param message: Address of the message ;; @param message: Address of the message or string literal
;******************************************************************************** ;;********************************************************************************
.macro PrintNC message .macro PrintNC message
lda #<message .if .match(message, "") ; message is a string literal -> store in rodata
sta ARG0 .pushseg
lda #>message .rodata
sta ARG1 : .asciiz message
.popseg
lda #<:-
sta ARG0
lda #>:-
sta ARG1
.else ; message is not a string
lda #<message
sta ARG0
lda #>message
sta ARG1
.endif
jsr lcd::print jsr lcd::print
.endmacro .endmacro

View File

@ -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 ; @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 out: Output string address
; @param x0-x9: Additional parameters ; @param x0-x9: Additional parameters
; @warning Addresses as additional paramteres must be passed like this `#<addr,#>addr` ; @warning Addresses as additional paramters must be passed like this `#<addr,#>addr`
; @modifies: A, X, Y ; @modifies: A, X, Y
; @see strf ; @see strf
;******************************************************************************** ;********************************************************************************
.macro Strf fmt,out,x0,x1,x2,x3,x4,x5,x6,x7,x8,x9 .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 @N_ARGS .set 0 ; @ so that it doesnt break cheap labels
lda #<fmt .if .match(fmt, "") ; fmt is a string literal -> store in rodata
sta ARG0 .pushseg
lda #>fmt .rodata
sta ARG1 : .asciiz fmt
.popseg
lda #<:-
sta ARG0
lda #>:-
sta ARG1
.else ; message is not a string
lda #<fmt
sta ARG0
lda #>fmt
sta ARG1
.endif
lda #<out lda #<out
sta ARG2 sta ARG2
lda #>out lda #>out
@ -56,8 +67,10 @@ Import str, hex_char_to_uint8, hex_str_to_uint, uint8_to_hex_str
_StrfStoreArg x5 _StrfStoreArg x5
_StrfStoreArg x6 _StrfStoreArg x6
_StrfStoreArg x7 _StrfStoreArg x7
_StrfStoreArg x8
_StrfStoreArg x9
jsr str::strf jsr str::strf
.out .sprintf("info: Strf: called with %d arguments", @N_ARGS) ; .out .sprintf("info: Strf: called with %d arguments", @N_ARGS)
.endmacro .endmacro
; TODO allocate zp memory ; TODO allocate zp memory