diff options
Diffstat (limited to 'backends/platform/ds/arm9/source/dsmain.cpp')
-rw-r--r-- | backends/platform/ds/arm9/source/dsmain.cpp | 616 |
1 files changed, 308 insertions, 308 deletions
diff --git a/backends/platform/ds/arm9/source/dsmain.cpp b/backends/platform/ds/arm9/source/dsmain.cpp index 458cfe7923..492b7384ec 100644 --- a/backends/platform/ds/arm9/source/dsmain.cpp +++ b/backends/platform/ds/arm9/source/dsmain.cpp @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ - + // - Remove scummconsole.c // - Delete files @@ -244,8 +244,8 @@ bool cpuScalerEnable = false; // 150 192 // 200 128 - // (256 << 8) / scale - + // (256 << 8) / scale + #ifdef USE_PROFILER @@ -259,7 +259,7 @@ u8* scalerBackBuffer = NULL; gameListType gameList[NUM_SUPPORTED_GAMES] = { // Unknown game - use normal SCUMM controls {"unknown", CONT_SCUMM_ORIGINAL}, - + // SCUMM games {"maniac", CONT_SCUMM_ORIGINAL}, {"zak", CONT_SCUMM_ORIGINAL}, @@ -270,7 +270,7 @@ gameListType gameList[NUM_SUPPORTED_GAMES] = { {"monkey2", CONT_SCUMM_ORIGINAL}, {"tentacle", CONT_SCUMM_ORIGINAL}, {"samnmax", CONT_SCUMM_SAMNMAX}, - + // Non-SCUMM games {"sky", CONT_SKY}, {"simon1", CONT_SIMON}, @@ -356,8 +356,8 @@ void setTopScreenZoom(int percentage) { // 150 192 // 200 128 - // (256 << 8) / scale - + // (256 << 8) / scale + s32 scale = (percentage << 8) / 100; subScreenScale = (256 * 256) / scale; @@ -374,11 +374,11 @@ controlType getControlType() { //plays an 8 bit mono sample at 11025Hz void playSound(const void* data, u32 length, bool loop, bool adpcm, int rate) { - + if (!IPC->soundData) { soundControl.count = 0; } - + soundControl.data[soundControl.count].data = data; soundControl.data[soundControl.count].len = length | (loop? 0x80000000: 0x00000000); soundControl.data[soundControl.count].rate = rate; // 367 samples per frame @@ -428,14 +428,14 @@ void initSprites() { sprites[i].attribute[2] = 0; sprites[i].filler = 0; } - + for (int i = 0; i < 128; i++) { spritesMain[i].attribute[0] = ATTR0_DISABLED; spritesMain[i].attribute[1] = 0; spritesMain[i].attribute[2] = 0; spritesMain[i].filler = 0; } - + updateOAM(); } @@ -446,7 +446,7 @@ void saveGameBackBuffer() { // So, I lock the video memory here, as if I'm going to modify it. This // forces OSystem_DS to create a system memory copy if one doesn't exist. // This will be automatially resotred by OSystem_DS::updateScreen(). - + OSystem_DS::instance()->lockScreen(); OSystem_DS::instance()->unlockScreen(); } @@ -460,22 +460,22 @@ void startSound(int freq, int buffer) { bufferFirstHalf = false; bufferSecondHalf = true; - + int bytes = (2 * (bufferSamples)) + 100; - + soundBuffer = (s16 *) malloc(bytes * 2); if (!soundBuffer) consolePrintf("Sound buffer alloc failed\n"); soundHiPart = true; - + for (int r = 0; r < bytes; r++) { soundBuffer[r] = 0; } soundFrequency = freq; - + swiWaitForVBlank(); swiWaitForVBlank(); @@ -507,14 +507,14 @@ void initGame() { // consolePrintf("\n\n\n\nCurrent game: '%s' %d\n", gameName, gameName[0]); currentGame = &gameList[0]; // Default game - + for (int r = 0; r < NUM_SUPPORTED_GAMES; r++) { if (!stricmp(gameName, gameList[r].gameId)) { currentGame = &gameList[r]; // consolePrintf("Game list num: %d\n", currentGame); } } - + /* if (firstTime) { firstTime = false; @@ -557,7 +557,7 @@ void displayMode8Bit() { consolePrintf("displayMode8Bit..."); #endif u16 buffer[32 * 32]; - + setKeyboardEnable(false); if (!displayModeIs8Bit) { @@ -568,7 +568,7 @@ void displayMode8Bit() { consoleInitDefault((u16*)SCREEN_BASE_BLOCK(2), (u16*)CHAR_BASE_BLOCK(0), 16); consolePrintSet(0, 23); - + if (!displayModeIs8Bit) { for (int r = 0; r < 32 * 32; r++) { ((u16 *) SCREEN_BASE_BLOCK(2))[r] = buffer[r]; @@ -577,20 +577,20 @@ void displayMode8Bit() { } displayModeIs8Bit = true; - + if (isCpuScalerEnabled()) { - videoSetMode(MODE_5_2D | (consoleEnable? DISPLAY_BG0_ACTIVE: 0) | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_1D_BMP); + videoSetMode(MODE_5_2D | (consoleEnable? DISPLAY_BG0_ACTIVE: 0) | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_1D_BMP); videoSetModeSub(MODE_3_2D /*| DISPLAY_BG0_ACTIVE*/ | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_1D_BMP); //sub bg 0 will be used to print text - + vramSetBankA(VRAM_A_MAIN_BG_0x06000000); vramSetBankB(VRAM_B_MAIN_BG_0x06020000); - + vramSetBankC(VRAM_C_SUB_BG_0x06200000); vramSetBankD(VRAM_D_SUB_SPRITE); - + vramSetBankH(VRAM_H_LCD); - + BG3_CR = BG_BMP16_256x256 | BG_BMP_BASE(8); BG3_XDX = 256; @@ -601,27 +601,27 @@ void displayMode8Bit() { } else { - videoSetMode(MODE_5_2D | (consoleEnable? DISPLAY_BG0_ACTIVE: 0) | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_1D_BMP); + videoSetMode(MODE_5_2D | (consoleEnable? DISPLAY_BG0_ACTIVE: 0) | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_1D_BMP); videoSetModeSub(MODE_3_2D /*| DISPLAY_BG0_ACTIVE*/ | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_1D_BMP); //sub bg 0 will be used to print text - + vramSetBankA(VRAM_A_MAIN_BG_0x06000000); vramSetBankB(VRAM_B_MAIN_BG_0x06020000); - + vramSetBankC(VRAM_C_SUB_BG_0x06200000); vramSetBankD(VRAM_D_SUB_SPRITE); - + vramSetBankH(VRAM_H_LCD); - + BG3_CR = BG_BMP8_512x256 | BG_BMP_BASE(8); - + BG3_XDX = (int) (((float) (gameWidth) / 256.0f) * 256); BG3_XDY = 0; BG3_YDX = 0; BG3_YDY = (int) ((200.0f / 192.0f) * 256); - } - + } + SUB_BG3_CR = BG_BMP8_512x256; - + SUB_BG3_XDX = (int) (subScreenWidth / 256.0f * 256); SUB_BG3_XDY = 0; SUB_BG3_YDX = 0; @@ -633,15 +633,15 @@ void displayMode8Bit() { BG0_CR = BG_MAP_BASE(2) | BG_TILE_BASE(0); BG0_Y0 = 0; - - // Restore palette entry used by text in the front-end + + // Restore palette entry used by text in the front-end // PALETTE_SUB[255] = savedPalEntry255; - - + + initGame(); - + #ifdef HEAVY_LOGGING consolePrintf("done\n"); #endif @@ -653,9 +653,9 @@ void displayMode8Bit() { } uploadSpriteGfx(); - + keyboardEnable = false; - + } void setGameID(int id) { @@ -668,22 +668,22 @@ void dummyHandler() { void checkSleepMode() { if (IPC->performArm9SleepMode) { - + consolePrintf("ARM9 Entering sleep mode\n"); - + int intSave = REG_IE; irqSet(IRQ_VBLANK, dummyHandler); // int irqHandlerSave = (int) IRQ_HANDLER; REG_IE = IRQ_VBLANK; //IRQ_HANDLER = dummyHandler; - + int powerSave = POWER_CR; POWER_CR &= ~POWER_ALL; - + while (IPC->performArm9SleepMode) { swiWaitForVBlank(); } - + POWER_CR = powerSave; // IRQ_HANDLER = (void (*)()) irqHandlerSave; irqSet(IRQ_VBLANK, VBlankHandler); @@ -722,18 +722,18 @@ void setCursorIcon(const u8* icon, uint w, uint h, byte keycolor, int hotspotX, { int off = 128*64; - - + + memset(SPRITE_GFX + off, 0, 32 * 32 * 2); memset(SPRITE_GFX_SUB + off, 0, 32 * 32 * 2); - + for (uint y=0; y<h; y++) { for (uint x=0; x<w; x++) { int color = icon[y*w+x]; //consolePrintf("%d:%d ", color, OSystem_DS::instance()->getDSPaletteEntry(color)); - + if (color == keycolor) { SPRITE_GFX[off+(y)*32+x] = 0x0000; // black background SPRITE_GFX_SUB[off+(y)*32+x] = 0x0000; // black background @@ -743,23 +743,23 @@ void setCursorIcon(const u8* icon, uint w, uint h, byte keycolor, int hotspotX, } } } - + } if (currentGame->control != CONT_SCUMM_SAMNMAX) return; uint16 border = RGB15(24,24,24) | 0x8000; - - + + int off = 176*64; memset(SPRITE_GFX_SUB+off, 0, 64*64*2); memset(SPRITE_GFX+off, 0, 64*64*2); - + int pos = 190 - (w+2); - - + + // make border for (uint i=0; i<w+2; i++) { SPRITE_GFX[off+i] = border; @@ -775,7 +775,7 @@ void setCursorIcon(const u8* icon, uint w, uint h, byte keycolor, int hotspotX, SPRITE_GFX_SUB[off+(i*64)] = border; SPRITE_GFX_SUB[off+(i*64)+(w+1)] = border; } - + int offset = (32 - h) >> 1; for (uint y=0; y<h; y++) { @@ -791,8 +791,8 @@ void setCursorIcon(const u8* icon, uint w, uint h, byte keycolor, int hotspotX, } } } - - + + if ((cursorEnable)) { sprites[1].attribute[0] = ATTR0_BMP | 150; sprites[1].attribute[1] = ATTR1_SIZE_64 | pos; @@ -827,7 +827,7 @@ void displayMode16Bit() { } - videoSetMode(MODE_5_2D | /*DISPLAY_BG0_ACTIVE |*/ DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_1D_BMP); + videoSetMode(MODE_5_2D | /*DISPLAY_BG0_ACTIVE |*/ DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_1D_BMP); videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE |/* DISPLAY_BG1_ACTIVE |*/ DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_1D_BMP); //sub bg 0 will be used to print text vramSetBankA(VRAM_A_MAIN_BG); @@ -838,10 +838,10 @@ void displayMode16Bit() { BG3_CR = BG_BMP16_512x256; highBuffer = false; - + memset(BG_GFX, 0, 512 * 256 * 2); - + savedPalEntry255 = PALETTE_SUB[255]; PALETTE_SUB[255] = RGB15(31,31,31);//by default font will be rendered with color 255 @@ -860,11 +860,11 @@ void displayMode16Bit() { consolePrintSet(0, 23); consolePrintf("\n"); - + // Show keyboard SUB_BG1_CR = BG_TILE_BASE(1) | BG_MAP_BASE(12); //drawKeyboard(1, 12); - + POWER_CR &= ~POWER_SWAP_LCDS; displayModeIs8Bit = false; @@ -887,10 +887,10 @@ void displayMode16BitFlipBuffer() { #endif if (!displayModeIs8Bit) { u16* back = get16BitBackBuffer(); - + // highBuffer = !highBuffer; // BG3_CR = BG_BMP16_512x256 | BG_BMP_RAM(highBuffer? 1: 0); - + if (isCpuScalerEnabled()) { Rescale_320x256x1555_To_256x256x1555(BG_GFX, back, 512, 512); @@ -912,14 +912,14 @@ void displayMode16BitFlipBuffer() { #endif const u8* back = (const u8*)get8BitBackBuffer(); u16* base = BG_GFX + 0x10000; - Rescale_320x256xPAL8_To_256x256x1555( + Rescale_320x256xPAL8_To_256x256x1555( base, back, 256, get8BitBackBufferStride(), - BG_PALETTE, + BG_PALETTE, getGameHeight() ); - + #ifdef SCALER_PROFILE // 10 pixels : 1ms u16 t1 = TIMER1_DATA; @@ -982,10 +982,10 @@ void doSoundCallback() { if (OSystem_DS::instance()) if (OSystem_DS::instance()->getMixerImpl()) { lastCallbackFrame = frameCount; - + for (int r = IPC->playingSection; r < IPC->playingSection + 4; r++) { int chunk = r & 3; - + if (IPC->fillNeeded[chunk]) { IPC->fillNeeded[chunk] = false; DC_FlushAll(); @@ -993,9 +993,9 @@ void doSoundCallback() { IPC->fillNeeded[chunk] = false; DC_FlushAll(); } - + } - + } #ifdef HEAVY_LOGGING consolePrintf("done\n"); @@ -1007,7 +1007,7 @@ void doTimerCallback() { if (callbackTimer <= 0) { callbackTimer += callbackInterval; callback(callbackInterval); - } + } } } @@ -1016,15 +1016,15 @@ void soundUpdate() { // playSound(soundBuffer, (bufferSamples * 2), true); } // consolePrintf("%x\n", IPC->test); - - + + if (bufferFrame == 0) { // bufferFirstHalf = true; - } + } if (bufferFrame == bufferSize >> 1) { //bufferSecondHalf = true; - } - + } + bufferFrame++; if (bufferFrame == bufferSize) { bufferFrame = 0; @@ -1037,20 +1037,20 @@ void memoryReport() { do { p = (int *) malloc(r * 8192); free(p); - r++; + r++; } while ((p) && (r < 512)); - + int t = -1; void* block[1024]; do { t++; block[t] = (int *) malloc(4096); - } while ((t < 1024) && (block[t])); - + } while ((t < 1024) && (block[t])); + for (int q = 0; q < t; q++) { free(block[q]); } - + consolePrintf("Free: %dK, Largest: %dK\n", t * 4, r * 8); } @@ -1061,7 +1061,7 @@ void addIndyFightingKeys() { event.type = Common::EVENT_KEYDOWN; event.kbd.flags = 0; - + // consolePrintf("Fight keys\n"); if ((getKeysDown() & KEY_L)) { @@ -1091,16 +1091,16 @@ void addIndyFightingKeys() { event.kbd.keycode = Common::KEYCODE_6; event.kbd.ascii = '6'; system->addEvent(event); - } + } if ((getKeysChanged() & KEY_DOWN)) { event.type = getKeyEvent(KEY_DOWN); event.kbd.keycode = Common::KEYCODE_2; event.kbd.ascii = '2'; system->addEvent(event); } - + if (indyFightRight) { - + if ((getKeysChanged() & KEY_X)) { event.type = getKeyEvent(KEY_X); event.kbd.keycode = Common::KEYCODE_9; @@ -1118,7 +1118,7 @@ void addIndyFightingKeys() { event.kbd.keycode = Common::KEYCODE_3; event.kbd.ascii = '3'; system->addEvent(event); - } + } } else { @@ -1139,18 +1139,18 @@ void addIndyFightingKeys() { event.kbd.keycode = Common::KEYCODE_1; event.kbd.ascii = '1'; system->addEvent(event); - } - + } + } - - + + if ((getKeysChanged() & KEY_Y)) { event.type = getKeyEvent(KEY_Y); event.kbd.keycode = Common::KEYCODE_5; event.kbd.ascii = '5'; system->addEvent(event); } -} +} void setKeyboardEnable(bool en) { @@ -1162,8 +1162,8 @@ void setKeyboardEnable(bool en) { DS::drawKeyboard(1, 15, backupBank); - - + + SUB_BG1_CR = BG_TILE_BASE(1) | BG_MAP_BASE(15); if (displayModeIs8Bit) { @@ -1185,10 +1185,10 @@ void setKeyboardEnable(bool en) { for (int r = 0; r < 256; r++) { BG_PALETTE_SUB[r] = BG_PALETTE[r]; } - - + + //restoreVRAM(1, 12, backupBank); - + if (displayModeIs8Bit) { // Copy the sub screen VRAM from the top screen - they should always be // the same. @@ -1200,17 +1200,17 @@ void setKeyboardEnable(bool en) { BG_GFX_SUB[y * 256 + x] = buffer[(y * (stride / 2)) + x]; } } -/* +/* for (int r = 0; r < (512 * 256) >> 1; r++) BG_GFX_SUB[r] = buffer[r]; - */ + */ SUB_DISPLAY_CR &= ~DISPLAY_BG1_ACTIVE; // Turn off keyboard layer SUB_DISPLAY_CR |= DISPLAY_BG3_ACTIVE; // Turn on game layer } else { SUB_DISPLAY_CR &= ~DISPLAY_BG1_ACTIVE; // Turn off keyboard layer SUB_DISPLAY_CR |= DISPLAY_BG0_ACTIVE; // Turn on console layer } - + // Restore the screens so they're the right way round if (gameScreenSwap) { POWER_CR |= POWER_SWAP_LCDS; @@ -1321,7 +1321,7 @@ void doButtonSelectMode(OSystem_DS* system) if ((mouseMode != MOUSE_HOVER) || (!displayModeIs8Bit)) { - if (getPenDown() && (!(getKeysHeld() & KEY_L)) && (!(getKeysHeld() & KEY_R))) { + if (getPenDown() && (!(getKeysHeld() & KEY_L)) && (!(getKeysHeld() & KEY_R))) { if ((mouseMode == MOUSE_LEFT) || (!displayModeIs8Bit)) { event.type = Common::EVENT_LBUTTONDOWN; leftButtonDown = true; @@ -1333,7 +1333,7 @@ void doButtonSelectMode(OSystem_DS* system) event.mouse = Common::Point(getPenX(), getPenY()); system->addEvent(event); } - + } else { // In hover mode, D-pad left and right click the mouse when the pen is on the screen @@ -1369,7 +1369,7 @@ void doButtonSelectMode(OSystem_DS* system) if (getKeysDown() & KEY_LEFT) { mouseMode = MOUSE_LEFT; } - + if (rightButtonDown) { Common::Event event; @@ -1378,8 +1378,8 @@ void doButtonSelectMode(OSystem_DS* system) system->addEvent(event); rightButtonDown = false; } - - + + if (getKeysDown() & KEY_RIGHT) { if ((currentGame->control != CONT_SCUMM_SAMNMAX) && (currentGame->control != CONT_FUTURE_WARS) && (currentGame->control != CONT_GOBLINS)) { mouseMode = MOUSE_RIGHT; @@ -1387,7 +1387,7 @@ void doButtonSelectMode(OSystem_DS* system) // If we're playing sam and max, click and release the right mouse // button to change verb Common::Event event; - + if (currentGame->control == CONT_FUTURE_WARS) { event.mouse = Common::Point(320 - 128, 200 - 128); event.type = Common::EVENT_MOUSEMOVE; @@ -1395,20 +1395,20 @@ void doButtonSelectMode(OSystem_DS* system) } else { event.mouse = Common::Point(getPenX(), getPenY()); } - + rightButtonDown = true; - - + + event.type = Common::EVENT_RBUTTONDOWN; system->addEvent(event); - + //event.type = Common::EVENT_RBUTTONUP; //system->addEvent(event); } } - - - + + + if (getKeysDown() & KEY_UP) { mouseMode = MOUSE_HOVER; } @@ -1423,7 +1423,7 @@ void addEventsToQueue() { OSystem_DS* system = OSystem_DS::instance(); Common::Event event; - + #ifdef USE_PROFILER if (keysDown() & KEY_R) { cygprofile_begin(); @@ -1435,7 +1435,7 @@ void addEventsToQueue() { } #endif - + if (system->isEventQueueEmpty()) { /* @@ -1444,7 +1444,7 @@ void addEventsToQueue() { consolePrintf("Tweak: %d\n", tweak); IPC->tweakChanged = true; } - + if (getKeysDown() & KEY_R) { tweak++; @@ -1460,14 +1460,14 @@ void addEventsToQueue() { if (!indyFightState) { - if ((!(getKeysHeld() & KEY_L)) && (!(getKeysHeld() & KEY_R)) && (getKeysDown() & KEY_B)) { + if ((!(getKeysHeld() & KEY_L)) && (!(getKeysHeld() & KEY_R)) && (getKeysDown() & KEY_B)) { if (currentGame->control == CONT_AGI) { event.kbd.keycode = Common::KEYCODE_RETURN; event.kbd.ascii = 13; event.kbd.flags = 0; } else { - event.kbd.keycode = Common::KEYCODE_ESCAPE; - event.kbd.ascii = 27; + event.kbd.keycode = Common::KEYCODE_ESCAPE; + event.kbd.ascii = 27; event.kbd.flags = 0; } @@ -1477,11 +1477,11 @@ void addEventsToQueue() { event.type = Common::EVENT_KEYUP; system->addEvent(event); } - + } - - - + + + if ((!getIndyFightState()) && (getKeysDown() & KEY_Y)) { consoleEnable = !consoleEnable; if (displayModeIs8Bit) { @@ -1490,7 +1490,7 @@ void addEventsToQueue() { displayMode16Bit(); } } - + if ((getKeyboardEnable())) { event.kbd.flags = 0; @@ -1498,30 +1498,30 @@ void addEventsToQueue() { bool release = getKeysReleased() & (KEY_LEFT | KEY_RIGHT | KEY_UP | KEY_DOWN); bool shoulders = getKeysHeld() & (KEY_L | KEY_R); - if ( (down && (!shoulders)) || release) + if ( (down && (!shoulders)) || release) { - + if (getKeysChanged() & KEY_LEFT) { event.kbd.keycode = Common::KEYCODE_LEFT; event.kbd.ascii = 0; event.type = getKeyEvent(KEY_LEFT); system->addEvent(event); } - + if (getKeysChanged() & KEY_RIGHT) { event.kbd.keycode = Common::KEYCODE_RIGHT; event.kbd.ascii = 0; event.type = getKeyEvent(KEY_RIGHT); system->addEvent(event); } - + if (getKeysChanged() & KEY_UP) { event.kbd.keycode = Common::KEYCODE_UP; event.kbd.ascii = 0; event.type = getKeyEvent(KEY_UP); system->addEvent(event); } - + if (getKeysChanged() & KEY_DOWN) { event.kbd.keycode = Common::KEYCODE_DOWN; event.kbd.ascii = 0; @@ -1529,9 +1529,9 @@ void addEventsToQueue() { system->addEvent(event); } } - + } - + if (!((getKeysHeld() & KEY_L) || (getKeysHeld() & KEY_R)) && (!getIndyFightState()) && (!getKeyboardEnable())) { if ((getKeysDown() & KEY_A) && (!indyFightState)) { @@ -1544,10 +1544,10 @@ void addEventsToQueue() { } } - - - - + + + + } if ((getKeysDown() & KEY_SELECT)) { @@ -1556,18 +1556,18 @@ void addEventsToQueue() { showOptionsDialog(); } - + } - + if (!getIndyFightState() && !((getKeysHeld() & KEY_L) || (getKeysHeld() & KEY_R)) && (getKeysDown() & KEY_X)) { setKeyboardEnable(!keyboardEnable); } - - updateStatus(); - + + updateStatus(); + Common::Event event; - + if (!keyboardEnable) { if ((tapScreenClicks) && (getIsDisplayMode8Bit())) @@ -1578,11 +1578,11 @@ void addEventsToQueue() { { doButtonSelectMode(system); } - + if (((!(getKeysHeld() & KEY_L)) && (!(getKeysHeld() & KEY_R)) || (indyFightState)) && (displayModeIs8Bit)) { // Controls specific to the control method - - + + if (currentGame->control == CONT_SKY) { // Extra controls for Beneath a Steel Sky if ((getKeysDown() & KEY_DOWN)) { @@ -1595,7 +1595,7 @@ void addEventsToQueue() { // Extra controls for Simon the Sorcerer if ((getKeysDown() & KEY_DOWN)) { Common::Event event; - + event.type = Common::EVENT_KEYDOWN; event.kbd.keycode = Common::KEYCODE_F10; // F10 or # - show hotspots event.kbd.ascii = Common::ASCII_F10; @@ -1608,13 +1608,13 @@ void addEventsToQueue() { } } - - + + if (currentGame->control == CONT_SCUMM_ORIGINAL) { // Extra controls for Scumm v1-5 games if ((getKeysDown() & KEY_DOWN)) { Common::Event event; - + event.type = Common::EVENT_KEYDOWN; event.kbd.keycode = Common::KEYCODE_PERIOD; // Full stop - skips current dialogue line event.kbd.ascii = '.'; @@ -1624,19 +1624,19 @@ void addEventsToQueue() { event.type = Common::EVENT_KEYUP; system->addEvent(event); } - + if (indyFightState) { addIndyFightingKeys(); } - + } - + } } - + if (!displayModeIs8Bit) { // Front end controls - + if (leftHandedSwap(getKeysChanged()) & KEY_UP) { event.type = getKeyEvent(leftHandedSwap(KEY_UP)); event.kbd.keycode = Common::KEYCODE_UP; @@ -1663,10 +1663,10 @@ void addEventsToQueue() { event.type = Common::EVENT_KEYUP; system->addEvent(event); } - + } - + if ((getKeysChanged() & KEY_START)) { event.type = getKeyEvent(KEY_START); if (currentGame->control == CONT_FUTURE_WARS) { @@ -1688,34 +1688,34 @@ void addEventsToQueue() { system->addEvent(event); } - + if (keyboardEnable) { DS::addKeyboardEvents(); } - + consumeKeys(); - + consumePenEvents(); } } - + void triggerIcon(int imageNum) { triggeredIcon = imageNum; - triggeredIconTimeout = 120; + triggeredIconTimeout = 120; } - + void setIcon(int num, int x, int y, int imageNum, int flags, bool enable) { - sprites[num].attribute[0] = ATTR0_BMP | (enable? (y & 0xFF): 192) | (!enable? ATTR0_DISABLED: 0); + sprites[num].attribute[0] = ATTR0_BMP | (enable? (y & 0xFF): 192) | (!enable? ATTR0_DISABLED: 0); sprites[num].attribute[1] = ATTR1_SIZE_32 | (x & 0x1FF) | flags; sprites[num].attribute[2] = ATTR2_ALPHA(1)| (imageNum * 16); } void setIconMain(int num, int x, int y, int imageNum, int flags, bool enable) { - spritesMain[num].attribute[0] = ATTR0_BMP | (y & 0xFF) | (!enable? ATTR0_DISABLED: 0); + spritesMain[num].attribute[0] = ATTR0_BMP | (y & 0xFF) | (!enable? ATTR0_DISABLED: 0); spritesMain[num].attribute[1] = ATTR1_SIZE_32 | (x & 0x1FF) | flags; spritesMain[num].attribute[2] = ATTR2_ALPHA(1)| (imageNum * 16); } @@ -1744,17 +1744,17 @@ void updateStatus() { break; } } - + setIcon(0, 208, 150, offs, 0, true); } - + if (indyFightState) { setIcon(1, (190 - 32), 150, 3, (indyFightRight? 0: ATTR1_FLIP_X), true); // consolePrintf("%d\n", indyFightRight); } else { // setIcon(1, 0, 0, 0, 0, false); } - + if (triggeredIconTimeout > 0) { triggeredIconTimeout--; setIcon(4, 16, 150, triggeredIcon, 0, true); @@ -1793,7 +1793,7 @@ void soundBufferEmptyHandler() { } else { // bufferFirstHalf = true; } - + soundHiPart = !soundHiPart; } @@ -1804,7 +1804,7 @@ void setMainScreenScroll(int x, int y) { } else */{ BG3_CX = x + (((frameCount & 1) == 0)? 64: 0); BG3_CY = y; - + if ((!gameScreenSwap) || (touchPadStyle)) { touchX = x >> 8; touchY = y >> 8; @@ -1827,14 +1827,14 @@ void setMainScreenScale(int x, int y) { BG3_YDY = y; } else - { + { BG3_XDX = x; BG3_XDY = 0; BG3_YDX = 0; BG3_YDY = y; } - - if ((!gameScreenSwap) || (touchPadStyle)) { + + if ((!gameScreenSwap) || (touchPadStyle)) { touchScX = x; touchScY = y; } @@ -1845,7 +1845,7 @@ void setZoomedScreenScroll(int x, int y, bool shake) { /* if (gameScreenSwap) { BG3_CX = x + ((shake && ((frameCount & 1) == 0))? 64: 0); BG3_CY = y; - + touchX = x >> 8; touchY = y >> 8; } else */{ @@ -1908,7 +1908,7 @@ void VBlankHandler(void) { soundUpdate(); - + if ((!gameScreenSwap) && (!(getKeysHeld() & KEY_L) && !(getKeysHeld() & KEY_R))) { if (currentGame) { @@ -1923,14 +1923,14 @@ void VBlankHandler(void) { } } } - + penUpdate(); keysUpdate(); frameCount++; - + if ((cursorEnable) && (mouseCursorVisible)) { if (!keyboardEnable) { storedMouseX = penX; @@ -1953,31 +1953,31 @@ void VBlankHandler(void) { if (callback) { callbackTimer -= FRAME_TIME; } - + if ((getKeysHeld() & KEY_L) || (getKeysHeld() & KEY_R)) { - + if ((!dragging) && (getPenHeld()) && (penDownFrames > 5)) { dragging = true; dragStartX = penX; dragStartY = penY; - + if (gameScreenSwap) { dragScX = subScTargetX; dragScY = subScTargetY; } else { dragScX = scX; - dragScY = scY; - } - - + dragScY = scY; + } + + } - + if ((dragging) && (!getPenHeld())) { dragging = false; } - + if (dragging) { - + if (gameScreenSwap) { subScTargetX = dragScX + ((dragStartX - penX) << 8); subScTargetY = dragScY + ((dragStartY - penY) << 8); @@ -1985,18 +1985,18 @@ void VBlankHandler(void) { scX = dragScX + ((dragStartX - penX)); scY = dragScY + ((dragStartY - penY)); } - + // consolePrintf("X:%d Y:%d\n", dragStartX - penX, dragStartY - penY); } - } - - + } + + /* if ((frameCount & 1) == 0) { SUB_BG3_CX = subScX; } else { SUB_BG3_CX = subScX + 64; } - + SUB_BG3_CY = subScY + (shakePos << 8);*/ /*SUB_BG3_XDX = (int) (subScreenWidth / 256.0f * 256); @@ -2005,26 +2005,26 @@ void VBlankHandler(void) { SUB_BG3_YDY = (int) (subScreenHeight / 192.0f * 256);*/ static int ratio = (320 << 8) / SCUMM_GAME_WIDTH; - + bool zooming = false; - + if ((getKeysHeld() & KEY_L) || (getKeysHeld() & KEY_R)) { if ((getKeysHeld() & KEY_A) && (subScreenScale < ratio)) { subScreenScale += 1; zooming = true; } - + if ((getKeysHeld() & KEY_B) && (subScreenScale > 128)) { subScreenScale -=1; zooming = true; } } - + int xCenter = subScTargetX + ((subScreenWidth >> 1) << 8); int yCenter = subScTargetY + ((subScreenHeight >> 1) << 8); - + if (twoHundredPercentFixedScale) { subScreenWidth = 256 >> 1; subScreenHeight = 192 >> 1; @@ -2033,9 +2033,9 @@ void VBlankHandler(void) { // subScreenHeight = SCUMM_GAME_HEIGHT * subScreenScale >> 8; - subScreenWidth = (256 * subScreenScale) >> 8; + subScreenWidth = (256 * subScreenScale) >> 8; subScreenHeight = (192 * subScreenScale) >> 8; - + if ( ((subScreenWidth) > 256 - 8) && ((subScreenWidth) < 256 + 8) ) { subScreenWidth = 256; subScreenHeight = 192; @@ -2064,13 +2064,13 @@ void VBlankHandler(void) { //triggerIcon(-1); } } - + subScTargetX = xCenter - ((subScreenWidth >> 1) << 8); subScTargetY = yCenter - ((subScreenHeight >> 1) << 8); - - + + if (subScTargetX < 0) subScTargetX = 0; if (subScTargetX > (gameWidth - subScreenWidth) << 8) subScTargetX = (gameWidth - subScreenWidth) << 8; @@ -2082,30 +2082,30 @@ void VBlankHandler(void) { subScX += (subScTargetX - subScX) >> 2; subScY += (subScTargetY - subScY) >> 2; - + if (displayModeIs8Bit) { - + if ((getKeysHeld() & KEY_L) || (getKeysHeld() & KEY_R)) { - + int offsX = 0, offsY = 0; if (getKeysHeld() & KEY_LEFT) { offsX -= 1; } - + if (getKeysHeld() & KEY_RIGHT) { offsX += 1; } - + if (getKeysHeld() & KEY_UP) { offsY -= 1; } - + if (getKeysHeld() & KEY_DOWN) { offsY += 1; } - + if (((gameScreenSwap) && (getKeysHeld() & KEY_L)) || ((!gameScreenSwap) && (getKeysHeld() & KEY_R))) { subScTargetX += offsX << 8; subScTargetY += offsY << 8; @@ -2116,32 +2116,32 @@ void VBlankHandler(void) { } if (!scaledMode) { - + if (scX + 256 > gameWidth - 1) { scX = gameWidth - 1 - 256; } - + if (scX < 0) { scX = 0; } - + if (scY + 192 > gameHeight - 1) { scY = gameHeight - 1 - 192; } - + if (scY < 0) { scY = 0; } - + setZoomedScreenScroll(subScX, subScY, (subScreenWidth != 256) && (subScreenWidth != 128)); setZoomedScreenScale(subScreenWidth, ((subScreenHeight * (256 << 8)) / 192) >> 8); - - + + setMainScreenScroll(scX << 8, (scY << 8) + (shakePos << 8)); setMainScreenScale(256, 256); // 1:1 scale - + } else { - + if (scY > gameHeight - 192 - 1) { scY = gameHeight - 192 - 1; } @@ -2149,13 +2149,13 @@ void VBlankHandler(void) { if (scY < 0) { scY = 0; } - + setZoomedScreenScroll(subScX, subScY, (subScreenWidth != 256) && (subScreenWidth != 128)); setZoomedScreenScale(subScreenWidth, ((subScreenHeight * (256 << 8)) / 192) >> 8); - + setMainScreenScroll(64, (scY << 8) + (shakePos << 8)); setMainScreenScale(320, 256); // 1:1 scale - + } } else { setZoomedScreenScroll(0, 0, true); @@ -2164,12 +2164,12 @@ void VBlankHandler(void) { setMainScreenScroll(0, 0); setMainScreenScale(320, 256); // 1:1 scale } - + // Enable on screen keyboard when pen taps icon if ((keyboardIcon) && (penX < 32) && (penY > 160) && (penHeld)) { setKeyboardEnable(true); } - + if (keyboardEnable) { if (DS::getKeyboardClosed()) { setKeyboardEnable(false); @@ -2219,7 +2219,7 @@ void setTopScreenTarget(int x, int y) { if (subScTargetY < 0) subScTargetY = 0; if (subScTargetY > gameHeight - subScreenHeight) subScTargetY = gameHeight - subScreenHeight; - + subScTargetX <<=8; subScTargetY <<=8; } @@ -2233,8 +2233,8 @@ void hBlankHandler() { #endif void uploadSpriteGfx() { - vramSetBankD(VRAM_D_SUB_SPRITE); - vramSetBankE(VRAM_E_MAIN_SPRITE); + vramSetBankD(VRAM_D_SUB_SPRITE); + vramSetBankE(VRAM_E_MAIN_SPRITE); // Convert texture from 24bit 888 to 16bit 1555, remembering to set top bit! u8* srcTex = (u8 *) ::icons_raw; @@ -2242,7 +2242,7 @@ void uploadSpriteGfx() { SPRITE_GFX_SUB[r] = 0x8000 | (srcTex[r * 3] >> 3) | ((srcTex[r * 3 + 1] >> 3) << 5) | ((srcTex[r * 3 + 2] >> 3) << 10); SPRITE_GFX[r] = 0x8000 | (srcTex[r * 3] >> 3) | ((srcTex[r * 3 + 1] >> 3) << 5) | ((srcTex[r * 3 + 2] >> 3) << 10); } - + } void initHardware() { @@ -2253,12 +2253,12 @@ void initHardware() { penInit(); powerON(POWER_ALL); -/* vramSetBankA(VRAM_A_MAIN_BG); - vramSetBankB(VRAM_B_MAIN_BG); +/* vramSetBankA(VRAM_A_MAIN_BG); + vramSetBankB(VRAM_B_MAIN_BG); vramSetBankC(VRAM_C_SUB_BG); */ - vramSetBankD(VRAM_D_SUB_SPRITE); - vramSetBankE(VRAM_E_MAIN_SPRITE); - + vramSetBankD(VRAM_D_SUB_SPRITE); + vramSetBankE(VRAM_E_MAIN_SPRITE); + currentTimeMillis = 0; @@ -2286,8 +2286,8 @@ void initHardware() { // Allocate save buffer for game screen // savedBuffer = new u8[320 * 200]; displayMode16Bit(); - - memset(BG_GFX, 0, 512 * 256 * 2); + + memset(BG_GFX, 0, 512 * 256 * 2); scaledMode = true; scX = 0; scY = 0; @@ -2295,33 +2295,33 @@ void initHardware() { subScY = 0; subScTargetX = 0; subScTargetY = 0; - + //lcdSwap(); POWER_CR &= ~POWER_SWAP_LCDS; - + frameCount = 0; callback = NULL; - -// vramSetBankH(VRAM_H_SUB_BG); - + +// vramSetBankH(VRAM_H_SUB_BG); + // // Do text stuff //BG0_CR = BG_MAP_BASE(0) | BG_TILE_BASE(1); // BG0_Y0 = 48; - + PALETTE[255] = RGB15(31,31,31);//by default font will be rendered with color 255 - + //consoleInit() is a lot more flexible but this gets you up and running quick // consoleInitDefault((u16*)SCREEN_BASE_BLOCK(0), (u16*)CHAR_BASE_BLOCK(1), 16); //consolePrintSet(0, 6); - + //irqs are nice irqInit(); // irqInitHandler(); irqSet(IRQ_VBLANK, VBlankHandler); irqSet(IRQ_TIMER0, timerTickHandler); irqSet(IRQ_TIMER2, soundBufferEmptyHandler); - + irqEnable(IRQ_VBLANK); irqEnable(IRQ_TIMER0); irqEnable(IRQ_TIMER2); @@ -2330,15 +2330,15 @@ void initHardware() { irqSet(IRQ_HBLANK, hBlankHandler); irqEnable(IRQ_HBLANK); #endif - - + + // Set up a millisecond timer #ifdef HEAVY_LOGGING consolePrintf("Setting up timer..."); #endif TIMER0_CR = 0; TIMER0_DATA = (u32) TIMER_FREQ(1000); - TIMER0_CR = TIMER_ENABLE | TIMER_DIV_1 | TIMER_IRQ_REQ; + TIMER0_CR = TIMER_ENABLE | TIMER_DIV_1 | TIMER_IRQ_REQ; REG_IME = 1; #ifdef HEAVY_LOGGING consolePrintf("done\n"); @@ -2347,7 +2347,7 @@ void initHardware() { PALETTE[255] = RGB15(0,0,31); initSprites(); - + // videoSetModeSub(MODE_3_2D | DISPLAY_BG0_ACTIVE | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_1D_BMP); //sub bg 0 will be used to print text // If the software scaler's back buffer has not been allocated, do it now @@ -2405,7 +2405,7 @@ void penUpdate() { if ((tapTimeout >= 0)) { tapTimeout++; - + if (((tapTimeout > 15) || (tapCount == 2)) && (tapCount > 0)) { tapComplete = tapCount; tapCount = 0; @@ -2413,7 +2413,7 @@ void penUpdate() { } } - + if ((penHeld) && (!penDownThisFrame)) { if ((touchPadStyle) || (moved) || (tapCount == 1)) { @@ -2427,15 +2427,15 @@ void penUpdate() { } } - + if ((touchPadStyle) && (getIsDisplayMode8Bit())) { - - if ((penDownFrames > 0)) { - - + + if ((penDownFrames > 0)) { + + if ((penHeld)) { - + if (penDownThisFrame) { if (penDownFrames >= 2) { @@ -2446,13 +2446,13 @@ void penUpdate() { if ((ABS(diffX) < 35) && (ABS(diffY) < 35)) { - + if (speed >= 8) { diffX *= ((speed >> 3) * touchPadSensitivity) >> 3; diffY *= ((speed >> 3) * touchPadSensitivity) >> 3; } - + penX += diffX; penY += diffY; if (penX > 255) penX = 255; @@ -2460,30 +2460,30 @@ void penUpdate() { if (penY > 191) penY = 191; if (penY < 0) penY = 0; } - + // consolePrintf("x: %d y: %d\n", IPC->touchYpx - penDownY, IPC->touchYpx - penDownY); penDownX = IPC->touchXpx; penDownY = IPC->touchYpx; - + } } else { } - - + + } else { penDown = true; penHeld = true; penDownSaved = true; - + // First frame, so save pen positions if (penDownThisFrame) { penDownX = IPC->touchXpx; penDownY = IPC->touchYpx; } } - + } else { if (penHeld) { penReleased = true; @@ -2491,13 +2491,13 @@ void penUpdate() { } else { penReleased = false; } - + penDown = false; penHeld = false; } } else { if ((penDownFrames > 1)) { // Is this right? Dunno, but it works for me. - + if ((penHeld)) { penHeld = true; penDown = false; @@ -2512,9 +2512,9 @@ void penUpdate() { penY = IPC->touchYpx + touchYOffset; moved = true; } - - + + } else { if (penHeld) { penReleased = true; @@ -2522,12 +2522,12 @@ void penUpdate() { } else { penReleased = false; } - + penDown = false; penHeld = false; } - - + + } @@ -2545,20 +2545,20 @@ int leftHandedSwap(int keys) { // Start and select are unchanged if (leftHandedMode) { int result = keys & (~(KEY_R | KEY_L | KEY_Y | KEY_A | KEY_B | KEY_X | KEY_LEFT | KEY_RIGHT | KEY_UP | KEY_DOWN)); - + if (keys & KEY_L) result |= KEY_R; if (keys & KEY_R) result |= KEY_L; - + if (keys & KEY_LEFT) result |= KEY_Y; if (keys & KEY_RIGHT) result |= KEY_A; if (keys & KEY_DOWN) result |= KEY_B; if (keys & KEY_UP) result |= KEY_X; - + if (keys & KEY_Y) result |= KEY_LEFT; if (keys & KEY_A) result |= KEY_RIGHT; if (keys & KEY_B) result |= KEY_DOWN; if (keys & KEY_X) result |= KEY_UP; - + return result; } else { return keys; @@ -2647,10 +2647,10 @@ int getPenY() { GLvector getPenPos() { GLvector v; - + v.x = (penX * inttof32(1)) / SCREEN_WIDTH; v.y = (penY * inttof32(1)) / SCREEN_HEIGHT; - + return v; } @@ -2659,18 +2659,18 @@ GLvector getPenPos() { void formatSramOption() { consolePrintf("The following files are present in save RAM:\n"); DSSaveFileManager::instance()->listFiles(); - + consolePrintf("\nAre you sure you want to\n"); consolePrintf("DELETE all files?\n"); consolePrintf("A = Yes, X = No\n"); - + while (true) { if (keysHeld() & KEY_A) { DSSaveFileManager::instance()->formatSram(); consolePrintf("SRAM cleared!\n"); return; } - + if (keysHeld() & KEY_X) { consolePrintf("Whew, that was close!\n"); return; @@ -2708,7 +2708,7 @@ void* fastRamAlloc(int size) { if(fastRamPointer > fastRamData + FAST_RAM_SIZE) { consolePrintf("FastRam (ITCM) allocation failed!\n"); return NULL; - } + } return result; } @@ -2723,7 +2723,7 @@ void fastRamReset() { bool GBAMPAvail = false; -bool initGBAMP(int mode) { +bool initGBAMP(int mode) { if (FAT_InitFiles()) { if (mode == 2) { disc_IsInserted(); @@ -2748,14 +2748,14 @@ void initDebugger() { set_verbosity(VERBOSE_INFO | VERBOSE_ERROR); wireless_init(0); wireless_connect(); - + // This is where the address of the computer running the Java // stub goes. debugger_connect_tcp(192, 168, 0, 1); - debugger_init(); - + debugger_init(); + // Update function - should really call every frame - user_debugger_update(); + user_debugger_update(); } @@ -2788,7 +2788,7 @@ cardTranslate cardReaderTable[] = { void reboot() { int deviceType = -1; - + if (disc_getDeviceId() == DEVICE_DLDI) { char id[6]; @@ -2855,7 +2855,7 @@ void dsExceptionHandler() { consolePrintf("Blue screen of death"); setExceptionHandler(NULL); - + u32 currentMode = getCPSR() & 0x1f; u32 thumbState = ((*(u32*)0x027FFD90) & 0x20); @@ -2871,7 +2871,7 @@ void dsExceptionHandler() { exceptionAddress = getExceptionAddress( codeAddress, thumbState); else exceptionAddress = codeAddress; - + } else { if (thumbState) offset = 2; @@ -2919,13 +2919,13 @@ int main(void) { initDebugger(); } #endif - + // Let arm9 read cartridge *((u16 *) (0x04000204)) &= ~0x0080; - + lastCallbackFrame = 0; tweak = 0; - + indyFightState = false; indyFightRight = true; @@ -2938,25 +2938,25 @@ int main(void) { // bufferSize = 10; - + /*bufferRate = 44100; bufferFrame = 0; bufferSamples = 8192; bufferFirstHalf = false; bufferSecondHalf = true; - + int bytes = (2 * (bufferSamples)) + 100; - + soundBuffer = (s16 *) malloc(bytes * 2); soundHiPart = true; - + for (int r = 0; r < bytes; r++) { soundBuffer[r] = 0; } - + swiWaitForVBlank(); swiWaitForVBlank(); @@ -2965,29 +2965,29 @@ int main(void) { swiWaitForVBlank(); swiWaitForVBlank(); */ - + lastEventFrame = 0; mouseMode = MOUSE_LEFT; - + /* TIMER1_CR = 0; TIMER1_DATA = TIMER_FREQ(bufferRate); TIMER1_CR = TIMER_ENABLE | TIMER_DIV_1; - + TIMER2_CR = 0; TIMER2_DATA = 0xFFFF - (bufferSamples / 2); TIMER2_CR = TIMER_ENABLE | TIMER_IRQ_REQ | TIMER_CASCADE; */ // 2945 - 2947 - - + + // for (int r = 2946; r < 3000; r++) { // soundBuffer[r] = 30000; // } - + //2372 consolePrintf("-------------------------------\n"); @@ -3040,7 +3040,7 @@ int main(void) { consolePrintf("\n"); #endif - + #ifdef USE_BUILT_IN_DRIVER_SELECTION // Do M3 detection selectioon int extraData = DSSaveFileManager::getExtraData(); @@ -3079,7 +3079,7 @@ int main(void) { disc_setEnable(mode); DSSaveFileManager::setExtraData(mode); #else - + int mode = 0; #endif @@ -3125,11 +3125,11 @@ int main(void) { } delete node; - + updateStatus(); - - + + // OSystem_DS::instance(); g_system = new OSystem_DS(); |