Create a define for the special "signal" offset used throughout the engine, and fixed the arbitrary 0 values from commit #44294, set when some math functions do invalid calculations

svn-id: r44359
This commit is contained in:
Filippos Karapetis 2009-09-25 16:15:57 +00:00
parent 2fe6b32968
commit 180b3f1247
9 changed files with 33 additions and 29 deletions

View File

@ -2750,7 +2750,7 @@ bool Console::cmdStopSfx(int argc, const char **argv) {
if (id.segment) {
_vm->_gamestate->_sound.sfx_song_set_status(handle, SOUND_STATUS_STOPPED);
_vm->_gamestate->_sound.sfx_remove_song(handle);
PUT_SEL32V(id, signal, -1);
PUT_SEL32V(id, signal, SIGNAL_OFFSET);
PUT_SEL32V(id, nodePtr, 0);
PUT_SEL32V(id, handle, 0);
}

View File

@ -144,7 +144,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, -1);
s->r_acc = make_reg(0, SIGNAL_OFFSET);
return;
}

View File

@ -873,7 +873,7 @@ reg_t kIsItSkip(EngineState *s, int, int argc, reg_t *argv) {
if (!res) {
warning("[GFX] Attempt to get cel parameters for invalid view %d", view);
return make_reg(0, -1);
return make_reg(0, SIGNAL_OFFSET);
}
pxm = res->loops[loop].cels[cel];

View File

@ -129,8 +129,8 @@ reg_t kCosDiv(EngineState *s, int, int argc, reg_t *argv) {
double cosval = cos(angle * PI / 180.0);
if ((cosval < 0.0001) && (cosval > -0.0001)) {
warning("Attempted division by zero");
return make_reg(0, 0);
warning("kCosDiv: Attempted division by zero");
return make_reg(0, SIGNAL_OFFSET);
} else
return make_reg(0, (int16)(value / cosval));
}
@ -141,8 +141,8 @@ reg_t kSinDiv(EngineState *s, int, int argc, reg_t *argv) {
double sinval = sin(angle * PI / 180.0);
if ((sinval < 0.0001) && (sinval > -0.0001)) {
warning("Attempted division by zero");
return make_reg(0, 0);
warning("kSinDiv: Attempted division by zero");
return make_reg(0, SIGNAL_OFFSET);
} else
return make_reg(0, (int16)(value / sinval));
}
@ -153,8 +153,8 @@ reg_t kTimesTan(EngineState *s, int, int argc, reg_t *argv) {
param -= 90;
if ((param % 90) == 0) {
warning("Attempted tan(pi/2)");
return make_reg(0, 0);
warning("kTimesTan: Attempted tan(pi/2)");
return make_reg(0, SIGNAL_OFFSET);
} else
return make_reg(0, (int16) - (tan(param * PI / 180.0) * scale));
}
@ -164,8 +164,8 @@ reg_t kTimesCot(EngineState *s, int, int argc, reg_t *argv) {
int scale = (argc > 1) ? argv[1].toSint16() : 1;
if ((param % 90) == 0) {
warning("Attempted tan(pi/2)");
return make_reg(0, 0);
warning("kTimesCot: Attempted tan(pi/2)");
return make_reg(0, SIGNAL_OFFSET);
} else
return make_reg(0, (int16)(tan(param * PI / 180.0) * scale));
}

View File

@ -60,7 +60,7 @@ reg_t kGameIsRestarting(EngineState *s, int, int argc, reg_t *argv) {
}
reg_t kHaveMouse(EngineState *s, int, int argc, reg_t *argv) {
return make_reg(0, -1);
return make_reg(0, SIGNAL_OFFSET);
}
enum kMemoryInfoFunc {

View File

@ -401,7 +401,7 @@ reg_t kDoAvoider(EngineState *s, int, int argc, reg_t *argv) {
int dx, dy;
int destx, desty;
s->r_acc = make_reg(0, -1);
s->r_acc = make_reg(0, SIGNAL_OFFSET);
if (!s->segMan->isHeapObject(avoider)) {
warning("DoAvoider() where avoider %04x:%04x is not an object", PRINT_REG(avoider));

View File

@ -184,7 +184,7 @@ void process_sound_events(EngineState *s) { /* Get all sound events, apply their
debugC(2, kDebugLevelSound, "[process-sound] Song %04x:%04x looped (to %d)\n",
PRINT_REG(obj), cue);
/* PUT_SEL32V(obj, loops, GET_SEL32V(obj, loop) - 1);*/
PUT_SEL32V(obj, signal, -1);
PUT_SEL32V(obj, signal, SIGNAL_OFFSET);
break;
case SI_RELATIVE_CUE:
@ -202,7 +202,7 @@ void process_sound_events(EngineState *s) { /* Get all sound events, apply their
case SI_FINISHED:
debugC(2, kDebugLevelSound, "[process-sound] Song %04x:%04x finished\n",
PRINT_REG(obj));
PUT_SEL32V(obj, signal, -1);
PUT_SEL32V(obj, signal, SIGNAL_OFFSET);
PUT_SEL32V(obj, state, _K_SOUND_STATUS_STOPPED);
break;
@ -372,7 +372,7 @@ static reg_t kDoSoundSci0(EngineState *s, int argc, reg_t *argv) {
if (obj.segment) {
s->_sound.sfx_song_set_status(handle, SOUND_STATUS_STOPPED);
PUT_SEL32V(obj, state, SOUND_STATUS_STOPPED);
PUT_SEL32V(obj, signal, -1);
PUT_SEL32V(obj, signal, SIGNAL_OFFSET);
}
break;
@ -560,7 +560,7 @@ static reg_t kDoSoundSci1Early(EngineState *s, int argc, reg_t *argv) {
break;
}
case _K_SCI01_SOUND_STOP_HANDLE : {
PUT_SEL32V(obj, signal, -1);
PUT_SEL32V(obj, signal, SIGNAL_OFFSET);
if (obj.segment) {
s->_sound.sfx_song_set_status(handle, SOUND_STATUS_STOPPED);
}
@ -581,7 +581,7 @@ static reg_t kDoSoundSci1Early(EngineState *s, int argc, reg_t *argv) {
* TODO: Figure out the exact semantics */
/* FIXME: The next couple of lines actually STOP the song right away */
PUT_SEL32V(obj, signal, -1);
PUT_SEL32V(obj, signal, SIGNAL_OFFSET);
if (obj.segment) {
s->_sound.sfx_song_set_status(handle, SOUND_STATUS_STOPPED);
}
@ -622,7 +622,7 @@ static reg_t kDoSoundSci1Early(EngineState *s, int argc, reg_t *argv) {
case SI_FINISHED:
debugC(2, kDebugLevelSound, "--- [FINISHED] %04x:%04x\n", PRINT_REG(obj));
PUT_SEL32V(obj, signal, -1);
PUT_SEL32V(obj, signal, SIGNAL_OFFSET);
break;
case SI_LOOP:
@ -842,7 +842,7 @@ static reg_t kDoSoundSci1Late(EngineState *s, int argc, reg_t *argv) {
warning("Could not open song number %d", number);
// Send a "stop handle" event so that the engine won't wait forever here
s->_sound.sfx_song_set_status(handle, SOUND_STATUS_STOPPED);
PUT_SEL32V(obj, signal, -1);
PUT_SEL32V(obj, signal, SIGNAL_OFFSET);
return s->r_acc;
}
debugC(2, kDebugLevelSound, "Initializing song number %d\n", number);
@ -890,7 +890,7 @@ static reg_t kDoSoundSci1Late(EngineState *s, int argc, reg_t *argv) {
break;
}
case _K_SCI1_SOUND_STOP_HANDLE : {
PUT_SEL32V(obj, signal, -1);
PUT_SEL32V(obj, signal, SIGNAL_OFFSET);
if (obj.segment) {
s->_sound.sfx_song_set_status(handle, SOUND_STATUS_STOPPED);
}
@ -914,13 +914,13 @@ static reg_t kDoSoundSci1Late(EngineState *s, int argc, reg_t *argv) {
/* FIXME: The next couple of lines actually STOP the handle, rather
** than fading it! */
if (argv[5].toUint16()) {
PUT_SEL32V(obj, signal, -1);
PUT_SEL32V(obj, signal, SIGNAL_OFFSET);
PUT_SEL32V(obj, nodePtr, 0);
PUT_SEL32V(obj, handle, 0);
s->_sound.sfx_song_set_status(handle, SOUND_STATUS_STOPPED);
} else {
// FIXME: Support fade-and-continue. For now, send signal right away.
PUT_SEL32V(obj, signal, -1);
PUT_SEL32V(obj, signal, SIGNAL_OFFSET);
}
}
break;
@ -976,7 +976,7 @@ static reg_t kDoSoundSci1Late(EngineState *s, int argc, reg_t *argv) {
break;
case SI_FINISHED:
PUT_SEL32V(obj, signal, -1);
PUT_SEL32V(obj, signal, SIGNAL_OFFSET);
break;
case SI_LOOP:
@ -1106,7 +1106,7 @@ reg_t kDoSync(EngineState *s, int, int argc, reg_t *argv) {
} else {
warning("DoSync: failed to find resource %s", id.toString().c_str());
// Notify the scripts to stop sound sync
PUT_SEL32V(argv[1], syncCue, -1);
PUT_SEL32V(argv[1], syncCue, SIGNAL_OFFSET);
}
break;
}

View File

@ -67,9 +67,13 @@ typedef reg_t *StackPtr;
typedef int Selector;
#define NULL_SELECTOR -1
// Offset sent to indicate an error, or that an operation has finished
// (depending on the case)
#define SIGNAL_OFFSET 0xffff
#define PRINT_STK(v) (unsigned) (v - s->stack_base)
static inline reg_t make_reg(SegmentId segment, int16 offset) {
static inline reg_t make_reg(SegmentId segment, uint16 offset) {
reg_t r;
r.offset = offset;
r.segment = segment;

View File

@ -343,10 +343,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, -1);
return make_reg(0, SIGNAL_OFFSET);
if ((menu_nr >= (int)_menus.size()) || (item_nr >= (int)_menus[menu_nr]._items.size()))
return make_reg(0, -1);
return make_reg(0, SIGNAL_OFFSET);
const MenuItem &item = _menus[menu_nr]._items[item_nr];
@ -368,7 +368,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, -1);
return make_reg(0, SIGNAL_OFFSET);
}
}