From 55baf6ef9ad6cbfcfa066a799deb0b3be406620a Mon Sep 17 00:00:00 2001 From: Eniko Date: Fri, 19 Nov 2021 18:06:28 -0600 Subject: [PATCH] Fix RAW OPL reading --- utils/capture_opl/OPBinaryLib/opblib.c | 29 +++++++++++++------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/utils/capture_opl/OPBinaryLib/opblib.c b/utils/capture_opl/OPBinaryLib/opblib.c index 0918098..8b3e1d3 100644 --- a/utils/capture_opl/OPBinaryLib/opblib.c +++ b/utils/capture_opl/OPBinaryLib/opblib.c @@ -146,7 +146,7 @@ static const char* GetFilename(const char* path) { return lastFwd > lastBck ? lastFwd + 1 : lastBck + 1; } -static const char* GetSourceFilename() { +static const char* GetSourceFilename(void) { return GetFilename(__FILE__); } @@ -413,7 +413,7 @@ typedef struct Instrument { int Index; } Instrument; -static Context Context_New() { +static Context Context_New(void) { Context context; memset(&context, 0, sizeof(Context)); @@ -1340,26 +1340,27 @@ static int ReadOpbDefault(Context* context) { } #define RAW_READBUFFER_SIZE 256 - -typedef struct RawOpbEntry { - uint16_t Elapsed; - uint16_t Addr; - uint8_t Data; -} RawOpbEntry; +#define RAW_ENTRY_SIZE 5 static int ReadOpbRaw(Context* context) { double time = 0; - RawOpbEntry buffer[RAW_READBUFFER_SIZE]; + uint8_t buffer[RAW_READBUFFER_SIZE * RAW_ENTRY_SIZE]; OPB_Command commandStream[RAW_READBUFFER_SIZE]; size_t itemsRead; - while ((itemsRead = context->Read(buffer, sizeof(RawOpbEntry), RAW_READBUFFER_SIZE, context->UserData)) > 0) { - for (int i = 0; i < itemsRead; i++) { - time += buffer[i].Elapsed / 1000.0; + while ((itemsRead = context->Read(buffer, RAW_ENTRY_SIZE, RAW_READBUFFER_SIZE, context->UserData)) > 0) { + uint8_t* value = buffer; + + for (int i = 0; i < itemsRead; i++, value += RAW_ENTRY_SIZE) { + uint16_t elapsed = (value[0] << 8) | value[1]; + uint16_t addr = (value[2] << 8) | value[3]; + uint8_t data = value[4]; + + time += elapsed / 1000.0; OPB_Command cmd = { - buffer[i].Addr, - buffer[i].Data, + addr, + data, time }; commandStream[i] = cmd;