EarthBound/ASM/SRAM Routines: Difference between revisions

From Data Crystal
Jump to navigation Jump to search
(Finish locating all routines and correct block end)
(Document a bunch of the routines)
Line 7: Line 7:
}}
}}


==<tt>$ef05a9-$ef062f</tt>: Reset SRAM Block==
==<tt>$ef05a9-$ef062f</tt>: Reset SRAM Block<span class="anchor" id="$ef05a9"></span>==
Zeroes out an entire <tt>0x500</tt> block of [[EarthBound/SRAM_map|SRAM]] and then rewrites the block signature ("HAL Laboratory, inc.", loaded from ROM at address [[EarthBound/ROM_map#2F0791|<tt>$ef0591</tt>]]).


==<tt>$ef0630-$ef0682</tt>: Validate SRAM Block Signature==
===Inputs===
* <tt>accumulator</tt>: SRAM block idx (<tt>0-5</tt>)


==<tt>$ef0683-$ef06a1</tt>: Validate All SRAM Block Signature==
==<tt>$ef0630-$ef0682</tt>: Validate SRAM Block Signature<span class="anchor" id="$ef0630"></span>==
Checks if the <tt>0x500</tt> block of [[EarthBound/SRAM_map|SRAM]] begins with the expected block signature ("HAL Laboratory, inc.", loaded from ROM at address [[EarthBound/ROM_map#2F0791|<tt>$ef0591</tt>]]). If the signature does not match the expectation, the block is reset via a call to [[#$ef05a9|<tt>$ef05a9</tt>]].


==<tt>$ef06a2-$ef0733</tt>: Copy SRAM Block==
===Inputs===
* <tt>accumulator</tt>: SRAM block idx (<tt>0-5</tt>)


==<tt>$ef0734-$ef077a</tt>: Calculate SRAM Block Checksum 1==
===Outputs===
* <tt>accumulator</tt>: <code>0001</code> if the block was reset. Otherwise <code>0000</code>.


==<tt>$ef077b-$ef07bf</tt>: Calculate SRAM Block Checksum 2==
==<tt>$ef0683-$ef06a1</tt>: Validate All SRAM Block Signature<span class="anchor" id="$ef0683"></span>==
Checks all <tt>0x500</tt> blocks of [[EarthBound/SRAM_map|SRAM]] to confirm they each begin with the expected block signature ("HAL Laboratory, inc.", loaded from ROM at address [[EarthBound/ROM_map#2F0791|<tt>$ef0591</tt>]]), resetting any blocks as needed. Implemented via a trivial for loop and calls to [[#$ef0630|<tt>$ef0630</tt>]].


==<tt>$ef07c0-$ef0824</tt>: Validate SRAM Block Checksums==
==<tt>$ef06a2-$ef0733</tt>: Copy SRAM Block<span class="anchor" id="$ef06a2"></span>==
Copies the entire contents of one <tt>0x500</tt> block of [[EarthBound/SRAM_map|SRAM]], overwriting another block. Implemented via a simple call to <tt>memcpy</tt> ([[EarthBound/ASM/Memory_And_String_Util_Routines#$c08eed|<tt>$c08eed</tt>]]).


==<tt>$ef0825-$ef088e</tt>: Validate Save Slot Checksums==
===Inputs===
*<tt>accumulator</tt>: Destination SRAM block idx (<tt>0-5</tt>)
*<tt>x</tt>: Source SRAM block idx (<tt>0-5</tt>)


==<tt>$ef088f-$ef0a4c</tt>: Save Persistent WRAM to SRAM Block==
==<tt>$ef0734-$ef077a</tt>: Calculate SRAM Block Checksum 1<span class="anchor" id="$ef0734"></span>==
Calculates a checksum for the data contents of one <tt>0x500</tt> block of [[EarthBound/SRAM_map|SRAM]]. (The checksum does not cover the block signature or checksums.)


==<tt>$ef0a4d-$ef0a67</tt>: Save Persistent WRAM to Save Slot==
Checksum 1 is calculated by adding together all bytes of the data contents.


==<tt>$ef0a68-$ef0b9d</tt>: Load Save Slot to Persistent WRAM==
===Inputs===
* <tt>accumulator</tt>: SRAM block idx (<tt>0-5</tt>)


==<tt>$ef0b9e-$ef0bf9</tt>: Validate SRAM==
===Outputs===
* <tt>accumulator</tt>: Checksum value


==<tt>$ef0bfa-$ef0c14</tt>: Erase Save Slot==
==<tt>$ef077b-$ef07bf</tt>: Calculate SRAM Block Checksum 2<span class="anchor" id="$ef077b"></span>==
Calculates a checksum for the data contents of one <tt>0x500</tt> block of [[EarthBound/SRAM_map|SRAM]]. (The checksum does not cover the block signature or checksums.)


==<tt>$ef0c15-$ef0c3c</tt>: Copy Save Slot==
Checksum 2 is calculated by XORing every 2-byte short of the data contents.
 
===Inputs===
* <tt>accumulator</tt>: SRAM block idx (<tt>0-5</tt>)
 
===Outputs===
* <tt>accumulator</tt>: Checksum value
 
==<tt>$ef07c0-$ef0824</tt>: Validate SRAM Block Checksums<span class="anchor" id="$ef07c0"></span>==
Checks if the checksums stored in one <tt>0x500</tt> block of [[EarthBound/SRAM_map|SRAM]] are consistent with the data contents of the block. Calculates the expected checksums via calls to [[#$ef0734|<tt>$ef0734</tt>]] and [[#$ef077b|<tt>$ef077b</tt>]].
 
===Inputs===
* <tt>accumulator</tt>: SRAM block idx (<tt>0-5</tt>)
 
===Outputs===
* <tt>accumulator</tt>: <code>0000</code> on consistent checksums. <code>ffff</code> if inconsistent.
 
==<tt>$ef0825-$ef088e</tt>: Validate Save Slot Checksums<span class="anchor" id="$ef0825"></span>==
Validates the checksums stored in two <tt>0x500</tt> blocks of [[EarthBound/SRAM_map|SRAM]], redundantly storing a single save game slot, via calls to [[#$ef07c0|<tt>$ef07c0</tt>]]. Inconsistent blocks are reset via a call to [[#$ef05a9|<tt>$ef05a9</tt>]], and if an inconsistency is found in only one block, the good block is copied over the bad block via a call to [[#$ef06a2|<tt>$ef06a2</tt>]].
 
===Inputs===
* <tt>accumulator</tt>: Save slot idx (<tt>0-2</tt>)
 
==<tt>$ef088f-$ef0a4c</tt>: Save Persistent WRAM to SRAM Block<span class="anchor" id="$ef088f"></span>==
 
==<tt>$ef0a4d-$ef0a67</tt>: Save Persistent WRAM to Save Slot<span class="anchor" id="$ef0a4d"></span>==
 
==<tt>$ef0a68-$ef0b9d</tt>: Load Save Slot to Persistent WRAM<span class="anchor" id="$ef0a68"></span>==
 
==<tt>$ef0b9e-$ef0bf9</tt>: Validate SRAM<span class="anchor" id="$ef0b9e"></span>==
 
==<tt>$ef0bfa-$ef0c14</tt>: Erase Save Slot<span class="anchor" id="$ef0bfa"></span>==
 
==<tt>$ef0c15-$ef0c3c</tt>: Copy Save Slot<span class="anchor" id="$ef0c15"></span>==


{{stub}}
{{stub}}

Revision as of 17:33, 9 June 2024

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?