Ticket #9123: svm-n64-patch-27122009-1.diff
File svm-n64-patch-27122009-1.diff, 66.5 KB (added by , 14 years ago) |
---|
-
common/scummsys.h
301 301 #define SCUMM_LITTLE_ENDIAN 302 302 #define SCUMM_NEED_ALIGNMENT 303 303 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 304 329 #elif defined(__PSP__) 305 330 306 331 #include <malloc.h> -
common/util.cpp
46 46 #define fputs(str, file) DS::std_fwrite(str, strlen(str), 1, file) 47 47 #endif 48 48 49 #ifdef __N64__ 50 #define fputs(str, file) asm("nop"); 51 #endif 49 52 50 53 namespace Common { 51 54 -
common/debug.cpp
45 45 #define fflush(file) DS::std_fflush(file) 46 46 #endif 47 47 48 #ifdef __N64__ 49 #include <n64utils.h> 48 50 51 #define fputs(str, file) asm("nop"); 52 #define fflush(a) asm("nop"); 53 #define OutputDebugString addLineTextLayer 54 #endif 49 55 56 50 57 // TODO: Move gDebugLevel into namespace Common. 51 58 int gDebugLevel = -1; 52 59 -
engines/scumm/saveload.cpp
163 163 memcpy(hdr.name, _saveLoadName, sizeof(hdr.name)); 164 164 saveSaveGameHeader(out, hdr); 165 165 } 166 #if !defined(__DS__) /* && !defined(__PLAYSTATION2__) */166 #if !defined(__DS__) && !defined(__N64__) /* && !defined(__PLAYSTATION2__) */ 167 167 Graphics::saveThumbnail(*out); 168 168 #endif 169 169 saveInfos(out); -
sound/softsynth/opl/mame.cpp
33 33 34 34 #include "mame.h" 35 35 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__) 37 37 #include "common/config-manager.h" 38 38 #endif 39 39 … … 1212 1212 // We need to emulate one YM3812 chip 1213 1213 int env_bits = FMOPL_ENV_BITS_HQ; 1214 1214 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__) 1216 1216 if (ConfMan.hasKey("FM_high_quality") && ConfMan.getBool("FM_high_quality")) { 1217 1217 env_bits = FMOPL_ENV_BITS_HQ; 1218 1218 eg_ent = FMOPL_EG_ENT_HQ; -
graphics/colormasks.h
117 117 kGreenBits = 5, 118 118 kBlueBits = 5, 119 119 120 #ifdef __N64__ 120 121 kAlphaShift = 0, 122 kRedShift = kBlueBits+kGreenBits+1, 123 kGreenShift = kBlueBits + 1, 124 kBlueShift = 1, 125 #else 126 kAlphaShift = 0, 121 127 kRedShift = kGreenBits+kBlueBits, 122 128 kGreenShift = kBlueBits, 123 129 kBlueShift = 0, 130 #endif 124 131 125 132 kAlphaMask = ((1 << kAlphaBits) - 1) << kAlphaShift, 126 133 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 32 extern uint8 _romfs; // Defined by linker (used to calculate position of romfs image) 33 34 inline uint16 colBGR888toRGB555(byte r, byte g, byte b); 35 36 static 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 46 OSystem_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 loadPakData(0); 62 63 // Screen size 64 _screenWidth = DEFAULT_SCREEN_WIDTH; 65 _screenHeight = DEFAULT_SCREEN_HEIGHT; 66 67 // Game screen size 68 _gameHeight = DEFAULT_SCREEN_WIDTH; 69 _gameWidth = DEFAULT_SCREEN_HEIGHT; 70 71 // Overlay size 72 _overlayWidth = DEFAULT_SCREEN_WIDTH; 73 _overlayHeight = DEFAULT_SCREEN_HEIGHT; 74 75 // Framebuffer width 76 _frameBufferWidth = DEFAULT_FRAMEBUFFER_WIDTH; 77 78 // Pixels to skip 79 _offscrPixels = DEFAULT_PIX_SKIP; 80 81 // Video clock 82 _viClockRate = VI_NTSC_CLOCK; 83 84 _maxFps = N64_NTSC_FPS; 85 86 _overlayVisible = false; 87 88 _shakeOffset = 0; 89 90 // Allocate memory for offscreen buffers 91 _offscreen_hic = (uint16*)memalign(8, DEFAULT_SCREEN_WIDTH * DEFAULT_SCREEN_HEIGHT * 2); 92 _offscreen_pal = (uint8*)memalign(8, DEFAULT_SCREEN_WIDTH * DEFAULT_SCREEN_HEIGHT); 93 _overlayBuffer = (uint16*)memalign(8, DEFAULT_SCREEN_WIDTH * DEFAULT_SCREEN_HEIGHT * sizeof(OverlayColor)); 94 95 _cursor_pal = NULL; 96 97 _cursorWidth = -1; 98 _cursorHeight = -1; 99 _cursorKeycolor = -1; 100 _mouseHotspotX = _mouseHotspotY = -1; 101 102 // Clean offscreen buffers 103 memset(_offscreen_hic, 0, _screenWidth * _screenHeight * 2); 104 memset(_offscreen_pal, 0, _screenWidth * _screenHeight); 105 memset(_overlayBuffer, 0, _overlayWidth * _overlayHeight * sizeof(OverlayColor)); 106 107 // Default graphic mode 108 _graphicMode = OVERS_NTSC_340X240; 109 110 // Clear palette array 111 _screenPalette = (uint16*)memalign(8, 256 * sizeof(uint16)); 112 memset(_screenPalette, 0, 256 * sizeof(uint16)); 113 memset(_cursorPalette, 0, 256 * sizeof(uint16)); 114 115 _dirtyPalette = false; 116 _cursorPaletteDisabled = false; 117 118 _audioEnabled = false; 119 120 // Initialize ROMFS access interface 121 initRomFSmanager((uint8*)(((uint32)&_romfs + (uint32)0xc00) | (uint32)0xB0000000)); 122 123 // Register vblank callback 124 registerVIhandler(vblCallback); 125 126 _mouseVisible = false; 127 128 _mouseX = _overlayWidth / 2; 129 _mouseY = _overlayHeight / 2; 130 _mouseMaxX = _overlayWidth; 131 _mouseMaxY = _overlayHeight; 132 133 _savefile = 0; 134 _mixer = 0; 135 _timer = 0; 136 137 _dirtyOffscreen = false; 138 139 _ctrlData = (controller_data_buttons*)memalign(8, sizeof(controller_data_buttons)); 140 141 _fsFactory = new N64FilesystemFactory(); 142 143 } 144 145 OSystem_N64::~OSystem_N64() { 146 delete _savefile; 147 delete _mixer; 148 delete _timer; 149 delete _fsFactory; 150 } 151 152 void OSystem_N64::initBackend() { 153 ConfMan.setInt("autosave_period", 0); 154 ConfMan.setBool("FM_high_quality", false); 155 ConfMan.setBool("FM_medium_quality", true); 156 ConfMan.set("gui_theme", "modern"); // In case of modern theme being present, use it. 157 158 _savefile = new PAKSaveManager(); 159 160 _mixer = new Audio::MixerImpl(this); 161 _mixer->setReady(false); 162 163 _timer = new DefaultTimerManager(); 164 165 setTimerCallback(&timer_handler, 10); 166 167 setupMixer(); 168 169 OSystem::initBackend(); 170 171 } 172 173 bool OSystem_N64::hasFeature(Feature f) { 174 return (f == kFeatureCursorHasPalette); 175 } 176 177 void OSystem_N64::setFeatureState(Feature f, bool enable) { 178 return; 179 } 180 181 bool OSystem_N64::getFeatureState(Feature f) { 182 return false; 183 } 184 185 const OSystem::GraphicsMode* OSystem_N64::getSupportedGraphicsModes() const { 186 return s_supportedGraphicsModes; 187 } 188 189 190 int OSystem_N64::getDefaultGraphicsMode() const { 191 return OVERS_NTSC_340X240; 192 } 193 194 bool OSystem_N64::setGraphicsMode(const char *mode) { 195 int i = 0; 196 197 while (s_supportedGraphicsModes[i].name) { 198 if (!strcmpi(s_supportedGraphicsModes[i].name, mode)) { 199 _graphicMode = s_supportedGraphicsModes[i].id; 200 201 switchGraphicModeId(_graphicMode); 202 203 return true; 204 } 205 i++; 206 } 207 208 return true; 209 } 210 211 bool OSystem_N64::setGraphicsMode(int mode) { 212 _graphicMode = mode; 213 switchGraphicModeId(_graphicMode); 214 215 return true; 216 } 217 218 void OSystem_N64::switchGraphicModeId(int mode) { 219 switch (mode) { 220 case NORM_PAL_320X240: 221 disableAudioPlayback(); 222 _viClockRate = VI_PAL_CLOCK; 223 _maxFps = N64_PAL_FPS; 224 initDisplay(PAL_320X240_16BIT); 225 _frameBufferWidth = 320; 226 _screenWidth = DEFAULT_SCREEN_WIDTH; 227 _screenHeight = DEFAULT_SCREEN_HEIGHT; 228 _offscrPixels = 0; 229 _graphicMode = NORM_PAL_320X240; 230 enableAudioPlayback(); 231 break; 232 233 case OVERS_PAL_340X240: 234 disableAudioPlayback(); 235 _viClockRate = VI_PAL_CLOCK; 236 _maxFps = N64_PAL_FPS; 237 initDisplay(PAL_340X240_16BIT); 238 _frameBufferWidth = DEFAULT_FRAMEBUFFER_WIDTH; 239 _screenWidth = DEFAULT_SCREEN_WIDTH; 240 _screenHeight = DEFAULT_SCREEN_HEIGHT; 241 _offscrPixels = DEFAULT_PIX_SKIP; 242 _graphicMode = OVERS_PAL_340X240; 243 enableAudioPlayback(); 244 break; 245 246 case NORM_MPAL_320X240: 247 disableAudioPlayback(); 248 _viClockRate = VI_MPAL_CLOCK; 249 _maxFps = N64_NTSC_FPS; 250 initDisplay(MPAL_320X240_16BIT); 251 _frameBufferWidth = 320; 252 _screenWidth = DEFAULT_SCREEN_WIDTH; 253 _screenHeight = DEFAULT_SCREEN_HEIGHT; 254 _offscrPixels = 0; 255 _graphicMode = NORM_MPAL_320X240; 256 enableAudioPlayback(); 257 break; 258 259 case OVERS_MPAL_340X240: 260 disableAudioPlayback(); 261 _viClockRate = VI_MPAL_CLOCK; 262 _maxFps = N64_NTSC_FPS; 263 initDisplay(MPAL_340X240_16BIT); 264 _frameBufferWidth = DEFAULT_FRAMEBUFFER_WIDTH; 265 _screenWidth = DEFAULT_SCREEN_WIDTH; 266 _screenHeight = DEFAULT_SCREEN_HEIGHT; 267 _offscrPixels = DEFAULT_PIX_SKIP; 268 _graphicMode = OVERS_MPAL_340X240; 269 enableAudioPlayback(); 270 break; 271 272 case NORM_NTSC_320X240: 273 disableAudioPlayback(); 274 _viClockRate = VI_NTSC_CLOCK; 275 _maxFps = N64_NTSC_FPS; 276 initDisplay(NTSC_320X240_16BIT); 277 _frameBufferWidth = 320; 278 _screenWidth = DEFAULT_SCREEN_WIDTH; 279 _screenHeight = DEFAULT_SCREEN_HEIGHT; 280 _offscrPixels = 0; 281 _graphicMode = NORM_NTSC_320X240; 282 enableAudioPlayback(); 283 break; 284 285 case OVERS_NTSC_340X240: 286 default: 287 disableAudioPlayback(); 288 _viClockRate = VI_NTSC_CLOCK; 289 _maxFps = N64_NTSC_FPS; 290 initDisplay(NTSC_340X240_16BIT); 291 _frameBufferWidth = DEFAULT_FRAMEBUFFER_WIDTH; 292 _screenWidth = DEFAULT_SCREEN_WIDTH; 293 _screenHeight = DEFAULT_SCREEN_HEIGHT; 294 _offscrPixels = DEFAULT_PIX_SKIP; 295 _graphicMode = OVERS_NTSC_340X240; 296 enableAudioPlayback(); 297 break; 298 } 299 } 300 301 int OSystem_N64::getGraphicsMode() const { 302 return _graphicMode; 303 } 304 305 void OSystem_N64::initSize(uint width, uint height, const Graphics::PixelFormat *format) { 306 _gameWidth = width; 307 _gameHeight = height; 308 309 if (_gameWidth > _screenWidth) 310 _gameWidth = _screenWidth; 311 if (_gameHeight > _screenHeight) 312 _gameHeight = _screenHeight; 313 314 _mouseMaxX = _gameWidth; 315 _mouseMaxY = _gameHeight; 316 } 317 318 int16 OSystem_N64::getHeight() { 319 return _screenHeight; 320 } 321 322 int16 OSystem_N64::getWidth() { 323 return _screenWidth; 324 } 325 326 void OSystem_N64::setPalette(const byte *colors, uint start, uint num) { 327 for (int i = 0; i < num; ++i) { 328 uint8 c[4]; 329 _screenPalette[start + i] = colBGR888toRGB555(colors[2], colors[1], colors[0]); 330 colors += 4; 331 } 332 333 _dirtyPalette = true; 334 _dirtyOffscreen = true; 335 } 336 337 void OSystem_N64::rebuildOffscreenGameBuffer(void) { 338 // Regenerate hi-color offscreen buffer 339 #if 0 340 for (int h = 0; h < _gameHeight; h++) 341 for (int w = 0; w < _gameWidth; w++) { 342 uint8 color = _offscreen_pal[(h * _screenWidth) + w]; 343 _offscreen_hic[(h * _screenWidth) + w] = _screenPalette[color]; 344 } 345 #else 346 uint32 two_col_hi; 347 uint32 four_col_pal; 348 for (int h = 0; h < _gameHeight; h++) 349 for (int w = 0; w < _gameWidth; w += 4) { 350 four_col_pal = *(uint32*)(_offscreen_pal + ((h * _screenWidth) + w)); 351 352 two_col_hi = 0; 353 two_col_hi = _screenPalette[((four_col_pal >> (8 * 3)) & 0xFF)] | (two_col_hi << (16 * 0)); 354 two_col_hi = _screenPalette[((four_col_pal >> (8 * 2)) & 0xFF)] | (two_col_hi << (16 * 1)); 355 356 *(uint32*)(_offscreen_hic + (h * _screenWidth) + w + 0) = two_col_hi; 357 358 two_col_hi = 0; 359 two_col_hi = _screenPalette[((four_col_pal >> (8 * 1)) & 0xFF)] | (two_col_hi << (16 * 0)); 360 two_col_hi = _screenPalette[((four_col_pal >> (8 * 0)) & 0xFF)] | (two_col_hi << (16 * 1)); 361 362 *(uint32*)(_offscreen_hic + (h * _screenWidth) + w + 2) = two_col_hi; 363 } 364 #endif 365 } 366 367 void OSystem_N64::grabPalette(byte *colors, uint start, uint num) { 368 uint32 i; 369 uint16 color; 370 371 for (i = start; i < start + num; i++) { 372 color = _screenPalette[i]; 373 374 // Color format on the n64 is RGB - 1555 375 *colors++ = ((color & 0x1F) << 3); 376 *colors++ = (((color >> 5) & 0x1F) << 3); 377 *colors++ = (((color >> 10) & 0x1F) << 3); 378 *colors++ = 0; 379 } 380 381 return; 382 } 383 384 void OSystem_N64::setCursorPalette(const byte *colors, uint start, uint num) { 385 for (int i = 0; i < num; ++i) { 386 _cursorPalette[start + i] = colBGR888toRGB555(colors[2], colors[1], colors[0]); 387 colors += 4; 388 } 389 390 _cursorPaletteDisabled = false; 391 _dirtyOffscreen = true; 392 } 393 394 void OSystem_N64::disableCursorPalette(bool disable) { 395 _cursorPaletteDisabled = disable; 396 397 _dirtyOffscreen = true; 398 } 399 400 void OSystem_N64::copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h) { 401 //Clip the coordinates 402 if (x < 0) { 403 w += x; 404 buf -= x; 405 x = 0; 406 } 407 408 if (y < 0) { 409 h += y; 410 buf -= y * pitch; 411 y = 0; 412 } 413 414 if (w > _screenWidth - x) { 415 w = _screenWidth - x; 416 } 417 418 if (h > _screenHeight - y) { 419 h = _screenHeight - y; 420 } 421 422 if (w <= 0 || h <= 0) 423 return; 424 425 uint8 *dst_pal = _offscreen_pal + ((y * _screenWidth) + x); 426 uint16 *dst_hicol = _offscreen_hic + ((y * _screenWidth) + x); 427 428 do { 429 for (int hor = 0; hor < w; hor++) { 430 if (dst_pal[hor] != buf[hor]) { 431 uint16 color = _screenPalette[buf[hor]]; 432 dst_hicol[hor] = color; // Save image converted to 16-bit 433 dst_pal[hor] = buf[hor]; // Save palettized display 434 } 435 } 436 437 buf += pitch; 438 dst_pal += _screenWidth; 439 dst_hicol += _screenWidth; 440 } while (--h); 441 442 _dirtyOffscreen = true; 443 444 return; 445 } 446 447 void OSystem_N64::updateScreen() { 448 // Check if audio buffer needs refill 449 // Done here because this gets called regularly 450 refillAudioBuffers(); 451 452 #ifdef LIMIT_FPS 453 static uint32 _lastScreenUpdate = 0; 454 uint32 now = getMillis(); 455 if (now - _lastScreenUpdate < 1000 / _maxFps) 456 return; 457 458 _lastScreenUpdate = now; 459 #endif 460 461 if (!_dirtyOffscreen && !_dirtyPalette) return; // The offscreen is clean 462 463 uint8 skip_lines = (_screenHeight - _gameHeight) / 4; 464 uint8 skip_pixels = (_screenWidth - _gameWidth) / 2; // Center horizontally the image 465 466 if (_dirtyPalette) { 467 rebuildOffscreenGameBuffer(); 468 _dirtyPalette = false; 469 } 470 471 while (!(_dc = lockDisplay())); 472 473 uint16 *overlay_framebuffer = (uint16*)_dc->conf.framebuffer; // Current screen framebuffer 474 uint16 *game_framebuffer = overlay_framebuffer + (_frameBufferWidth * skip_lines * 2); // Skip some lines to center the image vertically 475 476 uint16 currentHeight; 477 uint16 *tmpDst; 478 uint16 *tmpSrc; 479 480 // Copy the game buffer to screen 481 if (!_overlayVisible) { 482 tmpDst = game_framebuffer; 483 tmpSrc = _offscreen_hic + (_shakeOffset * _screenWidth); 484 for (currentHeight = _shakeOffset; currentHeight < _gameHeight; currentHeight++) { 485 memcpy((tmpDst + skip_pixels + _offscrPixels), tmpSrc, _screenWidth * 2); 486 tmpDst += _frameBufferWidth; 487 tmpSrc += _screenWidth; 488 } 489 490 Uint16 _clearLines = _shakeOffset; // When shaking we must take care of remaining lines to clear 491 while (_clearLines--) { 492 memset(tmpDst + skip_pixels + _offscrPixels, 0, _screenWidth * 2); 493 tmpDst += _frameBufferWidth; 494 } 495 } 496 497 // If the overlay is enabled, draw it on top of game screen 498 if (_overlayVisible) { 499 tmpDst = overlay_framebuffer; 500 tmpSrc = _overlayBuffer; 501 for (currentHeight = 0; currentHeight < _overlayHeight; currentHeight++) { 502 memcpy((tmpDst + _offscrPixels), tmpSrc, _overlayWidth * 2); 503 tmpDst += _frameBufferWidth; 504 tmpSrc += _overlayWidth; 505 } 506 } 507 508 // Draw mouse cursor 509 if ((_mouseVisible || _overlayVisible) && _cursorHeight > 0 && _cursorWidth > 0) { 510 uint16 *mouse_framebuffer; 511 uint16 horiz_pix_skip = 0; 512 513 if (_overlayVisible) { 514 mouse_framebuffer = overlay_framebuffer; 515 } else { 516 mouse_framebuffer = game_framebuffer; 517 horiz_pix_skip = skip_pixels; 518 } 519 520 int mX = _mouseX - _mouseHotspotX; 521 int mY = _mouseY - _mouseHotspotY; 522 523 for (int h = 0; h < _cursorHeight; h++) 524 for (int w = 0; w < _cursorWidth; w++) { 525 uint16 color; 526 uint8 index = _cursor_pal[(h * _cursorWidth) + w]; 527 528 // Read palette color 529 if (!_cursorPaletteDisabled) 530 color = _cursorPalette[index]; 531 else 532 color = _screenPalette[index]; 533 534 if ((index != _cursorKeycolor) && ((mY + h) >= 0) && ((mY + h) < _mouseMaxY) && ((mX + w) >= 0) && ((mX + w) < _mouseMaxX)) 535 mouse_framebuffer[((mY + h) * _frameBufferWidth) + ((mX + w) + _offscrPixels + horiz_pix_skip)] = color; 536 } 537 } 538 539 #ifndef _ENABLE_DEBUG_ 540 showDisplay(_dc); 541 #else 542 showDisplayAndText(_dc); 543 #endif 544 545 _dc = NULL; 546 _dirtyOffscreen = false; 547 548 return; 549 } 550 551 Graphics::Surface *OSystem_N64::lockScreen() { 552 _framebuffer.pixels = _offscreen_pal; 553 _framebuffer.w = _gameWidth; 554 _framebuffer.h = _gameHeight; 555 _framebuffer.pitch = _screenWidth; 556 _framebuffer.bytesPerPixel = 1; 557 558 return &_framebuffer; 559 } 560 561 void OSystem_N64::unlockScreen() { 562 _dirtyPalette = true; 563 _dirtyOffscreen = true; 564 } 565 566 void OSystem_N64::setShakePos(int shakeOffset) { 567 _shakeOffset = shakeOffset; 568 _dirtyOffscreen = true; 569 570 return; 571 } 572 573 void OSystem_N64::showOverlay() { 574 // Change min/max mouse coords 575 _mouseMaxX = _overlayWidth; 576 _mouseMaxY = _overlayHeight; 577 578 // Relocate the mouse cursor given the new limitations 579 warpMouse(_mouseX, _mouseY); 580 581 _overlayVisible = true; 582 _dirtyOffscreen = true; 583 } 584 585 void OSystem_N64::hideOverlay() { 586 // Change min/max mouse coords 587 _mouseMaxX = _gameWidth; 588 _mouseMaxY = _gameHeight; 589 590 // Relocate the mouse cursor given the new limitations 591 warpMouse(_mouseX, _mouseY); 592 593 _overlayVisible = false; 594 595 // Clear double buffered display 596 clearAllVideoBuffers(); 597 598 _dirtyOffscreen = true; 599 } 600 601 void OSystem_N64::clearOverlay() { 602 memset(_overlayBuffer, 0, _overlayWidth * _overlayHeight * sizeof(OverlayColor)); 603 604 uint8 skip_lines = (_screenHeight - _gameHeight) / 4; 605 uint8 skip_pixels = (_screenWidth - _gameWidth) / 2; // Center horizontally the image 606 607 uint16 *tmpDst = _overlayBuffer + (_overlayWidth * skip_lines * 2); 608 uint16 *tmpSrc = _offscreen_hic + (_shakeOffset * _screenWidth); 609 for (uint16 currentHeight = _shakeOffset; currentHeight < _gameHeight; currentHeight++) { 610 memcpy((tmpDst + skip_pixels), tmpSrc, _gameWidth * 2); 611 tmpDst += _overlayWidth; 612 tmpSrc += _screenWidth; 613 } 614 615 _dirtyOffscreen = true; 616 } 617 618 void OSystem_N64::grabOverlay(OverlayColor *buf, int pitch) { 619 int h = _overlayHeight; 620 OverlayColor *src = _overlayBuffer; 621 622 do { 623 memcpy(buf, src, _overlayWidth * sizeof(OverlayColor)); 624 src += _overlayWidth; 625 buf += pitch; 626 } while (--h); 627 } 628 629 void OSystem_N64::copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h) { 630 //Clip the coordinates 631 if (x < 0) { 632 w += x; 633 buf -= x; 634 x = 0; 635 } 636 637 if (y < 0) { 638 h += y; 639 buf -= y * pitch; 640 y = 0; 641 } 642 643 if (w > _overlayWidth - x) { 644 w = _overlayWidth - x; 645 } 646 647 if (h > _overlayHeight - y) { 648 h = _overlayHeight - y; 649 } 650 651 if (w <= 0 || h <= 0) 652 return; 653 654 655 OverlayColor *dst = _overlayBuffer + (y * _overlayWidth + x); 656 657 if (_overlayWidth == pitch && pitch == w) { 658 memcpy(dst, buf, h * w * sizeof(OverlayColor)); 659 } else { 660 do { 661 memcpy(dst, buf, w * sizeof(OverlayColor)); 662 buf += pitch; 663 dst += _overlayWidth; 664 } while (--h); 665 } 666 667 _dirtyOffscreen = true; 668 669 return; 670 } 671 672 int16 OSystem_N64::getOverlayHeight() { 673 return _overlayHeight; 674 } 675 676 int16 OSystem_N64::getOverlayWidth() { 677 return _overlayWidth; 678 } 679 680 681 bool OSystem_N64::showMouse(bool visible) { 682 bool last = _mouseVisible; 683 _mouseVisible = visible; 684 685 _dirtyOffscreen = true; 686 687 return last; 688 } 689 690 void OSystem_N64::warpMouse(int x, int y) { 691 692 if (x < 0) 693 _mouseX = 0; 694 else if (x >= _mouseMaxX) 695 _mouseX = _mouseMaxX - 1; 696 else 697 _mouseX = x; 698 699 if (y < 0) 700 _mouseY = 0; 701 else if (y >= _mouseMaxY) 702 _mouseY = _mouseMaxY - 1; 703 else 704 _mouseY = y; 705 706 _dirtyOffscreen = true; 707 } 708 709 void OSystem_N64::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format) { 710 if (!w || !h) return; 711 712 _mouseHotspotX = hotspotX; 713 _mouseHotspotY = hotspotY; 714 715 if (_cursor_pal && ((w != _cursorWidth) || (h != _cursorHeight))) { 716 free(_cursor_pal); 717 _cursor_pal = NULL; 718 } 719 720 if (!_cursor_pal) { 721 _cursor_pal = (uint8*)malloc(w * h); 722 } 723 724 _cursorWidth = w; 725 _cursorHeight = h; 726 727 memcpy(_cursor_pal, buf, w * h); // Copy the palettized cursor 728 729 _cursorKeycolor = keycolor & 0xFF; 730 731 _dirtyOffscreen = true; 732 733 return; 734 } 735 736 uint32 OSystem_N64::getMillis() { 737 return getMilliTick(); 738 } 739 740 void OSystem_N64::delayMillis(uint msecs) { 741 delay(msecs); 742 } 743 744 OSystem::MutexRef OSystem_N64::createMutex(void) { 745 return NULL; 746 } 747 748 void OSystem_N64::lockMutex(MutexRef mutex) { 749 return; 750 } 751 752 void OSystem_N64::unlockMutex(MutexRef mutex) { 753 return; 754 } 755 756 void OSystem_N64::deleteMutex(MutexRef mutex) { 757 return; 758 } 759 760 void OSystem_N64::quit() { 761 // Not much to do... 762 return; 763 } 764 765 Common::SaveFileManager *OSystem_N64::getSavefileManager() { 766 assert(_savefile); 767 return _savefile; 768 } 769 770 Audio::Mixer *OSystem_N64::getMixer() { 771 assert(_mixer); 772 return _mixer; 773 } 774 775 Common::TimerManager *OSystem_N64::getTimerManager() { 776 assert(_timer); 777 return _timer; 778 } 779 780 void OSystem_N64::getTimeAndDate(TimeDate &t) const { 781 // No clock inside the N64 782 // TODO: use getMillis to provide some kind of time-counting feature? 783 t.tm_sec = 0; 784 t.tm_min = 0; 785 t.tm_hour = 0; 786 t.tm_mday = 0; 787 t.tm_mon = 0; 788 t.tm_year = 0; 789 790 return; 791 } 792 793 FilesystemFactory *OSystem_N64::getFilesystemFactory() { 794 return _fsFactory; 795 } 796 797 void OSystem_N64::setTimerCallback(TimerProc callback, int interval) { 798 if (callback != NULL) { 799 _timerCallbackTimer = interval; 800 _timerCallbackNext = getMillis() + interval; 801 _timerCallback = callback; 802 } else 803 _timerCallback = NULL; 804 } 805 806 void OSystem_N64::setupMixer(void) { 807 enableAudioPlayback(); 808 } 809 810 inline uint16 colBGR888toRGB555(byte r, byte g, byte b) { 811 return ((r >> 3) << 1) | ((g >> 3) << 6) | ((b >> 3) << 11); 812 } 813 -
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 26 void 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 38 void 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 49 void 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 86 static volatile Uint32 _requiredSoundSlots = 0; 87 88 void 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 102 void sndCallback() { 103 // Signal that an audio buffer finished playing and that we need more samples 104 if (_requiredSoundSlots < 2) 105 _requiredSoundSlots++; 106 } 107 108 void 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 126 int 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 31 bool deleteSaveGame(const char *filename); 32 33 class InPAKSave : public Common::InSaveFile { 34 private: 35 PAKFILE *fd; 36 37 uint32 read(void *buf, uint32 cnt); 38 bool skip(uint32 offset); 39 bool seek(int32 offs, int whence); 40 41 public: 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 68 class OutPAKSave : public Common::OutSaveFile { 69 private: 70 PAKFILE *fd; 71 72 public: 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 98 class PAKSaveManager : public Common::SaveFileManager { 99 public: 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 26 int 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 52 bool 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 56 typedef int (*TimerProc)(int interval); 57 58 // Interrupt callback functions 59 void vblCallback(void); 60 void sndCallback(void); 61 void refillAudioBuffers(void); 62 63 // External utility functions 64 void enableAudioPlayback(void); 65 void disableAudioPlayback(void); 66 void checkTimers(void); 67 int timer_handler(int t); 68 69 static volatile bool _audioEnabled = false; // Used by interrupt callbacks 70 71 /* Graphic mode identifiers */ 72 enum 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 81 class OSystem_N64 : public BaseBackend { 82 protected: 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 127 public: 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 3 TARGET="scummvm" 4 BASESIZE=2097152 5 6 CARTSIZE=`ls -l $TARGET.v64 | cut -d" " -f5` 7 8 REMAINDER=`echo $CARTSIZE % $BASESIZE | bc` 9 REMAINDER=`echo $BASESIZE - $REMAINDER | bc` 10 CARTSIZE=`echo $CARTSIZE + $REMAINDER | bc` 11 12 ucon64 -q --n64 --v64 --chk --padn=$CARTSIZE $TARGET.v64 13 -
backends/platform/n64/module.mk
1 MODULE := backends/platform/n64 2 3 MODULE_OBJS := \ 4 nintendo64.o 5 6 MODULE_DIRS += \ 7 backends/platform/n64/ 8 9 # We don't use the rules.mk here on purpose 10 OBJS := $(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 2 TOOLPATH = /opt/mips64-toolchain 3 LIBN64PATH = $(TOOLPATH)/hkz-libn64/ 4 GCCN64PREFIX = $(TOOLPATH)/bin/mips64- 5 6 srcdir = ../../.. 7 VPATH = $(srcdir) 8 9 CC = $(GCCN64PREFIX)gcc 10 CXX = $(GCCN64PREFIX)g++ 11 AS = $(GCCN64PREFIX)as 12 LD = $(GCCN64PREFIX)g++ 13 OBJCOPY = $(GCCN64PREFIX)objcopy 14 AR = $(GCCN64PREFIX)ar cru 15 RANLIB = $(GCCN64PREFIX)ranlib 16 17 DEFINES += -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 18 LIBS += -lpakfs -ln64 -ln64utils -lromfs 19 20 DEFINES += -D_ENABLE_DEBUG_ 21 22 USE_LIBMAD=0 23 USE_LIBOGG=1 24 25 ifeq ($(USE_LIBMAD),1) 26 DEFINES += -DUSE_MAD 27 LIBS += -lmad 28 endif 29 ifeq ($(USE_LIBOGG), 1) 30 DEFINES += -DUSE_VORBIS -DUSE_TREMOR 31 LIBS += -lvorbisidec 32 endif 33 34 LIBS += -lm -lstdc++ -lc -lgcc -lz -lnosys 35 36 CXXFLAGS = -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 37 LDFLAGS = -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 39 TARGET = scummvm 40 DEPDIR = .deps 41 CXX_UPDATE_DEP_FLAG = -Wp,-MMD,"$(*D)/$(DEPDIR)/$(*F).d",-MQ,"$@",-MP 42 MKDIR = mkdir -p 43 RM = rm -f 44 RM_REC = rm -rf 45 46 VERBOSE_BUILD=0 47 HAVE_GCC3=1 48 DISABLE_SCALERS=1 49 DISABLE_HQ_SCALER=1 50 USE_MT32EMU=0 51 USE_RGB_COLOR=0 52 53 ENABLED=STATIC_PLUGIN 54 55 ENABLE_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 63 OBJS := nintendo64.o osys_n64_base.o osys_n64_events.o osys_n64_utilities.o pakfs_save_manager.o 64 65 include $(srcdir)/Makefile.common 66 67 MODULE_DIRS += ./ 68 69 all: $(TARGET).v64 70 71 $(TARGET).v64: $(TARGET).bin ROMFS.img bootcode 72 cat bootcode $(TARGET).bin ROMFS.img > $(TARGET).v64 73 ./pad_rom.sh 74 75 ROMFS.img: 76 genromfs -f ./ROMFS.img -d ./ROMFS -V romtest 77 78 $(TARGET).elf: $(OBJS) 79 $(LD) -o $(TARGET).elf $(OBJS) $(LDFLAGS) 80 81 $(TARGET).bin : $(TARGET).elf 82 $(OBJCOPY) $(TARGET).elf $(TARGET).bin -O binary 83 84 spotless : distclean 85 $(RM) *.bin *.elf *.v64 *.img *.bak *.tmp *.map 86 87 send: $(TARGET).v64 88 sudo ucon64 --xv64 $(TARGET).v64 89 -
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 26 static bool matches(const char *glob, const char *name); 27 28 bool deleteSaveGame(const char *filename) { 29 int res = removeFileOnPak(filename); 30 flushCurrentPakData(); 31 32 return (res == 0); 33 } 34 35 uint32 InPAKSave::read(void *buf, uint32 cnt) { 36 return pakfs_read(buf, 1, cnt, fd); 37 } 38 39 bool InPAKSave::seek(int32 offs, int whence) { 40 pakfs_seek(fd, offs, whence); 41 42 return true; 43 } 44 45 bool InPAKSave::skip(uint32 offset) { 46 pakfs_seek(fd, offset, SEEK_CUR); 47 48 return true; 49 } 50 51 uint32 OutPAKSave::write(const void *buf, uint32 cnt) { 52 return pakfs_write(buf, 1, cnt, fd); 53 } 54 55 Common::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 72 static 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
25 25 26 26 #include "backends/fs/stdiostream.h" 27 27 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 28 50 StdioStream::StdioStream(void *handle) : _handle(handle) { 29 51 assert(handle); 30 52 } -
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 32 AbstractFSNode *N64FilesystemFactory::makeRootFileNode() const { 33 return new N64FilesystemNode(); 34 } 35 36 AbstractFSNode *N64FilesystemFactory::makeCurrentDirectoryFileNode() const { 37 char buf[MAXPATHLEN]; 38 return romfs_getcwd(buf, MAXPATHLEN) ? new N64FilesystemNode(Common::String(buf), false) : NULL; 39 } 40 41 AbstractFSNode *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 */ 36 class 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 */ 41 class N64FilesystemNode : public AbstractFSNode { 42 protected: 43 Common::String _displayName; 44 Common::String _path; 45 bool _isDirectory; 46 bool _isValid; 47 48 public: 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 86 N64FilesystemNode::N64FilesystemNode() { 87 _isDirectory = true; 88 _displayName = "Root"; 89 _isValid = true; 90 _path = ROOT_PATH; 91 } 92 93 N64FilesystemNode::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 109 bool N64FilesystemNode::exists() const { 110 int ret = -1; 111 112 ret = romfs_access(_path.c_str(), F_OK); 113 114 return ret == 0; 115 } 116 117 bool 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! 126 bool N64FilesystemNode::isWritable() const { 127 return false; 128 } 129 130 131 AbstractFSNode *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 144 bool 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 194 AbstractFSNode *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 204 Common::SeekableReadStream *N64FilesystemNode::createReadStream() { 205 return StdioStream::makeFromPath(getPath(), false); 206 } 207 208 Common::WriteStream *N64FilesystemNode::createWriteStream() { 209 return StdioStream::makeFromPath(getPath(), true); 210 } 211 212 #endif //#ifdef __N64__ 213 -
backends/module.mk
15 15 fs/symbian/symbian-fs-factory.o \ 16 16 fs/windows/windows-fs-factory.o \ 17 17 fs/wii/wii-fs-factory.o \ 18 fs/n64/n64-fs-factory.o \ 18 19 keymapper/action.o \ 19 20 keymapper/keymap.o \ 20 21 keymapper/keymapper.o \