Digging Deeper

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.

Start a new project. Select Generic 6502. For the data file, navigate to the Examples directory, then from the Tutorial directory select "Tutorial2".


Looking at the code list, the first thing you'll notice is that we immediately ran into a BRK, which is a pretty reliable sign that we're not in a code section. This particular file begins with 00 20, which could be a load address (e.g. some C64 binaries look like this). So let's start with that assumption.

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.


Click on the first line of code at address $1000, and select Actions > Remove Analyzer Tags (Ctrl+H Ctrl+R). This removes the "code start point" tag. Then, click on the .addrs line above it, and select Actions > Create / Edit Address Region. Down at the bottom, click Delete Region. This removes the default address region, replacing it with one that says "NA", 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.


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 Edit > Toggle Data Scan (Ctrl+D). This turns off the feature that automatically generates string and .FILL directives, so now each uncategorized byte is on its own line.


You could select the first two lines and use Actions > Edit Operand 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 Actions > Format As Word (Ctrl+W). It automatically grabbed the following byte and combined them.


Since we currently believe $2000 is the load address for everything that follows, click on the line with offset +000002, select Actions > Create/Edit Address Region, and enter "2000" for the address. Click OK. With that line still selected, use Actions > Tag Address As Code Start Point (Ctrl+H Ctrl+C) to tell the analyzer to start looking for code there.


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 Edit > Toggle Data Scan (Ctrl+D) to turn the string-finder back on. Now it's easier to read.

« Previous Next »