background changing

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
background changing
by on (#2488)
Okay, I am making a small game that is basicly the same thing as pacman, and I have my title screen scroll down from the top. Then what I want is that when you press start, like it says to do so on the title screen, you can change the background to the map of the level, and start the game. I can't think of a way to do this. I hope it wasn't a bad idea to make the map of the level a .nam file. Whenever I write stuff saying do this when start is pressed, It does it anyway, even if start isn't pressed. and it doesn't even do the right stuff, which is changing the background. It just flashes the background for about a tenth of a second, and then stays at the title screen, and does it again after a second, and again and again. so yeah, how would you say change the background when start is pressed? thanks.

by on (#2489)
One very handy way to do this is to have your game logic independent from your NMI routine.

Inside your NMI routine, perform 'vital' functions such as sprite DMA, palette updates and VRAM I/O, controller reading, and audio playback, and at the very end, increment some variable named 'nmicount'.

Elsewhere in your code, you will have a set of routines which start by waiting for nmicount to become nonzero (and then zeroing it afterwards), then perform some functions (checking input, executing game logic, queueing background/sprite updates, etc.), and then JMPing to some other routine based on the outcome (possibly the same one it's already in). Your very first routine in this group will be called 'Titlescreen' (or equivalent) and you will JMP to it at the end of your reset code (after NMIs are enabled, of course).

This has the advantage of being very easy to organize and expand and having less clutter in the 'important' routines (namely, your NMI and IRQ handlers).

I'm using this exact method in a game I'm making which is ALSO quite similar to Pac-Man but is still very much different. The player is a Drip™ of water, each level is a set of pipes, and the player must rust them while being chased by 4 enemies and avoiding hazards (electric coils between the pipes, projectiles shooting from the pipes) and collecting bonuses. The game itself is basically a port/remake of the Amiga game "Drip" by Art Skiles.

by on (#2508)
Sorry, I still can't get things to work well. Well, I actually got my scrolling crap in my NMI routine, but for some reason, I can't get key readings right.
Here is my code to load the background:

Code:
background:
   ldx #0
   lda #$20
   sta $2006
   stx $2006
   lda #low(titlescreen)
   sta adrlo
   lda #high(titlescreen)
   sta adrhi

   ldx #8
   ldy #0
loop:
   lda [adrlo], y
   sta $2007
   iny
   bne loop
   inc adrhi
   dex
   bne loop


Well my code for the keypresses at the moment only applies for the start key right now, cause I don't care about anything else at the moment.:
Code:

        lda $4016
        do the same two more times
        lda $4016
        and #1
        bne StKey
        the rest are just lda $4016

StKey:
        lda LdStart
        sta SvStart



And this the embarassing attempt at changing the background:

Code:
aaaa:
        lda #low(lev1)
        sta adrlo
        lda #high(lev1)
        sta adrhi

aaab:
        lda aaaa
        sta LdStart
        lda SvStart
        sta $2007


I think it's something wrong with my key presses, because nothing happens with that code. I'm sorry, I'm rambling on, and I'm sort of dumb feeling right now. So, whoever responds to this, thanks. :)

by on (#2509)
Sorry, I forgot to log in before I posted the previous message. But just to let you know, I posted that thing above. :)

by on (#2512)
Be sure that the screen *is* OFF when you're writing to the PPU via $2006; $2007. Uses Nintendolator tracing is a good way to ckeck if you're timing is okay or not.

by on (#2717)
I don't know why you do ,
Code:
lda aaaa
        sta LdStart
        lda SvStart
        sta $2007

Could you give me your source and all files needed,maybe I can help you to correct it.

by on (#2718)
My E-mail maoshan108_369@126.com

by on (#2781)
Oh yeah, I scrapped that code like a thousand years ago, so I don't have it any more. I think I would be pretty embarrased to look at it if I still had it. So , sorry, but thanks. :)