Skip to content

Commit 2b7c8b9

Browse files
committed
integrate sokol debug ui
1 parent 0a879d6 commit 2b7c8b9

File tree

13 files changed

+76
-5
lines changed

13 files changed

+76
-5
lines changed

ui/ui_atom.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ typedef void (*ui_atom_boot_cb)(atom_t* sys);
6969
typedef struct {
7070
atom_t* atom;
7171
ui_atom_boot_cb boot_cb;
72+
ui_inject_t inject;
7273
ui_dbg_texture_callbacks_t dbg_texture; // texture create/update/destroy callbacks
7374
ui_dbg_keys_desc_t dbg_keys; // user-defined hotkeys for ui_dbg_t
7475
ui_snapshot_desc_t snapshot; // snapshot ui setup params
@@ -77,6 +78,7 @@ typedef struct {
7778
typedef struct {
7879
atom_t* atom;
7980
ui_atom_boot_cb boot_cb;
81+
ui_inject_t inject;
8082
ui_m6502_t cpu;
8183
ui_i8255_t ppi;
8284
ui_m6522_t via;
@@ -178,6 +180,9 @@ static void _ui_atom_draw_menu(ui_atom_t* ui) {
178180
}
179181
ImGui::EndMenu();
180182
}
183+
if (ui->inject.menu_cb) {
184+
ui->inject.menu_cb();
185+
}
181186
ui_util_options_menu();
182187
ImGui::EndMainMenuBar();
183188
}
@@ -351,6 +356,7 @@ void ui_atom_init(ui_atom_t* ui, const ui_atom_desc_t* ui_desc) {
351356
ui_snapshot_init(&ui->snapshot, &ui_desc->snapshot);
352357
ui->atom = ui_desc->atom;
353358
ui->boot_cb = ui_desc->boot_cb;
359+
ui->inject = ui_desc->inject;
354360
int x = 20, y = 20, dx = 10, dy = 10;
355361
{
356362
ui_dbg_desc_t desc = {0};

ui/ui_bombjack.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ extern "C" {
6363

6464
typedef struct {
6565
bombjack_t* sys;
66+
ui_inject_t inject;
6667
ui_dbg_texture_callbacks_t dbg_texture; // texture create/update/destroy callbacks
6768
ui_dbg_keys_desc_t dbg_keys; // user-defined hotkeys for ui_dbg_t
6869
ui_snapshot_desc_t snapshot;
@@ -84,6 +85,7 @@ typedef struct {
8485
bombjack_t* bj;
8586
uint8_t sys_clear_mask;
8687
double sys_clear_modified_age;
88+
ui_inject_t inject;
8789
struct {
8890
ui_z80_t cpu;
8991
ui_dbg_t dbg;
@@ -260,6 +262,7 @@ void ui_bombjack_init(ui_bombjack_t* ui, const ui_bombjack_desc_t* ui_desc) {
260262
CHIPS_ASSERT(ui_desc->sys);
261263
memset(ui, 0, sizeof(ui_bombjack_t));
262264
ui->bj = ui_desc->sys;
265+
ui->inject = ui_desc->inject;
263266
ui_snapshot_init(&ui->snapshot, &ui_desc->snapshot);
264267
int x = 20, y = 20, dx = 10, dy = 10;
265268
{
@@ -413,10 +416,10 @@ void ui_bombjack_init(ui_bombjack_t* ui, const ui_bombjack_desc_t* ui_desc) {
413416
ui->video.h = 568;
414417
ui->video.hovered_palette_column = -1;
415418
for (int i = 0; i < 24; i++) {
416-
ui->video.tex_16x16[i] = ui->video.texture_cbs.create_cb(16, 16);
419+
ui->video.tex_16x16[i] = ui->video.texture_cbs.create_cb(16, 16, "sprite-16x16");
417420
}
418421
for (int i = 0; i < 24; i++) {
419-
ui->video.tex_32x32[i] = ui->video.texture_cbs.create_cb(32, 32);
422+
ui->video.tex_32x32[i] = ui->video.texture_cbs.create_cb(32, 32, "sprite-32x32");
420423
}
421424
}
422425
}
@@ -664,6 +667,9 @@ static void _ui_bombjack_draw_menu(ui_bombjack_t* ui) {
664667
}
665668
ImGui::EndMenu();
666669
}
670+
if (ui->inject.menu_cb) {
671+
ui->inject.menu_cb();
672+
}
667673
ui_util_options_menu();
668674
ImGui::EndMainMenuBar();
669675
}

ui/ui_c64.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ typedef void (*ui_c64_boot_cb)(c64_t* sys);
7373
typedef struct {
7474
c64_t* c64; // pointer to c64_t instance to track
7575
ui_c64_boot_cb boot_cb; // reboot callback function
76+
ui_inject_t inject;
7677
ui_dbg_texture_callbacks_t dbg_texture; // texture create/update/destroy callbacks
7778
ui_dbg_debug_callbacks_t dbg_debug;
7879
ui_dbg_keys_desc_t dbg_keys; // user-defined hotkeys for ui_dbg_t
@@ -83,6 +84,7 @@ typedef struct {
8384
c64_t* c64;
8485
int dbg_scanline;
8586
ui_c64_boot_cb boot_cb;
87+
ui_inject_t inject;
8688
ui_m6502_t cpu;
8789
ui_m6502_t c1541_cpu;
8890
ui_m6526_t cia[2];
@@ -212,6 +214,9 @@ static void _ui_c64_draw_menu(ui_c64_t* ui) {
212214
}
213215
ImGui::EndMenu();
214216
}
217+
if (ui->inject.menu_cb) {
218+
ui->inject.menu_cb();
219+
}
215220
ui_util_options_menu();
216221
ImGui::EndMainMenuBar();
217222
}
@@ -554,6 +559,7 @@ void ui_c64_init(ui_c64_t* ui, const ui_c64_desc_t* ui_desc) {
554559
CHIPS_ASSERT(ui_desc->boot_cb);
555560
ui->c64 = ui_desc->c64;
556561
ui->boot_cb = ui_desc->boot_cb;
562+
ui->inject = ui_desc->inject;
557563
ui_snapshot_init(&ui->snapshot, &ui_desc->snapshot);
558564
int x = 20, y = 20, dx = 10, dy = 10;
559565
{

ui/ui_cpc.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ typedef void (*ui_cpc_boot_t)(cpc_t* sys, cpc_type_t type);
7373
typedef struct {
7474
cpc_t* cpc;
7575
ui_cpc_boot_t boot_cb; // user-provided callback to reboot to different config
76+
ui_inject_t inject;
7677
ui_dbg_texture_callbacks_t dbg_texture; // debug texture create/update/destroy callbacks
7778
ui_dbg_debug_callbacks_t dbg_debug; // user-provided debugger callbacks
7879
ui_dbg_keys_desc_t dbg_keys; // user-defined hotkeys for ui_dbg_t
@@ -88,6 +89,7 @@ typedef struct {
8889
int dbg_scanline;
8990
bool dbg_vsync;
9091
ui_cpc_boot_t boot_cb;
92+
ui_inject_t inject;
9193
ui_z80_t cpu;
9294
ui_ay38910_t psg;
9395
ui_mc6845_t vdc;
@@ -197,6 +199,9 @@ static void _ui_cpc_draw_menu(ui_cpc_t* ui) {
197199
}
198200
ImGui::EndMenu();
199201
}
202+
if (ui->inject.menu_cb) {
203+
ui->inject.menu_cb();
204+
}
200205
ui_util_options_menu();
201206
ImGui::EndMainMenuBar();
202207
}
@@ -589,6 +594,7 @@ void ui_cpc_init(ui_cpc_t* ui, const ui_cpc_desc_t* ui_desc) {
589594
CHIPS_ASSERT(ui_desc->boot_cb);
590595
ui->cpc = ui_desc->cpc;
591596
ui->boot_cb = ui_desc->boot_cb;
597+
ui->inject = ui_desc->inject;
592598
ui_snapshot_init(&ui->snapshot, &ui_desc->snapshot);
593599
int x = 20, y = 20, dx = 10, dy = 10;
594600
{

ui/ui_dbg.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ typedef uint8_t (*ui_dbg_read_t)(int layer, uint16_t addr, void* user_data);
142142
/* callback for evaluating uer breakpoints, return breakpoint index, or -1 */
143143
typedef int (*ui_dbg_user_break_t)(struct ui_dbg_t* win, int trap_id, uint64_t pins, void* user_data);
144144
/* a callback to create a dynamic-update RGBA8 UI texture, needs to return an ImTextureID handle */
145-
typedef ui_texture_t (*ui_dbg_create_texture_t)(int w, int h);
145+
typedef ui_texture_t (*ui_dbg_create_texture_t)(int w, int h, const char* label);
146146
/* callback to update a UI texture with new data */
147147
typedef void (*ui_dbg_update_texture_t)(ui_texture_t tex_handle, void* data, int data_byte_size);
148148
/* callback to destroy a UI texture */
@@ -1113,7 +1113,7 @@ static void _ui_dbg_heatmap_init(ui_dbg_t* win) {
11131113
win->heatmap.tex_height = 256;
11141114
win->heatmap.tex_width_uicombo_state = 4;
11151115
win->heatmap.next_tex_width = win->heatmap.tex_width;
1116-
win->heatmap.texture = win->texture_cbs.create_cb(win->heatmap.tex_width, win->heatmap.tex_height);
1116+
win->heatmap.texture = win->texture_cbs.create_cb(win->heatmap.tex_width, win->heatmap.tex_height, "heatmap");
11171117
win->heatmap.show_ops = win->heatmap.show_reads = win->heatmap.show_writes = true;
11181118
win->heatmap.scale = 1;
11191119
win->heatmap.autoclear_interval = 0; /* 0 means: no autoclear */
@@ -1129,7 +1129,7 @@ static void _ui_dbg_heatmap_update_texture_size(ui_dbg_t* win, int new_width) {
11291129
win->heatmap.tex_width = new_width;
11301130
win->heatmap.tex_height = (1<<16) / new_width;
11311131
win->texture_cbs.destroy_cb(win->heatmap.texture);
1132-
win->heatmap.texture = win->texture_cbs.create_cb(win->heatmap.tex_width, win->heatmap.tex_height);
1132+
win->heatmap.texture = win->texture_cbs.create_cb(win->heatmap.tex_width, win->heatmap.tex_height, "heatmap");
11331133
}
11341134
}
11351135

ui/ui_kc85.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ typedef void (*ui_kc85_boot_t)(kc85_t* sys);
8080
typedef struct {
8181
kc85_t* kc85;
8282
ui_kc85_boot_t boot_cb; // user-provided callback to reboot
83+
ui_inject_t inject;
8384
ui_dbg_texture_callbacks_t dbg_texture; // user-provided texture create/update/destroy callbacks
8485
ui_dbg_debug_callbacks_t dbg_debug; // user-provided debugger callbacks
8586
ui_dbg_keys_desc_t dbg_keys; // user-defined hotkeys for ui_dbg_t
@@ -93,6 +94,7 @@ typedef struct {
9394
typedef struct {
9495
kc85_t* kc85;
9596
ui_kc85_boot_t boot_cb;
97+
ui_inject_t inject;
9698
ui_z80_t cpu;
9799
ui_z80pio_t pio;
98100
ui_z80ctc_t ctc;
@@ -180,6 +182,9 @@ static void _ui_kc85_draw_menu(ui_kc85_t* ui) {
180182
ImGui::MenuItem("Scan Commands (TODO)");
181183
ImGui::EndMenu();
182184
}
185+
if (ui->inject.menu_cb) {
186+
ui->inject.menu_cb();
187+
}
183188
ui_util_options_menu();
184189
ImGui::EndMainMenuBar();
185190
}
@@ -378,6 +383,7 @@ void ui_kc85_init(ui_kc85_t* ui, const ui_kc85_desc_t* ui_desc) {
378383
CHIPS_ASSERT(ui_desc->boot_cb);
379384
ui->kc85 = ui_desc->kc85;
380385
ui->boot_cb = ui_desc->boot_cb;
386+
ui->inject = ui_desc->inject;
381387
ui_snapshot_init(&ui->snapshot, &ui_desc->snapshot);
382388
int x = 20, y = 20, dx = 10, dy = 10;
383389
{

ui/ui_lc80.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ typedef void (*ui_lc80_boot_t)(lc80_t* sys);
6565
typedef struct {
6666
lc80_t* sys;
6767
ui_lc80_boot_t boot_cb; // user-provided callback to reboot to different config
68+
ui_inject_t inject;
6869
ui_dbg_texture_callbacks_t dbg_texture; // texture create/update/destroy callback
6970
ui_dbg_keys_desc_t dbg_keys; // user-defined hotkeys for ui_dbg_t
7071
ui_snapshot_desc_t snapshot; // snapshot system creation params
@@ -83,6 +84,7 @@ typedef struct {
8384
void* imgui_font;
8485
lc80_t* sys;
8586
ui_lc80_boot_t boot_cb;
87+
ui_inject_t inject;
8688
struct {
8789
ui_z80_t cpu;
8890
ui_z80pio_t pio_sys;
@@ -748,6 +750,9 @@ static void _ui_lc80_draw_menu(ui_lc80_t* ui) {
748750
}
749751
ImGui::EndMenu();
750752
}
753+
if (ui->inject.menu_cb) {
754+
ui->inject.menu_cb();
755+
}
751756
ui_util_options_menu();
752757
ImGui::EndMainMenuBar();
753758
}
@@ -1168,6 +1173,7 @@ void ui_lc80_init(ui_lc80_t* ui, const ui_lc80_desc_t* ui_desc) {
11681173
CHIPS_ASSERT(ui_desc->boot_cb);
11691174
ui->sys = ui_desc->sys;
11701175
ui->boot_cb = ui_desc->boot_cb;
1176+
ui->inject = ui_desc->inject;
11711177
_ui_lc80_init_windows(ui, ui_desc);
11721178
_ui_lc80_init_motherboard(ui);
11731179
}

ui/ui_namco.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,15 @@ extern "C" {
6565

6666
typedef struct {
6767
namco_t* sys;
68+
ui_inject_t inject;
6869
ui_dbg_texture_callbacks_t dbg_texture; // user-provided texture create/update/destroy callbacks
6970
ui_dbg_keys_desc_t dbg_keys; // user-defined hotkeys for ui_dbg_t
7071
ui_snapshot_desc_t snapshot; // snapshot system creation params
7172
} ui_namco_desc_t;
7273

7374
typedef struct {
7475
namco_t* sys;
76+
ui_inject_t inject;
7577
ui_z80_t cpu;
7678
ui_dbg_t dbg;
7779
ui_audio_t audio;
@@ -210,6 +212,7 @@ void ui_namco_init(ui_namco_t* ui, const ui_namco_desc_t* ui_desc) {
210212
CHIPS_ASSERT(ui_desc->sys);
211213
memset(ui, 0, sizeof(ui_namco_t));
212214
ui->sys = ui_desc->sys;
215+
ui->inject = ui_desc->inject;
213216
ui_snapshot_init(&ui->snapshot, &ui_desc->snapshot);
214217
int x = 20, y = 20, dx = 10, dy = 10;
215218
{
@@ -357,6 +360,9 @@ static void _ui_namco_draw_menu(ui_namco_t* ui) {
357360
}
358361
ImGui::EndMenu();
359362
}
363+
if (ui->inject.menu_cb) {
364+
ui->inject.menu_cb();
365+
}
360366
ui_util_options_menu();
361367
ImGui::EndMainMenuBar();
362368
}

ui/ui_util.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ extern "C" {
5151
// Dear ImGui compatible texture handle
5252
typedef uint64_t ui_texture_t;
5353

54+
// injected callbacks
55+
typedef struct {
56+
void (*menu_cb)(void);
57+
} ui_inject_t;
58+
5459
// draw an 16-bit hex text input field
5560
uint16_t ui_util_input_u16(const char* label, uint16_t val);
5661
// draw an 8-bit hex text input field

ui/ui_vic20.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ typedef void (*ui_vic20_boot_cb)(vic20_t* sys);
7373
typedef struct {
7474
vic20_t* vic20; // pointer to vic20_t instance to track
7575
ui_vic20_boot_cb boot_cb; // reboot callback function
76+
ui_inject_t inject;
7677
ui_dbg_texture_callbacks_t dbg_texture; // user-provided texture create/update/destroy callbacks
7778
ui_dbg_keys_desc_t dbg_keys; // user-defined hotkeys for ui_dbg_t
7879
ui_snapshot_desc_t snapshot; // snapshot ui setup params
@@ -81,6 +82,7 @@ typedef struct {
8182
typedef struct {
8283
vic20_t* vic20;
8384
int dbg_scanline;
85+
ui_inject_t inject;
8486
ui_c1530_t c1530;
8587
ui_vic20_boot_cb boot_cb;
8688
ui_m6502_t cpu;
@@ -195,6 +197,9 @@ static void _ui_vic20_draw_menu(ui_vic20_t* ui) {
195197
}
196198
ImGui::EndMenu();
197199
}
200+
if (ui->inject.menu_cb) {
201+
ui->inject.menu_cb();
202+
}
198203
ui_util_options_menu();
199204
ImGui::EndMainMenuBar();
200205
}
@@ -407,6 +412,7 @@ void ui_vic20_init(ui_vic20_t* ui, const ui_vic20_desc_t* ui_desc) {
407412
ui->vic20 = ui_desc->vic20;
408413
ui->system.title = "VIC-20 System";
409414
ui->boot_cb = ui_desc->boot_cb;
415+
ui->inject = ui_desc->inject;
410416
ui_snapshot_init(&ui->snapshot, &ui_desc->snapshot);
411417
int x = 20, y = 20, dx = 10, dy = 10;
412418
{

0 commit comments

Comments
 (0)