String Formatting

Programs can encode strings, such as human-readable text or filenames, in a variety of ways. Assemblers generally support one or more of these. SourceGen allows you to choose from a number of different formats, and automatically generates appropriate assembler directives.

The most popular formats are null-terminated (string data followed by $00), length-delimited (first byte or two holds the string length), and dextral character inverted (the high bit on the last byte is flipped). Sometimes strings are stored in reverse, so the output routine can decrement a register to zero.

t2-str-null-term-start

Looking at the Tutorial2 code, there are four strings starting at address $2004, each of which is followed by $00. These look like null-terminated strings, so let's make it official.

t2-str-null-term-bad

First, let's do it wrong. Click on the line with address $2004 to select it. Hold the shift key down, then double-click on the operand field of the line with address $2031 (i.e. double-click on the words "last string").

The Edit Data Operand dialog opens, but the null-terminated strings option is not available. This is because we didn't include the null byte on the last string. To be recognized as one of the "special" string types, every selected string must match the expected pattern.

t2-str-null-term-good

Cancel out of the dialog. Hold the shift key down, and double-click on the operand on line $203C ($00). With all 57 bytes selected, you should now see "Null-terminated strings (4)" as an available option (make sure the Character Encoding pop-up is set to "Low or High ASCII"). Click on that, then click OK. The strings are now shown as .ZSTR operands.

« Previous Next »