6502bench SourceGen: Visualizations

Back to index

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.

Bitmaps will always be scaled up as much as possible to make them easy to see. This means that small shapes and large shapes may appears to be the same size when displayed as thumbnails in the code list.

The role of a visualization generator is to take a collection of input parameters and generate graphical data. It's most useful for graphical sources like bitmaps, but it's not limited to that. You could, for example, write a script that generates random flowers, and use it to make your source listings more cheerful.

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 data or near the instructions that perform the drawing. Or both.

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. Similarly, if you select "New Bitmap Animation" or edit an existing bitmap animation, the Bitmap Animation Editor 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 across all visualizations (bitmaps, animations, etc).

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.

Bitmap Animation Editor

Bitmap animations allow you to create a simple animation from a collection of other visualizations. This can be useful when a program stores animated graphics as a series of frames.

The "tag" is a unique string that will be shown in the display list. The same rules apply as for bitmap visualizations.

The list at the top left holds all visualizations. Select items on the left and use the "Add" button to add them to the list on the right, which has the set that is included in the animation. You can reorder the list with the up/down buttons. Adding the same frame multiple times is allowed.

The "frame delay" field lets you specify how long each frame is shown on screen, in milliseconds. Some animation formats may use a different time resolution; for example, animated GIFs use units of 1/100th of a second. The closest value will be used. Note also that some viewers (notably web browsers) will cap the update rate.

When you have one or more frames in the animation list, you can preview the result in the window at the bottom. The actual appearance may be slightly different, especially if the frames are different sizes. For example, the preview window scales individual frames, but animated GIFs will be scaled to the size of the largest frame.

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:

Remember that this is a disassembler, not an image converter. The results do not need to be perfectly accurate to be useful when disassembling code.

Apple II - Apple/VisHiRes and Apple/VisShapeTable

There is no standard format for small hi-res bitmaps, but certain arrangements are common. The VisHiRes script defines four generators:

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 two checkboxes that affect the color. The first causes the first byte to be treated as being in an odd column rather than an even one, which affects green vs. purple and orange vs. blue. The second flips the high bits on every byte, switching green vs. orange and purple vs. blue. Neither has any effect on black & white bitmaps.

The converter generates one output pixel for every source pixel, so half-pixel shifts are not represented.

The VisShapeTable script renders Applesoft shape tables, which can have multiple vector shapes. The only parameter other than the offset is the shape number.

Atari 2600 - Atari/Vis2600

The Atari 2600 graphics system has registers that determine the appearance of a sprite or playfield on a single row. The register values are typically changed as the screen is drawn to get different data on successive rows. The visualization generator works for data stored in a straightforward fashion.

Commodore 64 - Commodore/VisC64

The Commodore 64 has a 64-bit sprite format defined by the hardware. It comes in two basic varieties:

Sprites can be doubled in width and/or height.

Colors come from a hardware-defined palette of 16:

  1.  black 
  2.  white 
  3.  red 
  4.  cyan 
  5.  purple 
  6.  green 
  7.  blue 
  8.  yellow 
  9.  orange 
  10.  brown 
  11.  light red 
  12.  dark grey 
  13.  grey 
  14.  light green 
  15.  light blue 
  16.  light grey 

Bear in mind that the editor scales images to their maximum size, so a sprite that is doubled in both width and height will look exactly like a sprite that is not doubled at all.