A memory overflow in Sonic 2 SMS

Discussion in 'Discussion & Q&A' started by Bluestreak, Dec 16, 2020.

  1. Bluestreak

    Bluestreak Lady in red, living in dread. Member

    Joined:
    Apr 1, 2016
    Messages:
    202
    Location:
    Eastwatch Island
    So, I have just returned to hacking Sonic 2 for SMS after a yearlong hiatus. All was going well, with me trying to revamp the original game to look more aesthetically pleasing, when I finished Aqua Lake Zone. When I built it the first time, it said something about the mappings for Aqua Lake 2 being done twice. Filled with anxiety, I reverted the changes to the mappings by copy-pasting in the mappings from a backup disassembly, and redoing things from there. Finally, I do it, but now I get an error message saying I have a memory overflow in Bank 21.

    I have not added any tiles or anything. Just changed what was there. I am unsure how I caused the overflow.
     
  2. mrcat-pixel

    mrcat-pixel The Holy Cat Jr. Member

    Joined:
    May 31, 2014
    Messages:
    386
    Now, even though I don't feel like I'm too qualified to answer this question as I haven't hacked the game in a really long time, I can suggest a thing.

    The reason tile edits can enlarge file size is that the level tile data in the game is compressed. As such, editing the actual art can affect the filesize in ways that aren't always predictable.
    Here's what you can do to add one more bank to the ROM, relocate the data there and see if that solves the problem.

    In s2.asm you can find the ROM bank map, which you can change to look like this:
    Code:
    .ROMBANKMAP
    BANKSTOTAL 32
    BANKSIZE $7FF0
    BANKS 1
    BANKSIZE $0010
    BANKS 1
    BANKSIZE $4000
    BANKS 30
    .ENDRO
    
    This will give you Bank 31 of size $4000 to work with.

    Now open /src/includes/banks.asm and define that new bank:
    Code:
    ;===========================================================================
    ;        BANK 31 -
    ;            Level tile art for ALZ 1/2/3
    ;===========================================================================
    .BANK 31
    .ORG $0000
    Bank31:
    
    .include "src/includes/bank31.asm"
    Now you can create /src/includes/bank31.asm and move the ALZ art from bank21.asm to bank31.asm.

    If I have made a mistake here, then someone more knowledgeable can correct me, but this seems to work on a random disassembly I pulled up. Hope this helps!
     
    ProjectFM likes this.
  3. Bluestreak

    Bluestreak Lady in red, living in dread. Member

    Joined:
    Apr 1, 2016
    Messages:
    202
    Location:
    Eastwatch Island
    Thank you so much! I will try that soon. I'll letcha know if it works. I may just put each level in its own bank.
     
  4. Bluestreak

    Bluestreak Lady in red, living in dread. Member

    Joined:
    Apr 1, 2016
    Messages:
    202
    Location:
    Eastwatch Island
    Oddly, my disassembly seems to already has a bank 31. Within is:

    Code:
    .include "src\object_animations.asm"
    
    .include "src\object_logic\bank31_logic.asm"
    
    ;$BCCB
    .include "src\player_sprite_defs.asm"
    I added it to bank 31, and while it built successfully, it crashed upon starting the ROM on KEGA Fusion. It is interesting how the disassembly has the stuff for tiles, mappings, and layouts arranged. It is strange each bank isn't attributed to a single Zone.
     
    Last edited: Dec 19, 2020
  5. mrcat-pixel

    mrcat-pixel The Holy Cat Jr. Member

    Joined:
    May 31, 2014
    Messages:
    386
    I might have made a mistake. What happens when you add bank 32?
     
  6. Ravenfreak

    Ravenfreak Is actually a guy. Member

    Joined:
    Feb 10, 2010
    Messages:
    395
    Location:
    O'Fallon, MO
    You forgot to change the number of banks in the bank map. The first number is correct, but the last number in the bank map is still 30. The tiles would need to be added to the new bank as well if that already hasn't been done. :)