diff options
author | Colin Snover | 2017-01-05 10:29:14 -0600 |
---|---|---|
committer | Colin Snover | 2017-03-30 19:46:27 -0500 |
commit | f4d3664d3fb529a451ef57658b443fb1c878bdfa (patch) | |
tree | 458b84d7d1a6b1ef52f016c6c411a824b21df1a0 | |
parent | 3b34f17fb3f8d4f325fd8f7b10dc3a9325d72b29 (diff) | |
download | scummvm-rg350-f4d3664d3fb529a451ef57658b443fb1c878bdfa.tar.gz scummvm-rg350-f4d3664d3fb529a451ef57658b443fb1c878bdfa.tar.bz2 scummvm-rg350-f4d3664d3fb529a451ef57658b443fb1c878bdfa.zip |
SCI: Replace magic numbers in reg_t handling with symbols
-rw-r--r-- | engines/sci/engine/kernel.cpp | 2 | ||||
-rw-r--r-- | engines/sci/engine/scriptdebug.cpp | 4 | ||||
-rw-r--r-- | engines/sci/engine/vm.cpp | 10 | ||||
-rw-r--r-- | engines/sci/engine/vm.h | 2 | ||||
-rw-r--r-- | engines/sci/engine/vm_types.h | 12 |
5 files changed, 18 insertions, 12 deletions
diff --git a/engines/sci/engine/kernel.cpp b/engines/sci/engine/kernel.cpp index 60d4ccbf22..13a836ab77 100644 --- a/engines/sci/engine/kernel.cpp +++ b/engines/sci/engine/kernel.cpp @@ -380,7 +380,7 @@ uint16 Kernel::findRegType(reg_t reg) { if (!reg.getSegment()) return SIG_TYPE_INTEGER | (reg.getOffset() ? 0 : SIG_TYPE_NULL); - if (reg.getSegment() == 0xFFFF) + if (reg.getSegment() == kUninitializedSegment) return SIG_TYPE_UNINITIALIZED; // Otherwise it's an object diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp index d15cf83b71..971c721d6b 100644 --- a/engines/sci/engine/scriptdebug.cpp +++ b/engines/sci/engine/scriptdebug.cpp @@ -230,12 +230,12 @@ reg_t disassemble(EngineState *s, reg32_t pos, reg_t objAddr, bool printBWTag, b if (opsize) { int8 offset = (int8)scr[retval.getOffset()]; retval.incOffset(1); - debugN("\t%02x [%04x]", 0xff & offset, 0xffff & (retval.getOffset() + offset)); + debugN("\t%02x [%04x]", 0xff & offset, kOffsetMask & (retval.getOffset() + offset)); } else { int16 offset = (int16)READ_SCI11ENDIAN_UINT16(&scr[retval.getOffset()]); retval.incOffset(2); - debugN("\t%04x [%04x]", 0xffff & offset, 0xffff & (retval.getOffset() + offset)); + debugN("\t%04x [%04x]", 0xffff & offset, kOffsetMask & (retval.getOffset() + offset)); } break; diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp index 74a2841521..a9d575b013 100644 --- a/engines/sci/engine/vm.cpp +++ b/engines/sci/engine/vm.cpp @@ -120,7 +120,7 @@ extern const char *opcodeNames[]; // from scriptdebug.cpp static reg_t read_var(EngineState *s, int type, int index) { if (validate_variable(s->variables[type], s->stack_base, type, s->variablesMax[type], index)) { - if (s->variables[type][index].getSegment() == 0xffff) { + if (s->variables[type][index].getSegment() == kUninitializedSegment) { switch (type) { case VAR_TEMP: { // Uninitialized read on a temp @@ -194,7 +194,7 @@ static void write_var(EngineState *s, int type, int index, reg_t value) { // this happens at least in sq1/room 44 (slot-machine), because a send is missing parameters, then // those parameters are taken from uninitialized stack and afterwards they are copied back into temps // if we don't remove the segment, we would get false-positive uninitialized reads later - if (type == VAR_TEMP && value.getSegment() == 0xffff) + if (type == VAR_TEMP && value.getSegment() == kUninitializedSegment) value.setSegment(0); s->variables[type][index] = value; @@ -331,7 +331,7 @@ ExecStack *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, StackPt assert(argp[0].toUint16() == argc); // The first argument is argc ExecStack xstack(work_obj, send_obj, curSP, argc, argp, - 0xFFFF, curFP, selector, -1, -1, -1, -1, + kUninitializedSegment, curFP, selector, -1, -1, -1, -1, origin, stackType); if (selectorType == kSelectorVariable) @@ -360,7 +360,7 @@ static void addKernelCallToExecStack(EngineState *s, int kernelCallNr, int kerne // Add stack frame to indicate we're executing a callk. // This is useful in debugger backtraces if this // kernel function calls a script itself. - ExecStack xstack(NULL_REG, NULL_REG, NULL, argc, argv - 1, 0xFFFF, make_reg32(0, 0), + ExecStack xstack(NULL_REG, NULL_REG, NULL, argc, argv - 1, kUninitializedSegment, make_reg32(0, 0), -1, kernelCallNr, kernelSubCallNr, -1, -1, s->_executionStack.size() - 1, EXEC_STACK_TYPE_KERNEL); s->_executionStack.push_back(xstack); } @@ -884,7 +884,7 @@ void run_vm(EngineState *s) { // We shouldn't initialize temp variables at all // We put special segment 0xFFFF in there, so that uninitialized reads can get detected for (int i = 0; i < opparams[0]; i++) - s->xs->sp[i] = make_reg(0xffff, 0); + s->xs->sp[i] = make_reg(kUninitializedSegment, 0); s->xs->sp += opparams[0]; break; diff --git a/engines/sci/engine/vm.h b/engines/sci/engine/vm.h index 18549e3a0e..dbd4ee13d6 100644 --- a/engines/sci/engine/vm.h +++ b/engines/sci/engine/vm.h @@ -116,7 +116,7 @@ struct ExecStack { fp = sp = sp_; argc = argc_; variables_argp = argp_; - if (localsSegment_ != 0xFFFF) + if (localsSegment_ != kUninitializedSegment) local_segment = localsSegment_; else local_segment = pc_.getSegment(); diff --git a/engines/sci/engine/vm_types.h b/engines/sci/engine/vm_types.h index e60f52e85c..734f4d3101 100644 --- a/engines/sci/engine/vm_types.h +++ b/engines/sci/engine/vm_types.h @@ -30,6 +30,12 @@ namespace Sci { // Segment ID type typedef uint16 SegmentId; +enum { + kUninitializedSegment = 0x1FFF, + kSegmentMask = 0x1FFF, + kOffsetMask = 0x7FFFF +}; + struct reg_t { // Segment and offset. These should never be accessed directly SegmentId _segment; @@ -61,14 +67,14 @@ struct reg_t { } bool isPointer() const { - return getSegment() != 0 && getSegment() != 0xFFFF; + return getSegment() != 0 && getSegment() != kUninitializedSegment; } uint16 requireUint16() const; int16 requireSint16() const; inline bool isInitialized() const { - return getSegment() != 0xFFFF; + return getSegment() != kUninitializedSegment; } // Comparison operators @@ -173,7 +179,7 @@ static inline reg_t make_reg(SegmentId segment, uint16 offset) { return r; } -#define PRINT_REG(r) (0xffff) & (unsigned) (r).getSegment(), (unsigned) (r).getOffset() +#define PRINT_REG(r) (kSegmentMask) & (unsigned) (r).getSegment(), (unsigned) (r).getOffset() // A true 32-bit reg_t struct reg32_t { |