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

Author Topic: [HELP] Restoring the Kirby sprite (Debug menu) in EarthBound (for MaternalBound)  (Read 3785 times)

ShadowOne333

  • Hero Member
  • *****
  • Posts: 995
    • View Profile
Good day, RomHacking community.

I am seeking help with one issue I stumbled upon, which I've been trying to fix throughout half a month already, but haven’t been able to do so at the moment, and it’s something every EarthBound ROM compiled with CoilSnake suffers from, including clean ROMs without modifications.

You see, there’s this particular Debug menu that uses Kirby as its cursor sprite, more widely known as the Boot-up Debug Menu. For those that are not familiar with this, here's the entry in The Cutting Room Floor for it and how to enable it:
https://tcrf.net/EarthBound/Boot-Up_Debug_Menu

Once you enable said Debug menu, and you start the game, you enter directly into the Menu itself with Kirby making a neat cameo appearance:


However, when you try to do this with a compiled CoilSnake ROM, Kirby’s sprite does one of two things:
  • Does not appear at all
  • Is a garbled mess.
Here are some examples of that:

NOTE: The garbled effect might vary, I sometimes get other portions of the sprite to appear, or with other colours, etc

(Another side-effect to this is that the palette for the Windows inside the “View Map” option show random colours instead of the pinkish one from the Cutting Room Floor site)

You can try it out for yourself, make a clean dump of EB’s files alongside its script, and then compile it back, then try to boot-up this Debug menu with the cheat codes and you will have a similar result.

I stumbled into this when trying to fix the options of the Debug Menu found inside the “View Map” option.
I ended up fixing the options without issues, but for some reason I cannot seem to fix Kirby’s sprite here.

I tried to fix this by repointing stuff from the Debug bank (according to Data crystal) to no success, I even grabbed the Hex data of Kirby’s sprite and put it in a CCS file with its newly repointed pointer, but nothing.


From the test that I have done, I still haven't narrowed down what the culprit of the problem might be.
I think it is related to the Title Screen module in CoilSnake, but I'm unsure yet.
If anyone knows better, please let me know.
I’ve been trying hard to restore it, but so far I haven’t had any luck at all.

So I was wondering if perhaps someone here could lend a helping hand on restoring this Kirby sprite.
There are two ways one can go about restoring the sprite:

  • Checking out which CoilSnake build broke it.
    It has to be a commit between CoilSnake 2.3.1 and CoilSnake 3.0, or commits between June 14th, 2017 and January 24th, 2017, since the Kirby sprite shows up fine with ROMs compiled with CoilSnake 2.3.1, but they started to fail on 3.0 and onwards.
  • Make a fix to the compiled ROM directly.
    Perhaps taking the data from an original ROM and implementing it into a compiled one.
    I just need to know what changes are required for the fix to hopefully implement them into MaternalBound's CCS files and make the fix work on any compiled ROM afterwards.

I am leaning more towards the later, perhaps finding out why the sprite is disappearing on compiled ROMs and how to fix it in a compiled one could lead to a fix to CoilSnake source, but right now all I want to do is simply fix it in a compiled ROM, no need to touch the CoilSnake source, I simply want to know what is causing the sprite to not appear and how to fix it on my end.

Here's the MaternalBound source:
https://github.com/ShadowOne333/MaternalBound

And here's a link to CoilSnake to compile it:
http://mrtenda.github.io/CoilSnake/


So far that is the only issue I’ve come across.
Perhaps I am being to nitpicky or OCD-driven, but I’d like to have this feature restored, more so because it seems to be something that CoilSnake is doing during compilation.

Any kind of help would be greatly appreciated!
Thank you!
« Last Edit: October 04, 2018, 05:58:56 pm by ShadowOne333 »

ShadowOne333

  • Hero Member
  • *****
  • Posts: 995
    • View Profile
Following on this issue.
I haven't been able to fix it yet, but PK Hack user d-man has been helping to narrow down the problem.

He did some tests on his own to a completely clean ROM and compiled it back with CoilSnake.
He started compiling a ROM with no changes made to it and adding certain ranges of addresses into the "used_ranges.yml" file. This YML file tells CoilSnake what addresses NOT to touch during compilation.

Right now, it has come down to the following ranges (the ones with # are commented out):

Code: [Select]
- (0x17E83F, 0x17FFFC)
# - (0x180000, 0x18FFFF)
 - (0x190000, 0x19FFFF)
# - (0x1A0000, 0x1AFFFF)
 - (0x1B0000, 0x1BFFFF)
 - (0x1C0000, 0x1CFFFF)
 - (0x1D0000, 0x1DFFFF)
 - (0x1E0000, 0x1EFFFF)
 - (0x1F0000, 0x1FB36D)
(They all seem to be related to tileset data according to Data Crystal)

However, I cannot test this on my own, as when I try to add these ranges on MaternalBound, I run out of free space on the ROM to compile it. So we still have yet to narrow it down even further.

One thing of importance, it seems that whenever CoilSnake starts its compilation, it frees-up these ranges, since the original data that used to go here gets repointed and moved into another place in the ROM.
To add to this even further, it seems that once CoilSnake frees up these ranges, what usually gets placed in this addresses is the Title Screen data. I'm not sure if this has something to do with it or not, but perhaps the Title Screen data could be somehow related to the Kirby sprite.

I will try to debug this even further, but if someone else has more insight or figures out how to restore the sprite, please let us know!

emerilfryer

  • Jr. Member
  • **
  • Posts: 25
    • View Profile
Haven't had much time to check this. But a starter. Kirby's sprite is raw 4-bpp data. Uploaded to vram every frame during debug menu. Fixed pointer.

Code: [Select]
DMA[0]: CPU->PPU Mode:1 0xEFEFB7->0x2118 Bytes:200 (inc) V:230 VRAM: 4000 (1,0) word


$EF/E556 C2 31       REP #$31                A:0000 X:0000 Y:FFC9 D:1E00 DB:7E S:1FEE P:envmxdIZc HC:0496 VC:240 FC:08 I:00
$EF/E558 0B          PHD                     A:0000 X:0000 Y:FFC9 D:1E00 DB:7E S:1FEE P:envmxdIZc HC:0520 VC:240 FC:08 I:00
$EF/E559 7B          TDC                     A:0000 X:0000 Y:FFC9 D:1E00 DB:7E S:1FEC P:envmxdIZc HC:0594 VC:240 FC:08 I:00
$EF/E55A 69 EE FF    ADC #$FFEE              A:1E00 X:0000 Y:FFC9 D:1E00 DB:7E S:1FEC P:envmxdIzc HC:0612 VC:240 FC:08 I:00
$EF/E55D 5B          TCD                     A:1DEE X:0000 Y:FFC9 D:1E00 DB:7E S:1FEC P:envmxdIzC HC:0636 VC:240 FC:08 I:00
$EF/E55E A9 B7 EF    LDA #$EFB7              A:1DEE X:0000 Y:FFC9 D:1DEE DB:7E S:1FEC P:envmxdIzC HC:0654 VC:240 FC:08 I:00
$EF/E561 85 0E       STA $0E    [$00:1DFC]   A:EFB7 X:0000 Y:FFC9 D:1DEE DB:7E S:1FEC P:eNvmxdIzC HC:0678 VC:240 FC:08 I:00
$EF/E563 A9 EF 00    LDA #$00EF              A:EFB7 X:0000 Y:FFC9 D:1DEE DB:7E S:1FEC P:eNvmxdIzC HC:0718 VC:240 FC:08 I:00
$EF/E566 85 10       STA $10    [$00:1DFE]   A:00EF X:0000 Y:FFC9 D:1DEE DB:7E S:1FEC P:envmxdIzC HC:0742 VC:240 FC:08 I:00
$EF/E568 A0 00 40    LDY #$4000              A:00EF X:0000 Y:FFC9 D:1DEE DB:7E S:1FEC P:envmxdIzC HC:0782 VC:240 FC:08 I:00
$EF/E56B A2 00 02    LDX #$0200              A:00EF X:0000 Y:4000 D:1DEE DB:7E S:1FEC P:envmxdIzC HC:0806 VC:240 FC:08 I:00
$EF/E56E E2 20       SEP #$20                A:00EF X:0200 Y:4000 D:1DEE DB:7E S:1FEC P:envmxdIzC HC:0830 VC:240 FC:08 I:00
$EF/E570 A9 00       LDA #$00                A:00EF X:0200 Y:4000 D:1DEE DB:7E S:1FEC P:envMxdIzC HC:0854 VC:240 FC:08 I:00
$EF/E572 22 16 86 C0 JSL $C08616[$C0:8616]   A:0000 X:0200 Y:4000 D:1DEE DB:7E S:1FEC P:envMxdIZC HC:0872 VC:240 FC:08 I:00

edit: Sprite looks okay in vram after CoilSnake project upgrade. Oam table gets smacked.

Code: [Select]
ef:f5bd = normal oam table

$C0/8BA1 BD C4 24    LDA $24C4,x[$7E:24C4]   A:FFFF X:0000 Y:FFFF D:1F00 DB:7E S:1FF6 P:eNvmxdIzc HC:1196 VC:046 FC:05 I:00
$C0/8BA4 8D 0B 00    STA $000B  [$7E:000B]   A:00EF X:0000 Y:FFFF D:1F00 DB:7E S:1FF6 P:envmxdIzc HC:1242 VC:046 FC:05 I:00
$C0/8BA7 DA          PHX                     A:00EF X:0000 Y:FFFF D:1F00 DB:7E S:1FF6 P:envmxdIzc HC:1282 VC:046 FC:05 I:00
$C0/8BA8 BD 04 24    LDA $2404,x[$7E:2404]   A:00EF X:0000 Y:FFFF D:1F00 DB:7E S:1FF4 P:envmxdIzc HC:1316 VC:046 FC:05 I:00
$C0/8BAB 48          PHA                     A:F5BD X:0000 Y:FFFF D:1F00 DB:7E S:1FF4 P:eNvmxdIzc HC:1362 VC:046 FC:05 I:00
$C0/8BAC BD 84 24    LDA $2484,x[$7E:2484]   A:F5BD X:0000 Y:FFFF D:1F00 DB:7E S:1FF2 P:eNvmxdIzc HC:0032 VC:047 FC:05 I:00
$C0/8BAF A8          TAY                     A:0034 X:0000 Y:FFFF D:1F00 DB:7E S:1FF2 P:envmxdIzc HC:0078 VC:047 FC:05 I:00
$C0/8BB0 BD 44 24    LDA $2444,x[$7E:2444]   A:0034 X:0000 Y:0034 D:1F00 DB:7E S:1FF2 P:envmxdIzc HC:0096 VC:047 FC:05 I:00
$C0/8BB3 AA          TAX                     A:0034 X:0000 Y:0034 D:1F00 DB:7E S:1FF2 P:envmxdIzc HC:0142 VC:047 FC:05 I:00
$C0/8BB4 68          PLA                     A:0034 X:0034 Y:0034 D:1F00 DB:7E S:1FF2 P:envmxdIzc HC:0160 VC:047 FC:05 I:00
$C0/8BB5 22 D5 8C C0 JSL $C08CD5[$C0:8CD5]   A:F5BD X:0034 Y:0034 D:1F00 DB:7E S:1FF4 P:eNvmxdIzc HC:0200 VC:047 FC:05 I:00

ef:f5bd is actually okay but new Coil patcher now reads oam from dc:f5bd

Code: [Select]
Original rom
$80/A0FC E2 20       SEP #$20                A:0000 X:0000 Y:0000 D:1D00 DB:7E S:1FED P:envmxdIZc HC:0294 VC:045 FC:05 I:00
$80/A0FE A5 8E       LDA $8E    [$00:1D8E]   A:0000 X:0000 Y:0000 D:1D00 DB:7E S:1FED P:envMxdIZc HC:0318 VC:045 FC:05 I:00
$80/A100 8D 0B 00    STA $000B  [$7E:000B]   A:00EF X:0000 Y:0000 D:1D00 DB:7E S:1FED P:eNvMxdIzc HC:0344 VC:045 FC:05 I:00



Coil rom
80a0fc sep #$20               A:0000 X:0000 Y:0000 S:1fed D:1d00 DB:7e nvmxdIZc V:243 H: 528 F:59
80a0fe lda #$dc               A:0000 X:0000 Y:0000 S:1fed D:1d00 DB:7e nvMxdIZc V:243 H: 586 F:59
80a100 sta $000b     [7e000b] A:00dc X:0000 Y:0000 S:1fed D:1d00 DB:7e NvMxdIzc V:243 H: 598 F:59

And there's our problem. So quick bandage would be to either
(1) find empty space in bank dc and move kirby oam table / ptr there
(2) find out why Coil hard-coded that bank dc and let authors fix it
« Last Edit: October 27, 2018, 05:10:49 pm by emerilfryer »

ShadowOne333

  • Hero Member
  • *****
  • Posts: 995
    • View Profile
Sorry, I forgot to reply back here, but the problem was found thanks to DarkSamus993, and I was able to make a workaround for this through ccscript :P
You can check out the problem in detail here:
https://github.com/mrtenda/CoilSnake/issues/166#issuecomment-431865231

I think I also explained how I made the workaround.
I tried to go into much detail as possible, and turns out the issue was related to the Title Screen module, which was changing said bank for the character layout of the Title Screen itself.

So I got both things you suggest working, I managed to move the Kirby assembly to bank $DE (it's DE in my most recent hack) and I also contacted the developer of CoilSnake letting him know about it, though I think someone else might tackle that issue in a subsequent version.

Still, though, I gotta thank you for dropping by and lending a hand to this problem :)
You came up exactly with the same correction that was found, and if it wouldn't have been found by now, your comment would for sure have done it!

Thanks again for your time and for posting to this issue, @emerilfryer!
I really... REALLY appreciate it!