-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathui.cc
2411 lines (2291 loc) · 96.5 KB
/
ui.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//------------------------------------------------------------------------------
// ui.cc
//------------------------------------------------------------------------------
#include "imgui.h"
#include "res/fonts.h"
#include "res/iconsfontawesome4_c.h"
#include "res/markdown.h"
#include "imgui_markdown/imgui_markdown.h"
#include "sokol_app.h"
#include "sokol_gfx.h"
#include "sokol_imgui.h"
#include "sokol_gfx_imgui.h"
#define CHIPS_IMPL
#define CHIPS_UI_IMPL
#if defined(CHIP_6502) || defined(CHIP_2A03)
#define UI_DASM_USE_M6502
#include "chips/m6502dasm.h"
#elif defined(CHIP_Z80)
#define UI_DASM_USE_Z80
#include "chips/z80dasm.h"
#endif
#include "chips/ui_memedit.h"
#include "chips/ui_util.h"
#include "chips/ui_dasm.h"
#include "ui.h"
#include "ui_asm.h"
#include "asm.h"
#include "gfx.h"
#include "sim.h"
#include "pick.h"
#include "trace.h"
#include "util.h"
#include "TextEditor.h"
#include "nodenames.h"
#include <math.h> // sinf, fmodf
#include <string.h> // strncpy
#ifdef _MSC_VER
#pragma warning (disable: 4566) // character represented by universal-character-name '\u...' cannot be represented in the current code page
#endif
enum {
TRACELOG_HOVERED = (1<<0),
TIMINGDIAGRAM_HOVERED = (1<<1),
};
static const ImU32 ui_trace_hovered_color = 0xFF3643F4;
static const ImU32 ui_trace_selected_color = 0xFF0000D5;
static const ImU32 ui_trace_diff_selected_color = 0xFF8843F4;
static const ImU32 ui_trace_bg_colors[4] = { 0xFF327D2E, 0xFF3C8E38, 0xFFC06515, 0xFFD17619 };
static const ImU32 ui_diagram_line_color = 0xFFEEEEEE;
static const ImU32 ui_diagram_text_color = 0xFFFFFFFF;
static const ImU32 ui_diagram_text_bg_color = 0x88000000;
static const ImU32 ui_found_text_color = 0xFF00FF00;
static const ImU32 ui_notfound_text_color = 0xFF4488FF;
#define MAX_NODEEXPLORER_TOKENBUFFER_SIZE (1024)
#define MAX_NODEEXPLORER_HOVERED_NODES (32)
#define MAX_TRACELOG_COLUMNS (64)
typedef struct {
const char* label;
ImGuiTableColumnFlags flags;
int width;
} ui_tracelog_column_t;
#if defined(CHIP_6502)
#define UI_TRACELOG_NUM_COLUMNS (19)
static const ui_tracelog_column_t ui_tracelog_columns[UI_TRACELOG_NUM_COLUMNS] = {
{ "Cycle/h", ImGuiTableColumnFlags_None, 7 },
{ "SYNC", ImGuiTableColumnFlags_NoClip, 4 },
{ "RW", ImGuiTableColumnFlags_NoClip, 2 },
{ "AB", ImGuiTableColumnFlags_NoClip, 4 },
{ "DB", ImGuiTableColumnFlags_NoClip, 2 },
{ "PC", ImGuiTableColumnFlags_NoClip, 4 },
{ "OP", ImGuiTableColumnFlags_NoClip, 2 },
{ "A", ImGuiTableColumnFlags_NoClip, 2 },
{ "X", ImGuiTableColumnFlags_NoClip, 2 },
{ "Y", ImGuiTableColumnFlags_NoClip, 2 },
{ "S", ImGuiTableColumnFlags_NoClip, 2 },
{ "P", ImGuiTableColumnFlags_NoClip, 2 },
{ "Watch", ImGuiTableColumnFlags_NoClip, 5 },
{ "Flags", ImGuiTableColumnFlags_NoClip, 8 },
{ "IRQ", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 3 },
{ "NMI", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 3 },
{ "RES", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 3 },
{ "RDY", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 3 },
{ "Asm", ImGuiTableColumnFlags_NoClip, 8 },
};
#elif defined(CHIP_Z80)
#define UI_TRACELOG_NUM_COLUMNS (34)
static const ui_tracelog_column_t ui_tracelog_columns[UI_TRACELOG_NUM_COLUMNS] = {
{ "Cycle/h", ImGuiTableColumnFlags_None, 7 },
{ "M1", ImGuiTableColumnFlags_NoClip, 2 },
{ "MREQ", ImGuiTableColumnFlags_NoClip, 4 },
{ "IORQ", ImGuiTableColumnFlags_NoClip, 4 },
{ "RFSH", ImGuiTableColumnFlags_NoClip, 4 },
{ "RD", ImGuiTableColumnFlags_NoClip, 2 },
{ "WR", ImGuiTableColumnFlags_NoClip, 2 },
{ "INT", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 3 },
{ "NMI", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 3 },
{ "WAIT", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 4 },
{ "HALT", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 4 },
{ "AB", ImGuiTableColumnFlags_NoClip, 4 },
{ "DB", ImGuiTableColumnFlags_NoClip, 2 },
{ "PC", ImGuiTableColumnFlags_NoClip, 4 },
{ "OP", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 2 },
{ "AF", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 4 },
{ "BC", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 4 },
{ "DE", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 4 },
{ "HL", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 4 },
{ "AF'", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 4 },
{ "BC'", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 4 },
{ "DE'", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 4 },
{ "HL'", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 4 },
{ "IX", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 4 },
{ "IY", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 4 },
{ "SP", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 4 },
{ "WZ", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 4 },
{ "I", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 2 },
{ "R", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 2 },
{ "IM", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 2 },
{ "IFF1", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 4 },
{ "Watch", ImGuiTableColumnFlags_NoClip, 5 },
{ "Flags", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 8 },
{ "Asm", ImGuiTableColumnFlags_NoClip, 12 }
};
#elif defined(CHIP_2A03)
#define UI_TRACELOG_NUM_COLUMNS (24)
static const ui_tracelog_column_t ui_tracelog_columns[UI_TRACELOG_NUM_COLUMNS] = {
{ "Cycle/h", ImGuiTableColumnFlags_None, 7 },
{ "SYNC", ImGuiTableColumnFlags_NoClip, 4 },
{ "RW", ImGuiTableColumnFlags_NoClip, 2 },
{ "AB", ImGuiTableColumnFlags_NoClip, 4 },
{ "DB", ImGuiTableColumnFlags_NoClip, 2 },
{ "PC", ImGuiTableColumnFlags_NoClip, 4 },
{ "OP", ImGuiTableColumnFlags_NoClip, 2 },
{ "A", ImGuiTableColumnFlags_NoClip, 2 },
{ "X", ImGuiTableColumnFlags_NoClip, 2 },
{ "Y", ImGuiTableColumnFlags_NoClip, 2 },
{ "S", ImGuiTableColumnFlags_NoClip, 2 },
{ "P", ImGuiTableColumnFlags_NoClip, 2 },
{ "Watch", ImGuiTableColumnFlags_NoClip, 5 },
{ "Flags", ImGuiTableColumnFlags_NoClip, 8 },
{ "IRQ", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 3 },
{ "NMI", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 3 },
{ "RES", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 3 },
{ "RDY", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 3 },
{ "Asm", ImGuiTableColumnFlags_NoClip, 8 },
{ "Sq0", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 3 },
{ "Sq1", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 3 },
{ "Tri", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 3 },
{ "Noi", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 3 },
{ "Pcm", ImGuiTableColumnFlags_NoClip|ImGuiTableColumnFlags_DefaultHide, 3 },
};
#endif
#define MAX_TRACEDUMP_SIZE ((MAX_TRACE_ITEMS+2) * UI_TRACELOG_NUM_COLUMNS * 16)
static struct {
bool valid;
ui_memedit_t memedit;
ui_memedit_t memedit_integrated;
#if defined(CHIP_Z80)
ui_memedit_t ioedit;
ui_memedit_t ioedit_integrated;
#endif
ui_dasm_t dasm;
struct {
bool cpu_controls;
#if defined(CHIP_2A03)
bool audio_controls;
#endif
bool tracelog;
bool timingdiagram;
bool nodeexplorer;
bool listing;
bool help_asm;
bool help_opcodes;
bool help_about;
} window_open;
struct {
bool open_source_hovered;
bool save_source_hovered;
bool save_binary_hovered;
bool save_listing_hovered;
bool save_tracelog_hovered;
bool cut_hovered;
bool copy_hovered;
} menu;
struct {
int hovered_flags;
bool diff_view_active;
bool is_selected;
bool is_diff_selected;
uint32_t hovered_cycle;
uint32_t selected_cycle;
uint32_t diff_selected_cycle;
bool watch_node_valid;
char watch_str[32];
uint32_t watch_node_index;
bool column_visible[UI_TRACELOG_NUM_COLUMNS];
} trace;
struct {
TextEditor* editor;
bool window_focused;
bool explorer_mode_active;
int num_hovered_nodes;
uint32_t hovered_node_indices[MAX_NODEEXPLORER_HOVERED_NODES];
uint8_t selected[MAX_NODES];
char token_buffer[MAX_NODEEXPLORER_TOKENBUFFER_SIZE];
} explorer;
bool link_hovered;
char link_url[MAX_LINKURL_SIZE];
struct {
int pos;
char buf[MAX_TRACEDUMP_SIZE];
} tracedump;
sgimgui_t sgimgui;
} ui;
static void ui_menu(void);
static void ui_picking(void);
static void ui_tracelog_timingdiagram_begin(void);
static void ui_tracelog(void);
static void ui_timingdiagram(void);
static void ui_tracelog_timingdiagram_end(void);
static void ui_nodeexplorer_init(void);
static void ui_nodeexplorer_discard(void);
static void ui_nodeexplorer_undo(void);
static void ui_nodeexplorer_redo(void);
static void ui_nodeexplorer_cut(void);
static void ui_nodeexplorer_copy(void);
static void ui_nodeexplorer_paste(void);
static void ui_nodeexplorer(void);
static void ui_controls(void);
static void ui_listing(void);
static void ui_help_assembler(void);
static void ui_help_opcodes(void);
static void ui_help_about(void);
static void markdown_link_callback(ImGui::MarkdownLinkCallbackData data);
static ImGui::MarkdownConfig md_conf;
// read and write callback for memory/io editor windows
static uint8_t ui_mem_read(int /*layer*/, uint16_t addr, void* /*user_data*/) {
return sim_mem_r8(addr);
}
static void ui_mem_write(int /*layer*/, uint16_t addr, uint8_t data, void* /*user_data*/) {
sim_mem_w8(addr, data);
}
#if defined(CHIP_Z80)
static uint8_t ui_io_read(int /*layer*/, uint16_t addr, void* /*user_data*/) {
return sim_io_r8(addr);
}
static void ui_io_write(int /*layer*/, uint16_t addr, uint8_t data, void* /*user_data*/) {
sim_io_w8(addr, data);
}
#endif
static const ImVec4 dim(const ImVec4 c, float d) {
return ImVec4(c.x*d, c.y*d, c.z*d, c.w);
}
void ui_init() {
assert(!ui.valid);
// setup sokol-gfx debugging UI
const sgimgui_desc_t sgimgui_desc = {};
sgimgui_init(&ui.sgimgui, &sgimgui_desc);
// default window open state
ui.window_open.cpu_controls = true;
ui.window_open.tracelog = true;
ui_nodeexplorer_init();
// setup sokol-imgui
simgui_desc_t simgui_desc = { };
simgui_desc.no_default_font = true;
simgui_desc.disable_paste_override = true;
simgui_setup(&simgui_desc);
auto& style = ImGui::GetStyle();
style.WindowRounding = 0.0f;
style.WindowBorderSize = 1.0f;
style.Alpha = 1.0f;
style.Colors[ImGuiCol_WindowBg] = ImVec4(0.1f, 0.1f, 0.15f, 1.0f);
style.Colors[ImGuiCol_TitleBg] = style.Colors[ImGuiCol_WindowBg];
style.Colors[ImGuiCol_Border] = dim(style.Colors[ImGuiCol_TitleBgActive], 0.75f);
style.Colors[ImGuiCol_Separator] = style.Colors[ImGuiCol_Border];
style.Colors[ImGuiCol_TableBorderLight] = style.Colors[ImGuiCol_Border];
style.Colors[ImGuiCol_TableBorderStrong] = style.Colors[ImGuiCol_Border];
style.Colors[ImGuiCol_MenuBarBg] = style.Colors[ImGuiCol_WindowBg];
style.Colors[ImGuiCol_ChildBg] = style.Colors[ImGuiCol_WindowBg];
style.Colors[ImGuiCol_PopupBg] = style.Colors[ImGuiCol_WindowBg];
style.Colors[ImGuiCol_ScrollbarBg] = dim(style.Colors[ImGuiCol_WindowBg], 0.85f);
// setup ImGui font with custom icons
auto& io = ImGui::GetIO();
io.Fonts->AddFontDefault();
static const ImWchar icons_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 };
ImFontConfig icons_config;
icons_config.MergeMode = true;
icons_config.PixelSnapH = true;
icons_config.FontDataOwnedByAtlas = false;
io.Fonts->AddFontFromMemoryTTF(dump_fontawesome_ttf,
sizeof(dump_fontawesome_ttf),
16.0f, &icons_config, icons_ranges);
ImFontConfig h1Conf;
h1Conf.SizePixels = 26.0f;
md_conf.headingFormats[0].font = io.Fonts->AddFontDefault(&h1Conf);
unsigned char* font_pixels;
int font_width, font_height;
io.Fonts->GetTexDataAsRGBA32(&font_pixels, &font_width, &font_height);
{
sg_image_desc img_desc = { };
img_desc.width = font_width;
img_desc.height = font_height;
img_desc.pixel_format = SG_PIXELFORMAT_RGBA8;
img_desc.data.subimage[0][0].ptr = font_pixels;
img_desc.data.subimage[0][0].size = font_width * font_height * 4;
img_desc.label = "icon-font";
sg_image img = sg_make_image(&img_desc);
simgui_image_desc_t ui_img_desc = { };
ui_img_desc.image = img;
io.Fonts->TexID = simgui_imtextureid(simgui_make_image(&ui_img_desc));
}
// initialize helper windows from the chips projects
{
ui_memedit_desc_t desc = { };
desc.title = "Memory Editor";
desc.open = false;
desc.num_cols = 8;
desc.h = 300;
desc.x = 50;
desc.y = 50;
desc.hide_ascii = true;
desc.read_cb = ui_mem_read;
desc.write_cb = ui_mem_write;
ui_memedit_init(&ui.memedit, &desc);
desc.title = "Integrated Memory Editor";
desc.hide_options = true;
desc.hide_addr_input = true;
ui_memedit_init(&ui.memedit_integrated, &desc);
}
#if defined(CHIP_Z80)
{
ui_memedit_desc_t desc = { };
desc.title = "IO Editor";
desc.open = false;
desc.num_cols = 8;
desc.h = 300;
desc.x = 60;
desc.y = 60;
desc.hide_ascii = true;
desc.read_cb = ui_io_read;
desc.write_cb = ui_io_write;
ui_memedit_init(&ui.ioedit, &desc);
desc.title = "Integrated IO Editor";
desc.hide_options = true;
desc.hide_addr_input = true;
ui_memedit_init(&ui.ioedit_integrated, &desc);
}
#endif
{
ui_dasm_desc_t desc = { };
desc.title = "Disassembler";
desc.open = false;
#if defined(CHIP_6502) || defined(CHIP_2A03)
desc.cpu_type = UI_DASM_CPUTYPE_M6502;
#elif defined(CHIP_Z80)
desc.cpu_type = UI_DASM_CPUTYPE_Z80;
#endif
desc.start_addr = 0;
desc.read_cb = ui_mem_read;
desc.x = 50;
desc.y = 50;
desc.w = 450;
ui_dasm_init(&ui.dasm, &desc);
}
ui_asm_init();
// setup ImGui::Markdown configuration
md_conf.linkCallback = markdown_link_callback;
md_conf.headingFormats[0].separator = true;
md_conf.headingFormats[0].newline_above = false;
md_conf.headingFormats[0].newline_below = false;
md_conf.headingFormats[1].newline_below = false;
md_conf.linkIcon = ICON_FA_LINK;
ui.valid = true;
}
void ui_shutdown() {
assert(ui.valid);
sgimgui_discard(&ui.sgimgui);
ui_nodeexplorer_discard();
ui_asm_discard();
ui_dasm_discard(&ui.dasm);
ui_memedit_discard(&ui.memedit);
ui_memedit_discard(&ui.memedit_integrated);
#if defined(CHIP_Z80)
ui_memedit_discard(&ui.ioedit);
ui_memedit_discard(&ui.ioedit_integrated);
#endif
simgui_shutdown();
}
static bool test_alt(const sapp_event* ev, sapp_keycode key_code) {
if (ev->type == SAPP_EVENTTYPE_KEY_DOWN) {
if ((ev->modifiers == SAPP_MODIFIER_ALT) && (ev->key_code == key_code)) {
return true;
}
}
return false;
}
static bool test_ctrl(const sapp_event* ev, sapp_keycode key_code) {
if (ev->type == SAPP_EVENTTYPE_KEY_DOWN) {
uint32_t mod = util_is_osx() ? SAPP_MODIFIER_SUPER : SAPP_MODIFIER_CTRL;
if ((ev->modifiers == mod) && (ev->key_code == key_code)) {
return true;
}
}
return false;
}
static bool test_ctrl_shift(const sapp_event* ev, sapp_keycode key_code) {
if (ev->type == SAPP_EVENTTYPE_KEY_DOWN) {
uint32_t mod = SAPP_MODIFIER_SHIFT | (util_is_osx() ? SAPP_MODIFIER_SUPER : SAPP_MODIFIER_CTRL);
if ((ev->modifiers == mod) && (ev->key_code == key_code)) {
return true;
}
}
return false;
}
static bool test_click(const sapp_event* ev, bool hovered) {
if (hovered && (ev->type == SAPP_EVENTTYPE_MOUSE_UP) && (ev->mouse_button == SAPP_MOUSEBUTTON_LEFT)) {
return true;
}
else {
return false;
}
}
static bool handle_special_link(void) {
if (0 == strcmp(ui.link_url, "ui://listing")) {
ui.window_open.listing = true;
ImGui::SetWindowFocus("Listing");
return true;
}
else if (0 == strcmp(ui.link_url, "ui://assembler")) {
ui_asm_set_window_open(true);
ImGui::SetWindowFocus("Assembler");
return true;
}
return false;
}
static void ui_undo(void) {
if (ui_asm_is_window_focused()) {
ui_asm_undo();
}
else if (ui.explorer.window_focused) {
ui_nodeexplorer_undo();
}
}
static void ui_redo(void) {
if (ui_asm_is_window_focused()) {
ui_asm_redo();
}
else if (ui.explorer.window_focused) {
ui_nodeexplorer_redo();
}
}
static void ui_cut(void) {
if (ui_asm_is_window_focused()) {
ui_asm_cut();
}
else if (ui.explorer.window_focused) {
ui_nodeexplorer_cut();
}
}
static void ui_copy(void) {
if (ui_asm_is_window_focused()) {
ui_asm_copy();
}
else if (ui.explorer.window_focused) {
ui_nodeexplorer_copy();
}
}
static void ui_paste(void) {
if (ui_asm_is_window_focused()) {
ui_asm_paste();
}
else if (ui.explorer.window_focused) {
ui_nodeexplorer_paste();
}
}
bool ui_handle_input(const sapp_event* ev) {
assert(ui.valid);
int l = -1;
if (test_click(ev, ui.link_hovered)) {
ui.link_hovered = false;
if (!handle_special_link()) {
util_html5_open_link(ui.link_url);
}
}
if (test_alt(ev, SAPP_KEYCODE_1)) {
l = 0;
}
else if (test_alt(ev, SAPP_KEYCODE_2)) {
l = 1;
}
else if (test_alt(ev, SAPP_KEYCODE_3)) {
l = 2;
}
else if (test_alt(ev, SAPP_KEYCODE_4)) {
l = 3;
}
else if (test_alt(ev, SAPP_KEYCODE_5)) {
l = 4;
}
else if (test_alt(ev, SAPP_KEYCODE_6)) {
l = 5;
}
if (l != -1) {
gfx_toggle_layer_visibility(l);
return true;
}
if (test_alt(ev, SAPP_KEYCODE_C)) {
ui.window_open.cpu_controls = !ui.window_open.cpu_controls;
}
if (test_alt(ev, SAPP_KEYCODE_T)) {
ui.window_open.tracelog = !ui.window_open.tracelog;
}
if (test_alt(ev, SAPP_KEYCODE_A)) {
ui_asm_toggle_window_open();
}
if (test_alt(ev, SAPP_KEYCODE_L)) {
ui.window_open.listing = !ui.window_open.listing;
}
if (test_alt(ev, SAPP_KEYCODE_M)) {
ui.memedit.open = !ui.memedit.open;
}
if (test_alt(ev, SAPP_KEYCODE_D)) {
ui.dasm.open = !ui.dasm.open;
}
if (test_alt(ev, SAPP_KEYCODE_E)) {
ui.window_open.nodeexplorer = !ui.window_open.nodeexplorer;
}
if (test_click(ev, ui.menu.open_source_hovered) || test_ctrl_shift(ev, SAPP_KEYCODE_O)) {
util_html5_load();
ui.menu.open_source_hovered = false;
sapp_consume_event();
}
if (test_click(ev, ui.menu.save_source_hovered) || test_ctrl_shift(ev, SAPP_KEYCODE_S)) {
util_html5_download_string("source.asm", ui_asm_source());
ui.menu.save_source_hovered = false;
sapp_consume_event();
}
if (test_click(ev, ui.menu.save_listing_hovered)) {
util_html5_download_string("listing.lst", asm_listing());
ui.menu.save_listing_hovered = false;
}
if (test_click(ev, ui.menu.save_binary_hovered)) {
util_html5_download_binary("binary.bin", ui_asm_get_binary());
ui.menu.save_binary_hovered = false;
}
if (test_click(ev, ui.menu.save_tracelog_hovered)) {
util_html5_download_string("tracelog.txt", ui_trace_get_dump());
ui.menu.save_tracelog_hovered = false;
}
if (test_ctrl(ev, SAPP_KEYCODE_Z) || test_ctrl(ev, SAPP_KEYCODE_Y)) {
ui_undo();
sapp_consume_event();
}
if (test_ctrl_shift(ev, SAPP_KEYCODE_Z) || test_ctrl_shift(ev, SAPP_KEYCODE_Y)) {
ui_redo();
sapp_consume_event();
}
if (test_click(ev, ui.menu.cut_hovered) || test_ctrl(ev, SAPP_KEYCODE_X)) {
ui_cut();
ui.menu.cut_hovered = false;
sapp_consume_event();
}
if (test_click(ev, ui.menu.copy_hovered) || test_ctrl(ev, SAPP_KEYCODE_C)) {
ui_copy();
ui.menu.copy_hovered = false;
sapp_consume_event();
}
if (ev->type == SAPP_EVENTTYPE_CLIPBOARD_PASTED) {
ui_paste();
}
if (0 != (ev->modifiers & (SAPP_MODIFIER_CTRL|SAPP_MODIFIER_ALT|SAPP_MODIFIER_SUPER))) {
return false;
}
else {
// sokol_imgui.h returns true if either WantsCaptureKeyboard or
// WantsCaptureMouse is set which is too broad in our case,
// we just need to prevent further mouse input handling when
// Dear ImGui wants to capture the mouse
simgui_handle_event(ev);
return ImGui::GetIO().WantCaptureMouse;
}
}
void ui_frame() {
assert(ui.valid);
ui.link_hovered = false;
simgui_new_frame({ sapp_width(), sapp_height(), sapp_frame_duration(), sapp_dpi_scale() });
ui_menu();
ui_picking();
ui_memedit_draw(&ui.memedit);
#if defined(CHIP_Z80)
ui_memedit_draw(&ui.ioedit);
#endif
ui_dasm_draw(&ui.dasm);
ui_tracelog_timingdiagram_begin();
ui_tracelog();
ui_timingdiagram();
ui_tracelog_timingdiagram_end();
ui_nodeexplorer();
ui_controls();
ui_asm_draw();
ui_listing();
ui_help_assembler();
ui_help_opcodes();
ui_help_about();
if (ui.link_hovered) {
sapp_set_mouse_cursor(SAPP_MOUSECURSOR_POINTING_HAND);
}
}
void ui_draw() {
assert(ui.valid);
sgimgui_draw(&ui.sgimgui);
simgui_render();
}
static void ui_menu(void) {
ui.menu.open_source_hovered = false;
ui.menu.save_source_hovered = false;
ui.menu.save_binary_hovered = false;
ui.menu.save_listing_hovered = false;
ui.menu.save_tracelog_hovered = false;
if (ImGui::BeginMainMenuBar()) {
bool is_osx = util_is_osx();
if (ImGui::BeginMenu("File")) {
// this looks all a bit weired because on the web platforms
// these actions must be invoked from within an input handler
ImGui::MenuItem("Open Source...", is_osx?"Cmd+Shift+O":"Ctrl+Shift+O");
ui.menu.open_source_hovered = ImGui::IsItemHovered();
ImGui::MenuItem("Save Source...", is_osx?"Cmd+Shift+S":"Ctrl+Shift+S");
ui.menu.save_source_hovered = ImGui::IsItemHovered();
ImGui::MenuItem("Save .BIN/.PRG...", 0);
ui.menu.save_binary_hovered = ImGui::IsItemHovered();
ImGui::MenuItem("Save Listing...", 0);
ui.menu.save_listing_hovered = ImGui::IsItemHovered();
ImGui::MenuItem("Save Tracelog...", 0);
ui.menu.save_tracelog_hovered = ImGui::IsItemHovered();
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Edit")) {
if (ImGui::MenuItem("Undo", is_osx?"Cmd+Z|Y":"Ctrl+Z|Y")) {
ui_asm_undo();
}
if (ImGui::MenuItem("Redo", is_osx?"Cmd+Shift+Z|Y":"Ctrl+Shift+Z|Y")) {
ui_asm_redo();
}
ImGui::Separator();
ImGui::MenuItem("Cut", is_osx?"Cmd+X":"Ctrl+X");
ui.menu.cut_hovered = ImGui::IsItemHovered();
ImGui::MenuItem("Copy", is_osx?"Cmd+C":"Ctrl+C");
ui.menu.copy_hovered = ImGui::IsItemHovered();
#if defined(__EMSCRIPTEN__)
ImGui::MenuItem("Paste", is_osx?"Cmd+V":"Ctrl+V");
if (ImGui::IsItemHovered()) {
ImGui::SetTooltip("Please use keyboard shortcut or\nbrowser menu for pasting!");
}
#else
if (ImGui::MenuItem("Paste", is_osx?"Cmd+V":"Ctrl+V")) {
ui_asm_paste();
}
#endif
ImGui::EndMenu();
}
if (ImGui::BeginMenu("View")) {
ImGui::MenuItem("Controls", "Alt+C", &ui.window_open.cpu_controls);
#if defined(CHIP_2A03)
ImGui::MenuItem("Audio", nullptr, &ui.window_open.audio_controls);
#endif
ImGui::MenuItem("Node Explorer", "Alt+E", &ui.window_open.nodeexplorer);
ImGui::MenuItem("Trace Log", "Alt+T", &ui.window_open.tracelog);
ImGui::MenuItem("Timing Diagram", nullptr, &ui.window_open.timingdiagram);
ImGui::MenuItem("Listing", "Alt+L", &ui.window_open.listing);
ImGui::MenuItem("Memory Editor", "Alt+M", &ui.memedit.open);
#if defined(CHIP_Z80)
ImGui::MenuItem("IO Editor", nullptr, &ui.ioedit.open);
#endif
ImGui::MenuItem("Disassembler", "Alt+D", &ui.dasm.open);
if (ImGui::MenuItem("Assembler", "Alt+A", ui_asm_is_window_open())) {
ui_asm_toggle_window_open();
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Layers")) {
if (ImGui::BeginMenu("Visible")) {
const char* label[MAX_LAYERS] = {
"Layer #1##V", "Layer #2##V", "Layer #3##V", "Layer #4##V", "Layer #5##V", "Layer #6##V",
};
const char* hotkey[MAX_LAYERS] = {
"Alt+1", "Alt+2", "Alt+3", "Alt+4", "Alt+5", "Alt+6"
};
for (int i = 0; i < MAX_LAYERS; i++) {
if (ImGui::MenuItem(label[i], hotkey[i], gfx_get_layer_visibility(i))) {
gfx_toggle_layer_visibility(i);
}
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Pickable")) {
const char* label[MAX_LAYERS] = {
"Layer #1##P", "Layer #2##P", "Layer #3##P", "Layer #4##P", "Layer #5##P", "Layer #6##P",
};
for (int i = 0; i < MAX_LAYERS; i++) {
if (ImGui::MenuItem(label[i], 0, pick_get_layer_enabled(i))) {
pick_toggle_layer_enabled(i);
}
}
ImGui::EndMenu();
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Theme")) {
if (ImGui::MenuItem("Remix")) {
gfx_set_layer_palette(false, gfx_default_palette);
}
if (ImGui::MenuItem("Original")) {
gfx_set_layer_palette(false, {
{
{ 1.0f, 0.0f, 0.0f, 1.0f },
{ 1.0f, 1.0f, 0.0f, 1.0f },
{ 1.0f, 0.0f, 1.0f, 1.0f },
{ 0.3f, 1.5f, 0.3f, 1.0f },
{ 1.0f, 0.3f, 0.3f, 1.0f },
{ 0.5f, 0.1f, 0.75f, 1.0f },
},
{ 0.0f, 0.0f, 0.0f, 1.0f }
});
}
if (ImGui::MenuItem("Contrast")) {
gfx_set_layer_palette(false, {
{
{ 1.0f, 0.0f, 0.0f, 1.0f },
{ 0.8f, 0.5f, 0.0f, 1.0f },
{ 1.0f, 0.0f, 1.0f, 1.0f },
{ 0.3f, 1.0f, 0.3f, 1.0f },
{ 1.0f, 0.3f, 0.3f, 1.0f },
{ 0.5f, 0.1f, 0.75f, 1.0f },
},
{ 1.0f, 1.0f, 1.0f, 1.0f }
});
}
if (ImGui::MenuItem("Matrix")) {
gfx_set_layer_palette(true, {
{
{ 0.0f, 0.5f, 0.0f, 1.0f },
{ 0.0f, 0.5f, 0.0f, 1.0f },
{ 0.0f, 0.5f, 0.0f, 1.0f },
{ 0.0f, 0.5f, 0.0f, 1.0f },
{ 0.0f, 0.5f, 0.0f, 1.0f },
{ 0.0f, 0.5f, 0.0f, 1.0f },
},
{ 0.0f, 0.0f, 0.0f, 1.0f }
});
}
if (ImGui::MenuItem("X-Ray")) {
gfx_set_layer_palette(true, {
{
{ 0.5f, 0.5f, 0.5f, 1.0f },
{ 0.5f, 0.5f, 0.5f, 1.0f },
{ 0.5f, 0.5f, 0.5f, 1.0f },
{ 0.5f, 0.5f, 0.5f, 1.0f },
{ 0.5f, 0.5f, 0.5f, 1.0f },
{ 0.5f, 0.5f, 0.5f, 1.0f },
},
{ 0.0f, 0.0f, 0.0f, 1.0f }
});
}
ImGui::EndMenu();
}
sgimgui_draw_menu(&ui.sgimgui, "Sokol");
if (ImGui::BeginMenu("Help")) {
ImGui::MenuItem("Assembler", 0, &ui.window_open.help_asm);
ImGui::MenuItem("Opcode Table", 0, &ui.window_open.help_opcodes);
ImGui::MenuItem("About", 0, &ui.window_open.help_about);
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
}
}
#if defined(CHIP_6502) || defined(CHIP_2A03)
static void ui_input_6502_vec(const char* label, const char* id, uint16_t addr) {
ImGui::AlignTextToFramePadding();
ImGui::Text("%s", label); ImGui::SameLine();
sim_mem_w16(addr, ui_util_input_u16(id, sim_mem_r16(addr)));
}
#endif
#if defined(CHIP_Z80)
static void ui_input_z80_intvec(const char* label, const char* id) {
ImGui::AlignTextToFramePadding();
ImGui::Text("%s", label); ImGui::SameLine();
sim_z80_set_intvec(ui_util_input_u8(id, sim_z80_get_intvec()));
}
#endif
static const char* ui_cpu_flags_as_string(uint8_t flags, char* buf, size_t buf_size) {
assert(buf && (buf_size >= 9)); (void)buf_size;
#if defined(CHIP_6502) || defined(CHIP_2A03)
const char* chrs[2] = { "czidbxvn", "CZIDBXVN" };
#elif defined(CHIP_Z80)
const char* chrs[2] = { "cnvxhyzs", "CNVXHYZS" };
#endif
for (int i = 0; i < 8; i++) {
buf[7 - i] = chrs[(flags>>i) & 1][i];
}
buf[8] = 0;
return buf;
}
#if defined(CHIP_6502)
static void ui_cpu_status_panel(void) {
const uint8_t ir = sim_6502_get_op();
const uint8_t p = sim_get_flags();
ImGui::Text("A:%02X X:%02X Y:%02X SP:%02X PC:%04X",
sim_6502_get_a(), sim_6502_get_x(), sim_6502_get_y(), sim_6502_get_sp(), sim_get_pc());
char p_buf[9];
ImGui::Text("P:%02X (%s) Cycle: %d", p, ui_cpu_flags_as_string(sim_get_flags(), p_buf, sizeof(p_buf)), sim_get_cycle()>>1);
ImGui::Text("OP:%02X [%s]\n", ir, trace_get_disasm(0));
ImGui::Text("Data:%02X Addr:%04X %s %s %s",
sim_get_data(), sim_get_addr(),
sim_6502_get_rw()?"R":"W",
sim_6502_get_clk0()?"CLK0":"clk0",
sim_6502_get_sync()?"SYNC":"sync");
ImGui::Separator();
ui_input_6502_vec("NMI vector (FFFA): ", "##nmi_vec", 0xFFFA);
ui_input_6502_vec("RES vector (FFFC): ", "##res_vec", 0xFFFC);
ui_input_6502_vec("IRQ vector (FFFE): ", "##irq_vec", 0xFFFE);
ImGui::Separator();
bool rdy_active = !sim_6502_get_rdy();
if (ImGui::Checkbox("RDY", &rdy_active)) {
sim_6502_set_rdy(!rdy_active);
}
ImGui::SameLine();
bool irq_active = !sim_6502_get_irq();
if (ImGui::Checkbox("IRQ", &irq_active)) {
sim_6502_set_irq(!irq_active);
}
ImGui::SameLine();
bool nmi_active = !sim_6502_get_nmi();
if (ImGui::Checkbox("NMI", &nmi_active)) {
sim_6502_set_nmi(!nmi_active);
}
ImGui::SameLine();
bool res_active = !sim_6502_get_res();
if (ImGui::Checkbox("RES", &res_active)) {
sim_6502_set_res(!res_active);
}
}
#endif
#if defined(CHIP_Z80)
static void ui_cpu_status_panel(void) {
ImGui::Text("AF:%04X BC:%04X DE:%04X HL:%04X", sim_z80_get_af(), sim_z80_get_bc(), sim_z80_get_de(), sim_z80_get_hl());
ImGui::Text("AF'%04X BC'%04X DE'%04X HL'%04X", sim_z80_get_af2(), sim_z80_get_bc2(), sim_z80_get_de2(), sim_z80_get_hl2());
ImGui::Text("IX:%04X IY:%04X SP:%04X PC:%04X", sim_z80_get_ix(), sim_z80_get_iy(), sim_z80_get_sp(), sim_z80_get_pc());
char f_buf[9];
ImGui::Text("WZ:%04X IR:%02X%02X IM:%X F:%s", sim_z80_get_wz(), sim_z80_get_i(), sim_z80_get_r(), sim_z80_get_im(), ui_cpu_flags_as_string(sim_z80_get_f(), f_buf, sizeof(f_buf)));
ImGui::Text("OP:%02X [%s]", sim_z80_get_op(), trace_get_disasm(0));
const char* m_str = "??";
const char* t_str = "??";
switch (sim_z80_get_m()) {
case (1<<0): m_str = "M1"; break;
case (1<<1): m_str = "M2"; break;
case (1<<2): m_str = "M3"; break;
case (1<<3): m_str = "M4"; break;
case (1<<4): m_str = "M5"; break;
};
switch (sim_z80_get_t()) {
case (1<<0): t_str = "T1"; break;
case (1<<1): t_str = "T2"; break;
case (1<<2): t_str = "T3"; break;
case (1<<3): t_str = "T4"; break;
case (1<<4): t_str = "T5"; break;
case (1<<5): t_str = "T6"; break;
}
ImGui::Text("Cycle:%s/%s DBus:%02X ABus:%04X %s",
m_str, t_str, sim_get_data(), sim_get_addr(), sim_z80_get_iff1() ? "IFF1":"iff1");
ImGui::Text("%s %s %s %s %s %s %s %s\n%s %s %s %s %s %s",
sim_z80_get_clk() ? "CLK":"clk",
sim_z80_get_m1() ? "m1":"M1",
sim_z80_get_mreq() ? "mreq":"MREQ",
sim_z80_get_iorq() ? "iorq":"IORQ",
sim_z80_get_rd() ? "rd":"RD",
sim_z80_get_wr() ? "wr":"WR",
sim_z80_get_rfsh() ? "rfsh":"RFSH",
sim_z80_get_halt() ? "halt":"HALT",
sim_z80_get_wait() ? "wait":"WAIT",
sim_z80_get_int() ? "int":"INT",
sim_z80_get_nmi() ? "nmi":"NMI",
sim_z80_get_reset() ? "reset":"RESET",
sim_z80_get_busrq() ? "busrq":"BUSRQ",
sim_z80_get_busak() ? "busak":"BUSAK");
ImGui::Separator();
ui_input_z80_intvec("INT vector: ", "##int_vec");
ImGui::Separator();
bool wait_active = !sim_z80_get_wait();
if (ImGui::Checkbox("WAIT", &wait_active)) {
sim_z80_set_wait(!wait_active);
}
ImGui::SameLine();
bool int_active = !sim_z80_get_int();
if (ImGui::Checkbox("INT", &int_active)) {
sim_z80_set_int(!int_active);
}
ImGui::SameLine();
bool nmi_active = !sim_z80_get_nmi();
if (ImGui::Checkbox("NMI", &nmi_active)) {
sim_z80_set_nmi(!nmi_active);
}
ImGui::SameLine();
bool res_active = !sim_z80_get_reset();
if (ImGui::Checkbox("RESET", &res_active)) {
sim_z80_set_reset(!res_active);
}
bool busrq_active = !sim_z80_get_busrq();
if (ImGui::Checkbox("BUSRQ", &busrq_active)) {
sim_z80_set_busrq(!busrq_active);
}
}
#endif
#if defined(CHIP_2A03)
static void ui_cpu_status_panel(void) {
const uint8_t ir = sim_2a03_get_op();
const uint8_t p = sim_get_flags();
ImGui::Text("A:%02X X:%02X Y:%02X SP:%02X PC:%04X",
sim_2a03_get_a(), sim_2a03_get_x(), sim_2a03_get_y(), sim_2a03_get_sp(), sim_get_pc());
char p_buf[9];
ImGui::Text("P:%02X (%s) Cycle: %d", p, ui_cpu_flags_as_string(sim_get_flags(), p_buf, sizeof(p_buf)), sim_get_cycle()>>1);
ImGui::Text("OP:%02X [%s]\n", ir, trace_get_disasm(0));
ImGui::Text("Data:%02X Addr:%04X %s %s %s",
sim_get_data(), sim_get_addr(),
sim_2a03_get_rw()?"R":"W",
sim_2a03_get_clk0()?"CLK0":"clk0",
sim_2a03_get_sync()?"SYNC":"sync");
ImGui::Separator();
ui_input_6502_vec("NMI vector (FFFA): ", "##nmi_vec", 0xFFFA);
ui_input_6502_vec("RES vector (FFFC): ", "##res_vec", 0xFFFC);
ui_input_6502_vec("IRQ vector (FFFE): ", "##irq_vec", 0xFFFE);
ImGui::Separator();
bool rdy_active = !sim_2a03_get_rdy();
if (ImGui::Checkbox("RDY", &rdy_active)) {
sim_2a03_set_rdy(!rdy_active);
}
ImGui::SameLine();
bool irq_active = !sim_2a03_get_irq();
if (ImGui::Checkbox("IRQ", &irq_active)) {
sim_2a03_set_irq(!irq_active);
}
ImGui::SameLine();
bool nmi_active = !sim_2a03_get_nmi();
if (ImGui::Checkbox("NMI", &nmi_active)) {
sim_2a03_set_nmi(!nmi_active);
}
ImGui::SameLine();
bool res_active = !sim_2a03_get_res();
if (ImGui::Checkbox("RES", &res_active)) {
sim_2a03_set_res(!res_active);
}