http://learn.cemetech.net/index.php?title=Z80:Coding&feed=atom&action=historyZ80:Coding - Revision history2024-03-29T07:43:50ZRevision history for this page on the wikiMediaWiki 1.34.0http://learn.cemetech.net/index.php?title=Z80:Coding&diff=393&oldid=prevKermMartian at 08:01, 6 February 20162016-02-06T08:01:00Z<p></p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">Revision as of 08:01, 6 February 2016</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l8" >Line 8:</td>
<td colspan="2" class="diff-lineno">Line 8:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div># Put all the code you want that routine to do under that label.</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div># Put all the code you want that routine to do under that label.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div># When you want to call the routine, just make sure you pass the correct arguments by loading the correct values into the inputs.</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div># When you want to call the routine, just make sure you pass the correct arguments by loading the correct values into the inputs.</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div># To call a routine, use the ''[[Z80:Opcodes:<del class="diffchange diffchange-inline">Call</del>|call]]'' instruction, followed by the label name. Please note that you can also set the call routine up so that it can jump with similar arguments as jp/jr.</div></td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div># To call a routine, use the ''[[Z80:Opcodes:<ins class="diffchange diffchange-inline">CALL</ins>|call]]'' instruction, followed by the label name. Please note that you can also set the call routine up so that it can jump with similar arguments as jp/jr.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>It is not necessary, but is highly recommended, that you include before the routine a description of the routine, the inputs, outputs, and other general information. See the comments section below.</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>It is not necessary, but is highly recommended, that you include before the routine a description of the routine, the inputs, outputs, and other general information. See the comments section below.</div></td></tr>
</table>KermMartianhttp://learn.cemetech.net/index.php?title=Z80:Coding&diff=125&oldid=prevKermMartian at 06:08, 5 February 20162016-02-05T06:08:05Z<p></p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">Revision as of 06:08, 5 February 2016</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l136" >Line 136:</td>
<td colspan="2" class="diff-lineno">Line 136:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>If you know any higher level languages (C(++),Java, Visual Basic, TI-Basic, etc.), then you can write pseudo code that may help you understand how the low-level assembly code is working. It doesn't even have to be 100% correct coding for a higher level language, so long as you understand what you're trying to do.</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>If you know any higher level languages (C(++),Java, Visual Basic, TI-Basic, etc.), then you can write pseudo code that may help you understand how the low-level assembly code is working. It doesn't even have to be 100% correct coding for a higher level language, so long as you understand what you're trying to do.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>For example, you can think of ''<del class="diffchange diffchange-inline">djn</del>'' as ''for'', ''call <del class="diffchange diffchange-inline">functio</del>'' as ''function('', etc.</div></td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>For example, you can think of ''<ins class="diffchange diffchange-inline">djnz</ins>'' as ''for'', ''call <ins class="diffchange diffchange-inline">function</ins>'' as ''function(<ins class="diffchange diffchange-inline">)</ins>'', etc.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>'''Algorithm in higher level language'''</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>'''Algorithm in higher level language'''</div></td></tr>
</table>KermMartianhttp://learn.cemetech.net/index.php?title=Z80:Coding&diff=111&oldid=prevKermMartian at 02:24, 5 February 20162016-02-05T02:24:02Z<p></p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">Revision as of 02:24, 5 February 2016</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l37" >Line 37:</td>
<td colspan="2" class="diff-lineno">Line 37:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> inc B</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> inc B</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> inc HL</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> inc HL</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> jr <del class="diffchange diffchange-inline">StrLength</del></div></td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> jr <ins class="diffchange diffchange-inline">StrLength10</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l65" >Line 65:</td>
<td colspan="2" class="diff-lineno">Line 65:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> maxshots .equ 5</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> maxshots .equ 5</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">== Jump Table ==</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">If your program is designed to offer subroutines, a jump table to specific routines will often be located at the beginning of the program or App. The first jump is to your main code, the rest are to specific routines. For example:</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> <<header>></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> Start:</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> jp Main</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> jp PutSprite</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> jp PutSpriteLarge</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> jp BufToLCD</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> jp SearchString</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> Main:</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> <<rest of code></ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del class="diffchange diffchange-inline">+</del>= Routines =</div></td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">This way, other programs using your program for routines will know where to call, and if you update any of your routines, you and your users don't need to worry about changing addresses in other programs.</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">For the most part, this technique is only used by shells; Ion, MirageOS, and Doors CS all use it.</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>= Routines =</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Routines generally go after the main code. Also be sure to denote where a certain routine starts and where it ends if using multiple labels.</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Routines generally go after the main code. Also be sure to denote where a certain routine starts and where it ends if using multiple labels.</div></td></tr>
</table>KermMartianhttp://learn.cemetech.net/index.php?title=Z80:Coding&diff=91&oldid=prevKermMartian: Adjusted lowercase z802016-02-03T21:10:05Z<p>Adjusted lowercase z80</p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">Revision as of 21:10, 3 February 2016</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l8" >Line 8:</td>
<td colspan="2" class="diff-lineno">Line 8:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div># Put all the code you want that routine to do under that label.</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div># Put all the code you want that routine to do under that label.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div># When you want to call the routine, just make sure you pass the correct arguments by loading the correct values into the inputs.</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div># When you want to call the routine, just make sure you pass the correct arguments by loading the correct values into the inputs.</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div># To call a routine, use the ''[[<del class="diffchange diffchange-inline">z80</del>:Opcodes:Call|call]]'' instruction, followed by the label name. Please note that you can also set the call routine up so that it can jump with similar arguments as jp/jr.</div></td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div># To call a routine, use the ''[[<ins class="diffchange diffchange-inline">Z80</ins>:Opcodes:Call|call]]'' instruction, followed by the label name. Please note that you can also set the call routine up so that it can jump with similar arguments as jp/jr.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>It is not necessary, but is highly recommended, that you include before the routine a description of the routine, the inputs, outputs, and other general information. See the comments section below.</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>It is not necessary, but is highly recommended, that you include before the routine a description of the routine, the inputs, outputs, and other general information. See the comments section below.</div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l147" >Line 147:</td>
<td colspan="2" class="diff-lineno">Line 147:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>= Conclusion =</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>= Conclusion =</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>Now that you have your code written, your done, right? Wrong. There are many other aspects to creating a successful program than just writing the code. If you wish, you may release your program at this point, but it probably won't get a good review by the program users. Instead, it is recommended that you [[<del class="diffchange diffchange-inline">z80</del>:Debugging|read on]] to see what you need to do to finalize your program.</div></td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>Now that you have your code written, your done, right? Wrong. There are many other aspects to creating a successful program than just writing the code. If you wish, you may release your program at this point, but it probably won't get a good review by the program users. Instead, it is recommended that you [[<ins class="diffchange diffchange-inline">Z80</ins>:Debugging|read on]] to see what you need to do to finalize your program.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>{{lowercase}}</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>{{lowercase}}</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>[[Category:<del class="diffchange diffchange-inline">z80 </del>Assembly]]</div></td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>[[Category:<ins class="diffchange diffchange-inline">Z80 </ins>Assembly]]</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>[[Category:<del class="diffchange diffchange-inline">z80 </del>Heaven]]</div></td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>[[Category:<ins class="diffchange diffchange-inline">Z80 </ins>Heaven]]</div></td></tr>
</table>KermMartianhttp://learn.cemetech.net/index.php?title=Z80:Coding&diff=57&oldid=prevKermMartian: Created page with "Now that we have a basic idea of what we're going to do, it's time to actually write the code. Depending on what kind of program you're creating, your code will vary a great d..."2016-02-03T20:14:50Z<p>Created page with "Now that we have a basic idea of what we're going to do, it's time to actually write the code. Depending on what kind of program you're creating, your code will vary a great d..."</p>
<p><b>New page</b></p><div>Now that we have a basic idea of what we're going to do, it's time to actually write the code. Depending on what kind of program you're creating, your code will vary a great deal. However, it is possible to provide a few tips on coding:<br />
<br />
= Routines =<br />
<br />
If you don't know already, re-writing the same code multiple times is a waste of time and space. Instead, it is much more efficient to create routines. Here's how to create a routine:<br />
<br />
# Create a label. This is the name of the routine, and should be specific for that routine.<br />
# Put all the code you want that routine to do under that label.<br />
# When you want to call the routine, just make sure you pass the correct arguments by loading the correct values into the inputs.<br />
# To call a routine, use the ''[[z80:Opcodes:Call|call]]'' instruction, followed by the label name. Please note that you can also set the call routine up so that it can jump with similar arguments as jp/jr.<br />
<br />
It is not necessary, but is highly recommended, that you include before the routine a description of the routine, the inputs, outputs, and other general information. See the comments section below.<br />
<br />
== General routine setup ==<br />
<br />
Note that the stuff at the beginning is not necessary, but is recommended so that you know what the routine does.<br />
<br />
<br />
;*****************<br />
;_StringLength Inline<br />
;*****************<br />
;Description: the StrLength function inline<br />
;<br />
;Inputs: HL points to the start of a null-terminating string<br />
;<br />
;Outputs: String length (not including null term) in B<br />
; HL points to null term<br />
;<br />
;Destroyed: A, HL, B<br />
<br />
StrLength:<br />
ld B,0<br />
StrLength10:<br />
ld A,(HL)<br />
or A<br />
ret Z<br />
inc B<br />
inc HL<br />
jr StrLength<br />
<br />
<br />
== Calling routines ==<br />
<br />
A general way to call routines that you have written.<br />
<br />
<br />
ld HL,strData<br />
call StrLength<br />
strData:<br />
.db "Test String",0<br />
<br />
<br />
= Code Structure =<br />
<br />
It's important that you organize your code so that it is manage-able by you and others who see your code. Here are a few guidelines that you can follow:<br />
<br />
== Headers and Definitions/Equates ==<br />
<br />
Headers must go at the top of the page. These are specific to the kind of program you are writing and what platform it is for. Definitions are those that make coding easier for you. They are equates that the compiler searches-and-replaces on compile, but allow you to understand what you are doing.<br />
<br />
'''Sample Definitions/Equates'''<br />
<br />
#define shot 0<br />
#define shootFlags asmFlags1<br />
maxshots .equ 5<br />
<br />
<br />
+= Routines =<br />
<br />
Routines generally go after the main code. Also be sure to denote where a certain routine starts and where it ends if using multiple labels.<br />
<br />
== Data ==<br />
<br />
Data that your program uses is the last thing that should be in your program. Data includes strings that you display, saved high-scores, picture data, and anything else that you want to include in your program.<br />
Note that here data does not include equates to saferam areas.<br />
<br />
== Multiple files ==<br />
<br />
Sometimes, if you're writing large programs are even large routines, you'll want to split your program up into multiple files. How you split them up depends on the code itself, but generally here's how I like to do it:<br />
<br />
* Create a separate file for all the headers and definitions stuff. Usually this file is denoted with a "*.inc" or "*.h" file type, but it's okay if you just make it a "*.asm"/"*.z80" file type.<br />
* Create a separate file for the main code. This does not have to include the data your using, but can.<br />
* Create a separate file for routines. If you have large routines, create separate files for those, too.<br />
* Create a separate file for data. This is not necessary, but is useful when trying to make animated sprites/greyscale pictures. Put each animated sprite/greyscale picture into it's own file so that you can edit them together and not get confused with other stuff. Sometimes, you may also want to include the routines that operate on that data with the data, too.<br />
<br />
=== Getting it all together ===<br />
<br />
So now that you have multiple files, you need to put them together in an orderly fashion. Using the #include directive and the guidelines above, you should be able to put your program together so that it will make sense and run correctly. Usually you use your main code file for this, so that way you don't have to create a separate file to put all the includes together.<br />
<br />
<br />
#include headers.inc<br />
<br />
main:<br />
... ;main code<br />
<br />
#include routines1.asm<br />
#include routines2.z80<br />
#include spriteData.h<br />
#include textData.asm<br />
<br />
<br />
= Comments =<br />
<br />
Although they aren't included in the program or affect the compilation of the code in any way shape or form, comments do provide a very useful perspective on the code at the time the code is being written. It also makes debugging easier, as you know what the code is supposed to do, as well as anyone else that is viewing your code.<br />
<br />
To denote a line as a comment, put a semicolon (;) in front of the line. The comment will then continue until the end of that line.<br />
<br />
ld (hl),a ;loads a to a very important location in memory<br />
;the next section of code generates the world<br />
...<br />
<br />
Knowing when to use comments and when not to is an important aspect of programming. Here are some general pointers on how to use comments:<br />
* Do use to Describe routines that you have written, including information such as inputs, outputs, and what it does<br />
* Do use to Describe where the program is jumping to, and what it will do<br />
* Do use to Describe the conditions of a test, ex. if value is greater than 100, jump<br />
* Don't use to point out the obvious ex. loads a into (hl)<br />
* Don't use for every line, cluttering up your code. Instead, try to summarize small chunks of code<br />
<br />
= Pseudo Code =<br />
<br />
If you know any higher level languages (C(++),Java, Visual Basic, TI-Basic, etc.), then you can write pseudo code that may help you understand how the low-level assembly code is working. It doesn't even have to be 100% correct coding for a higher level language, so long as you understand what you're trying to do.<br />
<br />
For example, you can think of ''djn'' as ''for'', ''call functio'' as ''function('', etc.<br />
<br />
'''Algorithm in higher level language'''<br />
<br />
for(int i=5;i>0;i--){<br />
display("HI");<br />
}<br />
<br />
'''Translated to assembly'''<br />
<br />
;assembly for-loop:<br />
ld b,4 ;loop 4 times<br />
loop: ;don't use this label twice!<br />
push bc ;save loop counter b<br />
ld hl,txtHI ;load text<br />
bcall(_PutS) ;display<br />
pop bc ;load loop counter b<br />
djnz loop ;loop!<br />
;...<br />
<br />
txtHI:<br />
.db "HI",0<br />
<br />
<br />
= Conclusion =<br />
<br />
Now that you have your code written, your done, right? Wrong. There are many other aspects to creating a successful program than just writing the code. If you wish, you may release your program at this point, but it probably won't get a good review by the program users. Instead, it is recommended that you [[z80:Debugging|read on]] to see what you need to do to finalize your program.<br />
<br />
{{lowercase}}<br />
[[Category:z80 Assembly]]<br />
[[Category:z80 Heaven]]</div>KermMartian