int parse_prg(const char* filename) { size_t size = 0; const char* data = (const char*)load_to_memory(filename, &size); if (!data) { return -1; } if (size < 10) { free((void*)data); log_debug("Prg file %s it too small (less than 7 bytes)\n", filename); return -1; } // Seek to pos 7 in the file where the sys offset is located. The file looks like this // // load offset - 2 bytes // unknown - 5 // text string (null terminated) decimal start adress int runAddress = atoi(&data[7]); free((void*)data); return runAddress; }
int osux_database_init(osux_database *db, char const *file_path) { memset(db, 0, sizeof *db); db->in_memory = false; int ret = sqlite3_open(file_path, &db->file_handle); if (ret) { osux_debug("%s\n", sqlite3_errmsg(db->file_handle)); sqlite3_close(db->file_handle); return -OSUX_ERR_DATABASE; } if ((ret = load_to_memory(db)) < 0) return ret; return 0; }
static uint8_t* get_memory_internal(PluginData* data, const char* tempfile, size_t* read_size, uint16_t address, uint16_t addressEnd) { *read_size = 0; #ifndef _WIN32 if (unlink(tempfile) < 0) { log_debug("c64_vice: Unable to delete %s (error %d)\n", tempfile, errno); } #else // TODO: Implement me. /* if (DeleteFile(tempfile) != 0) { printf("failed to delete %s\n", timepfile); return 0; } */ #endif send_command(data, "save \"%s\" 0 %04x %04x\n", tempfile, address, addressEnd); // TODO: Improve this? (wait for (C: as return data back from send command) // Wait 10 ms for operation to complete and if we can't open the file we try for a few times and if we still can't we bail sleepMs(10); for (int i = 0; i < 10; ++i) { uint8_t* mem = load_to_memory(data->temp_file_full, read_size); if (!mem) { sleepMs(1); continue; } log_debug("returing mem...\n", ""); return mem; } log_debug("Unable to get memory...\n", ""); return 0; }