From 7db72310244e11524cad14105017fd82c46a0d94 Mon Sep 17 00:00:00 2001 From: James Brown Date: Thu, 14 Mar 2002 14:09:14 +0000 Subject: Add files for new WinCE port. svn-id: r3750 --- wince/findgame.cpp | 416 ++++++++++++++++++++++++ wince/gapi_keys.cpp | 223 +++++++++++++ wince/pocketpc.cpp | 867 ++++++++++++++++++++++++++++++++++++-------------- wince/pocketscumm.ico | Bin 0 -> 670 bytes 4 files changed, 1272 insertions(+), 234 deletions(-) create mode 100644 wince/findgame.cpp create mode 100644 wince/gapi_keys.cpp create mode 100644 wince/pocketscumm.ico (limited to 'wince') diff --git a/wince/findgame.cpp b/wince/findgame.cpp new file mode 100644 index 0000000000..6b1c4dd76d --- /dev/null +++ b/wince/findgame.cpp @@ -0,0 +1,416 @@ +#ifdef _WIN32_WCE + +// Browse directories to locate SCUMM games + +#include "stdafx.h" +#include +#include "resource.h" + +#define MAX_GAMES 20 + +struct ScummGame { + const char *gamename; + const char *description; + const char *directory; + const char *check_file_1; + const char *check_file_2; + const char *filename; + unsigned char next_demo; +}; + +struct InstalledScummGame { + unsigned char reference; + TCHAR directory[MAX_PATH]; +}; + +static const ScummGame GameList[] = { + { + "Indiana Jones 3 (new)", + "Buggy, unplayable", + "indy3", "", "", + "indy3", + 0 + }, + { + "Zak Mc Kracken (new)", + "Buggy, unplayable", + "zak256", "", "", + "zak256", + 0 + }, + { + "Loom (old)", + "Not working", + "loom", "", "", + "loom", + 0 + }, + { + "Monkey Island 1 (EGA)", + "Not tested", + "monkeyEGA", "", "", + "monkeyEGA", + 0 + }, + { + "Loom (VGA)", + "Buggy, playable a bit", + "loomcd", "", "", + "loomcd", + 0 + }, + { + "Monkey Island 1 (VGA)", + "Working well, perhaps completable ?", + "", "MONKEY.000", "MONKEY.001", + "monkey", + 0 + }, + { + "Monkey Island 2 (VGA)", + "Completable", + "", "MONKEY2.000", "MONKEY2.001", + "monkey2", + 0 + }, + { + "Indiana Jones 4", + "Completable", + "", "ATLANTIS.000", "ATLANTIS.001", + "atlantis", + 1 + }, + { + "Indiana Jones 4 demo", + "Completable", + "", "PLAYFATE.000", "PLAYFATE.001", + "playfate", + 0 + }, + { + "Day of the Tentacle", + "Completable", + "", "TENTACLE.000", "TENTACLE.001", + "tentacle", + 1 + }, + { + "Day of the Tentacle demo", + "Completable", + "", "DOTTDEMO.000", "DOTTDEMO.001", + "dottdemo", + 0 + }, + { + "Sam & Max", + "Completable,glitches,no music", + "", "SAMNMAX.000", "SAMNMAX.001", + "samnmax", + 1 + }, + { + "Sam & Max demo", + "Completable, minor glitches, no music", + "", "SNMDEMO.000", "SNMDEMO.001", + "snmdemo", + 0 + }, + { + "Full Throttle", + "Partially working", + "", "FT.LA0", "FT.LA1", + "ft", + 0 + }, + { + "The Dig", + "Partially working", + "", "DIG.LA0", "DIG.LA1", + "dig", + 0 + }, + { + NULL, NULL, NULL, NULL, NULL, NULL, 0 + } +}; + +void findGame(TCHAR*); +int displayFoundGames(void); + +char gamesFound[MAX_GAMES]; +unsigned char listIndex[MAX_GAMES]; +InstalledScummGame gamesInstalled[MAX_GAMES]; +int installedGamesNumber; +HWND hwndDlg; + +void setFindGameDlgHandle(HWND x) { + hwndDlg = x; +} + +bool loadGameSettings() { + HKEY hkey; + DWORD disposition; + DWORD keyType, keySize, dummy; + int index; + int i; + unsigned char references[MAX_PATH]; + + if(RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Software\\PocketSCUMM"), + 0, NULL, 0, 0, NULL, &hkey, &disposition) == ERROR_SUCCESS) { + + keyType = REG_DWORD; + keySize = sizeof(DWORD); + if (RegQueryValueEx(hkey, TEXT("GamesInstalled"), NULL, &keyType, + (unsigned char*)&dummy, &keySize) == ERROR_SUCCESS) + index = dummy; + else + return FALSE; + + installedGamesNumber = index; + + keyType = REG_BINARY; + keySize = index; + if (RegQueryValueEx(hkey, TEXT("GamesReferences"), NULL, &keyType, + references, &keySize) != ERROR_SUCCESS) + return FALSE; + + for (i=0; i +#include +#include +#include +#include + +#include "gapi_keys.h" + +#include "screen.h" + +struct oneAction _actions[NUMBER_ACTIONS]; +struct GXKeyList _keys; +pAction *_action_functions; + +const char* ActionsText[] = { + "Pause", + "Save", + "Quit", + "Skip", + "Hide", + "Keyboard", + "Sound", + "Right click" +}; + +bool _typeExists(int x) { + int i; + + for (i=0; i TOTAL_ACTIONS) + current = 1; + if (!_typeExists(current)) { + _actions[action].action_type = current; + return; + } + } +} + +void setPreviousType(int action) { + int start = _actions[action].action_type; + int current = start; + for (;;) { + current--; + if (current == start) + return; + if (current <= 0) + current = TOTAL_ACTIONS; + if (!_typeExists(current)) { + _actions[action].action_type = current; + return; + } + } +} + + + +void setActionKeys(unsigned char *actionKeys) { + int i; + + for (i=0; i +#include +#include +#include + +#include "gapi_keys.h" + +#include "SDL.h" +#include "SDL_audio.h" +#include "SDL_timer.h" +#include "SDL_thread.h" + +#define VERSION "Build " POCKETSCUMM_BUILD " (VM " SCUMMVM_CVS ")" + +#define SHMenuBar_GetMenu(hWndMB,ID_MENU) (HMENU)SendMessage((hWndMB), SHCMBM_GETSUBMENU, (WPARAM)0, (LPARAM)ID_MENU) + +#define SDL_INIT_AUDIO 0x00000010 +extern "C" DECLSPEC int SDL_Init(Uint32 flags); #define SAMPLES_PER_SEC 22050 #define BUFFER_SIZE (8192) #define BITS_PER_SAMPLE 16 +void drawAllToolbar(bool); +void redrawSoundItem(); +ToolbarSelected getToolbarSelection(int, int); + +extern void palette_update(); +extern void Cls(); + +extern void startFindGame(); +extern void displayGameInfo(); +extern bool loadGameSettings(void); +extern void setFindGameDlgHandle(HWND); +extern void getSelectedGame(int, char*, TCHAR*); + +const char KEYBOARD_MAPPING_ALPHA_HIGH[] = { + "ABCDEFGHIJKLM" +}; + +const char KEYBOARD_MAPPING_NUMERIC_HIGH[] = { + "12345" +}; + +const char KEYBOARD_MAPPING_ALPHA_LOW[] = { + "NOPQRSTUVWXYZ" +}; + +const char KEYBOARD_MAPPING_NUMERIC_LOW[] = { + "67890" +}; + +/* Added from generic X-Win port - not used right now */ + +#define MAX_NUMBER_OF_DIRTY_SQUARES 32 +typedef struct { + int x, y, w, h; +} dirty_square; +static dirty_square ds[MAX_NUMBER_OF_DIRTY_SQUARES]; +static int num_of_dirty_square; + +static int old_mouse_x, old_mouse_y; +static int old_mouse_h, old_mouse_w; +static bool has_mouse, hide_mouse; + +#define BAK_WIDTH 40 +#define BAK_HEIGHT 40 +unsigned char old_backup[BAK_WIDTH * BAK_HEIGHT]; + + +#define AddDirtyRec(xi,yi,wi,hi) \ + if (num_of_dirty_square < MAX_NUMBER_OF_DIRTY_SQUARES) { \ + ds[num_of_dirty_square].x = xi; \ + ds[num_of_dirty_square].y = yi; \ + ds[num_of_dirty_square].w = wi; \ + ds[num_of_dirty_square].h = hi; \ + num_of_dirty_square++; \ + } + // Practically identical to the one in windows.cpp class WndMan { @@ -58,6 +128,7 @@ public: HWAVEOUT _handle; WAVEHDR _hdr[2]; + public: void init(); @@ -66,16 +137,13 @@ public: void setPalette(byte *ctab, int first, int num); void writeToScreen(); - void prepare_header(WAVEHDR *wh, int i); - void sound_init(); - static DWORD _stdcall sound_thread(WndMan *wm); }; // Similar to Error in windows.cpp but has to take Unicode in account void Error(LPCTSTR msg) { OutputDebugString(msg); - MessageBox(0, msg, TEXT("Error"), MB_ICONSTOP); + MessageBox(HWND_DESKTOP, msg, TEXT("Error"), MB_ICONSTOP); exit(1); } @@ -85,11 +153,27 @@ ScummDebugger debugger; Gui gui; SoundEngine sound; +SOUND_DRIVER_TYPE snd_driv; + WndMan wm[1]; byte veryFastMode; //}} +bool sound_activated; +HWND hWnd_MainMenu; +HWND hWnd_Window; + +extern bool toolbar_drawn; +extern bool draw_keyboard; +bool hide_toolbar; + +bool get_key_mapping; + +//long TEMPO_BASE; + +static char _directory[MAX_PATH]; + // WndProc is significantly port-specific int mapKey(int key) { if (key>=VK_F1 && key<=VK_F9) { @@ -98,6 +182,175 @@ int mapKey(int key) { return key; } +void error_handler(char *text, char is_error) { + if (is_error) { + TCHAR error[1024]; + GXCloseInput(); + GXCloseDisplay(); + ShowWindow(hWnd_Window, SW_HIDE); + MultiByteToWideChar(CP_ACP, 0, text, strlen(text) + 1, error, sizeof(error)); + MessageBox(GetForegroundWindow(), error, TEXT("ScummVM error"), MB_OK); + } +} + + +void do_quit() { + GXCloseInput(); + GXCloseDisplay(); + SDL_AudioQuit(); + exit(1); +} + +/* Registry support */ + +void registry_init() { + HKEY hkey; + DWORD disposition; + DWORD keyType, keySize, dummy; + unsigned char actions[NUMBER_ACTIONS]; + + memset(actions, 0, NUMBER_ACTIONS); + + if(RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Software\\PocketSCUMM"), + 0, NULL, 0, 0, NULL, &hkey, &disposition) == ERROR_SUCCESS) { + + keyType = REG_DWORD; + keySize = sizeof(DWORD); + if (RegQueryValueEx(hkey, TEXT("VolumeMaster"), NULL, &keyType, + (unsigned char*)&dummy, &keySize) == ERROR_SUCCESS) + scumm._sound_volume_master = (uint16)dummy; + else + scumm._sound_volume_master = 100; + + if (RegQueryValueEx(hkey, TEXT("VolumeMusic"), NULL, &keyType, + (unsigned char*)&dummy, &keySize) == ERROR_SUCCESS) + scumm._sound_volume_music = (uint16)dummy; + else + scumm._sound_volume_music = 60; + if (RegQueryValueEx(hkey, TEXT("VolumeSfx"), NULL, &keyType, + (unsigned char*)&dummy, &keySize) == ERROR_SUCCESS) + scumm._sound_volume_sfx = (uint16)dummy; + else + scumm._sound_volume_sfx = 100; + keyType = REG_BINARY; + keySize = NUMBER_ACTIONS; + memset(actions, 0, sizeof(actions)); + RegQueryValueEx(hkey, TEXT("ActionsKeys"), NULL, &keyType, + actions, &keySize); + setActionKeys(actions); + actions[0] = ACTION_PAUSE; + actions[1] = ACTION_SAVE; + actions[2] = ACTION_QUIT; + actions[3] = ACTION_SKIP; + actions[4] = ACTION_HIDE; + RegQueryValueEx(hkey, TEXT("ActionsTypes"), NULL, &keyType, + actions, &keySize); + setActionTypes(actions); + + RegCloseKey(hkey); + } +} + +void registry_save() { + HKEY hkey; + DWORD disposition; + DWORD keyType, keySize, dummy; + + if(RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Software\\PocketSCUMM"), + 0, NULL, 0, 0, NULL, &hkey, &disposition) == ERROR_SUCCESS) { + + keyType = REG_DWORD; + keySize = sizeof(DWORD); + dummy = scumm._sound_volume_master; + RegSetValueEx(hkey, TEXT("VolumeMaster"), 0, keyType, (unsigned char*)&dummy, keySize); + dummy = scumm._sound_volume_music; + RegSetValueEx(hkey, TEXT("VolumeMusic"), 0, keyType, (unsigned char*)&dummy, keySize); + dummy = scumm._sound_volume_sfx; + RegSetValueEx(hkey, TEXT("VolumeSfx"), 0, keyType, (unsigned char*)&dummy, keySize); + keyType = REG_BINARY; + keySize = NUMBER_ACTIONS; + RegSetValueEx(hkey, TEXT("ActionsKeys"), 0, keyType, getActionKeys(), + keySize); + RegSetValueEx(hkey, TEXT("ActionsTypes"), 0, keyType, getActionTypes(), + keySize); + + RegCloseKey(hkey); + } +} + +/* Action functions */ + +void action_right_click() { + wm->_scumm->_rightBtnPressed |= msDown|msClicked; +} + +void action_pause() { + wm->_scumm->_keyPressed = mapKey(VK_SPACE); +} + +void action_save() { + if (GetScreenMode()) { + draw_keyboard = true; + if (!hide_toolbar) + toolbar_drawn = false; + } + + wm->_scumm->_keyPressed = mapKey(VK_F5); +} + +void action_quit() { + do_quit(); +} + +void action_skip() { + wm->_scumm->_keyPressed = mapKey(VK_ESCAPE); +} + +void action_hide() { + hide_toolbar = !hide_toolbar; + Cls(); + toolbar_drawn = hide_toolbar; + wm->writeToScreen(); +} + +void action_keyboard() { + if (GetScreenMode()) { + draw_keyboard = !draw_keyboard; + if (!hide_toolbar) + toolbar_drawn = false; + } +} + +void action_sound() { + sound_activated = !sound_activated; + wm->_scumm->_soundsPaused2 = !sound_activated; +} + +/* Initialization */ + +void keypad_init() { + static pAction actions[TOTAL_ACTIONS] = + { action_pause, action_save, action_quit, action_skip, action_hide, + action_keyboard, action_sound, action_right_click }; + + GAPIKeysInit(actions); + +} + +void keypad_close() { + GXCloseInput(); +} + +/* *************************************************************************** */ +/* SDL sound */ +/* *************************************************************************** */ + +void fill_sound(void *userdata, Uint8 *stream, int len) { + scumm.mixWaves((int16*)stream, len>>1); +} + + +// TODO : check SIP state - menu seems to be not drawn on some devices static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { @@ -109,7 +362,9 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM l { case WM_CREATE: memset(&sai, 0, sizeof(sai)); - SHSipPreference(hWnd, SIP_INPUTDIALOG); + SHSipPreference(hWnd, SIP_FORCEDOWN); +// SHSipPreference(hWnd, SIP_INPUTDIALOG); + return 0; case WM_DESTROY: @@ -127,7 +382,7 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM l hDC = GetDC(hWnd); if(rc.top < rc.bottom) FillRect(hDC, &rc, (HBRUSH)GetStockObject(BLACK_BRUSH)); - ReleaseDC(hWnd, hDC); + ReleaseDC(hWnd, hDC); } return 1; @@ -137,59 +392,110 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM l PAINTSTRUCT ps; hDC = BeginPaint (hWnd, &ps); EndPaint (hWnd, &ps); + if (!hide_toolbar) + toolbar_drawn = false; + + /* + if(!GetScreenMode()) { + SHSipPreference(hWnd, SIP_UP); + } else { + SHSipPreference(hWnd, SIP_FORCEDOWN); + } + */ } - SHSipPreference(hWnd, SIP_UP); /* Hack! */ -#ifdef USE_F_KEYS - adjust_extra_windows(); -#endif +// SHSipPreference(hWnd, SIP_UP); /* Hack! */ /* It does not happen often but I don't want to see tooltip traces */ wm->writeToScreen(); return 0; case WM_ACTIVATE: GraphicsResume(); - SHHandleWMActivate(hWnd, wParam, lParam, &sai, SHA_INPUTDIALOG); -#ifdef USE_F_KEYS - adjust_extra_windows(); -#endif + if (!hide_toolbar) + toolbar_drawn = false; +// SHHandleWMActivate(hWnd, wParam, lParam, &sai, SHA_INPUTDIALOG); return 0; case WM_HIBERNATE: GraphicsSuspend(); + if (!hide_toolbar) + toolbar_drawn = false; return 0; case WM_SETTINGCHANGE: SHHandleWMSettingChange(hWnd, wParam, lParam, &sai); -#ifdef USE_F_KEYS - adjust_extra_windows(); -#endif + if (!hide_toolbar) + toolbar_drawn = false; return 0; case WM_COMMAND: switch(wParam) { - case IDC_ABOUT: + case IDC_OPTIONS: + wm->_scumm->_keyPressed = KEY_SET_OPTIONS; break; case IDC_EXIT: DestroyWindow(hWnd); + do_quit(); + break; + case IDC_SKIP: + wParam = VK_ESCAPE; + wm->_scumm->_keyPressed = mapKey(wParam); break; -// Landscape mode is broken. This will be uncommented when it works -/* + case IDC_LOADSAVE: + if (GetScreenMode()) { + draw_keyboard = true; + if (!hide_toolbar) + toolbar_drawn = false; + } + wParam = VK_F5; + wm->_scumm->_keyPressed = mapKey(wParam); + break; + + case IDC_SOUND: + sound_activated = !sound_activated; + CheckMenuItem ( + SHMenuBar_GetMenu (hWnd_MainMenu, IDM_POCKETSCUMM), + IDC_SOUND, + MF_BYCOMMAND | (sound_activated ? MF_CHECKED : MF_UNCHECKED)); + wm->_scumm->_soundsPaused2 = !sound_activated; + break; + + break; + case IDC_LANDSCAPE: - SetScreenMode(1); + SetScreenMode(!GetScreenMode()); + SHSipPreference(hWnd,SIP_FORCEDOWN); SetCapture(hWnd); // to prevent input panel from getting taps + SHFullScreen (hWnd, SHFS_HIDESIPBUTTON | SHFS_HIDETASKBAR | SHFS_HIDESTARTICON); InvalidateRect(HWND_DESKTOP, NULL, TRUE); + /* + SipShowIM(SIPF_OFF); + SHSipPreference(hWnd, SIP_FORCEDOWN); + */ + if (!hide_toolbar) + toolbar_drawn = false; break; -*/ + } return 0; + + case WM_KEYDOWN: + if(wParam) { // gets rid of zero that seems to preceed GAPI events. + unsigned char GAPI_key; - case WM_KEYDOWN: - if(wParam == VK_BACKSLASH) - wParam = VK_ESCAPE; + GAPI_key = getGAPIKeyMapping((short)wParam); + if (GAPI_key) { + if (get_key_mapping) + wm->_scumm->_keyPressed = GAPI_KEY_BASE + GAPI_key; + else + processAction((short)wParam); + } + else { + wm->_scumm->_keyPressed = mapKey(wParam); + } + } - wm->_scumm->_keyPressed = mapKey(wParam); break; case WM_MOUSEMOVE: @@ -203,27 +509,100 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM l break; case WM_LBUTTONDOWN: { + ToolbarSelected toolbar_selection; int x = ((int16*)&lParam)[0]; int y = ((int16*)&lParam)[1]; Translate(&x, &y); - wm->_scumm->mouse.x = x; - wm->_scumm->mouse.y = y; - wm->_scumm->_leftBtnPressed |= 1; - if(y > 200) - { - if(x<160) - wm->_scumm->_keyPressed = VK_ESCAPE; + + if (draw_keyboard) { + // Handle keyboard selection + + if (x<185 && y>=200) { + //Alpha selection + wm->_scumm->_keyPressed = + (y <= 220 ? KEYBOARD_MAPPING_ALPHA_HIGH[((x + 10) / 14) - 1] : + KEYBOARD_MAPPING_ALPHA_LOW[((x + 10) / 14) - 1]); + break; + } + else + if (x>=186 && y>=200 && x<=255) { + // Numeric selection + wm->_scumm->_keyPressed = + (y <= 220 ? KEYBOARD_MAPPING_NUMERIC_HIGH[((x - 187 + 10) / 14) - 1] : + KEYBOARD_MAPPING_NUMERIC_LOW[((x - 187 + 10) / 14) - 1]); + break; + } else + if (x>=302 && x <= 316 && y >= 200 && y <= 220) { + // Backspace + wm->_scumm->_keyPressed = mapKey(VK_BACK); + break; + } + + wm->_scumm->mouse.x = x; + wm->_scumm->mouse.y = y; + wm->_scumm->_leftBtnPressed |= msClicked|msDown; + break; + + } + + + toolbar_selection = (hide_toolbar || get_key_mapping ? ToolbarNone : + getToolbarSelection(x, y)); + if (toolbar_selection == ToolbarNone) { + wm->_scumm->mouse.x = x; + wm->_scumm->mouse.y = y; + + wm->_scumm->_leftBtnPressed |= msClicked|msDown; + + if(y > 200 && !hide_toolbar) { - SetScreenMode(0); // restore normal tap logic - ReleaseCapture(); - InvalidateRect(HWND_DESKTOP, NULL, TRUE); + if(x<160) + wm->_scumm->_keyPressed = VK_ESCAPE; + else + { + SetScreenMode(0); // restore normal tap logic + SHSipPreference(hWnd,SIP_UP); + ReleaseCapture(); + InvalidateRect(HWND_DESKTOP, NULL, TRUE); + } + } + } + else { + switch(toolbar_selection) { + case ToolbarSaveLoad: + if (GetScreenMode()) { + draw_keyboard = true; + if (!hide_toolbar) + toolbar_drawn = false; + } + wm->_scumm->_keyPressed = mapKey(VK_F5); + break; + case ToolbarExit: + wm->_scumm->_keyPressed = KEY_SET_OPTIONS; + break; + case ToolbarSkip: + wm->_scumm->_keyPressed = mapKey(VK_ESCAPE); + break; + case ToolbarSound: + sound_activated = !sound_activated; + wm->_scumm->_soundsPaused2 = !sound_activated; + redrawSoundItem(); + break; + default: + break; } } } break; - case WM_RBUTTONDOWN: - wm->_scumm->_rightBtnPressed |= 1; + case WM_LBUTTONUP: + { + // pinched from the SDL code. Distinguishes between taps and not + wm->_scumm->_leftBtnPressed &= ~msDown; + } + break; + case WM_LBUTTONDBLCLK: // doesn't seem to work right now + wm->_scumm->_rightBtnPressed |= msClicked | msDown; break; default: return DefWindowProc(hWnd, message, wParam, lParam); @@ -242,6 +621,8 @@ void WndMan::setPalette(byte *ctab, int first, int num) { for (i=0; i<256; i++) SetPalEntry(i, ctab[i*3+0], ctab[i*3+1], ctab[i*3+2]); + + palette_update(); } @@ -267,6 +648,7 @@ void WndMan::init() hWnd = CreateWindow(TEXT("ScummVM"), TEXT("ScummVM"), WS_VISIBLE, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), NULL, NULL, hInst, NULL); + hWnd_Window = hWnd; SetWindowLong(hWnd, GWL_USERDATA, (long)this); ShowWindow(hWnd, SW_SHOW); @@ -281,17 +663,21 @@ void WndMan::init() smbi.cBmpImages = 0; smbi.hwndMB = NULL; BOOL res = SHCreateMenuBar(&smbi); + hWnd_MainMenu = smbi.hwndMB; + + /* Sound is activated on default - initialize it in the menu */ + CheckMenuItem((HMENU)SHMenuBar_GetMenu (hWnd_MainMenu, IDM_POCKETSCUMM), + IDC_SOUND, + MF_BYCOMMAND | MF_CHECKED); GraphicsOn(hWnd); SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); SetForegroundWindow(hWnd); - SHFullScreen(hWnd, SHFS_SHOWSIPBUTTON); - SHFullScreen(hWnd, SHFS_HIDETASKBAR); +// SHFullScreen(hWnd, SHFS_SHOWSIPBUTTON); + SHFullScreen(hWnd, SHFS_HIDESIPBUTTON | SHFS_HIDETASKBAR | SHFS_HIDESTARTICON); -#ifdef USE_F_KEYS - setup_extra_windows(hWnd); -#endif + Cls(); } @@ -304,7 +690,7 @@ bool WndMan::handleMessage() { if (msg.message==WM_QUIT) { terminated=true; - exit(1); + do_quit(); return true; } @@ -317,12 +703,24 @@ bool WndMan::handleMessage() { // This function is very similar to the one in windows.cpp except for // one line removed. + +// TODO : use dirty rects + void blitToScreen(Scumm *s, byte *src,int x, int y, int w, int h) { byte *dst; - int i; + //int i; dst = (byte*)wm->_vgabuf + y*320 + x; + if (h<=0) return; + + hide_mouse = true; + if (has_mouse) { + s->drawMouse(); + } + + AddDirtyRec(x, y, w, h); + do { memcpy(dst, src, w); dst += 320; @@ -334,7 +732,15 @@ void blitToScreen(Scumm *s, byte *src,int x, int y, int w, int h) { //{{ int clock; +// TODO : use dirty rects for faster screen updates + void updateScreen(Scumm *s) { + + if (hide_mouse) { + hide_mouse = false; + s->drawMouse(); + } + if (s->_palDirtyMax != -1) { wm->setPalette(s->_currentPalette, 0, 256); s->_palDirtyMax = -1; @@ -347,88 +753,126 @@ void waitForTimer(Scumm *s, int delay) { wm->handleMessage(); if (!veryFastMode) { assert(delay<5000); + if(!delay) + delay++; Sleep(delay); } } -void initGraphics(Scumm *s, bool fullScreen) { +void initGraphics(Scumm *s, bool fullScreen, unsigned int scaleFactor) { + SDL_AudioSpec desired; + if(fullScreen) warning("Use SDL for fullscreen support"); -} - -void drawMouse(Scumm *s, int, int, int, byte*, bool) { -} - -void drawMouse(Scumm *s, int x, int y, int w, int h, byte *buf, bool visible) { -} -void fill_buffer(int16 *buf, int len) { - memset(buf, 0, len*2); - scumm.mixWaves(buf, len); -} - -void WndMan::prepare_header(WAVEHDR *wh, int i) { - memset(wh, 0, sizeof(WAVEHDR)); - wh->lpData = (char*)malloc(BUFFER_SIZE); - wh->dwBufferLength = BUFFER_SIZE; - - waveOutPrepareHeader(_handle, wh, sizeof(WAVEHDR)); + if (SDL_Init(SDL_INIT_AUDIO)==-1) { + exit(1); + } - fill_buffer((int16*)wh->lpData, wh->dwBufferLength>>1); - waveOutWrite(_handle, wh, sizeof(WAVEHDR)); + desired.freq = 11025; + desired.format = AUDIO_S16SYS; + desired.channels = 1; + desired.samples = 128; // seems correct + desired.callback = fill_sound; + SDL_OpenAudio(&desired, NULL); + SDL_PauseAudio(0); } -void WndMan::sound_init() { - WAVEFORMATEX wfx; - - memset(&wfx, 0, sizeof(wfx)); - wfx.wFormatTag = WAVE_FORMAT_PCM; - wfx.nChannels = 1; - wfx.nSamplesPerSec = SAMPLES_PER_SEC; - wfx.nAvgBytesPerSec = SAMPLES_PER_SEC * BITS_PER_SAMPLE / 8; - wfx.wBitsPerSample = BITS_PER_SAMPLE; - wfx.nBlockAlign = BITS_PER_SAMPLE * 1 / 8; - - CreateThread(NULL, 0, (unsigned long (__stdcall *)(void *))&sound_thread, this, 0, &_threadId); - SetThreadPriority((void*)_threadId, THREAD_PRIORITY_HIGHEST); - - _event = CreateEvent(NULL, false, false, NULL); - - memset(_hdr,0,sizeof(_hdr)); - - waveOutOpen(&_handle, WAVE_MAPPER, &wfx, (long)_event, (long)this, CALLBACK_EVENT ); - - prepare_header(&_hdr[0], 0); - prepare_header(&_hdr[1], 1); +// Copy/Paste from X11 +// Dirty rects not managed now + +void drawMouse(Scumm *s, int xdraw, int ydraw, int w, int h, byte *buf, bool visible) { + unsigned char *dst,*bak; + + if ((xdraw >= 320) || ((xdraw + w) <= 0) || + (ydraw >= 200) || ((ydraw + h) <= 0)) { + if (hide_mouse) visible = false; + if (has_mouse) has_mouse = false; + if (visible) has_mouse = true; + return; + } + + if (hide_mouse) + visible = false; + + assert(w<=BAK_WIDTH && h<=BAK_HEIGHT); + + if (has_mouse) { + int old_h = old_mouse_h; + + has_mouse = false; + AddDirtyRec(old_mouse_x, old_mouse_y, old_mouse_w, old_mouse_h); + + dst = wm->_vgabuf + (old_mouse_y * 320) + old_mouse_x; + bak = old_backup; + + while (old_h > 0) { + memcpy(dst, bak, old_mouse_w); + bak += BAK_WIDTH; + dst += 320; + old_h--; + } + } + + if (visible) { + int real_w; + int real_h; + int real_h_2; + unsigned char *dst2; + + if (ydraw < 0) { + real_h = h + ydraw; + buf += (-ydraw) * w; + ydraw = 0; + } else { + real_h = (ydraw + h) > 200 ? (200 - ydraw) : h; + } + if (xdraw < 0) { + real_w = w + xdraw; + buf += (-xdraw); + xdraw = 0; + } else { + real_w = (xdraw + w) > 320 ? (320 - xdraw) : w; + } + + dst = wm->_vgabuf + (ydraw * 320) + xdraw; + dst2 = dst; + bak = old_backup; + + has_mouse = true; + + AddDirtyRec(xdraw, ydraw, real_w, real_h); + old_mouse_x = xdraw; + old_mouse_y = ydraw; + old_mouse_w = real_w; + old_mouse_h = real_h; + + real_h_2 = real_h; + while (real_h_2 > 0) { + memcpy(bak, dst, real_w); + bak += BAK_WIDTH; + dst += 320; + real_h_2--; + } + while (real_h > 0) { + int width = real_w; + while (width > 0) { + unsigned char color = *buf; + if (color != 0xFF) { + *dst2 = color; + } + buf++; + dst2++; + width--; + } + buf += w - real_w; + dst2 += 320 - real_w; + real_h--; + } + } } -DWORD _stdcall WndMan::sound_thread(WndMan *wm) { - int i; - bool signaled; - int time = GetTickCount(), cur; - - while (1) { - cur = GetTickCount(); - while (time < cur) { - sound.on_timer(); - time += 10; - } - - signaled = WaitForSingleObject(wm->_event, time - cur) == WAIT_OBJECT_0; - if (signaled) { - for(i=0; i<2; i++) { - WAVEHDR *hdr = &wm->_hdr[i]; - if (hdr->dwFlags & WHDR_DONE) { - fill_buffer((int16*)hdr->lpData, hdr->dwBufferLength>>1); - waveOutWrite(wm->_handle, hdr, sizeof(WAVEHDR)); - } - } - } - } - return 1; // not in windows.cpp - a bug! -} -//}} BOOL CALLBACK SelectDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { @@ -436,16 +880,41 @@ BOOL CALLBACK SelectDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara { case WM_INITDIALOG: { + TCHAR work[1024]; RECT rc; GetWindowRect(hwndDlg, &rc); MoveWindow(hwndDlg, (GetSystemMetrics(SM_CXSCREEN)-rc.right+rc.left)/2, (GetSystemMetrics(SM_CYSCREEN)-rc.bottom+rc.top)/2, rc.right-rc.left, rc.bottom-rc.top, TRUE); BringWindowToTop(hwndDlg); + setFindGameDlgHandle(hwndDlg); + MultiByteToWideChar(CP_ACP, 0, VERSION, strlen(VERSION) + 1, work, sizeof(work)); + SetDlgItemText(hwndDlg, IDC_GAMEDESC, work); + loadGameSettings(); } return TRUE; + case WM_COMMAND: - EndDialog(hwndDlg, wParam); + + if (LOWORD(wParam) == IDC_LISTAVAILABLE && HIWORD(wParam) == LBN_SELCHANGE) + displayGameInfo(); + + if (wParam == IDC_SCAN) + startFindGame(); + + if (wParam == IDC_PLAY) { + int item; + + item = SendMessage(GetDlgItem(hwndDlg, IDC_LISTAVAILABLE), LB_GETCURSEL, 0, 0); + if (item == LB_ERR) { + MessageBox(hwndDlg, TEXT("Please select a game"), TEXT("Error"), MB_OK); + } + else + EndDialog(hwndDlg, item + 1000); + } + + if (wParam == IDC_EXIT) + EndDialog(hwndDlg, 0); return TRUE; default: return FALSE; @@ -454,18 +923,22 @@ BOOL CALLBACK SelectDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara char* GameSelector() { - switch(DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_GAMESELECT), HWND_DESKTOP, SelectDlgProc)) - { - case IDC_MONKEY: return "monkey"; - case IDC_MONKEY2: return "monkey2"; - case IDC_ATLANTIS: return "atlantis"; - case IDC_PLAYFATE: return "playfate"; - case IDC_TENTACLE: return "tentacle"; - case IDC_DOTTDEMO: return "dottdemo"; - case IDC_SAMNMAX: return "samnmax"; - case IDC_SNMDEMO: return "snmdemo"; - default: return NULL; - } + TCHAR directory[MAX_PATH]; + static char id[100]; + + DWORD result = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_GAMESELECT), HWND_DESKTOP, SelectDlgProc); + if (result < 1000) + return NULL; + result -= 1000; + + getSelectedGame(result, id, directory); + + WideCharToMultiByte(CP_ACP, 0, directory, wcslen(directory) + 1, _directory, sizeof(_directory), NULL, NULL); + + strcat(_directory, "\\"); + + return id; + } // Directly corresponds to main in windows.cpp @@ -474,28 +947,43 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLin int delta; int tmp; - int argc = 2; - char* argv[2]; + int argc = 3; + char* argv[3]; + char argdir[MAX_PATH]; + SoundEngine *se; + + sound_activated = true; + hide_toolbar = false; + argv[0] = NULL; argv[1] = GameSelector(); + sprintf(argdir, "-p%s", _directory); + argv[2] = argdir; + scumm._savegame_dir = _directory; + scumm._error_handler = error_handler; if(argv[1] == NULL) return 0; wm->init(); - wm->sound_init(); wm->_vgabuf = (byte*)calloc(320,200); wm->_scumm = &scumm; - -// sound.initialize(&scumm); -// scumm._soundDriver = &sound; - scumm._soundDriver = NULL; // sound is not working yet and has been disabled + sound.initialize(&scumm, &snd_driv); + scumm._soundsPaused = false; + scumm._soundsPaused2 = false; scumm._gui = &gui; scumm.scummMain(argc, argv); gui.init(&scumm); + + keypad_init(); + registry_init(); + + se = (SoundEngine*)scumm._soundEngine; + se->set_music_volume(scumm._sound_volume_music); + se->set_master_volume(scumm._sound_volume_master); delta = 0; tmp = 0; @@ -525,100 +1013,11 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLin return 0; } -#ifdef USE_F_KEYS -/* Window for F-key input. Hack but some people asked for it. */ -LRESULT CALLBACK FWindowProc(HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM lParam) -{ - switch (nMsg) - { - case WM_CREATE: - return 0; - case WM_PAINT: - { - HDC hDC; - PAINTSTRUCT ps; - RECT rc; - hDC = BeginPaint(hwnd, &ps); - GetClientRect(hwnd, &rc); - HGDIOBJ oldPen = SelectObject(hDC, (HGDIOBJ)GetStockObject(BLACK_PEN)); - HGDIOBJ oldBr = SelectObject(hDC, (HGDIOBJ)GetStockObject(WHITE_BRUSH)); - HGDIOBJ oldFont = SelectObject(hDC, (HGDIOBJ)GetStockObject(SYSTEM_FONT)); - int rcWidth = rc.right-rc.left; - RECT rcItem; - rcItem.top = rc.top; - rcItem.bottom = rc.bottom; - POINT pts[2]; - pts[0].y = rc.top; - pts[1].y = rc.bottom; - TCHAR text[4]; - for(int i=0; i<10; i++) - { - wsprintf(text, TEXT("F%d"), i+1); - rcItem.left = rc.left+rcWidth*i/10; - rcItem.right = rc.left+rcWidth*(i+1)/10; - pts[0].x = pts[1].x = rcItem.right; - Polyline(hDC, pts, 2); - DrawText(hDC, text, -1, &rcItem, DT_CENTER|DT_VCENTER); - } - SelectObject(hDC, oldPen); - SelectObject(hDC, oldBr); - SelectObject(hDC, oldFont); - EndPaint(hwnd, &ps); - } - return 0; - case WM_LBUTTONDOWN: - { - int x = LOWORD(lParam); - RECT rc; GetWindowRect(hwnd, &rc); - int fnum = x*10/(rc.right-rc.left); - PostMessage(GetParent(hwnd), WM_KEYDOWN, VK_F1+fnum, 0); - } - return 0; - } +/* Unsupported funcs */ - return DefWindowProc(hwnd, nMsg, wParam, lParam); -} +// TODO : implement +void setShakePos(Scumm *s, int shake_pos) {} +// TODO : switch to MP3 support +void cd_playtrack(int track, int offset, int delay) {} -void setup_extra_windows(HWND hwndTop) -{ - LPTSTR fkeyname = TEXT("fkeys"); - - WNDCLASS wc; - wc.style = CS_HREDRAW | CS_VREDRAW; - wc.lpfnWndProc = FWindowProc; - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hInstance = GetModuleHandle(NULL); - wc.hIcon = NULL; - wc.hCursor = NULL; - wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); - wc.lpszMenuName = NULL; - wc.lpszClassName = fkeyname; - RegisterClass(&wc); - - hwndFKeys = CreateWindow(fkeyname, - fkeyname, - WS_VISIBLE|WS_CHILD, - 0, - 200, - GetSystemMetrics(SM_CXSCREEN), - 20, - hwndTop, - (HMENU)100, - GetModuleHandle(NULL), - NULL); -} -void adjust_extra_windows() -{ - SIPINFO si; - si.cbSize = sizeof(SIPINFO); - SHSipInfo(SPI_GETSIPINFO, 0, &si, 0); - if(si.fdwFlags & SIPF_ON) - { - int bottom = si.rcVisibleDesktop.bottom; - SetWindowPos(hwndFKeys, 0, 0, 200, GetSystemMetrics(SM_CXSCREEN), bottom-200, - SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOZORDER); - } -} -#endif diff --git a/wince/pocketscumm.ico b/wince/pocketscumm.ico new file mode 100644 index 0000000000..799279e856 Binary files /dev/null and b/wince/pocketscumm.ico differ -- cgit v1.2.3