libretro: Cleanup some #ifdefs

This commit is contained in:
retro-wertz 2018-06-06 16:20:32 +08:00
parent 1d4dacc6f9
commit 1606ea7482
16 changed files with 134 additions and 272 deletions

View File

@ -2,15 +2,12 @@
#define SYSTEM_H
#ifndef __LIBRETRO__
#include <zlib.h>
#include "common/cstdint.h"
#else
#include <stdint.h>
#endif
#ifndef __LIBRETRO__
#include <zlib.h>
#endif
#define winlog log
class SoundDriver;

View File

@ -16,22 +16,18 @@
#define MAX_CHEATS 16384
#ifndef __LIBRETRO__
extern bool cpuIsMultiBoot;
extern bool mirroringEnable;
extern bool parseDebug;
extern bool speedHack;
extern bool speedup;
#endif
extern char *rewindMemory;
extern const char *aviRecordDir;
extern const char *biosFileNameGB;
extern const char *biosFileNameGBA;
extern const char *biosFileNameGBC;
#ifndef __LIBRETRO__
extern const char *loadDotCodeFile;
extern const char *saveDotCodeFile;
#endif
extern const char *linkHostAddr;
extern const char *movieRecordDir;
extern const char *romDirGB;
@ -50,11 +46,9 @@ extern int autoPatch;
extern int autoSaveLoadCheatList;
extern int aviRecording;
extern int captureFormat;
#ifndef __LIBRETRO__
extern int cheatsEnabled;
extern int cpuDisableSfx;
extern int cpuSaveType;
#endif
extern int dinputKeyFocus;
extern int disableMMX;
extern int disableStatusMessages;
@ -80,10 +74,8 @@ extern int glFilter;
extern int ifbType;
extern int joypadDefault;
extern int languageOption;
#ifndef __LIBRETRO__
extern int layerEnable;
extern int layerSettings;
#endif
extern int linkAuto;
extern int linkHacks;
extern int linkMode;
@ -101,9 +93,7 @@ extern int optPrintUsage;
extern int paused;
extern int pauseWhenInactive;
extern int recentFreeze;
#ifndef __LIBRETRO__
extern int renderedFrames;
#endif
extern int rewindCount;
extern int rewindCounter;
extern int rewindPos;
@ -111,10 +101,8 @@ extern int rewindSaveNeeded;
extern int rewindTimer;
extern int rewindTopPos;
// extern int romSize;
#ifndef __LIBRETRO__
extern int rtcEnabled;
extern int saveType;
#endif
extern int screenMessage;
extern int sensorX;
extern int sensorY;
@ -123,9 +111,7 @@ extern int showSpeed;
extern int showSpeedTransparent;
extern int sizeX;
extern int sizeY;
#ifndef __LIBRETRO__
extern int skipBios;
#endif
extern int skipSaveGameBattery;
extern int skipSaveGameCheats;
extern int soundRecording;
@ -135,9 +121,7 @@ extern int surfaceSizeX;
extern int surfaceSizeY;
extern int threadPriority;
extern int tripleBuffering;
#ifndef __LIBRETRO__
extern int useBios;
#endif
extern int useBiosFileGB;
extern int useBiosFileGBA;
extern int useBiosFileGBC;

View File

