From 2e5f91a0dbcd6b4db8972651791e03e83efcaa40 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sun, 22 Jan 2023 08:20:59 -0800 Subject: [PATCH 1/4] wip gfx --- mandel.s | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 109 insertions(+), 1 deletion(-) diff --git a/mandel.s b/mandel.s index 6880e8b..c6d3cf7 100644 --- a/mandel.s +++ b/mandel.s @@ -16,6 +16,7 @@ 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 ; FP registers in zero page FR0 = $d4 @@ -33,7 +34,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 @@ -133,6 +135,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 @@ -228,6 +238,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 +524,89 @@ enough: ; screen coords in signed sx,sy ; iter holds the target to use ; @todo implement + + pixel_ptr = $b0 + pixel_color = $b2 + pixel_mask = $b3 + pixel_shift = $b4 + pixel_offset = $b5 + + ; 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) + extend_8_16 temp, sy + shl16 temp + shl16 temp + shl16 temp + add16 pixel_ptr, temp, temp + shl16 temp + shl16 temp + add16 pixel_ptr, temp, 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 + 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 (temp),y + and pixel_mask + ora pixel_color + sta (temp),y + rts .endproc From a8872b4e661bb95b4c32b413800c68052c235edf Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sun, 22 Jan 2023 08:34:06 -0800 Subject: [PATCH 2/4] hmm --- mandel.s | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/mandel.s b/mandel.s index c6d3cf7..5cf1e9a 100644 --- a/mandel.s +++ b/mandel.s @@ -567,10 +567,10 @@ point: shl16 temp shl16 temp shl16 temp - add16 pixel_ptr, temp, temp + add16 pixel_ptr, pixel_ptr, temp shl16 temp shl16 temp - add16 pixel_ptr, temp, 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 @@ -605,6 +605,7 @@ shift_done: lda (temp),y and pixel_mask ora pixel_color + lda #255 sta (temp),y rts @@ -701,7 +702,9 @@ loop_sy: loop_sx: zoom_factor cx, sx, zoom, aspect_x zoom_factor cy, sy, zoom, aspect_y - jsr mandelbrot + ;jsr mandelbrot + lda #1 + sta iter jsr pset @@ -709,13 +712,13 @@ loop_sx: clc 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: @@ -724,13 +727,13 @@ loop_sx_done: clc 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: From efac8f4f621d11698caa69f2f6ea57aabc106408 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sun, 22 Jan 2023 09:09:12 -0800 Subject: [PATCH 3/4] now writes pixels sorta --- mandel.s | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/mandel.s b/mandel.s index 5cf1e9a..8a963d6 100644 --- a/mandel.s +++ b/mandel.s @@ -18,6 +18,12 @@ 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 FRE = $da @@ -108,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 @@ -185,8 +191,8 @@ color_map: .macro shl bytes, arg asl arg - .repeat bytes-1 - rol arg + .repeat bytes-1, i + rol arg + 1 + i .endrepeat .endmacro @@ -525,12 +531,6 @@ enough: ; iter holds the target to use ; @todo implement - pixel_ptr = $b0 - pixel_color = $b2 - pixel_mask = $b3 - pixel_shift = $b4 - pixel_offset = $b5 - ; iter -> color ldx iter lda color_map,x @@ -563,7 +563,7 @@ point: ; temp * 40 ; = temp * 32 + temp * 8 ; = (temp << 5) + (temp << 3) - extend_8_16 temp, sy + copy16 temp, sy shl16 temp shl16 temp shl16 temp @@ -588,6 +588,9 @@ point: shift_loop: beq shift_done asl pixel_color + asl pixel_color + sec + rol pixel_mask sec rol pixel_mask dex @@ -602,11 +605,10 @@ shift_done: tay ; read, mask, or, write - lda (temp),y + lda (pixel_ptr),y and pixel_mask ora pixel_color - lda #255 - sta (temp),y + sta (pixel_ptr),y rts .endproc @@ -703,13 +705,12 @@ loop_sx: zoom_factor cx, sx, zoom, aspect_x zoom_factor cy, sy, zoom, aspect_y ;jsr mandelbrot - lda #1 + lda #2 sta iter jsr pset - - lda sx clc + lda sx adc #1 sta sx lda sx + 1 @@ -723,8 +724,8 @@ loop_sx: loop_sx_done: - lda sy clc + lda sy adc #1 sta sy lda sy + 1 From d36667938d8a3b11ac9c1cb7ecaf80125a1c19ba Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sun, 22 Jan 2023 09:13:19 -0800 Subject: [PATCH 4/4] run it (fails) --- mandel.s | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mandel.s b/mandel.s index 8a963d6..be1f59e 100644 --- a/mandel.s +++ b/mandel.s @@ -704,9 +704,7 @@ loop_sy: loop_sx: zoom_factor cx, sx, zoom, aspect_x zoom_factor cy, sy, zoom, aspect_y - ;jsr mandelbrot - lda #2 - sta iter + jsr mandelbrot jsr pset clc