Skip to content

Commit

Permalink
Revert "Unify emulator and c8 VDP codebases"
Browse files Browse the repository at this point in the history
  • Loading branch information
stevesims authored Jan 16, 2025
1 parent 7bb290f commit 2a95a0d
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 79 deletions.
14 changes: 4 additions & 10 deletions video/agon_ps2.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,11 @@ uint32_t mWheelAcc = MOUSE_DEFAULT_WHEELACC; // Mouse wheel acceleration

// Forward declarations
//
#ifdef USERSPACE
bool zdi_mode () { return false; }
void zdi_enter () {}
void zdi_process_cmd (uint8_t key) {}
#else
bool zdi_mode ();
void zdi_enter ();
void zdi_process_cmd (uint8_t key);
#endif

bool resetMousePositioner(uint16_t width, uint16_t height, fabgl::VGABaseController * display);

extern bool zdi_mode();
extern void zdi_enter();
extern void zdi_process_cmd(uint8_t key);
extern bool consoleMode;
extern HardwareSerial DBGSerial;

Expand Down
3 changes: 2 additions & 1 deletion video/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class Context {
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

Point origin; // Screen origin
Expand Down Expand Up @@ -239,7 +240,7 @@ class Context {
bool usingSystemFont();
char getScreenChar(uint8_t x, uint8_t y);
char getScreenCharAt(uint16_t px, uint16_t py);
void mapCharToBitmap(uint8_t c, uint16_t bitmapId);
void mapCharToBitmap(char c, uint16_t bitmapId);
void unmapBitmapFromChars(uint16_t bitmapId);
void resetCharToBitmap();

Expand Down
2 changes: 1 addition & 1 deletion video/context/fonts.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ char Context::getScreenCharAt(uint16_t px, uint16_t py) {
return getScreenChar(toScreenCoordinates(px, py));
}

void Context::mapCharToBitmap(uint8_t c, uint16_t bitmapId) {
void Context::mapCharToBitmap(char c, uint16_t bitmapId) {
auto bitmap = getBitmap(bitmapId);
if (bitmap) {
charToBitmap[c] = bitmapId;
Expand Down
1 change: 0 additions & 1 deletion video/context/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "buffers.h"
#include "sprites.h"
#include "types.h"
#include "mat.h"

// Definitions for the functions we're implementing here
#include "context.h"
Expand Down
13 changes: 1 addition & 12 deletions video/hexload.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@
#define HEXLOAD_H

#include <stdbool.h>
#ifndef USERSPACE
#include "CRC16.h"
#include "CRC32.h"
#endif /* !USERSPACE */

extern void printFmt(const char *format, ...);
extern HardwareSerial DBGSerial;

#ifndef USERSPACE
CRC16 linecrc16(0x8005, 0x0, 0x0, false, false);
CRC32 crc32,crc32tmp;
#endif /* !USERSPACE */
bool aborted;

#define DEF_LOAD_ADDRESS 0x040000
Expand Down Expand Up @@ -61,15 +57,13 @@ void consumeHexMarker(void) {

// Receive a single iHex Nibble from the external Debug serial interface
uint8_t getIHexNibble(bool addcrc) {
#ifndef USERSPACE
uint8_t nibble, input;
input = toupper(serialRx_t());
if(addcrc) linecrc16.add(input);
if((input >= '0') && input <='9') nibble = input - '0';
else nibble = input - 'A' + 10;
// illegal characters will be dealt with by checksum later
return nibble;
#endif /* !USERSPACE */
}

// Receive a byte from the external Debug serial interface as two iHex nibbles
Expand Down Expand Up @@ -112,10 +106,6 @@ void serialTx(uint32_t crc) {
}

void VDUStreamProcessor::vdu_sys_hexload(void) {
#ifdef USERSPACE
// no hexload for emulators :)
return;
#else /* !USERSPACE */
uint32_t segment_address;
uint32_t crc32target;
uint8_t u,h,l,tmp;
Expand Down Expand Up @@ -300,7 +290,6 @@ void VDUStreamProcessor::vdu_sys_hexload(void) {
}
if(rom_area) printFmt("\r\nHEX data overlapping ROM area, transfer unsuccessful\r\nERROR\r\n");
printFmt("VDP done\r\n");
#endif /* !USERSPACE */
}

#endif // HEXLOAD_H
#endif // HEXLOAD_H
7 changes: 0 additions & 7 deletions video/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

#include <cstddef>
#include <cstdint>
#include <cmath>
#include <optional>
#include <memory>

Expand Down Expand Up @@ -115,12 +114,6 @@ class psram_allocator
}
};

template <typename T, typename U>
bool operator==(const psram_allocator<T>&, const psram_allocator<U>&) { return true; }

template <typename T, typename U>
bool operator!=(const psram_allocator<T>&a, const psram_allocator<U>&b) { return !(a == b); }

// Typically we do not need a deleter because the regular one can handle PSRAM deallocations just fine,
// but for completeness, here it is.

Expand Down
36 changes: 18 additions & 18 deletions video/vdu_buffered.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ void IRAM_ATTR VDUStreamProcessor::vdu_sys_buffered() {
}
auto matrixSize = getMatrixSize(bufferId);
if (matrixSize.value != 0) {
float transform[matrixSize.size()];
float transform[matrixSize.size()] = {0.0f};
if (getMatrixFromBuffer(bufferId, transform, matrixSize)) {
force_debug_log("buffer contains a %d x %d matrix with contents:\n\r", matrixSize.rows, matrixSize.columns);
for (int i = 0; i < matrixSize.rows; i++) {
Expand Down Expand Up @@ -1580,7 +1580,7 @@ void VDUStreamProcessor::bufferAffineTransform(uint16_t bufferId, uint8_t comman
MatrixSize size;
size.rows = dimensions + 1;
size.columns = size.rows;
float transform[size.size()];
float transform[size.size()] = {0.0f};
for (int i = 0; i < size.rows; i++) {
transform[i * size.rows + i] = 1.0f;
}
Expand Down Expand Up @@ -1657,7 +1657,7 @@ void VDUStreamProcessor::bufferAffineTransform(uint16_t bufferId, uint8_t comman
} break;
case AFFINE_SCALE: {
// scale by a given factor in each dimension
float scales[dimensions];
float scales[dimensions] = {0.0f};
if (!readFloatArguments(scales, dimensions, useBufferValue, useAdvancedOffsets, useMultiFormat)) {
return;
}
Expand All @@ -1667,7 +1667,7 @@ void VDUStreamProcessor::bufferAffineTransform(uint16_t bufferId, uint8_t comman
} break;
case AFFINE_TRANSLATE: {
// translate by a given amount
float translateXY[dimensions];
float translateXY[dimensions] = {0.0f};
if (!readFloatArguments(translateXY, dimensions, useBufferValue, useAdvancedOffsets, useMultiFormat)) {
return;
}
Expand All @@ -1677,7 +1677,7 @@ void VDUStreamProcessor::bufferAffineTransform(uint16_t bufferId, uint8_t comman
} break;
case AFFINE_TRANSLATE_OS_COORDS: {
// translate by a given amount of pixels where x and y match current coordinate system scaling
float translateXY[dimensions];
float translateXY[dimensions] = {0.0f};
if (!readFloatArguments(translateXY, dimensions, useBufferValue, useAdvancedOffsets, useMultiFormat)) {
return;
}
Expand All @@ -1690,7 +1690,7 @@ void VDUStreamProcessor::bufferAffineTransform(uint16_t bufferId, uint8_t comman
} break;
case AFFINE_SHEAR: {
// shear by a given amount
float shearXY[dimensions];
float shearXY[dimensions] = {0.0f};
if (!readFloatArguments(shearXY, dimensions, useBufferValue, useAdvancedOffsets, useMultiFormat)) {
return;
}
Expand All @@ -1702,7 +1702,7 @@ void VDUStreamProcessor::bufferAffineTransform(uint16_t bufferId, uint8_t comman
case AFFINE_SKEW_RAD: {
// skew by a given amount (angle)
bool conversion = op == AFFINE_SKEW ? DEG_TO_RAD : 1.0f;
float skewXY[dimensions];
float skewXY[dimensions] = {0.0f};
if (!readFloatArguments(skewXY, dimensions, useBufferValue, useAdvancedOffsets, useMultiFormat)) {
return;
}
Expand Down Expand Up @@ -1744,10 +1744,10 @@ void VDUStreamProcessor::bufferAffineTransform(uint16_t bufferId, uint8_t comman
if (!replace) {
// we are combining - for now, only if the existing matrix is the same size
// TODO consider handling different size matrices - could combine at larger size, and then truncate
float existing[size.size()];
float existing[size.size()] = {0.0f};
if (getMatrixFromBuffer(bufferId, existing, size, false)) {
// combine the two matrices together
float newTransform[size.size()];
float newTransform[size.size()] = {0.0f};
dspm_mult_f32(transform, existing, newTransform, size.rows, size.columns, size.columns);
// copy data from matrix back to our working transform matrix
memcpy(transform, newTransform, size.sizeBytes());
Expand Down Expand Up @@ -1775,7 +1775,7 @@ void VDUStreamProcessor::bufferMatrixManipulate(uint16_t bufferId, uint8_t comma
const bool useAdvancedOffsets = command & MATRIX_OP_ADVANCED_OFFSETS;
const bool useBufferValue = command & MATRIX_OP_BUFFER_VALUE;

float matrix[size.size()];
float matrix[size.size()] = {0.0f};

switch (op) {
case MATRIX_SET: {
Expand Down Expand Up @@ -1817,7 +1817,7 @@ void VDUStreamProcessor::bufferMatrixManipulate(uint16_t bufferId, uint8_t comma
case MATRIX_DIAGONAL: {
// diagonal matrix with given values
auto argCount = fabgl::imin(size.rows, size.columns);
float args[argCount];
float args[argCount] = {0.0f};
if (!readFloatArguments(args, argCount, useBufferValue, useAdvancedOffsets, false)) {
return;
}
Expand All @@ -1830,7 +1830,7 @@ void VDUStreamProcessor::bufferMatrixManipulate(uint16_t bufferId, uint8_t comma
auto sourceId1 = readWord_t(); if (sourceId1 == -1) return;
auto sourceId2 = readWord_t(); if (sourceId2 == -1) return;
// Get the matrixes, for our target size, padding or truncating as necessary
float source[size.size()];
float source[size.size()] = {0.0f};
if (!getMatrixFromBuffer(sourceId1, matrix, size) || !getMatrixFromBuffer(sourceId2, source, size)) {
debug_log("bufferMatrixManipulate: failed to read matrix from buffer %d or %d\n\r", sourceId1, sourceId2);
return;
Expand All @@ -1845,7 +1845,7 @@ void VDUStreamProcessor::bufferMatrixManipulate(uint16_t bufferId, uint8_t comma
auto sourceId1 = readWord_t(); if (sourceId1 == -1) return;
auto sourceId2 = readWord_t(); if (sourceId2 == -1) return;
// Get the matrixes, for our target size, padding or truncating as necessary
float source[size.size()];
float source[size.size()] = {0.0f};
if (!getMatrixFromBuffer(sourceId1, matrix, size) || !getMatrixFromBuffer(sourceId2, source, size)) {
debug_log("bufferMatrixManipulate: failed to read matrix from buffer %d or %d\n\r", sourceId1, sourceId2);
return;
Expand All @@ -1871,14 +1871,14 @@ void VDUStreamProcessor::bufferMatrixManipulate(uint16_t bufferId, uint8_t comma
MatrixSize resultSize;
resultSize.rows = dimensions;
resultSize.columns = dimensions;
float source1[resultSize.size()];
float source2[resultSize.size()];
float source1[resultSize.size()] = {0.0f};
float source2[resultSize.size()] = {0.0f};
if (!getMatrixFromBuffer(sourceId1, source1, resultSize) || !getMatrixFromBuffer(sourceId2, source2, resultSize)) {
debug_log("bufferMatrixManipulate: failed to read matrix from buffer %d or %d\n\r", sourceId1, sourceId2);
return;
}
// multiply values in source1 and source2
float result[resultSize.size()];
float result[resultSize.size()] = {0.0f};
dspm_mult_f32(source1, source2, result, resultSize.rows, resultSize.columns, resultSize.columns);
for (int row = 0; row < size.rows; row++) {
for (int column = 0; column < size.columns; column++) {
Expand Down Expand Up @@ -1913,7 +1913,7 @@ void VDUStreamProcessor::bufferMatrixManipulate(uint16_t bufferId, uint8_t comma
debug_log("bufferMatrixManipulate: source matrix %d not found\n\r", sourceId);
return;
}
float source[sourceSize.size()];
float source[sourceSize.size()] = {0.0f};
if (!getMatrixFromBuffer(sourceId, source, sourceSize)) {
debug_log("bufferMatrixManipulate: failed to read matrix from buffer %d\n\r", sourceId);
return;
Expand All @@ -1940,7 +1940,7 @@ void VDUStreamProcessor::bufferMatrixManipulate(uint16_t bufferId, uint8_t comma
return;
}
// read source matrix
float source[sourceSize.size()];
float source[sourceSize.size()] = {0.0f};
if (!getMatrixFromBuffer(sourceId, source, sourceSize)) {
debug_log("bufferMatrixManipulate: failed to read matrix from buffer %d\n\r", sourceId);
return;
Expand Down
2 changes: 1 addition & 1 deletion video/vdu_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ void VDUStreamProcessor::sendCursorPosition() {
//
void VDUStreamProcessor::sendScreenChar(char c) {
uint8_t packet[] = {
(uint8_t)c,
c,
};
send_packet(PACKET_SCRCHAR, sizeof packet, packet);
}
Expand Down
31 changes: 3 additions & 28 deletions video/video.ino
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,14 @@
// 12/09/2023: + Refactored
// 17/09/2023: + Added ZDI mode

#include <esp_task_wdt.h>
#include <HardwareSerial.h>
#include <WiFi.h>
#include <fabgl.h>

// Serial Debug Mode: 1 = enable
// Always enabled on the emulator, to support --verbose mode
#ifdef USERSPACE
# define DEBUG 1
#else /* !USERSPACE */
# define DEBUG 0
#endif /* USERSPACE */

#define DEBUG 0 // Serial Debug Mode: 1 = enable
#define SERIALBAUDRATE 115200

#ifdef USERSPACE
extern uint32_t startup_screen_mode; /* in rust_glue.cpp */
#else /* !USERSPACE */
#define startup_screen_mode 0
#endif /* !USERSPACE */

HardwareSerial DBGSerial(0);

#include "agon.h" // Configuration file
Expand All @@ -86,9 +74,7 @@ bool controlKeys = true; // Control keys enabled
std::unique_ptr<fabgl::Terminal> Terminal; // Used for Terminal emulation mode (for CP/M, etc)
VDUStreamProcessor * processor; // VDU Stream Processor

#ifndef USERSPACE
#include "zdi.h" // ZDI debugging console
#endif /* !USERSPACE */

TaskHandle_t Core0Task; // Core 0 task handle

Expand All @@ -98,7 +84,7 @@ void setup() {
disableCore1WDT(); delay(200);
#endif
DBGSerial.begin(SERIALBAUDRATE, SERIAL_8N1, 3, 1);
changeMode(startup_screen_mode);
changeMode(0);
copy_font();
setupVDPProtocol();
processor = new VDUStreamProcessor(&VDPSerial);
Expand Down Expand Up @@ -128,16 +114,7 @@ void loop() {
}

void processLoop(void * parameter) {
#ifdef USERSPACE
uint32_t count = 0;
#endif /* USERSPACE */

while (true) {
#ifdef USERSPACE
if ((count & 0x7f) == 0) delay(1 /* -TM- ms */);
count++;
#endif /* USERSPACE */

#ifdef VDP_USE_WDT
esp_task_wdt_reset();
#endif
Expand Down Expand Up @@ -226,7 +203,6 @@ void boot_screen() {

// Debug printf to PC
//
#ifndef USERSPACE
void debug_log(const char *format, ...) {
#if DEBUG == 1
va_list ap;
Expand All @@ -242,7 +218,6 @@ void debug_log(const char *format, ...) {
va_end(ap);
#endif
}
#endif

void force_debug_log(const char *format, ...) {
va_list ap;
Expand Down

0 comments on commit 2a95a0d

Please sign in to comment.