Add some Sfall opcodes

See #200
This commit is contained in:
Alexander Batalov 2022-11-07 20:03:04 +03:00
parent 9c6286f94a
commit 393d89f8c4
4 changed files with 114 additions and 0 deletions

View File

@ -269,6 +269,8 @@ target_sources(${EXECUTABLE_NAME} PUBLIC
"src/settings.h" "src/settings.h"
"src/sfall_config.cc" "src/sfall_config.cc"
"src/sfall_config.h" "src/sfall_config.h"
"src/sfall_opcodes.cc"
"src/sfall_opcodes.h"
) )
if(IOS) if(IOS)

View File

@ -36,6 +36,7 @@
#include "reaction.h" #include "reaction.h"
#include "scripts.h" #include "scripts.h"
#include "settings.h" #include "settings.h"
#include "sfall_opcodes.h"
#include "skill.h" #include "skill.h"
#include "stat.h" #include "stat.h"
#include "svga.h" #include "svga.h"
@ -4834,6 +4835,7 @@ static void opGetPcStat(Program* program)
// 0x45CDD4 // 0x45CDD4
void _intExtraClose_() void _intExtraClose_()
{ {
sfallOpcodesExit();
} }
// 0x45CDD8 // 0x45CDD8
@ -5020,6 +5022,8 @@ void _initIntExtra()
interpreterRegisterOpcode(0x8153, opTerminateCombat); // op_terminate_combat interpreterRegisterOpcode(0x8153, opTerminateCombat); // op_terminate_combat
interpreterRegisterOpcode(0x8154, opDebugMessage); // op_debug_msg interpreterRegisterOpcode(0x8154, opDebugMessage); // op_debug_msg
interpreterRegisterOpcode(0x8155, opCritterStopAttacking); // op_critter_stop_attacking interpreterRegisterOpcode(0x8155, opCritterStopAttacking); // op_critter_stop_attacking
sfallOpcodesInit();
} }
// NOTE: Uncollapsed 0x45D878. // NOTE: Uncollapsed 0x45D878.

97
src/sfall_opcodes.cc Normal file
View File

@ -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<int>(strtol(string, nullptr, 0)));
}
// strlen
static void opGetStringLength(Program* program)
{
const char* string = programStackPopString(program);
programStackPushInteger(program, static_cast<int>(strlen(string)));
}
// round
static void opRound(Program* program)
{
float floatValue = programStackPopFloat(program);
int integerValue = static_cast<int>(floatValue);
float mod = floatValue - static_cast<float>(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

11
src/sfall_opcodes.h Normal file
View File

@ -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_ */