Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify emulator and main VDP codebases #274

Merged
merged 42 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
128d0ee
Prevent irritating invisible cursor while navigating. Just 1 pet peev…
tomm Oct 31, 2023
8133415
Sleep sometimes in main loop, to avoid eating 100% cpu
tomm Oct 31, 2023
e6c5954
Merge tag 'v2.1.0' into emulator-console8
tomm Nov 14, 2023
a0016d7
Merge branch 'main' of github.com:AgonConsole8/agon-vdp into emulator…
tomm Dec 15, 2023
79f32d9
Comment out zdi.h
tomm Dec 15, 2023
1210d69
More zdi.h fixes
tomm Dec 15, 2023
f2acc90
Merge branch 'main' of github.com:AgonConsole8/agon-vdp into emulator…
tomm Dec 15, 2023
aba3358
Use raw pointer for soundGenerator to avoid de-init crash. Guard its …
tomm Dec 15, 2023
65ee4e1
Merge tag '2.3.0' of github.com:AgonConsole8/agon-vdp into emulator-c…
tomm Dec 19, 2023
763eb37
Merge branch 'main' of github.com:AgonConsole8/agon-vdp into emulator…
tomm Jan 9, 2024
df1ee2c
Compile fix for clang
tomm Jan 15, 2024
1530a89
Merge tag 'v2.5.0' of github.com:AgonConsole8/agon-vdp into emulator-…
tomm Jan 24, 2024
4c4cf36
playmod fix: workaround for having no real xTaskAbortDelay
tomm Jan 28, 2024
ee0ca71
Merge tag 'v2.6.0' into emulator-console8
tomm Feb 8, 2024
533a157
Support for VDP debug logging in emulator
tomm Feb 23, 2024
39be310
Merge tag 'v2.7.0' into emulator-console8
tomm Mar 22, 2024
ed77f48
Build fixes for the emulator
tomm Mar 22, 2024
a4a9ff0
Support booting into different video mode
tomm Mar 30, 2024
2b51448
Merge tag 'v2.7.1' into emulator-console8
tomm Mar 30, 2024
f50f456
Merge tag 'v2.7.2' into emulator-console8
tomm Apr 5, 2024
94a7051
Bring back sane cursor behaviour while making cursor movements (ie ma…
tomm Apr 5, 2024
d267c52
Merge tag 'v2.7.3' into emulator-console8
tomm Apr 6, 2024
d9e4f72
Merge tag 'v2.8.0' into emulator-console8
tomm Apr 27, 2024
f7d9853
Merge tag 'v2.8.1' into emulator-console8
tomm Apr 27, 2024
132787e
Eliminate some VDP-C8 audio crashes
tomm Jun 10, 2024
a97da69
Fix off-by-one error in charToBitmap, and bad indexing by signed char
tomm Jun 10, 2024
365fc5b
Fix memory corruption due to out-of-bounds vdu_palette calls
tomm Jun 13, 2024
4b719d8
Disable hexload on the emulator
tomm Jun 13, 2024
d2a152f
Audio subsystem redesign
tomm Jun 13, 2024
d179b59
Merge tag 'v2.9.2' into emulator-console8
tomm Jun 21, 2024
9a87197
Fix crash when starting plasma.bin, https://github.com/jblang/agon-demos
tomm Jul 18, 2024
89dc768
Merge tag 'v2.10.0' into emulator-console8
tomm Aug 24, 2024
a95cc70
Build fix post-merge of c8 2.10.0
tomm Aug 25, 2024
80b4086
Clang (macos) build fixes post-2.10.0 merge
tomm Aug 28, 2024
5c6aa1f
Merge tag 'v2.10.1' into emulator-console8
tomm Aug 28, 2024
f194131
Conditional compilation of some emulator-specific code
tomm Sep 17, 2024
ba2646c
Conditional compilation for USERSPACE around DEBUG define
tomm Oct 11, 2024
ca49625
Disable custom terminal keyboard handler. fabgl does this
tomm Dec 23, 2024
7bb290f
Merge pull request #256 from tomm/emulator-console8
stevesims Jan 16, 2025
e7fc7d6
add calls to clear variable size float arrays
stevesims Jan 16, 2025
f384602
fix compiler warning
stevesims Jan 16, 2025
1e5fa08
minor code formatting tweaks
stevesims Jan 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading