Clang buildfixes - step 1

This commit is contained in:
libretroadmin 2023-11-01 16:17:22 +01:00
parent e21bf74bdd
commit 9455d40922
22 changed files with 369 additions and 688 deletions

View File

@ -49,10 +49,9 @@ typedef enum {
EMU_LANG_UNKNOWN = -1 EMU_LANG_UNKNOWN = -1
} EmuLanguageType; } EmuLanguageType;
void langInit(); void langInit(void);
int langSetLanguage(EmuLanguageType languageType); EmuLanguageType langGetLanguage(void);
EmuLanguageType langGetLanguage();
EmuLanguageType langFromName(char* name, int translate); EmuLanguageType langFromName(char* name, int translate);
const char* langToName(EmuLanguageType languageType, int translate); const char* langToName(EmuLanguageType languageType, int translate);
EmuLanguageType langGetType(int i); EmuLanguageType langGetType(int i);

View File

@ -44,14 +44,7 @@ EmuLanguageType langGetType(int i)
return i == 0 ? EMU_LANG_ENGLISH : EMU_LANG_UNKNOWN; return i == 0 ? EMU_LANG_ENGLISH : EMU_LANG_UNKNOWN;
} }
void langInit() { void langInit(void) { }
}
int langSetLanguage(EmuLanguageType languageType)
{
return languageType == EMU_LANG_ENGLISH ? 1 : 0;
}
//---------------------- //----------------------
// Generic lines // Generic lines

View File

@ -164,7 +164,7 @@ static void setDeviceInfo(BoardDeviceInfo* deviceInfo)
strcpy(deviceInfo->tapes[i].inZipName, properties->media.tapes[i].fileNameInZip); strcpy(deviceInfo->tapes[i].inZipName, properties->media.tapes[i].fileNameInZip);
} }
deviceInfo->video.vdpSyncMode = properties->emulation.vdpSyncMode; deviceInfo->video.vdpSyncMode = (VdpSyncMode)properties->emulation.vdpSyncMode;
} }

View File

@ -79,7 +79,7 @@ ArchGlob* archGlob(const char* pattern, int flags)
strcat(path, wfd.cFileName); strcat(path, wfd.cFileName);
glob->count++; glob->count++;
glob->pathVector = realloc(glob->pathVector, sizeof(char*) * glob->count); glob->pathVector = (char**)realloc(glob->pathVector, sizeof(char*) * glob->count);
glob->pathVector[glob->count - 1] = path; glob->pathVector[glob->count - 1] = path;
} }
} while (FindNextFile(handle, &wfd)); } while (FindNextFile(handle, &wfd));
@ -124,13 +124,10 @@ ArchGlob* archGlob(const char* pattern, int flags)
{ {
glob_t g; glob_t g;
ArchGlob* globHandle = NULL; ArchGlob* globHandle = NULL;
int rv;
int i; int i;
int rv = glob(pattern, GLOB_MARK, NULL, &g);
rv = glob(pattern, GLOB_MARK, NULL, &g); if (rv != 0)
if (rv != 0) {
return NULL; return NULL;
}
globHandle = (ArchGlob*)calloc(1, sizeof(ArchGlob)); globHandle = (ArchGlob*)calloc(1, sizeof(ArchGlob));
@ -139,18 +136,18 @@ ArchGlob* archGlob(const char* pattern, int flags)
int len = strlen(path); int len = strlen(path);
if ((flags & ARCH_GLOB_DIRS) && path[len - 1] == '/') { if ((flags & ARCH_GLOB_DIRS) && path[len - 1] == '/') {
char* storePath = calloc(1, len); char* storePath = (char*)calloc(1, len);
memcpy(storePath, path, len - 1); memcpy(storePath, path, len - 1);
globHandle->count++; globHandle->count++;
globHandle->pathVector = realloc(globHandle->pathVector, sizeof(char*) * globHandle->count); globHandle->pathVector = (char**)realloc(globHandle->pathVector, sizeof(char*) * globHandle->count);
globHandle->pathVector[globHandle->count - 1] = storePath; globHandle->pathVector[globHandle->count - 1] = storePath;
} }
if ((flags & ARCH_GLOB_FILES) && path[len - 1] != '/') { if ((flags & ARCH_GLOB_FILES) && path[len - 1] != '/') {
char* storePath = calloc(1, len + 1); char* storePath = (char*)calloc(1, len + 1);
memcpy(storePath, path, len); memcpy(storePath, path, len);
globHandle->count++; globHandle->count++;
globHandle->pathVector = realloc(globHandle->pathVector, sizeof(char*) * globHandle->count); globHandle->pathVector = (char**)realloc(globHandle->pathVector, sizeof(char*) * globHandle->count);
globHandle->pathVector[globHandle->count - 1] = storePath; globHandle->pathVector[globHandle->count - 1] = storePath;
} }
} }

View File

