Skip to content

Commit

Permalink
z80: add mcycle and tstate to tracelog (default hidden)
Browse files Browse the repository at this point in the history
  • Loading branch information
floooh committed Dec 9, 2024
1 parent 27269e2 commit 5e8aa8c
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 35 deletions.
2 changes: 2 additions & 0 deletions src/sim.c
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,8 @@ static void sim_init_nodegroups(void) {
sim_add_nodegroup("ALU_Out", RANGE(nodegroup_aluout));
sim_add_nodegroup("DBus", RANGE(nodegroup_dbus));
sim_add_nodegroup("DLatch", RANGE(nodegroup_dlatch));
sim_add_nodegroup("MCycle", RANGE(nodegroup_m));
sim_add_nodegroup("TState", RANGE(nodegroup_t));
#elif defined(CHIP_2A03)
sim_add_nodegroup("Addr", RANGE(nodegroup_ab));
sim_add_nodegroup("Data", RANGE(nodegroup_db));
Expand Down
23 changes: 23 additions & 0 deletions src/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,29 @@ uint8_t trace_z80_get_z(uint32_t index) {
return read_nodes(index, 8, nodegroup_reg_z);
}

uint8_t trace_z80_get_mcycle(uint32_t index) {
switch (read_nodes(index, 5, nodegroup_m)) {
case (1<<0): return 1;
case (1<<1): return 2;
case (1<<2): return 3;
case (1<<3): return 4;
case (1<<4): return 5;
default: return 0xFF;
}
}

uint8_t trace_z80_get_tstate(uint32_t index) {
switch (read_nodes(index, 6, nodegroup_t)) {
case (1<<0): return 1;
case (1<<1): return 2;
case (1<<2): return 3;
case (1<<3): return 4;
case (1<<4): return 5;
case (1<<5): return 6;
default: return 0xFF;
}
}

uint16_t trace_z80_get_af(uint32_t index) {
return (trace_z80_get_a(index)<<8) | trace_z80_get_f(index);
}
Expand Down
2 changes: 2 additions & 0 deletions src/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ uint8_t trace_z80_get_i(uint32_t index);
uint8_t trace_z80_get_r(uint32_t index);
uint8_t trace_z80_get_w(uint32_t index);
uint8_t trace_z80_get_z(uint32_t index);
uint8_t trace_z80_get_mcycle(uint32_t index);
uint8_t trace_z80_get_tstate(uint32_t index);
uint16_t trace_z80_get_af(uint32_t index);
uint16_t trace_z80_get_af2(uint32_t index);
uint16_t trace_z80_get_bc(uint32_t index);
Expand Down
72 changes: 38 additions & 34 deletions src/ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ static const ui_tracelog_column_t ui_tracelog_columns[UI_TRACELOG_NUM_COLUMNS] =
{ "Asm", ImGuiTableColumnFlags_NoClip, 8 },
};
#elif defined(CHIP_Z80)
#define UI_TRACELOG_NUM_COLUMNS (34)
#define UI_TRACELOG_NUM_COLUMNS (36)
static const ui_tracelog_column_t ui_tracelog_columns[UI_TRACELOG_NUM_COLUMNS] = {
{ "Cycle/h", ImGuiTableColumnFlags_None, 7 },
{ "M", ImGuiTableColumnFlags_DefaultHide, 2 },
{ "T", ImGuiTableColumnFlags_DefaultHide, 2 },
{ "M1", ImGuiTableColumnFlags_NoClip, 2 },
{ "MREQ", ImGuiTableColumnFlags_NoClip, 4 },
{ "IORQ", ImGuiTableColumnFlags_NoClip, 4 },
Expand Down Expand Up @@ -1324,45 +1326,47 @@ static int ui_tracelog_print_item(int trace_index, int col_index, char* buf, siz
char f_buf[9];
switch (col_index) {
case 0: return snprintf(buf, buf_size, "%5d/%d", cur_cycle >> 1, cur_cycle & 1);
case 1: return snprintf(buf, buf_size, "%s", trace_z80_get_m1(trace_index)?"":"M1");
case 2: return snprintf(buf, buf_size, "%s", trace_z80_get_mreq(trace_index)?"":"MREQ");
case 3: return snprintf(buf, buf_size, "%s", trace_z80_get_ioreq(trace_index)?"":"IORQ");
case 4: return snprintf(buf, buf_size, "%s", trace_z80_get_rfsh(trace_index)?"":"RFSH");
case 5: return snprintf(buf, buf_size, "%s", trace_z80_get_rd(trace_index)?"":"RD");
case 6: return snprintf(buf, buf_size, "%s", trace_z80_get_wr(trace_index)?"":"WR");
case 7: return snprintf(buf, buf_size, "%s", trace_z80_get_int(trace_index)?"":"INT");
case 8: return snprintf(buf, buf_size, "%s", trace_z80_get_nmi(trace_index)?"":"NMI");
case 9: return snprintf(buf, buf_size, "%s", trace_z80_get_wait(trace_index)?"":"WAIT");
case 10: return snprintf(buf, buf_size, "%s", trace_z80_get_halt(trace_index)?"":"HALT");
case 11: return snprintf(buf, buf_size, "%04X", trace_get_addr(trace_index));
case 12: return snprintf(buf, buf_size, "%02X", trace_get_data(trace_index));
case 13: return snprintf(buf, buf_size, "%04X", trace_get_pc(trace_index));
case 14: return snprintf(buf, buf_size, "%02X", trace_z80_get_op(trace_index));
case 15: return snprintf(buf, buf_size, "%04X", trace_z80_get_af(trace_index));
case 16: return snprintf(buf, buf_size, "%04X", trace_z80_get_bc(trace_index));
case 17: return snprintf(buf, buf_size, "%04X", trace_z80_get_de(trace_index));
case 18: return snprintf(buf, buf_size, "%04X", trace_z80_get_hl(trace_index));
case 19: return snprintf(buf, buf_size, "%04X", trace_z80_get_af2(trace_index));
case 20: return snprintf(buf, buf_size, "%04X", trace_z80_get_bc2(trace_index));
case 21: return snprintf(buf, buf_size, "%04X", trace_z80_get_de2(trace_index));
case 22: return snprintf(buf, buf_size, "%04X", trace_z80_get_hl2(trace_index));
case 23: return snprintf(buf, buf_size, "%04X", trace_z80_get_ix(trace_index));
case 24: return snprintf(buf, buf_size, "%04X", trace_z80_get_iy(trace_index));
case 25: return snprintf(buf, buf_size, "%04X", trace_z80_get_sp(trace_index));
case 26: return snprintf(buf, buf_size, "%04X", trace_z80_get_wz(trace_index));
case 27: return snprintf(buf, buf_size, "%02X", trace_z80_get_i(trace_index));
case 28: return snprintf(buf, buf_size, "%02X", trace_z80_get_r(trace_index));
case 29: return snprintf(buf, buf_size, "%01X", trace_z80_get_im(trace_index));
case 30: return snprintf(buf, buf_size, "%s", trace_z80_get_iff1(trace_index) ? "IFF1":" ");
case 31:
case 1: return snprintf(buf, buf_size, "%d", trace_z80_get_mcycle(trace_index));
case 2: return snprintf(buf, buf_size, "%d", trace_z80_get_tstate(trace_index));
case 3: return snprintf(buf, buf_size, "%s", trace_z80_get_m1(trace_index)?"":"M1");
case 4: return snprintf(buf, buf_size, "%s", trace_z80_get_mreq(trace_index)?"":"MREQ");
case 5: return snprintf(buf, buf_size, "%s", trace_z80_get_ioreq(trace_index)?"":"IORQ");
case 6: return snprintf(buf, buf_size, "%s", trace_z80_get_rfsh(trace_index)?"":"RFSH");
case 7: return snprintf(buf, buf_size, "%s", trace_z80_get_rd(trace_index)?"":"RD");
case 8: return snprintf(buf, buf_size, "%s", trace_z80_get_wr(trace_index)?"":"WR");
case 9: return snprintf(buf, buf_size, "%s", trace_z80_get_int(trace_index)?"":"INT");
case 10: return snprintf(buf, buf_size, "%s", trace_z80_get_nmi(trace_index)?"":"NMI");
case 11: return snprintf(buf, buf_size, "%s", trace_z80_get_wait(trace_index)?"":"WAIT");
case 12: return snprintf(buf, buf_size, "%s", trace_z80_get_halt(trace_index)?"":"HALT");
case 13: return snprintf(buf, buf_size, "%04X", trace_get_addr(trace_index));
case 14: return snprintf(buf, buf_size, "%02X", trace_get_data(trace_index));
case 15: return snprintf(buf, buf_size, "%04X", trace_get_pc(trace_index));
case 16: return snprintf(buf, buf_size, "%02X", trace_z80_get_op(trace_index));
case 17: return snprintf(buf, buf_size, "%04X", trace_z80_get_af(trace_index));
case 18: return snprintf(buf, buf_size, "%04X", trace_z80_get_bc(trace_index));
case 19: return snprintf(buf, buf_size, "%04X", trace_z80_get_de(trace_index));
case 20: return snprintf(buf, buf_size, "%04X", trace_z80_get_hl(trace_index));
case 21: return snprintf(buf, buf_size, "%04X", trace_z80_get_af2(trace_index));
case 22: return snprintf(buf, buf_size, "%04X", trace_z80_get_bc2(trace_index));
case 23: return snprintf(buf, buf_size, "%04X", trace_z80_get_de2(trace_index));
case 24: return snprintf(buf, buf_size, "%04X", trace_z80_get_hl2(trace_index));
case 25: return snprintf(buf, buf_size, "%04X", trace_z80_get_ix(trace_index));
case 26: return snprintf(buf, buf_size, "%04X", trace_z80_get_iy(trace_index));
case 27: return snprintf(buf, buf_size, "%04X", trace_z80_get_sp(trace_index));
case 28: return snprintf(buf, buf_size, "%04X", trace_z80_get_wz(trace_index));
case 29: return snprintf(buf, buf_size, "%02X", trace_z80_get_i(trace_index));
case 30: return snprintf(buf, buf_size, "%02X", trace_z80_get_r(trace_index));
case 31: return snprintf(buf, buf_size, "%01X", trace_z80_get_im(trace_index));
case 32: return snprintf(buf, buf_size, "%s", trace_z80_get_iff1(trace_index) ? "IFF1":" ");
case 33:
if (ui.trace.watch_node_valid) {
return snprintf(buf, buf_size, "%c", trace_is_node_high(trace_index, ui.trace.watch_node_index) ? '1':'0');
}
else {
return snprintf(buf, buf_size, "%s", "??");
}
case 32: return snprintf(buf, buf_size, "%s", ui_cpu_flags_as_string(trace_get_flags(trace_index), f_buf, sizeof(f_buf)));
case 33: return snprintf(buf, buf_size, "%s", trace_get_disasm(trace_index));
case 34: return snprintf(buf, buf_size, "%s", ui_cpu_flags_as_string(trace_get_flags(trace_index), f_buf, sizeof(f_buf)));
case 35: return snprintf(buf, buf_size, "%s", trace_get_disasm(trace_index));
default: return snprintf(buf, buf_size, "%s", "???");
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/z80/nodegroups.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ static uint32_t nodegroup_alulat[4] = { pz80_alulat0, pz80_alulat1, pz80_alulat2
static uint32_t nodegroup_aluout[4] = { pz80_aluout0, pz80_aluout1, pz80_aluout2, pz80_aluout3 };
static uint32_t nodegroup_dbus[8] = { pz80_dbus0, pz80_dbus1, pz80_dbus2, pz80_dbus3, pz80_dbus4, pz80_dbus5, pz80_dbus6, pz80_dbus7 };
static uint32_t nodegroup_dlatch[8] = { pz80_dlatch0, pz80_dlatch1, pz80_dlatch2, pz80_dlatch3, pz80_dlatch4, pz80_dlatch5, pz80_dlatch6, pz80_dlatch7 };

static uint32_t nodegroup_m[5] = { pz80_m1, pz80_m2, pz80_m3, pz80_m4, pz80_m5 };
static uint32_t nodegroup_t[6] = { pz80_t1, pz80_t2, pz80_t3, pz80_t4, pz80_t5, pz80_t6 };
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif

0 comments on commit 5e8aa8c

Please sign in to comment.