zeropage tweaks

* switched zero-page from hardcoded assignments to symbols
* moved most non-hotpath stuff out to .data
* merged ptr and pixel_ptr

Slight slowdown in Atari800MacX from 5m13s to 5m15s
This commit is contained in:
Brooke Vibber 2026-04-08 19:58:27 -07:00
commit 25c37a1188

View file

@ -1,44 +1,44 @@
; Our zero-page vars
ox = $80 ; fixed6.26: center point x
oy = $84 ; fixed6.26: center point y
cx = $88 ; fixed6.26: c_x
cy = $8c ; fixed6.26: c_y
.zeropage
zx = $90 ; fixed6.26: z_x
zy = $94 ; fixed6.26: z_y
zx_2 = $98 ; fixed6.26: z_x^2
zy_2 = $9c ; fixed6.26: z_y^2
ox: .res 4 ; fixed6.26: center point x
oy: .res 4 ; fixed6.26: center point y
cx: .res 4 ; fixed6.26: c_x
cy: .res 4 ; fixed6.26: c_y
zx_zy = $a0 ; fixed6.26: z_x * z_y
dist = $a4 ; fixed6.26: z_x^2 + z_y^2
sx = $a8 ; i16: screen pixel x
sy = $aa ; i16: screen pixel y
z_buffer_active = $ac ; boolean: 1 if we triggered the lake, 0 if not
z_buffer_start = $ad ; u8: index into z_buffer
z_buffer_end = $ae ; u8: index into z_buffer
iter = $af ; u8: iteration count
zx: .res 4 ; fixed6.26: z_x
zy: .res 4 ; fixed6.26: z_y
zx_2: .res 4 ; fixed6.26: z_x^2
zy_2: .res 4 ; fixed6.26: z_y^2
ptr = $b0 ; u16
pixel_ptr = $b2 ; u16
zoom = $b4 ; u8: zoom shift level
fill_level = $b5 ; u8
pixel_color = $b6 ; u8
pixel_mask = $b7 ; u8
pixel_shift = $b8 ; u8
pixel_offset = $b9 ; u8
palette_offset = $ba ; u8
chroma_offset = $bb ; u8
palette_ticks = $bc ; u8
chroma_ticks = $bd ; u8
count_frames = $be ; u8
; free space $bf
zx_zy: .res 4 ; fixed6.26: z_x * z_y
dist: .res 4 ; fixed6.26: z_x^2 + z_y^2
count_iters = $c0 ; u16
text_col = $c2 ; u8
text_row = $c3 ; u8
; free space c4-cb
temp = $cc ; u16
temp2 = $ce ; u16
z_buffer_active: .res 1 ; boolean: 1 if we triggered the lake, 0 if not
z_buffer_start: .res 1 ; u8: index into z_buffer
z_buffer_end: .res 1 ; u8: index into z_buffer
iter: .res 1 ; u8: iteration count
ptr: .res 2 ; u16
temp: .res 2 ; u16
temp2: .res 2 ; u16
.data
; can move to .data
sx: .res 2 ; i16: screen pixel x
sy: .res 2 ; i16: screen pixel y
zoom: .res 1 ; u8: zoom shift level
fill_level: .res 1 ; u8
pixel_color: .res 1 ; u8
pixel_mask: .res 1 ; u8
pixel_shift: .res 1 ; u8
pixel_offset: .res 1 ; u8
palette_offset: .res 1 ; u8
chroma_offset: .res 1 ; u8
palette_ticks: .res 1 ; u8
chroma_ticks: .res 1 ; u8
count_frames: .res 1 ; u8
count_iters: .res 2 ; u16
text_col: .res 1 ; u8
text_row: .res 1 ; u8
palette_delay = 23
chroma_delay = 137
@ -131,6 +131,8 @@ KEY_E = 42
KEY_X = 22
KEY_Y = 43
.data
.struct float48
exponent .byte
mantissa .byte 5
@ -142,7 +144,6 @@ KEY_Y = 43
.import sqr_lobyte
.import sqr_hibyte
.data
strings:
str_self:
@ -1253,21 +1254,21 @@ enough:
negative:
; temp1 = top half
lda #.lobyte(framebuffer_top + stride * half_height)
sta pixel_ptr
sta ptr
lda #.hibyte(framebuffer_top + stride * half_height)
sta pixel_ptr + 1
sta ptr + 1
jmp point
positive:
lda #.lobyte(framebuffer_bottom)
sta pixel_ptr
sta ptr
lda #.hibyte(framebuffer_bottom)
sta pixel_ptr + 1
sta ptr + 1
point:
; pixel_ptr += sy * stride
; ptr += sy * stride
; temp * 40
; = temp * 32 + temp * 8
; = (temp << 5) + (temp << 3)
@ -1275,10 +1276,10 @@ point:
shl16 temp
shl16 temp
shl16 temp
add16 pixel_ptr, pixel_ptr, temp
add16 ptr, ptr, temp
shl16 temp
shl16 temp
add16 pixel_ptr, pixel_ptr, temp
add16 ptr, ptr, temp
; Ok so temp1 points to the start of the line, which is 40 bytes.
; Get the byte and bit offsets
@ -1318,20 +1319,20 @@ shift_done:
draw_pixel:
; read, mask, or, write
lda (pixel_ptr),y
lda (ptr),y
and pixel_mask
ora pixel_color
sta (pixel_ptr),y
sta (ptr),y
dex
beq done
clc
lda #40
adc pixel_ptr
sta pixel_ptr
adc ptr
sta ptr
lda #0
adc pixel_ptr + 1
sta pixel_ptr + 1
adc ptr + 1
sta ptr + 1
jmp draw_pixel
done: