Ticket #9123: svm-n64-patch-29122009-1.diff

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

Little performance tweaks

  • 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;
  • 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);
  • 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
  • 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        while (s_supportedGraphicsModes[i].name) {
     206                if (!strcmpi(s_supportedGraphicsModes[i].name, mode)) {
     207                        _graphicMode = s_supportedGraphicsModes[i].id;
     208
     209                        switchGraphicModeId(_graphicMode);
     210
     211                        return true;
     212                }
     213                i++;
     214        }
     215
     216        return true;
     217}
     218
     219bool OSystem_N64::setGraphicsMode(int mode) {
     220        _graphicMode = mode;
     221        switchGraphicModeId(_graphicMode);
     222
     223        return true;
     224}
     225
     226void OSystem_N64::switchGraphicModeId(int mode) {
     227        switch (mode) {
     228        case NORM_PAL_320X240:
     229                disableAudioPlayback();
     230                _viClockRate = VI_PAL_CLOCK;
     231                _maxFps = N64_PAL_FPS;
     232                initDisplay(PAL_320X240_16BIT);
     233                _frameBufferWidth = 320;
     234                _screenWidth = DEFAULT_SCREEN_WIDTH;
     235                _screenHeight = DEFAULT_SCREEN_HEIGHT;
     236                _offscrPixels = 0;
     237                _graphicMode = NORM_PAL_320X240;
     238                enableAudioPlayback();
     239                break;
     240
     241        case OVERS_PAL_340X240:
     242                disableAudioPlayback();
     243                _viClockRate = VI_PAL_CLOCK;
     244                _maxFps = N64_PAL_FPS;
     245                initDisplay(PAL_340X240_16BIT);
     246                _frameBufferWidth = DEFAULT_FRAMEBUFFER_WIDTH;
     247                _screenWidth = DEFAULT_SCREEN_WIDTH;
     248                _screenHeight = DEFAULT_SCREEN_HEIGHT;
     249                _offscrPixels = DEFAULT_PIX_SKIP;
     250                _graphicMode = OVERS_PAL_340X240;
     251                enableAudioPlayback();
     252                break;
     253
     254        case NORM_MPAL_320X240:
     255                disableAudioPlayback();
     256                _viClockRate = VI_MPAL_CLOCK;
     257                _maxFps = N64_NTSC_FPS;
     258                initDisplay(MPAL_320X240_16BIT);
     259                _frameBufferWidth = 320;
     260                _screenWidth = DEFAULT_SCREEN_WIDTH;
     261                _screenHeight = DEFAULT_SCREEN_HEIGHT;
     262                _offscrPixels = 0;
     263                _graphicMode = NORM_MPAL_320X240;
     264                enableAudioPlayback();
     265                break;
     266
     267        case OVERS_MPAL_340X240:
     268                disableAudioPlayback();
     269                _viClockRate = VI_MPAL_CLOCK;
     270                _maxFps = N64_NTSC_FPS;
     271                initDisplay(MPAL_340X240_16BIT);
     272                _frameBufferWidth = DEFAULT_FRAMEBUFFER_WIDTH;
     273                _screenWidth = DEFAULT_SCREEN_WIDTH;
     274                _screenHeight = DEFAULT_SCREEN_HEIGHT;
     275                _offscrPixels = DEFAULT_PIX_SKIP;
     276                _graphicMode = OVERS_MPAL_340X240;
     277                enableAudioPlayback();
     278                break;
     279
     280        case NORM_NTSC_320X240:
     281                disableAudioPlayback();
     282                _viClockRate = VI_NTSC_CLOCK;
     283                _maxFps = N64_NTSC_FPS;
     284                initDisplay(NTSC_320X240_16BIT);
     285                _frameBufferWidth = 320;
     286                _screenWidth = DEFAULT_SCREEN_WIDTH;
     287                _screenHeight = DEFAULT_SCREEN_HEIGHT;
     288                _offscrPixels = 0;
     289                _graphicMode = NORM_NTSC_320X240;
     290                enableAudioPlayback();
     291                break;
     292
     293        case OVERS_NTSC_340X240:
     294        default:
     295                disableAudioPlayback();
     296                _viClockRate = VI_NTSC_CLOCK;
     297                _maxFps = N64_NTSC_FPS;
     298                initDisplay(NTSC_340X240_16BIT);
     299                _frameBufferWidth = DEFAULT_FRAMEBUFFER_WIDTH;
     300                _screenWidth = DEFAULT_SCREEN_WIDTH;
     301                _screenHeight = DEFAULT_SCREEN_HEIGHT;
     302                _offscrPixels = DEFAULT_PIX_SKIP;
     303                _graphicMode = OVERS_NTSC_340X240;
     304                enableAudioPlayback();
     305                break;
     306        }
     307}
     308
     309int OSystem_N64::getGraphicsMode() const {
     310        return _graphicMode;
     311}
     312
     313void OSystem_N64::initSize(uint width, uint height, const Graphics::PixelFormat *format) {
     314        _gameWidth = width;
     315        _gameHeight = height;
     316
     317        if (_gameWidth > _screenWidth)
     318                _gameWidth = _screenWidth;
     319        if (_gameHeight > _screenHeight)
     320                _gameHeight = _screenHeight;
     321
     322        _mouseMaxX = _gameWidth;
     323        _mouseMaxY = _gameHeight;
     324}
     325
     326int16 OSystem_N64::getHeight() {
     327        return _screenHeight;
     328}
     329
     330int16 OSystem_N64::getWidth() {
     331        return _screenWidth;
     332}
     333
     334void OSystem_N64::setPalette(const byte *colors, uint start, uint num) {
     335        for (int i = 0; i < num; ++i) {
     336                uint8 c[4];
     337                _screenPalette[start + i] = colBGR888toRGB555(colors[2], colors[1], colors[0]);
     338                colors += 4;
     339        }
     340
     341        _dirtyPalette = true;
     342        _dirtyOffscreen = true;
     343}
     344
     345void OSystem_N64::rebuildOffscreenGameBuffer(void) {
     346        // Regenerate hi-color offscreen buffer
     347#if 0
     348        for (int h = 0; h < _gameHeight; h++)
     349                for (int w = 0; w < _gameWidth; w++) {
     350                        uint8 color = _offscreen_pal[(h * _screenWidth) + w];
     351                        _offscreen_hic[(h * _screenWidth) + w] = _screenPalette[color];
     352                }
     353#else
     354        uint32 two_col_hi;
     355        uint32 four_col_pal;
     356        for (int h = 0; h < _gameHeight; h++)
     357                for (int w = 0; w < _gameWidth; w += 4) {
     358                        four_col_pal = *(uint32*)(_offscreen_pal + ((h * _screenWidth) + w));
     359
     360                        two_col_hi = 0;
     361                        two_col_hi = _screenPalette[((four_col_pal >> (8 * 3)) & 0xFF)] | (two_col_hi << (16 * 0));
     362                        two_col_hi = _screenPalette[((four_col_pal >> (8 * 2)) & 0xFF)] | (two_col_hi << (16 * 1));
     363
     364                        *(uint32*)(_offscreen_hic + (h * _screenWidth) + w + 0) = two_col_hi;
     365
     366                        two_col_hi = 0;
     367                        two_col_hi = _screenPalette[((four_col_pal >> (8 * 1)) & 0xFF)] | (two_col_hi << (16 * 0));
     368                        two_col_hi = _screenPalette[((four_col_pal >> (8 * 0)) & 0xFF)] | (two_col_hi << (16 * 1));
     369
     370                        *(uint32*)(_offscreen_hic + (h * _screenWidth) + w + 2) = two_col_hi;
     371                }
     372#endif
     373}
     374
     375void OSystem_N64::grabPalette(byte *colors, uint start, uint num) {
     376        uint32 i;
     377        uint16 color;
     378
     379        for (i = start; i < start + num; i++) {
     380                color = _screenPalette[i];
     381
     382                // Color format on the n64 is RGB - 1555
     383                *colors++ = ((color & 0x1F) << 3);
     384                *colors++ = (((color >> 5) & 0x1F) << 3);
     385                *colors++ = (((color >> 10) & 0x1F) << 3);
     386                *colors++ = 0;
     387        }
     388
     389        return;
     390}
     391
     392void OSystem_N64::setCursorPalette(const byte *colors, uint start, uint num) {
     393        for (int i = 0; i < num; ++i) {
     394                _cursorPalette[start + i] = colBGR888toRGB555(colors[2], colors[1], colors[0]);
     395                colors += 4;
     396        }
     397
     398        _cursorPaletteDisabled = false;
     399        _dirtyOffscreen = true;
     400}
     401
     402void OSystem_N64::disableCursorPalette(bool disable) {
     403        _cursorPaletteDisabled = disable;
     404
     405        _dirtyOffscreen = true;
     406}
     407
     408void OSystem_N64::copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h) {
     409        //Clip the coordinates
     410        if (x < 0) {
     411                w += x;
     412                buf -= x;
     413                x = 0;
     414        }
     415
     416        if (y < 0) {
     417                h += y;
     418                buf -= y * pitch;
     419                y = 0;
     420        }
     421
     422        if (w > _screenWidth - x) {
     423                w = _screenWidth - x;
     424        }
     425
     426        if (h > _screenHeight - y) {
     427                h = _screenHeight - y;
     428        }
     429
     430        if (w <= 0 || h <= 0)
     431                return;
     432
     433        uint8 *dst_pal = _offscreen_pal + ((y * _screenWidth) + x);
     434        uint16 *dst_hicol = _offscreen_hic + ((y * _screenWidth) + x);
     435
     436        do {
     437                for (int hor = 0; hor < w; hor++) {
     438                        if (dst_pal[hor] != buf[hor]) {
     439                                uint16 color = _screenPalette[buf[hor]];
     440                                dst_hicol[hor] = color;  // Save image converted to 16-bit
     441                                dst_pal[hor] = buf[hor]; // Save palettized display
     442                        }
     443                }
     444
     445                buf += pitch;
     446                dst_pal += _screenWidth;
     447                dst_hicol += _screenWidth;
     448        } while (--h);
     449
     450        _dirtyOffscreen = true;
     451
     452        return;
     453}
     454
     455void OSystem_N64::updateScreen() {
     456#ifdef LIMIT_FPS
     457        static uint32 _lastScreenUpdate = 0;
     458        uint32 now = getMillis();
     459        if (now - _lastScreenUpdate < 1000 / _maxFps)
     460                return;
     461
     462        _lastScreenUpdate = now;
     463#endif
     464
     465        // Check if audio buffer needs refill
     466        // Done here because this gets called regularly
     467        refillAudioBuffers();
     468
     469        if (!_dirtyOffscreen && !_dirtyPalette) return; // The offscreen is clean
     470
     471        uint8 skip_lines = (_screenHeight - _gameHeight) / 4;
     472        uint8 skip_pixels = (_screenWidth - _gameWidth) / 2; // Center horizontally the image
     473
     474        if (_dirtyPalette)
     475                rebuildOffscreenGameBuffer();
     476
     477        while (!(_dc = lockDisplay()));
     478
     479        uint16 *overlay_framebuffer = (uint16*)_dc->conf.framebuffer; // Current screen framebuffer
     480        uint16 *game_framebuffer = overlay_framebuffer + (_frameBufferWidth * skip_lines * 2); // Skip some lines to center the image vertically
     481
     482        uint16 currentHeight;
     483        uint16 *tmpDst;
     484        uint16 *tmpSrc;
     485
     486        // Copy the game buffer to screen
     487        if (!_overlayVisible) {
     488                tmpDst = game_framebuffer;
     489                tmpSrc = _offscreen_hic + (_shakeOffset * _screenWidth);
     490                for (currentHeight = _shakeOffset; currentHeight < _gameHeight; currentHeight++) {
     491                        memcpy((tmpDst + skip_pixels + _offscrPixels), tmpSrc, _screenWidth * 2);
     492                        tmpDst += _frameBufferWidth;
     493                        tmpSrc += _screenWidth;
     494                }
     495
     496                uint16 _clearLines = _shakeOffset; // When shaking we must take care of remaining lines to clear
     497                while (_clearLines--) {
     498                        memset(tmpDst + skip_pixels + _offscrPixels, 0, _screenWidth * 2);
     499                        tmpDst += _frameBufferWidth;
     500                }
     501        } else { // If the overlay is enabled, draw it on top of game screen
     502                tmpDst = overlay_framebuffer;
     503                tmpSrc = _overlayBuffer;
     504                for (currentHeight = 0; currentHeight < _overlayHeight; currentHeight++) {
     505                        memcpy((tmpDst + _offscrPixels), tmpSrc, _overlayWidth * 2);
     506                        tmpDst += _frameBufferWidth;
     507                        tmpSrc += _overlayWidth;
     508                }
     509        }
     510
     511        // Draw mouse cursor
     512        if ((_mouseVisible || _overlayVisible) && _cursorHeight > 0 && _cursorWidth > 0) {
     513                uint16 *mouse_framebuffer;
     514                uint16 horiz_pix_skip = 0;
     515
     516                if (_overlayVisible) {
     517                        mouse_framebuffer = overlay_framebuffer;
     518                } else {
     519                        mouse_framebuffer = game_framebuffer;
     520                        horiz_pix_skip = skip_pixels;
     521                }
     522
     523                int mX = _mouseX - _mouseHotspotX;
     524                int mY = _mouseY - _mouseHotspotY;
     525
     526                uint16 *_cursorSource = _cursorPaletteDisabled ? _screenPalette : _cursorPalette;
     527                for (int h = 0; h < _cursorHeight; h++)
     528                        for (int w = 0; w < _cursorWidth; w++) {
     529                                uint8 index = _cursor_pal[(h * _cursorWidth) + w];
     530
     531                                // Draw pixel
     532                                if ((index != _cursorKeycolor) && ((mY + h) >= 0) && ((mY + h) < _mouseMaxY) && ((mX + w) >= 0) && ((mX + w) < _mouseMaxX))
     533                                        mouse_framebuffer[((mY + h) * _frameBufferWidth) + ((mX + w) + _offscrPixels + horiz_pix_skip)] = _cursorSource[index];
     534                        }
     535        }
     536
     537#ifndef _ENABLE_DEBUG_
     538        showDisplay(_dc);
     539#else
     540        showDisplayAndText(_dc);
     541#endif
     542
     543        _dc = NULL;
     544        _dirtyOffscreen = false;
     545        _dirtyPalette = false;
     546
     547        return;
     548}
     549
     550Graphics::Surface *OSystem_N64::lockScreen() {
     551        _framebuffer.pixels = _offscreen_pal;
     552        _framebuffer.w = _gameWidth;
     553        _framebuffer.h = _gameHeight;
     554        _framebuffer.pitch = _screenWidth;
     555        _framebuffer.bytesPerPixel = 1;
     556
     557        return &_framebuffer;
     558}
     559
     560void OSystem_N64::unlockScreen() {
     561        _dirtyPalette = true;
     562        _dirtyOffscreen = true;
     563}
     564
     565void OSystem_N64::setShakePos(int shakeOffset) {
     566        _shakeOffset = shakeOffset;
     567        _dirtyOffscreen = true;
     568
     569        return;
     570}
     571
     572void OSystem_N64::showOverlay() {
     573        // Change min/max mouse coords
     574        _mouseMaxX = _overlayWidth;
     575        _mouseMaxY = _overlayHeight;
     576
     577        // Relocate the mouse cursor given the new limitations
     578        warpMouse(_mouseX, _mouseY);
     579
     580        _overlayVisible = true;
     581        _dirtyOffscreen = true;
     582}
     583
     584void OSystem_N64::hideOverlay() {
     585        // Change min/max mouse coords
     586        _mouseMaxX = _gameWidth;
     587        _mouseMaxY = _gameHeight;
     588
     589        // Relocate the mouse cursor given the new limitations
     590        warpMouse(_mouseX, _mouseY);
     591
     592        _overlayVisible = false;
     593
     594        // Clear double buffered display
     595        clearAllVideoBuffers();
     596
     597        _dirtyOffscreen = true;
     598}
     599
     600void OSystem_N64::clearOverlay() {
     601        memset(_overlayBuffer, 0, _overlayWidth * _overlayHeight * sizeof(OverlayColor));
     602
     603        uint8 skip_lines = (_screenHeight - _gameHeight) / 4;
     604        uint8 skip_pixels = (_screenWidth - _gameWidth) / 2; // Center horizontally the image
     605
     606        uint16 *tmpDst = _overlayBuffer + (_overlayWidth * skip_lines * 2);
     607        uint16 *tmpSrc = _offscreen_hic + (_shakeOffset * _screenWidth);
     608        for (uint16 currentHeight = _shakeOffset; currentHeight < _gameHeight; currentHeight++) {
     609                memcpy((tmpDst + skip_pixels), tmpSrc, _gameWidth * 2);
     610                tmpDst += _overlayWidth;
     611                tmpSrc += _screenWidth;
     612        }
     613
     614        _dirtyOffscreen = true;
     615}
     616
     617void OSystem_N64::grabOverlay(OverlayColor *buf, int pitch) {
     618        int h = _overlayHeight;
     619        OverlayColor *src = _overlayBuffer;
     620
     621        do {
     622                memcpy(buf, src, _overlayWidth * sizeof(OverlayColor));
     623                src += _overlayWidth;
     624                buf += pitch;
     625        } while (--h);
     626}
     627
     628void OSystem_N64::copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h) {
     629        //Clip the coordinates
     630        if (x < 0) {
     631                w += x;
     632                buf -= x;
     633                x = 0;
     634        }
     635
     636        if (y < 0) {
     637                h += y;
     638                buf -= y * pitch;
     639                y = 0;
     640        }
     641
     642        if (w > _overlayWidth - x) {
     643                w = _overlayWidth - x;
     644        }
     645
     646        if (h > _overlayHeight - y) {
     647                h = _overlayHeight - y;
     648        }
     649
     650        if (w <= 0 || h <= 0)
     651                return;
     652
     653
     654        OverlayColor *dst = _overlayBuffer + (y * _overlayWidth + x);
     655
     656        if (_overlayWidth == pitch && pitch == w) {
     657                memcpy(dst, buf, h * w * sizeof(OverlayColor));
     658        } else {
     659                do {
     660                        memcpy(dst, buf, w * sizeof(OverlayColor));
     661                        buf += pitch;
     662                        dst += _overlayWidth;
     663                } while (--h);
     664        }
     665
     666        _dirtyOffscreen = true;
     667
     668        return;
     669}
     670
     671int16 OSystem_N64::getOverlayHeight() {
     672        return _overlayHeight;
     673}
     674
     675int16 OSystem_N64::getOverlayWidth() {
     676        return _overlayWidth;
     677}
     678
     679
     680bool OSystem_N64::showMouse(bool visible) {
     681        bool last = _mouseVisible;
     682        _mouseVisible = visible;
     683
     684        _dirtyOffscreen = true;
     685
     686        return last;
     687}
     688
     689void OSystem_N64::warpMouse(int x, int y) {
     690
     691        if (x < 0)
     692                _mouseX = 0;
     693        else if (x >= _mouseMaxX)
     694                _mouseX = _mouseMaxX - 1;
     695        else
     696                _mouseX = x;
     697
     698        if (y < 0)
     699                _mouseY = 0;
     700        else if (y >= _mouseMaxY)
     701                _mouseY = _mouseMaxY - 1;
     702        else
     703                _mouseY = y;
     704
     705        _dirtyOffscreen = true;
     706}
     707
     708void OSystem_N64::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format) {
     709        if (!w || !h) return;
     710
     711        _mouseHotspotX = hotspotX;
     712        _mouseHotspotY = hotspotY;
     713
     714        if (_cursor_pal && ((w != _cursorWidth) || (h != _cursorHeight))) {
     715                free(_cursor_pal);
     716                _cursor_pal = NULL;
     717        }
     718
     719        if (!_cursor_pal) {
     720                _cursor_pal = (uint8*)malloc(w * h);
     721        }
     722
     723        _cursorWidth = w;
     724        _cursorHeight = h;
     725
     726        memcpy(_cursor_pal, buf, w * h); // Copy the palettized cursor
     727
     728        _cursorKeycolor = keycolor & 0xFF;
     729
     730        _dirtyOffscreen = true;
     731
     732        return;
     733}
     734
     735uint32 OSystem_N64::getMillis() {
     736        return getMilliTick();
     737}
     738
     739void OSystem_N64::delayMillis(uint msecs) {
     740        delay(msecs);
     741}
     742
     743OSystem::MutexRef OSystem_N64::createMutex(void) {
     744        return NULL;
     745}
     746
     747void OSystem_N64::lockMutex(MutexRef mutex) {
     748        return;
     749}
     750
     751void OSystem_N64::unlockMutex(MutexRef mutex) {
     752        return;
     753}
     754
     755void OSystem_N64::deleteMutex(MutexRef mutex) {
     756        return;
     757}
     758
     759void OSystem_N64::quit() {
     760        // Not much to do...
     761        return;
     762}
     763
     764Common::SaveFileManager *OSystem_N64::getSavefileManager() {
     765        assert(_savefile);
     766        return _savefile;
     767}
     768
     769Audio::Mixer *OSystem_N64::getMixer() {
     770        assert(_mixer);
     771        return _mixer;
     772}
     773
     774Common::TimerManager *OSystem_N64::getTimerManager() {
     775        assert(_timer);
     776        return _timer;
     777}
     778
     779void OSystem_N64::getTimeAndDate(TimeDate &t) const {
     780        // No clock inside the N64
     781        // TODO: use getMillis to provide some kind of time-counting feature?
     782        t.tm_sec  = 0;
     783        t.tm_min  = 0;
     784        t.tm_hour = 0;
     785        t.tm_mday = 0;
     786        t.tm_mon  = 0;
     787        t.tm_year = 0;
     788
     789        return;
     790}
     791
     792FilesystemFactory *OSystem_N64::getFilesystemFactory() {
     793        return _fsFactory;
     794}
     795
     796void OSystem_N64::setTimerCallback(TimerProc callback, int interval) {
     797        if (callback != NULL) {
     798                _timerCallbackTimer = interval;
     799                _timerCallbackNext = getMillis() + interval;
     800                _timerCallback = callback;
     801        } else
     802                _timerCallback = NULL;
     803}
     804
     805void OSystem_N64::setupMixer(void) {
     806        enableAudioPlayback();
     807}
     808
     809inline uint16 colBGR888toRGB555(byte r, byte g, byte b) {
     810        return ((r >> 3) << 1) | ((g >> 3) << 6) | ((b >> 3) << 11);
     811}
     812
  • 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 (newButtons != oldButtons) {
     75                if (DL_BUTTON(newButtons) && !DL_BUTTON(oldButtons)) // Pressed LEFT
     76                        left_digital = true;
     77                else if (!DL_BUTTON(newButtons) && DL_BUTTON(oldButtons)) // Released LEFT
     78                        left_digital = false;
     79
     80                if (DR_BUTTON(newButtons) && !DR_BUTTON(oldButtons)) // Pressed RIGHT
     81                        right_digital = true;
     82                else if (!DR_BUTTON(newButtons) && DR_BUTTON(oldButtons)) // Released RIGHT
     83                        right_digital = false;
     84
     85                if (DU_BUTTON(newButtons) && !DU_BUTTON(oldButtons)) // Pressed UP
     86                        up_digital = true;
     87                else if (!DU_BUTTON(newButtons) && DU_BUTTON(oldButtons)) // Released UP
     88                        up_digital = false;
     89
     90                if (DD_BUTTON(newButtons) && !DD_BUTTON(oldButtons)) // Pressed DOWN
     91                        down_digital = true;
     92                else if (!DD_BUTTON(newButtons) && DD_BUTTON(oldButtons)) // Released DOWN
     93                        down_digital = false;
     94
     95                if (B_BUTTON(newButtons) && !B_BUTTON(oldButtons)) { // Pressed B - Right Mouse Button
     96                        buttonPressed = true;
     97                        event.type = Common::EVENT_RBUTTONDOWN;
     98                } else if (!B_BUTTON(newButtons) && B_BUTTON(oldButtons)) { // Released B
     99                        buttonPressed = true;
     100                        event.type = Common::EVENT_RBUTTONUP;
     101                } else if (A_BUTTON(newButtons) && !A_BUTTON(oldButtons)) { // Pressed A - Period
     102                        buttonPressed = true;
     103                        event.kbd.keycode = Common::KEYCODE_PERIOD;
     104                        event.kbd.ascii = '.';
     105                        event.type = Common::EVENT_KEYDOWN;
     106                } else if (!A_BUTTON(newButtons) && A_BUTTON(oldButtons)) { // Released A
     107                        buttonPressed = true;
     108                        event.kbd.keycode = Common::KEYCODE_PERIOD;
     109                        event.kbd.ascii = '.';
     110                        event.type = Common::EVENT_KEYUP;
     111                } else if (START_BUTTON(newButtons) && !START_BUTTON(oldButtons)) { // Pressed START - F5
     112                        buttonPressed = true;
     113                        event.kbd.keycode = Common::KEYCODE_F5;
     114                        event.kbd.ascii = Common::ASCII_F5;
     115                        event.type = Common::EVENT_KEYDOWN;
     116                } else if (!START_BUTTON(newButtons) && START_BUTTON(oldButtons)) { // Released START
     117                        buttonPressed = true;
     118                        event.kbd.keycode = Common::KEYCODE_F5;
     119                        event.kbd.ascii = Common::ASCII_F5;
     120                        event.type = Common::EVENT_KEYUP;
     121                } else if (CU_BUTTON(newButtons) && !CU_BUTTON(oldButtons)) { // Pressed Yellow Up - UP
     122                        buttonPressed = true;
     123                        event.kbd.keycode = Common::KEYCODE_UP;
     124                        event.type = Common::EVENT_KEYDOWN;
     125                } else if (!CU_BUTTON(newButtons) && CU_BUTTON(oldButtons)) { // Released Yellow Up
     126                        buttonPressed = true;
     127                        event.kbd.keycode = Common::KEYCODE_UP;
     128                        event.type = Common::EVENT_KEYUP;
     129                } else if (CD_BUTTON(newButtons) && !CD_BUTTON(oldButtons)) { // Pressed Yellow Down - DOWN
     130                        buttonPressed = true;
     131                        event.kbd.keycode = Common::KEYCODE_DOWN;
     132                        event.type = Common::EVENT_KEYDOWN;
     133                } else if (!CD_BUTTON(newButtons) && CD_BUTTON(oldButtons)) { // Released Yellow Down
     134                        buttonPressed = true;
     135                        event.kbd.keycode = Common::KEYCODE_DOWN;
     136                        event.type = Common::EVENT_KEYUP;
     137                } else if (CL_BUTTON(newButtons) && !CL_BUTTON(oldButtons)) { // Pressed Yellow Left - LEFT
     138                        buttonPressed = true;
     139                        event.kbd.keycode = Common::KEYCODE_LEFT;
     140                        event.type = Common::EVENT_KEYDOWN;
     141                } else if (!CL_BUTTON(newButtons) && CL_BUTTON(oldButtons)) { // Released Yellow Left
     142                        buttonPressed = true;
     143                        event.kbd.keycode = Common::KEYCODE_LEFT;
     144                        event.type = Common::EVENT_KEYUP;
     145                } else if (CR_BUTTON(newButtons) && !CR_BUTTON(oldButtons)) { // Pressed Yellow Right - RIGHT
     146                        buttonPressed = true;
     147                        event.kbd.keycode = Common::KEYCODE_RIGHT;
     148                        event.type = Common::EVENT_KEYDOWN;
     149                } else if (!CR_BUTTON(newButtons) && CR_BUTTON(oldButtons)) { // Released Yellow Right
     150                        buttonPressed = true;
     151                        event.kbd.keycode = Common::KEYCODE_RIGHT;
     152                        event.type = Common::EVENT_KEYUP;
     153                } else if (TL_BUTTON(newButtons) && !TL_BUTTON(oldButtons)) { // Pressed Trigger Left - ESC
     154                        buttonPressed = true;
     155                        event.kbd.keycode = Common::KEYCODE_ESCAPE;
     156                        event.kbd.ascii = 27;
     157                        event.type = Common::EVENT_KEYDOWN;
     158                } else if (!TL_BUTTON(newButtons) && TL_BUTTON(oldButtons)) { // Released Trigger Left
     159                        buttonPressed = true;
     160                        event.kbd.keycode = Common::KEYCODE_ESCAPE;
     161                        event.kbd.ascii = 27;
     162                        event.type = Common::EVENT_KEYUP;
     163                } else if (TR_BUTTON(newButtons) && !TR_BUTTON(oldButtons)) { // Pressed Trigger Right - F7
     164                        buttonPressed = true;
     165                        event.kbd.keycode = Common::KEYCODE_F7;
     166                        event.kbd.ascii = Common::ASCII_F7;
     167                        event.type = Common::EVENT_KEYDOWN;
     168                } else if (!TR_BUTTON(newButtons) && TR_BUTTON(oldButtons)) { // Released Trigger Right
     169                        buttonPressed = true;
     170                        event.kbd.keycode = Common::KEYCODE_F7;
     171                        event.kbd.ascii = Common::ASCII_F7;
     172                        event.type = Common::EVENT_KEYUP;
     173                } else if (Z_BUTTON(newButtons) && !Z_BUTTON(oldButtons)) { // Pressed Z - Left Mouse Button
     174                        buttonPressed = true;
     175                        event.type = Common::EVENT_LBUTTONDOWN;
     176                } else if (!Z_BUTTON(newButtons) && Z_BUTTON(oldButtons)) { // Released Z
     177                        buttonPressed = true;
     178                        event.type = Common::EVENT_LBUTTONUP;
     179                }
     180
     181                oldButtons = newButtons; // Save current button status
     182
     183                if (buttonPressed) {
     184                        event.mouse.x = _mouseX;
     185                        event.mouse.y = _mouseY;
     186                        return true;
     187                }
     188        }
     189
     190        static uint32 _lastPadCheck = 0;
     191        uint32 curTime = getMillis();
     192
     193        if ((curTime - _lastPadCheck) > PAD_CHECK_TIME) {
     194                _lastPadCheck = curTime;
     195
     196                int32 mx = _mouseX;
     197                int32 my = _mouseY;
     198
     199                if (left_digital || right_digital || up_digital || down_digital) {
     200                        if (left_digital)
     201                                mx -= 5;
     202                        else if (right_digital)
     203                                mx += 5;
     204                        if (up_digital)
     205                                my -= 5;
     206                        else if (down_digital)
     207                                my += 5;
     208                }
     209
     210                if (abs(analogX) > PAD_DEADZONE)
     211                        mx += analogX / (PAD_ACCELERATION - (abs(analogX) / 20));
     212
     213                if (abs(analogY) > PAD_DEADZONE)
     214                        my -= analogY / (PAD_ACCELERATION - (abs(analogY) / 20));
     215
     216                if (mx < 0)
     217                        mx = 0;
     218
     219                if (mx >= _mouseMaxX)
     220                        mx = _mouseMaxX - 1;
     221
     222                if (my < 0)
     223                        my = 0;
     224
     225                if (my >= _mouseMaxY)
     226                        my = _mouseMaxY - 1;
     227
     228                if ((mx != _mouseX) || (my != _mouseY)) {
     229
     230                        event.type = Common::EVENT_MOUSEMOVE;
     231                        event.mouse.x = _mouseX = mx;
     232                        event.mouse.y = _mouseY = my;
     233
     234                        _dirtyOffscreen = true;
     235
     236                        return true;
     237                }
     238
     239        }
     240
     241        return false;
     242}
     243
  • 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 -O2 -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
     55#ENABLE_SCUMM=$(ENABLED)
     56#ENABLE_SKY=$(ENABLED)
     57#ENABLE_SCI=$(ENABLED)
     58#ENABLE_GOB=$(ENABLED)
     59#ENABLE_PARALLACTION=$(ENABLED)
     60ENABLE_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 \