keyboard nav sorta working

This commit is contained in:
Brooke Vibber 2023-03-11 20:45:32 -08:00
parent b1c26c1edd
commit 3d792603db

126
mandel.s
View file

@ -87,9 +87,13 @@ SYSVBV = $E45F
XITVBV = $E462
SETVBV = $E45C
; Keys
KEY_RIGHT = $07
; Keycodes!
KEY_PLUS = $06
KEY_MINUS = $0e
KEY_UP = $8e
KEY_DOWN = $8f
KEY_LEFT = $86
KEY_RIGHT = $87
.struct float48
exponent .byte
@ -643,12 +647,12 @@ next:
.endproc
.macro zoom_factor dest, src, zoom, aspect
.macro scale_zoom dest
; clobbers X, flags
.local cont
.local enough
; cx = (sx << (8 - zoom))
copy16 dest, src
ldx zoom
cont:
cpx #8
@ -657,6 +661,12 @@ cont:
inx
jmp cont
enough:
.endmacro
.macro zoom_factor dest, src, zoom, aspect
; clobbers A, X, flags, etc
copy16 dest, src
scale_zoom dest
; cy = cy * (3 / 4)
; cx = cx * (5 / 4)
@ -803,6 +813,74 @@ done:
; draw text
.endproc
.proc keycheck
; clobbers all
; returns 255 in A if state change or 0 if no change
; check keyboard buffer
lda CH
cmp #$ff
beq skip_char
; Clear the keyboard buffer and re-enable interrupts
ldx #$ff
stx CH
tay
lda zoom
cpy #KEY_PLUS
beq plus
cpy #KEY_MINUS
beq minus
; temp = $0010 << (8 - zoom)
lda #$10
sta temp
lda #$00
sta temp + 1
scale_zoom temp
cpy #KEY_UP
beq up
cpy #KEY_DOWN
beq down
cpy #KEY_LEFT
beq left
cpy #KEY_RIGHT
beq right
skip_char:
lda #0
rts
plus:
cmp #8
bpl skip_char
inc zoom
jmp done
minus:
cmp #1
bmi skip_char
dec zoom
jmp done
up:
sub16 oy, oy, temp
jmp done
down:
add16 oy, oy, temp
jmp done
left:
sub16 ox, ox, temp
jmp done
right:
add16 ox, ox, temp
done:
lda #255
rts
.endproc
.proc start
; ox = 0; oy = 0; zoom = 0
@ -896,38 +974,17 @@ loop_sy:
loop_sx:
zoom_factor cx, sx, zoom, aspect_x
add16 cx, cx, ox
zoom_factor cy, sy, zoom, aspect_y
add16 cy, cy, oy
jsr mandelbrot
jsr pset
; check keyboard buffer
lda CH
cmp #$ff
beq skip_char
; Clear the keyboard buffer and re-enable interrupts
ldx #$ff
stx CH
tax
lsr a
lsr a
lsr a
lsr a
tay
lda hex_chars,y
sta temp
txa
and #$0f
tay
lda hex_chars,y
sta temp + 1
draw_text 14, 2, temp
skip_char:
jsr keycheck
beq no_key
jmp main_loop
no_key:
; check if we should update the counters
;
; count_pixels >= width? update!
@ -1039,5 +1096,8 @@ loop_sy_done:
loop:
; finished
jmp loop
jsr keycheck
beq loop
jmp main_loop
.endproc