Skip to content

Commit 0d4b935

Browse files
committed
show chispet run_mode
1 parent b45fbd3 commit 0d4b935

File tree

4 files changed

+65
-8
lines changed

4 files changed

+65
-8
lines changed

emulator/lua-common.lua

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,33 @@ local break_targets = {}
5757

5858
local posttickfns = {}
5959

60+
function run_mode(rm)
61+
if rm == nil then
62+
if emu:run_mode() == 0 then
63+
print("RM_STOP(0)")
64+
end
65+
if emu:run_mode() == 1 then
66+
print("RM_HALT(1)")
67+
end
68+
if emu:run_mode() == 2 then
69+
print("RM_RUN(2)")
70+
end
71+
return
72+
end
73+
if rm == 'RM_STOP' then
74+
rm = 0
75+
end
76+
if rm == 'RM_HALT' then
77+
rm = 1
78+
end
79+
if rm == 'RM_RUN' then
80+
rm = 2
81+
end
82+
if type(rm) == 'number' then
83+
emu:run_mode(rm)
84+
end
85+
end
86+
6087
function addposttick(fn)
6188
if type(fn) ~= 'function' then
6289
print('Argument is not a function')

emulator/src/Chipset/Chipset.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@ namespace casioemu {
2626
INT_COUNT = 128
2727
};
2828

29-
enum RunMode {
30-
RM_STOP,
31-
RM_HALT,
32-
RM_RUN
33-
};
34-
RunMode run_mode;
35-
3629
std::forward_list<Peripheral *> peripherals;
3730

3831
/**
@@ -54,6 +47,13 @@ namespace casioemu {
5447
static const uint16_t interrupt_bitfield_mask = (1 << managed_interrupt_amount) - 1;
5548

5649
public:
50+
enum RunMode {
51+
RM_STOP,
52+
RM_HALT,
53+
RM_RUN
54+
};
55+
RunMode run_mode;
56+
5757
Chipset(Emulator &emulator);
5858
void Setup(); // must be called after emulator.hardware_id is initialized
5959
~Chipset();

emulator/src/Emulator.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,28 @@ namespace casioemu {
200200
});
201201
lua_setfield(lua_state, -2, "set_paused");
202202

203+
lua_pushcfunction(lua_state, [](lua_State *lua_state) {
204+
Emulator *emu = *(Emulator **)lua_topointer(lua_state, 1);
205+
switch (lua_gettop(lua_state)) {
206+
case 1: {
207+
int run_mode = emu->chipset.run_mode;
208+
lua_pushinteger(lua_state, run_mode);
209+
return 1;
210+
}
211+
case 2: {
212+
// RM_STOP, RM_HALT, RM_RUN
213+
int run_mode = lua_tointeger(lua_state, 2);
214+
if (Chipset::RM_STOP <= run_mode && run_mode <= Chipset::RM_RUN) {
215+
emu->chipset.run_mode = (Chipset::RunMode)run_mode;
216+
}
217+
return 0;
218+
}
219+
default:
220+
return 0;
221+
}
222+
});
223+
lua_setfield(lua_state, -2, "run_mode");
224+
203225
lua_model_ref = LUA_REFNIL;
204226
lua_pushcfunction(lua_state, [](lua_State *lua_state) {
205227
Emulator *emu = *(Emulator **)lua_topointer(lua_state, 1);

emulator/src/Gui/Watcher.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ void Watcher::DrawWindow() {
1313
casioemu::Chipset &chipset = emu->chipset;
1414
casioemu::CPU &cpu = chipset.cpu;
1515
std::string s = cpu.GetBacktrace();
16+
std::string run_mode;
17+
if (chipset.run_mode == casioemu::Chipset::RM_STOP) {
18+
run_mode = "RM_STOP";
19+
} else if (chipset.run_mode == casioemu::Chipset::RM_HALT) {
20+
run_mode = "RM_HALT";
21+
} else { // RM_RUN
22+
run_mode = "RM_RUN";
23+
}
1624
ImGui::InputTextMultiline("##as", (char *)s.c_str(), s.size(), ImVec2(ImGui::GetWindowWidth(), 0), ImGuiInputTextFlags_ReadOnly);
1725
ImGui::EndChild();
1826
ImGui::Text("Registers");
@@ -21,7 +29,7 @@ void Watcher::DrawWindow() {
2129
ImGui::Text("r4 %02X | r5 %02X | r6 %02X | r7 %02X | EPSW1 %02X | ELR1 %01X:%04X", cpu.reg_r[ 4] & 0xff, cpu.reg_r[ 5] & 0xff, cpu.reg_r[ 6] & 0xff, cpu.reg_r[ 7] & 0xff, cpu.reg_epsw[1] & 0xff, cpu.reg_ecsr[1] & 0xf, cpu.reg_elr[1] & 0xffff);
2230
ImGui::Text("r8 %02X | r9 %02X | r10 %02X | r11 %02X | EPSW2 %02X | ELR2 %01X:%04X", cpu.reg_r[ 8] & 0xff, cpu.reg_r[ 9] & 0xff, cpu.reg_r[10] & 0xff, cpu.reg_r[11] & 0xff, cpu.reg_epsw[2] & 0xff, cpu.reg_ecsr[2] & 0xf, cpu.reg_elr[2] & 0xffff);
2331
ImGui::Text("r12 %02X | r13 %02X | r14 %02X | r15 %02X | EPSW3 %02X | ELR3 %01X:%04X", cpu.reg_r[12] & 0xff, cpu.reg_r[13] & 0xff, cpu.reg_r[14] & 0xff, cpu.reg_r[15] & 0xff, cpu.reg_epsw[3] & 0xff, cpu.reg_ecsr[3] & 0xf, cpu.reg_elr[3] & 0xffff);
24-
ImGui::Text("SP %04X, EA %04X, ELVL %01X, PC %01X:%04X", cpu.reg_sp & 0xffff, cpu.reg_ea & 0xffff, cpu.reg_psw & 3, cpu.reg_csr & 0xf, cpu.reg_pc & 0xffff);
32+
ImGui::Text("SP %04X, EA %04X, ELVL %01X, PC %01X:%04X, %s", cpu.reg_sp & 0xffff, cpu.reg_ea & 0xffff, cpu.reg_psw & 3, cpu.reg_csr & 0xf, cpu.reg_pc & 0xffff, run_mode.c_str());
2533
ImGui::EndChild();
2634
ImGui::End();
2735
}

0 commit comments

Comments
 (0)