2008-08-07 14:26:07 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Genesis Plus 1.2a
|
|
|
|
*
|
|
|
|
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Charles Mac Donald
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
***************************************************************************/
|
|
|
|
#include "shared.h"
|
|
|
|
#include "gcaram.h"
|
|
|
|
#include "font.h"
|
|
|
|
#include "history.h"
|
2008-11-13 08:24:30 +01:00
|
|
|
|
|
|
|
#ifdef HW_DOL
|
2008-08-19 19:15:08 +02:00
|
|
|
#include "dvd.h"
|
|
|
|
#else
|
2008-12-08 12:24:04 +01:00
|
|
|
#include <di/di.h>
|
2008-08-07 14:26:07 +02:00
|
|
|
#endif
|
|
|
|
|
2008-12-07 20:31:50 +01:00
|
|
|
int Shutdown = 0;
|
|
|
|
|
2008-11-13 08:24:30 +01:00
|
|
|
#ifdef HW_RVL
|
|
|
|
/* Power Button callback */
|
|
|
|
void Power_Off(void)
|
|
|
|
{
|
|
|
|
Shutdown = 1;
|
|
|
|
ConfigRequested = 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-12-07 20:31:50 +01:00
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
/***************************************************************************
|
|
|
|
* Genesis Virtual Machine
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
static void load_bios()
|
|
|
|
{
|
|
|
|
/* reset BIOS found flag */
|
|
|
|
config.bios_enabled &= ~2;
|
|
|
|
|
|
|
|
/* open file */
|
|
|
|
FILE *fp = fopen("/genplus/BIOS.bin", "rb");
|
|
|
|
if (fp == NULL) return;
|
|
|
|
|
|
|
|
/* read file */
|
|
|
|
fread(bios_rom, 1, 0x800, fp);
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
/* update BIOS flags */
|
|
|
|
config.bios_enabled |= 2;
|
2008-08-19 19:15:08 +02:00
|
|
|
|
|
|
|
if (config.bios_enabled == 3)
|
|
|
|
{
|
|
|
|
/* initialize system */
|
|
|
|
system_init ();
|
|
|
|
audio_init(48000);
|
|
|
|
}
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
|
2008-12-07 20:31:50 +01:00
|
|
|
static void init_machine (void)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
|
|
|
/* Allocate cart_rom here */
|
2008-11-13 08:24:30 +01:00
|
|
|
cart_rom = memalign(32, 10 * 1024 * 1024);
|
2008-08-07 14:26:07 +02:00
|
|
|
|
|
|
|
/* allocate global work bitmap */
|
|
|
|
memset (&bitmap, 0, sizeof (bitmap));
|
2008-10-02 22:22:53 +02:00
|
|
|
bitmap.width = 360 * 2;
|
2008-08-07 14:26:07 +02:00
|
|
|
bitmap.height = 576;
|
|
|
|
bitmap.depth = 16;
|
|
|
|
bitmap.granularity = 2;
|
|
|
|
bitmap.pitch = bitmap.width * bitmap.granularity;
|
|
|
|
bitmap.viewport.w = 256;
|
|
|
|
bitmap.viewport.h = 224;
|
|
|
|
bitmap.viewport.x = 0;
|
|
|
|
bitmap.viewport.y = 0;
|
|
|
|
bitmap.remap = 1;
|
2008-12-04 20:32:22 +01:00
|
|
|
bitmap.data = texturemem;
|
2008-08-07 14:26:07 +02:00
|
|
|
|
|
|
|
/* default system */
|
|
|
|
input.system[0] = SYSTEM_GAMEPAD;
|
|
|
|
input.system[1] = SYSTEM_GAMEPAD;
|
2008-08-19 19:15:08 +02:00
|
|
|
|
|
|
|
/* BIOS support */
|
|
|
|
load_bios();
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************
|
|
|
|
Load a new rom and performs some initialization
|
|
|
|
***************************************************/
|
|
|
|
void reloadrom ()
|
|
|
|
{
|
|
|
|
load_rom(""); /* Load ROM */
|
|
|
|
system_init (); /* Initialize System */
|
|
|
|
audio_init(48000); /* Audio System initialization */
|
|
|
|
ClearGGCodes (); /* Clear Game Genie patches */
|
|
|
|
system_reset (); /* System Power ON */
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* M A I N
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
int FramesPerSecond = 0;
|
|
|
|
int frameticker = 0;
|
2008-10-26 19:32:32 +01:00
|
|
|
bool use_FAT = 0;
|
2008-08-07 14:26:07 +02:00
|
|
|
|
|
|
|
int main (int argc, char *argv[])
|
|
|
|
{
|
2008-08-19 19:15:08 +02:00
|
|
|
#ifdef HW_RVL
|
|
|
|
/* initialize Wii DVD interface first */
|
2008-12-07 20:31:50 +01:00
|
|
|
DI_Close();
|
2008-08-19 19:15:08 +02:00
|
|
|
DI_Init();
|
|
|
|
#endif
|
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
u16 usBetweenFrames;
|
|
|
|
long long now, prev;
|
|
|
|
int RenderedFrameCount = 0;
|
|
|
|
int FrameCount = 0;
|
|
|
|
|
|
|
|
/* Initialize OGC subsystems */
|
|
|
|
ogc_video__init();
|
|
|
|
ogc_input__init();
|
|
|
|
ogc_audio__init();
|
|
|
|
|
2008-11-13 08:24:30 +01:00
|
|
|
#ifdef HW_DOL
|
2008-08-19 19:15:08 +02:00
|
|
|
/* Initialize GC DVD interface */
|
2008-08-07 14:26:07 +02:00
|
|
|
DVD_Init ();
|
|
|
|
dvd_drive_detect();
|
|
|
|
#endif
|
|
|
|
|
2008-11-13 08:24:30 +01:00
|
|
|
#ifdef HW_RVL
|
|
|
|
/* Power Button callback */
|
|
|
|
SYS_SetPowerCallback(Power_Off);
|
|
|
|
#endif
|
|
|
|
|
2008-12-08 12:24:04 +01:00
|
|
|
/* Initialize FAT Interface */
|
2008-10-26 19:32:32 +01:00
|
|
|
if (fatInitDefault() == true)
|
|
|
|
{
|
|
|
|
use_FAT = 1;
|
|
|
|
}
|
2008-10-17 20:35:28 +02:00
|
|
|
|
2008-12-07 20:31:50 +01:00
|
|
|
/* Default Config */
|
2008-08-07 14:26:07 +02:00
|
|
|
set_config_defaults();
|
|
|
|
config_load();
|
|
|
|
|
|
|
|
/* Restore Recent Files list */
|
|
|
|
set_history_defaults();
|
|
|
|
history_load();
|
|
|
|
|
|
|
|
/* Initialize Genesis Virtual Machine */
|
|
|
|
init_machine ();
|
|
|
|
|
|
|
|
/* Load any injected rom */
|
|
|
|
if (genromsize)
|
|
|
|
{
|
|
|
|
ARAMFetch((char *)cart_rom, (void *)0x8000, genromsize);
|
|
|
|
reloadrom ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Show Menu */
|
|
|
|
legal();
|
|
|
|
MainMenu();
|
|
|
|
ConfigRequested = 0;
|
|
|
|
|
|
|
|
/* Initialize Frame timings */
|
|
|
|
frameticker = 0;
|
|
|
|
prev = gettime();
|
|
|
|
|
|
|
|
/* Emulation Loop */
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
/* Frame synchronization */
|
|
|
|
if (gc_pal != vdp_pal)
|
|
|
|
{
|
|
|
|
/* use timers */
|
|
|
|
usBetweenFrames = vdp_pal ? 20000 : 16666;
|
|
|
|
now = gettime();
|
|
|
|
if (diff_usec(prev, now) > usBetweenFrames)
|
|
|
|
{
|
|
|
|
/* Frame skipping */
|
|
|
|
prev = now;
|
|
|
|
system_frame(1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Delay */
|
|
|
|
while (diff_usec(prev, now) < usBetweenFrames) now = gettime();
|
|
|
|
|
|
|
|
/* Render Frame */
|
|
|
|
prev = now;
|
|
|
|
system_frame(0);
|
|
|
|
RenderedFrameCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* use VSync */
|
|
|
|
if (frameticker > 1)
|
|
|
|
{
|
|
|
|
/* Frame skipping */
|
|
|
|
frameticker--;
|
|
|
|
system_frame (1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Delay */
|
|
|
|
while (!frameticker) usleep(10);
|
|
|
|
|
|
|
|
system_frame (0);
|
|
|
|
RenderedFrameCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
frameticker--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* update video & audio */
|
|
|
|
ogc_video__update();
|
|
|
|
ogc_audio__update();
|
|
|
|
|
|
|
|
/* Check rendered frames (FPS) */
|
|
|
|
FrameCount++;
|
|
|
|
if (FrameCount == vdp_rate)
|
|
|
|
{
|
|
|
|
FramesPerSecond = RenderedFrameCount;
|
|
|
|
RenderedFrameCount = 0;
|
|
|
|
FrameCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for Menu request */
|
|
|
|
if (ConfigRequested)
|
|
|
|
{
|
|
|
|
/* reset AUDIO */
|
|
|
|
ogc_audio__reset();
|
2008-11-13 08:24:30 +01:00
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
/* go to menu */
|
|
|
|
MainMenu ();
|
|
|
|
ConfigRequested = 0;
|
|
|
|
|
|
|
|
/* reset frame timings */
|
|
|
|
frameticker = 0;
|
|
|
|
prev = gettime();
|
|
|
|
FrameCount = 0;
|
|
|
|
RenderedFrameCount = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|