LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

Is Gameboy Emulation Possible?

Root / Programming Questions / [.]

XeylerCreated:
Hey, I've been thinking about trying to code a Gameboy emulator with SmileBASIC. Due to CPU limitations, I don't expect that it will be able to run in real time at all, but I hope that it can be at least some sort of playable with a N3DS. What I'm most worried about is memory usage: the original Gameboy had a 16-bit data bus(65,536 different addresses) which could retrieve 8-bit values(0-255). Although, thanks to bank switching, the addressable memory position grows to alarming sizes. Now, SmileBASIC uses 32-bit integers in arrays, so with some bit operations, I could fit four 8-bit Gameboy memory address values into one 32-bit number, but should I only do that until the value is accessed by the emulated CPU? Or should I code an 8-bit CPU around 32-bit ints(this makes me shudder, but I'll do what makes it work)? Or should I not try to optimize memory at all? Any clues on how to make this possible? Or if it even is?

SB has more than enough memory to store 1 byte per integer.

Are you sure about that? Maybe I should have been more detailed about the memory bank switching because with it, some games have reached 2MB in size with just the 16KB of addressable space. Can SmileBASIC really handle arrays that have upwards of 2,000,000 values?

Are you sure about that? Maybe I should have been more detailed about the memory bank switching because with it, some games have reached 2MB in size with just the 16KB of addressable space. Can SmileBASIC really handle arrays that have upwards of 2,000,000 values?
Yeah but its gotta be an integer array

You technically can store a 2 million element array but you're likely to run out of memory somewhere else. It might make more sense to store the ROMs packed so 4 bytes are to an int and unpack each specific 16K page to 1 byte per int on demand, per bank-switching. Less likely to run out of memory, but could be expensive for games which bank-switch often.

I think I thought about this before and concluded that depending on how you handle memory accesses, you could always store the ROM in packed form and read from it directly that way. Since it's read-only, extracting bytes is fairly cheap and you don't have to deal with modifying individual bytes.

Alright, I'm thinking I'll have a compressed ROM from which the emulated CPU can switch to, causing the program to decompress it into part of an array that represents the GameBoy's active memory(~16,000 of ~64,000 bytes). This will allow me to use an estimated 1,000,000 integers for emulation(ROM takes about 500,000 which leaves a generous 500,000 for everything else).

You're not the only one trying to do this, but still, I encourage you to try to get it to work. I really like the idea of playing GameBoy on my 2DS. (Come to think of it, that might not work. Willing to try it, though.)