2007-05-30 21:56:52 +00:00
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers , whose names
* are too numerous to list here . Please refer to the COPYRIGHT
* file distributed with this source distribution .
2006-07-09 11:47:17 +00:00
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version 2
* of the License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA .
*
*/
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
2006-11-03 23:16:29 +00:00
// - Remove scummconsole.c
// - Delete files
2006-12-01 22:36:54 +00:00
// - Fatlib conversion?
// - libcartreset
// - Alternative controls - tap for left click, double for right
// - Inherit the Earth?
// - Stereo audio?
// - Delete saves?
// - Software scaler?
2007-10-13 15:40:11 +00:00
// - 100% scale
// - Arrow keys cause key events when keyboard enabled - Done
// - Mouse cursor display - Done
// - Disable scaler on options menu - Done
// - Fix scale icons on top screen - Done
// - Fseek optimisation? - No need
// - Fix agi hack to be cleaner - done
// - Fix not typing looong words - Done
// - Show keyboard by default in AGI games
// - Fix mouse moving when cursor on keyboard screen - Done
// - Fix 'fit' thingy always appearing - Done
// - check cine backbuffer code - Done
// - Add long filename support - Done
// - New icons
// - Add key config for gob engine: Start:F1, Shift-numbers: F keys - Done
// - Fix [ds] appearing in game menu
// - Find out what's going wrong when you turn the console off
// - enable console when asserting
2007-08-18 11:10:41 +00:00
// - Alternative controls?
2008-05-15 22:12:51 +00:00
// - Fix 512x256 backbuffer to 320x240 - Done
// - Fix keyboard appearing on wrong screen - Done
// - Volume amplify option
// - Make save/restore game screen use scaler buffer
2007-08-18 11:10:41 +00:00
2007-10-13 15:40:11 +00:00
//#define USE_LIBCARTRESET
2006-11-03 23:16:29 +00:00
2006-07-09 11:47:17 +00:00
# include <nds.h>
2008-09-14 22:24:35 +00:00
# include <nds/registers_alt.h>
2006-07-09 11:47:17 +00:00
2007-04-06 18:34:53 +00:00
//#include <ARM9/console.h> //basic print funcionality
2006-07-09 11:47:17 +00:00
# include <stdlib.h>
# include "dsmain.h"
# include "string.h"
# include "osystem_ds.h"
# include "icons_raw.h"
2008-05-31 19:02:35 +00:00
# include "fat/gba_nds_fat.h"
# include "fat/disc_io.h"
2008-09-14 22:24:35 +00:00
//#include "common/config-manager.h"
2006-07-09 11:47:17 +00:00
# include "keyboard_raw.h"
# include "keyboard_pal_raw.h"
# define V16(a, b) ((a << 12) | b)
# include "touchkeyboard.h"
//#include "compact_flash.h"
# include "dsoptions.h"
2006-11-19 20:10:52 +00:00
# ifdef USE_DEBUGGER
2006-11-03 23:16:29 +00:00
# include "user_debugger.h"
2006-11-19 20:10:52 +00:00
# endif
2006-11-03 23:16:29 +00:00
# include "ramsave.h"
2006-10-05 22:44:11 +00:00
# include "blitters.h"
2007-01-19 21:47:10 +00:00
# include "cartreset_nolibfat.h"
2007-04-06 18:34:53 +00:00
# include "keys.h"
2007-10-13 15:40:11 +00:00
# ifdef USE_PROFILER
2007-06-30 23:03:03 +00:00
# include "profiler/cyg-profile.h"
2007-10-13 15:40:11 +00:00
# endif
2008-05-31 19:02:35 +00:00
# include "backends/fs/ds/ds-fs.h"
2006-07-09 11:47:17 +00:00
namespace DS {
// From console.c in NDSLib
//location of cursor
extern u8 row ;
extern u8 col ;
// Mouse mode
enum MouseMode {
MOUSE_LEFT , MOUSE_RIGHT , MOUSE_HOVER , MOUSE_NUM_MODES
} ;
// Defines
# define FRAME_TIME 17
# define SCUMM_GAME_HEIGHT 142
2006-11-03 23:16:29 +00:00
# define SCUMM_GAME_WIDTH 227
2006-07-09 11:47:17 +00:00
int textureID ;
u16 * texture ;
int frameCount ;
int currentTimeMillis ;
// Timer Callback
int callbackInterval ;
int callbackTimer ;
2006-10-25 19:18:38 +00:00
OSystem_DS : : TimerProc callback ;
2006-07-09 11:47:17 +00:00
// Scaled
bool scaledMode ;
int scX ;
int scY ;
int subScX ;
int subScY ;
int subScTargetX ;
int subScTargetY ;
int subScreenWidth = SCUMM_GAME_WIDTH ;
int subScreenHeight = SCUMM_GAME_HEIGHT ;
int subScreenScale = 256 ;
// Sound
int bufferSize ;
s16 * soundBuffer ;
int bufferFrame ;
int bufferRate ;
int bufferSamples ;
bool soundHiPart ;
2006-11-03 23:16:29 +00:00
int soundFrequency ;
2006-07-09 11:47:17 +00:00
// Events
int lastEventFrame ;
bool indyFightState ;
bool indyFightRight ;
2006-10-25 19:18:38 +00:00
OSystem_DS : : SoundProc soundCallback ;
2006-07-09 11:47:17 +00:00
void * soundParam ;
int lastCallbackFrame ;
bool bufferFirstHalf ;
bool bufferSecondHalf ;
// Saved buffers
bool highBuffer ;
2006-07-09 18:28:58 +00:00
bool displayModeIs8Bit = false ;
2006-07-09 11:47:17 +00:00
// Game id
u8 gameID ;
2007-10-13 15:40:11 +00:00
bool snapToBorder = false ;
2008-07-09 16:50:23 +00:00
bool consoleEnable = true ;
2006-07-09 11:47:17 +00:00
bool gameScreenSwap = false ;
2006-11-03 23:16:29 +00:00
bool isCpuScalerEnabled ( ) ;
2006-11-25 20:35:34 +00:00
//#define HEAVY_LOGGING
2006-07-09 11:47:17 +00:00
MouseMode mouseMode ;
2007-06-30 23:03:03 +00:00
int storedMouseX = 0 ;
int storedMouseY = 0 ;
2006-07-09 11:47:17 +00:00
// Sprites
SpriteEntry sprites [ 128 ] ;
SpriteEntry spritesMain [ 128 ] ;
int tweak ;
// Shake
int shakePos = 0 ;
// Keyboard
bool keyboardEnable = false ;
bool leftHandedMode = false ;
bool keyboardIcon = false ;
// Touch
int touchScX , touchScY , touchX , touchY ;
2007-06-30 23:03:03 +00:00
int mouseHotspotX , mouseHotspotY ;
bool cursorEnable = false ;
bool mouseCursorVisible = true ;
2007-10-13 15:40:11 +00:00
bool rightButtonDown = false ;
2006-07-09 11:47:17 +00:00
// Dragging
int dragStartX , dragStartY ;
bool dragging = false ;
int dragScX , dragScY ;
// Interface styles
char gameName [ 32 ] ;
// 8-bit surface size
int gameWidth = 320 ;
int gameHeight = 200 ;
2006-11-03 23:16:29 +00:00
// Scale
bool twoHundredPercentFixedScale = false ;
2007-12-21 18:36:40 +00:00
bool cpuScalerEnable = false ;
2008-05-15 22:12:51 +00:00
# define NUM_SUPPORTED_GAMES 20
2006-11-03 23:16:29 +00:00
2007-06-30 23:03:03 +00:00
# ifdef USE_PROFILER
int hBlankCount = 0 ;
# endif
2006-07-09 11:47:17 +00:00
2008-05-15 22:12:51 +00:00
u8 * scalerBackBuffer = NULL ;
2006-07-09 11:47:17 +00:00
gameListType gameList [ NUM_SUPPORTED_GAMES ] = {
// Unknown game - use normal SCUMM controls
2008-05-15 22:12:51 +00:00
{ " unknown " , CONT_SCUMM_ORIGINAL } ,
2006-07-09 11:47:17 +00:00
// SCUMM games
{ " maniac " , CONT_SCUMM_ORIGINAL } ,
{ " zak " , CONT_SCUMM_ORIGINAL } ,
{ " loom " , CONT_SCUMM_ORIGINAL } ,
{ " indy3 " , CONT_SCUMM_ORIGINAL } ,
2008-05-15 22:12:51 +00:00
{ " atlantis " , CONT_SCUMM_ORIGINAL } ,
2006-07-09 11:47:17 +00:00
{ " monkey " , CONT_SCUMM_ORIGINAL } ,
{ " monkey2 " , CONT_SCUMM_ORIGINAL } ,
2008-05-15 22:12:51 +00:00
{ " tentacle " , CONT_SCUMM_ORIGINAL } ,
2006-07-09 11:47:17 +00:00
{ " samnmax " , CONT_SCUMM_SAMNMAX } ,
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
// Non-SCUMM games
{ " sky " , CONT_SKY } ,
{ " simon1 " , CONT_SIMON } ,
{ " simon2 " , CONT_SIMON } ,
2008-05-15 22:12:51 +00:00
{ " gob " , CONT_GOBLINS } ,
2007-06-30 23:03:03 +00:00
{ " queen " , CONT_SCUMM_ORIGINAL } ,
{ " cine " , CONT_FUTURE_WARS } ,
2008-05-15 22:12:51 +00:00
{ " agi " , CONT_AGI } ,
{ " elvira2 " , CONT_SIMON } ,
{ " elvira1 " , CONT_SIMON } ,
{ " waxworks " , CONT_SIMON } ,
2006-07-09 11:47:17 +00:00
} ;
gameListType * currentGame = NULL ;
// Stylus
# define ABS(x) ((x)>0?(x):-(x))
bool penDown ;
bool penHeld ;
bool penReleased ;
bool penDownLastFrame ;
2007-04-06 18:34:53 +00:00
s32 penX , penY ;
2006-07-09 11:47:17 +00:00
int keysDownSaved ;
int keysReleasedSaved ;
2007-04-06 18:34:53 +00:00
int keysChangedSaved ;
2006-07-09 11:47:17 +00:00
bool penDownSaved ;
bool penReleasedSaved ;
int penDownFrames ;
int touchXOffset = 0 ;
int touchYOffset = 0 ;
2007-04-06 18:34:53 +00:00
int triggeredIcon = 0 ;
int triggeredIconTimeout = 0 ;
2006-07-09 11:47:17 +00:00
u16 savedPalEntry255 = RGB15 ( 31 , 31 , 31 ) ;
extern " C " int scummvm_main ( int argc , char * argv [ ] ) ;
2007-04-06 18:34:53 +00:00
Common : : EventType getKeyEvent ( int key ) ;
int getKeysChanged ( ) ;
2006-07-09 11:47:17 +00:00
void updateStatus ( ) ;
2007-04-06 18:34:53 +00:00
void triggerIcon ( int imageNum ) ;
void setIcon ( int num , int x , int y , int imageNum , int flags , bool enable ) ;
2007-06-30 23:03:03 +00:00
void setIconMain ( int num , int x , int y , int imageNum , int flags , bool enable ) ;
2008-05-15 22:12:51 +00:00
void uploadSpriteGfx ( ) ;
2006-07-09 11:47:17 +00:00
TransferSound soundControl ;
2007-06-30 23:03:03 +00:00
2007-02-13 21:04:31 +00:00
bool isCpuScalerEnabled ( )
{
2008-05-15 22:12:51 +00:00
return cpuScalerEnable | | ! displayModeIs8Bit ;
2006-11-03 23:16:29 +00:00
}
2007-12-21 18:36:40 +00:00
void setCpuScalerEnable ( bool enable ) {
cpuScalerEnable = enable ;
}
// return (ConfMan.hasKey("cpu_scaler", "ds") && ConfMan.getBool("cpu_scaler", "ds"));
2006-07-09 11:47:17 +00:00
//plays an 8 bit mono sample at 11025Hz
void playSound ( const void * data , u32 length , bool loop , bool adpcm , int rate )
{
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( ! IPC - > soundData ) {
soundControl . count = 0 ;
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
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
soundControl . data [ soundControl . count ] . pan = 64 ;
soundControl . data [ soundControl . count ] . vol = 127 ;
soundControl . data [ soundControl . count ] . format = adpcm ? 2 : 0 ;
soundControl . count + + ;
DC_FlushAll ( ) ;
IPC - > soundData = & soundControl ;
}
void stopSound ( int channel ) {
playSound ( NULL , 0 , false , false , - channel ) ;
}
void updateOAM ( ) {
DC_FlushAll ( ) ;
2008-05-15 22:12:51 +00:00
if ( gameScreenSwap ) {
dmaCopy ( sprites , OAM , 128 * sizeof ( SpriteEntry ) ) ;
dmaCopy ( spritesMain , OAM_SUB , 128 * sizeof ( SpriteEntry ) ) ;
} else {
dmaCopy ( sprites , OAM_SUB , 128 * sizeof ( SpriteEntry ) ) ;
dmaCopy ( spritesMain , OAM , 128 * sizeof ( SpriteEntry ) ) ;
}
2006-07-09 11:47:17 +00:00
}
void setGameSize ( int width , int height ) {
gameWidth = width ;
gameHeight = height ;
}
int getGameWidth ( ) {
return gameWidth ;
}
int getGameHeight ( ) {
return gameHeight ;
}
void initSprites ( ) {
2007-09-18 20:16:33 +00:00
for ( int i = 0 ; i < 128 ; i + + ) {
2006-07-09 11:47:17 +00:00
sprites [ i ] . attribute [ 0 ] = ATTR0_DISABLED ;
sprites [ i ] . attribute [ 1 ] = 0 ;
sprites [ i ] . attribute [ 2 ] = 0 ;
2008-05-31 19:24:26 +00:00
sprites [ i ] . filler = 0 ;
2006-07-09 11:47:17 +00:00
}
2008-05-15 22:12:51 +00:00
2007-09-18 20:16:33 +00:00
for ( int i = 0 ; i < 128 ; i + + ) {
2006-07-09 11:47:17 +00:00
spritesMain [ i ] . attribute [ 0 ] = ATTR0_DISABLED ;
spritesMain [ i ] . attribute [ 1 ] = 0 ;
spritesMain [ i ] . attribute [ 2 ] = 0 ;
2008-05-31 19:24:26 +00:00
spritesMain [ i ] . filler = 0 ;
2006-07-09 11:47:17 +00:00
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
updateOAM ( ) ;
}
void saveGameBackBuffer ( ) {
2007-12-21 18:36:40 +00:00
2008-05-15 22:12:51 +00:00
// Sometimes the only copy of the game screen is in video memory.
// 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 ( ) ;
2006-07-09 11:47:17 +00:00
}
2006-11-03 23:16:29 +00:00
void startSound ( int freq , int buffer ) {
bufferRate = freq * 2 ;
bufferFrame = 0 ;
bufferSamples = 4096 ;
bufferFirstHalf = false ;
bufferSecondHalf = true ;
2008-05-15 22:12:51 +00:00
2006-11-03 23:16:29 +00:00
int bytes = ( 2 * ( bufferSamples ) ) + 100 ;
2008-05-15 22:12:51 +00:00
2006-11-03 23:16:29 +00:00
soundBuffer = ( s16 * ) malloc ( bytes * 2 ) ;
2006-11-25 20:35:34 +00:00
if ( ! soundBuffer )
consolePrintf ( " Sound buffer alloc failed \n " ) ;
2006-11-03 23:16:29 +00:00
soundHiPart = true ;
2008-05-15 22:12:51 +00:00
2006-11-03 23:16:29 +00:00
for ( int r = 0 ; r < bytes ; r + + ) {
soundBuffer [ r ] = 0 ;
}
soundFrequency = freq ;
2008-05-15 22:12:51 +00:00
2006-11-03 23:16:29 +00:00
swiWaitForVBlank ( ) ;
swiWaitForVBlank ( ) ;
playSound ( soundBuffer , ( bufferSamples * 2 ) , true , false , freq * 2 ) ;
swiWaitForVBlank ( ) ;
swiWaitForVBlank ( ) ;
swiWaitForVBlank ( ) ;
}
int getSoundFrequency ( ) {
return soundFrequency ;
}
2006-07-09 11:47:17 +00:00
void initGame ( ) {
// This is a good time to check for left handed mode since the mode change is done as the game starts.
// There's probably a better way, but hey.
2006-11-25 20:35:34 +00:00
# ifdef HEAVY_LOGGING
consolePrintf ( " initing game... " ) ;
# endif
2006-07-09 11:47:17 +00:00
2006-11-03 23:16:29 +00:00
static bool firstTime = true ;
2006-07-09 11:47:17 +00:00
setOptions ( ) ;
//strcpy(gameName, ConfMan.getActiveDomain().c_str());
strcpy ( gameName , ConfMan . get ( " gameid " ) . c_str ( ) ) ;
2007-08-18 11:10:41 +00:00
consolePrintf ( " \n \n \n \n Current game: '%s' %d \n " , gameName , gameName [ 0 ] ) ;
2006-07-09 11:47:17 +00:00
currentGame = & gameList [ 0 ] ; // Default game
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
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);
}
}
2008-05-15 22:12:51 +00:00
2006-11-03 23:16:29 +00:00
if ( firstTime ) {
firstTime = false ;
if ( ConfMan . hasKey ( " 22khzaudio " , " ds " ) & & ConfMan . getBool ( " 22khzaudio " , " ds " ) ) {
startSound ( 22050 , 8192 ) ;
} else {
startSound ( 11025 , 4096 ) ;
}
}
2006-11-25 20:35:34 +00:00
# ifdef HEAVY_LOGGING
consolePrintf ( " done \n " ) ;
# endif
2006-07-09 11:47:17 +00:00
}
void setLeftHanded ( bool enable ) {
leftHandedMode = enable ;
}
2007-10-13 15:40:11 +00:00
void setSnapToBorder ( bool enable ) {
snapToBorder = enable ;
}
2006-07-09 11:47:17 +00:00
void setTouchXOffset ( int x ) {
touchXOffset = x ;
}
void setTouchYOffset ( int y ) {
touchYOffset = y ;
}
2006-11-03 23:16:29 +00:00
void set200PercentFixedScale ( bool on ) {
twoHundredPercentFixedScale = on ;
}
2006-07-09 11:47:17 +00:00
void setUnscaledMode ( bool enable ) {
scaledMode = ! enable ;
}
void displayMode8Bit ( ) {
2006-11-25 20:35:34 +00:00
# ifdef HEAVY_LOGGING
consolePrintf ( " displayMode8Bit... " ) ;
# endif
2006-07-09 11:47:17 +00:00
u16 buffer [ 32 * 32 ] ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
setKeyboardEnable ( false ) ;
if ( ! displayModeIs8Bit ) {
for ( int r = 0 ; r < 32 * 32 ; r + + ) {
buffer [ r ] = ( ( u16 * ) SCREEN_BASE_BLOCK_SUB ( 4 ) ) [ r ] ;
}
}
2008-01-27 19:47:41 +00:00
2008-05-15 22:12:51 +00:00
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 ] ;
}
// dmaCopyHalfWords(3, (u16 *) SCREEN_BASE_BLOCK(0), buffer, 32 * 32 * 2);
}
displayModeIs8Bit = true ;
2006-11-25 20:35:34 +00:00
if ( isCpuScalerEnabled ( ) )
{
2008-05-15 22:12:51 +00:00
videoSetMode ( MODE_5_2D | ( consoleEnable ? DISPLAY_BG0_ACTIVE : 0 ) | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_1D_BMP ) ;
2006-11-25 20:35:34 +00:00
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
2008-05-15 22:12:51 +00:00
2007-04-06 18:34:53 +00:00
vramSetBankA ( VRAM_A_MAIN_BG_0x06000000 ) ;
vramSetBankB ( VRAM_B_MAIN_BG_0x06020000 ) ;
2008-05-15 22:12:51 +00:00
2007-04-06 18:34:53 +00:00
vramSetBankC ( VRAM_C_SUB_BG_0x06200000 ) ;
2008-05-15 22:12:51 +00:00
vramSetBankD ( VRAM_D_SUB_SPRITE ) ;
2006-11-25 20:35:34 +00:00
vramSetBankH ( VRAM_H_LCD ) ;
2008-05-15 22:12:51 +00:00
2006-11-25 20:35:34 +00:00
BG3_CR = BG_BMP16_256x256 | BG_BMP_BASE ( 8 ) ;
2006-07-09 11:47:17 +00:00
2006-11-25 20:35:34 +00:00
BG3_XDX = 256 ;
BG3_XDY = 0 ;
BG3_YDX = 0 ;
BG3_YDY = ( int ) ( ( 200.0f / 192.0f ) * 256 ) ;
2008-05-15 22:12:51 +00:00
2006-11-25 20:35:34 +00:00
}
else
{
2008-05-15 22:12:51 +00:00
videoSetMode ( MODE_5_2D | ( consoleEnable ? DISPLAY_BG0_ACTIVE : 0 ) | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_1D_BMP ) ;
2006-11-25 20:35:34 +00:00
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
2008-05-15 22:12:51 +00:00
2007-04-06 18:34:53 +00:00
vramSetBankA ( VRAM_A_MAIN_BG_0x06000000 ) ;
vramSetBankB ( VRAM_B_MAIN_BG_0x06020000 ) ;
2008-05-15 22:12:51 +00:00
2007-04-06 18:34:53 +00:00
vramSetBankC ( VRAM_C_SUB_BG_0x06200000 ) ;
2008-05-15 22:12:51 +00:00
vramSetBankD ( VRAM_D_SUB_SPRITE ) ;
2006-11-25 20:35:34 +00:00
vramSetBankH ( VRAM_H_LCD ) ;
2008-05-15 22:12:51 +00:00
2006-11-25 20:35:34 +00:00
BG3_CR = BG_BMP8_512x256 | BG_BMP_BASE ( 8 ) ;
2008-05-15 22:12:51 +00:00
2006-11-25 20:35:34 +00:00
BG3_XDX = ( int ) ( ( ( float ) ( gameWidth ) / 256.0f ) * 256 ) ;
BG3_XDY = 0 ;
BG3_YDX = 0 ;
BG3_YDY = ( int ) ( ( 200.0f / 192.0f ) * 256 ) ;
2008-05-15 22:12:51 +00:00
}
2006-11-25 22:03:34 +00:00
SUB_BG3_CR = BG_BMP8_512x256 ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
SUB_BG3_XDX = ( int ) ( subScreenWidth / 256.0f * 256 ) ;
SUB_BG3_XDY = 0 ;
SUB_BG3_YDX = 0 ;
SUB_BG3_YDY = ( int ) ( subScreenHeight / 192.0f * 256 ) ;
// Do text stuff
2007-12-21 18:36:40 +00:00
// console chars at 1C000 (7), map at 1D000 (74)
BG0_CR = BG_MAP_BASE ( 2 ) | BG_TILE_BASE ( 0 ) ;
2006-07-09 11:47:17 +00:00
BG0_Y0 = 0 ;
2008-05-15 22:12:51 +00:00
// Restore palette entry used by text in the front-end
2007-01-20 17:29:20 +00:00
// PALETTE_SUB[255] = savedPalEntry255;
2007-12-21 18:36:40 +00:00
2008-05-15 22:12:51 +00:00
2007-12-21 18:36:40 +00:00
initGame ( ) ;
2008-05-15 22:12:51 +00:00
2006-11-25 20:35:34 +00:00
# ifdef HEAVY_LOGGING
consolePrintf ( " done \n " ) ;
# endif
2008-05-15 22:12:51 +00:00
if ( gameScreenSwap ) {
POWER_CR | = POWER_SWAP_LCDS ;
} else {
POWER_CR & = ~ POWER_SWAP_LCDS ;
}
2007-12-21 18:36:40 +00:00
2008-05-15 22:12:51 +00:00
uploadSpriteGfx ( ) ;
2006-07-09 11:47:17 +00:00
keyboardEnable = false ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
}
void setGameID ( int id ) {
gameID = id ;
}
void dummyHandler ( ) {
REG_IF = IRQ_VBLANK ;
}
void checkSleepMode ( ) {
if ( IPC - > performArm9SleepMode ) {
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
consolePrintf ( " ARM9 Entering sleep mode \n " ) ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
int intSave = REG_IE ;
irqSet ( IRQ_VBLANK , dummyHandler ) ;
// int irqHandlerSave = (int) IRQ_HANDLER;
REG_IE = IRQ_VBLANK ;
//IRQ_HANDLER = dummyHandler;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
int powerSave = POWER_CR ;
POWER_CR & = ~ POWER_ALL ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
while ( IPC - > performArm9SleepMode ) {
swiWaitForVBlank ( ) ;
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
POWER_CR = powerSave ;
// IRQ_HANDLER = (void (*)()) irqHandlerSave;
irqSet ( IRQ_VBLANK , VBlankHandler ) ;
REG_IE = intSave ;
consolePrintf ( " ARM9 Waking from sleep mode \n " ) ;
}
}
2007-06-30 23:03:03 +00:00
void setShowCursor ( bool enable )
{
if ( currentGame - > control = = CONT_SCUMM_SAMNMAX )
{
if ( cursorEnable ) {
sprites [ 1 ] . attribute [ 0 ] = ATTR0_BMP | 150 ;
} else {
sprites [ 1 ] . attribute [ 0 ] = ATTR0_DISABLED ;
}
}
cursorEnable = enable ;
}
void setMouseCursorVisible ( bool enable )
{
mouseCursorVisible = enable ;
}
void setCursorIcon ( const u8 * icon , uint w , uint h , byte keycolor , int hotspotX , int hotspotY ) {
mouseHotspotX = hotspotX ;
mouseHotspotY = hotspotY ;
{
int off = 128 * 64 ;
2008-05-15 22:12:51 +00:00
2007-06-30 23:03:03 +00:00
memset ( SPRITE_GFX + off , 0 , 32 * 32 * 2 ) ;
2008-05-15 22:12:51 +00:00
memset ( SPRITE_GFX_SUB + off , 0 , 32 * 32 * 2 ) ;
2007-06-30 23:03:03 +00:00
for ( uint y = 0 ; y < h ; y + + ) {
for ( uint x = 0 ; x < w ; x + + ) {
int color = icon [ y * w + x ] ;
2008-05-15 22:12:51 +00:00
2007-06-30 23:03:03 +00:00
if ( color = = keycolor ) {
SPRITE_GFX [ off + ( y ) * 32 + x ] = 0x0000 ; // black background
2008-05-15 22:12:51 +00:00
SPRITE_GFX_SUB [ off + ( y ) * 32 + x ] = 0x0000 ; // black background
2007-06-30 23:03:03 +00:00
} else {
SPRITE_GFX [ off + ( y ) * 32 + x ] = BG_PALETTE [ color ] | 0x8000 ;
2008-05-15 22:12:51 +00:00
SPRITE_GFX_SUB [ off + ( y ) * 32 + x ] = BG_PALETTE [ color ] | 0x8000 ;
2007-06-30 23:03:03 +00:00
}
}
}
2008-05-15 22:12:51 +00:00
2007-06-30 23:03:03 +00:00
}
2006-07-09 11:47:17 +00:00
if ( currentGame - > control ! = CONT_SCUMM_SAMNMAX )
return ;
uint16 border = RGB15 ( 24 , 24 , 24 ) | 0x8000 ;
2008-05-15 22:12:51 +00:00
int off = 176 * 64 ;
2006-07-09 11:47:17 +00:00
memset ( SPRITE_GFX_SUB + off , 0 , 64 * 64 * 2 ) ;
2008-05-15 22:12:51 +00:00
memset ( SPRITE_GFX + off , 0 , 64 * 64 * 2 ) ;
2006-07-09 11:47:17 +00:00
int pos = 190 - ( w + 2 ) ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
// make border
for ( uint i = 0 ; i < w + 2 ; i + + ) {
2008-05-15 22:12:51 +00:00
SPRITE_GFX [ off + i ] = border ;
SPRITE_GFX [ off + ( 31 ) * 64 + i ] = border ;
2006-07-09 11:47:17 +00:00
SPRITE_GFX_SUB [ off + i ] = border ;
SPRITE_GFX_SUB [ off + ( 31 ) * 64 + i ] = border ;
}
for ( uint i = 1 ; i < 31 ; i + + ) {
2008-05-15 22:12:51 +00:00
SPRITE_GFX [ off + ( i * 64 ) ] = border ;
SPRITE_GFX [ off + ( i * 64 ) + ( w + 1 ) ] = border ;
2006-07-09 11:47:17 +00:00
SPRITE_GFX_SUB [ off + ( i * 64 ) ] = border ;
SPRITE_GFX_SUB [ off + ( i * 64 ) + ( w + 1 ) ] = border ;
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
int offset = ( 32 - h ) > > 1 ;
for ( uint y = 0 ; y < h ; y + + ) {
for ( uint x = 0 ; x < w ; x + + ) {
int color = icon [ y * w + x ] ;
2007-06-30 23:03:03 +00:00
2006-07-09 11:47:17 +00:00
if ( color = = keycolor ) {
2008-05-15 22:12:51 +00:00
SPRITE_GFX [ off + ( y + 1 + offset ) * 64 + ( x + 1 ) ] = 0x8000 ; // black background
2006-07-09 11:47:17 +00:00
SPRITE_GFX_SUB [ off + ( y + 1 + offset ) * 64 + ( x + 1 ) ] = 0x8000 ; // black background
} else {
2008-05-15 22:12:51 +00:00
SPRITE_GFX [ off + ( y + 1 + offset ) * 64 + ( x + 1 ) ] = BG_PALETTE [ color ] | 0x8000 ;
2006-07-09 11:47:17 +00:00
SPRITE_GFX_SUB [ off + ( y + 1 + offset ) * 64 + ( x + 1 ) ] = BG_PALETTE [ color ] | 0x8000 ;
}
}
}
2008-05-15 22:12:51 +00:00
if ( ( cursorEnable ) ) {
2007-06-30 23:03:03 +00:00
sprites [ 1 ] . attribute [ 0 ] = ATTR0_BMP | 150 ;
sprites [ 1 ] . attribute [ 1 ] = ATTR1_SIZE_64 | pos ;
2008-05-15 22:12:51 +00:00
sprites [ 1 ] . attribute [ 2 ] = ATTR2_ALPHA ( 1 ) | 176 ;
2007-06-30 23:03:03 +00:00
} else {
sprites [ 1 ] . attribute [ 0 ] = ATTR0_DISABLED | 150 ;
sprites [ 1 ] . attribute [ 1 ] = ATTR1_SIZE_64 | pos ;
2008-05-15 22:12:51 +00:00
sprites [ 1 ] . attribute [ 2 ] = ATTR2_ALPHA ( 1 ) | 176 ;
2007-06-30 23:03:03 +00:00
}
2006-07-09 11:47:17 +00:00
}
void displayMode16Bit ( ) {
2006-11-25 20:35:34 +00:00
# ifdef HEAVY_LOGGING
consolePrintf ( " displayMode16Bit... " ) ;
# endif
2006-07-09 11:47:17 +00:00
u16 buffer [ 32 * 32 * 2 ] ;
if ( displayModeIs8Bit ) {
2008-05-31 19:02:35 +00:00
// static int test = 0;
2008-05-15 22:12:51 +00:00
// consolePrintf("saving buffer... %d\n", test++);
2006-07-09 11:47:17 +00:00
saveGameBackBuffer ( ) ;
for ( int r = 0 ; r < 32 * 32 ; r + + ) {
2007-12-21 18:36:40 +00:00
buffer [ r ] = ( ( u16 * ) SCREEN_BASE_BLOCK ( 2 ) ) [ r ] ;
2006-07-09 11:47:17 +00:00
}
}
2008-05-15 22:12:51 +00:00
videoSetMode ( MODE_5_2D | /*DISPLAY_BG0_ACTIVE |*/ DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_1D_BMP ) ;
2006-07-09 11:47:17 +00:00
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 ) ;
vramSetBankB ( VRAM_B_MAIN_BG ) ;
vramSetBankC ( VRAM_C_MAIN_BG ) ;
vramSetBankD ( VRAM_D_MAIN_BG ) ;
vramSetBankH ( VRAM_H_SUB_BG ) ;
BG3_CR = BG_BMP16_512x256 ;
highBuffer = false ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
memset ( BG_GFX , 0 , 512 * 256 * 2 ) ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
savedPalEntry255 = PALETTE_SUB [ 255 ] ;
PALETTE_SUB [ 255 ] = RGB15 ( 31 , 31 , 31 ) ; //by default font will be rendered with color 255
// Do text stuff
SUB_BG0_CR = BG_MAP_BASE ( 4 ) | BG_TILE_BASE ( 0 ) ;
SUB_BG0_Y0 = 0 ;
consoleInitDefault ( ( u16 * ) SCREEN_BASE_BLOCK_SUB ( 4 ) , ( u16 * ) CHAR_BASE_BLOCK_SUB ( 0 ) , 16 ) ;
if ( displayModeIs8Bit ) {
//dmaCopyHalfWords(3, (u16 *) SCREEN_BASE_BLOCK_SUB(0), buffer, 32 * 32 * 2);
for ( int r = 0 ; r < 32 * 32 ; r + + ) {
( ( u16 * ) SCREEN_BASE_BLOCK_SUB ( 4 ) ) [ r ] = buffer [ r ] ;
}
}
consolePrintSet ( 0 , 23 ) ;
consolePrintf ( " \n " ) ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
// Show keyboard
SUB_BG1_CR = BG_TILE_BASE ( 1 ) | BG_MAP_BASE ( 12 ) ;
//drawKeyboard(1, 12);
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
POWER_CR & = ~ POWER_SWAP_LCDS ;
displayModeIs8Bit = false ;
2008-05-15 22:12:51 +00:00
BG3_XDX = isCpuScalerEnabled ( ) ? 256 : ( int ) ( 1.25f * 256 ) ;
BG3_XDY = 0 ;
BG3_YDX = 0 ;
BG3_YDY = ( int ) ( ( 200.0f / 192.0f ) * 256 ) ;
2006-11-25 20:35:34 +00:00
# ifdef HEAVY_LOGGING
consolePrintf ( " done \n " ) ;
# endif
2006-07-09 11:47:17 +00:00
}
void displayMode16BitFlipBuffer ( ) {
2006-11-25 20:35:34 +00:00
# ifdef HEAVY_LOGGING
consolePrintf ( " Flip %s... " , displayModeIs8Bit ? " 8bpp " : " 16bpp " ) ;
# endif
2006-07-09 11:47:17 +00:00
if ( ! displayModeIs8Bit ) {
u16 * back = get16BitBackBuffer ( ) ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
// highBuffer = !highBuffer;
// BG3_CR = BG_BMP16_512x256 | BG_BMP_RAM(highBuffer? 1: 0);
2008-05-15 22:12:51 +00:00
2007-02-13 21:04:31 +00:00
if ( isCpuScalerEnabled ( ) )
2006-10-05 22:44:11 +00:00
{
2008-05-15 22:12:51 +00:00
Rescale_320x256x1555_To_256x256x1555 ( BG_GFX , back , 512 , 512 ) ;
2006-10-05 22:44:11 +00:00
}
else
{
for ( int r = 0 ; r < 512 * 256 ; r + + ) {
* ( BG_GFX + r ) = * ( back + r ) ;
}
2006-07-09 11:47:17 +00:00
}
}
2006-11-25 20:35:34 +00:00
else if ( isCpuScalerEnabled ( ) )
{
2007-06-12 07:14:04 +00:00
//#define SCALER_PROFILE
2006-12-06 20:17:21 +00:00
# ifdef SCALER_PROFILE
TIMER1_CR = TIMER_ENABLE | TIMER_DIV_1024 ;
u16 t0 = TIMER1_DATA ;
# endif
2006-11-25 20:35:34 +00:00
const u8 * back = ( const u8 * ) get8BitBackBuffer ( ) ;
u16 * base = BG_GFX + 0x10000 ;
2008-05-15 22:12:51 +00:00
Rescale_320x256xPAL8_To_256x256x1555 (
base ,
back ,
256 ,
get8BitBackBufferStride ( ) ,
BG_PALETTE ,
getGameHeight ( ) ) ;
2006-12-06 20:17:21 +00:00
# ifdef SCALER_PROFILE
2007-12-09 19:33:30 +00:00
// 10 pixels : 1ms
2006-12-06 20:17:21 +00:00
u16 t1 = TIMER1_DATA ;
TIMER1_CR & = ~ TIMER_ENABLE ;
2007-02-18 20:53:06 +00:00
u32 dt = t1 - t0 ;
u32 dt_us = ( dt * 10240 ) / 334 ;
2007-12-09 19:33:30 +00:00
u32 dt_10ms = dt_us / 100 ;
int i ;
for ( i = 0 ; i < dt_10ms ; + + i )
base [ i ] = ( ( i / 10 ) & 1 ) ? 0xFFFF : 0x801F ;
for ( ; i < 256 ; + + i )
base [ i ] = 0x8000 ;
2006-12-06 20:17:21 +00:00
# endif
2006-11-25 20:35:34 +00:00
}
# ifdef HEAVY_LOGGING
consolePrintf ( " done \n " ) ;
# endif
2006-07-09 11:47:17 +00:00
}
void setShakePos ( int shakePos ) {
shakePos = shakePos ;
}
u16 * get16BitBackBuffer ( ) {
return BG_GFX + 0x20000 ;
}
2008-05-15 22:12:51 +00:00
s32 get8BitBackBufferStride ( ) {
// When the CPU scaler is enabled, the back buffer is in system RAM and is 320 pixels wide
// When the CPU scaler is disabled, the back buffer is in video memory and therefore must have a 512 pixel stride
if ( isCpuScalerEnabled ( ) ) {
return 320 ;
} else {
return 512 ;
}
}
u16 * getScalerBuffer ( ) {
return ( u16 * ) scalerBackBuffer ;
}
2006-07-09 11:47:17 +00:00
u16 * get8BitBackBuffer ( ) {
2007-02-13 21:04:31 +00:00
if ( isCpuScalerEnabled ( ) )
2008-05-15 22:12:51 +00:00
return ( u16 * ) scalerBackBuffer ;
2006-11-25 20:35:34 +00:00
else
return BG_GFX + 0x10000 ; // 16bit qty!
2006-07-09 11:47:17 +00:00
}
// The sound system in ScummVM seems to always return stereo interleaved samples.
// Here, I'm treating an 11Khz stereo stream as a 22Khz mono stream, which works sorta ok, but is
// a horrible bodge. Any advice on how to change the engine to output mono would be greatly
// appreciated.
void doSoundCallback ( ) {
2006-11-25 20:35:34 +00:00
# ifdef HEAVY_LOGGING
consolePrintf ( " doSoundCallback... " ) ;
# endif
2008-07-09 16:50:23 +00:00
if ( OSystem_DS : : instance ( ) )
if ( OSystem_DS : : instance ( ) - > getMixerImpl ( ) ) {
2006-07-09 11:47:17 +00:00
lastCallbackFrame = frameCount ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
for ( int r = IPC - > playingSection ; r < IPC - > playingSection + 4 ; r + + ) {
int chunk = r & 3 ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( IPC - > fillNeeded [ chunk ] ) {
IPC - > fillNeeded [ chunk ] = false ;
DC_FlushAll ( ) ;
2008-07-09 16:50:23 +00:00
OSystem_DS : : instance ( ) - > getMixerImpl ( ) - > mixCallback ( ( byte * ) ( soundBuffer + ( ( bufferSamples > > 2 ) * chunk ) ) , bufferSamples > > 1 ) ;
2006-07-09 11:47:17 +00:00
IPC - > fillNeeded [ chunk ] = false ;
DC_FlushAll ( ) ;
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
}
2006-11-25 20:35:34 +00:00
# ifdef HEAVY_LOGGING
consolePrintf ( " done \n " ) ;
# endif
2006-07-09 11:47:17 +00:00
}
void doTimerCallback ( ) {
if ( callback ) {
if ( callbackTimer < = 0 ) {
callbackTimer + = callbackInterval ;
callback ( callbackInterval ) ;
2008-05-15 22:12:51 +00:00
}
2006-07-09 11:47:17 +00:00
}
}
void soundUpdate ( ) {
if ( ( bufferFrame = = 0 ) ) {
// playSound(soundBuffer, (bufferSamples * 2), true);
}
// consolePrintf("%x\n", IPC->test);
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( bufferFrame = = 0 ) {
// bufferFirstHalf = true;
2008-05-15 22:12:51 +00:00
}
2006-07-09 11:47:17 +00:00
if ( bufferFrame = = bufferSize > > 1 ) {
//bufferSecondHalf = true;
2008-05-15 22:12:51 +00:00
}
2006-07-09 11:47:17 +00:00
bufferFrame + + ;
if ( bufferFrame = = bufferSize ) {
bufferFrame = 0 ;
}
}
void memoryReport ( ) {
int r = 0 ;
int * p ;
do {
p = ( int * ) malloc ( r * 8192 ) ;
free ( p ) ;
2008-05-15 22:12:51 +00:00
r + + ;
2006-07-09 11:47:17 +00:00
} while ( ( p ) & & ( r < 512 ) ) ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
int t = - 1 ;
void * block [ 1024 ] ;
do {
t + + ;
block [ t ] = ( int * ) malloc ( 4096 ) ;
2008-05-15 22:12:51 +00:00
} while ( ( t < 1024 ) & & ( block [ t ] ) ) ;
2006-07-09 11:47:17 +00:00
for ( int q = 0 ; q < t ; q + + ) {
free ( block [ q ] ) ;
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
consolePrintf ( " Free: %dK, Largest: %dK \n " , t * 4 , r * 8 ) ;
}
void addIndyFightingKeys ( ) {
OSystem_DS * system = OSystem_DS : : instance ( ) ;
2007-03-17 19:02:05 +00:00
Common : : Event event ;
2006-07-09 11:47:17 +00:00
2007-03-17 19:02:05 +00:00
event . type = Common : : EVENT_KEYDOWN ;
2006-07-09 11:47:17 +00:00
event . kbd . flags = 0 ;
2008-05-15 22:12:51 +00:00
2007-06-30 23:03:03 +00:00
// consolePrintf("Fight keys\n");
2006-07-09 11:47:17 +00:00
if ( ( getKeysDown ( ) & KEY_L ) ) {
indyFightRight = false ;
}
if ( ( getKeysDown ( ) & KEY_R ) ) {
indyFightRight = true ;
}
2007-06-30 23:03:03 +00:00
// consolePrintf("ifr:%d\n", indyFightRight);
2007-04-06 18:34:53 +00:00
if ( ( getKeysChanged ( ) & KEY_UP ) ) {
event . type = getKeyEvent ( KEY_UP ) ;
2007-08-18 11:10:41 +00:00
event . kbd . keycode = Common : : KEYCODE_8 ;
2006-07-09 11:47:17 +00:00
event . kbd . ascii = ' 8 ' ;
system - > addEvent ( event ) ;
}
2007-04-06 18:34:53 +00:00
if ( ( getKeysChanged ( ) & KEY_LEFT ) ) {
event . type = getKeyEvent ( KEY_LEFT ) ;
2007-08-18 11:10:41 +00:00
event . kbd . keycode = Common : : KEYCODE_4 ;
2006-07-09 11:47:17 +00:00
event . kbd . ascii = ' 4 ' ;
system - > addEvent ( event ) ;
}
2007-04-06 18:34:53 +00:00
if ( ( getKeysChanged ( ) & KEY_RIGHT ) ) {
event . type = getKeyEvent ( KEY_RIGHT ) ;
2007-08-18 11:10:41 +00:00
event . kbd . keycode = Common : : KEYCODE_6 ;
2006-07-09 11:47:17 +00:00
event . kbd . ascii = ' 6 ' ;
system - > addEvent ( event ) ;
2008-05-15 22:12:51 +00:00
}
2007-04-06 18:34:53 +00:00
if ( ( getKeysChanged ( ) & KEY_DOWN ) ) {
event . type = getKeyEvent ( KEY_DOWN ) ;
2007-08-18 11:10:41 +00:00
event . kbd . keycode = Common : : KEYCODE_2 ;
2006-07-09 11:47:17 +00:00
event . kbd . ascii = ' 2 ' ;
system - > addEvent ( event ) ;
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( indyFightRight ) {
2008-05-15 22:12:51 +00:00
2007-04-06 18:34:53 +00:00
if ( ( getKeysChanged ( ) & KEY_X ) ) {
event . type = getKeyEvent ( KEY_X ) ;
2007-08-18 11:10:41 +00:00
event . kbd . keycode = Common : : KEYCODE_9 ;
2006-07-09 11:47:17 +00:00
event . kbd . ascii = ' 9 ' ;
system - > addEvent ( event ) ;
}
2007-04-06 18:34:53 +00:00
if ( ( getKeysChanged ( ) & KEY_A ) ) {
event . type = getKeyEvent ( KEY_A ) ;
2007-08-18 11:10:41 +00:00
event . kbd . keycode = Common : : KEYCODE_6 ;
2006-07-09 11:47:17 +00:00
event . kbd . ascii = ' 6 ' ;
system - > addEvent ( event ) ;
}
2007-04-06 18:34:53 +00:00
if ( ( getKeysChanged ( ) & KEY_B ) ) {
event . type = getKeyEvent ( KEY_B ) ;
2007-08-18 11:10:41 +00:00
event . kbd . keycode = Common : : KEYCODE_3 ;
2006-07-09 11:47:17 +00:00
event . kbd . ascii = ' 3 ' ;
system - > addEvent ( event ) ;
2008-05-15 22:12:51 +00:00
}
2006-07-09 11:47:17 +00:00
} else {
2007-04-06 18:34:53 +00:00
if ( ( getKeysChanged ( ) & KEY_X ) ) {
event . type = getKeyEvent ( KEY_X ) ;
2007-08-18 11:10:41 +00:00
event . kbd . keycode = Common : : KEYCODE_7 ;
2006-07-09 11:47:17 +00:00
event . kbd . ascii = ' 7 ' ;
system - > addEvent ( event ) ;
}
2007-04-06 18:34:53 +00:00
if ( ( getKeysChanged ( ) & KEY_A ) ) {
event . type = getKeyEvent ( KEY_A ) ;
2007-08-18 11:10:41 +00:00
event . kbd . keycode = Common : : KEYCODE_4 ;
2006-07-09 11:47:17 +00:00
event . kbd . ascii = ' 4 ' ;
system - > addEvent ( event ) ;
}
2007-04-06 18:34:53 +00:00
if ( ( getKeysChanged ( ) & KEY_B ) ) {
event . type = getKeyEvent ( KEY_B ) ;
2007-08-18 11:10:41 +00:00
event . kbd . keycode = Common : : KEYCODE_1 ;
2006-07-09 11:47:17 +00:00
event . kbd . ascii = ' 1 ' ;
system - > addEvent ( event ) ;
2008-05-15 22:12:51 +00:00
}
2006-07-09 11:47:17 +00:00
}
2008-05-15 22:12:51 +00:00
2007-04-06 18:34:53 +00:00
if ( ( getKeysChanged ( ) & KEY_Y ) ) {
event . type = getKeyEvent ( KEY_Y ) ;
2007-08-18 11:10:41 +00:00
event . kbd . keycode = Common : : KEYCODE_5 ;
2006-07-09 11:47:17 +00:00
event . kbd . ascii = ' 5 ' ;
system - > addEvent ( event ) ;
}
2008-05-15 22:12:51 +00:00
}
2006-07-09 11:47:17 +00:00
void setKeyboardEnable ( bool en ) {
if ( en = = keyboardEnable ) return ;
keyboardEnable = en ;
u16 * backupBank = ( u16 * ) 0x6040000 ;
if ( keyboardEnable ) {
2007-12-21 18:36:40 +00:00
DS : : drawKeyboard ( 1 , 15 , backupBank ) ;
2008-05-15 22:12:51 +00:00
2007-12-21 18:36:40 +00:00
SUB_BG1_CR = BG_TILE_BASE ( 1 ) | BG_MAP_BASE ( 15 ) ;
2006-07-09 11:47:17 +00:00
if ( displayModeIs8Bit ) {
SUB_DISPLAY_CR | = DISPLAY_BG1_ACTIVE ; // Turn on keyboard layer
SUB_DISPLAY_CR & = ~ DISPLAY_BG3_ACTIVE ; // Turn off game layer
} else {
SUB_DISPLAY_CR | = DISPLAY_BG1_ACTIVE ; // Turn on keyboard layer
SUB_DISPLAY_CR & = ~ DISPLAY_BG0_ACTIVE ; // Turn off console layer
}
2008-05-15 22:12:51 +00:00
// Ensure the keyboard is on the lower screen
POWER_CR | = POWER_SWAP_LCDS ;
2006-07-09 11:47:17 +00:00
} else {
// Restore the palette that the keyboard has used
for ( int r = 0 ; r < 256 ; r + + ) {
BG_PALETTE_SUB [ r ] = BG_PALETTE [ r ] ;
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
//restoreVRAM(1, 12, backupBank);
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( displayModeIs8Bit ) {
// Copy the sub screen VRAM from the top screen - they should always be
// the same.
2007-04-06 18:34:53 +00:00
u16 * buffer = get8BitBackBuffer ( ) ;
2008-05-15 22:12:51 +00:00
s32 stride = get8BitBackBufferStride ( ) ;
2008-01-27 19:47:41 +00:00
2008-05-15 22:12:51 +00:00
for ( int y = 0 ; y < gameHeight ; y + + ) {
for ( int x = 0 ; x < gameWidth ; x + + ) {
BG_GFX_SUB [ y * 256 + x ] = buffer [ ( y * ( stride / 2 ) ) + x ] ;
}
}
/*
2007-06-18 07:06:24 +00:00
for ( int r = 0 ; r < ( 512 * 256 ) > > 1 ; r + + )
BG_GFX_SUB [ r ] = buffer [ r ] ;
2008-05-15 22:12:51 +00:00
*/
2006-07-09 11:47:17 +00:00
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
}
2008-05-15 22:12:51 +00:00
// Restore the screens so they're the right way round
if ( gameScreenSwap ) {
POWER_CR | = POWER_SWAP_LCDS ;
} else {
POWER_CR & = ~ POWER_SWAP_LCDS ;
}
2006-07-09 11:47:17 +00:00
}
}
bool getKeyboardEnable ( ) {
return keyboardEnable ;
}
bool getIsDisplayMode8Bit ( ) {
return displayModeIs8Bit ;
}
void addEventsToQueue ( ) {
2006-11-25 20:35:34 +00:00
# ifdef HEAVY_LOGGING
consolePrintf ( " addEventsToQueue \n " ) ;
# endif
2006-07-09 11:47:17 +00:00
OSystem_DS * system = OSystem_DS : : instance ( ) ;
2007-03-17 19:02:05 +00:00
Common : : Event event ;
2006-07-09 11:47:17 +00:00
2008-05-15 22:12:51 +00:00
2007-06-30 23:03:03 +00:00
# ifdef USE_PROFILER
if ( keysDown ( ) & KEY_R ) {
cygprofile_begin ( ) ;
cygprofile_enable ( ) ;
}
if ( keysDown ( ) & KEY_L ) {
cygprofile_disable ( ) ;
cygprofile_end ( ) ;
}
# endif
2006-07-09 11:47:17 +00:00
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( system - > isEventQueueEmpty ( ) ) {
/*
if ( getKeysDown ( ) & KEY_L ) {
tweak - - ;
consolePrintf ( " Tweak: %d \n " , tweak ) ;
IPC - > tweakChanged = true ;
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( getKeysDown ( ) & KEY_R ) {
tweak + + ;
consolePrintf ( " Tweak: %d \n " , tweak ) ;
IPC - > tweakChanged = true ;
}
*/
if ( ( keysHeld ( ) & KEY_L ) & & ( keysHeld ( ) & KEY_R ) ) {
memoryReport ( ) ;
}
if ( displayModeIs8Bit ) {
if ( ! indyFightState ) {
2008-05-15 22:12:51 +00:00
if ( ( ! ( getKeysHeld ( ) & KEY_L ) ) & & ( ! ( getKeysHeld ( ) & KEY_R ) ) & & ( getKeysDown ( ) & KEY_B ) ) {
2007-10-13 15:40:11 +00:00
if ( currentGame - > control = = CONT_AGI ) {
event . kbd . keycode = Common : : KEYCODE_RETURN ;
event . kbd . ascii = 13 ;
event . kbd . flags = 0 ;
} else {
2008-05-15 22:12:51 +00:00
event . kbd . keycode = Common : : KEYCODE_ESCAPE ;
event . kbd . ascii = 27 ;
2007-10-13 15:40:11 +00:00
event . kbd . flags = 0 ;
}
event . type = Common : : EVENT_KEYDOWN ;
system - > addEvent ( event ) ;
2007-04-06 18:34:53 +00:00
2007-10-13 15:40:11 +00:00
event . type = Common : : EVENT_KEYUP ;
2006-07-09 11:47:17 +00:00
system - > addEvent ( event ) ;
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( ( ! getIndyFightState ( ) ) & & ( getKeysDown ( ) & KEY_Y ) ) {
consoleEnable = ! consoleEnable ;
if ( displayModeIs8Bit ) {
displayMode8Bit ( ) ;
} else {
displayMode16Bit ( ) ;
}
}
2008-05-15 22:12:51 +00:00
2007-10-13 15:40:11 +00:00
if ( ( getKeyboardEnable ( ) ) ) {
2007-06-30 23:03:03 +00:00
event . kbd . flags = 0 ;
2007-10-13 15:40:11 +00:00
bool down = getKeysDown ( ) & ( KEY_LEFT | KEY_RIGHT | KEY_UP | KEY_DOWN ) ;
bool release = getKeysReleased ( ) & ( KEY_LEFT | KEY_RIGHT | KEY_UP | KEY_DOWN ) ;
bool shoulders = getKeysHeld ( ) & ( KEY_L | KEY_R ) ;
2007-06-30 23:03:03 +00:00
2008-05-15 22:12:51 +00:00
if ( ( down & & ( ! shoulders ) ) | | release )
2007-10-13 15:40:11 +00:00
{
2008-05-15 22:12:51 +00:00
2007-10-13 15:40:11 +00:00
if ( getKeysChanged ( ) & KEY_LEFT ) {
event . kbd . keycode = Common : : KEYCODE_LEFT ;
event . kbd . ascii = 0 ;
event . type = getKeyEvent ( KEY_LEFT ) ;
system - > addEvent ( event ) ;
}
2008-05-15 22:12:51 +00:00
2007-10-13 15:40:11 +00:00
if ( getKeysChanged ( ) & KEY_RIGHT ) {
event . kbd . keycode = Common : : KEYCODE_RIGHT ;
event . kbd . ascii = 0 ;
event . type = getKeyEvent ( KEY_RIGHT ) ;
system - > addEvent ( event ) ;
}
2008-05-15 22:12:51 +00:00
2007-10-13 15:40:11 +00:00
if ( getKeysChanged ( ) & KEY_UP ) {
event . kbd . keycode = Common : : KEYCODE_UP ;
event . kbd . ascii = 0 ;
event . type = getKeyEvent ( KEY_UP ) ;
system - > addEvent ( event ) ;
}
2008-05-15 22:12:51 +00:00
2007-10-13 15:40:11 +00:00
if ( getKeysChanged ( ) & KEY_DOWN ) {
event . kbd . keycode = Common : : KEYCODE_DOWN ;
event . kbd . ascii = 0 ;
event . type = getKeyEvent ( KEY_DOWN ) ;
system - > addEvent ( event ) ;
}
2007-06-30 23:03:03 +00:00
}
2008-05-15 22:12:51 +00:00
2007-06-30 23:03:03 +00:00
}
2008-05-15 22:12:51 +00:00
2007-06-30 23:03:03 +00:00
if ( ! ( ( getKeysHeld ( ) & KEY_L ) | | ( getKeysHeld ( ) & KEY_R ) ) & & ( ! getIndyFightState ( ) ) & & ( ! getKeyboardEnable ( ) ) ) {
2006-07-09 11:47:17 +00:00
if ( ( getKeysDown ( ) & KEY_A ) & & ( ! indyFightState ) ) {
gameScreenSwap = ! gameScreenSwap ;
2008-01-27 19:47:41 +00:00
2008-05-15 22:12:51 +00:00
if ( gameScreenSwap ) {
POWER_CR | = POWER_SWAP_LCDS ;
} else {
POWER_CR & = ~ POWER_SWAP_LCDS ;
}
}
2006-07-09 11:47:17 +00:00
if ( ! getPenHeld ( ) | | ( mouseMode ! = MOUSE_HOVER ) ) {
if ( getKeysDown ( ) & KEY_LEFT ) {
mouseMode = MOUSE_LEFT ;
}
2007-06-30 23:03:03 +00:00
2007-10-13 15:40:11 +00:00
if ( rightButtonDown )
{
Common : : Event event ;
event . mouse = Common : : Point ( getPenX ( ) , getPenY ( ) ) ;
event . type = Common : : EVENT_RBUTTONUP ;
system - > addEvent ( event ) ;
rightButtonDown = false ;
}
2008-05-15 22:12:51 +00:00
2007-10-13 15:40:11 +00:00
2006-07-09 11:47:17 +00:00
if ( getKeysDown ( ) & KEY_RIGHT ) {
2007-10-13 15:40:11 +00:00
if ( ( currentGame - > control ! = CONT_SCUMM_SAMNMAX ) & & ( currentGame - > control ! = CONT_FUTURE_WARS ) & & ( currentGame - > control ! = CONT_GOBLINS ) ) {
2006-07-09 11:47:17 +00:00
mouseMode = MOUSE_RIGHT ;
} else {
// If we're playing sam and max, click and release the right mouse
// button to change verb
2007-03-17 19:02:05 +00:00
Common : : Event event ;
2007-06-30 23:03:03 +00:00
if ( currentGame - > control = = CONT_FUTURE_WARS ) {
event . mouse = Common : : Point ( 320 - 128 , 200 - 128 ) ;
event . type = Common : : EVENT_MOUSEMOVE ;
system - > addEvent ( event ) ;
} else {
event . mouse = Common : : Point ( getPenX ( ) , getPenY ( ) ) ;
}
2008-05-15 22:12:51 +00:00
2007-10-13 15:40:11 +00:00
rightButtonDown = true ;
2007-06-30 23:03:03 +00:00
2008-05-15 22:12:51 +00:00
2007-03-17 19:02:05 +00:00
event . type = Common : : EVENT_RBUTTONDOWN ;
2006-07-09 11:47:17 +00:00
system - > addEvent ( event ) ;
2008-05-15 22:12:51 +00:00
2007-10-13 15:40:11 +00:00
//event.type = Common::EVENT_RBUTTONUP;
//system->addEvent(event);
2006-07-09 11:47:17 +00:00
}
}
2007-10-13 15:40:11 +00:00
2006-07-09 11:47:17 +00:00
if ( getKeysDown ( ) & KEY_UP ) {
mouseMode = MOUSE_HOVER ;
}
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
}
if ( ( getKeysDown ( ) & KEY_SELECT ) ) {
//scaledMode = !scaledMode;
//scY = 4;
showOptionsDialog ( ) ;
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( ! getIndyFightState ( ) & & ! ( ( getKeysHeld ( ) & KEY_L ) | | ( getKeysHeld ( ) & KEY_R ) ) & & ( getKeysDown ( ) & KEY_X ) ) {
setKeyboardEnable ( ! keyboardEnable ) ;
}
2008-05-15 22:12:51 +00:00
updateStatus ( ) ;
2007-03-17 19:02:05 +00:00
Common : : Event event ;
2006-07-09 11:47:17 +00:00
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( ! keyboardEnable ) {
2007-06-30 23:03:03 +00:00
if ( ( ! ( getKeysHeld ( ) & KEY_L ) ) & & ( ! ( getKeysHeld ( ) & KEY_R ) ) ) {
event . type = Common : : EVENT_MOUSEMOVE ;
event . mouse = Common : : Point ( getPenX ( ) , getPenY ( ) ) ;
system - > addEvent ( event ) ;
//consolePrintf("x=%d y=%d \n", getPenX(), getPenY());
}
2006-07-09 11:47:17 +00:00
if ( ( mouseMode ! = MOUSE_HOVER ) | | ( ! displayModeIs8Bit ) ) {
2008-05-15 22:12:51 +00:00
if ( getPenDown ( ) & & ( ! ( getKeysHeld ( ) & KEY_L ) ) & & ( ! ( getKeysHeld ( ) & KEY_R ) ) ) {
2007-03-18 21:55:57 +00:00
event . type = ( ( mouseMode = = MOUSE_LEFT ) | | ( ! displayModeIs8Bit ) ) ? Common : : EVENT_LBUTTONDOWN : Common : : EVENT_RBUTTONDOWN ;
2006-07-09 11:47:17 +00:00
event . mouse = Common : : Point ( getPenX ( ) , getPenY ( ) ) ;
system - > addEvent ( event ) ;
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( getPenReleased ( ) ) {
2007-03-18 21:55:57 +00:00
event . type = mouseMode = = MOUSE_LEFT ? Common : : EVENT_LBUTTONUP : Common : : EVENT_RBUTTONUP ;
2006-07-09 11:47:17 +00:00
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
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( getPenHeld ( ) ) {
if ( getKeysDown ( ) & KEY_LEFT ) {
2007-03-17 19:02:05 +00:00
event . type = Common : : EVENT_LBUTTONDOWN ;
2006-07-09 11:47:17 +00:00
event . mouse = Common : : Point ( getPenX ( ) , getPenY ( ) ) ;
system - > addEvent ( event ) ;
}
2008-05-15 22:12:51 +00:00
if ( getKeysReleased ( ) & KEY_LEFT ) {
2007-03-17 19:02:05 +00:00
event . type = Common : : EVENT_LBUTTONUP ;
2006-07-09 11:47:17 +00:00
event . mouse = Common : : Point ( getPenX ( ) , getPenY ( ) ) ;
system - > addEvent ( event ) ;
2008-05-15 22:12:51 +00:00
}
2008-01-27 19:47:41 +00:00
2006-07-09 11:47:17 +00:00
if ( getKeysDown ( ) & KEY_RIGHT ) {
2007-03-17 19:02:05 +00:00
event . type = Common : : EVENT_RBUTTONDOWN ;
2006-07-09 11:47:17 +00:00
event . mouse = Common : : Point ( getPenX ( ) , getPenY ( ) ) ;
system - > addEvent ( event ) ;
}
2008-05-15 22:12:51 +00:00
if ( getKeysReleased ( ) & KEY_RIGHT ) {
2007-03-17 19:02:05 +00:00
event . type = Common : : EVENT_RBUTTONUP ;
2006-07-09 11:47:17 +00:00
event . mouse = Common : : Point ( getPenX ( ) , getPenY ( ) ) ;
system - > addEvent ( event ) ;
2008-05-15 22:12:51 +00:00
}
2006-07-09 11:47:17 +00:00
}
}
2008-05-15 22:12:51 +00:00
2007-04-06 18:34:53 +00:00
if ( ( ( ! ( getKeysHeld ( ) & KEY_L ) ) & & ( ! ( getKeysHeld ( ) & KEY_R ) ) | | ( indyFightState ) ) & & ( displayModeIs8Bit ) ) {
2006-07-09 11:47:17 +00:00
// Controls specific to the control method
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( currentGame - > control = = CONT_SKY ) {
2007-06-30 16:11:20 +00:00
// Extra controls for Beneath a Steel Sky
2006-07-09 11:47:17 +00:00
if ( ( getKeysDown ( ) & KEY_DOWN ) ) {
penY = 0 ;
2006-11-03 23:16:29 +00:00
penX = 160 ; // Show inventory by moving mouse onto top line
2006-07-09 11:47:17 +00:00
}
}
if ( currentGame - > control = = CONT_SIMON ) {
// Extra controls for Simon the Sorcerer
2007-10-13 15:40:11 +00:00
if ( ( getKeysDown ( ) & KEY_DOWN ) ) {
2007-03-17 19:02:05 +00:00
Common : : Event event ;
2008-05-15 22:12:51 +00:00
2007-10-13 15:40:11 +00:00
event . type = Common : : EVENT_KEYDOWN ;
2007-08-18 11:10:41 +00:00
event . kbd . keycode = Common : : KEYCODE_F10 ; // F10 or # - show hotspots
event . kbd . ascii = Common : : ASCII_F10 ;
2006-07-09 11:47:17 +00:00
event . kbd . flags = 0 ;
system - > addEvent ( event ) ;
// consolePrintf("F10\n");
2007-10-13 15:40:11 +00:00
event . type = Common : : EVENT_KEYUP ;
system - > addEvent ( event ) ;
2006-07-09 11:47:17 +00:00
}
}
2007-10-13 15:40:11 +00:00
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( currentGame - > control = = CONT_SCUMM_ORIGINAL ) {
// Extra controls for Scumm v1-5 games
2007-10-13 15:40:11 +00:00
if ( ( getKeysDown ( ) & KEY_DOWN ) ) {
2007-03-17 19:02:05 +00:00
Common : : Event event ;
2008-05-15 22:12:51 +00:00
2007-10-13 15:40:11 +00:00
event . type = Common : : EVENT_KEYDOWN ;
2007-08-18 11:10:41 +00:00
event . kbd . keycode = Common : : KEYCODE_PERIOD ; // Full stop - skips current dialogue line
2006-07-09 11:47:17 +00:00
event . kbd . ascii = ' . ' ;
event . kbd . flags = 0 ;
system - > addEvent ( event ) ;
2007-10-13 15:40:11 +00:00
event . type = Common : : EVENT_KEYUP ;
system - > addEvent ( event ) ;
2006-07-09 11:47:17 +00:00
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( indyFightState ) {
addIndyFightingKeys ( ) ;
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
}
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( ! displayModeIs8Bit ) {
// Front end controls
2008-05-15 22:12:51 +00:00
2007-04-06 18:34:53 +00:00
if ( leftHandedSwap ( getKeysChanged ( ) ) & KEY_UP ) {
event . type = getKeyEvent ( leftHandedSwap ( KEY_UP ) ) ;
2007-06-22 20:04:44 +00:00
event . kbd . keycode = Common : : KEYCODE_UP ;
2006-07-09 11:47:17 +00:00
event . kbd . ascii = 0 ;
event . kbd . flags = 0 ;
system - > addEvent ( event ) ;
}
2007-04-06 18:34:53 +00:00
if ( leftHandedSwap ( getKeysChanged ( ) ) & KEY_DOWN ) {
event . type = getKeyEvent ( leftHandedSwap ( KEY_DOWN ) ) ;
2007-06-22 20:04:44 +00:00
event . kbd . keycode = Common : : KEYCODE_DOWN ;
2006-07-09 11:47:17 +00:00
event . kbd . ascii = 0 ;
event . kbd . flags = 0 ;
system - > addEvent ( event ) ;
}
if ( leftHandedSwap ( getKeysDown ( ) ) & KEY_A ) {
2007-10-13 15:40:11 +00:00
event . type = Common : : EVENT_KEYDOWN ;
2007-06-22 20:04:44 +00:00
event . kbd . keycode = Common : : KEYCODE_RETURN ;
2006-07-09 11:47:17 +00:00
event . kbd . ascii = 0 ;
event . kbd . flags = 0 ;
system - > addEvent ( event ) ;
2007-10-13 15:40:11 +00:00
event . type = Common : : EVENT_KEYUP ;
system - > addEvent ( event ) ;
2006-07-09 11:47:17 +00:00
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
}
2008-05-15 22:12:51 +00:00
2007-04-06 18:34:53 +00:00
if ( ( getKeysChanged ( ) & KEY_START ) ) {
event . type = getKeyEvent ( KEY_START ) ;
2007-06-30 23:03:03 +00:00
if ( currentGame - > control = = CONT_FUTURE_WARS ) {
event . kbd . keycode = Common : : KEYCODE_F10 ;
event . kbd . ascii = Common : : ASCII_F10 ;
} else if ( currentGame - > control = = CONT_GOBLINS ) {
event . kbd . keycode = Common : : KEYCODE_F1 ;
event . kbd . ascii = Common : : ASCII_F1 ;
// consolePrintf("!!!!!F1!!!!!");
2007-10-13 15:40:11 +00:00
} else if ( currentGame - > control = = CONT_AGI ) {
event . kbd . keycode = Common : : KEYCODE_ESCAPE ;
event . kbd . ascii = 27 ;
2007-06-30 23:03:03 +00:00
} else {
2007-10-13 15:40:11 +00:00
event . kbd . keycode = Common : : KEYCODE_F5 ; // F5
2007-06-30 23:03:03 +00:00
event . kbd . ascii = Common : : ASCII_F5 ;
// consolePrintf("!!!!!F5!!!!!");
}
2006-07-09 11:47:17 +00:00
event . kbd . flags = 0 ;
system - > addEvent ( event ) ;
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( keyboardEnable ) {
DS : : addKeyboardEvents ( ) ;
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
consumeKeys ( ) ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
consumePenEvents ( ) ;
}
}
2007-04-06 18:34:53 +00:00
2008-05-15 22:12:51 +00:00
2007-04-06 18:34:53 +00:00
void triggerIcon ( int imageNum ) {
triggeredIcon = imageNum ;
2008-05-15 22:12:51 +00:00
triggeredIconTimeout = 120 ;
2007-04-06 18:34:53 +00:00
}
2008-05-15 22:12:51 +00:00
2007-04-06 18:34:53 +00:00
void setIcon ( int num , int x , int y , int imageNum , int flags , bool enable ) {
2008-05-15 22:12:51 +00:00
sprites [ num ] . attribute [ 0 ] = ATTR0_BMP | ( enable ? y : 192 ) | ( ! enable ? ATTR0_DISABLED : 0 ) ;
2007-04-06 18:34:53 +00:00
sprites [ num ] . attribute [ 1 ] = ATTR1_SIZE_32 | x | flags ;
sprites [ num ] . attribute [ 2 ] = ATTR2_ALPHA ( 1 ) | ( imageNum * 16 ) ;
}
2007-06-30 23:03:03 +00:00
void setIconMain ( int num , int x , int y , int imageNum , int flags , bool enable ) {
2008-05-15 22:12:51 +00:00
spritesMain [ num ] . attribute [ 0 ] = ATTR0_BMP | ( y & 0xFF ) | ( ! enable ? ATTR0_DISABLED : 0 ) ;
2007-06-30 23:03:03 +00:00
spritesMain [ num ] . attribute [ 1 ] = ATTR1_SIZE_32 | ( x & 0x1FF ) | flags ;
spritesMain [ num ] . attribute [ 2 ] = ATTR2_ALPHA ( 1 ) | ( imageNum * 16 ) ;
}
2006-07-09 11:47:17 +00:00
void updateStatus ( ) {
int offs ;
if ( displayModeIs8Bit ) {
switch ( mouseMode ) {
case MOUSE_LEFT : {
2007-04-06 18:34:53 +00:00
offs = 1 ;
2006-07-09 11:47:17 +00:00
break ;
}
case MOUSE_RIGHT : {
2007-04-06 18:34:53 +00:00
offs = 2 ;
2006-07-09 11:47:17 +00:00
break ;
}
case MOUSE_HOVER : {
offs = 0 ;
break ;
}
default : {
// Nothing!
offs = 0 ;
break ;
}
}
2008-05-15 22:12:51 +00:00
2007-04-06 18:34:53 +00:00
setIcon ( 0 , 208 , 150 , offs , 0 , true ) ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( indyFightState ) {
2007-04-06 18:34:53 +00:00
setIcon ( 1 , ( 190 - 32 ) , 150 , 3 , ( indyFightRight ? 0 : ATTR1_FLIP_X ) , true ) ;
2007-06-30 23:03:03 +00:00
// consolePrintf("%d\n", indyFightRight);
2006-07-09 11:47:17 +00:00
} else {
2007-04-06 18:34:53 +00:00
// setIcon(1, 0, 0, 0, 0, false);
2006-07-09 11:47:17 +00:00
}
2008-05-15 22:12:51 +00:00
2007-04-06 18:34:53 +00:00
if ( triggeredIconTimeout > 0 ) {
triggeredIconTimeout - - ;
setIcon ( 4 , 16 , 150 , triggeredIcon , 0 , true ) ;
} else {
setIcon ( 4 , 0 , 0 , 0 , 0 , false ) ;
}
2007-06-30 23:03:03 +00:00
2006-07-09 11:47:17 +00:00
} else {
2007-04-06 18:34:53 +00:00
setIcon ( 0 , 0 , 0 , 0 , 0 , false ) ;
setIcon ( 1 , 0 , 0 , 0 , 0 , false ) ;
setIcon ( 2 , 0 , 0 , 0 , 0 , false ) ;
setIcon ( 3 , 0 , 0 , 0 , 0 , false ) ;
setIcon ( 4 , 0 , 0 , 0 , 0 , false ) ;
2006-07-09 11:47:17 +00:00
}
if ( ( keyboardIcon ) & & ( ! keyboardEnable ) & & ( ! displayModeIs8Bit ) ) {
2007-06-30 23:03:03 +00:00
// spritesMain[0].attribute[0] = ATTR0_BMP | 160;
// spritesMain[0].attribute[1] = ATTR1_SIZE_32 | 0;
// spritesMain[0].attribute[2] = ATTR2_ALPHA(1) | 64;
setIconMain ( 0 , 0 , 160 , 4 , 0 , true ) ;
2006-07-09 11:47:17 +00:00
} else {
2007-06-30 23:03:03 +00:00
// spritesMain[0].attribute[0] = ATTR0_DISABLED;
// spritesMain[0].attribute[1] = 0;
// spritesMain[0].attribute[2] = 0;
2008-05-31 19:24:26 +00:00
// spritesMain[0].filler = 0;
2007-06-30 23:03:03 +00:00
setIconMain ( 0 , 0 , 0 , 0 , 0 , false ) ;
2006-07-09 11:47:17 +00:00
}
}
void soundBufferEmptyHandler ( ) {
REG_IF = IRQ_TIMER2 ;
if ( soundHiPart ) {
// bufferSecondHalf = true;
} else {
// bufferFirstHalf = true;
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
soundHiPart = ! soundHiPart ;
}
void setMainScreenScroll ( int x , int y ) {
2008-05-15 22:12:51 +00:00
/* if (gameScreenSwap) {
2006-07-09 11:47:17 +00:00
SUB_BG3_CX = x + ( ( ( frameCount & 1 ) = = 0 ) ? 64 : 0 ) ;
SUB_BG3_CY = y ;
2008-05-15 22:12:51 +00:00
} else */ {
2006-07-09 11:47:17 +00:00
BG3_CX = x + ( ( ( frameCount & 1 ) = = 0 ) ? 64 : 0 ) ;
BG3_CY = y ;
2008-05-15 22:12:51 +00:00
if ( ! gameScreenSwap ) {
touchX = x > > 8 ;
touchY = y > > 8 ;
}
2006-07-09 11:47:17 +00:00
}
}
void setMainScreenScale ( int x , int y ) {
2008-05-15 22:12:51 +00:00
/* if (gameScreenSwap) {
2006-07-09 11:47:17 +00:00
SUB_BG3_XDX = x ;
SUB_BG3_XDY = 0 ;
SUB_BG3_YDX = 0 ;
SUB_BG3_YDY = y ;
2008-05-15 22:12:51 +00:00
} else */ {
2007-02-13 21:04:31 +00:00
if ( isCpuScalerEnabled ( ) & & ( x = = 320 ) )
2006-10-05 22:44:11 +00:00
{
BG3_XDX = 256 ;
BG3_XDY = 0 ;
BG3_YDX = 0 ;
BG3_YDY = y ;
}
else
2008-05-15 22:12:51 +00:00
{
2006-10-05 22:44:11 +00:00
BG3_XDX = x ;
BG3_XDY = 0 ;
BG3_YDX = 0 ;
BG3_YDY = y ;
}
2008-05-15 22:12:51 +00:00
if ( ! gameScreenSwap ) {
touchScX = x ;
touchScY = y ;
}
2006-07-09 11:47:17 +00:00
}
}
2007-04-06 18:34:53 +00:00
void setZoomedScreenScroll ( int x , int y , bool shake ) {
2008-05-15 22:12:51 +00:00
/* if (gameScreenSwap) {
2007-04-06 18:34:53 +00:00
BG3_CX = x + ( ( shake & & ( ( frameCount & 1 ) = = 0 ) ) ? 64 : 0 ) ;
2006-07-09 11:47:17 +00:00
BG3_CY = y ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
touchX = x > > 8 ;
touchY = y > > 8 ;
2008-05-15 22:12:51 +00:00
} else */ {
if ( gameScreenSwap ) {
touchX = x > > 8 ;
touchY = y > > 8 ;
}
2007-04-06 18:34:53 +00:00
SUB_BG3_CX = x + ( ( shake & & ( frameCount & 1 ) = = 0 ) ? 64 : 0 ) ;
2006-07-09 11:47:17 +00:00
SUB_BG3_CY = y ;
}
}
void setZoomedScreenScale ( int x , int y ) {
2008-05-15 22:12:51 +00:00
/* if (gameScreenSwap) {
2006-07-09 11:47:17 +00:00
BG3_XDX = x ;
BG3_XDY = 0 ;
BG3_YDX = 0 ;
BG3_YDY = y ;
2008-05-15 22:12:51 +00:00
} else */ {
if ( gameScreenSwap ) {
touchScX = x ;
touchScY = y ;
}
2006-07-09 11:47:17 +00:00
SUB_BG3_XDX = x ;
SUB_BG3_XDY = 0 ;
SUB_BG3_YDX = 0 ;
SUB_BG3_YDY = y ;
}
}
2007-06-30 23:03:03 +00:00
# ifdef USE_PROFILER
void VBlankHandler ( void ) __attribute__ ( ( no_instrument_function ) ) ;
# endif
2006-07-09 11:47:17 +00:00
void VBlankHandler ( void ) {
// BG_PALETTE[0] = RGB15(31, 31, 31);
// if (*((int *) (0x023FFF00)) != 0xBEEFCAFE) {
// consolePrintf("Guard band overwritten!");
// }
2006-11-25 20:35:34 +00:00
//consolePrintf("X:%d Y:%d\n", getPenX(), getPenY());
2006-07-09 11:47:17 +00:00
2006-11-03 23:16:29 +00:00
static bool firstTime = true ;
// This is to ensure that the ARM7 vblank handler runs before this one.
// Fixes the problem with the MMD when the screens swap over on load.
if ( firstTime ) {
firstTime = false ;
return ;
}
2006-07-09 11:47:17 +00:00
IPC - > tweak = tweak ;
soundUpdate ( ) ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( ( ! gameScreenSwap ) & & ( ! ( getKeysHeld ( ) & KEY_L ) & & ! ( getKeysHeld ( ) & KEY_R ) ) ) {
if ( currentGame ) {
if ( currentGame - > control ! = CONT_SCUMM_SAMNMAX ) {
if ( getPenHeld ( ) & & ( getPenY ( ) < SCUMM_GAME_HEIGHT ) ) {
setTopScreenTarget ( getPenX ( ) , getPenY ( ) ) ;
}
} else {
if ( getPenHeld ( ) ) {
setTopScreenTarget ( getPenX ( ) , getPenY ( ) ) ;
}
}
}
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
penUpdate ( ) ;
keysUpdate ( ) ;
frameCount + + ;
2008-05-15 22:12:51 +00:00
2007-06-30 23:03:03 +00:00
if ( ( cursorEnable ) & & ( mouseCursorVisible ) )
{
if ( ! keyboardEnable ) {
storedMouseX = penX ;
storedMouseY = penY ;
}
setIconMain ( 3 , storedMouseX - mouseHotspotX , storedMouseY - mouseHotspotY , 8 , 0 , true ) ;
}
else
{
setIconMain ( 3 , 0 , 0 , 0 , 0 , false ) ;
}
2006-07-09 11:47:17 +00:00
if ( callback ) {
callbackTimer - = FRAME_TIME ;
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( ( getKeysHeld ( ) & KEY_L ) | | ( getKeysHeld ( ) & KEY_R ) ) {
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( ( ! dragging ) & & ( getPenHeld ( ) ) & & ( penDownFrames > 5 ) ) {
dragging = true ;
dragStartX = penX ;
dragStartY = penY ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( gameScreenSwap ) {
dragScX = subScTargetX ;
dragScY = subScTargetY ;
} else {
dragScX = scX ;
2008-05-15 22:12:51 +00:00
dragScY = scY ;
}
2006-07-09 11:47:17 +00:00
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( ( dragging ) & & ( ! getPenHeld ( ) ) ) {
dragging = false ;
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( dragging ) {
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( gameScreenSwap ) {
subScTargetX = dragScX + ( ( dragStartX - penX ) < < 8 ) ;
subScTargetY = dragScY + ( ( dragStartY - penY ) < < 8 ) ;
} else {
scX = dragScX + ( ( dragStartX - penX ) ) ;
scY = dragScY + ( ( dragStartY - penY ) ) ;
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
// consolePrintf("X:%d Y:%d\n", dragStartX - penX, dragStartY - penY);
}
2008-05-15 22:12:51 +00:00
}
2006-07-09 11:47:17 +00:00
/* if ((frameCount & 1) == 0) {
SUB_BG3_CX = subScX ;
} else {
SUB_BG3_CX = subScX + 64 ;
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
SUB_BG3_CY = subScY + ( shakePos < < 8 ) ; */
/*SUB_BG3_XDX = (int) (subScreenWidth / 256.0f * 256);
SUB_BG3_XDY = 0 ;
SUB_BG3_YDX = 0 ;
SUB_BG3_YDY = ( int ) ( subScreenHeight / 192.0f * 256 ) ; */
2006-11-03 23:16:29 +00:00
static int ratio = ( 320 < < 8 ) / SCUMM_GAME_WIDTH ;
2008-05-15 22:12:51 +00:00
2007-04-06 18:34:53 +00:00
bool zooming = false ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( ( getKeysHeld ( ) & KEY_L ) | | ( getKeysHeld ( ) & KEY_R ) ) {
2006-11-03 23:16:29 +00:00
if ( ( getKeysHeld ( ) & KEY_A ) & & ( subScreenScale < ratio ) ) {
2007-04-06 18:34:53 +00:00
subScreenScale + = 1 ;
zooming = true ;
2006-07-09 11:47:17 +00:00
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( ( getKeysHeld ( ) & KEY_B ) & & ( subScreenScale > 128 ) ) {
2007-04-06 18:34:53 +00:00
subScreenScale - = 1 ;
zooming = true ;
2006-07-09 11:47:17 +00:00
}
2006-11-03 23:16:29 +00:00
}
2006-07-09 11:47:17 +00:00
2008-05-15 22:12:51 +00:00
2006-11-03 23:16:29 +00:00
int xCenter = subScTargetX + ( ( subScreenWidth > > 1 ) < < 8 ) ;
int yCenter = subScTargetY + ( ( subScreenHeight > > 1 ) < < 8 ) ;
2007-04-06 18:34:53 +00:00
2008-05-15 22:12:51 +00:00
2006-11-03 23:16:29 +00:00
if ( twoHundredPercentFixedScale ) {
subScreenWidth = 256 > > 1 ;
subScreenHeight = 192 > > 1 ;
} else {
2007-04-06 18:34:53 +00:00
subScreenWidth = ( ( ( SCUMM_GAME_HEIGHT * 256 ) / 192 ) * subScreenScale ) > > 8 ;
2006-11-03 23:16:29 +00:00
subScreenHeight = SCUMM_GAME_HEIGHT * subScreenScale > > 8 ;
2008-05-15 22:12:51 +00:00
2007-04-06 18:34:53 +00:00
if ( ( ( subScreenWidth ) > 256 - 8 ) & & ( ( subScreenWidth ) < 256 + 8 ) ) {
subScreenWidth = 256 ;
subScreenHeight = 192 ;
if ( zooming ) {
subScX = subScTargetX ;
subScY = subScTargetY ;
2008-05-15 22:12:51 +00:00
triggerIcon ( 5 ) ;
2007-04-06 18:34:53 +00:00
}
} else if ( ( ( subScreenWidth ) > 128 - 8 ) & & ( ( subScreenWidth ) < 128 + 8 ) ) {
subScreenWidth = 128 ;
subScreenHeight = 96 ;
if ( zooming ) {
subScX = subScTargetX ;
subScY = subScTargetY ;
2007-06-30 23:03:03 +00:00
triggerIcon ( 6 ) ;
2007-04-06 18:34:53 +00:00
}
} else if ( subScreenWidth > 256 ) {
subScreenWidth = 320 ;
subScreenHeight = 200 ;
if ( zooming ) {
subScX = subScTargetX ;
subScY = subScTargetY ;
2007-06-30 23:03:03 +00:00
triggerIcon ( 7 ) ;
2007-04-06 18:34:53 +00:00
}
} else {
2007-06-30 23:03:03 +00:00
//triggerIcon(-1);
2007-04-06 18:34:53 +00:00
}
2006-07-09 11:47:17 +00:00
}
2008-05-15 22:12:51 +00:00
2007-04-06 18:34:53 +00:00
2006-11-03 23:16:29 +00:00
subScTargetX = xCenter - ( ( subScreenWidth > > 1 ) < < 8 ) ;
subScTargetY = yCenter - ( ( subScreenHeight > > 1 ) < < 8 ) ;
2008-05-15 22:12:51 +00:00
2006-11-03 23:16:29 +00:00
2008-05-15 22:12:51 +00:00
2006-11-03 23:16:29 +00:00
if ( subScTargetX < 0 ) subScTargetX = 0 ;
if ( subScTargetX > ( gameWidth - subScreenWidth ) < < 8 ) subScTargetX = ( gameWidth - subScreenWidth ) < < 8 ;
if ( subScTargetY < 0 ) subScTargetY = 0 ;
if ( subScTargetY > ( gameHeight - subScreenHeight ) < < 8 ) subScTargetY = ( gameHeight - subScreenHeight ) < < 8 ;
2006-07-09 11:47:17 +00:00
subScX + = ( subScTargetX - subScX ) > > 2 ;
subScY + = ( subScTargetY - subScY ) > > 2 ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( displayModeIs8Bit ) {
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( ( getKeysHeld ( ) & KEY_L ) | | ( getKeysHeld ( ) & KEY_R ) ) {
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
int offsX = 0 , offsY = 0 ;
if ( getKeysHeld ( ) & KEY_LEFT ) {
offsX - = 1 ;
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( getKeysHeld ( ) & KEY_RIGHT ) {
offsX + = 1 ;
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( getKeysHeld ( ) & KEY_UP ) {
offsY - = 1 ;
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( getKeysHeld ( ) & KEY_DOWN ) {
offsY + = 1 ;
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( ( ( gameScreenSwap ) & & ( getKeysHeld ( ) & KEY_L ) ) | | ( ( ! gameScreenSwap ) & & ( getKeysHeld ( ) & KEY_R ) ) ) {
subScTargetX + = offsX < < 8 ;
subScTargetY + = offsY < < 8 ;
} else {
scX + = offsX ;
scY + = offsY ;
}
}
if ( ! scaledMode ) {
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( scX + 256 > gameWidth - 1 ) {
scX = gameWidth - 1 - 256 ;
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( scX < 0 ) {
scX = 0 ;
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( scY + 192 > gameHeight - 1 ) {
scY = gameHeight - 1 - 192 ;
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( scY < 0 ) {
scY = 0 ;
}
2008-05-15 22:12:51 +00:00
2007-04-06 18:34:53 +00:00
setZoomedScreenScroll ( subScX , subScY , ( subScreenWidth ! = 256 ) & & ( subScreenWidth ! = 128 ) ) ;
setZoomedScreenScale ( subScreenWidth , ( ( subScreenHeight * ( 256 < < 8 ) ) / 192 ) > > 8 ) ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
setMainScreenScroll ( scX < < 8 , ( scY < < 8 ) + ( shakePos < < 8 ) ) ;
setMainScreenScale ( 256 , 256 ) ; // 1:1 scale
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
} else {
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( scY > gameHeight - 192 - 1 ) {
scY = gameHeight - 192 - 1 ;
}
if ( scY < 0 ) {
scY = 0 ;
}
2008-05-15 22:12:51 +00:00
2007-04-06 18:34:53 +00:00
setZoomedScreenScroll ( subScX , subScY , ( subScreenWidth ! = 256 ) & & ( subScreenWidth ! = 128 ) ) ;
setZoomedScreenScale ( subScreenWidth , ( ( subScreenHeight * ( 256 < < 8 ) ) / 192 ) > > 8 ) ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
setMainScreenScroll ( 64 , ( scY < < 8 ) + ( shakePos < < 8 ) ) ;
setMainScreenScale ( 320 , 256 ) ; // 1:1 scale
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
}
} else {
2007-04-06 18:34:53 +00:00
setZoomedScreenScroll ( 0 , 0 , true ) ;
2006-07-09 11:47:17 +00:00
setZoomedScreenScale ( 320 , 256 ) ;
setMainScreenScroll ( 0 , 0 ) ;
setMainScreenScale ( 320 , 256 ) ; // 1:1 scale
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
// Enable on screen keyboard when pen taps icon
if ( ( keyboardIcon ) & & ( penX < 32 ) & & ( penY > 160 ) & & ( penHeld ) ) {
setKeyboardEnable ( true ) ;
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( keyboardEnable ) {
if ( DS : : getKeyboardClosed ( ) ) {
setKeyboardEnable ( false ) ;
}
}
updateOAM ( ) ;
//PALETTE[0] = RGB15(0, 0, 0);
REG_IF = IRQ_VBLANK ;
}
int getMillis ( ) {
return currentTimeMillis ;
// return frameCount * FRAME_TIME;
}
2006-10-25 19:18:38 +00:00
void setTimerCallback ( OSystem_DS : : TimerProc proc , int interval ) {
2006-07-09 11:47:17 +00:00
// consolePrintf("Set timer proc %x, int %d\n", proc, interval);
callback = proc ;
callbackInterval = interval ;
callbackTimer = interval ;
}
void timerTickHandler ( ) {
REG_IF = IRQ_TIMER0 ;
if ( ( callback ) & & ( callbackTimer > 0 ) ) {
callbackTimer - - ;
}
currentTimeMillis + + ;
}
void setTalkPos ( int x , int y ) {
// if (gameID != Scumm::GID_SAMNMAX) {
// setTopScreenTarget(x, 0);
// } else {
setTopScreenTarget ( x , y ) ;
// }
}
void setTopScreenTarget ( int x , int y ) {
subScTargetX = ( x - ( subScreenWidth > > 1 ) ) ;
subScTargetY = ( y - ( subScreenHeight > > 1 ) ) ;
if ( subScTargetX < 0 ) subScTargetX = 0 ;
if ( subScTargetX > gameWidth - subScreenWidth ) subScTargetX = gameWidth - subScreenWidth ;
if ( subScTargetY < 0 ) subScTargetY = 0 ;
if ( subScTargetY > gameHeight - subScreenHeight ) subScTargetY = gameHeight - subScreenHeight ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
subScTargetX < < = 8 ;
subScTargetY < < = 8 ;
}
2007-06-30 23:03:03 +00:00
# ifdef USE_PROFILER
void hBlankHanlder ( ) __attribute__ ( ( no_instrument_function ) ) ;
void hBlankHandler ( ) {
hBlankCount + + ;
}
# endif
2008-05-15 22:12:51 +00:00
void uploadSpriteGfx ( ) {
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 ;
for ( int r = 32 * 256 ; r > = 0 ; r - - ) {
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 ) ;
}
}
2006-07-09 11:47:17 +00:00
void initHardware ( ) {
// Guard band
//((int *) (0x023FFF00)) = 0xBEEFCAFE;
penInit ( ) ;
powerON ( POWER_ALL ) ;
2008-05-15 22:12:51 +00:00
/* vramSetBankA(VRAM_A_MAIN_BG);
vramSetBankB ( VRAM_B_MAIN_BG ) ;
2006-07-09 11:47:17 +00:00
vramSetBankC ( VRAM_C_SUB_BG ) ; */
2008-05-15 22:12:51 +00:00
vramSetBankD ( VRAM_D_SUB_SPRITE ) ;
vramSetBankE ( VRAM_E_MAIN_SPRITE ) ;
2006-07-09 11:47:17 +00:00
currentTimeMillis = 0 ;
/*
// Set up a millisecond counter
TIMER0_CR = 0 ;
TIMER0_DATA = 0xFFFF ;
TIMER0_CR = TIMER_ENABLE | TIMER_CASCADE ;
*/
2006-11-03 23:16:29 +00:00
for ( int r = 0 ; r < 255 ; r + + ) {
PALETTE [ r ] = 0 ;
}
2006-07-09 11:47:17 +00:00
PALETTE [ 255 ] = RGB15 ( 0 , 31 , 0 ) ;
2006-11-03 23:16:29 +00:00
for ( int r = 0 ; r < 255 ; r + + ) {
PALETTE_SUB [ r ] = 0 ;
}
PALETTE_SUB [ 255 ] = RGB15 ( 0 , 31 , 0 ) ;
2006-07-09 11:47:17 +00:00
// Allocate save buffer for game screen
// savedBuffer = new u8[320 * 200];
displayMode16Bit ( ) ;
2008-05-15 22:12:51 +00:00
memset ( BG_GFX , 0 , 512 * 256 * 2 ) ;
2006-07-09 11:47:17 +00:00
scaledMode = true ;
scX = 0 ;
scY = 0 ;
subScX = 0 ;
subScY = 0 ;
subScTargetX = 0 ;
subScTargetY = 0 ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
//lcdSwap();
POWER_CR & = ~ POWER_SWAP_LCDS ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
frameCount = 0 ;
callback = NULL ;
2008-05-15 22:12:51 +00:00
// vramSetBankH(VRAM_H_SUB_BG);
2006-07-09 11:47:17 +00:00
// // Do text stuff
//BG0_CR = BG_MAP_BASE(0) | BG_TILE_BASE(1);
// BG0_Y0 = 48;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
PALETTE [ 255 ] = RGB15 ( 31 , 31 , 31 ) ; //by default font will be rendered with color 255
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
//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);
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
//irqs are nice
irqInit ( ) ;
// irqInitHandler();
irqSet ( IRQ_VBLANK , VBlankHandler ) ;
irqSet ( IRQ_TIMER0 , timerTickHandler ) ;
irqSet ( IRQ_TIMER2 , soundBufferEmptyHandler ) ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
irqEnable ( IRQ_VBLANK ) ;
irqEnable ( IRQ_TIMER0 ) ;
irqEnable ( IRQ_TIMER2 ) ;
2007-06-30 23:03:03 +00:00
# ifdef USE_PROFILER
irqSet ( IRQ_HBLANK , hBlankHandler ) ;
irqEnable ( IRQ_HBLANK ) ;
# endif
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
// Set up a millisecond timer
2006-11-25 20:35:34 +00:00
# ifdef HEAVY_LOGGING
consolePrintf ( " Setting up timer... " ) ;
# endif
2006-07-09 11:47:17 +00:00
TIMER0_CR = 0 ;
TIMER0_DATA = ( u32 ) TIMER_FREQ ( 1000 ) ;
2008-05-15 22:12:51 +00:00
TIMER0_CR = TIMER_ENABLE | TIMER_DIV_1 | TIMER_IRQ_REQ ;
2006-07-09 11:47:17 +00:00
REG_IME = 1 ;
2006-11-25 20:35:34 +00:00
# ifdef HEAVY_LOGGING
consolePrintf ( " done \n " ) ;
# endif
2006-07-09 11:47:17 +00:00
PALETTE [ 255 ] = RGB15 ( 0 , 0 , 31 ) ;
initSprites ( ) ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
// 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
2008-01-27 19:47:41 +00:00
2008-05-15 22:12:51 +00:00
// If the software scaler's back buffer has not been allocated, do it now
scalerBackBuffer = ( u8 * ) malloc ( 320 * 256 ) ;
2007-06-30 23:03:03 +00:00
2006-07-09 11:47:17 +00:00
WAIT_CR & = ~ ( 0x0080 ) ;
2007-04-06 18:34:53 +00:00
// REG_WRAM_CNT = 0;
2006-07-09 11:47:17 +00:00
2008-05-15 22:12:51 +00:00
uploadSpriteGfx ( ) ;
2007-06-30 23:03:03 +00:00
// This is a bodge to get around the fact that the cursor is turned on before it's image is set
// during startup in Sam & Max. This bodge moves the cursor offscreen so it is not seen.
sprites [ 1 ] . attribute [ 1 ] = ATTR1_SIZE_64 | 192 ;
2006-07-09 11:47:17 +00:00
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
void setKeyboardIcon ( bool enable ) {
keyboardIcon = enable ;
}
bool getKeyboardIcon ( ) {
return keyboardIcon ;
}
////////////////////
// Pen stuff
////////////////////
void penInit ( ) {
penDown = false ;
penHeld = false ;
penReleased = false ;
penDownLastFrame = false ;
penDownSaved = false ;
penReleasedSaved = false ;
penDownFrames = 0 ;
consumeKeys ( ) ;
}
void penUpdate ( ) {
// if (getKeysHeld() & KEY_L) consolePrintf("%d, %d penX=%d, penY=%d tz=%d\n", IPC->touchXpx, IPC->touchYpx, penX, penY, IPC->touchZ1);
if ( ( penDownFrames > 1 ) ) { // Is this right? Dunno, but it works for me.
if ( ( penHeld ) ) {
penHeld = true ;
penDown = false ;
if ( ( IPC - > touchZ1 > 0 ) & & ( IPC - > touchXpx > 0 ) & & ( IPC - > touchYpx > 0 ) ) {
penX = IPC - > touchXpx + touchXOffset ;
penY = IPC - > touchYpx + touchYOffset ;
}
} else {
penDown = true ;
penHeld = true ;
penDownSaved = true ;
//if ( (ABS(penX - IPC->touchXpx) < 10) && (ABS(penY - IPC->touchYpx) < 10) ) {
if ( ( IPC - > touchZ1 > 0 ) & & ( IPC - > touchXpx > 0 ) & & ( IPC - > touchYpx > 0 ) ) {
penX = IPC - > touchXpx ;
penY = IPC - > touchYpx ;
}
//}
}
} else {
if ( penHeld ) {
penReleased = true ;
penReleasedSaved = true ;
} else {
penReleased = false ;
}
penDown = false ;
penHeld = false ;
}
if ( ( IPC - > touchZ1 > 0 ) | | ( ( penDownFrames = = 2 ) ) ) {
penDownLastFrame = true ;
penDownFrames + + ;
} else {
penDownLastFrame = false ;
penDownFrames = 0 ;
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
}
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 ) ) ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( keys & KEY_L ) result | = KEY_R ;
if ( keys & KEY_R ) result | = KEY_L ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
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 ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
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 ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
return result ;
} else {
return keys ;
}
}
void keysUpdate ( ) {
scanKeys ( ) ;
keysDownSaved | = leftHandedSwap ( keysDown ( ) ) ;
keysReleasedSaved | = leftHandedSwap ( keysUp ( ) ) ;
2007-04-06 18:34:53 +00:00
keysChangedSaved = keysDownSaved | keysReleasedSaved ;
2006-07-09 11:47:17 +00:00
}
int getKeysDown ( ) {
return keysDownSaved ;
}
int getKeysHeld ( ) {
return leftHandedSwap ( keysHeld ( ) ) ;
}
int getKeysReleased ( ) {
return keysReleasedSaved ;
}
2007-04-06 18:34:53 +00:00
int getKeysChanged ( ) {
return keysChangedSaved ;
}
Common : : EventType getKeyEvent ( int key ) {
if ( getKeysDown ( ) & key ) {
return Common : : EVENT_KEYDOWN ;
} else if ( getKeysReleased ( ) & key ) {
return Common : : EVENT_KEYUP ;
} else {
return ( Common : : EventType ) 0 ;
}
}
2006-07-09 11:47:17 +00:00
void consumeKeys ( ) {
keysDownSaved = 0 ;
keysReleasedSaved = 0 ;
2007-04-06 18:34:53 +00:00
keysChangedSaved = 0 ;
2006-07-09 11:47:17 +00:00
}
bool getPenDown ( ) {
return penDownSaved ;
}
bool getPenHeld ( ) {
return penHeld ;
}
bool getPenReleased ( ) {
return penReleasedSaved ;
}
void consumePenEvents ( ) {
penDownSaved = false ;
penReleasedSaved = false ;
}
int getPenX ( ) {
int x = ( ( penX * touchScX ) > > 8 ) + touchX ;
x = x < 0 ? 0 : ( x > gameWidth - 1 ? gameWidth - 1 : x ) ;
2007-10-13 15:40:11 +00:00
if ( snapToBorder )
{
if ( x < 8 ) x = 0 ;
if ( x > gameWidth - 8 ) x = gameWidth - 1 ;
}
2006-07-09 11:47:17 +00:00
return x ;
}
int getPenY ( ) {
int y = ( ( penY * touchScY ) > > 8 ) + touchY ;
y = y < 0 ? 0 : ( y > gameHeight - 1 ? gameHeight - 1 : y ) ;
2007-10-13 15:40:11 +00:00
if ( snapToBorder )
{
if ( y < 8 ) y = 0 ;
if ( y > gameHeight - 8 ) y = gameHeight - 1 ;
}
2006-07-09 11:47:17 +00:00
return y ;
}
GLvector getPenPos ( ) {
GLvector v ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
v . x = ( penX * inttof32 ( 1 ) ) / SCREEN_WIDTH ;
v . y = ( penY * inttof32 ( 1 ) ) / SCREEN_HEIGHT ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
return v ;
}
void formatSramOption ( ) {
consolePrintf ( " The following files are present in save RAM: \n " ) ;
DSSaveFileManager : : instance ( ) - > listFiles ( ) ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
consolePrintf ( " \n Are you sure you want to \n " ) ;
consolePrintf ( " DELETE all files? \n " ) ;
consolePrintf ( " A = Yes, X = No \n " ) ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
while ( true ) {
if ( keysHeld ( ) & KEY_A ) {
DSSaveFileManager : : instance ( ) - > formatSram ( ) ;
consolePrintf ( " SRAM cleared! \n " ) ;
return ;
}
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
if ( keysHeld ( ) & KEY_X ) {
consolePrintf ( " Whew, that was close! \n " ) ;
return ;
}
}
}
void setIndyFightState ( bool st ) {
indyFightState = st ;
indyFightRight = true ;
}
bool getIndyFightState ( ) {
return indyFightState ;
}
2007-06-30 23:03:03 +00:00
gameListType * getCurrentGame ( ) {
return currentGame ;
}
2007-04-06 18:34:53 +00:00
///////////////////
// Fast Ram
///////////////////
2007-06-30 23:03:03 +00:00
# define FAST_RAM_SIZE (24000)
2007-04-06 18:34:53 +00:00
u8 * fastRamPointer ;
u8 fastRamData [ FAST_RAM_SIZE ] ITCM_DATA ;
void * fastRamAlloc ( int size ) {
2007-06-30 23:03:03 +00:00
// return malloc(size);
2008-05-31 19:06:50 +00:00
void * result = ( void * ) fastRamPointer ;
2007-04-06 18:34:53 +00:00
fastRamPointer + = size ;
2008-05-15 08:50:47 +00:00
if ( fastRamPointer > fastRamData + FAST_RAM_SIZE ) {
consolePrintf ( " FastRam (ITCM) allocation failed! \n " ) ;
return NULL ;
}
return result ;
2007-04-06 18:34:53 +00:00
}
void fastRamReset ( ) {
2007-06-30 23:03:03 +00:00
fastRamPointer = & fastRamData [ 0 ] ;
2007-04-06 18:34:53 +00:00
}
2006-07-09 11:47:17 +00:00
/////////////////
// GBAMP
/////////////////
bool GBAMPAvail = false ;
2008-05-15 22:12:51 +00:00
bool initGBAMP ( int mode ) {
2006-11-03 23:16:29 +00:00
if ( FAT_InitFiles ( ) ) {
if ( mode = = 2 ) {
disc_IsInserted ( ) ;
}
2006-07-09 11:47:17 +00:00
GBAMPAvail = true ;
2007-02-15 23:23:03 +00:00
// consolePrintf("Found flash card reader!\n");
return true ;
2006-07-09 11:47:17 +00:00
} else {
GBAMPAvail = false ;
2007-02-15 23:23:03 +00:00
// consolePrintf("Flash card reader not found!\n");
return false ;
2006-07-09 11:47:17 +00:00
}
}
2007-02-15 23:23:03 +00:00
2006-07-09 11:47:17 +00:00
bool isGBAMPAvailable ( ) {
return GBAMPAvail ;
}
2006-11-03 23:16:29 +00:00
# ifdef USE_DEBUGGER
void initDebugger ( ) {
set_verbosity ( VERBOSE_INFO | VERBOSE_ERROR ) ;
wireless_init ( 0 ) ;
wireless_connect ( ) ;
2008-05-15 22:12:51 +00:00
2006-11-03 23:16:29 +00:00
// This is where the address of the computer running the Java
// stub goes.
debugger_connect_tcp ( 192 , 168 , 0 , 1 ) ;
2008-05-15 22:12:51 +00:00
debugger_init ( ) ;
2006-11-03 23:16:29 +00:00
// Update function - should really call every frame
2008-05-15 22:12:51 +00:00
user_debugger_update ( ) ;
2006-11-03 23:16:29 +00:00
}
// Ensure the function is processed with C linkage
extern " C " void debug_print_stub ( char * string ) ;
void debug_print_stub ( char * string ) {
consolePrintf ( string ) ;
}
# endif
2007-01-19 21:47:10 +00:00
# ifdef USE_LIBCARTRESET
2007-02-15 23:23:03 +00:00
struct cardTranslate {
int cartResetId ;
int svmId ;
char dldiId [ 5 ] ;
} ;
# define NUM_CARD_READERS 7
cardTranslate cardReaderTable [ ] = {
{ DEVICE_TYPE_M3SD , DEVICE_M3SD , " M3SD " } ,
{ DEVICE_TYPE_M3CF , DEVICE_M3CF , " M3CF " } ,
{ DEVICE_TYPE_MPCF , DEVICE_MPCF , " MPCF " } ,
{ DEVICE_TYPE_SCCF , DEVICE_SCCF , " SCCF " } ,
{ DEVICE_TYPE_SCSD , DEVICE_SCSD , " SCSD " } ,
{ DEVICE_TYPE_SCSD , DEVICE_SCSD , " SCLT " } ,
{ DEVICE_TYPE_NMMC , DEVICE_NMMC , " NMMC " } ,
} ;
2007-01-19 21:47:10 +00:00
void reboot ( ) {
int deviceType = - 1 ;
2008-05-15 22:12:51 +00:00
2007-02-15 23:23:03 +00:00
if ( disc_getDeviceId ( ) = = DEVICE_DLDI ) {
char id [ 6 ] ;
disc_getDldiId ( id ) ;
consolePrintf ( " DLDI Device ID: %s \n " , id ) ;
for ( int r = 0 ; r < NUM_CARD_READERS ; r + + ) {
if ( ! stricmp ( id , cardReaderTable [ r ] . dldiId ) ) {
deviceType = cardReaderTable [ r ] . cartResetId ;
}
2007-01-19 21:47:10 +00:00
}
2007-02-15 23:23:03 +00:00
} else {
for ( int r = 0 ; r < NUM_CARD_READERS ; r + + ) {
if ( disc_getDeviceId ( ) = = cardReaderTable [ r ] . svmId ) {
deviceType = cardReaderTable [ r ] . cartResetId ;
}
2007-01-19 21:47:10 +00:00
}
}
2007-02-15 23:23:03 +00:00
consolePrintf ( " Device number: %x \n " , deviceType ) ;
2007-01-19 21:47:10 +00:00
if ( deviceType = = - 1 ) {
IPC - > reset = true ; // Send message to ARM7 to turn power off
} else {
cartSetMenuMode ( deviceType ) ;
passmeloopEnter ( ) ;
}
while ( true ) ; // Stop the program continuing beyond this point
}
# endif
2006-11-03 23:16:29 +00:00
void powerOff ( ) {
while ( keysHeld ( ) ! = 0 ) { // Wait for all keys to be released.
swiWaitForVBlank ( ) ; // Allow you to read error before the power
} // is turned off.
for ( int r = 0 ; r < 60 ; r + + ) {
swiWaitForVBlank ( ) ;
}
if ( ConfMan . hasKey ( " disablepoweroff " , " ds " ) & & ConfMan . getBool ( " disablepoweroff " , " ds " ) ) {
while ( true ) ;
} else {
2007-01-19 21:47:10 +00:00
# ifdef USE_LIBCARTRESET
reboot ( ) ;
# else
2006-11-03 23:16:29 +00:00
IPC - > reset = true ; // Send message to ARM7 to turn power off
while ( true ) ; // Stop the program continuing beyond this point
2007-01-19 21:47:10 +00:00
# endif
2006-11-03 23:16:29 +00:00
}
}
2006-07-09 11:47:17 +00:00
/////////////////
// Main
/////////////////
int main ( void )
{
2007-01-19 21:47:10 +00:00
2006-07-09 11:47:17 +00:00
soundCallback = NULL ;
initHardware ( ) ;
2007-01-19 21:47:10 +00:00
2006-11-03 23:16:29 +00:00
# ifdef USE_DEBUGGER
2006-12-01 22:36:54 +00:00
for ( int r = 0 ; r < 150 ; r + + ) {
swiWaitForVBlank ( ) ;
}
2006-11-03 23:16:29 +00:00
if ( ! ( keysHeld ( ) & KEY_Y ) ) {
initDebugger ( ) ;
}
# endif
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
// Let arm9 read cartridge
* ( ( u16 * ) ( 0x04000204 ) ) & = ~ 0x0080 ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
lastCallbackFrame = 0 ;
tweak = 0 ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
indyFightState = false ;
indyFightRight = true ;
2007-04-06 18:34:53 +00:00
2006-07-09 11:47:17 +00:00
// CPU speed = 67108864
// 8 frames = 2946 368.5 bytes per fr
// playSound(stretch, 47619, false);
// playSound(twang, 11010, true); // 18640
// bufferSize = 10;
2008-05-15 22:12:51 +00:00
2006-11-03 23:16:29 +00:00
/*bufferRate = 44100;
bufferFrame = 0 ;
bufferSamples = 8192 ;
2006-07-09 11:47:17 +00:00
2006-11-03 23:16:29 +00:00
bufferFirstHalf = false ;
bufferSecondHalf = true ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
int bytes = ( 2 * ( bufferSamples ) ) + 100 ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
soundBuffer = ( s16 * ) malloc ( bytes * 2 ) ;
soundHiPart = true ;
2008-05-15 22:12:51 +00:00
2006-11-03 23:16:29 +00:00
for ( int r = 0 ; r < bytes ; r + + ) {
soundBuffer [ r ] = 0 ;
}
2008-05-15 22:12:51 +00:00
2006-11-03 23:16:29 +00:00
swiWaitForVBlank ( ) ;
swiWaitForVBlank ( ) ;
playSound ( soundBuffer , ( bufferSamples * 2 ) , true ) ;
swiWaitForVBlank ( ) ;
swiWaitForVBlank ( ) ;
swiWaitForVBlank ( ) ;
*/
2008-05-15 22:12:51 +00:00
2006-11-03 23:16:29 +00:00
lastEventFrame = 0 ;
mouseMode = MOUSE_LEFT ;
2008-05-15 22:12:51 +00:00
2006-11-03 23:16:29 +00:00
2006-07-09 11:47:17 +00:00
/*
TIMER1_CR = 0 ;
TIMER1_DATA = TIMER_FREQ ( bufferRate ) ;
TIMER1_CR = TIMER_ENABLE | TIMER_DIV_1 ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
TIMER2_CR = 0 ;
TIMER2_DATA = 0xFFFF - ( bufferSamples / 2 ) ;
TIMER2_CR = TIMER_ENABLE | TIMER_IRQ_REQ | TIMER_CASCADE ;
*/
// 2945 - 2947
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
// for (int r = 2946; r < 3000; r++) {
// soundBuffer[r] = 30000;
// }
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
2007-06-30 23:03:03 +00:00
//2372
2007-02-15 23:23:03 +00:00
consolePrintf ( " ------------------------------- \n " ) ;
2006-07-09 11:47:17 +00:00
consolePrintf ( " ScummVM DS \n " ) ;
consolePrintf ( " Ported by Neil Millstone \n " ) ;
2008-05-15 22:12:51 +00:00
consolePrintf ( " Version 0.11.1 beta2 " ) ;
2006-11-03 23:16:29 +00:00
# if defined(DS_BUILD_A)
consolePrintf ( " build A \n " ) ;
2007-06-30 23:03:03 +00:00
consolePrintf ( " Lucasarts SCUMM games (SCUMM) \n " ) ;
2007-02-15 23:23:03 +00:00
consolePrintf ( " ------------------------------- \n " ) ;
2006-11-03 23:16:29 +00:00
# elif defined(DS_BUILD_B)
consolePrintf ( " build B \n " ) ;
2007-06-30 23:03:03 +00:00
consolePrintf ( " BASS, QUEEN \n " ) ;
2007-02-15 23:23:03 +00:00
consolePrintf ( " ------------------------------- \n " ) ;
2006-11-03 23:16:29 +00:00
# elif defined(DS_BUILD_C)
consolePrintf ( " build C \n " ) ;
2008-05-15 22:12:51 +00:00
consolePrintf ( " Simon/Elvira/Waxworks (AGOS) \n " ) ;
2007-06-30 23:03:03 +00:00
consolePrintf ( " ------------------------------- \n " ) ;
# elif defined(DS_BUILD_D)
consolePrintf ( " build D \n " ) ;
consolePrintf ( " AGI, CINE, GOB \n " ) ;
consolePrintf ( " ------------------------------- \n " ) ;
# elif defined(DS_BUILD_E)
consolePrintf ( " build E \n " ) ;
2008-05-15 22:12:51 +00:00
consolePrintf ( " Inherit the Earth (SAGA) \n " ) ;
2007-06-30 23:03:03 +00:00
consolePrintf ( " ------------------------------- \n " ) ;
# elif defined(DS_BUILD_F)
consolePrintf ( " build F \n " ) ;
consolePrintf ( " The Legend of Kyrandia (KYRA) \n " ) ;
2007-02-15 23:23:03 +00:00
consolePrintf ( " ------------------------------- \n " ) ;
2007-12-21 18:36:40 +00:00
# elif defined(DS_BUILD_G)
consolePrintf ( " build F \n " ) ;
consolePrintf ( " Lure of the Temptress (LURE) \n " ) ;
consolePrintf ( " ------------------------------- \n " ) ;
2006-07-09 11:47:17 +00:00
# endif
2007-02-15 23:23:03 +00:00
consolePrintf ( " L/R + D-pad/pen: Scroll view \n " ) ;
consolePrintf ( " D-pad left: Left mouse button \n " ) ;
2006-07-09 11:47:17 +00:00
consolePrintf ( " D-pad right: Right mouse button \n " ) ;
2007-02-15 23:23:03 +00:00
consolePrintf ( " D-pad up: Hover mouse \n " ) ;
consolePrintf ( " B button: Skip cutscenes \n " ) ;
2007-06-30 23:03:03 +00:00
consolePrintf ( " Select: DS Options menu \n " ) ;
2007-02-15 23:23:03 +00:00
consolePrintf ( " Start: Game menu (some games) \n " ) ;
consolePrintf ( " Y (in game): Toggle console \n " ) ;
consolePrintf ( " X: Toggle keyboard \n " ) ;
consolePrintf ( " A: Swap screens \n " ) ;
consolePrintf ( " L+R (on start): Clear SRAM \n " ) ;
2006-11-03 23:16:29 +00:00
# if defined(DS_BUILD_A)
consolePrintf ( " For a complete key list see the \n " ) ;
2006-07-09 18:28:58 +00:00
consolePrintf ( " help screen. \n \n " ) ;
2006-11-03 23:16:29 +00:00
# else
consolePrintf ( " \n " ) ;
# endif
2006-07-09 11:47:17 +00:00
2008-05-15 22:12:51 +00:00
2007-02-15 23:23:03 +00:00
# ifdef USE_BUILT_IN_DRIVER_SELECTION
2006-11-03 23:16:29 +00:00
// Do M3 detection selectioon
int extraData = DSSaveFileManager : : getExtraData ( ) ;
bool present = DSSaveFileManager : : isExtraDataPresent ( ) ;
2006-07-09 11:47:17 +00:00
2006-11-03 23:16:29 +00:00
for ( int r = 0 ; r < 30 ; r + + ) {
swiWaitForVBlank ( ) ;
2006-07-09 11:47:17 +00:00
}
2006-11-03 23:16:29 +00:00
int mode = extraData & 0x03 ;
if ( mode = = 0 ) {
if ( ( keysHeld ( ) & KEY_L ) & & ! ( keysHeld ( ) & KEY_R ) ) {
mode = 1 ;
} else if ( ! ( keysHeld ( ) & KEY_L ) & & ( keysHeld ( ) & KEY_R ) ) {
mode = 2 ;
}
} else {
if ( ( keysHeld ( ) & KEY_L ) & & ! ( keysHeld ( ) & KEY_R ) ) {
mode = 0 ;
}
}
2006-07-09 11:47:17 +00:00
2006-11-03 23:16:29 +00:00
if ( mode = = 0 ) {
consolePrintf ( " On startup hold L if you have \n " ) ;
consolePrintf ( " an M3 SD or R for an SC SD \n " ) ;
} else if ( mode = = 1 ) {
consolePrintf ( " Using M3 SD Mode. \n " ) ;
consolePrintf ( " Hold L on startup to disable. \n " ) ;
} else if ( mode = = 2 ) {
consolePrintf ( " Using SC SD Mode. \n " ) ;
consolePrintf ( " Hold L on startup to disable. \n " ) ;
}
disc_setEnable ( mode ) ;
DSSaveFileManager : : setExtraData ( mode ) ;
2007-02-15 23:23:03 +00:00
# else
2008-05-15 22:12:51 +00:00
2007-02-15 23:23:03 +00:00
int mode = 0 ;
# endif
2006-11-03 23:16:29 +00:00
/*
if ( ( present ) & & ( extraData & 0x00000001 ) ) {
if ( keysHeld ( ) & KEY_L ) {
extraData & = ~ 0x00000001 ;
consolePrintf ( " M3 SD Detection: OFF \n " ) ;
DSSaveFileManager : : setExtraData ( extraData ) ;
} else {
consolePrintf ( " M3 SD Detection: ON \n " ) ;
consolePrintf ( " Hold L on startup to disable. \n " ) ;
}
} else if ( keysHeld ( ) & KEY_L ) {
consolePrintf ( " M3 SD Detection: ON \n " ) ;
extraData | = 0x00000001 ;
DSSaveFileManager : : setExtraData ( extraData ) ;
} else {
consolePrintf ( " M3 SD Detection: OFF \n " ) ;
consolePrintf ( " Hold L on startup to enable. \n " ) ;
}
disc_setM3SDEnable ( extraData & 0x00000001 ) ;
*/
2006-07-09 11:47:17 +00:00
// Create a file system node to force search for a zip file in GBA rom space
2006-11-03 23:16:29 +00:00
2006-07-09 11:47:17 +00:00
DSFileSystemNode * node = new DSFileSystemNode ( ) ;
if ( ! node - > getZip ( ) | | ( ! node - > getZip ( ) - > isReady ( ) ) ) {
// If not found, init CF/SD driver
2006-11-03 23:16:29 +00:00
initGBAMP ( mode ) ;
2007-02-15 23:23:03 +00:00
if ( ! initGBAMP ( mode ) ) {
consolePrintf ( " \n No file system was found. \n " ) ;
2007-10-13 15:40:11 +00:00
consolePrintf ( " View the readme file \n " ) ;
2007-02-15 23:23:03 +00:00
consolePrintf ( " for more information. \n " ) ;
while ( 1 ) ;
}
2006-07-09 11:47:17 +00:00
}
delete node ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
updateStatus ( ) ;
2008-05-15 22:12:51 +00:00
2006-07-09 11:47:17 +00:00
// OSystem_DS::instance();
2006-11-03 23:16:29 +00:00
2006-07-09 11:47:17 +00:00
g_system = new OSystem_DS ( ) ;
assert ( g_system ) ;
if ( ( keysHeld ( ) & KEY_L ) & & ( keysHeld ( ) & KEY_R ) ) {
formatSramOption ( ) ;
}
2007-10-13 15:40:11 +00:00
IPC - > adpcm . semaphore = false ;
2006-07-09 11:47:17 +00:00
// printf("'%s'", Common::ConfigManager::kTransientDomain.c_str());
//printf("'%s'", Common::ConfigManager::kApplicationDomain.c_str());
2006-11-03 23:16:29 +00:00
# if defined(DS_BUILD_A)
2008-05-31 19:06:50 +00:00
const char * argv [ ] = { " /scummvmds " } ;
2006-11-03 23:16:29 +00:00
# elif defined(DS_BUILD_B)
2008-05-31 19:06:50 +00:00
const char * argv [ ] = { " /scummvmds " , " --config=scummvmb.ini " } ;
2006-11-03 23:16:29 +00:00
# elif defined(DS_BUILD_C)
2008-05-31 19:06:50 +00:00
const char * argv [ ] = { " /scummvmds " , " --config=scummvmc.ini " } ;
2007-04-06 18:34:53 +00:00
# elif defined(DS_BUILD_D)
2008-05-31 19:06:50 +00:00
const char * argv [ ] = { " /scummvmds " , " --config=scummvmd.ini " } ;
2007-06-30 23:03:03 +00:00
# elif defined(DS_BUILD_E)
2008-05-31 19:06:50 +00:00
const char * argv [ ] = { " /scummvmds " , " --config=scummvme.ini " } ;
2007-06-30 23:03:03 +00:00
# elif defined(DS_BUILD_F)
2008-05-31 19:06:50 +00:00
const char * argv [ ] = { " /scummvmds " , " --config=scummvmf.ini " } ;
2007-12-21 18:36:40 +00:00
# elif defined(DS_BUILD_G)
2008-05-31 19:06:50 +00:00
const char * argv [ ] = { " /scummvmds " , " --config=scummvmg.ini " } ;
2006-11-03 23:16:29 +00:00
# endif
2006-07-09 11:47:17 +00:00
while ( 1 ) {
2008-05-31 19:06:50 +00:00
scummvm_main ( ARRAYSIZE ( argv ) , ( char * * ) & argv ) ;
2006-11-03 23:16:29 +00:00
powerOff ( ) ;
2006-07-09 11:47:17 +00:00
}
return 0 ;
}
}
int main ( ) {
DS : : main ( ) ;
}
2007-06-30 23:03:03 +00:00
# ifdef USE_PROFILER
int cygprofile_getHBlanks ( ) __attribute__ ( ( no_instrument_function ) ) ;
int cygprofile_getHBlanks ( ) {
return DS : : hBlankCount ;
}
# endif