git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

commit 4609d285538b3a64b37ee5a34fea0a1ad012f798
parent ce6010908f34b2c0e90ef038a110259e19759e7c
Author: Toxa <56631470+untoxa@users.noreply.github.com>
Date:   Fri,  9 Sep 2022 18:13:06 +0300

Merge pull request #409 from michel-iwaniec/nes_indirect_vram_fixes

NES: Support setting tile data indirectly via vram transfer buffer when display is on
Diffstat:
Mgbdk-lib/libc/targets/mos6502/nes/crt0.s13+++++++------
Mgbdk-lib/libc/targets/mos6502/nes/fill_rect_bk.s50++++++++++++++++++++++++++++++++++++++++++++++----
Mgbdk-lib/libc/targets/mos6502/nes/set_data.s100+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 153 insertions(+), 10 deletions(-)

diff --git a/gbdk-lib/libc/targets/mos6502/nes/crt0.s b/gbdk-lib/libc/targets/mos6502/nes/crt0.s @@ -80,7 +80,7 @@ __crt0_NMI_insideNMI: .ds 1 __crt0_ScrollHV: .ds 1 __crt0_drawListValid: .ds 1 __crt0_drawListNumDelayCycles_x8: .ds 1 -__crt0_drawListPosW: .ds 1 +__crt0_drawListPosW:: .ds 1 __crt0_textPPUAddr: .ds 2 __crt0_NMITEMP: .ds 4 __crt0_textTemp: .ds 1 @@ -90,7 +90,7 @@ _bkg_scroll_x:: .ds 1 _bkg_scroll_y:: .ds 1 _attribute_row_dirty:: .ds 1 .crt0_textStringBegin: .ds 1 -.crt0_forced_blanking: .ds 1 +.crt0_forced_blanking:: .ds 1 ;; **************************************** @@ -696,9 +696,9 @@ _display_on:: clc adc #VRAM_HDR_SIZEOF sta *__crt0_drawListPosW - ; __crt0_drawListNumDelayCycles_x8 -= 7 (assumes carry clear) + ; __crt0_drawListNumDelayCycles_x8 -= 6 (assumes carry clear) lda *__crt0_drawListNumDelayCycles_x8 - sbc #6 + sbc #5 sta *__crt0_drawListNumDelayCycles_x8 ldy *__crt0_textTemp rts @@ -721,10 +721,12 @@ _display_on:: tya sec sbc *.crt0_textStringBegin - sec sbc #VRAM_HDR_SIZEOF ldy *.crt0_textStringBegin sta _vram_transfer_buffer+VRAM_HDR_LENGTH,y + lda *__crt0_drawListNumDelayCycles_x8 + sbc _vram_transfer_buffer+VRAM_HDR_LENGTH,y + sta *__crt0_drawListNumDelayCycles_x8 VRAM_BUFFER_UNLOCK ldy *__crt0_textTemp rts @@ -742,7 +744,6 @@ _display_on:: ldy *__crt0_drawListPosW sta _vram_transfer_buffer,y inc *__crt0_drawListPosW - dec *__crt0_drawListNumDelayCycles_x8 ldy *__crt0_textTemp rts diff --git a/gbdk-lib/libc/targets/mos6502/nes/fill_rect_bk.s b/gbdk-lib/libc/targets/mos6502/nes/fill_rect_bk.s @@ -17,6 +17,11 @@ _fill_bkg_rect:: sta *.xpos stx *.ypos ldy *.height + ; Prefer vertical stripes if height > width + cpy *.width + beq _fill_bkg_rect_horizontalStripes + bcs _fill_bkg_rect_verticalStripes +_fill_bkg_rect_horizontalStripes: 1$: lda #0 sta *.tmp+1 @@ -36,16 +41,53 @@ _fill_bkg_rect:: ; lda *.tmp+1 ora #0x20 - sta PPUADDR + tax lda *.tmp - sta PPUADDR + jsr .ppu_stripe_begin_horizontal ldx *.width - lda *.tile 2$: - sta PPUDATA + lda *.tile + jsr .ppu_stripe_write_byte dex bne 2$ + jsr .ppu_stripe_end inc *.ypos dey bne 1$ rts + +_fill_bkg_rect_verticalStripes: + ldy *.width +1$: + lda #0 + sta *.tmp+1 + lda *.ypos + asl + rol *.tmp+1 + asl + rol *.tmp+1 + asl + rol *.tmp+1 + asl + rol *.tmp+1 + asl + rol *.tmp+1 + ora *.xpos + sta *.tmp + ; + lda *.tmp+1 + ora #0x20 + tax + lda *.tmp + jsr .ppu_stripe_begin_vertical + ldx *.height +2$: + lda *.tile + jsr .ppu_stripe_write_byte + dex + bne 2$ + jsr .ppu_stripe_end + inc *.xpos + dey + bne 1$ + rts diff --git a/gbdk-lib/libc/targets/mos6502/nes/set_data.s b/gbdk-lib/libc/targets/mos6502/nes/set_data.s @@ -6,6 +6,7 @@ _set_tile_data_PARM_3:: .ds 2 _set_tile_data_PARM_4:: .ds 1 src: .ds 2 + tmpX: .ds 1 .area _HOME @@ -62,6 +63,9 @@ _set_sprite_data:: rol asl *.tmp rol + bit *.crt0_forced_blanking + bpl .copy_tiles_indirect + ; Direct write sta PPUADDR lda *.tmp sta PPUADDR @@ -84,6 +88,43 @@ _set_sprite_data:: bne .copy_tiles_loop rts +.copy_tiles_indirect: + sta *.tmp+1 +.copy_tiles_indirect_loop: + stx *tmpX + ; + ldx *.tmp+1 + lda *.tmp + jsr .ppu_stripe_begin_horizontal + ; + ldx *__crt0_drawListPosW + ldy #0 + jsr .copy_tiles_indirect_2planes + lda .identity+16,x + sta *__crt0_drawListPosW + jsr .ppu_stripe_end + ; src += 16 + lda *src + clc + adc #16 + sta *src + lda *src+1 + adc #0 + sta *src+1 + ; tmp += 16 + lda *.tmp + clc + adc #16 + sta *.tmp + lda *.tmp+1 + adc #0 + sta *.tmp+1 + ; + ldx *tmpX + dex + bne .copy_tiles_indirect_loop + rts + .copy_tiles_1plane: lda [*src],y iny @@ -126,3 +167,62 @@ _set_sprite_data:: sta PPUDATA ; rts + +.copy_tiles_indirect_2planes: + lda [*src],y + iny + sta _vram_transfer_buffer+0,x + lda [*src],y + iny + sta _vram_transfer_buffer+8,x + ; + lda [*src],y + iny + sta _vram_transfer_buffer+1,x + lda [*src],y + iny + sta _vram_transfer_buffer+9,x + ; + lda [*src],y + iny + sta _vram_transfer_buffer+2,x + lda [*src],y + iny + sta _vram_transfer_buffer+10,x + ; + lda [*src],y + iny + sta _vram_transfer_buffer+3,x + lda [*src],y + iny + sta _vram_transfer_buffer+11,x + ; + lda [*src],y + iny + sta _vram_transfer_buffer+4,x + lda [*src],y + iny + sta _vram_transfer_buffer+12,x + ; + lda [*src],y + iny + sta _vram_transfer_buffer+5,x + lda [*src],y + iny + sta _vram_transfer_buffer+13,x + ; + lda [*src],y + iny + sta _vram_transfer_buffer+6,x + lda [*src],y + iny + sta _vram_transfer_buffer+14,x + ; + lda [*src],y + iny + sta _vram_transfer_buffer+7,x + lda [*src],y + iny + sta _vram_transfer_buffer+15,x + ; + rts

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.