Skip to content
Permalink
Browse files

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

  • Loading branch information
rkitover committed Jul 19, 2019
2 parents 2e97b27 + bdd4386 commit 352eb149aed30209e96bd5db4206cf55bf0f737d
@@ -200,6 +200,7 @@ int gbCaptureNumber = 0;
bool gbCapture = false;
bool gbCapturePrevious = false;
int gbJoymask[4] = { 0, 0, 0, 0 };
static bool allow_colorizer_hack;

uint8_t gbRamFill = 0xff;

@@ -776,6 +777,51 @@ static const uint16_t gbColorizationPaletteData[32][3][4] = {
#define GBSAVE_GAME_VERSION_12 12
#define GBSAVE_GAME_VERSION GBSAVE_GAME_VERSION_12

void setColorizerHack(bool value)
{
allow_colorizer_hack = value;
}

bool allowColorizerHack(void)
{
if (gbHardware & 0xA)
return (allow_colorizer_hack);
return false;
}

static inline bool gbVramReadAccessValid(void)
{
// A lot of 'ugly' checks... But only way to emulate this particular behaviour...
if (allowColorizerHack()||
((gbHardware & 0xa) && ((gbLcdModeDelayed != 3) || (((register_LY == 0) && (gbScreenOn == false) && (register_LCDC & 0x80)) && (gbLcdLYIncrementTicksDelayed == (GBLY_INCREMENT_CLOCK_TICKS - GBLCD_MODE_2_CLOCK_TICKS))))) ||
((gbHardware & 0x5) && (gbLcdModeDelayed != 3) && ((gbLcdMode != 3) || ((register_LY == 0) && ((gbScreenOn == false) && (register_LCDC & 0x80)) && (gbLcdLYIncrementTicks == (GBLY_INCREMENT_CLOCK_TICKS - GBLCD_MODE_2_CLOCK_TICKS))))))
return true;
return false;
}

static inline bool gbVramWriteAccessValid(void)
{
if (allowColorizerHack() ||
// No access to Vram during mode 3
// (used to emulate the gfx differences between GB & GBC-GBA/SP in Stunt Racer)
(gbLcdModeDelayed != 3) ||
// This part is used to emulate a small difference between hardwares
// (check 8-in-1's arrow on GBA/GBC to verify it)
((register_LY == 0) && ((gbHardware & 0xa) && (gbScreenOn == false) && (register_LCDC & 0x80)) && (gbLcdLYIncrementTicksDelayed == (GBLY_INCREMENT_CLOCK_TICKS - GBLCD_MODE_2_CLOCK_TICKS))))
return true;
return false;
}

static inline bool gbCgbPaletteAccessValid(void)
{
// No access to gbPalette during mode 3 (Color Panel Demo)
if (allowColorizerHack() ||
((gbLcdModeDelayed != 3) && (!((gbLcdMode == 0) && (gbLcdTicks >= (GBLCD_MODE_0_CLOCK_TICKS - gbSpritesTicks[299] - 1)))) && (!gbSpeed)) ||
(gbSpeed && ((gbLcdMode == 1) || (gbLcdMode == 2) || ((gbLcdMode == 3) && (gbLcdTicks > (GBLCD_MODE_3_CLOCK_TICKS - 2))) || ((gbLcdMode == 0) && (gbLcdTicks <= (GBLCD_MODE_0_CLOCK_TICKS - gbSpritesTicks[299] - 2))))))
return true;
return false;
}

int inline gbGetValue(int min, int max, int v)
{
return (int)(min + (float)(max - min) * (2.0 * (v / 31.0) - (v / 31.0) * (v / 31.0)));
@@ -919,12 +965,8 @@ void gbWriteMemory(uint16_t address, uint8_t value)
}

if (address < 0xa000) {
// No access to Vram during mode 3
// (used to emulate the gfx differences between GB & GBC-GBA/SP in Stunt Racer)
if ((gbLcdModeDelayed != 3) ||
// This part is used to emulate a small difference between hardwares
// (check 8-in-1's arrow on GBA/GBC to verify it)
((register_LY == 0) && ((gbHardware & 0xa) && (gbScreenOn == false) && (register_LCDC & 0x80)) && (gbLcdLYIncrementTicksDelayed == (GBLY_INCREMENT_CLOCK_TICKS - GBLCD_MODE_2_CLOCK_TICKS))))

if (gbVramWriteAccessValid())
gbMemoryMap[address >> 12][address & 0x0fff] = value;
return;
}
@@ -1270,6 +1312,7 @@ void gbWriteMemory(uint16_t address, uint8_t value)
//register_STAT = (register_STAT & 0x87) |
// (value & 0x7c);
gbMemory[0xff41] = register_STAT = (value & 0xf8) | (register_STAT & 0x07); // fix ?
// TODO:
// GB bug from Devrs FAQ
// http://www.devrs.com/gb/files/faqs.html#GBBugs
// 2018-7-26 Backported STAT register bug behavior
@@ -1280,12 +1323,15 @@ void gbWriteMemory(uint16_t address, uint8_t value)
// Games below relies on this bug, , and are incompatible with the GBC.
// - Road Rash: crash after player screen
// - Zerg no Densetsu: crash right after showing a small portion of intro
// - 2019-07-18 - Speedy Gonzalez status bar relies on this as well.

if ((gbHardware & 5)
&& (((!gbInt48Signal) && (gbLcdMode < 2) && (register_LCDC & 0x80))
|| (register_LY == register_LYC))) {

gbMemory[0xff0f] = register_IF |=2;
// send LCD interrupt only if no interrupt 48h signal...
if (!gbInt48Signal)
gbMemory[0xff0f] = register_IF |= 2;
}

gbInt48Signal &= ((register_STAT >> 3) & 0xF);
@@ -1307,7 +1353,7 @@ void gbWriteMemory(uint16_t address, uint8_t value)
if (!gbInt48Signal) {
gbMemory[0xff0f] = register_IF |= 2;
}
gbInt48Signal |= 4;
//gbInt48Signal |= 4;
}
gbCompareLYToLYC();

