out of range error in MMC1 prg switching code...

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
vishu_supreme
Posts: 13
Joined: Mon May 24, 2010 4:20 pm

out of range error in MMC1 prg switching code...

Post by vishu_supreme »

I have previously done chr switching using MMC1 mapper and it worked well and good .....here I was using 32 kb switching mode (but I never switched)

But now I want to use 16kb prg bank switching ...
for that, the changes I have made to the previous code [the code in which chr switching is working fine] are :

1)I have generated a .lst file and seen where the first 16 kb of code ends...
then I have cut and pasted the next 16 kb code into other .asm file (two.asm) and the first 16 kb as(one.asm)

2)next I added the bank with the following code and in the first 16 kb file(one.asm)...

Quote:
.base $C000
.incbin "two.asm"
.org $ffff


3)in the mapper initialization I changed to the following :
Quote:
LDX #%00010011
jsr initMMC1Mapper
initMMC1Mapper:
LDA #$80
STA $8000

TXA
JSR setMMC1ControlMode

LDA #$00
JSR setCHRPage0000

LDA #$01
JSR setCHRPage1000


LDA #$01
JSR setPRGBank

RTS
the subroutines writes to the registers.....


3)when I compiled I am getting weird results...

value out of range in the 3rd line of the following added code:

.base $C000
.incbin "two.asm"
.org $ffff


So, please can you say me when does bank actually gets switched for first time ...?? like before the first pass after second...??

please can any one help me regarding the mentioned error...???

thanks in advance..
User avatar
Bregalad
Posts: 8036
Joined: Fri Nov 12, 2004 2:49 pm
Location: Caen, France

Post by Bregalad »

LDX #%00010011
jsr initMMC1Mapper
initMMC1Mapper:
LDA #$80
STA $8000

TXA
JSR setMMC1ControlMode

LDA #$00
JSR setCHRPage0000

LDA #$01
JSR setCHRPage1000


LDA #$01
JSR setPRGBank

RTS
You do a "jsr initMMC1Mapper" which is immediately followed by the initMMC1Mapper routine itself... so it will call the routine TWICE (it will call it with the jsr, and then return in the routine itself and execute a second time). You probably don't want that to happen, so you'd want to fix hat.

Then you have to change the value you write to control register...
Here you write #%00010011 (on the first call) which sets the MMC1 in 32k switching mode, but you say in your post you want to do 16k switching. So you probably want to write #$1f (#%00011111) instead.

This should fix your program I think (assuming the set**** routines are correct, and do 5 writes to MMC1 regs).
Useless, lumbering half-wits don't scare us.
vishu_supreme
Posts: 13
Joined: Mon May 24, 2010 4:20 pm

Post by vishu_supreme »

I have not called it twice ....

I just mentioned what is the code of the subroutine called...

I took care so that it is called only once ...

I changed it to #$1f...

but still I'm getting the same error.. :(
doppelganger
Posts: 183
Joined: Tue Apr 05, 2005 7:30 pm

Post by doppelganger »

What assembler are you using?
Be whatever the situation demands.
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

He's using ASM6. The problem was already solved though... The problem was that the interrupt vectors were defined at the end of the "two.asm" file, so the PC was already past $ffff when the ".org $ffff" line was reached. Changing the $ffff to $10000 or simply removing that line does the trick.
Post Reply