Difference between revisions of "Sonic the Hedgehog (16-bit)/RAM Editing"
From Sonic Retro
m (→Unused/Used RAM Addresses starting from $FF00) |
MarkeyJester (talk | contribs) m (→Main System Memory Locations: explained $A800 - $A9FF) |
||
Line 14: | Line 14: | ||
|- | |- | ||
| $A800 - $A9FF | | $A800 - $A9FF | ||
− | | | + | | 16 pixel scroll buffer primarily used for SLZ (4 bytes = one 16 pixel'd block scroll for FG and BG), this data is transfered/converter correctly to $CC00 - $CFFF (Scroll RAM cache). |
|- | |- | ||
| $AA00 - $ABFF | | $AA00 - $ABFF |
Revision as of 00:08, 11 September 2011
SCHG: Sonic the Hedgehog |
---|
|
Main System Memory Locations
This is a map of 68k memory as used by the main gameplay engine. Note that any numbers entered (for example, score or number of rings) will have to be converted to hex first.
These are the offsets in RAM. To convert them to Genecyst savestate offsets, add $2478. For use in disassemblies, simply add $FF0000 for addresses below $8000 and $FFFF0000 for addresses above or equal to $8000, for example, Sonic's top speed here is $F760, but in the disassembly it is referenced as $FFFFF760. This is useful for finding what bits of code do what when the purpose of a RAM variable is known, or conversely for figuring out the purpose of a RAM variable by looking at the referencing code.
RAM offset | Description |
---|---|
$0000 - $A3FF | Chunk mappings |
$A400 - $A7FF | Level layout (1 byte per chunk, $40 bytes per line, lines for planes A and B interlaced) |
$A800 - $A9FF | 16 pixel scroll buffer primarily used for SLZ (4 bytes = one 16 pixel'd block scroll for FG and BG), this data is transfered/converter correctly to $CC00 - $CFFF (Scroll RAM cache). |
$AA00 - $ABFF | Nemesis decompression buffer |
$AC00 - $AFFF | Sprite table (2 bytes per sprite + 2 bytes per priority level, each priority level takes $80 bytes.) |
$B000 - $C7FF | Block mappings |
$C800 - $CAFF | Sonic's art buffer. Sonic's dynamic pattern reloading routine copies the relevant art over here, from where it is DMAed to VRAM every V-int. |
$CB00 - $CBFF | Sonic previous position array (used for invincibility stars and such) |
$CC00 - $CFFF | Scroll RAM cache (sent to VRAM every frame via DMA) |
$D000 - $D7FF | Reserved object SST space |
$D800 - $EFFF | Main SST space |
$F000 - $F5FF | Flags used by the sound engine |
$F600 | Screen Mode
|
$F614-$F615 | An universal counter, mainly used for time to display screens (like the title screen and the demo mode) |
$F616-$F617 | Plane A y-position for previous frame |
$F618-$F619 | Plane B y-position for previous frame |
$F61A-$F61B | Plane A x-position for previous frame |
$F61C-$F61D | Plane B x-position for previous frame |
$F61E-$F61F | Value of $F71C for previous frame |
$F620-$F621 | Value of $F718 for previous frame |
$F680 | Address queue for Pattern Load Cues |
$F700-$F701 | Plane A x-position |
$F704-$F705 | Plane A y-position |
$F708-$F709 | Plane B x-position |
$F70C-$F70D | Plane B y-position |
$F73E-$F73F | Y-camera position, based on Sonic ($60 = default) |
$F744 | Scroll Hold Flag (set to stop all scrolling dead) |
$F754-$F755 $F756-$F757 $F758-$F759 $F75A-$F75B |
Bitfields used by the scrolling engine |
$F760-$F761 | Sonic's Top Speed |
$F762-$F763 | Sonic's Acceleration |
$F764-$F765 | Sonic's Deceleration |
$F7AA | Screen Lock Flag (Set to lock screen) |
$F7C8 | Control Lock Flag (Set to lock controls) |
$FA00-$FA7F | Target underwater palette |
$FA80-$FAFF | Normal underwater palette |
$FB00-$FB7F | Normal palette |
$FB80-$FBFF | Target palette (calling Pal_FadeTo will brighten the normal palette until it is the same as the target palette) |
$FC00-$FD7F | Destroyable object state table |
$FE02 | Restart Level Flag (Set to restart level) |
$FE04 | Level Timer |
$FE08 | Set if debug mode is being used |
$FE10-$FE11 | Zone/Act |
$FE12 | Lives |
$FE14 | Remaining Air (When underwater) |
$FE16 | Last Special Stage Entered |
$FE18 | Continues |
$FE1C | Lives Counter (Set to update lives total on screen) |
$FE1D | Ring Counter (Set to update rings total on screen) |
$FE1E | Time Counter (Set to update current time on screen) |
$FE1F | Score Counter (Set to update score total on screen) |
$FE20-$FE21 | Rings |
$FE22-$FE25 | Time |
$FE26-$FE29 | Score |
$FE2C | Shield Flag (Set to take a single hit without losing rings) |
$FE2D | Invincibility Flag (Set to make Sonic invincible) |
$FE2E | Speed Shoes Flag (Set to activate speed shoe physics) |
$FE2F | Unused flag (cleared when level starts but purpose is unknown) |
$FE30 | Lamppost Counter |
$FE57 | Emeralds |
$FFF4 | Credits Index Number |
$FFFA | Debug Flag (Set to enable debug mode) |
Unused/Used RAM Addresses starting from $FF00
RAM Adresses | Size | Status |
---|---|---|
$FF00 - $FF0F | $10 | Unused |
$FF10 - $FF13 | $04 | Used |
$FF14 - $FF17 | $04 | Unused |
$FF18 - $FF37 | $20 | Used |
$FF38 - $FF7F | $48 | Unused |
$FF80 - $FF85 | $06 | Used |
$FF86 - $FFB7 | $32 | Unused |
$FFB8 - $FFBB | $04 | Used |
$FFBC - $FFDF | $24 | Unused |
$FFE0 - $FFE7 | $08 | Used |
$FFE8 - $FFE9 | $02 | Unused |
$FFEA - $FFF1 | $08 | Used |
$FFF2 - $FFF4 | $03 | Used |
$FFF5 - $FFF7 | $03 | Unused |
$FFF8 - $FFFF | $08 | Used |
Object Status Table Format
The Object Status Table is located at RAM address $D000. Each entry is $40 bytes long. Here is a list of all the values for one entry in the OST:
Offset | Size | Description | |||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
$00 | byte | Object type | |||||||||||||||||||||||||||
$01 | byte | Render flags. The bitfield looks like this:
| |||||||||||||||||||||||||||
$02 | word | The lower 11 bits of this represent the starting art block. This is an index into an array of cells; to get the actual address, multiply by $20. Bits 14 and 13 are used to specify the default palette line the sprite uses, and bit 15 is the priority flag - if this is set, the sprite will be given high priority. | |||||||||||||||||||||||||||
$04 | long | Mappings offset | |||||||||||||||||||||||||||
$08 | word |
| |||||||||||||||||||||||||||
$0A | word |
| |||||||||||||||||||||||||||
$0C | word |
| |||||||||||||||||||||||||||
$0E | word |
| |||||||||||||||||||||||||||
$10 | word | Horizontal (X) velocity | |||||||||||||||||||||||||||
$12 | word | Vertical (Y) velocity | |||||||||||||||||||||||||||
$14 | word | Ground velocity (inertia). | |||||||||||||||||||||||||||
$16 | byte | Vertical radius of the object's hitbox. | |||||||||||||||||||||||||||
$17 | byte | Horizontal radius of the object's hitbox. | |||||||||||||||||||||||||||
$18 | byte | Sprite priority (00 = front, 03 = behind). | |||||||||||||||||||||||||||
$19 | byte | Horizontal radius of the object's visible sprite. | |||||||||||||||||||||||||||
$1A | byte | Current animation frame to display. i.e, the frame currently being displayed on-screen, according to the animation script (currently parsed mappings frame, in other words). | |||||||||||||||||||||||||||
$1B | byte | Current frame in animation script. i.e, the frame entry IN the animation script being currently processed. | |||||||||||||||||||||||||||
$1C | byte | Animation number. When an animation ID is moved here, it's processed and displayed. | |||||||||||||||||||||||||||
$1D | byte | Restart animation flag (when $1D is not equal to $1C, animation restarts) | |||||||||||||||||||||||||||
$1E | byte | Animation frame duration (time until next frame). | |||||||||||||||||||||||||||
$20 | byte | Collision response bitfield. Tells what the object will do if hit by the character. The bitfield is in the format TTSS SSSS. TT is the type of collision - 00 is enemy, 01 increments the routine counter, 10 is harm, and 11 is "special", used for the starpole, caterkiller, yadrin and some other objects. SSSSSS is the size, lifted from a lookup table in the collision response routine. | |||||||||||||||||||||||||||
$21 | byte | Custom collision property, for special interaction with Sonic. This is used by bosses, badniks, bumpers and other objects. The way in which this byte is used is different for each object. Bosses use this byte as a hit counter. | |||||||||||||||||||||||||||
$22 | byte | Status bitfield.
Counting from the least significant bit:
| |||||||||||||||||||||||||||
$23 | byte | Respawn index reference number, used by badniks, rings and monitors. Each destroyable object is assigned an index number (01, 02, 03 etc.) which refers to a list at $FC00 in the RAM. | |||||||||||||||||||||||||||
$24 | byte | Routine counter. | |||||||||||||||||||||||||||
$25 | byte | Second routine counter. This is used for some of the more complicated objects. | |||||||||||||||||||||||||||
$26 | word | Angle. | |||||||||||||||||||||||||||
$28 | byte | Object subtype. For example, the current monitor selected. See the Object List above for values. Has a different meaning for Sonic. | |||||||||||||||||||||||||||
$29-$3F | Object's scratch RAM | ||||||||||||||||||||||||||||
Sonic-specific variables | |||||||||||||||||||||||||||||
Offset | Size | Description | |||||||||||||||||||||||||||
$22 | byte | Special bitfield. Counting from the least significant bit:
You can add the hex values together to use multiple settings at once. Also notice that the first 3 bits (0-2) are used in the character object as a second routine counter. | |||||||||||||||||||||||||||
$28 | byte | Seconds of air left. Usually $1E; it decrements every second while the player is underwater. Beeps on $18, $13, and $0E. Countdown starts on $0B. | |||||||||||||||||||||||||||
$29-$2F | Unused (scratch RAM) | ||||||||||||||||||||||||||||
$30-$31 | word | Remaining invulnerability time. Starts at $0078 after Sonic is hit, and seems to decrement every frame until it reaches $0000. | |||||||||||||||||||||||||||
$32-$33 | word | Remaining time of invincibility. | |||||||||||||||||||||||||||
$34-$35 | word | Remaining time of Speed Shoes. | |||||||||||||||||||||||||||
$36 | byte | Angle of ground at Sonic's front collision hot spot ($03 is "edge of ground") | |||||||||||||||||||||||||||
$37 | byte | Angle of ground at Sonic's rear collision hot spot | |||||||||||||||||||||||||||
$39 | byte | Unused. | |||||||||||||||||||||||||||
$3A-$3B | word | Unused. | |||||||||||||||||||||||||||
$3C | byte | Set if jumping. | |||||||||||||||||||||||||||
$3D | byte | OST index of object currently being stood on. (multiply by $40 and add $D000 to get the object's address). | |||||||||||||||||||||||||||
$3E-$3F | word | Control lock timer. Set to lock left and right controls after hitting a spring or running down a slope. | |||||||||||||||||||||||||||
Boss Variables | |||||||||||||||||||||||||||||
Offset | Size | Description | |||||||||||||||||||||||||||
$21 | byte | Hit counter. Number of hits it takes to defeat a boss. | |||||||||||||||||||||||||||
$30 | word | X position | |||||||||||||||||||||||||||
$38 | word | Y position | |||||||||||||||||||||||||||
$3E | byte | Number of times to flash when hit |