2008-06-04 20:28:20 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* 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.
|
2014-02-18 02:34:27 +01:00
|
|
|
*
|
2008-06-04 20:28:20 +00:00
|
|
|
* 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.
|
2014-02-18 02:34:27 +01:00
|
|
|
*
|
2008-06-04 20:28:20 +00:00
|
|
|
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2014-02-18 02:34:27 +01:00
|
|
|
*
|
2008-06-04 20:28:20 +00:00
|
|
|
*/
|
|
|
|
|
2011-05-03 12:52:28 +02:00
|
|
|
#define FORBIDDEN_SYMBOL_EXCEPTION_chdir
|
2011-05-03 14:30:25 +02:00
|
|
|
#define FORBIDDEN_SYMBOL_EXCEPTION_getcwd
|
2011-05-03 12:52:28 +02:00
|
|
|
#define FORBIDDEN_SYMBOL_EXCEPTION_printf
|
|
|
|
|
2008-06-04 20:28:20 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2009-03-19 18:56:54 +00:00
|
|
|
#include "osystem.h"
|
2010-09-05 12:49:29 +00:00
|
|
|
#include "backends/plugins/wii/wii-provider.h"
|
2009-03-19 18:56:54 +00:00
|
|
|
|
2009-09-18 18:56:16 +00:00
|
|
|
#include <ogc/machine/processor.h>
|
|
|
|
#include <fat.h>
|
2009-09-18 21:25:32 +00:00
|
|
|
#ifndef GAMECUBE
|
|
|
|
#include <wiiuse/wpad.h>
|
|
|
|
#endif
|
2009-01-21 19:29:02 +00:00
|
|
|
#ifdef USE_WII_DI
|
2009-01-19 23:57:49 +00:00
|
|
|
#include <di/di.h>
|
|
|
|
#endif
|
2009-01-19 15:11:18 +00:00
|
|
|
#ifdef DEBUG_WII_GDB
|
2008-06-04 20:28:20 +00:00
|
|
|
#include <debug.h>
|
|
|
|
#endif
|
2010-08-28 12:51:12 +00:00
|
|
|
#include <gxflux/gfx_con.h>
|
2009-08-30 17:01:03 +00:00
|
|
|
|
2008-06-04 20:28:20 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2008-06-07 15:37:17 +00:00
|
|
|
bool reset_btn_pressed = false;
|
|
|
|
bool power_btn_pressed = false;
|
|
|
|
|
|
|
|
void reset_cb(void) {
|
2009-01-19 15:11:18 +00:00
|
|
|
#ifdef DEBUG_WII_GDB
|
|
|
|
printf("attach gdb now\n");
|
|
|
|
_break();
|
|
|
|
#else
|
2008-06-07 15:37:17 +00:00
|
|
|
reset_btn_pressed = true;
|
2009-01-19 15:11:18 +00:00
|
|
|
#endif
|
2008-06-07 15:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void power_cb(void) {
|
|
|
|
power_btn_pressed = true;
|
|
|
|
}
|
|
|
|
|
2009-09-18 21:25:32 +00:00
|
|
|
static void show_console(int code) {
|
2010-04-19 20:25:20 +00:00
|
|
|
u32 i, b;
|
2009-09-18 21:25:32 +00:00
|
|
|
|
|
|
|
printf("ScummVM exited abnormally (%d).\n", code);
|
|
|
|
|
2009-09-21 20:45:21 +00:00
|
|
|
gfx_frame_abort();
|
2010-04-19 20:25:20 +00:00
|
|
|
gfx_init();
|
|
|
|
|
|
|
|
if (!gfx_frame_start())
|
|
|
|
return;
|
|
|
|
|
|
|
|
gfx_con_draw();
|
|
|
|
gfx_frame_end();
|
|
|
|
|
|
|
|
for (i = 0; i < 60 * 3; ++i)
|
|
|
|
VIDEO_WaitVSync();
|
|
|
|
|
2010-08-28 12:51:12 +00:00
|
|
|
#ifdef DEBUG_WII_GDB
|
|
|
|
printf("attach gdb now\n");
|
|
|
|
_break();
|
|
|
|
#endif
|
|
|
|
|
2010-04-19 20:25:20 +00:00
|
|
|
printf("Press any key to continue.\n");
|
|
|
|
|
2009-09-18 21:25:32 +00:00
|
|
|
if (!gfx_frame_start())
|
|
|
|
return;
|
|
|
|
|
|
|
|
gfx_con_draw();
|
|
|
|
gfx_frame_end();
|
2010-04-19 20:25:20 +00:00
|
|
|
VIDEO_WaitVSync();
|
2009-09-18 21:25:32 +00:00
|
|
|
|
|
|
|
while (true) {
|
|
|
|
b = 0;
|
|
|
|
|
|
|
|
if (PAD_ScanPads() & 1)
|
|
|
|
b = PAD_ButtonsDown(0);
|
|
|
|
|
|
|
|
#ifndef GAMECUBE
|
|
|
|
WPAD_ScanPads();
|
|
|
|
if (WPAD_Probe(0, NULL) == WPAD_ERR_NONE)
|
|
|
|
b |= WPAD_ButtonsDown(0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (b)
|
|
|
|
break;
|
|
|
|
|
|
|
|
VIDEO_WaitVSync();
|
|
|
|
}
|
2010-04-19 20:25:20 +00:00
|
|
|
|
|
|
|
printf("\n\nExiting...\n");
|
|
|
|
|
|
|
|
if (!gfx_frame_start())
|
|
|
|
return;
|
|
|
|
|
|
|
|
gfx_con_draw();
|
|
|
|
gfx_frame_end();
|
|
|
|
VIDEO_WaitVSync();
|
2009-09-18 21:25:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
s32 reset_func(s32 final) {
|
|
|
|
static bool done = false;
|
|
|
|
|
|
|
|
if (!done) {
|
|
|
|
show_console(-127);
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static sys_resetinfo resetinfo = {
|
|
|
|
{ NULL, NULL },
|
|
|
|
reset_func,
|
|
|
|
1
|
|
|
|
};
|
|
|
|
|
2009-01-19 15:11:18 +00:00
|
|
|
#ifdef DEBUG_WII_MEMSTATS
|
|
|
|
void wii_memstats(void) {
|
|
|
|
static u32 min_free = UINT_MAX;
|
|
|
|
static u32 temp_free;
|
|
|
|
static u32 level;
|
|
|
|
|
|
|
|
_CPU_ISR_Disable(level);
|
|
|
|
#ifdef GAMECUBE
|
|
|
|
temp_free = (u32) SYS_GetArenaHi() - (u32) SYS_GetArenaLo();
|
|
|
|
#else
|
|
|
|
temp_free = (u32) SYS_GetArena1Hi() - (u32) SYS_GetArena1Lo() +
|
|
|
|
(u32) SYS_GetArena2Hi() - (u32) SYS_GetArena2Lo();
|
|
|
|
#endif
|
|
|
|
_CPU_ISR_Restore(level);
|
|
|
|
|
|
|
|
if (temp_free < min_free) {
|
|
|
|
min_free = temp_free;
|
|
|
|
fprintf(stderr, "free: %8u\n", min_free);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-06-04 20:28:20 +00:00
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
s32 res;
|
|
|
|
|
2010-08-28 12:51:12 +00:00
|
|
|
#if defined(USE_WII_DI) && !defined(GAMECUBE)
|
2009-01-19 23:57:49 +00:00
|
|
|
DI_Init();
|
|
|
|
#endif
|
|
|
|
|
2008-06-04 20:28:20 +00:00
|
|
|
VIDEO_Init();
|
|
|
|
PAD_Init();
|
2010-08-28 12:51:12 +00:00
|
|
|
DSP_Init();
|
2008-06-04 20:28:20 +00:00
|
|
|
AUDIO_Init(NULL);
|
|
|
|
|
2009-09-21 20:45:21 +00:00
|
|
|
gfx_video_init(NULL);
|
2009-09-18 18:56:16 +00:00
|
|
|
gfx_init();
|
|
|
|
gfx_con_init(NULL);
|
2009-01-19 15:11:18 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_WII_GDB
|
|
|
|
DEBUG_Init(GDBSTUB_DEVICE_USB, 1);
|
2008-06-04 20:28:20 +00:00
|
|
|
#endif
|
|
|
|
|
2008-12-23 19:16:38 +00:00
|
|
|
printf("startup as ");
|
|
|
|
if (argc > 0)
|
|
|
|
printf("'%s'\n", argv[0]);
|
|
|
|
else
|
|
|
|
printf("<unknown>\n");
|
2008-06-04 20:28:20 +00:00
|
|
|
|
2009-09-18 21:25:32 +00:00
|
|
|
SYS_RegisterResetFunc(&resetinfo);
|
|
|
|
|
2008-06-07 15:37:17 +00:00
|
|
|
SYS_SetResetCallback(reset_cb);
|
2008-08-09 20:02:56 +00:00
|
|
|
#ifndef GAMECUBE
|
2008-06-07 15:37:17 +00:00
|
|
|
SYS_SetPowerCallback(power_cb);
|
2008-08-09 20:02:56 +00:00
|
|
|
#endif
|
2008-06-07 15:37:17 +00:00
|
|
|
|
2008-06-04 20:28:20 +00:00
|
|
|
if (!fatInitDefault()) {
|
|
|
|
printf("fatInitDefault failed\n");
|
|
|
|
} else {
|
|
|
|
// set the default path if libfat couldnt set it
|
|
|
|
// this allows loading over tcp/usbgecko
|
2008-12-23 19:16:38 +00:00
|
|
|
char cwd[MAXPATHLEN];
|
2008-06-04 20:28:20 +00:00
|
|
|
|
2008-12-23 19:16:38 +00:00
|
|
|
if (getcwd(cwd, MAXPATHLEN)) {
|
|
|
|
size_t len = strlen(cwd);
|
2008-06-04 20:28:20 +00:00
|
|
|
|
2008-12-23 19:16:38 +00:00
|
|
|
if (len > 2 && (cwd[len - 1] == ':' || cwd[len - 2] == ':')) {
|
|
|
|
printf("chdir to default\n");
|
|
|
|
chdir("/apps/scummvm");
|
|
|
|
}
|
|
|
|
}
|
2008-06-04 20:28:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_system = new OSystem_Wii();
|
|
|
|
assert(g_system);
|
|
|
|
|
2010-09-05 12:49:29 +00:00
|
|
|
#ifdef DYNAMIC_MODULES
|
|
|
|
PluginManager::instance().addPluginProvider(new WiiPluginProvider());
|
|
|
|
#endif
|
|
|
|
|
2008-06-04 20:28:20 +00:00
|
|
|
res = scummvm_main(argc, argv);
|
|
|
|
g_system->quit();
|
|
|
|
|
|
|
|
printf("shutdown\n");
|
|
|
|
|
2009-09-18 21:25:32 +00:00
|
|
|
SYS_UnregisterResetFunc(&resetinfo);
|
2013-11-22 15:13:56 +01:00
|
|
|
fatUnmount("usb:/");
|
|
|
|
fatUnmount("sd:/");
|
2008-06-04 20:28:20 +00:00
|
|
|
|
2009-09-18 21:25:32 +00:00
|
|
|
if (res)
|
|
|
|
show_console(res);
|
|
|
|
|
2008-06-07 15:37:17 +00:00
|
|
|
if (power_btn_pressed) {
|
|
|
|
printf("shutting down\n");
|
|
|
|
SYS_ResetSystem(SYS_POWEROFF, 0, 0);
|
|
|
|
}
|
|
|
|
|
2008-06-04 20:28:20 +00:00
|
|
|
printf("reloading\n");
|
|
|
|
|
2009-09-18 18:56:16 +00:00
|
|
|
gfx_con_deinit();
|
|
|
|
gfx_deinit();
|
2009-08-30 17:01:03 +00:00
|
|
|
gfx_video_deinit();
|
|
|
|
|
2008-06-04 20:28:20 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|