comparison nuklear_ui/debug_ui.c @ 2696:25fc676e3521

WIP plane debugger UI
author Michael Pavone <pavone@retrodev.com>
date Thu, 19 Jun 2025 21:55:54 -0700
parents 46dba737b931
children
comparison
equal deleted inserted replaced
2695:84771c6e31c5 2696:25fc676e3521
49 case SYSTEM_COLECOVISION: 49 case SYSTEM_COLECOVISION:
50 return ((coleco_context *)current_system)->vdp; 50 return ((coleco_context *)current_system)->vdp;
51 default: 51 default:
52 return NULL; 52 return NULL;
53 } 53 }
54 }
55
56 static void plane_debug_ui(void)
57 {
58 vdp_context *vdp = get_vdp();
59 if (!vdp) {
60 return;
61 }
62 struct nk_context *context = windows[DEBUG_PLANE].context;
63 nk_input_end(context);
64 struct nk_image main_image = nk_image_id((int)render_get_window_texture(windows[DEBUG_PLANE].win_idx));
65 if (nk_begin(context, "Plane Debug", nk_rect(0, 0, windows[DEBUG_PLANE].tex_width + 100 + 8, windows[DEBUG_PLANE].tex_height + 8), NK_WINDOW_NO_SCROLLBAR)) {
66 nk_layout_space_begin(context, NK_STATIC, windows[DEBUG_PLANE].tex_height, INT_MAX);
67 nk_layout_space_push(context, nk_rect(100, 0, windows[DEBUG_PLANE].tex_width, windows[DEBUG_PLANE].tex_height));
68 nk_image(context, main_image);
69 struct nk_rect bounds = nk_layout_widget_bounds(context);
70 bounds.x += 100;
71 bounds.w -= 100;
72 char buf[64];
73 if (nk_input_is_mouse_hovering_rect(&context->input, bounds)) {
74 //TODO: display plane position
75 int x = context->input.mouse.pos.x - bounds.x;
76 int y = context->input.mouse.pos.y - bounds.y;
77 switch (vdp->debug_modes[DEBUG_PLANE])
78 {
79 case 0:
80 case 1:
81 y &= 0xFF | (vdp->regs[REG_SCROLL] & 0x30) << 4;
82 switch(vdp->regs[REG_SCROLL] & 0x3)
83 {
84 case 0:
85 x &= 0xFF;
86 break;
87 case 0x1:
88 x &= 0x1FF;
89 break;
90 case 0x2:
91 x &= 0xFF;
92 break;
93 case 0x3:
94 x &= 0x3FF;
95 break;
96 }
97 break;
98 case 2:
99 y &= 0xFF;
100 if (vdp->regs[REG_MODE_4] & BIT_H40) {
101 x &= 0x1FF;
102 } else {
103 x &= 0xFF;
104 }
105 break;
106 case 3:
107 x >>= 1;
108 y >>= 1;
109 x -= 128;
110 y -= 128;
111 break;
112 }
113 nk_layout_space_push(context, nk_rect(0, windows[DEBUG_PLANE].tex_height - 52, 100, 32));
114 snprintf(buf, sizeof(buf), "X: %d", x);
115 nk_label(context, buf, NK_TEXT_LEFT);
116 nk_layout_space_push(context, nk_rect(0, windows[DEBUG_PLANE].tex_height - 32, 100, 32));
117 snprintf(buf, sizeof(buf), "Y: %d", y);
118 nk_label(context, buf, NK_TEXT_LEFT);
119 }
120 static const char* names[] = {
121 "Plane A",
122 "Plane B",
123 "Window",
124 "Sprites"
125 };
126 for (int i = 0; i < 4; i++)
127 {
128 nk_layout_space_push(context, nk_rect(0, i * 32, 100, 32));
129 int selected = i == vdp->debug_modes[DEBUG_PLANE];
130 nk_selectable_label(context, names[i], NK_TEXT_ALIGN_LEFT, &selected);
131 if (selected) {
132 vdp->debug_modes[DEBUG_PLANE] = i;
133 }
134 }
135 nk_end(context);
136 }
137 nk_sdl_render(context, NK_ANTI_ALIASING_ON, 512 * 1024, 128 * 1024);
138 nk_input_begin(context);
54 } 139 }
55 140
56 void write_cram_internal(vdp_context * context, uint16_t addr, uint16_t value); 141 void write_cram_internal(vdp_context * context, uint16_t addr, uint16_t value);
57 static void cram_debug_ui(void) 142 static void cram_debug_ui(void)
58 { 143 {
137 } 222 }
138 uint32_t win_width = width, win_height = height; 223 uint32_t win_width = width, win_height = height;
139 ui_render_fun render = NULL; 224 ui_render_fun render = NULL;
140 switch (debug_type) 225 switch (debug_type)
141 { 226 {
227 case DEBUG_PLANE:
228 win_width += 100;
229 render = plane_debug_ui;
230 break;
142 case DEBUG_CRAM: 231 case DEBUG_CRAM:
143 win_width += 100; 232 win_width += 100;
144 render = cram_debug_ui; 233 render = cram_debug_ui;
145 break; 234 break;
146 } 235 }