Merge pull request #73 from retro-wertz/libretro_cleanup

Libretro cleanup and MBC3 RTC update
This commit is contained in:
hizzlekizzle 2019-08-10 08:33:02 -05:00 committed by GitHub
commit 36f3a739ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 405 additions and 360 deletions

View File

@ -195,6 +195,7 @@ int gbSynchronizeTicks = GBSYNCHRONIZE_CLOCK_TICKS;
// emulator features // emulator features
int gbBattery = 0; int gbBattery = 0;
int gbRumble = 0; int gbRumble = 0;
int gbRTCPresent = 0;
bool gbBatteryError = false; bool gbBatteryError = false;
int gbCaptureNumber = 0; int gbCaptureNumber = 0;
bool gbCapture = false; bool gbCapture = false;
@ -4360,8 +4361,6 @@ bool gbUpdateSizes()
memset(gbRam, gbRamFill, gbRamSize); memset(gbRam, gbRamFill, gbRamSize);
} }
gbBattery = gbRumble = 0;
switch (gbRomType) { switch (gbRomType) {
case 0x03: case 0x03:
case 0x06: case 0x06:
@ -4377,6 +4376,9 @@ bool gbUpdateSizes()
case 0xff: case 0xff:
gbBattery = 1; gbBattery = 1;
break; break;
default:
gbBattery = 0;
break;
} }
switch (gbRomType) { switch (gbRomType) {
@ -4384,6 +4386,21 @@ bool gbUpdateSizes()
case 0x1d: case 0x1d:
case 0x1e: case 0x1e:
gbRumble = 1; 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(); gbInit();

View File

@ -62,6 +62,7 @@ bool allowColorizerHack(void);
extern int gbHardware; extern int gbHardware;
extern int gbRomType; // gets type from header 0x147 extern int gbRomType; // gets type from header 0x147
extern int gbBattery; // enabled when gbRamSize != 0 extern int gbBattery; // enabled when gbRamSize != 0
extern int gbRTCPresent; // gbROM has RTC support
extern struct EmulatedSystem GBSystem; extern struct EmulatedSystem GBSystem;

View File

@ -389,7 +389,7 @@ void mapperMBC3ROM(uint16_t address, uint8_t value)
gbDataMBC3.mapperRAMBank = value; gbDataMBC3.mapperRAMBank = value;
gbDataMBC3.mapperRAMAddress = tmpAddress; gbDataMBC3.mapperRAMAddress = tmpAddress;
} else { } else {
if (gbDataMBC3.mapperRAMEnable) { if (gbRTCPresent && gbDataMBC3.mapperRAMEnable) {
gbDataMBC3.mapperRAMBank = -1; gbDataMBC3.mapperRAMBank = -1;
gbDataMBC3.mapperClockRegister = value; gbDataMBC3.mapperClockRegister = value;
@ -397,6 +397,7 @@ void mapperMBC3ROM(uint16_t address, uint8_t value)
} }
break; break;
case 0x6000: // clock latch case 0x6000: // clock latch
if (gbRTCPresent) {
if (gbDataMBC3.mapperClockLatch == 0 && value == 1) { if (gbDataMBC3.mapperClockLatch == 0 && value == 1) {
memoryUpdateMBC3Clock(); memoryUpdateMBC3Clock();
gbDataMBC3.mapperLSeconds = gbDataMBC3.mapperSeconds; gbDataMBC3.mapperLSeconds = gbDataMBC3.mapperSeconds;
@ -407,6 +408,7 @@ void mapperMBC3ROM(uint16_t address, uint8_t value)
} }
if (value == 0x00 || value == 0x01) if (value == 0x00 || value == 0x01)
gbDataMBC3.mapperClockLatch = value; gbDataMBC3.mapperClockLatch = value;
}
break; break;
} }
} }
@ -415,12 +417,12 @@ void mapperMBC3ROM(uint16_t address, uint8_t value)
void mapperMBC3RAM(uint16_t address, uint8_t value) void mapperMBC3RAM(uint16_t address, uint8_t value)
{ {
if (gbDataMBC3.mapperRAMEnable) { if (gbDataMBC3.mapperRAMEnable) {
if (gbDataMBC3.mapperRAMBank != -1) { if (gbDataMBC3.mapperRAMBank >= 0) {
if (gbRamSize) { if (gbRamSize) {
gbMemoryMap[address >> 12][address & 0x0fff] = value; gbMemoryMap[address >> 12][address & 0x0fff] = value;
systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED; systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
} }
} else { } else if (gbRTCPresent) {
time(&gbDataMBC3.mapperLastTime); time(&gbDataMBC3.mapperLastTime);
switch (gbDataMBC3.mapperClockRegister) { switch (gbDataMBC3.mapperClockRegister) {
case 0x08: case 0x08:
@ -450,10 +452,9 @@ void mapperMBC3RAM(uint16_t address, uint8_t value)
uint8_t mapperMBC3ReadRAM(uint16_t address) uint8_t mapperMBC3ReadRAM(uint16_t address)
{ {
if (gbDataMBC3.mapperRAMEnable) { if (gbDataMBC3.mapperRAMEnable) {
if (gbDataMBC3.mapperRAMBank != -1) { if (gbDataMBC3.mapperRAMBank >= 0) {
return gbMemoryMap[address >> 12][address & 0x0fff]; return gbMemoryMap[address >> 12][address & 0x0fff];
} } else if (gbRTCPresent) {
switch (gbDataMBC3.mapperClockRegister) { switch (gbDataMBC3.mapperClockRegister) {
case 0x08: case 0x08:
return gbDataMBC3.mapperLSeconds; return gbDataMBC3.mapperLSeconds;
@ -471,6 +472,7 @@ uint8_t mapperMBC3ReadRAM(uint16_t address)
return gbDataMBC3.mapperLControl; return gbDataMBC3.mapperLControl;
} }
} }
}
if (!genericflashcardEnable) if (!genericflashcardEnable)
return 0xff; return 0xff;

View File

@ -33,31 +33,37 @@
#include "../gb/gbSGB.h" #include "../gb/gbSGB.h"
#include "../gb/gbSound.h" #include "../gb/gbSound.h"
#define FRAMERATE (16777216.0 / 280896.0) // 59.73
#define SAMPLERATE 32768.0
static retro_log_printf_t log_cb; static retro_log_printf_t log_cb;
static retro_video_refresh_t video_cb; static retro_video_refresh_t video_cb;
static retro_input_poll_t poll_cb; static retro_input_poll_t poll_cb;
static retro_input_state_t input_cb; static retro_input_state_t input_cb;
static retro_environment_t environ_cb; static retro_environment_t environ_cb;
retro_audio_sample_batch_t audio_batch_cb;
static retro_set_rumble_state_t rumble_cb; static retro_set_rumble_state_t rumble_cb;
retro_audio_sample_batch_t audio_batch_cb;
static char retro_system_directory[2048]; static char retro_system_directory[2048];
static char biosfile[4096]; static char biosfile[4096];
static float sndFiltering = 0.5f;
static bool sndInterpolation = true;
static bool can_dupe = false; static bool can_dupe = false;
static bool usebios = false;
// core options
static bool option_sndInterpolation = true;
static bool option_useBios = false;
static bool option_colorizerHack = false;
static bool option_forceRTCenable = false;
static bool option_showAdvancedOptions = false;
static double option_sndFiltering = 0.5;
static unsigned option_gbPalette = 0;
static unsigned retropad_device[4] = {0}; static unsigned retropad_device[4] = {0};
static const double FramesPerSecond = (16777216.0 / 280896.0); // 59.73 static unsigned systemWidth = gbaWidth;
static const long SampleRate = 32768; static unsigned systemHeight = gbaHeight;
static unsigned width = gbaWidth;
static unsigned height = gbaHeight;
static EmulatedSystem* core = NULL; static EmulatedSystem* core = NULL;
static IMAGE_TYPE type = IMAGE_UNKNOWN; static IMAGE_TYPE type = IMAGE_UNKNOWN;
static unsigned current_gbPalette = 0;
static bool opt_colorizer_hack = false;
static bool opt_forceRTCenable = false;
// 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 = 0;
@ -203,65 +209,39 @@ static void set_gbPalette(void)
if (gbCgbMode || gbSgbMode) if (gbCgbMode || gbSgbMode)
return; return;
const uint16_t *pal = defaultGBPalettes[current_gbPalette].data; const uint16_t *pal = defaultGBPalettes[option_gbPalette].data;
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
uint16_t val = pal[i]; uint16_t val = pal[i];
gbPalette[i] = val; gbPalette[i] = val;
} }
} }
static void set_gbColorCorrection(int value)
{
gbColorOption = value;
}
static bool gb_hasrtc(void)
{
switch (gbRomType) {
case 0x0f:
case 0x10: // MBC3 + extended
case 0x13:
case 0xfd: // TAMA5 + extended
return true;
}
return false;
}
static void* gb_rtcdata_prt(void) static void* gb_rtcdata_prt(void)
{ {
if (gb_hasrtc()) {
switch (gbRomType) { switch (gbRomType) {
case 0x0f: case 0x0f:
case 0x10: // MBC3 + extended case 0x10: // MBC3 + extended
return &gbDataMBC3.mapperSeconds; return &gbDataMBC3.mapperSeconds;
case 0x13:
case 0xfd: // TAMA5 + extended case 0xfd: // TAMA5 + extended
return &gbDataTAMA5.mapperSeconds; return &gbDataTAMA5.mapperSeconds;
} }
}
return NULL; return NULL;
} }
static size_t gb_rtcdata_size(void) static size_t gb_rtcdata_size(void)
{ {
if (gb_hasrtc()) {
switch (gbRomType) { switch (gbRomType) {
case 0x0f: case 0x0f:
case 0x10: // MBC3 + extended case 0x10: // MBC3 + extended
return MBC3_RTC_DATA_SIZE; return MBC3_RTC_DATA_SIZE;
break;
case 0x13:
case 0xfd: // TAMA5 + extended case 0xfd: // TAMA5 + extended
return TAMA5_RTC_DATA_SIZE; return TAMA5_RTC_DATA_SIZE;
break;
}
} }
return 0; return 0;
} }
static void gbUpdateRTC(void) static void gbInitRTC(void)
{ {
if (gb_hasrtc()) {
struct tm* lt; struct tm* lt;
time_t rawtime; time_t rawtime;
time(&rawtime); time(&rawtime);
@ -269,17 +249,17 @@ static void gbUpdateRTC(void)
switch (gbRomType) { switch (gbRomType) {
case 0x0f: case 0x0f:
case 0x10: { case 0x10:
gbDataMBC3.mapperSeconds = lt->tm_sec; gbDataMBC3.mapperSeconds = lt->tm_sec;
gbDataMBC3.mapperMinutes = lt->tm_min; gbDataMBC3.mapperMinutes = lt->tm_min;
gbDataMBC3.mapperHours = lt->tm_hour; gbDataMBC3.mapperHours = lt->tm_hour;
gbDataMBC3.mapperDays = lt->tm_yday & 255; gbDataMBC3.mapperDays = lt->tm_yday & 255;
gbDataMBC3.mapperControl = (gbDataMBC3.mapperControl & 0xfe) | (lt->tm_yday > 255 ? 1 : 0); gbDataMBC3.mapperControl = (gbDataMBC3.mapperControl & 0xfe) | (lt->tm_yday > 255 ? 1 : 0);
gbDataMBC3.mapperLastTime = rawtime; gbDataMBC3.mapperLastTime = rawtime;
}
break; break;
case 0xfd: { case 0xfd: {
uint8_t gbDaysinMonth[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; uint8_t gbDaysinMonth[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int days = lt->tm_yday + 365 * 3;
gbDataTAMA5.mapperSeconds = lt->tm_sec; gbDataTAMA5.mapperSeconds = lt->tm_sec;
gbDataTAMA5.mapperMinutes = lt->tm_min; gbDataTAMA5.mapperMinutes = lt->tm_min;
gbDataTAMA5.mapperHours = lt->tm_hour; gbDataTAMA5.mapperHours = lt->tm_hour;
@ -287,7 +267,6 @@ static void gbUpdateRTC(void)
gbDataTAMA5.mapperMonths = 1; gbDataTAMA5.mapperMonths = 1;
gbDataTAMA5.mapperYears = 1970; gbDataTAMA5.mapperYears = 1970;
gbDataTAMA5.mapperLastTime = rawtime; gbDataTAMA5.mapperLastTime = rawtime;
int days = lt->tm_yday + 365 * 3;
while (days) { while (days) {
gbDataTAMA5.mapperDays++; gbDataTAMA5.mapperDays++;
days--; days--;
@ -308,75 +287,124 @@ static void gbUpdateRTC(void)
} }
break; break;
} }
}
static void SetGBBorder(unsigned val)
{
struct retro_system_av_info avinfo;
unsigned _changed = 0;
switch (val) {
case 0:
_changed = ((systemWidth != gbWidth) || (systemHeight != gbHeight)) ? 1 : 0;
systemWidth = gbBorderLineSkip = gbWidth;
systemHeight = gbHeight;
gbBorderColumnSkip = gbBorderRowSkip = 0;
break;
case 1:
_changed = ((systemWidth != sgbWidth) || (systemHeight != sgbHeight)) ? 1 : 0;
systemWidth = gbBorderLineSkip = sgbWidth;
systemHeight = sgbHeight;
gbBorderColumnSkip = (sgbWidth - gbWidth) >> 1;
gbBorderRowSkip = (sgbHeight - gbHeight) >> 1;
break;
} }
retro_get_system_av_info(&avinfo);
if (!_changed)
environ_cb(RETRO_ENVIRONMENT_SET_GEOMETRY, &avinfo);
else
environ_cb(RETRO_ENVIRONMENT_SET_SYSTEM_AV_INFO, &avinfo);
} }
void* retro_get_memory_data(unsigned id) void* retro_get_memory_data(unsigned id)
{ {
if (type == IMAGE_GBA) { void *data = NULL;
switch (type) {
case IMAGE_GBA:
switch (id) { switch (id) {
case RETRO_MEMORY_SAVE_RAM: case RETRO_MEMORY_SAVE_RAM:
if ((saveType == GBA_SAVE_EEPROM) | (saveType == GBA_SAVE_EEPROM_SENSOR)) if ((saveType == GBA_SAVE_EEPROM) | (saveType == GBA_SAVE_EEPROM_SENSOR))
return eepromData; data = eepromData;
if ((saveType == GBA_SAVE_SRAM) | (saveType == GBA_SAVE_FLASH)) else if ((saveType == GBA_SAVE_SRAM) | (saveType == GBA_SAVE_FLASH))
return flashSaveMemory; data = flashSaveMemory;
return NULL; break;
case RETRO_MEMORY_SYSTEM_RAM: case RETRO_MEMORY_SYSTEM_RAM:
return workRAM; data = workRAM;
break;
case RETRO_MEMORY_VIDEO_RAM: case RETRO_MEMORY_VIDEO_RAM:
return vram; data = vram;
} break;
} }
if (type == IMAGE_GB) { case IMAGE_GB:
switch (id) { switch (id) {
case RETRO_MEMORY_SAVE_RAM: case RETRO_MEMORY_SAVE_RAM:
if (gbBattery) if (gbBattery)
return gbRam; data = gbRam;
return NULL; break;
case RETRO_MEMORY_SYSTEM_RAM: case RETRO_MEMORY_SYSTEM_RAM:
return (gbCgbMode ? gbWram : (gbMemory + 0xC000)); data = (gbCgbMode ? gbWram : (gbMemory + 0xC000));
break;
case RETRO_MEMORY_VIDEO_RAM: case RETRO_MEMORY_VIDEO_RAM:
return (gbCgbMode ? gbVram : (gbMemory + 0x8000)); data = (gbCgbMode ? gbVram : (gbMemory + 0x8000));
} break;
case RETRO_MEMORY_RTC:
if (gbBattery && gbRTCPresent)
data = gb_rtcdata_prt();
break;
} }
return NULL; default: break;
}
return data;
} }
size_t retro_get_memory_size(unsigned id) size_t retro_get_memory_size(unsigned id)
{ {
if (type == IMAGE_GBA) { size_t size = 0;
switch (type) {
case IMAGE_GBA:
switch (id) { switch (id) {
case RETRO_MEMORY_SAVE_RAM: case RETRO_MEMORY_SAVE_RAM:
if ((saveType == GBA_SAVE_EEPROM) | (saveType == GBA_SAVE_EEPROM_SENSOR)) if ((saveType == GBA_SAVE_EEPROM) | (saveType == GBA_SAVE_EEPROM_SENSOR))
return eepromSize; size = eepromSize;
if (saveType == GBA_SAVE_FLASH) else if (saveType == GBA_SAVE_FLASH)
return flashSize; size = flashSize;
if (saveType == GBA_SAVE_SRAM) else if (saveType == GBA_SAVE_SRAM)
return SIZE_SRAM; size = SIZE_SRAM;
return 0; break;
case RETRO_MEMORY_SYSTEM_RAM: case RETRO_MEMORY_SYSTEM_RAM:
return SIZE_WRAM; size = SIZE_WRAM;
break;
case RETRO_MEMORY_VIDEO_RAM: case RETRO_MEMORY_VIDEO_RAM:
return SIZE_VRAM - 0x2000; // usuable vram is only 0x18000 size = SIZE_VRAM - 0x2000; // usuable vram is only 0x18000
} break;
} }
if (type == IMAGE_GB) { case IMAGE_GB:
switch (id) { switch (id) {
case RETRO_MEMORY_SAVE_RAM: case RETRO_MEMORY_SAVE_RAM:
if (gbBattery) if (gbBattery)
return gbRamSize; size = gbRamSize;
return 0; break;
case RETRO_MEMORY_SYSTEM_RAM: case RETRO_MEMORY_SYSTEM_RAM:
return gbCgbMode ? 0x8000 : 0x2000; size = gbCgbMode ? 0x8000 : 0x2000;
break;
case RETRO_MEMORY_VIDEO_RAM: case RETRO_MEMORY_VIDEO_RAM:
return gbCgbMode ? 0x4000 : 0x2000; size = gbCgbMode ? 0x4000 : 0x2000;
} break;
case RETRO_MEMORY_RTC:
size = gb_rtcdata_size();
break;
} }
return 0; default: break;
}
return size;
} }
unsigned retro_api_version(void) unsigned retro_api_version(void)
@ -543,17 +571,23 @@ void retro_get_system_info(struct retro_system_info *info)
void retro_get_system_av_info(struct retro_system_av_info *info) void retro_get_system_av_info(struct retro_system_av_info *info)
{ {
float aspect = (3.0f / 2.0f); double aspect = (3.0f / 2.0f);
if (type == IMAGE_GB) unsigned maxWidth = gbaWidth;
aspect = !gbBorderOn ? (10.0 / 9.0) : (8.0 / 7.0); unsigned maxHeight = gbaHeight;
info->geometry.base_width = width; if (type == IMAGE_GB) {
info->geometry.base_height = height; aspect = !gbBorderOn ? (10.0 / 9.0) : (8.0 / 7.0);
info->geometry.max_width = width; maxWidth = sgbWidth;
info->geometry.max_height = height; maxHeight = sgbHeight;
}
info->geometry.base_width = systemWidth;
info->geometry.base_height = systemHeight;
info->geometry.max_width = maxWidth;
info->geometry.max_height = maxHeight;
info->geometry.aspect_ratio = aspect; info->geometry.aspect_ratio = aspect;
info->timing.fps = FramesPerSecond; info->timing.fps = FRAMERATE;
info->timing.sample_rate = (double)SampleRate; info->timing.sample_rate = SAMPLERATE;
} }
void retro_init(void) void retro_init(void)
@ -572,10 +606,18 @@ void retro_init(void)
snprintf(retro_system_directory, sizeof(retro_system_directory), "%s", dir); snprintf(retro_system_directory, sizeof(retro_system_directory), "%s", dir);
#ifdef FRONTEND_SUPPORTS_RGB565 #ifdef FRONTEND_SUPPORTS_RGB565
systemColorDepth = 16;
systemRedShift = 11;
systemGreenShift = 6;
systemBlueShift = 0;
enum retro_pixel_format rgb565 = RETRO_PIXEL_FORMAT_RGB565; enum retro_pixel_format rgb565 = RETRO_PIXEL_FORMAT_RGB565;
if (environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &rgb565) && log_cb) if (environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &rgb565) && log_cb)
log_cb(RETRO_LOG_INFO, "Frontend supports RGB565 - will use that instead of XRGB1555.\n"); log_cb(RETRO_LOG_INFO, "Frontend supports RGB565 - will use that instead of XRGB1555.\n");
#else #else
systemColorDepth = 32;
systemRedShift = 19;
systemGreenShift = 11;
systemBlueShift = 3;
enum retro_pixel_format rgb8888 = RETRO_PIXEL_FORMAT_XRGB8888; enum retro_pixel_format rgb8888 = RETRO_PIXEL_FORMAT_XRGB8888;
if (environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &rgb8888) && log_cb) if (environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &rgb8888) && log_cb)
log_cb(RETRO_LOG_INFO, "Frontend supports XRGB8888 - will use that instead of XRGB1555.\n"); log_cb(RETRO_LOG_INFO, "Frontend supports XRGB8888 - will use that instead of XRGB1555.\n");
@ -588,7 +630,6 @@ void retro_init(void)
rumble_cb = rumble.set_rumble_state; rumble_cb = rumble.set_rumble_state;
} else } else
rumble_cb = NULL; rumble_cb = NULL;
} }
static const char *gbGetCartridgeType(void) static const char *gbGetCartridgeType(void)
@ -802,7 +843,7 @@ static void load_image_preferences(void)
if (flashSize == SIZE_FLASH512 || flashSize == SIZE_FLASH1M) if (flashSize == SIZE_FLASH512 || flashSize == SIZE_FLASH1M)
flashSetSize(flashSize); flashSetSize(flashSize);
if (opt_forceRTCenable) if (option_forceRTCenable)
rtcEnabled = true; rtcEnabled = true;
rtcEnable(rtcEnabled); rtcEnable(rtcEnabled);
@ -825,25 +866,6 @@ static void load_image_preferences(void)
log("mirroringEnable : %s.\n", mirroringEnable ? "Yes" : "No"); log("mirroringEnable : %s.\n", mirroringEnable ? "Yes" : "No");
} }
static void update_colormaps(void)
{
#ifdef FRONTEND_SUPPORTS_RGB565
systemColorDepth = 16;
systemRedShift = 11;
systemGreenShift = 6;
systemBlueShift = 0;
#else
systemColorDepth = 32;
systemRedShift = 19;
systemGreenShift = 11;
systemBlueShift = 3;
#endif
utilUpdateSystemColorMaps(false);
log("Color Depth = %d\n", systemColorDepth);
}
#ifdef _WIN32 #ifdef _WIN32
static const char SLASH = '\\'; static const char SLASH = '\\';
#else #else
@ -855,16 +877,16 @@ static void gba_init(void)
log("Loading VBA-M Core (GBA)...\n"); log("Loading VBA-M Core (GBA)...\n");
load_image_preferences(); load_image_preferences();
soundSetSampleRate(SampleRate); soundSetSampleRate(SAMPLERATE);
if (usebios) { if (option_useBios) {
snprintf(biosfile, sizeof(biosfile), "%s%c%s", retro_system_directory, SLASH, "gba_bios.bin"); snprintf(biosfile, sizeof(biosfile), "%s%c%s", retro_system_directory, SLASH, "gba_bios.bin");
log("Loading bios: %s\n", biosfile); log("Loading bios: %s\n", biosfile);
} }
CPUInit(biosfile, usebios); CPUInit(biosfile, option_useBios);
width = gbaWidth; systemWidth = gbaWidth;
height = gbaHeight; systemHeight = gbaHeight;
CPUReset(); CPUReset();
} }
@ -877,41 +899,37 @@ static void gb_init(void)
gbGetHardwareType(); gbGetHardwareType();
setColorizerHack(opt_colorizer_hack); setColorizerHack(option_colorizerHack);
// Disable bios loading when using Colorizer hack // Disable bios loading when using Colorizer hack
if (opt_colorizer_hack) if (option_colorizerHack)
usebios = false; option_useBios = false;
if (usebios) { if (option_useBios) {
snprintf(biosfile, sizeof(biosfile), "%s%c%s", snprintf(biosfile, sizeof(biosfile), "%s%c%s",
retro_system_directory, SLASH, biosname[gbCgbMode]); retro_system_directory, SLASH, biosname[gbCgbMode]);
log("Loading bios: %s\n", biosfile); log("Loading bios: %s\n", biosfile);
} }
gbCPUInit(biosfile, usebios); gbCPUInit(biosfile, option_useBios);
if (gbBorderOn) { if (gbBorderOn) {
width = gbBorderLineSkip = sgbWidth; systemWidth = gbBorderLineSkip = sgbWidth;
height = sgbHeight; systemHeight = sgbHeight;
gbBorderColumnSkip = (sgbWidth - gbWidth) >> 1; gbBorderColumnSkip = (sgbWidth - gbWidth) >> 1;
gbBorderRowSkip = (sgbHeight - gbHeight) >> 1; gbBorderRowSkip = (sgbHeight - gbHeight) >> 1;
} else { } else {
width = gbBorderLineSkip = gbWidth; systemWidth = gbBorderLineSkip = gbWidth;
height = gbHeight; systemHeight = gbHeight;
gbBorderColumnSkip = gbBorderRowSkip = 0; gbBorderColumnSkip = gbBorderRowSkip = 0;
} }
gbSoundSetSampleRate(SampleRate); gbSoundSetSampleRate(SAMPLERATE);
gbSoundSetDeclicking(1); gbSoundSetDeclicking(1);
gbReset(); // also resets sound; gbReset(); // also resets sound;
set_gbPalette(); set_gbPalette();
// VBA-M always updates time based on current time and not in-game time.
// No need to add RTC data to RETRO_MEMORY_RTC, so its safe to place this here.
gbUpdateRTC();
log("Rom size : %02x (%dK)\n", gbRom[0x148], (romSize + 1023) / 1024); log("Rom size : %02x (%dK)\n", gbRom[0x148], (romSize + 1023) / 1024);
log("Cartridge type : %02x (%s)\n", gbRom[0x147], gbGetCartridgeType()); log("Cartridge type : %02x (%s)\n", gbRom[0x147], gbGetCartridgeType());
log("Ram size : %02x (%s)\n", gbRom[0x149], gbGetSaveRamSize()); log("Ram size : %02x (%s)\n", gbRom[0x149], gbGetSaveRamSize());
@ -942,12 +960,6 @@ static void gb_init(void)
log("Game supports SGB functions\n"); log("Game supports SGB functions\n");
} }
static void gba_soundchanged(void)
{
soundInterpolation = sndInterpolation;
soundFiltering = sndFiltering;
}
void retro_deinit(void) void retro_deinit(void)
{ {
emulating = 0; emulating = 0;
@ -964,8 +976,8 @@ void retro_reset(void)
#define MAX_PLAYERS 4 #define MAX_PLAYERS 4
#define MAX_BUTTONS 10 #define MAX_BUTTONS 10
#define TURBO_BUTTONS 2 #define TURBO_BUTTONS 2
static bool turbo_enable = false; static bool option_turboEnable = false;
static unsigned turbo_delay = 3; static unsigned option_turboDelay = 3;
static unsigned turbo_delay_counter[MAX_PLAYERS][TURBO_BUTTONS] = {{0}, {0}}; static unsigned turbo_delay_counter[MAX_PLAYERS][TURBO_BUTTONS] = {{0}, {0}};
static const unsigned binds[MAX_BUTTONS] = { static const unsigned binds[MAX_BUTTONS] = {
RETRO_DEVICE_ID_JOYPAD_A, RETRO_DEVICE_ID_JOYPAD_A,
@ -985,23 +997,22 @@ static const unsigned turbo_binds[TURBO_BUTTONS] = {
RETRO_DEVICE_ID_JOYPAD_Y RETRO_DEVICE_ID_JOYPAD_Y
}; };
static void systemGbBorderOff(void);
static void systemUpdateSolarSensor(int level); static void systemUpdateSolarSensor(int level);
static uint8_t sensorDarkness = 0xE8; static uint8_t sensorDarkness = 0xE8;
static uint8_t sensorDarknessLevel = 0; // so we can adjust sensor from gamepad static uint8_t sensorDarknessLevel = 0; // so we can adjust sensor from gamepad
static int astick_deadzone; static int option_analogDeadzone;
static int gyro_sensitivity, tilt_sensitivity; static int option_gyroSensitivity, option_tiltSensitivity;
static bool swap_astick; static bool option_swapAnalogSticks;
static void update_variables(bool startup) static void update_variables(bool startup)
{ {
struct retro_variable var = {0};
char key[256] = {0};
int disabled_layers = 0;
int sound_enabled = 0x30F;
bool sound_changed = false; bool sound_changed = false;
char key[256];
struct retro_variable var;
var.key = key; var.key = key;
int disabled_layers=0;
strcpy(key, "vbam_layer_x"); strcpy(key, "vbam_layer_x");
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
key[strlen("vbam_layer_")] = '1' + i; key[strlen("vbam_layer_")] = '1' + i;
@ -1014,7 +1025,6 @@ static void update_variables(bool startup)
layerEnable = DISPCNT & layerSettings; layerEnable = DISPCNT & layerSettings;
CPUUpdateRenderBuffers(false); CPUUpdateRenderBuffers(false);
int sound_enabled = 0x30F;
strcpy(key, "vbam_sound_x"); strcpy(key, "vbam_sound_x");
for (unsigned i = 0; i < 6; i++) { for (unsigned i = 0; i < 6; i++) {
key[strlen("vbam_sound_")] = '1' + i; key[strlen("vbam_sound_")] = '1' + i;
@ -1032,9 +1042,9 @@ static void update_variables(bool startup)
var.value = NULL; var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
bool newval = (strcmp(var.value, "enabled") == 0); bool newval = (!strcmp(var.value, "enabled"));
if (sndInterpolation != newval) { if (option_sndInterpolation != newval) {
sndInterpolation = newval; option_sndInterpolation = newval;
sound_changed = true; sound_changed = true;
} }
} }
@ -1043,32 +1053,30 @@ static void update_variables(bool startup)
var.value = NULL; var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
float newval = atof(var.value) * 0.1f; double newval = atof(var.value) * 0.1f;
if (sndFiltering != newval) { if (option_sndFiltering != newval) {
sndFiltering = newval; option_sndFiltering = newval;
sound_changed = true; sound_changed = true;
} }
} }
if (sound_changed) { if (sound_changed) {
//Update interpolation and filtering values soundInterpolation = option_sndInterpolation;
gba_soundchanged(); soundFiltering = option_sndFiltering;
} }
var.key = "vbam_usebios"; var.key = "vbam_usebios";
var.value = NULL; var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
bool newval = (strcmp(var.value, "enabled") == 0); option_useBios = (!strcmp(var.value, "enabled")) ? true : false;
usebios = newval;
} }
var.key = "vbam_forceRTCenable"; var.key = "vbam_forceRTCenable";
var.value = NULL; var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
bool newval = (strcmp(var.value, "enabled") == 0) ? true : false; option_forceRTCenable = (!strcmp(var.value, "enabled")) ? true : false;
opt_forceRTCenable = newval;
} }
var.key = "vbam_solarsensor"; var.key = "vbam_solarsensor";
@ -1083,29 +1091,19 @@ static void update_variables(bool startup)
var.value = NULL; var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
int oldval = (gbBorderOn << 1) | gbBorderAutomatic;
if (strcmp(var.value, "auto") == 0) { if (strcmp(var.value, "auto") == 0) {
gbBorderOn = 0;
gbBorderAutomatic = 1; gbBorderAutomatic = 1;
} }
else if (strcmp(var.value, "enabled") == 0) { else if (!strcmp(var.value, "enabled")) {
gbBorderAutomatic = 0; gbBorderAutomatic = 0;
gbBorderOn = 1; gbBorderOn = 1;
} } else { // disabled
else { // disabled
gbBorderOn = 0; gbBorderOn = 0;
gbBorderAutomatic = 0; gbBorderAutomatic = 0;
} }
if ((type == IMAGE_GB) && if ((type == IMAGE_GB) && !startup)
(oldval != ((gbBorderOn << 1) | gbBorderAutomatic)) && !startup) { SetGBBorder(gbBorderOn);
if (gbBorderOn) {
systemGbBorderOn();
gbSgbRenderBorder();
}
else
systemGbBorderOff();
}
} }
var.key = "vbam_gbHardware"; var.key = "vbam_gbHardware";
@ -1130,96 +1128,116 @@ static void update_variables(bool startup)
var.value = NULL; var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
if (strcmp(var.value, "enabled") == 0) option_colorizerHack = (!strcmp(var.value, "enabled")) ? true : false;
opt_colorizer_hack = true;
else
opt_colorizer_hack = false;
} }
var.key = "vbam_turboenable"; var.key = "vbam_turboenable";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
{ option_turboEnable = (!strcmp(var.value, "enabled")) ? true : false;
bool val = !strcmp(var.value, "enabled");
turbo_enable = val;
} }
var.key = "vbam_turbodelay"; var.key = "vbam_turbodelay";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
{ option_turboDelay = atoi(var.value);
turbo_delay = atoi(var.value);
} }
var.key = "vbam_astick_deadzone"; var.key = "vbam_astick_deadzone";
var.value = NULL; var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
{ option_analogDeadzone = (int)(atof(var.value) * 0.01 * 0x8000);
astick_deadzone = (int)(atoi(var.value) * 0.01f * 0x8000);
} }
var.key = "vbam_tilt_sensitivity"; var.key = "vbam_tilt_sensitivity";
var.value = NULL; var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
{ option_tiltSensitivity = atoi(var.value);
tilt_sensitivity = atoi(var.value);
} }
var.key = "vbam_gyro_sensitivity"; var.key = "vbam_gyro_sensitivity";
var.value = NULL; var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
{ option_gyroSensitivity = atoi(var.value);
gyro_sensitivity = atoi(var.value);
} }
var.key = "vbam_swap_astick"; var.key = "vbam_swap_astick";
var.value = NULL; var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
{ option_swapAnalogSticks = (!strcmp(var.value, "enabled")) ? true : false;
swap_astick = (bool)(!strcmp(var.value, "enabled"));
} }
var.key = "vbam_palettes"; var.key = "vbam_palettes";
var.value = NULL; var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
{ unsigned lastpal = option_gbPalette;
unsigned lastpal = current_gbPalette;
if (!strcmp(var.value, "black and white")) if (!strcmp(var.value, "black and white"))
current_gbPalette = 0; option_gbPalette = 0;
else if (!strcmp(var.value, "blue sea")) else if (!strcmp(var.value, "blue sea"))
current_gbPalette = 1; option_gbPalette = 1;
else if (!strcmp(var.value, "dark knight")) else if (!strcmp(var.value, "dark knight"))
current_gbPalette = 2; option_gbPalette = 2;
else if (!strcmp(var.value, "green forest")) else if (!strcmp(var.value, "green forest"))
current_gbPalette = 3; option_gbPalette = 3;
else if (!strcmp(var.value, "hot desert")) else if (!strcmp(var.value, "hot desert"))
current_gbPalette = 4; option_gbPalette = 4;
else if (!strcmp(var.value, "pink dreams")) else if (!strcmp(var.value, "pink dreams"))
current_gbPalette = 5; option_gbPalette = 5;
else if (!strcmp(var.value, "wierd colors")) else if (!strcmp(var.value, "wierd colors"))
current_gbPalette = 6; option_gbPalette = 6;
else if (!strcmp(var.value, "original gameboy")) else if (!strcmp(var.value, "original gameboy"))
current_gbPalette = 7; option_gbPalette = 7;
else if (!strcmp(var.value, "gba sp")) else if (!strcmp(var.value, "gba sp"))
current_gbPalette = 8; option_gbPalette = 8;
if (lastpal != current_gbPalette) if (lastpal != option_gbPalette)
set_gbPalette(); set_gbPalette();
} }
var.key = "vbam_gbcoloroption"; var.key = "vbam_gbcoloroption";
var.value = NULL; var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
{ gbColorOption = (!strcmp(var.value, "enabled")) ? 1 : 0;
int val = (!strcmp(var.value, "enabled")) ? 1 : 0; }
set_gbColorCorrection(val);
var.key = "vbam_show_advanced_options";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
bool newval = (!strcmp(var.value, "enabled")) ? true : false;
if ((option_showAdvancedOptions != newval) || startup) {
option_showAdvancedOptions = newval;
struct retro_core_option_display option_display;
unsigned i;
char options[][13] = {
"vbam_sound_1",
"vbam_sound_2",
"vbam_sound_3",
"vbam_sound_4",
"vbam_sound_5",
"vbam_sound_6",
"vbam_layer_1",
"vbam_layer_2",
"vbam_layer_3",
"vbam_layer_4",
"vbam_layer_5",
"vbam_layer_6",
"vbam_layer_7",
"vbam_layer_8"
};
option_display.visible = option_showAdvancedOptions;
for (i = 0; i < (sizeof(options) / sizeof(options[0])); i++) {
option_display.key = options[i];
environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);
}
}
} }
// Hide some core options depending on rom image type // Hide some core options depending on rom image type
@ -1233,10 +1251,8 @@ static void update_variables(bool startup)
"vbam_showborders", "vbam_showborders",
"vbam_gbcoloroption" "vbam_gbcoloroption"
}; };
char gba_options[5][22] = { char gba_options[3][22] = {
"vbam_solarsensor", "vbam_solarsensor",
"vbam_sound_5",
"vbam_sound_6",
"vbam_gyro_sensitivity", "vbam_gyro_sensitivity",
"vbam_forceRTCenable" "vbam_forceRTCenable"
}; };
@ -1251,7 +1267,7 @@ static void update_variables(bool startup)
// Show or hide GBA only options // Show or hide GBA only options
option_display.visible = (type == IMAGE_GBA) ? 1 : 0; option_display.visible = (type == IMAGE_GBA) ? 1 : 0;
for (i = 0; i < 5; i++) for (i = 0; i < 3; i++)
{ {
option_display.key = gba_options[i]; option_display.key = gba_options[i];
environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display); environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);
@ -1271,9 +1287,9 @@ static void updateInput_MotionSensors(void)
int16_t analog[3], astick_data[3]; int16_t analog[3], astick_data[3];
double scaled_range, radius, angle; double scaled_range, radius, angle;
unsigned tilt_retro_device_index = unsigned tilt_retro_device_index =
swap_astick ? RETRO_DEVICE_INDEX_ANALOG_LEFT : RETRO_DEVICE_INDEX_ANALOG_RIGHT; option_swapAnalogSticks ? RETRO_DEVICE_INDEX_ANALOG_LEFT : RETRO_DEVICE_INDEX_ANALOG_RIGHT;
unsigned gyro_retro_device_index = unsigned gyro_retro_device_index =
swap_astick ? RETRO_DEVICE_INDEX_ANALOG_RIGHT : RETRO_DEVICE_INDEX_ANALOG_LEFT; option_swapAnalogSticks ? RETRO_DEVICE_INDEX_ANALOG_RIGHT : RETRO_DEVICE_INDEX_ANALOG_LEFT;
// Tilt sensor section // Tilt sensor section
analog[0] = input_cb(0, RETRO_DEVICE_ANALOG, analog[0] = input_cb(0, RETRO_DEVICE_ANALOG,
@ -1285,12 +1301,12 @@ static void updateInput_MotionSensors(void)
radius = sqrt(analog[0] * analog[0] + analog[1] * analog[1]); radius = sqrt(analog[0] * analog[0] + analog[1] * analog[1]);
angle = atan2(analog[1], analog[0]); angle = atan2(analog[1], analog[0]);
if (radius > astick_deadzone) { if (radius > option_analogDeadzone) {
// Re-scale analog stick range to negate deadzone (makes slow movements possible) // Re-scale analog stick range to negate deadzone (makes slow movements possible)
radius = (radius - astick_deadzone) * radius = (radius - option_analogDeadzone) *
((float)ASTICK_MAX/(ASTICK_MAX - astick_deadzone)); ((float)ASTICK_MAX/(ASTICK_MAX - option_analogDeadzone));
// Tilt sensor range is from from 1897 to 2197 // Tilt sensor range is from from 1897 to 2197
radius *= 150.0 / ASTICK_MAX * (tilt_sensitivity / 100.0); radius *= 150.0 / ASTICK_MAX * (option_tiltSensitivity / 100.0);
// Convert back to cartesian coordinates // Convert back to cartesian coordinates
astick_data[0] = +(int16_t)ROUND(radius * cos(angle)); astick_data[0] = +(int16_t)ROUND(radius * cos(angle));
astick_data[1] = -(int16_t)ROUND(radius * sin(angle)); astick_data[1] = -(int16_t)ROUND(radius * sin(angle));
@ -1304,17 +1320,17 @@ static void updateInput_MotionSensors(void)
analog[2] = input_cb(0, RETRO_DEVICE_ANALOG, analog[2] = input_cb(0, RETRO_DEVICE_ANALOG,
gyro_retro_device_index, RETRO_DEVICE_ID_ANALOG_X); gyro_retro_device_index, RETRO_DEVICE_ID_ANALOG_X);
if ( analog[2] < -astick_deadzone ) { if ( analog[2] < -option_analogDeadzone ) {
// Re-scale analog stick range // Re-scale analog stick range
scaled_range = (-analog[2] - astick_deadzone) * scaled_range = (-analog[2] - option_analogDeadzone) *
((float)ASTICK_MAX / (ASTICK_MAX - astick_deadzone)); ((float)ASTICK_MAX / (ASTICK_MAX - option_analogDeadzone));
// Gyro sensor range is +/- 1800 // Gyro sensor range is +/- 1800
scaled_range *= 1800.0 / ASTICK_MAX * (gyro_sensitivity / 100.0); scaled_range *= 1800.0 / ASTICK_MAX * (option_gyroSensitivity / 100.0);
astick_data[2] = -(int16_t)ROUND(scaled_range); astick_data[2] = -(int16_t)ROUND(scaled_range);
} else if ( analog[2] > astick_deadzone ) { } else if ( analog[2] > option_analogDeadzone ) {
scaled_range = (analog[2] - astick_deadzone) * scaled_range = (analog[2] - option_analogDeadzone) *
((float)ASTICK_MAX / (ASTICK_MAX - astick_deadzone)); ((float)ASTICK_MAX / (ASTICK_MAX - option_analogDeadzone));
scaled_range *= (1800.0 / ASTICK_MAX * (gyro_sensitivity / 100.0)); scaled_range *= (1800.0 / ASTICK_MAX * (option_gyroSensitivity / 100.0));
astick_data[2] = +(int16_t)ROUND(scaled_range); astick_data[2] = +(int16_t)ROUND(scaled_range);
} else } else
astick_data[2] = 0; astick_data[2] = 0;
@ -1346,12 +1362,37 @@ void updateInput_SolarSensor(void)
} }
} }
static bool firstrun = true;
static unsigned has_frame; static unsigned has_frame;
void retro_run(void) void retro_run(void)
{ {
bool updated = false; bool updated = false;
if (firstrun) {
bool initRTC = false;
firstrun = false;
/* Check if GB game has RTC data. Has to be check here since this is where the data will be
* available when using libretro api. */
if ((type == IMAGE_GB) && gbRTCPresent) {
switch (gbRomType) {
case 0x0f:
case 0x10:
/* Check if any RTC has been loaded, zero value means nothing has been loaded. */
if (!gbDataMBC3.mapperSeconds && !gbDataMBC3.mapperLSeconds && !gbDataMBC3.mapperLastTime)
initRTC = true;
break;
case 0xfd:
if (!gbDataTAMA5.mapperSeconds && !gbDataTAMA5.mapperLSeconds && !gbDataTAMA5.mapperLastTime)
initRTC = true;
break;
}
/* Initialize RTC using local time if needed */
if (initRTC)
gbInitRTC();
}
}
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated) if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated)
update_variables(false); update_variables(false);
@ -1362,9 +1403,8 @@ void retro_run(void)
has_frame = 0; has_frame = 0;
do { while (!has_frame)
core->emuMain(core->emuCount); core->emuMain(core->emuCount);
} while (!has_frame);
} }
static unsigned serialize_size = 0; static unsigned serialize_size = 0;
@ -1496,7 +1536,7 @@ bool retro_load_game(const struct retro_game_info *game)
} }
update_variables(true); update_variables(true);
update_colormaps(); utilUpdateSystemColorMaps(false);
soundInit(); soundInit();
if (type == IMAGE_GBA) { if (type == IMAGE_GBA) {
@ -1639,6 +1679,8 @@ unsigned retro_get_region(void)
return RETRO_REGION_NTSC; return RETRO_REGION_NTSC;
} }
// system callbacks
void systemOnWriteDataToSoundBuffer(const uint16_t*, int) void systemOnWriteDataToSoundBuffer(const uint16_t*, int)
{ {
} }
@ -1654,8 +1696,8 @@ bool systemCanChangeSoundQuality(void)
void systemDrawScreen(void) void systemDrawScreen(void)
{ {
unsigned pitch = width * (systemColorDepth >> 3); unsigned pitch = systemWidth * (systemColorDepth >> 3);
video_cb(pix, width, height, pitch); video_cb(pix, systemWidth, systemHeight, pitch);
} }
void systemFrame(void) void systemFrame(void)
@ -1665,35 +1707,7 @@ void systemFrame(void)
void systemGbBorderOn(void) void systemGbBorderOn(void)
{ {
bool changed = ((width != sgbWidth) || (height != sgbHeight)); SetGBBorder(1);
width = gbBorderLineSkip = sgbWidth;
height = sgbHeight;
gbBorderColumnSkip = (sgbWidth - gbWidth) >> 1;
gbBorderRowSkip = (sgbHeight - gbHeight) >> 1;
struct retro_system_av_info avinfo;
retro_get_system_av_info(&avinfo);
if (!changed)
environ_cb(RETRO_ENVIRONMENT_SET_GEOMETRY, &avinfo);
else
environ_cb(RETRO_ENVIRONMENT_SET_SYSTEM_AV_INFO, &avinfo);
}
static void systemGbBorderOff(void)
{
bool changed = ((width != gbWidth) || (height != gbHeight));
width = gbBorderLineSkip = gbWidth;
height = gbHeight;
gbBorderColumnSkip = gbBorderRowSkip = 0;
struct retro_system_av_info avinfo;
retro_get_system_av_info(&avinfo);
if (!changed)
environ_cb(RETRO_ENVIRONMENT_SET_GEOMETRY, &avinfo);
else
environ_cb(RETRO_ENVIRONMENT_SET_SYSTEM_AV_INFO, &avinfo);
} }
void systemMessage(const char* fmt, ...) void systemMessage(const char* fmt, ...)
@ -1730,14 +1744,14 @@ uint32_t systemReadJoypad(int which)
for (i = 0; i < buttons; i++) for (i = 0; i < buttons; i++)
J |= input_cb(which, RETRO_DEVICE_JOYPAD, 0, binds[i]) << i; J |= input_cb(which, RETRO_DEVICE_JOYPAD, 0, binds[i]) << i;
if (turbo_enable) { if (option_turboEnable) {
/* Handle Turbo A & B buttons */ /* Handle Turbo A & B buttons */
for (i = 0; i < TURBO_BUTTONS; i++) { for (i = 0; i < TURBO_BUTTONS; i++) {
if (input_cb(which, RETRO_DEVICE_JOYPAD, 0, turbo_binds[i])) { if (input_cb(which, RETRO_DEVICE_JOYPAD, 0, turbo_binds[i])) {
if (!turbo_delay_counter[which][i]) if (!turbo_delay_counter[which][i])
J |= 1 << i; J |= 1 << i;
turbo_delay_counter[which][i]++; turbo_delay_counter[which][i]++;
if (turbo_delay_counter[which][i] > turbo_delay) if (turbo_delay_counter[which][i] > option_turboDelay)
/* Reset the toggle if delay value is reached */ /* Reset the toggle if delay value is reached */
turbo_delay_counter[which][i] = 0; turbo_delay_counter[which][i] = 0;
} else } else

View File

@ -29,7 +29,7 @@ extern "C" {
struct retro_core_option_definition option_defs_us[] = { struct retro_core_option_definition option_defs_us[] = {
{ {
"vbam_solarsensor", "vbam_solarsensor",
"Solar sensor level", "Solar Sensor Level",
"Adjusts simulated solar level in Boktai games. L2/R2 buttons can also be used to quickly change levels.", "Adjusts simulated solar level in Boktai games. L2/R2 buttons can also be used to quickly change levels.",
{ {
{ "0", NULL }, { "0", NULL },
@ -49,7 +49,7 @@ struct retro_core_option_definition option_defs_us[] = {
}, },
{ {
"vbam_usebios", "vbam_usebios",
"Use BIOS file if available (Restart)", "Use Official BIOS (If Available)",
"Use official BIOS when available. Core needs to be restarted for changes to apply.", "Use official BIOS when available. Core needs to be restarted for changes to apply.",
{ {
{ "disabled", NULL }, { "disabled", NULL },
@ -60,7 +60,7 @@ struct retro_core_option_definition option_defs_us[] = {
}, },
{ {
"vbam_forceRTCenable", "vbam_forceRTCenable",
"Force enable RTC", "Force-Enable RTC",
"Forces the internal real-time clock to be enabled regardless of rom. Usuable for rom patches that requires clock to be enabled (aka Pokemon).", "Forces the internal real-time clock to be enabled regardless of rom. Usuable for rom patches that requires clock to be enabled (aka Pokemon).",
{ {
{ "disabled", NULL }, { "disabled", NULL },
@ -103,7 +103,7 @@ struct retro_core_option_definition option_defs_us[] = {
{ {
"vbam_palettes", "vbam_palettes",
"(GB) Color Palette", "(GB) Color Palette",
"Set Game Boy palettes.", "Set Game Boy palettes to use.",
{ {
{ "black and white", NULL }, { "black and white", NULL },
{ "blue sea", NULL }, { "blue sea", NULL },
@ -120,7 +120,7 @@ struct retro_core_option_definition option_defs_us[] = {
}, },
{ {
"vbam_gbHardware", "vbam_gbHardware",
"(GB) Emulated Hardware", "(GB) Emulated Hardware (Needs Restart)",
"Sets the Game Boy hardware type to emulate. Restart core to apply.", "Sets the Game Boy hardware type to emulate. Restart core to apply.",
{ {
{ "gbc", "Game Boy Color" }, { "gbc", "Game Boy Color" },
@ -293,9 +293,20 @@ struct retro_core_option_definition option_defs_us[] = {
}, },
"disabled" "disabled"
}, },
{
"vbam_show_advanced_options",
"Show Advanced Options",
"Show advanced options which can enable or disable sound channels and graphics layers.",
{
{ "disabled", NULL },
{ "enabled", NULL },
{ NULL, NULL },
},
"disabled"
},
{ {
"vbam_sound_1", "vbam_sound_1",
"Sound channel 1", "Sound Channel 1",
"Enables or disables tone & sweep sound channel.", "Enables or disables tone & sweep sound channel.",
{ {
{ "disabled", NULL }, { "disabled", NULL },
@ -304,9 +315,9 @@ struct retro_core_option_definition option_defs_us[] = {
}, },
"enabled" "enabled"
}, },
{ {
"vbam_sound_2", "vbam_sound_2",
"Sound channel 2", "Sound Channel 2",
"Enables or disables tone sound channel.", "Enables or disables tone sound channel.",
{ {
{ "disabled", NULL }, { "disabled", NULL },
@ -317,7 +328,7 @@ struct retro_core_option_definition option_defs_us[] = {
}, },
{ {
"vbam_sound_3", "vbam_sound_3",
"Sound channel 3", "Sound Channel 3",
"Enables or disables wave output sound channel.", "Enables or disables wave output sound channel.",
{ {
{ "disabled", NULL }, { "disabled", NULL },
@ -328,7 +339,7 @@ struct retro_core_option_definition option_defs_us[] = {
}, },
{ {
"vbam_sound_4", "vbam_sound_4",
"Sound channel 4", "Sound Channel 4",
"Enables or disables noise audio channel.", "Enables or disables noise audio channel.",
{ {
{ "disabled", NULL }, { "disabled", NULL },
@ -339,7 +350,7 @@ struct retro_core_option_definition option_defs_us[] = {
}, },
{ {
"vbam_sound_5", "vbam_sound_5",
"Sound DMA channel A", "Sound DMA Channel A",
"Enables or disables DMA sound channel A.", "Enables or disables DMA sound channel A.",
{ {
{ "disabled", NULL }, { "disabled", NULL },
@ -350,7 +361,7 @@ struct retro_core_option_definition option_defs_us[] = {
}, },
{ {
"vbam_sound_6", "vbam_sound_6",
"Sound DMA channel B", "Sound DMA Channel B",
"Enables or disables DMA sound channel B.", "Enables or disables DMA sound channel B.",
{ {
{ "disabled", NULL }, { "disabled", NULL },
@ -361,7 +372,7 @@ struct retro_core_option_definition option_defs_us[] = {
}, },
{ {
"vbam_layer_1", "vbam_layer_1",
"Show background layer 1", "Show Background Layer 1",
"Shows or hides background layer 1.", "Shows or hides background layer 1.",
{ {
{ "disabled", NULL }, { "disabled", NULL },
@ -372,7 +383,7 @@ struct retro_core_option_definition option_defs_us[] = {
}, },
{ {
"vbam_layer_2", "vbam_layer_2",
"Show background layer 2", "Show Background Layer 2",
"Shows or hides background layer 2.", "Shows or hides background layer 2.",
{ {
{ "disabled", NULL }, { "disabled", NULL },
@ -383,7 +394,7 @@ struct retro_core_option_definition option_defs_us[] = {
}, },
{ {
"vbam_layer_3", "vbam_layer_3",
"Show background layer 3", "Show Background Layer 3",
"Shows or hides background layer 3.", "Shows or hides background layer 3.",
{ {
{ "disabled", NULL }, { "disabled", NULL },
@ -394,7 +405,7 @@ struct retro_core_option_definition option_defs_us[] = {
}, },
{ {
"vbam_layer_4", "vbam_layer_4",
"Show background layer 4", "Show Background Layer 4",
"Shows or hides background layer 4.", "Shows or hides background layer 4.",
{ {
{ "disabled", NULL }, { "disabled", NULL },
@ -405,7 +416,7 @@ struct retro_core_option_definition option_defs_us[] = {
}, },
{ {
"vbam_layer_5", "vbam_layer_5",
"Show sprite layer", "Show Sprite Layer",
"Shows or hides sprite layer.", "Shows or hides sprite layer.",
{ {
{ "disabled", NULL }, { "disabled", NULL },
@ -416,7 +427,7 @@ struct retro_core_option_definition option_defs_us[] = {
}, },
{ {
"vbam_layer_6", "vbam_layer_6",
"Show window layer 1", "Show Window Layer 1",
"Shows or hides window layer 1.", "Shows or hides window layer 1.",
{ {
{ "disabled", NULL }, { "disabled", NULL },
@ -427,7 +438,7 @@ struct retro_core_option_definition option_defs_us[] = {
}, },
{ {
"vbam_layer_7", "vbam_layer_7",
"Show window layer 2", "Show Window Layer 2",
"Shows or hides window layer 2.", "Shows or hides window layer 2.",
{ {
{ "disabled", NULL }, { "disabled", NULL },
@ -438,7 +449,7 @@ struct retro_core_option_definition option_defs_us[] = {
}, },
{ {
"vbam_layer_8", "vbam_layer_8",
"Show sprite window layer", "Show Sprite Window Layer",
"Shows or hides sprite window layer.", "Shows or hides sprite window layer.",
{ {
{ "disabled", NULL }, { "disabled", NULL },