wip: kb
This commit is contained in:
parent
811d50122f
commit
0e774c5c86
34
main.s65
34
main.s65
@ -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='"
|
||||||
|
|
||||||
|
23
spicode.s65
23
spicode.s65
@ -107,9 +107,6 @@ CODE_START:
|
|||||||
bra @loop
|
bra @loop
|
||||||
|
|
||||||
|
|
||||||
; .out .sprintf("SPI: CODE_START at %x", *)
|
|
||||||
|
|
||||||
|
|
||||||
kbinit:
|
kbinit:
|
||||||
lda #'['
|
lda #'['
|
||||||
jsr lcd::print_char
|
jsr lcd::print_char
|
||||||
@ -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
|
||||||
|
@ -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)
|
||||||
|
@ -22,26 +22,25 @@ 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))
|
jsr lcd::clear
|
||||||
.if .match(message, "")
|
.if .match(message, "") ; message is a string literal -> store in rodata
|
||||||
.pushseg
|
.pushseg
|
||||||
.rodata
|
.rodata
|
||||||
: .asciiz message
|
: .asciiz message
|
||||||
.popseg
|
.popseg
|
||||||
.out .sprintf("message is a string literal: '%s' len=%x", message, .strlen(message))
|
|
||||||
jsr lcd::clear
|
|
||||||
lda #<:-
|
lda #<:-
|
||||||
sta ARG0
|
sta ARG0
|
||||||
lda #>:-
|
lda #>:-
|
||||||
sta ARG1
|
sta ARG1
|
||||||
.else
|
.else ; message is not a string
|
||||||
.out "message is a n0t string"
|
|
||||||
jsr lcd::clear
|
|
||||||
lda #<message
|
lda #<message
|
||||||
sta ARG0
|
sta ARG0
|
||||||
lda #>message
|
lda #>message
|
||||||
@ -51,15 +50,26 @@ Import lcd,_cmd,_wait_nbusy,_write_ram,_read_ram
|
|||||||
.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
|
||||||
|
.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
|
lda #<message
|
||||||
sta ARG0
|
sta ARG0
|
||||||
lda #>message
|
lda #>message
|
||||||
sta ARG1
|
sta ARG1
|
||||||
|
.endif
|
||||||
jsr lcd::print
|
jsr lcd::print
|
||||||
.endmacro
|
.endmacro
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
.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
|
lda #<fmt
|
||||||
sta ARG0
|
sta ARG0
|
||||||
lda #>fmt
|
lda #>fmt
|
||||||
sta ARG1
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user