aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
Diffstat (limited to 'engines')
-rw-r--r--engines/sci/engine/kernel32.cpp42
-rw-r--r--engines/sci/gui/gui.cpp8
-rw-r--r--engines/sci/gui/gui.h3
-rw-r--r--engines/sci/gui32/gui32.h3
4 files changed, 48 insertions, 8 deletions
diff --git a/engines/sci/engine/kernel32.cpp b/engines/sci/engine/kernel32.cpp
index d6fe995467..d984bf4117 100644
--- a/engines/sci/engine/kernel32.cpp
+++ b/engines/sci/engine/kernel32.cpp
@@ -640,13 +640,26 @@ reg_t kSave(EngineState *s, int argc, reg_t *argv) {
reg_t kAddScreenItem(EngineState *s, int argc, reg_t *argv) {
reg_t viewObj = argv[0];
uint16 viewId = GET_SEL32V(s->_segMan, viewObj, view);
- int16 loopNo = GET_SEL32V(s->_segMan, viewObj, loop);
- int16 celNo = GET_SEL32V(s->_segMan, viewObj, cel);
- int16 leftPos = GET_SEL32V(s->_segMan, viewObj, x);
- int16 topPos = GET_SEL32V(s->_segMan, viewObj, y);
+ uint16 loopNo = GET_SEL32V(s->_segMan, viewObj, loop);
+ uint16 celNo = GET_SEL32V(s->_segMan, viewObj, cel);
+ uint16 leftPos = GET_SEL32V(s->_segMan, viewObj, x);
+ uint16 topPos = GET_SEL32V(s->_segMan, viewObj, y);
int16 priority = GET_SEL32V(s->_segMan, viewObj, priority);
//int16 control = 0;
+ // Theoretically, leftPos and topPos should be sane
+ // Apparently, sometimes they're not, therefore I'm adding some sanity checks here so that
+ // the hack underneath does not try and draw cels outside the screen coordinates
+ if (leftPos >= (int16)s->_gui->getScreenWidth()) {
+ warning("kAddScreenItem: invalid left position (%d), resetting to 0", leftPos);
+ leftPos = 0;
+ }
+
+ if (topPos >= s->_gui->getScreenHeight()) {
+ warning("kAddScreenItem: invalid top position (%d), resetting to 0", topPos);
+ topPos = 0;
+ }
+
// HACK: just draw the view on screen
if (viewId != 0xffff)
s->_gui->drawCel(viewId, loopNo, celNo, leftPos, topPos, priority, 0);
@@ -661,13 +674,26 @@ reg_t kAddScreenItem(EngineState *s, int argc, reg_t *argv) {
reg_t kUpdateScreenItem(EngineState *s, int argc, reg_t *argv) {
reg_t viewObj = argv[0];
uint16 viewId = GET_SEL32V(s->_segMan, viewObj, view);
- int16 loopNo = GET_SEL32V(s->_segMan, viewObj, loop);
- int16 celNo = GET_SEL32V(s->_segMan, viewObj, cel);
- int16 leftPos = GET_SEL32V(s->_segMan, viewObj, x);
- int16 topPos = GET_SEL32V(s->_segMan, viewObj, y);
+ uint16 loopNo = GET_SEL32V(s->_segMan, viewObj, loop);
+ uint16 celNo = GET_SEL32V(s->_segMan, viewObj, cel);
+ uint16 leftPos = GET_SEL32V(s->_segMan, viewObj, x);
+ uint16 topPos = GET_SEL32V(s->_segMan, viewObj, y);
int16 priority = GET_SEL32V(s->_segMan, viewObj, priority);
//int16 control = 0;
+ // Theoretically, leftPos and topPos should be sane
+ // Apparently, sometimes they're not, therefore I'm adding some sanity checks here so that
+ // the hack underneath does not try and draw cels outside the screen coordinates
+ if (leftPos >= s->_gui->getScreenWidth()) {
+ warning("kUpdateScreenItem: invalid left position (%d), resetting to 0", leftPos);
+ leftPos = 0;
+ }
+
+ if (topPos >= s->_gui->getScreenHeight()) {
+ warning("kUpdateScreenItem: invalid top position (%d), resetting to 0", topPos);
+ topPos = 0;
+ }
+
// HACK: just draw the view on screen
if (viewId != 0xffff)
s->_gui->drawCel(viewId, loopNo, celNo, leftPos, topPos, priority, 0);
diff --git a/engines/sci/gui/gui.cpp b/engines/sci/gui/gui.cpp
index 33d124cc54..fcbe4f9a05 100644
--- a/engines/sci/gui/gui.cpp
+++ b/engines/sci/gui/gui.cpp
@@ -823,6 +823,14 @@ void SciGui::portraitShow(Common::String resourceName, Common::Point position, u
void SciGui::portraitUnload(uint16 portraitId) {
}
+uint16 SciGui::getScreenWidth() {
+ return _screen->_displayWidth;
+}
+
+uint16 SciGui::getScreenHeight() {
+ return _screen->_displayHeight;
+}
+
bool SciGui::debugUndither(bool flag) {
_screen->unditherSetState(flag);
return false;
diff --git a/engines/sci/gui/gui.h b/engines/sci/gui/gui.h
index 4db3d931d2..ee1604d25b 100644
--- a/engines/sci/gui/gui.h
+++ b/engines/sci/gui/gui.h
@@ -149,6 +149,9 @@ public:
virtual void portraitShow(Common::String resourceName, Common::Point position, uint16 resourceNum, uint16 noun, uint16 verb, uint16 cond, uint16 seq);
virtual void portraitUnload(uint16 portraitId);
+ virtual uint16 getScreenWidth();
+ virtual uint16 getScreenHeight();
+
virtual bool debugUndither(bool flag);
virtual bool debugShowMap(int mapNo);
diff --git a/engines/sci/gui32/gui32.h b/engines/sci/gui32/gui32.h
index 7646d0c026..2bd13ae850 100644
--- a/engines/sci/gui32/gui32.h
+++ b/engines/sci/gui32/gui32.h
@@ -108,6 +108,9 @@ public:
void setCursorPos(Common::Point pos);
void moveCursor(Common::Point pos);
+ uint16 getScreenWidth() { return 320; }
+ uint16 getScreenHeight() { return 200; }
+
bool debugUndither(bool flag);
bool debugShowMap(int mapNo);