Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
retro-wertz committed Aug 6, 2019
1 parent 408cab7 commit d9f8396
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 127 deletions.
7 changes: 7 additions & 0 deletions src/gb/gb.h
@@ -1,6 +1,11 @@
#ifndef GB_H
#define GB_H

#define gbWidth 160
#define gbHeight 144
#define sgbWidth 256
#define sgbHeight 224

const int GB_C_FLAG = 0x10;
const int GB_H_FLAG = 0x20;
const int GB_N_FLAG = 0x40;
Expand Down Expand Up @@ -55,6 +60,8 @@ void setColorizerHack(bool value);
bool allowColorizerHack(void);

extern int gbHardware;
extern int gbRomType; // gets type from header 0x147
extern int gbBattery; // enabled when gbRamSize != 0

extern struct EmulatedSystem GBSystem;

Expand Down
2 changes: 1 addition & 1 deletion src/gb/gbSound.cpp
Expand Up @@ -246,6 +246,7 @@ static char dummy_state[735 * 2];
&name, sizeof(type) \
}

#ifndef __LIBRETRO__
// Old save state support

static variable_desc gbsound_format[] = {
Expand Down Expand Up @@ -355,7 +356,6 @@ enum {
nr52
};

#ifndef __LIBRETRO__
static void gbSoundReadGameOld(int version, gzFile gzFile)
{
if (version == 11) {
Expand Down
134 changes: 67 additions & 67 deletions src/gba/Flash.cpp
Expand Up @@ -27,30 +27,6 @@ int flashDeviceID = 0x1b;
int flashManufacturerID = 0x32;
int flashBank = 0;

static variable_desc flashSaveData[] = {
{ &flashState, sizeof(int) },
{ &flashReadState, sizeof(int) },
{ &flashSaveMemory[0], SIZE_FLASH512 },
{ NULL, 0 }
};

static variable_desc flashSaveData2[] = {
{ &flashState, sizeof(int) },
{ &flashReadState, sizeof(int) },
{ &flashSize, sizeof(int) },
{ &flashSaveMemory[0], SIZE_FLASH1M },
{ NULL, 0 }
};

static variable_desc flashSaveData3[] = {
{ &flashState, sizeof(int) },
{ &flashReadState, sizeof(int) },
{ &flashSize, sizeof(int) },
{ &flashBank, sizeof(int) },
{ &flashSaveMemory[0], SIZE_FLASH1M },
{ NULL, 0 }
};

void flashInit()
{
memset(flashSaveMemory, 0xff, sizeof(flashSaveMemory));
Expand All @@ -63,49 +39,6 @@ void flashReset()
flashBank = 0;
}

#ifdef __LIBRETRO__
void flashSaveGame(uint8_t*& data)
{
utilWriteDataMem(data, flashSaveData3);
}

void flashReadGame(const uint8_t*& data, int)
{
utilReadDataMem(data, flashSaveData3);
}

#else // !__LIBRETRO__
void flashSaveGame(gzFile gzFile)
{
utilWriteData(gzFile, flashSaveData3);
}

void flashReadGame(gzFile gzFile, int version)
{
if (version < SAVE_GAME_VERSION_5)
utilReadData(gzFile, flashSaveData);
else if (version < SAVE_GAME_VERSION_7) {
utilReadData(gzFile, flashSaveData2);
flashBank = 0;
flashSetSize(flashSize);
} else {
utilReadData(gzFile, flashSaveData3);
}
}

void flashReadGameSkip(gzFile gzFile, int version)
{
// skip the flash data in a save game
if (version < SAVE_GAME_VERSION_5)
utilReadDataSkip(gzFile, flashSaveData);
else if (version < SAVE_GAME_VERSION_7) {
utilReadDataSkip(gzFile, flashSaveData2);
} else {
utilReadDataSkip(gzFile, flashSaveData3);
}
}
#endif

void flashSetSize(int size)
{
// log("Setting flash size to %d\n", size);
Expand Down Expand Up @@ -279,3 +212,70 @@ void flashWrite(uint32_t address, uint8_t byte)
break;
}
}

static variable_desc flashSaveData3[] = {
{ &flashState, sizeof(int) },
{ &flashReadState, sizeof(int) },
{ &flashSize, sizeof(int) },
{ &flashBank, sizeof(int) },
{ &flashSaveMemory[0], SIZE_FLASH1M },
{ NULL, 0 }
};

#ifdef __LIBRETRO__
void flashSaveGame(uint8_t*& data)
{
utilWriteDataMem(data, flashSaveData3);
}

void flashReadGame(const uint8_t*& data, int)
{
utilReadDataMem(data, flashSaveData3);
}

#else // !__LIBRETRO__
static variable_desc flashSaveData[] = {
{ &flashState, sizeof(int) },
{ &flashReadState, sizeof(int) },
{ &flashSaveMemory[0], SIZE_FLASH512 },
{ NULL, 0 }
};

static variable_desc flashSaveData2[] = {
{ &flashState, sizeof(int) },
{ &flashReadState, sizeof(int) },
{ &flashSize, sizeof(int) },
{ &flashSaveMemory[0], SIZE_FLASH1M },
{ NULL, 0 }
};

void flashSaveGame(gzFile gzFile)
{
utilWriteData(gzFile, flashSaveData3);
}

void flashReadGame(gzFile gzFile, int version)
{
if (version < SAVE_GAME_VERSION_5)
utilReadData(gzFile, flashSaveData);
else if (version < SAVE_GAME_VERSION_7) {
utilReadData(gzFile, flashSaveData2);
flashBank = 0;
flashSetSize(flashSize);
} else {
utilReadData(gzFile, flashSaveData3);
}
}

void flashReadGameSkip(gzFile gzFile, int version)
{
// skip the flash data in a save game
if (version < SAVE_GAME_VERSION_5)
utilReadDataSkip(gzFile, flashSaveData);
else if (version < SAVE_GAME_VERSION_7) {
utilReadDataSkip(gzFile, flashSaveData2);
} else {
utilReadDataSkip(gzFile, flashSaveData3);
}
}
#endif
1 change: 1 addition & 0 deletions src/gba/GBA-arm.cpp
Expand Up @@ -1235,6 +1235,7 @@ DEFINE_ALU_INSN_C(1F, 3F, MVNS, YES)
int mult = (opcode & 0x0F); \
uint32_t rs = reg[(opcode >> 8) & 0x0F].I; \
int acc = (opcode >> 12) & 0x0F; /* or destLo */ \
maybe_unused(acc); \
int dest = (opcode >> 16) & 0x0F; /* or destHi */ \
OP; \
SETCOND; \
Expand Down
3 changes: 3 additions & 0 deletions src/gba/GBA.h
Expand Up @@ -19,6 +19,9 @@ const uint64_t TICKS_PER_SECOND = 16777216;
#define SAVE_GAME_VERSION_10 10
#define SAVE_GAME_VERSION SAVE_GAME_VERSION_10

#define gbaWidth 240
#define gbaHeight 160

enum {
GBA_SAVE_AUTO = 0,
GBA_SAVE_EEPROM,
Expand Down
2 changes: 2 additions & 0 deletions src/gba/Sound.cpp
Expand Up @@ -588,6 +588,7 @@ static struct {
int soundDSBValue;
} state;

#ifndef __LIBRETRO__
// Old GBA sound state format
static variable_desc old_gba_state[] = {
SKIP(int, soundPaused),
Expand Down Expand Up @@ -673,6 +674,7 @@ variable_desc old_gba_state2[] = {
SKIP(int, sound3ForcedOutput),
{ NULL, 0 }
};
#endif

// New state format
static variable_desc gba_state[] = {
Expand Down
3 changes: 1 addition & 2 deletions src/libretro/Makefile.common
Expand Up @@ -6,8 +6,7 @@ SOURCES_CXX :=
SOURCES_CXX += \
$(CORE_DIR)/libretro/libretro.cpp \
$(CORE_DIR)/libretro/UtilRetro.cpp \
$(CORE_DIR)/libretro/SoundRetro.cpp \
$(CORE_DIR)/libretro/scrc32.cpp
$(CORE_DIR)/libretro/SoundRetro.cpp

SOURCES_CXX += \
$(CORE_DIR)/apu/Gb_Oscs.cpp \
Expand Down

0 comments on commit d9f8396

Please sign in to comment.