2023-12-08 22:56:35 +01:00
|
|
|
.include "system.h65"
|
2023-12-16 02:41:19 +01:00
|
|
|
.include "string.h65"
|
2023-12-08 22:56:35 +01:00
|
|
|
.include "lcd.h65"
|
|
|
|
.include "math.h65"
|
2023-12-09 23:33:42 +01:00
|
|
|
.include "keypad.h65"
|
2023-12-16 02:41:19 +01:00
|
|
|
.include "chars.h65"
|
|
|
|
.import homeloop:absolute
|
2023-12-08 22:56:35 +01:00
|
|
|
.import home:absolute
|
2023-12-20 12:27:54 +01:00
|
|
|
|
2023-12-08 22:56:35 +01:00
|
|
|
.segment "SPI"
|
|
|
|
.export CODE_START
|
|
|
|
|
2023-12-20 12:27:54 +01:00
|
|
|
.import memcopy
|
|
|
|
|
|
|
|
.scope kb
|
|
|
|
KB_IO = IO1
|
|
|
|
.endscope
|
|
|
|
|
|
|
|
|
2023-12-08 22:56:35 +01:00
|
|
|
CODE_START:
|
2023-12-09 23:33:42 +01:00
|
|
|
.assert * = $5000, error, "SPI Code not at $5000"
|
2023-12-16 02:41:19 +01:00
|
|
|
jsr lcd::clear
|
2023-12-20 12:27:54 +01:00
|
|
|
lda #'$'
|
|
|
|
jsr lcd::print_char
|
|
|
|
|
|
|
|
; stz kp::_DEBUG_VAL
|
|
|
|
; @loop:
|
|
|
|
; lda kp::_DEBUG_VAL
|
|
|
|
; beq @loop
|
|
|
|
; stz kp::_DEBUG_VAL
|
|
|
|
; cmp #'*'
|
|
|
|
; jeq homeloop
|
|
|
|
; jsr lcd::print_char
|
|
|
|
; bra @loop
|
|
|
|
|
|
|
|
lda #<kb_irq1
|
|
|
|
sta ARG0
|
|
|
|
lda #>kb_irq1
|
|
|
|
sta ARG1
|
|
|
|
lda #<$3000
|
|
|
|
sta ARG2
|
|
|
|
lda #>$3000
|
|
|
|
sta ARG3
|
|
|
|
ldy #20
|
|
|
|
jsr memcopy
|
|
|
|
|
|
|
|
lda #<kb_irq2
|
|
|
|
sta ARG0
|
|
|
|
lda #>kb_irq2
|
|
|
|
sta ARG1
|
|
|
|
lda #<$3100
|
|
|
|
sta ARG2
|
|
|
|
lda #>$3100
|
|
|
|
sta ARG3
|
|
|
|
ldy #20
|
|
|
|
jsr memcopy
|
|
|
|
|
|
|
|
lda #'?'
|
2023-12-08 22:56:35 +01:00
|
|
|
jsr lcd::print_char
|
2023-12-20 12:27:54 +01:00
|
|
|
|
|
|
|
; PrintNC $3000
|
|
|
|
|
|
|
|
jsr kbinit
|
|
|
|
|
|
|
|
lda #'%'
|
|
|
|
jsr lcd::print_char
|
|
|
|
|
2023-12-09 23:33:42 +01:00
|
|
|
stz kp::_DEBUG_VAL
|
2023-12-16 02:41:19 +01:00
|
|
|
ldy #0
|
2023-12-20 12:27:54 +01:00
|
|
|
|
2023-12-09 23:33:42 +01:00
|
|
|
@loop:
|
|
|
|
lda kp::_DEBUG_VAL
|
2023-12-16 02:41:19 +01:00
|
|
|
beq @loop
|
2023-12-20 12:27:54 +01:00
|
|
|
stz kp::_DEBUG_VAL
|
2023-12-16 02:41:19 +01:00
|
|
|
cmp #'*'
|
|
|
|
jeq homeloop
|
2023-12-20 12:27:54 +01:00
|
|
|
cmp #'1'
|
|
|
|
beq @l1
|
|
|
|
cmp #'2'
|
|
|
|
beq @l2
|
|
|
|
cmp #'3'
|
|
|
|
beq @l3
|
|
|
|
cmp #'A'
|
|
|
|
beq @lA
|
|
|
|
jsr lcd::print_char
|
|
|
|
bra @loop
|
|
|
|
@l1:
|
|
|
|
; jsr irq_on_shift_reg
|
|
|
|
jsr $3000
|
|
|
|
lda #'*'
|
|
|
|
jsr lcd::print_char
|
|
|
|
bra @loop
|
|
|
|
@l2:
|
|
|
|
; jsr irq_on_timer
|
|
|
|
jsr $3100
|
|
|
|
lda #'#'
|
|
|
|
jsr lcd::print_char
|
|
|
|
bra @loop
|
|
|
|
@l3:
|
|
|
|
lda $3000,y
|
|
|
|
jsr lcd::print_char
|
2023-12-16 02:41:19 +01:00
|
|
|
iny
|
2023-12-20 12:27:54 +01:00
|
|
|
bra @loop
|
|
|
|
@lA:
|
|
|
|
lda kb::KB_IO + IO::SR
|
2023-12-16 02:41:19 +01:00
|
|
|
jsr lcd::print_char
|
2023-12-09 23:33:42 +01:00
|
|
|
bra @loop
|
2023-12-08 22:56:35 +01:00
|
|
|
|
2023-12-10 12:10:55 +01:00
|
|
|
|
2023-12-20 12:27:54 +01:00
|
|
|
kbinit:
|
|
|
|
lda #'['
|
2023-12-16 02:41:19 +01:00
|
|
|
jsr lcd::print_char
|
2023-12-20 12:27:54 +01:00
|
|
|
; - use the shift register interrupts to read the first 8 bits
|
|
|
|
; set shift register to shift in under external clock on CB1
|
|
|
|
; - configure timer for timing the read of the last 3 bits
|
|
|
|
; timer 2 one shot mode is sufficient, leaves T1 available
|
|
|
|
lda #(IO::ACR::SR_SIN_PHIE | IO::ACR::T2_IRQ_LOAD)
|
|
|
|
tsb kb::KB_IO + IO::ACR
|
|
|
|
; 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
|
2023-12-21 17:27:54 +01:00
|
|
|
stz key_read
|
|
|
|
stz key_read+1
|
2023-12-20 12:27:54 +01:00
|
|
|
|
|
|
|
; enable SR interrupts
|
|
|
|
lda #(IO::IRQ::IRQ | IO::IRQ::SR)
|
|
|
|
sta kb::KB_IO + IO::IER
|
|
|
|
; load SR to reset
|
|
|
|
lda kb::KB_IO + IO::SR
|
|
|
|
lda #']'
|
2023-12-16 02:41:19 +01:00
|
|
|
jsr lcd::print_char
|
2023-12-20 12:27:54 +01:00
|
|
|
rts
|
2023-12-08 22:56:35 +01:00
|
|
|
|
2023-12-20 12:27:54 +01:00
|
|
|
|
|
|
|
irq_on_shift_reg:
|
2023-12-22 02:17:58 +01:00
|
|
|
; lda #'{'
|
|
|
|
; jsr lcd::print_char
|
2023-12-20 12:27:54 +01:00
|
|
|
lda kb::KB_IO + IO::SR
|
2023-12-21 17:27:54 +01:00
|
|
|
sta key_read
|
2023-12-20 12:27:54 +01:00
|
|
|
stz kb::KB_IO + IO::SR
|
|
|
|
|
|
|
|
; disable SR interrupts
|
|
|
|
lda #IO::IRQ::SR
|
|
|
|
sta kb::KB_IO + IO::IER
|
|
|
|
; enable timer interrupts
|
|
|
|
lda #(IO::IRQ::IRQ | IO::IRQ::T2)
|
|
|
|
sta kb::KB_IO + IO::IER
|
|
|
|
; start timer
|
|
|
|
lda #1
|
|
|
|
sta kb::KB_IO + IO::T2CH
|
|
|
|
; lda #'}'
|
|
|
|
; jsr lcd::print_char
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
|
|
irq_on_timer:
|
|
|
|
lda #'<'
|
2023-12-16 02:41:19 +01:00
|
|
|
jsr lcd::print_char
|
2023-12-20 12:27:54 +01:00
|
|
|
lda kb::KB_IO + IO::SR
|
2023-12-21 17:27:54 +01:00
|
|
|
sta key_read + 1
|
2023-12-20 12:27:54 +01:00
|
|
|
|
|
|
|
lda kb::KB_IO + IO::T2CL ; clear interrupt flag
|
|
|
|
|
|
|
|
; disable timer interrupts
|
|
|
|
lda #(IO::IRQ::T2)
|
|
|
|
sta kb::KB_IO + IO::IER
|
|
|
|
; enable shift register interrupts
|
|
|
|
lda #(IO::IRQ::IRQ | IO::IRQ::SR)
|
|
|
|
sta kb::KB_IO + IO::IER
|
|
|
|
; load SR to reset
|
|
|
|
stz kb::KB_IO + IO::SR
|
|
|
|
|
|
|
|
; lda #'|'
|
2023-12-21 17:27:54 +01:00
|
|
|
lda key_read
|
2023-12-16 02:41:19 +01:00
|
|
|
jsr lcd::print_char
|
2023-12-21 17:27:54 +01:00
|
|
|
lda key_read + 1
|
2023-12-16 02:41:19 +01:00
|
|
|
jsr lcd::print_char
|
2023-12-20 12:27:54 +01:00
|
|
|
; rotate bit 2 (last bit of keycode) into the carry
|
|
|
|
ror
|
|
|
|
ror
|
|
|
|
ror
|
2023-12-21 17:27:54 +01:00
|
|
|
lda key_read ; not affecting carry
|
2023-12-20 12:27:54 +01:00
|
|
|
rol ; rotate carry into byte, rotate startbit into carry
|
|
|
|
; TODO byte is inverted, maybe consider wasting 256 bytes for a bit reverse lookup table?
|
2023-12-21 17:27:54 +01:00
|
|
|
sta keycode
|
|
|
|
stz key_read
|
|
|
|
stz key_read+1
|
|
|
|
|
2023-12-22 02:17:58 +01:00
|
|
|
Strf "kc:%x", out_str, keycode
|
|
|
|
PrintNC out_str
|
2023-12-08 22:56:35 +01:00
|
|
|
rts
|
2023-12-16 02:41:19 +01:00
|
|
|
|
2023-12-21 17:27:54 +01:00
|
|
|
key_read: .res 2
|
|
|
|
keycode: .res 1
|
2023-12-20 12:27:54 +01:00
|
|
|
kb_irq1:
|
2023-12-22 02:17:58 +01:00
|
|
|
; lda #'!'
|
|
|
|
; jsr lcd::print_char
|
2023-12-20 12:27:54 +01:00
|
|
|
jsr irq_on_shift_reg
|
2023-12-22 02:17:58 +01:00
|
|
|
; lda #':'
|
|
|
|
; jsr lcd::print_char
|
2023-12-16 02:41:19 +01:00
|
|
|
rts
|
2023-12-20 12:27:54 +01:00
|
|
|
.byte '='
|
|
|
|
kb_irq2:
|
2023-12-22 02:17:58 +01:00
|
|
|
; lda #'?'
|
|
|
|
; jsr lcd::print_char
|
2023-12-20 12:27:54 +01:00
|
|
|
jsr irq_on_timer
|
|
|
|
lda #';'
|
|
|
|
jsr lcd::print_char
|
2023-12-09 23:33:42 +01:00
|
|
|
rts
|
2023-12-20 12:27:54 +01:00
|
|
|
.byte '@'
|
2023-12-08 22:56:35 +01:00
|
|
|
|
2023-12-22 02:17:58 +01:00
|
|
|
out_str: .res 40
|
|
|
|
|