Actions

SCHG How-to

Work with Water in S3K

From Sonic Retro

Written by Katelynn, inspired by Robjoe1107. Special Thanks to drx and SMTP, cause the water guide they made for Sonic 2 helped me with my explanations.

Replacing water is easy, but doing it this way only allows 5 levels to have water. It can get a little confusing, since Knuckles is thrown into the mix. The game checks whether the character is Knuckles or not, and loads water in a slightly different manner. Remember, you need a basic knowledge of hex, or you're screwed when it comes to this guide. If you don't understand this, steer clear for a while.

Switching the levels that have water in them

$007892 - If the level is AIZ act 1, jump to $0078F2. (Enable water).
$00789A - If the level is AIZ act 2, jump to $0078F2. (Enable water).
$0078B2 - If the level is HCZ (either act), jump to $0078F2. (Enable water).
$0078BA - If the level is CNZ act 2, jump to $0078F2. (Enable water).
$0078CA - If the level is ICZ act 2, jump to $0078F2. (Enable water).
$0078D8 - If the level is LBZ act 2, jump to $0078F2. (Enable water).

Now, if you want to change which level has water, you'll see the following: 0C78 XXYY FE10 66ZZ. I'll explain:

XX = level id number
YY = act number (00 is act 1, 01is act 2)
ZZ = number of bytes to jump. If you're just changing the levels that have water in them, do NOT touch these.

So, for example, if you wanted Water in Marble Garden act 1, you would change XXYY to 0200. For other level ID numbers, Look at the subsection "Level ID numbers".

Switching Water Palettes

Starting at Location $007974, the underwater palettes are loaded.

Here is an example of the underwater palette loading.

70WW 21FC 0000 7502 F62E 0C78 XXYY FE10 67ZZ

WW = Palette ID to load
XX = Level ID
YY = Act number (00 = Act 1, 01 = Act 2)
ZZ = number of bytes to jump. If you're just changing the levels that have water in them, do NOT touch these.

The first underwater palette loading is different. I've laid it out here.

70UU 0C78 WWXX FE10 6700 YYZZ

UU = Palette ID to load
WW = Level ID
XX = Act ID
YYZZ = Branch location. If you're just replacing the levels with water, do NOT touch.

I'm not sure what the difference between these two are, but the AIZ 1 MUST remain the way it is, or else the game will crash on that level.

Here are the locations:

$007974 - If the level is AIZ act 1, load palette 2B and branch to location $0079FE, loading the Underwater Palette. This is the different one, so be careful.
$007980 - If the level is AIZ act 2, load palette 2C and branch to location $0079FE, loading the Underwater Palette.
$007992 - If the level is HCZ act 1, load palette 31 and branch to location $0079FE, loading the Underwater Palette.
$0079A4 - If the level is HCZ act 2, load palette 32 and branch to location $0079FE, loading the Underwater Palette.
$0079B6 - If the level is CNZ act 2, load palette 3A and branch to location $0079FE, loading the Underwater Palette.
$0079C8 - If the level is ICZ act 2, load palette 39 and branch to location $0079FE, loading the Underwater Palette.
$0079DA - If the level is LBZ act 1, load palette 2D and branch to location $0079FE, loading the Underwater Palette. This one seems to be unused.
$0079EC - If the level is LBZ act 2, load palette 2E and branch to location $0079FE, loading the Underwater Palette.

Adding Water to more levels

This section is for advanced hackers that understand what they're doing. This allows for more levels to have water than normal. However, you will need to relocate stuff to other locations within the ROM. A good location is $00300000, the art for Sonic in Sonic 3. It isn't used, and provides PLENTY of space for use.

Let's start with the relocation. Let's select a new location for the code. Since S3K is 4 MB, you can't just place it at the end of the ROM. So, let's just put it at that location I just talked about, $00300000. For all intents and purposes, we'll be relocating to that offset. If you wish to move it elsewhere, go right ahead.

So, at offset $007892, select everything from there until you see "11FC 0001 F730". Don't copy that, just up to it. Your selection should be $60 bytes. Copy your selection and go to offset $00300000, and REPLACE $60 bytes. Don't insert, as it might mess up the game pretty badly. Chances are it will screw the game up. After that, type in "4EF9 0000 78F2". This jumps back to the water loading code.