@ -97,9 +97,8 @@ static int checkCommandProgram(AmdFlash* rm)
if (rm->cmdIdx < 4) return 1; if (rm->cmdIdx < 4) return 1;
if (((rm->writeProtectMask >> (rm->cmd[3].address / rm->sectorSize)) & 1) == 0) { if (((rm->writeProtectMask >> (rm->cmd[3].address / rm->sectorSize)) & 1) == 0)
rm->romData[rm->cmd[3].address & (rm->flashSize - 1)] &= rm->cmd[3].value; rm->romData[rm->cmd[3].address & (rm->flashSize - 1)] &= rm->cmd[3].value;
}
return 0; return 0;
} }
@ -109,9 +108,8 @@ static int checkCommandManifacturer(AmdFlash* rm)
if (rm->cmdIdx > 1 && ((rm->cmd[1].address & 0x7ff) != rm->cmdAddr2 || rm->cmd[1].value != 0x55)) return 0; if (rm->cmdIdx > 1 && ((rm->cmd[1].address & 0x7ff) != rm->cmdAddr2 || rm->cmd[1].value != 0x55)) return 0;
if (rm->cmdIdx > 2 && ((rm->cmd[2].address & 0x7ff) != rm->cmdAddr1 || rm->cmd[2].value != 0x90)) return 0; if (rm->cmdIdx > 2 && ((rm->cmd[2].address & 0x7ff) != rm->cmdAddr1 || rm->cmd[2].value != 0x90)) return 0;
if (rm->cmdIdx == 3) { if (rm->cmdIdx == 3)
rm->state = ST_IDENT; rm->state = ST_IDENT;
}
if (rm->cmdIdx < 4) return 1; if (rm->cmdIdx < 4) return 1;
return 0; return 0;
@ -121,7 +119,6 @@ UInt8 amdFlashRead(AmdFlash* rm, UInt32 address)
{ {
if (rm->state == ST_IDENT) { if (rm->state == ST_IDENT) {
rm->cmdIdx = 0; rm->cmdIdx = 0;
// printf("R %.4x: XX\n", address);
switch (address & 0x03) { switch (address & 0x03) {
case 0: case 0:
return 0x01; return 0x01;
@ -134,7 +131,6 @@ UInt8 amdFlashRead(AmdFlash* rm, UInt32 address)
} }
return 0xff; return 0xff;
} }
// printf("R %.4x: %.2x\n", address, rm->romData[address & (rm->flashSize - 1)]);
address &= rm->flashSize - 1; address &= rm->flashSize - 1;
@ -146,8 +142,6 @@ void amdFlashWrite(AmdFlash* rm, UInt32 address, UInt8 value)
if (rm->cmdIdx < sizeof(rm->cmd) / sizeof(rm->cmd[0])) { if (rm->cmdIdx < sizeof(rm->cmd) / sizeof(rm->cmd[0])) {
int stateValid = 0; int stateValid = 0;
// { static int x = 0; if (++x < 220) printf("W %.4x: %.2x %d\n", address, value, rm->cmdIdx);}
rm->cmd[rm->cmdIdx].address = address; rm->cmd[rm->cmdIdx].address = address;
rm->cmd[rm->cmdIdx].value = value; rm->cmd[rm->cmdIdx].value = value;
rm->cmdIdx++; rm->cmdIdx++;
@ -244,19 +238,17 @@ AmdFlash* amdFlashCreate(AmdType type, int flashSize, int sectorSize, UInt32 wri
rm->flashSize = flashSize; rm->flashSize = flashSize;
rm->sectorSize = sectorSize; rm->sectorSize = sectorSize;
rm->romData = malloc(flashSize); rm->romData = (UInt8*)malloc(flashSize);
if (size >= flashSize) { if (size >= flashSize)
size = flashSize; size = flashSize;
}
if (rm->sramFilename[0]) { if (rm->sramFilename[0]) {
memset(rm->romData + size, 0xff, flashSize - size); memset(rm->romData + size, 0xff, flashSize - size);
sramLoad(rm->sramFilename, rm->romData, rm->flashSize, NULL, 0); sramLoad(rm->sramFilename, rm->romData, rm->flashSize, NULL, 0);
} }
if (size > 0) { if (size > 0)
memcpy(rm->romData, romData, size); memcpy(rm->romData, romData, size);
}
#if 0 #if 0
if (rm->sramFilename[0] && loadSram) { if (rm->sramFilename[0] && loadSram) {
sramLoad(rm->sramFilename, rm->romData, rm->flashSize, NULL, 0); sramLoad(rm->sramFilename, rm->romData, rm->flashSize, NULL, 0);
@ -268,8 +260,7 @@ AmdFlash* amdFlashCreate(AmdType type, int flashSize, int sectorSize, UInt32 wri
void amdFlashDestroy(AmdFlash* rm) void amdFlashDestroy(AmdFlash* rm)
{ {
if (rm->sramFilename[0]) { if (rm->sramFilename[0])
sramSave(rm->sramFilename, rm->romData, rm->flashSize, NULL, 0); sramSave(rm->sramFilename, rm->romData, rm->flashSize, NULL, 0);
}
free(rm); free(rm);
} }

View File

@ -244,23 +244,20 @@ AtmelPerom* atmelPeromCreate(AmdType type, int flashSize, int sectorSize, UInt32
rm->flashSize = flashSize; rm->flashSize = flashSize;
rm->sectorSize = sectorSize; rm->sectorSize = sectorSize;
rm->romData = malloc(flashSize); rm->romData = (UInt8*)malloc(flashSize);
if (size >= flashSize) { if (size >= flashSize)
size = flashSize; size = flashSize;
}
if (rm->sramFilename[0]) { if (rm->sramFilename[0]) {
memset(rm->romData + size, 0xff, flashSize - size); memset(rm->romData + size, 0xff, flashSize - size);
sramLoad(rm->sramFilename, rm->romData, rm->flashSize, NULL, 0); sramLoad(rm->sramFilename, rm->romData, rm->flashSize, NULL, 0);
} }
if (size > 0) { if (size > 0)
memcpy(rm->romData, romData, size); memcpy(rm->romData, romData, size);
}
#if 0 #if 0
if (rm->sramFilename[0] && loadSram) { if (rm->sramFilename[0] && loadSram)
sramLoad(rm->sramFilename, rm->romData, rm->flashSize, NULL, 0); sramLoad(rm->sramFilename, rm->romData, rm->flashSize, NULL, 0);
}
#endif #endif
return rm; return rm;
@ -268,8 +265,7 @@ AtmelPerom* atmelPeromCreate(AmdType type, int flashSize, int sectorSize, UInt32
void atmelPeromDestroy(AtmelPerom* rm) void atmelPeromDestroy(AtmelPerom* rm)
{ {
if (rm->sramFilename[0]) { if (rm->sramFilename[0])
sramSave(rm->sramFilename, rm->romData, rm->flashSize, NULL, 0); sramSave(rm->sramFilename, rm->romData, rm->flashSize, NULL, 0);
}
free(rm); free(rm);
} }

View File

@ -39,36 +39,34 @@ UInt8* romLoad(const char *fileName, const char *fileInZipFile, int* size)
UInt8* buf = NULL; UInt8* buf = NULL;
FILE *file; FILE *file;
if (fileName == NULL || strlen(fileName) == 0) { if (!fileName || strlen(fileName) == 0)
goto error; goto error;
}
if (fileInZipFile != NULL && strlen(fileInZipFile) == 0) { if (fileInZipFile && strlen(fileInZipFile) == 0)
fileInZipFile = NULL; fileInZipFile = NULL;
}
if (fileInZipFile != NULL) { if (fileInZipFile)
buf = zipLoadFile(fileName, fileInZipFile, size); {
if (buf == NULL) buf = (UInt8*)zipLoadFile(fileName, fileInZipFile, size);
if (!buf)
goto error; goto error;
return buf; return buf;
} }
file = fopen(fileName, "rb"); file = fopen(fileName, "rb");
if (file == NULL) { if (!file)
goto error; goto error;
}
fseek(file, 0, SEEK_END); fseek(file, 0, SEEK_END);
*size = ftell(file); *size = ftell(file);
if (*size == 0) { if (*size == 0) {
fclose(file); fclose(file);
return malloc(1); return (UInt8*)malloc(1);
} }
fseek(file, 0, SEEK_SET); fseek(file, 0, SEEK_SET);
buf = malloc(*size); buf = (UInt8*)malloc(*size);
*size = fread(buf, 1, *size, file); *size = fread(buf, 1, *size, file);
fclose(file); fclose(file);
@ -80,4 +78,3 @@ error:
fflush(stdout); fflush(stdout);
return NULL; return NULL;
} }

View File

@ -48,8 +48,9 @@ typedef struct {
UInt8 ramData[0x2000]; UInt8 ramData[0x2000];
} Ram1kBMirrored; } Ram1kBMirrored;
static void saveState(Ram1kBMirrored* rm) static void ram1kb_saveState(void *data)
{ {
Ram1kBMirrored *rm = (Ram1kBMirrored*)data;
SaveState* state = saveStateOpenForWrite("mapperMirroredRam"); SaveState* state = saveStateOpenForWrite("mapperMirroredRam");
saveStateSet(state, "mask", rm->mask); saveStateSet(state, "mask", rm->mask);
@ -58,8 +59,9 @@ static void saveState(Ram1kBMirrored* rm)
saveStateClose(state); saveStateClose(state);
} }
static void loadState(Ram1kBMirrored* rm) static void ram1kb_loadState(void *data)
{ {
Ram1kBMirrored *rm = (Ram1kBMirrored*)data;
SaveState* state = saveStateOpenForRead("mapperMirroredRam"); SaveState* state = saveStateOpenForRead("mapperMirroredRam");
rm->mask = saveStateGet(state, "mask", 0x400); rm->mask = saveStateGet(state, "mask", 0x400);
@ -68,8 +70,9 @@ static void loadState(Ram1kBMirrored* rm)
saveStateClose(state); saveStateClose(state);
} }
static void destroy(Ram1kBMirrored* rm) static void ram1kb_destroy(void *data)
{ {
Ram1kBMirrored *rm = (Ram1kBMirrored*)data;
debugDeviceUnregister(rm->debugHandle); debugDeviceUnregister(rm->debugHandle);
slotUnregister(rm->slot, rm->sslot, 0); slotUnregister(rm->slot, rm->sslot, 0);
@ -78,51 +81,52 @@ static void destroy(Ram1kBMirrored* rm)
free(rm); free(rm);
} }
static void getDebugInfo(Ram1kBMirrored* rm, DbgDevice* dbgDevice) static void ram1kb_getDebugInfo(void *data, DbgDevice* dbgDevice)
{ {
Ram1kBMirrored *rm = (Ram1kBMirrored*)data;
dbgDeviceAddMemoryBlock(dbgDevice, langDbgMemRamNormal(), 0, 0, rm->mask + 1, rm->ramData); dbgDeviceAddMemoryBlock(dbgDevice, langDbgMemRamNormal(), 0, 0, rm->mask + 1, rm->ramData);
} }
static int dbgWriteMemory(Ram1kBMirrored* rm, char* name, void* data, int start, int size) static int ram1kb_dbgWriteMemory(void *data1, char* name, void *data2, int start, int size)
{ {
if (strcmp(name, "Normal") || start + size >= (int)rm->mask) { Ram1kBMirrored *rm = (Ram1kBMirrored*)data1;
if (strcmp(name, "Normal") || start + size >= (int)rm->mask)
return 0; return 0;
}
memcpy(rm->ramData + start, data, size); memcpy(rm->ramData + start, data2, size);
return 1; return 1;
} }
static UInt8 read(Ram1kBMirrored* rm, UInt16 address) static UInt8 ram1kb_read(void *data, UInt16 address)
{ {
Ram1kBMirrored *rm = (Ram1kBMirrored*)data;
return rm->ramData[address & rm->mask]; return rm->ramData[address & rm->mask];
} }
static void write(Ram1kBMirrored* rm, UInt16 address, UInt8 value) static void ram1kb_write(void *data, UInt16 address, UInt8 value)
{ {
Ram1kBMirrored *rm = (Ram1kBMirrored*)data;
rm->ramData[address & rm->mask] = value; rm->ramData[address & rm->mask] = value;
} }
int ramMirroredCreate(int size, int slot, int sslot, int startPage, int ramMirroredCreate(int size, int slot, int sslot, int startPage,
UInt32 ramBlockSize, UInt8** ramPtr, UInt32* ramSize) UInt32 ramBlockSize, UInt8** ramPtr, UInt32* ramSize)
{ {
DeviceCallbacks callbacks = { destroy, NULL, saveState, loadState }; DeviceCallbacks callbacks = { ram1kb_destroy, NULL, ram1kb_saveState, ram1kb_loadState };
DebugCallbacks dbgCallbacks = { getDebugInfo, dbgWriteMemory, NULL, NULL }; DebugCallbacks dbgCallbacks = { ram1kb_getDebugInfo, ram1kb_dbgWriteMemory, NULL, NULL };
Ram1kBMirrored* rm; Ram1kBMirrored* rm;
int pages = size / 0x2000; int pages = size / 0x2000;
int i; int i;
if (size > 0x10000 || (size & 0x1fff)) { if (size > 0x10000 || (size & 0x1fff))
return 0; return 0;
}
// Start page must be zero (only full slot allowed) // Start page must be zero (only full slot allowed)
if (startPage + pages > 8) { if (startPage + pages > 8)
return 0; return 0;
}
rm = malloc(sizeof(Ram1kBMirrored)); rm = (Ram1kBMirrored*)malloc(sizeof(Ram1kBMirrored));
rm->mask = ramBlockSize - 1; rm->mask = ramBlockSize - 1;
rm->slot = slot; rm->slot = slot;
@ -134,22 +138,18 @@ int ramMirroredCreate(int size, int slot, int sslot, int startPage,
rm->debugHandle = debugDeviceRegister(DBGTYPE_RAM, langDbgDevRam(), &dbgCallbacks, rm); rm->debugHandle = debugDeviceRegister(DBGTYPE_RAM, langDbgDevRam(), &dbgCallbacks, rm);
for (i = 0; i < pages; i++) { for (i = 0; i < pages; i++)
slotMapPage(slot, sslot, i + startPage, NULL, 0, 0); slotMapPage(slot, sslot, i + startPage, NULL, 0, 0);
}
rm->deviceHandle = deviceManagerRegister(ramBlockSize == 0x400 ? RAM_1KB_MIRRORED : RAM_2KB_MIRRORED, rm->deviceHandle = deviceManagerRegister(ramBlockSize == 0x400 ? RAM_1KB_MIRRORED : RAM_2KB_MIRRORED,
&callbacks, rm); &callbacks, rm);
slotRegister(slot, sslot, startPage, pages, read, read, write, destroy, rm); slotRegister(slot, sslot, startPage, pages, ram1kb_read, ram1kb_read, ram1kb_write, ram1kb_destroy, rm);
if (ramPtr != NULL) { if (ramPtr)
*ramPtr = rm->ramData; *ramPtr = rm->ramData;
}
if (ramSize != NULL) { if (ramSize)
*ramSize = rm->pages * 0x2000; *ramSize = rm->pages * 0x2000;
}
return 1; return 1;
} }

View File

@ -39,7 +39,6 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
typedef struct { typedef struct {
int deviceHandle; int deviceHandle;
UInt8* ramData; UInt8* ramData;
@ -54,10 +53,9 @@ typedef struct {
int size; int size;
} RamMapper; } RamMapper;
static void writeIo(RamMapper* rm, UInt16 page, UInt8 value); static void rammapper_saveState(void *data)
static void saveState(RamMapper* rm)
{ {
RamMapper *rm = (RamMapper*)rm;
SaveState* state = saveStateOpenForWrite("mapperRam"); SaveState* state = saveStateOpenForWrite("mapperRam");
saveStateSet(state, "mask", rm->mask); saveStateSet(state, "mask", rm->mask);
@ -69,39 +67,10 @@ static void saveState(RamMapper* rm)
saveStateClose(state); saveStateClose(state);
} }
static void loadState(RamMapper* rm) static void rammapper_writeIo(void *data, UInt16 page, UInt8 value)
{ {
SaveState* state = saveStateOpenForRead("mapperRam"); RamMapper *rm = (RamMapper*)rm;
int i; int baseAddr = 0x4000 * (value & rm->mask);
rm->mask = saveStateGet(state, "mask", 0);
rm->dramMode = saveStateGet(state, "dramMode", 0);
saveStateGetBuffer(state, "port", rm->port, 4);
saveStateGetBuffer(state, "ramData", rm->ramData, 0x4000 * (rm->mask + 1));
saveStateClose(state);
#if 1
for (i = 0; i < 4; i++) {
writeIo(rm, i, rm->port[i]);
}
#else
ramMapperIoRemove(rm->handle);
rm->handle = ramMapperIoAdd(0x4000 * (rm->mask + 1), writeIo, rm);
for (i = 0; i < 4; i++) {
int value = ramMapperIoGetPortValue(i) & rm->mask;
int mapped = rm->dramMode && (rm->mask - value < 4) ? 0 : 1;
slotMapPage(rm->slot, rm->sslot, 2 * i, rm->ramData + 0x4000 * value, 1, mapped);
slotMapPage(rm->slot, rm->sslot, 2 * i + 1, rm->ramData + 0x4000 * value + 0x2000, 1, mapped);
}
#endif
}
static void writeIo(RamMapper* rm, UInt16 page, UInt8 value)
{
int baseAddr = 0x4000 * (value & rm->mask);
rm->port[page] = value; rm->port[page] = value;
if (rm->dramMode && baseAddr >= (rm->size - 0x10000)) { if (rm->dramMode && baseAddr >= (rm->size - 0x10000)) {
slotMapPage(rm->slot, rm->sslot, 2 * page, NULL, 0, 0); slotMapPage(rm->slot, rm->sslot, 2 * page, NULL, 0, 0);
@ -113,24 +82,55 @@ static void writeIo(RamMapper* rm, UInt16 page, UInt8 value)
} }
} }
static void setDram(RamMapper* rm, int enable) static void rammapper_loadState(void *data)
{ {
int i; int i;
RamMapper *rm = (RamMapper*)data;
SaveState* state = saveStateOpenForRead("mapperRam");
rm->mask = saveStateGet(state, "mask", 0);
rm->dramMode = saveStateGet(state, "dramMode", 0);
saveStateGetBuffer(state, "port", rm->port, 4);
saveStateGetBuffer(state, "ramData", rm->ramData, 0x4000 * (rm->mask + 1));
saveStateClose(state);
#if 1
for (i = 0; i < 4; i++)
rammapper_writeIo(rm, i, rm->port[i]);
#else
ramMapperIoRemove(rm->handle);
rm->handle = ramMapperIoAdd(0x4000 * (rm->mask + 1), rammapper_writeIo, rm);
for (i = 0; i < 4; i++) {
int value = ramMapperIoGetPortValue(i) & rm->mask;
int mapped = rm->dramMode && (rm->mask - value < 4) ? 0 : 1;
slotMapPage(rm->slot, rm->sslot, 2 * i, rm->ramData + 0x4000 * value, 1, mapped);
slotMapPage(rm->slot, rm->sslot, 2 * i + 1, rm->ramData + 0x4000 * value + 0x2000, 1, mapped);
}
#endif
}
static void rammapper_setDram(void *data, int enable)
{
int i;
RamMapper *rm = (RamMapper*)data;
rm->dramMode = enable; rm->dramMode = enable;
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++)
writeIo(rm, i, ramMapperIoGetPortValue(i)); rammapper_writeIo(rm, i, ramMapperIoGetPortValue(i));
}
} }
static void reset(RamMapper* rm) static void rammapper_reset(RamMapper* rm)
{ {
setDram(rm, 0); rammapper_setDram(rm, 0);
} }
static void destroy(RamMapper* rm) static void rammapper_destroy(void *data)
{ {
RamMapper *rm = (RamMapper*)data;
debugDeviceUnregister(rm->debugHandle); debugDeviceUnregister(rm->debugHandle);
ramMapperIoRemove(rm->handle); ramMapperIoRemove(rm->handle);
slotUnregister(rm->slot, rm->sslot, 0); slotUnregister(rm->slot, rm->sslot, 0);
@ -141,26 +141,27 @@ static void destroy(RamMapper* rm)
free(rm); free(rm);
} }
static void getDebugInfo(RamMapper* rm, DbgDevice* dbgDevice) static void rammapper_getDebugInfo(void *data, DbgDevice* dbgDevice)
{ {
RamMapper *rm = (RamMapper*)data;
dbgDeviceAddMemoryBlock(dbgDevice, langDbgMemRamMapped(), 0, 0, rm->size, rm->ramData); dbgDeviceAddMemoryBlock(dbgDevice, langDbgMemRamMapped(), 0, 0, rm->size, rm->ramData);
} }
static int dbgWriteMemory(RamMapper* rm, char* name, void* data, int start, int size) static int rammapper_dbgWriteMemory(void *data1, char* name, void *data2, int start, int size)
{ {
if (strcmp(name, "Mapped") || start + size > rm->size) { RamMapper *rm = (RamMapper*)data1;
if (strcmp(name, "Mapped") || start + size > rm->size)
return 0; return 0;
}
memcpy(rm->ramData + start, data, size); memcpy(rm->ramData + start, data2, size);
return 1; return 1;
} }
int ramMapperCreate(int size, int slot, int sslot, int startPage, UInt8** ramPtr, UInt32* ramSize) int ramMapperCreate(int size, int slot, int sslot, int startPage, UInt8** ramPtr, UInt32* ramSize)
{ {
DeviceCallbacks callbacks = { destroy, NULL, saveState, loadState }; DeviceCallbacks callbacks = { rammapper_destroy, NULL, rammapper_saveState, rammapper_loadState };
DebugCallbacks dbgCallbacks = { getDebugInfo, dbgWriteMemory, NULL, NULL }; DebugCallbacks dbgCallbacks = { rammapper_getDebugInfo, rammapper_dbgWriteMemory, NULL, NULL };
RamMapper* rm; RamMapper* rm;
int pages = size / 0x4000; int pages = size / 0x4000;
int i; int i;
@ -168,20 +169,18 @@ int ramMapperCreate(int size, int slot, int sslot, int startPage, UInt8** ramPtr
// Check that memory is a power of 2 and at least 64kB // Check that memory is a power of 2 and at least 64kB
for (i = 4; i < pages; i <<= 1); for (i = 4; i < pages; i <<= 1);
if (i != pages) { if (i != pages)
return 0; return 0;
}
size = pages * 0x4000; size = pages * 0x4000;
// Start page must be zero (only full slot allowed) // Start page must be zero (only full slot allowed)
if (startPage != 0) { if (startPage != 0)
return 0; return 0;
}
rm = malloc(sizeof(RamMapper)); rm = (RamMapper*)malloc(sizeof(RamMapper));
rm->ramData = malloc(size); rm->ramData = (UInt8*)malloc(size);
rm->size = size; rm->size = size;
rm->slot = slot; rm->slot = slot;
rm->sslot = sslot; rm->sslot = sslot;
@ -190,23 +189,22 @@ int ramMapperCreate(int size, int slot, int sslot, int startPage, UInt8** ramPtr
memset(rm->ramData, 0xff, size); memset(rm->ramData, 0xff, size);
rm->handle = ramMapperIoAdd(pages * 0x4000, writeIo, rm); rm->handle = ramMapperIoAdd(pages * 0x4000, rammapper_writeIo, rm);
rm->debugHandle = debugDeviceRegister(DBGTYPE_RAM, langDbgDevRam(), &dbgCallbacks, rm); rm->debugHandle = debugDeviceRegister(DBGTYPE_RAM, langDbgDevRam(), &dbgCallbacks, rm);
rm->deviceHandle = deviceManagerRegister(RAM_MAPPER, &callbacks, rm); rm->deviceHandle = deviceManagerRegister(RAM_MAPPER, &callbacks, rm);
slotRegister(slot, sslot, 0, 8, NULL, NULL, NULL, destroy, rm); slotRegister(slot, sslot, 0, 8, NULL, NULL, NULL, rammapper_destroy, rm);
reset(rm); rammapper_reset(rm);
if (ramPtr != NULL) { if (ramPtr != NULL) {
// Main RAM // Main RAM
rm->dramHandle = panasonicDramRegister(setDram, rm); rm->dramHandle = panasonicDramRegister(rammapper_setDram, rm);
*ramPtr = rm->ramData; *ramPtr = rm->ramData;
} }
if (ramSize != NULL) { if (ramSize != NULL)
*ramSize = size; *ramSize = size;
}
return 1; return 1;
} }

View File

@ -63,16 +63,16 @@ static int ramMapperIoGetMask(RamMapperIo* rm)
int i; int i;
for (i = 0; i < rm->count; i++) { for (i = 0; i < rm->count; i++) {
while (size < rm->mapperCb[i].size) { while (size < rm->mapperCb[i].size)
size <<= 1; size <<= 1;
}
} }
return (size / 0x4000) - 1; return (size / 0x4000) - 1;
} }
static void saveState(RamMapperIo* rm) static void rammapperio_saveState(void *data)
{ {
RamMapperIo *rm = (RamMapperIo*)data;
SaveState* state = saveStateOpenForWrite("mapperRamIo"); SaveState* state = saveStateOpenForWrite("mapperRamIo");
saveStateSet(state, "port0", rm->port[0]); saveStateSet(state, "port0", rm->port[0]);
saveStateSet(state, "port1", rm->port[1]); saveStateSet(state, "port1", rm->port[1]);
@ -82,8 +82,9 @@ static void saveState(RamMapperIo* rm)
saveStateClose(state); saveStateClose(state);
} }
static void loadState(RamMapperIo* rm) static void rammapperio_loadState(void *data)
{ {
RamMapperIo *rm = (RamMapperIo*)data;
SaveState* state = saveStateOpenForRead("mapperRamIo"); SaveState* state = saveStateOpenForRead("mapperRamIo");
rm->port[0] = saveStateGet(state, "port0", 3); rm->port[0] = saveStateGet(state, "port0", 3);
rm->port[1] = saveStateGet(state, "port1", 2); rm->port[1] = saveStateGet(state, "port1", 2);
@ -95,8 +96,9 @@ static void loadState(RamMapperIo* rm)
saveStateClose(state); saveStateClose(state);
} }
static void destroy(RamMapperIo* rm) static void rammapperio_destroy(void *data)
{ {
RamMapperIo *rm = (RamMapperIo*)data;
ioPortUnregister(0xfc); ioPortUnregister(0xfc);
ioPortUnregister(0xfd); ioPortUnregister(0xfd);
ioPortUnregister(0xfe); ioPortUnregister(0xfe);
@ -109,13 +111,15 @@ static void destroy(RamMapperIo* rm)
mapperIo = NULL; mapperIo = NULL;
} }
static UInt8 read(RamMapperIo* rm, UInt16 ioPort) static UInt8 rammapperio_read(void *data, UInt16 ioPort)
{ {
RamMapperIo *rm = (RamMapperIo*)data;
return rm->port[ioPort & 3] | ~rm->mask; return rm->port[ioPort & 3] | ~rm->mask;
} }
static void write(RamMapperIo* rm, UInt16 ioPort, UInt8 value) static void rammapperio_write(void *data, UInt16 ioPort, UInt8 value)
{ {
RamMapperIo *rm = (RamMapperIo*)data;
ioPort &= 3; ioPort &= 3;
if (rm->port[ioPort] != value) { if (rm->port[ioPort] != value) {
@ -124,31 +128,28 @@ static void write(RamMapperIo* rm, UInt16 ioPort, UInt8 value)
rm->port[ioPort] = value; rm->port[ioPort] = value;
for (i = 0; i < rm->count; i++) { for (i = 0; i < rm->count; i++) {
if (rm->mapperCb[i].write != NULL) { if (rm->mapperCb[i].write != NULL)
rm->mapperCb[i].write(rm->mapperCb[i].ref, ioPort, value); rm->mapperCb[i].write(rm->mapperCb[i].ref, ioPort, value);
}
} }
} }
} }
static void getDebugInfo(RamMapperIo* rm, DbgDevice* dbgDevice) static void rammapperio_getDebugInfo(void *data, DbgDevice* dbgDevice)
{ {
DbgIoPorts* ioPorts;
int i; int i;
RamMapperIo *rm = (RamMapperIo*)data;
ioPorts = dbgDeviceAddIoPorts(dbgDevice, langDbgDevRamMapper(), 4); DbgIoPorts *ioPorts = dbgDeviceAddIoPorts(dbgDevice, langDbgDevRamMapper(), 4);
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++)
dbgIoPortsAddPort(ioPorts, i, 0xfc + i, DBG_IO_READWRITE, read(rm, 0xfc + i)); dbgIoPortsAddPort(ioPorts, i, 0xfc + i, DBG_IO_READWRITE, rammapperio_read(rm, 0xfc + i));
}
} }
int ramMapperIoCreate() int ramMapperIoCreate()
{ {
RamMapperIo* rm; RamMapperIo* rm;
DeviceCallbacks callbacks = { destroy, NULL, saveState, loadState }; DeviceCallbacks callbacks = { rammapperio_destroy, NULL, rammapperio_saveState, rammapperio_loadState };
DebugCallbacks dbgCallbacks = { getDebugInfo, NULL, NULL, NULL }; DebugCallbacks dbgCallbacks = { rammapperio_getDebugInfo, NULL, NULL, NULL };
rm = malloc(sizeof(RamMapperIo)); rm = (RamMapperIo*)malloc(sizeof(RamMapperIo));
rm->count = 0; rm->count = 0;
rm->mask = 0; rm->mask = 0;
rm->handleCount = 0; rm->handleCount = 0;
@ -161,10 +162,10 @@ int ramMapperIoCreate()
rm->deviceHandle = deviceManagerRegister(RAM_MAPPER, &callbacks, rm); rm->deviceHandle = deviceManagerRegister(RAM_MAPPER, &callbacks, rm);
rm->debugHandle = debugDeviceRegister(DBGTYPE_BIOS, langDbgDevRamMapper(), &dbgCallbacks, rm); rm->debugHandle = debugDeviceRegister(DBGTYPE_BIOS, langDbgDevRamMapper(), &dbgCallbacks, rm);
ioPortRegister(0xfc, read, write, rm); ioPortRegister(0xfc, rammapperio_read, rammapperio_write, rm);
ioPortRegister(0xfd, read, write, rm); ioPortRegister(0xfd, rammapperio_read, rammapperio_write, rm);
ioPortRegister(0xfe, read, write, rm); ioPortRegister(0xfe, rammapperio_read, rammapperio_write, rm);
ioPortRegister(0xff, read, write, rm); ioPortRegister(0xff, rammapperio_read, rammapperio_write, rm);
mapperIo = rm; mapperIo = rm;
@ -174,10 +175,8 @@ int ramMapperIoCreate()
int ramMapperIoGetPortValue(int ioPort) int ramMapperIoGetPortValue(int ioPort)
{ {
RamMapperIo* rm = mapperIo; RamMapperIo* rm = mapperIo;
if (rm == NULL) { if (rm == NULL)
return 0xff; return 0xff;
}
return rm->port[ioPort & 3]; return rm->port[ioPort & 3];
} }

View File

@ -47,8 +47,9 @@ typedef struct {
UInt8 ramData[0x10000]; UInt8 ramData[0x10000];
} RamNormal; } RamNormal;
static void saveState(RamNormal* rm) static void ramnormal_saveState(void *data)
{ {
RamNormal *rm = (RamNormal*)data;
SaveState* state = saveStateOpenForWrite("mapperNormalRam"); SaveState* state = saveStateOpenForWrite("mapperNormalRam");
saveStateSet(state, "pages", rm->pages); saveStateSet(state, "pages", rm->pages);
@ -57,10 +58,11 @@ static void saveState(RamNormal* rm)
saveStateClose(state); saveStateClose(state);
} }
static void loadState(RamNormal* rm) static void ramnormal_loadState(void *data)
{ {
SaveState* state = saveStateOpenForRead("mapperNormalRam");
int i; int i;
RamNormal *rm = (RamNormal*)data;
SaveState* state = saveStateOpenForRead("mapperNormalRam");
rm->pages = saveStateGet(state, "pages", 0); rm->pages = saveStateGet(state, "pages", 0);
@ -68,13 +70,16 @@ static void loadState(RamNormal* rm)
saveStateClose(state); saveStateClose(state);
#if 0
for (i = 0; i < rm->pages; i++) { for (i = 0; i < rm->pages; i++) {
// slotMapPage(rm->slot, rm->sslot, i + rm->startPage, rm->ramData + 0x2000 * i, 1, 1); // slotMapPage(rm->slot, rm->sslot, i + rm->startPage, rm->ramData + 0x2000 * i, 1, 1);
} }
#endif
} }
static void destroy(RamNormal* rm) static void ramnormal_destroy(void *data)
{ {
RamNormal *rm = (RamNormal*)data;
debugDeviceUnregister(rm->debugHandle); debugDeviceUnregister(rm->debugHandle);
slotUnregister(rm->slot, rm->sslot, 0); slotUnregister(rm->slot, rm->sslot, 0);
@ -83,40 +88,39 @@ static void destroy(RamNormal* rm)
free(rm); free(rm);
} }
static void getDebugInfo(RamNormal* rm, DbgDevice* dbgDevice) static void ramnormal_getDebugInfo(void *data, DbgDevice* dbgDevice)
{ {
RamNormal *rm = (RamNormal*)data;
dbgDeviceAddMemoryBlock(dbgDevice, langDbgMemRamNormal(), 0, 0, rm->pages * 0x2000, rm->ramData); dbgDeviceAddMemoryBlock(dbgDevice, langDbgMemRamNormal(), 0, 0, rm->pages * 0x2000, rm->ramData);
} }
static int dbgWriteMemory(RamNormal* rm, char* name, void* data, int start, int size) static int ramnormal_dbgWriteMemory(void *data1, char* name, void* data2, int start, int size)
{ {
if (strcmp(name, "Normal") || start + size > rm->pages * 0x2000) { RamNormal *rm = (RamNormal*)data1;
if (strcmp(name, "Normal") || start + size > rm->pages * 0x2000)
return 0; return 0;
}
memcpy(rm->ramData + start, data, size); memcpy(rm->ramData + start, data2, size);
return 1; return 1;
} }
int ramNormalCreate(int size, int slot, int sslot, int startPage, UInt8** ramPtr, UInt32* ramSize) int ramNormalCreate(int size, int slot, int sslot, int startPage, UInt8** ramPtr, UInt32* ramSize)
{ {
DeviceCallbacks callbacks = { destroy, NULL, saveState, loadState }; DeviceCallbacks callbacks = { ramnormal_destroy, NULL, ramnormal_saveState, ramnormal_loadState };
DebugCallbacks dbgCallbacks = { getDebugInfo, dbgWriteMemory, NULL, NULL }; DebugCallbacks dbgCallbacks = { ramnormal_getDebugInfo, ramnormal_dbgWriteMemory, NULL, NULL };
RamNormal* rm; RamNormal* rm;
int pages = size / 0x2000; int pages = size / 0x2000;
int i; int i;
if (size > 0x10000 || (size & 0x1fff)) { if (size > 0x10000 || (size & 0x1fff))
return 0; return 0;
}
// Start page must be zero (only full slot allowed) // Start page must be zero (only full slot allowed)
if (startPage + pages > 8) { if (startPage + pages > 8)
return 0; return 0;
}
rm = malloc(sizeof(RamNormal)); rm = (RamNormal*)malloc(sizeof(RamNormal));
rm->slot = slot; rm->slot = slot;
rm->sslot = sslot; rm->sslot = sslot;
@ -127,20 +131,17 @@ int ramNormalCreate(int size, int slot, int sslot, int startPage, UInt8** ramPtr
rm->debugHandle = debugDeviceRegister(DBGTYPE_RAM, langDbgDevRam(), &dbgCallbacks, rm); rm->debugHandle = debugDeviceRegister(DBGTYPE_RAM, langDbgDevRam(), &dbgCallbacks, rm);
for (i = 0; i < pages; i++) { for (i = 0; i < pages; i++)
slotMapPage(slot, sslot, i + startPage, rm->ramData + 0x2000 * i, 1, 1); slotMapPage(slot, sslot, i + startPage, rm->ramData + 0x2000 * i, 1, 1);
}
rm->deviceHandle = deviceManagerRegister(RAM_NORMAL, &callbacks, rm); rm->deviceHandle = deviceManagerRegister(RAM_NORMAL, &callbacks, rm);
slotRegister(slot, sslot, startPage, pages, NULL, NULL, NULL, destroy, rm); slotRegister(slot, sslot, startPage, pages, NULL, NULL, NULL, ramnormal_destroy, rm);
if (ramPtr != NULL) { if (ramPtr)
*ramPtr = rm->ramData; *ramPtr = rm->ramData;
}
if (ramSize != NULL) { if (ramSize)
*ramSize = pages * 0x2000; *ramSize = pages * 0x2000;
}
return 1; return 1;
} }

View File

@ -37,7 +37,7 @@
#include <stdio.h> #include <stdio.h>
enum { enum {
READ_SRAM, READ_SRAM = 0,
READ_EMPTY, READ_EMPTY,
READ_ROM READ_ROM
}; };
@ -70,17 +70,15 @@ static UInt32 panasonicSramMask = 0;
UInt8 panasonicSramGet(UInt32 address) UInt8 panasonicSramGet(UInt32 address)
{ {
if (panasonicSramMask == 0) { if (panasonicSramMask == 0)
return 0xff; return 0xff;
}
return panasonicSramData[address & panasonicSramMask]; return panasonicSramData[address & panasonicSramMask];
} }
void panasonicSramSet(UInt32 address, UInt8 value) void panasonicSramSet(UInt32 address, UInt8 value)
{ {
if (panasonicSramMask > 0) { if (panasonicSramMask > 0)
panasonicSramData[address & panasonicSramMask] = value; panasonicSramData[address & panasonicSramMask] = value;
}
} }
void panasonicSramCreate(UInt8* sram, UInt32 size) void panasonicSramCreate(UInt8* sram, UInt32 size)
@ -89,17 +87,17 @@ void panasonicSramCreate(UInt8* sram, UInt32 size)
panasonicSramMask = size - 1; panasonicSramMask = size - 1;
} }
void panasonicSramDestroy() void panasonicSramDestroy(void)
{ {
panasonicSramMask = 0; panasonicSramMask = 0;
} }
static void changeBank(RomMapperA1FM* rm, int region, int bank); static void changeBank(RomMapperA1FM* rm, int region, int bank);
static void saveState(RomMapperA1FM* rm) static void rommappera1fm_saveState(void *data)
{ {
SaveState* state = saveStateOpenForWrite("mapperPanasonic"); RomMapperA1FM *rm = (RomMapperA1FM*)data;
SaveState* state = saveStateOpenForWrite("mapperPanasonic");
char tag[16]; char tag[16];
int i; int i;
@ -115,9 +113,10 @@ static void saveState(RomMapperA1FM* rm)
saveStateClose(state); saveStateClose(state);
} }
static void loadState(RomMapperA1FM* rm) static void rommappera1fm_loadState(void *data)
{ {
SaveState* state = saveStateOpenForRead("mapperPanasonic"); RomMapperA1FM *rm = (RomMapperA1FM*)data;
SaveState* state = saveStateOpenForRead("mapperPanasonic");
int romMapper[8]; int romMapper[8];
char tag[16]; char tag[16];
int i; int i;
@ -133,9 +132,8 @@ static void loadState(RomMapperA1FM* rm)
saveStateClose(state); saveStateClose(state);
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++)
changeBank(rm, i, romMapper[i]); changeBank(rm, i, romMapper[i]);
}
switch (rm->readSection) { switch (rm->readSection) {
case READ_SRAM: case READ_SRAM:
@ -150,8 +148,9 @@ static void loadState(RomMapperA1FM* rm)
} }
} }
static void destroy(RomMapperA1FM* rm) static void rommappera1fm_destroy(void *data)
{ {
RomMapperA1FM *rm = (RomMapperA1FM*)data;
sramSave(rm->sramFilename, rm->sram, rm->sramSize, NULL, 0); sramSave(rm->sramFilename, rm->sram, rm->sramSize, NULL, 0);
slotUnregister(rm->slot, rm->sslot, rm->startPage); slotUnregister(rm->slot, rm->sslot, rm->startPage);
@ -168,7 +167,7 @@ static void changeBank(RomMapperA1FM* rm, int region, int bank)
{ {
UInt8* readBlock; UInt8* readBlock;
rm->romMapper[region] = bank; rm->romMapper[region] = bank;
if (bank >= 0x80 && bank < 0x90) { if (bank >= 0x80 && bank < 0x90) {
if (bank & 0x04) { if (bank & 0x04) {
@ -197,35 +196,34 @@ static void changeBank(RomMapperA1FM* rm, int region, int bank)
readBlock = rm->romData + 0x2000 * (bank & 0x7f); readBlock = rm->romData + 0x2000 * (bank & 0x7f);
} }
if (region >=6) { if (region >=6)
readBlock = emptyRam; readBlock = emptyRam;
}
slotMapPage(rm->slot, rm->sslot, region, readBlock, region != 3, 0); slotMapPage(rm->slot, rm->sslot, region, readBlock, region != 3, 0);
} }
static UInt8 read(RomMapperA1FM* rm, UInt16 address) static UInt8 rommappera1fm_read(void *data, UInt16 address)
{ {
if ((rm->control & 0x04) && address >= 0x7ff0 && address < 0x7ff8) { RomMapperA1FM *rm = (RomMapperA1FM*)data;
if ((rm->control & 0x04) && address >= 0x7ff0 && address < 0x7ff8)
return rm->romMapper[address & 7]; return rm->romMapper[address & 7];
}
return rm->readBlock[address & 0x1fff]; return rm->readBlock[address & 0x1fff];
} }
static void write(RomMapperA1FM* rm, UInt16 address, UInt8 value) static void rommappera1fm_write(void *data, UInt16 address, UInt8 value)
{ {
int bank; int bank;
RomMapperA1FM *rm = (RomMapperA1FM*)data;
if (address >= 0x6000 && address < 0x7ff0) { if (address >= 0x6000 && address < 0x7ff0) {
static const int Regions[8] = { 2, 0, 3, 1, 4, -1, 5, -1 }; static const int Regions[8] = { 2, 0, 3, 1, 4, -1, 5, -1 };
int region = Regions[(address >> 10) & 7]; int region = Regions[(address >> 10) & 7];
if (region != -1) { if (region != -1)
changeBank(rm, region, value); changeBank(rm, region, value);
}
return; return;
} }
if (address == 0x7ff9) { if (address == 0x7ff9) {
rm->control = value; rm->control = value;
@ -240,15 +238,15 @@ static void write(RomMapperA1FM* rm, UInt16 address, UInt8 value)
} }
} }
static void reset(RomMapperA1FM* rm) static void rommappera1fm_reset(void *data)
{ {
int i; int i;
RomMapperA1FM *rm = (RomMapperA1FM*)data;
rm->control = 0; rm->control = 0;
for (i = 0; i < 6; i++) { for (i = 0; i < 6; i++)
changeBank(rm, i, 0xa8); changeBank(rm, i, 0xa8);
}
changeBank(rm, 6, 0); changeBank(rm, 6, 0);
changeBank(rm, 7, 0); changeBank(rm, 7, 0);
} }
@ -257,26 +255,25 @@ int romMapperA1FMCreate(const char* filename, UInt8* romData,
int size, int slot, int sslot, int startPage, int size, int slot, int sslot, int startPage,
int sramSize) int sramSize)
{ {
DeviceCallbacks callbacks = { destroy, reset, saveState, loadState }; DeviceCallbacks callbacks = { rommappera1fm_destroy, rommappera1fm_reset, rommappera1fm_saveState, rommappera1fm_loadState };
RomMapperA1FM* rm; RomMapperA1FM* rm;
char suffix[16]; char suffix[16];
if (size < 0x8000 || startPage != 0) { if (size < 0x8000 || startPage != 0)
return 0; return 0;
}
memset(emptyRam, 0xff, sizeof(emptyRam)); memset(emptyRam, 0xff, sizeof(emptyRam));
rm = malloc(sizeof(RomMapperA1FM)); rm = (RomMapperA1FM*)malloc(sizeof(RomMapperA1FM));
rm->deviceHandle = deviceManagerRegister(ROM_PANASONIC8, &callbacks, rm); rm->deviceHandle = deviceManagerRegister(ROM_PANASONIC8, &callbacks, rm);
slotRegister(slot, sslot, 0, 8, read, read, write, destroy, rm); slotRegister(slot, sslot, 0, 8, rommappera1fm_read, rommappera1fm_read, rommappera1fm_write, rommappera1fm_destroy, rm);
rm->romData = malloc(size); rm->romData = (UInt8*)malloc(size);
memcpy(rm->romData, romData, size); memcpy(rm->romData, romData, size);
rm->romSize = size; rm->romSize = size;
rm->sramSize = sramSize; rm->sramSize = sramSize;
rm->sram = malloc(sramSize); rm->sram = (UInt8*)malloc(sramSize);
memset(rm->sram, 0xff, sramSize); memset(rm->sram, 0xff, sramSize);
rm->maxSRAMBank = SRAM_BASE + sramSize / 0x2000; rm->maxSRAMBank = SRAM_BASE + sramSize / 0x2000;
memset(rm->romMapper, 0, sizeof(rm->romMapper)); memset(rm->romMapper, 0, sizeof(rm->romMapper));
@ -292,7 +289,7 @@ int romMapperA1FMCreate(const char* filename, UInt8* romData,
panasonicSramCreate(rm->sram, rm->sramSize); panasonicSramCreate(rm->sram, rm->sramSize);
reset(rm); rommappera1fm_reset(rm);
return 1; return 1;
} }

View File

@ -49,8 +49,9 @@ typedef struct {
int romMapper; int romMapper;
} RomMapperA1FMModem; } RomMapperA1FMModem;
static void saveState(RomMapperA1FMModem* rm) static void rommappera1fm_saveState(void *data)
{ {
RomMapperA1FMModem *rm = (RomMapperA1FMModem*)data;
SaveState* state = saveStateOpenForWrite("mapperPanasonicA1FM"); SaveState* state = saveStateOpenForWrite("mapperPanasonicA1FM");
saveStateSet(state, "romMapper", rm->romMapper); saveStateSet(state, "romMapper", rm->romMapper);
@ -58,18 +59,20 @@ static void saveState(RomMapperA1FMModem* rm)
saveStateClose(state); saveStateClose(state);
} }
static void loadState(RomMapperA1FMModem* rm) static void rommappera1fm_loadState(void *data)
{ {
SaveState* state = saveStateOpenForRead("mapperPanasonicA1FM"); RomMapperA1FMModem *rm = (RomMapperA1FMModem*)data;
rm->romMapper = saveStateGet(state, "romMapper", 0); SaveState* state = saveStateOpenForRead("mapperPanasonicA1FM");
rm->romMapper = saveStateGet(state, "romMapper", 0);
saveStateClose(state); saveStateClose(state);
slotMapPage(rm->slot, rm->sslot, rm->startPage, rm->romData + rm->romMapper * 0x2000, 1, 0); slotMapPage(rm->slot, rm->sslot, rm->startPage, rm->romData + rm->romMapper * 0x2000, 1, 0);
} }
static void destroy(RomMapperA1FMModem* rm) static void rommappera1fm_destroy(void *data)
{ {
RomMapperA1FMModem *rm = (RomMapperA1FMModem*)data;
slotUnregister(rm->slot, rm->sslot, rm->startPage); slotUnregister(rm->slot, rm->sslot, rm->startPage);
deviceManagerUnregister(rm->deviceHandle); deviceManagerUnregister(rm->deviceHandle);
@ -77,8 +80,9 @@ static void destroy(RomMapperA1FMModem* rm)
free(rm); free(rm);
} }
static UInt8 read(RomMapperA1FMModem* rm, UInt16 address) static UInt8 rommappera1fm_read(void *data, UInt16 address)
{ {
RomMapperA1FMModem* rm = (RomMapperA1FMModem*)data;
address += 0x4000; address += 0x4000;
if (address >= 0x7fc0 && address < 0x7fd0) { if (address >= 0x7fc0 && address < 0x7fd0) {
@ -95,8 +99,9 @@ static UInt8 read(RomMapperA1FMModem* rm, UInt16 address)
return panasonicSramGet(address & 0x1fff); return panasonicSramGet(address & 0x1fff);
} }
static void write(RomMapperA1FMModem* rm, UInt16 address, UInt8 value) static void rommappera1fm_write(void *data, UInt16 address, UInt8 value)
{ {
RomMapperA1FMModem *rm = (RomMapperA1FMModem*)data;
address += 0x4000; address += 0x4000;
if (address >= 0x6000 && address < 0x8000) { if (address >= 0x6000 && address < 0x8000) {
@ -109,8 +114,9 @@ static void write(RomMapperA1FMModem* rm, UInt16 address, UInt8 value)
} }
} }
static void reset(RomMapperA1FMModem* rm) static void rommappera1fm_reset(void *data)
{ {
RomMapperA1FMModem *rm = (RomMapperA1FMModem*)data;
slotMapPage(rm->slot, rm->sslot, rm->startPage + 0, rm->romData + rm->romMapper * 0x2000, 1, 0); slotMapPage(rm->slot, rm->sslot, rm->startPage + 0, rm->romData + rm->romMapper * 0x2000, 1, 0);
slotMapPage(rm->slot, rm->sslot, rm->startPage + 1, NULL, 0, 0); slotMapPage(rm->slot, rm->sslot, rm->startPage + 1, NULL, 0, 0);
} }
@ -118,15 +124,13 @@ static void reset(RomMapperA1FMModem* rm)
int romMapperA1FMModemCreate(const char* filename, UInt8* romData, int romMapperA1FMModemCreate(const char* filename, UInt8* romData,
int size, int slot, int sslot, int startPage) int size, int slot, int sslot, int startPage)
{ {
DeviceCallbacks callbacks = { destroy, reset, saveState, loadState }; DeviceCallbacks callbacks = { rommappera1fm_destroy, rommappera1fm_reset, rommappera1fm_saveState, rommappera1fm_loadState };
RomMapperA1FMModem* rm; RomMapperA1FMModem *rm = (RomMapperA1FMModem*)malloc(sizeof(RomMapperA1FMModem));
rm = malloc(sizeof(RomMapperA1FMModem));
rm->deviceHandle = deviceManagerRegister(ROM_FSA1FMMODEM, &callbacks, rm); rm->deviceHandle = deviceManagerRegister(ROM_FSA1FMMODEM, &callbacks, rm);
slotRegister(slot, sslot, startPage, 2, read, read, write, destroy, rm); slotRegister(slot, sslot, startPage, 2, rommappera1fm_read, rommappera1fm_read, rommappera1fm_write, rommappera1fm_destroy, rm);
rm->romData = malloc(size); rm->romData = (UInt8*)malloc(size);
memcpy(rm->romData, romData, size); memcpy(rm->romData, romData, size);
rm->romSize = size; rm->romSize = size;
rm->slot = slot; rm->slot = slot;
@ -135,7 +139,7 @@ int romMapperA1FMModemCreate(const char* filename, UInt8* romData,
rm->romMapper = 0; rm->romMapper = 0;
reset(rm); rommappera1fm_reset(rm);
return 1; return 1;
} }

View File

@ -147,9 +147,8 @@ static void write(RomMapperSunriseIde* rm, UInt16 address, UInt8 value)
} }
if (rm->ideEnabled && (address & 0x3e00) == 0x3c00) { if (rm->ideEnabled && (address & 0x3e00) == 0x3c00) {
if ((address & 1) == 0) { if ((address & 1) == 0)
rm->writeLatch = value; rm->writeLatch = value;
}
else { else {
sunriseIdeWrite(rm->ide, (value << 8) | rm->writeLatch); sunriseIdeWrite(rm->ide, (value << 8) | rm->writeLatch);
} }
@ -181,19 +180,15 @@ int romMapperSunriseIdeCreate(int hdId, const char* filename, UInt8* romData,
int i; int i;
int origSize = size; int origSize = size;
if (startPage != 0) { if (startPage != 0)
return 0; return 0;
}
size = 0x4000; size = 0x4000;
while (size < origSize) { while (size < origSize)
size *= 2; size *= 2;
}
if (romData == NULL) { if (romData == NULL)
size = 0x80000; size = 0x80000;
}
rm = malloc(sizeof(RomMapperSunriseIde)); rm = malloc(sizeof(RomMapperSunriseIde));
@ -203,12 +198,10 @@ int romMapperSunriseIdeCreate(int hdId, const char* filename, UInt8* romData,
rm->ide = sunriseIdeCreate(hdId); rm->ide = sunriseIdeCreate(hdId);
rm->romData = calloc(1, size); rm->romData = calloc(1, size);
if (romData != NULL) { if (romData != NULL)
memcpy(rm->romData, romData, origSize); memcpy(rm->romData, romData, origSize);
} else
else {
memset(rm->romData, 0xff, size); memset(rm->romData, 0xff, size);
}
rm->romMask = size / 0x4000 - 1; rm->romMask = size / 0x4000 - 1;
rm->slot = slot; rm->slot = slot;
rm->sslot = sslot; rm->sslot = sslot;
@ -216,9 +209,8 @@ int romMapperSunriseIdeCreate(int hdId, const char* filename, UInt8* romData,
rm->romMapper = 0; rm->romMapper = 0;
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++)
slotMapPage(rm->slot, rm->sslot, rm->startPage + i, NULL, 0, 0); slotMapPage(rm->slot, rm->sslot, rm->startPage + i, NULL, 0, 0);
}
rm->ideEnabled = 1; rm->ideEnabled = 1;
rm->romMapper = 0; rm->romMapper = 0;

View File

@ -31,8 +31,6 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
const char* sramCreateFilenameWithSuffix(const char* romFilename, char* suffix, char* ext) const char* sramCreateFilenameWithSuffix(const char* romFilename, char* suffix, char* ext)
{ {
static char SRAMfileName[512]; static char SRAMfileName[512];
@ -78,6 +76,7 @@ const char* sramCreateFilenameWithSuffix(const char* romFilename, char* suffix,
const char* sramCreateFilename(const char* romFilename) { const char* sramCreateFilename(const char* romFilename) {
return sramCreateFilenameWithSuffix(romFilename, "", NULL); return sramCreateFilenameWithSuffix(romFilename, "", NULL);
} }
void sramLoad(const char* filename, UInt8* sram, int length, void* header, int headerLength) { void sramLoad(const char* filename, UInt8* sram, int length, void* header, int headerLength) {
FILE* file; FILE* file;

View File

@ -79,12 +79,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#define DBGLOG(fmt)
#define DBGLOG1(fmt, arg1)
#define DBGLOG2(fmt, arg1, arg2)
#define DBGLOG3(fmt, arg1, arg2, arg3)
#define DBGLOG4(fmt, arg1, arg2, arg3, arg4)
#define SPC_BANK 0x7f #define SPC_BANK 0x7f
typedef struct { typedef struct {
@ -115,8 +109,6 @@ static void setMapper(SramMapperMegaSCSI* rm, int page, UInt8 value)
int readFlag; int readFlag;
UInt8* adr; UInt8* adr;
DBGLOG2("setMapper: %x %x\n", page, value);
if (rm->type && (value & 0xc0) == 0x40) { if (rm->type && (value & 0xc0) == 0x40) {
readFlag = 0; readFlag = 0;
writeFlag = 0; writeFlag = 0;
@ -131,11 +123,8 @@ static void setMapper(SramMapperMegaSCSI* rm, int page, UInt8 value)
if (rm->mapper[page] != value) { if (rm->mapper[page] != value) {
rm->mapper[page] = value; rm->mapper[page] = value;
DBGLOG4("bank change: p%x v%x r%d w%d\n", page, value, readFlag, writeFlag);
slotMapPage(rm->pSlot, rm->sSlot, rm->startPage + page, slotMapPage(rm->pSlot, rm->sSlot, rm->startPage + page,
adr, readFlag, writeFlag); adr, readFlag, writeFlag);
} else {
DBGLOG("bank not changed\n");
} }
} }
@ -166,9 +155,8 @@ static void saveState(SramMapperMegaSCSI* rm)
} }
saveStateClose(state); saveStateClose(state);
if (rm->type) { if (rm->type)
mb89352SaveState(rm->spc); mb89352SaveState(rm->spc);
}
} }
static void loadState(SramMapperMegaSCSI* rm) static void loadState(SramMapperMegaSCSI* rm)
@ -177,8 +165,6 @@ static void loadState(SramMapperMegaSCSI* rm)
char tag[16]; char tag[16];
int i; int i;
DBGLOG("load State\n");
saveStateGetBuffer(state, "sramData", rm->sramData, rm->sramSize); saveStateGetBuffer(state, "sramData", rm->sramData, rm->sramSize);
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
@ -187,27 +173,23 @@ static void loadState(SramMapperMegaSCSI* rm)
} }
saveStateClose(state); saveStateClose(state);
if (rm->type) { if (rm->type)
mb89352LoadState(rm->spc); mb89352LoadState(rm->spc);
}
} }
static void destroy(SramMapperMegaSCSI* rm) static void destroy(SramMapperMegaSCSI* rm)
{ {
if (!rm->isZip) { if (!rm->isZip)
sramSave(rm->sramFilename, rm->sramData, rm->sramSize, NULL, 0); sramSave(rm->sramFilename, rm->sramData, rm->sramSize, NULL, 0);
}
slotUnregister(rm->pSlot, rm->sSlot, rm->startPage); slotUnregister(rm->pSlot, rm->sSlot, rm->startPage);
deviceManagerUnregister(rm->deviceHandle); deviceManagerUnregister(rm->deviceHandle);
if (rm->type) { if (rm->type)
mb89352Destroy(rm->spc); mb89352Destroy(rm->spc);
}
if (rm->isAutoName) { if (rm->isAutoName)
--autoNameCounter[rm->type][rm->element]; --autoNameCounter[rm->type][rm->element];
}
free(rm->sramData); free(rm->sramData);
free(rm); free(rm);
@ -221,15 +203,13 @@ static UInt8 read(SramMapperMegaSCSI* rm, UInt16 address)
address &= 0x1fff; address &= 0x1fff;
// SPC read // SPC read
if (address < 0x1000) { if (address < 0x1000)
// Data Register // Data Register
return mb89352ReadDREG(rm->spc); return mb89352ReadDREG(rm->spc);
}
address &= 0x0f; address &= 0x0f;
return mb89352ReadRegister(rm->spc, (UInt8)address); return mb89352ReadRegister(rm->spc, (UInt8)address);
} else {
return 0xff;
} }
return 0xff;
} }
static UInt8 peek(SramMapperMegaSCSI* rm, UInt16 address) static UInt8 peek(SramMapperMegaSCSI* rm, UInt16 address)
@ -246,10 +226,10 @@ static UInt8 peek(SramMapperMegaSCSI* rm, UInt16 address)
} }
address &= 0x0f; address &= 0x0f;
return mb89352PeekRegister(rm->spc, (UInt8)address); return mb89352PeekRegister(rm->spc, (UInt8)address);
} else {
return 0xff;
} }
return 0xff;
} }
static void write(SramMapperMegaSCSI* rm, UInt16 address, UInt8 value) static void write(SramMapperMegaSCSI* rm, UInt16 address, UInt8 value)
{ {
int page = (address >> 13); int page = (address >> 13);
@ -261,11 +241,10 @@ static void write(SramMapperMegaSCSI* rm, UInt16 address, UInt8 value)
if (rm->type && (rm->mapper[page] == SPC_BANK)){ if (rm->type && (rm->mapper[page] == SPC_BANK)){
address &= 0x1fff; address &= 0x1fff;
if (address < 0x1000) { if (address < 0x1000)
mb89352WriteDREG(rm->spc, value); mb89352WriteDREG(rm->spc, value);
} else { else
mb89352WriteRegister(rm->spc, address & 0x0f, value); mb89352WriteRegister(rm->spc, address & 0x0f, value);
}
} }
} }
@ -278,9 +257,8 @@ int sramMapperMegaSCSICreate(const char* filename, UInt8* buf, int size, int pSl
int i; int i;
if (((size != 0x100000) && (size != 0x80000) && if (((size != 0x100000) && (size != 0x80000) &&
(size != 0x40000) && (size != 0x20000)) || (flag & ~0x81)) { (size != 0x40000) && (size != 0x20000)) || (flag & ~0x81))
return 0; return 0;
}
rm = malloc(sizeof(SramMapperMegaSCSI)); rm = malloc(sizeof(SramMapperMegaSCSI));
rm->type = flag & 1; rm->type = flag & 1;
@ -288,24 +266,22 @@ int sramMapperMegaSCSICreate(const char* filename, UInt8* buf, int size, int pSl
rm->deviceHandle = deviceManagerRegister(SRAM_MEGASCSI, &callbacks, rm); rm->deviceHandle = deviceManagerRegister(SRAM_MEGASCSI, &callbacks, rm);
if (rm->type) { if (rm->type)
slotRegister(pSlot, sSlot, startPage, 4, slotRegister(pSlot, sSlot, startPage, 4,
(SlotRead)read, (SlotRead)peek, (SlotWrite)write, (SlotRead)read, (SlotRead)peek, (SlotWrite)write,
(SlotEject)destroy, rm); (SlotEject)destroy, rm);
} else { else
slotRegister(pSlot, sSlot, startPage, 4, NULL, NULL, (SlotWrite)write, slotRegister(pSlot, sSlot, startPage, 4, NULL, NULL, (SlotWrite)write,
(SlotEject)destroy, rm); (SlotEject)destroy, rm);
}
rm->pSlot = pSlot; rm->pSlot = pSlot;
rm->sSlot = sSlot; rm->sSlot = sSlot;
rm->startPage = startPage; rm->startPage = startPage;
rm->mapperMask = ((size >> 13) - 1) | 0x80; rm->mapperMask = ((size >> 13) - 1) | 0x80;
DBGLOG1("mapper mask: %x\n", (unsigned int)rm->mapperMask);
if (strlen(filename)) { if (strlen(filename))
rm->isAutoName = 0; rm->isAutoName = 0;
} else { else {
rm->element = EseRamSize(size); rm->element = EseRamSize(size);
rm->isAutoName = 1; rm->isAutoName = 1;
} }

View File

@ -34,11 +34,11 @@
*/ */
static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab) static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab)
{ {
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an /* POTENTIAL BUG: temp*(temp^1) may overflow in an
* unpredictable manner on 16-bit systems; not a problem * unpredictable manner on 16-bit systems; not a problem
* with any known compiler so far, though */ * with any known compiler so far, though */
temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2; unsigned temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;
return (int)(((temp * (temp ^ 1)) >> 8) & 0xff); return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
} }
@ -87,13 +87,7 @@ static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned lon
# define ZCR_SEED2 3141592654UL /* use PI as default pattern */ # define ZCR_SEED2 3141592654UL /* use PI as default pattern */
# endif # endif
static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting) static int crypthead(const char *passwd, unsigned char *buf, int bufSize, unsigned long *pkeys, const unsigned long *pcrc_32_tab, unsigned long crcForCrypting)
const char *passwd; /* password string */
unsigned char *buf; /* where to write header */
int bufSize;
unsigned long* pkeys;
const unsigned long* pcrc_32_tab;
unsigned long crcForCrypting;
{ {
int n; /* index in random header */ int n; /* index in random header */
int t; /* temporary */ int t; /* temporary */

View File

@ -65,10 +65,7 @@ int ZCALLBACK ferror_file_func OF((
voidpf stream)); voidpf stream));
voidpf ZCALLBACK fopen_file_func (opaque, filename, mode) voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char *filename, int mode)
voidpf opaque;
const char* filename;
int mode;
{ {
FILE* file = NULL; FILE* file = NULL;
const char* mode_fopen = NULL; const char* mode_fopen = NULL;
@ -87,43 +84,23 @@ voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
} }
uLong ZCALLBACK fread_file_func (opaque, stream, buf, size) uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void *buf, uLong size)
voidpf opaque;
voidpf stream;
void* buf;
uLong size;
{ {
uLong ret; return (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
return ret;
} }
uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size) uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void *buf, uLong size)
voidpf opaque;
voidpf stream;
const void* buf;
uLong size;
{ {
uLong ret; return (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
return ret;
} }
long ZCALLBACK ftell_file_func (opaque, stream) long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)
voidpf opaque;
voidpf stream;
{ {
long ret; return (long)ftell((FILE *)stream);
ret = ftell((FILE *)stream);
return ret;
} }
long ZCALLBACK fseek_file_func (opaque, stream, offset, origin) long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin)
voidpf opaque;
voidpf stream;
uLong offset;
int origin;
{ {
int fseek_origin=0; int fseek_origin=0;
long ret; long ret;
@ -145,26 +122,17 @@ long ZCALLBACK fseek_file_func (opaque, stream, offset, origin)
return ret; return ret;
} }
int ZCALLBACK fclose_file_func (opaque, stream) int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream)
voidpf opaque;
voidpf stream;
{ {
int ret; return (int)fclose((FILE *)stream);
ret = fclose((FILE *)stream);
return ret;
} }
int ZCALLBACK ferror_file_func (opaque, stream) int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream)
voidpf opaque;
voidpf stream;
{ {
int ret; return (int)ferror((FILE *)stream);
ret = ferror((FILE *)stream);
return ret;
} }
void fill_fopen_filefunc (pzlib_filefunc_def) void fill_fopen_filefunc (zlib_filefunc_def *pzlib_filefunc_def)
zlib_filefunc_def* pzlib_filefunc_def;
{ {
pzlib_filefunc_def->zopen_file = fopen_file_func; pzlib_filefunc_def->zopen_file = fopen_file_func;
pzlib_filefunc_def->zread_file = fread_file_func; pzlib_filefunc_def->zread_file = fread_file_func;

View File

@ -162,16 +162,7 @@ typedef struct
IN assertion: the stream s has been sucessfully opened for reading. IN assertion: the stream s has been sucessfully opened for reading.
*/ */
local int unzlocal_getByte(const zlib_filefunc_def *pzlib_filefunc_def, voidpf filestream, int *pi)
local int unzlocal_getByte OF((
const zlib_filefunc_def* pzlib_filefunc_def,
voidpf filestream,
int *pi));
local int unzlocal_getByte(pzlib_filefunc_def,filestream,pi)
const zlib_filefunc_def* pzlib_filefunc_def;
voidpf filestream;
int *pi;
{ {
unsigned char c; unsigned char c;
int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1); int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1);
@ -193,22 +184,11 @@ local int unzlocal_getByte(pzlib_filefunc_def,filestream,pi)
/* =========================================================================== /* ===========================================================================
Reads a long in LSB order from the given gz_stream. Sets Reads a long in LSB order from the given gz_stream. Sets
*/ */
local int unzlocal_getShort OF(( local int unzlocal_getShort (const zlib_filefunc_def *pzlib_filefunc_def, voidpf filestream, uLong *pX)
const zlib_filefunc_def* pzlib_filefunc_def,
voidpf filestream,
uLong *pX));
local int unzlocal_getShort (pzlib_filefunc_def,filestream,pX)
const zlib_filefunc_def* pzlib_filefunc_def;
voidpf filestream;
uLong *pX;
{ {
uLong x ;
int i; int i;
int err; int err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
uLong x = (uLong)i;
err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
x = (uLong)i;
if (err==UNZ_OK) if (err==UNZ_OK)
err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
@ -221,15 +201,7 @@ local int unzlocal_getShort (pzlib_filefunc_def,filestream,pX)
return err; return err;
} }
local int unzlocal_getLong OF(( local int unzlocal_getLong (const zlib_filefunc_def *pzlib_filefunc_def, voidpf filestream, uLong *pX)
const zlib_filefunc_def* pzlib_filefunc_def,
voidpf filestream,
uLong *pX));
local int unzlocal_getLong (pzlib_filefunc_def,filestream,pX)
const zlib_filefunc_def* pzlib_filefunc_def;
voidpf filestream;
uLong *pX;
{ {
uLong x ; uLong x ;
int i; int i;
@ -259,9 +231,7 @@ local int unzlocal_getLong (pzlib_filefunc_def,filestream,pX)
/* My own strcmpi / strcasecmp */ /* My own strcmpi / strcasecmp */
local int strcmpcasenosensitive_internal (fileName1,fileName2) local int strcmpcasenosensitive_internal (const char *fileName1, const char *fileName2)
const char* fileName1;
const char* fileName2;
{ {
for (;;) for (;;)
{ {
@ -302,10 +272,7 @@ local int strcmpcasenosensitive_internal (fileName1,fileName2)
(like 1 on Unix, 2 on Windows) (like 1 on Unix, 2 on Windows)
*/ */
extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivity) extern int ZEXPORT unzStringFileNameCompare (const char *fileName1, const char *fileName2, int iCaseSensitivity)
const char* fileName1;
const char* fileName2;
int iCaseSensitivity;
{ {
if (iCaseSensitivity==0) if (iCaseSensitivity==0)
iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
@ -328,9 +295,7 @@ local uLong unzlocal_SearchCentralDir OF((
const zlib_filefunc_def* pzlib_filefunc_def, const zlib_filefunc_def* pzlib_filefunc_def,
voidpf filestream)); voidpf filestream));
local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream) local uLong unzlocal_SearchCentralDir(const zlib_filefunc_def *pzlib_filefunc_def, voidpf filestream)
const zlib_filefunc_def* pzlib_filefunc_def;
voidpf filestream;
{ {
unsigned char* buf; unsigned char* buf;
uLong uSizeFile; uLong uSizeFile;
@ -394,9 +359,7 @@ local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream)
Else, the return value is a unzFile Handle, usable with other function Else, the return value is a unzFile Handle, usable with other function
of this unzip package. of this unzip package.
*/ */
extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def) extern unzFile ZEXPORT unzOpen2 (const char *path, zlib_filefunc_def *pzlib_filefunc_def)
const char *path;
zlib_filefunc_def* pzlib_filefunc_def;
{ {
unz_s us; unz_s us;
unz_s *s; unz_s *s;
@ -497,8 +460,7 @@ extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def)
} }
extern unzFile ZEXPORT unzOpen (path) extern unzFile ZEXPORT unzOpen (const char *path)
const char *path;
{ {
return unzOpen2(path, NULL); return unzOpen2(path, NULL);
} }
@ -508,8 +470,7 @@ extern unzFile ZEXPORT unzOpen (path)
If there is files inside the .Zip opened with unzipOpenCurrentFile (see later), If there is files inside the .Zip opened with unzipOpenCurrentFile (see later),
these files MUST be closed with unzipCloseCurrentFile before call unzipClose. these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
return UNZ_OK if there is no problem. */ return UNZ_OK if there is no problem. */
extern int ZEXPORT unzClose (file) extern int ZEXPORT unzClose (unzFile file)
unzFile file;
{ {
unz_s* s; unz_s* s;
if (file==NULL) if (file==NULL)
@ -529,9 +490,7 @@ extern int ZEXPORT unzClose (file)
Write info about the ZipFile in the *pglobal_info structure. Write info about the ZipFile in the *pglobal_info structure.
No preparation of the structure is needed No preparation of the structure is needed
return UNZ_OK if there is no problem. */ return UNZ_OK if there is no problem. */
extern int ZEXPORT unzGetGlobalInfo (file,pglobal_info) extern int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info *pglobal_info)
unzFile file;
unz_global_info *pglobal_info;
{ {
unz_s* s; unz_s* s;
if (file==NULL) if (file==NULL)
@ -545,19 +504,16 @@ extern int ZEXPORT unzGetGlobalInfo (file,pglobal_info)
/* /*
Translate date/time from Dos format to tm_unz (readable more easilty) Translate date/time from Dos format to tm_unz (readable more easilty)
*/ */
local void unzlocal_DosDateToTmuDate (ulDosDate, ptm) local void unzlocal_DosDateToTmuDate (uLong ulDosDate, tm_unz *ptm)
uLong ulDosDate;
tm_unz* ptm;
{ {
uLong uDate; uLong uDate = (uLong)(ulDosDate>>16);
uDate = (uLong)(ulDosDate>>16);
ptm->tm_mday = (uInt)(uDate&0x1f) ; ptm->tm_mday = (uInt)(uDate&0x1f) ;
ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ; ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ;
ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ; ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ;
ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800); ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800);
ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20) ; ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20) ;
ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)) ; ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)) ;
} }
/* /*
@ -574,21 +530,12 @@ local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file,
char *szComment, char *szComment,
uLong commentBufferSize)); uLong commentBufferSize));
local int unzlocal_GetCurrentFileInfoInternal (file, local int unzlocal_GetCurrentFileInfoInternal (unzFile file,
pfile_info, unz_file_info *pfile_info,
pfile_info_internal, unz_file_info_internal *pfile_info_internal,
szFileName, fileNameBufferSize, char *szFileName, uLong fileNameBufferSize,
extraField, extraFieldBufferSize, void *extraField, uLong extraFieldBufferSize,
szComment, commentBufferSize) char *szComment, uLong commentBufferSize)
unzFile file;
unz_file_info *pfile_info;
unz_file_info_internal *pfile_info_internal;
char *szFileName;
uLong fileNameBufferSize;
void *extraField;
uLong extraFieldBufferSize;
char *szComment;
uLong commentBufferSize;
{ {
unz_s* s; unz_s* s;
unz_file_info file_info; unz_file_info file_info;
@ -741,19 +688,11 @@ local int unzlocal_GetCurrentFileInfoInternal (file,
No preparation of the structure is needed No preparation of the structure is needed
return UNZ_OK if there is no problem. return UNZ_OK if there is no problem.
*/ */
extern int ZEXPORT unzGetCurrentFileInfo (file, extern int ZEXPORT unzGetCurrentFileInfo (unzFile file,
pfile_info, unz_file_info *pfile_info,
szFileName, fileNameBufferSize, char *szFileName, uLong fileNameBufferSize,
extraField, extraFieldBufferSize, void *extraField, uLong extraFieldBufferSize,
szComment, commentBufferSize) char *szComment, uLong commentBufferSize)
unzFile file;
unz_file_info *pfile_info;
char *szFileName;
uLong fileNameBufferSize;
void *extraField;
uLong extraFieldBufferSize;
char *szComment;
uLong commentBufferSize;
{ {
return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL, return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL,
szFileName,fileNameBufferSize, szFileName,fileNameBufferSize,
@ -765,8 +704,7 @@ extern int ZEXPORT unzGetCurrentFileInfo (file,
Set the current file of the zipfile to the first file. Set the current file of the zipfile to the first file.
return UNZ_OK if there is no problem return UNZ_OK if there is no problem
*/ */
extern int ZEXPORT unzGoToFirstFile (file) extern int ZEXPORT unzGoToFirstFile (unzFile file)
unzFile file;
{ {
int err=UNZ_OK; int err=UNZ_OK;
unz_s* s; unz_s* s;
@ -787,8 +725,7 @@ extern int ZEXPORT unzGoToFirstFile (file)
return UNZ_OK if there is no problem return UNZ_OK if there is no problem
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
*/ */
extern int ZEXPORT unzGoToNextFile (file) extern int ZEXPORT unzGoToNextFile (unzFile file)
unzFile file;
{ {
unz_s* s; unz_s* s;
int err; int err;
@ -821,10 +758,7 @@ extern int ZEXPORT unzGoToNextFile (file)
UNZ_OK if the file is found. It becomes the current file. UNZ_OK if the file is found. It becomes the current file.
UNZ_END_OF_LIST_OF_FILE if the file is not found UNZ_END_OF_LIST_OF_FILE if the file is not found
*/ */
extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity) extern int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity)
unzFile file;
const char *szFileName;
int iCaseSensitivity;
{ {
unz_s* s; unz_s* s;
int err; int err;
@ -900,9 +834,7 @@ typedef struct unz_file_pos_s
} unz_file_pos; } unz_file_pos;
*/ */
extern int ZEXPORT unzGetFilePos(file, file_pos) extern int ZEXPORT unzGetFilePos(unzFile file, unz_file_pos *file_pos)
unzFile file;
unz_file_pos* file_pos;
{ {
unz_s* s; unz_s* s;
@ -918,9 +850,7 @@ extern int ZEXPORT unzGetFilePos(file, file_pos)
return UNZ_OK; return UNZ_OK;
} }
extern int ZEXPORT unzGoToFilePos(file, file_pos) extern int ZEXPORT unzGoToFilePos(unzFile file, unz_file_pos *file_pos)
unzFile file;
unz_file_pos* file_pos;
{ {
unz_s* s; unz_s* s;
int err; int err;
@ -954,13 +884,9 @@ extern int ZEXPORT unzGoToFilePos(file, file_pos)
store in *piSizeVar the size of extra info in local header store in *piSizeVar the size of extra info in local header
(filename and size of extra field data) (filename and size of extra field data)
*/ */
local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar, local int unzlocal_CheckCurrentFileCoherencyHeader (unz_s *s, uInt *piSizeVar,
poffset_local_extrafield, uLong *poffset_local_extrafield,
psize_local_extrafield) uInt *psize_local_extrafield)
unz_s* s;
uInt* piSizeVar;
uLong *poffset_local_extrafield;
uInt *psize_local_extrafield;
{ {
uLong uMagic,uData,uFlags; uLong uMagic,uData,uFlags;
uLong size_filename; uLong size_filename;
@ -1044,12 +970,7 @@ local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar,
Open for reading data the current file in the zipfile. Open for reading data the current file in the zipfile.
If there is no error and the file is opened, the return value is UNZ_OK. If there is no error and the file is opened, the return value is UNZ_OK.
*/ */
extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password) extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int *method, int *level, int raw, const char *password)
unzFile file;
int* method;
int* level;
int raw;
const char* password;
{ {
int err=UNZ_OK; int err=UNZ_OK;
uInt iSizeVar; uInt iSizeVar;
@ -1130,7 +1051,7 @@ extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
pfile_in_zip_read_info->stream.zfree = (free_func)0; pfile_in_zip_read_info->stream.zfree = (free_func)0;
pfile_in_zip_read_info->stream.opaque = (voidpf)0; pfile_in_zip_read_info->stream.opaque = (voidpf)0;
pfile_in_zip_read_info->stream.next_in = (voidpf)0; pfile_in_zip_read_info->stream.next_in = (Bytef*)0;
pfile_in_zip_read_info->stream.avail_in = 0; pfile_in_zip_read_info->stream.avail_in = 0;
err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS); err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
@ -1189,24 +1110,17 @@ extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
return UNZ_OK; return UNZ_OK;
} }
extern int ZEXPORT unzOpenCurrentFile (file) extern int ZEXPORT unzOpenCurrentFile (unzFile file)
unzFile file;
{ {
return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL); return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
} }
extern int ZEXPORT unzOpenCurrentFilePassword (file, password) extern int ZEXPORT unzOpenCurrentFilePassword (unzFile file, const char *password)
unzFile file;
const char* password;
{ {
return unzOpenCurrentFile3(file, NULL, NULL, 0, password); return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
} }
extern int ZEXPORT unzOpenCurrentFile2 (file,method,level,raw) extern int ZEXPORT unzOpenCurrentFile2 (unzFile file, int *method, int*level, int raw)
unzFile file;
int* method;
int* level;
int raw;
{ {
return unzOpenCurrentFile3(file, method, level, raw, NULL); return unzOpenCurrentFile3(file, method, level, raw, NULL);
} }
@ -1221,10 +1135,7 @@ extern int ZEXPORT unzOpenCurrentFile2 (file,method,level,raw)
return <0 with error code if there is an error return <0 with error code if there is an error
(UNZ_ERRNO for IO error, or zLib error for uncompress error) (UNZ_ERRNO for IO error, or zLib error for uncompress error)
*/ */
extern int ZEXPORT unzReadCurrentFile (file, buf, len) extern int ZEXPORT unzReadCurrentFile (unzFile file, voidpf buf, unsigned len)
unzFile file;
voidp buf;
unsigned len;
{ {
int err=UNZ_OK; int err=UNZ_OK;
uInt iRead = 0; uInt iRead = 0;
@ -1382,8 +1293,7 @@ extern int ZEXPORT unzReadCurrentFile (file, buf, len)
/* /*
Give the current position in uncompressed data Give the current position in uncompressed data
*/ */
extern z_off_t ZEXPORT unztell (file) extern z_off_t ZEXPORT unztell (unzFile file)
unzFile file;
{ {
unz_s* s; unz_s* s;
file_in_zip_read_info_s* pfile_in_zip_read_info; file_in_zip_read_info_s* pfile_in_zip_read_info;
@ -1402,8 +1312,7 @@ extern z_off_t ZEXPORT unztell (file)
/* /*
return 1 if the end of file was reached, 0 elsewhere return 1 if the end of file was reached, 0 elsewhere
*/ */
extern int ZEXPORT unzeof (file) extern int ZEXPORT unzeof (unzFile file)
unzFile file;
{ {
unz_s* s; unz_s* s;
file_in_zip_read_info_s* pfile_in_zip_read_info; file_in_zip_read_info_s* pfile_in_zip_read_info;
@ -1435,10 +1344,7 @@ extern int ZEXPORT unzeof (file)
the return value is the number of bytes copied in buf, or (if <0) the return value is the number of bytes copied in buf, or (if <0)
the error code the error code
*/ */
extern int ZEXPORT unzGetLocalExtrafield (file,buf,len) extern int ZEXPORT unzGetLocalExtrafield (unzFile file, voidp buf, unsigned len)
unzFile file;
voidp buf;
unsigned len;
{ {
unz_s* s; unz_s* s;
file_in_zip_read_info_s* pfile_in_zip_read_info; file_in_zip_read_info_s* pfile_in_zip_read_info;
@ -1486,11 +1392,9 @@ extern int ZEXPORT unzGetLocalExtrafield (file,buf,len)
Close the file in zip opened with unzipOpenCurrentFile Close the file in zip opened with unzipOpenCurrentFile
Return UNZ_CRCERROR if all the file was read but the CRC is not good Return UNZ_CRCERROR if all the file was read but the CRC is not good
*/ */
extern int ZEXPORT unzCloseCurrentFile (file) extern int ZEXPORT unzCloseCurrentFile (unzFile file)
unzFile file;
{ {
int err=UNZ_OK; int err=UNZ_OK;
unz_s* s; unz_s* s;
file_in_zip_read_info_s* pfile_in_zip_read_info; file_in_zip_read_info_s* pfile_in_zip_read_info;
if (file==NULL) if (file==NULL)
@ -1529,10 +1433,7 @@ extern int ZEXPORT unzCloseCurrentFile (file)
uSizeBuf is the size of the szComment buffer. uSizeBuf is the size of the szComment buffer.
return the number of byte copied or an error code <0 return the number of byte copied or an error code <0
*/ */
extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf) extern int ZEXPORT unzGetGlobalComment (unzFile file, char *szComment, uLong uSizeBuf)
unzFile file;
char *szComment;
uLong uSizeBuf;
{ {
int err=UNZ_OK; int err=UNZ_OK;
unz_s* s; unz_s* s;
@ -1561,8 +1462,7 @@ extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf)
} }
/* Additions by RX '2004 */ /* Additions by RX '2004 */
extern uLong ZEXPORT unzGetOffset (file) extern uLong ZEXPORT unzGetOffset (unzFile file)
unzFile file;
{ {
unz_s* s; unz_s* s;
@ -1577,9 +1477,7 @@ extern uLong ZEXPORT unzGetOffset (file)
return s->pos_in_central_dir; return s->pos_in_central_dir;
} }
extern int ZEXPORT unzSetOffset (file, pos) extern int ZEXPORT unzSetOffset (unzFile file, uLong pos)
unzFile file;
uLong pos;
{ {
unz_s* s; unz_s* s;
int err; int err;

View File

@ -172,10 +172,9 @@ local linkedlist_datablock_internal* allocate_new_datablock()
return ldi; return ldi;
} }
local void free_datablock(ldi) local void free_datablock(linkedlist_datablock_internal* ldi)
linkedlist_datablock_internal* ldi;
{ {
while (ldi!=NULL) while (ldi)
{ {
linkedlist_datablock_internal* ldinext = ldi->next_datablock; linkedlist_datablock_internal* ldinext = ldi->next_datablock;
TRYFREE(ldi); TRYFREE(ldi);
@ -183,32 +182,27 @@ local void free_datablock(ldi)
} }
} }
local void init_linkedlist(ll) local void init_linkedlist(linkedlist_data* ll)
linkedlist_data* ll;
{ {
ll->first_block = ll->last_block = NULL; ll->first_block = ll->last_block = NULL;
} }
local void free_linkedlist(ll) local void free_linkedlist(linkedlist_data*ll)
linkedlist_data* ll;
{ {
free_datablock(ll->first_block); free_datablock(ll->first_block);
ll->first_block = ll->last_block = NULL; ll->first_block = ll->last_block = NULL;
} }
local int add_data_in_datablock(ll,buf,len) local int add_data_in_datablock(linkedlist_data*ll,const void *buf,uLong len)
linkedlist_data* ll;
const void* buf;
uLong len;
{ {
linkedlist_datablock_internal* ldi; linkedlist_datablock_internal* ldi;
const unsigned char* from_copy; const unsigned char* from_copy;
if (ll==NULL) if (!ll)
return ZIP_INTERNALERROR; return ZIP_INTERNALERROR;
if (ll->last_block == NULL) if (!ll->last_block)
{ {
ll->first_block = ll->last_block = allocate_new_datablock(); ll->first_block = ll->last_block = allocate_new_datablock();
if (ll->first_block == NULL) if (ll->first_block == NULL)
@ -261,13 +255,7 @@ local int add_data_in_datablock(ll,buf,len)
nbByte == 1, 2 or 4 (byte, short or long) nbByte == 1, 2 or 4 (byte, short or long)
*/ */
local int ziplocal_putValue OF((const zlib_filefunc_def* pzlib_filefunc_def, local int ziplocal_putValue (const zlib_filefunc_def *pzlib_filefunc_def, voidpf filestream, uLong x, int nbByte)
voidpf filestream, uLong x, int nbByte));
local int ziplocal_putValue (pzlib_filefunc_def, filestream, x, nbByte)
const zlib_filefunc_def* pzlib_filefunc_def;
voidpf filestream;
uLong x;
int nbByte;
{ {
unsigned char buf[4]; unsigned char buf[4];
int n; int n;
@ -279,22 +267,15 @@ local int ziplocal_putValue (pzlib_filefunc_def, filestream, x, nbByte)
if (x != 0) if (x != 0)
{ /* data overflow - hack for ZIP64 (X Roche) */ { /* data overflow - hack for ZIP64 (X Roche) */
for (n = 0; n < nbByte; n++) for (n = 0; n < nbByte; n++)
{
buf[n] = 0xff; buf[n] = 0xff;
}
} }
if (ZWRITE(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte) if (ZWRITE(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte)
return ZIP_ERRNO; return ZIP_ERRNO;
else return ZIP_OK;
return ZIP_OK;
} }
local void ziplocal_putValue_inmemory OF((void* dest, uLong x, int nbByte)); local void ziplocal_putValue_inmemory (void *dest, uLong x, int nbByte)
local void ziplocal_putValue_inmemory (dest, x, nbByte)
void* dest;
uLong x;
int nbByte;
{ {
unsigned char* buf=(unsigned char*)dest; unsigned char* buf=(unsigned char*)dest;
int n; int n;
@ -315,9 +296,7 @@ local void ziplocal_putValue_inmemory (dest, x, nbByte)
/****************************************************************************/ /****************************************************************************/
local uLong ziplocal_TmzDateToDosDate(ptm,dosDate) local uLong ziplocal_TmzDateToDosDate(const tm_zip *ptm, uLong dosDate)
const tm_zip* ptm;
uLong dosDate;
{ {
uLong year = (uLong)ptm->tm_year; uLong year = (uLong)ptm->tm_year;
if (year>1980) if (year>1980)
@ -332,15 +311,7 @@ local uLong ziplocal_TmzDateToDosDate(ptm,dosDate)
/****************************************************************************/ /****************************************************************************/
local int ziplocal_getByte OF(( local int ziplocal_getByte(const zlib_filefunc_def *pzlib_filefunc_def, voidpf filestream, int *pi)
const zlib_filefunc_def* pzlib_filefunc_def,
voidpf filestream,
int *pi));
local int ziplocal_getByte(pzlib_filefunc_def,filestream,pi)
const zlib_filefunc_def* pzlib_filefunc_def;
voidpf filestream;
int *pi;
{ {
unsigned char c; unsigned char c;
int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1); int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1);
@ -362,22 +333,11 @@ local int ziplocal_getByte(pzlib_filefunc_def,filestream,pi)
/* =========================================================================== /* ===========================================================================
Reads a long in LSB order from the given gz_stream. Sets Reads a long in LSB order from the given gz_stream. Sets
*/ */
local int ziplocal_getShort OF(( local int ziplocal_getShort (const zlib_filefunc_def *pzlib_filefunc_def, voidpf filestream, uLong *pX)
const zlib_filefunc_def* pzlib_filefunc_def,
voidpf filestream,
uLong *pX));
local int ziplocal_getShort (pzlib_filefunc_def,filestream,pX)
const zlib_filefunc_def* pzlib_filefunc_def;
voidpf filestream;
uLong *pX;
{ {
uLong x ;
int i; int i;
int err; int err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
uLong x = (uLong)i;
err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
x = (uLong)i;
if (err==ZIP_OK) if (err==ZIP_OK)
err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
@ -390,22 +350,11 @@ local int ziplocal_getShort (pzlib_filefunc_def,filestream,pX)
return err; return err;
} }
local int ziplocal_getLong OF(( local int ziplocal_getLong (const zlib_filefunc_def *pzlib_filefunc_def, voidpf filestream, uLong *pX)
const zlib_filefunc_def* pzlib_filefunc_def,
voidpf filestream,
uLong *pX));
local int ziplocal_getLong (pzlib_filefunc_def,filestream,pX)
const zlib_filefunc_def* pzlib_filefunc_def;
voidpf filestream;
uLong *pX;
{ {
uLong x ;
int i; int i;
int err; int err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
uLong x = (uLong)i;
err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
x = (uLong)i;
if (err==ZIP_OK) if (err==ZIP_OK)
err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
@ -433,13 +382,7 @@ local int ziplocal_getLong (pzlib_filefunc_def,filestream,pX)
Locate the Central directory of a zipfile (at the end, just before Locate the Central directory of a zipfile (at the end, just before
the global comment) the global comment)
*/ */
local uLong ziplocal_SearchCentralDir OF(( local uLong ziplocal_SearchCentralDir(const zlib_filefunc_def *pzlib_filefunc_def, voidpf filestream)
const zlib_filefunc_def* pzlib_filefunc_def,
voidpf filestream));
local uLong ziplocal_SearchCentralDir(pzlib_filefunc_def,filestream)
const zlib_filefunc_def* pzlib_filefunc_def;
voidpf filestream;
{ {
unsigned char* buf; unsigned char* buf;
uLong uSizeFile; uLong uSizeFile;
@ -496,17 +439,12 @@ local uLong ziplocal_SearchCentralDir(pzlib_filefunc_def,filestream)
#endif /* !NO_ADDFILEINEXISTINGZIP*/ #endif /* !NO_ADDFILEINEXISTINGZIP*/
/************************************************************/ /************************************************************/
extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc_def) extern zipFile ZEXPORT zipOpen2 (const char *pathname, int append, zipcharpc *globalcomment, zlib_filefunc_def *pzlib_filefunc_def)
const char *pathname;
int append;
zipcharpc* globalcomment;
zlib_filefunc_def* pzlib_filefunc_def;
{ {
zip_internal ziinit; zip_internal ziinit;
zip_internal* zi; zip_internal* zi;
int err=ZIP_OK; int err=ZIP_OK;
if (pzlib_filefunc_def==NULL) if (pzlib_filefunc_def==NULL)
fill_fopen_filefunc(&ziinit.z_filefunc); fill_fopen_filefunc(&ziinit.z_filefunc);
else else
@ -615,7 +553,7 @@ extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc
if (size_comment>0) if (size_comment>0)
{ {
ziinit.globalcomment = ALLOC(size_comment+1); ziinit.globalcomment = (char*)ALLOC(size_comment+1);
if (ziinit.globalcomment) if (ziinit.globalcomment)
{ {
size_comment = ZREAD(ziinit.z_filefunc, ziinit.filestream,ziinit.globalcomment,size_comment); size_comment = ZREAD(ziinit.z_filefunc, ziinit.filestream,ziinit.globalcomment,size_comment);
@ -680,35 +618,17 @@ extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc
} }
} }
extern zipFile ZEXPORT zipOpen (pathname, append) extern zipFile ZEXPORT zipOpen (const char *pathname, int append)
const char *pathname;
int append;
{ {
return zipOpen2(pathname,append,NULL,NULL); return zipOpen2(pathname,append,NULL,NULL);
} }
extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi, extern int ZEXPORT zipOpenNewFileInZip3 (zipFile file, const char *filename, const zip_fileinfo *zipfi,
extrafield_local, size_extrafield_local, const void *extrafield_local, uInt size_extrafield_local,
extrafield_global, size_extrafield_global, const void *extrafield_global, uInt size_extrafield_global,
comment, method, level, raw, const char *comment, int method, int level, int raw,
windowBits, memLevel, strategy, int windowBits, int memLevel, int strategy,
password, crcForCrypting) const char *password, uLong crcForCrypting)
zipFile file;
const char* filename;
const zip_fileinfo* zipfi;
const void* extrafield_local;
uInt size_extrafield_local;
const void* extrafield_global;
uInt size_extrafield_global;
const char* comment;
int method;
int level;
int raw;
int windowBits;
int memLevel;
int strategy;
const char* password;
uLong crcForCrypting;
{ {
zip_internal* zi; zip_internal* zi;
uInt size_filename; uInt size_filename;
@ -896,21 +816,10 @@ extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi,
return err; return err;
} }
extern int ZEXPORT zipOpenNewFileInZip2(file, filename, zipfi, extern int ZEXPORT zipOpenNewFileInZip2(zipFile file, const char *filename, const zip_fileinfo *zipfi,
extrafield_local, size_extrafield_local, const void *extrafield_local, uInt size_extrafield_local,
extrafield_global, size_extrafield_global, const void *extrafield_global, uInt size_extrafield_global,
comment, method, level, raw) const char *comment, int method, int level, int raw)
zipFile file;
const char* filename;
const zip_fileinfo* zipfi;
const void* extrafield_local;
uInt size_extrafield_local;
const void* extrafield_global;
uInt size_extrafield_global;
const char* comment;
int method;
int level;
int raw;
{ {
return zipOpenNewFileInZip3 (file, filename, zipfi, return zipOpenNewFileInZip3 (file, filename, zipfi,
extrafield_local, size_extrafield_local, extrafield_local, size_extrafield_local,
@ -920,20 +829,10 @@ extern int ZEXPORT zipOpenNewFileInZip2(file, filename, zipfi,
NULL, 0); NULL, 0);
} }
extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi, extern int ZEXPORT zipOpenNewFileInZip (zipFile file, const char *filename, const zip_fileinfo *zipfi,
extrafield_local, size_extrafield_local, const void *extrafield_local, uInt size_extrafield_local,
extrafield_global, size_extrafield_global, const void *extrafield_global, uInt size_extrafield_global,
comment, method, level) const char *comment, int method, int level)
zipFile file;
const char* filename;
const zip_fileinfo* zipfi;
const void* extrafield_local;
uInt size_extrafield_local;
const void* extrafield_global;
uInt size_extrafield_global;
const char* comment;
int method;
int level;
{ {
return zipOpenNewFileInZip2 (file, filename, zipfi, return zipOpenNewFileInZip2 (file, filename, zipfi,
extrafield_local, size_extrafield_local, extrafield_local, size_extrafield_local,
@ -941,8 +840,7 @@ extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi,
comment, method, level, 0); comment, method, level, 0);
} }
local int zipFlushWriteBuffer(zi) local int zipFlushWriteBuffer(zip_internal *zi)
zip_internal* zi;
{ {
int err=ZIP_OK; int err=ZIP_OK;
@ -963,10 +861,7 @@ local int zipFlushWriteBuffer(zi)
return err; return err;
} }
extern int ZEXPORT zipWriteInFileInZip (file, buf, len) extern int ZEXPORT zipWriteInFileInZip (zipFile file, const void *buf, unsigned len)
zipFile file;
const void* buf;
unsigned len;
{ {
zip_internal* zi; zip_internal* zi;
int err=ZIP_OK; int err=ZIP_OK;
@ -978,9 +873,9 @@ extern int ZEXPORT zipWriteInFileInZip (file, buf, len)
if (zi->in_opened_file_inzip == 0) if (zi->in_opened_file_inzip == 0)
return ZIP_PARAMERROR; return ZIP_PARAMERROR;
zi->ci.stream.next_in = (void*)buf; zi->ci.stream.next_in = (Bytef*)buf;
zi->ci.stream.avail_in = len; zi->ci.stream.avail_in = len;
zi->ci.crc32 = crc32(zi->ci.crc32,buf,len); zi->ci.crc32 = crc32(zi->ci.crc32,(const Bytef*)buf,len);
while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0)) while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0))
{ {
@ -1028,10 +923,7 @@ extern int ZEXPORT zipWriteInFileInZip (file, buf, len)
return err; return err;
} }
extern int ZEXPORT zipCloseFileInZipRaw (file, uncompressed_size, crc32) extern int ZEXPORT zipCloseFileInZipRaw (zipFile file, uLong uncompressed_size, uLong crc32)
zipFile file;
uLong uncompressed_size;
uLong crc32;
{ {
zip_internal* zi; zip_internal* zi;
uLong compressed_size; uLong compressed_size;
@ -1124,15 +1016,12 @@ extern int ZEXPORT zipCloseFileInZipRaw (file, uncompressed_size, crc32)
return err; return err;
} }
extern int ZEXPORT zipCloseFileInZip (file) extern int ZEXPORT zipCloseFileInZip (zipFile file)
zipFile file;
{ {
return zipCloseFileInZipRaw (file,0,0); return zipCloseFileInZipRaw (file,0,0);
} }
extern int ZEXPORT zipClose (file, global_comment) extern int ZEXPORT zipClose (zipFile file, const char *global_comment)
zipFile file;
const char* global_comment;
{ {
zip_internal* zi; zip_internal* zi;
int err = 0; int err = 0;

View File

@ -152,7 +152,7 @@ MemZipFile* memZipFileCreate(const char* zipName)
{ {
if (memZipFiles[i] == NULL) if (memZipFiles[i] == NULL)
{ {
memZipFiles[i] = malloc(sizeof(MemZipFile)); memZipFiles[i] = (MemZipFile*)malloc(sizeof(MemZipFile));
strcpy(memZipFiles[i]->zipName, zipName); strcpy(memZipFiles[i]->zipName, zipName);
memZipFiles[i]->count = 0; memZipFiles[i]->count = 0;
return memZipFiles[i]; return memZipFiles[i];
@ -202,20 +202,16 @@ int memFileSave(const char* zipName, const char* filename, int append, void* buf
memZipFile = NULL; memZipFile = NULL;
} }
if (memZipFile == NULL) if (!memZipFile)
{
memZipFile = memZipFileCreate(zipName); memZipFile = memZipFileCreate(zipName);
}
if (memZipFile == NULL || memZipFile->count == MAX_FILES_IN_ZIP) if (memZipFile == NULL || memZipFile->count == MAX_FILES_IN_ZIP)
{
return 0; return 0;
}
memFile = malloc(sizeof(MemFile)); memFile = (MemFile*)malloc(sizeof(MemFile));
memFile->buffer = malloc(size); memFile->buffer = (char*)malloc(size);
memcpy(memFile->buffer, buffer, size); memcpy(memFile->buffer, buffer, size);
memFile->size = size; memFile->size = size;
strcpy(memFile->filename, filename); strcpy(memFile->filename, filename);
memZipFile->memFiles[memZipFile->count++] = memFile; memZipFile->memFiles[memZipFile->count++] = memFile;
@ -519,12 +515,11 @@ void zipCacheReadOnlyZip(const char* zipName)
filesize = ftell(file); filesize = ftell(file);
fill_fopen_memfunc(&cacheFilefunc, filesize); fill_fopen_memfunc(&cacheFilefunc, filesize);
fseek(file, 0, SEEK_SET); fseek(file, 0, SEEK_SET);
cacheData = malloc(filesize); cacheData = (char*)malloc(filesize);
if( cacheData != NULL ) { if( cacheData != NULL ) {
size_t size = fread(cacheData, 1, filesize, file); size_t size = fread(cacheData, 1, filesize, file);
if( size == filesize ) { if( size == filesize )
strcpy(cacheFile, zipName); strcpy(cacheFile, zipName);
}
} }
fclose(file); fclose(file);
} }
@ -704,8 +699,8 @@ char* zipGetFileList(const char* zipName, const char* ext, int* count) {
toLower(tmp); toLower(tmp);
if (strstr(tmp, extension) != NULL) { if (strstr(tmp, extension) != NULL) {
int entryLen = strlen(tempName) + 1; size_t entryLen = strlen(tempName) + 1;
fileArray = realloc(fileArray, totalLen + entryLen + 1); fileArray = (char*)realloc(fileArray, totalLen + entryLen + 1);
strcpy(fileArray + totalLen, tempName); strcpy(fileArray + totalLen, tempName);
totalLen += entryLen; totalLen += entryLen;
fileArray[totalLen] = '\0'; // double null termination at end fileArray[totalLen] = '\0'; // double null termination at end
@ -918,9 +913,9 @@ void* zipCompress(void* buffer, int size, unsigned long* retSize)
void* retBuf; void* retBuf;
*retSize = (size * 1001) / 1000 + 12; *retSize = (size * 1001) / 1000 + 12;
retBuf = malloc(*retSize); retBuf = malloc(*retSize);
if (compress(retBuf, retSize, buffer, size) != Z_OK) { if (compress((Bytef*)retBuf, retSize, (const Bytef*)buffer, size) != Z_OK) {
free(retBuf); free(retBuf);
retBuf = NULL; retBuf = NULL;
} }
@ -932,7 +927,7 @@ void* zipUncompress(void* buffer, int size, unsigned long* retSize)
{ {
void* retBuf = malloc(*retSize); void* retBuf = malloc(*retSize);
if (uncompress(retBuf, retSize, buffer, size) != Z_OK) { if (uncompress((Bytef*)retBuf, retSize, (const Bytef*)buffer, size) != Z_OK) {
free(retBuf); free(retBuf);
retBuf = NULL; retBuf = NULL;
} }

View File

@ -825,7 +825,7 @@ bool retro_load_game(const struct retro_game_info *info)
if (!info) if (!info)
return false; return false;
image_buffer = malloc(FB_MAX_LINE_WIDTH*FB_MAX_LINES*sizeof(uint16_t)); image_buffer = (uint16_t*)malloc(FB_MAX_LINE_WIDTH*FB_MAX_LINES*sizeof(uint16_t));
image_buffer_base_width = 272; image_buffer_base_width = 272;
image_buffer_current_width = image_buffer_base_width; image_buffer_current_width = image_buffer_base_width;
image_buffer_height = 240; image_buffer_height = 240;
@ -904,10 +904,8 @@ bool retro_load_game(const struct retro_game_info *info)
if (auto_rewind_cas) if (auto_rewind_cas)
tapeRewindNextInsert(); tapeRewindNextInsert();
langSetLanguage(properties->language); joystickPortSetType(0, (JoystickPortType)properties->joy1.typeId);
joystickPortSetType(1, (JoystickPortType)properties->joy2.typeId);
joystickPortSetType(0, properties->joy1.typeId);
joystickPortSetType(1, properties->joy2.typeId);
#if 0 #if 0
printerIoSetType(properties->ports.Lpt.type, properties->ports.Lpt.fileName); printerIoSetType(properties->ports.Lpt.type, properties->ports.Lpt.fileName);
@ -1205,12 +1203,12 @@ int frameBufferGetScanline(void)
FrameBufferData* frameBufferDataCreate(int maxWidth, int maxHeight, int defaultHorizZoom) FrameBufferData* frameBufferDataCreate(int maxWidth, int maxHeight, int defaultHorizZoom)
{ {
return (void*)image_buffer; return (FrameBufferData*)image_buffer;
} }
FrameBufferData* frameBufferGetActive() FrameBufferData* frameBufferGetActive(void)
{ {
return (void*)image_buffer; return (FrameBufferData*)image_buffer;
} }
void frameBufferSetLineCount(FrameBuffer* frameBuffer, int val) void frameBufferSetLineCount(FrameBuffer* frameBuffer, int val)
@ -1332,7 +1330,7 @@ bool retro_unserialize(const void *data, size_t size)
data = (char*)data + sizeof(((MemFile*)0)->filename); data = (char*)data + sizeof(((MemFile*)0)->filename);
sz = * (int *)data; sz = * (int *)data;
data = (char*)data + sizeof(int); data = (char*)data + sizeof(int);
zipSaveFile("mem0", filename, 1, data, sz ); zipSaveFile("mem0", filename, 1, (void*)data, sz );
data = (char*)data + sz; data = (char*)data + sz;
} }
saveStateCreateForRead("mem0"); saveStateCreateForRead("mem0");