Ticket #8871: scummvm-wii-take3.diff
File scummvm-wii-take3.diff, 64.5 KB (added by , 16 years ago) |
---|
-
dists/wii/meta.xml
1 <?xml version="1.0" encoding="UTF-8" standalone="yes"?> 2 <app version="1"> 3 <name>ScummVM</name> 4 <coder>The ScummVM Team</coder> 5 <version>rev FIXME</version> 6 <release_date>FIXME</release_date> 7 <short_description>Point & Click Adventures</short_description> 8 <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! 9 10 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> 11 </app> 12 -
dists/wii/READMII
1 Wii port of ScummVM README 2 -------------------------- 3 4 features not compiled in: 5 - the AGI game engine 6 7 REQUIREMENTS 8 9 - sd card 10 - wiimote or gamecube controller in port 1 11 12 INSTALL 13 14 - copy the "scummvm" and "apps" folders to the root of your sd card 15 - copy your demos and/or games onto the same sd card 16 freeware versions: http://scummvm.org/downloads.php#extras 17 demos: http://scummvm.org/demos.php 18 19 RUN 20 21 either use the homebrew channel, available at 22 23 http://hbc.hackmii.com/ 24 25 or load "boot.dol" with your favorite loader 26 27 CONTROLS 28 29 wiimote 30 31 analog stick: mouse movement 32 a: left mouse button 33 b: right mouse button 34 minus: escape 35 plus: "." (skip current line of text) 36 2: enter 37 home: f5 (scummvm menu) 38 dpad up: shift (mass add for the gui) 39 dpad left: "0" 40 41 gamecube pad 42 43 analog stick: mouse movement 44 a: left mouse button 45 b: right mouse button 46 x: escape 47 y: "." (skip current line of text) 48 z: enter 49 start: f5 (scummvm menu) 50 dpad up: shift (mass add for the gui) 51 dpad left: "0" 52 53 THANKS 54 55 shagkur and WinterMute, for devkitppc/libogc and the coorperation 56 svpe, for fixing the libfat feof/thread bugs on the last minute 57 para, for making wiiuse available in libogc 58 -
common/scummsys.h
Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: dists/wii/icon.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream
369 369 #define STRINGBUFLEN 256 370 370 #define printf(fmt, ...) consolePrintf(fmt, ##__VA_ARGS__) 371 371 372 #elif defined(__WII__) 373 374 #define scumm_stricmp strcasecmp 375 #define scumm_strnicmp strncasecmp 376 377 #define SCUMM_BIG_ENDIAN 378 #define SCUMM_NEED_ALIGNMENT 379 372 380 #else 373 381 #error No system type defined 374 382 -
common/system.cpp
137 137 #endif 138 138 139 139 FilesystemFactory *OSystem::getFilesystemFactory() { 140 #if defined(__amigaos4__) || defined(__DC__) || defined(__SYMBIAN32__) || defined(UNIX) || defined(WIN32) || defined(__ PSP__) || defined(__DS__)140 #if defined(__amigaos4__) || defined(__DC__) || defined(__SYMBIAN32__) || defined(UNIX) || defined(WIN32) || defined(__WII__) || defined(__PSP__) || defined(__DS__) 141 141 // These ports already implement this function, so it should never be called. 142 142 return 0; 143 143 #elif defined(PALMOS_MODE) -
backends/platform/wii/gecko_console.h
1 #ifndef _WII_GECKO_CONSOLE_H_ 2 #define _WII_GECKO_CONSOLE_H_ 3 4 #ifdef __cplusplus 5 extern "C" { 6 #endif 7 8 void gecko_console_init(int chain); 9 10 #ifdef __cplusplus 11 } 12 #endif 13 14 #endif -
backends/platform/wii/osystem.cpp
1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 */ 21 22 #include "osystem.h" 23 #include "backends/fs/wii/wii-fs-factory.h" 24 25 #include <unistd.h> 26 27 #include <ogc/mutex.h> 28 #include <ogc/lwp_watchdog.h> 29 30 OSystem_Wii::OSystem_Wii() : 31 _startup_time(0), 32 _alarm(-1), 33 34 _palette(NULL), 35 _cursorPalette(NULL), 36 _cursorPaletteDisabled(true), 37 38 _gameWidth(0), 39 _gameHeight(0), 40 _gamePixels(NULL), 41 42 _overlayVisible(false), 43 _overlayWidth(0), 44 _overlayHeight(0), 45 _overlaySize(0), 46 _overlayPixels(NULL), 47 48 _lastScreenUpdate(0), 49 _texture(NULL), 50 _currentWidth(0), 51 _currentHeight(0), 52 53 _supportedGraphicsModes(NULL), 54 _activeGraphicsMode(-1), 55 56 _mouseVisible(false), 57 _mouseX(0), 58 _mouseY(0), 59 _mouseWidth(0), 60 _mouseHeight(0), 61 _mouseHotspotX(0), 62 _mouseHotspotY(0), 63 _mouseKeyColor(0), 64 _mouseCursor(NULL), 65 66 _savefile(NULL), 67 _mixer(NULL), 68 _timer(NULL) { 69 70 TRACE(0); 71 } 72 73 OSystem_Wii::~OSystem_Wii() { 74 TRACE(0); 75 76 if (_savefile) { 77 delete _savefile; 78 _savefile = NULL; 79 } 80 81 if (_mixer) { 82 delete _mixer; 83 _mixer = NULL; 84 } 85 86 if (_timer) { 87 delete _timer; 88 _timer = NULL; 89 } 90 } 91 92 void OSystem_Wii::initBackend() { 93 TRACE(0); 94 95 _startup_time = gettime(); 96 97 _savefile = new DefaultSaveFileManager(); 98 _mixer = new Audio::Mixer(); 99 _timer = new DefaultTimerManager(); 100 101 initGfx(); 102 initSfx(); 103 initEvents(); 104 105 OSystem::initBackend(); 106 } 107 108 void OSystem_Wii::quit() { 109 TRACE(0); 110 111 deinitEvents(); 112 deinitSfx(); 113 deinitGfx(); 114 } 115 116 bool OSystem_Wii::hasFeature(Feature f) { 117 return f == kFeatureCursorHasPalette; 118 } 119 120 void OSystem_Wii::setFeatureState(Feature f, bool enable) { 121 } 122 123 bool OSystem_Wii::getFeatureState(Feature f) { 124 return false; 125 } 126 127 uint32 OSystem_Wii::getMillis() { 128 return ticks_to_millisecs(diff_ticks(_startup_time, gettime())); 129 } 130 131 void OSystem_Wii::delayMillis(uint msecs) { 132 usleep(msecs * 1000); 133 } 134 135 OSystem::MutexRef OSystem_Wii::createMutex() { 136 mutex_t *mutex = (mutex_t *) malloc(sizeof(mutex_t)); 137 s32 res = LWP_MutexInit(mutex, false); 138 139 if (res) { 140 printf("ERROR creating mutex\n"); 141 delete mutex; 142 return NULL; 143 } 144 145 return (MutexRef) mutex; 146 } 147 148 void OSystem_Wii::lockMutex(MutexRef mutex) { 149 s32 res = LWP_MutexLock(*(mutex_t *) mutex); 150 151 if (res) 152 printf("ERROR locking mutex %p (%d)\n", mutex, res); 153 } 154 155 void OSystem_Wii::unlockMutex(MutexRef mutex) { 156 s32 res = LWP_MutexUnlock(*(mutex_t *) mutex); 157 158 if (res) 159 printf("ERROR unlocking mutex %p (%d)\n", mutex, res); 160 } 161 162 void OSystem_Wii::deleteMutex(MutexRef mutex) { 163 s32 res = LWP_MutexDestroy(*(mutex_t *) mutex); 164 165 if (res) 166 printf("ERROR destroying mutex %p (%d)\n", mutex, res); 167 } 168 169 void OSystem_Wii::setWindowCaption(const char *caption) { 170 printf("window caption: %s\n", caption); 171 } 172 173 Common::SaveFileManager *OSystem_Wii::getSavefileManager() { 174 assert(_savefile); 175 return _savefile; 176 } 177 178 Audio::Mixer *OSystem_Wii::getMixer() { 179 assert(_mixer); 180 return _mixer; 181 } 182 183 Common::TimerManager *OSystem_Wii::getTimerManager() { 184 assert(_timer); 185 return _timer; 186 } 187 188 FilesystemFactory *OSystem_Wii::getFilesystemFactory() { 189 return &WiiFilesystemFactory::instance(); 190 } 191 192 void OSystem_Wii::getTimeAndDate(struct tm &t) const { 193 time_t curTime = time(0); 194 t = *localtime(&curTime); 195 } 196 -
backends/platform/wii/osystem_sfx.cpp
1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 */ 21 22 #include "osystem.h" 23 24 #define SFX_THREAD_STACKSIZE (1024 * 128) 25 #define SFX_THREAD_PRIO 80 26 #define SFX_THREAD_FRAG_SIZE 4096 27 28 static lwpq_t sfx_queue; 29 static lwp_t sfx_thread; 30 static u8 *sfx_stack; 31 static bool sfx_thread_running = false; 32 static bool sfx_thread_quit = false; 33 34 static u8 sb = 0; 35 static u8 *sound_buffer[2]; 36 37 static OSystem_Wii::SoundProc sound_proc = NULL; 38 static void *proc_param = NULL; 39 40 static void audio_switch_buffers() { 41 AUDIO_StopDMA(); 42 AUDIO_InitDMA((u32) sound_buffer[sb], SFX_THREAD_FRAG_SIZE); 43 AUDIO_StartDMA(); 44 45 LWP_ThreadSignal(sfx_queue); 46 } 47 48 static void * sfx_thread_func(void *arg) { 49 u8 next_sb; 50 51 while (true) { 52 LWP_ThreadSleep(sfx_queue); 53 54 if (sfx_thread_quit) 55 break; 56 57 next_sb = sb ^ 1; 58 sound_proc(proc_param, sound_buffer[next_sb], SFX_THREAD_FRAG_SIZE); 59 DCFlushRange(sound_buffer[next_sb], SFX_THREAD_FRAG_SIZE); 60 61 sb = next_sb; 62 } 63 64 return NULL; 65 } 66 67 void OSystem_Wii::initSfx() { 68 TRACE(0); 69 70 sfx_thread_running = false; 71 sfx_thread_quit = false; 72 73 sfx_stack = (u8 *) memalign(32, SFX_THREAD_STACKSIZE); 74 memset(sfx_stack, 0, SFX_THREAD_STACKSIZE); 75 76 LWP_InitQueue(&sfx_queue); 77 78 s32 res = LWP_CreateThread(&sfx_thread, sfx_thread_func, NULL, sfx_stack, 79 SFX_THREAD_STACKSIZE, SFX_THREAD_PRIO); 80 81 if (res) { 82 printf("ERROR creating sfx thread: %d\n", res); 83 LWP_CloseQueue(sfx_queue); 84 return; 85 } 86 87 sfx_thread_running = true; 88 89 sound_buffer[0] = (u8 *) memalign(32, SFX_THREAD_FRAG_SIZE); 90 sound_buffer[1] = (u8 *) memalign(32, SFX_THREAD_FRAG_SIZE); 91 92 memset(sound_buffer[0], 0, SFX_THREAD_FRAG_SIZE); 93 memset(sound_buffer[1], 0, SFX_THREAD_FRAG_SIZE); 94 95 DCFlushRange(sound_buffer[0], SFX_THREAD_FRAG_SIZE); 96 DCFlushRange(sound_buffer[1], SFX_THREAD_FRAG_SIZE); 97 98 sound_proc = Audio::Mixer::mixCallback; 99 proc_param = _mixer; 100 101 _mixer->setReady(true); 102 103 AUDIO_SetDSPSampleRate(AI_SAMPLERATE_48KHZ); 104 AUDIO_RegisterDMACallback(audio_switch_buffers); 105 106 audio_switch_buffers(); 107 } 108 109 void OSystem_Wii::deinitSfx() { 110 TRACE(0); 111 112 if (_mixer) 113 _mixer->setReady(false); 114 115 AUDIO_StopDMA(); 116 AUDIO_RegisterDMACallback(NULL); 117 118 if (sfx_thread_running) { 119 sfx_thread_quit = true; 120 LWP_ThreadBroadcast(sfx_queue); 121 122 LWP_JoinThread(sfx_thread, NULL); 123 LWP_CloseQueue(sfx_queue); 124 125 sfx_thread_running = false; 126 127 free(sound_buffer[0]); 128 free(sound_buffer[1]); 129 } 130 } 131 132 int OSystem_Wii::getOutputSampleRate() const { 133 return 48000; 134 } 135 -
backends/platform/wii/main.cpp
1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 */ 21 22 #include <fat.h> 23 #include <sys/stat.h> 24 #include <sys/types.h> 25 #include <errno.h> 26 #include <unistd.h> 27 28 #include "osystem.h" 29 30 #ifdef DEBUG_WII 31 #include <debug.h> 32 #include <gecko_console.h> 33 #endif 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 int main(int argc, char *argv[]) { 40 s32 res; 41 42 VIDEO_Init(); 43 PAD_Init(); 44 AUDIO_Init(NULL); 45 46 #ifdef DEBUG_WII 47 gecko_console_init(0); 48 //DEBUG_Init(GDBSTUB_DEVICE_USB, 1); 49 #endif 50 51 printf("startup\n"); 52 53 if (!fatInit(32, false)) { 54 printf("fatInit failed\n"); 55 } else { 56 //fatEnableReadAhead(PI_DEFAULT, 32, 128); 57 58 if (chdir("fat:/scummvm")) { 59 mkdir("fat:/scummvm", 0777); 60 chdir("fat:/scummvm"); 61 } 62 } 63 64 g_system = new OSystem_Wii(); 65 assert(g_system); 66 67 res = scummvm_main(argc, argv); 68 g_system->quit(); 69 70 printf("shutdown\n"); 71 72 if (!fatUnmount(PI_DEFAULT)) { 73 printf("fatUnmount failed\n"); 74 fatUnsafeUnmount(PI_DEFAULT); 75 } 76 77 printf("reloading\n"); 78 79 return res; 80 } 81 82 #ifdef __cplusplus 83 } 84 #endif 85 -
backends/platform/wii/gx_supp.cpp
1 /**************************************************************************** 2 * Generic GX Support for Emulators 3 * softdev 2007 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License along 16 * with this program; if not, write to the Free Software Foundation, Inc., 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * NGC GX Video Functions 20 * 21 * These are pretty standard functions to setup and use GX scaling. 22 ****************************************************************************/ 23 24 #include <gccore.h> 25 #include <stdio.h> 26 #include <stdlib.h> 27 #include <string.h> 28 #include <malloc.h> 29 30 #define DEFAULT_FIFO_SIZE (256 * 1024) 31 32 #define HASPECT 320 33 #define VASPECT 240 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 /*** 2D ***/ 40 static u32 whichfb; 41 static u32 *xfb[2]; 42 static GXRModeObj *vmode; 43 44 /*** 3D GX ***/ 45 static u8 *gp_fifo; 46 47 /*** Texture memory ***/ 48 static u8 *texturemem; 49 static u32 texturesize; 50 51 GXTexObj texobj; 52 static Mtx view; 53 static u16 vwidth, vheight, oldvwidth, oldvheight; 54 55 /* New texture based scaler */ 56 typedef struct tagcamera { 57 Vector pos; 58 Vector up; 59 Vector view; 60 } camera; 61 62 static s16 square[] ATTRIBUTE_ALIGN(32) = { 63 -HASPECT, VASPECT, 0, 64 HASPECT, VASPECT, 0, 65 HASPECT, -VASPECT, 0, 66 -HASPECT, -VASPECT, 0, 67 }; 68 69 static camera cam = { 70 { 0.0f, 0.0f, 370.0f }, 71 { 0.0f, 0.5f, 0.0f }, 72 { 0.0f, 0.0f, -0.5f } 73 }; 74 75 void GX_InitVideo() { 76 vmode = VIDEO_GetPreferredMode(NULL); 77 VIDEO_Configure(vmode); 78 79 xfb[0] = (u32 *) MEM_K0_TO_K1 (SYS_AllocateFramebuffer(vmode)); 80 xfb[1] = (u32 *) MEM_K0_TO_K1 (SYS_AllocateFramebuffer(vmode)); 81 gp_fifo = (u8 *) memalign(32, DEFAULT_FIFO_SIZE); 82 83 VIDEO_ClearFrameBuffer(vmode, xfb[0], COLOR_BLACK); 84 VIDEO_ClearFrameBuffer(vmode, xfb[1], COLOR_BLACK); 85 86 whichfb = 0; 87 VIDEO_SetNextFramebuffer(xfb[whichfb]); 88 VIDEO_SetBlack(FALSE); 89 VIDEO_Flush(); 90 VIDEO_WaitVSync(); 91 92 if (vmode->viTVMode & VI_NON_INTERLACE) 93 VIDEO_WaitVSync(); 94 } 95 96 /**************************************************************************** 97 * Scaler Support Functions 98 ****************************************************************************/ 99 static void draw_init(void) { 100 GX_ClearVtxDesc(); 101 GX_SetVtxDesc(GX_VA_POS, GX_INDEX8); 102 GX_SetVtxDesc(GX_VA_CLR0, GX_INDEX8); 103 GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); 104 105 GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_S16, 0); 106 GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0); 107 GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); 108 109 GX_SetArray(GX_VA_POS, square, 3 * sizeof(s16)); 110 111 GX_SetNumTexGens(1); 112 GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY); 113 114 GX_InvalidateTexAll(); 115 116 GX_InitTexObj(&texobj, texturemem, vwidth, vheight, GX_TF_RGB565, 117 GX_CLAMP, GX_CLAMP, GX_FALSE); 118 } 119 120 static void draw_vert(u8 pos, u8 c, f32 s, f32 t) { 121 GX_Position1x8(pos); 122 GX_Color1x8(c); 123 GX_TexCoord2f32(s, t); 124 } 125 126 static void draw_square(Mtx v) { 127 Mtx m; 128 Mtx mv; 129 130 guMtxIdentity(m); 131 guMtxTransApply(m, m, 0, 0, -100); 132 guMtxConcat(v, m, mv); 133 134 GX_LoadPosMtxImm(mv, GX_PNMTX0); 135 GX_Begin(GX_QUADS, GX_VTXFMT0, 4); 136 draw_vert(0, 0, 0.0, 0.0); 137 draw_vert(1, 0, 1.0, 0.0); 138 draw_vert(2, 0, 1.0, 1.0); 139 draw_vert(3, 0, 0.0, 1.0); 140 GX_End(); 141 } 142 143 /**************************************************************************** 144 * StartGX 145 ****************************************************************************/ 146 void GX_Start(u16 width, u16 height, s16 haspect, s16 vaspect) { 147 Mtx p; 148 149 GX_AbortFrame(); 150 151 /*** Set new aspect ***/ 152 square[0] = square[9] = -haspect; 153 square[3] = square[6] = haspect; 154 square[1] = square[4] = vaspect; 155 square[7] = square[10] = -vaspect; 156 157 /*** Allocate 32byte aligned texture memory ***/ 158 texturesize = (width * height) * 2; 159 texturemem = (u8 *) memalign(32, texturesize); 160 161 GXColor gxbackground = { 0, 0, 0, 0xff }; 162 163 /*** Clear out FIFO area ***/ 164 memset(gp_fifo, 0, DEFAULT_FIFO_SIZE); 165 166 /*** Initialise GX ***/ 167 GX_Init(gp_fifo, DEFAULT_FIFO_SIZE); 168 GX_SetCopyClear(gxbackground, 0x00ffffff); 169 170 GX_SetViewport(0, 0, vmode->fbWidth, vmode->efbHeight, 0, 1); 171 GX_SetDispCopyYScale((f32) vmode->xfbHeight / (f32) vmode->efbHeight); 172 GX_SetScissor(0, 0, vmode->fbWidth, vmode->efbHeight); 173 GX_SetDispCopySrc(0, 0, vmode->fbWidth, vmode->efbHeight); 174 GX_SetDispCopyDst(vmode->fbWidth, vmode->xfbHeight); 175 GX_SetCopyFilter(vmode->aa, vmode->sample_pattern, GX_TRUE, 176 vmode->vfilter); 177 GX_SetFieldMode(vmode->field_rendering, 178 ((vmode->viHeight == 2 * vmode->xfbHeight) ? 179 GX_ENABLE : GX_DISABLE)); 180 GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR); 181 GX_SetCullMode(GX_CULL_NONE); 182 GX_CopyDisp(xfb[whichfb ^ 1], GX_TRUE); 183 GX_SetDispCopyGamma(GX_GM_1_0); 184 185 guPerspective(p, 60, 1.33f, 10.0f, 1000.0f); 186 GX_LoadProjectionMtx(p, GX_PERSPECTIVE); 187 memset(texturemem, 0, texturesize); 188 189 GX_Flush(); 190 191 /*** Setup for first call to scaler ***/ 192 vwidth = vheight = -1; 193 } 194 195 /**************************************************************************** 196 * GX_Render 197 * 198 * Pass in a buffer, width and height to update as a tiled RGB565 texture 199 ****************************************************************************/ 200 void GX_Render(u16 width, u16 height, u8 *buffer, u16 pitch) { 201 u16 h, w; 202 u64 *dst = (u64 *) texturemem; 203 u64 *src1 = (u64 *) buffer; 204 u64 *src2 = (u64 *) (buffer + pitch); 205 u64 *src3 = (u64 *) (buffer + (pitch * 2)); 206 u64 *src4 = (u64 *) (buffer + (pitch * 3)); 207 u16 rowpitch = (pitch >> 3) * 3 + pitch % 8; 208 209 vwidth = width; 210 vheight = height; 211 212 whichfb ^= 1; 213 214 if ((oldvheight != vheight) || (oldvwidth != vwidth)) { 215 /** Update scaling **/ 216 oldvwidth = vwidth; 217 oldvheight = vheight; 218 draw_init(); 219 memset(&view, 0, sizeof(Mtx)); 220 guLookAt(view, &cam.pos, &cam.up, &cam.view); 221 GX_SetViewport(0, 0, vmode->fbWidth, vmode->efbHeight, 0, 1); 222 } 223 224 GX_InvVtxCache(); 225 GX_InvalidateTexAll(); 226 GX_SetTevOp(GX_TEVSTAGE0, GX_DECAL); 227 GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); 228 229 for (h = 0; h < vheight; h += 4) { 230 for (w = 0; w < (vwidth >> 2); w++) { 231 *dst++ = *src1++; 232 *dst++ = *src2++; 233 *dst++ = *src3++; 234 *dst++ = *src4++; 235 } 236 237 src1 += rowpitch; 238 src2 += rowpitch; 239 src3 += rowpitch; 240 src4 += rowpitch; 241 } 242 243 DCFlushRange(texturemem, texturesize); 244 245 GX_SetNumChans(1); 246 GX_LoadTexObj(&texobj, GX_TEXMAP0); 247 248 draw_square(view); 249 250 GX_DrawDone(); 251 252 GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); 253 GX_SetColorUpdate(GX_TRUE); 254 GX_CopyDisp(xfb[whichfb], GX_TRUE); 255 GX_Flush(); 256 257 VIDEO_SetNextFramebuffer(xfb[whichfb]); 258 VIDEO_Flush(); 259 } 260 261 #ifdef __cplusplus 262 } 263 #endif 264 -
backends/platform/wii/osystem_gfx.cpp
1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 */ 21 22 #include "osystem.h" 23 #include "gx_supp.h" 24 25 #define MAX_FPS 30 26 27 enum GraphicModeID { 28 GM_DEFAULT 29 }; 30 31 void OSystem_Wii::initGfx() { 32 _surface.w = 0; 33 _surface.h = 0; 34 _surface.pitch = 0; 35 _surface.pixels = NULL; 36 _surface.bytesPerPixel = 0; 37 38 GX_InitVideo(); 39 40 _overlayWidth = 640; 41 _overlayHeight = 480; 42 43 _overlaySize = _overlayWidth * _overlayHeight * 2; 44 _overlayPixels = (OverlayColor *) memalign(32, _overlaySize); 45 46 _palette = (u16 *) memalign(32, 256 * 2); 47 memset(_palette, 0, 256 * 2); 48 49 _cursorPalette = (u16 *) memalign(32, 256 * 2); 50 memset(_cursorPalette, 0, 256 * 2); 51 52 _supportedGraphicsModes = new OSystem::GraphicsMode[2]; 53 _supportedGraphicsModes[0].name = strdup("gx"); 54 _supportedGraphicsModes[0].description = strdup("wii hardware scaler"); 55 _supportedGraphicsModes[0].id = GM_DEFAULT; 56 _supportedGraphicsModes[1].name = 0; 57 _supportedGraphicsModes[1].description = 0; 58 _supportedGraphicsModes[1].id = 0; 59 60 _texture = (u16 *) memalign(32, _overlaySize); 61 62 GX_Start(_overlayWidth, _overlayHeight, 320, 240); 63 } 64 65 void OSystem_Wii::deinitGfx() { 66 TRACE(0); 67 68 GX_AbortFrame(); 69 70 if (_supportedGraphicsModes) { 71 delete[] _supportedGraphicsModes; 72 _supportedGraphicsModes = NULL; 73 } 74 75 if (_gamePixels) { 76 free(_gamePixels); 77 _gamePixels = NULL; 78 } 79 80 if (_palette) { 81 free(_palette); 82 _palette = NULL; 83 } 84 85 if (_overlayPixels) { 86 free(_overlayPixels); 87 _overlayPixels = NULL; 88 } 89 90 if (_mouseCursor) { 91 free(_mouseCursor); 92 _mouseCursor = NULL; 93 } 94 95 if (_cursorPalette) { 96 free(_cursorPalette); 97 _cursorPalette = NULL; 98 } 99 100 if (_texture) { 101 free(_texture); 102 _texture = NULL; 103 } 104 } 105 106 const OSystem::GraphicsMode* OSystem_Wii::getSupportedGraphicsModes() const { 107 return _supportedGraphicsModes; 108 } 109 110 int OSystem_Wii::getDefaultGraphicsMode() const { 111 return GM_DEFAULT; 112 } 113 114 bool OSystem_Wii::setGraphicsMode(const char *mode) { 115 setGraphicsMode(GM_DEFAULT); 116 117 return true; 118 } 119 120 bool OSystem_Wii::setGraphicsMode(int mode) { 121 return true; 122 } 123 124 int OSystem_Wii::getGraphicsMode() const { 125 return _activeGraphicsMode; 126 } 127 128 void OSystem_Wii::initSize(uint width, uint height) { 129 if (_gameWidth != width || _gameHeight != height) { 130 printf("initSize %u %u\n", width, height); 131 132 _gameWidth = width; 133 _gameHeight = height; 134 135 if(_gamePixels) 136 free(_gamePixels); 137 138 _gamePixels = (u8 *) memalign(32, _gameWidth * _gameHeight); 139 140 if (!_overlayVisible) { 141 _currentWidth = _gameWidth; 142 _currentHeight = _gameHeight; 143 updateEventScreenResolution(); 144 } 145 } 146 } 147 148 int16 OSystem_Wii::getWidth() { 149 return _gameWidth; 150 } 151 152 int16 OSystem_Wii::getHeight() { 153 return _gameHeight; 154 } 155 156 void OSystem_Wii::setPalette(const byte *colors, uint start, uint num) { 157 const byte *p = colors; 158 for (uint i = 0; i < num; ++i) { 159 _palette[start + i] = RGBToColor(p[0], p[1], p[2]); 160 p += 4; 161 } 162 } 163 164 void OSystem_Wii::grabPalette(byte *colors, uint start, uint num) { 165 byte *p = colors; 166 u8 r, g, b; 167 for (uint i = 0; i < num; ++i) { 168 colorToRGB(_palette[start + i], r, g, b); 169 p[0] = r; 170 p[1] = g; 171 p[2] = b; 172 p[3] = 0xff; 173 p += 4; 174 } 175 } 176 177 void OSystem_Wii::setCursorPalette(const byte *colors, uint start, uint num) { 178 const byte *p = colors; 179 for (uint i = 0; i < num; ++i) { 180 _cursorPalette[start + i] = RGBToColor(p[0], p[1], p[2]); 181 p += 4; 182 } 183 184 _cursorPaletteDisabled = false; 185 } 186 187 void OSystem_Wii::disableCursorPalette(bool disable) { 188 TRACE(disable); 189 190 _cursorPaletteDisabled = disable; 191 } 192 193 void OSystem_Wii::copyRectToScreen(const byte *buf, int pitch, int x, int y, 194 int w, int h) { 195 if (x < 0) { 196 w += x; 197 buf -= x; 198 x = 0; 199 } 200 201 if (y < 0) { 202 h += y; 203 buf -= y * pitch; 204 y = 0; 205 } 206 207 if (w > _gameWidth - x) 208 w = _gameWidth - x; 209 210 if (h > _gameHeight - y) 211 h = _gameHeight - y; 212 213 if (w <= 0 || h <= 0) 214 return; 215 216 byte *dst = _gamePixels + y * _gameWidth + x; 217 if (_gameWidth == pitch && pitch == w) { 218 memcpy(dst, buf, h * w); 219 } else { 220 do { 221 memcpy(dst, buf, w); 222 buf += pitch; 223 dst += _gameWidth; 224 } while (--h); 225 } 226 } 227 228 void OSystem_Wii::updateScreen() { 229 static u32 x, y, h, skip; 230 static s16 msx, msy, mox, moy, mskip; 231 static u16 mpx, mpy; 232 static u8 *s; 233 static u16 *d, *p; 234 235 u32 now = getMillis(); 236 if (now - _lastScreenUpdate < 1000 / MAX_FPS) 237 return; 238 239 _lastScreenUpdate = now; 240 241 h = 0; 242 if (_overlayVisible) { 243 memcpy(_texture, _overlayPixels, _overlaySize); 244 } else { 245 for (y = 0; y < _gameHeight; ++y) { 246 for (x = 0; x < _gameWidth; ++x) 247 _texture[h + x] = _palette[_gamePixels[h + x]]; 248 249 h += _gameWidth; 250 } 251 } 252 253 if (_mouseVisible) { 254 msx = _mouseX - _mouseHotspotX; 255 msy = _mouseY - _mouseHotspotY; 256 mox = 0; 257 moy = 0; 258 mpx = _mouseWidth; 259 mpy = _mouseHeight; 260 261 if (msx < 0) { 262 mox = -msx; 263 mpx -= mox; 264 msx = 0; 265 } else 266 if (msx + mpx > _currentWidth - 1) 267 mpx = _currentWidth - msx - 1; 268 269 if (msy < 0) { 270 moy = -msy; 271 mpy -= moy; 272 msy = 0; 273 } else 274 if (msy + mpy + 1 > _currentHeight - 1) 275 mpy = _currentHeight - msy - 1; 276 277 278 if (_cursorPaletteDisabled) 279 p = _palette; 280 else 281 p = _cursorPalette; 282 283 skip = _currentWidth - mpx; 284 mskip = _mouseWidth - mpx; 285 286 s = _mouseCursor + moy * _mouseWidth + mox; 287 d = _texture + (msy * _currentWidth + msx); 288 289 for (y = 0; y < mpy; ++y) { 290 for (x = 0; x < mpx; ++x) { 291 if (*s == _mouseKeyColor) { 292 s++; 293 d++; 294 295 continue; 296 } 297 298 *d++ = p[*s]; 299 s++; 300 } 301 302 d += skip; 303 s += mskip; 304 } 305 } 306 307 GX_Render(_currentWidth, _currentHeight, (u8 *) _texture, 308 _currentWidth * 2); 309 } 310 311 Graphics::Surface *OSystem_Wii::lockScreen() { 312 TRACE(0); 313 314 _surface.pixels = _gamePixels; 315 _surface.w = _gameWidth; 316 _surface.h = _gameHeight; 317 _surface.pitch = _gameWidth; 318 _surface.bytesPerPixel = 1; 319 320 return &_surface; 321 } 322 323 void OSystem_Wii::unlockScreen() { 324 TRACE(0); 325 } 326 327 void OSystem_Wii::setShakePos(int shakeOffset) { 328 TRACE(shakeOffset); 329 } 330 331 void OSystem_Wii::showOverlay() { 332 TRACE(1); 333 334 _mouseX = _overlayWidth / 2; 335 _mouseY = _overlayHeight / 2; 336 _overlayVisible = true; 337 _currentWidth = _overlayWidth; 338 _currentHeight = _overlayHeight; 339 340 updateEventScreenResolution(); 341 } 342 343 void OSystem_Wii::hideOverlay() { 344 TRACE(0); 345 346 _mouseX = _gameWidth / 2; 347 _mouseY = _gameHeight / 2; 348 _overlayVisible = false; 349 _currentWidth = _gameWidth; 350 _currentHeight = _gameHeight; 351 352 updateEventScreenResolution(); 353 } 354 355 void OSystem_Wii::clearOverlay() { 356 memset(_overlayPixels, 0, _overlaySize); 357 } 358 359 void OSystem_Wii::grabOverlay(OverlayColor *buf, int pitch) { 360 int h = _overlayHeight; 361 OverlayColor *src = _overlayPixels; 362 363 do { 364 memcpy(buf, src, _overlayWidth * sizeof(OverlayColor)); 365 src += _overlayWidth; 366 buf += pitch; 367 } while (--h); 368 } 369 370 void OSystem_Wii::copyRectToOverlay(const OverlayColor *buf, int pitch, int x, 371 int y, int w, int h) { 372 if (x < 0) { 373 w += x; 374 buf -= x; 375 x = 0; 376 } 377 378 if (y < 0) { 379 h += y; 380 buf -= y * pitch; 381 y = 0; 382 } 383 384 if (w > _overlayWidth - x) 385 w = _overlayWidth - x; 386 387 if (h > _overlayHeight - y) 388 h = _overlayHeight - y; 389 390 if (w <= 0 || h <= 0) 391 return; 392 393 OverlayColor *dst = _overlayPixels + (y * _overlayWidth + x); 394 if (_overlayWidth == pitch && pitch == w) { 395 memcpy(dst, buf, h * w * sizeof(OverlayColor)); 396 } else { 397 do { 398 memcpy(dst, buf, w * sizeof(OverlayColor)); 399 buf += pitch; 400 dst += _overlayWidth; 401 } while (--h); 402 } 403 } 404 405 int16 OSystem_Wii::getOverlayWidth() { 406 return _overlayWidth; 407 } 408 409 int16 OSystem_Wii::getOverlayHeight() { 410 return _overlayHeight; 411 } 412 413 OverlayColor OSystem_Wii::RGBToColor(uint8 r, uint8 g, uint8 b) { 414 return (((r >> 3) & 0x1f) << 11) | (((g >> 2) & 0x3f) << 5 ) | 415 ((b >> 3) & 0x1f); 416 } 417 418 void OSystem_Wii::colorToRGB(OverlayColor color, uint8 &r, uint8 &g, uint8 &b) { 419 r = ((color >> 11) & 0x1f) << 3; 420 g = ((color >> 5) & 0x3f) << 2; 421 b = (color & 0x1f) << 3; 422 } 423 424 OverlayColor OSystem_Wii::ARGBToColor(uint8 a, uint8 r, uint8 g, uint8 b) { 425 TRACE(0); 426 return RGBToColor(r, g, b); 427 } 428 429 void OSystem_Wii::colorToARGB(OverlayColor color, uint8 &a, uint8 &r, uint8 &g, 430 uint8 &b) { 431 TRACE(0); 432 a = 0xff; 433 colorToRGB(color, r, g, b); 434 } 435 436 bool OSystem_Wii::showMouse(bool visible) { 437 bool last = _mouseVisible; 438 _mouseVisible = visible; 439 440 return last; 441 } 442 443 void OSystem_Wii::warpMouse(int x, int y) { 444 _mouseX = x; 445 _mouseY = y; 446 } 447 448 void OSystem_Wii::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, 449 int hotspotY, byte keycolor, 450 int cursorTargetScale) { 451 (void) cursorTargetScale; // TODO 452 453 _mouseWidth = w; 454 _mouseHeight = h; 455 _mouseHotspotX = hotspotX; 456 _mouseHotspotY = hotspotY; 457 _mouseKeyColor = keycolor; 458 459 if (_mouseCursor) 460 free(_mouseCursor); 461 462 _mouseCursor = (u8 *) memalign(32, w * h); 463 memcpy(_mouseCursor, buf, w * h); 464 } 465 -
backends/platform/wii/osystem_events.cpp
1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 */ 21 22 #include <unistd.h> 23 24 #ifndef GAMECUBE 25 #include <wiiuse/wpad.h> 26 #endif 27 28 #include <ogc/lwp_watchdog.h> 29 30 #include "osystem.h" 31 32 #define TIMER_THREAD_STACKSIZE (1024 * 32) 33 #define TIMER_THREAD_PRIO 64 34 35 #define PAD_CHECK_TIME 40 36 37 #ifndef GAMECUBE 38 #define PADS_A (PAD_BUTTON_A | (WPAD_BUTTON_A << 16)) 39 #define PADS_B (PAD_BUTTON_B | (WPAD_BUTTON_B << 16)) 40 #define PADS_X (PAD_BUTTON_X | (WPAD_BUTTON_MINUS << 16)) 41 #define PADS_Y (PAD_BUTTON_Y | (WPAD_BUTTON_PLUS << 16)) 42 #define PADS_Z (PAD_TRIGGER_Z | (WPAD_BUTTON_2 << 16)) 43 #define PADS_START (PAD_BUTTON_START | (WPAD_BUTTON_HOME << 16)) 44 #define PADS_UP (PAD_BUTTON_UP | (WPAD_BUTTON_UP << 16)) 45 #define PADS_DOWN (PAD_BUTTON_DOWN | (WPAD_BUTTON_DOWN << 16)) 46 #define PADS_LEFT (PAD_BUTTON_LEFT | (WPAD_BUTTON_LEFT << 16)) 47 #define PADS_RIGHT (PAD_BUTTON_RIGHT | (WPAD_BUTTON_RIGHT << 16)) 48 #else 49 #define PADS_A PAD_BUTTON_A 50 #define PADS_B PAD_BUTTON_B 51 #define PADS_X PAD_BUTTON_X 52 #define PADS_Y PAD_BUTTON_Y 53 #define PADS_Z PAD_TRIGGER_Z 54 #define PADS_START PAD_BUTTON_START 55 #define PADS_UP PAD_BUTTON_UP 56 #define PADS_DOWN PAD_BUTTON_DOWN 57 #define PADS_LEFT PAD_BUTTON_LEFT 58 #define PADS_RIGHT PAD_BUTTON_RIGHT 59 #endif 60 61 static lwpq_t timer_queue; 62 static lwp_t timer_thread; 63 static u8 *timer_stack; 64 static bool timer_thread_running = false; 65 static bool timer_thread_quit = false; 66 67 static void * timer_thread_func(void *arg) { 68 while (!timer_thread_quit) { 69 DefaultTimerManager *tm = 70 (DefaultTimerManager *) g_system->getTimerManager(); 71 tm->handler(); 72 73 usleep(1000 * 10); 74 } 75 76 return NULL; 77 } 78 79 #ifndef GAMECUBE 80 // smoothing algorithm by marcan, thx buddy! 81 // the following license applies to smooth_ir() 82 83 /*------------------------------------------------------------- 84 85 Copyright (C) 2008 86 Hector Martin (marcan) 87 88 This software is provided 'as-is', without any express or implied 89 warranty. In no event will the authors be held liable for any 90 damages arising from the use of this software. 91 92 Permission is granted to anyone to use this software for any 93 purpose, including commercial applications, and to alter it and 94 redistribute it freely, subject to the following restrictions: 95 96 1. The origin of this software must not be misrepresented; you 97 must not claim that you wrote the original software. If you use 98 this software in a product, an acknowledgment in the product 99 documentation would be appreciated but is not required. 100 101 2. Altered source versions must be plainly marked as such, and 102 must not be misrepresented as being the original software. 103 104 3. This notice may not be removed or altered from any source 105 distribution. 106 107 -------------------------------------------------------------*/ 108 109 #define SMOOTH_IR_RADIUS 8.0f 110 #define SMOOTH_IR_SPEED 0.25f 111 #define SMOOTH_IR_DEADZONE 2.5f 112 #define SMOOTH_IR_ERRCNT 3 113 114 u32 smooth_ir(const WPADData *wpad, s32 *sx, s32 *sy) { 115 static u32 errors = SMOOTH_IR_ERRCNT; 116 static f32 cx = 0.0, cy = 0.0; 117 118 f32 dx, dy, d, theta; 119 120 // wiiuse likes to return (0,0) when things are screwy but tracking 121 // isn't totally lost so we filter it out here 122 if ((wpad->err == WPAD_ERR_NONE) && (wpad->ir.num_dots > 1) && 123 (wpad->ir.x != 0 || wpad->ir.y != 0)) { 124 if (errors >= SMOOTH_IR_ERRCNT) { 125 cx = wpad->ir.x; 126 cy = wpad->ir.y; 127 } 128 129 errors = 0; 130 131 dx = (f32) wpad->ir.x - cx; 132 dy = (f32) wpad->ir.y - cy; 133 d = sqrtf(dx*dx + dy*dy); 134 135 if (d > SMOOTH_IR_DEADZONE) { 136 theta = atan2f(dy, dx); 137 138 if (d < SMOOTH_IR_RADIUS) { 139 cx += dx * SMOOTH_IR_SPEED; 140 cy += dy * SMOOTH_IR_SPEED; 141 } else { 142 cx = (f32) wpad->ir.x - cosf(theta) * SMOOTH_IR_RADIUS; 143 cy = (f32) wpad->ir.y - sinf(theta) * SMOOTH_IR_RADIUS; 144 } 145 } 146 147 *sx = (s32) cx; 148 *sy = (s32) cy; 149 150 return true; 151 } else { 152 if (errors < SMOOTH_IR_ERRCNT) 153 errors++; 154 155 return false; 156 } 157 } 158 #endif 159 160 void OSystem_Wii::initEvents() { 161 TRACE(0); 162 163 timer_thread_quit = false; 164 165 timer_stack = (u8 *) memalign(32, TIMER_THREAD_STACKSIZE); 166 memset(timer_stack, 0, TIMER_THREAD_STACKSIZE); 167 168 LWP_InitQueue(&timer_queue); 169 170 s32 res = LWP_CreateThread(&timer_thread, timer_thread_func, NULL, 171 timer_stack, TIMER_THREAD_STACKSIZE, 172 TIMER_THREAD_PRIO); 173 174 if (res) { 175 printf("ERROR creating timer thread: %d\n", res); 176 LWP_CloseQueue(timer_queue); 177 } 178 179 timer_thread_running = res == 0; 180 181 #ifndef GAMECUBE 182 WPAD_Init(); 183 WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_CORE_ACC_IR); 184 WPAD_SetSleepTime(30); 185 #endif 186 } 187 188 void OSystem_Wii::deinitEvents() { 189 TRACE(0); 190 191 if (timer_thread_running) { 192 timer_thread_quit = true; 193 LWP_ThreadBroadcast(timer_queue); 194 195 LWP_JoinThread(timer_thread, NULL); 196 LWP_CloseQueue(timer_queue); 197 198 timer_thread_running = false; 199 } 200 201 #ifndef GAMECUBE 202 WPAD_Shutdown(); 203 #endif 204 } 205 206 void OSystem_Wii::updateEventScreenResolution() { 207 #ifndef GAMECUBE 208 WPAD_SetVRes(WPAD_CHAN_0, _currentWidth, _currentHeight); 209 #endif 210 } 211 212 #define KBD_EVENT(pad_button, kbd_keycode, kbd_ascii) \ 213 do { \ 214 if ((bd | bu) & pad_button) { \ 215 if (bd & pad_button) \ 216 event.type = Common::EVENT_KEYDOWN; \ 217 else \ 218 event.type = Common::EVENT_KEYUP; \ 219 event.kbd.keycode = kbd_keycode; \ 220 event.kbd.ascii = kbd_ascii; \ 221 return true; \ 222 } \ 223 } while (0) 224 225 bool OSystem_Wii::pollEvent(Common::Event &event) { 226 u32 bd, bh, bu; 227 PAD_ScanPads(); 228 229 bd = PAD_ButtonsDown(0); 230 bh = PAD_ButtonsHeld(0); 231 bu = PAD_ButtonsUp(0); 232 233 #ifndef GAMECUBE 234 if (WPAD_GetStatus() == WPAD_STATE_ENABLED) { 235 WPAD_ScanPads(); 236 237 bd |= WPAD_ButtonsDown(0) << 16; 238 bh |= WPAD_ButtonsHeld(0) << 16; 239 bu |= WPAD_ButtonsUp(0) << 16; 240 } 241 #endif 242 243 if (bd || bu) { 244 if (bh & PADS_UP) 245 event.kbd.flags = Common::KBD_SHIFT; 246 247 KBD_EVENT(PADS_Z, Common::KEYCODE_RETURN, Common::ASCII_RETURN); 248 249 KBD_EVENT(PADS_X, Common::KEYCODE_ESCAPE, Common::ASCII_ESCAPE); 250 251 KBD_EVENT(PADS_Y, Common::KEYCODE_PERIOD, '.'); 252 253 KBD_EVENT(PADS_START, Common::KEYCODE_F5, Common::ASCII_F5); 254 255 KBD_EVENT(PADS_UP, Common::KEYCODE_LSHIFT, 0); 256 257 KBD_EVENT(PADS_LEFT, Common::KEYCODE_0, '0'); 258 259 if ((bd | bu) & (PADS_A | PADS_B)) { 260 if (bd & PADS_A) 261 event.type = Common::EVENT_LBUTTONDOWN; 262 else if (bu & PADS_A) 263 event.type = Common::EVENT_LBUTTONUP; 264 else if (bd & PADS_B) 265 event.type = Common::EVENT_RBUTTONDOWN; 266 else if (bu & PADS_B) 267 event.type = Common::EVENT_RBUTTONUP; 268 269 event.mouse.x = _mouseX; 270 event.mouse.y = _mouseY; 271 272 return true; 273 } 274 } 275 276 s32 mx = _mouseX; 277 s32 my = _mouseY; 278 279 #ifndef GAMECUBE 280 if ((WPAD_GetStatus() == WPAD_STATE_ENABLED) && 281 (WPAD_Probe(0, NULL) == WPAD_ERR_NONE)) { 282 WPADData wpad; 283 284 WPAD_Read(0, &wpad); 285 286 if (smooth_ir(&wpad, &mx, &my)) { 287 if ((mx != _mouseX) || (my != _mouseY)) { 288 event.type = Common::EVENT_MOUSEMOVE; 289 event.mouse.x = _mouseX = mx; 290 event.mouse.y = _mouseY = my; 291 292 return true; 293 } 294 } 295 } 296 #endif 297 298 uint32 time = getMillis(); 299 if (time - _lastPadCheck > PAD_CHECK_TIME) { 300 _lastPadCheck = time; 301 302 if (abs (PAD_StickX(0)) > 16) 303 mx += PAD_StickX(0) / (4 * _overlayWidth / _currentWidth); 304 if (abs (PAD_StickY(0)) > 16) 305 my -= PAD_StickY(0) / (4 * _overlayHeight / _currentHeight); 306 307 if (mx < 0) 308 mx = 0; 309 if (mx >= _currentWidth) 310 mx = _currentWidth - 1; 311 if (my < 0) 312 my = 0; 313 if (my >= _currentHeight - 1) 314 my = _currentHeight - 1; 315 316 if ((mx != _mouseX) || (my != _mouseY)) { 317 event.type = Common::EVENT_MOUSEMOVE; 318 event.mouse.x = _mouseX = mx; 319 event.mouse.y = _mouseY = my; 320 321 return true; 322 } 323 } 324 325 return false; 326 } 327 -
backends/platform/wii/osystem.h
1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 */ 21 22 #ifndef _WII_OSYSTEM_H_ 23 #define _WII_OSYSTEM_H_ 24 25 #include "common/system.h" 26 #include "base/main.h" 27 28 #include "common/rect.h" 29 #include "common/events.h" 30 31 #include "backends/saves/default/default-saves.h" 32 #include "backends/timer/default/default-timer.h" 33 #include "graphics/surface.h" 34 #include "sound/mixer.h" 35 36 #include <gctypes.h> 37 #include <gccore.h> 38 #include <ogcsys.h> 39 40 class OSystem_Wii : public OSystem { 41 private: 42 s64 _startup_time; 43 syswd_t _alarm; 44 45 u16 *_palette; 46 u16 *_cursorPalette; 47 bool _cursorPaletteDisabled; 48 49 u16 _gameWidth, _gameHeight; 50 u8 *_gamePixels; 51 Graphics::Surface _surface; 52 53 bool _overlayVisible; 54 u16 _overlayWidth, _overlayHeight; 55 u32 _overlaySize; 56 OverlayColor *_overlayPixels; 57 58 u32 _lastScreenUpdate; 59 u16 *_texture; 60 u16 _currentWidth, _currentHeight; 61 62 OSystem::GraphicsMode *_supportedGraphicsModes; 63 s32 _activeGraphicsMode; 64 65 bool _mouseVisible; 66 s32 _mouseX, _mouseY; 67 u32 _mouseWidth, _mouseHeight; 68 s32 _mouseHotspotX, _mouseHotspotY; 69 u8 _mouseKeyColor; 70 u8 *_mouseCursor; 71 72 u32 _lastPadCheck; 73 74 void initGfx(); 75 void deinitGfx(); 76 77 void initSfx(); 78 void deinitSfx(); 79 80 void initEvents(); 81 void deinitEvents(); 82 void updateEventScreenResolution(); 83 84 protected: 85 Common::SaveFileManager *_savefile; 86 Audio::Mixer *_mixer; 87 DefaultTimerManager *_timer; 88 89 public: 90 OSystem_Wii(); 91 virtual ~OSystem_Wii(); 92 93 virtual void initBackend(); 94 95 virtual bool hasFeature(Feature f); 96 virtual void setFeatureState(Feature f, bool enable); 97 virtual bool getFeatureState(Feature f); 98 virtual const GraphicsMode *getSupportedGraphicsModes() const; 99 virtual int getDefaultGraphicsMode() const; 100 bool setGraphicsMode(const char *name); 101 virtual bool setGraphicsMode(int mode); 102 virtual int getGraphicsMode() const; 103 virtual void initSize(uint width, uint height); 104 virtual int16 getWidth(); 105 virtual int16 getHeight(); 106 virtual void setPalette(const byte *colors, uint start, uint num); 107 virtual void grabPalette(byte *colors, uint start, uint num); 108 virtual void setCursorPalette(const byte *colors, uint start, uint num); 109 virtual void disableCursorPalette(bool disable); 110 virtual void copyRectToScreen(const byte *buf, int pitch, int x, int y, 111 int w, int h); 112 virtual void updateScreen(); 113 virtual Graphics::Surface *lockScreen(); 114 virtual void unlockScreen(); 115 virtual void setShakePos(int shakeOffset); 116 117 virtual void showOverlay(); 118 virtual void hideOverlay(); 119 virtual void clearOverlay(); 120 virtual void grabOverlay(OverlayColor *buf, int pitch); 121 virtual void copyRectToOverlay(const OverlayColor *buf, int pitch, 122 int x, int y, int w, int h); 123 virtual int16 getOverlayWidth(); 124 virtual int16 getOverlayHeight(); 125 126 virtual OverlayColor RGBToColor(uint8 r, uint8 g, uint8 b); 127 virtual void colorToRGB(OverlayColor color, uint8 &r, uint8 &g, uint8 &b); 128 virtual OverlayColor ARGBToColor(uint8 a, uint8 r, uint8 g, uint8 b); 129 virtual void colorToARGB(OverlayColor color, uint8 &a, uint8 &r, 130 uint8 &g, uint8 &b); 131 132 virtual bool showMouse(bool visible); 133 134 virtual void warpMouse(int x, int y); 135 virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, 136 int hotspotY, byte keycolor = 255, 137 int cursorTargetScale = 1); 138 139 virtual bool pollEvent(Common::Event &event); 140 virtual uint32 getMillis(); 141 virtual void delayMillis(uint msecs); 142 143 virtual MutexRef createMutex(); 144 virtual void lockMutex(MutexRef mutex); 145 virtual void unlockMutex(MutexRef mutex); 146 virtual void deleteMutex(MutexRef mutex); 147 148 typedef void (*SoundProc)(void *param, byte *buf, int len); 149 virtual int getOutputSampleRate() const; 150 151 virtual void quit(); 152 153 virtual void setWindowCaption(const char *caption); 154 155 virtual Common::SaveFileManager *getSavefileManager(); 156 virtual Audio::Mixer *getMixer(); 157 virtual Common::TimerManager *getTimerManager(); 158 FilesystemFactory *getFilesystemFactory(); 159 void getTimeAndDate(struct tm &t) const; 160 }; 161 162 #endif 163 -
backends/platform/wii/gecko_console.cpp
1 /*------------------------------------------------------------- 2 3 Copyright (C) 2008 4 Hector Martin (marcan) 5 6 This software is provided 'as-is', without any express or implied 7 warranty. In no event will the authors be held liable for any 8 damages arising from the use of this software. 9 10 Permission is granted to anyone to use this software for any 11 purpose, including commercial applications, and to alter it and 12 redistribute it freely, subject to the following restrictions: 13 14 1. The origin of this software must not be misrepresented; you 15 must not claim that you wrote the original software. If you use 16 this software in a product, an acknowledgment in the product 17 documentation would be appreciated but is not required. 18 19 2. Altered source versions must be plainly marked as such, and 20 must not be misrepresented as being the original software. 21 22 3. This notice may not be removed or altered from any source 23 distribution. 24 25 -------------------------------------------------------------*/ 26 27 #include <stdio.h> 28 #include <sys/iosupport.h> 29 #include <ogcsys.h> 30 #include <gccore.h> 31 #include <reent.h> 32 33 #include "gecko_console.h" 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 static const devoptab_t *dotab_console; 40 int usb_sendbuffer_safe(s32 chn,const void *buffer,int size); 41 int usb_sendbuffer(s32 chn,const void *buffer,int size); 42 43 int __gecko_write(struct _reent *r,int fd,const char *ptr,int len) { 44 char *tmp = (char*)ptr; 45 u32 level; 46 if(dotab_console) 47 dotab_console->write_r(r,fd,ptr,len); 48 49 if(!tmp || len<=0) 50 return -1; 51 level = IRQ_Disable(); 52 usb_sendbuffer(1, ptr, len); 53 IRQ_Restore(level); 54 return len; 55 } 56 57 const devoptab_t dotab_gecko = { 58 "stdout", // device name 59 0, // size of file structure 60 NULL, // device open 61 NULL, // device close 62 __gecko_write, // device write 63 NULL, // device read 64 NULL, // device seek 65 NULL, // device fstat 66 NULL, // device stat 67 NULL, // device link 68 NULL, // device unlink 69 NULL, // device chdir 70 NULL, // device rename 71 NULL, // device mkdir 72 0, // dirStateSize 73 NULL, // device diropen_r 74 NULL, // device dirreset_r 75 NULL, // device dirnext_r 76 NULL, // device dirclose_r 77 NULL // device statvfs_r 78 }; 79 80 void gecko_console_init(int chain) { 81 dotab_console = NULL; 82 if(chain) 83 dotab_console = devoptab_list[STD_OUT]; 84 devoptab_list[STD_OUT] = &dotab_gecko; 85 devoptab_list[STD_ERR] = &dotab_gecko; 86 } 87 88 #ifdef __cplusplus 89 } 90 #endif 91 -
backends/platform/wii/gx_supp.h
1 /**************************************************************************** 2 * Generic GX Scaler 3 * softdev 2007 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License along 16 * with this program; if not, write to the Free Software Foundation, Inc., 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * NGC GX Video Functions 20 * 21 * These are pretty standard functions to setup and use GX scaling. 22 ****************************************************************************/ 23 #ifndef _WII_GX_SUPP_H_ 24 #define _WII_GX_SUPP_H_ 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 void GX_InitVideo(); 31 32 void GX_Start(u16 width, u16 height, s16 haspect, s16 vaspect); 33 void GX_Render(u16 width, u16 height, u8 *buffer, u16 pitch); 34 35 #ifdef __cplusplus 36 } 37 #endif 38 39 #endif -
backends/platform/wii/portdefs.h
1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 */ 21 22 #ifndef PORTDEFS_H 23 #define PORTDEFS_H 24 25 #include <stdio.h> 26 #include <stdlib.h> 27 #include <string.h> 28 #include <stdarg.h> 29 #include <malloc.h> 30 #include <math.h> 31 #include <ctype.h> 32 #include <assert.h> 33 34 #define DATA_PATH "/scummvm" 35 36 #ifdef DEBUG_WII 37 #define TRACE(x) printf("passing '%s' (%d): %d\n", __FUNCTION__, __LINE__, x); 38 #else 39 #define TRACE(x) 40 #endif 41 42 #endif /* PORTDEFS_H */ 43 -
backends/platform/wii/Makefile
1 DEBUG_WII = 1 2 3 ENABLE_SCUMM = 1 4 ENABLE_SCUMM_7_8 = 1 5 ENABLE_HE = 1 6 # ENABLE_AGI = 1 7 ENABLE_AGOS = 1 8 ENABLE_CINE = 1 9 ENABLE_CRUISE = 1 10 ENABLE_DRASCULA = 1 11 ENABLE_GOB = 1 12 ENABLE_IGOR = 1 13 ENABLE_KYRA = 1 14 ENABLE_LURE = 1 15 ENABLE_M4 = 1 16 ENABLE_MADE = 1 17 ENABLE_PARALLACTION = 1 18 ENABLE_QUEEN = 1 19 ENABLE_SAGA = 1 20 ENABLE_SKY = 1 21 ENABLE_SWORD1 = 1 22 ENABLE_SWORD2 = 1 23 ENABLE_TOUCHE = 1 24 25 DISABLE_HQ_SCALERS = 1 26 DISABLE_SCALERS = 1 27 28 USE_ZLIB = 1 29 USE_MAD = 1 30 USE_TREMOR = 1 31 USE_FLAC = 1 32 USE_MPEG2 = 1 33 USE_MT32EMU = 1 34 35 srcdir = ../../.. 36 VPATH = $(srcdir) 37 HAVE_GCC3 = 1 38 39 THEMEPATH = $(srcdir)/gui/themes 40 EDPATH = $(srcdir)/dists/engine-data 41 DISTPATH = $(srcdir)/dists/wii 42 43 ifeq ($(strip $(DEVKITPPC)),) 44 $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC") 45 endif 46 47 PREFIX = $(DEVKITPPC)/bin/powerpc-gekko- 48 CXX = $(PREFIX)g++ 49 AS = $(PREFIX)gcc 50 LD = $(PREFIX)gcc 51 AR = $(PREFIX)ar cru 52 RANLIB = $(PREFIX)ranlib 53 STRIP = $(PREFIX)strip -g 54 OBJCOPY = $(PREFIX)objcopy 55 MKDIR = mkdir -p 56 RM = rm -f 57 CP = cp -f 58 59 TARGET = scummvm-wii 60 61 MACHDEP = -DGEKKO -mrvl -mcpu=750 -meabi -mhard-float \ 62 -ffunction-sections -fdata-sections -fmodulo-sched 63 64 INCDIR = $(srcdir) . $(srcdir)/engines/ . $(DEVKITPRO)/libogc/include 65 LIBDIR = . $(DEVKITPRO)/libogc/lib/wii 66 67 CXXFLAGS = -g -Os -Wall $(MACHDEP) -DNONSTANDARD_PORT -D__WII__ \ 68 -Wno-multichar -fno-exceptions -fno-rtti 69 70 CXXFLAGS += $(addprefix -I,$(INCDIR)) 71 LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(TARGET).elf.map 72 LDFLAGS += $(addprefix -L,$(LIBDIR)) 73 LIBS = -lstdc++ -lfat -lwiiuse -lbte -logc -lm 74 75 CXXFLAGS += -I$(DEVKITPRO)/3rd/wii/include 76 LDFLAGS += -L$(DEVKITPRO)/3rd/wii/lib 77 78 ifdef DEBUG_WII 79 CXXFLAGS += -DDEBUG_WII 80 LIBS += -ldb 81 endif 82 83 ifdef USE_ZLIB 84 CXXFLAGS += -DUSE_ZLIB 85 LIBS += -lz 86 endif 87 88 ifdef USE_MAD 89 CXXFLAGS += -DUSE_MAD -I$(DEVKITPRO)/libogc/include/mad 90 LIBS += -lmad 91 endif 92 93 ifdef USE_TREMOR 94 CXXFLAGS += -DUSE_VORBIS -DUSE_TREMOR 95 LIBS += -lvorbisidec 96 endif 97 98 ifdef USE_FLAC 99 CXXFLAGS += -DUSE_FLAC 100 LIBS += -lFLAC 101 endif 102 103 ifdef USE_MPEG2 104 CXXFLAGS += -DUSE_MPEG2 105 LIBS += -lmpeg2 106 endif 107 108 ifdef USE_MT32EMU 109 CXXFLAGS += -DUSE_MT32EMU 110 endif 111 112 OBJS := main.o \ 113 gecko_console.o \ 114 gx_supp.o \ 115 osystem.o \ 116 osystem_gfx.o \ 117 osystem_sfx.o \ 118 osystem_events.o 119 120 MODULE_DIRS += . 121 122 include $(srcdir)/Makefile.common 123 124 .PHONY: clean distclean upload dist 125 126 all: $(TARGET).dol 127 128 $(TARGET).dol: $(TARGET).elf 129 $(OBJCOPY) -O binary $< $@ 130 131 $(TARGET).elf: $(OBJS) 132 $(LD) $^ $(LDFLAGS) $(LIBS) -o $@ 133 134 clean: 135 @-$(RM) *.o *.d $(TARGET).elf $(TARGET).elf.map $(TARGET).dol 136 @-$(RM) -r backends base common engines graphics gui sound 137 138 distclean: clean 139 @-$(RM) dist 140 141 upload: 142 $(DEVKITPPC)/bin/wiiload $(TARGET).dol 143 144 dist: 145 $(MKDIR) dist/scummvm 146 $(MKDIR) dist/apps/scummvm 147 $(CP) $(TARGET).dol dist/apps/scummvm/boot.dol 148 $(CP) $(DISTPATH)/meta.xml dist/apps/scummvm/ 149 $(CP) $(DISTPATH)/icon.png dist/apps/scummvm/ 150 $(CP) $(DISTPATH)/READMII dist/apps/scummvm/ 151 $(CP) $(srcdir)/AUTHORS dist/apps/scummvm/ 152 $(CP) $(srcdir)/COPYING dist/apps/scummvm/ 153 $(CP) $(srcdir)/COPYRIGHT dist/apps/scummvm/ 154 $(CP) $(srcdir)/NEWS dist/apps/scummvm/ 155 $(CP) $(srcdir)/README dist/apps/scummvm/ 156 $(CP) $(THEMEPATH)/modern.* dist/scummvm 157 $(CP) $(EDPATH)/*.tbl dist/scummvm 158 $(CP) $(EDPATH)/*.dat dist/scummvm 159 $(CP) $(EDPATH)/*.cpt dist/scummvm 160 -
backends/fs/wii/wii-fs.cpp
1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #if defined(__WII__) 24 25 #include "backends/fs/abstract-fs.h" 26 27 #include <sys/dir.h> 28 29 #include <sys/types.h> 30 #include <sys/stat.h> 31 #include <unistd.h> 32 33 /** 34 * Implementation of the ScummVM file system API based on Wii. 35 * 36 * Parts of this class are documented in the base interface class, AbstractFilesystemNode. 37 */ 38 class WiiFilesystemNode : public AbstractFilesystemNode { 39 protected: 40 String _displayName; 41 String _path; 42 bool _isDirectory, _isReadable, _isWritable; 43 44 public: 45 /** 46 * Creates a WiiFilesystemNode with the root node as path. 47 */ 48 WiiFilesystemNode(); 49 50 /** 51 * Creates a WiiFilesystemNode for a given path. 52 * 53 * @param path String with the path the new node should point to. 54 * @param verify true if the isValid and isDirectory flags should be verified during the construction. 55 */ 56 WiiFilesystemNode(const String &path, bool verify); 57 58 virtual bool exists() const; 59 virtual String getDisplayName() const { return _displayName; } 60 virtual String getName() const { return _displayName; } 61 virtual String getPath() const { return _path; } 62 virtual bool isDirectory() const { return _isDirectory; } 63 virtual bool isReadable() const { return _isReadable; } 64 virtual bool isWritable() const { return _isWritable; } 65 66 virtual AbstractFilesystemNode *getChild(const String &n) const; 67 virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const; 68 virtual AbstractFilesystemNode *getParent() const; 69 70 private: 71 virtual void setFlags(); 72 }; 73 74 /** 75 * Returns the last component of a given path. 76 * 77 * Examples: 78 * /foo/bar.txt would return /bar.txt 79 * /foo/bar/ would return /bar/ 80 * 81 * @param str String containing the path. 82 * @return Pointer to the first char of the last component inside str. 83 */ 84 const char *lastPathComponent(const Common::String &str) { 85 if(str.empty()) 86 return ""; 87 88 const char *start = str.c_str(); 89 const char *cur = start + str.size() - 2; 90 91 while (cur >= start && *cur != '/') { 92 --cur; 93 } 94 95 return cur + 1; 96 } 97 98 void WiiFilesystemNode::setFlags() { 99 struct stat st; 100 101 _isDirectory = false; 102 _isReadable = false; 103 _isWritable = false; 104 105 if (!stat(_path.c_str(), &st)) { 106 _isDirectory = S_ISDIR(st.st_mode); 107 _isReadable = (st.st_mode & S_IRUSR) > 0; 108 _isWritable = (st.st_mode & S_IWUSR) > 0; 109 } 110 } 111 112 113 WiiFilesystemNode::WiiFilesystemNode() { 114 // The root dir. 115 _path = "/"; 116 _displayName = _path; 117 118 setFlags(); 119 } 120 121 WiiFilesystemNode::WiiFilesystemNode(const String &p, bool verify) { 122 assert(p.size() > 0); 123 124 _path = p; 125 126 _displayName = lastPathComponent(_path); 127 128 if (verify) 129 setFlags(); 130 } 131 132 bool WiiFilesystemNode::exists() const { 133 struct stat st; 134 return stat(_path.c_str (), &st) == 0; 135 } 136 137 AbstractFilesystemNode *WiiFilesystemNode::getChild(const String &n) const { 138 assert(_isDirectory); 139 140 String newPath(_path); 141 if (newPath.lastChar() != '/') 142 newPath += '/'; 143 newPath += n; 144 145 return new WiiFilesystemNode(newPath, true); 146 } 147 148 bool WiiFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const { 149 assert(_isDirectory); 150 151 DIR_ITER* dp = diropen (_path.c_str()); 152 153 if (dp == NULL) { 154 TRACE(0); 155 return false; 156 } 157 158 char filename[MAXPATHLEN]; 159 struct stat st; 160 161 while (dirnext(dp, filename, &st) == 0) { 162 if (strcmp(filename, ".") == 0 || strcmp(filename, "..") == 0) 163 continue; 164 165 String newPath(_path); 166 if (newPath.lastChar() != '/') 167 newPath += '/'; 168 newPath += filename; 169 170 bool isDir = S_ISDIR(st.st_mode); 171 172 if ((mode == FilesystemNode::kListFilesOnly && isDir) || 173 (mode == FilesystemNode::kListDirectoriesOnly && !isDir)) 174 continue; 175 176 if (isDir) 177 newPath += '/'; 178 179 WiiFilesystemNode *n = new WiiFilesystemNode(newPath, false); 180 n->_isDirectory = isDir; 181 n->_isReadable = (st.st_mode & S_IRUSR) > 0; 182 n->_isWritable = (st.st_mode & S_IWUSR) > 0; 183 184 myList.push_back(n); 185 } 186 187 dirclose(dp); 188 189 return true; 190 } 191 192 AbstractFilesystemNode *WiiFilesystemNode::getParent() const { 193 if (_path == "/") 194 return 0; 195 196 const char *start = _path.c_str(); 197 const char *end = lastPathComponent(_path); 198 199 return new WiiFilesystemNode(String(start, end - start), true); 200 } 201 202 #endif //#if defined(__WII__) 203 -
backends/fs/wii/wii-fs-factory.cpp
1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #if defined(__WII__) 24 #include "backends/fs/wii/wii-fs-factory.h" 25 #include "backends/fs/wii/wii-fs.cpp" 26 27 DECLARE_SINGLETON(WiiFilesystemFactory); 28 29 AbstractFilesystemNode *WiiFilesystemFactory::makeRootFileNode() const { 30 return new WiiFilesystemNode(); 31 } 32 33 AbstractFilesystemNode *WiiFilesystemFactory::makeCurrentDirectoryFileNode() const { 34 return new WiiFilesystemNode("/scummvm", true); 35 } 36 37 AbstractFilesystemNode *WiiFilesystemFactory::makeFileNodePath(const String &path) const { 38 return new WiiFilesystemNode(path, true); 39 } 40 #endif 41 -
backends/fs/wii/wii-fs-factory.h
1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #ifndef _WII_FILESYSTEM_FACTORY_H_ 24 #define _WII_FILESYSTEM_FACTORY_H_ 25 26 #include "common/singleton.h" 27 #include "backends/fs/fs-factory.h" 28 29 /** 30 * Creates WiiFilesystemNode objects. 31 * 32 * Parts of this class are documented in the base interface class, FilesystemFactory. 33 */ 34 class WiiFilesystemFactory : public FilesystemFactory, public Common::Singleton<WiiFilesystemFactory> { 35 public: 36 typedef Common::String String; 37 38 virtual AbstractFilesystemNode *makeRootFileNode() const; 39 virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; 40 virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; 41 42 protected: 43 WiiFilesystemFactory() {}; 44 45 private: 46 friend class Common::Singleton<SingletonBaseType>; 47 }; 48 49 #endif /*Wii_FILESYSTEM_FACTORY_H*/ 50 -
backends/module.mk
9 9 fs/psp/psp-fs-factory.o \ 10 10 fs/symbian/symbian-fs-factory.o \ 11 11 fs/windows/windows-fs-factory.o \ 12 fs/wii/wii-fs-factory.o \ 12 13 events/default/default-events.o \ 13 14 midi/alsa.o \ 14 15 midi/camd.o \