2024-04-10 17:28:34 -04:00
|
|
|
; .setcpu "65C02"
|
|
|
|
.include "./macro.inc"
|
|
|
|
|
|
|
|
; okay so rn i wanna set up a very basic system init, and write a few subroutines to draw characters at x,y coordinates
|
|
|
|
n = $01 ; temporary storage for data stack operations
|
|
|
|
|
|
|
|
key_row = $200 ; used for character lookup when key pressed
|
|
|
|
key_col = $201
|
|
|
|
cursor = $202
|
|
|
|
|
|
|
|
char_buffer = $300 ; 256 byte character buffer
|
|
|
|
|
2024-06-15 22:45:27 -04:00
|
|
|
kb_row = $4400 ; keyboard hardware register
|
2024-04-10 17:28:34 -04:00
|
|
|
kb_row_cache = $203 ; cache
|
|
|
|
|
|
|
|
.org $8000
|
|
|
|
|
|
|
|
reset:
|
|
|
|
sei
|
|
|
|
ldx #0; initialize data stack pointer
|
|
|
|
|
|
|
|
initdisplay:
|
|
|
|
lda #$20
|
|
|
|
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
|
2024-06-15 22:45:27 -04:00
|
|
|
; cli
|
2024-04-10 17:28:34 -04:00
|
|
|
|
|
|
|
main:
|
2024-06-29 23:38:02 -04:00
|
|
|
jsr printtext
|
2024-06-15 22:45:27 -04:00
|
|
|
; key_zero:
|
|
|
|
; stz keyboard_cache, x
|
|
|
|
; dex
|
|
|
|
; bpl key_zero
|
|
|
|
; fim:
|
|
|
|
; cli
|
|
|
|
; bra fim
|
2024-04-10 17:28:34 -04:00
|
|
|
jmp main
|
|
|
|
|
2024-06-29 23:38:02 -04:00
|
|
|
printtext:
|
|
|
|
ldx 0
|
|
|
|
loop:
|
|
|
|
lda text, x
|
|
|
|
beq end
|
|
|
|
sta $6000, x
|
|
|
|
inx
|
|
|
|
bra loop
|
|
|
|
end:
|
|
|
|
rts
|
2024-06-15 22:45:27 -04:00
|
|
|
|
2024-06-29 23:38:02 -04:00
|
|
|
text:
|
|
|
|
.asciiz "hi <3"
|
2024-06-15 22:45:27 -04:00
|
|
|
|
2024-04-10 17:28:34 -04:00
|
|
|
keyboard:
|
|
|
|
ldy #0
|
2024-06-15 22:45:27 -04:00
|
|
|
.check_row: ; loop through each row
|
2024-04-10 17:28:34 -04:00
|
|
|
lda kb_row, y
|
2024-06-15 22:45:27 -04:00
|
|
|
beq .skip_row ; if row has no key pressed, skip checking which key
|
2024-06-29 23:38:02 -04:00
|
|
|
; jmp key_down
|
2024-04-10 17:28:34 -04:00
|
|
|
sta kb_row_cache, y ; if key pressed, cache it
|
|
|
|
lda kb_row, y
|
|
|
|
cmp kb_row_cache, y ; has key changed?
|
|
|
|
beq key_down
|
2024-06-15 22:45:27 -04:00
|
|
|
.skip_row:
|
2024-04-10 17:28:34 -04:00
|
|
|
iny
|
|
|
|
cpy #5
|
2024-06-15 22:45:27 -04:00
|
|
|
bne .check_row
|
2024-04-10 17:28:34 -04:00
|
|
|
rts
|
|
|
|
|
|
|
|
key_down: ; a is loaded with the row byte
|
|
|
|
phy
|
2024-06-15 22:45:27 -04:00
|
|
|
sty key_row ; store character row
|
2024-04-10 17:28:34 -04:00
|
|
|
ldy #0
|
|
|
|
.find_col: ; test each row bit, store column if key pressed
|
|
|
|
lsr ; test bit 7
|
|
|
|
bcs store_col ; if unset, don't go store character columnb
|
|
|
|
.skip:
|
|
|
|
iny
|
|
|
|
cpy #8
|
|
|
|
bne .find_col ; loop until we've checked each bit
|
|
|
|
|
|
|
|
store_col:
|
|
|
|
sty key_col
|
|
|
|
|
|
|
|
keymap_index:
|
|
|
|
push
|
|
|
|
lda key_col
|
|
|
|
stz 1, x
|
|
|
|
sta 0, x
|
|
|
|
push
|
|
|
|
lda #8
|
|
|
|
stz 1, x
|
|
|
|
sta 0, x
|
|
|
|
push
|
|
|
|
lda key_row
|
|
|
|
stz 1, x
|
|
|
|
sta 0, x
|
|
|
|
jsr mult
|
|
|
|
jsr plus
|
|
|
|
lda 0, x
|
|
|
|
tay
|
|
|
|
|
2024-06-15 22:45:27 -04:00
|
|
|
print: ; we've stored the character position, now let's
|
2024-04-10 17:28:34 -04:00
|
|
|
lda keymap, y
|
|
|
|
ldy cursor
|
|
|
|
sta $6000, y
|
2024-06-15 22:45:27 -04:00
|
|
|
inc cursor
|
2024-04-10 17:28:34 -04:00
|
|
|
ply
|
|
|
|
rts
|
|
|
|
|
|
|
|
keymap:
|
|
|
|
.byte "?outrew?"
|
|
|
|
.byte "?piygsq?"
|
|
|
|
.byte "a??khvd?"
|
|
|
|
.byte "42ljbfz?"
|
|
|
|
.byte "31?mncx?"
|
|
|
|
.byte "????? m"
|
|
|
|
|
|
|
|
draw:
|
2024-06-15 22:45:27 -04:00
|
|
|
; push_coords #0, #0
|
|
|
|
; push_char #$00
|
|
|
|
; jsr draw_char
|
2024-04-10 17:28:34 -04:00
|
|
|
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
|
|
|
|
|
|
|
|
isr: ; interrupt service routine
|
|
|
|
pha
|
|
|
|
phx
|
|
|
|
phy
|
2024-06-15 22:45:27 -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
|