NESDev and Strangulation Records messageboards
Forum Index | FAQ | New User | Login | Search

Previous ThreadView All ThreadsNext ThreadShow in Flat Mode*


SubjectRe: Importing and another question  
Posted byDisch
Posted on9/13/04 3:32 PM
From IP66.82.9.82  



SDL Image won't help you in any way when making an NES emu. Also, I don't think OpenGL has anything to offer, either. Just the basic SDL library is really all you need. You won't need/have any textures/surfaces other than the back buffer (your best bet is to redraw the entire screen pixel by pixel every frame, rather than blit 8x8 tiles to the screen.. this way mid-scanline and mid-frame writes can be properly emulated).

I'm not really familiar with OpenAL, but I think the Sound streaming functions in SDL should more than suffice for your needs.


The hardest part about emulating the NES is running the PPU, main CPU, and pAPU all at the same time (as time passes in one of them, time is also passing in the 2 other ones, and you have to keep them all updated). Games often use timing tricks for some visual effects, so you have to manage the 3 areas properly.

In my emu I kept 3 different cycle counters, (one for CPU, PPU, and APU). I based EVERYTHING in PPU cycles (since 1 PPU cycle is a third of a CPU cycle... this avoids having to deal with fractions of cycles). I'd recommend doing something like this (which has worked well for me in the past):

1) Lock the back buffer, hand off the pointer to the buffer to your PPU emu.

2) Run the CPU for a frame.. or until the nearest IRQ (whichever comes first)

--a) whenever the CPU makes a write/read to PPU/APU regs, have the PPU/APU 'catch up' to the current CPU cycle (in the case of the PPU, this means rendering pixels up to the current time, in the APU it means generating sound samples). Also update the PPU on CHR-bank swaps... and update the APU on PRG-bank swaps.

--b) when the CPU strobes the joypads, poll user input (makes it pretty simple ^^)

--c) when the CPU does anything IRQ related, re-evaluate when the next IRQ is going to occur

3) Repeat #2 until a full frame has passed

4) Catch the PPU and APU up to the CPU

5) Unlock back buffer, wait until ~1/60th of a second has passed, then swap the image to the screen (this is probably where you could check for SDL events like exit messages and stuff).


For CPU emulation... a big switch statement is the best way to go. Most if not all compilers will convert a large switch statement to a jump table after it's compiled, and that's really the best you can get (unless maybe you put inline assembly... but that would destroy the portability I'd assume you're going for with SDL).



-
Entire Thread
Subject  Posted byPosted On
*Importing and another question  Anonymous9/13/04 00:07 AM
..Re: Importing and another question  Disch9/13/04 3:32 PM
..*Re: Importing and another question  Anonymous9/14/04 00:41 AM
...*Re: Importing and another question  Fx39/14/04 02:15 AM
....*Re: Importing and another question  Anonymous9/14/04 03:00 AM
.....*Re: Importing and another question  Anonymous9/14/04 2:44 PM
.....*Unsigned charmander go!  tepples9/14/04 03:53 AM
......*Re: Unsigned charmander go!  Fx39/14/04 03:59 AM
.......*Re: Unsigned charmander go!  Anonymous9/14/04 11:49 AM
..*Re: Importing and another question  Fx39/13/04 8:41 PM
...*Re: Importing and another question  Disch9/13/04 10:05 PM
.*Re: Importing and another question  Memblers9/13/04 11:20 AM
Jump to

Memblers' homepage             Contact Me

Forums powered by WWWThreads Demo