fix range checks

This commit is contained in:
Brooke Vibber 2023-01-22 13:56:19 -08:00
parent 0afed893a6
commit 7009e16235

View file

@ -434,15 +434,15 @@ loop:
rts rts
keep_going: keep_going:
.macro quick_exit arg .macro quick_exit arg, max
.local keep_going .local keep_going
.local keep_going2 .local keep_going2
lda arg + 1 lda arg + 1
cmp #(4 << 4) cmp #((max) << 4)
bmi keep_going bmi keep_going
rts rts
keep_going: keep_going:
cmp #(256 - (4 << 4)) cmp #(256 - ((max) << 4))
bpl keep_going2 bpl keep_going2
rts rts
keep_going2: keep_going2:
@ -452,28 +452,25 @@ keep_going:
; zx = zx_2 - zy_2 + cx ; zx = zx_2 - zy_2 + cx
sub16 zx, zx_2, zy_2 sub16 zx, zx_2, zy_2
add16 zx, zx, cx add16 zx, zx, cx
quick_exit zx quick_exit zx, 2
; zy = zx_zy + zx_zy + cy ; zy = zx_zy + zx_zy + cy
add16 zy, zx_zy, zx_zy add16 zy, zx_zy, zx_zy
add16 zy, zy, cy add16 zy, zy, cy
quick_exit zy quick_exit zy, 2
; zx_2 = zx * zx ; zx_2 = zx * zx
imul16_round zx_2, zx, zx, 4 imul16_round zx_2, zx, zx, 4
quick_exit zx_2
; zy_2 = zy * zy ; zy_2 = zy * zy
imul16_round zy_2, zy, zy, 4 imul16_round zy_2, zy, zy, 4
quick_exit zy_2
; zx_zy = zx * zy ; zx_zy = zx * zy
imul16_round zx_zy, zx, zy, 4 imul16_round zx_zy, zx, zy, 4
quick_exit zx_zy
; dist = zx_2 + zy_2 ; dist = zx_2 + zy_2
add16 dist, zx_2, zy_2 add16 dist, zx_2, zy_2
quick_exit dist quick_exit dist, 4
; if may be in the lake, look for looping output with a small buffer ; if may be in the lake, look for looping output with a small buffer
; as an optimization vs running to max iters ; as an optimization vs running to max iters