2024-04-10 17:28:34 -04:00
|
|
|
; .setcpu "65C02"
|
|
|
|
.include "./macro.inc"
|
|
|
|
|
|
|
|
.org $8000
|
|
|
|
|
2024-06-29 23:38:02 -04:00
|
|
|
n = $01 ; temporary storage for data stack operations
|
2024-06-30 22:49:54 -04:00
|
|
|
key_buffer = $200
|
2024-06-29 23:38:02 -04:00
|
|
|
|
2024-04-10 17:28:34 -04:00
|
|
|
reset:
|
|
|
|
sei
|
|
|
|
ldx #0; initialize data stack pointer
|
|
|
|
|
|
|
|
initdisplay:
|
2024-06-29 23:38:02 -04:00
|
|
|
lda #0
|
2024-04-10 17:28:34 -04:00
|
|
|
ldy #0
|
|
|
|
|
|
|
|
cleardisplay:
|
|
|
|
sta $6000,y
|
|
|
|
sta $6100,y
|
|
|
|
sta $6200,y
|
|
|
|
sta $6300,y
|
|
|
|
sta $6400,y
|
|
|
|
sta $6500,y
|
|
|
|
sta $6600,y
|
|
|
|
sta $6700,y ; this goes slightly over but it's fine
|
|
|
|
iny
|
|
|
|
bne cleardisplay
|
|
|
|
cli
|
|
|
|
|
|
|
|
main:
|
2024-06-30 22:49:54 -04:00
|
|
|
; jsr read_keys
|
|
|
|
; lda key_buffer
|
2024-07-04 13:04:13 -04:00
|
|
|
lda $4400
|
2024-06-30 22:49:54 -04:00
|
|
|
sta $6000
|
2024-04-10 17:28:34 -04:00
|
|
|
jmp main
|
|
|
|
|
2024-06-30 22:49:54 -04:00
|
|
|
; first, let's do the simplest case of just the letter a being pressed
|
|
|
|
; 1. check row 2 ($4402, where the a key is) for pressed keys
|
|
|
|
; 2. if any keys are pressed, check if the key is a (bit 0)
|
|
|
|
; 3. if the key is not a, store zero in the key buffer
|
|
|
|
; 4. if the key is a, store the ascii for a in the key buffer
|
|
|
|
; 5. return
|
|
|
|
|
|
|
|
; so u don't have to scroll: key_buffer = $200
|
|
|
|
; key buffer just shows the current state of the keyboard
|
|
|
|
; it is not a queue of keys to print
|
|
|
|
|
|
|
|
read_keys:
|
|
|
|
lda $4402 ; check row 2
|
|
|
|
beq check_key ; if there're any keys, check which
|
|
|
|
clear_buffer:
|
|
|
|
stz key_buffer
|
|
|
|
rts
|
|
|
|
check_key: ; if there is a key pressed, check if it's a
|
|
|
|
ror
|
|
|
|
bmi store_key
|
|
|
|
rts
|
|
|
|
store_key:
|
|
|
|
; in a sec we'll set up ascii table lookup,
|
|
|
|
; for now let's just load the ascii byte for a
|
|
|
|
lda #$61
|
|
|
|
sta key_buffer
|
|
|
|
rts
|
|
|
|
|
2024-04-10 17:28:34 -04:00
|
|
|
draw:
|
|
|
|
push_coords #0, #0
|
2024-06-29 23:38:02 -04:00
|
|
|
push_char #$af
|
2024-04-10 17:28:34 -04:00
|
|
|
jsr draw_char
|
|
|
|
rts
|
|
|
|
|
|
|
|
draw_char: ; draw a character c at (x, y) (n1: x n2: y n3: c -- )
|
|
|
|
lda 0, x ; load a with character to draw
|
|
|
|
pop ; and pop it off the stack
|
|
|
|
jsr get_char_address ; calculate where to put the character in memory
|
|
|
|
sta (0, x) ; store a at the address pointed to on the stack
|
|
|
|
rts
|
|
|
|
|
|
|
|
get_char_address: ; gets vram address for a character at (x, y),
|
|
|
|
; (n1: x n2: y -- n: $6000 + x + (64 * y))
|
|
|
|
;jsr push_lit ; push 64 onto stack, low byte first
|
|
|
|
;.byte 64
|
|
|
|
;.byte 0
|
|
|
|
pha
|
|
|
|
lda #64
|
|
|
|
push ; doing this instead until `push_lit` is fixed
|
|
|
|
sta 0, x
|
|
|
|
stz 1, x
|
|
|
|
jsr mult ; multiply 64 with y (n2)
|
|
|
|
jsr plus ; add result with x (n1)
|
|
|
|
|
|
|
|
;jsr push_lit ; push vram address onto the stack
|
|
|
|
;.byte $00
|
|
|
|
;.byte $60
|
|
|
|
lda #$60
|
|
|
|
push
|
|
|
|
sta 1, x
|
|
|
|
stz 0, x
|
|
|
|
jsr plus ; add vram start address to result
|
|
|
|
|
|
|
|
pla
|
|
|
|
rts
|
|
|
|
|
|
|
|
fill: ; fills an area from (x1, y1) to (x2, y2) will character c, (n1: c n2: x1 n3: y1 n4: x2 n5: y2 -- )
|
|
|
|
jsr get_char_address
|
|
|
|
|
2024-06-29 23:38:02 -04:00
|
|
|
irq:
|
|
|
|
rts
|
|
|
|
|
2024-04-10 17:28:34 -04:00
|
|
|
isr: ; interrupt service routine
|
|
|
|
pha
|
|
|
|
phx
|
|
|
|
phy
|
2024-06-29 23:38:02 -04:00
|
|
|
jsr irq
|
2024-04-10 17:28:34 -04:00
|
|
|
ply
|
|
|
|
plx
|
|
|
|
pla
|
|
|
|
rti
|
|
|
|
|
|
|
|
.include "math.inc"
|
|
|
|
|
|
|
|
.org $fffc
|
|
|
|
.word reset
|
|
|
|
.word isr
|