News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: First SRAM hack: Boxxle for Game Boy  (Read 415 times)

CecilMcW00t

  • Jr. Member
  • **
  • Posts: 5
    • View Profile
First SRAM hack: Boxxle for Game Boy
« on: March 16, 2019, 10:53:51 pm »
I posted recently about my dream of adding SRAM to games with high score tables and I got a bit overwhelmed. I ended up deciding to take on a simpler but similar project I've been wanting to do. Adding SRAM to games which use passwords. I've noticed a couple other users have done a few of these so I studied what they did. I want to focus on the Game Boy line of consoles as that is one of my favorite consoles of all time.

Boxxle has a simple 4 digit password. I was able to find where the game stores the data for stages that you have cleared. Afterwards, I did some some hex edits to point that data to the SRAM area. I already knew how to do this from working on a Tetris SRAM hack another user, Capaneus, was working on. But, I ran into the same problem he ran into. The saves work, but it requires a save file filled with zeroes on first boot. Otherwise, the first set of levels are already cleared.

Regarding other things I did, I changed the ROM type to ROM+RAM+BATTERY and the RAM size to 32 KiB. From what I understand, if I use the MBC1 ROM type, I can add code which will initialize the SRAM on first boot. Someone posted some code which will do this on another forum, but when I tried to compile the code with a thumb compiler I downloaded from PokeCommunity.com, every single line in the code spit out an error. I can post the code in this thread if anyone wants to help me troubleshoot it.

I'm still very much a noob at this, so if anything I said up there is totally wrong or stupid, please let me know.

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 6810
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: First SRAM hack: Boxxle for Game Boy
« Reply #1 on: March 17, 2019, 05:13:06 pm »
A Thump compiler? You mean ARM?
Well, that is your first problem. The original Game Boy (and GBC, since it's just an upgrade) don't use an ARM, they use a Z80.

Of course that likewise mean example code written for ARM is useless as well.
You will need to know Z80 ASM.
If you do, it should be a fairly easy hack to make, assuming you can find where in the code to replace the password menu with a load option.
I don't think SRAM support for a mapperless ROM is defined, so for maximum emulator compatibility you would want to do a mapper hack to MBC1 or MBC2, the latter would be more likely in a real game. Though you might have to worry about the mapper SRAM-lock functionality.
Also once the header is changed (to change the mapper) then the GB/GBC boot ROM won't work unless the header is fixed (though that will only be an issue on hardware or on emulators with "use boot ROM" enabled). I don't think it's really a hard problem to fix once you know how to use a debugger, and not really something to worry about anyways until as a last step of the hack (use emulation without the boot ROM to test the hack itself).
« Last Edit: March 17, 2019, 05:23:14 pm by KingMike »
"My watch says 30 chickens" Google, 2018

CecilMcW00t

  • Jr. Member
  • **
  • Posts: 5
    • View Profile
Re: First SRAM hack: Boxxle for Game Boy
« Reply #2 on: March 17, 2019, 05:32:03 pm »
Well... That would certainly explain a lot! The place I got the compiler from was using it for GBA games. Game Boy Advance uses the ARM language, correct? I should have known it was different from the Z80 that GB and GBC use. I still have a lot to learn.

Psyklax

  • Hero Member
  • *****
  • Posts: 951
    • View Profile
    • Psyklax Translations
Re: First SRAM hack: Boxxle for Game Boy
« Reply #3 on: March 18, 2019, 02:19:49 am »
I want to focus on the Game Boy line of consoles

Well there's your first problem: GB and GBA are not in a 'line'. :) They use different CPUs - just because they both have 'Game Boy' in their names doesn't mean they're the same. ;) Any ARM assembly someone posted isn't going to work on a Z80, but I'm sure the actual code necessary won't be too complicated.

Just for reference, NES uses 6502, SNES uses 65816, GB uses Z80, GBA uses ARM. Thus, code is incompatible between each of them (although the 65816 is a more advanced version of the 6502 so actually the code can be pretty similar, and could go from NES to SNES but not necessarily vice versa).

I hope you don't mind me saying, but I have a bit of a dislike for SRAM hacks on principle - since most hacked games are played on emulators which have save states anyway, and a lot of flash carts have save states too - but Sokoban is probably the worst example of replacing passwords with save states. Four digits! Anyone can easily enter four digits, and it's both predictable and portable between games (unlike a save file).

A more logical hack would be for something like Little Ninja Brothers on NES, which being like an RPG has long unpredictable passwords, so using a save file would actually be quite useful there. But hacking is about the journey not the destination, so perhaps a Sokoban game is a good first step, and you can do more complex ones in future. :)

CecilMcW00t

  • Jr. Member
  • **
  • Posts: 5
    • View Profile
Re: First SRAM hack: Boxxle for Game Boy
« Reply #4 on: March 18, 2019, 02:36:36 am »
Yeah, I was just looking for something simple to practice on. I know it isn't practical. And yes, when I said the "Game Boy" line, I should have specified I meant strictly the Game Boy and the Game Boy Color.

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 6810
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: First SRAM hack: Boxxle for Game Boy
« Reply #5 on: March 18, 2019, 10:42:06 am »
Four digits! Anyone can easily enter four digits, and it's both predictable and portable between games (unlike a save file).

Blizzard bothered with a SRAM feature for the GBA port of The Lost Vikings (replacing the four-character passwords).
Wouldn't be surprised then if the Blackthorne port did as well.
If you want to see the most questionable use of save feature in a game.
Reportedly Pocahontas for Genesis was originally planned to use a save feature, reportedly by non-programmers, until the programmer told them it only needed passwords.
"My watch says 30 chickens" Google, 2018