Skip to content
Permalink
Browse files

Merge remote-tracking branch 'vbam-libretro/master'

  • Loading branch information
rkitover committed Aug 15, 2019
2 parents 6b18c1f + b8afa8c commit 51a4f74b94af92e3c91c9d766196ab3a72f2eba9
@@ -195,6 +195,7 @@ int gbSynchronizeTicks = GBSYNCHRONIZE_CLOCK_TICKS;
// emulator features
int gbBattery = 0;
int gbRumble = 0;
int gbRTCPresent = 0;
bool gbBatteryError = false;
int gbCaptureNumber = 0;
bool gbCapture = false;
@@ -4360,8 +4361,6 @@ bool gbUpdateSizes()
memset(gbRam, gbRamFill, gbRamSize);
}

gbBattery = gbRumble = 0;

switch (gbRomType) {
case 0x03:
case 0x06:
@@ -4377,13 +4376,31 @@ bool gbUpdateSizes()
case 0xff:
gbBattery = 1;
break;
default:
gbBattery = 0;
break;
}

switch (gbRomType) {
case 0x1c:
case 0x1d:
case 0x1e:
gbRumble = 1;
break;
default:
gbRumble = 0;
break;
}

switch (gbRomType) {
case 0x0f:
case 0x10: // mbc3
case 0xfd: // tama5
gbRTCPresent = 1;
break;
default:
gbRTCPresent = 0;
break;
}

gbInit();
@@ -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;
@@ -55,6 +60,9 @@ 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 int gbRTCPresent; // gbROM has RTC support

extern struct EmulatedSystem GBSystem;

@@ -389,24 +389,26 @@ void mapperMBC3ROM(uint16_t address, uint8_t value)
gbDataMBC3.mapperRAMBank = value;
gbDataMBC3.mapperRAMAddress = tmpAddress;
} else {
if (gbDataMBC3.mapperRAMEnable) {
if (gbRTCPresent && gbDataMBC3.mapperRAMEnable) {
gbDataMBC3.mapperRAMBank = -1;

gbDataMBC3.mapperClockRegister = value;
}
}
break;
case 0x6000: // clock latch
if (gbDataMBC3.mapperClockLatch == 0 && value == 1) {
memoryUpdateMBC3Clock();
gbDataMBC3.mapperLSeconds = gbDataMBC3.mapperSeconds;
gbDataMBC3.mapperLMinutes = gbDataMBC3.mapperMinutes;
gbDataMBC3.mapperLHours = gbDataMBC3.mapperHours;
gbDataMBC3.mapperLDays = gbDataMBC3.mapperDays;
gbDataMBC3.mapperLControl = gbDataMBC3.mapperControl;
if (gbRTCPresent) {
if (gbDataMBC3.mapperClockLatch == 0 && value == 1) {
memoryUpdateMBC3Clock();
gbDataMBC3.mapperLSeconds = gbDataMBC3.mapperSeconds;
gbDataMBC3.mapperLMinutes = gbDataMBC3.mapperMinutes;
gbDataMBC3.mapperLHours = gbDataMBC3.mapperHours;
gbDataMBC3.mapperLDays = gbDataMBC3.mapperDays;
gbDataMBC3.mapperLControl = gbDataMBC3.mapperControl;
}
if (value == 0x00 || value == 0x01)
gbDataMBC3.mapperClockLatch = value;
}
if (value == 0x00 || value == 0x01)
gbDataMBC3.mapperClockLatch = value;
break;
}
}
@@ -415,12 +417,12 @@ void mapperMBC3ROM(uint16_t address, uint8_t value)
void mapperMBC3RAM(uint16_t address, uint8_t value)
{
if (gbDataMBC3.mapperRAMEnable) {
if (gbDataMBC3.mapperRAMBank != -1) {
if (gbDataMBC3.mapperRAMBank >= 0) {
if (gbRamSize) {
gbMemoryMap[address >> 12][address & 0x0fff] = value;
systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
}
} else {
} else if (gbRTCPresent) {
time(&gbDataMBC3.mapperLastTime);
switch (gbDataMBC3.mapperClockRegister) {
case 0x08:
@@ -450,25 +452,25 @@ void mapperMBC3RAM(uint16_t address, uint8_t value)
uint8_t mapperMBC3ReadRAM(uint16_t address)
{
if (gbDataMBC3.mapperRAMEnable) {
if (gbDataMBC3.mapperRAMBank != -1) {
if (gbDataMBC3.mapperRAMBank >= 0) {
return gbMemoryMap[address >> 12][address & 0x0fff];
}

switch (gbDataMBC3.mapperClockRegister) {
case 0x08:
return gbDataMBC3.mapperLSeconds;
break;
case 0x09:
return gbDataMBC3.mapperLMinutes;
break;
case 0x0a:
return gbDataMBC3.mapperLHours;
break;
case 0x0b:
return gbDataMBC3.mapperLDays;
break;
case 0x0c:
return gbDataMBC3.mapperLControl;
} else if (gbRTCPresent) {
switch (gbDataMBC3.mapperClockRegister) {
case 0x08:
return gbDataMBC3.mapperLSeconds;
break;
case 0x09:
return gbDataMBC3.mapperLMinutes;
break;
case 0x0a:
return gbDataMBC3.mapperLHours;
break;
case 0x0b:
return gbDataMBC3.mapperLDays;
break;
case 0x0c:
return gbDataMBC3.mapperLControl;
}
}
}

@@ -246,6 +246,7 @@ static char dummy_state[735 * 2];
&name, sizeof(type) \
}

#ifndef __LIBRETRO__
// Old save state support

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

#ifndef __LIBRETRO__
static void gbSoundReadGameOld(int version, gzFile gzFile)
{
if (version == 11) {
@@ -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));
@@ -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);
@@ -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
@@ -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; \
@@ -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,
@@ -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),
@@ -673,6 +674,7 @@ variable_desc old_gba_state2[] = {
SKIP(int, sound3ForcedOutput),
{ NULL, 0 }
};
#endif

// New state format
static variable_desc gba_state[] = {

0 comments on commit 51a4f74

Please sign in to comment.
You can’t perform that action at this time.