From 4624769069de808ef0aa561d53700c1bf5c7279e Mon Sep 17 00:00:00 2001 From: Chris Apers Date: Tue, 1 May 2007 10:12:55 +0000 Subject: - Prevent lose of events - Added hard arrow keys support - Revamped mouse code to prevent duplication and get rid of fixed size mouse buffer - Reviewed event code (more work needed for OS5 and keyup emulation) - Cleanup svn-id: r26699 --- backends/platform/PalmOS/Src/base_event.cpp | 142 +++++++++++++++++------- backends/platform/PalmOS/Src/base_mouse.cpp | 39 ++++++- backends/platform/PalmOS/Src/be_base.cpp | 29 +++-- backends/platform/PalmOS/Src/be_base.h | 30 +++-- backends/platform/PalmOS/Src/be_os5.cpp | 22 +--- backends/platform/PalmOS/Src/be_os5.h | 11 +- backends/platform/PalmOS/Src/be_zodiac.cpp | 11 +- backends/platform/PalmOS/Src/be_zodiac.h | 4 - backends/platform/PalmOS/Src/os5_event.cpp | 22 ++-- backends/platform/PalmOS/Src/os5_gfx.cpp | 53 +++------ backends/platform/PalmOS/Src/os5_mouse.cpp | 129 +++++++-------------- backends/platform/PalmOS/Src/os5_overlay.cpp | 2 +- backends/platform/PalmOS/Src/os5_sound.cpp | 2 +- backends/platform/PalmOS/Src/zodiac_gfx.cpp | 20 ++-- backends/platform/PalmOS/Src/zodiac_mouse.cpp | 97 ++++++++-------- backends/platform/PalmOS/Src/zodiac_overlay.cpp | 2 +- 16 files changed, 312 insertions(+), 303 deletions(-) (limited to 'backends/platform') diff --git a/backends/platform/PalmOS/Src/base_event.cpp b/backends/platform/PalmOS/Src/base_event.cpp index 7da7cd5861..1f7d07f4ae 100644 --- a/backends/platform/PalmOS/Src/base_event.cpp +++ b/backends/platform/PalmOS/Src/base_event.cpp @@ -81,7 +81,7 @@ void OSystem_PalmBase::battery_handler() { } } -bool OSystem_PalmBase::pollEvent(Event &event) { +bool OSystem_PalmBase::pollEvent(Common::Event &event) { ::EventType ev; Boolean handled; UInt32 keyCurrentState; @@ -92,52 +92,60 @@ bool OSystem_PalmBase::pollEvent(Event &event) { sound_handler(); for(;;) { -#if defined(COMPILE_OS5) && defined(PALMOS_ARM) - SysEventGet(&ev, evtNoWait); -#else - EvtGetEvent(&ev, evtNoWait); -#endif - // check for hardkey repeat for mouse emulation - keyCurrentState = KeyCurrentState(); - // check_hard_keys(); + // if it was a key pressed, let the keyup event raise + if (_wasKey) { + // check for hardkey repeat for mouse emulation + keyCurrentState = KeyCurrentState(); - if (!(keyCurrentState & _keyMouseMask)) { - _lastKeyRepeat = 0; - } else { - if (getMillis() >= (_keyMouseRepeat + _keyMouseDelay)) { - _keyMouseRepeat = getMillis(); + if (!(keyCurrentState & _keyExtraMask)) { + _lastKeyRepeat = 0; + + } else if (getMillis() >= (_keyExtraRepeat + _keyExtraDelay)) { + _keyExtraRepeat = getMillis(); if (gVars->arrowKeys) { - event.kbd.keycode = 0; - - if (keyCurrentState & _keyMouse.bitUp) - event.kbd.keycode = 273; - else if (keyCurrentState & _keyMouse.bitDown) - event.kbd.keycode = 274; - else if (keyCurrentState & _keyMouse.bitLeft) - event.kbd.keycode = 276; - else if (keyCurrentState & _keyMouse.bitRight) - event.kbd.keycode = 275; - - if (event.kbd.keycode) { - event.type = Common::EVENT_KEYDOWN; - event.kbd.ascii = event.kbd.keycode; - event.kbd.flags = 0; - return true; +/* if HARD_KEY(Up, chrUpArrow) + else if HARD_KEY(Down, chrDownArrow) + else if HARD_KEY(Left, chrLeftArrow) + else if HARD_KEY(Right, chrRightArrow) +*/ + } else { + // button released ? + if (_keyExtraPressed) { + if (_keyExtraPressed & _keyExtra.bitActionA) { + if (!(keyCurrentState & _keyExtra.bitActionA)) { + _keyExtraPressed &= ~_keyExtra.bitActionA; + + event.type = Common::EVENT_LBUTTONUP; + event.mouse.x = _mouseCurState.x; + event.mouse.y = _mouseCurState.y; + return true; + } + } + + if (_keyExtraPressed & _keyExtra.bitActionB) { + if (!(keyCurrentState & _keyExtra.bitActionB)) { + _keyExtraPressed &= ~_keyExtra.bitActionB; + + event.type = Common::EVENT_RBUTTONUP; + event.mouse.x = _mouseCurState.x; + event.mouse.y = _mouseCurState.y; + return true; + } + } } - } else { Int8 sx = 0; Int8 sy = 0; - if (keyCurrentState & _keyMouse.bitUp) + if (keyCurrentState & _keyExtra.bitUp) sy = -1; - else if (keyCurrentState & _keyMouse.bitDown) + else if (keyCurrentState & _keyExtra.bitDown) sy = +1; - if (keyCurrentState & _keyMouse.bitLeft) + if (keyCurrentState & _keyExtra.bitLeft) sx = -1; - else if (keyCurrentState & _keyMouse.bitRight) + else if (keyCurrentState & _keyExtra.bitRight) sx = +1; if (sx || sy) { @@ -148,12 +156,42 @@ bool OSystem_PalmBase::pollEvent(Event &event) { warpMouse(x, y); return true; - } + } } } } - if (ev.eType == keyDownEvent) { +#if defined(COMPILE_OS5) && defined(PALMOS_ARM) + SysEventGet(&ev, evtNoWait); +#else + EvtGetEvent(&ev, evtNoWait); +#endif + + if (ev.eType == keyUpEvent) { + int k = 0; + switch (ev.data.keyUp.chr) { + + // arrow keys + case chrUpArrow: + k = 273; break; + case chrDownArrow: + k = 274; break; + case chrLeftArrow: + k = 275; break; + case chrRightArrow: + k = 276; break; + } + + if (k) { + event.type = Common::EVENT_KEYUP; + event.kbd.keycode = k; + event.kbd.ascii = k; + event.kbd.flags = 0; + return true; + } + + } else if (ev.eType == keyDownEvent) { + int k = 0; switch (ev.data.keyDown.chr) { // ESC key case vchrLaunch: @@ -180,6 +218,24 @@ bool OSystem_PalmBase::pollEvent(Event &event) { case vchrContrast: // do nothing return true; + + // arrow keys + case chrUpArrow: + k = 273; break; + case chrDownArrow: + k = 274; break; + case chrLeftArrow: + k = 275; break; + case chrRightArrow: + k = 276; break; + } + + if (k) { + event.type = Common::EVENT_KEYDOWN; + event.kbd.keycode = k; + event.kbd.ascii = k; + event.kbd.flags = 0; + return true; } } @@ -192,11 +248,13 @@ bool OSystem_PalmBase::pollEvent(Event &event) { ((ev.data.keyDown.chr == vchrAttnStateChanged) || (ev.data.keyDown.chr == vchrAttnUnsnooze))); + // graffiti strokes, auto-off, etc... if (!handled) if (SysHandleEvent(&ev)) continue; + switch(ev.eType) { case penMoveEvent: get_coordinates(&ev, x, y); @@ -222,7 +280,7 @@ bool OSystem_PalmBase::pollEvent(Event &event) { num += 9 - (3 - (3 * x / _screenWidth )) - (3 * (3 * y / _screenHeight)); - + event.type = Common::EVENT_KEYDOWN; event.kbd.keycode = num; event.kbd.ascii = num; @@ -252,7 +310,7 @@ bool OSystem_PalmBase::pollEvent(Event &event) { event.mouse.y = y; warpMouse(x, y); return true; - + case keyDownEvent: if (ev.data.keyDown.chr == vchrCommand && (ev.data.keyDown.modifiers & commandKeyMask)) { @@ -302,7 +360,7 @@ bool OSystem_PalmBase::pollEvent(Event &event) { } else if ((key == 'z' && mask == Common::KBD_CTRL) || (mask == Common::KBD_ALT && key == 'x')) { event.type = Common::EVENT_QUIT; return true; - + // num pad (indy fight mode) } else if (key == 'n' && mask == (Common::KBD_CTRL|Common::KBD_ALT) && !_overlayVisible) { _useNumPad = !_useNumPad; @@ -310,7 +368,7 @@ bool OSystem_PalmBase::pollEvent(Event &event) { displayMessageOnOSD(_useNumPad ? "Fight mode on." : "Fight mode off."); return false; } - + // other keys _wasKey = true; event.type = Common::EVENT_KEYDOWN; @@ -320,7 +378,7 @@ bool OSystem_PalmBase::pollEvent(Event &event) { return true; default: - if (_wasKey) { + if (_wasKey && ev.eType != keyHoldEvent) { event.type = Common::EVENT_KEYUP; _wasKey = false; return true; diff --git a/backends/platform/PalmOS/Src/base_mouse.cpp b/backends/platform/PalmOS/Src/base_mouse.cpp index 2f3d3f5476..99b89b7f8c 100644 --- a/backends/platform/PalmOS/Src/base_mouse.cpp +++ b/backends/platform/PalmOS/Src/base_mouse.cpp @@ -26,22 +26,53 @@ void OSystem_PalmBase::warpMouse(int x, int y) { if (x != _mouseCurState.x || y != _mouseCurState.y) { + x = x >= _screenWidth ? _screenWidth - 1 : x; + y = y >= _screenHeight ? _screenHeight - 1 : y; + _mouseCurState.x = x; _mouseCurState.y = y; - undraw_mouse(); } } bool OSystem_PalmBase::showMouse(bool visible) { - if (_mouseVisible == visible) - return visible; - bool last = _mouseVisible; _mouseVisible = visible; return last; } +void OSystem_PalmBase::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor, int cursorTargetScale) { + if (w == 0 || h == 0) + return; + + _mouseHotspotX = hotspotX; + _mouseHotspotY = hotspotY; + + _mouseKeyColor = keycolor; + + if (_mouseCurState.w != w || _mouseCurState.h != h) { + _mouseCurState.w = w; + _mouseCurState.h = h; + + if (_mouseDataP) + free(_mouseDataP); + + if (_mouseBackupP) + free(_mouseBackupP); + + _mouseDataP = (byte *)malloc(w * h); + _mouseBackupP = (byte *)malloc(w * h * 2); // if 16bit = *2 + } + + if (!_mouseBackupP) { + free(_mouseDataP); + _mouseDataP = NULL; + } + + if (_mouseDataP) + memcpy(_mouseDataP, buf, w * h); +} + void OSystem_PalmBase::simulate_mouse(Common::Event &event, Int8 iHoriz, Int8 iVert, Coord *xr, Coord *yr) { Int16 x = _mouseCurState.x; Int16 y = _mouseCurState.y; diff --git a/backends/platform/PalmOS/Src/be_base.cpp b/backends/platform/PalmOS/Src/be_base.cpp index 8776376ee5..705a2597fd 100644 --- a/backends/platform/PalmOS/Src/be_base.cpp +++ b/backends/platform/PalmOS/Src/be_base.cpp @@ -1,7 +1,7 @@ /* ScummVM - Scumm Interpreter * Copyright (C) 2001 Ludvig Strigeus - * Copyright (C) 2001-2006 The ScummVM project - * Copyright (C) 2002-2006 Chris Apers - PalmOS Backend + * Copyright (C) 2001-2007 The ScummVM project + * Copyright (C) 2002-2007 Chris Apers - PalmOS Backend * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -64,16 +64,18 @@ OSystem_PalmBase::OSystem_PalmBase() { _mixerMgr = 0; _mouseDataP = NULL; + _mouseBackupP = NULL; _mouseVisible = false; _mouseDrawn = false; - MemSet(&_keyMouse, sizeof(_keyMouse), 0); + MemSet(&_keyExtra, sizeof(_keyExtra), 0); MemSet(&_mouseCurState, sizeof(_mouseCurState), 0); MemSet(&_mouseOldState, sizeof(_mouseOldState), 0); MemSet(&_timer, sizeof(TimerType), 0); MemSet(&_sound, sizeof(SoundType), 0); - _keyMouseRepeat = 0; - _keyMouseDelay = (gVars->arrowKeys) ? computeMsecs(125) : computeMsecs(25); + _keyExtraRepeat = 0; + _keyExtraPressed = 0; + _keyExtraDelay = (gVars->arrowKeys) ? computeMsecs(125) : computeMsecs(25); } static int timer_handler(int t) { @@ -86,13 +88,13 @@ void OSystem_PalmBase::initBackend() { if (gVars->autoSave != -1) ConfMan.setInt("autosave_period", gVars->autoSave); - _keyMouse.bitUp = keyBitPageUp; - _keyMouse.bitDown = keyBitPageDown; - _keyMouse.bitLeft = keyBitHard2; - _keyMouse.bitRight = keyBitHard3; + _keyExtra.bitUp = keyBitPageUp; + _keyExtra.bitDown = keyBitPageDown; + _keyExtra.bitLeft = keyBitHard2; + _keyExtra.bitRight = keyBitHard3; int_initBackend(); - _keyMouseMask = (_keyMouse.bitUp | _keyMouse.bitDown | _keyMouse.bitLeft | _keyMouse.bitRight); + _keyExtraMask = (_keyExtra.bitUp | _keyExtra.bitDown | _keyExtra.bitLeft | _keyExtra.bitRight | _keyExtra.bitActionA | _keyExtra.bitActionB); // Create the savefile manager, if none exists yet (we check for this to // allow subclasses to provide their own). @@ -143,7 +145,12 @@ void OSystem_PalmBase::quit() { int_quit(); clearSoundCallback(); unload_gfx_mode(); - + + if (_mouseDataP) { + MemPtrFree(_mouseBackupP); + MemPtrFree(_mouseDataP); + } + delete _saveMgr; delete _timerMgr; delete _mixerMgr; diff --git a/backends/platform/PalmOS/Src/be_base.h b/backends/platform/PalmOS/Src/be_base.h index d6bb4548d1..65ed93d9a5 100644 --- a/backends/platform/PalmOS/Src/be_base.h +++ b/backends/platform/PalmOS/Src/be_base.h @@ -25,9 +25,13 @@ #ifndef BE_BASE_H #define BE_BASE_H +#include "PalmVersion.h" +#include "globals.h" + #include "common/stdafx.h" #include "common/scummsys.h" #include "common/system.h" +#include "common/events.h" namespace Audio { class Mixer; @@ -52,6 +56,12 @@ enum { kModifierCount }; +// Mouse button event +enum { + vchrMouseLeft = vchrHardKeyMax - 2, + vchrMouseRight = vchrHardKeyMax - 1 +}; + // OSD resource id #define kDrawKeyState 3000 #define kDrawNumPad 3010 @@ -94,7 +104,6 @@ private: virtual void draw_mouse() = 0; virtual void undraw_mouse() = 0; -// virtual bool check_hard_keys() = 0; virtual bool check_event(Common::Event &event, EventPtr ev) = 0; virtual void timer_handler(); @@ -107,12 +116,10 @@ private: virtual void clearSoundCallback() = 0; protected: + OSystem_PalmBase(); + virtual void draw_osd(UInt16 id, Int32 x, Int32 y, Boolean show, UInt8 color = 0); - enum { - MAX_MOUSE_W = 80, - MAX_MOUSE_H = 80 - }; struct MousePos { int16 x,y,w,h; }; @@ -145,13 +152,15 @@ protected: Boolean _overlayVisible; Boolean _redawOSD, _setPalette; - UInt32 _keyMouseMask, _keyMouseRepeat, _keyMouseDelay; + UInt32 _keyExtraMask, _keyExtraPressed, _keyExtraRepeat, _keyExtraDelay; struct { UInt32 bitUp; UInt32 bitDown; UInt32 bitLeft; UInt32 bitRight; - } _keyMouse; + UInt32 bitActionA; // left mouse button + UInt32 bitActionB; // right mouse button + } _keyExtra; bool _mouseVisible; bool _mouseDrawn; @@ -163,7 +172,7 @@ protected: byte *_mouseDataP, *_mouseBackupP; - eventsEnum _wasKey; + bool _wasKey; UInt8 _lastKeyModifier; UInt32 _lastKeyRepeat; Boolean _useNumPad, _showBatLow; @@ -172,11 +181,10 @@ protected: int _samplesPerSec; public: - OSystem_PalmBase(); void initBackend(); /* - virtual void setFeatureState(Feature f, bool enable) {} + virtual void setFeatureState(Feature f, bool enable) {}; bool hasFeature(Feature f); @@ -216,7 +224,7 @@ public: bool showMouse(bool visible); void warpMouse(int x, int y); - virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor, int cursorTargetScale) = 0; + void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor, int cursorTargetScale); virtual void showOverlay() = 0; virtual void hideOverlay() = 0; diff --git a/backends/platform/PalmOS/Src/be_os5.cpp b/backends/platform/PalmOS/Src/be_os5.cpp index 74551607b7..d3e1d3578f 100644 --- a/backends/platform/PalmOS/Src/be_os5.cpp +++ b/backends/platform/PalmOS/Src/be_os5.cpp @@ -23,11 +23,7 @@ */ #include "be_os5.h" - -#ifndef __TWKEYS_H__ -#include #include -#endif OSystem_PalmOS5::OSystem_PalmOS5() : OSystem_PalmBase() { _sound.active = false; @@ -78,18 +74,12 @@ void OSystem_PalmOS5::calc_rect(Boolean fullscreen) { } void OSystem_PalmOS5::int_initBackend() { - if (OPTIONS_TST(kOpt5WayNavigatorV1)) { - _keyMouse.bitUp = keyBitPageUp; - _keyMouse.bitDown = keyBitPageDown; - _keyMouse.bitLeft = keyBitNavLeft; - _keyMouse.bitRight = keyBitNavRight; - - } else if (OPTIONS_TST(kOpt5WayNavigatorV2)) { - _keyMouse.bitUp = keyBitRockerUp|keyBitPageUp; - _keyMouse.bitDown = keyBitRockerDown|keyBitPageDown; - _keyMouse.bitLeft = keyBitRockerLeft; - _keyMouse.bitRight = keyBitRockerRight; - } + _keyExtra.bitUp = keyBitRockerUp|keyBitPageUp; + _keyExtra.bitDown = keyBitRockerDown|keyBitPageDown; + _keyExtra.bitLeft = keyBitRockerLeft; + _keyExtra.bitRight = keyBitRockerRight; + _keyExtra.bitActionA = keyBitHard3; + _keyExtra.bitActionB = keyBitHard4; } bool OSystem_PalmOS5::hasFeature(Feature f) { diff --git a/backends/platform/PalmOS/Src/be_os5.h b/backends/platform/PalmOS/Src/be_os5.h index e6c4227e71..b4b68bc920 100644 --- a/backends/platform/PalmOS/Src/be_os5.h +++ b/backends/platform/PalmOS/Src/be_os5.h @@ -99,6 +99,9 @@ typedef struct { extern SoundExType _soundEx; class OSystem_PalmOS5 : public OSystem_PalmBase { +protected: + int16 _nativePal[256], _mousePal[256]; + private: uint16 _scaleTableX[512]; uint32 _scaleTableY[512]; @@ -108,7 +111,6 @@ private: OverlayColor *_overlayP; WinHandle _overlayH, _workScreenH; - int16 _nativePal[256], _mousePal[256]; int16 *_workScreenP; Boolean _isSwitchable, _wasRotated; @@ -124,7 +126,7 @@ private: void draw_mouse(); void undraw_mouse(); virtual bool check_event(Common::Event &event, EventPtr ev); - virtual void extras_palette(uint8 index, uint8 r, uint8 g, uint8 b); + void extras_palette(uint8 index, uint8 r, uint8 g, uint8 b); void calc_scale(); void render_landscapeAny(RectangleType &r, PointType &p); @@ -168,8 +170,7 @@ public: void clearScreen(); bool grabRawScreen(Graphics::Surface *surf); - void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor, int cursorTargetScale); - virtual void setCursorPalette(const byte *colors, uint start, uint num); + void setCursorPalette(const byte *colors, uint start, uint num); void disableCursorPalette(bool disable); void showOverlay(); @@ -179,7 +180,7 @@ public: virtual void copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h); virtual OverlayColor RGBToColor(uint8 r, uint8 g, uint8 b); virtual void colorToRGB(OverlayColor color, uint8 &r, uint8 &g, uint8 &b); - + void setWindowCaption(const char *caption); }; diff --git a/backends/platform/PalmOS/Src/be_zodiac.cpp b/backends/platform/PalmOS/Src/be_zodiac.cpp index ce4dfa6013..76e3ed8562 100644 --- a/backends/platform/PalmOS/Src/be_zodiac.cpp +++ b/backends/platform/PalmOS/Src/be_zodiac.cpp @@ -33,10 +33,13 @@ OSystem_PalmZodiac::OSystem_PalmZodiac() : OSystem_PalmOS5Ex() { } void OSystem_PalmZodiac::int_initBackend() { - _keyMouse.bitUp = keyBitRockerUp; - _keyMouse.bitDown = keyBitRockerDown; - _keyMouse.bitLeft = keyBitRockerLeft; - _keyMouse.bitRight = keyBitRockerRight; + _keyExtra.bitUp = keyBitRockerUp; + _keyExtra.bitDown = keyBitRockerDown; + _keyExtra.bitLeft = keyBitRockerLeft; + _keyExtra.bitRight = keyBitRockerRight; + +// _keyExtra.bitActionA = keyBitActionD; +// _keyExtra.bitActionB = keyBitActionB; } void OSystem_PalmZodiac::calc_rect(Boolean fullscreen) { diff --git a/backends/platform/PalmOS/Src/be_zodiac.h b/backends/platform/PalmOS/Src/be_zodiac.h index 1d28afa493..c93004c89a 100644 --- a/backends/platform/PalmOS/Src/be_zodiac.h +++ b/backends/platform/PalmOS/Src/be_zodiac.h @@ -36,7 +36,6 @@ private: TwGfxType *_gfxH; TwGfxSurfaceType *_palmScreenP, *_tmpScreenP; TwGfxSurfaceType *_overlayP; - UInt16 _nativePal[256], _mousePal[256]; Boolean _fullscreen; TwGfxPointType _srcPos; @@ -53,7 +52,6 @@ private: void load_gfx_mode(); void hotswap_gfx_mode(int mode); - void extras_palette(uint8 index, uint8 r, uint8 g, uint8 b); void calc_rect(Boolean fullscreen); bool check_event(Common::Event &event, EventPtr ev); void draw_osd(UInt16 id, Int32 x, Int32 y, Boolean show, UInt8 color = 0); @@ -69,8 +67,6 @@ public: void updateScreen(); - void setCursorPalette(const byte *colors, uint start, uint num); - void clearOverlay(); void grabOverlay(OverlayColor *buf, int pitch); void copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h); diff --git a/backends/platform/PalmOS/Src/os5_event.cpp b/backends/platform/PalmOS/Src/os5_event.cpp index 8af2a717a7..85a3b49426 100644 --- a/backends/platform/PalmOS/Src/os5_event.cpp +++ b/backends/platform/PalmOS/Src/os5_event.cpp @@ -37,19 +37,12 @@ void OSystem_PalmOS5::get_coordinates(EventPtr ev, Coord &x, Coord &y) { } } -bool OSystem_PalmOS5::check_event(Event &event, EventPtr ev) { +bool OSystem_PalmOS5::check_event(Common::Event &event, EventPtr ev) { if (ev->eType == keyUpEvent) { - switch (ev->data.keyDown.chr) { + switch (ev->data.keyUp.chr) { case vchrHard3: - event.type = Common::EVENT_LBUTTONUP; - event.mouse.x = _mouseCurState.x; - event.mouse.y = _mouseCurState.y; - return true; - case vchrHard4: - event.type = Common::EVENT_RBUTTONUP; - event.mouse.x = _mouseCurState.x; - event.mouse.y = _mouseCurState.y; + // will be handled by hard keys return true; } @@ -59,23 +52,24 @@ bool OSystem_PalmOS5::check_event(Event &event, EventPtr ev) { // hot swap gfx // case 0x1B04: case vchrHard1: - printf("swap\n"); if (OPTIONS_TST(kOptCollapsible)) hotswap_gfx_mode(_mode == GFX_WIDE ? GFX_NORMAL: GFX_WIDE); return false; // not a key // case 0x1B05: case vchrHard2: - setFeatureState(kFeatureAspectRatioCorrection, 0); - return false; // not a key + setFeatureState(kFeatureAspectRatioCorrection, 0); + return false; // not a key case vchrHard3: - event.type = Common::EVENT_RBUTTONDOWN; + _keyExtraPressed |= _keyExtra.bitActionA; + event.type = Common::EVENT_LBUTTONDOWN; event.mouse.x = _mouseCurState.x; event.mouse.y = _mouseCurState.y; return true; case vchrHard4: + _keyExtraPressed |= _keyExtra.bitActionB; event.type = Common::EVENT_RBUTTONDOWN; event.mouse.x = _mouseCurState.x; event.mouse.y = _mouseCurState.y; diff --git a/backends/platform/PalmOS/Src/os5_gfx.cpp b/backends/platform/PalmOS/Src/os5_gfx.cpp index 295c753604..c68e5ea8c7 100644 --- a/backends/platform/PalmOS/Src/os5_gfx.cpp +++ b/backends/platform/PalmOS/Src/os5_gfx.cpp @@ -28,11 +28,6 @@ #include #include -#ifdef PALMOS_ARM -#include -#include -#endif - #include "oscalls.h" void OSystem_PalmOS5::int_initSize(uint w, uint h) { @@ -63,8 +58,6 @@ void OSystem_PalmOS5::load_gfx_mode() { _ratio.width = (gVars->screenFullHeight * _screenWidth / _screenHeight); _ratio.height = (gVars->screenFullWidth * _screenHeight / _screenWidth); - _mouseBackupP = (byte *)MemPtrNew(MAX_MOUSE_W * MAX_MOUSE_H * 2); // *2 if 16bit - _mouseDataP = (byte *)MemPtrNew(MAX_MOUSE_W * MAX_MOUSE_H); _offScreenP = (byte *)malloc(_screenWidth * _screenHeight); MemSet(_offScreenP, _screenWidth * _screenHeight, 0); @@ -75,6 +68,11 @@ void OSystem_PalmOS5::load_gfx_mode() { WinScreenMode(winScreenModeSet, NULL, NULL, &depth, NULL); clearScreen(); + if (OPTIONS_TST(kOptModeRotatable)) { + _sysOldOrientation = __68K(SysGetOrientation()); + __68K(SysSetOrientation(sysOrientationLandscape)); + } + gVars->indicator.on = RGBToColor(0,255,0); gVars->indicator.off = RGBToColor(0,0,0); @@ -97,13 +95,6 @@ void OSystem_PalmOS5::hotswap_gfx_mode(int mode) { if (_mode != GFX_NORMAL && !_isSwitchable) return; -#ifdef PALMOS_ARM - UInt32 device; - Boolean isT3 = false; - if (!FtrGet(sysFileCSystem, sysFtrNumOEMDeviceID, &device)) - isT3 = (device == kPalmOneDeviceIDTungstenT3); -#endif - if (_workScreenH) WinDeleteWindow(_workScreenH, false); _workScreenH = NULL; @@ -117,17 +108,9 @@ void OSystem_PalmOS5::hotswap_gfx_mode(int mode) { _stretched = (_screenWidth > gVars->screenWidth); if (OPTIONS_TST(kOptCollapsible)) { -#ifdef PALMOS_ARM - if (isT3) { - //AiaSetInputAreaState(aiaInputAreaShow); - StatShow_68k(); - PINSetInputAreaState_68k(pinInputAreaOpen); - } else -#endif - { - StatShow(); - PINSetInputAreaState(pinInputAreaOpen); - } + //AiaSetInputAreaState(aiaInputAreaShow); // For T3 ?? + __68K(StatShow()); + __68K(PINSetInputAreaState(pinInputAreaOpen)); } if (_stretched) { @@ -143,18 +126,10 @@ void OSystem_PalmOS5::hotswap_gfx_mode(int mode) { _stretched = true; if (OPTIONS_TST(kOptCollapsible)) { -#ifdef PALMOS_ARM // T3 DIA library is 68k base, there is no possible native call - if (isT3) { - //AiaSetInputAreaState(aiaInputAreaFullScreen); - PINSetInputAreaState_68k(pinInputAreaClosed); - StatHide_68k(); - } else -#endif - { - PINSetInputAreaState(pinInputAreaClosed); - StatHide(); - } + //AiaSetInputAreaState(aiaInputAreaFullScreen); + __68K(PINSetInputAreaState(pinInputAreaClosed)); + __68K(StatHide()); } calc_rect(true); @@ -182,8 +157,7 @@ void OSystem_PalmOS5::unload_gfx_mode() { return; _gfxLoaded = false; - MemPtrFree(_mouseBackupP); - MemPtrFree(_mouseDataP); + // mouse data freed in quit() free(_offScreenP); if (_workScreenH) @@ -198,6 +172,9 @@ void OSystem_PalmOS5::unload_gfx_mode() { WinScreenMode(winScreenModeSet, NULL, NULL, &depth, NULL); clearScreen(); + if (OPTIONS_TST(kOptModeRotatable)) + __68K(SysSetOrientation(_sysOldOrientation)); + WinSetCoordinateSystem(_sysOldCoord); } diff --git a/backends/platform/PalmOS/Src/os5_mouse.cpp b/backends/platform/PalmOS/Src/os5_mouse.cpp index 20e725694c..a0b372bfad 100644 --- a/backends/platform/PalmOS/Src/os5_mouse.cpp +++ b/backends/platform/PalmOS/Src/os5_mouse.cpp @@ -37,130 +37,86 @@ void OSystem_PalmOS5::disableCursorPalette(bool disable) { _cursorPaletteDisabled = disable; } -void OSystem_PalmOS5::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor, int cursorTargetScale) { - if (w == 0 || h == 0) - return; - -FIXME: The restriction on MAX_MOUSE_H / MAX_MOUSE_W is obsolete; -in particular, BS2 might use bigger cursors these days. -See also bug #1609058. 1607180 -Hence this code now might overwrite memory unchecked; at the -very least an assert should be inserted to cause a controlled -crash, but of course it would be better to remove the restriction -on "small" cursors. - - - _mouseCurState.w = w; - _mouseCurState.h = h; - - _mouseHotspotX = hotspotX; - _mouseHotspotY = hotspotY; - - _mouseKeyColor = keycolor; - - // copy new cursor - byte *dst = _mouseDataP; - memset(dst, MAX_MOUSE_W * MAX_MOUSE_H, keycolor); - while (h--) { - memcpy(dst, buf, w); - dst += MAX_MOUSE_W; - buf += w; - } -} - +// TODO: this code is almost the same as Zodiac version. void OSystem_PalmOS5::draw_mouse() { - if (_mouseDrawn || !_mouseVisible) + if (!_mouseDataP || _mouseDrawn || !_mouseVisible) return; - - byte *src = _mouseDataP; // Image representing the mouse - byte color; - int width; - - _mouseCurState.y = _mouseCurState.y >= _screenHeight ? _screenHeight - 1 : _mouseCurState.y; + + byte *src = _mouseDataP; int x = _mouseCurState.x - _mouseHotspotX; int y = _mouseCurState.y - _mouseHotspotY; int w = _mouseCurState.w; int h = _mouseCurState.h; - int draw_x = x; - int draw_y = y; - // clip the mouse rect - if (x < 0) { - w += x; - src -= x; - x = 0; - } if (y < 0) { + src -= y * w; h += y; - src -= y * MAX_MOUSE_W; y = 0; } - if (w > _screenWidth - x) - w = _screenWidth - x; + if (x < 0) { + src -= x; + w += x; + x = 0; + } + if (h > _screenHeight - y) h = _screenHeight - y; + if (w > _screenWidth - x) + w = _screenWidth - x; - // Quick check to see if anything has to be drawn at all if (w <= 0 || h <= 0) return; - // Store the bounding box so that undraw mouse can restore the area the - // mouse currently covers to its original content. + // store the bounding box so that undraw mouse can restore the area the + // mouse currently covers to its original content _mouseOldState.x = x; _mouseOldState.y = y; _mouseOldState.w = w; _mouseOldState.h = h; - // Quick check to see if anything has to be drawn at all - if (w <= 0 || h <= 0) - return; - - // Store the bounding box so that undraw mouse can restore the area the - // mouse currently covers to its original content. - _mouseOldState.x = x; - _mouseOldState.y = y; - _mouseOldState.w = w; - _mouseOldState.h = h; + byte color; + int ww; - // Backup the covered area draw the mouse cursor if (_overlayVisible) { - int16 *bak = (int16 *)_mouseBackupP; // Surface used to backup the area obscured by the mouse - int16 *dst = _overlayP + y * _screenWidth + x; + int16 *bak = (int16 *)_mouseBackupP; int16 *pal = _cursorPaletteDisabled ? _nativePal : _mousePal; + int16 *dst = _overlayP + y * _screenWidth + x; do { - width = w; + ww = w; do { *bak++ = *dst; color = *src++; - if (color != _mouseKeyColor) // transparent, don't draw + + // transparent, don't draw + if (color != _mouseKeyColor) *dst = pal[color]; dst++; - } while (--width); + } while (--ww); - src += MAX_MOUSE_W - w; - bak += MAX_MOUSE_W - w; + src += _mouseCurState.w - w; dst += _screenWidth - w; } while (--h); } else { - byte *bak = _mouseBackupP; // Surface used to backup the area obscured by the mouse - byte *dst =_offScreenP + y * _screenWidth + x; // Surface we are drawing into + byte *bak = _mouseBackupP; + byte *dst =_offScreenP + y * _screenWidth + x; do { - width = w; + ww = w; do { *bak++ = *dst; color = *src++; - if (color != _mouseKeyColor) // transparent, don't draw + + // transparent, don't draw + if (color != _mouseKeyColor) *dst = color; dst++; - } while (--width); + } while (--ww); - src += MAX_MOUSE_W - w; - bak += MAX_MOUSE_W - w; + src += _mouseCurState.w - w; dst += _screenWidth - w; } while (--h); } @@ -173,27 +129,28 @@ void OSystem_PalmOS5::undraw_mouse() { return; int h = _mouseOldState.h; - // No need to do clipping here, since draw_mouse() did that already + + // no need to do clipping here, since draw_mouse() did that already if (_overlayVisible) { - int16 *bak = (int16 *)_mouseBackupP; int16 *dst = _overlayP + _mouseOldState.y * _screenWidth + _mouseOldState.x; + int16 *bak = (int16 *)_mouseBackupP; do { - memcpy(dst, bak, _mouseOldState.w * 2); - bak += MAX_MOUSE_W; + MemMove(dst, bak, _mouseOldState.w * 2); dst += _screenWidth; + bak += _mouseOldState.w; } while (--h); } else { - byte *dst, *bak = _mouseBackupP; - dst = _offScreenP + _mouseOldState.y * _screenWidth + _mouseOldState.x; + byte *dst = _offScreenP + _mouseOldState.y * _screenWidth + _mouseOldState.x; + byte *bak = _mouseBackupP; do { - memcpy(dst, bak, _mouseOldState.w); - bak += MAX_MOUSE_W; + MemMove(dst, bak, _mouseOldState.w); dst += _screenWidth; + bak += _mouseOldState.w; } while (--h); } _mouseDrawn = false; -} +} \ No newline at end of file diff --git a/backends/platform/PalmOS/Src/os5_overlay.cpp b/backends/platform/PalmOS/Src/os5_overlay.cpp index 93c6123cef..0eee6d167b 100644 --- a/backends/platform/PalmOS/Src/os5_overlay.cpp +++ b/backends/platform/PalmOS/Src/os5_overlay.cpp @@ -31,7 +31,7 @@ void OSystem_PalmOS5::showOverlay() { undraw_mouse(); _overlayVisible = true; - clearOverlay(); + clearOverlay(); } void OSystem_PalmOS5::hideOverlay() { diff --git a/backends/platform/PalmOS/Src/os5_sound.cpp b/backends/platform/PalmOS/Src/os5_sound.cpp index 4bdded13e7..7af173036f 100644 --- a/backends/platform/PalmOS/Src/os5_sound.cpp +++ b/backends/platform/PalmOS/Src/os5_sound.cpp @@ -134,7 +134,7 @@ void OSystem_PalmOS5::clearSoundCallback() { } if (_soundEx.dataP) - free(_soundEx.dataP); + MemPtrFree(_soundEx.dataP); } _sound.active = false; diff --git a/backends/platform/PalmOS/Src/zodiac_gfx.cpp b/backends/platform/PalmOS/Src/zodiac_gfx.cpp index d14f745657..c84a6af056 100644 --- a/backends/platform/PalmOS/Src/zodiac_gfx.cpp +++ b/backends/platform/PalmOS/Src/zodiac_gfx.cpp @@ -56,11 +56,9 @@ void OSystem_PalmZodiac::load_gfx_mode() { _ratio.adjustAspect = ConfMan.getBool("aspect_ratio") ? kRatioHeight : kRatioNone; // precalc ratio (WIDE mode) - _ratio.width = ((float)_screenWidth / _screenHeight * gVars->screenFullHeight); - _ratio.height = ((float)_screenHeight / _screenWidth * gVars->screenFullWidth); + _ratio.width = (gVars->screenFullHeight * _screenWidth / _screenHeight); + _ratio.height = (gVars->screenFullWidth * _screenHeight / _screenWidth); - _mouseBackupP = (byte *)MemPtrNew(MAX_MOUSE_W * MAX_MOUSE_H * 2); // *2 if 16bit - _mouseDataP = (byte *)MemPtrNew(MAX_MOUSE_W * MAX_MOUSE_H); _offScreenP = (byte *)MemPtrNew(_screenWidth * _screenHeight); MemSet(_offScreenP, _screenWidth * _screenHeight, 0); @@ -98,7 +96,7 @@ void OSystem_PalmZodiac::load_gfx_mode() { _srcBmp.rowBytes = _screenWidth; _srcBmp.pixelFormat = twGfxPixelFormat8bpp; _srcBmp.data = _offScreenP; - _srcBmp.palette = _nativePal; + _srcBmp.palette = (UInt16 *)_nativePal; _srcRect.x = 0; _srcRect.y = 0; @@ -192,8 +190,6 @@ void OSystem_PalmZodiac::unload_gfx_mode() { WinScreenMode(winScreenModeSet, NULL, NULL, &depth, NULL); clearScreen(); - MemPtrFree(_mouseBackupP); - MemPtrFree(_mouseDataP); MemPtrFree(_offScreenP); SysSetOrientation(_sysOldOrientation); @@ -217,7 +213,8 @@ void OSystem_PalmZodiac::updateScreen() { Err e; // draw the mouse pointer - draw_mouse(); + draw_mouse(); + // update the screen if (_overlayVisible) { if (_stretched) { @@ -247,6 +244,7 @@ void OSystem_PalmZodiac::updateScreen() { dst.y += _new_shake_pos; } e = TwGfxDrawBitmap(_tmpScreenP, &pos, &_srcBmp); + e = TwGfxWaitForVBlank(_gfxH); e = TwGfxStretchBlt2(_palmScreenP, &dst, _tmpScreenP, &_srcRect, twGfxStretchFast| (gVars->filter ? twGfxStretchSmooth : 0)); } else { @@ -264,13 +262,11 @@ void OSystem_PalmZodiac::updateScreen() { e = TwGfxDrawBitmap(_palmScreenP, &pos, &_srcBmp); } } + + // undraw the mouse undraw_mouse(); } -void OSystem_PalmZodiac::extras_palette(uint8 index, uint8 r, uint8 g, uint8 b) { - _nativePal[index] = TwGfxMakeDisplayRGB(r, g, b); -} - void OSystem_PalmZodiac::draw_osd(UInt16 id, Int32 x, Int32 y, Boolean show, UInt8 color) { if (_mode != GFX_NORMAL) return; diff --git a/backends/platform/PalmOS/Src/zodiac_mouse.cpp b/backends/platform/PalmOS/Src/zodiac_mouse.cpp index bd68be1ae7..52e2261e44 100644 --- a/backends/platform/PalmOS/Src/zodiac_mouse.cpp +++ b/backends/platform/PalmOS/Src/zodiac_mouse.cpp @@ -24,100 +24,90 @@ #include "be_zodiac.h" -void OSystem_PalmZodiac::setCursorPalette(const byte *colors, uint start, uint num) { - for(uint i = 0; i < num; i++) { - _mousePal[i + start] = TwGfxMakeDisplayRGB(colors[0], colors[1], colors[2]); - colors += 4; - } - _cursorPaletteDisabled = false; -} - void OSystem_PalmZodiac::draw_mouse() { - if (_mouseDrawn || !_mouseVisible) + if (!_mouseDataP || _mouseDrawn || !_mouseVisible) return; - - byte *src = _mouseDataP; // Image representing the mouse - byte color; - int width; - - _mouseCurState.y = _mouseCurState.y >= _screenHeight ? _screenHeight - 1 : _mouseCurState.y; + + byte *src = _mouseDataP; int x = _mouseCurState.x - _mouseHotspotX; int y = _mouseCurState.y - _mouseHotspotY; int w = _mouseCurState.w; int h = _mouseCurState.h; - int draw_x = x; - int draw_y = y; - // clip the mouse rect - if (x < 0) { - w += x; - src -= x; - x = 0; - } if (y < 0) { + src -= y * w; h += y; - src -= y * MAX_MOUSE_W; y = 0; } - if (w > _screenWidth - x) - w = _screenWidth - x; + if (x < 0) { + src -= x; + w += x; + x = 0; + } + if (h > _screenHeight - y) h = _screenHeight - y; + if (w > _screenWidth - x) + w = _screenWidth - x; - // Quick check to see if anything has to be drawn at all if (w <= 0 || h <= 0) return; - // Store the bounding box so that undraw mouse can restore the area the - // mouse currently covers to its original content. + // store the bounding box so that undraw mouse can restore the area the + // mouse currently covers to its original content _mouseOldState.x = x; _mouseOldState.y = y; _mouseOldState.w = w; _mouseOldState.h = h; - // Backup the covered area draw the mouse cursor + byte color; + int ww; + if (_overlayVisible) { - uint16 *bak = (uint16 *)_mouseBackupP; // Surface used to backup the area obscured by the mouse - uint16 *dst, *pal = _cursorPaletteDisabled ? _nativePal : _mousePal; + int16 *bak = (int16 *)_mouseBackupP; + int16 *pal = _cursorPaletteDisabled ? _nativePal : _mousePal; + int16 *dst; TwGfxLockSurface(_overlayP, (void **)&dst); dst += y * _screenWidth + x; do { - width = w; + ww = w; do { *bak++ = *dst; color = *src++; - if (color != _mouseKeyColor) // transparent, don't draw + + // transparent, don't draw + if (color != _mouseKeyColor) *dst = pal[color]; dst++; - } while (--width); + } while (--ww); - src += MAX_MOUSE_W - w; - bak += MAX_MOUSE_W - w; + src += _mouseCurState.w - w; dst += _screenWidth - w; } while (--h); TwGfxUnlockSurface(_overlayP, true); } else { - byte *bak = _mouseBackupP; // Surface used to backup the area obscured by the mouse - byte *dst =_offScreenP + y * _screenWidth + x; // Surface we are drawing into + byte *bak = _mouseBackupP; + byte *dst =_offScreenP + y * _screenWidth + x; do { - width = w; + ww = w; do { *bak++ = *dst; color = *src++; - if (color != _mouseKeyColor) // transparent, don't draw + + // transparent, don't draw + if (color != _mouseKeyColor) *dst = color; dst++; - } while (--width); + } while (--ww); - src += MAX_MOUSE_W - w; - bak += MAX_MOUSE_W - w; + src += _mouseCurState.w - w; dst += _screenWidth - w; } while (--h); } @@ -130,30 +120,31 @@ void OSystem_PalmZodiac::undraw_mouse() { return; int h = _mouseOldState.h; - // No need to do clipping here, since draw_mouse() did that already + + // no need to do clipping here, since draw_mouse() did that already if (_overlayVisible) { - uint16 *bak = (uint16 *)_mouseBackupP; uint16 *dst; + uint16 *bak = (uint16 *)_mouseBackupP; TwGfxLockSurface(_overlayP, (void **)&dst); dst += _mouseOldState.y * _screenWidth + _mouseOldState.x; do { - memcpy(dst, bak, _mouseOldState.w * 2); - bak += MAX_MOUSE_W; + MemMove(dst, bak, _mouseOldState.w * 2); dst += _screenWidth; + bak += _mouseOldState.w; } while (--h); TwGfxUnlockSurface(_overlayP, true); } else { - byte *dst, *bak = _mouseBackupP; - dst = _offScreenP + _mouseOldState.y * _screenWidth + _mouseOldState.x; - + byte *dst = _offScreenP + _mouseOldState.y * _screenWidth + _mouseOldState.x; + byte *bak = _mouseBackupP; + do { - memcpy(dst, bak, _mouseOldState.w); - bak += MAX_MOUSE_W; + MemMove(dst, bak, _mouseOldState.w); dst += _screenWidth; + bak += _mouseOldState.w; } while (--h); } diff --git a/backends/platform/PalmOS/Src/zodiac_overlay.cpp b/backends/platform/PalmOS/Src/zodiac_overlay.cpp index d1b2f7a558..09385c110a 100644 --- a/backends/platform/PalmOS/Src/zodiac_overlay.cpp +++ b/backends/platform/PalmOS/Src/zodiac_overlay.cpp @@ -34,7 +34,7 @@ void OSystem_PalmZodiac::clearOverlay() { TwGfxBitmapType bmp = { sizeof(TwGfxBitmapType), _screenWidth, _screenHeight, _screenWidth, twGfxPixelFormat8bpp, - (void *)_offScreenP, _nativePal + (void *)_offScreenP, (UInt16 *)_nativePal }; e = TwGfxDrawBitmap(_overlayP, &pos, &bmp); } -- cgit v1.2.3