RACE/main.c

292 lines
7.5 KiB
C
Raw Normal View History

2016-10-14 17:01:29 +00:00
//---------------------------------------------------------------------------
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version. See also the license.txt file for
// additional informations.
//---------------------------------------------------------------------------
2020-10-03 21:57:24 +00:00
#include "types.h"
2016-10-14 17:01:29 +00:00
#include "main.h"
2021-09-17 03:14:05 +00:00
#include <libretro.h>
#include <streams/file_stream.h>
2016-10-14 17:01:29 +00:00
2020-10-03 22:10:09 +00:00
#include "flash.h"
2020-10-03 21:29:32 +00:00
#include "race-memory.h"
2016-10-14 17:01:29 +00:00
#include "tlcs900h.h"
#include "input.h"
#include "graphics.h"
#include "tlcs900h.h"
#include "neopopsound.h"
#ifdef DRZ80
#include "DrZ80_support.h"
#else
#if defined(CZ80)
#include "cz80_support.h"
#else
#include "z80.h"
#endif
#endif
extern int finscan;
2019-12-19 19:44:20 +00:00
extern int language;
2016-10-14 17:01:29 +00:00
extern int tipo_consola;
2021-09-17 03:14:05 +00:00
extern retro_log_printf_t log_cb;
2021-09-20 16:28:54 +00:00
/* standard VRAM table adresses */
unsigned char *sprite_table = NULL;
unsigned char *pattern_table = NULL;
unsigned short *patterns = NULL;
unsigned short *tile_table_front = NULL;
unsigned short *tile_table_back = NULL;
unsigned short *palette_table = NULL;
unsigned char *bw_palette_table = NULL;
unsigned char *sprite_palette_numbers = NULL;
/* VDP registers
*
* where is the vdp rendering now on the lcd display?
*/
unsigned char *scanlineY = NULL;
/* frame 0/1 priority registers */
unsigned char *frame0Pri = NULL;
unsigned char *frame1Pri = NULL;
/* windowing registers */
unsigned char *wndTopLeftX = NULL;
unsigned char *wndTopLeftY = NULL;
unsigned char *wndSizeX = NULL;
unsigned char *wndSizeY = NULL;
/* scrolling registers */
unsigned char *scrollSpriteX = NULL;
unsigned char *scrollSpriteY = NULL;
unsigned char *scrollFrontX = NULL;
unsigned char *scrollFrontY = NULL;
unsigned char *scrollBackX = NULL;
unsigned char *scrollBackY = NULL;
/* background color selection register and table */
unsigned char *bgSelect = NULL;
unsigned short *bgTable = NULL;
unsigned char *oowSelect = NULL;
unsigned short *oowTable = NULL;
/* machine constants */
unsigned char *color_switch = NULL;
unsigned char *rasterY = NULL;
2020-10-03 21:57:24 +00:00
int m_bIsActive;
2016-10-14 17:01:29 +00:00
EMUINFO m_emuInfo;
2020-01-07 12:14:10 +00:00
void mainemuinit(void)
2016-10-14 17:01:29 +00:00
{
2021-09-20 16:28:54 +00:00
sprite_table = get_address(0x00008800);
pattern_table = get_address(0x0000A000);
patterns = (unsigned short*)pattern_table;
tile_table_front = (unsigned short *)get_address(0x00009000);
tile_table_back = (unsigned short *)get_address(0x00009800);
palette_table = (unsigned short *)get_address(0x00008200);
bw_palette_table = get_address(0x00008100);
sprite_palette_numbers = get_address(0x00008C00);
/* VDP registers
*
* where is the vdp rendering now on the lcd display?
*/
scanlineY = get_address(0x00008009);
/* frame 0/1 priority registers */
frame0Pri = get_address(0x00008000);
frame1Pri = get_address(0x00008030);
/* windowing registers */
wndTopLeftX = get_address(0x00008002);
wndTopLeftY = get_address(0x00008003);
wndSizeX = get_address(0x00008004);
wndSizeY = get_address(0x00008005);
/* scrolling registers */
scrollSpriteX = get_address(0x00008020);
scrollSpriteY = get_address(0x00008021);
scrollFrontX = get_address(0x00008032);
scrollFrontY = get_address(0x00008033);
scrollBackX = get_address(0x00008034);
scrollBackY = get_address(0x00008035);
/* background color selection register and table */
bgSelect = get_address(0x00008118);
bgTable = (unsigned short *)get_address(0x000083E0);
oowSelect = get_address(0x00008012);
oowTable = (unsigned short *)get_address(0x000083F0);
/* machine constants */
color_switch = get_address(0x00006F91);
rasterY = get_address(0x00008035);
/* Initialize CPU memory */
2020-01-07 12:28:50 +00:00
mem_init();
graphics_init();
2016-10-14 17:01:29 +00:00
2021-09-20 16:28:54 +00:00
/* initialize the TLCS-900H CPU */
2020-01-07 12:28:50 +00:00
tlcs_init();
2016-10-14 17:01:29 +00:00
2019-12-26 23:44:42 +00:00
#if defined(CZ80)
2020-01-07 12:28:50 +00:00
Z80_Init();
2019-12-26 23:44:42 +00:00
#endif
#if defined(DRZ80) || defined(CZ80)
2020-01-07 12:28:50 +00:00
Z80_Reset();
2016-10-14 17:01:29 +00:00
#else
2020-01-07 12:28:50 +00:00
z80Init();
2016-10-14 17:01:29 +00:00
#endif
2021-09-21 21:10:17 +00:00
/* If NeoGeo Pocket Color ROM, act if we are a NeoGeo Pocket Color */
2020-01-07 12:28:50 +00:00
tlcsMemWriteB(0x6F91,tlcsMemReadB(0x00200023));
if (tipo_consola==1)
tlcsMemWriteB(0x6F91,0x00);
2021-09-21 21:10:17 +00:00
/* Pretend we're running in English mode */
2020-01-07 12:28:50 +00:00
2021-09-21 21:10:17 +00:00
/* NOTA setting_ngp_language 00 Ingles - 01 Jap */
2020-01-07 12:28:50 +00:00
if (setting_ngp_language == 0)
tlcsMemWriteB(0x00006F87,0x01);
if (setting_ngp_language == 1)
tlcsMemWriteB(0x00006F87,0x00);
2021-09-21 21:10:17 +00:00
/* kludges & fixes */
2020-01-07 12:28:50 +00:00
switch (tlcsMemReadW(0x00200020))
{
2021-09-21 21:10:17 +00:00
case 0x0059: /* Sonic */
case 0x0061: /* Metal Slug 2nd */
2020-01-07 12:28:50 +00:00
*get_address(0x0020001F) = 0xFF;
break;
}
ngpSoundOff();
2016-10-14 17:01:29 +00:00
}
2020-10-03 22:22:14 +00:00
static void SetActive(BOOL bActive)
2016-10-14 17:01:29 +00:00
{
m_bIsActive = bActive;
}
2020-10-03 22:22:14 +00:00
static void SetEmu(int machine)
2016-10-14 17:01:29 +00:00
{
m_emuInfo.machine = machine;
}
2020-10-03 22:26:00 +00:00
static int initRom(void)
2016-10-14 17:01:29 +00:00
{
2020-01-07 12:28:50 +00:00
int i, m;
char *licenseInfo = " BY SNK CORPORATION";
BOOL romFound = TRUE;
finscan=198;
if (mainrom[0x000020] == 0x65 || mainrom[0x000020] == 0x93)
finscan=199;
2021-09-21 21:10:17 +00:00
/* first stop the current emulation */
2020-01-07 12:28:50 +00:00
SetEmu(NGPC);
SetActive(FALSE);
2021-09-21 21:10:17 +00:00
/* check NEOGEO POCKET
* check license info */
2020-01-07 12:28:50 +00:00
for (i=0;i<19;i++)
{
if (mainrom[0x000009 + i] != licenseInfo[i])
romFound = FALSE;
}
if (romFound)
{
i = mainrom[0x000023];
if (i == 0x10 || i == 0x00)
{
/* initialize emulation */
if (i == 0x10)
m = NGPC;
else
{
// fix for missing Mono/Color setting in Cool Coom Jam SAMPLE rom
if (mainrom[0x000020] == 0x34 && mainrom[0x000021] == 0x12)
m = NGPC;
else
m = NGP;
}
if (tipo_consola==1)
m = NGP;
SetEmu(m);
mainemuinit();
// start running the emulation loop
SetActive(TRUE);
return TRUE;
}
2021-09-17 03:14:05 +00:00
log_cb(RETRO_LOG_ERROR, "Not a valid or unsupported rom file.\n");
2020-01-07 12:28:50 +00:00
return FALSE;
}
2021-09-17 03:14:05 +00:00
log_cb(RETRO_LOG_ERROR, "Not a valid or unsupported rom file. romFound==FALSE\n");
2020-01-07 12:28:50 +00:00
return FALSE;
2016-10-14 17:01:29 +00:00
}
2020-10-03 22:22:14 +00:00
static void initSysInfo(void)
2016-10-14 17:01:29 +00:00
{
2021-09-21 21:10:17 +00:00
m_bIsActive = FALSE;
2016-10-14 17:01:29 +00:00
m_emuInfo.machine = NGPC;
m_emuInfo.romSize = 0;
strcpy(m_emuInfo.RomFileName, "");
}
int handleInputFile(const char *romName,
const unsigned char *romData, int romSize)
2016-10-14 17:01:29 +00:00
{
2021-09-21 21:10:17 +00:00
initSysInfo(); /* initialize it all */
2016-10-14 17:01:29 +00:00
if (romData)
{
int size = romSize > MAINROM_SIZE_MAX ?
MAINROM_SIZE_MAX : romSize;
2016-10-14 17:01:29 +00:00
m_emuInfo.romSize = size;
memcpy(mainrom, romData, size);
strcpy(m_emuInfo.RomFileName, romName);
2016-10-14 17:01:29 +00:00
}
else
{
int64_t size = 0;
2021-09-21 21:10:17 +00:00
/* get ROM from binary ROM file */
RFILE *romFile = filestream_open(romName,
RETRO_VFS_FILE_ACCESS_READ,
RETRO_VFS_FILE_ACCESS_HINT_NONE);
if(!romFile)
{
log_cb(RETRO_LOG_ERROR, "Couldn't open %s file\n", romName);
return 0;
}
size = filestream_read(romFile, mainrom, MAINROM_SIZE_MAX);
filestream_close(romFile);
if (size <= 0)
{
log_cb(RETRO_LOG_ERROR, "Couldn't read %s file\n", romName);
return 0;
}
m_emuInfo.romSize = (int)size;
strcpy(m_emuInfo.RomFileName, romName);
}
if (!initRom())
2016-10-14 17:01:29 +00:00
{
2021-09-17 03:14:05 +00:00
log_cb(RETRO_LOG_ERROR, "initRom couldn't handle %s file\n", romName);
2016-10-14 17:01:29 +00:00
return 0;
}
setFlashSize(m_emuInfo.romSize);
return 1;
}