Ticket #8871: scummvm-wii-take4.diff

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

diff against trunk, take four

  • 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 &amp; 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
     10Some 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

     
     1Wii port of ScummVM README
     2--------------------------
     3
     4features not compiled in:
     5- the AGI game engine
     6
     7REQUIREMENTS
     8
     9  - sd card
     10  - wiimote or gamecube controller in port 1
     11
     12INSTALL
     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
     19RUN
     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
     27CONTROLS
     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
     53THANKS
     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
    
     
    369369        #define STRINGBUFLEN 256
    370370        #define printf(fmt, ...)                                        consolePrintf(fmt, ##__VA_ARGS__)
    371371
     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
    372380#else
    373381        #error No system type defined
    374382
  • common/system.cpp

     
    137137#endif
    138138
    139139FilesystemFactory *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__)
    141141                // These ports already implement this function, so it should never be called.
    142142                return 0;
    143143        #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
     5extern "C" {
     6#endif
     7
     8void 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
     30OSystem_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
     71OSystem_Wii::~OSystem_Wii() {
     72        if (_savefile) {
     73                delete _savefile;
     74                _savefile = NULL;
     75        }
     76
     77        if (_mixer) {
     78                delete _mixer;
     79                _mixer = NULL;
     80        }
     81
     82        if (_timer) {
     83                delete _timer;
     84                _timer = NULL;
     85        }
     86}
     87
     88void OSystem_Wii::initBackend() {
     89        _startup_time = gettime();
     90
     91        _savefile = new DefaultSaveFileManager();
     92        _mixer = new Audio::Mixer();
     93        _timer = new DefaultTimerManager();
     94
     95        initGfx();
     96        initSfx();
     97        initEvents();
     98
     99        OSystem::initBackend();
     100}
     101
     102void OSystem_Wii::quit() {
     103        deinitEvents();
     104        deinitSfx();
     105        deinitGfx();
     106}
     107
     108bool OSystem_Wii::hasFeature(Feature f) {
     109        return f == kFeatureCursorHasPalette;
     110}
     111
     112void OSystem_Wii::setFeatureState(Feature f, bool enable) {
     113}
     114
     115bool OSystem_Wii::getFeatureState(Feature f) {
     116        return false;
     117}
     118
     119uint32 OSystem_Wii::getMillis() {
     120        return ticks_to_millisecs(diff_ticks(_startup_time, gettime()));
     121}
     122
     123void OSystem_Wii::delayMillis(uint msecs) {
     124        usleep(msecs * 1000);
     125}
     126
     127OSystem::MutexRef OSystem_Wii::createMutex() {
     128        mutex_t *mutex = (mutex_t *) malloc(sizeof(mutex_t));
     129        s32 res = LWP_MutexInit(mutex, false);
     130
     131        if (res) {
     132                printf("ERROR creating mutex\n");
     133                delete mutex;
     134                return NULL;
     135        }
     136
     137        return (MutexRef) mutex;
     138}
     139
     140void OSystem_Wii::lockMutex(MutexRef mutex) {
     141        s32 res = LWP_MutexLock(*(mutex_t *) mutex);
     142
     143        if (res)
     144                printf("ERROR locking mutex %p (%d)\n", mutex, res);
     145}
     146
     147void OSystem_Wii::unlockMutex(MutexRef mutex) {
     148        s32 res = LWP_MutexUnlock(*(mutex_t *) mutex);
     149
     150        if (res)
     151                printf("ERROR unlocking mutex %p (%d)\n", mutex, res);
     152}
     153
     154void OSystem_Wii::deleteMutex(MutexRef mutex) {
     155        s32 res = LWP_MutexDestroy(*(mutex_t *) mutex);
     156
     157        if (res)
     158                printf("ERROR destroying mutex %p (%d)\n", mutex, res);
     159}
     160
     161void OSystem_Wii::setWindowCaption(const char *caption) {
     162        printf("window caption: %s\n", caption);
     163}
     164
     165Common::SaveFileManager *OSystem_Wii::getSavefileManager() {
     166        assert(_savefile);
     167        return _savefile;
     168}
     169
     170Audio::Mixer *OSystem_Wii::getMixer() {
     171        assert(_mixer);
     172        return _mixer;
     173}
     174
     175Common::TimerManager *OSystem_Wii::getTimerManager() {
     176        assert(_timer);
     177        return _timer;
     178}
     179
     180FilesystemFactory *OSystem_Wii::getFilesystemFactory() {
     181        return &WiiFilesystemFactory::instance();
     182}
     183
     184void OSystem_Wii::getTimeAndDate(struct tm &t) const {
     185        time_t curTime = time(0);
     186        t = *localtime(&curTime);
     187}
     188
  • 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 <malloc.h>
     23
     24#include "osystem.h"
     25
     26#define SFX_THREAD_STACKSIZE (1024 * 128)
     27#define SFX_THREAD_PRIO 80
     28#define SFX_THREAD_FRAG_SIZE 4096
     29
     30static lwpq_t sfx_queue;
     31static lwp_t sfx_thread;
     32static u8 *sfx_stack;
     33static bool sfx_thread_running = false;
     34static bool sfx_thread_quit = false;
     35
     36static u8 sb = 0;
     37static u8 *sound_buffer[2];
     38
     39static OSystem_Wii::SoundProc sound_proc = NULL;
     40static void *proc_param = NULL;
     41
     42static void audio_switch_buffers() {
     43        AUDIO_StopDMA();
     44        AUDIO_InitDMA((u32) sound_buffer[sb], SFX_THREAD_FRAG_SIZE);
     45        AUDIO_StartDMA();
     46
     47        LWP_ThreadSignal(sfx_queue);
     48}
     49
     50static void * sfx_thread_func(void *arg) {
     51        u8 next_sb;
     52
     53        while (true) {
     54                LWP_ThreadSleep(sfx_queue);
     55
     56                if (sfx_thread_quit)
     57                        break;
     58
     59                next_sb = sb ^ 1;
     60                sound_proc(proc_param, sound_buffer[next_sb], SFX_THREAD_FRAG_SIZE);
     61                DCFlushRange(sound_buffer[next_sb], SFX_THREAD_FRAG_SIZE);
     62
     63                sb = next_sb;
     64        }
     65
     66        return NULL;
     67}
     68
     69void OSystem_Wii::initSfx() {
     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
     109void OSystem_Wii::deinitSfx() {
     110        if (_mixer)
     111                _mixer->setReady(false);
     112
     113        AUDIO_StopDMA();
     114        AUDIO_RegisterDMACallback(NULL);
     115
     116        if (sfx_thread_running) {
     117                sfx_thread_quit = true;
     118                LWP_ThreadBroadcast(sfx_queue);
     119
     120                LWP_JoinThread(sfx_thread, NULL);
     121                LWP_CloseQueue(sfx_queue);
     122
     123                sfx_thread_running = false;
     124
     125                free(sound_buffer[0]);
     126                free(sound_buffer[1]);
     127        }
     128}
     129
     130int OSystem_Wii::getOutputSampleRate() const {
     131        return 48000;
     132}
     133
  • 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
     36extern "C" {
     37#endif
     38
     39int 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
     36extern "C" {
     37#endif
     38
     39/*** 2D ***/
     40static u32 whichfb;
     41static u32 *xfb[2];
     42static GXRModeObj *vmode;
     43
     44/*** 3D GX ***/
     45static u8 *gp_fifo;
     46
     47/*** Texture memory ***/
     48static u8 *texturemem;
     49static u32 texturesize;
     50
     51GXTexObj texobj;
     52static Mtx view;
     53static u16 vwidth, vheight, oldvwidth, oldvheight;
     54
     55/* New texture based scaler */
     56typedef struct tagcamera {
     57        Vector pos;
     58        Vector up;
     59        Vector view;
     60} camera;
     61
     62static s16 square[] ATTRIBUTE_ALIGN(32) = {
     63        -HASPECT, VASPECT, 0,
     64        HASPECT, VASPECT, 0,
     65        HASPECT, -VASPECT, 0,
     66        -HASPECT, -VASPECT, 0,
     67};
     68
     69static 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
     75void 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 ****************************************************************************/
     99static 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
     120static 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
     126static 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 ****************************************************************************/
     146void 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****************************************************************************/
     200void 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 <malloc.h>
     23
     24#include "osystem.h"
     25#include "gx_supp.h"
     26
     27#define MAX_FPS 30
     28
     29enum GraphicModeID {
     30        GM_DEFAULT
     31};
     32
     33void OSystem_Wii::initGfx() {
     34        _surface.w = 0;
     35        _surface.h = 0;
     36        _surface.pitch = 0;
     37        _surface.pixels = NULL;
     38        _surface.bytesPerPixel = 0;
     39
     40        GX_InitVideo();
     41
     42        _overlayWidth = 640;
     43        _overlayHeight = 480;
     44
     45        _overlaySize = _overlayWidth * _overlayHeight * 2;
     46        _overlayPixels = (OverlayColor *) memalign(32, _overlaySize);
     47
     48        _palette = (u16 *) memalign(32, 256 * 2);
     49        memset(_palette, 0, 256 * 2);
     50
     51        _cursorPalette = (u16 *) memalign(32, 256 * 2);
     52        memset(_cursorPalette, 0, 256 * 2);
     53
     54        _supportedGraphicsModes = new OSystem::GraphicsMode[2];
     55        _supportedGraphicsModes[0].name = strdup("gx");
     56        _supportedGraphicsModes[0].description = strdup("wii hardware scaler");
     57        _supportedGraphicsModes[0].id = GM_DEFAULT;
     58        _supportedGraphicsModes[1].name = 0;
     59        _supportedGraphicsModes[1].description = 0;
     60        _supportedGraphicsModes[1].id = 0;
     61
     62        _texture = (u16 *) memalign(32, _overlaySize);
     63
     64        GX_Start(_overlayWidth, _overlayHeight, 320, 240);
     65}
     66
     67void OSystem_Wii::deinitGfx() {
     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
     106const OSystem::GraphicsMode* OSystem_Wii::getSupportedGraphicsModes() const {
     107        return _supportedGraphicsModes;
     108}
     109
     110int OSystem_Wii::getDefaultGraphicsMode() const {
     111        return GM_DEFAULT;
     112}
     113
     114bool OSystem_Wii::setGraphicsMode(const char *mode) {
     115        setGraphicsMode(GM_DEFAULT);
     116
     117        return true;
     118}
     119
     120bool OSystem_Wii::setGraphicsMode(int mode) {
     121        return true;
     122}
     123
     124int OSystem_Wii::getGraphicsMode() const {
     125        return _activeGraphicsMode;
     126}
     127
     128void 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
     148int16 OSystem_Wii::getWidth() {
     149        return _gameWidth;
     150}
     151
     152int16 OSystem_Wii::getHeight() {
     153        return _gameHeight;
     154}
     155
     156void 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
     164void 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
     177void 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
     187void OSystem_Wii::disableCursorPalette(bool disable) {
     188        _cursorPaletteDisabled = disable;
     189}
     190
     191void OSystem_Wii::copyRectToScreen(const byte *buf, int pitch, int x, int y,
     192                                                                        int w, int h) {
     193        if (x < 0) {
     194                w += x;
     195                buf -= x;
     196                x = 0;
     197        }
     198
     199        if (y < 0) {
     200                h += y;
     201                buf -= y * pitch;
     202                y = 0;
     203        }
     204
     205        if (w > _gameWidth - x)
     206                w = _gameWidth - x;
     207
     208        if (h > _gameHeight - y)
     209                h = _gameHeight - y;
     210
     211        if (w <= 0 || h <= 0)
     212                return;
     213
     214        byte *dst = _gamePixels + y * _gameWidth + x;
     215        if (_gameWidth == pitch && pitch == w) {
     216                memcpy(dst, buf, h * w);
     217        } else {
     218                do {
     219                        memcpy(dst, buf, w);
     220                        buf += pitch;
     221                        dst += _gameWidth;
     222                } while (--h);
     223        }
     224}
     225
     226void OSystem_Wii::updateScreen() {
     227        static u32 x, y, h, skip;
     228        static s16 msx, msy, mox, moy, mskip;
     229        static u16 mpx, mpy;
     230        static u8 *s;
     231        static u16 *d, *p;
     232
     233        u32 now = getMillis();
     234        if (now - _lastScreenUpdate < 1000 / MAX_FPS)
     235                return;
     236
     237        _lastScreenUpdate = now;
     238
     239        h = 0;
     240        if (_overlayVisible) {
     241                memcpy(_texture, _overlayPixels, _overlaySize);
     242        } else {
     243                for (y = 0; y < _gameHeight; ++y) {
     244                        for (x = 0; x < _gameWidth; ++x)
     245                                _texture[h + x] = _palette[_gamePixels[h + x]];
     246
     247                        h += _gameWidth;
     248                }
     249        }
     250
     251        if (_mouseVisible) {
     252                msx = _mouseX - _mouseHotspotX;
     253                msy = _mouseY - _mouseHotspotY;
     254                mox = 0;
     255                moy = 0;
     256                mpx = _mouseWidth;
     257                mpy = _mouseHeight;
     258
     259                if (msx < 0) {
     260                        mox = -msx;
     261                        mpx -= mox;
     262                        msx = 0;
     263                } else
     264                        if (msx + mpx > _currentWidth - 1)
     265                                mpx = _currentWidth - msx - 1;
     266
     267                if (msy < 0) {
     268                        moy = -msy;
     269                        mpy -= moy;
     270                        msy = 0;
     271                } else
     272                        if (msy + mpy + 1 > _currentHeight - 1)
     273                                mpy = _currentHeight - msy - 1;
     274
     275
     276                if (_cursorPaletteDisabled)
     277                        p = _palette;
     278                else
     279                        p = _cursorPalette;
     280
     281                skip = _currentWidth - mpx;
     282                mskip = _mouseWidth - mpx;
     283
     284                s = _mouseCursor + moy * _mouseWidth + mox;
     285                d = _texture + (msy * _currentWidth + msx);
     286
     287                for (y = 0; y < mpy; ++y) {
     288                        for (x = 0; x < mpx; ++x) {
     289                                if (*s == _mouseKeyColor) {
     290                                        s++;
     291                                        d++;
     292
     293                                        continue;
     294                                }
     295
     296                                *d++ = p[*s];
     297                                s++;
     298                        }
     299
     300                        d += skip;
     301                        s += mskip;
     302                }
     303        }
     304
     305        GX_Render(_currentWidth, _currentHeight, (u8 *) _texture,
     306                                _currentWidth * 2);
     307}
     308
     309Graphics::Surface *OSystem_Wii::lockScreen() {
     310        _surface.pixels = _gamePixels;
     311        _surface.w = _gameWidth;
     312        _surface.h = _gameHeight;
     313        _surface.pitch = _gameWidth;
     314        _surface.bytesPerPixel = 1;
     315
     316        return &_surface;
     317}
     318
     319void OSystem_Wii::unlockScreen() {
     320}
     321
     322void OSystem_Wii::setShakePos(int shakeOffset) {
     323}
     324
     325void OSystem_Wii::showOverlay() {
     326        _mouseX = _overlayWidth / 2;
     327        _mouseY = _overlayHeight / 2;
     328        _overlayVisible = true;
     329        _currentWidth = _overlayWidth;
     330        _currentHeight = _overlayHeight;
     331
     332        updateEventScreenResolution();
     333}
     334
     335void OSystem_Wii::hideOverlay() {
     336        _mouseX = _gameWidth / 2;
     337        _mouseY = _gameHeight / 2;
     338        _overlayVisible = false;
     339        _currentWidth = _gameWidth;
     340        _currentHeight = _gameHeight;
     341
     342        updateEventScreenResolution();
     343}
     344
     345void OSystem_Wii::clearOverlay() {
     346        memset(_overlayPixels, 0, _overlaySize);
     347}
     348
     349void OSystem_Wii::grabOverlay(OverlayColor *buf, int pitch) {
     350        int h = _overlayHeight;
     351        OverlayColor *src = _overlayPixels;
     352
     353        do {
     354                memcpy(buf, src, _overlayWidth * sizeof(OverlayColor));
     355                src += _overlayWidth;
     356                buf += pitch;
     357        } while (--h);
     358}
     359
     360void OSystem_Wii::copyRectToOverlay(const OverlayColor *buf, int pitch, int x,
     361                                                                        int y, int w, int h) {
     362        if (x < 0) {
     363                w += x;
     364                buf -= x;
     365                x = 0;
     366        }
     367
     368        if (y < 0) {
     369                h += y;
     370                buf -= y * pitch;
     371                y = 0;
     372        }
     373
     374        if (w > _overlayWidth - x)
     375                w = _overlayWidth - x;
     376
     377        if (h > _overlayHeight - y)
     378                h = _overlayHeight - y;
     379
     380        if (w <= 0 || h <= 0)
     381                return;
     382
     383        OverlayColor *dst = _overlayPixels + (y * _overlayWidth + x);
     384        if (_overlayWidth == pitch && pitch == w) {
     385                memcpy(dst, buf, h * w * sizeof(OverlayColor));
     386        } else {
     387                do {
     388                        memcpy(dst, buf, w * sizeof(OverlayColor));
     389                        buf += pitch;
     390                        dst += _overlayWidth;
     391                } while (--h);
     392        }
     393}
     394
     395int16 OSystem_Wii::getOverlayWidth() {
     396        return _overlayWidth;
     397}
     398
     399int16 OSystem_Wii::getOverlayHeight() {
     400        return _overlayHeight;
     401}
     402
     403OverlayColor OSystem_Wii::RGBToColor(uint8 r, uint8 g, uint8 b) {
     404        return (((r >> 3) & 0x1f) << 11) | (((g >> 2) & 0x3f) << 5 ) |
     405                        ((b >> 3) & 0x1f);
     406}
     407
     408void OSystem_Wii::colorToRGB(OverlayColor color, uint8 &r, uint8 &g, uint8 &b) {
     409        r = ((color >> 11) & 0x1f) << 3;
     410        g = ((color >> 5) & 0x3f) << 2;
     411        b = (color & 0x1f) << 3;
     412}
     413
     414OverlayColor OSystem_Wii::ARGBToColor(uint8 a, uint8 r, uint8 g, uint8 b) {
     415        return RGBToColor(r, g, b);
     416}
     417
     418void OSystem_Wii::colorToARGB(OverlayColor color, uint8 &a, uint8 &r, uint8 &g,
     419                                                                uint8 &b) {
     420        a = 0xff;
     421        colorToRGB(color, r, g, b);
     422}
     423
     424bool OSystem_Wii::showMouse(bool visible) {
     425        bool last = _mouseVisible;
     426        _mouseVisible = visible;
     427
     428        return last;
     429}
     430
     431void OSystem_Wii::warpMouse(int x, int y) {
     432        _mouseX = x;
     433        _mouseY = y;
     434}
     435
     436void OSystem_Wii::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX,
     437                                                                        int hotspotY, byte keycolor,
     438                                                                        int cursorTargetScale) {
     439        (void) cursorTargetScale; // TODO
     440
     441        _mouseWidth = w;
     442        _mouseHeight = h;
     443        _mouseHotspotX = hotspotX;
     444        _mouseHotspotY = hotspotY;
     445        _mouseKeyColor = keycolor;
     446
     447        if (_mouseCursor)
     448                free(_mouseCursor);
     449
     450        _mouseCursor = (u8 *) memalign(32, w * h);
     451        memcpy(_mouseCursor, buf, w * h);
     452}
     453
  • 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#include <malloc.h>
     24
     25#ifndef GAMECUBE
     26#include <wiiuse/wpad.h>
     27#endif
     28
     29#include <ogc/lwp_watchdog.h>
     30
     31#include "osystem.h"
     32
     33#define TIMER_THREAD_STACKSIZE (1024 * 32)
     34#define TIMER_THREAD_PRIO 64
     35
     36#define PAD_CHECK_TIME 40
     37
     38#ifndef GAMECUBE
     39#define PADS_A (PAD_BUTTON_A | (WPAD_BUTTON_A << 16))
     40#define PADS_B (PAD_BUTTON_B | (WPAD_BUTTON_B << 16))
     41#define PADS_X (PAD_BUTTON_X | (WPAD_BUTTON_MINUS << 16))
     42#define PADS_Y (PAD_BUTTON_Y | (WPAD_BUTTON_PLUS << 16))
     43#define PADS_Z (PAD_TRIGGER_Z | (WPAD_BUTTON_2 << 16))
     44#define PADS_START (PAD_BUTTON_START | (WPAD_BUTTON_HOME << 16))
     45#define PADS_UP (PAD_BUTTON_UP | (WPAD_BUTTON_UP << 16))
     46#define PADS_DOWN (PAD_BUTTON_DOWN | (WPAD_BUTTON_DOWN << 16))
     47#define PADS_LEFT (PAD_BUTTON_LEFT | (WPAD_BUTTON_LEFT << 16))
     48#define PADS_RIGHT (PAD_BUTTON_RIGHT | (WPAD_BUTTON_RIGHT << 16))
     49#else
     50#define PADS_A PAD_BUTTON_A
     51#define PADS_B PAD_BUTTON_B
     52#define PADS_X PAD_BUTTON_X
     53#define PADS_Y PAD_BUTTON_Y
     54#define PADS_Z PAD_TRIGGER_Z
     55#define PADS_START PAD_BUTTON_START
     56#define PADS_UP PAD_BUTTON_UP
     57#define PADS_DOWN PAD_BUTTON_DOWN
     58#define PADS_LEFT PAD_BUTTON_LEFT
     59#define PADS_RIGHT PAD_BUTTON_RIGHT
     60#endif
     61
     62static lwpq_t timer_queue;
     63static lwp_t timer_thread;
     64static u8 *timer_stack;
     65static bool timer_thread_running = false;
     66static bool timer_thread_quit = false;
     67
     68static void * timer_thread_func(void *arg) {
     69        while (!timer_thread_quit) {
     70                DefaultTimerManager *tm =
     71                        (DefaultTimerManager *) g_system->getTimerManager();
     72                tm->handler();
     73
     74                usleep(1000 * 10);
     75        }
     76
     77        return NULL;
     78}
     79
     80void OSystem_Wii::initEvents() {
     81        timer_thread_quit = false;
     82
     83        timer_stack = (u8 *) memalign(32, TIMER_THREAD_STACKSIZE);
     84        memset(timer_stack, 0, TIMER_THREAD_STACKSIZE);
     85
     86        LWP_InitQueue(&timer_queue);
     87
     88        s32 res = LWP_CreateThread(&timer_thread, timer_thread_func, NULL,
     89                                                                timer_stack, TIMER_THREAD_STACKSIZE,
     90                                                                TIMER_THREAD_PRIO);
     91
     92        if (res) {
     93                printf("ERROR creating timer thread: %d\n", res);
     94                LWP_CloseQueue(timer_queue);
     95        }
     96
     97        timer_thread_running = res == 0;
     98
     99#ifndef GAMECUBE
     100        WPAD_Init();
     101        WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);
     102        WPAD_SetIdleTimeout(120);
     103#endif
     104}
     105
     106void OSystem_Wii::deinitEvents() {
     107        if (timer_thread_running) {
     108                timer_thread_quit = true;
     109                LWP_ThreadBroadcast(timer_queue);
     110
     111                LWP_JoinThread(timer_thread, NULL);
     112                LWP_CloseQueue(timer_queue);
     113
     114                timer_thread_running = false;
     115        }
     116
     117#ifndef GAMECUBE
     118        WPAD_Shutdown();
     119#endif
     120}
     121
     122void OSystem_Wii::updateEventScreenResolution() {
     123#ifndef GAMECUBE
     124        WPAD_SetVRes(WPAD_CHAN_0, _currentWidth + 128, _currentHeight + 128);
     125#endif
     126}
     127
     128#define KBD_EVENT(pad_button, kbd_keycode, kbd_ascii) \
     129        do { \
     130                if ((bd | bu) & pad_button) { \
     131                        if (bd & pad_button) \
     132                                event.type = Common::EVENT_KEYDOWN; \
     133                        else \
     134                                event.type = Common::EVENT_KEYUP; \
     135                        event.kbd.keycode = kbd_keycode; \
     136                        event.kbd.ascii = kbd_ascii; \
     137                        return true; \
     138                } \
     139        } while (0)
     140
     141bool OSystem_Wii::pollEvent(Common::Event &event) {
     142        u32 bd, bh, bu;
     143
     144        PAD_ScanPads();
     145
     146        bd = PAD_ButtonsDown(0);
     147        bh = PAD_ButtonsHeld(0);
     148        bu = PAD_ButtonsUp(0);
     149
     150#ifndef GAMECUBE
     151        WPAD_ScanPads();
     152
     153        s32 res = WPAD_Probe(0, NULL);
     154
     155        if (res == WPAD_ERR_NONE) {
     156
     157                bd |= WPAD_ButtonsDown(0) << 16;
     158                bh |= WPAD_ButtonsHeld(0) << 16;
     159                bu |= WPAD_ButtonsUp(0) << 16;
     160        }
     161#endif
     162
     163        if (bd || bu) {
     164                if (bh & PADS_UP)
     165                        event.kbd.flags = Common::KBD_SHIFT;
     166
     167                KBD_EVENT(PADS_Z, Common::KEYCODE_RETURN, Common::ASCII_RETURN);
     168
     169                KBD_EVENT(PADS_X, Common::KEYCODE_ESCAPE, Common::ASCII_ESCAPE);
     170
     171                KBD_EVENT(PADS_Y, Common::KEYCODE_PERIOD, '.');
     172
     173                KBD_EVENT(PADS_START, Common::KEYCODE_F5, Common::ASCII_F5);
     174
     175                KBD_EVENT(PADS_UP, Common::KEYCODE_LSHIFT, 0);
     176
     177                KBD_EVENT(PADS_LEFT, Common::KEYCODE_0, '0');
     178
     179                if ((bd | bu) & (PADS_A | PADS_B)) {
     180                        if (bd & PADS_A)
     181                                event.type = Common::EVENT_LBUTTONDOWN;
     182                        else if (bu & PADS_A)
     183                                event.type = Common::EVENT_LBUTTONUP;
     184                        else if (bd & PADS_B)
     185                                event.type = Common::EVENT_RBUTTONDOWN;
     186                        else if (bu & PADS_B)
     187                                event.type = Common::EVENT_RBUTTONUP;
     188
     189                        event.mouse.x = _mouseX;
     190                        event.mouse.y = _mouseY;
     191
     192                        return true;
     193                }
     194        }
     195
     196        s32 mx = _mouseX;
     197        s32 my = _mouseY;
     198
     199#ifndef GAMECUBE
     200        if (res == WPAD_ERR_NONE) {
     201                struct ir_t ir;
     202
     203                WPAD_IR(0, &ir);
     204
     205                if (ir.smooth_valid) {
     206                        mx = ir.sx - 64;
     207                        my = ir.sy - 64;
     208
     209                        if (mx < 0)
     210                                mx = 0;
     211
     212                        if (mx >= _currentWidth)
     213                                mx = _currentWidth - 1;
     214
     215                        if (my < 0)
     216                                my = 0;
     217
     218                        if (my >= _currentHeight)
     219                                my = _currentHeight - 1;
     220
     221                        if ( (mx != _mouseX) || (my != _mouseY)) {
     222                                event.type = Common::EVENT_MOUSEMOVE;
     223                                event.mouse.x = _mouseX = mx;
     224                                event.mouse.y = _mouseY = my;
     225
     226                                return true;
     227                        }
     228                }
     229        }
     230#endif
     231
     232        uint32 time = getMillis();
     233        if (time - _lastPadCheck > PAD_CHECK_TIME) {
     234                _lastPadCheck = time;
     235
     236                if (abs (PAD_StickX(0)) > 16)
     237                        mx += PAD_StickX(0) / (4 * _overlayWidth / _currentWidth);
     238                if (abs (PAD_StickY(0)) > 16)
     239                        my -= PAD_StickY(0) / (4 * _overlayHeight / _currentHeight);
     240
     241                if (mx < 0)
     242                        mx = 0;
     243
     244                if (mx >= _currentWidth)
     245                        mx = _currentWidth - 1;
     246
     247                if (my < 0)
     248                        my = 0;
     249
     250                if (my >= _currentHeight)
     251                        my = _currentHeight - 1;
     252
     253                if ((mx != _mouseX) || (my != _mouseY)) {
     254                        event.type = Common::EVENT_MOUSEMOVE;
     255                        event.mouse.x = _mouseX = mx;
     256                        event.mouse.y = _mouseY = my;
     257
     258                        return true;
     259                }
     260        }
     261
     262        return false;
     263}
     264
  • 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
     40class OSystem_Wii : public OSystem {
     41private:
     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
     84protected:
     85        Common::SaveFileManager *_savefile;
     86        Audio::Mixer *_mixer;
     87        DefaultTimerManager *_timer;
     88
     89public:
     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
     3Copyright (C) 2008
     4Hector Martin (marcan)
     5
     6This software is provided 'as-is', without any express or implied
     7warranty.  In no event will the authors be held liable for any
     8damages arising from the use of this software.
     9
     10Permission is granted to anyone to use this software for any
     11purpose, including commercial applications, and to alter it and
     12redistribute it freely, subject to the following restrictions:
     13
     141.      The origin of this software must not be misrepresented; you
     15must not claim that you wrote the original software. If you use
     16this software in a product, an acknowledgment in the product
     17documentation would be appreciated but is not required.
     18
     192.      Altered source versions must be plainly marked as such, and
     20must not be misrepresented as being the original software.
     21
     223.      This notice may not be removed or altered from any source
     23distribution.
     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
     36extern "C" {
     37#endif
     38
     39static const devoptab_t *dotab_console;
     40int usb_sendbuffer_safe(s32 chn,const void *buffer,int size);
     41int usb_sendbuffer(s32 chn,const void *buffer,int size);
     42
     43int __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
     57const 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
     80void 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
     27extern "C" {
     28#endif
     29
     30void GX_InitVideo();
     31
     32void GX_Start(u16 width, u16 height, s16 haspect, s16 vaspect);
     33void GX_Render(u16 width, u16 height, u8 *buffer, u16 pitch);
     34
     35#ifdef __cplusplus
     36}
     37#endif
     38
     39#endif
  • backends/platform/wii/Makefile

     
     1DEBUG_WII = 1
     2
     3ENABLE_SCUMM = 1
     4ENABLE_SCUMM_7_8 = 1
     5ENABLE_HE = 1
     6# ENABLE_AGI = 1
     7ENABLE_AGOS = 1
     8ENABLE_CINE = 1
     9ENABLE_CRUISE = 1
     10ENABLE_DRASCULA = 1
     11ENABLE_GOB = 1
     12ENABLE_IGOR = 1
     13ENABLE_KYRA = 1
     14ENABLE_LURE = 1
     15ENABLE_M4 = 1
     16ENABLE_MADE = 1
     17ENABLE_PARALLACTION = 1
     18ENABLE_QUEEN = 1
     19ENABLE_SAGA = 1
     20ENABLE_SKY = 1
     21ENABLE_SWORD1 = 1
     22ENABLE_SWORD2 = 1
     23ENABLE_TOUCHE = 1
     24
     25DISABLE_HQ_SCALERS = 1
     26DISABLE_SCALERS = 1
     27
     28USE_ZLIB = 1
     29USE_MAD = 1
     30USE_TREMOR = 1
     31USE_FLAC = 1
     32USE_MPEG2 = 1
     33USE_MT32EMU = 1
     34
     35srcdir = ../../..
     36VPATH = $(srcdir)
     37HAVE_GCC3 = 1
     38
     39DISTPATH = $(srcdir)/dists/wii
     40
     41ifeq ($(strip $(DEVKITPPC)),)
     42$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
     43endif
     44
     45PREFIX  = $(DEVKITPPC)/bin/powerpc-gekko-
     46CXX     = $(PREFIX)g++
     47AS      = $(PREFIX)gcc
     48LD      = $(PREFIX)gcc
     49AR      = $(PREFIX)ar cru
     50RANLIB  = $(PREFIX)ranlib
     51STRIP   = $(PREFIX)strip -g
     52OBJCOPY = $(PREFIX)objcopy
     53MKDIR   = mkdir -p
     54RM      = rm -f
     55CP      = cp -f
     56
     57TARGET  = scummvm-wii
     58
     59MACHDEP  = -DGEKKO -mrvl -mcpu=750 -meabi -mhard-float \
     60                        -ffunction-sections -fdata-sections -fmodulo-sched
     61
     62INCDIR   = $(srcdir) . $(srcdir)/engines/ $(DEVKITPRO)/libogc/include
     63LIBDIR   = $(DEVKITPRO)/libogc/lib/wii
     64
     65CXXFLAGS = -g -Os -Wall $(MACHDEP) -D__WII__ \
     66                        -Wno-multichar -fno-exceptions -fno-rtti
     67
     68CXXFLAGS += $(addprefix -I,$(INCDIR))
     69LDFLAGS   = -g $(MACHDEP) -Wl,-Map,$(TARGET).elf.map
     70LDFLAGS  += $(addprefix -L,$(LIBDIR))
     71LIBS      = -lstdc++ -lfat -lwiiuse -lbte -logc -lm
     72
     73CXXFLAGS += -I$(DEVKITPRO)/3rd/wii/include
     74LDFLAGS  += -L$(DEVKITPRO)/3rd/wii/lib
     75
     76ifdef DEBUG_WII
     77CXXFLAGS += -DDEBUG_WII
     78LIBS     += -ldb
     79endif
     80
     81ifdef USE_ZLIB
     82CXXFLAGS += -DUSE_ZLIB
     83LIBS     += -lz
     84endif
     85
     86ifdef USE_MAD
     87CXXFLAGS += -DUSE_MAD -I$(DEVKITPRO)/libogc/include/mad
     88LIBS     += -lmad
     89endif
     90
     91ifdef USE_TREMOR
     92CXXFLAGS += -DUSE_VORBIS -DUSE_TREMOR
     93LIBS     += -lvorbisidec
     94endif
     95
     96ifdef USE_FLAC
     97CXXFLAGS += -DUSE_FLAC
     98LIBS     += -lFLAC
     99endif
     100
     101ifdef USE_MPEG2
     102CXXFLAGS += -DUSE_MPEG2
     103LIBS     += -lmpeg2
     104endif
     105
     106ifdef USE_MT32EMU
     107CXXFLAGS += -DUSE_MT32EMU
     108endif
     109
     110OBJS := backends/platform/wii/main.o \
     111                backends/platform/wii/gecko_console.o \
     112                backends/platform/wii/gx_supp.o \
     113                backends/platform/wii/osystem.o \
     114                backends/platform/wii/osystem_gfx.o \
     115                backends/platform/wii/osystem_sfx.o \
     116                backends/platform/wii/osystem_events.o
     117
     118include $(srcdir)/Makefile.common
     119
     120.PHONY: clean-wii distclean-wii upload dist
     121
     122all: $(TARGET).dol
     123
     124$(TARGET).dol: $(TARGET).elf
     125        $(OBJCOPY) -O binary $< $@
     126
     127$(TARGET).elf: $(OBJS)
     128        $(LD) $^ $(LDFLAGS) $(LIBS) -o $@
     129
     130clean: clean-wii
     131
     132clean-wii:
     133        @-$(RM) $(TARGET).elf $(TARGET).elf.map $(TARGET).dol
     134
     135distclean: distclean-wii
     136
     137distclean-wii:
     138        @-$(RM) dist
     139
     140upload:
     141        $(DEVKITPPC)/bin/wiiload $(TARGET).dol
     142
     143dist:
     144        $(MKDIR) dist/scummvm
     145        $(MKDIR) dist/apps/scummvm
     146        $(CP) $(TARGET).dol dist/apps/scummvm/boot.dol
     147        $(CP) $(DISTPATH)/meta.xml dist/apps/scummvm/
     148        $(CP) $(DISTPATH)/icon.png dist/apps/scummvm/
     149        $(CP) $(DISTPATH)/READMII dist/apps/scummvm/
     150        $(CP) $(srcdir)/AUTHORS dist/apps/scummvm/
     151        $(CP) $(srcdir)/COPYING dist/apps/scummvm/
     152        $(CP) $(srcdir)/COPYRIGHT dist/apps/scummvm/
     153        $(CP) $(srcdir)/NEWS dist/apps/scummvm/
     154        $(CP) $(srcdir)/README dist/apps/scummvm/
     155        $(CP) $(DIST_FILES_THEMES) dist/scummvm
     156        $(CP) $(DIST_FILES_ENGINEDATA) dist/scummvm
     157
  • 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 */
     38class WiiFilesystemNode : public AbstractFilesystemNode {
     39protected:
     40        String _displayName;
     41        String _path;
     42        bool _isDirectory, _isReadable, _isWritable;
     43
     44public:
     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
     70private:
     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 */
     84const 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
     98void 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
     113WiiFilesystemNode::WiiFilesystemNode() {
     114        // The root dir.
     115        _path = "/";
     116        _displayName = _path;
     117
     118        setFlags();
     119}
     120
     121WiiFilesystemNode::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
     132bool WiiFilesystemNode::exists() const {
     133        struct stat st;
     134        return stat(_path.c_str (), &st) == 0;
     135}
     136
     137AbstractFilesystemNode *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
     148bool 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                return false;
     155
     156        char filename[MAXPATHLEN];
     157        struct stat st;
     158
     159        while (dirnext(dp, filename, &st) == 0) {
     160                if (strcmp(filename, ".") == 0 || strcmp(filename, "..") == 0)
     161                        continue;
     162
     163                String newPath(_path);
     164                if (newPath.lastChar() != '/')
     165                                newPath += '/';
     166                newPath += filename;
     167
     168                bool isDir = S_ISDIR(st.st_mode);
     169
     170                if ((mode == FilesystemNode::kListFilesOnly && isDir) ||
     171                        (mode == FilesystemNode::kListDirectoriesOnly && !isDir))
     172                        continue;
     173
     174                if (isDir)
     175                        newPath += '/';
     176
     177                WiiFilesystemNode *n = new WiiFilesystemNode(newPath, false);
     178                n->_isDirectory = isDir;
     179                n->_isReadable = (st.st_mode & S_IRUSR) > 0;
     180                n->_isWritable = (st.st_mode & S_IWUSR) > 0;
     181
     182                myList.push_back(n);
     183        }
     184
     185        dirclose(dp);
     186
     187        return true;
     188}
     189
     190AbstractFilesystemNode *WiiFilesystemNode::getParent() const {
     191        if (_path == "/")
     192                return 0;
     193
     194        const char *start = _path.c_str();
     195        const char *end = lastPathComponent(_path);
     196
     197        return new WiiFilesystemNode(String(start, end - start), true);
     198}
     199
     200#endif //#if defined(__WII__)
     201
  • 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
     27DECLARE_SINGLETON(WiiFilesystemFactory);
     28
     29AbstractFilesystemNode *WiiFilesystemFactory::makeRootFileNode() const {
     30        return new WiiFilesystemNode();
     31}
     32
     33AbstractFilesystemNode *WiiFilesystemFactory::makeCurrentDirectoryFileNode() const {
     34        return new WiiFilesystemNode("/scummvm", true);
     35}
     36
     37AbstractFilesystemNode *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 */
     34class WiiFilesystemFactory : public FilesystemFactory, public Common::Singleton<WiiFilesystemFactory> {
     35public:
     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
     42protected:
     43        WiiFilesystemFactory() {};
     44
     45private:
     46        friend class Common::Singleton<SingletonBaseType>;
     47};
     48
     49#endif /*Wii_FILESYSTEM_FACTORY_H*/
     50
  • backends/module.mk

     
    99        fs/psp/psp-fs-factory.o \
    1010        fs/symbian/symbian-fs-factory.o \
    1111        fs/windows/windows-fs-factory.o \
     12        fs/wii/wii-fs-factory.o \
    1213        events/default/default-events.o \
    1314        midi/alsa.o \
    1415        midi/camd.o \