Page 2 of 2

NMI and MAIN

Posted: Tue Jul 18, 2006 11:18 pm
by nineTENdo
Would it be good to use a main loop as well as an NMI? What would be the purpose of having a main loop run apart from an NMI? Can i use them in conjuntion?

Re: NMI and MAIN

Posted: Wed Jul 19, 2006 3:42 am
by Memblers
nineTENdo wrote:Would it be good to use a main loop as well as an NMI? What would be the purpose of having a main loop run apart from an NMI? Can i use them in conjuntion?
Yes, I think it's good to do that.

In some cases, the code in the main loop might take longer than a frame. It's good to have the music play in the NMI routine (after the PPU stuff), because people are very perceptive of even subtle glitches/wrong speed changes in music (much more annoying than gameplay slowdown IMHO). I'm sure there's other reasons too, I can't think of now.

At the very least you'll want a frame counter in the NMI routine so your main loop knows when to run. There are some games though that run everything in the NMI, with the code after startup just being an infinite JMP loop. I think that's kinda weird though. I think Metroid even enabled NMIs inside it's NMI routine so they could happen recursively, for when it takes longer than a frame.

Posted: Wed Jul 19, 2006 5:16 am
by Dwedit
You could also choose not to run your game logic in the NMI, and instead, have the NMI update a byte in memory indicating "Yeah, the frame is ready", then have your main loop repeatedly poll that byte to check if it's ready to proceed or not. Tons and tons of games do this.

Re: NMI and MAIN

Posted: Wed Jul 19, 2006 2:15 pm
by tepples
Memblers wrote:here are some games though that run everything in the NMI, with the code after startup just being an infinite JMP loop. I think that's kinda weird though.
Making everything after the init code into an NMI-listener is actually rawther common in games published by Nintendo. It's also the case in the Java platform (standalone programs or applets), where you build a frame, toss stuff into its panel, and then all the logic runs as event listeners inside the panel.
I think Metroid even enabled NMIs inside it's NMI routine so they could happen recursively, for when it takes longer than a frame.
Yes, reentrancy has its benefits. One is music catch-up (as seen in Pokémon for Game Boy). Another is not missing serial communication events, especially on a Vs Dualsystem or a pair of Game Boy systems.

Attributes and Palettes

Posted: Thu Jul 20, 2006 4:58 am
by nineTENdo
Hello Again,
I was wondering about how Attributes Tables work. Im working on the Atomic demo by CC. and in it he switches palettes to change the color on the screen. What im wondering is why he sets his attributes where he should be setting up his palletes. Can i use this in a simple demo to color my screen instead of using palletes? How does Attirbute coding work (look at .attribute). Heres the code:

Code: Select all

;other code-----------------------------------------------
	lda   #$23   
	sta   $2006   
	lda   #$D0   
	sta   $2006       	;Point to right spot in Attr. Map 
	ldx   #$00   
	ldy   #$20
.DrawAtt 
	lda .Attribute,X   
	sta   $2007 
	inx   
	dey  
	bne   .DrawAtt

.Attribute  
dc.b #$40,#$55,#$01,#$01 ,#$00,#$00,#$00,#$00            
dc.b #$04,#$05,#$51,#$00 ,#$00,#$00,#$00,#$00     
dc.b #$04,#$11,#$44,#$00 ,#$00,#$00,#$00,#$00            
dc.b #$04,#$01,#$00,#$00 ,#$01,#$00,#$00,#$00

; Other code ---------------------------------------------------------------
; than this------------------------------------------------------------------

InitPal 
   
	pha   
	txa   
	pha   
	tya   
	pha   
	
	lda   #$3F   
	sta   $2006   
	sty   $2006   
	ldy   #$08     			;Set up 8 colours.

.InitPal1 
	lda   .Palette,X   
	sta   $2007   
	inx   
	dey   
	bne   .InitPal1   
	
	pla   
	tay   
	pla   
	tax   
	pla   
	
	rts

.Palette 
dc.b #$0D,#$1D,#$2D,#$00 ,#$0D,#$10,#$3D,#$30    ;Greys         
dc.b #$0D,#$07,#$16,#$27 ,#$0D,#$37,#$38,#$30    ;Red-Yellow         
dc.b #$0D,#$01,#$11,#$1C ,#$0D,#$2C,#$3C,#$30    ;Blue-Cyan   
dc.b #$0D,#$03,#$14,#$25 ,#$0D,#$36,#$37,#$30    ;Magenta-Yellow         
dc.b #$0D,#$05,#$06,#$07 ,#$0D,#$17,#$18,#$28    ;Rusty       
dc.b #$0D,#$11,#$2C,#$2B ,#$0D,#$2A,#$38,#$26    ;Spectrum1         
dc.b #$0D,#$16,#$39,#$2A ,#$0D,#$2C,#$11,#$13

Thanks Again
EL

Posted: Thu Jul 20, 2006 3:37 pm
by Disch
The attribute table assigns one of the four 4-color palettes to the tiles in the nametable. It's difficult to explain in words the pattern in how this is done --- a diagram is pretty much a necessity -- and any diagram I could draw would be no better than the many diagrams already in existence.

For this one... pick up a copy of nestech.txt, or look on the wiki, or look at some other nes technical reference and search the doc for "attribute tables" until you find the relevent info.

Posted: Sun Jul 23, 2006 8:07 pm
by nineTENdo
ok i think im getting the attribute thing. IN yy-CHR You can change the attributes in the pallete from 00-FF. So you can if you wanted to, use attributes to setup your screen. Which would allow you to color more of the screen directly (per 4x4 cell (32x32 pixel))and use more colors right.

Oh yeah why would you want to start your pallete at $3F3F?

Posted: Mon Jul 24, 2006 5:13 am
by Disch
nineTENdo wrote:IN yy-CHR You can change the attributes in the pallete from 00-FF.
Erm... well...

YY-CHR does let you select different palettes -- but how it does it doesn't really reflect how the NES handles it at all. Plus any changes it makes are merely cosmetic to make editing easier -- they will not change your ROM. The only thing YY-CHR changes in the ROM is the CHR (pattern tables). Attribute tables and palettes cannot be edited using that tool.
So you can if you wanted to, use attributes to setup your screen. Which would allow you to color more of the screen directly (per 4x4 cell (32x32 pixel))and use more colors right.
Right. If you want, you can think of there being 4 different 4-color palettes available for your background:

$3F00-$3F03 -- palette 0
$3F04-$3F07 -- palette 1
$3F08-$3F0B -- palette 2
$3F0C-$3F0F -- palette 3

Attribute tables let you assign one of those four palettes to each 16x16 pixel block in the nametable (not just 32x32).
Oh yeah why would you want to start your pallete at $3F3F?
Generally, you wouldn't. That guy in that other thread most likely had an error in his code.