EarthBound/ASM/SRAM Routines

From Data Crystal
< EarthBound
Revision as of 17:33, 9 June 2024 by Esorth (talk | contribs) (Document a bunch of the routines)
Jump to navigation Jump to search
SRAM Routines
Game EarthBound
Start Address 0x2F07A9
End Address 0x2F0E3C
Total Length 1684 bytes (0x0694)
Back to the ROM map

$ef05a9-$ef062f: Reset SRAM Block

Zeroes out an entire 0x500 block of SRAM and then rewrites the block signature ("HAL Laboratory, inc.", loaded from ROM at address $ef0591).

Inputs

  • accumulator: SRAM block idx (0-5)

$ef0630-$ef0682: Validate SRAM Block Signature

Checks if the 0x500 block of SRAM begins with the expected block signature ("HAL Laboratory, inc.", loaded from ROM at address $ef0591). If the signature does not match the expectation, the block is reset via a call to $ef05a9.

Inputs

  • accumulator: SRAM block idx (0-5)

Outputs

  • accumulator: 0001 if the block was reset. Otherwise 0000.

$ef0683-$ef06a1: Validate All SRAM Block Signature

Checks all 0x500 blocks of SRAM to confirm they each begin with the expected block signature ("HAL Laboratory, inc.", loaded from ROM at address $ef0591), resetting any blocks as needed. Implemented via a trivial for loop and calls to $ef0630.

$ef06a2-$ef0733: Copy SRAM Block

Copies the entire contents of one 0x500 block of SRAM, overwriting another block. Implemented via a simple call to memcpy ($c08eed).

Inputs

  • accumulator: Destination SRAM block idx (0-5)
  • x: Source SRAM block idx (0-5)

$ef0734-$ef077a: Calculate SRAM Block Checksum 1

Calculates a checksum for the data contents of one 0x500 block of SRAM. (The checksum does not cover the block signature or checksums.)

Checksum 1 is calculated by adding together all bytes of the data contents.

Inputs

  • accumulator: SRAM block idx (0-5)

Outputs

  • accumulator: Checksum value

$ef077b-$ef07bf: Calculate SRAM Block Checksum 2

Calculates a checksum for the data contents of one 0x500 block of SRAM. (The checksum does not cover the block signature or checksums.)

Checksum 2 is calculated by XORing every 2-byte short of the data contents.

Inputs

  • accumulator: SRAM block idx (0-5)

Outputs

  • accumulator: Checksum value

$ef07c0-$ef0824: Validate SRAM Block Checksums

Checks if the checksums stored in one 0x500 block of SRAM are consistent with the data contents of the block. Calculates the expected checksums via calls to $ef0734 and $ef077b.

Inputs

  • accumulator: SRAM block idx (0-5)

Outputs

  • accumulator: 0000 on consistent checksums. ffff if inconsistent.

$ef0825-$ef088e: Validate Save Slot Checksums

Validates the checksums stored in two 0x500 blocks of SRAM, redundantly storing a single save game slot, via calls to $ef07c0. Inconsistent blocks are reset via a call to $ef05a9, and if an inconsistency is found in only one block, the good block is copied over the bad block via a call to $ef06a2.

Inputs

  • accumulator: Save slot idx (0-2)

$ef088f-$ef0a4c: Save Persistent WRAM to SRAM Block

$ef0a4d-$ef0a67: Save Persistent WRAM to Save Slot

$ef0a68-$ef0b9d: Load Save Slot to Persistent WRAM

$ef0b9e-$ef0bf9: Validate SRAM

$ef0bfa-$ef0c14: Erase Save Slot

$ef0c15-$ef0c3c: Copy Save Slot

So very stubbly.
This page is rather stubbly and could use some expansion.
Are you a bad enough dude to rescue this article?