1
1
#include " sfall_opcodes.h"
2
2
3
+ #include < math.h>
3
4
#include < string.h>
4
5
5
6
#include " animation.h"
@@ -328,6 +329,73 @@ static void op_abs(Program* program)
328
329
}
329
330
}
330
331
332
+ // sin
333
+ static void op_sin (Program* program)
334
+ {
335
+ ProgramValue programValue = programStackPopValue (program);
336
+ programStackPushFloat (program, sinf (programValue.asFloat ()));
337
+ }
338
+
339
+ // cos
340
+ static void op_cos (Program* program)
341
+ {
342
+ ProgramValue programValue = programStackPopValue (program);
343
+ programStackPushFloat (program, cosf (programValue.asFloat ()));
344
+ }
345
+
346
+ // tan
347
+ static void op_tan (Program* program)
348
+ {
349
+ ProgramValue programValue = programStackPopValue (program);
350
+ programStackPushFloat (program, tanf (programValue.asFloat ()));
351
+ }
352
+
353
+ // arctan
354
+ static void op_arctan (Program* program)
355
+ {
356
+ ProgramValue xValue = programStackPopValue (program);
357
+ ProgramValue yValue = programStackPopValue (program);
358
+ programStackPushFloat (program, atan2f (yValue.asFloat (), xValue.asFloat ()));
359
+ }
360
+
361
+ // pow (^)
362
+ static void op_power (Program* program)
363
+ {
364
+ ProgramValue expValue = programStackPopValue (program);
365
+ ProgramValue baseValue = programStackPopValue (program);
366
+
367
+ // CE: Implementation is slightly different, check.
368
+ float result = powf (baseValue.asFloat (), expValue.asFloat ());
369
+
370
+ if (baseValue.isInt () && expValue.isInt ()) {
371
+ // Note: this will truncate the result if power is negative. Keeping it to match sfall.
372
+ programStackPushInteger (program, static_cast <int >(result));
373
+ } else {
374
+ programStackPushFloat (program, result);
375
+ }
376
+ }
377
+
378
+ // log
379
+ static void op_log (Program* program)
380
+ {
381
+ ProgramValue programValue = programStackPopValue (program);
382
+ programStackPushFloat (program, logf (programValue.asFloat ()));
383
+ }
384
+
385
+ // ceil
386
+ static void op_ceil (Program* program)
387
+ {
388
+ ProgramValue programValue = programStackPopValue (program);
389
+ programStackPushInteger (program, static_cast <int >(ceilf (programValue.asFloat ())));
390
+ }
391
+
392
+ // exp
393
+ static void op_exponent (Program* program)
394
+ {
395
+ ProgramValue programValue = programStackPopValue (program);
396
+ programStackPushFloat (program, expf (programValue.asFloat ()));
397
+ }
398
+
331
399
// get_script
332
400
static void op_get_script (Program* program)
333
401
{
@@ -774,22 +842,6 @@ static void op_explosions_metarule(Program* program)
774
842
}
775
843
}
776
844
777
- // pow (^)
778
- static void op_power (Program* program)
779
- {
780
- ProgramValue expValue = programStackPopValue (program);
781
- ProgramValue baseValue = programStackPopValue (program);
782
-
783
- // CE: Implementation is slightly different, check.
784
- float result = powf (baseValue.asFloat (), expValue.asFloat ());
785
-
786
- if (baseValue.isInt () && expValue.isInt ()) {
787
- programStackPushInteger (program, static_cast <int >(result));
788
- } else {
789
- programStackPushFloat (program, result);
790
- }
791
- }
792
-
793
845
// message_str_game
794
846
static void op_get_message (Program* program)
795
847
{
@@ -942,13 +994,8 @@ static void op_type_of(Program* program)
942
994
// round
943
995
static void op_round (Program* program)
944
996
{
945
- float floatValue = programStackPopFloat (program);
946
- int integerValue = static_cast <int >(floatValue);
947
- float mod = floatValue - static_cast <float >(integerValue);
948
- if (abs (mod) >= 0.5 ) {
949
- integerValue += mod > 0.0 ? 1 : -1 ;
950
- }
951
- programStackPushInteger (program, integerValue);
997
+ float floatValue = programStackPopValue (program).asFloat ();
998
+ programStackPushInteger (program, lroundf (floatValue));
952
999
}
953
1000
954
1001
enum BlockType {
@@ -1138,7 +1185,7 @@ void sfallOpcodesInit()
1138
1185
interpreterRegisterOpcode (0x819B , op_set_global_script_type);
1139
1186
interpreterRegisterOpcode (0x819D , op_set_sfall_global);
1140
1187
interpreterRegisterOpcode (0x819E , op_get_sfall_global_int);
1141
- // missing: get_sfall_global_float, skill_max, eax, npc_level, viewport, mod
1188
+ // missing: get_sfall_global_float, skill_max, eax (deprecated) , npc_level, viewport, mod
1142
1189
interpreterRegisterOpcode (0x81AC , op_get_ini_setting);
1143
1190
// missing: get_shader_version, get_shader_mode
1144
1191
interpreterRegisterOpcode (0x81AF , op_get_game_mode);
@@ -1159,7 +1206,10 @@ void sfallOpcodesInit()
1159
1206
interpreterRegisterOpcode (0x81EB , op_get_ini_string);
1160
1207
interpreterRegisterOpcode (0x81EC , op_sqrt);
1161
1208
interpreterRegisterOpcode (0x81ED , op_abs);
1162
- // missing: sin, cos, tan, atan
1209
+ interpreterRegisterOpcode (0x81EE , op_sin);
1210
+ interpreterRegisterOpcode (0x81EF , op_cos);
1211
+ interpreterRegisterOpcode (0x81F0 , op_tan);
1212
+ interpreterRegisterOpcode (0x81F1 , op_arctan);
1163
1213
// missing: set_palette
1164
1214
// missing: remove_script, set_script
1165
1215
interpreterRegisterOpcode (0x81F5 , op_get_script);
@@ -1219,9 +1269,10 @@ void sfallOpcodesInit()
1219
1269
// missing: <reserved>x2, reg_anim_*
1220
1270
interpreterRegisterOpcode (0x8261 , op_explosions_metarule);
1221
1271
// missing: register_hook_proc
1222
- // missing: log
1223
1272
interpreterRegisterOpcode (0x8263 , op_power);
1224
- // missing: ceil
1273
+ interpreterRegisterOpcode (0x8264 , op_log);
1274
+ interpreterRegisterOpcode (0x8265 , op_exponent);
1275
+ interpreterRegisterOpcode (0x8266 , op_ceil);
1225
1276
interpreterRegisterOpcode (0x8267 , op_round);
1226
1277
// 3 reserved opcodes
1227
1278
interpreterRegisterOpcode (0x826B , op_get_message);
0 commit comments