EDIT: My problem has been solved! Among other things, I was stupid and tried to TYX. Interestingly enough, ASM6 seems to have read that as a label and didn't fail on compile.
Hey all,
I've been working on this for a while, and I've hit a point where I just don't know what to fix.
I'm working on a metatile routine. Metatile is 2x2 tiles, and it seemed to work alright. However, now I'm working on adding attribute mapping based on the metatile, and it's all messed up.
Here's my metatile attribute routine. The idea is that it's supposed to read the metatile number from the game map in "metascr", and then use that index to lookup the palette number (0 - 3) for the corresponding metatile in "METAattr". Right now, all of the metatiles should be with palette 0 except for the blank sky, #$15, which is palette 01. Then I'm shifting bits to the left, and adding the resulting number to the attribute number I have stored. At the end, I'm writing the number to $2007. I think I'm starting at the right address in $2006, just doing what NerdyNights had.
Var attrtemp is used to store my attribute byte, and var attrx is used to store my X counter before I TAX.
When I compile and run, I get something really weird. My loop increments Y twice at the end, and should end when Y==16, so I'm only expecting to apply attributes to the first 8 32x32 attribute squares (if this was working correctly, the first row of 16px metatiles would be palette 0, the second would be palette 1, all subsequent would be palette 0). But it seems that instead, random 32px attribute squares are of only palette 1, all over the screen. To compound this, more and more attribute squares are changed to palette 1 when I reset. Making things weirder still, when I change to PAL mode, I can see that there is a single background tile on the top which is completely incorrect, and this tile changes position when I reset.
I know there are multiple things I must be doing wrong. I know this means I'm not handling my reset correctly, but I don't know enough to fix it. Could someone out there walk me through the changes I need to make to apply this correctly? I realize this is a lot to ask.
Attached is the entire ASM file. It's not too huge, based on the NerdyNights week 6, and in ASM6 symtax.
EDIT: Also attached are the CHR and NES files if you want to test it out.
Hey all,
I've been working on this for a while, and I've hit a point where I just don't know what to fix.
I'm working on a metatile routine. Metatile is 2x2 tiles, and it seemed to work alright. However, now I'm working on adding attribute mapping based on the metatile, and it's all messed up.
Here's my metatile attribute routine. The idea is that it's supposed to read the metatile number from the game map in "metascr", and then use that index to lookup the palette number (0 - 3) for the corresponding metatile in "METAattr". Right now, all of the metatiles should be with palette 0 except for the blank sky, #$15, which is palette 01. Then I'm shifting bits to the left, and adding the resulting number to the attribute number I have stored. At the end, I'm writing the number to $2007. I think I'm starting at the right address in $2006, just doing what NerdyNights had.
Var attrtemp is used to store my attribute byte, and var attrx is used to store my X counter before I TAX.
Code:
LoadMETAattr:
LDA $2002 ;read PPU to reset high/low latch
LDA #$23
STA $2006 ;write hight byte of $23C0 address
LDA #$C0
STA $2006 ;write low byte of $23C0 address
LDX #$00
LDY #$00
LoadMETAattrLoop:
TYX
LDA metascr, x ;load data from metatable
STX attrx
TAX
LDA METAattr, x
STA attrtemp ;load first attr
LDX attrx
INX
LDA metascr, x
STX attrx
TAX
LDA METAattr, x
ASL A
ASL A ;multiply second attr by 4
CLC
ADC attrtemp
STA attrtemp
LDX attrx
DEX
TXA
CLC
ADC #$10
TAX
LDA metascr, x
STX attrx
TAX
LDA METAattr, x
ASL A
ASL A
ASL A
ASL A ;multiply third attr by 16
CLC
ADC attrtemp
STA attrtemp
LDX attrx
INX
LDA metascr, x
STX attrx
TAX
LDA METAattr, x
ASL A
ASL A
ASL A
ASL A
ASL A
ASL A ;multiply fourth attr by 64
CLC
ADC attrtemp
STA attrtemp
STA $2007
INY
INY
CPY #$10
BNE LoadMETAattrLoop
JMP METAattrdone
LDA $2002 ;read PPU to reset high/low latch
LDA #$23
STA $2006 ;write hight byte of $23C0 address
LDA #$C0
STA $2006 ;write low byte of $23C0 address
LDX #$00
LDY #$00
LoadMETAattrLoop:
TYX
LDA metascr, x ;load data from metatable
STX attrx
TAX
LDA METAattr, x
STA attrtemp ;load first attr
LDX attrx
INX
LDA metascr, x
STX attrx
TAX
LDA METAattr, x
ASL A
ASL A ;multiply second attr by 4
CLC
ADC attrtemp
STA attrtemp
LDX attrx
DEX
TXA
CLC
ADC #$10
TAX
LDA metascr, x
STX attrx
TAX
LDA METAattr, x
ASL A
ASL A
ASL A
ASL A ;multiply third attr by 16
CLC
ADC attrtemp
STA attrtemp
LDX attrx
INX
LDA metascr, x
STX attrx
TAX
LDA METAattr, x
ASL A
ASL A
ASL A
ASL A
ASL A
ASL A ;multiply fourth attr by 64
CLC
ADC attrtemp
STA attrtemp
STA $2007
INY
INY
CPY #$10
BNE LoadMETAattrLoop
JMP METAattrdone
When I compile and run, I get something really weird. My loop increments Y twice at the end, and should end when Y==16, so I'm only expecting to apply attributes to the first 8 32x32 attribute squares (if this was working correctly, the first row of 16px metatiles would be palette 0, the second would be palette 1, all subsequent would be palette 0). But it seems that instead, random 32px attribute squares are of only palette 1, all over the screen. To compound this, more and more attribute squares are changed to palette 1 when I reset. Making things weirder still, when I change to PAL mode, I can see that there is a single background tile on the top which is completely incorrect, and this tile changes position when I reset.
I know there are multiple things I must be doing wrong. I know this means I'm not handling my reset correctly, but I don't know enough to fix it. Could someone out there walk me through the changes I need to make to apply this correctly? I realize this is a lot to ask.
Attached is the entire ASM file. It's not too huge, based on the NerdyNights week 6, and in ASM6 symtax.
EDIT: Also attached are the CHR and NES files if you want to test it out.