Skip to content

Commit

Permalink
Merge pull request #163 from AgonConsole8/dotted-lines
Browse files Browse the repository at this point in the history
update PLOT to support dotted lines
  • Loading branch information
stevesims authored Mar 21, 2024
2 parents f9f73b3 + 837fd7c commit d148cd6
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 30 deletions.
3 changes: 2 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ board_build.f_cpu = 240000000L
board_build.f_flash = 80000000L
framework = arduino
lib_deps =
https://github.com/AgonConsole8/vdp-gl.git#gcol-paint-modes
https://github.com/AgonConsole8/vdp-gl.git#dotted-lines
; ../vdp-gl
fbiego/ESP32Time@^2.0.0
build_unflags = -Os
build_flags =
Expand Down
1 change: 1 addition & 0 deletions video/agon.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#define VDP_LOGICALCOORDS 0xC0 // Switch BBC Micro style logical coords on and off
#define VDP_LEGACYMODES 0xC1 // Switch VDP 1.03 compatible modes on and off
#define VDP_SWITCHBUFFER 0xC3 // Double buffering control
#define VDP_PATTERN_LENGTH 0xF2 // Set pattern length (*FX 163,242,n)
#define VDP_CONSOLEMODE 0xFE // Switch console mode on and off
#define VDP_TERMINALMODE 0xFF // Switch to terminal mode

Expand Down
54 changes: 26 additions & 28 deletions video/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,36 +404,17 @@ void moveTo() {

// Line plot
//
void plotLine(bool omitFirstPoint = false, bool omitLastPoint = false) {
RGB888 firstPixelColour;
RGB888 lastPixelColour;
if (omitFirstPoint) {
if (p2.X >= 0 && p2.X < canvasW && p2.Y >= 0 && p2.Y < canvasH) {
canvas->waitCompletion(false);
firstPixelColour = canvas->getPixel(p2.X, p2.Y);
} else {
omitFirstPoint = false;
}
}
if (omitLastPoint) {
if (p1.X >= 0 && p1.X < canvasW && p1.Y >= 0 && p1.Y < canvasH) {
canvas->waitCompletion(false);
lastPixelColour = canvas->getPixel(p1.X, p1.Y);
} else {
omitLastPoint = false;
}
void plotLine(bool omitFirstPoint = false, bool omitLastPoint = false, bool usePattern = false, bool resetPattern = true) {
auto lineOptions = fabgl::LineOptions();
lineOptions.omitFirst = omitFirstPoint;
lineOptions.omitLast = omitLastPoint;
lineOptions.usePattern = usePattern;
if (resetPattern) {
canvas->setLinePatternOffset(0);
}
canvas->setLineOptions(lineOptions);

canvas->lineTo(p1.X, p1.Y);
if (omitFirstPoint) {
auto paintOptions = getPaintOptions(fabgl::PaintMode::Set, gpofg);
canvas->setPaintOptions(paintOptions);
canvas->setPixel(p2, firstPixelColour);
}
if (omitLastPoint) {
auto paintOptions = getPaintOptions(fabgl::PaintMode::Set, gpofg);
canvas->setPaintOptions(paintOptions);
canvas->setPixel(p1, lastPixelColour);
}
}

// Fill horizontal line
Expand Down Expand Up @@ -991,4 +972,21 @@ void setLineThickness(uint8_t thickness) {
canvas->setPenWidth(thickness);
}

void setDottedLinePattern(uint8_t pattern[8]) {
auto linePattern = fabgl::LinePattern();
linePattern.setPattern(pattern);
canvas->setLinePattern(linePattern);
}

void setDottedLinePatternLength(uint8_t length) {
if (length == 0) {
// reset the line pattern
auto linePattern = fabgl::LinePattern();
canvas->setLinePattern(linePattern);
canvas->setLinePatternLength(8);
return;
}
canvas->setLinePatternLength(length);
}

#endif
8 changes: 7 additions & 1 deletion video/vdu.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,16 @@ void VDUStreamProcessor::vdu_plot() {
plotLine(false, true);
break;
case 0x10: // dot-dash line
plotLine(false, false, true);
break;
case 0x18: // dot-dash line, omitting first point
plotLine(true, false, true);
break;
case 0x30: // dot-dash line, omitting first, pattern continued
plotLine(true, false, true, false);
break;
case 0x38: // dot-dash line, omitting both, pattern continued
debug_log("plot dot-dash line not implemented\n\r");
plotLine(true, true, true, false);
break;
case 0x20: // solid line, first point omitted
plotLine(true, false);
Expand Down
13 changes: 13 additions & 0 deletions video/vdu_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ void VDUStreamProcessor::vdu_sys() {
}
}
} break;
case 0x06: { // VDU 23, 6
uint8_t pattern[8]; // Set dotted line pattern
auto remaining = readIntoBuffer(pattern, 8);
if (remaining == 0) {
setDottedLinePattern(pattern);
}
} break;
case 0x07: { // VDU 23, 7
vdu_sys_scroll(); // Scroll
} break;
Expand Down Expand Up @@ -249,6 +256,12 @@ void VDUStreamProcessor::vdu_sys_video() {
case VDP_SWITCHBUFFER: { // VDU 23, 0, &C3
switchBuffer();
} break;
case VDP_PATTERN_LENGTH: { // VDU 23, 0, &F2, n
auto b = readByte_t(); // Set pattern length
if (b >= 0) {
setDottedLinePatternLength(b);
}
} break;
case VDP_CONSOLEMODE: { // VDU 23, 0, &FE, n
auto b = readByte_t();
setConsoleMode((bool) b);
Expand Down

0 comments on commit d148cd6

Please sign in to comment.