Skip to content

Commit

Permalink
Fix shape table rendering
Browse files Browse the repository at this point in the history
The code wasn't correctly ignoring a zeroed-out middle section.

(issue #21)
  • Loading branch information
fadden committed Jun 28, 2024
1 parent 52a7ac9 commit d2a71ce
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
8 changes: 4 additions & 4 deletions FileConv/Gfx/ShapeTable-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ Movement is:
11: left
```
When drawing, vectors are handled in the order A-B-C. If the plot flag bit is set to 1, a point
will be plotted before the cursor is moved.
will be plotted before the cursor is moved. Note that vector C does not have a plot flag, so it
can only move without plotting.

Note that vector C does not have a plot flag, so it can only move without plotting. Additionally,
the value 00 is treated as a no-op, so vector C cannot move upward. Setting all bits to zero
marks the end of the shape.
If all bits are zero, the byte marks the end of the shape. If C is zero then it is ignored, and if
B and C are both zero then both are ignored.

See page 93 in the Applesoft manual for an example.

Expand Down
30 changes: 18 additions & 12 deletions FileConv/Gfx/ShapeTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,22 @@ private static bool DrawShape(byte[] buf, ShapeInfo shInfo, ImageGrid? grid) {
break; // done!
}

DrawVector(val & 0x07, // A
false, ref xc, ref yc, ref xmin, ref xmax, ref ymin, ref ymax, setPixel);
DrawVector((val >> 3) & 0x07, // B
false, ref xc, ref yc, ref xmin, ref xmax, ref ymin, ref ymax, setPixel);
DrawVector((val >> 6) & 0x03, // C
true, ref xc, ref yc, ref xmin, ref xmax, ref ymin, ref ymax, setPixel);
// "If all the remaining sections of the byte contain only zeroes, then those
// sections are ignored." We ignore C if it's zero, and if B and C are both zero
// then both parts are ignored.
int abits = val & 0x07;
int bbits = (val >> 3) & 0x07;
int cbits = val >> 6;

DrawVector(abits, ref xc, ref yc, ref xmin, ref xmax, ref ymin, ref ymax, setPixel);
if (bbits != 0 || cbits != 0) {
DrawVector(bbits, ref xc, ref yc, ref xmin, ref xmax, ref ymin, ref ymax,
setPixel);
}
if (cbits != 0) {
DrawVector(cbits, ref xc, ref yc, ref xmin, ref xmax, ref ymin, ref ymax,
setPixel);
}
}
shInfo.mMinX = xmin;
shInfo.mMaxX = xmax;
Expand All @@ -332,7 +342,7 @@ private static bool DrawShape(byte[] buf, ShapeInfo shInfo, ImageGrid? grid) {
return true;
}

private static void DrawVector(int bits, bool isC, ref int xc, ref int yc,
private static void DrawVector(int bits, ref int xc, ref int yc,
ref int xmin, ref int xmax, ref int ymin, ref int ymax, SetPixelFunc? func) {
if ((bits & 0x04) != 0) {
// Plot point, then update bounds.
Expand All @@ -354,11 +364,7 @@ private static void DrawVector(int bits, bool isC, ref int xc, ref int yc,
}
switch (bits & 0x03) {
case 0x00: // move up
if (isC) {
// vector C, do nothing
} else {
yc--;
}
yc--;
break;
case 0x01: // move right
xc++;
Expand Down

0 comments on commit d2a71ce

Please sign in to comment.