Actions

Difference between revisions of "Source code/Technical information"

From Sonic Retro

m (Linked "edit mode".)
(Removed marker from Glossary.)
Line 195: Line 195:
 
| coli
 
| coli
 
| collision
 
| collision
|-
 
| marker
 
| [[Checkpoint|checkpoint]]
 
 
|-
 
|-
 
| pat
 
| pat

Revision as of 07:51, 19 March 2024

This page contains information about names and labels used in the original source code of the Mega Drive and Mega-CD games, namely Sonic the Hedgehog, Sonic the Hedgehog 2, Sonic the Hedgehog CD, Sonic the Hedgehog 3, and Sonic & Knuckles. While no full source code for any of these games has been made publicly available, several labels and constants have been found in a few places.

Global variables

Name Description
actwk[1] Action object work. An array of sprite status objects. In Sonic the Hedgehog and Sonic CD, it has 128 elements. In Sonic 2, it has 128 elements normally, but can go up to 152 elements in some cases. In Sonic 3, Sonic & Knuckles, and Sonic 3 & Knuckles, it has 110 elements.
chibi_flag[1] Chibi is Japanese slang for small. Zero when the player is in a normal state. Non-zero when the player has been shrunk by a shrink ray in Metallic Madness. Sonic CD only.
chibi_s[1] Chibi save. Stores the the value of chibi_flag at the time of the last checkpoint activation.
colibuffer[2] Collision buffer. An array of 64 words. The first word stores how many of the remaining 63 elements are free, multiplied by two. Each of the remaining elements stores the low word of a sprite status object's memory address. The sprite status objects referenced here are processed by the collision response routine. Exists from Sonic 3 onwards.
editmode[1][3] Zero when edit mode is not enabled. Non-zero if edit mode is enabled.
editno[1][3] Edit numero. When edit mode is enabled and the player is cycling through the objects that can be placed, this contains the index of the current object.
editstack[3] Copy of scralim_up, used by edit mode.
editstack2[3] Copy of scralim_n_down, used by edit mode.
edittimer[3] Two separate timers for use in edit mode: the high byte is a speed timer, while the low byte is the speed itself.
emyscorecnt[1] Enemy score count. Stores the number of enemies, multiplied by 2, that the player has destroyed while in the air. When the player lands on the ground, it's reset to zero.
generate_flag[1] Zero if the robot transporter hasn't been destroyed (yet). 1 if it has been destroyed. Sonic CD only.
gmmode[3] Game mode.
markerno[1] Marker numero. Stores the identifier of the last activated checkpoint.
pbuffer[1] Priority buffer. A multi-dimensional array, consisting of 8 levels (one for each sprite priority value), each having 64 words. The first word of each level stores how many of the remaining 63 elements are free, multiplied by two. Each of the remaining elements stores the low word of a sprite status object's memory address. The sprite status objects referenced here are displayed on the screen.
playerwk[3] Player work RAM. The first entry of actwk, reserved for the main player character.
pl_suu[1] Player lives. suu is the Japanese verb for breathing.
plpower_b[1] Player power baria. Baria is the Japanese word for barrier. Zero when the player character doesn't have a shield. 1 when the player character has a shield.
plpower_m[1] Player power muteki. Muteki is the Japanese word for invincible. Zero when not invincible. 1 when invincible.
plring[1] Player rings.
plring_s[1] Player rings save. Stores the value of plring at the time of the last checkpoint activation.
plscore[1] Player score.
pltime[1] Player time. The duration of time since starting the act. Stored as three bytes: 1/60 seconds, seconds,and minutes.
pltime_s[1] Player time save. Stores the value of pltime at the time of the last checkpoint activation.
plxposi_s[1] Player x position save. Stores the x position of the last activated checkpoint.
plyposi_s[1] Player y position save. Stores the y position of the last activated checkpoint.
projector_flag[1] Zero if the Metal Sonic projector hasn't been destroyed (yet). 1 if it has been destroyed. Sonic CD only.
ranum[1] Random number. The seed for generating the next random number.
ringbonus[1] The bonus score for the amount of rings the player has when finishing the act.
rotdir[3] Rotation direction, used by the Special Stages in Sonic the Hedgehog.
rotspd[3] Rotation speed, used by the Special Stages in Sonic the Hedgehog.
scra_v_posit[3] Scroll plane A vertical position.
scralim_n_down[3] Target bottom level boundary. The name can be parsed as "scroll A limit, new, down".
scralim_up[3] Top level boundary. The name can be parsed as "scroll A limit, up".
scrb_v_posit[3] Scroll plane B vertical position.
stageno[1] Stage numero. This variable is a combination of two values: the high byte contains the zero-based zone number, and the low byte contains the zero-based act number.
swdata1[1] This variable is a combination of two values related to controller 1: the low byte contains a bit field of buttons that have been newly pressed this frame, and the high byte contains a bit field of buttons that were already pressed this frame.
swdata2[1] This variable is a combination of two values related to controller 2: the low byte contains a bit field of buttons that have been newly pressed this frame, and the high byte contains a bit field of buttons that were already pressed this frame.
ta_flag[1] Time attack flag. Zero during regular play. Non-zero when in Time Attack mode. Sonic CD only.
time_flag[1] This flag is a combination of two values: the most significant bit stores the player currently has the power of time travel, and the rest of the byte stores a time period. If the player doesn't have the power of time travel, the time period is the current time period. If the player has the power of time travel, the time period is the one the player will travel to when time-traveling. The possible time period values are zero for past, 1 for present, and 2 for future.
time_item[1] Stores the value of the last activated Time Warp Plate. Possible values: 0 for none, 1 for future, and -1 for past. Sonic CD only.
timebonus[1] The bonus score for the length of time it took the player to finish the act.

Routines/Functions

Name Description
actionsub[1][3][4] Queues a sprite status object for display.
atan[3], atan_sonic[1] Calculates the angle formed from coordinates (0, 0) to the given (X, Y) coordinates. An implementation of the atan2 function[5]. atan_sonic is the name used in Sonic the Hedgehog and Sonic CD. atan is used from Sonic 2 onwards.
bgmset[1][4] Plays background music.
edit[3] Edit mode.
frameout[1][4] Clears (logical delete) a sprite status object.
patchg[1][3][4] Updates the sprite's animation. The name can be parsed as "pattern change".
random[1][4] Generates a random number.
scoreup[1][4] Adds obtained points to the player's score.
sinset[1][4] Gets the sine and cosine values for a given angle.
soundset[1][4] Plays a sound effect.

Constants

Name Description
word[3][2] A word, or two bytes. Has a value of 2. Based on one portion of source code, this was used to advance routine counters such that they would read from the next word in an index.

Glossary

The original programmers used certain terms and abbreviations in the source code that unintentionally obfuscate the original meaning if one isn't familiar with them.

Term Meaning
emie Amy
emy enemy
act action object
bye "I'm outta here!"
coli collision
pat pattern
pl player
pri priority

References