Hey, this is our first post on these forums. We have been working on making a NES game with NESASM. What do you think of our VRAM buffer code?
The format is;
For RAM it uses 2 general purpose pointer bytes and 3 incremental bytes in zero page and 36 bytes in RAM
And then we have the following code in NMI;
The format is;
Code:
----------------------------------
Bytes Purpose
----------------------------------
0 Length of data
1-2 PPU write address
3 Mode flag
0 - Location
1 - RLE
4 RLE byte
4-6 Data read address
Bytes Purpose
----------------------------------
0 Length of data
1-2 PPU write address
3 Mode flag
0 - Location
1 - RLE
4 RLE byte
4-6 Data read address
For RAM it uses 2 general purpose pointer bytes and 3 incremental bytes in zero page and 36 bytes in RAM
Code:
.zp
.org $0000
PointerLo .ds 1 ;general purpose address pointer variables
PointerHi .ds 1 ;low byte first, high byte immediately after
GfxBufferPtr .ds 1 ;pointer for GfxBuffer
GfxBufferLen .ds 1 ;length of bytes to write
FlushGfxBuffer .ds 1 ;should the buffer be flushed
.bss
.org $0400
GfxBuffer .ds 36 ;36 byte buffer
.org $0000
PointerLo .ds 1 ;general purpose address pointer variables
PointerHi .ds 1 ;low byte first, high byte immediately after
GfxBufferPtr .ds 1 ;pointer for GfxBuffer
GfxBufferLen .ds 1 ;length of bytes to write
FlushGfxBuffer .ds 1 ;should the buffer be flushed
.bss
.org $0400
GfxBuffer .ds 36 ;36 byte buffer
And then we have the following code in NMI;
Code:
.code
.bank 0
.org $8000
NMI: ;it all happens in NMI, using all in NMI for code
LDX #$00 ;start at the begining
Draw_Gfx_Buffer:
LDA GfxBuffer, x ;load length byte from buffer
BEQ .done ;we are done if the length is $00
STA <GfxBufferLen ;store length
LDA PPU_STATUS ;read PPU status to reset the high/low latch
INX ;incriment pointer
LDA GfxBuffer, x
STA PPU_ADDRESS ;write the high byte of the write address
INX ;incriment pointer
LDA GfxBuffer, x
STA PPU_ADDRESS ;write the low byte of the write address
INX
LDA GfxBuffer, x ;load flags byte from buffer
CMP #ModeLocation ;are we in location mode?
BEQ .modeLocation
CMP #ModeRLE ;are we in RLE mode?
BEQ .modeRLE
.modeLocation:
INX
LDA GfxBuffer, x
STA <PointerHi ;write high byte of the read address
INX
LDA GfxBuffer, x
STA <PointerLo ;write low byte of the read address
INX ;incriment pointer
LDY #$00 ;start at 0
.loop:
LDA [PointerLo], y ;load data from address
STA PPU_DATA ;write to PPU
INY ;incriment counter
CPY <GfxBufferLen ;Compare X to buffer length
BNE .loop ;Branch if compare was Not Equal to zero
LDA #True
STA <FlushGfxBuffer ;we will need to flush the buffer
JMP Draw_Gfx_Buffer
.modeRLE:
INX ;incriment pointer
;crap for RLE goes here
LDA #True
STA <FlushGfxBuffer ;we will need to flush the buffer
JMP Draw_Gfx_Buffer
.done:
Flush_Gfx_Buffer:
LDA <FlushGfxBuffer ;if FlushGrxBuffer
BEQ .done ;equals 0, false then we are done
LDA #$00 ;fill with 0's
LDY #$00 ;start at 0
.loop:
STA GfxBuffer, y
INY
CPY #36
BNE .loop
STA GfxBufferPtr ;and clear the buffer pointer
.done:
.bank 0
.org $8000
NMI: ;it all happens in NMI, using all in NMI for code
LDX #$00 ;start at the begining
Draw_Gfx_Buffer:
LDA GfxBuffer, x ;load length byte from buffer
BEQ .done ;we are done if the length is $00
STA <GfxBufferLen ;store length
LDA PPU_STATUS ;read PPU status to reset the high/low latch
INX ;incriment pointer
LDA GfxBuffer, x
STA PPU_ADDRESS ;write the high byte of the write address
INX ;incriment pointer
LDA GfxBuffer, x
STA PPU_ADDRESS ;write the low byte of the write address
INX
LDA GfxBuffer, x ;load flags byte from buffer
CMP #ModeLocation ;are we in location mode?
BEQ .modeLocation
CMP #ModeRLE ;are we in RLE mode?
BEQ .modeRLE
.modeLocation:
INX
LDA GfxBuffer, x
STA <PointerHi ;write high byte of the read address
INX
LDA GfxBuffer, x
STA <PointerLo ;write low byte of the read address
INX ;incriment pointer
LDY #$00 ;start at 0
.loop:
LDA [PointerLo], y ;load data from address
STA PPU_DATA ;write to PPU
INY ;incriment counter
CPY <GfxBufferLen ;Compare X to buffer length
BNE .loop ;Branch if compare was Not Equal to zero
LDA #True
STA <FlushGfxBuffer ;we will need to flush the buffer
JMP Draw_Gfx_Buffer
.modeRLE:
INX ;incriment pointer
;crap for RLE goes here
LDA #True
STA <FlushGfxBuffer ;we will need to flush the buffer
JMP Draw_Gfx_Buffer
.done:
Flush_Gfx_Buffer:
LDA <FlushGfxBuffer ;if FlushGrxBuffer
BEQ .done ;equals 0, false then we are done
LDA #$00 ;fill with 0's
LDY #$00 ;start at 0
.loop:
STA GfxBuffer, y
INY
CPY #36
BNE .loop
STA GfxBufferPtr ;and clear the buffer pointer
.done: