From 393d89f8c4200d9a53d1f288b377cceed10e181e Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Mon, 7 Nov 2022 20:03:04 +0300 Subject: [PATCH] Add some Sfall opcodes See #200 --- CMakeLists.txt | 2 + src/interpreter_extra.cc | 4 ++ src/sfall_opcodes.cc | 97 ++++++++++++++++++++++++++++++++++++++++ src/sfall_opcodes.h | 11 +++++ 4 files changed, 114 insertions(+) create mode 100644 src/sfall_opcodes.cc create mode 100644 src/sfall_opcodes.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 3db0b41..8267917 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -269,6 +269,8 @@ target_sources(${EXECUTABLE_NAME} PUBLIC "src/settings.h" "src/sfall_config.cc" "src/sfall_config.h" + "src/sfall_opcodes.cc" + "src/sfall_opcodes.h" ) if(IOS) diff --git a/src/interpreter_extra.cc b/src/interpreter_extra.cc index 312ca56..da59779 100644 --- a/src/interpreter_extra.cc +++ b/src/interpreter_extra.cc @@ -36,6 +36,7 @@ #include "reaction.h" #include "scripts.h" #include "settings.h" +#include "sfall_opcodes.h" #include "skill.h" #include "stat.h" #include "svga.h" @@ -4834,6 +4835,7 @@ static void opGetPcStat(Program* program) // 0x45CDD4 void _intExtraClose_() { + sfallOpcodesExit(); } // 0x45CDD8 @@ -5020,6 +5022,8 @@ void _initIntExtra() interpreterRegisterOpcode(0x8153, opTerminateCombat); // op_terminate_combat interpreterRegisterOpcode(0x8154, opDebugMessage); // op_debug_msg interpreterRegisterOpcode(0x8155, opCritterStopAttacking); // op_critter_stop_attacking + + sfallOpcodesInit(); } // NOTE: Uncollapsed 0x45D878. diff --git a/src/sfall_opcodes.cc b/src/sfall_opcodes.cc new file mode 100644 index 0000000..8cf5954 --- /dev/null +++ b/src/sfall_opcodes.cc @@ -0,0 +1,97 @@ +#include "sfall_opcodes.h" + +#include "art.h" +#include "interface.h" +#include "interpreter.h" +#include "mouse.h" +#include "svga.h" + +namespace fallout { + +// active_hand +static void opGetCurrentHand(Program* program) +{ + programStackPushInteger(program, interfaceGetCurrentHand()); +} + +// get_mouse_x +static void opGetMouseX(Program* program) +{ + int x; + int y; + mouseGetPosition(&x, &y); + programStackPushInteger(program, x); +} + +// get_mouse_y +static void opGetMouseY(Program* program) +{ + int x; + int y; + mouseGetPosition(&x, &y); + programStackPushInteger(program, y); +} + +// get_screen_width +static void opGetScreenWidth(Program* program) +{ + programStackPushInteger(program, screenGetWidth()); +} + +// get_screen_height +static void opGetScreenHeight(Program* program) +{ + programStackPushInteger(program, screenGetHeight()); +} + +// atoi +static void opParseInt(Program* program) +{ + const char* string = programStackPopString(program); + programStackPushInteger(program, static_cast(strtol(string, nullptr, 0))); +} + +// strlen +static void opGetStringLength(Program* program) +{ + const char* string = programStackPopString(program); + programStackPushInteger(program, static_cast(strlen(string))); +} + +// round +static void opRound(Program* program) +{ + float floatValue = programStackPopFloat(program); + int integerValue = static_cast(floatValue); + float mod = floatValue - static_cast(integerValue); + if (abs(mod) >= 0.5) { + integerValue += mod > 0.0 ? 1 : -1; + } + programStackPushInteger(program, integerValue); +} + +// art_exists +static void opArtExists(Program* program) +{ + int fid = programStackPopInteger(program); + programStackPushInteger(program, artExists(fid)); +} + +void sfallOpcodesInit() +{ + interpreterRegisterOpcode(0x8193, opGetCurrentHand); + interpreterRegisterOpcode(0x821C, opGetMouseX); + interpreterRegisterOpcode(0x821D, opGetMouseY); + interpreterRegisterOpcode(0x8220, opGetScreenWidth); + interpreterRegisterOpcode(0x8221, opGetScreenHeight); + interpreterRegisterOpcode(0x8237, opParseInt); + interpreterRegisterOpcode(0x824F, opGetStringLength); + interpreterRegisterOpcode(0x8267, opRound); + interpreterRegisterOpcode(0x8274, opArtExists); +} + +void sfallOpcodesExit() +{ +} + +} // namespace fallout diff --git a/src/sfall_opcodes.h b/src/sfall_opcodes.h new file mode 100644 index 0000000..1173a55 --- /dev/null +++ b/src/sfall_opcodes.h @@ -0,0 +1,11 @@ +#ifndef FALLOUT_SFALL_OPCODES_H_ +#define FALLOUT_SFALL_OPCODES_H_ + +namespace fallout { + +void sfallOpcodesInit(); +void sfallOpcodesExit(); + +} // namespace fallout + +#endif /* FALLOUT_SFALL_OPCODES_H_ */