From ce7e051504f7a83ef6d8ce8ecfa174a9f26690a6 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sat, 26 Nov 2022 08:48:01 -0800 Subject: [PATCH] WORKS --- dither-image.js | 10 +++--- dither4.s | 89 +++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 81 insertions(+), 18 deletions(-) diff --git a/dither-image.js b/dither-image.js index 040ed5e..88bbcbb 100644 --- a/dither-image.js +++ b/dither-image.js @@ -663,7 +663,7 @@ function genAssembly(width, height, nbits, lines) { let palette1 = new Uint8Array(height); let palette2 = new Uint8Array(height); let palette3 = new Uint8Array(height); - let framebuffer = new Uint8Array(stride * height); + let bitmap = new Uint8Array(stride * height); for (let y = 0; y < height; y++) { palette1[y] = lines[y].palette[1]; palette2[y] = lines[y].palette[2]; @@ -672,7 +672,7 @@ function genAssembly(width, height, nbits, lines) { width, nbits, lines[y].output, - framebuffer.subarray(y * stride, (y + 1) * stride) + bitmap.subarray(y * stride, (y + 1) * stride) ); } @@ -680,7 +680,7 @@ function genAssembly(width, height, nbits, lines) { .export palette1 .export palette2 .export palette3 -.export framebuffer +.export bitmap palette1: ${byte2byte(palette1)} @@ -691,8 +691,8 @@ ${byte2byte(palette2)} palette3: ${byte2byte(palette3)} -framebuffer: -${byte2byte(framebuffer)} +bitmap: +${byte2byte(bitmap)} `; } diff --git a/dither4.s b/dither4.s index 58f4d41..ac8f2eb 100644 --- a/dither4.s +++ b/dither4.s @@ -12,29 +12,41 @@ WSYNC = $D40A VCOUNT = $D40B NMIEN = $D40E +framebuffer = $a000 +framebuffer2 = $b000 + +temp1l = $80 +temp1h = $81 +temp1 = temp1l +temp2l = $82 +temp2h = $83 +temp2 = temp2l + +height = 192 +bytes_per_line = 40 +pages_per_frame = 32 + .data .import palette1 .import palette2 .import palette3 -.import framebuffer +.import bitmap displaylist: ; @fixme resolve the line counts .repeat 3 .byte $70 ; 8 blank lines .endrep - ; Note the framebuffer cannot cross a 4KiB boundary - ; so this is split in half ; ANTIC mode e (160px 2bpp, 1 scan line per line) .byte $4e .addr framebuffer - .repeat 95 + .repeat height / 2 - 1 .byte $0e .endrep .byte $4e - .addr framebuffer + 96*40 - .repeat 95 + .addr framebuffer2 + .repeat height / 2 - 1 .byte $0e .endrep .byte $41 ; jump and blank @@ -46,19 +58,35 @@ displaylist: .export start .proc start + ; Copy the bitmap into our framebuffer + lda #.lobyte(bitmap) + sta temp1l + lda #.hibyte(bitmap) + sta temp1h + lda #.lobyte(framebuffer) + sta temp2h + lda #.hibyte(framebuffer) + sta temp2h + jsr copy_half_frame + + ; Second half of bitmap has to be separately aligned + lda #.lobyte(framebuffer2) + sta temp2h + lda #.hibyte(framebuffer2) + sta temp2h + jsr copy_half_frame + + ; Disable display DMA lda #$00 sta SDMCTL + ; Set up the display list lda #.lobyte(displaylist) sta SDLSTL lda #.hibyte(displaylist) sta SDLSTH - ; Turn off interrupts except reset button - ;lda #$20 - ;sta NMIEN - ; Manually wait for first scan line wait_vblank: lda VCOUNT @@ -97,14 +125,49 @@ each_scanline: pla tay iny - cpy #192 + cpy height bne each_scanline jmp wait_start .endproc -; Loop through scan lines updating the palette -.proc update_palette +; temp1 contains source address +; temp2 contains dest address +; clobbers a/x/y +; incremepts temp1 and temp2 to the end of their regions +.proc copy_half_frame + ldx #0 + +copy_loop_lines: + ldy #00 + +copy_loop_bytes: + lda (temp1),y + sta (temp2),y + iny + cpy #bytes_per_line + bne copy_loop_bytes + + clc + lda temp1l + adc #bytes_per_line + sta temp1l + lda temp1h + adc #00 + sta temp1h + + clc + lda temp2l + adc #bytes_per_line + sta temp2l + lda temp2h + adc #00 + sta temp2h + + inx + cpx #(height / 2) + bne copy_loop_lines + rts .endproc