<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ASM/Readme.md - fork/training-mode-ce @ master</title>
<meta name="description" content="ASM/Readme.md in fork/training-mode-ce at master.">
<meta property="og:title" content="ASM/Readme.md - fork/training-mode-ce @ master">
<meta property="og:description" content="ASM/Readme.md in fork/training-mode-ce at master.">
<meta property="og:type" content="website">
<meta property="og:site_name" content="git.julia.blue">
<link rel="stylesheet" href="/css/style.css?v=62">
<script type="module" src="/js/main.js?v=62"></script>
</head>
<body>
<main data-ref="master" data-tip="042fd346162a34cda5017c394f566ae94f5282a7">
<noscript>
  <div class="callout">
    <p>
      hey! this is a static git repo viewer. commit diffs, file history,
      older commits and other revisions won't load without javascript.
    </p>
    <p>
      you are still able to view source files on branch/tag tips,
      but the experience is degraded.
    </p>
  </div>
</noscript>
<header class="repo"><div>
<h1>fork/training-mode-ce</h1>
</div>
<pre class="clone">git clone https://git.julia.blue/fork/training-mode-ce</pre>
</header>
<p class="snapshot-commit"><span class="commit-author">Alex Harrison</span><span class="commit-message" data-commit="a2748249f56a38ae847f18587c31f5bcd9559045">update docs</span><span class="snapshot-sha sha" data-commit="a2748249f56a38ae847f18587c31f5bcd9559045">a274824</span><time datetime="2025-07-30T13:57:45-06:00" title="2025-07-30 13:57:45 -0600">2025-07-30</time></p>
<header class="topbar"><details class="switcher"><summary>master</summary><div class="menu"><strong>branches</strong><a class="current" href="/fork/training-mode-ce/ref/master/">master</a><a href="/fork/training-mode-ce/ref/nix/">nix</a><a href="/fork/training-mode-ce/ref/techchase-camera/">techchase-camera</a><a class="all" href="/fork/training-mode-ce/refs">all refs →</a></div></details><nav class="crumbs"><a href="/fork/training-mode-ce/">training-mode-ce</a> / <a href="/fork/training-mode-ce/ref/master/tree/ASM/">ASM</a> / <span class="cur">Readme.md</span></nav>
<span class="view-stats"><span>5.1 KiB</span><span>107 lines</span></span><span class="actions"><a class="raw" href="/fork/training-mode-ce/raw/16a3bf1fbb28023e2f8c67a8054bb5bed2778669/ASM/Readme.md">raw</a></span></header>
<div class="markdown-view"><input type="radio" name="markdown-view" id="markdown-rendered" checked><label for="markdown-rendered">rendered</label><input type="radio" name="markdown-view" id="markdown-code"><label for="markdown-code">code</label><section class="readme rendered"><h1>ASM</h1>
<p>Aitch: I don't write much melee asm, but here's some things I've picked up by hacking on unclepunch's asm.
Here are some things you should know before diving into here, and some questions I have.</p>
<p>Clown: I have written a good amount of melee asm. I've added some useful information I have here. If you
have any questions, reach out on the discord.</p>
<h2>Overview</h2>
<p>PowerPC (PPC) is an instruction set architecture (ISA) that used to be used in
computers and game consoles in the 90s and 2000s, notably in several Apple products,
the Xbox 360, the PS3, and the GC/Wii/Wii U. Specifically, the GameCube and Wii use an embedded,
big-endian, 32-bit version of PowerPC on their CPUs.</p>
<h2>Resources:</h2>
<ul>
<li><a href="https://files.decomp.dev/ppc_isa.pdf">IBM PPC User Instruction Set Architecture</a></li>
<li><a href="https://files.decomp.dev/IBM_PPC_Compiler_Writer&#x27;s_Guide-cwg.pdf">IBM PPC Compiler Writer's Guide</a></li>
<li><a href="https://mariokartwii.com/showthread.php?tid=1114">Beginner to advanced tutorials for PowerPC</a></li>
<li><a href="https://celestialamber.github.io/rlwinm-clrlwi-decoder/">rlwinm/rlwimi/rlwmn Decoder</a></li>
<li><a href="https://github.com/doldecomp/melee">Decompilation project for Melee</a></li>
<li><a href="https://github.com/doldecomp/melee/wiki/Decomp-Intro">Decomp Intro</a></li>
</ul>
<p>You should prioritize reading Section 2 and Appendix A of the Compiler's Writing Guide. Also,
Section 1.6 and Appendix B of the User Instruction Set Architecture.</p>
<p>The decompilation project is useful for understanding Melee's code. If you have an address of a Melee function,
you can grep the decomp codebase and see if it's been decompiled. Even if it hasn't been, it's easier to
search around for related code within that repo than it is to work within the dolphin debugger. If
you're interested in learning more, you should read the Decomp Intro.</p>
<h2>Notes:</h2>
<ul>
<li><strong>The numbers 0..32 are allowed as registers!</strong>
You may run into silent errors where you expect to use a constant value but end up using a register.
The most common place to see this are in math instructions - <code>addi r3, r3, 10</code> can be accidentally written as <code>add r3, r3, 10</code> and introduce a bug.</li>
<li>If you see a load with offset around 0x23ec-0x2424 in OSD related code,
it's probably reading or writing to <code>struct MEX</code> or <code>struct TM</code> in <code>struct FighterData</code> in <code>MexTK/include/fighter.h</code>.</li>
<li><strong>Don't be afraid of the dolphin debugger!</strong>. Use the latest version of dolphin.</li>
<li>Everything in both <code>ASM/Globals.s</code> and <code>ASM/training-mode/Globals.s</code> are helper macros.
These are imported into most other ASM files. <code>ASM/Globals.s</code> is outdated, use <code>ASM/training-mode/Globals.s</code> for new asm files.</li>
</ul>
<h3><code>mflr</code></h3>
<p>Because ASM files could be placed anywhere, you can't exactly just load a label as an address in a register.
To get around this, there is an extremely common pattern using the <code>mflr</code> instruction.
When the <code>bl &lt;label&gt;</code> instruction is followed by an <code>mflr &lt;r&gt;</code> instruction, the address right after the <code>bl</code> is placed in <code>r</code>.
So often you will see something like:</p>
<pre>bl SkipData
.long 12345     # important data
SkipData:
mflr r4
lwz r3, 0x0(r4) # r3 now contains 12345
</pre>
<h3><code>EventJumpTable</code></h3>
<p>If you see the macro <code>EventJumpTable</code> in an ASM file somewhere, you're in for a wild ride.
This macro is defined as:</p>
<pre>.macro EventJumpTable
  bl Minigames
  bl GeneralTech
  bl SpacieTech
