6502-OS/spicode.s65

305 lines
5.6 KiB
Plaintext
Raw Normal View History

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-27 16:56:14 +01:00
.include "keyboard.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
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
2023-12-31 01:59:06 +01:00
; jmp homeloop
DEBUG_LED_OFF 0
DEBUG_LED_OFF 1
DEBUG_LED_OFF 2
2023-12-20 12:27:54 +01:00
lda #<kb_irq1
sta ARG0
lda #>kb_irq1
sta ARG1
lda #<$3000
sta ARG2
lda #>$3000
sta ARG3
2023-12-31 01:59:06 +01:00
ldy #10
2023-12-20 12:27:54 +01:00
jsr memcopy
lda #<kb_irq2
sta ARG0
lda #>kb_irq2
sta ARG1
lda #<$3100
sta ARG2
lda #>$3100
sta ARG3
2023-12-31 01:59:06 +01:00
ldy #10
2023-12-20 12:27:54 +01:00
jsr memcopy
; PrintNC $3000
2023-12-27 16:56:14 +01:00
jsr kb::init
2023-12-20 12:27:54 +01:00
2023-12-31 01:59:06 +01:00
stz kb::status
2023-12-20 12:27:54 +01:00
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:
2023-12-31 01:59:06 +01:00
wai
lda kb::scancode
beq @noscancode
jsr process_scancode
stz kb::scancode
lda char
beq @onlykeycode
Strf fmt_codechar,out_str,keycode,kb::status,char
PrintNC out_str
stz char
stz keycode
bra @noscancode
@onlykeycode:
lda keycode
beq @noscancode
Strf fmt_code,out_str,keycode,keycode_flags
PrintNC out_str
stz keycode
@noscancode:
bbr5 kb::status, @shift_off
@shift_on:
DEBUG_LED_ON 0
bra @check_caps
@shift_off:
DEBUG_LED_OFF 0
@check_caps:
bbr4 kb::status, @caps_off
@caps_on:
DEBUG_LED_ON 2
bra @read_keypad
@caps_off:
DEBUG_LED_OFF 2
@read_keypad:
2023-12-09 23:33:42 +01:00
lda kp::_DEBUG_VAL
2023-12-31 01:59:06 +01:00
jeq @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
2023-12-22 12:10:54 +01:00
cmp #'B'
beq @lB
cmp #'C'
beq @lC
2023-12-20 12:27:54 +01:00
jsr lcd::print_char
2023-12-31 01:59:06 +01:00
jmp @loop
2023-12-20 12:27:54 +01:00
@l1:
; jsr irq_on_shift_reg
jsr $3000
lda #'*'
jsr lcd::print_char
2023-12-31 01:59:06 +01:00
jmp @loop
2023-12-20 12:27:54 +01:00
@l2:
; jsr irq_on_timer
jsr $3100
lda #'#'
jsr lcd::print_char
2023-12-31 01:59:06 +01:00
jmp @loop
2023-12-20 12:27:54 +01:00
@l3:
lda $3000,y
jsr lcd::print_char
2023-12-16 02:41:19 +01:00
iny
2023-12-31 01:59:06 +01:00
jmp @loop
2023-12-20 12:27:54 +01:00
@lA:
lda kb::KB_IO + IO::SR
2023-12-16 02:41:19 +01:00
jsr lcd::print_char
2023-12-31 01:59:06 +01:00
jmp @loop
2023-12-22 12:10:54 +01:00
@lB:
2023-12-31 01:59:06 +01:00
; Printf "kc%x;", out_str, kb::scancode
jsr lcd::clear
ldx out_idx
lda #0
sta out_str,x
2023-12-22 12:10:54 +01:00
Print out_str
2023-12-31 01:59:06 +01:00
stz out_idx
jmp @loop
2023-12-22 12:10:54 +01:00
@lC:
jsr lcd::clear
2023-12-31 01:59:06 +01:00
jmp @loop
2023-12-20 12:27:54 +01:00
2023-12-16 02:41:19 +01:00
2023-12-23 14:17:49 +01:00
; key_read: .res 2
2023-12-31 01:59:06 +01:00
; scancode: .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-27 16:56:14 +01:00
jsr kb::irq_shift_reg_handler
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-23 14:17:49 +01:00
; jsr kb::on_timer_irq
2023-12-31 01:59:06 +01:00
jsr kb::irq_timer_handler
2023-12-22 12:10:54 +01:00
; 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-31 01:59:06 +01:00
.proc process_scancode
; DEBUG_LED_OFF 1
; check how this scancode needs to be interpreted
ldx kb::scancode
bit kb::status
jmi release_key ; bit 7 set
bvs @twobytecode ; bit 6 set
; DEBUG_LED_ON 1
; check mods
cpx #kb::K_RELEASE
beq @code_release
cpx #kb::K::LEFTSHIFT
beq @code_shift
cpx #kb::K::RIGHTSHIFT
beq @code_shift
cpx #kb::K_TWOBYTE
beq @code_twobytecode
cpx #kb::K::CAPSLOCK
beq @code_capslock
; a real keycode and not a released keycode, twobyte or release scancode
stz keycode_flags
stx keycode
cmp #$62 ; $61 is the largest ascii scancode
bcs @special
bbs5 kb::status,@modshift ; if shift active
@nomod:
lda kb::CHARS_NOMOD,x
beq @special
@char: ; order which is fastet most of the time (lowercase characters)
sta char
rts
@modshift:
lda kb::CHARS_MODSHIFT,x
bne @char
@special:
rts
@code_release: ; set release
smb7 kb::status
rts
@code_twobytecode: ; set twobytecode
smb6 kb::status
rts
@code_shift: ; process shift
bbs4 kb::status, @unset_shift ; unset shift when capslock is on
@set_shift:
smb5 kb::status
rts
@unset_shift:
rmb5 kb::status
rts
@code_capslock: ; toggle capslock & shift
bbs1 kb::status, @rts ; ignore if held
lda kb::status
ora #(kb::STATUS::CAPSLOCK_HELD)
; toggle and capslock shift
eor #(kb::STATUS::CAPSLOCK | kb::STATUS::SHIFT)
sta kb::status
rts
@code_rightalt: ; set rightalt
smb3 kb::status
rts
@code_numlock: ; set numlock
smb2 kb::status
rts
2023-12-22 02:17:58 +01:00
2023-12-31 01:59:06 +01:00
@twobytecode:
rmb6 kb::status ; unset twobytecode
; check mods
cpx #kb::K2::RIGHTALT
beq @code_rightalt
lda #kb::STATUS::TWOBYTE
sta keycode_flags
stx keycode
@rts:
rts
.endproc
;; @param S: The status register must be set through `bit kb::status`
;; @param X: The scancode
.proc release_key
bvs @twobytecode
rmb7 kb::status
; check mods
cpx #kb::K_TWOBYTE
beq @code_twobytecode
cpx #kb::K::LEFTSHIFT
beq @code_shift
cpx #kb::K::RIGHTSHIFT
beq @code_shift
cpx #kb::K::CAPSLOCK
beq @code_capslock
; no need to process capslock - it gets toggled when pressed
rts
@code_twobytecode: ; unset special
rmb6 kb::status
rts
@code_shift: ; process shift
bbs4 kb::status, @code_shift_caps ; set shift when capslock is on
rmb5 kb::status ; unset if capslock is off
rts
@code_shift_caps:
smb5 kb::status
rts
@code_capslock: ; unset CAPSLOCK_HELD
rmb1 kb::status
rts
@code_rightalt: ; unset rightalt
rmb3 kb::status
rts
@code_numlock: ; unset numlock
rmb2 kb::status
rts
@twobytecode:
rmb6 kb::status ; unset twobytecode
; check mods
cpx #kb::K2::RIGHTALT
beq @code_rightalt
rts
.endproc
out_idx: .res 1
out_str: .res 40
char: .res 1
keycode: .res 1
keycode_flags: .res 1
fmt_codechar: .asciiz "%x %x %c "
fmt_code: .asciiz "%x %x "