-
-
Save mbamac/49bd741ad9da3e0a680bd93dd20fe558 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Keyboard test program by M. Bartosiak | |
!cpu 65c02 | |
!to "via-keyboard-5.bin", plain | |
keyb_row = $8000 | |
key_pressed = $C001 | |
via2a_out = $D004 | |
delay_via = $D805 | |
param_addr_ptr = $FE | |
!source "via-addrs-2-A8.h" | |
*=$E000 | |
; reset vector | |
; everything starts here after power up or reset | |
reset_vec | |
lda #$0 ; a = 0 | |
sta keyb_row ; keyb_line = a = 0 | |
sta via2a_out ; via2a_out = a = 0 | |
lda #$1 ; a = 1 | |
jsr lcd_init ; initialize lcd | |
jsr via_init ; initialize vias | |
lda #<msg1 | |
sta param_addr_ptr ; store high byte of message address | |
lda #>msg1 | |
sta param_addr_ptr+1 ; store low byte of message address | |
jsr lcd_print ;print message | |
jmp main_loop ; | |
msg1 !raw "OK." | |
!byte $00 ;terminating null for string | |
nmi_vec | |
pha | |
bit via1_t1c_l ; read anything from t1c_l to turn off interrupt signal | |
lda via1_iora ; read keyboard status from VIA | |
bmi + ; if a < 0 go to "+" label (key not pressed) | |
sta key_pressed ; key_pressed = a (store pressed key) | |
pla | |
rti | |
+ ; key not pressed. prepare to scan next row | |
lda keyb_row ; a = keyb_line | |
clc ; | |
adc #1 ; a++ | |
cmp #8 ; | |
bne + ; if a != 7 then | |
lda #0 ; a = 0 | |
+ | |
sta via1_iora ; send to via1 port A | |
sta keyb_row ; keyb_line = a | |
lda #$FF | |
sta key_pressed ; key_pressesd = 0 | |
pla | |
rti | |
irq_vec | |
pha | |
bit via2_t1c_l ; read anything from t1c_l to turn off interrupt signal | |
lda delay_via ; a = delay_via | |
bne + ; if a == 0 then | |
lda #$10 ; a = $10 | |
+ | |
sec | |
sbc #1 ; a-- | |
sta delay_via ; delay_via = a | |
bne + ; | |
clc | |
lda via2a_out ; a = char_to_via | |
sta via1_iorb ; send to via1 port B | |
sta via2_iora ; send to via2 port A | |
rol ; a =>> 1 | |
bne ++ ; if a == 0 then | |
lda #$1 ; a = $1 | |
++ | |
sta via2a_out ; char_to_via = a | |
+ | |
pla | |
rti | |
main_loop | |
lda #40 | |
jsr lcd_goto | |
lda keyb_row | |
jsr lcd_hex | |
lda #':' | |
jsr lcd_putchar | |
lda key_pressed | |
jsr lcd_hex | |
jmp main_loop ; | |
;;; VIA's STUFF | |
via_init | |
pha | |
lda #%00000111 ; load #$ff into via_ddra | |
sta via1_ddra ; set first 3 bits pf port A of via1 to output | |
lda #$ff ; load #$ff into via_ddra | |
sta via1_ddrb ; set port A of via2 to output | |
sta via2_ddra ; set port A of via2 to output | |
lda #$0 | |
sta via1_iora ; set port A pins to low state | |
sta via2_iora ; in both vias | |
sta via1_iorb ; set port A pins to low state | |
; initialize timer | |
lda #%01000000 | |
sta via1_acr ; set timer to continous mode, no PB7 | |
lda #%11000000 | |
sta via1_ier ; enable timer 1 interrupt on via1 | |
lda #$ff | |
sta via1_t1c_l ; set timer to interrupt | |
sta via1_t1c_h ; ... every 65535 ticks | |
; initialize timer | |
lda #%01000000 | |
sta via2_acr ; set timer to continous mode, no PB7 | |
lda #%11000000 | |
sta via2_ier ; enable timer 1 interrupt on via1 | |
lda #$ff | |
sta via2_t1c_l ; set timer to interrupt | |
sta via2_t1c_h ; ... every 65535 ticks | |
cli | |
pla | |
rts | |
; insert LCD stuff | |
!source "lcd.s" | |
;;; STANDARD 65c02 VECTORS | |
*=$FFFA | |
!word nmi_vec | |
!word reset_vec | |
!word irq_vec |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment