Skip to content

Commit

Permalink
Merge pull request #233 from AgonConsole8/optimised-print
Browse files Browse the repository at this point in the history
optimised print routine
  • Loading branch information
stevesims authored Jun 16, 2024
2 parents 39948cc + 37a260b commit ee06ebe
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
1 change: 1 addition & 0 deletions video/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class Context {
fabgl::LinePattern linePattern = fabgl::LinePattern(); // Dotted line pattern
uint8_t linePatternLength = 8; // Dotted line pattern length
std::vector<uint16_t> charToBitmap = std::vector<uint16_t>(256, 65535); // character to bitmap mapping
bool plottingText = false; // Are we currently plotting text?

bool logicalCoords = true; // Use BBC BASIC logical coordinates

Expand Down
1 change: 1 addition & 0 deletions video/context/cursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ inline void Context::setActiveCursor(CursorType type) {
setActiveViewport(ViewportType::Graphics);
break;
}
plottingText = false;
}

inline void Context::setCursorBehaviour(uint8_t setting, uint8_t mask = 0xFF) {
Expand Down
18 changes: 17 additions & 1 deletion video/context/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ void Context::plotBitmap(uint8_t mode) {
canvas->setPaintOptions(paintOptions);
}
drawBitmap(p1.X, p1.Y, true, false);
plottingText = false;
}


Expand All @@ -351,6 +352,7 @@ void Context::scrollRegion(Rect * region, uint8_t direction, int16_t movement) {
canvas->setPenColor(tbg);
canvas->setBrushColor(tbg);
canvas->setPaintOptions(tpo);
plottingText = false;
switch (direction) {
case 0: // Right
moveX = 1;
Expand Down Expand Up @@ -488,11 +490,17 @@ void Context::setTextColour(uint8_t colour) {
if (colour < 64) {
tfg = colourLookup[c];
tfgc = col;
if (plottingText && textCursorActive()) {
canvas->setPenColor(tfg);
}
debug_log("vdu_colour: tfg %d = %02X : %02X,%02X,%02X\n\r", colour, c, tfg.R, tfg.G, tfg.B);
}
else if (colour >= 128 && colour < 192) {
tbg = colourLookup[c];
tbgc = col;
if (plottingText && textCursorActive()) {
canvas->setBrushColor(tbg);
}
debug_log("vdu_colour: tbg %d = %02X : %02X,%02X,%02X\n\r", colour, c, tbg.R, tbg.G, tbg.B);
}
else {
Expand Down Expand Up @@ -611,6 +619,7 @@ bool IRAM_ATTR Context::plot(int16_t x, int16_t y, uint8_t command) {
auto mode = command & 0x07;
auto operation = command & 0xF8;
bool pending = false;
plottingText = false;

if (mode < 4) {
pushPointRelative(x, y);
Expand Down Expand Up @@ -748,7 +757,7 @@ void Context::plotPending(int16_t peeked) {
// Plot a string
//
void Context::plotString(const std::string& s) {
if (!ttxtMode) {
if (!ttxtMode && !plottingText) {
if (textCursorActive()) {
setClippingRect(textViewport);
canvas->setPenColor(tfg);
Expand All @@ -759,6 +768,7 @@ void Context::plotString(const std::string& s) {
canvas->setPenColor(gfg);
canvas->setPaintOptions(gpofg);
}
plottingText = true;
}

auto font = getFont();
Expand Down Expand Up @@ -792,6 +802,7 @@ void Context::plotBackspace() {
} else {
canvas->setBrushColor(textCursorActive() ? tbg : gbg);
canvas->fillRectangle(activeCursor->X, activeCursor->Y, activeCursor->X + getFont()->width - 1, activeCursor->Y + getFont()->height - 1);
plottingText = false;
}
}

Expand Down Expand Up @@ -852,6 +863,7 @@ void Context::drawCursor(Point p) {
canvas->setBrushColor(tfg);
canvas->fillRectangle(p.X + cursorHStart, p.Y + cursorVStart, p.X + std::min(((int)cursorHEnd), font->width - 1), p.Y + std::min(((int)cursorVEnd), font->height - 1));
canvas->setPaintOptions(tpo);
plottingText = false;
}
}
}
Expand All @@ -876,6 +888,7 @@ void Context::cls() {
canvas->setPaintOptions(tpo);
setClippingRect(textViewport);
clearViewport(ViewportType::Text);
plottingText = true;
}
cursorHome();
setPagedMode(pagedMode);
Expand All @@ -890,6 +903,7 @@ void Context::clg() {
canvas->setPaintOptions(gpobg);
setClippingRect(graphicsViewport);
clearViewport(ViewportType::Graphics);
plottingText = false;
}
pushPoint(0, 0); // Reset graphics cursor position (as per BBC Micro CLG)
}
Expand Down Expand Up @@ -931,6 +945,7 @@ void Context::resetTextPainting() {
tbg = colourLookup[0x00];
tpo = getPaintOptions(fabgl::PaintMode::Set, tpo);
cpo = getPaintOptions(fabgl::PaintMode::XOR, tpo);
plottingText = false;
}

// Reset graphics context, called after a mode change
Expand All @@ -949,6 +964,7 @@ void Context::reset() {
// Activate the context, setting up canvas as required
//
void Context::activate() {
plottingText = false;
if (!ttxtMode) {
canvas->selectFont(font == nullptr ? &FONT_AGON : font.get());
}
Expand Down
12 changes: 6 additions & 6 deletions video/vdu.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,25 +194,25 @@ void VDUStreamProcessor::vdu_print(char c, bool usePeek) {
s += c;
// gather our string for printing
if (usePeek) {
auto limit = 39;
auto limit = 15;
while (--limit) {
if (!byteAvailable()) {
break;
}
auto next = peekByte_t(FAST_COMMS_TIMEOUT);
auto next = inputStream->peek();
if (next == 27) {
readByte_t();
inputStream->read();
if (consoleMode) {
DBGSerial.write(next);
}
next = readByte_t(FAST_COMMS_TIMEOUT);
next = readByte_t();
if (next == -1) {
break;
}
s += (char)next;
} else if (next != -1 && ((next >= 0x20 && next <= 0x7E) || (next >= 0x80 && next <= 0xFF))) {
} else if ((next >= 0x20 && next <= 0x7E) || (next >= 0x80 && next <= 0xFF)) {
s += (char)next;
readByte_t();
inputStream->read();
} else {
break;
}
Expand Down

0 comments on commit ee06ebe

Please sign in to comment.