Merge remote-tracking branch 'libretro/master'

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
Rafael Kitover 2020-08-14 11:00:06 +00:00
commit 08b5685049
No known key found for this signature in database
GPG Key ID: 08AB596679D86240
9 changed files with 169 additions and 77 deletions

1
.gitignore vendored
View File

@ -14,6 +14,7 @@ vcpkg/*
*.so *.so
*.dll *.dll
*.exe *.exe
.vscode
# vim swap files # vim swap files
*.sw? *.sw?

View File

@ -2581,8 +2581,7 @@ static INSN_REGPARM void armA00(uint32_t opcode)
armNextPC = reg[15].I; armNextPC = reg[15].I;
reg[15].I += 4; reg[15].I += 4;
ARM_PREFETCH; ARM_PREFETCH;
clockTicks = codeTicksAccessSeq32(armNextPC) + 1; clockTicks = (codeTicksAccessSeq32(armNextPC) * 2) + codeTicksAccess32(armNextPC) + 3;
clockTicks = (clockTicks * 2) + codeTicksAccess32(armNextPC) + 1;
busPrefetchCount = 0; busPrefetchCount = 0;
} }
@ -2595,8 +2594,7 @@ static INSN_REGPARM void armB00(uint32_t opcode)
armNextPC = reg[15].I; armNextPC = reg[15].I;
reg[15].I += 4; reg[15].I += 4;
ARM_PREFETCH; ARM_PREFETCH;
clockTicks = codeTicksAccessSeq32(armNextPC) + 1; clockTicks = (codeTicksAccessSeq32(armNextPC) * 2) + codeTicksAccess32(armNextPC) + 3;
clockTicks = (clockTicks * 2) + codeTicksAccess32(armNextPC) + 1;
busPrefetchCount = 0; busPrefetchCount = 0;
} }
@ -2612,8 +2610,7 @@ static INSN_REGPARM void armE01(uint32_t opcode)
// SWI <comment> // SWI <comment>
static INSN_REGPARM void armF00(uint32_t opcode) static INSN_REGPARM void armF00(uint32_t opcode)
{ {
clockTicks = codeTicksAccessSeq32(armNextPC) + 1; clockTicks = (codeTicksAccessSeq32(armNextPC) * 2) + codeTicksAccess32(armNextPC) + 3;
clockTicks = (clockTicks * 2) + codeTicksAccess32(armNextPC) + 1;
busPrefetchCount = 0; busPrefetchCount = 0;
CPUSoftwareInterrupt(opcode & 0x00FFFFFF); CPUSoftwareInterrupt(opcode & 0x00FFFFFF);
} }

View File

@ -1146,9 +1146,9 @@ static INSN_REGPARM void thumb43_1(uint32_t opcode)
reg[dest].I = reg[(opcode >> 3) & 7].I * rm; reg[dest].I = reg[(opcode >> 3) & 7].I * rm;
if (((int32_t)rm) < 0) if (((int32_t)rm) < 0)
rm = ~rm; rm = ~rm;
if ((rm & 0xFFFFFF00) == 0) if ((rm & 0xFFFFFF00) == 0) {
clockTicks += 0; // clockTicks += 0;
else if ((rm & 0xFFFF0000) == 0) } else if ((rm & 0xFFFF0000) == 0)
clockTicks += 1; clockTicks += 1;
else if ((rm & 0xFF000000) == 0) else if ((rm & 0xFF000000) == 0)
clockTicks += 2; clockTicks += 2;
@ -1625,7 +1625,7 @@ static INSN_REGPARM void thumbBD(uint32_t opcode)
reg[13].I = temp; reg[13].I = temp;
THUMB_PREFETCH; THUMB_PREFETCH;
busPrefetchCount = 0; busPrefetchCount = 0;
clockTicks += 3 + codeTicksAccess16(armNextPC) + codeTicksAccess16(armNextPC); clockTicks += 3 + (codeTicksAccess16(armNextPC) * 2);
} }
// Load/store multiple //////////////////////////////////////////////////// // Load/store multiple ////////////////////////////////////////////////////
@ -1703,7 +1703,7 @@ static INSN_REGPARM void thumbC8(uint32_t opcode)
#define THUMB_CONDITIONAL_BRANCH(COND) \ #define THUMB_CONDITIONAL_BRANCH(COND) \
UPDATE_OLDREG; \ UPDATE_OLDREG; \
clockTicks = codeTicksAccessSeq16(armNextPC) + 1; \ clockTicks = codeTicksAccessSeq16(armNextPC) + 1; \
if (COND) { \ if ((bool)COND) { \
uint32_t offset = (uint32_t)((int8_t)(opcode & 0xFF)) << 1; \ uint32_t offset = (uint32_t)((int8_t)(opcode & 0xFF)) << 1; \
reg[15].I += offset; \ reg[15].I += offset; \
armNextPC = reg[15].I; \ armNextPC = reg[15].I; \

View File

@ -103,16 +103,17 @@ static inline uint32_t CPUReadMemory(uint32_t address)
case 5: case 5:
value = READ32LE(((uint32_t*)&paletteRAM[address & 0x3fC])); value = READ32LE(((uint32_t*)&paletteRAM[address & 0x3fC]));
break; break;
case 6: case 6: {
address = (address & 0x1fffc); unsigned addr = (address & 0x1fffc);
if (((DISPCNT & 7) > 2) && ((address & 0x1C000) == 0x18000)) { if (((DISPCNT & 7) > 2) && ((addr & 0x1C000) == 0x18000)) {
value = 0; value = 0;
break; break;
} }
if ((address & 0x18000) == 0x18000) if ((addr & 0x18000) == 0x18000)
address &= 0x17fff; addr &= 0x17fff;
value = READ32LE(((uint32_t*)&vram[address])); value = READ32LE(((uint32_t*)&vram[addr]));
break; break;
}
case 7: case 7:
value = READ32LE(((uint32_t*)&oam[address & 0x3FC])); value = READ32LE(((uint32_t*)&oam[address & 0x3FC]));
break; break;
@ -253,16 +254,17 @@ static inline uint32_t CPUReadHalfWord(uint32_t address)
case 5: case 5:
value = READ16LE(((uint16_t*)&paletteRAM[address & 0x3fe])); value = READ16LE(((uint16_t*)&paletteRAM[address & 0x3fe]));
break; break;
case 6: case 6: {
address = (address & 0x1fffe); unsigned addr = (address & 0x1fffe);
if (((DISPCNT & 7) > 2) && ((address & 0x1C000) == 0x18000)) { if (((DISPCNT & 7) > 2) && ((addr & 0x1C000) == 0x18000)) {
value = 0; value = 0;
break; break;
} }
if ((address & 0x18000) == 0x18000) if ((addr & 0x18000) == 0x18000)
address &= 0x17fff; addr &= 0x17fff;
value = READ16LE(((uint16_t*)&vram[address])); value = READ16LE(((uint16_t*)&vram[addr]));
break; break;
}
case 7: case 7:
value = READ16LE(((uint16_t*)&oam[address & 0x3fe])); value = READ16LE(((uint16_t*)&oam[address & 0x3fe]));
break; break;
@ -293,11 +295,10 @@ static inline uint32_t CPUReadHalfWord(uint32_t address)
if (cpuDmaHack) { if (cpuDmaHack) {
value = cpuDmaLast & 0xFFFF; value = cpuDmaLast & 0xFFFF;
} else { } else {
if (armState) { int param = reg[15].I;
value = CPUReadHalfWordQuick(reg[15].I + (address & 2)); if (armState)
} else { param += (address & 2);
value = CPUReadHalfWordQuick(reg[15].I); value = CPUReadHalfWordQuick(param);
}
} }
#ifdef GBA_LOGGING #ifdef GBA_LOGGING
if (systemVerbose & VERBOSE_ILLEGAL_READ) { if (systemVerbose & VERBOSE_ILLEGAL_READ) {

View File

@ -42,6 +42,11 @@ int16_t sineTable[256] = {
(int16_t)0xF384, (int16_t)0xF50F, (int16_t)0xF69C, (int16_t)0xF82B, (int16_t)0xF9BB, (int16_t)0xFB4B, (int16_t)0xFCDD, (int16_t)0xFE6E (int16_t)0xF384, (int16_t)0xF50F, (int16_t)0xF69C, (int16_t)0xF82B, (int16_t)0xF9BB, (int16_t)0xFB4B, (int16_t)0xFCDD, (int16_t)0xFE6E
}; };
// 2020-08-12 - negativeExponent
// Fix ArcTan and ArcTan2 based on mgba's hle bios fixes
// https://github.com/mgba-emu/mgba/commit/14dc01409c9e971ea0697f5017b45d0db6a7faf5#diff-8f06a143a9fd912c83209f935d3aca25
// https://github.com/mgba-emu/mgba/commit/b154457857d3367a4c0196a4abadeeb6c850ffdf#diff-8f06a143a9fd912c83209f935d3aca25
void BIOS_ArcTan() void BIOS_ArcTan()
{ {
#ifdef GBA_LOGGING #ifdef GBA_LOGGING
@ -53,7 +58,7 @@ void BIOS_ArcTan()
#endif #endif
int32_t i = reg[0].I; int32_t i = reg[0].I;
int32_t a = -((i*i) >> 14); int32_t a = -((i * i) >> 14);
int32_t b = ((0xA9 * a) >> 14) + 0x390; int32_t b = ((0xA9 * a) >> 14) + 0x390;
b = ((b * a) >> 14) + 0x91C; b = ((b * a) >> 14) + 0x91C;
b = ((b * a) >> 14) + 0xFB6; b = ((b * a) >> 14) + 0xFB6;
@ -111,6 +116,7 @@ void BIOS_ArcTan2()
} }
} }
reg[0].I = res; reg[0].I = res;
reg[3].I = 0x170;
#ifdef GBA_LOGGING #ifdef GBA_LOGGING
if (systemVerbose & VERBOSE_SWI) { if (systemVerbose & VERBOSE_SWI) {

View File

@ -59,3 +59,8 @@ SOURCES_CXX += \
$(CORE_DIR)/gb/gbMemory.cpp \ $(CORE_DIR)/gb/gbMemory.cpp \
$(CORE_DIR)/gb/gbSGB.cpp \ $(CORE_DIR)/gb/gbSGB.cpp \
$(CORE_DIR)/gb/gbSound.cpp $(CORE_DIR)/gb/gbSound.cpp
# Filters
SOURCES_CXX += \
$(CORE_DIR)/filters/interframe.cpp \
$(CORE_DIR)/gba/gbafilter.cpp

View File

@ -232,18 +232,26 @@ void utilUpdateSystemColorMaps(bool lcd)
{ {
int i = 0; int i = 0;
(void)lcd;
switch (systemColorDepth) { switch (systemColorDepth) {
case 16: case 16:
for (i = 0; i < 0x10000; i++) for (i = 0; i < 0x10000; i++) {
systemColorMap16[i] = ((i & 0x1f) << systemRedShift) | (((i & 0x3e0) >> 5) << systemGreenShift) | (((i & 0x7c00) >> 10) << systemBlueShift); systemColorMap16[i] = ((i & 0x1f) << systemRedShift) |
break; (((i & 0x3e0) >> 5) << systemGreenShift) |
case 24: (((i & 0x7c00) >> 10) << systemBlueShift);
case 32: }
for (i = 0; i < 0x10000; i++) if (lcd)
systemColorMap32[i] = ((i & 0x1f) << systemRedShift) | (((i & 0x3e0) >> 5) << systemGreenShift) | (((i & 0x7c00) >> 10) << systemBlueShift); gbafilter_pal(systemColorMap16, 0x10000);
break; break;
case 24:
case 32:
for (i = 0; i < 0x10000; i++) {
systemColorMap32[i] = ((i & 0x1f) << systemRedShift) |
(((i & 0x3e0) >> 5) << systemGreenShift) |
(((i & 0x7c00) >> 10) << systemBlueShift);
}
if (lcd)
gbafilter_pal32(systemColorMap32, 0x10000);
break;
} }
} }

View File

@ -33,6 +33,8 @@
#include "../gb/gbSGB.h" #include "../gb/gbSGB.h"
#include "../gb/gbSound.h" #include "../gb/gbSound.h"
#include "../filters/interframe.hpp"
#define FRAMERATE (16777216.0 / 280896.0) // 59.73 #define FRAMERATE (16777216.0 / 280896.0) // 59.73
#define SAMPLERATE 32768.0 #define SAMPLERATE 32768.0
@ -56,6 +58,9 @@ static bool option_forceRTCenable = false;
static bool option_showAdvancedOptions = false; static bool option_showAdvancedOptions = false;
static double option_sndFiltering = 0.5; static double option_sndFiltering = 0.5;
static unsigned option_gbPalette = 0; static unsigned option_gbPalette = 0;
static bool option_lcdfilter = false;
// filters
static IFBFilterFunc ifb_filter_func = NULL;
static unsigned retropad_device[4] = {0}; static unsigned retropad_device[4] = {0};
static unsigned systemWidth = gbaWidth; static unsigned systemWidth = gbaWidth;
@ -66,7 +71,7 @@ static IMAGE_TYPE type = IMAGE_UNKNOWN;
// global vars // global vars
uint16_t systemColorMap16[0x10000]; uint16_t systemColorMap16[0x10000];
uint32_t systemColorMap32[0x10000]; uint32_t systemColorMap32[0x10000];
int RGB_LOW_BITS_MASK = 0; int RGB_LOW_BITS_MASK = 0x821; // used for 16bit inter-frame filters
int systemRedShift = 0; int systemRedShift = 0;
int systemBlueShift = 0; int systemBlueShift = 0;
int systemGreenShift = 0; int systemGreenShift = 0;
@ -189,7 +194,7 @@ static struct palettes_t defaultGBPalettes[] = {
}, },
{ {
"Weird Colors", "Weird Colors",
{ 0x621F, 0x401F, 0x001F, 0x2010, 0x621F, 0x401F, 0x001F, 0x2010 } { 0x621F, 0x401F, 0x001F, 0x2010, 0x621F, 0x401F, 0x001F, 0x2010 },
}, },
{ {
"Real GB Colors", "Real GB Colors",
@ -630,9 +635,9 @@ void retro_init(void)
bool yes = true; bool yes = true;
environ_cb(RETRO_ENVIRONMENT_SET_SUPPORT_ACHIEVEMENTS, &yes); environ_cb(RETRO_ENVIRONMENT_SET_SUPPORT_ACHIEVEMENTS, &yes);
if (environ_cb(RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE, &rumble)) { if (environ_cb(RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE, &rumble))
rumble_cb = rumble.set_rumble_state; rumble_cb = rumble.set_rumble_state;
} else else
rumble_cb = NULL; rumble_cb = NULL;
} }
@ -1211,6 +1216,40 @@ static void update_variables(bool startup)
gbColorOption = (!strcmp(var.value, "enabled")) ? 1 : 0; gbColorOption = (!strcmp(var.value, "enabled")) ? 1 : 0;
} }
var.key = "vbam_lcdfilter";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
bool prev_lcdfilter = option_lcdfilter;
option_lcdfilter = (!strcmp(var.value, "enabled")) ? true : false;
if (prev_lcdfilter != option_lcdfilter)
utilUpdateSystemColorMaps(option_lcdfilter);
}
var.key = "vbam_interframeblending";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
if (!strcmp(var.value, "smart"))
{
if (systemColorDepth == 16)
ifb_filter_func = SmartIB;
else
ifb_filter_func = SmartIB32;
}
else if (!strcmp(var.value, "motion blur"))
{
if (systemColorDepth == 16)
ifb_filter_func = MotionBlurIB;
else
ifb_filter_func = MotionBlurIB32;
}
else
ifb_filter_func = NULL;
}
else
ifb_filter_func = NULL;
var.key = "vbam_show_advanced_options"; var.key = "vbam_show_advanced_options";
var.value = NULL; var.value = NULL;
@ -1285,6 +1324,7 @@ static void update_variables(bool startup)
#define ROUND(x) floor((x) + 0.5) #define ROUND(x) floor((x) + 0.5)
#define ASTICK_MAX 0x8000 #define ASTICK_MAX 0x8000
static int analog_x, analog_y, analog_z; static int analog_x, analog_y, analog_z;
static uint32_t input_buf[MAX_PLAYERS] = { 0 };
static void updateInput_MotionSensors(void) static void updateInput_MotionSensors(void)
{ {
@ -1366,6 +1406,45 @@ void updateInput_SolarSensor(void)
} }
} }
// Update joypads
static void updateInput_Joypad(void)
{
unsigned max_buttons = MAX_BUTTONS - ((type == IMAGE_GB) ? 2 : 0); // gb only has 8 buttons
for (unsigned port = 0; port < MAX_PLAYERS; port++)
{
// Reset input states
input_buf[port] = 0;
if (retropad_device[port] == RETRO_DEVICE_JOYPAD) {
for (unsigned button = 0; button < max_buttons; button++)
input_buf[port] |= input_cb(port, RETRO_DEVICE_JOYPAD, 0, binds[button]) << button;
if (option_turboEnable) {
/* Handle Turbo A & B buttons */
for (unsigned tbutton = 0; tbutton < TURBO_BUTTONS; tbutton++) {
if (input_cb(port, RETRO_DEVICE_JOYPAD, 0, turbo_binds[tbutton])) {
if (!turbo_delay_counter[port][tbutton])
input_buf[port] |= 1 << tbutton;
turbo_delay_counter[port][tbutton]++;
if (turbo_delay_counter[port][tbutton] > option_turboDelay)
/* Reset the toggle if delay value is reached */
turbo_delay_counter[port][tbutton] = 0;
}
else
/* If the button is not pressed, just reset the toggle */
turbo_delay_counter[port][tbutton] = 0;
}
}
// Do not allow opposing directions
if ((input_buf[port] & 0x30) == 0x30)
input_buf[port] &= ~(0x30);
else if ((input_buf[port] & 0xC0) == 0xC0)
input_buf[port] &= ~(0xC0);
}
}
}
static bool firstrun = true; static bool firstrun = true;
static unsigned has_frame; static unsigned has_frame;
@ -1402,6 +1481,7 @@ void retro_run(void)
poll_cb(); poll_cb();
updateInput_Joypad();
updateInput_SolarSensor(); updateInput_SolarSensor();
updateInput_MotionSensors(); updateInput_MotionSensors();
@ -1539,8 +1619,8 @@ bool retro_load_game(const struct retro_game_info *game)
return false; return false;
} }
utilUpdateSystemColorMaps(option_lcdfilter);
update_variables(true); update_variables(true);
utilUpdateSystemColorMaps(false);
soundInit(); soundInit();
if (type == IMAGE_GBA) { if (type == IMAGE_GBA) {
@ -1701,6 +1781,8 @@ bool systemCanChangeSoundQuality(void)
void systemDrawScreen(void) void systemDrawScreen(void)
{ {
unsigned pitch = systemWidth * (systemColorDepth >> 3); unsigned pitch = systemWidth * (systemColorDepth >> 3);
if (ifb_filter_func)
ifb_filter_func(pix, pitch, systemWidth, systemHeight);
video_cb(pix, systemWidth, systemHeight, pitch); video_cb(pix, systemWidth, systemHeight, pitch);
} }
@ -1742,40 +1824,9 @@ void systemMessage(int, const char* fmt, ...)
uint32_t systemReadJoypad(int which) uint32_t systemReadJoypad(int which)
{ {
uint32_t J = 0;
unsigned i, buttons = MAX_BUTTONS - ((type == IMAGE_GB) ? 2 : 0); // gb only has 8 buttons
if (which == -1) if (which == -1)
which = 0; which = 0;
return input_buf[which];
if (retropad_device[which] == RETRO_DEVICE_JOYPAD) {
for (i = 0; i < buttons; i++)
J |= input_cb(which, RETRO_DEVICE_JOYPAD, 0, binds[i]) << i;
if (option_turboEnable) {
/* Handle Turbo A & B buttons */
for (i = 0; i < TURBO_BUTTONS; i++) {
if (input_cb(which, RETRO_DEVICE_JOYPAD, 0, turbo_binds[i])) {
if (!turbo_delay_counter[which][i])
J |= 1 << i;
turbo_delay_counter[which][i]++;
if (turbo_delay_counter[which][i] > option_turboDelay)
/* Reset the toggle if delay value is reached */
turbo_delay_counter[which][i] = 0;
} else
/* If the button is not pressed, just reset the toggle */
turbo_delay_counter[which][i] = 0;
}
}
}
// Do not allow opposing directions
if ((J & 0x30) == 0x30)
J &= ~(0x30);
else if ((J & 0xC0) == 0xC0)
J &= ~(0xC0);
return J;
} }
static void systemUpdateSolarSensor(int v) static void systemUpdateSolarSensor(int v)

View File

@ -189,6 +189,29 @@ struct retro_core_option_definition option_defs_us[] = {
}, },
"disabled" "disabled"
}, },
{
"vbam_lcdfilter",
"LCD Color Filter",
"TODO:",
{
{ "disabled", NULL },
{ "enabled", NULL },
{ NULL, NULL },
},
"disabled"
},
{
"vbam_interframeblending",
"Interframe Blending",
"TODO:",
{
{ "disabled", NULL },
{ "smart", NULL },
{ "motion blur", NULL },
{ NULL, NULL },
},
"disabled"
},
{ {
"vbam_turboenable", "vbam_turboenable",
"Enable Turbo Buttons", "Enable Turbo Buttons",