Compare commits
No commits in common. "03221c5fb4d934c2cda0a0ed243193e6ad85d785" and "811d50122fca8eb2fbd7b278600a386333029551" have entirely different histories.
03221c5fb4
...
811d50122f
32
main.s65
32
main.s65
@ -54,7 +54,7 @@
|
||||
; Interrupts
|
||||
;********************************************************************************
|
||||
.zeropage
|
||||
irq_via_ifr: .res 1
|
||||
IRQ_VAR: .res 1
|
||||
.code
|
||||
nmi:
|
||||
lda #'%'
|
||||
@ -62,22 +62,26 @@ nmi:
|
||||
rti
|
||||
irq:
|
||||
; read IRFs, while bit 7 ist set handle interrupts
|
||||
@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_io1:
|
||||
; lda SPI_IO+IO::IFR
|
||||
; sta IRQ_VAR
|
||||
; bbr7 IRQ_VAR,@irq_io2
|
||||
@irq_io2:
|
||||
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
|
||||
sta IRQ_VAR
|
||||
bbr7 IRQ_VAR,@irq_return
|
||||
bbs2 IRQ_VAR,@irq_spi_p ; check SR
|
||||
bbs1 IRQ_VAR,@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 "Unknown IRQ"
|
||||
Print str_irq_unknown
|
||||
; force reset interrupt flags
|
||||
lda #$ff
|
||||
sta IO1 + IO::IFR
|
||||
@ -230,6 +234,10 @@ 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='"
|
||||
|
||||
|
23
spicode.s65
23
spicode.s65
@ -107,6 +107,9 @@ CODE_START:
|
||||
bra @loop
|
||||
|
||||
|
||||
; .out .sprintf("SPI: CODE_START at %x", *)
|
||||
|
||||
|
||||
kbinit:
|
||||
lda #'['
|
||||
jsr lcd::print_char
|
||||
@ -119,8 +122,6 @@ 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)
|
||||
@ -136,7 +137,7 @@ irq_on_shift_reg:
|
||||
lda #'{'
|
||||
jsr lcd::print_char
|
||||
lda kb::KB_IO + IO::SR
|
||||
sta key_read
|
||||
sta keycode
|
||||
stz kb::KB_IO + IO::SR
|
||||
|
||||
; disable SR interrupts
|
||||
@ -158,7 +159,7 @@ irq_on_timer:
|
||||
lda #'<'
|
||||
jsr lcd::print_char
|
||||
lda kb::KB_IO + IO::SR
|
||||
sta key_read + 1
|
||||
sta keycode + 1
|
||||
|
||||
lda kb::KB_IO + IO::T2CL ; clear interrupt flag
|
||||
|
||||
@ -172,29 +173,25 @@ irq_on_timer:
|
||||
stz kb::KB_IO + IO::SR
|
||||
|
||||
; lda #'|'
|
||||
lda key_read
|
||||
lda keycode
|
||||
jsr lcd::print_char
|
||||
lda key_read + 1
|
||||
lda keycode + 1
|
||||
jsr lcd::print_char
|
||||
; rotate bit 2 (last bit of keycode) into the carry
|
||||
ror
|
||||
ror
|
||||
ror
|
||||
lda key_read ; not affecting carry
|
||||
lda keycode ; 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
|
||||
sta keycode + 1
|
||||
jsr lcd::print_char
|
||||
|
||||
stz key_read
|
||||
stz key_read+1
|
||||
|
||||
lda #'>'
|
||||
jsr lcd::print_char
|
||||
rts
|
||||
|
||||
key_read: .res 2
|
||||
keycode: .res 1
|
||||
keycode: .res 3
|
||||
kb_irq1:
|
||||
lda #'!'
|
||||
jsr lcd::print_char
|
||||
|
@ -10,8 +10,6 @@ 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)
|
||||
|
@ -1,12 +0,0 @@
|
||||
;********************************************************************************
|
||||
; @module irq_handler
|
||||
; @type system
|
||||
;********************************************************************************
|
||||
.ifndef INCLUDE_IRQ_HANDLER
|
||||
INCLUDE_IRQ_HANDLER = 1
|
||||
|
||||
.scope irq
|
||||
|
||||
.endscope
|
||||
.endif
|
||||
|
@ -1,43 +0,0 @@
|
||||
.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
|
@ -22,25 +22,26 @@ 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 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 Clear the screen and print a null-terminated string
|
||||
; @param message: Address of the message
|
||||
;********************************************************************************
|
||||
.macro Print message
|
||||
jsr lcd::clear
|
||||
.if .match(message, "") ; message is a string literal -> store in rodata
|
||||
; .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 ; message is not a string
|
||||
.else
|
||||
.out "message is a n0t string"
|
||||
jsr lcd::clear
|
||||
lda #<message
|
||||
sta ARG0
|
||||
lda #>message
|
||||
@ -50,26 +51,15 @@ Import lcd,_cmd,_wait_nbusy,_write_ram,_read_ram
|
||||
.endmacro
|
||||
|
||||
|
||||
;;********************************************************************************
|
||||
;; @macro Print a null-terminated string
|
||||
;; @param message: Address of the message or string literal
|
||||
;;********************************************************************************
|
||||
;********************************************************************************
|
||||
; @macro Print a null-terminated string
|
||||
; @param message: Address of the message
|
||||
;********************************************************************************
|
||||
.macro PrintNC message
|
||||
.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 ARG0
|
||||
lda #>message
|
||||
sta ARG1
|
||||
.endif
|
||||
jsr lcd::print
|
||||
.endmacro
|
||||
|
||||
|
@ -31,30 +31,19 @@ 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 or string literal
|
||||
; @param fmt: Format string address
|
||||
; @param out: Output string address
|
||||
; @param x0-x9: Additional parameters
|
||||
; @warning Addresses as additional paramters must be passed like this `#<addr,#>addr`
|
||||
; @warning Addresses as additional paramteres must be passed like this `#<addr,#>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
|
||||
.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 ARG0
|
||||
lda #>fmt
|
||||
sta ARG1
|
||||
.endif
|
||||
lda #<out
|
||||
sta ARG2
|
||||
lda #>out
|
||||
@ -67,10 +56,8 @@ 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
|
||||
|
Loading…
Reference in New Issue
Block a user