Skip to content

Commit

Permalink
Fix RAW OPL reading
Browse files Browse the repository at this point in the history
  • Loading branch information
Eniko committed Nov 20, 2021
1 parent 6160e08 commit 55baf6e
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions utils/capture_opl/OPBinaryLib/opblib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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__);
}

Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 55baf6e

Please # to comment.