Ticket #8871: scummvm-wii-take2.diff

File scummvm-wii-take2.diff, 64.5 KB (added by dhewg, 16 years ago)

diff against trunk, take two

Line 
1Index: dists/wii/meta.xml
2===================================================================
3--- dists/wii/meta.xml (revision 0)
4+++ dists/wii/meta.xml (revision 0)
5@@ -0,0 +1,12 @@
6+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
7+<app version="1">
8+ <name>ScummVM</name>
9+ <coder>The ScummVM Team</coder>
10+ <version>rev FIXME</version>
11+ <release_date>FIXME</release_date>
12+ <short_description>Point &amp; Click Adventures</short_description>
13+ <long_description>ScummVM is a program which allows you to run certain classic graphical point-and-click adventure games, provided you already have their data files. The clever part about this: ScummVM just replaces the executables shipped with the games, allowing you to play them on systems for which they were never designed!
14+
15+Some of the adventures ScummVM supports include Adventure Soft's Simon the Sorcerer 1 and 2; Revolution's Beneath A Steel Sky, Broken Sword 1 and Broken Sword 2; Flight of the Amazon Queen; Wyrmkeep's Inherit the Earth; Coktel Vision's Gobliiins; Westwood Studios' The Legend of Kyrandia and games based on LucasArts' SCUMM (Script Creation Utility for Maniac Mansion) system such as Monkey Island, Day of the Tentacle, Sam and Max and more.</long_description>
16+</app>
17+
18Index: dists/wii/READMII
19===================================================================
20--- dists/wii/READMII (revision 0)
21+++ dists/wii/READMII (revision 0)
22@@ -0,0 +1,58 @@
23+Wii port of ScummVM README
24+--------------------------
25+
26+features not compiled in:
27+- the AGI game engine
28+
29+REQUIREMENTS
30+
31+ - sd card
32+ - wiimote or gamecube controller in port 1
33+
34+INSTALL
35+
36+ - copy the "scummvm" and "apps" folders to the root of your sd card
37+ - copy your demos and/or games onto the same sd card
38+ freeware versions: http://scummvm.org/downloads.php#extras
39+ demos: http://scummvm.org/demos.php
40+
41+RUN
42+
43+ either use the homebrew channel, available at
44+
45+ http://hbc.hackmii.com/
46+
47+ or load "boot.dol" with your favorite loader
48+
49+CONTROLS
50+
51+ wiimote
52+
53+ analog stick: mouse movement
54+ a: left mouse button
55+ b: right mouse button
56+ minus: escape
57+ plus: "." (skip current line of text)
58+ 2: enter
59+ home: f5 (scummvm menu)
60+ dpad up: shift (mass add for the gui)
61+ dpad left: "0"
62+
63+ gamecube pad
64+
65+ analog stick: mouse movement
66+ a: left mouse button
67+ b: right mouse button
68+ x: escape
69+ y: "." (skip current line of text)
70+ z: enter
71+ start: f5 (scummvm menu)
72+ dpad up: shift (mass add for the gui)
73+ dpad left: "0"
74+
75+THANKS
76+
77+ shagkur and WinterMute, for devkitppc/libogc and the coorperation
78+ svpe, for fixing the libfat feof/thread bugs on the last minute
79+ para, for making wiiuse available in libogc
80+
81Index: dists/wii/icon.png
82===================================================================
83Cannot display: file marked as a binary type.
84svn:mime-type = application/octet-stream
85
86Property changes on: dists/wii/icon.png
87___________________________________________________________________
88Name: svn:mime-type
89 + application/octet-stream
90
91Index: common/scummsys.h
92===================================================================
93--- common/scummsys.h (revision 32343)
94+++ common/scummsys.h (working copy)
95@@ -369,6 +369,14 @@
96 #define STRINGBUFLEN 256
97 #define printf(fmt, ...) consolePrintf(fmt, ##__VA_ARGS__)
98
99+#elif defined(__WII__)
100+
101+ #define scumm_stricmp strcasecmp
102+ #define scumm_strnicmp strncasecmp
103+
104+ #define SCUMM_BIG_ENDIAN
105+ #define SCUMM_NEED_ALIGNMENT
106+
107 #else
108 #error No system type defined
109
110Index: common/system.cpp
111===================================================================
112--- common/system.cpp (revision 32343)
113+++ common/system.cpp (working copy)
114@@ -137,7 +137,7 @@
115 #endif
116
117 FilesystemFactory *OSystem::getFilesystemFactory() {
118- #if defined(__amigaos4__) || defined(__DC__) || defined(__SYMBIAN32__) || defined(UNIX) || defined(WIN32) || defined(__PSP__) || defined(__DS__)
119+ #if defined(__amigaos4__) || defined(__DC__) || defined(__SYMBIAN32__) || defined(UNIX) || defined(WIN32) || defined(__WII__) || defined(__PSP__) || defined(__DS__)
120 // These ports already implement this function, so it should never be called.
121 return 0;
122 #elif defined(PALMOS_MODE)
123Index: backends/platform/wii/gecko_console.h
124===================================================================
125--- backends/platform/wii/gecko_console.h (revision 0)
126+++ backends/platform/wii/gecko_console.h (revision 0)
127@@ -0,0 +1,14 @@
128+#ifndef _WII_GECKO_CONSOLE_H_
129+#define _WII_GECKO_CONSOLE_H_
130+
131+#ifdef __cplusplus
132+extern "C" {
133+#endif
134+
135+void gecko_console_init(int chain);
136+
137+#ifdef __cplusplus
138+}
139+#endif
140+
141+#endif
142Index: backends/platform/wii/osystem.cpp
143===================================================================
144--- backends/platform/wii/osystem.cpp (revision 0)
145+++ backends/platform/wii/osystem.cpp (revision 0)
146@@ -0,0 +1,196 @@
147+/* ScummVM - Graphic Adventure Engine
148+ *
149+ * ScummVM is the legal property of its developers, whose names
150+ * are too numerous to list here. Please refer to the COPYRIGHT
151+ * file distributed with this source distribution.
152+ *
153+ * This program is free software; you can redistribute it and/or
154+ * modify it under the terms of the GNU General Public License
155+ * as published by the Free Software Foundation; either version 2
156+ * of the License, or (at your option) any later version.
157+
158+ * This program is distributed in the hope that it will be useful,
159+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
160+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
161+ * GNU General Public License for more details.
162+
163+ * You should have received a copy of the GNU General Public License
164+ * along with this program; if not, write to the Free Software
165+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
166+ */
167+
168+#include "osystem.h"
169+#include "backends/fs/wii/wii-fs-factory.h"
170+
171+#include <unistd.h>
172+
173+#include <ogc/mutex.h>
174+#include <ogc/lwp_watchdog.h>
175+
176+OSystem_Wii::OSystem_Wii() :
177+ _startup_time(0),
178+ _alarm(-1),
179+
180+ _palette(NULL),
181+ _cursorPalette(NULL),
182+ _cursorPaletteDisabled(true),
183+
184+ _gameWidth(0),
185+ _gameHeight(0),
186+ _gamePixels(NULL),
187+
188+ _overlayVisible(false),
189+ _overlayWidth(0),
190+ _overlayHeight(0),
191+ _overlaySize(0),
192+ _overlayPixels(NULL),
193+
194+ _lastScreenUpdate(0),
195+ _texture(NULL),
196+ _currentWidth(0),
197+ _currentHeight(0),
198+
199+ _supportedGraphicsModes(NULL),
200+ _activeGraphicsMode(-1),
201+
202+ _mouseVisible(false),
203+ _mouseX(0),
204+ _mouseY(0),
205+ _mouseWidth(0),
206+ _mouseHeight(0),
207+ _mouseHotspotX(0),
208+ _mouseHotspotY(0),
209+ _mouseKeyColor(0),
210+ _mouseCursor(NULL),
211+
212+ _savefile(NULL),
213+ _mixer(NULL),
214+ _timer(NULL) {
215+
216+ TRACE(0);
217+}
218+
219+OSystem_Wii::~OSystem_Wii() {
220+ TRACE(0);
221+
222+ if (_savefile) {
223+ delete _savefile;
224+ _savefile = NULL;
225+ }
226+
227+ if (_mixer) {
228+ delete _mixer;
229+ _mixer = NULL;
230+ }
231+
232+ if (_timer) {
233+ delete _timer;
234+ _timer = NULL;
235+ }
236+}
237+
238+void OSystem_Wii::initBackend() {
239+ TRACE(0);
240+
241+ _startup_time = gettime();
242+
243+ _savefile = new DefaultSaveFileManager();
244+ _mixer = new Audio::Mixer();
245+ _timer = new DefaultTimerManager();
246+
247+ initGfx();
248+ initSfx();
249+ initEvents();
250+
251+ OSystem::initBackend();
252+}
253+
254+void OSystem_Wii::quit() {
255+ TRACE(0);
256+
257+ deinitEvents();
258+ deinitSfx();
259+ deinitGfx();
260+}
261+
262+bool OSystem_Wii::hasFeature(Feature f) {
263+ return f == kFeatureCursorHasPalette;
264+}
265+
266+void OSystem_Wii::setFeatureState(Feature f, bool enable) {
267+}
268+
269+bool OSystem_Wii::getFeatureState(Feature f) {
270+ return false;
271+}
272+
273+uint32 OSystem_Wii::getMillis() {
274+ return ticks_to_millisecs(diff_ticks(_startup_time, gettime()));
275+}
276+
277+void OSystem_Wii::delayMillis(uint msecs) {
278+ usleep (msecs * 1000);
279+}
280+
281+OSystem::MutexRef OSystem_Wii::createMutex() {
282+ mutex_t *mutex = (mutex_t *) malloc(sizeof(mutex_t));
283+ s32 res = LWP_MutexInit(mutex, false);
284+
285+ if (res) {
286+ printf("ERROR creating mutex\n");
287+ delete mutex;
288+ return NULL;
289+ }
290+
291+ return (MutexRef) mutex;
292+}
293+
294+void OSystem_Wii::lockMutex(MutexRef mutex) {
295+ s32 res = LWP_MutexLock(*(mutex_t *) mutex);
296+
297+ if (res)
298+ printf("ERROR locking mutex %p (%d)\n", mutex, res);
299+}
300+
301+void OSystem_Wii::unlockMutex(MutexRef mutex) {
302+ s32 res = LWP_MutexUnlock(*(mutex_t *) mutex);
303+
304+ if (res)
305+ printf("ERROR unlocking mutex %p (%d)\n", mutex, res);
306+}
307+
308+void OSystem_Wii::deleteMutex(MutexRef mutex) {
309+ s32 res = LWP_MutexDestroy(*(mutex_t *) mutex);
310+
311+ if (res)
312+ printf("ERROR destroying mutex %p (%d)\n", mutex, res);
313+}
314+
315+void OSystem_Wii::setWindowCaption(const char *caption) {
316+ printf("window caption: %s\n", caption);
317+}
318+
319+Common::SaveFileManager *OSystem_Wii::getSavefileManager() {
320+ assert(_savefile);
321+ return _savefile;
322+}
323+
324+Audio::Mixer *OSystem_Wii::getMixer() {
325+ assert(_mixer);
326+ return _mixer;
327+}
328+
329+Common::TimerManager *OSystem_Wii::getTimerManager() {
330+ assert(_timer);
331+ return _timer;
332+}
333+
334+FilesystemFactory *OSystem_Wii::getFilesystemFactory() {
335+ return &WiiFilesystemFactory::instance();
336+}
337+
338+void OSystem_Wii::getTimeAndDate(struct tm &t) const {
339+ time_t curTime = time(0);
340+ t = *localtime(&curTime);
341+}
342+
343Index: backends/platform/wii/osystem_sfx.cpp
344===================================================================
345--- backends/platform/wii/osystem_sfx.cpp (revision 0)
346+++ backends/platform/wii/osystem_sfx.cpp (revision 0)
347@@ -0,0 +1,137 @@
348+/* ScummVM - Graphic Adventure Engine
349+ *
350+ * ScummVM is the legal property of its developers, whose names
351+ * are too numerous to list here. Please refer to the COPYRIGHT
352+ * file distributed with this source distribution.
353+ *
354+ * This program is free software; you can redistribute it and/or
355+ * modify it under the terms of the GNU General Public License
356+ * as published by the Free Software Foundation; either version 2
357+ * of the License, or (at your option) any later version.
358+
359+ * This program is distributed in the hope that it will be useful,
360+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
361+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
362+ * GNU General Public License for more details.
363+
364+ * You should have received a copy of the GNU General Public License
365+ * along with this program; if not, write to the Free Software
366+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
367+ */
368+
369+#include "osystem.h"
370+
371+#define SFX_THREAD_STACKSIZE (1024 * 128)
372+#define SFX_THREAD_PRIO 80
373+#define SFX_THREAD_FRAG_SIZE 4096
374+
375+static lwpq_t sfx_queue;
376+static lwp_t sfx_thread;
377+static u8 *sfx_stack;
378+static bool sfx_thread_running = false;
379+static bool sfx_thread_quit = false;
380+
381+static u8 sb = 0;
382+static u8 *sound_buffer[2];
383+
384+static OSystem_Wii::SoundProc sound_proc = NULL;
385+static void *proc_param = NULL;
386+
387+static void audio_switch_buffers() {
388+ AUDIO_StopDMA();
389+ AUDIO_InitDMA((u32) sound_buffer[sb], SFX_THREAD_FRAG_SIZE);
390+ AUDIO_StartDMA();
391+
392+ LWP_ThreadSignal(sfx_queue);
393+}
394+
395+static void * sfx_thread_func(void *arg) {
396+ u8 next_sb;
397+
398+ while (true) {
399+ LWP_ThreadSleep(sfx_queue);
400+
401+ if (sfx_thread_quit)
402+ break;
403+
404+ next_sb = sb ^ 1;
405+ sound_proc(proc_param, sound_buffer[next_sb], SFX_THREAD_FRAG_SIZE);
406+ DCFlushRange (sound_buffer[next_sb], SFX_THREAD_FRAG_SIZE);
407+
408+ sb = next_sb;
409+ }
410+
411+ return NULL;
412+}
413+
414+void OSystem_Wii::initSfx() {
415+ TRACE(0);
416+
417+ sfx_thread_running = false;
418+ sfx_thread_quit = false;
419+
420+ sfx_stack = (u8 *) memalign(32, SFX_THREAD_STACKSIZE);
421+ memset (sfx_stack, 0, SFX_THREAD_STACKSIZE);
422+
423+ LWP_InitQueue(&sfx_queue);
424+
425+ s32 res = LWP_CreateThread(&sfx_thread, sfx_thread_func, NULL,
426+ sfx_stack, SFX_THREAD_STACKSIZE,
427+ SFX_THREAD_PRIO);
428+
429+ if (res) {
430+ printf("ERROR creating sfx thread: %d\n", res);
431+ LWP_CloseQueue(sfx_queue);
432+ return;
433+ }
434+
435+ sfx_thread_running = true;
436+
437+ sound_buffer[0] = (u8 *) memalign(32, SFX_THREAD_FRAG_SIZE);
438+ sound_buffer[1] = (u8 *) memalign(32, SFX_THREAD_FRAG_SIZE);
439+
440+ memset(sound_buffer[0], 0, SFX_THREAD_FRAG_SIZE);
441+ memset(sound_buffer[1], 0, SFX_THREAD_FRAG_SIZE);
442+
443+ DCFlushRange(sound_buffer[0], SFX_THREAD_FRAG_SIZE);
444+ DCFlushRange(sound_buffer[1], SFX_THREAD_FRAG_SIZE);
445+
446+ sound_proc = Audio::Mixer::mixCallback;
447+ proc_param = _mixer;
448+
449+ _mixer->setReady(true);
450+
451+ AUDIO_SetDSPSampleRate(AI_SAMPLERATE_48KHZ);
452+ AUDIO_RegisterDMACallback(audio_switch_buffers);
453+
454+ audio_switch_buffers();
455+}
456+
457+void OSystem_Wii::deinitSfx() {
458+ TRACE(0);
459+
460+ if (_mixer)
461+ _mixer->setReady(false);
462+
463+ AUDIO_StopDMA();
464+ AUDIO_RegisterDMACallback(NULL);
465+
466+ if (sfx_thread_running) {
467+ sfx_thread_quit = true;
468+ LWP_ThreadBroadcast(sfx_queue);
469+
470+ LWP_JoinThread(sfx_thread, NULL);
471+ LWP_CloseQueue(sfx_queue);
472+
473+ sfx_thread_running = false;
474+
475+ free(sound_buffer[0]);
476+ free(sound_buffer[1]);
477+ }
478+}
479+
480+int OSystem_Wii::getOutputSampleRate() const {
481+ return 48000;
482+}
483+
484Index: backends/platform/wii/main.cpp
485===================================================================
486--- backends/platform/wii/main.cpp (revision 0)
487+++ backends/platform/wii/main.cpp (revision 0)
488@@ -0,0 +1,83 @@
489+/* ScummVM - Graphic Adventure Engine
490+ *
491+ * ScummVM is the legal property of its developers, whose names
492+ * are too numerous to list here. Please refer to the COPYRIGHT
493+ * file distributed with this source distribution.
494+ *
495+ * This program is free software; you can redistribute it and/or
496+ * modify it under the terms of the GNU General Public License
497+ * as published by the Free Software Foundation; either version 2
498+ * of the License, or (at your option) any later version.
499+
500+ * This program is distributed in the hope that it will be useful,
501+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
502+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
503+ * GNU General Public License for more details.
504+
505+ * You should have received a copy of the GNU General Public License
506+ * along with this program; if not, write to the Free Software
507+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
508+ */
509+
510+#include <fat.h>
511+#include <sys/stat.h>
512+#include <sys/types.h>
513+#include <errno.h>
514+#include <unistd.h>
515+
516+#include "osystem.h"
517+
518+#ifdef DEBUG_WII
519+#include <debug.h>
520+#include <gecko_console.h>
521+#endif
522+
523+#ifdef __cplusplus
524+extern "C" {
525+#endif
526+
527+int main(int argc, char *argv[]) {
528+ s32 res;
529+
530+ VIDEO_Init();
531+ PAD_Init();
532+ AUDIO_Init(NULL);
533+
534+#ifdef DEBUG_WII
535+ gecko_console_init(0);
536+ //DEBUG_Init(GDBSTUB_DEVICE_USB, 1);
537+#endif
538+
539+ printf("startup\n");
540+
541+ if (!fatInit(32, false)) {
542+ printf("fatInit failed\n");
543+ } else {
544+ if (chdir("fat:/scummvm")) {
545+ mkdir("fat:/scummvm", 0777);
546+ chdir("fat:/scummvm");
547+ }
548+ }
549+
550+ g_system = new OSystem_Wii();
551+ assert(g_system);
552+
553+ res = scummvm_main(argc, argv);
554+ g_system->quit();
555+
556+ printf("shutdown\n");
557+
558+ if (!fatUnmount(PI_DEFAULT)) {
559+ printf("fatUnmount failed\n");
560+ fatUnsafeUnmount(PI_DEFAULT);
561+ }
562+
563+ printf("reloading\n");
564+
565+ return res;
566+}
567+
568+#ifdef __cplusplus
569+}
570+#endif
571+
572Index: backends/platform/wii/gx_supp.cpp
573===================================================================
574--- backends/platform/wii/gx_supp.cpp (revision 0)
575+++ backends/platform/wii/gx_supp.cpp (revision 0)
576@@ -0,0 +1,264 @@
577+/****************************************************************************
578+* Generic GX Support for Emulators
579+* softdev 2007
580+*
581+* This program is free software; you can redistribute it and/or modify
582+* it under the terms of the GNU General Public License as published by
583+* the Free Software Foundation; either version 2 of the License, or
584+* (at your option) any later version.
585+*
586+* This program is distributed in the hope that it will be useful,
587+* but WITHOUT ANY WARRANTY; without even the implied warranty of
588+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
589+* GNU General Public License for more details.
590+*
591+* You should have received a copy of the GNU General Public License along
592+* with this program; if not, write to the Free Software Foundation, Inc.,
593+* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
594+*
595+* NGC GX Video Functions
596+*
597+* These are pretty standard functions to setup and use GX scaling.
598+****************************************************************************/
599+
600+#include <gccore.h>
601+#include <stdio.h>
602+#include <stdlib.h>
603+#include <string.h>
604+#include <malloc.h>
605+
606+#define DEFAULT_FIFO_SIZE (256 * 1024)
607+
608+#define HASPECT 320
609+#define VASPECT 240
610+
611+#ifdef __cplusplus
612+extern "C" {
613+#endif
614+
615+/*** 2D ***/
616+static u32 whichfb;
617+static u32 *xfb[2];
618+static GXRModeObj *vmode;
619+
620+/*** 3D GX ***/
621+static u8 *gp_fifo;
622+
623+/*** Texture memory ***/
624+static u8 *texturemem;
625+static u32 texturesize;
626+
627+GXTexObj texobj;
628+static Mtx view;
629+static u16 vwidth, vheight, oldvwidth, oldvheight;
630+
631+/* New texture based scaler */
632+typedef struct tagcamera {
633+ Vector pos;
634+ Vector up;
635+ Vector view;
636+} camera;
637+
638+static s16 square[] ATTRIBUTE_ALIGN(32) = {
639+ -HASPECT, VASPECT, 0,
640+ HASPECT, VASPECT, 0,
641+ HASPECT, -VASPECT, 0,
642+ -HASPECT, -VASPECT, 0,
643+};
644+
645+static camera cam = {
646+ { 0.0f, 0.0f, 370.0f },
647+ { 0.0f, 0.5f, 0.0f },
648+ { 0.0f, 0.0f, -0.5f }
649+};
650+
651+void GX_InitVideo() {
652+ vmode = VIDEO_GetPreferredMode(NULL);
653+ VIDEO_Configure(vmode);
654+
655+ xfb[0] = (u32 *) MEM_K0_TO_K1 (SYS_AllocateFramebuffer(vmode));
656+ xfb[1] = (u32 *) MEM_K0_TO_K1 (SYS_AllocateFramebuffer(vmode));
657+ gp_fifo = (u8 *) memalign(32, DEFAULT_FIFO_SIZE);
658+
659+ VIDEO_ClearFrameBuffer(vmode, xfb[0], COLOR_BLACK);
660+ VIDEO_ClearFrameBuffer(vmode, xfb[1], COLOR_BLACK);
661+
662+ whichfb = 0;
663+ VIDEO_SetNextFramebuffer(xfb[whichfb]);
664+ VIDEO_SetBlack(FALSE);
665+ VIDEO_Flush();
666+ VIDEO_WaitVSync();
667+
668+ if (vmode->viTVMode & VI_NON_INTERLACE)
669+ VIDEO_WaitVSync();
670+}
671+
672+/****************************************************************************
673+ * Scaler Support Functions
674+ ****************************************************************************/
675+static void draw_init(void) {
676+ GX_ClearVtxDesc();
677+ GX_SetVtxDesc(GX_VA_POS, GX_INDEX8);
678+ GX_SetVtxDesc(GX_VA_CLR0, GX_INDEX8);
679+ GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
680+
681+ GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_S16, 0);
682+ GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
683+ GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
684+
685+ GX_SetArray(GX_VA_POS, square, 3 * sizeof(s16));
686+
687+ GX_SetNumTexGens(1);
688+ GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);
689+
690+ GX_InvalidateTexAll();
691+
692+ GX_InitTexObj(&texobj, texturemem, vwidth, vheight, GX_TF_RGB565,
693+ GX_CLAMP, GX_CLAMP, GX_FALSE);
694+}
695+
696+static void draw_vert(u8 pos, u8 c, f32 s, f32 t) {
697+ GX_Position1x8(pos);
698+ GX_Color1x8(c);
699+ GX_TexCoord2f32(s, t);
700+}
701+
702+static void draw_square(Mtx v) {
703+ Mtx m;
704+ Mtx mv;
705+
706+ guMtxIdentity(m);
707+ guMtxTransApply(m, m, 0, 0, -100);
708+ guMtxConcat(v, m, mv);
709+
710+ GX_LoadPosMtxImm(mv, GX_PNMTX0);
711+ GX_Begin(GX_QUADS, GX_VTXFMT0, 4);
712+ draw_vert(0, 0, 0.0, 0.0);
713+ draw_vert(1, 0, 1.0, 0.0);
714+ draw_vert(2, 0, 1.0, 1.0);
715+ draw_vert(3, 0, 0.0, 1.0);
716+ GX_End();
717+}
718+
719+/****************************************************************************
720+ * StartGX
721+ ****************************************************************************/
722+void GX_Start(u16 width, u16 height, s16 haspect, s16 vaspect) {
723+ Mtx p;
724+
725+ GX_AbortFrame();
726+
727+ /*** Set new aspect ***/
728+ square[0] = square[9] = -haspect;
729+ square[3] = square[6] = haspect;
730+ square[1] = square[4] = vaspect;
731+ square[7] = square[10] = -vaspect;
732+
733+ /*** Allocate 32byte aligned texture memory ***/
734+ texturesize = (width * height) * 2;
735+ texturemem = (u8 *) memalign(32, texturesize);
736+
737+ GXColor gxbackground = { 0, 0, 0, 0xff };
738+
739+ /*** Clear out FIFO area ***/
740+ memset(gp_fifo, 0, DEFAULT_FIFO_SIZE);
741+
742+ /*** Initialise GX ***/
743+ GX_Init(gp_fifo, DEFAULT_FIFO_SIZE);
744+ GX_SetCopyClear(gxbackground, 0x00ffffff);
745+
746+ GX_SetViewport(0, 0, vmode->fbWidth, vmode->efbHeight, 0, 1);
747+ GX_SetDispCopyYScale((f32) vmode->xfbHeight / (f32) vmode->efbHeight);
748+ GX_SetScissor(0, 0, vmode->fbWidth, vmode->efbHeight);
749+ GX_SetDispCopySrc(0, 0, vmode->fbWidth, vmode->efbHeight);
750+ GX_SetDispCopyDst(vmode->fbWidth, vmode->xfbHeight);
751+ GX_SetCopyFilter(vmode->aa, vmode->sample_pattern, GX_TRUE,
752+ vmode->vfilter);
753+ GX_SetFieldMode(vmode->field_rendering,
754+ ((vmode->viHeight == 2 * vmode->xfbHeight) ?
755+ GX_ENABLE : GX_DISABLE));
756+ GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR);
757+ GX_SetCullMode(GX_CULL_NONE);
758+ GX_CopyDisp(xfb[whichfb ^ 1], GX_TRUE);
759+ GX_SetDispCopyGamma(GX_GM_1_0);
760+
761+ guPerspective(p, 60, 1.33f, 10.0f, 1000.0f);
762+ GX_LoadProjectionMtx(p, GX_PERSPECTIVE);
763+ memset(texturemem, 0, texturesize);
764+
765+ GX_Flush();
766+
767+ /*** Setup for first call to scaler ***/
768+ vwidth = vheight = -1;
769+}
770+
771+/****************************************************************************
772+* GX_Render
773+*
774+* Pass in a buffer, width and height to update as a tiled RGB565 texture
775+****************************************************************************/
776+void GX_Render(u16 width, u16 height, u8 *buffer, u16 pitch) {
777+ u16 h, w;
778+ u64 *dst = (u64 *) texturemem;
779+ u64 *src1 = (u64 *) buffer;
780+ u64 *src2 = (u64 *) (buffer + pitch);
781+ u64 *src3 = (u64 *) (buffer + (pitch * 2));
782+ u64 *src4 = (u64 *) (buffer + (pitch * 3));
783+ u16 rowpitch = (pitch >> 3) * 3 + pitch % 8;
784+
785+ vwidth = width;
786+ vheight = height;
787+
788+ whichfb ^= 1;
789+
790+ if ((oldvheight != vheight) || (oldvwidth != vwidth)) {
791+ /** Update scaling **/
792+ oldvwidth = vwidth;
793+ oldvheight = vheight;
794+ draw_init();
795+ memset(&view, 0, sizeof(Mtx));
796+ guLookAt(view, &cam.pos, &cam.up, &cam.view);
797+ GX_SetViewport(0, 0, vmode->fbWidth, vmode->efbHeight, 0, 1);
798+ }
799+
800+ GX_InvVtxCache();
801+ GX_InvalidateTexAll();
802+ GX_SetTevOp(GX_TEVSTAGE0, GX_DECAL);
803+ GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
804+
805+ for (h = 0; h < vheight; h += 4) {
806+ for (w = 0; w < (vwidth >> 2); w++) {
807+ *dst++ = *src1++;
808+ *dst++ = *src2++;
809+ *dst++ = *src3++;
810+ *dst++ = *src4++;
811+ }
812+
813+ src1 += rowpitch;
814+ src2 += rowpitch;
815+ src3 += rowpitch;
816+ src4 += rowpitch;
817+ }
818+
819+ DCFlushRange(texturemem, texturesize);
820+
821+ GX_SetNumChans(1);
822+ GX_LoadTexObj(&texobj, GX_TEXMAP0);
823+
824+ draw_square(view);
825+
826+ GX_DrawDone();
827+
828+ GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE);
829+ GX_SetColorUpdate(GX_TRUE);
830+ GX_CopyDisp(xfb[whichfb], GX_TRUE);
831+ GX_Flush();
832+
833+ VIDEO_SetNextFramebuffer(xfb[whichfb]);
834+ VIDEO_Flush();
835+}
836+
837+#ifdef __cplusplus
838+}
839+#endif
840+
841Index: backends/platform/wii/osystem_gfx.cpp
842===================================================================
843--- backends/platform/wii/osystem_gfx.cpp (revision 0)
844+++ backends/platform/wii/osystem_gfx.cpp (revision 0)
845@@ -0,0 +1,465 @@
846+/* ScummVM - Graphic Adventure Engine
847+ *
848+ * ScummVM is the legal property of its developers, whose names
849+ * are too numerous to list here. Please refer to the COPYRIGHT
850+ * file distributed with this source distribution.
851+ *
852+ * This program is free software; you can redistribute it and/or
853+ * modify it under the terms of the GNU General Public License
854+ * as published by the Free Software Foundation; either version 2
855+ * of the License, or (at your option) any later version.
856+
857+ * This program is distributed in the hope that it will be useful,
858+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
859+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
860+ * GNU General Public License for more details.
861+
862+ * You should have received a copy of the GNU General Public License
863+ * along with this program; if not, write to the Free Software
864+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
865+ */
866+
867+#include "osystem.h"
868+#include "gx_supp.h"
869+
870+#define MAX_FPS 30
871+
872+enum GraphicModeID {
873+ GM_DEFAULT
874+};
875+
876+void OSystem_Wii::initGfx() {
877+ _surface.w = 0;
878+ _surface.h = 0;
879+ _surface.pitch = 0;
880+ _surface.pixels = NULL;
881+ _surface.bytesPerPixel = 0;
882+
883+ GX_InitVideo();
884+
885+ _overlayWidth = 640;
886+ _overlayHeight = 480;
887+
888+ _overlaySize = _overlayWidth * _overlayHeight * 2;
889+ _overlayPixels = (OverlayColor *) memalign(32, _overlaySize);
890+
891+ _palette = (u16 *) memalign(32, 256 * 2);
892+ memset(_palette, 0, 256 * 2);
893+
894+ _cursorPalette = (u16 *) memalign(32, 256 * 2);
895+ memset(_cursorPalette, 0, 256 * 2);
896+
897+ _supportedGraphicsModes = new OSystem::GraphicsMode[2];
898+ _supportedGraphicsModes[0].name = strdup("gx");
899+ _supportedGraphicsModes[0].description = strdup("wii hardware scaler");
900+ _supportedGraphicsModes[0].id = GM_DEFAULT;
901+ _supportedGraphicsModes[1].name = 0;
902+ _supportedGraphicsModes[1].description = 0;
903+ _supportedGraphicsModes[1].id = 0;
904+
905+ _texture = (u16 *) memalign(32, _overlaySize);
906+
907+ GX_Start(_overlayWidth, _overlayHeight, 320, 240);
908+}
909+
910+void OSystem_Wii::deinitGfx() {
911+ TRACE(0);
912+
913+ GX_AbortFrame();
914+
915+ if (_supportedGraphicsModes) {
916+ delete[] _supportedGraphicsModes;
917+ _supportedGraphicsModes = NULL;
918+ }
919+
920+ if (_gamePixels) {
921+ free(_gamePixels);
922+ _gamePixels = NULL;
923+ }
924+
925+ if (_palette) {
926+ free(_palette);
927+ _palette = NULL;
928+ }
929+
930+ if (_overlayPixels) {
931+ free(_overlayPixels);
932+ _overlayPixels = NULL;
933+ }
934+
935+ if (_mouseCursor) {
936+ free(_mouseCursor);
937+ _mouseCursor = NULL;
938+ }
939+
940+ if (_cursorPalette) {
941+ free(_cursorPalette);
942+ _cursorPalette = NULL;
943+ }
944+
945+ if (_texture) {
946+ free(_texture);
947+ _texture = NULL;
948+ }
949+}
950+
951+const OSystem::GraphicsMode* OSystem_Wii::getSupportedGraphicsModes() const {
952+ return _supportedGraphicsModes;
953+}
954+
955+int OSystem_Wii::getDefaultGraphicsMode() const {
956+ return GM_DEFAULT;
957+}
958+
959+bool OSystem_Wii::setGraphicsMode(const char *mode) {
960+ setGraphicsMode(GM_DEFAULT);
961+
962+ return true;
963+}
964+
965+bool OSystem_Wii::setGraphicsMode(int mode) {
966+ return true;
967+}
968+
969+int OSystem_Wii::getGraphicsMode() const {
970+ return _activeGraphicsMode;
971+}
972+
973+void OSystem_Wii::initSize(uint width, uint height) {
974+ if (_gameWidth != width || _gameHeight != height) {
975+ printf("initSize %u %u\n", width, height);
976+
977+ _gameWidth = width;
978+ _gameHeight = height;
979+
980+ if(_gamePixels)
981+ free(_gamePixels);
982+
983+ _gamePixels = (u8 *) memalign(32, _gameWidth * _gameHeight);
984+
985+ if (!_overlayVisible) {
986+ _currentWidth = _gameWidth;
987+ _currentHeight = _gameHeight;
988+ updateEventScreenResolution();
989+ }
990+ }
991+}
992+
993+int16 OSystem_Wii::getWidth() {
994+ return _gameWidth;
995+}
996+
997+int16 OSystem_Wii::getHeight() {
998+ return _gameHeight;
999+}
1000+
1001+void OSystem_Wii::setPalette(const byte *colors, uint start, uint num) {
1002+ const byte *p = colors;
1003+ for (uint i = 0; i < num; ++i) {
1004+ _palette[start + i] = RGBToColor(p[0], p[1], p[2]);
1005+ p += 4;
1006+ }
1007+}
1008+
1009+void OSystem_Wii::grabPalette(byte *colors, uint start, uint num) {
1010+ byte *p = colors;
1011+ u8 r, g, b;
1012+ for (uint i = 0; i < num; ++i) {
1013+ colorToRGB(_palette[start + i], r, g, b);
1014+ p[0] = r;
1015+ p[1] = g;
1016+ p[2] = b;
1017+ p[3] = 0xff;
1018+ p += 4;
1019+ }
1020+}
1021+
1022+void OSystem_Wii::setCursorPalette(const byte *colors, uint start, uint num) {
1023+ const byte *p = colors;
1024+ for (uint i = 0; i < num; ++i) {
1025+ _cursorPalette[start + i] = RGBToColor(p[0], p[1], p[2]);
1026+ p += 4;
1027+ }
1028+
1029+ _cursorPaletteDisabled = false;
1030+}
1031+
1032+void OSystem_Wii::disableCursorPalette(bool disable) {
1033+ TRACE(disable);
1034+
1035+ _cursorPaletteDisabled = disable;
1036+}
1037+
1038+void OSystem_Wii::copyRectToScreen(const byte *buf, int pitch, int x, int y,
1039+ int w, int h) {
1040+ if (x < 0) {
1041+ w += x;
1042+ buf -= x;
1043+ x = 0;
1044+ }
1045+
1046+ if (y < 0) {
1047+ h += y;
1048+ buf -= y * pitch;
1049+ y = 0;
1050+ }
1051+
1052+ if (w > _gameWidth - x)
1053+ w = _gameWidth - x;
1054+
1055+ if (h > _gameHeight - y)
1056+ h = _gameHeight - y;
1057+
1058+ if (w <= 0 || h <= 0)
1059+ return;
1060+
1061+ byte *dst = _gamePixels + y * _gameWidth + x;
1062+ if (_gameWidth == pitch && pitch == w) {
1063+ memcpy(dst, buf, h * w);
1064+ } else {
1065+ do {
1066+ memcpy(dst, buf, w);
1067+ buf += pitch;
1068+ dst += _gameWidth;
1069+ } while (--h);
1070+ }
1071+}
1072+
1073+void OSystem_Wii::updateScreen() {
1074+ static u32 x, y, h, skip;
1075+ static s16 msx, msy, mox, moy, mskip;
1076+ static u16 mpx, mpy;
1077+ static u8 *s;
1078+ static u16 *d, *p;
1079+
1080+ u32 now = getMillis();
1081+ if (now - _lastScreenUpdate < 1000 / MAX_FPS)
1082+ return;
1083+
1084+ _lastScreenUpdate = now;
1085+
1086+ h = 0;
1087+ if (_overlayVisible) {
1088+ memcpy(_texture, _overlayPixels, _overlaySize);
1089+ } else {
1090+ for (y = 0; y < _gameHeight; ++y) {
1091+ for (x = 0; x < _gameWidth; ++x)
1092+ _texture[h + x] = _palette[_gamePixels[h + x]];
1093+
1094+ h += _gameWidth;
1095+ }
1096+ }
1097+
1098+ if (_mouseVisible) {
1099+ msx = _mouseX - _mouseHotspotX;
1100+ msy = _mouseY - _mouseHotspotY;
1101+ mox = 0;
1102+ moy = 0;
1103+ mpx = _mouseWidth;
1104+ mpy = _mouseHeight;
1105+
1106+ if (msx < 0) {
1107+ mox = -msx;
1108+ mpx -= mox;
1109+ msx = 0;
1110+ } else
1111+ if (msx + mpx > _currentWidth - 1)
1112+ mpx = _currentWidth - msx - 1;
1113+
1114+ if (msy < 0) {
1115+ moy = -msy;
1116+ mpy -= moy;
1117+ msy = 0;
1118+ } else
1119+ if (msy + mpy + 1 > _currentHeight - 1)
1120+ mpy = _currentHeight - msy - 1;
1121+
1122+
1123+ if (_cursorPaletteDisabled)
1124+ p = _palette;
1125+ else
1126+ p = _cursorPalette;
1127+
1128+ skip = _currentWidth - mpx;
1129+ mskip = _mouseWidth - mpx;
1130+
1131+ s = _mouseCursor + moy * _mouseWidth + mox;
1132+ d = _texture + (msy * _currentWidth + msx);
1133+
1134+ for (y = 0; y < mpy; ++y) {
1135+ for (x = 0; x < mpx; ++x) {
1136+ if (*s == _mouseKeyColor) {
1137+ s++;
1138+ d++;
1139+
1140+ continue;
1141+ }
1142+
1143+ *d++ = p[*s];
1144+ s++;
1145+ }
1146+
1147+ d += skip;
1148+ s += mskip;
1149+ }
1150+ }
1151+
1152+ GX_Render(_currentWidth, _currentHeight, (u8 *) _texture,
1153+ _currentWidth * 2);
1154+}
1155+
1156+Graphics::Surface *OSystem_Wii::lockScreen() {
1157+ TRACE(0);
1158+
1159+ _surface.pixels = _gamePixels;
1160+ _surface.w = _gameWidth;
1161+ _surface.h = _gameHeight;
1162+ _surface.pitch = _gameWidth;
1163+ _surface.bytesPerPixel = 1;
1164+
1165+ return &_surface;
1166+}
1167+
1168+void OSystem_Wii::unlockScreen() {
1169+ TRACE(0);
1170+}
1171+
1172+void OSystem_Wii::setShakePos(int shakeOffset) {
1173+ TRACE(shakeOffset);
1174+}
1175+
1176+void OSystem_Wii::showOverlay() {
1177+ TRACE(1);
1178+
1179+ _mouseX = _overlayWidth / 2;
1180+ _mouseY = _overlayHeight / 2;
1181+ _overlayVisible = true;
1182+ _currentWidth = _overlayWidth;
1183+ _currentHeight = _overlayHeight;
1184+
1185+ updateEventScreenResolution();
1186+}
1187+
1188+void OSystem_Wii::hideOverlay() {
1189+ TRACE(0);
1190+
1191+ _mouseX = _gameWidth / 2;
1192+ _mouseY = _gameHeight / 2;
1193+ _overlayVisible = false;
1194+ _currentWidth = _gameWidth;
1195+ _currentHeight = _gameHeight;
1196+
1197+ updateEventScreenResolution();
1198+}
1199+
1200+void OSystem_Wii::clearOverlay() {
1201+ memset(_overlayPixels, 0, _overlaySize);
1202+}
1203+
1204+void OSystem_Wii::grabOverlay(OverlayColor *buf, int pitch) {
1205+ int h = _overlayHeight;
1206+ OverlayColor *src = _overlayPixels;
1207+
1208+ do {
1209+ memcpy(buf, src, _overlayWidth * sizeof(OverlayColor));
1210+ src += _overlayWidth;
1211+ buf += pitch;
1212+ } while (--h);
1213+}
1214+
1215+void OSystem_Wii::copyRectToOverlay(const OverlayColor *buf, int pitch, int x,
1216+ int y, int w, int h) {
1217+ if (x < 0) {
1218+ w += x;
1219+ buf -= x;
1220+ x = 0;
1221+ }
1222+
1223+ if (y < 0) {
1224+ h += y;
1225+ buf -= y * pitch;
1226+ y = 0;
1227+ }
1228+
1229+ if (w > _overlayWidth - x)
1230+ w = _overlayWidth - x;
1231+
1232+ if (h > _overlayHeight - y)
1233+ h = _overlayHeight - y;
1234+
1235+ if (w <= 0 || h <= 0)
1236+ return;
1237+
1238+ OverlayColor *dst = _overlayPixels + (y * _overlayWidth + x);
1239+ if (_overlayWidth == pitch && pitch == w) {
1240+ memcpy(dst, buf, h * w * sizeof(OverlayColor));
1241+ } else {
1242+ do {
1243+ memcpy(dst, buf, w * sizeof(OverlayColor));
1244+ buf += pitch;
1245+ dst += _overlayWidth;
1246+ } while (--h);
1247+ }
1248+}
1249+
1250+int16 OSystem_Wii::getOverlayWidth() {
1251+ return _overlayWidth;
1252+}
1253+
1254+int16 OSystem_Wii::getOverlayHeight() {
1255+ return _overlayHeight;
1256+}
1257+
1258+OverlayColor OSystem_Wii::RGBToColor(uint8 r, uint8 g, uint8 b) {
1259+ return (((r >> 3) & 0x1f) << 11) | (((g >> 2) & 0x3f) << 5 ) |
1260+ ((b >> 3) & 0x1f);
1261+}
1262+
1263+void OSystem_Wii::colorToRGB(OverlayColor color, uint8 &r, uint8 &g, uint8 &b) {
1264+ r = ((color >> 11) & 0x1f) << 3;
1265+ g = ((color >> 5) & 0x3f) << 2;
1266+ b = (color & 0x1f) << 3;
1267+}
1268+
1269+OverlayColor OSystem_Wii::ARGBToColor(uint8 a, uint8 r, uint8 g, uint8 b) {
1270+ TRACE(0);
1271+ return RGBToColor(r, g, b);
1272+}
1273+
1274+void OSystem_Wii::colorToARGB(OverlayColor color, uint8 &a, uint8 &r, uint8 &g,
1275+ uint8 &b) {
1276+ TRACE(0);
1277+ a = 0xff;
1278+ colorToRGB(color, r, g, b);
1279+}
1280+
1281+bool OSystem_Wii::showMouse(bool visible) {
1282+ bool last = _mouseVisible;
1283+ _mouseVisible = visible;
1284+
1285+ return last;
1286+}
1287+
1288+void OSystem_Wii::warpMouse(int x, int y) {
1289+ _mouseX = x;
1290+ _mouseY = y;
1291+}
1292+
1293+void OSystem_Wii::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX,
1294+ int hotspotY, byte keycolor,
1295+ int cursorTargetScale) {
1296+ (void) cursorTargetScale; // TODO
1297+
1298+ _mouseWidth = w;
1299+ _mouseHeight = h;
1300+ _mouseHotspotX = hotspotX;
1301+ _mouseHotspotY = hotspotY;
1302+ _mouseKeyColor = keycolor;
1303+
1304+ if (_mouseCursor)
1305+ free(_mouseCursor);
1306+
1307+ _mouseCursor = (u8 *) memalign(32, w * h);
1308+ memcpy(_mouseCursor, buf, w * h);
1309+}
1310+
1311Index: backends/platform/wii/osystem_events.cpp
1312===================================================================
1313--- backends/platform/wii/osystem_events.cpp (revision 0)
1314+++ backends/platform/wii/osystem_events.cpp (revision 0)
1315@@ -0,0 +1,327 @@
1316+/* ScummVM - Graphic Adventure Engine
1317+ *
1318+ * ScummVM is the legal property of its developers, whose names
1319+ * are too numerous to list here. Please refer to the COPYRIGHT
1320+ * file distributed with this source distribution.
1321+ *
1322+ * This program is free software; you can redistribute it and/or
1323+ * modify it under the terms of the GNU General Public License
1324+ * as published by the Free Software Foundation; either version 2
1325+ * of the License, or (at your option) any later version.
1326+
1327+ * This program is distributed in the hope that it will be useful,
1328+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1329+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1330+ * GNU General Public License for more details.
1331+
1332+ * You should have received a copy of the GNU General Public License
1333+ * along with this program; if not, write to the Free Software
1334+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1335+ */
1336+
1337+#include <unistd.h>
1338+
1339+#ifndef GAMECUBE
1340+#include <wiiuse/wpad.h>
1341+#endif
1342+
1343+#include <ogc/lwp_watchdog.h>
1344+
1345+#include "osystem.h"
1346+
1347+#define TIMER_THREAD_STACKSIZE (1024 * 32)
1348+#define TIMER_THREAD_PRIO 64
1349+
1350+#define PAD_CHECK_TIME 40
1351+
1352+#ifndef GAMECUBE
1353+#define PADS_A (PAD_BUTTON_A | (WPAD_BUTTON_A << 16))
1354+#define PADS_B (PAD_BUTTON_B | (WPAD_BUTTON_B << 16))
1355+#define PADS_X (PAD_BUTTON_X | (WPAD_BUTTON_MINUS << 16))
1356+#define PADS_Y (PAD_BUTTON_Y | (WPAD_BUTTON_PLUS << 16))
1357+#define PADS_Z (PAD_TRIGGER_Z | (WPAD_BUTTON_2 << 16))
1358+#define PADS_START (PAD_BUTTON_START | (WPAD_BUTTON_HOME << 16))
1359+#define PADS_UP (PAD_BUTTON_UP | (WPAD_BUTTON_UP << 16))
1360+#define PADS_DOWN (PAD_BUTTON_DOWN | (WPAD_BUTTON_DOWN << 16))
1361+#define PADS_LEFT (PAD_BUTTON_LEFT | (WPAD_BUTTON_LEFT << 16))
1362+#define PADS_RIGHT (PAD_BUTTON_RIGHT | (WPAD_BUTTON_RIGHT << 16))
1363+#else
1364+#define PADS_A PAD_BUTTON_A
1365+#define PADS_B PAD_BUTTON_B
1366+#define PADS_X PAD_BUTTON_X
1367+#define PADS_Y PAD_BUTTON_Y
1368+#define PADS_Z PAD_TRIGGER_Z
1369+#define PADS_START PAD_BUTTON_START
1370+#define PADS_UP PAD_BUTTON_UP
1371+#define PADS_DOWN PAD_BUTTON_DOWN
1372+#define PADS_LEFT PAD_BUTTON_LEFT
1373+#define PADS_RIGHT PAD_BUTTON_RIGHT
1374+#endif
1375+
1376+static lwpq_t timer_queue;
1377+static lwp_t timer_thread;
1378+static u8 *timer_stack;
1379+static bool timer_thread_running = false;
1380+static bool timer_thread_quit = false;
1381+
1382+static void * timer_thread_func(void *arg) {
1383+ while (!timer_thread_quit) {
1384+ DefaultTimerManager *tm =
1385+ (DefaultTimerManager *) g_system->getTimerManager();
1386+ tm->handler();
1387+
1388+ usleep(1000 * 10);
1389+ }
1390+
1391+ return NULL;
1392+}
1393+
1394+#ifndef GAMECUBE
1395+// smoothing algorithm by marcan, thx buddy!
1396+// the following license applies to smooth_ir()
1397+
1398+/*-------------------------------------------------------------
1399+
1400+Copyright (C) 2008
1401+Hector Martin (marcan)
1402+
1403+This software is provided 'as-is', without any express or implied
1404+warranty. In no event will the authors be held liable for any
1405+damages arising from the use of this software.
1406+
1407+Permission is granted to anyone to use this software for any
1408+purpose, including commercial applications, and to alter it and
1409+redistribute it freely, subject to the following restrictions:
1410+
1411+1. The origin of this software must not be misrepresented; you
1412+must not claim that you wrote the original software. If you use
1413+this software in a product, an acknowledgment in the product
1414+documentation would be appreciated but is not required.
1415+
1416+2. Altered source versions must be plainly marked as such, and
1417+must not be misrepresented as being the original software.
1418+
1419+3. This notice may not be removed or altered from any source
1420+distribution.
1421+
1422+-------------------------------------------------------------*/
1423+
1424+#define SMOOTH_IR_RADIUS 8.0f
1425+#define SMOOTH_IR_SPEED 0.25f
1426+#define SMOOTH_IR_DEADZONE 2.5f
1427+#define SMOOTH_IR_ERRCNT 3
1428+
1429+u32 smooth_ir(const WPADData *wpad, s32 *sx, s32 *sy) {
1430+ static u32 errors = SMOOTH_IR_ERRCNT;
1431+ static f32 cx = 0.0, cy = 0.0;
1432+
1433+ f32 dx, dy, d, theta;
1434+
1435+ // wiiuse likes to return (0,0) when things are screwy but tracking
1436+ // isn't totally lost so we filter it out here
1437+ if ((wpad->err == WPAD_ERR_NONE) && (wpad->ir.num_dots > 1) &&
1438+ (wpad->ir.x != 0 || wpad->ir.y != 0)) {
1439+ if (errors >= SMOOTH_IR_ERRCNT) {
1440+ cx = wpad->ir.x;
1441+ cy = wpad->ir.y;
1442+ }
1443+
1444+ errors = 0;
1445+
1446+ dx = (f32)wpad->ir.x - cx;
1447+ dy = (f32)wpad->ir.y - cy;
1448+ d = sqrtf(dx*dx + dy*dy);
1449+
1450+ if (d > SMOOTH_IR_DEADZONE) {
1451+ theta = atan2f(dy, dx);
1452+
1453+ if (d < SMOOTH_IR_RADIUS) {
1454+ cx += dx * SMOOTH_IR_SPEED;
1455+ cy += dy * SMOOTH_IR_SPEED;
1456+ } else {
1457+ cx = (f32)wpad->ir.x - cosf(theta) * SMOOTH_IR_RADIUS;
1458+ cy = (f32)wpad->ir.y - sinf(theta) * SMOOTH_IR_RADIUS;
1459+ }
1460+ }
1461+
1462+ *sx = (s32)cx;
1463+ *sy = (s32)cy;
1464+
1465+ return true;
1466+ } else {
1467+ if (errors < SMOOTH_IR_ERRCNT)
1468+ errors++;
1469+
1470+ return false;
1471+ }
1472+}
1473+#endif
1474+
1475+void OSystem_Wii::initEvents() {
1476+ TRACE(0);
1477+
1478+ timer_thread_quit = false;
1479+
1480+ timer_stack = (u8 *) memalign(32, TIMER_THREAD_STACKSIZE);
1481+ memset(timer_stack, 0, TIMER_THREAD_STACKSIZE);
1482+
1483+ LWP_InitQueue(&timer_queue);
1484+
1485+ s32 res = LWP_CreateThread(&timer_thread, timer_thread_func, NULL,
1486+ timer_stack, TIMER_THREAD_STACKSIZE,
1487+ TIMER_THREAD_PRIO);
1488+
1489+ if (res) {
1490+ printf("ERROR creating timer thread: %d\n", res);
1491+ LWP_CloseQueue(timer_queue);
1492+ }
1493+
1494+ timer_thread_running = res == 0;
1495+
1496+#ifndef GAMECUBE
1497+ WPAD_Init();
1498+ WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_CORE_ACC_IR);
1499+ WPAD_SetSleepTime(30);
1500+#endif
1501+}
1502+
1503+void OSystem_Wii::deinitEvents() {
1504+ TRACE(0);
1505+
1506+ if (timer_thread_running) {
1507+ timer_thread_quit = true;
1508+ LWP_ThreadBroadcast(timer_queue);
1509+
1510+ LWP_JoinThread(timer_thread, NULL);
1511+ LWP_CloseQueue(timer_queue);
1512+
1513+ timer_thread_running = false;
1514+ }
1515+
1516+#ifndef GAMECUBE
1517+ WPAD_Shutdown();
1518+#endif
1519+}
1520+
1521+void OSystem_Wii::updateEventScreenResolution() {
1522+#ifndef GAMECUBE
1523+ WPAD_SetVRes(WPAD_CHAN_0, _currentWidth, _currentHeight);
1524+#endif
1525+}
1526+
1527+#define KBD_EVENT(pad_button, kbd_keycode, kbd_ascii) \
1528+ do { \
1529+ if ((bd | bu) & pad_button) { \
1530+ if (bd & pad_button) \
1531+ event.type = Common::EVENT_KEYDOWN; \
1532+ else \
1533+ event.type = Common::EVENT_KEYUP; \
1534+ event.kbd.keycode = kbd_keycode; \
1535+ event.kbd.ascii = kbd_ascii; \
1536+ return true; \
1537+ } \
1538+ } while (0)
1539+
1540+bool OSystem_Wii::pollEvent(Common::Event &event) {
1541+ u32 bd, bh, bu;
1542+ PAD_ScanPads();
1543+
1544+ bd = PAD_ButtonsDown(0);
1545+ bh = PAD_ButtonsHeld(0);
1546+ bu = PAD_ButtonsUp(0);
1547+
1548+#ifndef GAMECUBE
1549+ if (WPAD_GetStatus() == WPAD_STATE_ENABLED) {
1550+ WPAD_ScanPads();
1551+
1552+ bd |= ((u32) (WPAD_ButtonsDown(0))) << 16;
1553+ bh |= ((u32) (WPAD_ButtonsHeld(0))) << 16;
1554+ bu |= ((u32) (WPAD_ButtonsUp(0))) << 16;
1555+ }
1556+#endif
1557+
1558+ if (bd || bu) {
1559+ if (bh & PADS_UP)
1560+ event.kbd.flags = Common::KBD_SHIFT;
1561+
1562+ KBD_EVENT(PADS_Z, Common::KEYCODE_RETURN, Common::ASCII_RETURN);
1563+
1564+ KBD_EVENT(PADS_X, Common::KEYCODE_ESCAPE, Common::ASCII_ESCAPE);
1565+
1566+ KBD_EVENT(PADS_Y, Common::KEYCODE_PERIOD, '.');
1567+
1568+ KBD_EVENT(PADS_START, Common::KEYCODE_F5, Common::ASCII_F5);
1569+
1570+ KBD_EVENT(PADS_UP, Common::KEYCODE_LSHIFT, 0);
1571+
1572+ KBD_EVENT(PADS_LEFT, Common::KEYCODE_0, '0');
1573+
1574+ if ((bd | bu) & (PADS_A | PADS_B)) {
1575+ if (bd & PADS_A)
1576+ event.type = Common::EVENT_LBUTTONDOWN;
1577+ else if (bu & PADS_A)
1578+ event.type = Common::EVENT_LBUTTONUP;
1579+ else if (bd & PADS_B)
1580+ event.type = Common::EVENT_RBUTTONDOWN;
1581+ else if (bu & PADS_B)
1582+ event.type = Common::EVENT_RBUTTONUP;
1583+
1584+ event.mouse.x = _mouseX;
1585+ event.mouse.y = _mouseY;
1586+
1587+ return true;
1588+ }
1589+ }
1590+
1591+ s32 mx = _mouseX;
1592+ s32 my = _mouseY;
1593+
1594+#ifndef GAMECUBE
1595+ if ((WPAD_GetStatus() == WPAD_STATE_ENABLED) &&
1596+ (WPAD_Probe(0, NULL) == WPAD_ERR_NONE)) {
1597+ WPADData wpad;
1598+
1599+ WPAD_Read(0, &wpad);
1600+
1601+ if (smooth_ir(&wpad, &mx, &my)) {
1602+ if ((mx != _mouseX) || (my != _mouseY)) {
1603+ event.type = Common::EVENT_MOUSEMOVE;
1604+ event.mouse.x = _mouseX = mx;
1605+ event.mouse.y = _mouseY = my;
1606+
1607+ return true;
1608+ }
1609+ }
1610+ }
1611+#endif
1612+
1613+ uint32 time = getMillis();
1614+ if (time - _lastPadCheck > PAD_CHECK_TIME) {
1615+ _lastPadCheck = time;
1616+
1617+ if (abs (PAD_StickX(0)) > 16)
1618+ mx += PAD_StickX(0) / (4 * _overlayWidth / _currentWidth);
1619+ if (abs (PAD_StickY(0)) > 16)
1620+ my -= PAD_StickY(0) / (4 * _overlayHeight / _currentHeight);
1621+
1622+ if (mx < 0)
1623+ mx = 0;
1624+ if (mx >= _currentWidth)
1625+ mx = _currentWidth - 1;
1626+ if (my < 0)
1627+ my = 0;
1628+ if (my >= _currentHeight - 1)
1629+ my = _currentHeight - 1;
1630+
1631+ if ((mx != _mouseX) || (my != _mouseY)) {
1632+ event.type = Common::EVENT_MOUSEMOVE;
1633+ event.mouse.x = _mouseX = mx;
1634+ event.mouse.y = _mouseY = my;
1635+
1636+ return true;
1637+ }
1638+ }
1639+
1640+ return false;
1641+}
1642+
1643Index: backends/platform/wii/osystem.h
1644===================================================================
1645--- backends/platform/wii/osystem.h (revision 0)
1646+++ backends/platform/wii/osystem.h (revision 0)
1647@@ -0,0 +1,163 @@
1648+/* ScummVM - Graphic Adventure Engine
1649+ *
1650+ * ScummVM is the legal property of its developers, whose names
1651+ * are too numerous to list here. Please refer to the COPYRIGHT
1652+ * file distributed with this source distribution.
1653+ *
1654+ * This program is free software; you can redistribute it and/or
1655+ * modify it under the terms of the GNU General Public License
1656+ * as published by the Free Software Foundation; either version 2
1657+ * of the License, or (at your option) any later version.
1658+
1659+ * This program is distributed in the hope that it will be useful,
1660+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1661+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1662+ * GNU General Public License for more details.
1663+
1664+ * You should have received a copy of the GNU General Public License
1665+ * along with this program; if not, write to the Free Software
1666+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1667+ */
1668+
1669+#ifndef _WII_OSYSTEM_H_
1670+#define _WII_OSYSTEM_H_
1671+
1672+#include "common/system.h"
1673+#include "base/main.h"
1674+
1675+#include "common/rect.h"
1676+#include "common/events.h"
1677+
1678+#include "backends/saves/default/default-saves.h"
1679+#include "backends/timer/default/default-timer.h"
1680+#include "graphics/surface.h"
1681+#include "sound/mixer.h"
1682+
1683+#include <gctypes.h>
1684+#include <gccore.h>
1685+#include <ogcsys.h>
1686+
1687+class OSystem_Wii : public OSystem {
1688+private:
1689+ s64 _startup_time;
1690+ syswd_t _alarm;
1691+
1692+ u16 *_palette;
1693+ u16 *_cursorPalette;
1694+ bool _cursorPaletteDisabled;
1695+
1696+ u16 _gameWidth, _gameHeight;
1697+ u8 *_gamePixels;
1698+ Graphics::Surface _surface;
1699+
1700+ bool _overlayVisible;
1701+ u16 _overlayWidth, _overlayHeight;
1702+ u32 _overlaySize;
1703+ OverlayColor *_overlayPixels;
1704+
1705+ u32 _lastScreenUpdate;
1706+ u16 *_texture;
1707+ u16 _currentWidth, _currentHeight;
1708+
1709+ OSystem::GraphicsMode *_supportedGraphicsModes;
1710+ s32 _activeGraphicsMode;
1711+
1712+ bool _mouseVisible;
1713+ s32 _mouseX, _mouseY;
1714+ u32 _mouseWidth, _mouseHeight;
1715+ s32 _mouseHotspotX, _mouseHotspotY;
1716+ u8 _mouseKeyColor;
1717+ u8 *_mouseCursor;
1718+
1719+ u32 _lastPadCheck;
1720+
1721+ void initGfx();
1722+ void deinitGfx();
1723+
1724+ void initSfx();
1725+ void deinitSfx();
1726+
1727+ void initEvents();
1728+ void deinitEvents();
1729+ void updateEventScreenResolution();
1730+
1731+protected:
1732+ Common::SaveFileManager *_savefile;
1733+ Audio::Mixer *_mixer;
1734+ DefaultTimerManager *_timer;
1735+
1736+public:
1737+ OSystem_Wii();
1738+ virtual ~OSystem_Wii();
1739+
1740+ virtual void initBackend();
1741+
1742+ virtual bool hasFeature(Feature f);
1743+ virtual void setFeatureState(Feature f, bool enable);
1744+ virtual bool getFeatureState(Feature f);
1745+ virtual const GraphicsMode *getSupportedGraphicsModes() const;
1746+ virtual int getDefaultGraphicsMode() const;
1747+ bool setGraphicsMode(const char *name);
1748+ virtual bool setGraphicsMode(int mode);
1749+ virtual int getGraphicsMode() const;
1750+ virtual void initSize(uint width, uint height);
1751+ virtual int16 getWidth();
1752+ virtual int16 getHeight();
1753+ virtual void setPalette(const byte *colors, uint start, uint num);
1754+ virtual void grabPalette(byte *colors, uint start, uint num);
1755+ virtual void setCursorPalette(const byte *colors, uint start, uint num);
1756+ virtual void disableCursorPalette(bool disable);
1757+ virtual void copyRectToScreen(const byte *buf, int pitch, int x, int y,
1758+ int w, int h);
1759+ virtual void updateScreen();
1760+ virtual Graphics::Surface *lockScreen();
1761+ virtual void unlockScreen();
1762+ virtual void setShakePos(int shakeOffset);
1763+
1764+ virtual void showOverlay();
1765+ virtual void hideOverlay();
1766+ virtual void clearOverlay();
1767+ virtual void grabOverlay(OverlayColor *buf, int pitch);
1768+ virtual void copyRectToOverlay(const OverlayColor *buf, int pitch,
1769+ int x, int y, int w, int h);
1770+ virtual int16 getOverlayWidth();
1771+ virtual int16 getOverlayHeight();
1772+
1773+ virtual OverlayColor RGBToColor(uint8 r, uint8 g, uint8 b);
1774+ virtual void colorToRGB(OverlayColor color, uint8 &r, uint8 &g, uint8 &b);
1775+ virtual OverlayColor ARGBToColor(uint8 a, uint8 r, uint8 g, uint8 b);
1776+ virtual void colorToARGB(OverlayColor color, uint8 &a, uint8 &r,
1777+ uint8 &g, uint8 &b);
1778+
1779+ virtual bool showMouse(bool visible);
1780+
1781+ virtual void warpMouse(int x, int y);
1782+ virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX,
1783+ int hotspotY, byte keycolor = 255,
1784+ int cursorTargetScale = 1);
1785+
1786+ virtual bool pollEvent(Common::Event &event);
1787+ virtual uint32 getMillis();
1788+ virtual void delayMillis(uint msecs);
1789+
1790+ virtual MutexRef createMutex();
1791+ virtual void lockMutex(MutexRef mutex);
1792+ virtual void unlockMutex(MutexRef mutex);
1793+ virtual void deleteMutex(MutexRef mutex);
1794+
1795+ typedef void (*SoundProc)(void *param, byte *buf, int len);
1796+ virtual int getOutputSampleRate() const;
1797+
1798+ virtual void quit();
1799+
1800+ virtual void setWindowCaption(const char *caption);
1801+
1802+ virtual Common::SaveFileManager *getSavefileManager();
1803+ virtual Audio::Mixer *getMixer();
1804+ virtual Common::TimerManager *getTimerManager();
1805+ FilesystemFactory *getFilesystemFactory();
1806+ void getTimeAndDate(struct tm &t) const;
1807+};
1808+
1809+#endif
1810+
1811Index: backends/platform/wii/gecko_console.cpp
1812===================================================================
1813--- backends/platform/wii/gecko_console.cpp (revision 0)
1814+++ backends/platform/wii/gecko_console.cpp (revision 0)
1815@@ -0,0 +1,90 @@
1816+/*-------------------------------------------------------------
1817+
1818+Copyright (C) 2008
1819+Hector Martin (marcan)
1820+
1821+This software is provided 'as-is', without any express or implied
1822+warranty. In no event will the authors be held liable for any
1823+damages arising from the use of this software.
1824+
1825+Permission is granted to anyone to use this software for any
1826+purpose, including commercial applications, and to alter it and
1827+redistribute it freely, subject to the following restrictions:
1828+
1829+1. The origin of this software must not be misrepresented; you
1830+must not claim that you wrote the original software. If you use
1831+this software in a product, an acknowledgment in the product
1832+documentation would be appreciated but is not required.
1833+
1834+2. Altered source versions must be plainly marked as such, and
1835+must not be misrepresented as being the original software.
1836+
1837+3. This notice may not be removed or altered from any source
1838+distribution.
1839+
1840+-------------------------------------------------------------*/
1841+
1842+#include <stdio.h>
1843+#include <sys/iosupport.h>
1844+#include <ogcsys.h>
1845+#include <gccore.h>
1846+#include <reent.h>
1847+
1848+#include "gecko_console.h"
1849+
1850+#ifdef __cplusplus
1851+extern "C" {
1852+#endif
1853+
1854+static const devoptab_t *dotab_console;
1855+int usb_sendbuffer_safe(s32 chn,const void *buffer,int size);
1856+int usb_sendbuffer(s32 chn,const void *buffer,int size);
1857+
1858+int __gecko_write(struct _reent *r,int fd,const char *ptr,int len) {
1859+ char *tmp = (char*)ptr;
1860+ u32 level;
1861+ if(dotab_console)
1862+ dotab_console->write_r(r,fd,ptr,len);
1863+
1864+ if(!tmp || len<=0) return -1;
1865+ level = IRQ_Disable();
1866+ usb_sendbuffer(1, ptr, len);
1867+ IRQ_Restore(level);
1868+ return len;
1869+}
1870+
1871+const devoptab_t dotab_gecko = {
1872+ "stdout", // device name
1873+ 0, // size of file structure
1874+ NULL, // device open
1875+ NULL, // device close
1876+ __gecko_write, // device write
1877+ NULL, // device read
1878+ NULL, // device seek
1879+ NULL, // device fstat
1880+ NULL, // device stat
1881+ NULL, // device link
1882+ NULL, // device unlink
1883+ NULL, // device chdir
1884+ NULL, // device rename
1885+ NULL, // device mkdir
1886+ 0, // dirStateSize
1887+ NULL, // device diropen_r
1888+ NULL, // device dirreset_r
1889+ NULL, // device dirnext_r
1890+ NULL, // device dirclose_r
1891+ NULL // device statvfs_r
1892+};
1893+
1894+void gecko_console_init(int chain) {
1895+ dotab_console = NULL;
1896+ if(chain)
1897+ dotab_console = devoptab_list[STD_OUT];
1898+ devoptab_list[STD_OUT] = &dotab_gecko;
1899+ devoptab_list[STD_ERR] = &dotab_gecko;
1900+}
1901+
1902+#ifdef __cplusplus
1903+}
1904+#endif
1905+
1906Index: backends/platform/wii/gx_supp.h
1907===================================================================
1908--- backends/platform/wii/gx_supp.h (revision 0)
1909+++ backends/platform/wii/gx_supp.h (revision 0)
1910@@ -0,0 +1,39 @@
1911+/****************************************************************************
1912+* Generic GX Scaler
1913+* softdev 2007
1914+*
1915+* This program is free software; you can redistribute it and/or modify
1916+* it under the terms of the GNU General Public License as published by
1917+* the Free Software Foundation; either version 2 of the License, or
1918+* (at your option) any later version.
1919+*
1920+* This program is distributed in the hope that it will be useful,
1921+* but WITHOUT ANY WARRANTY; without even the implied warranty of
1922+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1923+* GNU General Public License for more details.
1924+*
1925+* You should have received a copy of the GNU General Public License along
1926+* with this program; if not, write to the Free Software Foundation, Inc.,
1927+* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1928+*
1929+* NGC GX Video Functions
1930+*
1931+* These are pretty standard functions to setup and use GX scaling.
1932+****************************************************************************/
1933+#ifndef _WII_GX_SUPP_H_
1934+#define _WII_GX_SUPP_H_
1935+
1936+#ifdef __cplusplus
1937+extern "C" {
1938+#endif
1939+
1940+void GX_InitVideo();
1941+
1942+void GX_Start(u16 width, u16 height, s16 haspect, s16 vaspect);
1943+void GX_Render(u16 width, u16 height, u8 *buffer, u16 pitch);
1944+
1945+#ifdef __cplusplus
1946+}
1947+#endif
1948+
1949+#endif
1950Index: backends/platform/wii/portdefs.h
1951===================================================================
1952--- backends/platform/wii/portdefs.h (revision 0)
1953+++ backends/platform/wii/portdefs.h (revision 0)
1954@@ -0,0 +1,44 @@
1955+/* ScummVM - Graphic Adventure Engine
1956+ *
1957+ * ScummVM is the legal property of its developers, whose names
1958+ * are too numerous to list here. Please refer to the COPYRIGHT
1959+ * file distributed with this source distribution.
1960+ *
1961+ * This program is free software; you can redistribute it and/or
1962+ * modify it under the terms of the GNU General Public License
1963+ * as published by the Free Software Foundation; either version 2
1964+ * of the License, or (at your option) any later version.
1965+
1966+ * This program is distributed in the hope that it will be useful,
1967+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1968+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1969+ * GNU General Public License for more details.
1970+
1971+ * You should have received a copy of the GNU General Public License
1972+ * along with this program; if not, write to the Free Software
1973+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1974+ */
1975+
1976+#ifndef PORTDEFS_H
1977+#define PORTDEFS_H
1978+
1979+#include <stdio.h>
1980+#include <stdlib.h>
1981+#include <string.h>
1982+#include <stdarg.h>
1983+#include <malloc.h>
1984+#include <math.h>
1985+#include <time.h>
1986+#include <ctype.h>
1987+#include <assert.h>
1988+
1989+#define DATA_PATH "/scummvm"
1990+
1991+#ifdef DEBUG_WII
1992+#define TRACE(x) printf("passing '%s' (%d): %d\n", __FUNCTION__, __LINE__, x);
1993+#else
1994+#define TRACE(x)
1995+#endif
1996+
1997+#endif /* PORTDEFS_H */
1998+
1999Index: backends/platform/wii/Makefile
2000===================================================================
2001--- backends/platform/wii/Makefile (revision 0)
2002+++ backends/platform/wii/Makefile (revision 0)
2003@@ -0,0 +1,160 @@
2004+DEBUG_WII = 1
2005+
2006+ENABLE_SCUMM = 1
2007+ENABLE_SCUMM_7_8 = 1
2008+ENABLE_HE = 1
2009+# ENABLE_AGI = 1
2010+ENABLE_AGOS = 1
2011+ENABLE_CINE = 1
2012+ENABLE_CRUISE = 1
2013+ENABLE_DRASCULA = 1
2014+ENABLE_GOB = 1
2015+ENABLE_IGOR = 1
2016+ENABLE_KYRA = 1
2017+ENABLE_LURE = 1
2018+ENABLE_M4 = 1
2019+ENABLE_MADE = 1
2020+ENABLE_PARALLACTION = 1
2021+ENABLE_QUEEN = 1
2022+ENABLE_SAGA = 1
2023+ENABLE_SKY = 1
2024+ENABLE_SWORD1 = 1
2025+ENABLE_SWORD2 = 1
2026+ENABLE_TOUCHE = 1
2027+
2028+DISABLE_HQ_SCALERS = 1
2029+DISABLE_SCALERS = 1
2030+
2031+USE_ZLIB = 1
2032+USE_MAD = 1
2033+USE_TREMOR = 1
2034+USE_FLAC = 1
2035+USE_MPEG2 = 1
2036+USE_MT32EMU = 1
2037+
2038+srcdir = ../../..
2039+VPATH = $(srcdir)
2040+HAVE_GCC3 = 1
2041+
2042+THEMEPATH = $(srcdir)/gui/themes
2043+EDPATH = $(srcdir)/dists/engine-data
2044+DISTPATH = $(srcdir)/dists/wii
2045+
2046+ifeq ($(strip $(DEVKITPPC)),)
2047+$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
2048+endif
2049+
2050+PREFIX = $(DEVKITPPC)/bin/powerpc-gekko-
2051+CXX = $(PREFIX)g++
2052+AS = $(PREFIX)gcc
2053+LD = $(PREFIX)gcc
2054+AR = $(PREFIX)ar cru
2055+RANLIB = $(PREFIX)ranlib
2056+STRIP = $(PREFIX)strip -g
2057+OBJCOPY = $(PREFIX)objcopy
2058+MKDIR = mkdir -p
2059+RM = rm -f
2060+CP = cp -f
2061+
2062+TARGET = scummvm-wii
2063+
2064+MACHDEP = -DGEKKO -mrvl -mcpu=750 -meabi -mhard-float \
2065+ -ffunction-sections -fdata-sections -fmodulo-sched
2066+
2067+INCDIR = $(srcdir) . $(srcdir)/engines/ . $(DEVKITPRO)/libogc/include
2068+LIBDIR = . $(DEVKITPRO)/libogc/lib/wii
2069+
2070+CXXFLAGS = -g -Os -Wall $(MACHDEP) -DNONSTANDARD_PORT -D__WII__ \
2071+ -Wno-multichar -fno-exceptions -fno-rtti
2072+
2073+CXXFLAGS += $(addprefix -I,$(INCDIR))
2074+LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(TARGET).elf.map
2075+LDFLAGS += $(addprefix -L,$(LIBDIR))
2076+LIBS = -lstdc++ -lfat -lwiiuse -lbte -logc -lm
2077+
2078+CXXFLAGS += -I$(DEVKITPRO)/3rd/wii/include
2079+LDFLAGS += -L$(DEVKITPRO)/3rd/wii/lib
2080+
2081+ifdef DEBUG_WII
2082+CXXFLAGS += -DDEBUG_WII
2083+LIBS += -ldb
2084+endif
2085+
2086+ifdef USE_ZLIB
2087+CXXFLAGS += -DUSE_ZLIB
2088+LIBS += -lz
2089+endif
2090+
2091+ifdef USE_MAD
2092+CXXFLAGS += -DUSE_MAD -I$(DEVKITPRO)/libogc/include/mad
2093+LIBS += -lmad
2094+endif
2095+
2096+ifdef USE_TREMOR
2097+CXXFLAGS += -DUSE_VORBIS -DUSE_TREMOR
2098+LIBS += -lvorbisidec
2099+endif
2100+
2101+ifdef USE_FLAC
2102+CXXFLAGS += -DUSE_FLAC
2103+LIBS += -lFLAC
2104+endif
2105+
2106+ifdef USE_MPEG2
2107+CXXFLAGS += -DUSE_MPEG2
2108+LIBS += -lmpeg2
2109+endif
2110+
2111+ifdef USE_MT32EMU
2112+CXXFLAGS += -DUSE_MT32EMU
2113+endif
2114+
2115+OBJS := main.o \
2116+ gecko_console.o \
2117+ gx_supp.o \
2118+ osystem.o \
2119+ osystem_gfx.o \
2120+ osystem_sfx.o \
2121+ osystem_events.o
2122+
2123+MODULE_DIRS += .
2124+
2125+include $(srcdir)/Makefile.common
2126+
2127+.PHONY: clean distclean upload dist
2128+
2129+all: $(TARGET).dol
2130+
2131+$(TARGET).dol: $(TARGET).elf
2132+ $(OBJCOPY) -O binary $< $@
2133+
2134+$(TARGET).elf: $(OBJS)
2135+ $(LD) $^ $(LDFLAGS) $(LIBS) -o $@
2136+
2137+clean:
2138+ @-$(RM) *.o *.d $(TARGET).elf $(TARGET).elf.map $(TARGET).dol
2139+ @-$(RM) -r backends base common engines graphics gui sound
2140+
2141+distclean: clean
2142+ @-$(RM) dist
2143+
2144+upload:
2145+ $(DEVKITPPC)/bin/wiiload $(TARGET).dol
2146+
2147+dist:
2148+ $(MKDIR) dist/scummvm
2149+ $(MKDIR) dist/apps/scummvm
2150+ $(CP) $(TARGET).dol dist/apps/scummvm/boot.dol
2151+ $(CP) $(DISTPATH)/meta.xml dist/apps/scummvm/
2152+ $(CP) $(DISTPATH)/icon.png dist/apps/scummvm/
2153+ $(CP) $(DISTPATH)/READMII dist/apps/scummvm/
2154+ $(CP) $(srcdir)/AUTHORS dist/apps/scummvm/
2155+ $(CP) $(srcdir)/COPYING dist/apps/scummvm/
2156+ $(CP) $(srcdir)/COPYRIGHT dist/apps/scummvm/
2157+ $(CP) $(srcdir)/NEWS dist/apps/scummvm/
2158+ $(CP) $(srcdir)/README dist/apps/scummvm/
2159+ $(CP) $(THEMEPATH)/modern.* dist/scummvm
2160+ $(CP) $(EDPATH)/*.tbl dist/scummvm
2161+ $(CP) $(EDPATH)/*.dat dist/scummvm
2162+ $(CP) $(EDPATH)/*.cpt dist/scummvm
2163+
2164Index: backends/fs/wii/wii-fs.cpp
2165===================================================================
2166--- backends/fs/wii/wii-fs.cpp (revision 0)
2167+++ backends/fs/wii/wii-fs.cpp (revision 0)
2168@@ -0,0 +1,203 @@
2169+/* ScummVM - Graphic Adventure Engine
2170+ *
2171+ * ScummVM is the legal property of its developers, whose names
2172+ * are too numerous to list here. Please refer to the COPYRIGHT
2173+ * file distributed with this source distribution.
2174+ *
2175+ * This program is free software; you can redistribute it and/or
2176+ * modify it under the terms of the GNU General Public License
2177+ * as published by the Free Software Foundation; either version 2
2178+ * of the License, or (at your option) any later version.
2179+ *
2180+ * This program is distributed in the hope that it will be useful,
2181+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2182+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2183+ * GNU General Public License for more details.
2184+ *
2185+ * You should have received a copy of the GNU General Public License
2186+ * along with this program; if not, write to the Free Software
2187+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2188+ *
2189+ */
2190+
2191+#if defined(__WII__)
2192+
2193+#include "backends/fs/abstract-fs.h"
2194+
2195+#include <sys/dir.h>
2196+
2197+#include <sys/types.h>
2198+#include <sys/stat.h>
2199+#include <unistd.h>
2200+
2201+/**
2202+ * Implementation of the ScummVM file system API based on Wii.
2203+ *
2204+ * Parts of this class are documented in the base interface class, AbstractFilesystemNode.
2205+ */
2206+class WiiFilesystemNode : public AbstractFilesystemNode {
2207+protected:
2208+ String _displayName;
2209+ String _path;
2210+ bool _isDirectory, _isReadable, _isWritable;
2211+
2212+public:
2213+ /**
2214+ * Creates a WiiFilesystemNode with the root node as path.
2215+ */
2216+ WiiFilesystemNode();
2217+
2218+ /**
2219+ * Creates a WiiFilesystemNode for a given path.
2220+ *
2221+ * @param path String with the path the new node should point to.
2222+ * @param verify true if the isValid and isDirectory flags should be verified during the construction.
2223+ */
2224+ WiiFilesystemNode(const String &path, bool verify);
2225+
2226+ virtual bool exists() const;
2227+ virtual String getDisplayName() const { return _displayName; }
2228+ virtual String getName() const { return _displayName; }
2229+ virtual String getPath() const { return _path; }
2230+ virtual bool isDirectory() const { return _isDirectory; }
2231+ virtual bool isReadable() const { return _isReadable; }
2232+ virtual bool isWritable() const { return _isWritable; }
2233+
2234+ virtual AbstractFilesystemNode *getChild(const String &n) const;
2235+ virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const;
2236+ virtual AbstractFilesystemNode *getParent() const;
2237+
2238+private:
2239+ virtual void setFlags();
2240+};
2241+
2242+/**
2243+ * Returns the last component of a given path.
2244+ *
2245+ * Examples:
2246+ * /foo/bar.txt would return /bar.txt
2247+ * /foo/bar/ would return /bar/
2248+ *
2249+ * @param str String containing the path.
2250+ * @return Pointer to the first char of the last component inside str.
2251+ */
2252+const char *lastPathComponent(const Common::String &str) {
2253+ if(str.empty())
2254+ return "";
2255+
2256+ const char *start = str.c_str();
2257+ const char *cur = start + str.size() - 2;
2258+
2259+ while (cur >= start && *cur != '/') {
2260+ --cur;
2261+ }
2262+
2263+ return cur + 1;
2264+}
2265+
2266+void WiiFilesystemNode::setFlags() {
2267+ struct stat st;
2268+
2269+ _isDirectory = false;
2270+ _isReadable = false;
2271+ _isWritable = false;
2272+
2273+ if (!stat(_path.c_str(), &st)) {
2274+ _isDirectory = S_ISDIR(st.st_mode);
2275+ _isReadable = (st.st_mode & S_IRUSR) > 0;
2276+ _isWritable = (st.st_mode & S_IWUSR) > 0;
2277+ }
2278+}
2279+
2280+
2281+WiiFilesystemNode::WiiFilesystemNode() {
2282+ // The root dir.
2283+ _path = "/";
2284+ _displayName = _path;
2285+
2286+ setFlags();
2287+}
2288+
2289+WiiFilesystemNode::WiiFilesystemNode(const String &p, bool verify) {
2290+ assert(p.size() > 0);
2291+
2292+ _path = p;
2293+
2294+ _displayName = lastPathComponent(_path);
2295+
2296+ if (verify)
2297+ setFlags();
2298+}
2299+
2300+bool WiiFilesystemNode::exists() const {
2301+ struct stat st;
2302+ return stat(_path.c_str (), &st) == 0;
2303+}
2304+
2305+AbstractFilesystemNode *WiiFilesystemNode::getChild(const String &n) const {
2306+ assert(_isDirectory);
2307+
2308+ String newPath(_path);
2309+ if (newPath.lastChar() != '/')
2310+ newPath += '/';
2311+ newPath += n;
2312+
2313+ return new WiiFilesystemNode(newPath, true);
2314+}
2315+
2316+bool WiiFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const {
2317+ assert(_isDirectory);
2318+
2319+ DIR_ITER* dp = diropen (_path.c_str());
2320+
2321+ if (dp == NULL) {
2322+ TRACE(0);
2323+ return false;
2324+ }
2325+
2326+ char filename[MAXPATHLEN];
2327+ struct stat st;
2328+
2329+ while (dirnext(dp, filename, &st) == 0) {
2330+ if (strcmp(filename, ".") == 0 || strcmp(filename, "..") == 0)
2331+ continue;
2332+
2333+ String newPath(_path);
2334+ if (newPath.lastChar() != '/')
2335+ newPath += '/';
2336+ newPath += filename;
2337+
2338+ bool isDir = S_ISDIR(st.st_mode);
2339+
2340+ if ((mode == FilesystemNode::kListFilesOnly && isDir) ||
2341+ (mode == FilesystemNode::kListDirectoriesOnly && !isDir))
2342+ continue;
2343+
2344+ if (isDir)
2345+ newPath += '/';
2346+
2347+ WiiFilesystemNode *n = new WiiFilesystemNode(newPath, false);
2348+ n->_isDirectory = isDir;
2349+ n->_isReadable = (st.st_mode & S_IRUSR) > 0;
2350+ n->_isWritable = (st.st_mode & S_IWUSR) > 0;
2351+
2352+ myList.push_back(n);
2353+ }
2354+
2355+ dirclose(dp);
2356+
2357+ return true;
2358+}
2359+
2360+AbstractFilesystemNode *WiiFilesystemNode::getParent() const {
2361+ if (_path == "/")
2362+ return 0;
2363+
2364+ const char *start = _path.c_str();
2365+ const char *end = lastPathComponent(_path);
2366+
2367+ return new WiiFilesystemNode(String(start, end - start), true);
2368+}
2369+
2370+#endif //#if defined(__WII__)
2371+
2372Index: backends/fs/wii/wii-fs-factory.cpp
2373===================================================================
2374--- backends/fs/wii/wii-fs-factory.cpp (revision 0)
2375+++ backends/fs/wii/wii-fs-factory.cpp (revision 0)
2376@@ -0,0 +1,41 @@
2377+/* ScummVM - Graphic Adventure Engine
2378+ *
2379+ * ScummVM is the legal property of its developers, whose names
2380+ * are too numerous to list here. Please refer to the COPYRIGHT
2381+ * file distributed with this source distribution.
2382+ *
2383+ * This program is free software; you can redistribute it and/or
2384+ * modify it under the terms of the GNU General Public License
2385+ * as published by the Free Software Foundation; either version 2
2386+ * of the License, or (at your option) any later version.
2387+ *
2388+ * This program is distributed in the hope that it will be useful,
2389+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2390+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2391+ * GNU General Public License for more details.
2392+ *
2393+ * You should have received a copy of the GNU General Public License
2394+ * along with this program; if not, write to the Free Software
2395+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2396+ *
2397+ */
2398+
2399+#if defined(__WII__)
2400+#include "backends/fs/wii/wii-fs-factory.h"
2401+#include "backends/fs/wii/wii-fs.cpp"
2402+
2403+DECLARE_SINGLETON(WiiFilesystemFactory);
2404+
2405+AbstractFilesystemNode *WiiFilesystemFactory::makeRootFileNode() const {
2406+ return new WiiFilesystemNode();
2407+}
2408+
2409+AbstractFilesystemNode *WiiFilesystemFactory::makeCurrentDirectoryFileNode() const {
2410+ return new WiiFilesystemNode("/scummvm", true);
2411+}
2412+
2413+AbstractFilesystemNode *WiiFilesystemFactory::makeFileNodePath(const String &path) const {
2414+ return new WiiFilesystemNode(path, true);
2415+}
2416+#endif
2417+
2418Index: backends/fs/wii/wii-fs-factory.h
2419===================================================================
2420--- backends/fs/wii/wii-fs-factory.h (revision 0)
2421+++ backends/fs/wii/wii-fs-factory.h (revision 0)
2422@@ -0,0 +1,50 @@
2423+/* ScummVM - Graphic Adventure Engine
2424+ *
2425+ * ScummVM is the legal property of its developers, whose names
2426+ * are too numerous to list here. Please refer to the COPYRIGHT
2427+ * file distributed with this source distribution.
2428+ *
2429+ * This program is free software; you can redistribute it and/or
2430+ * modify it under the terms of the GNU General Public License
2431+ * as published by the Free Software Foundation; either version 2
2432+ * of the License, or (at your option) any later version.
2433+ *
2434+ * This program is distributed in the hope that it will be useful,
2435+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2436+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2437+ * GNU General Public License for more details.
2438+ *
2439+ * You should have received a copy of the GNU General Public License
2440+ * along with this program; if not, write to the Free Software
2441+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2442+ *
2443+ */
2444+
2445+#ifndef _WII_FILESYSTEM_FACTORY_H_
2446+#define _WII_FILESYSTEM_FACTORY_H_
2447+
2448+#include "common/singleton.h"
2449+#include "backends/fs/fs-factory.h"
2450+
2451+/**
2452+ * Creates WiiFilesystemNode objects.
2453+ *
2454+ * Parts of this class are documented in the base interface class, FilesystemFactory.
2455+ */
2456+class WiiFilesystemFactory : public FilesystemFactory, public Common::Singleton<WiiFilesystemFactory> {
2457+public:
2458+ typedef Common::String String;
2459+
2460+ virtual AbstractFilesystemNode *makeRootFileNode() const;
2461+ virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const;
2462+ virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const;
2463+
2464+protected:
2465+ WiiFilesystemFactory() {};
2466+
2467+private:
2468+ friend class Common::Singleton<SingletonBaseType>;
2469+};
2470+
2471+#endif /*Wii_FILESYSTEM_FACTORY_H*/
2472+
2473Index: backends/module.mk
2474===================================================================
2475--- backends/module.mk (revision 32343)
2476+++ backends/module.mk (working copy)
2477@@ -9,6 +9,7 @@
2478 fs/psp/psp-fs-factory.o \
2479 fs/symbian/symbian-fs-factory.o \
2480 fs/windows/windows-fs-factory.o \
2481+ fs/wii/wii-fs-factory.o \
2482 events/default/default-events.o \
2483 midi/alsa.o \
2484 midi/camd.o \