Compare commits

..

4 commits

Author SHA1 Message Date
d36667938d run it (fails) 2023-01-22 09:13:19 -08:00
efac8f4f62 now writes pixels sorta 2023-01-22 09:09:12 -08:00
a8872b4e66 hmm 2023-01-22 08:34:06 -08:00
2e5f91a0db wip gfx 2023-01-22 08:20:59 -08:00

142
mandel.s
View file

@ -16,6 +16,13 @@ dist = $9c ; fixed6.26: z_x^2 + z_y^2
iter = $a0 ; u8: iteration count
zoom = $a1 ; u8: zoom shift level
temp = $a2 ; u16
temp2 = $a4 ; u16
pixel_ptr = $b0 ; u16
pixel_color = $b2 ; u8
pixel_mask = $b3 ; u8
pixel_shift = $b4 ; u8
pixel_offset = $b5 ; u8
; FP registers in zero page
FR0 = $d4
@ -33,7 +40,8 @@ framebuffer_end = $a000
height = 184
half_height = height >> 1
width = 160
half_width = 160 >> 1
half_width = width >> 1
stride = width >> 2
width_ratio_3_13 = (5 << 11) ; 5/4
height_ratio_3_13 = (3 << 11) ; 5/4
@ -106,8 +114,8 @@ bit_masks:
.byte 3 << 6
display_list_start:
; 48 lines overscan
.repeat 5
; 24 lines overscan
.repeat 3
.byte $70 ; 8 blank lines
.endrep
@ -133,6 +141,14 @@ display_list_start:
display_list_end:
display_list_len = display_list_end - display_list_start
color_map:
.byte 0
.repeat 85
.byte 1
.byte 2
.byte 3
.endrepeat
.code
.export start
@ -175,8 +191,8 @@ display_list_len = display_list_end - display_list_start
.macro shl bytes, arg
asl arg
.repeat bytes-1
rol arg
.repeat bytes-1, i
rol arg + 1 + i
.endrepeat
.endmacro
@ -228,6 +244,21 @@ display_list_len = display_list_end - display_list_start
neg 4, arg
.endmacro
.macro extend_8_16 dest, src
; clobbers A, X
; 13-15 cycles
.local positive
.local negative
ldx #0 ; 2 cyc
lda src ; 3 cyc
sta dest ; 3 cyc
bpl positive ; 2 cyc
negative:
dex ; 2 cyc
positive:
stx dest + 1 ; 3 cyc
.endmacro
; inner loop for imul16
; bitnum < 8: 25 or 41 cycles
; bitnum >= 8: 30 or 46 cycles
@ -499,6 +530,86 @@ enough:
; screen coords in signed sx,sy
; iter holds the target to use
; @todo implement
; iter -> color
ldx iter
lda color_map,x
sta pixel_color
lda #(255 - 3)
sta pixel_mask
; sy -> line base address in temp
lda sy
bpl positive
negative:
; temp1 = top half
lda #.lobyte(framebuffer_top + stride * half_height)
sta pixel_ptr
lda #.hibyte(framebuffer_top + stride * half_height)
sta pixel_ptr + 1
jmp point
positive:
lda #.lobyte(framebuffer_bottom)
sta pixel_ptr
lda #.hibyte(framebuffer_bottom)
sta pixel_ptr + 1
point:
; pixel_ptr += sy * stride
; temp * 40
; = temp * 32 + temp * 8
; = (temp << 5) + (temp << 3)
copy16 temp, sy
shl16 temp
shl16 temp
shl16 temp
add16 pixel_ptr, pixel_ptr, temp
shl16 temp
shl16 temp
add16 pixel_ptr, pixel_ptr, temp
; Ok so temp1 points to the start of the line, which is 40 bytes.
; Get the byte and bit offsets
lda sx
clc
adc #half_width
sta temp
; pixel_shift = temp & 3
; pixel_color <<= pixel_shift (shifting in zeros)
; pixel_mask <<= pixel_shift (shifting in ones)
and #3
sta pixel_shift
tax
shift_loop:
beq shift_done
asl pixel_color
asl pixel_color
sec
rol pixel_mask
sec
rol pixel_mask
dex
jmp shift_loop
shift_done:
; pixel_offset = temp >> 2
lda temp
lsr a
lsr a
sta pixel_offset
tay
; read, mask, or, write
lda (pixel_ptr),y
and pixel_mask
ora pixel_color
sta (pixel_ptr),y
rts
.endproc
@ -596,33 +707,32 @@ loop_sx:
jsr mandelbrot
jsr pset
lda sx
clc
lda sx
adc #1
sta sx
cmp #half_width
beq loop_sx_done
lda sx + 1
adc #0
sta sx + 1
lda sx
cmp #half_width
beq loop_sx_done
jmp loop_sx
loop_sx_done:
lda sy
clc
lda sy
adc #1
sta sy
cmp #half_height
beq loop_sy_done
lda sy + 1
adc #0
sta sy + 1
lda sy
cmp #half_height
beq loop_sy_done
jmp loop_sy
loop_sy_done: