From 30084d72a5eaedbd22cc14aa6bb1f72a573944f0 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Wed, 30 Sep 2009 23:00:03 +0000 Subject: [PATCH] Added a new special reg_t, SIGNAL_REG, for signaling when an error occurs (usually), or to signal success in some special occasions svn-id: r44505 --- engines/sci/engine/kfile.cpp | 4 ++-- engines/sci/engine/kgraphics.cpp | 2 +- engines/sci/engine/kmath.cpp | 8 ++++---- engines/sci/engine/kmisc.cpp | 2 +- engines/sci/engine/kmovement.cpp | 2 +- engines/sci/engine/vm.cpp | 1 + engines/sci/engine/vm_types.h | 1 + engines/sci/gfx/menubar.cpp | 6 +++--- 8 files changed, 14 insertions(+), 12 deletions(-) diff --git a/engines/sci/engine/kfile.cpp b/engines/sci/engine/kfile.cpp index 8e4dbdb1480..1c68428de51 100644 --- a/engines/sci/engine/kfile.cpp +++ b/engines/sci/engine/kfile.cpp @@ -148,7 +148,7 @@ void file_open(EngineState *s, const char *filename, int mode) { if (!inFile && !outFile) { // Failed debug(3, "file_open() failed"); - s->r_acc = make_reg(0, SIGNAL_OFFSET); + s->r_acc = SIGNAL_REG; return; } @@ -755,7 +755,7 @@ reg_t kFileIO(EngineState *s, int argc, reg_t *argv) { if (name.empty()) { warning("Attempted to open a file with an empty filename"); - return make_reg(0, SIGNAL_OFFSET); + return SIGNAL_REG; } file_open(s, name.c_str(), mode); debug(3, "K_FILEIO_OPEN(%s,0x%x)", name.c_str(), mode); diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp index ecfc6e1ae89..1afc2b76c47 100644 --- a/engines/sci/engine/kgraphics.cpp +++ b/engines/sci/engine/kgraphics.cpp @@ -876,7 +876,7 @@ reg_t kIsItSkip(EngineState *s, int argc, reg_t *argv) { if (!res) { warning("[GFX] Attempt to get cel parameters for invalid view %d", view); - return make_reg(0, SIGNAL_OFFSET); + return SIGNAL_REG; } pxm = res->loops[loop].cels[cel]; diff --git a/engines/sci/engine/kmath.cpp b/engines/sci/engine/kmath.cpp index 3ebe2483ce1..ea427435f26 100644 --- a/engines/sci/engine/kmath.cpp +++ b/engines/sci/engine/kmath.cpp @@ -130,7 +130,7 @@ reg_t kCosDiv(EngineState *s, int argc, reg_t *argv) { if ((cosval < 0.0001) && (cosval > -0.0001)) { warning("kCosDiv: Attempted division by zero"); - return make_reg(0, SIGNAL_OFFSET); + return SIGNAL_REG; } else return make_reg(0, (int16)(value / cosval)); } @@ -142,7 +142,7 @@ reg_t kSinDiv(EngineState *s, int argc, reg_t *argv) { if ((sinval < 0.0001) && (sinval > -0.0001)) { warning("kSinDiv: Attempted division by zero"); - return make_reg(0, SIGNAL_OFFSET); + return SIGNAL_REG; } else return make_reg(0, (int16)(value / sinval)); } @@ -154,7 +154,7 @@ reg_t kTimesTan(EngineState *s, int argc, reg_t *argv) { param -= 90; if ((param % 90) == 0) { warning("kTimesTan: Attempted tan(pi/2)"); - return make_reg(0, SIGNAL_OFFSET); + return SIGNAL_REG; } else return make_reg(0, (int16) - (tan(param * PI / 180.0) * scale)); } @@ -165,7 +165,7 @@ reg_t kTimesCot(EngineState *s, int argc, reg_t *argv) { if ((param % 90) == 0) { warning("kTimesCot: Attempted tan(pi/2)"); - return make_reg(0, SIGNAL_OFFSET); + return SIGNAL_REG; } else return make_reg(0, (int16)(tan(param * PI / 180.0) * scale)); } diff --git a/engines/sci/engine/kmisc.cpp b/engines/sci/engine/kmisc.cpp index 42a595cdd8a..4d0bd8a73a7 100644 --- a/engines/sci/engine/kmisc.cpp +++ b/engines/sci/engine/kmisc.cpp @@ -60,7 +60,7 @@ reg_t kGameIsRestarting(EngineState *s, int argc, reg_t *argv) { } reg_t kHaveMouse(EngineState *s, int argc, reg_t *argv) { - return make_reg(0, SIGNAL_OFFSET); + return SIGNAL_REG; } enum kMemoryInfoFunc { diff --git a/engines/sci/engine/kmovement.cpp b/engines/sci/engine/kmovement.cpp index ad5851cd3dc..3a21704469e 100644 --- a/engines/sci/engine/kmovement.cpp +++ b/engines/sci/engine/kmovement.cpp @@ -401,7 +401,7 @@ reg_t kDoAvoider(EngineState *s, int argc, reg_t *argv) { int dx, dy; int destx, desty; - s->r_acc = make_reg(0, SIGNAL_OFFSET); + s->r_acc = SIGNAL_REG; if (!s->segMan->isHeapObject(avoider)) { warning("DoAvoider() where avoider %04x:%04x is not an object", PRINT_REG(avoider)); diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp index f377e77d137..d617ecf64eb 100644 --- a/engines/sci/engine/vm.cpp +++ b/engines/sci/engine/vm.cpp @@ -40,6 +40,7 @@ namespace Sci { reg_t NULL_REG = {0, 0}; +reg_t SIGNAL_REG = {0, SIGNAL_OFFSET}; //#define VM_DEBUG_SEND #undef STRICT_SEND // Disallows variable sends with more than one parameter diff --git a/engines/sci/engine/vm_types.h b/engines/sci/engine/vm_types.h index 62dc35aae7e..93378fe3d1c 100644 --- a/engines/sci/engine/vm_types.h +++ b/engines/sci/engine/vm_types.h @@ -81,6 +81,7 @@ static inline reg_t make_reg(SegmentId segment, uint16 offset) { } extern reg_t NULL_REG; +extern reg_t SIGNAL_REG; } // End of namespace Sci diff --git a/engines/sci/gfx/menubar.cpp b/engines/sci/gfx/menubar.cpp index 283b2334775..6005e620412 100644 --- a/engines/sci/gfx/menubar.cpp +++ b/engines/sci/gfx/menubar.cpp @@ -345,10 +345,10 @@ int Menubar::setAttribute(EngineState *s, int menu_nr, int item_nr, int attribut reg_t Menubar::getAttribute(int menu_nr, int item_nr, int attribute) const { if ((menu_nr < 0) || (item_nr < 0)) - return make_reg(0, SIGNAL_OFFSET); + return SIGNAL_REG; if ((menu_nr >= (int)_menus.size()) || (item_nr >= (int)_menus[menu_nr]._items.size())) - return make_reg(0, SIGNAL_OFFSET); + return SIGNAL_REG; const MenuItem &item = _menus[menu_nr]._items[item_nr]; @@ -370,7 +370,7 @@ reg_t Menubar::getAttribute(int menu_nr, int item_nr, int attribute) const { default: warning("Attempt to read invalid attribute from menu %d, item %d: 0x%04x", menu_nr, item_nr, attribute); - return make_reg(0, SIGNAL_OFFSET); + return SIGNAL_REG; } }