annotate nuklear_ui/debug_ui.c @ 2697:d1a79e4ba26a default tip

Fix regression in oscilloscope and composition debug views
author Michael Pavone <pavone@retrodev.com>
date Fri, 20 Jun 2025 10:01:17 -0700
parents 25fc676e3521
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2693
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #include <limits.h>
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2 #include <string.h>
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
3 #include <stdlib.h>
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
4
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
5 #include "blastem_nuklear.h"
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
6 #include "../blastem.h"
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
7 #include "../genesis.h"
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
8 #include "../sms.h"
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
9 #include "../coleco.h"
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
10
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
11 typedef struct {
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
12 struct nk_context *context;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
13 uint32_t tex_width;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
14 uint32_t tex_height;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
15 uint8_t win_idx;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
16 } debug_window;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
17
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
18 static debug_window windows[NUM_DEBUG_TYPES];
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
19
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
20 static void debug_handle_event(uint8_t which, SDL_Event *event)
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
21 {
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
22 for (int i = 0; i < NUM_DEBUG_TYPES; i++)
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
23 {
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
24 if (windows[i].win_idx == which) {
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
25 nk_sdl_handle_event(windows[i].context, event);
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
26 break;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
27 }
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
28 }
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
29 }
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
30
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
31 #ifndef DISABLE_OPENGL
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
32 vdp_context *get_vdp(void)
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
33 {
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
34 if (!current_system) {
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
35 return NULL;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
36 }
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
37 switch (current_system->type)
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
38 {
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
39 case SYSTEM_GENESIS:
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
40 case SYSTEM_SEGACD:
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
41 case SYSTEM_PICO:
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
42 case SYSTEM_COPERA:
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
43 return ((genesis_context *)current_system)->vdp;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
44 case SYSTEM_SMS:
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
45 case SYSTEM_GAME_GEAR:
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
46 case SYSTEM_SG1000:
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
47 case SYSTEM_SC3000:
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
48 return ((sms_context *)current_system)->vdp;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
49 case SYSTEM_COLECOVISION:
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
50 return ((coleco_context *)current_system)->vdp;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
51 default:
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
52 return NULL;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
53 }
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
54 }
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
55
2696
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
56 static void plane_debug_ui(void)
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
57 {
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
58 vdp_context *vdp = get_vdp();
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
59 if (!vdp) {
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
60 return;
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
61 }
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
62 struct nk_context *context = windows[DEBUG_PLANE].context;
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
63 nk_input_end(context);
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
64 struct nk_image main_image = nk_image_id((int)render_get_window_texture(windows[DEBUG_PLANE].win_idx));
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
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)) {
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
66 nk_layout_space_begin(context, NK_STATIC, windows[DEBUG_PLANE].tex_height, INT_MAX);
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
67 nk_layout_space_push(context, nk_rect(100, 0, windows[DEBUG_PLANE].tex_width, windows[DEBUG_PLANE].tex_height));
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
68 nk_image(context, main_image);
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
69 struct nk_rect bounds = nk_layout_widget_bounds(context);
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
70 bounds.x += 100;
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
71 bounds.w -= 100;
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
72 char buf[64];
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
73 if (nk_input_is_mouse_hovering_rect(&context->input, bounds)) {
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
74 //TODO: display plane position
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
75 int x = context->input.mouse.pos.x - bounds.x;
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
76 int y = context->input.mouse.pos.y - bounds.y;
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
77 switch (vdp->debug_modes[DEBUG_PLANE])
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
78 {
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
79 case 0:
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
80 case 1:
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
81 y &= 0xFF | (vdp->regs[REG_SCROLL] & 0x30) << 4;
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
82 switch(vdp->regs[REG_SCROLL] & 0x3)
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
83 {
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
84 case 0:
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
85 x &= 0xFF;
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
86 break;
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
87 case 0x1:
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
88 x &= 0x1FF;
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
89 break;
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
90 case 0x2:
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
91 x &= 0xFF;
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
92 break;
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
93 case 0x3:
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
94 x &= 0x3FF;
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
95 break;
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
96 }
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
97 break;
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
98 case 2:
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
99 y &= 0xFF;
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
100 if (vdp->regs[REG_MODE_4] & BIT_H40) {
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
101 x &= 0x1FF;
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
102 } else {
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
103 x &= 0xFF;
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
104 }
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
105 break;
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
106 case 3:
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
107 x >>= 1;
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
108 y >>= 1;
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
109 x -= 128;
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
110 y -= 128;
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
111 break;
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
112 }
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
113 nk_layout_space_push(context, nk_rect(0, windows[DEBUG_PLANE].tex_height - 52, 100, 32));
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
114 snprintf(buf, sizeof(buf), "X: %d", x);
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
115 nk_label(context, buf, NK_TEXT_LEFT);
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
116 nk_layout_space_push(context, nk_rect(0, windows[DEBUG_PLANE].tex_height - 32, 100, 32));
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
117 snprintf(buf, sizeof(buf), "Y: %d", y);
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
118 nk_label(context, buf, NK_TEXT_LEFT);
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
119 }
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
120 static const char* names[] = {
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
121 "Plane A",
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
122 "Plane B",
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
123 "Window",
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
124 "Sprites"
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
125 };
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
126 for (int i = 0; i < 4; i++)
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
127 {
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
128 nk_layout_space_push(context, nk_rect(0, i * 32, 100, 32));
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
129 int selected = i == vdp->debug_modes[DEBUG_PLANE];
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
130 nk_selectable_label(context, names[i], NK_TEXT_ALIGN_LEFT, &selected);
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
131 if (selected) {
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
132 vdp->debug_modes[DEBUG_PLANE] = i;
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
133 }
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
134 }
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
135 nk_end(context);
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
136 }
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
137 nk_sdl_render(context, NK_ANTI_ALIASING_ON, 512 * 1024, 128 * 1024);
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
138 nk_input_begin(context);
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
139 }
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
140
2693
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
141 void write_cram_internal(vdp_context * context, uint16_t addr, uint16_t value);
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
142 static void cram_debug_ui(void)
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
143 {
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
144 vdp_context *vdp = get_vdp();
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
145 if (!vdp) {
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
146 return;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
147 }
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
148 struct nk_context *context = windows[DEBUG_CRAM].context;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
149 nk_input_end(context);
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
150 char buf[64];
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
151
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
152 struct nk_image main_image = nk_image_id((int)render_get_window_texture(windows[DEBUG_CRAM].win_idx));
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
153 if (nk_begin(context, "CRAM Debug", nk_rect(0, 0, windows[DEBUG_CRAM].tex_width + 100 + 8, windows[DEBUG_CRAM].tex_height + 8), NK_WINDOW_NO_SCROLLBAR)) {
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
154 nk_layout_space_begin(context, NK_STATIC, windows[DEBUG_CRAM].tex_height, INT_MAX);
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
155 nk_layout_space_push(context, nk_rect(100, 0, windows[DEBUG_CRAM].tex_width, windows[DEBUG_CRAM].tex_height));
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
156 nk_image(context, main_image);
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
157 struct nk_rect bounds = nk_layout_widget_bounds(context);
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
158 bounds.x += 100;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
159 bounds.w -= 100;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
160 bounds.h = (vdp->flags2 & FLAG2_REGION_PAL) ? 313 : 262;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
161 if (nk_input_is_mouse_hovering_rect(&context->input, bounds)) {
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
162 int off_y = context->input.mouse.pos.y - bounds.y;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
163 int off_x = context->input.mouse.pos.x - bounds.x;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
164 pixel_t pix = vdp->debug_fbs[DEBUG_CRAM][off_y * vdp->debug_fb_pitch[DEBUG_CRAM] / sizeof(pixel_t) + off_x];
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
165 #ifdef USE_GLES
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
166 pixel_t b = pix >> 20 & 0xE, g = pix >> 12 & 0xE, r = pix >> 4 & 0xE;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
167 #else
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
168 pixel_t r = pix >> 20 & 0xE, g = pix >> 12 & 0xE, b = pix >> 4 & 0xE;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
169 #endif
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
170 pix = b << 8 | g << 4 | r;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
171 snprintf(buf, sizeof(buf), "Line: %d, Index: %d, Value: %03X", off_y- vdp->border_top, off_x >> 3, pix & 0xFFFFFF);
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
172 nk_layout_space_push(context, nk_rect(100, 512 - 32*5, windows[DEBUG_CRAM].tex_width, 32));
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
173 nk_label(context, buf, NK_TEXT_LEFT);
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
174 }
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
175 bounds.y += 512-32*4;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
176 bounds.h = 32*4;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
177 if (nk_input_is_mouse_hovering_rect(&context->input, bounds)) {
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
178 int index = ((((int)(context->input.mouse.pos.y - bounds.y)) >> 1) & 0xF0) + (((int)(context->input.mouse.pos.x - bounds.x)) >> 5);
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
179 snprintf(buf, sizeof(buf), "Index: %2d, Value: %03X", index, vdp->cram[index]);
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
180 nk_layout_space_push(context, nk_rect(100, 512 - 32*5, windows[DEBUG_CRAM].tex_width, 32));
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
181 nk_label(context, buf, NK_TEXT_LEFT);
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
182 }
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
183
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
184 static struct nk_scroll scroll;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
185 context->style.window.scrollbar_size.y = 0;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
186 nk_layout_space_push(context, nk_rect(0, 0, 100, windows[DEBUG_CRAM].tex_height));
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
187 if (nk_group_scrolled_begin(context, &scroll, "Entries", 0)) {
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
188 nk_layout_space_begin(context, NK_STATIC, windows[DEBUG_CRAM].tex_height * 4, INT_MAX);
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
189 for (int i = 0; i < 64; i++)
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
190 {
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
191 nk_layout_space_push(context, nk_rect(0, i *32, 25, 32));
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
192 snprintf(buf, sizeof(buf), "%d", i);
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
193 nk_label(context, buf, NK_TEXT_RIGHT);
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
194 nk_layout_space_push(context, nk_rect(30, i *32, 50, 32));
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
195 snprintf(buf, sizeof(buf), "%03X", vdp->cram[i] & 0xEEE);
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
196 nk_edit_string_zero_terminated(context, NK_EDIT_FIELD, buf, sizeof(buf), nk_filter_hex);
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
197 char *end;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
198 long newv = strtol(buf, &end, 16);
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
199 if (end != buf && newv != vdp->cram[i]) {
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
200 write_cram_internal(vdp, i, newv & 0xEEE);
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
201 }
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
202 }
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
203 nk_layout_space_end(context);
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
204 nk_group_scrolled_end(context);
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
205 }
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
206
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
207 nk_end(context);
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
208 }
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
209 nk_sdl_render(context, NK_ANTI_ALIASING_ON, 512 * 1024, 128 * 1024);
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
210
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
211 nk_input_begin(context);
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
212 }
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
213 #endif
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
214
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
215 uint8_t debug_create_window(uint8_t debug_type, char *caption, uint32_t width, uint32_t height, window_close_handler close_handler)
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
216 {
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
217 #ifndef DISABLE_OPENGL
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
218 if (!render_has_gl()) {
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
219 #endif
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
220 return render_create_window(caption, width, height, close_handler);
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
221 #ifndef DISABLE_OPENGL
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
222 }
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
223 uint32_t win_width = width, win_height = height;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
224 ui_render_fun render = NULL;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
225 switch (debug_type)
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
226 {
2696
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
227 case DEBUG_PLANE:
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
228 win_width += 100;
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
229 render = plane_debug_ui;
25fc676e3521 WIP plane debugger UI
Michael Pavone <pavone@retrodev.com>
parents: 2693
diff changeset
230 break;
2693
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
231 case DEBUG_CRAM:
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
232 win_width += 100;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
233 render = cram_debug_ui;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
234 break;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
235 }
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
236 if (render) {
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
237 //compensate for padding
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
238 win_width += 4 * 2;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
239 win_height += 4 * 2;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
240 windows[debug_type].win_idx = render_create_window_tex(caption, win_width, win_height, width, height, close_handler);
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
241 windows[debug_type].tex_width = width;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
242 windows[debug_type].tex_height = width;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
243 windows[debug_type].context = shared_nuklear_init(windows[debug_type].win_idx);
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
244 render_set_ui_render_fun(windows[debug_type].win_idx, render);
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
245 render_set_event_handler(windows[debug_type].win_idx, debug_handle_event);
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
246 return windows[debug_type].win_idx;
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
247 } else {
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
248 return render_create_window(caption, width, height, close_handler);
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
249 }
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
250 #endif
46dba737b931 WIP Nuklear UI in VDP debug windows
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
251 }