Ticket #9123: svm-n64-patch-27122009-2.diff

File svm-n64-patch-27122009-2.diff, 66.8 KB (added by hkzlab, 14 years ago)

Patch to add Nintendo64 port to trunk - updated

  • common/scummsys.h

     
    301301        #define SCUMM_LITTLE_ENDIAN
    302302        #define SCUMM_NEED_ALIGNMENT
    303303
     304#elif defined(__N64__)
     305
     306        #define scumm_stricmp strcasecmp
     307        #define scumm_strnicmp strncasecmp
     308
     309        #define SCUMM_BIG_ENDIAN
     310        #define SCUMM_NEED_ALIGNMENT
     311
     312        #define STRINGBUFLEN 256
     313
     314        #define SCUMMVM_DONT_DEFINE_TYPES
     315        typedef unsigned char byte;
     316
     317        typedef unsigned char uint8;
     318        typedef signed char int8;
     319
     320        typedef unsigned short int uint16;
     321        typedef signed short int int16;
     322
     323        typedef unsigned int uint32;
     324        typedef signed int int32;
     325
     326        typedef unsigned long long uint64;
     327        typedef signed long long int64;
     328
    304329#elif defined(__PSP__)
    305330
    306331        #include <malloc.h>
  • common/util.cpp

     
    4646        #define fputs(str, file)        DS::std_fwrite(str, strlen(str), 1, file)
    4747#endif
    4848
     49#ifdef __N64__
     50        #define fputs(str, file)        asm("nop");
     51#endif
    4952
    5053namespace Common {
    5154
  • common/debug.cpp

     
    4545        #define fflush(file)            DS::std_fflush(file)
    4646#endif
    4747
     48#ifdef __N64__
     49        #include <n64utils.h>
    4850
     51        #define fputs(str, file)        asm("nop");
     52        #define fflush(a)                       asm("nop");
     53        #define OutputDebugString       addLineTextLayer
     54#endif
    4955
     56
    5057// TODO: Move gDebugLevel into namespace Common.
    5158int gDebugLevel = -1;
    5259
  • engines/scumm/saveload.cpp

     
    163163                memcpy(hdr.name, _saveLoadName, sizeof(hdr.name));
    164164                saveSaveGameHeader(out, hdr);
    165165        }
    166 #if !defined(__DS__) /* && !defined(__PLAYSTATION2__) */
     166#if !defined(__DS__) && !defined(__N64__) /* && !defined(__PLAYSTATION2__) */
    167167        Graphics::saveThumbnail(*out);
    168168#endif
    169169        saveInfos(out);
  • sound/softsynth/opl/mame.cpp

     
    3333
    3434#include "mame.h"
    3535
    36 #if defined (_WIN32_WCE) || defined (__SYMBIAN32__) || defined(PALMOS_MODE) || defined(__GP32__) || defined(GP2X) || defined (__MAEMO__) || defined(__DS__) || defined (__MINT__)
     36#if defined (_WIN32_WCE) || defined (__SYMBIAN32__) || defined(PALMOS_MODE) || defined(__GP32__) || defined(GP2X) || defined (__MAEMO__) || defined(__DS__) || defined (__MINT__) || defined(__N64__)
    3737#include "common/config-manager.h"
    3838#endif
    3939
     
    12121212        // We need to emulate one YM3812 chip
    12131213        int env_bits = FMOPL_ENV_BITS_HQ;
    12141214        int eg_ent = FMOPL_EG_ENT_HQ;
    1215 #if defined (_WIN32_WCE) || defined(__SYMBIAN32__) || defined(PALMOS_MODE) || defined(__GP32__) || defined (GP2X) || defined(__MAEMO__) || defined(__DS__) || defined (__MINT__)
     1215#if defined (_WIN32_WCE) || defined(__SYMBIAN32__) || defined(PALMOS_MODE) || defined(__GP32__) || defined (GP2X) || defined(__MAEMO__) || defined(__DS__) || defined (__MINT__) || defined(__N64__)
    12161216        if (ConfMan.hasKey("FM_high_quality") && ConfMan.getBool("FM_high_quality")) {
    12171217                env_bits = FMOPL_ENV_BITS_HQ;
    12181218                eg_ent = FMOPL_EG_ENT_HQ;
  • graphics/colormasks.h

     
    117117                kGreenBits  = 5,
    118118                kBlueBits   = 5,
    119119
     120#ifdef __N64__
    120121                kAlphaShift = 0,
     122                kRedShift   = kBlueBits+kGreenBits+1,
     123                kGreenShift = kBlueBits + 1,
     124                kBlueShift  = 1,
     125#else
     126                kAlphaShift = 0,
    121127                kRedShift   = kGreenBits+kBlueBits,
    122128                kGreenShift = kBlueBits,
    123129                kBlueShift  = 0,
     130#endif
    124131
    125132                kAlphaMask = ((1 << kAlphaBits) - 1) << kAlphaShift,
    126133                kRedMask   = ((1 << kRedBits) - 1) << kRedShift,
  • backends/platform/n64/osys_n64_base.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#include <romfs.h>
     24
     25#include "osys_n64.h"
     26#include "pakfs_save_manager.h"
     27#include "backends/fs/n64/n64-fs-factory.h"
     28
     29#define DEFAULT_FRAMEBUFFER_WIDTH 340 // a horizontal resolution of 340 takes into account overscan
     30#define DEFAULT_PIX_SKIP 15
     31
     32extern uint8 _romfs; // Defined by linker (used to calculate position of romfs image)
     33
     34inline uint16 colBGR888toRGB555(byte r, byte g, byte b);
     35
     36static const OSystem::GraphicsMode s_supportedGraphicsModes[] = {
     37        { "320x240 (PAL) fix overscan", "340x240 PAL",  OVERS_PAL_340X240   },
     38        { "320x240 (PAL) overscan", "320x240 PAL",  NORM_PAL_320X240   },
     39        { "320x240 (MPAL) fix overscan", "340x240 MPAL", OVERS_MPAL_340X240  },
     40        { "320x240 (MPAL) overscan", "320x240 MPAL", NORM_MPAL_320X240  },
     41        { "340x240 (NTSC) fix overscan", "340x240 NTSC", OVERS_NTSC_340X240 },
     42        { "320x240 (NTSC) overscan", "320x240 NTSC", NORM_NTSC_320X240  },
     43        { 0, 0, 0 }
     44};
     45
     46OSystem_N64::OSystem_N64() {
     47        // Enable Mips interrupts
     48        set_MI_interrupt(1);
     49
     50        // Initialize display: NTSC 340x240 (16 bit)
     51        initDisplay(NTSC_340X240_16BIT);
     52
     53        // Prepare virtual text layer for debugging purposes
     54        initTextLayer();
     55
     56        // Init PI interface
     57        PI_Init();
     58
     59        // Init Controller Pak
     60        initPakFs();
     61
     62        // Use the first save pak found
     63        uint8 ctrl_num;
     64        for (ctrl_num = 0; ctrl_num < 4; ctrl_num++) {
     65                int8 pak_type = identifyPak(ctrl_num);
     66                if (pak_type == 1) {
     67                        loadPakData(ctrl_num);
     68                        break;
     69                }
     70        }
     71
     72        // Screen size
     73        _screenWidth = DEFAULT_SCREEN_WIDTH;
     74        _screenHeight = DEFAULT_SCREEN_HEIGHT;
     75
     76        // Game screen size
     77        _gameHeight = DEFAULT_SCREEN_WIDTH;
     78        _gameWidth = DEFAULT_SCREEN_HEIGHT;
     79
     80        // Overlay size
     81        _overlayWidth = DEFAULT_SCREEN_WIDTH;
     82        _overlayHeight = DEFAULT_SCREEN_HEIGHT;
     83
     84        // Framebuffer width
     85        _frameBufferWidth = DEFAULT_FRAMEBUFFER_WIDTH;
     86
     87        // Pixels to skip
     88        _offscrPixels = DEFAULT_PIX_SKIP;
     89
     90        // Video clock
     91        _viClockRate = VI_NTSC_CLOCK;
     92
     93        _maxFps = N64_NTSC_FPS;
     94
     95        _overlayVisible = false;
     96
     97        _shakeOffset = 0;
     98
     99        // Allocate memory for offscreen buffers
     100        _offscreen_hic = (uint16*)memalign(8, DEFAULT_SCREEN_WIDTH * DEFAULT_SCREEN_HEIGHT * 2);
     101        _offscreen_pal = (uint8*)memalign(8, DEFAULT_SCREEN_WIDTH * DEFAULT_SCREEN_HEIGHT);
     102        _overlayBuffer = (uint16*)memalign(8, DEFAULT_SCREEN_WIDTH * DEFAULT_SCREEN_HEIGHT * sizeof(OverlayColor));
     103
     104        _cursor_pal = NULL;
     105
     106        _cursorWidth = -1;
     107        _cursorHeight = -1;
     108        _cursorKeycolor = -1;
     109        _mouseHotspotX = _mouseHotspotY = -1;
     110
     111        // Clean offscreen buffers
     112        memset(_offscreen_hic, 0, _screenWidth * _screenHeight * 2);
     113        memset(_offscreen_pal, 0, _screenWidth * _screenHeight);
     114        memset(_overlayBuffer, 0, _overlayWidth * _overlayHeight * sizeof(OverlayColor));
     115
     116        // Default graphic mode
     117        _graphicMode = OVERS_NTSC_340X240;
     118
     119        // Clear palette array
     120        _screenPalette = (uint16*)memalign(8, 256 * sizeof(uint16));
     121        memset(_screenPalette, 0, 256 * sizeof(uint16));
     122        memset(_cursorPalette, 0, 256 * sizeof(uint16));
     123
     124        _dirtyPalette = false;
     125        _cursorPaletteDisabled = false;
     126
     127        _audioEnabled = false;
     128
     129        // Initialize ROMFS access interface
     130        initRomFSmanager((uint8*)(((uint32)&_romfs + (uint32)0xc00) | (uint32)0xB0000000));
     131
     132        // Register vblank callback
     133        registerVIhandler(vblCallback);
     134
     135        _mouseVisible = false;
     136
     137        _mouseX = _overlayWidth  / 2;
     138        _mouseY = _overlayHeight / 2;
     139        _mouseMaxX = _overlayWidth;
     140        _mouseMaxY = _overlayHeight;
     141
     142        _savefile = 0;
     143        _mixer = 0;
     144        _timer = 0;
     145
     146        _dirtyOffscreen = false;
     147
     148        _ctrlData = (controller_data_buttons*)memalign(8, sizeof(controller_data_buttons));
     149
     150        _fsFactory = new N64FilesystemFactory();
     151
     152}
     153
     154OSystem_N64::~OSystem_N64() {
     155        delete _savefile;
     156        delete _mixer;
     157        delete _timer;
     158        delete _fsFactory;
     159}
     160
     161void OSystem_N64::initBackend() {
     162        ConfMan.setInt("autosave_period", 0);
     163        ConfMan.setBool("FM_high_quality", false);
     164        ConfMan.setBool("FM_medium_quality", true);
     165        ConfMan.set("gui_theme", "modern"); // In case of modern theme being present, use it.
     166
     167        _savefile = new PAKSaveManager();
     168
     169        _mixer = new Audio::MixerImpl(this);
     170        _mixer->setReady(false);
     171
     172        _timer = new DefaultTimerManager();
     173
     174        setTimerCallback(&timer_handler, 10);
     175
     176        setupMixer();
     177
     178        OSystem::initBackend();
     179
     180}
     181
     182bool OSystem_N64::hasFeature(Feature f) {
     183        return (f == kFeatureCursorHasPalette);
     184}
     185
     186void OSystem_N64::setFeatureState(Feature f, bool enable) {
     187        return;
     188}
     189
     190bool OSystem_N64::getFeatureState(Feature f) {
     191        return false;
     192}
     193
     194const OSystem::GraphicsMode* OSystem_N64::getSupportedGraphicsModes() const {
     195        return s_supportedGraphicsModes;
     196}
     197
     198
     199int OSystem_N64::getDefaultGraphicsMode() const {
     200        return OVERS_NTSC_340X240;
     201}
     202
     203bool OSystem_N64::setGraphicsMode(const char *mode) {
     204        int i = 0;
     205
     206        while (s_supportedGraphicsModes[i].name) {
     207                if (!strcmpi(s_supportedGraphicsModes[i].name, mode)) {
     208                        _graphicMode = s_supportedGraphicsModes[i].id;
     209
     210                        switchGraphicModeId(_graphicMode);
     211
     212                        return true;
     213                }
     214                i++;
     215        }
     216
     217        return true;
     218}
     219
     220bool OSystem_N64::setGraphicsMode(int mode) {
     221        _graphicMode = mode;
     222        switchGraphicModeId(_graphicMode);
     223
     224        return true;
     225}
     226
     227void OSystem_N64::switchGraphicModeId(int mode) {
     228        switch (mode) {
     229        case NORM_PAL_320X240:
     230                disableAudioPlayback();
     231                _viClockRate = VI_PAL_CLOCK;
     232                _maxFps = N64_PAL_FPS;
     233                initDisplay(PAL_320X240_16BIT);
     234                _frameBufferWidth = 320;
     235                _screenWidth = DEFAULT_SCREEN_WIDTH;
     236                _screenHeight = DEFAULT_SCREEN_HEIGHT;
     237                _offscrPixels = 0;
     238                _graphicMode = NORM_PAL_320X240;
     239                enableAudioPlayback();
     240                break;
     241
     242        case OVERS_PAL_340X240:
     243                disableAudioPlayback();
     244                _viClockRate = VI_PAL_CLOCK;
     245                _maxFps = N64_PAL_FPS;
     246                initDisplay(PAL_340X240_16BIT);
     247                _frameBufferWidth = DEFAULT_FRAMEBUFFER_WIDTH;
     248                _screenWidth = DEFAULT_SCREEN_WIDTH;
     249                _screenHeight = DEFAULT_SCREEN_HEIGHT;
     250                _offscrPixels = DEFAULT_PIX_SKIP;
     251                _graphicMode = OVERS_PAL_340X240;
     252                enableAudioPlayback();
     253                break;
     254
     255        case NORM_MPAL_320X240:
     256                disableAudioPlayback();
     257                _viClockRate = VI_MPAL_CLOCK;
     258                _maxFps = N64_NTSC_FPS;
     259                initDisplay(MPAL_320X240_16BIT);
     260                _frameBufferWidth = 320;
     261                _screenWidth = DEFAULT_SCREEN_WIDTH;
     262                _screenHeight = DEFAULT_SCREEN_HEIGHT;
     263                _offscrPixels = 0;
     264                _graphicMode = NORM_MPAL_320X240;
     265                enableAudioPlayback();
     266                break;
     267
     268        case OVERS_MPAL_340X240:
     269                disableAudioPlayback();
     270                _viClockRate = VI_MPAL_CLOCK;
     271                _maxFps = N64_NTSC_FPS;
     272                initDisplay(MPAL_340X240_16BIT);
     273                _frameBufferWidth = DEFAULT_FRAMEBUFFER_WIDTH;
     274                _screenWidth = DEFAULT_SCREEN_WIDTH;
     275                _screenHeight = DEFAULT_SCREEN_HEIGHT;
     276                _offscrPixels = DEFAULT_PIX_SKIP;
     277                _graphicMode = OVERS_MPAL_340X240;
     278                enableAudioPlayback();
     279                break;
     280
     281        case NORM_NTSC_320X240:
     282                disableAudioPlayback();
     283                _viClockRate = VI_NTSC_CLOCK;
     284                _maxFps = N64_NTSC_FPS;
     285                initDisplay(NTSC_320X240_16BIT);
     286                _frameBufferWidth = 320;
     287                _screenWidth = DEFAULT_SCREEN_WIDTH;
     288                _screenHeight = DEFAULT_SCREEN_HEIGHT;
     289                _offscrPixels = 0;
     290                _graphicMode = NORM_NTSC_320X240;
     291                enableAudioPlayback();
     292                break;
     293
     294        case OVERS_NTSC_340X240:
     295        default:
     296                disableAudioPlayback();
     297                _viClockRate = VI_NTSC_CLOCK;
     298                _maxFps = N64_NTSC_FPS;
     299                initDisplay(NTSC_340X240_16BIT);
     300                _frameBufferWidth = DEFAULT_FRAMEBUFFER_WIDTH;
     301                _screenWidth = DEFAULT_SCREEN_WIDTH;
     302                _screenHeight = DEFAULT_SCREEN_HEIGHT;
     303                _offscrPixels = DEFAULT_PIX_SKIP;
     304                _graphicMode = OVERS_NTSC_340X240;
     305                enableAudioPlayback();
     306                break;
     307        }
     308}
     309
     310int OSystem_N64::getGraphicsMode() const {
     311        return _graphicMode;
     312}
     313
     314void OSystem_N64::initSize(uint width, uint height, const Graphics::PixelFormat *format) {
     315        _gameWidth = width;
     316        _gameHeight = height;
     317
     318        if (_gameWidth > _screenWidth)
     319                _gameWidth = _screenWidth;
     320        if (_gameHeight > _screenHeight)
     321                _gameHeight = _screenHeight;
     322
     323        _mouseMaxX = _gameWidth;
     324        _mouseMaxY = _gameHeight;
     325}
     326
     327int16 OSystem_N64::getHeight() {
     328        return _screenHeight;
     329}
     330
     331int16 OSystem_N64::getWidth() {
     332        return _screenWidth;
     333}
     334
     335void OSystem_N64::setPalette(const byte *colors, uint start, uint num) {
     336        for (int i = 0; i < num; ++i) {
     337                uint8 c[4];
     338                _screenPalette[start + i] = colBGR888toRGB555(colors[2], colors[1], colors[0]);
     339                colors += 4;
     340        }
     341
     342        _dirtyPalette = true;
     343        _dirtyOffscreen = true;
     344}
     345
     346void OSystem_N64::rebuildOffscreenGameBuffer(void) {
     347        // Regenerate hi-color offscreen buffer
     348#if 0
     349        for (int h = 0; h < _gameHeight; h++)
     350                for (int w = 0; w < _gameWidth; w++) {
     351                        uint8 color = _offscreen_pal[(h * _screenWidth) + w];
     352                        _offscreen_hic[(h * _screenWidth) + w] = _screenPalette[color];
     353                }
     354#else
     355        uint32 two_col_hi;
     356        uint32 four_col_pal;
     357        for (int h = 0; h < _gameHeight; h++)
     358                for (int w = 0; w < _gameWidth; w += 4) {
     359                        four_col_pal = *(uint32*)(_offscreen_pal + ((h * _screenWidth) + w));
     360
     361                        two_col_hi = 0;
     362                        two_col_hi = _screenPalette[((four_col_pal >> (8 * 3)) & 0xFF)] | (two_col_hi << (16 * 0));
     363                        two_col_hi = _screenPalette[((four_col_pal >> (8 * 2)) & 0xFF)] | (two_col_hi << (16 * 1));
     364
     365                        *(uint32*)(_offscreen_hic + (h * _screenWidth) + w + 0) = two_col_hi;
     366
     367                        two_col_hi = 0;
     368                        two_col_hi = _screenPalette[((four_col_pal >> (8 * 1)) & 0xFF)] | (two_col_hi << (16 * 0));
     369                        two_col_hi = _screenPalette[((four_col_pal >> (8 * 0)) & 0xFF)] | (two_col_hi << (16 * 1));
     370
     371                        *(uint32*)(_offscreen_hic + (h * _screenWidth) + w + 2) = two_col_hi;
     372                }
     373#endif
     374}
     375
     376void OSystem_N64::grabPalette(byte *colors, uint start, uint num) {
     377        uint32 i;
     378        uint16 color;
     379
     380        for (i = start; i < start + num; i++) {
     381                color = _screenPalette[i];
     382
     383                // Color format on the n64 is RGB - 1555
     384                *colors++ = ((color & 0x1F) << 3);
     385                *colors++ = (((color >> 5) & 0x1F) << 3);
     386                *colors++ = (((color >> 10) & 0x1F) << 3);
     387                *colors++ = 0;
     388        }
     389
     390        return;
     391}
     392
     393void OSystem_N64::setCursorPalette(const byte *colors, uint start, uint num) {
     394        for (int i = 0; i < num; ++i) {
     395                _cursorPalette[start + i] = colBGR888toRGB555(colors[2], colors[1], colors[0]);
     396                colors += 4;
     397        }
     398
     399        _cursorPaletteDisabled = false;
     400        _dirtyOffscreen = true;
     401}
     402
     403void OSystem_N64::disableCursorPalette(bool disable) {
     404        _cursorPaletteDisabled = disable;
     405
     406        _dirtyOffscreen = true;
     407}
     408
     409void OSystem_N64::copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h) {
     410        //Clip the coordinates
     411        if (x < 0) {
     412                w += x;
     413                buf -= x;
     414                x = 0;
     415        }
     416
     417        if (y < 0) {
     418                h += y;
     419                buf -= y * pitch;
     420                y = 0;
     421        }
     422
     423        if (w > _screenWidth - x) {
     424                w = _screenWidth - x;
     425        }
     426
     427        if (h > _screenHeight - y) {
     428                h = _screenHeight - y;
     429        }
     430
     431        if (w <= 0 || h <= 0)
     432                return;
     433
     434        uint8 *dst_pal = _offscreen_pal + ((y * _screenWidth) + x);
     435        uint16 *dst_hicol = _offscreen_hic + ((y * _screenWidth) + x);
     436
     437        do {
     438                for (int hor = 0; hor < w; hor++) {
     439                        if (dst_pal[hor] != buf[hor]) {
     440                                uint16 color = _screenPalette[buf[hor]];
     441                                dst_hicol[hor] = color;  // Save image converted to 16-bit
     442                                dst_pal[hor] = buf[hor]; // Save palettized display
     443                        }
     444                }
     445
     446                buf += pitch;
     447                dst_pal += _screenWidth;
     448                dst_hicol += _screenWidth;
     449        } while (--h);
     450
     451        _dirtyOffscreen = true;
     452
     453        return;
     454}
     455
     456void OSystem_N64::updateScreen() {
     457        // Check if audio buffer needs refill
     458        // Done here because this gets called regularly
     459        refillAudioBuffers();
     460
     461#ifdef LIMIT_FPS
     462        static uint32 _lastScreenUpdate = 0;
     463        uint32 now = getMillis();
     464        if (now - _lastScreenUpdate < 1000 / _maxFps)
     465                return;
     466
     467        _lastScreenUpdate = now;
     468#endif
     469
     470        if (!_dirtyOffscreen && !_dirtyPalette) return; // The offscreen is clean
     471
     472        uint8 skip_lines = (_screenHeight - _gameHeight) / 4;
     473        uint8 skip_pixels = (_screenWidth - _gameWidth) / 2; // Center horizontally the image
     474
     475        if (_dirtyPalette) {
     476                rebuildOffscreenGameBuffer();
     477                _dirtyPalette = false;
     478        }
     479
     480        while (!(_dc = lockDisplay()));
     481
     482        uint16 *overlay_framebuffer = (uint16*)_dc->conf.framebuffer; // Current screen framebuffer
     483        uint16 *game_framebuffer = overlay_framebuffer + (_frameBufferWidth * skip_lines * 2); // Skip some lines to center the image vertically
     484
     485        uint16 currentHeight;
     486        uint16 *tmpDst;
     487        uint16 *tmpSrc;
     488
     489        // Copy the game buffer to screen
     490        if (!_overlayVisible) {
     491                tmpDst = game_framebuffer;
     492                tmpSrc = _offscreen_hic + (_shakeOffset * _screenWidth);
     493                for (currentHeight = _shakeOffset; currentHeight < _gameHeight; currentHeight++) {
     494                        memcpy((tmpDst + skip_pixels + _offscrPixels), tmpSrc, _screenWidth * 2);
     495                        tmpDst += _frameBufferWidth;
     496                        tmpSrc += _screenWidth;
     497                }
     498
     499                Uint16 _clearLines = _shakeOffset; // When shaking we must take care of remaining lines to clear
     500                while (_clearLines--) {
     501                        memset(tmpDst + skip_pixels + _offscrPixels, 0, _screenWidth * 2);
     502                        tmpDst += _frameBufferWidth;
     503                }
     504        }
     505
     506        // If the overlay is enabled, draw it on top of game screen
     507        if (_overlayVisible) {
     508                tmpDst = overlay_framebuffer;
     509                tmpSrc = _overlayBuffer;
     510                for (currentHeight = 0; currentHeight < _overlayHeight; currentHeight++) {
     511                        memcpy((tmpDst + _offscrPixels), tmpSrc, _overlayWidth * 2);
     512                        tmpDst += _frameBufferWidth;
     513                        tmpSrc += _overlayWidth;
     514                }
     515        }
     516
     517        // Draw mouse cursor
     518        if ((_mouseVisible || _overlayVisible) && _cursorHeight > 0 && _cursorWidth > 0) {
     519                uint16 *mouse_framebuffer;
     520                uint16 horiz_pix_skip = 0;
     521
     522                if (_overlayVisible) {
     523                        mouse_framebuffer = overlay_framebuffer;
     524                } else {
     525                        mouse_framebuffer = game_framebuffer;
     526                        horiz_pix_skip = skip_pixels;
     527                }
     528
     529                int mX = _mouseX - _mouseHotspotX;
     530                int mY = _mouseY - _mouseHotspotY;
     531
     532                for (int h = 0; h < _cursorHeight; h++)
     533                        for (int w = 0; w < _cursorWidth; w++) {
     534                                uint16 color;
     535                                uint8 index = _cursor_pal[(h * _cursorWidth) + w];
     536
     537                                // Read palette color
     538                                if (!_cursorPaletteDisabled)
     539                                        color = _cursorPalette[index];
     540                                else
     541                                        color = _screenPalette[index];
     542
     543                                if ((index != _cursorKeycolor) && ((mY + h) >= 0) && ((mY + h) < _mouseMaxY) && ((mX + w) >= 0) && ((mX + w) < _mouseMaxX))
     544                                        mouse_framebuffer[((mY + h) * _frameBufferWidth) + ((mX + w) + _offscrPixels + horiz_pix_skip)] = color;
     545                        }
     546        }
     547
     548#ifndef _ENABLE_DEBUG_
     549        showDisplay(_dc);
     550#else
     551        showDisplayAndText(_dc);
     552#endif
     553
     554        _dc = NULL;
     555        _dirtyOffscreen = false;
     556
     557        return;
     558}
     559
     560Graphics::Surface *OSystem_N64::lockScreen() {
     561        _framebuffer.pixels = _offscreen_pal;
     562        _framebuffer.w = _gameWidth;
     563        _framebuffer.h = _gameHeight;
     564        _framebuffer.pitch = _screenWidth;
     565        _framebuffer.bytesPerPixel = 1;
     566
     567        return &_framebuffer;
     568}
     569
     570void OSystem_N64::unlockScreen() {
     571        _dirtyPalette = true;
     572        _dirtyOffscreen = true;
     573}
     574
     575void OSystem_N64::setShakePos(int shakeOffset) {
     576        _shakeOffset = shakeOffset;
     577        _dirtyOffscreen = true;
     578
     579        return;
     580}
     581
     582void OSystem_N64::showOverlay() {
     583        // Change min/max mouse coords
     584        _mouseMaxX = _overlayWidth;
     585        _mouseMaxY = _overlayHeight;
     586
     587        // Relocate the mouse cursor given the new limitations
     588        warpMouse(_mouseX, _mouseY);
     589
     590        _overlayVisible = true;
     591        _dirtyOffscreen = true;
     592}
     593
     594void OSystem_N64::hideOverlay() {
     595        // Change min/max mouse coords
     596        _mouseMaxX = _gameWidth;
     597        _mouseMaxY = _gameHeight;
     598
     599        // Relocate the mouse cursor given the new limitations
     600        warpMouse(_mouseX, _mouseY);
     601
     602        _overlayVisible = false;
     603
     604        // Clear double buffered display
     605        clearAllVideoBuffers();
     606
     607        _dirtyOffscreen = true;
     608}
     609
     610void OSystem_N64::clearOverlay() {
     611        memset(_overlayBuffer, 0, _overlayWidth * _overlayHeight * sizeof(OverlayColor));
     612
     613        uint8 skip_lines = (_screenHeight - _gameHeight) / 4;
     614        uint8 skip_pixels = (_screenWidth - _gameWidth) / 2; // Center horizontally the image
     615
     616        uint16 *tmpDst = _overlayBuffer + (_overlayWidth * skip_lines * 2);
     617        uint16 *tmpSrc = _offscreen_hic + (_shakeOffset * _screenWidth);
     618        for (uint16 currentHeight = _shakeOffset; currentHeight < _gameHeight; currentHeight++) {
     619                memcpy((tmpDst + skip_pixels), tmpSrc, _gameWidth * 2);
     620                tmpDst += _overlayWidth;
     621                tmpSrc += _screenWidth;
     622        }
     623
     624        _dirtyOffscreen = true;
     625}
     626
     627void OSystem_N64::grabOverlay(OverlayColor *buf, int pitch) {
     628        int h = _overlayHeight;
     629        OverlayColor *src = _overlayBuffer;
     630
     631        do {
     632                memcpy(buf, src, _overlayWidth * sizeof(OverlayColor));
     633                src += _overlayWidth;
     634                buf += pitch;
     635        } while (--h);
     636}
     637
     638void OSystem_N64::copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h) {
     639        //Clip the coordinates
     640        if (x < 0) {
     641                w += x;
     642                buf -= x;
     643                x = 0;
     644        }
     645
     646        if (y < 0) {
     647                h += y;
     648                buf -= y * pitch;
     649                y = 0;
     650        }
     651
     652        if (w > _overlayWidth - x) {
     653                w = _overlayWidth - x;
     654        }
     655
     656        if (h > _overlayHeight - y) {
     657                h = _overlayHeight - y;
     658        }
     659
     660        if (w <= 0 || h <= 0)
     661                return;
     662
     663
     664        OverlayColor *dst = _overlayBuffer + (y * _overlayWidth + x);
     665
     666        if (_overlayWidth == pitch && pitch == w) {
     667                memcpy(dst, buf, h * w * sizeof(OverlayColor));
     668        } else {
     669                do {
     670                        memcpy(dst, buf, w * sizeof(OverlayColor));
     671                        buf += pitch;
     672                        dst += _overlayWidth;
     673                } while (--h);
     674        }
     675
     676        _dirtyOffscreen = true;
     677
     678        return;
     679}
     680
     681int16 OSystem_N64::getOverlayHeight() {
     682        return _overlayHeight;
     683}
     684
     685int16 OSystem_N64::getOverlayWidth() {
     686        return _overlayWidth;
     687}
     688
     689
     690bool OSystem_N64::showMouse(bool visible) {
     691        bool last = _mouseVisible;
     692        _mouseVisible = visible;
     693
     694        _dirtyOffscreen = true;
     695
     696        return last;
     697}
     698
     699void OSystem_N64::warpMouse(int x, int y) {
     700
     701        if (x < 0)
     702                _mouseX = 0;
     703        else if (x >= _mouseMaxX)
     704                _mouseX = _mouseMaxX - 1;
     705        else
     706                _mouseX = x;
     707
     708        if (y < 0)
     709                _mouseY = 0;
     710        else if (y >= _mouseMaxY)
     711                _mouseY = _mouseMaxY - 1;
     712        else
     713                _mouseY = y;
     714
     715        _dirtyOffscreen = true;
     716}
     717
     718void OSystem_N64::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format) {
     719        if (!w || !h) return;
     720
     721        _mouseHotspotX = hotspotX;
     722        _mouseHotspotY = hotspotY;
     723
     724        if (_cursor_pal && ((w != _cursorWidth) || (h != _cursorHeight))) {
     725                free(_cursor_pal);
     726                _cursor_pal = NULL;
     727        }
     728
     729        if (!_cursor_pal) {
     730                _cursor_pal = (uint8*)malloc(w * h);
     731        }
     732
     733        _cursorWidth = w;
     734        _cursorHeight = h;
     735
     736        memcpy(_cursor_pal, buf, w * h); // Copy the palettized cursor
     737
     738        _cursorKeycolor = keycolor & 0xFF;
     739
     740        _dirtyOffscreen = true;
     741
     742        return;
     743}
     744
     745uint32 OSystem_N64::getMillis() {
     746        return getMilliTick();
     747}
     748
     749void OSystem_N64::delayMillis(uint msecs) {
     750        delay(msecs);
     751}
     752
     753OSystem::MutexRef OSystem_N64::createMutex(void) {
     754        return NULL;
     755}
     756
     757void OSystem_N64::lockMutex(MutexRef mutex) {
     758        return;
     759}
     760
     761void OSystem_N64::unlockMutex(MutexRef mutex) {
     762        return;
     763}
     764
     765void OSystem_N64::deleteMutex(MutexRef mutex) {
     766        return;
     767}
     768
     769void OSystem_N64::quit() {
     770        // Not much to do...
     771        return;
     772}
     773
     774Common::SaveFileManager *OSystem_N64::getSavefileManager() {
     775        assert(_savefile);
     776        return _savefile;
     777}
     778
     779Audio::Mixer *OSystem_N64::getMixer() {
     780        assert(_mixer);
     781        return _mixer;
     782}
     783
     784Common::TimerManager *OSystem_N64::getTimerManager() {
     785        assert(_timer);
     786        return _timer;
     787}
     788
     789void OSystem_N64::getTimeAndDate(TimeDate &t) const {
     790        // No clock inside the N64
     791        // TODO: use getMillis to provide some kind of time-counting feature?
     792        t.tm_sec  = 0;
     793        t.tm_min  = 0;
     794        t.tm_hour = 0;
     795        t.tm_mday = 0;
     796        t.tm_mon  = 0;
     797        t.tm_year = 0;
     798
     799        return;
     800}
     801
     802FilesystemFactory *OSystem_N64::getFilesystemFactory() {
     803        return _fsFactory;
     804}
     805
     806void OSystem_N64::setTimerCallback(TimerProc callback, int interval) {
     807        if (callback != NULL) {
     808                _timerCallbackTimer = interval;
     809                _timerCallbackNext = getMillis() + interval;
     810                _timerCallback = callback;
     811        } else
     812                _timerCallback = NULL;
     813}
     814
     815void OSystem_N64::setupMixer(void) {
     816        enableAudioPlayback();
     817}
     818
     819inline uint16 colBGR888toRGB555(byte r, byte g, byte b) {
     820        return ((r >> 3) << 1) | ((g >> 3) << 6) | ((b >> 3) << 11);
     821}
     822
  • backends/platform/n64/osys_n64_utilities.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
     24#include "osys_n64.h"
     25
     26void checkTimers(void) {
     27        OSystem_N64 *osys = (OSystem_N64*)g_system;
     28
     29        uint32 curTime = osys->getMillis();
     30
     31        // Timer checking & firing
     32        if (osys->_timerCallback && (curTime >= osys->_timerCallbackNext)) {
     33                osys->_timerCallback(osys->_timerCallbackTimer);
     34                osys->_timerCallbackNext = curTime + osys->_timerCallbackTimer;
     35        }
     36}
     37
     38void disableAudioPlayback(void) {
     39        if (!_audioEnabled) return;
     40
     41        _audioEnabled = false;
     42
     43        OSystem_N64 *osys = (OSystem_N64*)g_system;
     44        Audio::MixerImpl *_localmixer = (Audio::MixerImpl*)osys->getMixer();
     45
     46        while (AI_busy()); // Wait for audio to stop
     47}
     48
     49void enableAudioPlayback(void) {
     50        static bool _firstRun = true;
     51
     52        OSystem_N64 *osys = (OSystem_N64*)g_system;
     53        Audio::MixerImpl *_localmixer = (Audio::MixerImpl*)osys->getMixer();
     54
     55#if 0
     56        uint32 samples = 8192;
     57        while ((16 * samples) >= DEFAULT_SOUND_SAMPLE_RATE) {
     58                samples >>= 1;
     59        }
     60        samples <<= 3;
     61#else
     62        uint32 samples = 4096; // 4096 bytes -> 2048 samples.
     63#endif
     64
     65        initAudioInterface(osys->_viClockRate, DEFAULT_SOUND_SAMPLE_RATE, 16, samples);
     66        osys->_audioBufferSize = getAIBufferSize();
     67
     68        if (_firstRun) {
     69                _localmixer->setOutputRate(DEFAULT_SOUND_SAMPLE_RATE);
     70                _localmixer->setReady(true);
     71                _firstRun = false;
     72        }
     73
     74        disable_interrupts();
     75
     76        _audioEnabled = true;
     77
     78        sndCallback();
     79        sndCallback();
     80
     81        registerAIhandler(sndCallback); // Lib checks if i try to register it multiple times
     82
     83        enable_interrupts();
     84}
     85
     86static volatile Uint32 _requiredSoundSlots = 0;
     87
     88void vblCallback(void) {
     89        // Switch display buffer
     90        switchDisplayBuffer();
     91
     92#if 1
     93        // If audio buffer got depleted, refill it.
     94        if (_audioEnabled && !AI_busy() && !_requiredSoundSlots) {
     95                sndCallback();
     96                sndCallback();
     97        }
     98#endif
     99
     100}
     101
     102void sndCallback() {
     103        // Signal that an audio buffer finished playing and that we need more samples
     104        if (_requiredSoundSlots < 2)
     105                _requiredSoundSlots++;
     106}
     107
     108void refillAudioBuffers(void) {
     109        if (!_audioEnabled) return;
     110
     111        OSystem_N64 *osys = (OSystem_N64*)g_system;
     112        byte *sndBuf;
     113        Audio::MixerImpl *_localmixer = (Audio::MixerImpl*)osys->getMixer();
     114
     115        while (_requiredSoundSlots) {
     116                sndBuf = (byte*)getAIBuffer();
     117
     118                _localmixer->mixCallback((byte*)sndBuf, osys->_audioBufferSize);
     119
     120                putAIBuffer();
     121
     122                _requiredSoundSlots--;
     123        }
     124}
     125
     126int timer_handler(int t) {
     127        DefaultTimerManager *tm = (DefaultTimerManager *)g_system->getTimerManager();
     128        tm->handler();
     129        return t;
     130}
     131
  • backends/platform/n64/pakfs_save_manager.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 __PAKFS_SAVE_MANAGER__
     24#define __PAKFS_SAVE_MANAGER__
     25
     26#include <common/savefile.h>
     27#include <common/zlib.h>
     28
     29#include <pakfs.h> // N64 PakFS library
     30
     31bool deleteSaveGame(const char *filename);
     32
     33class InPAKSave : public Common::InSaveFile {
     34private:
     35        PAKFILE *fd;
     36
     37        uint32 read(void *buf, uint32 cnt);
     38        bool skip(uint32 offset);
     39        bool seek(int32 offs, int whence);
     40
     41public:
     42        InPAKSave() : fd(0) { }
     43
     44        ~InPAKSave() {
     45                if (fd != NULL)
     46                        pakfs_close(fd);
     47        }
     48
     49        bool eos() const {
     50                return pakfs_eof(fd);
     51        }
     52        void clearErr() {
     53                pakfs_clearerr(fd);
     54        }
     55        int32 pos() const {
     56                return pakfs_tell(fd);
     57        }
     58        int32 size() const {
     59                return fd->size;
     60        }
     61
     62        bool readSaveGame(const char *filename) {
     63                fd = pakfs_open(filename, "r");
     64                return (fd != NULL);
     65        }
     66};
     67
     68class OutPAKSave : public Common::OutSaveFile {
     69private:
     70        PAKFILE *fd;
     71
     72public:
     73        uint32 write(const void *buf, uint32 cnt);
     74
     75        OutPAKSave(const char *_filename) {
     76                fd = pakfs_open(_filename, "w");
     77        }
     78
     79        ~OutPAKSave() {
     80                if (fd != NULL) {
     81                        finalize();
     82                        pakfs_close(fd);
     83                        flushCurrentPakData();
     84                }
     85        }
     86
     87        bool err() const {
     88                return pakfs_error(fd);
     89        }
     90        void clearErr() {
     91                pakfs_clearerr(fd);
     92        }
     93        void finalize() {
     94                pakfs_flush(fd);
     95        }
     96};
     97
     98class PAKSaveManager : public Common::SaveFileManager {
     99public:
     100
     101        virtual Common::OutSaveFile *openForSaving(const Common::String &filename) {
     102                return Common::wrapCompressedWriteStream(new OutPAKSave(filename.c_str()));
     103        }
     104
     105        virtual Common::InSaveFile *openForLoading(const Common::String &filename) {
     106                InPAKSave *s = new InPAKSave();
     107                if (s->readSaveGame(filename.c_str())) {
     108                        return Common::wrapCompressedReadStream(s);
     109                } else {
     110                        delete s;
     111                        return NULL;
     112                }
     113        }
     114
     115        virtual bool removeSavefile(const Common::String &filename) {
     116                return ::deleteSaveGame(filename.c_str());
     117        }
     118
     119        virtual Common::StringList listSavefiles(const Common::String &pattern);
     120};
     121
     122
     123#endif
     124
  • backends/platform/n64/nintendo64.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
     24#include "osys_n64.h"
     25
     26int main(void) {
     27        g_system = new OSystem_N64();
     28        assert(g_system);
     29
     30        // Invoke the actual ScummVM main entry point:
     31        int res = scummvm_main(0, NULL);
     32        g_system->quit();       // TODO: Consider removing / replacing this!
     33        return res;
     34}
     35
  • backends/platform/n64/osys_n64_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 */
     23
     24#include "osys_n64.h"
     25
     26// Pad buttons
     27#define START_BUTTON(a) (a & 0x1000)
     28#define A_BUTTON(a)     (a & 0x8000)
     29#define B_BUTTON(a)     (a & 0x4000)
     30#define Z_BUTTON(a)     (a & 0x2000)
     31
     32// Triggers
     33#define TL_BUTTON(a)    (a & 0x0020)
     34#define TR_BUTTON(a)    (a & 0x0010)
     35
     36// D-Pad
     37#define DL_BUTTON(a)    (a & 0x0200)
     38#define DR_BUTTON(a)    (a & 0x0100)
     39#define DU_BUTTON(a)    (a & 0x0800)
     40#define DD_BUTTON(a)    (a & 0x0400)
     41
     42// Yellow C buttons
     43#define CL_BUTTON(a)    (a & 0x0002)
     44#define CR_BUTTON(a)    (a & 0x0001)
     45#define CU_BUTTON(a)    (a & 0x0008)
     46#define CD_BUTTON(a)    (a & 0x0004)
     47
     48#define PAD_DEADZONE 5
     49#define PAD_ACCELERATION 10
     50#define PAD_CHECK_TIME 40
     51
     52bool OSystem_N64::pollEvent(Common::Event &event) {
     53        // Check Timers. Not the best place, but checking in interrupts proved to be unsafe
     54        checkTimers();
     55
     56        // Refill audio buffers, doing this inside interrupts could be harmful
     57        refillAudioBuffers();
     58
     59        // Read current controller status
     60        controller_Read_Buttons(_ctrlData);
     61
     62        static uint16 oldButtons = 0; // old button data... used for button press/release
     63        uint16 newButtons = _ctrlData->c[0].buttons; // Read from controller 0
     64
     65        bool buttonPressed = false;
     66        static bool left_digital = false;
     67        static bool right_digital = false;
     68        static bool up_digital = false;
     69        static bool down_digital = false;
     70
     71        int8 analogX = (_ctrlData->c[0].throttle >> 8) & 0xFF;
     72        int8 analogY = (_ctrlData->c[0].throttle >> 0) & 0xFF;
     73
     74        if (DL_BUTTON(newButtons) && !DL_BUTTON(oldButtons)) // Pressed LEFT
     75                left_digital = true;
     76        else if (!DL_BUTTON(newButtons) && DL_BUTTON(oldButtons)) // Released LEFT
     77                left_digital = false;
     78
     79        if (DR_BUTTON(newButtons) && !DR_BUTTON(oldButtons)) // Pressed RIGHT
     80                right_digital = true;
     81        else if (!DR_BUTTON(newButtons) && DR_BUTTON(oldButtons)) // Released RIGHT
     82                right_digital = false;
     83
     84        if (DU_BUTTON(newButtons) && !DU_BUTTON(oldButtons)) // Pressed UP
     85                up_digital = true;
     86        else if (!DU_BUTTON(newButtons) && DU_BUTTON(oldButtons)) // Released UP
     87                up_digital = false;
     88
     89        if (DD_BUTTON(newButtons) && !DD_BUTTON(oldButtons)) // Pressed DOWN
     90                down_digital = true;
     91        else if (!DD_BUTTON(newButtons) && DD_BUTTON(oldButtons)) // Released DOWN
     92                down_digital = false;
     93
     94        if (B_BUTTON(newButtons) && !B_BUTTON(oldButtons)) { // Pressed B - Right Mouse Button
     95                buttonPressed = true;
     96                event.type = Common::EVENT_RBUTTONDOWN;
     97        } else if (!B_BUTTON(newButtons) && B_BUTTON(oldButtons)) { // Released B
     98                buttonPressed = true;
     99                event.type = Common::EVENT_RBUTTONUP;
     100        } else if (A_BUTTON(newButtons) && !A_BUTTON(oldButtons)) { // Pressed A - Period
     101                buttonPressed = true;
     102                event.kbd.keycode = Common::KEYCODE_PERIOD;
     103                event.kbd.ascii = '.';
     104                event.type = Common::EVENT_KEYDOWN;
     105        } else if (!A_BUTTON(newButtons) && A_BUTTON(oldButtons)) { // Released A
     106                buttonPressed = true;
     107                event.kbd.keycode = Common::KEYCODE_PERIOD;
     108                event.kbd.ascii = '.';
     109                event.type = Common::EVENT_KEYUP;
     110        } else if (START_BUTTON(newButtons) && !START_BUTTON(oldButtons)) { // Pressed START - F5
     111                buttonPressed = true;
     112                event.kbd.keycode = Common::KEYCODE_F5;
     113                event.kbd.ascii = Common::ASCII_F5;
     114                event.type = Common::EVENT_KEYDOWN;
     115        } else if (!START_BUTTON(newButtons) && START_BUTTON(oldButtons)) { // Released START
     116                buttonPressed = true;
     117                event.kbd.keycode = Common::KEYCODE_F5;
     118                event.kbd.ascii = Common::ASCII_F5;
     119                event.type = Common::EVENT_KEYUP;
     120        } else if (CU_BUTTON(newButtons) && !CU_BUTTON(oldButtons)) { // Pressed Yellow Up - UP
     121                buttonPressed = true;
     122                event.kbd.keycode = Common::KEYCODE_UP;
     123                event.type = Common::EVENT_KEYDOWN;
     124        } else if (!CU_BUTTON(newButtons) && CU_BUTTON(oldButtons)) { // Released Yellow Up
     125                buttonPressed = true;
     126                event.kbd.keycode = Common::KEYCODE_UP;
     127                event.type = Common::EVENT_KEYUP;
     128        } else if (CD_BUTTON(newButtons) && !CD_BUTTON(oldButtons)) { // Pressed Yellow Down - DOWN
     129                buttonPressed = true;
     130                event.kbd.keycode = Common::KEYCODE_DOWN;
     131                event.type = Common::EVENT_KEYDOWN;
     132        } else if (!CD_BUTTON(newButtons) && CD_BUTTON(oldButtons)) { // Released Yellow Down
     133                buttonPressed = true;
     134                event.kbd.keycode = Common::KEYCODE_DOWN;
     135                event.type = Common::EVENT_KEYUP;
     136        } else if (CL_BUTTON(newButtons) && !CL_BUTTON(oldButtons)) { // Pressed Yellow Left - LEFT
     137                buttonPressed = true;
     138                event.kbd.keycode = Common::KEYCODE_LEFT;
     139                event.type = Common::EVENT_KEYDOWN;
     140        } else if (!CL_BUTTON(newButtons) && CL_BUTTON(oldButtons)) { // Released Yellow Left
     141                buttonPressed = true;
     142                event.kbd.keycode = Common::KEYCODE_LEFT;
     143                event.type = Common::EVENT_KEYUP;
     144        } else if (CR_BUTTON(newButtons) && !CR_BUTTON(oldButtons)) { // Pressed Yellow Right - RIGHT
     145                buttonPressed = true;
     146                event.kbd.keycode = Common::KEYCODE_RIGHT;
     147                event.type = Common::EVENT_KEYDOWN;
     148        } else if (!CR_BUTTON(newButtons) && CR_BUTTON(oldButtons)) { // Released Yellow Right
     149                buttonPressed = true;
     150                event.kbd.keycode = Common::KEYCODE_RIGHT;
     151                event.type = Common::EVENT_KEYUP;
     152        } else if (TL_BUTTON(newButtons) && !TL_BUTTON(oldButtons)) { // Pressed Trigger Left - ESC
     153                buttonPressed = true;
     154                event.kbd.keycode = Common::KEYCODE_ESCAPE;
     155                event.kbd.ascii = 27;
     156                event.type = Common::EVENT_KEYDOWN;
     157        } else if (!TL_BUTTON(newButtons) && TL_BUTTON(oldButtons)) { // Released Trigger Left
     158                buttonPressed = true;
     159                event.kbd.keycode = Common::KEYCODE_ESCAPE;
     160                event.kbd.ascii = 27;
     161                event.type = Common::EVENT_KEYUP;
     162        } else if (TR_BUTTON(newButtons) && !TR_BUTTON(oldButtons)) { // Pressed Trigger Right - F7
     163                buttonPressed = true;
     164                event.kbd.keycode = Common::KEYCODE_F7;
     165                event.kbd.ascii = Common::ASCII_F7;
     166                event.type = Common::EVENT_KEYDOWN;
     167        } else if (!TR_BUTTON(newButtons) && TR_BUTTON(oldButtons)) { // Released Trigger Right
     168                buttonPressed = true;
     169                event.kbd.keycode = Common::KEYCODE_F7;
     170                event.kbd.ascii = Common::ASCII_F7;
     171                event.type = Common::EVENT_KEYUP;
     172        } else if (Z_BUTTON(newButtons) && !Z_BUTTON(oldButtons)) { // Pressed Z - Left Mouse Button
     173                buttonPressed = true;
     174                event.type = Common::EVENT_LBUTTONDOWN;
     175        } else if (!Z_BUTTON(newButtons) && Z_BUTTON(oldButtons)) { // Released Z
     176                buttonPressed = true;
     177                event.type = Common::EVENT_LBUTTONUP;
     178        }
     179
     180        oldButtons = newButtons; // Save current button status
     181
     182        if (buttonPressed) {
     183                event.mouse.x = _mouseX;
     184                event.mouse.y = _mouseY;
     185                return true;
     186        }
     187
     188        static uint32 _lastPadCheck = 0;
     189        uint32 curTime = getMillis();
     190
     191        if ((curTime - _lastPadCheck) > PAD_CHECK_TIME) {
     192                _lastPadCheck = curTime;
     193
     194                int32 mx = _mouseX;
     195                int32 my = _mouseY;
     196
     197                if (left_digital || right_digital || up_digital || down_digital) {
     198                        if (left_digital)
     199                                mx -= 5;
     200                        else if (right_digital)
     201                                mx += 5;
     202                        if (up_digital)
     203                                my -= 5;
     204                        else if (down_digital)
     205                                my += 5;
     206                }
     207
     208                if (abs(analogX) > PAD_DEADZONE)
     209                        mx += analogX / (PAD_ACCELERATION - (abs(analogX) / 20));
     210
     211                if (abs(analogY) > PAD_DEADZONE)
     212                        my -= analogY / (PAD_ACCELERATION - (abs(analogY) / 20));
     213
     214                if (mx < 0)
     215                        mx = 0;
     216
     217                if (mx >= _mouseMaxX)
     218                        mx = _mouseMaxX - 1;
     219
     220                if (my < 0)
     221                        my = 0;
     222
     223                if (my >= _mouseMaxY)
     224                        my = _mouseMaxY - 1;
     225
     226                if ((mx != _mouseX) || (my != _mouseY)) {
     227
     228                        event.type = Common::EVENT_MOUSEMOVE;
     229                        event.mouse.x = _mouseX = mx;
     230                        event.mouse.y = _mouseY = my;
     231
     232                        _dirtyOffscreen = true;
     233
     234                        return true;
     235                }
     236
     237        }
     238
     239        return false;
     240}
     241
  • backends/platform/n64/osys_n64.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
     24#ifndef __OSYS_N64_H__
     25#define __OSYS_N64_H__
     26
     27#include "common/rect.h"
     28#include "common/config-manager.h"
     29
     30#include "backends/base-backend.h"
     31#include "backends/saves/default/default-saves.h"
     32#include "backends/timer/default/default-timer.h"
     33
     34#include "base/main.h"
     35
     36#include "graphics/surface.h"
     37#include "graphics/colormasks.h"
     38#include "graphics/pixelformat.h"
     39
     40#include "sound/mixer_intern.h"
     41
     42#include <libn64.h>
     43#include <n64utils.h>
     44
     45#define DEFAULT_SOUND_SAMPLE_RATE 8000 // 8 kHz
     46//#define DEFAULT_SOUND_SAMPLE_RATE 11025 // 11 kHz
     47
     48// Limit the N64 resolution to 320x240, because framebuffer
     49// at higher resolutions would be too slow and memory hogging
     50#define DEFAULT_SCREEN_WIDTH  320
     51#define DEFAULT_SCREEN_HEIGHT 240
     52
     53#define N64_PAL_FPS 25
     54#define N64_NTSC_FPS 30
     55
     56typedef int (*TimerProc)(int interval);
     57
     58// Interrupt callback functions
     59void vblCallback(void);
     60void sndCallback(void);
     61void refillAudioBuffers(void);
     62
     63// External utility functions
     64void enableAudioPlayback(void);
     65void disableAudioPlayback(void);
     66void checkTimers(void);
     67int timer_handler(int t);
     68
     69static volatile bool _audioEnabled = false; // Used by interrupt callbacks
     70
     71/* Graphic mode identifiers */
     72enum GraphicModeID {
     73        OVERS_NTSC_340X240,
     74        NORM_NTSC_320X240,
     75        NORM_PAL_320X240,
     76        OVERS_PAL_340X240,
     77        NORM_MPAL_320X240,
     78        OVERS_MPAL_340X240
     79};
     80
     81class OSystem_N64 : public BaseBackend {
     82protected:
     83        Common::SaveFileManager *_savefile;
     84        Audio::MixerImpl *_mixer;
     85        Common::TimerManager *_timer;
     86        FilesystemFactory *_fsFactory;
     87
     88        struct display_context * _dc; // Display context for N64 on screen buffer switching
     89
     90        Graphics::Surface _framebuffer;
     91
     92        uint16 *_offscreen_hic; // Offscreen converted to 16bit surface
     93        uint8  *_offscreen_pal; // Offscreen with palette indexes
     94        OverlayColor *_overlayBuffer; // Offscreen for the overlay (16 bit)
     95
     96        uint16 *_screenPalette; // Array for palette entries (256 colors max)
     97        uint16 _cursorPalette[256]; // Palette entries for the cursor
     98
     99        int _graphicMode; // Graphic mode
     100        uint16 _screenWidth, _screenHeight;
     101        uint16 _gameWidth, _gameHeight;
     102        uint16 _frameBufferWidth; // Width of framebuffer in N64 memory
     103        uint8 _offscrPixels; // Pixels to skip on each line before start drawing, used to center image
     104        uint8 _maxFps;
     105
     106        int _shakeOffset;
     107
     108        uint8 *_cursor_pal; // Cursor buffer, palettized
     109        bool _cursorPaletteDisabled;
     110        bool _dirtyPalette;
     111
     112        int _cursorWidth, _cursorHeight;
     113        int _cursorKeycolor;
     114
     115        uint16  _overlayHeight, _overlayWidth;
     116        bool    _overlayVisible;
     117
     118        bool _mouseVisible;
     119        int _mouseX, _mouseY;
     120        int _mouseMaxX, _mouseMaxY;
     121        int _mouseHotspotX, _mouseHotspotY;
     122
     123        controller_data_buttons *_ctrlData; // Controller data read from the N64 serial interface
     124
     125        bool _dirtyOffscreen;
     126
     127public:
     128
     129        /* These have to be accessed by interrupt callbacks */
     130        uint16 _audioBufferSize;
     131        uint32 _viClockRate; // Clock rate of video system, depending on VI mode
     132
     133        int _timerCallbackNext;
     134        int _timerCallbackTimer;
     135        TimerProc _timerCallback;
     136        /* *** */
     137
     138        OSystem_N64();
     139        virtual ~OSystem_N64();
     140
     141        virtual void initBackend();
     142
     143        virtual bool hasFeature(Feature f);
     144        virtual void setFeatureState(Feature f, bool enable);
     145        virtual bool getFeatureState(Feature f);
     146        virtual const GraphicsMode *getSupportedGraphicsModes() const;
     147        virtual int getDefaultGraphicsMode() const;
     148        bool setGraphicsMode(const char *name);
     149        virtual bool setGraphicsMode(int mode);
     150        virtual int getGraphicsMode() const;
     151        virtual void initSize(uint width, uint height, const Graphics::PixelFormat *format);
     152        virtual int16 getHeight();
     153        virtual int16 getWidth();
     154        virtual void setPalette(const byte *colors, uint start, uint num);
     155        virtual void grabPalette(byte *colors, uint start, uint num);
     156        virtual void copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h);
     157        virtual void updateScreen();
     158        virtual Graphics::Surface *lockScreen();
     159        virtual void unlockScreen();
     160        virtual void setShakePos(int shakeOffset);
     161
     162        virtual void showOverlay();
     163        virtual void hideOverlay();
     164        virtual void clearOverlay();
     165        virtual void grabOverlay(OverlayColor *buf, int pitch);
     166        virtual void copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h);
     167        virtual int16 getOverlayHeight();
     168        virtual int16 getOverlayWidth();
     169        virtual Graphics::PixelFormat getOverlayFormat() const {
     170                return Graphics::createPixelFormat<555>();
     171        }
     172
     173        virtual bool showMouse(bool visible);
     174
     175        virtual void warpMouse(int x, int y);
     176        virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format);
     177        virtual void setCursorPalette(const byte *colors, uint start, uint num);
     178        virtual void disableCursorPalette(bool disable);
     179
     180        virtual bool pollEvent(Common::Event &event);
     181        virtual uint32 getMillis();
     182        virtual void delayMillis(uint msecs);
     183
     184        virtual MutexRef createMutex(void);
     185        virtual void lockMutex(MutexRef mutex);
     186        virtual void unlockMutex(MutexRef mutex);
     187        virtual void deleteMutex(MutexRef mutex);
     188
     189        virtual void quit();
     190
     191        virtual Common::SaveFileManager *getSavefileManager();
     192        virtual Audio::Mixer *getMixer();
     193        virtual void getTimeAndDate(TimeDate &t) const;
     194        virtual Common::TimerManager *getTimerManager();
     195        virtual void setTimerCallback(TimerProc callback, int interval);
     196        FilesystemFactory *getFilesystemFactory();
     197
     198        void rebuildOffscreenGameBuffer(void);
     199        void switchGraphicModeId(int mode);
     200
     201        void setupMixer(void);
     202
     203};
     204
     205#endif /* __OSYS_N64_H__ */
     206
  • backends/platform/n64/pad_rom.sh

     
     1#!/bin/bash
     2
     3TARGET="scummvm"
     4BASESIZE=2097152
     5
     6CARTSIZE=`ls -l $TARGET.v64 | cut -d" " -f5`
     7
     8REMAINDER=`echo $CARTSIZE % $BASESIZE   | bc`
     9REMAINDER=`echo $BASESIZE - $REMAINDER  | bc`
     10CARTSIZE=`echo $CARTSIZE + $REMAINDER  | bc`
     11
     12ucon64 -q --n64 --v64 --chk --padn=$CARTSIZE  $TARGET.v64
     13
  • backends/platform/n64/module.mk

     
     1MODULE := backends/platform/n64
     2
     3MODULE_OBJS := \
     4        nintendo64.o
     5
     6MODULE_DIRS += \
     7        backends/platform/n64/
     8
     9# We don't use the rules.mk here on purpose
     10OBJS := $(addprefix $(MODULE)/, $(MODULE_OBJS)) $(OBJS)
  • backends/platform/n64/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 * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/backends/platform/dc/portdefs.h $
     22 * $Id: portdefs.h 27024 2007-05-30 21:56:52Z fingolfin $
     23 *
     24 */
     25
     26#ifndef __N64_PORTDEFS__
     27#define __N64_PORTDEFS__
     28
     29#include <n64utils.h>
     30
     31#include <sys/types.h>
     32#include <stdio.h>
     33#include <fcntl.h>
     34#include <stdlib.h>
     35#include <string.h>
     36#include <stdarg.h>
     37#include <assert.h>
     38#include <ctype.h>
     39#include <math.h>
     40#include <malloc.h>
     41
     42#undef assert
     43#define assert(x)  ((x) ? 0 : (print_error("["#x"] (%s:%d)", __FILE__, __LINE__)))
     44
     45#endif
     46
  • backends/platform/n64/Makefile

     
     1
     2TOOLPATH = /opt/mips64-toolchain
     3LIBN64PATH = $(TOOLPATH)/hkz-libn64/
     4GCCN64PREFIX = $(TOOLPATH)/bin/mips64-
     5
     6srcdir = ../../..
     7VPATH = $(srcdir)
     8
     9CC = $(GCCN64PREFIX)gcc
     10CXX = $(GCCN64PREFIX)g++
     11AS = $(GCCN64PREFIX)as
     12LD = $(GCCN64PREFIX)g++
     13OBJCOPY = $(GCCN64PREFIX)objcopy
     14AR = $(GCCN64PREFIX)ar cru
     15RANLIB = $(GCCN64PREFIX)ranlib
     16
     17DEFINES += -D__N64__ -DLIMIT_FPS -DNONSTANDARD_PORT -DDISABLE_DEFAULT_SAVEFILEMANAGER -DDISABLE_TEXT_CONSOLE -DDISABLE_COMMAND_LINE -DDISABLE_FANCY_THEMES -DDISABLE_DOSBOX_OPL -DENABLE_VKEYBD -DUSE_ZLIB
     18LIBS += -lpakfs -ln64 -ln64utils -lromfs
     19
     20DEFINES += -D_ENABLE_DEBUG_
     21
     22USE_LIBMAD=0
     23USE_LIBOGG=1
     24
     25ifeq ($(USE_LIBMAD),1)
     26DEFINES += -DUSE_MAD
     27LIBS    += -lmad
     28endif
     29ifeq ($(USE_LIBOGG), 1)
     30DEFINES += -DUSE_VORBIS -DUSE_TREMOR
     31LIBS    += -lvorbisidec
     32endif
     33
     34LIBS += -lm -lstdc++ -lc -lgcc -lz -lnosys
     35
     36CXXFLAGS = -g -Os -fomit-frame-pointer -march=vr4300 -mtune=vr4300 -mno-extern-sdata -fno-rtti -fno-exceptions -Wno-multichar -Wshadow -I$(LIBN64PATH) -I$(TOOLPATH)/include -I./ -I$(srcdir) -I$(srcdir)/engines
     37LDFLAGS = -g -march=vr4300 -mtune=vr4300 -nodefaultlibs -nostartfiles -mno-crt0 -L$(LIBN64PATH) -L$(TOOLPATH)/lib $(LIBS) -T n64ld_cpp.x -Xlinker -Map -Xlinker scummvm.map
     38
     39TARGET = scummvm
     40DEPDIR = .deps
     41CXX_UPDATE_DEP_FLAG = -Wp,-MMD,"$(*D)/$(DEPDIR)/$(*F).d",-MQ,"$@",-MP
     42MKDIR = mkdir -p
     43RM = rm -f
     44RM_REC = rm -rf
     45
     46VERBOSE_BUILD=0
     47HAVE_GCC3=1
     48DISABLE_SCALERS=1
     49DISABLE_HQ_SCALER=1
     50USE_MT32EMU=0
     51USE_RGB_COLOR=0
     52
     53ENABLED=STATIC_PLUGIN
     54
     55ENABLE_SCUMM=$(ENABLED)
     56#ENABLE_SKY=$(ENABLED)
     57#ENABLE_SCI=$(ENABLED)
     58#ENABLE_GOB=$(ENABLED)
     59#ENABLE_PARALLACTION=$(ENABLED)
     60#ENABLE_KYRA=$(ENABLED)
     61#ENABLE_AGOS = $(ENABLED)
     62#ENABLE_AGI = $(ENABLED)
     63
     64OBJS := nintendo64.o osys_n64_base.o osys_n64_events.o osys_n64_utilities.o pakfs_save_manager.o
     65
     66include $(srcdir)/Makefile.common
     67
     68MODULE_DIRS += ./
     69
     70all: $(TARGET).v64
     71
     72$(TARGET).v64: $(TARGET).bin ROMFS.img bootcode
     73        cat bootcode $(TARGET).bin ROMFS.img > $(TARGET).v64
     74        ./pad_rom.sh
     75
     76ROMFS.img:
     77        genromfs -f ./ROMFS.img -d ./ROMFS -V romtest
     78
     79$(TARGET).elf: $(OBJS)
     80        $(LD) -o $(TARGET).elf $(OBJS) $(LDFLAGS)
     81
     82$(TARGET).bin : $(TARGET).elf
     83        $(OBJCOPY) $(TARGET).elf $(TARGET).bin -O binary
     84
     85spotless : distclean
     86        $(RM) *.bin *.elf *.v64 *.img *.bak *.tmp *.map
     87
     88send: $(TARGET).v64
     89        sudo ucon64 --xv64  $(TARGET).v64
     90
  • backends/platform/n64/pakfs_save_manager.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#include <n64utils.h>
     24#include "pakfs_save_manager.h"
     25
     26static bool matches(const char *glob, const char *name);
     27
     28bool deleteSaveGame(const char *filename) {
     29        int res = removeFileOnPak(filename);
     30        flushCurrentPakData();
     31
     32        return (res == 0);
     33}
     34
     35uint32 InPAKSave::read(void *buf, uint32 cnt) {
     36        return pakfs_read(buf, 1, cnt, fd);
     37}
     38
     39bool InPAKSave::seek(int32 offs, int whence) {
     40        pakfs_seek(fd, offs, whence);
     41
     42        return true;
     43}
     44
     45bool InPAKSave::skip(uint32 offset) {
     46        pakfs_seek(fd, offset, SEEK_CUR);
     47
     48        return true;
     49}
     50
     51uint32 OutPAKSave::write(const void *buf, uint32 cnt) {
     52        return pakfs_write(buf, 1, cnt, fd);
     53}
     54
     55Common::StringList PAKSaveManager::listSavefiles(const Common::String &pattern) {
     56        PAKDIR *dirp = pakfs_opendir();
     57        pakfs_dirent *dp;
     58        Common::StringList list;
     59
     60        while ((dp = pakfs_readdir(dirp)) != NULL) {
     61                if (matches(pattern.c_str(), dp->entryname))
     62                        list.push_back(dp->entryname);
     63
     64                free(dp);
     65        }
     66
     67        pakfs_closedir(dirp);
     68
     69        return list;
     70}
     71
     72static bool matches(const char *glob, const char *name) {
     73        while (*glob)
     74                if (*glob == '*') {
     75                        while (*glob == '*')
     76                                glob++;
     77                        do {
     78                                if ((*name == *glob || *glob == '?') &&
     79                                        matches(glob, name))
     80                                        return true;
     81                        } while (*name++);
     82                        return false;
     83                } else if (!*name)
     84                        return false;
     85                else if (*glob == '?' || *glob == *name) {
     86                        glob++;
     87                        name++;
     88                } else
     89                        return false;
     90        return !*name;
     91}
     92
  • backends/fs/stdiostream.cpp

     
    2525
    2626#include "backends/fs/stdiostream.h"
    2727
     28#ifdef __N64__
     29        #include <romfs.h>
     30
     31        #undef feof
     32        #undef clearerr
     33        #undef ferror
     34
     35        #undef FILE
     36        #define FILE ROMFILE
     37
     38        #define fopen(name, mode)                                       romfs_open(name, mode)
     39        #define fclose(handle)                                          romfs_close(handle)
     40        #define fread(ptr, size, items, file)           romfs_read(ptr, size, items, file)
     41        #define fwrite(ptr, size, items, file)          romfs_write(ptr, size, items, file)
     42        #define feof(handle)                                            romfs_eof(handle)
     43        #define ftell(handle)                                           romfs_tell(handle)
     44        #define fseek(handle, offset, whence)           romfs_seek(handle, offset, whence)
     45        #define clearerr(handle)                                        romfs_clearerr(handle)
     46        #define fflush(file)                                            romfs_flush(file)
     47        #define ferror(handle)                                          romfs_error(handle)
     48#endif
     49
    2850StdioStream::StdioStream(void *handle) : _handle(handle) {
    2951        assert(handle);
    3052}
  • backends/fs/n64/n64-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 * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/backends/fs/posix/posix-fs-factory.cpp $
     22 * $Id: posix-fs-factory.cpp 39398 2009-03-14 17:07:07Z fingolfin $
     23 */
     24
     25#ifdef __N64__
     26
     27#include <n64utils.h>
     28
     29#include "backends/fs/n64/n64-fs-factory.h"
     30#include "backends/fs/n64/n64-fs.cpp"
     31
     32AbstractFSNode *N64FilesystemFactory::makeRootFileNode() const {
     33        return new N64FilesystemNode();
     34}
     35
     36AbstractFSNode *N64FilesystemFactory::makeCurrentDirectoryFileNode() const {
     37        char buf[MAXPATHLEN];
     38        return romfs_getcwd(buf, MAXPATHLEN) ? new N64FilesystemNode(Common::String(buf), false) : NULL;
     39}
     40
     41AbstractFSNode *N64FilesystemFactory::makeFileNodePath(const Common::String &path) const {
     42        assert(!path.empty());
     43        return new N64FilesystemNode(path, false);
     44}
     45
     46#endif
     47
  • backends/fs/n64/n64-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 * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/backends/fs/posix/posix-fs-factory.h $
     22 * $Id: posix-fs-factory.h 34716 2008-10-02 16:58:59Z fingolfin $
     23 */
     24
     25#ifndef N64_FILESYSTEM_FACTORY_H
     26#define N64_FILESYSTEM_FACTORY_H
     27
     28#include <romfs.h>
     29#include "backends/fs/fs-factory.h"
     30
     31/**
     32 * Creates N64FilesystemNode objects.
     33 *
     34 * Parts of this class are documented in the base interface class, FilesystemFactory.
     35 */
     36class N64FilesystemFactory : public FilesystemFactory {
     37        virtual AbstractFSNode *makeRootFileNode() const;
     38        virtual AbstractFSNode *makeCurrentDirectoryFileNode() const;
     39        virtual AbstractFSNode *makeFileNodePath(const Common::String &path) const;
     40};
     41
     42#endif /*N64_FILESYSTEM_FACTORY_H*/
  • backends/fs/n64/n64-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#ifdef __N64__
     24
     25#include "backends/fs/abstract-fs.h"
     26#include "backends/fs/stdiostream.h"
     27
     28#include <sys/param.h>
     29
     30#include <unistd.h>
     31
     32#include <n64utils.h>
     33
     34#define ROOT_PATH       "/"
     35
     36/**
     37 * Implementation of the ScummVM file system API based on N64 Hkz romfs.
     38 *
     39 * Parts of this class are documented in the base interface class, AbstractFSNode.
     40 */
     41class N64FilesystemNode : public AbstractFSNode {
     42protected:
     43        Common::String _displayName;
     44        Common::String _path;
     45        bool _isDirectory;
     46        bool _isValid;
     47
     48public:
     49        /**
     50         * Creates a N64FilesystemNode with the root node as path.
     51         */
     52        N64FilesystemNode();
     53
     54        /**
     55         * Creates a N64FilesystemNode for a given path.
     56         *
     57         * @param path Common::String with the path the new node should point to.
     58         * @param verify true if the isValid and isDirectory flags should be verified during the construction.
     59         */
     60        N64FilesystemNode(const Common::String &p, bool verify = true);
     61
     62        virtual bool exists() const;
     63        virtual Common::String getDisplayName() const {
     64                return _displayName;
     65        }
     66        virtual Common::String getName() const {
     67                return _displayName;
     68        }
     69        virtual Common::String getPath() const {
     70                return _path;
     71        }
     72        virtual bool isDirectory() const {
     73                return _isDirectory;
     74        }
     75        virtual bool isReadable() const;
     76        virtual bool isWritable() const;
     77
     78        virtual AbstractFSNode *getChild(const Common::String &n) const;
     79        virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const;
     80        virtual AbstractFSNode *getParent() const;
     81
     82        virtual Common::SeekableReadStream *createReadStream();
     83        virtual Common::WriteStream *createWriteStream();
     84};
     85
     86N64FilesystemNode::N64FilesystemNode() {
     87        _isDirectory = true;
     88        _displayName = "Root";
     89        _isValid = true;
     90        _path = ROOT_PATH;
     91}
     92
     93N64FilesystemNode::N64FilesystemNode(const Common::String &p, bool verify) {
     94        assert(p.size() > 0);
     95
     96        _path = p;
     97        _displayName = lastPathComponent(_path, '/');
     98        _isValid = true;
     99        _isDirectory = true;
     100
     101        // Check if it's a dir
     102        ROMFILE *tmpfd = romfs_open(p.c_str(), "r");
     103        if (tmpfd) {
     104                _isDirectory = (tmpfd->type == 0 || tmpfd->type == 1);
     105                romfs_close(tmpfd);
     106        }
     107}
     108
     109bool N64FilesystemNode::exists() const {
     110        int ret = -1;
     111
     112        ret = romfs_access(_path.c_str(), F_OK);
     113
     114        return ret == 0;
     115}
     116
     117bool N64FilesystemNode::isReadable() const {
     118        int ret = -1;
     119
     120        ret = romfs_access(_path.c_str(), R_OK);
     121
     122        return ret == 0;
     123}
     124
     125// We can't write on ROMFS!
     126bool N64FilesystemNode::isWritable() const {
     127        return false;
     128}
     129
     130
     131AbstractFSNode *N64FilesystemNode::getChild(const Common::String &n) const {
     132        // FIXME: Pretty lame implementation! We do no error checking to speak
     133        // of, do not check if this is a special node, etc.
     134        assert(_isDirectory);
     135
     136        Common::String newPath(_path);
     137        if (_path.lastChar() != '/')
     138                newPath += '/';
     139        newPath += n;
     140
     141        return new N64FilesystemNode(newPath, true);
     142}
     143
     144bool N64FilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const {
     145        assert(_isDirectory);
     146        ROMDIR *dirp = romfs_opendir(_path.c_str());
     147        romfs_dirent *dp;
     148
     149        if (dirp == NULL)
     150                return false;
     151
     152        // loop over dir entries using readdir
     153        while ((dp = romfs_readdir(dirp)) != NULL) {
     154                // Skip 'invisible' files if necessary
     155                if (dp->entryname[0] == '.' && !hidden) {
     156                        free(dp);
     157                        continue;
     158                }
     159                // Skip '.' and '..' to avoid cycles
     160                if ((dp->entryname[0] == '.' && dp->entryname[1] == 0) || (dp->entryname[0] == '.' && dp->entryname[1] == '.')) {
     161                        free(dp);
     162                        continue;
     163                }
     164
     165                // Start with a clone of this node, with the correct path set
     166                N64FilesystemNode entry(*this);
     167                entry._displayName = dp->entryname;
     168                if (_path.lastChar() != '/')
     169                        entry._path += '/';
     170                entry._path += entry._displayName;
     171
     172                // Force validity for now...
     173                entry._isValid = 1;
     174
     175                entry._isDirectory = (dp->type == 0 || dp->type == 1);
     176
     177                // Honor the chosen mode
     178                if ((mode == Common::FSNode::kListFilesOnly && entry._isDirectory) ||
     179                        (mode == Common::FSNode::kListDirectoriesOnly && !entry._isDirectory)) {
     180
     181                        free(dp);
     182                        continue;
     183                }
     184
     185                myList.push_back(new N64FilesystemNode(entry));
     186
     187                free(dp);
     188        }
     189        romfs_closedir(dirp);
     190
     191        return true;
     192}
     193
     194AbstractFSNode *N64FilesystemNode::getParent() const {
     195        if (_path == ROOT_PATH)
     196                return 0;
     197
     198        const char *start = _path.c_str();
     199        const char *end = lastPathComponent(_path, '/');
     200
     201        return new N64FilesystemNode(Common::String(start, end - start), false);
     202}
     203
     204Common::SeekableReadStream *N64FilesystemNode::createReadStream() {
     205        return StdioStream::makeFromPath(getPath(), false);
     206}
     207
     208Common::WriteStream *N64FilesystemNode::createWriteStream() {
     209        return StdioStream::makeFromPath(getPath(), true);
     210}
     211
     212#endif //#ifdef __N64__
     213
  • backends/module.mk

     
    1515        fs/symbian/symbian-fs-factory.o \
    1616        fs/windows/windows-fs-factory.o \
    1717        fs/wii/wii-fs-factory.o \
     18        fs/n64/n64-fs-factory.o \
    1819        keymapper/action.o \
    1920        keymapper/keymap.o \
    2021        keymapper/keymapper.o \