After successfully setting up the MMC3 and figured out how to use the IRQs, I decided to try something very few NES games attempt and change the palette mid-screen. One of the characteristics of the MMC3 scanline counter is that if the Sprites are loaded from Pattern Table 1 and the backgrounds are loaded from Pattern Table 0, the counter will trigger an IRQ at around pixel 260 of the current scanline. This means that we should be able to change at least one color without any visible graphical glitches.
So I started with a program that displays the following image:
I added an IRQ, which triggers at scanline 120, containing the following code:
I also added the following code in the NMI section to change back to the original color before the next frame starts:
When I ran the program, I ended up with this:
Now, I knew there were going to be problems. And it turns out that writing to $2006 messes with the scroll register. So I changed the IRQ code a bit and wrote to $2005, hoping to move the screen to where it should be:
Unfortunately, this didn't change anything at all. In an online MMC3 guide, I saw that instead of writing to $2005, they wrote to $2006, like so:
This brings the screen down a bit:
I decided to see what would happen if I put in a higher value on the second write to $2006
This brings the screen down more, but not by much:
So, can somebody tell me what is the right way to go about this? How do I fix these problems?
Thanks!
So I started with a program that displays the following image:
I added an IRQ, which triggers at scanline 120, containing the following code:
Code:
COW:
LDA #$00
STA $2001 ;Disable rendering
LDA $2002
LDA #$3F
STA $2006
LDA #$00
STA $2006
LDA #$16
STA $2007 ;Change Main Background color
LDA #%00011110 ;Enable sprites, Enable backgrounds
STA $2001
LDA #$01
STA $E000 ;Disable IRQ
RTI
LDA #$00
STA $2001 ;Disable rendering
LDA $2002
LDA #$3F
STA $2006
LDA #$00
STA $2006
LDA #$16
STA $2007 ;Change Main Background color
LDA #%00011110 ;Enable sprites, Enable backgrounds
STA $2001
LDA #$01
STA $E000 ;Disable IRQ
RTI
I also added the following code in the NMI section to change back to the original color before the next frame starts:
Code:
LDA $2002
LDA #$3F
STA $2006
LDA #$00
STA $2006
LDA #$21
STA $2007
LDA #$3F
STA $2006
LDA #$00
STA $2006
LDA #$21
STA $2007
When I ran the program, I ended up with this:
Now, I knew there were going to be problems. And it turns out that writing to $2006 messes with the scroll register. So I changed the IRQ code a bit and wrote to $2005, hoping to move the screen to where it should be:
Code:
COW:
LDA #$00
STA $2001 ;Disable rendering
LDA $2002
LDA #$3F
STA $2006
LDA #$00
STA $2006
LDA #$16
STA $2007 ;Change Main Background color
LDA #%00011110 ;Enable sprites, Enable backgrounds
STA $2001
LDA #$00
STA $2005
LDA #$78 ;Set Y Scroll position to 120
STA $2005
LDA #$01
STA $E000 ;Disable IRQ
RTI
LDA #$00
STA $2001 ;Disable rendering
LDA $2002
LDA #$3F
STA $2006
LDA #$00
STA $2006
LDA #$16
STA $2007 ;Change Main Background color
LDA #%00011110 ;Enable sprites, Enable backgrounds
STA $2001
LDA #$00
STA $2005
LDA #$78 ;Set Y Scroll position to 120
STA $2005
LDA #$01
STA $E000 ;Disable IRQ
RTI
Unfortunately, this didn't change anything at all. In an online MMC3 guide, I saw that instead of writing to $2005, they wrote to $2006, like so:
Code:
LDA #%00011110 ;Enable sprites, Enable backgrounds
STA $2001
LDA #$00
STA $2006
STA $2006
STA $2001
LDA #$00
STA $2006
STA $2006
This brings the screen down a bit:
I decided to see what would happen if I put in a higher value on the second write to $2006
Code:
LDA #%00011110 ;Enable sprites, Enable backgrounds
STA $2001
LDA #$00
STA $2006
LDA #$78
STA $2006
STA $2001
LDA #$00
STA $2006
LDA #$78
STA $2006
This brings the screen down more, but not by much:
So, can somebody tell me what is the right way to go about this? How do I fix these problems?
Thanks!