Skip navigation
NintendoAge
Welcome, Guest! Please Login or Join
Loading...

Question about changing tile attributes (Please don't make fun... I'm new to this...^_^)

May 26, 2008 at 4:52:42 PM
Rachel (10)
avatar
(Player of Games, Killer of Threads) < Eggplant Wizard >
Posts: 335 - Joined: 05/24/2008
Texas
Profile
I am hoping that  those of you well versed in NES programming could answer a beginner's question. I am new to the NES and to ASM. I have followed bunnyboy's excellent NESASM tutorials, and have tried to modify one of the demos in a small way. I'm trying to change the attribute of a sprite tile so that all four sprite palettes are shown for that one tile alternatingly. I've gotten it to work when switching between one four-color set and another, but when I try to show pal 0->1->2->3->0->..., it starts behaving oddly. I've tried writing the code in several ways (incrementing with X, using ADC/SBC) and I've tried slowing it down, but it still doesn't work. I think that maybe there's some kind of fundamental, obvious thing that I don't understand about what I'm doing. Any help would be greatly appreciated. Some code snippets are below. (Now, granted, this probably isn't the way I would actually do the color switching in a real game, but it's the way that I had saved in my .asm, so that's what gets posted.)
Thanks in advance for the help.
Rachel


; Switching between first two palettes (works)
  LDX #$00
Flash:
  INX
  TXA
  STA $0202
  DEX
  TXA
  STA $0202
  JMP Flash

; Switching between all four palettes (does not work)
  LDX #$00
Flash:
  INX
  TXA
  STA $0202
  INX
  TXA
  STA $0202
  DEX
  TXA
  STA $0202
  DEX
  TXA
  STA $0202
  JMP Flash

-------------------------
Resident collector of and expert on vintage girly games and consoles--especially rare stuff! 

Currently playing: Miitomo (iOS), Yoshi's Woolly World (WiiU)

May 26, 2008 at 5:37:14 PM
bunnyboy (81)
avatar
(Funktastic B) < Master Higgins >
Posts: 7704 - Joined: 02/28/2007
California
Profile
Is there more code between the writes to $0202 The sprites are only updated on screen once per frame (when you do the sprite dma), so if you are just writing all in one set then it will update on the last one only.

What you would want to do is only do one increment each frame. In your nmi, read from $0202, increment, write back to 0202. If it now equals 4, write 0 instead to start again. It will go super fast (60 fps) but try coding that and post again if you need more help!

May 26, 2008 at 5:57:59 PM
Rachel (10)
avatar
(Player of Games, Killer of Threads) < Eggplant Wizard >
Posts: 335 - Joined: 05/24/2008
Texas
Profile
Wow... I had tried what you described, but it wasn't working. Now I think I realize why--my LDA $0202 was part of the loop. Once I pulled the LDA $0202 outside of the loop, it worked. Genius! Thanks a ton!
If you don't mind, could you confirm that this code makes sense? I've already made the mistake of thinking I understood something that I didn't and then trying to build on that erroneous knowledge. It's a hard lesson to learn, but I know that just because it works in an emulator doesn't mean it makes a lick of sense.
Thanks again!

LDA $0202 ;(data at $0202 is 0)
Flash:
; I had the LDA $0202 here before... oops...
CLC
ADC #$01
STA $0202
CMP #$04
BNE Flash
Flash2:
SEC
SBC #$01
STA $0202
CMP #$00
BNE Flash2
JMP Flash

-------------------------
Resident collector of and expert on vintage girly games and consoles--especially rare stuff! 

Currently playing: Miitomo (iOS), Yoshi's Woolly World (WiiU)

May 26, 2008 at 10:35:31 PM
Memblers (3)
avatar
(Joey Parsell) < Eggplant Wizard >
Posts: 247 - Joined: 05/12/2008
Indiana
Profile
The code is incomplete because it only seems to set it to zero. It's an infinite loop, but the sprites only change during the vblank. So assuming NMIs are enabled, and LDA #2 / STA $4014 is in the NMI routine, I can see how it'd work because it'll use whatever number it was interrupted at. That's an interesting approach. It wouldn't do a 1,2,3,4 progression.

But I could only assume that without seeing the rest of the program.

-------------------------
 

May 26, 2008 at 11:02:30 PM
Rachel (10)
avatar
(Player of Games, Killer of Threads) < Eggplant Wizard >
Posts: 335 - Joined: 05/24/2008
Texas
Profile
But if there was a more random progression (not just 1->2->3->4), wouldn't you see the tile to start flipping horizontally and vertically as the attribute value got higher than expected? Or maybe I'm not understanding...

-------------------------
Resident collector of and expert on vintage girly games and consoles--especially rare stuff! 

Currently playing: Miitomo (iOS), Yoshi's Woolly World (WiiU)

May 27, 2008 at 1:13:57 AM
Zzap (47)
avatar
(James ) < King Solomon >
Posts: 3301 - Joined: 05/01/2007
Australia
Profile
The values at $0202 will be going through this cycle of numbers very quickly (like every 10 or so cpu cycles)

0-1-2-3-4-3-2-1-0-1-2-3-4-3-2-1 (etc)

Every 1/60th (or 1/50th of a second depending on PAL or NTSC) the vblank interrupt will occur causing the sprites to be updated using whatever value is currently at $0202. As Memblers pointed out, this will work out to be a random point in the above cycle of numbers - wherever it was up to at the point in time the vblank occured. If you want it to cycle through these palettes every frame, you should put the increase/decrease code into the vblank (and I think you want to loop between 0 and 3, not 0 to 4):

e.g.

vblank:
; Update sprites
LDA #$02
STA $4014

LDA DirectionVariable ; create a variable in Zero page memory called this to keep track of whether to loop forward or backwards. 0 = forwards, 1 = backwards
CMP #$01
BEQ loopBackwards

loopForwards:
LDA $0202
CLC
ADC #$01
STA $0202
CMP #$03 ; check if we are up to 3, if so we'll change direction next frame
BNE endNMI
LDA #$01
STA DirectionVariable
JMP endNMI

loopBackwards:
LDA $0202
SEC
SBC #$01
STA $0202
CMP #$00 ; check if we are up to 0, if so we'll change direction next frame
BNE endNMI
LDA #$00
STA DirectionVariable

endNMI:
RTI

-------------------------

Chunkout for iPhone, iPad and iTouch out now!
Chunkout Games: FaceBook | Web


Edited: 05/27/2008 at 01:14 AM by Zzap

May 27, 2008 at 1:47:36 AM
Rachel (10)
avatar
(Player of Games, Killer of Threads) < Eggplant Wizard >
Posts: 335 - Joined: 05/24/2008
Texas
Profile
Ergh, yeah... 0-3. Zzap, I think I understand what you mean. I'll take a look at my code again tomorrow after work and see if I can make sense of it. Thanks for all the help, everyone.
R

-------------------------
Resident collector of and expert on vintage girly games and consoles--especially rare stuff! 

Currently playing: Miitomo (iOS), Yoshi's Woolly World (WiiU)

May 27, 2008 at 2:20:24 AM
Zzap (47)
avatar
(James ) < King Solomon >
Posts: 3301 - Joined: 05/01/2007
Australia
Profile
No problems

Head over to NESDev too for lots of useful information and people:

http://nesdev.parodius.com/bbs/...

and

http://nesdevwiki.org/...

-------------------------

Chunkout for iPhone, iPad and iTouch out now!
Chunkout Games: FaceBook | Web

May 27, 2008 at 7:28:04 AM
jaredkk (57)
avatar
(Jared Klinger) < King Solomon >
Posts: 3064 - Joined: 03/25/2007
New Jersey
Profile
I thought this was an English language forum...

-------------------------


May 27, 2008 at 12:48:35 PM
Rachel (10)
avatar
(Player of Games, Killer of Threads) < Eggplant Wizard >
Posts: 335 - Joined: 05/24/2008
Texas
Profile
Yeah, I kinda lurk in the NesDev BBS. I think my ego might be too fragile to try posting there, though.

-------------------------
Resident collector of and expert on vintage girly games and consoles--especially rare stuff! 

Currently playing: Miitomo (iOS), Yoshi's Woolly World (WiiU)

May 27, 2008 at 3:49:48 PM
KHAN Games (89)
avatar
(Kevin Hanley) < Master Higgins >
Posts: 8126 - Joined: 06/21/2007
Florida
Profile
You could always come jump in the #nintendoage chatroom. That room is filled with bunny and zzap and roth and sivak spewing code nonsense way too often. What's one more person?

-------------------------

gauauu: look, we all paid $10K at some point in our lives for the privilege of hanging out with Kevin