.endm
</pre>
<p>This allows event asm code to find global event data.
This macro is not useful by itself. If this macro is used, there will be another macro imported (eg. <code>EventNameStrings</code>).
That other macro will have three labels: <code>Minigames</code>, <code>GeneralTech</code>, and <code>SpacieTech</code>.
Under each label, for each event, with be ANOTHER macro for the data for that event.</p>
<p>There will also be definitions for EventID and PageID, and this piece of code:</p>
<pre>SkipPageList:
  mflr r4                  #Jump Table Start in r4
  mulli r5, PageID, 0x4    #Each Pointer is 0x4 Long
  add r4, r4, r5           #Get Event's Pointer Address
  lwz r5, 0x0(r4)          #Get bl Instruction
  rlwinm r5, r5, 0, 6, 29  #Mask Bits 6-29 (the offset)
  mr r3,EventID
  add r4, r4, r5           #Gets ASCII Address in r4
</pre>
<p>After this, in the address r4, will be a pointer to the data for the event (event name, event allowed characters, etc.).
That is the entire purpose of all these imports and definitions and code.
Yes, this code reads a branch instruction and extracts the offset XD.
Absolutely bonkers.</p>
<h3><code>R13</code></h3>
<p><code>R13</code> is the small data area pointer.
This points to a small amount of static data contained inside the executable (Start.dol) itself, rather than the iso.
There are some offsets under the <code>r13 Offsets</code> header in <code>ASM/training-mode/Globals.s</code>, as well as in <code>MexTK/include/offsets.h</code>.
Look there for what is loaded if you see a load with negative offset into <code>R13</code>.
<code>R13 = 0x804db6a0</code> always for melee. It is indexed by <strong>signed</strong> 16-bit integers. Generally you want to be careful modifying
memory in the small data area, but there is some code in the repository that does so in a region unused by melee.</p>
<h2>PRIM Lite</h2>
<p>PRIM Lite is a drawing module developed by punkline. There may be better ways to draw geometry, but I don't know how.
Currently it's used by the DI draw code. See documentation at <a href="https://smashboards.com/threads/primitive-drawing-module.454232/">this smashboards thread</a></p>
</section><div class="code-panel"><pre class="code src language-markdown"><span class="code-line"><a class="ln" id="L1" href="#L1">1</a><span class="code-text"><a-p>#</a-p> <a-tt>ASM</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L2" href="#L2">2</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L3" href="#L3">3</a><span class="code-text">Aitch: I don&#39;t write much melee asm, but here&#39;s some things I&#39;ve picked up by hacking on unclepunch&#39;s asm.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L4" href="#L4">4</a><span class="code-text">Here are some things you should know before diving into here, and some questions I have.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L5" href="#L5">5</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L6" href="#L6">6</a><span class="code-text">Clown: I have written a good amount of melee asm. I&#39;ve added some useful information I have here. If you</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L7" href="#L7">7</a><span class="code-text">have any questions, reach out on the discord.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L8" href="#L8">8</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L9" href="#L9">9</a><span class="code-text"><a-p>##</a-p> <a-tt>Overview</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L10" href="#L10">10</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L11" href="#L11">11</a><span class="code-text">PowerPC (PPC) is an instruction set architecture (ISA) that used to be used in</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L12" href="#L12">12</a><span class="code-text">computers and game consoles in the 90s and 2000s, notably in several Apple products,</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L13" href="#L13">13</a><span class="code-text">the Xbox 360, the PS3, and the GC/Wii/Wii U. Specifically, the GameCube and Wii use an embedded,</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L14" href="#L14">14</a><span class="code-text">big-endian, 32-bit version of PowerPC on their CPUs.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L15" href="#L15">15</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L16" href="#L16">16</a><span class="code-text"><a-p>##</a-p> <a-tt>Resources:</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L17" href="#L17">17</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L18" href="#L18">18</a><span class="code-text"><a-p>- </a-p>[IBM PPC User Instruction Set Architecture](https://files.decomp.dev/ppc_isa.pdf)</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L19" href="#L19">19</a><span class="code-text"><a-p>- </a-p>[IBM PPC Compiler Writer&#39;s Guide](https://files.decomp.dev/IBM_PPC_Compiler_Writer&#39;s_Guide-cwg.pdf)</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L20" href="#L20">20</a><span class="code-text"><a-p>- </a-p>[Beginner to advanced tutorials for PowerPC](https://mariokartwii.com/showthread.php?tid=1114)</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L21" href="#L21">21</a><span class="code-text"><a-p>- </a-p>[rlwinm/rlwimi/rlwmn Decoder](https://celestialamber.github.io/rlwinm-clrlwi-decoder/)</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L22" href="#L22">22</a><span class="code-text"><a-p>- </a-p>[Decompilation project for Melee](https://github.com/doldecomp/melee)</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L23" href="#L23">23</a><span class="code-text"><a-p>- </a-p>[Decomp Intro](https://github.com/doldecomp/melee/wiki/Decomp-Intro)</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L24" href="#L24">24</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L25" href="#L25">25</a><span class="code-text"><a-p>You should prioritize reading Section 2 and Appendix A of the Compiler&#39;s Writing Guide. Also,</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L26" href="#L26">26</a><span class="code-text"><a-p>Section 1.6 and Appendix B of the User Instruction Set Architecture.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L27" href="#L27">27</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L28" href="#L28">28</a><span class="code-text"><a-p>The decompilation project is useful for understanding Melee&#39;s code. If you have an address of a Melee function,</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L29" href="#L29">29</a><span class="code-text"><a-p>you can grep the decomp codebase and see if it&#39;s been decompiled. Even if it hasn&#39;t been, it&#39;s easier to</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L30" href="#L30">30</a><span class="code-text"><a-p>search around for related code within that repo than it is to work within the dolphin debugger. If</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L31" href="#L31">31</a><span class="code-text"><a-p>you&#39;re interested in learning more, you should read the Decomp Intro.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L32" href="#L32">32</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L33" href="#L33">33</a><span class="code-text"><a-p>## </a-p><a-tt>Notes:</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L34" href="#L34">34</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L35" href="#L35">35</a><span class="code-text"><a-p>- **The numbers 0..32 are allowed as registers!**</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L36" href="#L36">36</a><span class="code-text"><a-p>  You may run into silent errors where you expect to use a constant value but end up using a register.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L37" href="#L37">37</a><span class="code-text"><a-p>  The most common place to see this are in math instructions - `addi r3, r3, 10` can be accidentally written as `add r3, r3, 10` and introduce a bug.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L38" href="#L38">38</a><span class="code-text"><a-p>- If you see a load with offset around 0x23ec-0x2424 in OSD related code,</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L39" href="#L39">39</a><span class="code-text"><a-p>  it&#39;s probably reading or writing to `struct MEX` or `struct TM` in `struct FighterData` in `MexTK/include/fighter.h`.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L40" href="#L40">40</a><span class="code-text"><a-p>- **Don&#39;t be afraid of the dolphin debugger!**. Use the latest version of dolphin.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L41" href="#L41">41</a><span class="code-text"><a-p>- Everything in both `ASM/Globals.s` and `ASM/training-mode/Globals.s` are helper macros.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L42" href="#L42">42</a><span class="code-text"><a-p>  These are imported into most other ASM files. `ASM/Globals.s` is outdated, use `ASM/training-mode/Globals.s` for new asm files.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L43" href="#L43">43</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L44" href="#L44">44</a><span class="code-text"><a-p>### </a-p><a-tt>`mflr`</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L45" href="#L45">45</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L46" href="#L46">46</a><span class="code-text"><a-p>Because ASM files could be placed anywhere, you can&#39;t exactly just load a label as an address in a register.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L47" href="#L47">47</a><span class="code-text"><a-p>To get around this, there is an extremely common pattern using the `mflr` instruction.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L48" href="#L48">48</a><span class="code-text"><a-p>When the `bl &lt;label&gt;` instruction is followed by an `mflr &lt;r&gt;` instruction, the address right after the `bl` is placed in `r`.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L49" href="#L49">49</a><span class="code-text"><a-p>So often you will see something like:</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L50" href="#L50">50</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L51" href="#L51">51</a><span class="code-text"><a-p>```</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L52" href="#L52">52</a><span class="code-text"><a-p>bl SkipData</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L53" href="#L53">53</a><span class="code-text"><a-p>.long 12345     # important data</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L54" href="#L54">54</a><span class="code-text"><a-p>SkipData:</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L55" href="#L55">55</a><span class="code-text"><a-p>mflr r4</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L56" href="#L56">56</a><span class="code-text"><a-p>lwz r3, 0x0(r4) # r3 now contains 12345</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L57" href="#L57">57</a><span class="code-text"><a-p>```</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L58" href="#L58">58</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L59" href="#L59">59</a><span class="code-text"><a-p>### </a-p><a-tt>`EventJumpTable`</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L60" href="#L60">60</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L61" href="#L61">61</a><span class="code-text"><a-p>If you see the macro `EventJumpTable` in an ASM file somewhere, you&#39;re in for a wild ride.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L62" href="#L62">62</a><span class="code-text"><a-p>This macro is defined as:</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L63" href="#L63">63</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L64" href="#L64">64</a><span class="code-text"><a-p>```</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L65" href="#L65">65</a><span class="code-text"><a-p>.macro EventJumpTable</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L66" href="#L66">66</a><span class="code-text"><a-p>  bl Minigames</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L67" href="#L67">67</a><span class="code-text"><a-p>  bl GeneralTech</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L68" href="#L68">68</a><span class="code-text"><a-p>  bl SpacieTech</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L69" href="#L69">69</a><span class="code-text"><a-p>.endm</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L70" href="#L70">70</a><span class="code-text"><a-p>```</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L71" href="#L71">71</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L72" href="#L72">72</a><span class="code-text"><a-p>This allows event asm code to find global event data.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L73" href="#L73">73</a><span class="code-text"><a-p>This macro is not useful by itself. If this macro is used, there will be another macro imported (eg. `EventNameStrings`).</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L74" href="#L74">74</a><span class="code-text"><a-p>That other macro will have three labels: `Minigames`, `GeneralTech`, and `SpacieTech`.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L75" href="#L75">75</a><span class="code-text"><a-p>Under each label, for each event, with be ANOTHER macro for the data for that event.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L76" href="#L76">76</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L77" href="#L77">77</a><span class="code-text"><a-p>There will also be definitions for EventID and PageID, and this piece of code:</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L78" href="#L78">78</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L79" href="#L79">79</a><span class="code-text"><a-p>```</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L80" href="#L80">80</a><span class="code-text"><a-p>SkipPageList:</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L81" href="#L81">81</a><span class="code-text"><a-p>  mflr r4                  #Jump Table Start in r4</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L82" href="#L82">82</a><span class="code-text"><a-p>  mulli r5, PageID, 0x4    #Each Pointer is 0x4 Long</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L83" href="#L83">83</a><span class="code-text"><a-p>  add r4, r4, r5           #Get Event&#39;s Pointer Address</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L84" href="#L84">84</a><span class="code-text"><a-p>  lwz r5, 0x0(r4)          #Get bl Instruction</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L85" href="#L85">85</a><span class="code-text"><a-p>  rlwinm r5, r5, 0, 6, 29  #Mask Bits 6-29 (the offset)</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L86" href="#L86">86</a><span class="code-text"><a-p>  mr r3,EventID</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L87" href="#L87">87</a><span class="code-text"><a-p>  add r4, r4, r5           #Gets ASCII Address in r4</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L88" href="#L88">88</a><span class="code-text"><a-p>```</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L89" href="#L89">89</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L90" href="#L90">90</a><span class="code-text"><a-p>After this, in the address r4, will be a pointer to the data for the event (event name, event allowed characters, etc.).</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L91" href="#L91">91</a><span class="code-text"><a-p>That is the entire purpose of all these imports and definitions and code.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L92" href="#L92">92</a><span class="code-text"><a-p>Yes, this code reads a branch instruction and extracts the offset XD.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L93" href="#L93">93</a><span class="code-text"><a-p>Absolutely bonkers.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L94" href="#L94">94</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L95" href="#L95">95</a><span class="code-text"><a-p>### </a-p><a-tt>`R13`</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L96" href="#L96">96</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L97" href="#L97">97</a><span class="code-text"><a-p>`R13` is the small data area pointer.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L98" href="#L98">98</a><span class="code-text"><a-p>This points to a small amount of static data contained inside the executable (Start.dol) itself, rather than the iso.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L99" href="#L99">99</a><span class="code-text"><a-p>There are some offsets under the `r13 Offsets` header in `ASM/training-mode/Globals.s`, as well as in `MexTK/include/offsets.h`.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L100" href="#L100">100</a><span class="code-text"><a-p>Look there for what is loaded if you see a load with negative offset into `R13`.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L101" href="#L101">101</a><span class="code-text"><a-p>`R13 = 0x804db6a0` always for melee. It is indexed by **signed** 16-bit integers. Generally you want to be careful modifying</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L102" href="#L102">102</a><span class="code-text"><a-p>memory in the small data area, but there is some code in the repository that does so in a region unused by melee.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L103" href="#L103">103</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L104" href="#L104">104</a><span class="code-text"><a-p>## </a-p><a-tt>PRIM Lite</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L105" href="#L105">105</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L106" href="#L106">106</a><span class="code-text">PRIM Lite is a drawing module developed by punkline. There may be better ways to draw geometry, but I don&#39;t know how.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L107" href="#L107">107</a><span class="code-text">Currently it&#39;s used by the DI draw code. See documentation at [this smashboards thread](https://smashboards.com/threads/primitive-drawing-module.454232/)</span></span></pre></div></div>
</main>
</body>
</html>
