Can't wait to play Game Boy games on SB + Savestates! :)
Gameboy Emulator
Root / Talk About Programs / [.]
SaladFingersCreated:
Hello! I’ve been a lurker here for a long time and I thought it is time to post.
I’ve been working on a gameboy emulator for the past year or so (though I hadn’t touched it since December, until today). Unfortunately, the long break has caused me to forget what some of my poorly-written, unclear code does. Though, I have gained a lot more experience on low-level stuff.
Just today, I have gone through all of the opcodes that I have implemented and fixed a few of them. I can now get far enough to get to what I can assume is loop of the credits screen of Tetris. Excitingly, the tiles are copied to VRAM. If I could only figure out how to upload pictures, I could show the tiles being dumped from VRAM.
Edit: added images. Both show some part of VRAM.
Anyway here’s what I have completed:
Spoiler
Spoiler
- about 75-85% of the opcodes
- timing and cycle emulation
- timer registers
- video registers
- interrupts
- button input
- OAM
- window registers
- anything else visual
- save states and battery saves
- respectable speeds
Great, now we can have two emulators! One from you and one from RaichuBender (I think that was his name). Also, did you test it on O3DS or N3DS? It would be nice if it could run on both at a playable speed.I have been testing on a New 3DS. I can change the clock to the old 3DS’s speed of 268MHz through CFW, so I’ll be sure to keep you updated on the slower clock speed. I do have an old 3DS to test it but I’ll have to get smilebasic on there.
-The GameBoy's games could be up to 8mb, which immediately uses up ALL memory SmileBASIC can use. -The GameBoy has 8KB of ram, which would most likely take up 32KB of SmileBASIC's memory. This could be reduced, at the expense of increased processor usage. -The GameBoy has 8KB of VRAM, which would most likely take up 32KB of SmileBASIC's memory, just like before. There are other things which would take up even more memory, but these are the main ones.For speed, I do waste the other bytes in each array index. The Gameboy can address 2^16 memory addresses, about half of it is RAM, the other half is the ROM. Only 32KB of ROM are addressable at one time… so the 8MB of ROM aren’t in smilebasic RAM (I hope that makes sense) all at once. Additionally. I don’t know any original gameboy game that is 8MB. Do you mean megabit? Since I’m able to create an array with &hFFFF indexes, I can load any cartridge size…
A few things. First off, I'm not aware of any games which were 8MB, I just read that it could handle cartridges up to 8MB. Second, the only way to really use less RAM to store the ROM is to store the GB ROM in several DAT files, and load them into the ROM array whenever that part of the GB ROM is needed. I suspect if you were to try to do this you would quickly find that it wastes a lot of time loading. You could improve load times by loading several 32KB ROM portions at once, and by storing them together.I’m sorry, I’m not following what you are saying... I only have one array that contains all of the Gameboy’s memory. When you said save RAM, I though you meant that I should pack 4 bytes into each array index, since each number can be 32 bits in SB, rather than fitting one byte into it, put 4 bytes.
Very excited to see this release be possible. I have one question: How are you going to handle ROMS? Will they just be transfered via SBMODEM? Keep up the great work! PS: Now I can play (or will be able to play) all my old GB ROMS on my calculator and 3DS!Thanks so much for the kind words :) I have been moving the ROMs via SB File manager by Trinitro21. I haven’t used SBModem yet but I’m guessing it will work. And don’t expect this to be as well made as Calc84’s emulator, that thing is truly incredible.
Woah... I hope this will work out well! Maybe I can load in ROMs with PetitModem?
Ahh, I understand. So SB doesn’t reallocate the memory… I’ll have to think about how to handle the ROM.You said that not all of the GameBoy ROM is in SmileBASIC RAM at one time. In order for that to work you would need to split the DAT file containing the ROM into several portions, and save it as several separate DAT files. That way, you could have an array with 32768 elements, and load the ROM portions into that array as each part was needed. It's impossible to only load part of a DAT file. Does anyone understand what I'm trying to say?A few things. First off, I'm not aware of any games which were 8MB, I just read that it could handle cartridges up to 8MB. Second, the only way to really use less RAM to store the ROM is to store the GB ROM in several DAT files, and load them into the ROM array whenever that part of the GB ROM is needed. I suspect if you were to try to do this you would quickly find that it wastes a lot of time loading. You could improve load times by loading several 32KB ROM portions at once, and by storing them together.I’m sorry, I’m not following what you are saying... I only have one array that contains all of the Gameboy’s memory. When you said save RAM, I though you meant that I should pack 4 bytes into each array index, since each number can be 32 bits in SB, rather than fitting one byte into it, put 4 bytes.
Woah... I hope this will work out well! Maybe I can load in ROMs with PetitModem?I haven’t used PetitModem and since Shelly voids it useless, an alternative can be found here: https://smilebasicsource.com/page?pid=308 Though, a 32KB ROM should take almost 6 minutes through PetitModem.
Well, there's something.
The Game Boy has ROM bank 0 loaded into RAM adresses $0000-$3FFF at any given time.
Other ROM banks can be swapped out in another 16KB area. $4000 - $7FFF
There go 32KB for the ROM banks 00 and another one.
You could easily store all of the gameboy's 64KB of address space into SB's 8MB of RAM lol, even without packing multiple bytes into each array element. 256KB is just 3% of the RAM that SB has.Right, but ROMs can be banked and Shelly says that 8MB ROMs will take up all of SB’s RAM. Based off what Shelly said, I’m guessing memory is not reallocated after loading a file during runtime
-The GameBoy has 8KB of ram, which would most likely take up 32KB of SmileBASIC's memory. This could be reduced, at the expense of increased processor usage. -The GameBoy has 8KB of VRAM, which would most likely take up 32KB of SmileBASIC's memory, just like before.64KB is literally a nip in SmileBASIC's memory what are you talking about
Well sure, technically there's no limit to the ROM size if you use a memory mapper. But you can still only have like 32KB or whatever of the cartridge memory accessible at once. If you need to, you could just store each bank in a separate file and only load them when you need to. But there's only like, one game that has 8MB of ROM. Even a big game like pokemon only uses 1 MB, and that would easily fit in SB's RAM even without packing.You could easily store all of the gameboy's 64KB of address space into SB's 8MB of RAM lol, even without packing multiple bytes into each array element. 256KB is just 3% of the RAM that SB has.Right, but ROMs can be banked and Shelly says that 8MB ROMs will take up all of SB’s RAM. Based off what Shelly said, I’m guessing memory is not reallocated after loading a file during runtime
I'm pretty sure that games for the original GameBoy rarely take more than 1 or 2 Megabytes. GameBoy Advance ROMs can take 8 or so, but that's not what we're dealing with here. We're talking about the original GameBoy with the grayscale (greenscale??) screen with no colors. ROMs for that are small.
Some(/most?) Game Boy games released before the GBC do have basic colors (not just grayscale) built-in for future use on the Super Game Boy or GBC. You can basically tell the game it's going to GBC compatibility mode to display colored things rather than 4 default grayscale colors...
Examples: Tetris, Pokémon Red/Blue/Green and other.
EDIT: Pokémon Red as an example simply swaps palettes rather than using color schemes from like Pokémon Crystal/Yellow.
I know. I was saying the screen has no colors. (Except for the green color that's always there.) My point is, ROMs for the original GameBoy aren't big files at all, I think SmileBASIC allows enough RAM for that.
Excuse my lack of progress updates, I am on vacation. I’m quite glad that the size of ROMs wouldn’t be a problem, thanks for the help guys!
Edit:
And yes, this is only emulating the original gameboy, which has four grayscale colors.
Can I haz gb emulator?
The emulator is not ready yet.
I’ve been working on it on and off. Though, I have been busy with school starting recently. I fixed a lot of logical bugs in the opcodes. I’m honestly not sure how the h*ck I had overlooked such bugs. For example, I’d push the PC to the stack on a conditional CALL no matter the outcome. Anyway, here is some more eye candy:
I’m guessing I’m at the point Raichu Bender was when he finished working on his emulator. He showed photos of the Nintendo logo from the boot firmware. This photo is the initial tile map screen from Tetris and is the full 32x32 map. Also note, that this isn’t rendered in real time: that is my next step.