2008-08-07 14:26:07 +02:00
|
|
|
/****************************************************************************
|
2009-04-15 17:33:51 +02:00
|
|
|
* main.c
|
2008-08-07 14:26:07 +02:00
|
|
|
*
|
2008-12-11 18:38:29 +01:00
|
|
|
* Genesis Plus GX main
|
|
|
|
*
|
|
|
|
* code by Softdev (2006), Eke-Eke (2007,2008)
|
2008-08-07 14:26:07 +02: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.
|
|
|
|
*
|
|
|
|
* 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
|
2008-12-11 18:38:29 +01:00
|
|
|
*
|
2008-08-07 14:26:07 +02:00
|
|
|
***************************************************************************/
|
2008-12-11 18:38:29 +01:00
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
#include "shared.h"
|
|
|
|
#include "font.h"
|
2009-04-20 00:31:08 +02:00
|
|
|
#include "menu.h"
|
2008-08-07 14:26:07 +02:00
|
|
|
#include "history.h"
|
2009-04-15 17:33:51 +02:00
|
|
|
#include "aram.h"
|
2008-08-19 19:15:08 +02:00
|
|
|
#include "dvd.h"
|
2008-08-07 14:26:07 +02:00
|
|
|
|
2008-12-10 19:16:30 +01:00
|
|
|
#include <fat.h>
|
|
|
|
|
2008-11-13 08:24:30 +01:00
|
|
|
#ifdef HW_RVL
|
2009-04-15 17:33:51 +02:00
|
|
|
#include <wiiuse/wpad.h>
|
|
|
|
#include <di/di.h>
|
2009-04-21 03:05:56 +02:00
|
|
|
#endif
|
2009-04-15 17:33:51 +02:00
|
|
|
|
2009-04-21 03:05:56 +02:00
|
|
|
#ifdef HW_RVL
|
2009-04-24 01:24:40 +02:00
|
|
|
|
2008-11-13 08:24:30 +01:00
|
|
|
/* Power Button callback */
|
2009-01-14 17:32:35 +01:00
|
|
|
u8 Shutdown = 0;
|
2009-04-20 00:31:08 +02:00
|
|
|
static void Power_Off(void)
|
2008-11-13 08:24:30 +01:00
|
|
|
{
|
|
|
|
Shutdown = 1;
|
|
|
|
ConfigRequested = 1;
|
|
|
|
}
|
|
|
|
|
2009-04-24 01:24:40 +02:00
|
|
|
#endif
|
2008-12-07 20:31:50 +01:00
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
/***************************************************************************
|
2008-12-12 16:38:04 +01:00
|
|
|
* Genesis Plus Virtual Machine
|
2008-08-07 14:26:07 +02:00
|
|
|
*
|
|
|
|
***************************************************************************/
|
2009-04-20 00:31:08 +02:00
|
|
|
static void load_bios(void)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
2008-12-10 19:16:30 +01:00
|
|
|
char pathname[MAXPATHLEN];
|
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
/* reset BIOS found flag */
|
|
|
|
config.bios_enabled &= ~2;
|
|
|
|
|
2008-12-12 16:38:04 +01:00
|
|
|
/* open BIOS file */
|
2008-12-11 18:38:29 +01:00
|
|
|
sprintf (pathname, "%s/BIOS.bin",DEFAULT_PATH);
|
2008-12-10 19:16:30 +01:00
|
|
|
FILE *fp = fopen(pathname, "rb");
|
2008-08-07 14:26:07 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-04-20 00:31:08 +02:00
|
|
|
static void init_machine(void)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
2008-12-19 16:38:26 +01:00
|
|
|
/* Allocate cart_rom here ( 10 MBytes ) */
|
2009-04-15 17:33:51 +02:00
|
|
|
cart_rom = memalign(32, MAXROMSIZE);
|
|
|
|
if (!cart_rom)
|
|
|
|
{
|
|
|
|
WaitPrompt("Failed to allocate ROM buffer... Rebooting");
|
2009-04-24 01:24:40 +02:00
|
|
|
gx_audio_Shutdown();
|
|
|
|
gx_video_Shutdown();
|
2009-04-15 17:33:51 +02:00
|
|
|
#ifdef HW_RVL
|
|
|
|
DI_Close();
|
|
|
|
SYS_ResetSystem(SYS_RESTART,0,0);
|
|
|
|
#else
|
|
|
|
SYS_ResetSystem(SYS_HOTRESET,0,0);
|
|
|
|
#endif
|
|
|
|
}
|
2008-08-07 14:26:07 +02:00
|
|
|
|
2008-12-12 16:38:04 +01:00
|
|
|
/* BIOS support */
|
|
|
|
load_bios();
|
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
/* allocate global work bitmap */
|
|
|
|
memset (&bitmap, 0, sizeof (bitmap));
|
2008-12-12 16:38:04 +01:00
|
|
|
bitmap.width = 720;
|
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;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************
|
|
|
|
Load a new rom and performs some initialization
|
|
|
|
***************************************************/
|
2009-04-20 00:31:08 +02:00
|
|
|
void reloadrom (int size, char *name)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
2009-04-20 00:31:08 +02:00
|
|
|
genromsize = size;
|
|
|
|
load_rom(name); /* Load ROM */
|
2008-12-17 18:18:07 +01:00
|
|
|
system_init (); /* Initialize System */
|
|
|
|
audio_init(48000); /* Audio System initialization */
|
|
|
|
ClearGGCodes (); /* Clear Game Genie patches */
|
|
|
|
system_reset (); /* System Power ON */
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
|
2009-04-20 00:31:08 +02:00
|
|
|
/**************************************************
|
|
|
|
Shutdown everything properly
|
|
|
|
***************************************************/
|
|
|
|
void shutdown(void)
|
|
|
|
{
|
|
|
|
/* system shutdown */
|
|
|
|
memfile_autosave(-1,config.state_auto);
|
|
|
|
system_shutdown();
|
|
|
|
audio_shutdown();
|
|
|
|
free(cart_rom);
|
2009-04-24 01:24:40 +02:00
|
|
|
gx_audio_Shutdown();
|
|
|
|
gx_video_Shutdown();
|
2009-04-20 00:31:08 +02:00
|
|
|
#ifdef HW_RVL
|
|
|
|
DI_Close();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
/***************************************************************************
|
|
|
|
* M A I N
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
2009-01-14 17:32:35 +01:00
|
|
|
u8 fat_enabled = 0;
|
|
|
|
u32 frameticker = 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
|
2009-04-20 00:31:08 +02:00
|
|
|
/* initialize DVD Mode */
|
2008-12-07 20:31:50 +01:00
|
|
|
DI_Close();
|
2008-08-19 19:15:08 +02:00
|
|
|
DI_Init();
|
|
|
|
#endif
|
|
|
|
|
2009-01-14 17:32:35 +01:00
|
|
|
uint32 RenderedFrames = 0;
|
|
|
|
uint32 TotalFrames = 0;
|
|
|
|
uint32 FramesPerSecond = 0;
|
2009-01-13 21:02:06 +01:00
|
|
|
|
2009-04-24 01:24:40 +02:00
|
|
|
/* initialize hardware */
|
|
|
|
gx_video_Init();
|
|
|
|
gx_input_Init();
|
|
|
|
gx_audio_Init();
|
2008-11-13 08:24:30 +01:00
|
|
|
#ifdef HW_DOL
|
2008-08-07 14:26:07 +02:00
|
|
|
DVD_Init ();
|
|
|
|
dvd_drive_detect();
|
|
|
|
#endif
|
|
|
|
|
2009-04-24 01:24:40 +02:00
|
|
|
/* initialize FAT devices */
|
2009-01-14 17:32:35 +01:00
|
|
|
if (fatInitDefault())
|
2008-10-26 19:32:32 +01:00
|
|
|
{
|
2008-12-10 19:16:30 +01:00
|
|
|
fat_enabled = 1;
|
2008-12-10 22:29:42 +01:00
|
|
|
#ifdef HW_RVL
|
|
|
|
fatEnableReadAhead ("sd", 6, 64);
|
|
|
|
fatEnableReadAhead ("usb", 6, 64);
|
|
|
|
#else
|
|
|
|
fatEnableReadAhead ("carda", 6, 64);
|
|
|
|
fatEnableReadAhead ("cardb", 6, 64);
|
|
|
|
#endif
|
2008-10-26 19:32:32 +01:00
|
|
|
}
|
2008-10-17 20:35:28 +02:00
|
|
|
|
2009-04-24 01:24:40 +02:00
|
|
|
/* Initialize sound engine */
|
|
|
|
gx_audio_Init();
|
2009-04-21 03:05:56 +02:00
|
|
|
|
2009-01-14 17:32:35 +01:00
|
|
|
/* default config */
|
2008-12-12 14:27:38 +01:00
|
|
|
legal();
|
2009-04-15 17:33:51 +02:00
|
|
|
config_setDefault();
|
2008-08-07 14:26:07 +02:00
|
|
|
config_load();
|
|
|
|
|
2009-04-24 01:24:40 +02:00
|
|
|
/* recent ROM files list */
|
2009-04-15 17:33:51 +02:00
|
|
|
history_setDefault();
|
2008-08-07 14:26:07 +02:00
|
|
|
history_load();
|
|
|
|
|
2009-01-14 17:32:35 +01:00
|
|
|
/* initialize Virtual Machine */
|
2008-08-07 14:26:07 +02:00
|
|
|
init_machine ();
|
2009-01-09 18:11:42 +01:00
|
|
|
|
2009-04-05 20:20:43 +02:00
|
|
|
/* run any injected rom */
|
2008-08-07 14:26:07 +02:00
|
|
|
if (genromsize)
|
|
|
|
{
|
|
|
|
ARAMFetch((char *)cart_rom, (void *)0x8000, genromsize);
|
2009-04-20 00:31:08 +02:00
|
|
|
reloadrom (genromsize,"INJECT.bin");
|
2009-04-24 01:24:40 +02:00
|
|
|
gx_video_Start();
|
|
|
|
gx_audio_Start();
|
2009-04-05 20:20:43 +02:00
|
|
|
frameticker = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* show menu first */
|
|
|
|
ConfigRequested = 1;
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
2009-01-09 18:11:42 +01:00
|
|
|
|
2009-04-24 01:24:40 +02:00
|
|
|
#ifdef HW_RVL
|
|
|
|
/* Power button callback */
|
|
|
|
SYS_SetPowerCallback(Power_Off);
|
|
|
|
#endif
|
|
|
|
|
2009-01-14 17:32:35 +01:00
|
|
|
/* main emulation loop */
|
2008-08-07 14:26:07 +02:00
|
|
|
while (1)
|
|
|
|
{
|
2009-01-14 17:32:35 +01:00
|
|
|
/* check for menu request */
|
2009-01-08 20:01:16 +01:00
|
|
|
if (ConfigRequested)
|
|
|
|
{
|
2009-01-14 17:32:35 +01:00
|
|
|
/* stop audio & video */
|
2009-04-24 01:24:40 +02:00
|
|
|
gx_video_Stop();
|
|
|
|
gx_audio_Stop();
|
2009-01-08 20:01:16 +01:00
|
|
|
|
|
|
|
/* go to menu */
|
2009-04-20 00:31:08 +02:00
|
|
|
MainMenu ();
|
2009-01-08 20:01:16 +01:00
|
|
|
ConfigRequested = 0;
|
|
|
|
|
2009-01-14 17:32:35 +01:00
|
|
|
/* reset framecounts */
|
2009-01-13 21:02:06 +01:00
|
|
|
RenderedFrames = 0;
|
|
|
|
TotalFrames = 0;
|
|
|
|
FramesPerSecond = vdp_rate;
|
2009-01-08 20:01:16 +01:00
|
|
|
|
2009-01-14 17:32:35 +01:00
|
|
|
/* start audio & video */
|
2009-04-24 01:24:40 +02:00
|
|
|
gx_video_Start();
|
|
|
|
gx_audio_Start();
|
2009-02-22 20:57:41 +01:00
|
|
|
|
|
|
|
/* reset framesync */
|
|
|
|
frameticker = 1;
|
2009-01-08 20:01:16 +01:00
|
|
|
}
|
2009-01-13 18:00:37 +01:00
|
|
|
|
|
|
|
if (frameticker > 1)
|
|
|
|
{
|
2009-01-14 17:32:35 +01:00
|
|
|
/* skip frame */
|
2009-02-22 20:57:41 +01:00
|
|
|
frameticker-=2;
|
2009-01-13 18:00:37 +01:00
|
|
|
system_frame (1);
|
|
|
|
|
|
|
|
/* update audio only */
|
2009-04-24 01:24:40 +02:00
|
|
|
gx_audio_Update();
|
2009-01-13 18:00:37 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-01-14 17:32:35 +01:00
|
|
|
/* framesync */
|
|
|
|
while (frameticker < 1) usleep(1);
|
2009-02-22 20:57:41 +01:00
|
|
|
frameticker--;
|
2009-01-13 18:00:37 +01:00
|
|
|
|
2009-01-14 17:32:35 +01:00
|
|
|
/* render frame */
|
2009-01-13 18:00:37 +01:00
|
|
|
system_frame (0);
|
|
|
|
|
|
|
|
/* update video & audio */
|
2009-04-24 01:24:40 +02:00
|
|
|
gx_video_Update();
|
|
|
|
gx_audio_Update();
|
2009-01-13 21:02:06 +01:00
|
|
|
RenderedFrames++;
|
2009-01-13 18:00:37 +01:00
|
|
|
}
|
|
|
|
|
2009-01-14 17:32:35 +01:00
|
|
|
/* update framecounts */
|
2009-01-13 21:02:06 +01:00
|
|
|
TotalFrames++;
|
|
|
|
if (TotalFrames == vdp_rate)
|
|
|
|
{
|
|
|
|
FramesPerSecond = RenderedFrames;
|
|
|
|
RenderedFrames = 0;
|
|
|
|
TotalFrames = 0;
|
|
|
|
}
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
2009-01-06 18:15:28 +01:00
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
return 0;
|
|
|
|
}
|