Mercurial > repos > blastem
annotate menu.c @ 2245:d220305e81b9
Add missing files
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 23 Nov 2022 09:36:42 -0800 |
parents | bdd83b47d78a |
children | d74d3998482c |
rev | line source |
---|---|
866
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #include <stdint.h> |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 #include <stdlib.h> |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 #include <string.h> |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 #include <stdio.h> |
934
05b0a0d4fa40
Add strerror output to menu dir open failure message
Michael Pavone <pavone@retrodev.com>
parents:
933
diff
changeset
|
5 #include <errno.h> |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
1059
diff
changeset
|
6 #include "genesis.h" |
866
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 #include "menu.h" |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 #include "backend.h" |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 #include "util.h" |
961
750995b587a0
Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents:
958
diff
changeset
|
10 #include "gst.h" |
1473
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
1438
diff
changeset
|
11 #include "paths.h" |
1478
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
12 #include "saves.h" |
1485
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
13 #include "config.h" |
866
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 |
1423
9a3e003bdcb3
Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents:
1418
diff
changeset
|
15 static menu_context *get_menu(genesis_context *gen) |
866
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 { |
1423
9a3e003bdcb3
Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents:
1418
diff
changeset
|
17 menu_context *menu = gen->extra; |
9a3e003bdcb3
Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents:
1418
diff
changeset
|
18 if (!menu) { |
9a3e003bdcb3
Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents:
1418
diff
changeset
|
19 gen->extra = menu = calloc(1, sizeof(menu_context)); |
1473
152a60c6787e
Moved initial path logic out of menu so it can be shared with new UI
Michael Pavone <pavone@retrodev.com>
parents:
1438
diff
changeset
|
20 get_initial_browse_path(&menu->curpath); |
1423
9a3e003bdcb3
Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents:
1418
diff
changeset
|
21 } |
9a3e003bdcb3
Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents:
1418
diff
changeset
|
22 return menu; |
9a3e003bdcb3
Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents:
1418
diff
changeset
|
23 } |
9a3e003bdcb3
Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents:
1418
diff
changeset
|
24 |
9a3e003bdcb3
Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents:
1418
diff
changeset
|
25 uint16_t menu_read_w(uint32_t address, void * vcontext) |
9a3e003bdcb3
Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents:
1418
diff
changeset
|
26 { |
9a3e003bdcb3
Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents:
1418
diff
changeset
|
27 if ((address >> 1) == 14) { |
9a3e003bdcb3
Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents:
1418
diff
changeset
|
28 m68k_context *context = vcontext; |
9a3e003bdcb3
Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents:
1418
diff
changeset
|
29 menu_context *menu = get_menu(context->system); |
9a3e003bdcb3
Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents:
1418
diff
changeset
|
30 uint16_t value = menu->external_game_load; |
9a3e003bdcb3
Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents:
1418
diff
changeset
|
31 if (value) { |
9a3e003bdcb3
Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents:
1418
diff
changeset
|
32 printf("Read: %X\n", value); |
9a3e003bdcb3
Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents:
1418
diff
changeset
|
33 } |
9a3e003bdcb3
Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents:
1418
diff
changeset
|
34 menu->external_game_load = 0; |
9a3e003bdcb3
Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents:
1418
diff
changeset
|
35 return value; |
9a3e003bdcb3
Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents:
1418
diff
changeset
|
36 } else { |
9a3e003bdcb3
Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents:
1418
diff
changeset
|
37 //This should return the status of the last request with 0 |
9a3e003bdcb3
Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents:
1418
diff
changeset
|
38 //meaning either the request is complete or no request is pending |
9a3e003bdcb3
Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents:
1418
diff
changeset
|
39 //in the current implementation, the operations happen instantly |
9a3e003bdcb3
Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents:
1418
diff
changeset
|
40 //in emulated time so we can always return 0 |
9a3e003bdcb3
Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents:
1418
diff
changeset
|
41 return 0; |
9a3e003bdcb3
Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents:
1418
diff
changeset
|
42 } |
866
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 } |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 |
873
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
45 void copy_string_from_guest(m68k_context *m68k, uint32_t guest_addr, char *buf, size_t maxchars) |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
46 { |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
47 char *cur; |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
48 char *src = NULL; |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
49 for (cur = buf; cur < buf+maxchars; cur+=2, guest_addr+=2, src+=2) |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
50 { |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
51 if (!src || !(guest_addr & 0xFFFF)) { |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
52 //we may have walked off the end of a memory block, get a fresh native pointer |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
53 src = get_native_pointer(guest_addr, (void **)m68k->mem_pointers, &m68k->options->gen); |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
54 if (!src) { |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
55 break; |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
56 } |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
57 } |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
58 *cur = src[1]; |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
59 cur[1] = *src; |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
60 if (!*src || !src[1]) { |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
61 break; |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
62 } |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
63 } |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
64 //make sure we terminate the string even if we did not hit a null terminator in the source |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
65 buf[maxchars-1] = 0; |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
66 } |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
67 |
957 | 68 void copy_to_guest(m68k_context *m68k, uint32_t guest_addr, char *src, size_t tocopy) |
69 { | |
70 char *dst = NULL; | |
71 for (char *cur = src; cur < src+tocopy; cur+=2, guest_addr+=2, dst+=2) | |
72 { | |
73 if (!dst || !(guest_addr & 0xFFFF)) { | |
74 //we may have walked off the end of a memory block, get a fresh native pointer | |
75 dst = get_native_pointer(guest_addr, (void **)m68k->mem_pointers, &m68k->options->gen); | |
76 if (!dst) { | |
77 break; | |
78 } | |
79 } | |
958
83532f944e3b
Get slot list displaying in "Save State" and "Load State" menu items
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
80 dst[1] = *cur; |
83532f944e3b
Get slot list displaying in "Save State" and "Load State" menu items
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
81 *dst = cur[1]; |
957 | 82 } |
83 } | |
84 | |
85 #define SAVE_INFO_BUFFER_SIZE (11*40) | |
86 | |
1059
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
87 uint32_t copy_dir_entry_to_guest(uint32_t dst, m68k_context *m68k, char *name, uint8_t is_dir) |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
88 { |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
89 uint8_t *dest = get_native_pointer(dst, (void **)m68k->mem_pointers, &m68k->options->gen); |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
90 if (!dest) { |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
91 return 0; |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
92 } |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
93 *(dest++) = is_dir; |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
94 *(dest++) = 1; |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
95 dst += 2; |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
96 uint8_t term = 0; |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
97 for (char *cpos = name; *cpos; cpos++) |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
98 { |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
99 dest[1] = *cpos; |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
100 dest[0] = cpos[1]; |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
101 if (cpos[1]) { |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
102 cpos++; |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
103 } else { |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
104 term = 1; |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
105 } |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
106 dst += 2; |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
107 if (!(dst & 0xFFFF)) { |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
108 //we may have walked off the end of a memory block, get a fresh native pointer |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
109 dest = get_native_pointer(dst, (void **)m68k->mem_pointers, &m68k->options->gen); |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
110 if (!dest) { |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
111 break; |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
112 } |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
113 } else { |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
114 dest += 2; |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
115 } |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
116 } |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
117 if (!term) { |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
118 *(dest++) = 0; |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
119 *dest = 0; |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
120 dst += 2; |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
121 } |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
122 return dst; |
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
123 } |
1525
3629366616da
Fix unguarged windows.h include
Michael Pavone <pavone@retrodev.com>
parents:
1524
diff
changeset
|
124 #ifdef _WIN32 |
1524
b96f9fae757f
Fix Windows build, added Windows default_font_path implementation
Michael Pavone <pavone@retrodev.com>
parents:
1485
diff
changeset
|
125 #include <windows.h> |
1525
3629366616da
Fix unguarged windows.h include
Michael Pavone <pavone@retrodev.com>
parents:
1524
diff
changeset
|
126 #endif |
866
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
127 void * menu_write_w(uint32_t address, void * context, uint16_t value) |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
128 { |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
129 m68k_context *m68k = context; |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
130 genesis_context *gen = m68k->system; |
1423
9a3e003bdcb3
Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents:
1418
diff
changeset
|
131 menu_context *menu = get_menu(gen); |
866
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
132 if (menu->state) { |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
133 uint32_t dst = menu->latch << 16 | value; |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
134 switch (address >> 2) |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
135 { |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
136 case 0: { |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
137 size_t num_entries; |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 dir_entry *entries = get_dir_list(menu->curpath, &num_entries); |
868
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
139 if (entries) { |
1484
d82af64c94d2
Sort directory listing in Nuklear UI file browser
Michael Pavone <pavone@retrodev.com>
parents:
1481
diff
changeset
|
140 sort_dir_list(entries, num_entries); |
933
f7da9b4df0e7
Log errors opening directories in the menu code
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
141 } else { |
934
05b0a0d4fa40
Add strerror output to menu dir open failure message
Michael Pavone <pavone@retrodev.com>
parents:
933
diff
changeset
|
142 warning("Failed to open directory %s: %s\n", menu->curpath, strerror(errno)); |
1034
2c8d76280e43
Slightly better handling of directory read errors
Michael Pavone <pavone@retrodev.com>
parents:
1024
diff
changeset
|
143 entries = malloc(sizeof(dir_entry)); |
2c8d76280e43
Slightly better handling of directory read errors
Michael Pavone <pavone@retrodev.com>
parents:
1024
diff
changeset
|
144 entries->name = strdup(".."); |
2c8d76280e43
Slightly better handling of directory read errors
Michael Pavone <pavone@retrodev.com>
parents:
1024
diff
changeset
|
145 entries->is_dir = 1; |
2c8d76280e43
Slightly better handling of directory read errors
Michael Pavone <pavone@retrodev.com>
parents:
1024
diff
changeset
|
146 num_entries = 1; |
868
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
147 } |
1485
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
148 uint32_t num_exts; |
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
149 char **ext_list = get_extension_list(config, &num_exts); |
1059
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
150 for (size_t i = 0; dst && i < num_entries; i++) |
866
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 { |
1417
e6efe6b2aee9
Add a file extension filter to the menu
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
152 if (num_exts && !entries[i].is_dir) { |
2158
bdd83b47d78a
Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents:
1674
diff
changeset
|
153 if (!path_matches_extensions(entries[i].name, (const char **)ext_list, num_exts)) { |
1417
e6efe6b2aee9
Add a file extension filter to the menu
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
154 continue; |
e6efe6b2aee9
Add a file extension filter to the menu
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
155 } |
e6efe6b2aee9
Add a file extension filter to the menu
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
156 } |
1059
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
157 dst = copy_dir_entry_to_guest(dst, m68k, entries[i].name, entries[i].is_dir); |
866
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
158 } |
1417
e6efe6b2aee9
Add a file extension filter to the menu
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
159 free(ext_list); |
868
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
160 //terminate list |
1059
8da967779710
Added some hacky code to support a virtual root directory for selecting drives on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1034
diff
changeset
|
161 uint8_t *dest = get_native_pointer(dst, (void **)m68k->mem_pointers, &m68k->options->gen); |
868
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
162 if (dest) { |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
163 *dest = dest[1] = 0; |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
164 } |
1034
2c8d76280e43
Slightly better handling of directory read errors
Michael Pavone <pavone@retrodev.com>
parents:
1024
diff
changeset
|
165 free_dir_list(entries, num_entries); |
868
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
166 break; |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
167 } |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
168 case 1: { |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
169 char buf[4096]; |
873
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
170 copy_string_from_guest(m68k, dst, buf, sizeof(buf)); |
1481
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
171 buf[sizeof(buf)-1] = 0; |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
172 char *tmp = menu->curpath; |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
173 menu->curpath = path_append(tmp, buf); |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
174 free(tmp); |
866
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
175 break; |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
176 } |
1438
e2bd03ed3190
Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents:
1434
diff
changeset
|
177 case 2: |
e2bd03ed3190
Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents:
1434
diff
changeset
|
178 case 8: { |
873
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
179 char buf[4096]; |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
180 copy_string_from_guest(m68k, dst, buf, sizeof(buf)); |
1008
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
972
diff
changeset
|
181 char const *pieces[] = {menu->curpath, PATH_SEP, buf}; |
1438
e2bd03ed3190
Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents:
1434
diff
changeset
|
182 char *selected = alloc_concat_m(3, pieces); |
e2bd03ed3190
Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents:
1434
diff
changeset
|
183 if ((address >> 2) == 2) { |
e2bd03ed3190
Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents:
1434
diff
changeset
|
184 gen->header.next_rom = selected; |
e2bd03ed3190
Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents:
1434
diff
changeset
|
185 m68k->should_return = 1; |
e2bd03ed3190
Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents:
1434
diff
changeset
|
186 } else { |
e2bd03ed3190
Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents:
1434
diff
changeset
|
187 lockon_media(selected); |
e2bd03ed3190
Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents:
1434
diff
changeset
|
188 free(selected); |
e2bd03ed3190
Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents:
1434
diff
changeset
|
189 } |
872
7022ba865cfd
Initial work for allowing loading a ROM from menu
Michael Pavone <pavone@retrodev.com>
parents:
870
diff
changeset
|
190 break; |
957 | 191 } |
949
5e4fb650de58
Make Exit option in menu work
Michael Pavone <pavone@retrodev.com>
parents:
934
diff
changeset
|
192 case 3: { |
954
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
193 switch (dst) |
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
194 { |
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
195 case 1: |
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
196 m68k->should_return = 1; |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
197 gen->header.should_exit = 1; |
954
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
198 break; |
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
199 case 2: |
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
200 m68k->should_return = 1; |
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
201 break; |
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
202 } |
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
203 |
949
5e4fb650de58
Make Exit option in menu work
Michael Pavone <pavone@retrodev.com>
parents:
934
diff
changeset
|
204 break; |
5e4fb650de58
Make Exit option in menu work
Michael Pavone <pavone@retrodev.com>
parents:
934
diff
changeset
|
205 } |
957 | 206 case 4: { |
207 char *buffer = malloc(SAVE_INFO_BUFFER_SIZE); | |
208 char *cur = buffer; | |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
209 if (gen->header.next_context && gen->header.next_context->save_dir) { |
957 | 210 char *end = buffer + SAVE_INFO_BUFFER_SIZE; |
1478
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
211 uint32_t num_slots; |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
212 save_slot_info *slots = get_slot_info(gen->header.next_context, &num_slots); |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
213 for (uint32_t i = 0; i < num_slots; i++) |
957 | 214 { |
1478
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
215 size_t desc_len = strlen(slots[i].desc) + 1;//+1 for string terminator |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
216 char *after = cur + desc_len + 1;//+1 for list terminator |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
217 if (after > cur) { |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
218 desc_len -= after - cur; |
957 | 219 } |
1478
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
220 memcpy(cur, slots[i].desc, desc_len); |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
221 cur = after; |
957 | 222 } |
1478
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1473
diff
changeset
|
223 *cur = 0;//terminate list |
957 | 224 } else { |
225 *(cur++) = 0; | |
226 *(cur++) = 0; | |
227 } | |
228 copy_to_guest(m68k, dst, buffer, cur-buffer); | |
229 break; | |
1423
9a3e003bdcb3
Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents:
1418
diff
changeset
|
230 } |
961
750995b587a0
Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents:
958
diff
changeset
|
231 case 5: |
750995b587a0
Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents:
958
diff
changeset
|
232 //save state |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
233 if (gen->header.next_context) { |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
234 gen->header.next_context->save_state = dst + 1; |
961
750995b587a0
Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents:
958
diff
changeset
|
235 } |
750995b587a0
Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents:
958
diff
changeset
|
236 m68k->should_return = 1; |
750995b587a0
Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents:
958
diff
changeset
|
237 break; |
750995b587a0
Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents:
958
diff
changeset
|
238 case 6: |
750995b587a0
Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents:
958
diff
changeset
|
239 //load state |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
240 if (gen->header.next_context && gen->header.next_context->save_dir) { |
1433
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
241 if (!gen->header.next_context->load_state(gen->header.next_context, dst)) { |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
242 break; |
961
750995b587a0
Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents:
958
diff
changeset
|
243 } |
750995b587a0
Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents:
958
diff
changeset
|
244 } |
750995b587a0
Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents:
958
diff
changeset
|
245 m68k->should_return = 1; |
750995b587a0
Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents:
958
diff
changeset
|
246 break; |
1423
9a3e003bdcb3
Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents:
1418
diff
changeset
|
247 case 7: |
9a3e003bdcb3
Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents:
1418
diff
changeset
|
248 //read only port |
9a3e003bdcb3
Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents:
1418
diff
changeset
|
249 break; |
866
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
250 default: |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
251 fprintf(stderr, "WARNING: write to undefined menu port %X\n", address); |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
252 } |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
253 menu->state = 0; |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
254 } else { |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
255 menu->latch = value; |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
256 menu->state = 1; |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
257 } |
954
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
258 if (m68k->should_return) { |
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
259 m68k->target_cycle = m68k->current_cycle; |
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
260 } |
866
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
261 |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
262 return context; |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
263 } |