It is currently Sun Aug 19, 2018 12:46 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Thu Oct 20, 2005 3:04 pm 
Offline

Joined: Thu Oct 20, 2005 1:15 pm
Posts: 3
I'm new to NES development but not programming and assembly in general. I'm working on a project just to get myself used to development for the system and stuff like that, and so far I've been pretty successful with it, mostly because I've stayed within the realms of what knowledge I already have. My project is a program that will run Conway's Game of Life.

What I've designed so far is an 8x8 board, which is a 64 byte array, one byte being one cell in the game. I know it'd be possible to write it so that one bit represents one cell and cut my memory in 8, but that seems like it'd require a lot more code to deal with, and I'll save that for a later revision. I've decided that the walls of the board wrap around, so the cell immediately to the left of the upper left corner is logically the upper right corner, and so on. In order to deal with this, I have divided the cells up into 9 "groups" or "areas", the middle (default case), upper-left (table offset 00), upper-right (table offset 07), lower-left (table offset 38), lower-right (table offset 3F), top side (table offset 01-06), left side (table offset mod 8 = 0), right side (table offset mod 8 = 7), and bottom (table offset 39-3E). There is a different section of code for counting the neighbors for each of these areas. I'm hoping that there's some way of making one general case that can handle all of these cases without needing to check for them explicitly, as I have done.

Here's a table showing what the offset for the array is for each cell. The #s in Red mean that there isn't actually a cell there, it's just logically there. I used this to make it easier when figuring out what the neighbors of a cell near the border were.
Image

Here's the code that I have so far:
http://userpages.umbc.edu/~mod1/life.asm
I wrote it, assembled, and ran it using 6502 simulator; it doesn't do any input or output, but by watching the values change in memory lets me see that the code is doing what it's supposed to do. I just set a breakpoint at the start of LIFECYCLE and ran through each cycle, and using that it looks like any Life simulator on the net. Different starting organisms can be put in by changing the MAKELIFE section of the code.

The things that I'd like to have help on are how I can turn this into code that will run on an NES, and any simpler methods of dealing with the border wraparound. My eventual goal is an NES ROM in which a player can use the controller to enter in which cells are alive and dead, as well as load several pre-defined patterns. I'm taking this one step at a time, and right now I at least have working code for the Life logic. The next step is adding graphics, which I'm at a bit of a loss for, and then player input, in which I'm even more at a loss for.

My aim screenname is OroKenshinor0 if any experienced, generous soul would like to walk me through the next step in my plan. Any other general comments or suggestions would be highly welcome. Thanks a lot :D


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 28, 2005 7:58 pm 
Offline

Joined: Thu Oct 20, 2005 1:15 pm
Posts: 3
I've gotten a fair bit of progress in this project. I've added code to display a blank grid in the background, add 64 sprites in the middle of the grid, which should be set to tile #00 if the cell is dead and #02 if the cell is alive. Then, whenever the A button is pressed, it does another iteration of the Life cycle, and updates the sprites. This is all working except for the update sprites subroutine. It works more or less depending on which emulator I'm using, which makes me think that hopefully it's a simple problem that's just due to my lack of understanding of the PPU (and certain emulators being very forgiving of these kind of mistakes)

Here's the sources: main code, life subroutine
sprites

And here's the ROM:
ROM

Here's my mileage based on which emulator I was using. I really don't know which ones are best to use, other than FCEU and Nintendulator, the rest I just randomly downloaded from zophar to try to see if different emulators would run it differently.

FCEU: The first two sprites work sort of exactly like I expect them to (that is, the upper corner and the sprite to the right of it). The only problem is that they display the correct state for the last two cells, not the first two like they're supposed to. All other sprites for some reason are always set to tile #01 (when they should be either #00 if dead or #02 if alive, never #01) Running through this in the FCEU debugger, the emulator seems to literally be doing this:

LDA #$00
STA $2004 ($01 is written to $2004) :shock:

Nintendulator: Works perfectly at first, displaying all of the sprites as they are supposed to be displayed. But, when you press the A button, all of the sprites disappear.

nessie: Just like FCEU

NESten: Works exactly like I expect it to

Nestopia: Just like FCEU

NNNesterJ: Works exactly like I expect it to

Here's just the update sprite code, since that seems to be the central problem:

Code:
update'sprites:

   lda #$01
   sta $2003   

   ldy #$00
*   tya
   asl
   asl
   clc
   adc #$01
   sta $2003

   tya
   tax
   lda CURR,X
   beq DEADSPR
   lda #$02
   jmp ENDUPSPR
DEADSPR:
   lda #$00

ENDUPSPR:
   sta $2004
   iny
   cpy #$40
   bne -
   rts



If anyone can show me what I'm doing wrong, I'd be incredibly grateful :D


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 28, 2005 8:05 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20420
Location: NE Indiana, USA (NTSC)
It's best to write to a local copy of OAM in $0200-$02FF, building this local copy during draw time. Then you can do this during vblank:
Code:
  lda #0
  sta $2003
  lda #2
  sta $4014



Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 28, 2005 8:12 pm 
Offline
User avatar

Joined: Sun Sep 19, 2004 10:59 pm
Posts: 1422
Your 'update sprites' routine is probably spilling into rendering time, and Nintendulator won't allow you to get away with that (on a real NES, it will cause problems as well). As tepples suggested, write your sprites into local system memory (page 2 is a convenient place to put it) and then do a Sprite DMA (the sample code above) immediately at the beginning of your NMI routine.

_________________
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 28, 2005 10:16 pm 
Offline

Joined: Thu Oct 20, 2005 1:15 pm
Posts: 3
Thanks a lot, guys! I got it working great now, and I think I understand how this thing works a little bit better. I kind of wasted a few hours with a really simple mistake... No graphics were showing up, and it took me a long time to realize that the problem was that with the new code, the first vblank happened right in between when I was loading a with the mask to enable graphics and when I was storing a to $2001, and I forgot to store my registers, so at the end of vblank, A was always zero again, thus leaving graphics disabled :oops: What a silly mistake to be stuck on for this long.

Anyways, if you're interested, the working code and ROM have been re-uploaded. Is it likely that this code would work on an actual console? I really don't want to get in the habit of writing stuff that wouldn't, but won't be able to get the means to check myself it for a while...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 28, 2005 10:51 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20420
Location: NE Indiana, USA (NTSC)
If you get something working on Nintendulator 0.950 or newer, it should be relatively safe to post it online as "working in the simulator; ready to test on NES".


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 4 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