@ -1,11 +1,7 @@
#ifndef CHEATS_H
#define CHEATS_H
#ifndef __LIBRETRO__
#include "../common/ConfigManager.h"
#else
#include "../src/libretro/UtilRetro.h"
#endif
struct CheatsData {
int code;

View File

@ -72,7 +72,9 @@ void eepromReadGame(const uint8_t*& data, int version)
eepromSize = 512;
}
}
#else
#else // !__LIBRETRO__
void eepromSaveGame(gzFile gzFile)
{
utilWriteData(gzFile, eepromSaveData);

View File

@ -12,20 +12,17 @@
#ifdef __LIBRETRO__
extern void eepromSaveGame(uint8_t*& data);
extern void eepromReadGame(const uint8_t*& data, int version);
#else
extern uint8_t* eepromData;
#else // !__LIBRETRO__
extern void eepromSaveGame(gzFile _gzFile);
extern void eepromReadGame(gzFile _gzFile, int version);
extern void eepromReadGameSkip(gzFile _gzFile, int version);
extern uint8_t eepromData[0x2000];
#endif
extern int eepromRead(uint32_t address);
extern void eepromWrite(uint32_t address, uint8_t value);
extern void eepromInit();
extern void eepromReset();
#ifdef __LIBRETRO__
extern uint8_t* eepromData;
#else
extern uint8_t eepromData[0x2000];
#endif
extern bool eepromInUse;
extern int eepromSize;

View File

@ -82,7 +82,8 @@ void flashReadGame(const uint8_t*& data, int)
{
utilReadDataMem(data, flashSaveData3);
}
#else
#else // !__LIBRETRO__
void flashSaveGame(gzFile gzFile)
{
utilWriteData(gzFile, flashSaveData3);

View File

@ -3,30 +3,26 @@
#ifndef __LIBRETRO__
#include "../common/cstdint.h"
#include <zlib.h>
#else
#include <stdint.h>
#endif
#include <zlib.h>
#define FLASH_128K_SZ 0x20000
#ifdef __LIBRETRO__
extern void flashSaveGame(uint8_t*& data);
extern void flashReadGame(const uint8_t*& data, int);
extern uint8_t* flashSaveMemory;
#else
extern void flashSaveGame(gzFile _gzFile);
extern void flashReadGame(gzFile _gzFile, int version);
extern void flashReadGameSkip(gzFile _gzFile, int version);
extern uint8_t flashSaveMemory[FLASH_128K_SZ];
#endif
extern uint8_t flashRead(uint32_t address);
extern void flashWrite(uint32_t address, uint8_t byte);
extern void flashDelayedWrite(uint32_t address, uint8_t byte);
#ifdef __LIBRETRO__
extern uint8_t* flashSaveMemory;
#else
extern uint8_t flashSaveMemory[FLASH_128K_SZ];
#endif
extern void flashSaveDecide(uint32_t address, uint8_t byte);
extern void flashReset();
extern void flashSetSize(int size);

View File

@ -7,11 +7,7 @@
#include "../NLS.h"
#include "../System.h"
#include "../Util.h"
#ifndef __LIBRETRO__
#include "../common/ConfigManager.h"
#else
#include "../src/libretro/UtilRetro.h"
#endif
#include "Cheats.h"
#include "EEprom.h"
#include "Flash.h"

View File

@ -10,11 +10,7 @@
#include "../NLS.h"
#include "../System.h"
#include "../Util.h"
#ifndef __LIBRETRO__
#include "../common/ConfigManager.h"
#else
#include "../src/libretro/UtilRetro.h"
#endif
#include "Cheats.h"
#include "EEprom.h"
#include "Flash.h"
@ -887,7 +883,7 @@ DEFINE_IMM5_INSN(IMM5_ASR, 10)
static INSN_REGPARM void thumb##BASE##_6(uint32_t opcode) { THREEARG_INSN(OP, 6); } \
static INSN_REGPARM void thumb##BASE##_7(uint32_t opcode) { THREEARG_INSN(OP, 7); }
#define DEFINE_IMM3_INSN(OP, BASE) \
#define DEFINE_IMM3_INSN(OP, BASE) \
static INSN_REGPARM void thumb##BASE##_0(uint32_t opcode) { THREEARG_INSN(OP##_0, 0); } \
static INSN_REGPARM void thumb##BASE##_1(uint32_t opcode) { THREEARG_INSN(OP, 1); } \
static INSN_REGPARM void thumb##BASE##_2(uint32_t opcode) { THREEARG_INSN(OP, 2); } \

View File

@ -10,11 +10,7 @@
#include "../NLS.h"
#include "../System.h"
#include "../Util.h"
#ifndef __LIBRETRO__
#include "../common/ConfigManager.h"
#else
#include "../src/libretro/UtilRetro.h"
#endif
#include "../common/Port.h"
#include "Cheats.h"
#include "EEprom.h"
@ -582,7 +578,7 @@ void CPUUpdateRenderBuffers(bool force)
}
#ifdef __LIBRETRO__
#include <cstddef>
#include <stddef.h>
unsigned int CPUWriteState(uint8_t* data, unsigned size)
{
@ -603,11 +599,7 @@ unsigned int CPUWriteState(uint8_t* data, unsigned size)
utilWriteMem(data, workRAM, 0x40000);
utilWriteMem(data, vram, 0x20000);
utilWriteMem(data, oam, 0x400);
#ifdef __LIBRETRO__
utilWriteMem(data, pix, 4 * 240 * 160);
#else
utilWriteMem(data, pix, 4 * 241 * 162);
#endif
utilWriteMem(data, ioMem, 0x400);
eepromSaveGame(data);
@ -622,7 +614,83 @@ bool CPUWriteMemState(char* memory, int available, long& reserved)
{
return false;
}
#else
bool CPUReadState(const uint8_t* data, unsigned size)
{
// Don't really care about version.
int version = utilReadIntMem(data);
if (version != SAVE_GAME_VERSION)
return false;
char romname[16];
utilReadMem(romname, data, 16);
if (memcmp(&rom[0xa0], romname, 16) != 0)
return false;
// Don't care about use bios ...
utilReadIntMem(data);
utilReadMem(&reg[0], data, sizeof(reg));
utilReadDataMem(data, saveGameStruct);
stopState = utilReadIntMem(data) ? true : false;
IRQTicks = utilReadIntMem(data);
if (IRQTicks > 0)
intState = true;
else {
intState = false;
IRQTicks = 0;
}
utilReadMem(internalRAM, data, 0x8000);
utilReadMem(paletteRAM, data, 0x400);
utilReadMem(workRAM, data, 0x40000);
utilReadMem(vram, data, 0x20000);
utilReadMem(oam, data, 0x400);
utilReadMem(pix, data, 4 * 240 * 160);
utilReadMem(ioMem, data, 0x400);
eepromReadGame(data, version);
flashReadGame(data, version);
soundReadGame(data, version);
rtcReadGame(data);
//// Copypasta stuff ...
// set pointers!
layerEnable = layerSettings & DISPCNT;
CPUUpdateRender();
// CPU Update Render Buffers set to true
CLEAR_ARRAY(line0);
CLEAR_ARRAY(line1);
CLEAR_ARRAY(line2);
CLEAR_ARRAY(line3);
// End of CPU Update Render Buffers set to true
CPUUpdateWindow0();
CPUUpdateWindow1();
gbaSaveType = 0;
SetSaveType(saveType);
if (eepromInUse)
gbaSaveType = 3;
systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
if (armState) {
ARM_PREFETCH;
} else {
THUMB_PREFETCH;
}
CPUUpdateRegister(0x204, CPUReadHalfWordQuick(0x4000204));
return true;
}
#else // !__LIBRETRO__
static bool CPUWriteState(gzFile gzFile)
{
utilWriteInt(gzFile, SAVE_GAME_VERSION);
@ -645,11 +713,7 @@ static bool CPUWriteState(gzFile gzFile)
utilGzWrite(gzFile, workRAM, 0x40000);
utilGzWrite(gzFile, vram, 0x20000);
utilGzWrite(gzFile, oam, 0x400);
#ifdef __LIBRETRO__
utilGzWrite(gzFile, pix, 4 * 240 * 160);
#else
utilGzWrite(gzFile, pix, 4 * 241 * 162);
#endif
utilGzWrite(gzFile, ioMem, 0x400);
eepromSaveGame(gzFile);
@ -699,110 +763,7 @@ bool CPUWriteMemState(char* memory, int available, long& reserved)
return res;
}
#endif
#ifdef __LIBRETRO__
bool CPUReadState(const uint8_t* data, unsigned size)
{
// Don't really care about version.
int version = utilReadIntMem(data);
if (version != SAVE_GAME_VERSION)
return false;
char romname[16];
utilReadMem(romname, data, 16);
if (memcmp(&rom[0xa0], romname, 16) != 0)
return false;
// Don't care about use bios ...
utilReadIntMem(data);
utilReadMem(&reg[0], data, sizeof(reg));
utilReadDataMem(data, saveGameStruct);
stopState = utilReadIntMem(data) ? true : false;
IRQTicks = utilReadIntMem(data);
if (IRQTicks > 0)
intState = true;
else {
intState = false;
IRQTicks = 0;
}
utilReadMem(internalRAM, data, 0x8000);
utilReadMem(paletteRAM, data, 0x400);
utilReadMem(workRAM, data, 0x40000);
utilReadMem(vram, data, 0x20000);
utilReadMem(oam, data, 0x400);
#ifdef __LIBRETRO__
utilReadMem(pix, data, 4 * 240 * 160);
#else
utilReadMem(pix, data, 4 * 241 * 162);
#endif
utilReadMem(ioMem, data, 0x400);
eepromReadGame(data, version);
flashReadGame(data, version);
soundReadGame(data, version);
rtcReadGame(data);
//// Copypasta stuff ...
// set pointers!
layerEnable = layerSettings & DISPCNT;
CPUUpdateRender();
// CPU Update Render Buffers set to true
CLEAR_ARRAY(line0);
CLEAR_ARRAY(line1);
CLEAR_ARRAY(line2);
CLEAR_ARRAY(line3);
// End of CPU Update Render Buffers set to true
CPUUpdateWindow0();
CPUUpdateWindow1();
gbaSaveType = 0;
switch (saveType) {
case 0:
cpuSaveGameFunc = flashSaveDecide;
break;
case 1:
cpuSaveGameFunc = sramWrite;
gbaSaveType = 1;
break;
case 2:
cpuSaveGameFunc = flashWrite;
gbaSaveType = 2;
break;
case 3:
break;
case 5:
gbaSaveType = 5;
break;
default:
#ifdef CELL_VBA_DEBUG
systemMessage(MSG_UNSUPPORTED_SAVE_TYPE,
N_("Unsupported save type %d"), saveType);
#endif
break;
}
if (eepromInUse)
gbaSaveType = 3;
systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
if (armState) {
ARM_PREFETCH;
} else {
THUMB_PREFETCH;
}
CPUUpdateRegister(0x204, CPUReadHalfWordQuick(0x4000204));
return true;
}
#else
static bool CPUReadState(gzFile gzFile)
{
int version = utilReadInt(gzFile);
@ -866,14 +827,10 @@ static bool CPUReadState(gzFile gzFile)
utilGzRead(gzFile, workRAM, 0x40000);
utilGzRead(gzFile, vram, 0x20000);
utilGzRead(gzFile, oam, 0x400);
#ifdef __LIBRETRO__
utilGzRead(gzFile, pix, 4 * 240 * 160);
#else
if (version < SAVE_GAME_VERSION_6)
utilGzRead(gzFile, pix, 4 * 240 * 160);
else
utilGzRead(gzFile, pix, 4 * 241 * 162);
#endif
utilGzRead(gzFile, ioMem, 0x400);
if (skipSaveGameBattery) {
@ -1610,11 +1567,8 @@ int CPULoadRom(const char* szFile)
CPUCleanUp();
return 0;
}
#ifdef __LIBRETRO__
pix = (uint8_t*)calloc(1, 4 * 240 * 160);
#else
pix = (uint8_t*)calloc(1, 4 * 241 * 162);
#endif
if (pix == NULL) {
systemMessage(MSG_OUT_OF_MEMORY, N_("Failed to allocate memory for %s"),
"PIX");
@ -1706,11 +1660,8 @@ int CPULoadRomData(const char* data, int size)
CPUCleanUp();
return 0;
}
#ifdef __LIBRETRO__
pix = (uint8_t*)calloc(1, 4 * 240 * 160);
#else
pix = (uint8_t*)calloc(1, 4 * 241 * 162);
#endif
if (pix == NULL) {
systemMessage(MSG_OUT_OF_MEMORY, N_("Failed to allocate memory for %s"),
"PIX");

View File

@ -17,6 +17,7 @@
#include "SoundRetro.h"
#include "libretro.h"
unsigned g_audio_frames;
extern retro_audio_sample_batch_t audio_batch_cb;

View File

@ -6,6 +6,7 @@
#include "System.h"
#include "Util.h"
#include "common/Port.h"
#include "common/ConfigManager.h"
#include "gba/Flash.h"
#include "gba/GBA.h"
#include "gba/Globals.h"
@ -14,44 +15,52 @@
#include "gb/gbGlobals.h"
#include "gba/gbafilter.h"
#include "UtilRetro.h"
#ifndef _MSC_VER
#include <strings.h>
#define _stricmp strcasecmp
#endif // ! _MSC_VER
// Because Configmanager was introduced, this has to be done.
int rtcEnabled = 0;
int cpuDisableSfx = 0;
int skipBios = 0;
int saveType = 0;
int cpuSaveType = 0;
int skipSaveGameBattery = 0;
int skipSaveGameCheats = 0;
int useBios = 0;
int cheatsEnabled = 1;
int layerSettings = 0xff00;
int layerEnable = 0xff00;
bool speedup = false;
bool parseDebug = false;
bool speedHack = false;
bool mirroringEnable = false;
bool cpuIsMultiBoot = false;
const char* loadDotCodeFile;
const char* saveDotCodeFile;
extern int systemColorDepth;
extern int systemRedShift;
extern int systemGreenShift;
extern int systemBlueShift;
// Because Configmanager was introduced, this has to be done.
const char* loadDotCodeFile;
const char* saveDotCodeFile;
int cheatsEnabled = true;
int saveType = 0;
int skipBios = 0;
int rtcEnabled;
int frameSkip = 1;
bool speedup = false;
bool cpuIsMultiBoot = false;
int cpuDisableSfx = false;
bool parseDebug = true;
int layerSettings = 0xff00;
int layerEnable = 0xff00;
bool speedHack = false;
int cpuSaveType = 0;
int useBios = 0;
bool mirroringEnable = true;
bool skipSaveGameBattery = false;
bool skipSaveGameCheats = false;
extern uint16_t systemColorMap16[0x10000];
extern uint32_t systemColorMap32[0x10000];
const char gb_image_header[] =
{
static_cast<const char>
(
0xce, 0xed, 0x66, 0x66, 0xcc, 0x0d, 0x00, 0x0b, 0x03, 0x73, 0x00,
0x83, 0x00, 0x0c, 0x00, 0x0d, 0x00, 0x08, 0x11, 0x1f, 0x88, 0x89,
0x00, 0x0e, 0xdc, 0xcc, 0x6e, 0xe6, 0xdd, 0xdd, 0xd9, 0x99, 0xbb,
0xbb, 0x67, 0x63, 0x6e, 0x0e, 0xec, 0xcc, 0xdd, 0xdc, 0x99, 0x9f,
0xbb, 0xb9, 0x33, 0x3e
)
};
bool utilWritePNGFile(const char* fileName, int w, int h, uint8_t* pix)
{
return false;

View File

@ -1,35 +0,0 @@
#ifndef _VBA_UTIL_RETRO_H
#define _VBA_UTIL_RETRO_H
extern bool speedup;
extern int cheatsEnabled;
extern int useBios;
extern int skipBios;
extern int synchronize;
extern int cpuDisableSfx;
extern bool cpuIsMultiBoot;
extern bool parseDebug;
extern bool speedHack;
extern bool mirroringEnable;
extern int rtcEnabled;
extern const char *loadDotCodeFile;
extern const char *saveDotCodeFile;
extern bool skipSaveGameBattery;
extern bool skipSaveGameCheats;
#define MAX_CHEATS 100
const char gb_image_header[] =
{
static_cast<const char>
(
0xce, 0xed, 0x66, 0x66, 0xcc, 0x0d, 0x00, 0x0b, 0x03, 0x73, 0x00,
0x83, 0x00, 0x0c, 0x00, 0x0d, 0x00, 0x08, 0x11, 0x1f, 0x88, 0x89,
0x00, 0x0e, 0xdc, 0xcc, 0x6e, 0xe6, 0xdd, 0xdd, 0xd9, 0x99, 0xbb,
0xbb, 0x67, 0x63, 0x6e, 0x0e, 0xec, 0xcc, 0xdd, 0xdc, 0x99, 0x9f,
0xbb, 0xb9, 0x33, 0x3e
)
};
#endif // _VBA_UTIL_RETRO_H

View File

@ -1,17 +0,0 @@
#include "configmanager.h"
int cheatsEnabled = true;
int saveType = 0;
int layerEnable = 0xff00;
int layerSettings = 0xff00;
bool parseDebug = true;
bool cpuIsMultiBoot = false;
int cpuDisableSfx = false;
bool mirroringEnable = true;
int skipBios = 0;
bool speedup = false;
bool speedHack = false;
const char* loadDotCodeFile;
const char* saveDotCodeFile;
int useBios = 0;
int rtcEnabled;
int cpuSaveType = 0;

View File

@ -1,15 +0,0 @@
extern bool cpuIsMultiBoot;
extern int cpuDisableSfx;
extern int cpuSaveType;
extern bool mirroringEnable;
extern bool parseDebug;
extern bool speedHack;
extern bool speedup;
extern int cheatsEnabled;
extern int layerEnable;
extern int layerSettings;
extern int skipBios;
extern int useBios;
extern const char *loadDotCodeFile;
extern const char *saveDotCodeFile;
extern int rtcEnabled;

View File

@ -15,6 +15,7 @@
#include "../apu/Gb_Apu.h"
#include "../apu/Gb_Oscs.h"
#include "../common/Port.h"
#include "../common/ConfigManager.h"
#include "../gba/Cheats.h"
#include "../gba/EEprom.h"
#include "../gba/Flash.h"
@ -37,7 +38,7 @@ static retro_input_state_t input_cb;
retro_audio_sample_batch_t audio_batch_cb;
static retro_environment_t environ_cb;
bool enableRtc;
static bool enableRtc;
static bool can_dupe;
unsigned device_type = 0;
int emulating = 0;
@ -64,8 +65,8 @@ int systemFrameSkip = 0;
int systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
int systemSpeed = 0;
uint64_t startTime = 0;
uint32_t renderedFrames = 0;
//uint64_t startTime = 0;
//uint32_t renderedFrames = 0;
void (*dbgOutput)(const char* s, uint32_t addr);
void (*dbgSignal)(int sig, int number);
@ -466,6 +467,7 @@ static void gba_init(void)
if (flashSize == 0x10000 || flashSize == 0x20000)
flashSetSize(flashSize);
rtcEnabled = enableRtc;
if (enableRtc)
rtcEnable(enableRtc);
@ -870,6 +872,7 @@ uint32_t systemReadJoypad(int which)
bool systemReadJoypads() { return true; }
void systemUpdateMotionSensor() {}
uint8_t systemGetSensorDarkness() { return 0; }
void systemCartridgeRumble(bool)