Mercurial > repos > blastem
annotate menu.c @ 1407:4c58695c1e1f
WIP ROM DB entry changes for Magistr 16
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 19 Jun 2017 09:44:37 -0700 |
parents | 071e761bcdcf |
children | e6efe6b2aee9 |
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" |
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
|
11 #include "m68k_internal.h" //needed for get_native_address_trans, should be eliminated once handling of PC is cleaned up |
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
|
12 |
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
|
13 |
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 uint16_t menu_read_w(uint32_t address, void * 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
|
15 { |
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 //This should return the status of the last request with 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
|
17 //meaning either the request is complete or no request is pending |
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
|
18 //in the current implementation, the operations happen instantly |
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
|
19 //in emulated time so we can always return 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
|
20 return 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
|
21 } |
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
|
22 |
868
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
23 int menu_dir_sort(const void *a, const void *b) |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
24 { |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
25 const dir_entry *da, *db; |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
26 da = a; |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
27 db = b; |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
28 if (da->is_dir != db->is_dir) { |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
29 return db->is_dir - da->is_dir; |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
30 } |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
31 return strcasecmp(((dir_entry *)a)->name, ((dir_entry *)b)->name); |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
32 } |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
33 |
873
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
34 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
|
35 { |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
36 char *cur; |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
37 char *src = NULL; |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
38 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
|
39 { |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
40 if (!src || !(guest_addr & 0xFFFF)) { |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
41 //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
|
42 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
|
43 if (!src) { |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
44 break; |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
45 } |
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 *cur = src[1]; |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
48 cur[1] = *src; |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
49 if (!*src || !src[1]) { |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
50 break; |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
51 } |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
52 } |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
53 //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
|
54 buf[maxchars-1] = 0; |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
55 } |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
56 |
957 | 57 void copy_to_guest(m68k_context *m68k, uint32_t guest_addr, char *src, size_t tocopy) |
58 { | |
59 char *dst = NULL; | |
60 for (char *cur = src; cur < src+tocopy; cur+=2, guest_addr+=2, dst+=2) | |
61 { | |
62 if (!dst || !(guest_addr & 0xFFFF)) { | |
63 //we may have walked off the end of a memory block, get a fresh native pointer | |
64 dst = get_native_pointer(guest_addr, (void **)m68k->mem_pointers, &m68k->options->gen); | |
65 if (!dst) { | |
66 break; | |
67 } | |
68 } | |
958
83532f944e3b
Get slot list displaying in "Save State" and "Load State" menu items
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
69 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
|
70 *dst = cur[1]; |
957 | 71 } |
72 } | |
73 | |
74 #define SAVE_INFO_BUFFER_SIZE (11*40) | |
75 | |
882
75453bf2ffac
SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
76 #ifdef __ANDROID__ |
75453bf2ffac
SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
77 #include <SDL.h> |
75453bf2ffac
SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
78 #include <jni.h> |
75453bf2ffac
SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
79 char *get_external_storage_path() |
75453bf2ffac
SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
80 { |
75453bf2ffac
SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
81 static char *ret; |
75453bf2ffac
SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
82 if (ret) { |
75453bf2ffac
SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
83 return ret; |
75453bf2ffac
SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
84 } |
75453bf2ffac
SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
85 JNIEnv *env = SDL_AndroidGetJNIEnv(); |
75453bf2ffac
SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
86 if ((*env)->PushLocalFrame(env, 8) < 0) { |
75453bf2ffac
SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
87 return NULL; |
75453bf2ffac
SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
88 } |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
882
diff
changeset
|
89 |
882
75453bf2ffac
SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
90 jclass Environment = (*env)->FindClass(env, "android/os/Environment"); |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
882
diff
changeset
|
91 jmethodID getExternalStorageDirectory = |
882
75453bf2ffac
SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
92 (*env)->GetStaticMethodID(env, Environment, "getExternalStorageDirectory", "()Ljava/io/File;"); |
75453bf2ffac
SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
93 jobject file = (*env)->CallStaticObjectMethod(env, Environment, getExternalStorageDirectory); |
75453bf2ffac
SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
94 if (!file) { |
75453bf2ffac
SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
95 goto cleanup; |
75453bf2ffac
SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
96 } |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
882
diff
changeset
|
97 |
882
75453bf2ffac
SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
98 jmethodID getAbsolutePath = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, file), |
75453bf2ffac
SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
99 "getAbsolutePath", "()Ljava/lang/String;"); |
75453bf2ffac
SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
100 jstring path = (*env)->CallObjectMethod(env, file, getAbsolutePath); |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
882
diff
changeset
|
101 |
882
75453bf2ffac
SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
102 char const *tmp = (*env)->GetStringUTFChars(env, path, NULL); |
75453bf2ffac
SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
103 ret = strdup(tmp); |
75453bf2ffac
SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
104 (*env)->ReleaseStringUTFChars(env, path, tmp); |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
882
diff
changeset
|
105 |
882
75453bf2ffac
SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
106 cleanup: |
75453bf2ffac
SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
107 (*env)->PopLocalFrame(env, NULL); |
75453bf2ffac
SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
108 return ret; |
75453bf2ffac
SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
109 } |
75453bf2ffac
SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
110 #endif |
75453bf2ffac
SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
111 |
972
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
112 #ifdef _WIN32 |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
113 #define localtime_r(a,b) localtime(a) |
1244
0a34e31c4fd0
Update Windows build to use mingw-w64 cross compiler rather than Wine
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
114 //windows inclues seem not to like certain single letter defines from m68k_internal.h |
0a34e31c4fd0
Update Windows build to use mingw-w64 cross compiler rather than Wine
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
115 //get rid of them here |
0a34e31c4fd0
Update Windows build to use mingw-w64 cross compiler rather than Wine
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
116 #undef X |
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
|
117 #undef N |
1244
0a34e31c4fd0
Update Windows build to use mingw-w64 cross compiler rather than Wine
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
118 #undef Z |
0a34e31c4fd0
Update Windows build to use mingw-w64 cross compiler rather than Wine
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
119 #undef V |
0a34e31c4fd0
Update Windows build to use mingw-w64 cross compiler rather than Wine
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
120 #undef C |
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
|
121 #include <windows.h> |
972
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
122 #endif |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
123 |
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
|
124 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
|
125 { |
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
|
126 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
|
127 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
|
128 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
|
129 } |
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
|
130 *(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
|
131 *(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
|
132 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
|
133 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
|
134 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
|
135 { |
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
|
136 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
|
137 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
|
138 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
|
139 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
|
140 } 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
|
141 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
|
142 } |
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
|
143 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
|
144 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
|
145 //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
|
146 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
|
147 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
|
148 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
|
149 } |
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 } 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
|
151 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
|
152 } |
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
|
153 } |
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
|
154 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
|
155 *(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
|
156 *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
|
157 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
|
158 } |
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
|
159 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
|
160 } |
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 |
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
|
162 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
|
163 { |
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
|
164 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
|
165 genesis_context *gen = m68k->system; |
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
|
166 menu_context *menu = gen->extra; |
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
|
167 if (!menu) { |
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
|
168 gen->extra = menu = calloc(1, sizeof(menu_context)); |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1293
diff
changeset
|
169 menu->curpath = tern_find_path(config, "ui\0initial_path\0", TVAL_PTR).ptrval; |
1292
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1244
diff
changeset
|
170 if (!menu->curpath){ |
875
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
171 #ifdef __ANDROID__ |
1292
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1244
diff
changeset
|
172 menu->curpath = get_external_storage_path(); |
875
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
173 #else |
1292
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1244
diff
changeset
|
174 menu->curpath = "$HOME"; |
875
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
175 #endif |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
176 } |
1292
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1244
diff
changeset
|
177 tern_node *vars = tern_insert_ptr(NULL, "HOME", get_home_dir()); |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1244
diff
changeset
|
178 vars = tern_insert_ptr(vars, "EXEDIR", get_exe_dir()); |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1244
diff
changeset
|
179 menu->curpath = replace_vars(menu->curpath, vars, 1); |
1293
72ea3885e7b5
Don't leak a ternary tree when building the menu's initial path
Michael Pavone <pavone@retrodev.com>
parents:
1292
diff
changeset
|
180 tern_free(vars); |
72ea3885e7b5
Don't leak a ternary tree when building the menu's initial path
Michael Pavone <pavone@retrodev.com>
parents:
1292
diff
changeset
|
181 |
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
|
182 } |
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
|
183 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
|
184 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
|
185 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
|
186 { |
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
|
187 case 0: { |
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
|
188 #ifdef _WIN32 |
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
|
189 //handle virtual "drives" directory |
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
|
190 if (menu->curpath[0] == PATH_SEP[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
|
191 char drivestrings[4096]; |
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
|
192 if (sizeof(drivestrings) >= GetLogicalDriveStrings(sizeof(drivestrings), drivestrings)) { |
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
|
193 for (char *cur = drivestrings; *cur; cur += strlen(cur) + 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
|
194 { |
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
|
195 dst = copy_dir_entry_to_guest(dst, m68k, cur, 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
|
196 } |
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
|
197 } |
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
|
198 //terminate list |
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
|
199 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
|
200 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
|
201 *dest = dest[1] = 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
|
202 } |
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
|
203 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
|
204 } |
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
|
205 #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
|
206 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
|
207 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
|
208 if (entries) { |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
209 qsort(entries, num_entries, sizeof(dir_entry), menu_dir_sort); |
933
f7da9b4df0e7
Log errors opening directories in the menu code
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
210 } else { |
934
05b0a0d4fa40
Add strerror output to menu dir open failure message
Michael Pavone <pavone@retrodev.com>
parents:
933
diff
changeset
|
211 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
|
212 entries = malloc(sizeof(dir_entry)); |
2c8d76280e43
Slightly better handling of directory read errors
Michael Pavone <pavone@retrodev.com>
parents:
1024
diff
changeset
|
213 entries->name = strdup(".."); |
2c8d76280e43
Slightly better handling of directory read errors
Michael Pavone <pavone@retrodev.com>
parents:
1024
diff
changeset
|
214 entries->is_dir = 1; |
2c8d76280e43
Slightly better handling of directory read errors
Michael Pavone <pavone@retrodev.com>
parents:
1024
diff
changeset
|
215 num_entries = 1; |
868
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
216 } |
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
|
217 #ifdef _WIN32 |
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
|
218 if (menu->curpath[1] == ':' && !menu->curpath[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
|
219 //Add fake .. entry to allow navigation to virtual "drives" directory |
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
|
220 dst = copy_dir_entry_to_guest(dst, m68k, "..", 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
|
221 } |
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
|
222 #endif |
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
|
223 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
|
224 { |
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
|
225 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
|
226 } |
868
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
227 //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
|
228 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
|
229 if (dest) { |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
230 *dest = dest[1] = 0; |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
231 } |
1034
2c8d76280e43
Slightly better handling of directory read errors
Michael Pavone <pavone@retrodev.com>
parents:
1024
diff
changeset
|
232 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
|
233 break; |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
234 } |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
235 case 1: { |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
236 char buf[4096]; |
873
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
237 copy_string_from_guest(m68k, dst, buf, sizeof(buf)); |
870
f173317ecdb4
More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents:
868
diff
changeset
|
238 if (!strcmp(buf, "..")) { |
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
|
239 #ifdef _WIN32 |
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
|
240 if (menu->curpath[1] == ':' && !menu->curpath[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
|
241 menu->curpath[0] = PATH_SEP[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
|
242 menu->curpath[1] = 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
|
243 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
|
244 } |
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
|
245 #endif |
870
f173317ecdb4
More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents:
868
diff
changeset
|
246 size_t len = strlen(menu->curpath); |
1024
5ebf6ddd5a44
Allow navigating to the root directory on Unix-like systems
Michael Pavone <pavone@retrodev.com>
parents:
1015
diff
changeset
|
247 while (len > 0) { |
870
f173317ecdb4
More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents:
868
diff
changeset
|
248 --len; |
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
|
249 if (is_path_sep(menu->curpath[len])) { |
1024
5ebf6ddd5a44
Allow navigating to the root directory on Unix-like systems
Michael Pavone <pavone@retrodev.com>
parents:
1015
diff
changeset
|
250 if (!len) { |
5ebf6ddd5a44
Allow navigating to the root directory on Unix-like systems
Michael Pavone <pavone@retrodev.com>
parents:
1015
diff
changeset
|
251 //special handling for / |
5ebf6ddd5a44
Allow navigating to the root directory on Unix-like systems
Michael Pavone <pavone@retrodev.com>
parents:
1015
diff
changeset
|
252 menu->curpath[len+1] = 0; |
5ebf6ddd5a44
Allow navigating to the root directory on Unix-like systems
Michael Pavone <pavone@retrodev.com>
parents:
1015
diff
changeset
|
253 } else { |
5ebf6ddd5a44
Allow navigating to the root directory on Unix-like systems
Michael Pavone <pavone@retrodev.com>
parents:
1015
diff
changeset
|
254 menu->curpath[len] = 0; |
5ebf6ddd5a44
Allow navigating to the root directory on Unix-like systems
Michael Pavone <pavone@retrodev.com>
parents:
1015
diff
changeset
|
255 } |
870
f173317ecdb4
More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents:
868
diff
changeset
|
256 break; |
f173317ecdb4
More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents:
868
diff
changeset
|
257 } |
f173317ecdb4
More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents:
868
diff
changeset
|
258 } |
f173317ecdb4
More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents:
868
diff
changeset
|
259 } else { |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
882
diff
changeset
|
260 char *tmp = menu->curpath; |
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
|
261 #ifdef _WIN32 |
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
|
262 if (menu->curpath[0] == PATH_SEP[0] && !menu->curpath[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
|
263 menu->curpath = strdup(buf); |
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
|
264 } 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
|
265 #endif |
1024
5ebf6ddd5a44
Allow navigating to the root directory on Unix-like systems
Michael Pavone <pavone@retrodev.com>
parents:
1015
diff
changeset
|
266 if (is_path_sep(menu->curpath[strlen(menu->curpath) - 1])) { |
5ebf6ddd5a44
Allow navigating to the root directory on Unix-like systems
Michael Pavone <pavone@retrodev.com>
parents:
1015
diff
changeset
|
267 menu->curpath = alloc_concat(menu->curpath, buf); |
5ebf6ddd5a44
Allow navigating to the root directory on Unix-like systems
Michael Pavone <pavone@retrodev.com>
parents:
1015
diff
changeset
|
268 } else { |
5ebf6ddd5a44
Allow navigating to the root directory on Unix-like systems
Michael Pavone <pavone@retrodev.com>
parents:
1015
diff
changeset
|
269 char const *pieces[] = {menu->curpath, PATH_SEP, buf}; |
5ebf6ddd5a44
Allow navigating to the root directory on Unix-like systems
Michael Pavone <pavone@retrodev.com>
parents:
1015
diff
changeset
|
270 menu->curpath = alloc_concat_m(3, pieces); |
5ebf6ddd5a44
Allow navigating to the root directory on Unix-like systems
Michael Pavone <pavone@retrodev.com>
parents:
1015
diff
changeset
|
271 } |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
882
diff
changeset
|
272 free(tmp); |
870
f173317ecdb4
More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents:
868
diff
changeset
|
273 } |
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
|
274 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
|
275 } |
873
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
276 case 2: { |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
277 char buf[4096]; |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
278 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
|
279 char const *pieces[] = {menu->curpath, PATH_SEP, buf}; |
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
|
280 gen->header.next_rom = alloc_concat_m(3, pieces); |
872
7022ba865cfd
Initial work for allowing loading a ROM from menu
Michael Pavone <pavone@retrodev.com>
parents:
870
diff
changeset
|
281 m68k->should_return = 1; |
7022ba865cfd
Initial work for allowing loading a ROM from menu
Michael Pavone <pavone@retrodev.com>
parents:
870
diff
changeset
|
282 break; |
957 | 283 } |
949
5e4fb650de58
Make Exit option in menu work
Michael Pavone <pavone@retrodev.com>
parents:
934
diff
changeset
|
284 case 3: { |
954
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
285 switch (dst) |
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
286 { |
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
287 case 1: |
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
288 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
|
289 gen->header.should_exit = 1; |
954
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
290 break; |
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
291 case 2: |
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
292 m68k->should_return = 1; |
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
293 break; |
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
294 } |
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
295 |
949
5e4fb650de58
Make Exit option in menu work
Michael Pavone <pavone@retrodev.com>
parents:
934
diff
changeset
|
296 break; |
5e4fb650de58
Make Exit option in menu work
Michael Pavone <pavone@retrodev.com>
parents:
934
diff
changeset
|
297 } |
957 | 298 case 4: { |
299 char *buffer = malloc(SAVE_INFO_BUFFER_SIZE); | |
300 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
|
301 if (gen->header.next_context && gen->header.next_context->save_dir) { |
957 | 302 char *end = buffer + SAVE_INFO_BUFFER_SIZE; |
303 char slotfile[] = "slot_0.gst"; | |
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
|
304 char const * parts[3] = {gen->header.next_context->save_dir, PATH_SEP, slotfile}; |
957 | 305 struct tm ltime; |
306 char *fname; | |
307 time_t modtime; | |
308 for (int i = 0; i < 10 && cur < end; i++) | |
309 { | |
310 slotfile[5] = i + '0'; | |
311 fname = alloc_concat_m(3, parts); | |
312 modtime = get_modification_time(fname); | |
313 free(fname); | |
314 if (modtime) { | |
315 cur += snprintf(cur, end-cur, "Slot %d - ", i); | |
316 cur += strftime(cur, end-cur, "%c", localtime_r(&modtime, <ime)); | |
317 | |
318 } else { | |
319 cur += snprintf(cur, end-cur, "Slot %d - EMPTY", i); | |
320 } | |
321 //advance past the null terminator for this entry | |
322 cur++; | |
323 } | |
324 if (cur < end) { | |
325 parts[2] = "quicksave.gst"; | |
326 fname = alloc_concat_m(3, parts); | |
327 modtime = get_modification_time(fname); | |
328 free(fname); | |
329 if (modtime) { | |
958
83532f944e3b
Get slot list displaying in "Save State" and "Load State" menu items
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
330 cur += strftime(cur, end-cur, "Quick - %c", localtime_r(&modtime, <ime)); |
83532f944e3b
Get slot list displaying in "Save State" and "Load State" menu items
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
331 } else if ((end-cur) > strlen("Quick - EMPTY")){ |
83532f944e3b
Get slot list displaying in "Save State" and "Load State" menu items
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
332 cur += strlen(strcpy(cur, "Quick - EMPTY")); |
957 | 333 } |
334 //advance past the null terminator for this entry | |
335 cur++; | |
336 if (cur < end) { | |
337 //terminate the list | |
958
83532f944e3b
Get slot list displaying in "Save State" and "Load State" menu items
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
338 *(cur++) = 0; |
957 | 339 } |
340 } | |
341 } else { | |
342 *(cur++) = 0; | |
343 *(cur++) = 0; | |
344 } | |
345 copy_to_guest(m68k, dst, buffer, cur-buffer); | |
346 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
|
347 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
|
348 //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
|
349 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
|
350 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
|
351 } |
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
|
352 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
|
353 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
|
354 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
|
355 //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
|
356 if (gen->header.next_context && gen->header.next_context->save_dir) { |
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
|
357 char numslotname[] = "slot_0.gst"; |
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
|
358 char *slotname; |
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
|
359 if (dst == QUICK_SAVE_SLOT) { |
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
|
360 slotname = "quicksave.gst"; |
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
|
361 } else { |
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
|
362 numslotname[5] = '0' + dst; |
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
|
363 slotname = numslotname; |
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
|
364 } |
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
|
365 char const *parts[] = {gen->header.next_context->save_dir, PATH_SEP, slotname}; |
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
|
366 char *gstpath = alloc_concat_m(3, parts); |
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
|
367 genesis_context *next = (genesis_context *)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
|
368 uint32_t pc = load_gst(next, gstpath); |
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
|
369 free(gstpath); |
1015
6c54d5a5c7c0
Handle failures to load save state from the menu more gracefully
Michael Pavone <pavone@retrodev.com>
parents:
1008
diff
changeset
|
370 if (!pc) { |
6c54d5a5c7c0
Handle failures to load save state from the menu more gracefully
Michael Pavone <pavone@retrodev.com>
parents:
1008
diff
changeset
|
371 break; |
6c54d5a5c7c0
Handle failures to load save state from the menu more gracefully
Michael Pavone <pavone@retrodev.com>
parents:
1008
diff
changeset
|
372 } |
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
|
373 next->m68k->resume_pc = get_native_address_trans(next->m68k, pc); |
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
|
374 } |
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
|
375 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
|
376 break; |
873
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
377 } |
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
|
378 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
|
379 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
|
380 } |
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
|
381 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
|
382 } 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
|
383 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
|
384 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
|
385 } |
954
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
386 if (m68k->should_return) { |
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
387 m68k->target_cycle = m68k->current_cycle; |
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
388 } |
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
|
389 |
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
|
390 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
|
391 } |