Skip to content

Commit

Permalink
Merge pull request #274 from AgonConsole8/tomm-unified-changes
Browse files Browse the repository at this point in the history
Unify emulator and main VDP codebases
  • Loading branch information
stevesims authored Jan 16, 2025
2 parents d382bf6 + 1e5fa08 commit 0c452cb
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 35 deletions.
14 changes: 10 additions & 4 deletions video/agon_ps2.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ uint32_t mWheelAcc = MOUSE_DEFAULT_WHEELACC; // Mouse wheel acceleration

// Forward declarations
//
bool resetMousePositioner(uint16_t width, uint16_t height, fabgl::VGABaseController * display);
#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

extern bool zdi_mode();
extern void zdi_enter();
extern void zdi_process_cmd(uint8_t key);
bool resetMousePositioner(uint16_t width, uint16_t height, fabgl::VGABaseController * display);
extern bool consoleMode;
extern HardwareSerial DBGSerial;

Expand Down
3 changes: 1 addition & 2 deletions video/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ 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 @@ -240,7 +239,7 @@ class Context {
bool usingSystemFont();
char getScreenChar(uint8_t x, uint8_t y);
char getScreenCharAt(uint16_t px, uint16_t py);
void mapCharToBitmap(char c, uint16_t bitmapId);
void mapCharToBitmap(uint8_t 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(char c, uint16_t bitmapId) {
void Context::mapCharToBitmap(uint8_t c, uint16_t bitmapId) {
auto bitmap = getBitmap(bitmapId);
if (bitmap) {
charToBitmap[c] = bitmapId;
Expand Down
1 change: 1 addition & 0 deletions video/context/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#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: 12 additions & 1 deletion video/hexload.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
#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 @@ -57,13 +61,15 @@ 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 @@ -106,6 +112,10 @@ 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 @@ -290,6 +300,7 @@ 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: 7 additions & 0 deletions video/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

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

Expand Down Expand Up @@ -114,6 +115,12 @@ 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
58 changes: 37 additions & 21 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()] = {0.0f};
float transform[matrixSize.size()];
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,8 @@ void VDUStreamProcessor::bufferAffineTransform(uint16_t bufferId, uint8_t comman
MatrixSize size;
size.rows = dimensions + 1;
size.columns = size.rows;
float transform[size.size()] = {0.0f};
float transform[size.size()];
memset(transform, 0, sizeof(transform));
for (int i = 0; i < size.rows; i++) {
transform[i * size.rows + i] = 1.0f;
}
Expand Down Expand Up @@ -1657,7 +1658,8 @@ void VDUStreamProcessor::bufferAffineTransform(uint16_t bufferId, uint8_t comman
} break;
case AFFINE_SCALE: {
// scale by a given factor in each dimension
float scales[dimensions] = {0.0f};
float scales[dimensions];
memset(scales, 0, sizeof(scales));
if (!readFloatArguments(scales, dimensions, useBufferValue, useAdvancedOffsets, useMultiFormat)) {
return;
}
Expand All @@ -1667,7 +1669,8 @@ void VDUStreamProcessor::bufferAffineTransform(uint16_t bufferId, uint8_t comman
} break;
case AFFINE_TRANSLATE: {
// translate by a given amount
float translateXY[dimensions] = {0.0f};
float translateXY[dimensions];
memset(translateXY, 0, sizeof(translateXY));
if (!readFloatArguments(translateXY, dimensions, useBufferValue, useAdvancedOffsets, useMultiFormat)) {
return;
}
Expand All @@ -1677,7 +1680,8 @@ 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] = {0.0f};
float translateXY[dimensions];
memset(translateXY, 0, sizeof(translateXY));
if (!readFloatArguments(translateXY, dimensions, useBufferValue, useAdvancedOffsets, useMultiFormat)) {
return;
}
Expand All @@ -1690,7 +1694,8 @@ void VDUStreamProcessor::bufferAffineTransform(uint16_t bufferId, uint8_t comman
} break;
case AFFINE_SHEAR: {
// shear by a given amount
float shearXY[dimensions] = {0.0f};
float shearXY[dimensions];
memset(shearXY, 0, sizeof(shearXY));
if (!readFloatArguments(shearXY, dimensions, useBufferValue, useAdvancedOffsets, useMultiFormat)) {
return;
}
Expand All @@ -1702,7 +1707,8 @@ 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] = {0.0f};
float skewXY[dimensions];
memset(skewXY, 0, sizeof(skewXY));
if (!readFloatArguments(skewXY, dimensions, useBufferValue, useAdvancedOffsets, useMultiFormat)) {
return;
}
Expand Down Expand Up @@ -1744,10 +1750,11 @@ 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()] = {0.0f};
float existing[size.size()];
memset(existing, 0, sizeof(existing));
if (getMatrixFromBuffer(bufferId, existing, size, false)) {
// combine the two matrices together
float newTransform[size.size()] = {0.0f};
float newTransform[size.size()];
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 +1782,8 @@ 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()] = {0.0f};
float matrix[size.size()];
memset(matrix, 0, sizeof(matrix));

switch (op) {
case MATRIX_SET: {
Expand Down Expand Up @@ -1817,7 +1825,8 @@ 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] = {0.0f};
float args[argCount];
memset(args, 0, sizeof(args));
if (!readFloatArguments(args, argCount, useBufferValue, useAdvancedOffsets, false)) {
return;
}
Expand All @@ -1830,7 +1839,8 @@ 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()] = {0.0f};
float source[size.size()];
memset(source, 0, sizeof(source));
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 +1855,8 @@ 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()] = {0.0f};
float source[size.size()];
memset(source, 0, sizeof(source));
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 +1882,17 @@ void VDUStreamProcessor::bufferMatrixManipulate(uint16_t bufferId, uint8_t comma
MatrixSize resultSize;
resultSize.rows = dimensions;
resultSize.columns = dimensions;
float source1[resultSize.size()] = {0.0f};
float source2[resultSize.size()] = {0.0f};
float source1[resultSize.size()];
float source2[resultSize.size()];
memset(source1, 0, sizeof(source1));
memset(source2, 0, sizeof(source2));
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()] = {0.0f};
float result[resultSize.size()];
memset(result, 0, sizeof(result));
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 +1927,8 @@ 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()] = {0.0f};
float source[sourceSize.size()];
memset(source, 0, sizeof(source));
if (!getMatrixFromBuffer(sourceId, source, sourceSize)) {
debug_log("bufferMatrixManipulate: failed to read matrix from buffer %d\n\r", sourceId);
return;
Expand All @@ -1940,7 +1955,8 @@ void VDUStreamProcessor::bufferMatrixManipulate(uint16_t bufferId, uint8_t comma
return;
}
// read source matrix
float source[sourceSize.size()] = {0.0f};
float source[sourceSize.size()];
memset(source, 0, sizeof(source));
if (!getMatrixFromBuffer(sourceId, source, sourceSize)) {
debug_log("bufferMatrixManipulate: failed to read matrix from buffer %d\n\r", sourceId);
return;
Expand Down Expand Up @@ -2101,8 +2117,8 @@ void VDUStreamProcessor::bufferTransformBitmap(uint16_t bufferId, uint8_t option

debug_log("bufferTransformBitmap: width %d, height %d, xOffset %d, yOffset %d\n\r", width, height, xOffset, yOffset);

for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
// calculate the source pixel
// NB we will need to adjust x,y here if we are auto-translating
pos[0] = (float)x + xOffset;
Expand All @@ -2114,7 +2130,7 @@ void VDUStreamProcessor::bufferTransformBitmap(uint16_t bufferId, uint8_t option
}
destination[(int)y * width + (int)x] = srcPixel;
}
}
}

// save new bitmap data to target buffer
bufferClear(bufferId);
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[] = {
c,
(uint8_t)c,
};
send_packet(PACKET_SCRCHAR, sizeof packet, packet);
}
Expand Down
Loading

0 comments on commit 0c452cb

Please sign in to comment.