2009-02-17 15:02:16 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-27 02:23:40 +00:00
|
|
|
#include "sci/engine/state.h"
|
2009-02-24 05:51:55 +00:00
|
|
|
#include "sci/engine/kernel.h"
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-21 10:23:36 +00:00
|
|
|
namespace Sci {
|
|
|
|
|
- Changed the unimplemented debug SCI kernel functions (InspectObj, ShowSends, ShowObjs, ShowFree, StackUsage and Profiler) to be dummy functions - we have our own debugger, and don't use these functions for debugging
- Removed the function number parameter from all kernel functions, as it's no longer needed, and removed the FAKE_FUNCT_NR hack
- Removed kUnknown() and kStub()
- Dummy/unknown kernel functions are no longer invoked, and a warning is shown instead, with the paremeters passed to them
Note: there is an evil hack used for debugging scripts in invoke_selector(), which probably no longer works now
svn-id: r44461
2009-09-29 14:24:07 +00:00
|
|
|
reg_t kRandom(EngineState *s, int argc, reg_t *argv) {
|
2009-10-19 19:38:42 +00:00
|
|
|
int fromNumber = argv[0].toUint16();
|
|
|
|
int toNumber = argv[1].toUint16();
|
2009-10-20 11:14:04 +00:00
|
|
|
double randomNumber = fromNumber + ((toNumber + 1.0 - fromNumber) * (rand() / (RAND_MAX + 1.0)));
|
|
|
|
return make_reg(0, (int)randomNumber);
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
|
- Changed the unimplemented debug SCI kernel functions (InspectObj, ShowSends, ShowObjs, ShowFree, StackUsage and Profiler) to be dummy functions - we have our own debugger, and don't use these functions for debugging
- Removed the function number parameter from all kernel functions, as it's no longer needed, and removed the FAKE_FUNCT_NR hack
- Removed kUnknown() and kStub()
- Dummy/unknown kernel functions are no longer invoked, and a warning is shown instead, with the paremeters passed to them
Note: there is an evil hack used for debugging scripts in invoke_selector(), which probably no longer works now
svn-id: r44461
2009-09-29 14:24:07 +00:00
|
|
|
reg_t kAbs(EngineState *s, int argc, reg_t *argv) {
|
2009-02-20 16:22:09 +00:00
|
|
|
// This is a hack, but so is the code in Hoyle1 that needs it.
|
2009-02-15 06:10:59 +00:00
|
|
|
if (argv[0].segment)
|
2009-11-02 23:06:30 +00:00
|
|
|
return make_reg(0, 0x3e9); // Yes people, this is an object
|
2009-06-07 15:53:30 +00:00
|
|
|
return make_reg(0, abs(argv[0].toSint16()));
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
|
- Changed the unimplemented debug SCI kernel functions (InspectObj, ShowSends, ShowObjs, ShowFree, StackUsage and Profiler) to be dummy functions - we have our own debugger, and don't use these functions for debugging
- Removed the function number parameter from all kernel functions, as it's no longer needed, and removed the FAKE_FUNCT_NR hack
- Removed kUnknown() and kStub()
- Dummy/unknown kernel functions are no longer invoked, and a warning is shown instead, with the paremeters passed to them
Note: there is an evil hack used for debugging scripts in invoke_selector(), which probably no longer works now
svn-id: r44461
2009-09-29 14:24:07 +00:00
|
|
|
reg_t kSqrt(EngineState *s, int argc, reg_t *argv) {
|
2009-06-07 15:53:30 +00:00
|
|
|
return make_reg(0, (int16) sqrt((float) abs(argv[0].toSint16())));
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
|
- Changed the unimplemented debug SCI kernel functions (InspectObj, ShowSends, ShowObjs, ShowFree, StackUsage and Profiler) to be dummy functions - we have our own debugger, and don't use these functions for debugging
- Removed the function number parameter from all kernel functions, as it's no longer needed, and removed the FAKE_FUNCT_NR hack
- Removed kUnknown() and kStub()
- Dummy/unknown kernel functions are no longer invoked, and a warning is shown instead, with the paremeters passed to them
Note: there is an evil hack used for debugging scripts in invoke_selector(), which probably no longer works now
svn-id: r44461
2009-09-29 14:24:07 +00:00
|
|
|
reg_t kGetAngle(EngineState *s, int argc, reg_t *argv) {
|
2009-02-20 16:22:09 +00:00
|
|
|
// Based on behavior observed with a test program created with
|
|
|
|
// SCI Studio.
|
2009-06-07 15:53:30 +00:00
|
|
|
int x1 = argv[0].toSint16();
|
|
|
|
int y1 = argv[1].toSint16();
|
|
|
|
int x2 = argv[2].toSint16();
|
|
|
|
int y2 = argv[3].toSint16();
|
2009-02-15 06:10:59 +00:00
|
|
|
int xrel = x2 - x1;
|
2009-02-20 16:22:09 +00:00
|
|
|
int yrel = y1 - y2; // y-axis is mirrored.
|
2009-02-15 06:10:59 +00:00
|
|
|
int angle;
|
|
|
|
|
2009-02-20 16:22:09 +00:00
|
|
|
// Move (xrel, yrel) to first quadrant.
|
2009-02-15 06:10:59 +00:00
|
|
|
if (y1 < y2)
|
|
|
|
yrel = -yrel;
|
|
|
|
if (x2 < x1)
|
|
|
|
xrel = -xrel;
|
|
|
|
|
2009-02-20 16:22:09 +00:00
|
|
|
// Compute angle in grads.
|
2009-02-15 06:10:59 +00:00
|
|
|
if (yrel == 0 && xrel == 0)
|
|
|
|
angle = 0;
|
|
|
|
else
|
|
|
|
angle = 100 * xrel / (xrel + yrel);
|
|
|
|
|
2009-02-20 16:22:09 +00:00
|
|
|
// Fix up angle for actual quadrant of (xrel, yrel).
|
2009-02-15 06:10:59 +00:00
|
|
|
if (y1 < y2)
|
|
|
|
angle = 200 - angle;
|
|
|
|
if (x2 < x1)
|
|
|
|
angle = 400 - angle;
|
|
|
|
|
2009-02-20 16:22:09 +00:00
|
|
|
// Convert from grads to degrees by merging grad 0 with grad 1,
|
|
|
|
// grad 10 with grad 11, grad 20 with grad 21, etc. This leads to
|
|
|
|
// "degrees" that equal either one or two grads.
|
2009-02-15 06:10:59 +00:00
|
|
|
angle -= (angle + 9) / 10;
|
|
|
|
|
|
|
|
return make_reg(0, angle);
|
|
|
|
}
|
|
|
|
|
- Changed the unimplemented debug SCI kernel functions (InspectObj, ShowSends, ShowObjs, ShowFree, StackUsage and Profiler) to be dummy functions - we have our own debugger, and don't use these functions for debugging
- Removed the function number parameter from all kernel functions, as it's no longer needed, and removed the FAKE_FUNCT_NR hack
- Removed kUnknown() and kStub()
- Dummy/unknown kernel functions are no longer invoked, and a warning is shown instead, with the paremeters passed to them
Note: there is an evil hack used for debugging scripts in invoke_selector(), which probably no longer works now
svn-id: r44461
2009-09-29 14:24:07 +00:00
|
|
|
reg_t kGetDistance(EngineState *s, int argc, reg_t *argv) {
|
2009-06-07 16:50:34 +00:00
|
|
|
int xdiff = (argc > 3) ? argv[3].toSint16() : 0;
|
|
|
|
int ydiff = (argc > 2) ? argv[2].toSint16() : 0;
|
|
|
|
int angle = (argc > 5) ? argv[5].toSint16() : 0;
|
|
|
|
int xrel = (int)(((float) argv[1].toSint16() - xdiff) / cos(angle * PI / 180.0)); // This works because cos(0)==1
|
|
|
|
int yrel = argv[0].toSint16() - ydiff;
|
2009-02-21 21:16:41 +00:00
|
|
|
return make_reg(0, (int16)sqrt((float) xrel*xrel + yrel*yrel));
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
|
- Changed the unimplemented debug SCI kernel functions (InspectObj, ShowSends, ShowObjs, ShowFree, StackUsage and Profiler) to be dummy functions - we have our own debugger, and don't use these functions for debugging
- Removed the function number parameter from all kernel functions, as it's no longer needed, and removed the FAKE_FUNCT_NR hack
- Removed kUnknown() and kStub()
- Dummy/unknown kernel functions are no longer invoked, and a warning is shown instead, with the paremeters passed to them
Note: there is an evil hack used for debugging scripts in invoke_selector(), which probably no longer works now
svn-id: r44461
2009-09-29 14:24:07 +00:00
|
|
|
reg_t kTimesSin(EngineState *s, int argc, reg_t *argv) {
|
2009-06-07 15:53:30 +00:00
|
|
|
int angle = argv[0].toSint16();
|
|
|
|
int factor = argv[1].toSint16();
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-09-25 13:01:35 +00:00
|
|
|
return make_reg(0, (int)(factor * sin(angle * PI / 180.0)));
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
|
- Changed the unimplemented debug SCI kernel functions (InspectObj, ShowSends, ShowObjs, ShowFree, StackUsage and Profiler) to be dummy functions - we have our own debugger, and don't use these functions for debugging
- Removed the function number parameter from all kernel functions, as it's no longer needed, and removed the FAKE_FUNCT_NR hack
- Removed kUnknown() and kStub()
- Dummy/unknown kernel functions are no longer invoked, and a warning is shown instead, with the paremeters passed to them
Note: there is an evil hack used for debugging scripts in invoke_selector(), which probably no longer works now
svn-id: r44461
2009-09-29 14:24:07 +00:00
|
|
|
reg_t kTimesCos(EngineState *s, int argc, reg_t *argv) {
|
2009-06-07 15:53:30 +00:00
|
|
|
int angle = argv[0].toSint16();
|
|
|
|
int factor = argv[1].toSint16();
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-09-25 13:01:35 +00:00
|
|
|
return make_reg(0, (int)(factor * cos(angle * PI / 180.0)));
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
|
- Changed the unimplemented debug SCI kernel functions (InspectObj, ShowSends, ShowObjs, ShowFree, StackUsage and Profiler) to be dummy functions - we have our own debugger, and don't use these functions for debugging
- Removed the function number parameter from all kernel functions, as it's no longer needed, and removed the FAKE_FUNCT_NR hack
- Removed kUnknown() and kStub()
- Dummy/unknown kernel functions are no longer invoked, and a warning is shown instead, with the paremeters passed to them
Note: there is an evil hack used for debugging scripts in invoke_selector(), which probably no longer works now
svn-id: r44461
2009-09-29 14:24:07 +00:00
|
|
|
reg_t kCosDiv(EngineState *s, int argc, reg_t *argv) {
|
2009-06-07 15:53:30 +00:00
|
|
|
int angle = argv[0].toSint16();
|
|
|
|
int value = argv[1].toSint16();
|
2009-02-15 06:10:59 +00:00
|
|
|
double cosval = cos(angle * PI / 180.0);
|
|
|
|
|
2009-09-24 14:07:02 +00:00
|
|
|
if ((cosval < 0.0001) && (cosval > -0.0001)) {
|
2009-09-25 16:15:57 +00:00
|
|
|
warning("kCosDiv: Attempted division by zero");
|
2009-09-30 23:00:03 +00:00
|
|
|
return SIGNAL_REG;
|
2009-02-15 06:10:59 +00:00
|
|
|
} else
|
2009-02-21 21:16:41 +00:00
|
|
|
return make_reg(0, (int16)(value / cosval));
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
|
- Changed the unimplemented debug SCI kernel functions (InspectObj, ShowSends, ShowObjs, ShowFree, StackUsage and Profiler) to be dummy functions - we have our own debugger, and don't use these functions for debugging
- Removed the function number parameter from all kernel functions, as it's no longer needed, and removed the FAKE_FUNCT_NR hack
- Removed kUnknown() and kStub()
- Dummy/unknown kernel functions are no longer invoked, and a warning is shown instead, with the paremeters passed to them
Note: there is an evil hack used for debugging scripts in invoke_selector(), which probably no longer works now
svn-id: r44461
2009-09-29 14:24:07 +00:00
|
|
|
reg_t kSinDiv(EngineState *s, int argc, reg_t *argv) {
|
2009-06-07 15:53:30 +00:00
|
|
|
int angle = argv[0].toSint16();
|
|
|
|
int value = argv[1].toSint16();
|
2009-02-15 06:10:59 +00:00
|
|
|
double sinval = sin(angle * PI / 180.0);
|
|
|
|
|
2009-09-24 14:07:02 +00:00
|
|
|
if ((sinval < 0.0001) && (sinval > -0.0001)) {
|
2009-09-25 16:15:57 +00:00
|
|
|
warning("kSinDiv: Attempted division by zero");
|
2009-09-30 23:00:03 +00:00
|
|
|
return SIGNAL_REG;
|
2009-02-15 06:10:59 +00:00
|
|
|
} else
|
2009-02-21 21:16:41 +00:00
|
|
|
return make_reg(0, (int16)(value / sinval));
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
|
- Changed the unimplemented debug SCI kernel functions (InspectObj, ShowSends, ShowObjs, ShowFree, StackUsage and Profiler) to be dummy functions - we have our own debugger, and don't use these functions for debugging
- Removed the function number parameter from all kernel functions, as it's no longer needed, and removed the FAKE_FUNCT_NR hack
- Removed kUnknown() and kStub()
- Dummy/unknown kernel functions are no longer invoked, and a warning is shown instead, with the paremeters passed to them
Note: there is an evil hack used for debugging scripts in invoke_selector(), which probably no longer works now
svn-id: r44461
2009-09-29 14:24:07 +00:00
|
|
|
reg_t kTimesTan(EngineState *s, int argc, reg_t *argv) {
|
2009-06-07 15:53:30 +00:00
|
|
|
int param = argv[0].toSint16();
|
2009-06-07 16:50:34 +00:00
|
|
|
int scale = (argc > 1) ? argv[1].toSint16() : 1;
|
2009-02-15 06:10:59 +00:00
|
|
|
|
|
|
|
param -= 90;
|
|
|
|
if ((param % 90) == 0) {
|
2009-09-25 16:15:57 +00:00
|
|
|
warning("kTimesTan: Attempted tan(pi/2)");
|
2009-09-30 23:00:03 +00:00
|
|
|
return SIGNAL_REG;
|
2009-02-15 06:10:59 +00:00
|
|
|
} else
|
2009-02-21 21:16:41 +00:00
|
|
|
return make_reg(0, (int16) - (tan(param * PI / 180.0) * scale));
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
|
- Changed the unimplemented debug SCI kernel functions (InspectObj, ShowSends, ShowObjs, ShowFree, StackUsage and Profiler) to be dummy functions - we have our own debugger, and don't use these functions for debugging
- Removed the function number parameter from all kernel functions, as it's no longer needed, and removed the FAKE_FUNCT_NR hack
- Removed kUnknown() and kStub()
- Dummy/unknown kernel functions are no longer invoked, and a warning is shown instead, with the paremeters passed to them
Note: there is an evil hack used for debugging scripts in invoke_selector(), which probably no longer works now
svn-id: r44461
2009-09-29 14:24:07 +00:00
|
|
|
reg_t kTimesCot(EngineState *s, int argc, reg_t *argv) {
|
2009-06-07 15:53:30 +00:00
|
|
|
int param = argv[0].toSint16();
|
2009-06-07 16:50:34 +00:00
|
|
|
int scale = (argc > 1) ? argv[1].toSint16() : 1;
|
2009-02-15 06:10:59 +00:00
|
|
|
|
|
|
|
if ((param % 90) == 0) {
|
2009-09-25 16:15:57 +00:00
|
|
|
warning("kTimesCot: Attempted tan(pi/2)");
|
2009-09-30 23:00:03 +00:00
|
|
|
return SIGNAL_REG;
|
2009-02-15 06:10:59 +00:00
|
|
|
} else
|
2009-02-21 21:16:41 +00:00
|
|
|
return make_reg(0, (int16)(tan(param * PI / 180.0) * scale));
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
2009-02-21 10:23:36 +00:00
|
|
|
|
|
|
|
} // End of namespace Sci
|