? Gameboy Emulator (Page 1) ● SmileBASIC Source Forums

Sign In

Register
*Usernames are case-sensitive
Forgot my password

Gameboy Emulator

1 2
  • #1 ✎ 36 SaladFingers 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:
    1. about 75-85% of the opcodes
    2. timing and cycle emulation
    3. timer registers
    4. video registers
    5. interrupts
    6. button input
    And, here’s what I haven’t implemented:
    1. OAM
    2. window registers
    3. anything else visual
    4. save states and battery saves
    5. respectable speeds
    I just thought I’d share my progress, can’t wait to get the credits screen up.
    Posted Edited by SaladFingers
  • #2 ✎ 111 CyberYoshi64 Avatar Taboo I didn't change my avatar for 180 days Website Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Night Person I like the quiet night and sleep late. Express Yourself Can't wait to play Game Boy games on SB + Savestates! :) Posted
  • #3 ✎ 32 Plancake Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Video Games I like to play video games! Hobbies Reading I like to read books! Hobbies 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. Posted
  • #4 ✎ 237 Shelly I would just like to point out that most gameboy games wouldn't be playable on any SmileBASIC emulator, since they would quickly cause an "Out of memory" error upon loading. Problems with memory (major): -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. Minor memory issues (not really a problem): -the processor has 7 eight-bit registers, which will take up 28 bytes. Issues with processing: -The GameBoy's processor is clocked at 4.19 megahertz. Good luck emulating that at a comparable speed. Posted Edited by Shelly
  • #5 ✎ 36 SaladFingers
    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…
    Posted Edited by SaladFingers
  • #6 ✎ 237 Shelly
    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.
    Posted Edited by Shelly
  • #7 ✎ 15 LAX18 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! Posted
  • #8 ✎ 36 SaladFingers
    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.
    Posted
  • #9 ✎ 15 LAX18 Ah so you are familar with TiBoyCE! Posted
  • #10 ✎ 237 Shelly
    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.
    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?
    Posted Edited by Shelly
  • #11 ✎ 13 SuperBeefJerkey Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Drawing I like to draw! Hobbies Avatar Block I didn't change my avatar for 30 days. Website Woah... I hope this will work out well! Maybe I can load in ROMs with PetitModem? Posted
  • #12 ✎ 237 Shelly
    Woah... I hope this will work out well! Maybe I can load in ROMs with PetitModem?
    Good luck. I tried doing it one time, and I was unable to load even a 2MB ROM.
    Posted
  • #13 ✎ 36 SaladFingers
    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.
    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?
    Ahh, I understand. So SB doesn’t reallocate the memory… I’ll have to think about how to handle the ROM.
    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.
    Posted
  • #14 ✎ 1550 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Second Year My account is over 2 years old Website 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. Posted Edited by 12Me21
  • #15 ✎ 111 CyberYoshi64 Avatar Taboo I didn't change my avatar for 180 days Website Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Night Person I like the quiet night and sleep late. Express Yourself 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. Posted
  • #16 ✎ 36 SaladFingers
    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
    Posted
  • #17 ✎ 223 AnswerXOX Great Page Hidden Achievements RNG Hidden Easter Eggs Second Year My account is over 2 years old Website
    -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
    Posted
  • #18 ✎ 1550 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Second Year My account is over 2 years old Website
    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
    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.
    Posted Edited by 12Me21
  • #19 ✎ 13 SuperBeefJerkey Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Drawing I like to draw! Hobbies Avatar Block I didn't change my avatar for 30 days. Website 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. Posted
  • #20 ✎ 111 CyberYoshi64 Avatar Taboo I didn't change my avatar for 180 days Website Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Night Person I like the quiet night and sleep late. Express Yourself 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. Posted Edited by CyberYoshi64
1 2