1
0
mirror of https://github.com/fadden/6502bench.git synced 2024-12-01 22:50:35 +00:00
6502bench/docs/sgtutorial/digging-deeper.html
Andy McFadden 8c5509d69d Update "digging deeper" tutorial
The tutorial was creating a new address region at +000002 without
removing the previous one, which leaves the 16-bit file load address
sitting at $1000 when it should be non-addressable.  The text now
shows the correct procedure.  Some screen shots had to be recaptured
to show the greyed-out address field.

This doesn't change anything meaningful about the disassembly -- the
PRG optimization hides the region start/end markers either way -- but
it's more correct this way, and it's an opportunity to introduce
the use of non-addressable regions for file headers.
2021-11-14 11:20:48 -08:00

226 lines
9.3 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<!-- START: /incl-head.html -->
<!-- common head elements -->
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"
integrity="sha384-vtXRMe3mGCbOeY7l30aIg8H9p3GdeSe4IFlP6G8JMa7o7lXvnz3GFKzPxzJdPfGK" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"/>
<link rel="stylesheet" href="../main.css"/>
<!-- END: /incl-head.html -->
<title>Digging Deeper - SourceGen Tutorial</title>
</head>
<body>
<!-- START: /incl-masthead.html -->
<div id="masthead">
<!--<div class="masthead-title" style="background-image: url('images/screenshot-mainwin.png');">-->
<div class="masthead-title">
6502bench
</div>
</div>
<!-- END: /incl-masthead.html -->
<!-- START: /incl-topnav.html active:#topnav-sgtutorial -->
<div id="topnav">
<!-- top navigation bar contents -->
<nav>
<a id="topnav-home" href=".././">HOME</a>
<a id="topnav-sgtutorial" class="active" href="../sgtutorial">SourceGen Tutorial</a>
<a id="topnav-menuicon" href="javascript:void(0);" class="icon" onclick="toggleSidenav()">
<i class="fa fa-bars"></i>
</a>
</nav>
<script>
// Sidenav toggle function.
//
// Use a jQuery function to toggle the sidenav bar. The initial state
// is undefined / inherited, so it will pop in and out as the screen
// resizes around the "large" breakpoint.
function toggleSidenav() {
$("#sidenav").toggle("fast");
}
</script>
</div>
<!-- END: /incl-topnav.html -->
<!-- START: incl-sidenav.html active:#sidenav-digging-deeper -->
<div id="sidenav">
<!-- side navigation bar contents -->
<ul>
<li id="sidenav-index"><a href="./">Introduction</a></li>
<li id="sidenav-about-disasm"><a href="about-disasm.html">About Disassembly</a></li>
<li id="sidenav-using-sourcegen"><a href="using-sourcegen.html">Using SourceGen</a>
<ul>
<li id="sidenav-moving-around"><a href="moving-around.html">Moving Around</a></li>
<li id="sidenav-making-edits"><a href="making-edits.html">Making Edits</a></li>
<li id="sidenav-labels-symbols"><a href="labels-symbols.html">Labels &amp; Symbols</a></li>
<li id="sidenav-editing-data"><a href="editing-data.html">Editing Data Operands</a></li>
<li id="sidenav-generating-code"><a href="generating-code.html">Generating Code</a></li>
</ul></li>
<li id="sidenav-digging-deeper" class="active"><a href="digging-deeper.html">Digging Deeper</a>
<ul>
<li id="sidenav-string-formatting"><a href="string-formatting.html">String Formatting</a></li>
<li id="sidenav-local-variables"><a href="local-variables.html">Local Variables</a></li>
<li id="sidenav-inline-data"><a href="inline-data.html">Inline Data</a></li>
<li id="sidenav-odds-ends"><a href="odds-ends.html">Odds &amp; Ends</a></li>
</ul></li>
<li id="sidenav-advanced-topics"><a href="advanced-topics.html">Advanced Topics</a>
<ul>
<li id="sidenav-address-tables"><a href="address-tables.html">Address Tables</a></li>
<li id="sidenav-extension-scripts"><a href="extension-scripts.html">Extension Scripts</a></li>
<li id="sidenav-visualizations"><a href="visualizations.html">Visualizations</a></li>
</ul></li>
<li id="sidenav-suggestions"><a href="suggestions.html">Suggestions</a></li>
</ul>
</div>
<!-- END: incl-sidenav.html -->
<div id="main">
<h2>Digging Deeper</h2>
<div class="grid-container">
<div class="grid-item-text">
<p>This tutorial will walk you through some of the fancier things SourceGen
can do. We assume you've already finished the basic features tutorial,
and know how to create projects and move around in them.</p>
<p>Start a new project. Select <samp>Generic 6502</samp>. For the
data file, navigate to the Examples directory, then from the Tutorial
directory select "Tutorial2".</p>
</div>
</div>
<div class="grid-container">
<div class="grid-item-image">
<img src="images/t2-tutorial-top.png" alt="t2-tutorial-top"/>
</div>
<div class="grid-item-text">
<p>Looking at the code list, the first thing you'll notice is that we
immediately ran into a
<code>BRK</code>, which is a pretty reliable sign that we're not in
a code section. This particular file begins with <code>00 20</code>, which
could be a load address (e.g. some C64 binaries look like this). So let's start
with that assumption.</p>
</div>
</div>
<div class="grid-container">
<div class="grid-item-text">
<p>As discussed in the introductory material, SourceGen separates code
from data by tracing all possible execution paths from declared entry
points. The generic profiles mark the first byte of the file as an entry
point, but that's wrong here. We want to change the entry point to
be after the 16-bit load address, at offset +000002.</p>
</div>
</div>
<div class="grid-container">
<div class="grid-item-image">
<img src="images/t2-1000-edit1.png" alt="t2-1000-edit1"/>
</div>
<div class="grid-item-text">
<p>Click on the first line of code at address $1000, and select
<samp>Actions &gt; Remove Analyzer Tags</samp>
(<kbd class="key">Ctrl+H</kbd> <kbd class="key">Ctrl+R</kbd>).
This removes the "code start point" tag.
Then, click on the <code>.addrs</code> line above it, and select
<samp>Actions &gt; Create / Edit Address Region</samp>. Down
at the bottom, click <samp>Delete Region</samp>. This
removes the default address region, replacing it with one that
says "<code>NA</code>", meaning that the code is non-addressable.
This is correct for the first two bytes, which will be
read by the system loader but not actually loaded into memory.
We still need to create a new address region at offset +000002.</p>
</div>
</div>
<div class="grid-container">
<div class="grid-item-image">
<img src="images/t2-1000-edit2.png" alt="t2-1000-edit2"/>
</div>
<div class="grid-item-text">
<p>Unfortunately the $20 is still auto-detected as being part
of a string directive, which is making it hard to manipulate
the next few bytes.
Let's fix that by selecting <samp>Edit &gt; Toggle Data Scan</samp>
(<kbd class="key">Ctrl+D</kbd>). This turns off the feature that
automatically generates string and <code>.FILL</code> directives,
so now each uncategorized byte is on its own line.</p>
</div>
</div>
<div class="grid-container">
<div class="grid-item-image">
<img src="images/t2-1000-fmt-word.png" alt="t2-1000-fmt-word"/>
</div>
<div class="grid-item-text">
<p>You could select the first two lines and use
<samp>Actions &gt; Edit Operand</samp> to format them as a 16-bit
little-endian hex value, but there's a shortcut: select the first
line with data (offset +000000), then
<samp>Actions &gt; Format As Word</samp>
(<kbd class="key">Ctrl+W</kbd>).
It automatically grabbed the following byte and combined them.</p>
</div>
</div>
<div class="grid-container">
<div class="grid-item-image">
<img src="images/t2-1000-setcode.png" alt="t2-1000-setcode"/>
</div>
<div class="grid-item-text">
<p>Since we currently believe $2000 is the load address for everything
that follows, click on the line with offset +000002, select
<samp>Actions &gt; Create/Edit Address Region</samp>, and enter "2000"
for the address. Click <samp>OK</samp>.
With that line still selected, use
<samp>Actions &gt; Tag Address As Code Start Point</samp>
(<kbd class="key">Ctrl+H</kbd> <kbd class="key">Ctrl+C</kbd>) to
tell the analyzer to start looking for code there.</p>
</div>
</div>
<div class="grid-container">
<div class="grid-item-image">
<img src="images/t2-1000-ready.png" alt="t2-1000-ready"/>
</div>
<div class="grid-item-text">
<p>That looks better, but the branch destination ($203D) is off the bottom of the
screen (unless you have a really tall screen or small fonts) because of
all the intervening data. Use <samp>Edit &gt; Toggle Data Scan</samp>
(<kbd class="key">Ctrl+D</kbd>)
to turn the string-finder back on. Now it's easier to read.</p>
</div>
</div>
</div> <!-- #main -->
<div id="prevnext">
<a href="generating-code.html" class="btn-previous">&laquo; Previous</a>
<a href="string-formatting.html" class="btn-next">Next &raquo;</a>
</div>
<!-- START: /incl-footer.html -->
<div id="footer">
<hr/>
<p>Copyright 2021 faddenSoft</p>
<!-- <p id="screen-size"></p>
<script>
var w = window.innerWidth;
var h = window.innerHeight;
var x = document.getElementById("screen-size");
x.innerHTML = "DEBUG: initial window size " + w + "x" + h;
</script> -->
</div>
<!-- END: /incl-footer.html -->
</body>
</html>