From 764dc651012c07f8820b9001321f4f66f15116c6 Mon Sep 17 00:00:00 2001 From: Neil Millstone Date: Fri, 21 Dec 2007 18:36:40 +0000 Subject: Scaler corruption fixes, scaler console fixes, adding Lure target (except it doesn't quite work yet), adding function keys to virtual keyboard svn-id: r29944 --- backends/platform/ds/arm7/Makefile | 2 +- backends/platform/ds/arm9/data/keyboard.raw | Bin 8192 -> 9472 bytes backends/platform/ds/arm9/makefile | 109 +++++++++++++++++++-- backends/platform/ds/arm9/source/dsmain.cpp | 71 ++++++++++---- backends/platform/ds/arm9/source/dsmain.h | 1 + backends/platform/ds/arm9/source/dsoptions.cpp | 29 ++++-- backends/platform/ds/arm9/source/dsoptions.h | 1 + backends/platform/ds/arm9/source/fat/disc_io.h | 4 + backends/platform/ds/arm9/source/osystem_ds.cpp | 80 +++++++++------ backends/platform/ds/arm9/source/osystem_ds.h | 11 ++- backends/platform/ds/arm9/source/portdefs.cpp | 14 +++ backends/platform/ds/arm9/source/scummconsole.c | 2 +- backends/platform/ds/arm9/source/touchkeyboard.cpp | 106 ++++++++++++-------- backends/platform/ds/arm9/source/touchkeyboard.h | 5 +- 14 files changed, 321 insertions(+), 114 deletions(-) diff --git a/backends/platform/ds/arm7/Makefile b/backends/platform/ds/arm7/Makefile index 847b6eea5a..41af6a2d71 100644 --- a/backends/platform/ds/arm7/Makefile +++ b/backends/platform/ds/arm7/Makefile @@ -68,7 +68,7 @@ endif # list of directories containing libraries, this must be the top level containing # include and lib #--------------------------------------------------------------------------------- -LIBDIRS := /home/neil/devkitpro/libnds home/neil/devkitpro/libnds/nds +LIBDIRS := /home/neil/devkitpror21/libnds home/neil/devkitpror21/libnds/nds #--------------------------------------------------------------------------------- diff --git a/backends/platform/ds/arm9/data/keyboard.raw b/backends/platform/ds/arm9/data/keyboard.raw index 7fbeed70cc..e8779f81ea 100644 Binary files a/backends/platform/ds/arm9/data/keyboard.raw and b/backends/platform/ds/arm9/data/keyboard.raw differ diff --git a/backends/platform/ds/arm9/makefile b/backends/platform/ds/arm9/makefile index c93fd66dcd..a64de889ad 100644 --- a/backends/platform/ds/arm9/makefile +++ b/backends/platform/ds/arm9/makefile @@ -1,16 +1,51 @@ #BUILD_PLUGINS = 1 #libndsdir = $(DEVKITPRO)/libnds -libndsdir = /home/neil/devkitpro/libnds +libndsdir = /home/neil/devkitpror21/libnds # Select the build you want by uncommenting one of the following lines: -DS_BUILD_A = 1 + +ifeq ($(SCUMM_BUILD),a) + DS_BUILD_A = 1 +endif + +ifeq ($(SCUMM_BUILD),b) + DS_BUILD_B = 1 +endif + +ifeq ($(SCUMM_BUILD),c) + DS_BUILD_C = 1 +endif + +ifeq ($(SCUMM_BUILD),d) + DS_BUILD_D = 1 +endif + +ifeq ($(SCUMM_BUILD),e) + DS_BUILD_E = 1 +endif + +ifeq ($(SCUMM_BUILD),f) + DS_BUILD_F = 1 +endif + +ifeq ($(SCUMM_BUILD),g) + DS_BUILD_G = 1 +endif + +#DS_BUILD_A = 1 #DS_BUILD_B = 1 #DS_BUILD_C = 1 -#DS_BUILD_D = 1 +#DS_BUILD_D = 1 # started! #DS_BUILD_E = 1 #DS_BUILD_F = 1 +#DS_BUILD_G = 1 + +# To do: +# - FAT cache? + + # Uncomment the following line to build in support for MP3 audio # using libmad: @@ -71,6 +106,7 @@ ifdef DS_BUILD_A USE_ARM_GFX_ASM = 1 DISABLE_CRUISE = 1 DISABLE_DRASCULA = 1 + DISABLE_IGOR = 1 BUILD=scummvm-A endif @@ -81,10 +117,10 @@ ifdef DS_BUILD_B DISABLE_SCUMM = 1 DISABLE_SCUMM_7_8 = 1 DISABLE_AGOS = 1 - #DISABLE_SKY = 1 + #DISABLE_SKY = 1# DISABLE_SWORD1 = 1 DISABLE_SWORD2 = 1 - #DISABLE_QUEEN = 1 + #DISABLE_QUEEN = 1# DISABLE_SAGA = 1 DISABLE_KYRA = 1 DISABLE_GOB = 1 @@ -95,6 +131,7 @@ ifdef DS_BUILD_B DISABLE_PARALLACTION = 1 DISABLE_CRUISE = 1 DISABLE_DRASCULA = 1 + DISABLE_IGOR = 1 BUILD=scummvm-B endif @@ -119,6 +156,7 @@ ifdef DS_BUILD_C DISABLE_PARALLACTION = 1 DISABLE_CRUISE = 1 DISABLE_DRASCULA = 1 + DISABLE_IGOR = 1 BUILD=scummvm-C endif @@ -143,6 +181,7 @@ ifdef DS_BUILD_D DISABLE_PARALLACTION = 1 DISABLE_CRUISE = 1 DISABLE_DRASCULA = 1 + DISABLE_IGOR = 1 BUILD=scummvm-D endif @@ -168,6 +207,7 @@ ifdef DS_BUILD_E DISABLE_PARALLACTION = 1 DISABLE_CRUISE = 1 DISABLE_DRASCULA = 1 + DISABLE_IGOR = 1 BUILD=scummvm-E endif @@ -193,10 +233,40 @@ ifdef DS_BUILD_F DISABLE_PARALLACTION = 1 DISABLE_CRUISE = 1 DISABLE_DRASCULA = 1 + DISABLE_IGOR = 1 BUILD=scummvm-F endif + + +ifdef DS_BUILD_G + DEFINES = -DDS_NON_SCUMM_BUILD -DDS_BUILD_G + LOGO = logog.bmp + DISABLE_HE = 1 + DISABLE_SCUMM = 1 + DISABLE_SCUMM_7_8 = 1 + DISABLE_AGOS = 1 + DISABLE_SKY = 1 + DISABLE_SWORD1 = 1 + DISABLE_SWORD2 = 1 + DISABLE_QUEEN = 1 + DISABLE_SAGA = 1 + DISABLE_KYRA = 1 + DISABLE_GOB = 1 + #DISABLE_LURE = 1 + DISABLE_CINE = 1 + DISABLE_AGI = 1 + DISABLE_TOUCHE = 1 + DISABLE_PARALLACTION = 1 + DISABLE_CRUISE = 1 + DISABLE_DRASCULA = 1 + DISABLE_IGOR = 1 + BUILD=scummvm-G + +endif + + ARM7BIN := -7 $(CURDIR)/../../arm7/arm7.bin ICON := -b ../../../logo.bmp "ScummVM;By Neil Millstone;" @@ -219,7 +289,18 @@ ifdef USE_PROFILER endif CXXFLAGS= $(CFLAGS) -Wno-non-virtual-dtor -Wno-non-virtual-dtor \ - -fno-exceptions -fno-rtti + -fno-exceptions -fno-rtti -mthumb-interwork + +# -mthumb + +# -fno-gcse\ +# -fno-schedule-insns2 + +# -fno-inline-functions-called-once\ +# -fno-gcse-lm\ +# -fno-rerun-cse-after-loop\ +# -fno-cse-follow-jumps -fno-cse-skip-blocks\ + ASFLAGS = -mcpu=arm9tdmi -mthumb-interwork DEFINES += -D__DS__ -DNDS -DARM9 -DNONSTANDARD_PORT -DDISABLE_FANCY_THEMES -DDISABLE_DEFAULT_SAVEFILEMANAGER -DARM @@ -228,7 +309,7 @@ ifdef USE_MAD endif -LDFLAGS = -specs=ds_arm9.specs -mthumb-interwork -mno-fpu -Wl,-Map,map.txt +LDFLAGS = -specs=ds_arm9.specs -mthumb-interwork -Wl,--wrap,time -mno-fpu -Wl,-Map,map.txt INCLUDES= -I./ -I$(portdir)/$(BUILD) -I$(srcdir) -I$(srcdir)/common -I$(portdir)/source -I$(portdir)/source/compressor -I$(portdir)/source/fat \ -I$(srcdir)/backends/fs -I$(srcdir)/backends/fs/ds -I$(portdir)/data -I$(libndsdir)/include -I$(portdir)/../commoninclude\ @@ -302,9 +383,17 @@ FAT_OBJS := $(portdir)/source/fat/disc_io.o $(portdir)/source/fat/gba_nds_fat.o LIBCARTRESET_OBJS := $(portdir)/source/libcartreset/cartreset.o -# Files in this list will be compiled with -O2, otherwise they will be compiled with -Os -OPTLIST := actor.cpp ds_main.cpp osystem_ds.cpp blitters.cpp fmopl.cpp rate.cpp mixer.cpp +# Files in this list will be optimisied for speed, otherwise they will be optimised for space +OPTLIST := actor.cpp ds_main.cpp osystem_ds.cpp blitters.cpp fmopl.cpp rate.cpp mixer.cpp isomap.cpp image.cpp gfx.cpp sprite.cpp actor_path.cpp actor_walk.cpp #OPTLIST := + +# Compiler options for files which should be optimised for speed +OPT_SPEED := -O3 + +# Compiler options for files which should be optimised for space +OPT_SIZE := -Os -mthumb -fno-gcse -fno-schedule-insns2 + + OBJS := $(DATA_OBJS) $(LIBCARTRESET_OBJS) $(PORT_OBJS) $(COMPRESSOR_OBJS) $(FAT_OBJS) @@ -396,7 +485,7 @@ else $(MKDIR) $(*D)/$(DEPDIR) $(CXX) -Wp,-MMD,"$(*D)/$(DEPDIR)/$(*F).d",-MQ,"$@",-MP $(CXXFLAGS) $(CPPFLAGS) -c $(<) -o $*.o - $(CXX) -MMD -MF "$(*D)/$(DEPDIR)/$(*F).d" $(CXXFLAGS) $(CPPFLAGS) -c $(<) -o $*.o $(if $(findstring $(notdir $<), $(OPTLIST)), -O2, -Os) + $(CXX) -MMD -MF "$(*D)/$(DEPDIR)/$(*F).d" $(if $(findstring $(notdir $<), $(OPTLIST)), $(OPT_SPEED), $(OPT_SIZE)) $(CXXFLAGS) $(CPPFLAGS) -c $(<) -o $*.o endif diff --git a/backends/platform/ds/arm9/source/dsmain.cpp b/backends/platform/ds/arm9/source/dsmain.cpp index 4d747604c6..07eb222dfb 100644 --- a/backends/platform/ds/arm9/source/dsmain.cpp +++ b/backends/platform/ds/arm9/source/dsmain.cpp @@ -210,6 +210,7 @@ int gameHeight = 200; // Scale bool twoHundredPercentFixedScale = false; +bool cpuScalerEnable = false; #define NUM_SUPPORTED_GAMES 17 #ifdef USE_PROFILER @@ -282,9 +283,18 @@ TransferSound soundControl; bool isCpuScalerEnabled() { - return (ConfMan.hasKey("cpu_scaler", "ds") && ConfMan.getBool("cpu_scaler", "ds")); + return cpuScalerEnable; } + +void setCpuScalerEnable(bool enable) { + cpuScalerEnable = enable; +} + + +// return (ConfMan.hasKey("cpu_scaler", "ds") && ConfMan.getBool("cpu_scaler", "ds")); + + //plays an 8 bit mono sample at 11025Hz void playSound(const void* data, u32 length, bool loop, bool adpcm, int rate) { @@ -352,7 +362,14 @@ void saveGameBackBuffer() { #ifdef DISABLE_SCUMM if (savedBuffer == NULL) savedBuffer = new u8[gameWidth * gameHeight]; for (int r = 0; r < gameHeight; r++) { - memcpy(savedBuffer + (r * gameWidth), ((u8 *) (get8BitBackBuffer())) + (r * 512), gameWidth); + + u16* dst = (u16 *) (savedBuffer + (r * gameWidth)); + u16* src = BG_GFX_SUB + (r * 256); + + for (int x = 0; x < gameWidth >> 1; x++) + { + *dst++ = *src++; + } } #endif } @@ -361,10 +378,19 @@ void restoreGameBackBuffer() { #ifdef DISABLE_SCUMM if (savedBuffer) { for (int r = 0; r < gameHeight; r++) { - memcpy(((u8 *) (BG_GFX_SUB)) + (r * 512), savedBuffer + (r * gameWidth), gameWidth); - memcpy(((u8 *) (get8BitBackBuffer())) + (r * 512), savedBuffer + (r * gameWidth), gameWidth); - } + + u16* dst = get8BitBackBuffer() + (r * 256); + u16* dst2 = BG_GFX_SUB + (r * 256); + u16* src = ((u16 *) (savedBuffer)) + (r * (gameWidth >> 1)); + + for (int x = 0; x < gameWidth >> 1; x++) + { + *dst++ = *src; + *dst2++ = *src++; + } + } + delete savedBuffer; savedBuffer = NULL; } @@ -500,7 +526,7 @@ void displayMode8Bit() { if (isCpuScalerEnabled()) { - videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_1D_BMP); + videoSetMode(MODE_5_2D | (consoleEnable? DISPLAY_BG0_ACTIVE: 0) | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_1D_BMP); videoSetModeSub(MODE_3_2D /*| DISPLAY_BG0_ACTIVE*/ | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_1D_BMP); //sub bg 0 will be used to print text vramSetBankA(VRAM_A_MAIN_BG_0x06000000); @@ -548,22 +574,27 @@ void displayMode8Bit() { // Do text stuff - BG0_CR = BG_MAP_BASE(0) | BG_TILE_BASE(1); + // console chars at 1C000 (7), map at 1D000 (74) + + BG0_CR = BG_MAP_BASE(2) | BG_TILE_BASE(0); BG0_Y0 = 0; // Restore palette entry used by text in the front-end // PALETTE_SUB[255] = savedPalEntry255; + + - consoleInitDefault((u16*)SCREEN_BASE_BLOCK(0), (u16*)CHAR_BASE_BLOCK(1), 16); + 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(0))[r] = buffer[r]; + ((u16 *) SCREEN_BASE_BLOCK(2))[r] = buffer[r]; } // dmaCopyHalfWords(3, (u16 *) SCREEN_BASE_BLOCK(0), buffer, 32 * 32 * 2); } + initGame(); if (!displayModeIs8Bit) restoreGameBackBuffer(); displayModeIs8Bit = true; @@ -571,10 +602,10 @@ void displayMode8Bit() { consolePrintf("done\n"); #endif + POWER_CR &= ~POWER_SWAP_LCDS; keyboardEnable = false; - initGame(); } @@ -722,7 +753,7 @@ void displayMode16Bit() { if (displayModeIs8Bit) { saveGameBackBuffer(); for (int r = 0; r < 32 * 32; r++) { - buffer[r] = ((u16 *) SCREEN_BASE_BLOCK(0))[r]; + buffer[r] = ((u16 *) SCREEN_BASE_BLOCK(2))[r]; } } @@ -846,7 +877,7 @@ u16* get16BitBackBuffer() { u16* get8BitBackBuffer() { if (isCpuScalerEnabled()) - return BG_GFX; + return BG_GFX + 0x60000; else return BG_GFX + 0x10000; // 16bit qty! } @@ -1047,10 +1078,10 @@ void setKeyboardEnable(bool en) { if (keyboardEnable) { - DS::drawKeyboard(1, 14, backupBank); + DS::drawKeyboard(1, 15, backupBank); - SUB_BG1_CR = BG_TILE_BASE(1) | BG_MAP_BASE(14); + SUB_BG1_CR = BG_TILE_BASE(1) | BG_MAP_BASE(15); if (displayModeIs8Bit) { SUB_DISPLAY_CR |= DISPLAY_BG1_ACTIVE; // Turn on keyboard layer @@ -2568,7 +2599,7 @@ int main(void) consolePrintf("-------------------------------\n"); consolePrintf("ScummVM DS\n"); consolePrintf("Ported by Neil Millstone\n"); - consolePrintf("Version 0.11.0SVN "); + consolePrintf("Version 0.11.0 beta1 "); #if defined(DS_BUILD_A) consolePrintf("build A\n"); consolePrintf("Lucasarts SCUMM games (SCUMM)\n"); @@ -2579,7 +2610,7 @@ int main(void) consolePrintf("-------------------------------\n"); #elif defined(DS_BUILD_C) consolePrintf("build C\n"); - consolePrintf("Simon the Sorcerer 1/2 (SIMON)\n"); + consolePrintf("Simon/Elvira (AGOS)\n"); consolePrintf("-------------------------------\n"); #elif defined(DS_BUILD_D) consolePrintf("build D\n"); @@ -2587,12 +2618,16 @@ int main(void) consolePrintf("-------------------------------\n"); #elif defined(DS_BUILD_E) consolePrintf("build E\n"); - consolePrintf("Inherit the earth (SAGA)\n"); + consolePrintf("ITE/IHNM (SAGA)\n"); consolePrintf("-------------------------------\n"); #elif defined(DS_BUILD_F) consolePrintf("build F\n"); consolePrintf("The Legend of Kyrandia (KYRA)\n"); consolePrintf("-------------------------------\n"); +#elif defined(DS_BUILD_G) + consolePrintf("build F\n"); + consolePrintf("Lure of the Temptress (LURE)\n"); + consolePrintf("-------------------------------\n"); #endif consolePrintf("L/R + D-pad/pen: Scroll view\n"); consolePrintf("D-pad left: Left mouse button\n"); @@ -2730,6 +2765,8 @@ int main(void) char* argv[3] = {"/scummvmds", "--config=scummvme.ini"}; #elif defined(DS_BUILD_F) char* argv[3] = {"/scummvmds", "--config=scummvmf.ini"}; +#elif defined(DS_BUILD_G) + char* argv[3] = {"/scummvmds", "--config=scummvmg.ini"}; #endif #ifdef DS_NON_SCUMM_BUILD diff --git a/backends/platform/ds/arm9/source/dsmain.h b/backends/platform/ds/arm9/source/dsmain.h index 1f6e6374ed..314ec97a44 100644 --- a/backends/platform/ds/arm9/source/dsmain.h +++ b/backends/platform/ds/arm9/source/dsmain.h @@ -129,6 +129,7 @@ void setSnapToBorder(bool enable); void setIndyFightState(bool st); bool getIndyFightState(); bool isCpuScalerEnabled(); +void setCpuScalerEnable(bool enable); // Display bool getIsDisplayMode8Bit(); diff --git a/backends/platform/ds/arm9/source/dsoptions.cpp b/backends/platform/ds/arm9/source/dsoptions.cpp index 0900e8e1e1..07fd121f05 100644 --- a/backends/platform/ds/arm9/source/dsoptions.cpp +++ b/backends/platform/ds/arm9/source/dsoptions.cpp @@ -58,9 +58,9 @@ DSOptionsDialog::DSOptionsDialog() : GUI::Dialog(20, 0, 320 - 40, 230 - 20) { _highQualityAudioCheckbox = new GUI::CheckboxWidget(this, 20, 85, 250, 20, "High quality audio (slower) (reboot)", 0, 'T'); _disablePowerOff = new GUI::CheckboxWidget(this, 20, 100, 250, 20, "Disable power off on quit", 0, 'T'); _showCursorCheckbox = new GUI::CheckboxWidget(this, 20, 115, 130, 20, "Show mouse cursor", 0, 'T'); - #ifdef ALLOW_CPU_SCALER +#ifdef ALLOW_CPU_SCALER _cpuScaler = new GUI::CheckboxWidget(this, 160, 115, 90, 20, "CPU scaler", 0, 'T'); - #endif +#endif _snapToBorderCheckbox = new GUI::CheckboxWidget(this, 20, 130, 250, 20, "Snap to border", 0, 'T'); new GUI::StaticTextWidget(this, 20, 145, 110, 15, "Touch X Offset", GUI::kTextAlignLeft); @@ -156,26 +156,29 @@ DSOptionsDialog::DSOptionsDialog() : GUI::Dialog(20, 0, 320 - 40, 230 - 20) { } DSOptionsDialog::~DSOptionsDialog() { + DS::setIndyFightState(_indyFightCheckbox->getState()); + ConfMan.flushToDisk(); +} + +void DSOptionsDialog::updateConfigManager() { ConfMan.setBool("lefthanded", _leftHandedCheckbox->getState(), "ds"); ConfMan.setBool("unscaled", _unscaledCheckbox->getState(), "ds"); ConfMan.setBool("twohundredpercent", _twoHundredPercentCheckbox->getState(), "ds"); ConfMan.setBool("22khzaudio", _highQualityAudioCheckbox->getState(), "ds"); ConfMan.setBool("disablepoweroff", _disablePowerOff->getState(), "ds"); - #ifdef ALLOW_CPU_SCALER +#ifdef ALLOW_CPU_SCALER ConfMan.setBool("cpu_scaler", _cpuScaler->getState(), "ds"); - #endif +#endif ConfMan.setInt("xoffset", _touchX->getValue(), "ds"); ConfMan.setInt("yoffset", _touchY->getValue(), "ds"); ConfMan.setBool("showcursor", _showCursorCheckbox->getState(), "ds"); ConfMan.setBool("snaptoborder", _snapToBorderCheckbox->getState(), "ds"); DS::setOptions(); - DS::setIndyFightState(_indyFightCheckbox->getState()); - ConfMan.flushToDisk(); } - void DSOptionsDialog::handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data) { if (cmd == GUI::kCloseCmd) { + updateConfigManager(); close(); } @@ -236,9 +239,10 @@ void showOptionsDialog() { DSOptionsDialog* d = new DSOptionsDialog(); d->runModal(); + consolePrintf("deleting dialog\n"); delete d; - + consolePrintf("going to 8 bit\n"); DS::displayMode8Bit(); togglePause(); @@ -292,7 +296,14 @@ void setOptions() { } else { DS::setTouchXOffset(0); } - + +#ifdef ALLOW_CPU_SCALER + if (ConfMan.hasKey("cpu_scaler", "ds")) { + DS::setCpuScalerEnable(ConfMan.getBool("cpu_scaler", "ds")); + } else { + DS::setCpuScalerEnable(false); + } +#endif } } diff --git a/backends/platform/ds/arm9/source/dsoptions.h b/backends/platform/ds/arm9/source/dsoptions.h index c0e87ab630..9a345feb3b 100644 --- a/backends/platform/ds/arm9/source/dsoptions.h +++ b/backends/platform/ds/arm9/source/dsoptions.h @@ -43,6 +43,7 @@ public: protected: virtual void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data); void togglePause(); + void updateConfigManager(); GUI::SliderWidget* _touchX; GUI::SliderWidget* _touchY; diff --git a/backends/platform/ds/arm9/source/fat/disc_io.h b/backends/platform/ds/arm9/source/fat/disc_io.h index 1e1638c3c4..05d4c020bd 100644 --- a/backends/platform/ds/arm9/source/fat/disc_io.h +++ b/backends/platform/ds/arm9/source/fat/disc_io.h @@ -46,6 +46,10 @@ #define REG_EXMEMCNT REG_EXEMEMCNT #endif +#ifndef REG_EXEMEMCNT +#define REG_EXEMEMCNT REG_EXMEMCNT +#endif + //---------------------------------------------------------------------- #if defined _CF_USE_DMA && defined _CF_ALLOW_UNALIGNED diff --git a/backends/platform/ds/arm9/source/osystem_ds.cpp b/backends/platform/ds/arm9/source/osystem_ds.cpp index 6427f3c079..455327f530 100644 --- a/backends/platform/ds/arm9/source/osystem_ds.cpp +++ b/backends/platform/ds/arm9/source/osystem_ds.cpp @@ -41,13 +41,15 @@ OSystem_DS* OSystem_DS::_instance = NULL; OSystem_DS::OSystem_DS() + : eventNum(0), lastPenFrame(0), queuePos(0), _mixer(NULL), _timer(NULL), _frameBufferExists(false) { - eventNum = 0; - lastPenFrame = 0; - queuePos = 0; +// eventNum = 0; +// lastPenFrame = 0; +// queuePos = 0; _instance = this; - _mixer = NULL; - _timer = NULL; +// _mixer = NULL; + // _timer = NULL; + //_frameBufferExists = false; } OSystem_DS::~OSystem_DS() { @@ -229,6 +231,18 @@ void OSystem_DS::copyRectToScreen(const byte *buf, int pitch, int x, int y, int void OSystem_DS::updateScreen() { + + if (_frameBufferExists) + { + // Copy temp framebuffer back to screen + copyRectToScreen((byte *)_framebuffer.pixels, _framebuffer.pitch, 0, 0, _framebuffer.w, _framebuffer.h); + + // Free memory + _framebuffer.free(); + + _frameBufferExists = false; + } + DS::displayMode16BitFlipBuffer(); DS::doSoundCallback(); // DS::doTimerCallback(); @@ -495,51 +509,53 @@ Common::SaveFileManager* OSystem_DS::getSavefileManager() } } -Graphics::Surface *OSystem_DS::lockScreen() { -/* // For now, we create a full temporary screen surface, to which we copy the + +Graphics::Surface* OSystem_DS::createTempFrameBuffer() { + // For now, we create a full temporary screen surface, to which we copy the // the screen content. Later unlockScreen will copy everything back. // Not very nice nor efficient, but at least works, and is not worse // than in the bad old times where we used grabRawScreen + copyRectToScreen. - +// consolePrintf("lockScreen()\n"); _framebuffer.create(DS::getGameWidth(), DS::getGameHeight(), 1); // Ensure we copy using 16 bit quantities due to limitation of VRAM addressing -<<<<<<< .working + size_t imageStrideInBytes = DS::isCpuScalerEnabled()? DS::getGameWidth() : 512; + size_t imageStrideInWords = imageStrideInBytes / 2; -======= - - size_t imageStrideInBytes = DS::isCpuScalerEnabled()? DS::getGameWidth() : 512; - size_t imageStrideInWords = imageStrideInBytes / 2; - ->>>>>>> .merge-right.r28656 u16* image = (u16 *) DS::get8BitBackBuffer(); - for (int y = 0; y < DS::getGameHeight(); y++) - { -<<<<<<< .working - DC_FlushRange(image + (y << 8), DS::getGameWidth()); -======= + for (int y = 0; y < DS::getGameHeight(); y++) { DC_FlushRange(image + (y * imageStrideInWords), DS::getGameWidth()); ->>>>>>> .merge-right.r28656 - for (int x = 0; x < DS::getGameWidth() >> 1; x++) - { -<<<<<<< .working - *(((u16 *) (_framebuffer.pixels)) + y * (DS::getGameWidth() >> 1) + x) = image[y << 8 + x]; -======= - *(((u16 *) (surf->pixels)) + y * (DS::getGameWidth() >> 1) + x) = image[y * imageStrideInWords + x]; ->>>>>>> .merge-right.r28656 + for (int x = 0; x < DS::getGameWidth() >> 1; x++) { + *(((u16 *) (_framebuffer.pixels)) + y * (DS::getGameWidth() >> 1) + x) = image[(y << 8) + x]; +// *(((u16 *) (surf->pixels)) + y * (DS::getGameWidth() >> 1) + x) = image[y * imageStrideInWords + x]; } } +// consolePrintf("lockScreen() done\n"); + _frameBufferExists = true; + + return &_framebuffer; +} + + +Graphics::Surface *OSystem_DS::lockScreen() { + if (!_frameBufferExists) { + createTempFrameBuffer(); + } - return &_framebuffer;*/ + return &_framebuffer; } void OSystem_DS::unlockScreen() { -/* // Copy temp framebuffer back to screen - copyRectToScreen((byte *)_framebuffer.pixels, _framebuffer.pitch, 0, 0, _framebuffer.w, _framebuffer.h); + +// consolePrintf("unlockScreen()\n"); + + // Copy temp framebuffer back to screen +// copyRectToScreen((byte *)_framebuffer.pixels, _framebuffer.pitch, 0, 0, _framebuffer.w, _framebuffer.h); // Free memory - _framebuffer.free(); */ +// _framebuffer.free(); +// consolePrintf("unlockScreen() done\n"); } void OSystem_DS::setFocusRectangle(const Common::Rect& rect) { diff --git a/backends/platform/ds/arm9/source/osystem_ds.h b/backends/platform/ds/arm9/source/osystem_ds.h index 0dc790030a..cae40be634 100644 --- a/backends/platform/ds/arm9/source/osystem_ds.h +++ b/backends/platform/ds/arm9/source/osystem_ds.h @@ -41,9 +41,8 @@ class DSTimerManager : public DefaultTimerManager { class OSystem_DS : public OSystem { -public: +protected: - static OSystem_DS *instance() { return _instance; } int eventNum; int lastPenFrame; @@ -55,18 +54,22 @@ public: DSAudioMixer* _mixer; DSTimerManager* _timer; Graphics::Surface _framebuffer; + bool _frameBufferExists; static OSystem_DS* _instance; - typedef void (*SoundProc)(void *param, byte *buf, int len); - typedef int (*TimerProc)(int interval); + Graphics::Surface* createTempFrameBuffer(); public: + typedef void (*SoundProc)(void *param, byte *buf, int len); + typedef int (*TimerProc)(int interval); OSystem_DS(); virtual ~OSystem_DS(); + static OSystem_DS *instance() { return _instance; } + virtual bool hasFeature(Feature f); virtual void setFeatureState(Feature f, bool enable); virtual bool getFeatureState(Feature f); diff --git a/backends/platform/ds/arm9/source/portdefs.cpp b/backends/platform/ds/arm9/source/portdefs.cpp index e669dd5b80..075d24d909 100644 --- a/backends/platform/ds/arm9/source/portdefs.cpp +++ b/backends/platform/ds/arm9/source/portdefs.cpp @@ -24,7 +24,20 @@ #include "nds/dma.h" #include "osystem_ds.h" +/* +extern "C" time_t __wrap_time(time_t* t) { + if (t) { + *t = OSystem_DS::instance()->getMillis() / 1000; + } + + return OSystem_DS::instance()->getMillis() / 1000; +} +*/ + + + time_t DS_time(time_t) { + consolePrintf("Time!"); if (OSystem_DS::instance()) { return 0xABCD1234 + (OSystem_DS::instance()->getMillis() / 1000); } else { @@ -33,6 +46,7 @@ time_t DS_time(time_t) { } time_t DS_time(long* t) { + consolePrintf("Time!"); if (OSystem_DS::instance()) { if (t) *t = 0xABCD1234 + (OSystem_DS::instance()->getMillis() / 1000); return 0xABCD1234 + (OSystem_DS::instance()->getMillis() / 1000); diff --git a/backends/platform/ds/arm9/source/scummconsole.c b/backends/platform/ds/arm9/source/scummconsole.c index b2b312e25d..2145b47353 100644 --- a/backends/platform/ds/arm9/source/scummconsole.c +++ b/backends/platform/ds/arm9/source/scummconsole.c @@ -140,7 +140,7 @@ void consoleInit(u16* font, u16* charBase, u16 numCharacters, u8 charStart, u16* void consoleInitDefault(u16* map, u16* charBase, u8 bitDepth) { - consoleInit((u16 *) default_font_bin, charBase, 256, 0, map, CONSOLE_USE_COLOR255, bitDepth); + consoleInit((u16 *) default_font_bin, charBase, 128, 0, map, CONSOLE_USE_COLOR255, bitDepth); } void consolePrintSet(int x, int y) diff --git a/backends/platform/ds/arm9/source/touchkeyboard.cpp b/backends/platform/ds/arm9/source/touchkeyboard.cpp index 8b3b651132..9ac8361985 100644 --- a/backends/platform/ds/arm9/source/touchkeyboard.cpp +++ b/backends/platform/ds/arm9/source/touchkeyboard.cpp @@ -31,12 +31,12 @@ namespace DS { struct key_data { char keyNum; - char x, y; + signed char x, y; int character; bool pressed; }; -#define DS_NUM_KEYS 60 +#define DS_NUM_KEYS 72 #define DS_SHIFT 2 #define DS_BACKSPACE 8 #define DS_RETURN 13 @@ -119,6 +119,20 @@ key_data keys[DS_NUM_KEYS] = { // Close button {56, 30, 0, Common::KEYCODE_INVALID}, + + // Function keys (needed for AGI) + {57, 4, -2, Common::KEYCODE_F1}, + {58, 6, -2, Common::KEYCODE_F2}, + {59, 8, -2, Common::KEYCODE_F3}, + {60, 10, -2, Common::KEYCODE_F4}, + {61, 14, -2, Common::KEYCODE_F5}, + {62, 16, -2, Common::KEYCODE_F6}, + {63, 18, -2, Common::KEYCODE_F7}, + {64, 20, -2, Common::KEYCODE_F8}, + {65, 24, -2, Common::KEYCODE_F9}, + {66, 26, -2, Common::KEYCODE_F10}, + {67, 28, -2, Common::KEYCODE_F11}, + {68, 30, -2, Common::KEYCODE_F12}, }; @@ -155,14 +169,14 @@ void restoreVRAM(int tileBase, int mapBase, u16* saveSpace) { } void drawKeyboard(int tileBase, int mapBase, u16* saveSpace) { - + int keyboardDataSize = 4736 * 2; for (int r = 0; r < 32 * 32; r++) { // *saveSpace++ = ((u16 *) SCREEN_BASE_BLOCK_SUB(mapBase))[r]; - ((u16 *) SCREEN_BASE_BLOCK_SUB(mapBase))[r] = 127; + ((u16 *) SCREEN_BASE_BLOCK_SUB(mapBase))[r] = 0; } - for (int r = 0; r < 4096; r++) { + for (int r = 0; r < KEYBOARD_DATA_SIZE / 2; r++) { // *saveSpace++ = ((u16 *) CHAR_BASE_BLOCK_SUB(tileBase))[r]; ((u16 *) CHAR_BASE_BLOCK_SUB(tileBase))[r] = ((u16 *) (keyboard_raw))[r]; } @@ -174,7 +188,7 @@ void drawKeyboard(int tileBase, int mapBase, u16* saveSpace) { // this is the font for (int tile = 0; tile < 94; tile++) { - u16* tileAddr = (u16 *) (CHAR_BASE_BLOCK_SUB(tileBase) + (8192 + (tile * 32))); + u16* tileAddr = (u16 *) (CHAR_BASE_BLOCK_SUB(tileBase) + ((KEYBOARD_DATA_SIZE) + (tile * 32))); u8* src = ((u8 *) (_8x8font_tga_raw)) + 18 + tile * 8; for (int y = 0 ; y < 8; y++) { @@ -208,7 +222,7 @@ void drawKeyboard(int tileBase, int mapBase, u16* saveSpace) { } keyboardX = -2; - keyboardY = 1; + keyboardY = 2; DS::mapBase = mapBase; DS::tileBase = tileBase; @@ -223,11 +237,11 @@ void drawKeyboard(int tileBase, int mapBase, u16* saveSpace) { baseAddress = base; for (int r = 0; r < DS_NUM_KEYS; r++) { - base[(y + keys[r].y) * 32 + x + keys[r].x] = keys[r].keyNum * 2; - base[(y + keys[r].y) * 32 + x + keys[r].x + 1] = keys[r].keyNum * 2 + 1; + base[(y + keys[r].y) * 32 + x + keys[r].x] = 10 + keys[r].keyNum * 2; + base[(y + keys[r].y) * 32 + x + keys[r].x + 1] = 10 + keys[r].keyNum * 2 + 1; - base[(y + keys[r].y + 1) * 32 + x + keys[r].x] = 128 + keys[r].keyNum * 2; - base[(y + keys[r].y + 1) * 32 + x + keys[r].x + 1] = 128 + keys[r].keyNum * 2 + 1; + base[(y + keys[r].y + 1) * 32 + x + keys[r].x] = 10 + 148 + keys[r].keyNum * 2; + base[(y + keys[r].y + 1) * 32 + x + keys[r].x + 1] = 10 + 148 + keys[r].keyNum * 2 + 1; keys[r].pressed = false; } @@ -240,7 +254,7 @@ void drawAutoComplete() { for (int y = 12; y < 24; y++) { for (int x = 0; x < 32; x++) { - baseAddress[y * 32 + x] = 127; + baseAddress[y * 32 + x] = 0; } } @@ -252,7 +266,7 @@ void drawAutoComplete() { for (int p = 0; p < strlen(autoCompleteWord[r]); p++) { char c = autoCompleteWord[r][p]; - int tile = c - 32 + 255; + int tile = c - 33 + (KEYBOARD_DATA_SIZE / 32); if (selectedCompletion == r) { tile |= 0x1000; @@ -354,6 +368,34 @@ void updateTypeEvents() } } +void createKeyEvent(int keyNum, Common::Event& event) +{ + event.kbd.flags = 0; + + if ((keys[keyNum].character >= '0') && (keys[keyNum].character <= '9')) { + + if (!DS::shiftState) { + event.kbd.ascii = keys[keyNum].character; + event.kbd.keycode = (Common::KeyCode) keys[keyNum].character; //Common::KEYCODE_INVALID; + } else { + event.kbd.keycode = (Common::KeyCode) (Common::KEYCODE_F1 - (keys[keyNum].character - '1')); + event.kbd.ascii = 0; + } + + } else if ((keys[keyNum].character >= 'A') && (keys[keyNum].character <= 'Z')) { + + if ((!DS::shiftState) && (!DS::capsLockState)) { + event.kbd.ascii = keys[keyNum].character + 32; // Make key lowercase. + } else { + event.kbd.ascii = keys[keyNum].character; + } + + event.kbd.keycode = (Common::KeyCode) event.kbd.ascii; + } else { + event.kbd.ascii = keys[keyNum].character; + event.kbd.keycode = (Common::KeyCode) keys[keyNum].character; + } +} void addKeyboardEvents() { updateTypeEvents(); @@ -398,40 +440,17 @@ void addKeyboardEvents() { if ((keys[r].character == Common::KEYCODE_INVALID)) { // Close button DS::closed = true; - } else if ((keys[r].character >= '0') && (keys[r].character <= '9')) { - - if (!DS::shiftState) { - event.kbd.ascii = keys[r].character; - event.kbd.keycode = Common::KEYCODE_INVALID; - } else { - event.kbd.keycode = (Common::KeyCode) (Common::KEYCODE_F1 - (keys[r].character - '1')); - event.kbd.ascii = 0; - } - - } else if ((keys[r].character >= 'A') && (keys[r].character <= 'Z')) { - - if ((!DS::shiftState) && (!DS::capsLockState)) { - event.kbd.ascii = keys[r].character + 32; // Make key lowercase. - } else { - event.kbd.ascii = keys[r].character; - } - - event.kbd.keycode = (Common::KeyCode) event.kbd.ascii; } else { - event.kbd.ascii = keys[r].character; - event.kbd.keycode = (Common::KeyCode) keys[r].character; + createKeyEvent(r, event); } - - //event.kbd.keycode = keys[r].character; //event.kbd.ascii = keys[r].character; event.type = Common::EVENT_KEYDOWN; - event.kbd.flags = 0; system->addEvent(event); - event.type = Common::EVENT_KEYUP; - system->addEvent(event); +// event.type = Common::EVENT_KEYUP; +// system->addEvent(event); switch (keys[r].character) { case DS_SHIFT: { @@ -467,9 +486,18 @@ void addKeyboardEvents() { } if (DS::getPenReleased()) { + for (int r = 0; r < DS_NUM_KEYS; r++) { if (keys[r].pressed) { DS::setKeyHighlight(r, false); + + OSystem_DS* system = OSystem_DS::instance(); + + Common::Event event; + createKeyEvent(r, event); + event.type = Common::EVENT_KEYUP; + system->addEvent(event); + keys[r].pressed = false; } } diff --git a/backends/platform/ds/arm9/source/touchkeyboard.h b/backends/platform/ds/arm9/source/touchkeyboard.h index 17988e050a..8a5fc728ce 100644 --- a/backends/platform/ds/arm9/source/touchkeyboard.h +++ b/backends/platform/ds/arm9/source/touchkeyboard.h @@ -23,11 +23,14 @@ #ifndef _TOUCHKEYBOARD_H_ #define _TOUCHKEYBOARD_H_ +#include "osystem_ds.h" + namespace DS { static const int NUM_WORDS = 12; +static const int KEYBOARD_DATA_SIZE = 4736 * 2; - +void createKeyEvent(int keyNum, Common::Event& event); void drawKeyboard(int tileBase, int mapBase, u16* saveSpace); void restoreVRAM(int tileBase, int mapBase, u16* saveSpace); -- cgit v1.2.3