To JoeGTake2:
I don't see anything directly wrong with your code logic (aside from the missing quadrant selection, of course), but I will ask why the addr variable in your example appears to be big endian, and the attributeToChangeAddress is little endian? Is that intentional? Also it doesn't match the name attributeAddressToChange used later; i'm assuming they're supposed to be the same variable?
What specifically was wrong with your code when you tested it? Did it appear to do nothing? Did you put a breakpoint on that $2007 write to see what was going through?
Updating attributes already in the attribute table
Moderator: Moderators
- rainwarrior
- Posts: 8734
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: Updating attributes already in the attribute table
OMG, addr+1 is the small byte in your code? Now it makes sense to me. Ok.
nesdoug.com -- blog/tutorial on programming for the NES
Re: Updating attributes already in the attribute table
Here's a mixture of the original code and mine...
NOTE:addr is the low byte, addr+1 is the high byte
Also NOTE: new_bits = 0-3 = the palette of a given 16x16 block (for anyone out there who doesn't know).
Tested. It works.
NOTE:addr is the low byte, addr+1 is the high byte
Also NOTE: new_bits = 0-3 = the palette of a given 16x16 block (for anyone out there who doesn't know).
Code: Select all
LDA addr
LSR
LSR
CMP #$20
AND #%00000111
STA temp
LDA addr+1
ROL
ASL
ASL
ASL
ORA #$C0
ORA temp
STA attrib_addr
LDA addr+1
ORA #$03
STA attrib_addr+1
Bit $2002
Lda attrib_addr+1
Sta $2006
Lda attrib_addr
Sta $2006
Lda $2007 ;junk
Lda $2007 ;data
Sta temp
Lda addr
And #$40 ;top or bottom?
BNE BOTTOM
TOP:
Lda addr
And #02
BNE TOP_R
TOP_L:
Lda temp ;our data
And #$fc ; mask out bits
ora new_bits ;in right 2 bit position
Sta temp
Jmp END
TOP_R:
Lda temp ;our data
And #$f3 ; mask out bits
Sta temp
Lda new_bits ;in right 2 bit position
Asl a
Asl a
Ora temp
Sta temp
Jmp END
BOTTOM:
Lda addr
And #02
BNE BOT_R
BOT_L:
Lda temp ;our data
And #$cf ; mask out bits
Sta temp
Lda new_bits ;in right 2 bit position
Asl a
Asl a
Asl a
Asl a
Ora temp
Sta temp
Jmp END
BOT_R:
Lda temp ;our data
And #$3f ; mask out bits
Sta temp
Lda new_bits ;in right 2 bit position
lsr a
Ror a
Ror a
Ora temp
Sta temp
END: ;put new data in attrib table
Lda attrib_addr+1
Sta $2006
Lda attrib_addr
Sta $2006
Lda temp
Sta $2007
nesdoug.com -- blog/tutorial on programming for the NES
Re: Updating attributes already in the attribute table
Thanks so much for all the help and explanation. This is *close* to working.
It seemed to give a false positive. For instance, I directly loaded 20 84 respectively into the addr bytes and ran the routine. It worked exactly as expected. But then dropped 20 - 86 into the bytes, and got the same output as 20 84...anomalous, for sure.
For kicks, I tried 21 84, that also worked. As did 21 44. And 20 c4. But in some instances, changing the input value had similar anomalous effects.
After much playing to see what direct values i got to work and which ones didn't, it seems the bottom rows behave as expected, but the top rows do not. I'm playing with it a bit, but that said...anything stick out?
It seemed to give a false positive. For instance, I directly loaded 20 84 respectively into the addr bytes and ran the routine. It worked exactly as expected. But then dropped 20 - 86 into the bytes, and got the same output as 20 84...anomalous, for sure.
For kicks, I tried 21 84, that also worked. As did 21 44. And 20 c4. But in some instances, changing the input value had similar anomalous effects.
After much playing to see what direct values i got to work and which ones didn't, it seems the bottom rows behave as expected, but the top rows do not. I'm playing with it a bit, but that said...anything stick out?
Re: Updating attributes already in the attribute table
It worked for me.
You'll need to either post the code or the ROM, or perhaps step through the code in a debugger.
You'll need to either post the code or the ROM, or perhaps step through the code in a debugger.
nesdoug.com -- blog/tutorial on programming for the NES
Re: Updating attributes already in the attribute table
Sorry - I debugged. It absolutely works. corrupted variable on my end...fixed and now flawless.
You guys rock. Glad to know I wasn't *too* far off. Can't thank you guys enough for your constant feedback!
You guys rock. Glad to know I wasn't *too* far off. Can't thank you guys enough for your constant feedback!
Re: Updating attributes already in the attribute table
I have a problem with the reverse of the code - that is, I would like to save the value of the block's palette from the given PPU address.
So in general, I'd like to reverse the operation of existing code.
EDIT: ok i think it works (demo.nes - button A place new block palette, button B copies the existing block palette)
So in general, I'd like to reverse the operation of existing code.
EDIT: ok i think it works (demo.nes - button A place new block palette, button B copies the existing block palette)
Code: Select all
LDA PPU_BLOCK_AddrLO
LSR A
LSR A
CMP #$20
AND #%00000111
STA temp
LDA PPU_BLOCK_AddrHI
ROL A
ASL A
ASL A
ASL A
ORA #$C0
ORA temp
STA PPU_ATTR_AddrLO
LDA PPU_BLOCK_AddrHI
ORA #$03
STA PPU_ATTR_AddrHI
BIT $2002
LDA PPU_ATTR_AddrHI
STA $2006
LDA PPU_ATTR_AddrLO
STA $2006
LDA $2007 ;junk
LDA $2007 ;data
STA temp
LDA PPU_BLOCK_AddrLO
AND #$40 ;up or down?
BNE BOTTOM
TOP:
LDA PPU_BLOCK_AddrLO
AND #02
BNE TOP_R
TOP_L:
; LDA temp ;our data
; AND #$fc ;mask out bits
; ORA palette ;in right 2 bit position
; STA temp
;copy temp bits0,1 (000000xx) to palette bit0,1
lda temp
and #%00000011
sta palette
JMP END
TOP_R:
; LDA temp ;our data
; AND #$f3 ;mask out bits
; STA temp
; LDA palette ;in right 2 bit position
; ASL A
; ASL A
; ORA temp
; STA temp
;copy temp bits2,3 (0000xx00) to palette bit0,1
lsr temp
lsr temp
lda temp
and #%00000011
sta palette
JMP END
BOTTOM:
LDA PPU_BLOCK_AddrLO
AND #$02
BNE BOT_R
BOT_L:
; LDA temp ;our data
; AND #$cf ;mask out bits
; STA temp
; LDA palette ;in right 2 bit position
; ASL A
; ASL A
; ASL A
; ASL A
; ORA temp
; STA temp
;copy temp bits4,5 (00xx0000) to palette bit0,1
lsr temp
lsr temp
lsr temp
lsr temp
lda temp
and #%00000011
sta palette
JMP END
BOT_R:
; LDA temp ;our data
; AND #$3f ;mask out bits
; STA temp
; LDA palette ;in right 2 bit position
; LSR A
; ROR A
; ROR A
; ORA temp
; STA temp
;copy temp bits6,7 (xx000000) to palette bit0,1
lsr temp
lsr temp
lsr temp
lsr temp
lsr temp
lsr temp
lda temp
and #%00000011
sta palette
END: ;put new data in attrib table (not used)
; LDA PPU_ATTR_AddrHI
; STA $2006
; LDA PPU_ATTR_AddrLO
; STA $2006
; LDA temp
; STA $2007
- Attachments
-
- demo.nes
- (128.02 KiB) Downloaded 121 times