6502bench SourceGen: Visualizations
Overview
Programs are generally a combination of code and data. Sometimes the data is graphical in nature, e.g. a bitmap used as a font or game sprite. Being able to see the data in graphic form can make it easier to determine the purpose of associated code.
While modern systems use GIF, JPEG, and PNG to hold 2D bitmaps, graphical elements embedded in 6502 applications are almost always in a platform-specific form. For this reason, the task of generating images from data is performed by extension scripts. Some scripts for common formats are included in the SourceGen runtime directory. If these don't do what you need, you can write your own scripts and include them in your project.
The project file doesn't store the converted graphics. Instead, the project file holds a string that identifies the converter, and a list of parameters that are passed to the converter. Images are generated when the project is first opened, and updated when certain things change in the project.
Visualizations are not included in generated assembly output. They may be included in HTML exports.
Because visualizations are associated with a specific file offset, they will become "hidden" if the offset isn't at the start of a line, e.g. it's in the middle of a multi-byte instruction or data item. The editors will try to prevent you from doing this.
Visualizations and Visualization Sets
Visualizations are essentially decorative: they do not affect the assembled output, and do not change how code is analyzed. They are contained in sets that are placed at arbitrary offsets. Each set can contain multiple items. For example, if a file has data for 10 bitmaps, you can place a visualization near each, or create a single visualization set with all 10 items and put it at the start of the file. You can display a visualization near the instructions that perform the drawing.
To create a visualization set, select a code or data line, and use Actions > Create/Edit Visualization Set. To edit a visualization set, select it and use the same menu item, or just double-click on it. This opens the Visualization Set Editor window.
The visualization set editor shows a list of visualizations associated with the selected file offset. You can create a new visualization, edit or remove an existing entry, or rearrange them. If you select "New Bitmap" or edit an existing bitmap entry, the Bitmap Visualization Editor window will open.
Bitmap Visualization Editor
The combo box at the top of the screen lists every bitmap visualization generator defined by an active extension script. Select the one that is appropriate for the data you're trying to visualize. Every visualizer may have different parameters, so as you select different entries the set of input parameters below the preview window may change.
The "tag" is a unique string that will be shown in the display list. This is not a label, and may contain any characters you want (but leading and trailing whitespace will be trimmed). The only requirement is that it be unique among visualization tags.
The preview window shows the visualizer output. The generated image is expanded to fill the window, so small images will be shown with very large pixels. If you resize the editor window, the preview window will expand, which can make it easier to see detail on larger images. If the generator fails, the preview window will show a red 'X', and an error message will appear below it.
Parameters may be numeric or boolean. The latter use a simple checkbox, the former a text entry field that accepts decimal and hexadecimal values. The range of allowable values is shown to the right of the entry field. If you enter an invalid value, the parameter description will turn red.
Scripts Included with SourceGen
A number of visualization generation scripts are included with SourceGen, in the platform-specific runtime data directories.
Most generators will take the file offset, bitmap width, and bitmap height as parameters. Offsets are handled as they are elsewhere, i.e. always in hexadecimal, with a leading '+'. Some less-common parameters include:
- Row stride - number of bytes used to hold a row. This is used when a row has padding on the end, e.g. a bitmap that's 7 bytes wide might be padded to 8 for easy indexing. If you set this to zero the visualizer will default to no padding (stride == width).
- Column stride - number of bytes used to hold a column. This is uncommon, but could be used if (say) a pair of bitmaps was stored with interleaved bytes. If you set this to zero the visualizer will default to no interleave (stride == 1).
Apple II - Apple/VisHiRes
There is no standard format for small hi-res bitmaps, but certain arrangements are common. The script defines three generators:
- Hi-Res Bitmap - converts an MxN row-major bitmap.
- Hi-Res Bitmap Font - converts a series of MxN row-major bitmaps. This is intended for hi-res fonts, which are typically 8 bytes per entry, stored one after another. These are always converted as monochrome, and have a 1-pixel transparent gap between elements.
- Hi-Res Screen Image - used for 8KiB screen images. The data is linearized and converted to a 280x192 bitmap. Because images are relatively large, the generator does not require them to be contiguous in the file, i.e. two halves of the image can be in different parts of the file so long as they end up contiguous in memory.
Widths are specified in bytes, not pixels. Each byte represents 7 pixels (with some hand-waving).
In addition to offset, dimensions, and stride values, the bitmap converter has a checkbox for monochrome or color, and a checkbox that will cause the first byte to be treated as an odd column rather than an event one. The odd/even setting affects green/purple and orange/blue, but has no effect on black or white.
The converter generates one output pixel for every source pixel, so half-pixel shifts are not rendered.
Atari 2600 - Atari/VisAtari2600
The Atari 2600 graphics system has registers that determine the appearance of a sprite or playfield on a single row. The visualization generator works for data stored in a straightforward fashion.
- Sprite - basic 1xN sprite, converted to an image 8 pixels wide.
- Playfield - assumes PF0,PF1,PF2 are stored in that order, multiple entries following each other. Specify the number of 3-byte entries as the height. Since most playfields aren't the full height of the screen, it will tend to look squashed. Use the "row duplication" feature to repeat each row N times to make it look more like it should.