@@ -1617,8 +1663,7 @@ void gbWriteMemory(uint16_t address, uint8_t value)
int paletteIndex = (v & 0x3f) >> 1;
int paletteHiLo = (v & 0x01);

// No access to gbPalette during mode 3 (Color Panel Demo)
if (((gbLcdModeDelayed != 3) && (!((gbLcdMode == 0) && (gbLcdTicks >= (GBLCD_MODE_0_CLOCK_TICKS - gbSpritesTicks[299] - 1)))) && (!gbSpeed)) || (gbSpeed && ((gbLcdMode == 1) || (gbLcdMode == 2) || ((gbLcdMode == 3) && (gbLcdTicks > (GBLCD_MODE_3_CLOCK_TICKS - 2))) || ((gbLcdMode == 0) && (gbLcdTicks <= (GBLCD_MODE_0_CLOCK_TICKS - gbSpritesTicks[299] - 2)))))) {
if (gbCgbPaletteAccessValid()) {
gbMemory[0xff69] = value;
gbPalette[paletteIndex] = (paletteHiLo ? ((value << 8) | (gbPalette[paletteIndex] & 0xff)) : ((gbPalette[paletteIndex] & 0xff00) | (value))) & 0x7fff;
}
@@ -1658,8 +1703,7 @@ void gbWriteMemory(uint16_t address, uint8_t value)

paletteIndex += 32;

// No access to gbPalette during mode 3 (Color Panel Demo)
if (((gbLcdModeDelayed != 3) && (!((gbLcdMode == 0) && (gbLcdTicks >= (GBLCD_MODE_0_CLOCK_TICKS - gbSpritesTicks[299] - 1)))) && (!gbSpeed)) || (gbSpeed && ((gbLcdMode == 1) || (gbLcdMode == 2) || ((gbLcdMode == 3) && (gbLcdTicks > (GBLCD_MODE_3_CLOCK_TICKS - 2))) || ((gbLcdMode == 0) && (gbLcdTicks <= (GBLCD_MODE_0_CLOCK_TICKS - gbSpritesTicks[299] - 2)))))) {
if (gbCgbPaletteAccessValid()) {
gbMemory[0xff6b] = value;
gbPalette[paletteIndex] = (paletteHiLo ? ((value << 8) | (gbPalette[paletteIndex] & 0xff)) : ((gbPalette[paletteIndex] & 0xff00) | (value))) & 0x7fff;
}
@@ -1729,13 +1773,8 @@ uint8_t gbReadMemory(uint16_t address)
return gbMemoryMap[address >> 12][address & 0x0fff];

if (address < 0xa000) {
// A lot of 'ugly' checks... But only way to emulate this particular behaviour...
if (
(
(gbHardware & 0xa) && ((gbLcdModeDelayed != 3) || (((register_LY == 0) && (gbScreenOn == false) && (register_LCDC & 0x80)) && (gbLcdLYIncrementTicksDelayed == (GBLY_INCREMENT_CLOCK_TICKS - GBLCD_MODE_2_CLOCK_TICKS)))))
|| ((gbHardware & 0x5) && (gbLcdModeDelayed != 3) && ((gbLcdMode != 3) || ((register_LY == 0) && ((gbScreenOn == false) && (register_LCDC & 0x80)) && (gbLcdLYIncrementTicks == (GBLY_INCREMENT_CLOCK_TICKS - GBLCD_MODE_2_CLOCK_TICKS))))))
if (gbVramReadAccessValid())
return gbMemoryMap[address >> 12][address & 0x0fff];

return 0xff;
}

@@ -1977,8 +2016,7 @@ uint8_t gbReadMemory(uint16_t address)
case 0x69:
case 0x6b:
if (gbCgbMode) {
// No access to gbPalette during mode 3 (Color Panel Demo)
if (((gbLcdModeDelayed != 3) && (!((gbLcdMode == 0) && (gbLcdTicks >= (GBLCD_MODE_0_CLOCK_TICKS - gbSpritesTicks[299] - 1)))) && (!gbSpeed)) || (gbSpeed && ((gbLcdMode == 1) || (gbLcdMode == 2) || ((gbLcdMode == 3) && (gbLcdTicks > (GBLCD_MODE_3_CLOCK_TICKS - 2))) || ((gbLcdMode == 0) && (gbLcdTicks <= (GBLCD_MODE_0_CLOCK_TICKS - gbSpritesTicks[299] - 2))))))
if (gbCgbPaletteAccessValid())
return (gbMemory[address]);
else
return 0xff;
@@ -3271,6 +3309,7 @@ void gbInit()
{
gbGenFilter();
gbSgbInit();
setColorizerHack(false);

gbMemory = (uint8_t*)malloc(65536);

@@ -5421,7 +5460,6 @@ bool gbLoadRomData(const char* data, unsigned size)
bios = NULL;
}
bios = (uint8_t*)calloc(1, 0x900);

return gbUpdateSizes();
}

@@ -50,6 +50,10 @@ bool gbReadGSASnapshot(const char*);

bool gbLoadRomData(const char* data, unsigned size);

// Allows invalid vram/palette access needed for Colorizer hacked games in GBC/GBA hardware
void setColorizerHack(bool value);
bool allowColorizerHack(void);

extern int gbHardware;

extern struct EmulatedSystem GBSystem;
@@ -308,7 +308,7 @@ mapperMBC3 gbDataMBC3 = {
0, // timer latched hours
0, // timer latched days
0, // timer latched control
0 // last time
{0} // last time
};

void memoryUpdateMBC3Clock()
@@ -1176,7 +1176,7 @@ mapperTAMA5 gbDataTAMA5 = {
0, // timer latched months
0, // timer latched years
0, // timer latched control
(time_t)-1 // last time
{(time_t)-1} // last time
};

void memoryUpdateTAMA5Clock()
@@ -142,8 +142,6 @@ const uint8_t gamepakWaitState[4] = { 4, 3, 2, 8 };
const uint8_t gamepakWaitState0[2] = { 2, 1 };
const uint8_t gamepakWaitState1[2] = { 4, 1 };
const uint8_t gamepakWaitState2[2] = { 8, 1 };
const bool isInRom[16] = { false, false, false, false, false, false, false, false,
true, true, true, true, true, true, false, false };

uint8_t memoryWait[16] = { 0, 0, 2, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 0 };
uint8_t memoryWait32[16] = { 0, 0, 5, 0, 0, 1, 1, 0, 7, 7, 9, 9, 13, 13, 4, 0 };
@@ -1,4 +1,6 @@
INCFLAGS := -I$(CORE_DIR)
LIBRETRO_COMMON := $(CORE_DIR)/libretro/libretro-common/include

INCFLAGS := -I$(CORE_DIR) -I$(LIBRETRO_COMMON)
SOURCES_CXX :=

SOURCES_CXX += \
@@ -49,18 +49,6 @@ extern int systemBlueShift;
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;
@@ -108,21 +96,6 @@ bool utilIsGBAImage(const char* file)

bool utilIsGBImage(const char* file)
{
/*
FILE *fp;
bool ret = false;
char buffer[47];
if (!file || !(fp = fopen (file, "r"))) //TODO more checks here (does file exist, is it a file, a symlink or a blockdevice)
return ret;
fseek (fp, 0, SEEK_END);
if (ftell (fp) >= 0x8000) { //afaik there can be no gb-rom smaller than this
fseek (fp, 0x104, SEEK_SET);
fread (buffer, sizeof (char), 47, fp);
ret = !memcmp (buffer, gb_image_header, 47);
}
fclose (fp);
return ret;
*/
if (strlen(file) > 4) {
const char *p = strrchr(file, '.');

@@ -7,9 +7,20 @@ include $(LIBRETRO_DIR)/Makefile.common

COREFLAGS := -DHAVE_STDINT_H -DLSB_FIRST -D__LIBRETRO__ -DFINAL_VERSION -DC_CORE -DNO_LINK -DFRONTEND_SUPPORTS_RGB565 -DTILED_RENDERING -DNO_DEBUGGER $(INCFLAGS)

GIT_VERSION := " $(shell git rev-parse --short HEAD || echo unknown)"
ifneq ($(GIT_VERSION)," unknown")
COREFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
#GIT_VERSION := " $(shell git rev-parse --short HEAD || echo unknown)"
#ifneq ($(GIT_VERSION)," unknown")
# COREFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
#endif

VBAM_VERSION := $(shell sed -En 's/.*\[([0-9]+[^]]+).*/\1/p; T; q' ../../CHANGELOG.md 2>/dev/null)

COREFLAGS += -DVBAM_VERSION=\"$(VBAM_VERSION)\"

TAG_COMMIT := $(shell git rev-list -n 1 v$(VBAM_VERSION) --abbrev-commit 2>/dev/null)
CURRENT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null)

ifneq ($(CURRENT_COMMIT),$(TAG_COMMIT))
COREFLAGS += -DGIT_COMMIT=\"$(CURRENT_COMMIT)\"
endif

include $(CLEAR_VARS)

0 comments on commit 352eb14

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