So, I have done the Hello Mario tutorial, and also with forum resources here I have written a simple BG tile loop for filling the screen with tiles. I have ironed out my own Joypad routines (ca65 requires that if you have to work with ZP variables to AND or ADD/SUB, they have to have the # for immediate value; weird but I see why now - I hope I didn't forget in the code I am about to show). I have even learned how to use the NMI to make counters using BG tiles! I LOVE this system! It's simple and is fun to bend the thing to my will.
Speaking of bending the thing to my will, THIS stubborn ol' thing tho; this is meant to fill a screen with metatiles of 16x16 using a map and a metatable. This is in its very early stages, for I am afraid if I add too much, I will stop programming altogether. That would be sad, seeing I got this far already even with bits and pieces of Nerdy Nights.
Code: Select all
;background CHR initialization <--
;
;includes anything to be plastered onto the BG
LDA #$20
STA PPU_AddrHi
STA PPU_AddrLo_2
SEC
SBC #$10
STA myRAM0
SEC
SBC #$10
STA PPU_AddrLo
TAX
bgSTART: ;Okay, this part works by itself, but...
LDA metaMapData, X
ASL
ASL
STA metaIndex ;takes map data for metatiles, and * 4 it
TAY
LDA PPU_StatReset ;writes metatiles upper left to lower right
LDA PPU_AddrHi ;works GREAT with Y increment!
STA PPU_Addr16
LDA PPU_AddrLo
STA PPU_Addr16
INC PPU_AddrLo
LDA metaTileData, Y
STA PPU_Data
INY
LDA PPU_StatReset
LDA PPU_AddrHi
STA PPU_Addr16
LDA PPU_AddrLo
STA PPU_Addr16
LDA metaTileData, Y
STA PPU_Data
INY
LDA PPU_StatReset
LDA PPU_AddrHi
STA PPU_Addr16
LDA PPU_AddrLo_2
STA PPU_Addr16
INC PPU_AddrLo_2
LDA metaTileData, Y
STA PPU_Data
INY
LDA PPU_StatReset
LDA PPU_AddrHi
STA PPU_Addr16
LDA PPU_AddrLo_2
STA PPU_Addr16
LDA metaTileData, Y
STA PPU_Data
INX ;next tile in map data
INC PPU_AddrLo
INC PPU_AddrLo_2
CPX myRAM0 ;whatever value is here.
BEQ bgNL ;will go to next line increment...
JMP bgSTART ;unless inequality occurs, then loops.
bgNL:
LDA myRAM0 ;<-- From here, NOTHING works as intended.
CLC ;The number at myRAM0 is supposed to be updated and
ADC #$10 ;tossed back into the above subroutine.
STA myRAM0 ;This way, it starts from a bookmark, writing next line.
;LDA PPU_AddrLo ;This comparative statement doesn't work, either.
;CMP #$e0
;BEQ PPUHi_INC
LDA PPU_AddrLo ;Here, I am trying to bring this low address to 32
CLC ;ahead by adding a value to it.
ADC #$21
STA PPU_AddrLo
LDA PPU_AddrLo_2 ;Same like above.
CLC
ADC #$21
STA PPU_AddrLo_2
JMP bgSTART
PPUHi_INC:
LDA PPU_AddrHi ;Here, I want to bring the high byte up,
INC PPU_AddrHi ;and when it hits a threshold, it doesn't have to
STA PPU_AddrHi ;change anymore.
CMP #$24
BEQ bgDONE
JMP bgNL
bgDONE:
I am still green in the horn here, as some might be able to tell clearer than others. Please be gentle...
