It is currently Fri Dec 14, 2018 3:30 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: NMI and MAIN
PostPosted: Tue Jul 18, 2006 11:18 pm 
Offline
User avatar

Joined: Sun Mar 19, 2006 12:37 am
Posts: 223
Location: San ANto, TX
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?

_________________
" If I have seen further it is by standing on the shoulders of giants" - Issac Newton, in a letter to Robert Hooke.


Top
 Profile  
 
 Post subject: Re: NMI and MAIN
PostPosted: Wed Jul 19, 2006 3:42 am 
Offline
Site Admin
User avatar

Joined: Mon Sep 20, 2004 6:04 am
Posts: 3599
Location: Indianapolis
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.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 5:16 am 
Offline
User avatar

Joined: Fri Nov 19, 2004 7:35 pm
Posts: 4108
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.

_________________
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!


Top
 Profile  
 
 Post subject: Re: NMI and MAIN
PostPosted: Wed Jul 19, 2006 2:15 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20875
Location: NE Indiana, USA (NTSC)
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.

Quote:
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.


Top
 Profile  
 
 Post subject: Attributes and Palettes
PostPosted: Thu Jul 20, 2006 4:58 am 
Offline
User avatar

Joined: Sun Mar 19, 2006 12:37 am
Posts: 223
Location: San ANto, TX
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:
;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

_________________
" If I have seen further it is by standing on the shoulders of giants" - Issac Newton, in a letter to Robert Hooke.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 20, 2006 3:37 pm 
Offline
User avatar

Joined: Wed Nov 10, 2004 6:47 pm
Posts: 1849
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.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 23, 2006 8:07 pm 
Offline
User avatar

Joined: Sun Mar 19, 2006 12:37 am
Posts: 223
Location: San ANto, TX
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?

_________________
" If I have seen further it is by standing on the shoulders of giants" - Issac Newton, in a letter to Robert Hooke.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 24, 2006 5:13 am 
Offline
User avatar

Joined: Wed Nov 10, 2004 6:47 pm
Posts: 1849
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.

Quote:
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).

Quote:
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group