Unverified Commit c3e69cf6 authored by kps501's avatar kps501 Committed by GitHub
Browse files

backport ppu fix, libretro cleanup, remove rom headers

Fix Umihara Kawase's brightness fluctuation.
tighter upstream sync
remove rom headers
parent 3773f823
......@@ -482,8 +482,6 @@ static int32 ApplyMulti (s9xcommand_t *, int32, int16);
static void do_polling (int);
static void UpdatePolledMouse (int);
extern int macsrifle_adjust_x, macsrifle_adjust_y;
static string& operator += (string &s, int i)
{
......@@ -527,8 +525,8 @@ static void DoGunLatch (int x, int y)
static void DoMacsRifleLatch (int x, int y)
{
PPU.GunVLatch = (uint16) (y + 42) + (int16) macsrifle_adjust_y;
PPU.GunHLatch = (uint16) (x + 76) + (int16) macsrifle_adjust_x;
PPU.GunVLatch = (uint16) (y + 42);
PPU.GunHLatch = (uint16) (x + 76);
}
static int maptype (int t)
......@@ -688,8 +686,8 @@ void S9xSetController (int port, enum controllers controller, int8 id1, int8 id2
if (id1 < 0 || id1 > 7)
break;
newcontrollers[port] = JOYPAD0 + id1;
curcontrollers[port] = newcontrollers[port];
// libretro: hotplug immediately
curcontrollers[port] = newcontrollers[port] = JOYPAD0 + id1;
return;
case CTL_MOUSE:
......@@ -701,8 +699,8 @@ void S9xSetController (int port, enum controllers controller, int8 id1, int8 id2
break;
}
newcontrollers[port] = MOUSE0 + id1;
curcontrollers[port] = newcontrollers[port];
// libretro: hotplug immediately
curcontrollers[port] = newcontrollers[port] = MOUSE0 + id1;
return;
case CTL_SUPERSCOPE:
......@@ -712,8 +710,8 @@ void S9xSetController (int port, enum controllers controller, int8 id1, int8 id2
break;
}
newcontrollers[port] = SUPERSCOPE;
curcontrollers[port] = newcontrollers[port];
// libretro: hotplug immediately
curcontrollers[port] = newcontrollers[port] = SUPERSCOPE;
return;
case CTL_JUSTIFIER:
......@@ -725,8 +723,8 @@ void S9xSetController (int port, enum controllers controller, int8 id1, int8 id2
break;
}
newcontrollers[port] = ONE_JUSTIFIER + id1;
curcontrollers[port] = newcontrollers[port];
// libretro: hotplug immediately
curcontrollers[port] = newcontrollers[port] = ONE_JUSTIFIER + id1;
return;
case CTL_MACSRIFLE:
......@@ -736,8 +734,8 @@ void S9xSetController (int port, enum controllers controller, int8 id1, int8 id2
break;
}
newcontrollers[port] = MACSRIFLE;
curcontrollers[port] = newcontrollers[port];
// libretro: hotplug immediately
curcontrollers[port] = newcontrollers[port] = MACSRIFLE;
return;
case CTL_MP5:
......@@ -755,9 +753,8 @@ void S9xSetController (int port, enum controllers controller, int8 id1, int8 id2
break;
}
newcontrollers[port] = MP5;
curcontrollers[port] = newcontrollers[port];
// libretro: hotplug immediately
curcontrollers[port] = newcontrollers[port] = MP5;
mp5[port].pads[0] = (id1 < 0) ? NONE : JOYPAD0 + id1;
mp5[port].pads[1] = (id2 < 0) ? NONE : JOYPAD0 + id2;
mp5[port].pads[2] = (id3 < 0) ? NONE : JOYPAD0 + id3;
......@@ -769,8 +766,8 @@ void S9xSetController (int port, enum controllers controller, int8 id1, int8 id2
break;
}
newcontrollers[port] = NONE;
curcontrollers[port] = newcontrollers[port];
// libretro: hotplug immediately
curcontrollers[port] = newcontrollers[port] = NONE;
}
bool S9xVerifyControllers (void)
......@@ -2185,7 +2182,6 @@ void S9xApplyCommand (s9xcommand_t cmd, int16 data1, int16 data2)
{
uint16 r, s, t, st;
s = t = st = 0;
r = cmd.button.joypad.buttons;
st = r & joypad[cmd.button.joypad.idx].togglestick & joypad[cmd.button.joypad.idx].toggleturbo;
r ^= st;
......@@ -2474,7 +2470,7 @@ void S9xApplyCommand (s9xcommand_t cmd, int16 data1, int16 data2)
if (S9xUnfreezeGame(filename))
{
sprintf(buf, "%s.%.*s loaded", def, _MAX_EXT - 1, "oops");
snprintf(buf, 256, "%s.%.*s loaded", def, _MAX_EXT - 1, "oops");
S9xSetInfoString (buf);
}
else
......@@ -2511,7 +2507,7 @@ void S9xApplyCommand (s9xcommand_t cmd, int16 data1, int16 data2)
if (S9xUnfreezeGame(filename))
{
sprintf(buf, "%s.%03d loaded", def, i - QuickLoad000);
snprintf(buf, 256, "%s.%03d loaded", def, i - QuickLoad000);
S9xSetInfoString(buf);
}
else
......@@ -2538,7 +2534,7 @@ void S9xApplyCommand (s9xcommand_t cmd, int16 data1, int16 data2)
_splitpath(Memory.ROMFilename, drive, dir, def, ext);
snprintf(filename, PATH_MAX + 1, "%s%s%s.%03d", S9xGetDirectory(SNAPSHOT_DIR), SLASH_STR, def, i - QuickSave000);
sprintf(buf, "%s.%03d saved", def, i - QuickSave000);
snprintf(buf, 256, "%s.%03d saved", def, i - QuickSave000);
S9xSetInfoString(buf);
S9xFreezeGame(filename);
......@@ -3702,7 +3698,6 @@ void S9xControlPostLoadState (struct SControlSnapshot *s)
COPY(superscope.next_buttons);
COPY(superscope.read_buttons);
for (int j = 0; j < 2; j++)
COPY(justifier.x[j]);
for (int j = 0; j < 2; j++)
......
......@@ -206,7 +206,6 @@
static void S9xResetCPU (void);
static void S9xSoftResetCPU (void);
extern bool randomize_memory;
static void S9xResetCPU (void)
......@@ -288,14 +287,7 @@ void S9xReset (void)
S9xResetSaveTimer(FALSE);
S9xResetLogger();
if(!randomize_memory)
memset(Memory.RAM, 0x55, 0x20000);
else
{
srand(time(NULL));
for(int lcv=0; lcv<0x20000; lcv++)
Memory.RAM[lcv] = rand()%256;
}
memset(Memory.RAM, 0x55, 0x20000);
memset(Memory.VRAM, 0x00, 0x10000);
memset(Memory.FillRAM, 0, 0x8000);
......
......@@ -54,7 +54,7 @@ bool overclock_cycles = false;
bool reduce_sprite_flicker = false;
bool randomize_memory = false;
int one_c, slow_one_c, two_c;
int macsrifle_adjust_x, macsrifle_adjust_y;
int16 macsrifle_adjust_x, macsrifle_adjust_y;
retro_log_printf_t log_cb = NULL;
static retro_video_refresh_t video_cb = NULL;
......@@ -478,7 +478,6 @@ unsigned retro_api_version()
return RETRO_API_VERSION;
}
void retro_reset()
{
S9xSoftReset();
......@@ -738,11 +737,46 @@ static int is_bsx (uint8 *p)
return (0);
}
static bool8 LoadBIOS(uint8 *biosrom, const char *biosname, size_t biossize)
static bool8 is_SufamiTurbo_Cart(const uint8 *data, size_t size)
{
if (size >= 0x80000 && size <= 0x100000 &&
strncmp((const char*)data, "BANDAI SFC-ADX", 14) == 0 && strncmp((const char*)(data + 0x10), "SFC-ADX BACKUP", 14) != 0)
return (TRUE);
return (FALSE);
}
static void Remove_Header(uint8_t *&romptr, size_t &romsize, bool multicart_sufami)
{
if (romptr==0 || romsize==0) return;
uint32 calc_size = (romsize / 0x2000) * 0x2000;
if ((romsize - calc_size == 512 && !Settings.ForceNoHeader) || Settings.ForceHeader)
{
romptr += 512;
romsize -= 512;
if(log_cb) log_cb(RETRO_LOG_INFO,"[libretro]: ROM header removed\n");
}
if (multicart_sufami)
{
if (strncmp((const char*)(romptr+0x100000), "BANDAI SFC-ADX", 14) == 0 &&
strncmp((const char*)(romptr+0x000000), "BANDAI SFC-ADX", 14) == 0)
{
romptr += 0x100000;
romsize -= 0x100000;
if(log_cb) log_cb(RETRO_LOG_INFO,"[libretro]: Sufami Turbo Multi-ROM bios removed\n");
}
}
}
static bool LoadBIOS(uint8 *biosrom, const char *biosname, int biossize)
{
FILE *fp;
char name[PATH_MAX + 1];
bool8 r = FALSE;
bool8 r = false;
strcpy(name, S9xGetDirectory(ROMFILENAME_DIR));
strcat(name, SLASH_STR);
......@@ -762,59 +796,34 @@ static bool8 LoadBIOS(uint8 *biosrom, const char *biosname, size_t biossize)
{
size_t size;
fseek(fp,0,SEEK_END);
if(ftell(fp)-0x200 == biossize)
fseek(fp,0x200,SEEK_SET);
else
fseek(fp,0,SEEK_SET);
size = fread((void *) biosrom, 1, biossize, fp);
fclose(fp);
if (size == biossize)
r = TRUE;
}
return (r);
}
static bool8 is_SufamiTurbo_Cart (const uint8 *data, size_t size)
{
if (size >= 0x80000 && size <= 0x100000 &&
strncmp((char *) data, "BANDAI SFC-ADX", 14) == 0 && strncmp((char * ) (data + 0x10), "SFC-ADX BACKUP", 14) != 0)
return (TRUE);
else
return (FALSE);
}
bool retro_load_game(const struct retro_game_info *game)
{
init_descriptors();
memorydesc_c = 0;
if(size == biossize) r = true;
}
update_variables();
if(game->data == NULL && game->size == 0 && game->path != NULL)
rom_loaded = Memory.LoadROM(game->path);
else
if(log_cb)
{
uint8 *biosrom = new uint8[0x100000];
if (game->path != NULL)
{
extract_basename(g_basename, game->path, sizeof(g_basename));
extract_directory(g_rom_dir, game->path, sizeof(g_rom_dir));
}
if (is_SufamiTurbo_Cart((uint8 *) game->data, game->size)) {
if ((rom_loaded = LoadBIOS(biosrom,"STBIOS.bin",0x40000)))
rom_loaded = Memory.LoadMultiCartMem((const uint8_t*)game->data, game->size, 0, 0, biosrom, 0x40000);
}
else
if ((is_bsx((uint8 *) game->data + 0x7fc0)==1) | (is_bsx((uint8 *) game->data + 0xffc0)==1)) {
if ((rom_loaded = LoadBIOS(biosrom,"BS-X.bin",0x100000)))
rom_loaded = Memory.LoadMultiCartMem(biosrom, 0x100000, (const uint8_t*)game->data, game->size, 0, 0);
}
if(!r)
log_cb(RETRO_LOG_INFO, "[libretro]: BIOS not found [%s]\n", biosname);
else
rom_loaded = Memory.LoadROMMem((const uint8_t*)game->data ,game->size);
if(biosrom) delete[] biosrom;
log_cb(RETRO_LOG_INFO, "[libretro]: BIOS loaded [%s]\n", biosname);
}
return (r);
}
void retro_load_init_reset()
{
struct retro_memory_map map={ memorydesc+MAX_MAPS-memorydesc_c, memorydesc_c };
if (rom_loaded) environ_cb(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &map);
int pixel_format = RGB555;
if(environ_cb) {
......@@ -827,9 +836,6 @@ bool retro_load_game(const struct retro_game_info *game)
S9xSetRenderPixelFormat(pixel_format);
S9xGraphicsInit();
if (!rom_loaded && log_cb)
log_cb(RETRO_LOG_ERROR, "[libretro]: Rom loading failed...\n");
/* Check if Chrono Trigger is loaded, if so, we need to set a variable to
* true to get rid of an annoying mid-frame resolution switch to 256x239
* which can cause an undesirable flicker/breakup of the screen for a
......@@ -856,32 +862,109 @@ bool retro_load_game(const struct retro_game_info *game)
lufia2_credits_hack = true;
}
struct retro_memory_map map={ memorydesc+MAX_MAPS-memorydesc_c, memorydesc_c };
if (rom_loaded) environ_cb(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &map);
update_geometry();
if(randomize_memory)
{
srand(time(NULL));
for(int lcv=0; lcv<0x20000; lcv++)
Memory.RAM[lcv] = rand()%256;
}
}
bool retro_load_game(const struct retro_game_info *game)
{
init_descriptors();
memorydesc_c = 0;
rom_loaded = false;
update_variables();
if(game->data == NULL && game->size == 0 && game->path != NULL)
rom_loaded = Memory.LoadROM(game->path);
else
{
uint8_t *romptr = (uint8_t *) game->data;
size_t romsize = game->size;
Remove_Header(romptr, romsize, false);
if (game->path != NULL)
{
extract_basename(g_basename, game->path, sizeof(g_basename));
extract_directory(g_rom_dir, game->path, sizeof(g_rom_dir));
}
if (is_SufamiTurbo_Cart(romptr,romsize)) {
uint8 *biosrom = new uint8[0x40000];
uint8 *biosptr = biosrom;
if (LoadBIOS(biosptr,"STBIOS.bin",0x40000)) {
if (log_cb) log_cb(RETRO_LOG_INFO, "[libretro]: Loading Sufami Turbo game\n");
rom_loaded = Memory.LoadMultiCartMem((const uint8_t*)romptr, romsize, 0, 0, biosptr, 0x40000);
}
if(biosrom) delete[] biosrom;
}
else
if ((is_bsx((uint8 *) romptr+0x7fc0)==1) | (is_bsx((uint8 *) romptr+0xffc0)==1)) {
uint8 *biosrom = new uint8[0x100000];
uint8 *biosptr = biosrom;
if (LoadBIOS(biosptr,"BS-X.bin",0x100000)) {
if (log_cb) log_cb(RETRO_LOG_INFO, "[libretro]: Loading Satellaview game\n");
rom_loaded = Memory.LoadMultiCartMem(biosptr, 0x100000, (const uint8_t*)romptr, romsize, 0, 0);
}
if(biosrom) delete[] biosrom;
}
else
rom_loaded = Memory.LoadROMMem((const uint8_t*)romptr, romsize);
}
if (rom_loaded)
retro_load_init_reset();
else if (log_cb)
log_cb(RETRO_LOG_ERROR, "[libretro]: Rom loading failed...\n");
return rom_loaded;
}
void retro_unload_game(void)
{}
bool retro_load_game_special(unsigned game_type, const struct retro_game_info *info, size_t num_info) {
bool retro_load_game_special(unsigned game_type, const struct retro_game_info *info, size_t num_info)
{
uint8_t *romptr[3];
size_t romsize[3];
for(int lcv=0; lcv<num_info; lcv++)
{
romptr[lcv] = (uint8_t *) info[lcv].data;
romsize[lcv] = info[lcv].size;
Remove_Header(romptr[lcv], romsize[lcv], true);
}
init_descriptors();
memorydesc_c = 0;
rom_loaded = false;
update_variables();
switch (game_type) {
case RETRO_GAME_TYPE_BSX:
if(num_info == 1) {
rom_loaded = Memory.LoadROMMem((const uint8_t*)info[0].data,info[0].size);
rom_loaded = Memory.LoadROMMem((const uint8_t*)romptr[0],romsize[0]);
} else if(num_info == 2) {
memcpy(Memory.BIOSROM,(const uint8_t*)info[0].data,info[0].size);
rom_loaded = Memory.LoadROMMem((const uint8_t*)info[1].data,info[1].size);
memcpy(Memory.BIOSROM,(const uint8_t*)romptr[0],info[0].size);
rom_loaded = Memory.LoadROMMem((const uint8_t*)romptr[1],info[1].size);
}
if (!rom_loaded && log_cb)
......@@ -891,22 +974,27 @@ bool retro_load_game_special(unsigned game_type, const struct retro_game_info *i
case RETRO_GAME_TYPE_BSX_SLOTTED:
case RETRO_GAME_TYPE_MULTI_CART:
if(num_info == 2) {
uint8 *biosrom = new uint8[0x100000];
if (is_SufamiTurbo_Cart((const uint8_t*)romptr[0], romsize[0])) {
uint8 *biosrom = new uint8[0x40000];
uint8 *biosptr = biosrom;
if (LoadBIOS(biosptr,"STBIOS.bin",0x40000)) {
if (log_cb) log_cb(RETRO_LOG_INFO, "[libretro]: Loading Sufami Turbo link game\n");
if (is_SufamiTurbo_Cart((const uint8_t*)info[0].data, info[0].size)) {
if ((rom_loaded = LoadBIOS(biosrom,"STBIOS.bin",0x40000)))
rom_loaded = Memory.LoadMultiCartMem((const uint8_t*)info[0].data, info[0].size,
(const uint8_t*)info[1].data, info[1].size, biosrom, 0x40000);
rom_loaded = Memory.LoadMultiCartMem((const uint8_t*)romptr[0], romsize[0],
(const uint8_t*)romptr[1], romsize[1], biosptr, 0x40000);
}
if (biosrom) delete[] biosrom;
}
else {
rom_loaded = Memory.LoadMultiCartMem((const uint8_t*)info[0].data, info[0].size,
(const uint8_t*)info[1].data, info[1].size, NULL, 0);
}
if (log_cb) log_cb(RETRO_LOG_INFO, "[libretro]: Loading Multi-Cart link game\n");
if (biosrom) delete[] biosrom;
rom_loaded = Memory.LoadMultiCartMem((const uint8_t*)romptr[0], romsize[0],
(const uint8_t*)romptr[1], romsize[1], NULL, 0);
}
}
if (!rom_loaded && log_cb)
......@@ -915,13 +1003,12 @@ bool retro_load_game_special(unsigned game_type, const struct retro_game_info *i
break;
case RETRO_GAME_TYPE_SUFAMI_TURBO:
if(num_info == 2) {
uint8 *biosrom = new uint8[0x100000];
if ((rom_loaded = LoadBIOS(biosrom,"STBIOS.bin",0x40000)))
rom_loaded = Memory.LoadMultiCartMem((const uint8_t*)info[0].data, info[0].size,
(const uint8_t*)info[1].data, info[1].size, biosrom, 0x40000);
if ((rom_loaded = LoadBIOS(biosrom,"STBIOS.bin",0x100000)))
rom_loaded = Memory.LoadMultiCartMem((const uint8_t*)romptr[0], romsize[0],
(const uint8_t*)romptr[1], romsize[1], biosrom, 0x40000);
if (biosrom) delete[] biosrom;
}
......@@ -933,26 +1020,12 @@ bool retro_load_game_special(unsigned game_type, const struct retro_game_info *i
default:
rom_loaded = false;
log_cb(RETRO_LOG_ERROR, "[libretro]: Multi-cart ROM loading failed...\n");
break;
}
int pixel_format = RGB555;
if(environ_cb) {
pixel_format = RGB565;
enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565;
if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt))
pixel_format = RGB555;
}
if (rom_loaded) retro_load_init_reset();
S9xGraphicsDeinit();
S9xSetRenderPixelFormat(pixel_format);
S9xGraphicsInit();
struct retro_memory_map map={ memorydesc+MAX_MAPS-memorydesc_c, memorydesc_c };
if (rom_loaded) environ_cb(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &map);
update_geometry();
return rom_loaded;
}
......@@ -1256,7 +1329,7 @@ static void report_buttons()
else if (snes_macsrifle_state[0] > (SNES_WIDTH-1)) snes_macsrifle_state[0] = SNES_WIDTH-1;
if (snes_macsrifle_state[1] < 0) snes_macsrifle_state[1] = 0;
else if (snes_macsrifle_state[1] > (SNES_HEIGHT-1)) snes_macsrifle_state[1] = SNES_HEIGHT-1;
S9xReportPointer(BTN_POINTER, snes_macsrifle_state[0], snes_macsrifle_state[1]);
S9xReportPointer(BTN_POINTER, snes_macsrifle_state[0]+macsrifle_adjust_x, snes_macsrifle_state[1]+macsrifle_adjust_y);
for (int i = MACSRIFLE_TRIGGER; i <= MACSRIFLE_LAST; i++)
S9xReportButton(MAKE_BUTTON(2, i), input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, i));
break;
......
......@@ -195,7 +195,11 @@
#include <assert.h>
#ifdef UNZIP_SUPPORT
#include "unzip/unzip.h"
# ifdef SYSTEM_ZIP
# include <minizip/unzip.h>
# else
# include "unzip/unzip.h"
# endif
#endif
#ifdef JMA_SUPPORT
......@@ -204,11 +208,6 @@
#include <ctype.h>
#include <sys/stat.h>
#ifdef _WIN32
#include <direct.h>
#else
#include <unistd.h>
#endif
#include "snes9x.h"
#include "memmap.h"
......@@ -220,8 +219,10 @@
#include "cheats.h"
#include "display.h"
#ifdef __LIBRETRO__
#include "libretro/libretro.h"
extern retro_log_printf_t log_cb;
#endif
int dma_kludge;
void S9xAppendMapping(struct retro_memory_descriptor *desc);
......@@ -1247,12 +1248,14 @@ static bool8 is_BSCart_BIOS(const uint8 *data, uint32 size)
{
Memory.LoROM = TRUE;
Memory.HiROM = FALSE;
return (TRUE);
}
else if ((data[0xFFB2] == 0x5A) && (data[0xFFB5] != 0x20) && (data[0xFFDA] == 0x33))
{
Memory.LoROM = FALSE;
Memory.HiROM = TRUE;
return (TRUE);
}
else
......@@ -1427,7 +1430,7 @@ uint32 CMemory::FileLoader (uint8 *buffer, const char *filename, uint32 maxsize)
_makepath(fname, drive, dir, name, exts);
int nFormat = FILE_DEFAULT;
if (strcasecmp(ext, "zip") == 0)
if (strcasecmp(ext, "zip") == 0 || strcasecmp(ext, "msu1") == 0)
nFormat = FILE_ZIP;
else
if (strcasecmp(ext, "jma") == 0)
......@@ -1540,16 +1543,6 @@ bool8 CMemory::LoadROMMem (const uint8 *source, uint32 sourceSize)
return FALSE;
strcpy(ROMFilename,"MemoryROM");
//allows headered roms to be loaded from ram instead of file
uint32 calc_size = (sourceSize / 0x2000) * 0x2000;
if ((sourceSize - calc_size == 512 && !Settings.ForceNoHeader) || Settings.ForceHeader)
{
source += 512;
sourceSize -= 512;
S9xMessage(S9X_INFO, S9X_HEADERS_INFO, "Found ROM file header (and ignored it).");
}
//end of header fix
do
{
......@@ -1804,7 +1797,7 @@ bool8 CMemory::LoadMultiCartMem (const uint8 *sourceA, uint32 sourceASize,
uint32 offset = 0;
memset(ROM, 0, MAX_ROM_SIZE);
memset(&Multi, 0, sizeof(Multi));
if(bios) {
if(!is_SufamiTurbo_BIOS(bios,biosSize))
return FALSE;
......@@ -1860,7 +1853,6 @@ bool8 CMemory::LoadMultiCart (const char *cartA, const char *cartB)
return LoadMultiCartInt();
}
extern int is_bsx (unsigned char *p);
bool8 CMemory::LoadMultiCartInt ()
{
bool8 r = TRUE;
......@@ -2666,7 +2658,7 @@ void CMemory::InitROM (void)
Checksum_Calculate();
bool8 isChecksumOK = (ROMChecksum + ROMComplementChecksum == 0xffff) &
(ROMChecksum == CalculatedChecksum);