Dumb Question

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

Post Reply
User avatar
neilbaldwin
Posts: 481
Joined: Tue Apr 28, 2009 4:12 am
Contact:

Dumb Question

Post by neilbaldwin »

Is there a reason that I can't write to RAM in my background loop?

It works fine if I modify some RAM values during VBLANK but doing the same modification in the background loop doesn't change the values.

I'm sure I'm missing something obvious but I can't see.


:?
User avatar
Disch
Posts: 1848
Joined: Wed Nov 10, 2004 6:47 pm

Post by Disch »

Do you mean VRAM ($2007)? Can't write to VRAM outside of VBlank unless you disable rendering (disable both BG and sprites via $2001).

There's no reason why you can't write to normal RAM though ($0000-07FF). In fact you certainly should be able to.
User avatar
neilbaldwin
Posts: 481
Joined: Tue Apr 28, 2009 4:12 am
Contact:

Post by neilbaldwin »

Disch wrote:Do you mean VRAM ($2007)? Can't write to VRAM outside of VBlank unless you disable rendering (disable both BG and sprites via $2001).

There's no reason why you can't write to normal RAM though ($0000-07FF). In fact you certainly should be able to.
Yes, normal RAM.

I was just going to come back and update this as it's not the writing of the RAM, it's the fact that my background loop actually doesn't do anything?!

After I've done the initial setup, right after the CLI I just have a loop

MainLoop jmp MainLoop

but it seems it doesn't execute. I tested it by calling my sound update routine and it doesn't make the call.

Am I doing something very stupid?
User avatar
neilbaldwin
Posts: 481
Joined: Tue Apr 28, 2009 4:12 am
Contact:

Post by neilbaldwin »

Ah, seems it's something to do with the CLI command. If I remove it, the background processing works.

Do you have to do something special in your IRQ routine, even if you're not using the IRQ to do anything? Currently my IRQ routine is just an RTI. Is that wrong?
User avatar
Jarhmander
Formerly ~J-@D!~
Posts: 521
Joined: Sun Mar 12, 2006 12:36 am
Location: Rive nord de Montréal

Post by Jarhmander »

Is the interrupt vector correctly point to RTI? At the moment the IRQ fires, does the right bank is visible at the end of the memory where interrupt vectors should be read, and when it vectors to the ISR, does the correct bank is 'seen' ?
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

neilbaldwin wrote:Do you have to do something special in your IRQ routine, even if you're not using the IRQ to do anything?
Nothing special, you can have just an RTI there, like you said. Some people even have the IRQ vector point to the same location as the RESET vector. Ideally, if you're not using IRQs, you'd better prevent them from happening at all.

If you are not using interrupts, why did you have a CLI command anyway? Just use SEI at the start of the program to disable all interrupts. If you do decide to use interrupts though, don't forget to disable DMC IRQs and Frame IRQs if you're not using them.
User avatar
Disch
Posts: 1848
Joined: Wed Nov 10, 2004 6:47 pm

Post by Disch »

Forgetting to disable the APU Frame IRQ is the common culprit, here.

Code: Select all

 ; do this at program startup
LDA #%01000000
STA $4017
User avatar
neilbaldwin
Posts: 481
Joined: Tue Apr 28, 2009 4:12 am
Contact:

Post by neilbaldwin »

Disch wrote:Forgetting to disable the APU Frame IRQ is the common culprit, here.

Code: Select all

 ; do this at program startup
LDA #%01000000
STA $4017
You got it :)

I've just removed the CLI command as I'm not using the IRQ anyway (doing the CLI was just a legacy thing, left over from old reset vector code - force of habit I guess).

But Disch was right - I wasn't disabling the APU frame IRQ - doh!

Thanks for the input everyone.
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

I once had a bunch problems because of Frame IRQs myself... It took me a long time to figure out the problem was such a tiny thing that's so easy to fix.
User avatar
Jarhmander
Formerly ~J-@D!~
Posts: 521
Joined: Sun Mar 12, 2006 12:36 am
Location: Rive nord de Montréal

Post by Jarhmander »

I assumed that if you used CLI, it is because eventually you'll use interrupts... :)
The code didn't work because the frame IRQ was never acknowledged.
Post Reply