worked on the first module

This commit is contained in:
douwe
2025-08-30 18:05:40 +02:00
parent 4e77198656
commit 75770bb7ff
7 changed files with 8 additions and 4 deletions

View File

@@ -24,6 +24,7 @@ namespace CoborVM
godot::String set_registers(int size, godot::PackedInt32Array preloaded_values); godot::String set_registers(int size, godot::PackedInt32Array preloaded_values);
godot::PackedInt32Array get_registers(); godot::PackedInt32Array get_registers();
int get_program_counter(); int get_program_counter();
int get_program_size();
godot::String run_step(); godot::String run_step();
godot::String run_all(); godot::String run_all();

View File

@@ -8,6 +8,7 @@ void CoborVM::CoborVirtualMachine::_bind_methods()
godot::ClassDB::bind_method(godot::D_METHOD("set_registers", "size", "preloaded_values"), &CoborVirtualMachine::set_registers); godot::ClassDB::bind_method(godot::D_METHOD("set_registers", "size", "preloaded_values"), &CoborVirtualMachine::set_registers);
godot::ClassDB::bind_method(godot::D_METHOD("get_registers"), &CoborVirtualMachine::get_registers); godot::ClassDB::bind_method(godot::D_METHOD("get_registers"), &CoborVirtualMachine::get_registers);
godot::ClassDB::bind_method(godot::D_METHOD("get_program_counter"), &CoborVirtualMachine::get_program_counter); godot::ClassDB::bind_method(godot::D_METHOD("get_program_counter"), &CoborVirtualMachine::get_program_counter);
godot::ClassDB::bind_method(godot::D_METHOD("get_program_size"), &CoborVirtualMachine::get_program_size);
godot::ClassDB::bind_method(godot::D_METHOD("run_step"), &CoborVirtualMachine::run_step); godot::ClassDB::bind_method(godot::D_METHOD("run_step"), &CoborVirtualMachine::run_step);
godot::ClassDB::bind_method(godot::D_METHOD("run_all"), &CoborVirtualMachine::run_all); godot::ClassDB::bind_method(godot::D_METHOD("run_all"), &CoborVirtualMachine::run_all);
} }
@@ -59,13 +60,10 @@ godot::String CoborVM::CoborVirtualMachine::set_registers(int size, godot::Packe
if (size <= 0) if (size <= 0)
return godot::String("Size must be one or higher"); return godot::String("Size must be one or higher");
register_memory = std::vector<int32_t>(size); register_memory = std::vector<int32_t>(size);
int i = 0; preloaded_values.resize(size);
for (int value : preloaded_values) for (int value : preloaded_values)
{ {
if (i >= size)
break;
register_memory[i] = value; register_memory[i] = value;
i++;
} }
return godot::String(); return godot::String();
} }
@@ -85,6 +83,11 @@ int CoborVM::CoborVirtualMachine::get_program_counter()
return register_memory[0]; return register_memory[0];
} }
int CoborVM::CoborVirtualMachine::get_program_size()
{
return program.size();
}
godot::String CoborVM::CoborVirtualMachine::run_step() godot::String CoborVM::CoborVirtualMachine::run_step()
{ {
if (program.empty()) if (program.empty())