aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/ds/arm9/source
diff options
context:
space:
mode:
authorNeil Millstone2010-02-26 17:29:18 +0000
committerNeil Millstone2010-02-26 17:29:18 +0000
commit4a8ab4b075a186ce70c441ee0ceb3f6d5019d948 (patch)
treefb81e929f451c6ea2f787c5df458c25b8ce96b1a /backends/platform/ds/arm9/source
parentbcb721cccd46fccba164044cf8afea92872a3c0f (diff)
downloadscummvm-rg350-4a8ab4b075a186ce70c441ee0ceb3f6d5019d948.tar.gz
scummvm-rg350-4a8ab4b075a186ce70c441ee0ceb3f6d5019d948.tar.bz2
scummvm-rg350-4a8ab4b075a186ce70c441ee0ceb3f6d5019d948.zip
DS: Merging accross changes from branch1-0-0 into trunk.
svn-id: r48136
Diffstat (limited to 'backends/platform/ds/arm9/source')
-rw-r--r--backends/platform/ds/arm9/source/cdaudio.cpp41
-rw-r--r--backends/platform/ds/arm9/source/dsmain.cpp275
-rw-r--r--backends/platform/ds/arm9/source/dsmain.h5
-rw-r--r--backends/platform/ds/arm9/source/osystem_ds.cpp14
-rw-r--r--backends/platform/ds/arm9/source/touchkeyboard.cpp79
-rw-r--r--backends/platform/ds/arm9/source/touchkeyboard.h2
6 files changed, 299 insertions, 117 deletions
diff --git a/backends/platform/ds/arm9/source/cdaudio.cpp b/backends/platform/ds/arm9/source/cdaudio.cpp
index 140c709a8c..7756286117 100644
--- a/backends/platform/ds/arm9/source/cdaudio.cpp
+++ b/backends/platform/ds/arm9/source/cdaudio.cpp
@@ -137,18 +137,21 @@ void playTrack(int track, int numLoops, int startFrame, int duration) {
char str[100];
- if (path[strlen(path.c_str()) - 1] == '/') {
- sprintf(str, "track%d.wav", track);
- path = path + str;
- } else {
- sprintf(str, "/track%d.wav", track);
- path = path + str;
+ if (path[strlen(path.c_str()) - 1] != '/') {
+ path = path + "/";
}
+ Common::String fname;
- //1820160
+ sprintf(str, "track%d.wav", track);
+ fname = path + str;
+ file = DS::std_fopen(fname.c_str(), "rb");
- file = DS::std_fopen(path.c_str(), "rb");
+ if (!file) {
+ sprintf(str, "track%02d.wav", track);
+ fname = path + str;
+ file = DS::std_fopen(fname.c_str(), "rb");
+ }
if (!file) {
consolePrintf("Failed to open %s!\n", path.c_str());
@@ -158,6 +161,8 @@ void playTrack(int track, int numLoops, int startFrame, int duration) {
DS::std_fread((const void *) &waveHeader, sizeof(waveHeader), 1, file);
+ consolePrintf("File: %s\n", fname.c_str());
+
consolePrintf("Playing track %d\n", track);
consolePrintf("Format: %d\n", waveHeader.fmtFormatTag);
consolePrintf("Rate : %d\n", waveHeader.fmtSamPerSec);
@@ -496,6 +501,26 @@ bool trackExists(int num) {
setActive(true);
DS::std_fclose(file);
return true;
+ }
+
+ sprintf(fname, "track%02d.wav", num);
+
+ path = ConfMan.get("path");
+
+ if (path[strlen(path.c_str()) - 1] == '/') {
+ path = path + fname;
+ } else {
+ path = path + "/" + fname;
+ }
+
+ consolePrintf("Looking for %s...", path.c_str());
+
+
+ if ((file = DS::std_fopen(path.c_str(), "r"))) {
+ consolePrintf("Success!\n");
+ setActive(true);
+ DS::std_fclose(file);
+ return true;
} else {
setActive(false);
consolePrintf("Failed!\n");
diff --git a/backends/platform/ds/arm9/source/dsmain.cpp b/backends/platform/ds/arm9/source/dsmain.cpp
index f959074d49..4132f4b138 100644
--- a/backends/platform/ds/arm9/source/dsmain.cpp
+++ b/backends/platform/ds/arm9/source/dsmain.cpp
@@ -117,17 +117,20 @@ static const char *registerNames[] =
extern "C" void* __real_malloc(size_t size);
+int total = 0;
+
void* operator new (size_t size)
{
register unsigned int reg asm("lr");
volatile unsigned int poo = reg;
void* res = __real_malloc(size);
+ total += size;
if (!res)
{
// *((u8 *) NULL) = 0;
- consolePrintf("Failed alloc (new) %d (%x)\n", size, poo);
+ consolePrintf("Failed alloc (new) %d (%d)\n", size, total);
return NULL;
}
@@ -155,18 +158,20 @@ extern "C" void* __wrap_malloc(size_t size) {
void* res = __real_malloc(size);
if (res) {
- if (size > 100 * 1024) {
- consolePrintf("Allocated %d (%d)\n", size, poo);
+ if (size > 50 * 1024) {
+ consolePrintf("Allocated %d (%x)\n", size, poo);
}
+ total += size;
return res;
} else {
// *((u8 *) NULL) = 0;
- consolePrintf("Failed alloc %d (%x)\n", size, poo);
+ consolePrintf("Failed alloc %d (%d)\n", size, total);
return NULL;
}
}
+
#endif
namespace DS {
@@ -545,6 +550,22 @@ int getSoundFrequency() {
return soundFrequency;
}
+void setControls(char* gameName) {
+
+ for (int r = 0; r < NUM_SUPPORTED_GAMES; r++) {
+ if (!stricmp(gameName, gameList[r].gameId)) {
+ currentGame = &gameList[r];
+ consolePrintf("Current game set to: %s\n", gameName);
+ return;
+ }
+ }
+
+ consolePrintf("Failed to set current game to: %s\n", gameName);
+}
+
+void exitGame() {
+ currentGame = NULL;
+}
void initGame() {
// This is a good time to check for left handed mode since the mode change is done as the game starts.
@@ -558,15 +579,18 @@ void initGame() {
setOptions();
//strcpy(gameName, ConfMan.getActiveDomain().c_str());
- strcpy(gameName, ConfMan.get("gameid").c_str());
-// consolePrintf("\n\n\n\nCurrent game: '%s' %d\n", gameName, gameName[0]);
-
- currentGame = &gameList[0]; // Default game
-
- for (int r = 0; r < NUM_SUPPORTED_GAMES; r++) {
- if (!stricmp(gameName, gameList[r].gameId)) {
- currentGame = &gameList[r];
-// consolePrintf("Game list num: %d\n", currentGame);
+ if (currentGame == NULL) {
+
+ strcpy(gameName, ConfMan.get("gameid").c_str());
+ // consolePrintf("\n\n\n\nCurrent game: '%s' %d\n", gameName, gameName[0]);
+
+ currentGame = &gameList[0]; // Default game
+
+ for (int r = 0; r < NUM_SUPPORTED_GAMES; r++) {
+ if (!stricmp(gameName, gameList[r].gameId)) {
+ currentGame = &gameList[r];
+ // consolePrintf("Game list num: %d\n", currentGame);
+ }
}
}
@@ -879,6 +903,8 @@ void displayMode16Bit() {
releaseAllKeys();
+ setKeyboardEnable(false);
+
if (!displayModeIs8Bit) {
for (int r = 0; r < 32 * 32; r++) {
buffer[r] = ((u16 *) SCREEN_BASE_BLOCK_SUB(4))[r];
@@ -1326,32 +1352,34 @@ void doScreenTapMode(OSystem_DS* system)
right = true;
}
-
- if (getKeysDown() & KEY_LEFT) {
- event.type = Common::EVENT_LBUTTONDOWN;
- event.mouse = Common::Point(getPenX(), getPenY());
- system->addEvent(event);
- }
-
- if (getKeysReleased() & KEY_LEFT) {
- event.type = Common::EVENT_LBUTTONUP;
- event.mouse = Common::Point(getPenX(), getPenY());
- system->addEvent(event);
- }
-
-
- if (getKeysDown() & KEY_RIGHT) {
- event.type = Common::EVENT_RBUTTONDOWN;
- event.mouse = Common::Point(getPenX(), getPenY());
- system->addEvent(event);
- }
-
- if (getKeysReleased() & KEY_RIGHT) {
- event.type = Common::EVENT_RBUTTONUP;
- event.mouse = Common::Point(getPenX(), getPenY());
- system->addEvent(event);
+ if (!(getKeysHeld() & (KEY_L | KEY_R))) {
+
+ if (getKeysDown() & KEY_LEFT) {
+ event.type = Common::EVENT_LBUTTONDOWN;
+ event.mouse = Common::Point(getPenX(), getPenY());
+ system->addEvent(event);
+ }
+
+ if (getKeysReleased() & KEY_LEFT) {
+ event.type = Common::EVENT_LBUTTONUP;
+ event.mouse = Common::Point(getPenX(), getPenY());
+ system->addEvent(event);
+ }
+
+
+ if (getKeysDown() & KEY_RIGHT) {
+ event.type = Common::EVENT_RBUTTONDOWN;
+ event.mouse = Common::Point(getPenX(), getPenY());
+ system->addEvent(event);
+ }
+
+ if (getKeysReleased() & KEY_RIGHT) {
+ event.type = Common::EVENT_RBUTTONUP;
+ event.mouse = Common::Point(getPenX(), getPenY());
+ system->addEvent(event);
+ }
}
-
+
event.type = Common::EVENT_MOUSEMOVE;
event.mouse = Common::Point(getPenX(), getPenY());
system->addEvent(event);
@@ -1487,8 +1515,8 @@ void addEventsToQueue() {
OSystem_DS* system = OSystem_DS::instance();
Common::Event event;
-
#ifdef USE_PROFILER
+/*
if (keysDown() & KEY_R) {
cygprofile_begin();
cygprofile_enable();
@@ -1497,9 +1525,11 @@ void addEventsToQueue() {
cygprofile_disable();
cygprofile_end();
}
+*/
#endif
+
if (system->isEventQueueEmpty()) {
/*
@@ -1645,18 +1675,27 @@ void addEventsToQueue() {
Common::Event event;
- if (!keyboardEnable) {
-
- if ((tapScreenClicks) && (getIsDisplayMode8Bit())) {
+ if ((tapScreenClicks) && (getIsDisplayMode8Bit())) {
+ if ((!keyboardEnable) || (!isInsideKeyboard(penDownX, penDownY))) {
doScreenTapMode(system);
- } else {
+ }
+ } else {
+ if (!keyboardEnable) {
doButtonSelectMode(system);
+ } else if ((!keyboardEnable) || (!isInsideKeyboard(penDownX, penDownY))) {
+ doScreenTapMode(system);
}
+ }
+
+
+ if (!keyboardEnable) {
+
if (((!(getKeysHeld() & KEY_L)) && (!(getKeysHeld() & KEY_R)) || (indyFightState)) && (displayModeIs8Bit)) {
// Controls specific to the control method
+
if (currentGame->control == CONT_SKY) {
// Extra controls for Beneath a Steel Sky
if ((getKeysDown() & KEY_DOWN)) {
@@ -1665,6 +1704,26 @@ void addEventsToQueue() {
}
}
+ if (currentGame->control == CONT_AGI) {
+ // Extra controls for Leisure Suit Larry and KQ4
+
+ if ((getKeysHeld() & KEY_UP) && (getKeysHeld() & KEY_START)
+ /*&& (!strcmp(gameName, "LLLLL"))*/) {
+ consolePrintf("Cheat key!\n");
+ event.type = Common::EVENT_KEYDOWN;
+ event.kbd.keycode = (Common::KeyCode)'X'; // Skip age test in LSL
+ event.kbd.ascii = 'X';
+ event.kbd.flags = Common::KBD_ALT;
+ system->addEvent(event);
+
+ event.type = Common::EVENT_KEYUP;
+ system->addEvent(event);
+ }
+
+ }
+
+
+
if (currentGame->control == CONT_SIMON) {
// Extra controls for Simon the Sorcerer
if ((getKeysDown() & KEY_DOWN)) {
@@ -2019,10 +2078,8 @@ void VBlankHandler(void) {
frameCount++;
if ((cursorEnable) && (mouseCursorVisible)) {
- if (!keyboardEnable) {
- storedMouseX = penX;
- storedMouseY = penY;
- }
+ storedMouseX = penX;
+ storedMouseY = penY;
if (gameScreenSwap) {
setIcon(3, storedMouseX - mouseHotspotX, storedMouseY - mouseHotspotY, 8, 0, true);
@@ -2177,20 +2234,20 @@ void VBlankHandler(void) {
int offsX = 0, offsY = 0;
- if (getKeysHeld() & KEY_LEFT) {
- offsX -= 1;
+ if ((getKeysHeld() & KEY_LEFT)) {
+ offsX -= 2;
}
- if (getKeysHeld() & KEY_RIGHT) {
- offsX += 1;
+ if ((getKeysHeld() & KEY_RIGHT)) {
+ offsX += 2;
}
- if (getKeysHeld() & KEY_UP) {
- offsY -= 1;
+ if ((getKeysHeld() & KEY_UP)) {
+ offsY -= 2;
}
- if (getKeysHeld() & KEY_DOWN) {
- offsY += 1;
+ if ((getKeysHeld() & KEY_DOWN)) {
+ offsY += 2;
}
if (((gameScreenSwap) && (getKeysHeld() & KEY_L)) || ((!gameScreenSwap) && (getKeysHeld() & KEY_R))) {
@@ -2491,7 +2548,8 @@ void penUpdate() {
bool penDownThisFrame = (IPC->touchZ1 > 0) && (IPC->touchXpx > 0) && (IPC->touchYpx > 0);
static bool moved = false;
- if ((tapScreenClicks) && (!getKeyboardEnable()) && (getIsDisplayMode8Bit())) {
+ if (( (tapScreenClicks) || getKeyboardEnable() ) && (getIsDisplayMode8Bit())) {
+
if ((tapTimeout >= 0)) {
tapTimeout++;
@@ -2506,7 +2564,7 @@ void penUpdate() {
if ((penHeld) && (!penDownThisFrame)) {
- if ((touchPadStyle) || (moved) || (tapCount == 1)) {
+ if ((touchPadStyle) || (getKeyboardEnable() && (!isInsideKeyboard(penDownX, penDownY))) || (moved) || (tapCount == 1)) {
if ((penDownFrames > 0) && (penDownFrames < 6) && ((tapTimeout == -1) || (tapTimeout > 2))) {
tapCount++;
tapTimeout = 0;
@@ -2518,40 +2576,56 @@ void penUpdate() {
}
+ if ( ((keyboardEnable) || (touchPadStyle)) && (getIsDisplayMode8Bit()) ) {
+ // Relative positioning mode
- if ((touchPadStyle) && (getIsDisplayMode8Bit())) {
-
- if ((penDownFrames > 0)) {
+ if ((penDownFrames > 0) ) {
if ((penHeld)) {
- if (penDownThisFrame)
- {
+ if (penDownThisFrame) {
if (penDownFrames >= 2) {
- int diffX = IPC->touchXpx - penDownX;
- int diffY = IPC->touchYpx - penDownY;
- int speed = ABS(diffX) + ABS(diffY);
-
- if ((ABS(diffX) < 35) && (ABS(diffY) < 35))
- {
-
- if (speed >= 8)
- {
- diffX *= ((speed >> 3) * touchPadSensitivity) >> 3;
- diffY *= ((speed >> 3) * touchPadSensitivity) >> 3;
+ if ((!keyboardEnable) || (!isInsideKeyboard(IPC->touchXpx, IPC->touchYpx))) {
+ int diffX = IPC->touchXpx - penDownX;
+ int diffY = IPC->touchYpx - penDownY;
+
+ int speed = ABS(diffX) + ABS(diffY);
+
+ if ((ABS(diffX) < 35) && (ABS(diffY) < 35)) {
+
+ if (speed >= 8) {
+ diffX *= ((speed >> 3) * touchPadSensitivity) >> 3;
+ diffY *= ((speed >> 3) * touchPadSensitivity) >> 3;
+ }
+
+ penX += diffX;
+ penY += diffY;
+
+ if (penX > 255) {
+ scX -= 255 - penX;
+ penX = 255;
+ }
+
+ if (penX < 0) {
+ scX -= -penX;
+ penX = 0;
+ }
+
+ if (penY > 191) {
+ scY += penY - 191;
+ penY = 191;
+ }
+
+ if (penY < 0) {
+ scY -= -penY;
+ penY = 0;
+ }
}
-
- penX += diffX;
- penY += diffY;
- if (penX > 255) penX = 255;
- if (penX < 0) penX = 0;
- if (penY > 191) penY = 191;
- if (penY < 0) penY = 0;
+
+ // consolePrintf("x: %d y: %d\n", IPC->touchYpx - penDownY, IPC->touchYpx - penDownY);
}
-
-// consolePrintf("x: %d y: %d\n", IPC->touchYpx - penDownY, IPC->touchYpx - penDownY);
penDownX = IPC->touchXpx;
penDownY = IPC->touchYpx;
@@ -2561,7 +2635,6 @@ void penUpdate() {
{
}
-
} else {
penDown = true;
penHeld = true;
@@ -2573,7 +2646,6 @@ void penUpdate() {
penDownY = IPC->touchYpx;
}
}
-
} else {
if (penHeld) {
penReleased = true;
@@ -2585,13 +2657,19 @@ void penUpdate() {
penDown = false;
penHeld = false;
}
- } else {
+
+
+ } else { // Absolute positioning mode
if ((penDownFrames > 1)) { // Is this right? Dunno, but it works for me.
if ((penHeld)) {
penHeld = true;
penDown = false;
} else {
+ if (penDownFrames == 2) {
+ penDownX = IPC->touchXpx;
+ penDownY = IPC->touchYpx;
+ }
penDown = true;
penHeld = true;
penDownSaved = true;
@@ -2604,7 +2682,6 @@ void penUpdate() {
}
-
} else {
if (penHeld) {
penReleased = true;
@@ -2616,8 +2693,6 @@ void penUpdate() {
penDown = false;
penHeld = false;
}
-
-
}
@@ -2971,13 +3046,17 @@ void dsExceptionHandler() {
consolePrintf(" pc: %08X addr: %08X\n\n",codeAddress,exceptionAddress);
+
int i;
for ( i=0; i < 8; i++ ) {
consolePrintf(" %s: %08X %s: %08X\n",
registerNames[i], exceptionRegisters[i],
registerNames[i+8],exceptionRegisters[i+8]);
}
+ while(1);
u32 *stack = (u32 *)exceptionRegisters[13];
+
+
for ( i=0; i<10; i++ ) {
consolePrintf("%08X %08X %08X\n", stack[i*3], stack[i*3+1], stack[(i*3)+2] );
}
@@ -3007,6 +3086,7 @@ int main(void) {
}
#endif
+
// Let arm9 read cartridge
*((u16 *) (0x04000204)) &= ~0x0080;
@@ -3080,7 +3160,7 @@ int main(void) {
consolePrintf("-------------------------------\n");
consolePrintf("ScummVM DS\n");
consolePrintf("Ported by Neil Millstone\n");
- consolePrintf("Version 1.0.0 RC1 ");
+ consolePrintf("Version 1.0.0 ");
#if defined(DS_BUILD_A)
consolePrintf("build A\n");
consolePrintf("Lucasarts SCUMM games (SCUMM)\n");
@@ -3105,6 +3185,12 @@ int main(void) {
#elif defined(DS_BUILD_H)
consolePrintf("build H\n");
consolePrintf("Nippon Safes (PARALLATION)\n");
+#elif defined(DS_BUILD_I)
+ consolePrintf("build I\n");
+ consolePrintf("Activision Games (MADE)\n");
+#elif defined(DS_BUILD_K)
+ consolePrintf("build K\n");
+ consolePrintf("Cruise for a Corpse (Cruise)\n");
#endif
consolePrintf("-------------------------------\n");
consolePrintf("L/R + D-pad/pen: Scroll view\n");
@@ -3249,13 +3335,21 @@ int main(void) {
const char *argv[] = {"/scummvmds", "--config=scummvmg.ini"};
#elif defined(DS_BUILD_H)
const char *argv[] = {"/scummvmds", "--config=scummvmh.ini"};
+#elif defined(DS_BUILD_I)
+ const char *argv[] = {"/scummvmds", "--config=scummvmi.ini"};
+#elif defined(DS_BUILD_J)
+ const char *argv[] = {"/scummvmds", "--config=scummvmj.ini"};
+#elif defined(DS_BUILD_K)
+ const char *argv[] = {"/scummvmds", "--config=scummvmk.ini"};
#endif
+
while (1) {
scummvm_main(ARRAYSIZE(argv), (char **) &argv);
powerOff();
}
+
return 0;
}
@@ -3273,6 +3367,9 @@ int cygprofile_getHBlanks() __attribute__ ((no_instrument_function));
int cygprofile_getHBlanks() {
return DS::hBlankCount;
}
+
+
+extern "C" void consolePrintf(char * format, ...) __attribute__ ((no_instrument_function));
#endif
diff --git a/backends/platform/ds/arm9/source/dsmain.h b/backends/platform/ds/arm9/source/dsmain.h
index 223221d80e..beda592ba2 100644
--- a/backends/platform/ds/arm9/source/dsmain.h
+++ b/backends/platform/ds/arm9/source/dsmain.h
@@ -68,6 +68,9 @@ int leftHandedSwap(int keys);
void setGameScreenSwap(bool enable);
void setSensitivity(int sensitivity);
+// Controls options
+void setControls(char* gameName);
+
// Video
void displayMode8Bit(); // Switch to 8-bit mode5
void displayMode16Bit(); // Switch to 16-bit mode5
@@ -151,7 +154,7 @@ int getGameHeight();
void fastRamReset();
void* fastRamAlloc(int size);
-
+void exitGame();
gameListType* getCurrentGame();
diff --git a/backends/platform/ds/arm9/source/osystem_ds.cpp b/backends/platform/ds/arm9/source/osystem_ds.cpp
index 8ea9b06b23..111f3a888b 100644
--- a/backends/platform/ds/arm9/source/osystem_ds.cpp
+++ b/backends/platform/ds/arm9/source/osystem_ds.cpp
@@ -60,6 +60,12 @@
#define DEFAULT_CONFIG_FILE "scummvmg.ini"
#elif defined(DS_BUILD_H)
#define DEFAULT_CONFIG_FILE "scummvmh.ini"
+#elif defined(DS_BUILD_I)
+#define DEFAULT_CONFIG_FILE "scummvmi.ini"
+#elif defined(DS_BUILD_J)
+#define DEFAULT_CONFIG_FILE "scummvmj.ini"
+#elif defined(DS_BUILD_K)
+#define DEFAULT_CONFIG_FILE "scummvmk.ini"
#endif
OSystem_DS* OSystem_DS::_instance = NULL;
@@ -177,7 +183,7 @@ void OSystem_DS::setPalette(const byte *colors, uint start, uint num) {
green >>= 3;
blue >>= 3;
- //if (r != 255)
+// if (r != 255)
{
u16 paletteValue = red | (green << 5) | (blue << 10);
@@ -265,12 +271,13 @@ void OSystem_DS::grabPalette(unsigned char *colours, uint start, uint num) {
#define MISALIGNED16(ptr) (((u32) (ptr) & 1) != 0)
void OSystem_DS::copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h) {
- //consolePrintf("Copy rect %d, %d %d, %d ", x, y, w, h);
if (!_graphicsEnable) return;
if (w <= 1) return;
if (h < 0) return;
if (!DS::getIsDisplayMode8Bit()) return;
+// consolePrintf("CopyRectToScreen %d\n", w * h);
+
u16* bg;
s32 stride;
u16* bgSub = (u16 *)BG_GFX_SUB;
@@ -452,6 +459,8 @@ void OSystem_DS::copyRectToScreen(const byte *buf, int pitch, int x, int y, int
}
void OSystem_DS::updateScreen() {
+ static int cnt = 0;
+// consolePrintf("updatescr %d\n", cnt++);
if ((_frameBufferExists) && (DS::getIsDisplayMode8Bit())) {
_frameBufferExists = false;
@@ -883,6 +892,7 @@ u16 OSystem_DS::applyGamma(u16 colour) {
void OSystem_DS::engineDone() {
// Scumm games appear not to stop their CD audio, so I stop the CD here.
stopCD();
+ DS::exitGame();
#ifdef ENABLE_AGI
DS::clearAutoCompleteWordList();
diff --git a/backends/platform/ds/arm9/source/touchkeyboard.cpp b/backends/platform/ds/arm9/source/touchkeyboard.cpp
index ddf182950d..2d4b6a94f4 100644
--- a/backends/platform/ds/arm9/source/touchkeyboard.cpp
+++ b/backends/platform/ds/arm9/source/touchkeyboard.cpp
@@ -156,6 +156,29 @@ char autoCompleteBuffer[128];
int selectedCompletion = -1;
int charactersEntered = 0;
+int typingTimeout = 0;
+
+// Render text onto the tiled screen
+
+void drawText(int tx, int ty, char* string, bool highlight) {
+
+ u16 baseValue = 0;
+
+ if (highlight) {
+ baseValue |= 0x1000;
+ }
+
+ for (int p = 0; *string; string++, p++) {
+ char c = *string;
+
+ if (c != ' ') {
+ int tile = c - 33 + (KEYBOARD_DATA_SIZE / 32);
+ baseAddress[ty * 32 + tx + p] = baseValue | tile;
+ }
+ }
+
+}
+
void restoreVRAM(int tileBase, int mapBase, u16* saveSpace) {
@@ -246,12 +269,16 @@ void drawKeyboard(int tileBase, int mapBase, u16* saveSpace) {
keys[r].pressed = false;
}
+
closed = false;
clearAutoComplete();
+
}
+
void drawAutoComplete() {
+ // Clear the auto complete area at the bottom of the screen.
for (int y = 12; y < 24; y++) {
for (int x = 0; x < 32; x++) {
baseAddress[y * 32 + x] = 0;
@@ -259,23 +286,26 @@ void drawAutoComplete() {
}
- for (int r = 0; r < autoCompleteCount; r++) {
- int y = 12 + (r % 6) * 2;
- int x = 0 + ((r / 6) * 16);
-
- for (int p = 0; autoCompleteWord[r][p] != 0; p++) {
- char c = autoCompleteWord[r][p];
-
- int tile = c - 33 + (KEYBOARD_DATA_SIZE / 32);
+ if ((autoCompleteCount == 0) || (typingTimeout > 0)) {
- if (selectedCompletion == r) {
- tile |= 0x1000;
- }
+ // When there's no completions on the bottom of the screen, it acts like a mouse pad
+ // so this text indicates that
+ drawText(11, 18, "MOUSE AREA", true);
+
- baseAddress[y * 32 + x + p] = tile;
+ } else {
+ consolePrintf("time: %d\n", typingTimeout);
+ // Otherwise, draw autocompletions if one isn't being entered and there are
+ // some available.
+ for (int r = 0; r < autoCompleteCount; r++) {
+ int y = 12 + (r % 6) * 2;
+ int x = 0 + ((r / 6) * 16);
+
+ drawText(x, y, autoCompleteWord[r], selectedCompletion == r);
}
+
}
}
@@ -309,6 +339,12 @@ void setCharactersEntered(int count) {
charactersEntered = count;
}
+bool isInsideKeyboard(int x, int y) {
+ // When completions are available, keyboard covers the whole screen.
+ // otherwise, it only covers the area above KEYBOARD_BOTTOM_Y
+ return (autoCompleteCount > 0) || (y < KEYBOARD_BOTTOM_Y);
+}
+
void clearAutoComplete() {
autoCompleteCount = 0;
selectedCompletion = -1;
@@ -345,10 +381,8 @@ void typeCompletion(int current) {
system->addEvent(event);*/
}
-void updateTypeEvents()
-{
- if (autoCompleteBuffer[0] != '\0')
- {
+void updateTypeEvents() {
+ if (autoCompleteBuffer[0] != '\0') {
Common::Event event;
OSystem_DS* system = OSystem_DS::instance();
@@ -365,6 +399,8 @@ void updateTypeEvents()
{
autoCompleteBuffer[r] = autoCompleteBuffer[r + 1];
}
+
+ typingTimeout = 100;
}
}
@@ -424,6 +460,13 @@ void addKeyboardEvents() {
updateTypeEvents();
+ if (typingTimeout > 0) {
+ typingTimeout--;
+ if (typingTimeout == 0) {
+ drawAutoComplete();
+ }
+ }
+
if (DS::getPenDown()) {
int x = IPC->touchXpx;
int y = IPC->touchYpx;
@@ -443,7 +486,9 @@ void addKeyboardEvents() {
if (selectedCompletion == current) {
typeCompletion(current);
} else {
- selectedCompletion = current;
+ if (current < autoCompleteCount) {
+ selectedCompletion = current;
+ }
}
drawAutoComplete();
diff --git a/backends/platform/ds/arm9/source/touchkeyboard.h b/backends/platform/ds/arm9/source/touchkeyboard.h
index 2894281962..6ceb83bfc7 100644
--- a/backends/platform/ds/arm9/source/touchkeyboard.h
+++ b/backends/platform/ds/arm9/source/touchkeyboard.h
@@ -29,6 +29,7 @@ namespace DS {
static const int NUM_WORDS = 12;
static const int KEYBOARD_DATA_SIZE = 4736 * 2;
+static const int KEYBOARD_BOTTOM_Y = 105;
void createKeyEvent(int keyNum, Common::Event& event);
@@ -36,6 +37,7 @@ void drawKeyboard(int tileBase, int mapBase, u16* saveSpace);
void restoreVRAM(int tileBase, int mapBase, u16* saveSpace);
void addKeyboardEvents();
bool getKeyboardClosed();
+bool isInsideKeyboard(int x, int y);
void addAutoComplete(const char* word);
void clearAutoComplete();