Now, copy and paste the water tags for however many levels you want. I'll show you how to calculate the branches.(the bytes "67XX" and "66XX") First, find your branch. Then, go to the next byte, and start selecting until you reach "4EF9 0000 78F2". Count up how many bytes in a hex value that selection is, and that is your branch. example: if your selection was $58 bytes, then your branch would either be "6758", or "6658", depending on your branch type. The branch types should always remain the same way they were when dealing with the water.

Next, after you've created all the water tags you want and fixed all the branches, it's time to point to our new code. Go back to location $007892 and type in "4EF9 0030 0000" It's as simple as that.

Now, if you load it up for a test play, and it doesn't work, you screwed something up. If it does work, the palettes should be messed up. It's a simple fix if you've just replaced the water, but here it's a bit more complicated:

Changing the palettes around when adding water

Now, go to offset $007980 and select $80 bytes. Copy that. Goto offset 003000A0. This may not be where your water loading code stops, but it's easier on me, the guy explaining it. So, REPLACE $80 bytes with what you copied. after that, type in "4EF9 0000 79FE". Now, copy and paste whatever you need for however many levels you need, then calculate the branches.

Go back to location $7980 and type in "4EF9 0030 00A0" or wherever you decided to place the code. Now if you take it for a test run, and it works, you'll notice the palettes are messed up for the levels you added water to. Now it's time to extend the palette index.

Extending the palette index

This part is ridiculously easy. Just go to the palette index at offset $0A872C. Then, select $210 bytes, and copy it. Go to offset $00300200 and REPLACE $210 bytes. Now, to change the pointers. There are four of them, and all of them need to point to the new offset table. The pointers are located at the following places:

$3DC0 = 1st reference to palette table / PalLoad1
$3DDC = 2nd reference to palette table / PalLoad2
$3DF4 = 3rd reference to palette table / PalLoad_Underwater
$3E10 = 4th reference to palette table / PalLoad4

Just replace "000A 872C" with "0030 0200" at each location. There isn't a need to test run, but you can to make sure the game works. Now, onto extending the offset table. I'll tell you the format to work with.

000A 893C FC00 001F

The first two pairs of bytes are the pointer. They point directly to the palette. The next pair of bytes is the RAM location to put the palette into. And finally, the last pair of bytes is always "00XX", where XX is your number of colors/2-1. So in that example, The palette can be found at $0A893C, goes into FC00 in RAM, and has $40 colors to it. Your underwater palette should follow that exact format, and not a different one. The only difference would be your pointer.

The default palette table has 65 different palettes. In a hex value, $41. So a new palette ID would be $42. Keep track of your palette IDs, as will help you with your underwater palettes.

AFTER This, you need to fix up your palette IDs within the "Changing Palettes around when adding water" section. Read into "Switching Water Palettes" for the appropriate formats. After this, if you haven't added your palettes, now is the time. Once you do that, load it up for a test run, to make sure everything works ok, and then edit your palettes to fit your level.

Useful Machine Code things

6600 = bne.s
6100 = bsr.s
6700 = beq.s
6600 0000 = bne.w
6700 0000 = beq.w
6100 0000 = bsr.w
4EF9 0000 0000 = jmp
4EB9 0000 0000 = jsr
B07C 0000 = cmp.w #$0000,d0
0C78 0000 XXXX = cmp.w #$0000,($FFFFXXXX).w  ; XXXX = Ram Location
70XX = moveq #$XX,d0
4E75 = rts
4E71 = nop

Level IDs

Here is a listing of Level ID's.

Angel Island = 00
Hydro City = 01
Marble Garden = 02
Carnival Night = 03
Flying Battery = 04
Ice Cap = 05
Launch Base = 06
Mushroom Hill = 07
Sandopolis = 08
Lava Reef = 09
Lava Reef Boss = 16/Act Id 00 Hidden Palace
Sky Sanctuary = 0A
Death Egg = 0B

I doubt you'd have ANY reason whatsoever for having water in Doomsday Zone, but regardless, here's the ID = 0C. Act 2 is the final showdown between Sonic and Robotnik on the Death Egg.

SCHG How-To Guide: Sonic the Hedgehog 3 and Knuckles
Fixing Bugs
Fix Blue Knuckles | Fix Tails' Respawn Speeds | Fix Super Sonic Bugs
Design Choices
Fix Scattered Rings' Underwater Physics | Edit Level Select Text & Pointers | Work with Water | Make the Slots Bonus Game Rotate Smoothly
Adding Features
Restore (Sonic 2) Options Menu