Welcome to Emulationworld

Forum Index | FAQ | New User | Login | Search

Make a New PostPrevious ThreadView All ThreadsNext ThreadShow in Flat Mode*


SubjectCPU emulation questions.. Reply to this message
Posted bycabaret voltaire
Posted on04/21/04 08:44 AM



A while ago I programmed a Chip8 emulator in Javascript.. It ran very well, but slowed down ALOT with some Superchip games. Recently I decided to have another go, and this time try to get all games running at a decent speed.

This time I'm doing something that is alot different to the normal interperative emulators I've seen, and was wondering if anyone could give some advice on implementing it properly. What I have so far (started yesterday, it runs a single game but with no controls implemented) can be seen here: http://www.elephantsneverforget.co.uk/c8x.html

What I do is:
I have an array called TranslatedBlocks.
The emulator starts at "ProgramCounter=0x200",
The emulator checks TranslatedBlocks[ProgramCounter]. If it is null then the emulator stores all opcodes from ProgramCounter onwards, until a jmp/rts/etc (any opcode that changes the ProgramCounter) occurs, in a temporary array and then sends the array to another function which translates the opcode into Javascript and stores the new Javascript function in the TranslatedBlocks array.

If TranslatedBlocks[ProgramCounter] isn't null, (it's a function) it is executed.

Whenever a "translatedblock" is executed the ProgramCounter is either set by an instruction (jmp/rts/etc) or incremented by the length of the block.


This seems to work fine, and if I turn off rendering (which is very slow at the moment) the emulator is so fast that the game is over within a second or two. My problem is knowing when interrupts occur. Do I have to increment a cycle counter for every opcode executed within translated blocks?? I just can't work out how to do it accurately.. It doesn't matter so much for Chip8 but I think it would be a laugh to try a NES emulator in javascript.. ha.



I would like to do something like this on GBA or GP32 (the translatedblocks would be arrays of hexcode right?) but am not sure if they would have the memory.. I figure that most games might only need a few translatedblocks active once, would that be the case?

I could allocate enough memory for 3 or 4 translated blocks and keep track of when the last block was executed. If a new block is to be translated and I don't have any room left I replace the one that was used last. However blocks would be variable length.. Anyway something like this would be possible?

Thanks :)



-
Entire Thread
Subject  Posted byPosted On
.CPU emulation questions..  cabaret voltaire04/21/04 08:44 AM
.*Re: CPU emulation questions..  galibert04/21/04 09:41 PM
..*Re: CPU emulation questions..  cabaret voltaire04/22/04 04:06 AM
...*Re: CPU emulation questions..  R. Belmont04/22/04 09:30 AM