Mercurial > repos > blastem
annotate menu.c @ 1124:e4deab85f9ac
The function of the HVC Latch enable bit in mode register 1 is different when not in mode 5
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 27 Dec 2016 13:38:58 -0800 |
parents | 2eb54e24914e |
children | 0a34e31c4fd0 |
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) |
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
|
114 #undef N |
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 #undef X |
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 #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
|
117 #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
|
118 |
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
|
119 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
|
120 { |
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 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
|
122 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
|
123 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
|
124 } |
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 *(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
|
126 *(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
|
127 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
|
128 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
|
129 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
|
130 { |
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] = *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
|
132 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
|
133 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
|
134 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 } 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
|
136 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
|
137 } |
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 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
|
139 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
|
140 //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
|
141 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
|
142 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
|
143 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
|
144 } |
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 } 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
|
146 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
|
147 } |
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 } |
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 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
|
150 *(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
|
151 *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
|
152 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
|
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 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
|
155 } |
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 |
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
|
157 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
|
158 { |
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
|
159 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
|
160 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
|
161 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
|
162 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
|
163 gen->extra = menu = calloc(1, sizeof(menu_context)); |
874
b6842dfb8edf
ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents:
873
diff
changeset
|
164 menu->curpath = tern_find_path(config, "ui\0initial_path\0").ptrval; |
875
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
165 if (menu->curpath) { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
166 menu->curpath = strdup(menu->curpath); |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
167 } else { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
168 #ifdef __ANDROID__ |
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
|
169 menu->curpath = strdup(get_external_storage_path()); |
875
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
170 #else |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
171 menu->curpath = strdup(get_home_dir()); |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
172 #endif |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
173 } |
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
|
174 } |
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 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
|
176 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
|
177 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
|
178 { |
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
|
179 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
|
180 #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
|
181 //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
|
182 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
|
183 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
|
184 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
|
185 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
|
186 { |
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
|
187 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
|
188 } |
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 } |
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 //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
|
191 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
|
192 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
|
193 *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
|
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 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
|
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 #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
|
198 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
|
199 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
|
200 if (entries) { |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
201 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
|
202 } else { |
934
05b0a0d4fa40
Add strerror output to menu dir open failure message
Michael Pavone <pavone@retrodev.com>
parents:
933
diff
changeset
|
203 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
|
204 entries = malloc(sizeof(dir_entry)); |
2c8d76280e43
Slightly better handling of directory read errors
Michael Pavone <pavone@retrodev.com>
parents:
1024
diff
changeset
|
205 entries->name = strdup(".."); |
2c8d76280e43
Slightly better handling of directory read errors
Michael Pavone <pavone@retrodev.com>
parents:
1024
diff
changeset
|
206 entries->is_dir = 1; |
2c8d76280e43
Slightly better handling of directory read errors
Michael Pavone <pavone@retrodev.com>
parents:
1024
diff
changeset
|
207 num_entries = 1; |
868
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
208 } |
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
|
209 #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
|
210 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
|
211 //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
|
212 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
|
213 } |
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
|
214 #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
|
215 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
|
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 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
|
218 } |
868
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
219 //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
|
220 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
|
221 if (dest) { |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
222 *dest = dest[1] = 0; |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
223 } |
1034
2c8d76280e43
Slightly better handling of directory read errors
Michael Pavone <pavone@retrodev.com>
parents:
1024
diff
changeset
|
224 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
|
225 break; |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
226 } |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
227 case 1: { |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
228 char buf[4096]; |
873
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
229 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
|
230 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
|
231 #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
|
232 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
|
233 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
|
234 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
|
235 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
|
236 } |
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
|
237 #endif |
870
f173317ecdb4
More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents:
868
diff
changeset
|
238 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
|
239 while (len > 0) { |
870
f173317ecdb4
More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents:
868
diff
changeset
|
240 --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
|
241 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
|
242 if (!len) { |
5ebf6ddd5a44
Allow navigating to the root directory on Unix-like systems
Michael Pavone <pavone@retrodev.com>
parents:
1015
diff
changeset
|
243 //special handling for / |
5ebf6ddd5a44
Allow navigating to the root directory on Unix-like systems
Michael Pavone <pavone@retrodev.com>
parents:
1015
diff
changeset
|
244 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
|
245 } else { |
5ebf6ddd5a44
Allow navigating to the root directory on Unix-like systems
Michael Pavone <pavone@retrodev.com>
parents:
1015
diff
changeset
|
246 menu->curpath[len] = 0; |
5ebf6ddd5a44
Allow navigating to the root directory on Unix-like systems
Michael Pavone <pavone@retrodev.com>
parents:
1015
diff
changeset
|
247 } |
870
f173317ecdb4
More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents:
868
diff
changeset
|
248 break; |
f173317ecdb4
More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents:
868
diff
changeset
|
249 } |
f173317ecdb4
More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents:
868
diff
changeset
|
250 } |
f173317ecdb4
More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents:
868
diff
changeset
|
251 } else { |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
882
diff
changeset
|
252 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
|
253 #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
|
254 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
|
255 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
|
256 } 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
|
257 #endif |
1024
5ebf6ddd5a44
Allow navigating to the root directory on Unix-like systems
Michael Pavone <pavone@retrodev.com>
parents:
1015
diff
changeset
|
258 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
|
259 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
|
260 } else { |
5ebf6ddd5a44
Allow navigating to the root directory on Unix-like systems
Michael Pavone <pavone@retrodev.com>
parents:
1015
diff
changeset
|
261 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
|
262 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
|
263 } |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
882
diff
changeset
|
264 free(tmp); |
870
f173317ecdb4
More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents:
868
diff
changeset
|
265 } |
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
|
266 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
|
267 } |
873
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
268 case 2: { |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
269 char buf[4096]; |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
270 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
|
271 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
|
272 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
|
273 m68k->should_return = 1; |
7022ba865cfd
Initial work for allowing loading a ROM from menu
Michael Pavone <pavone@retrodev.com>
parents:
870
diff
changeset
|
274 break; |
957 | 275 } |
949
5e4fb650de58
Make Exit option in menu work
Michael Pavone <pavone@retrodev.com>
parents:
934
diff
changeset
|
276 case 3: { |
954
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
277 switch (dst) |
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
278 { |
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
279 case 1: |
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
280 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
|
281 gen->header.should_exit = 1; |
954
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
282 break; |
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
283 case 2: |
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
284 m68k->should_return = 1; |
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
285 break; |
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 |
949
5e4fb650de58
Make Exit option in menu work
Michael Pavone <pavone@retrodev.com>
parents:
934
diff
changeset
|
288 break; |
5e4fb650de58
Make Exit option in menu work
Michael Pavone <pavone@retrodev.com>
parents:
934
diff
changeset
|
289 } |
957 | 290 case 4: { |
291 char *buffer = malloc(SAVE_INFO_BUFFER_SIZE); | |
292 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
|
293 if (gen->header.next_context && gen->header.next_context->save_dir) { |
957 | 294 char *end = buffer + SAVE_INFO_BUFFER_SIZE; |
295 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
|
296 char const * parts[3] = {gen->header.next_context->save_dir, PATH_SEP, slotfile}; |
957 | 297 struct tm ltime; |
298 char *fname; | |
299 time_t modtime; | |
300 for (int i = 0; i < 10 && cur < end; i++) | |
301 { | |
302 slotfile[5] = i + '0'; | |
303 fname = alloc_concat_m(3, parts); | |
304 modtime = get_modification_time(fname); | |
305 free(fname); | |
306 if (modtime) { | |
307 cur += snprintf(cur, end-cur, "Slot %d - ", i); | |
308 cur += strftime(cur, end-cur, "%c", localtime_r(&modtime, <ime)); | |
309 | |
310 } else { | |
311 cur += snprintf(cur, end-cur, "Slot %d - EMPTY", i); | |
312 } | |
313 //advance past the null terminator for this entry | |
314 cur++; | |
315 } | |
316 if (cur < end) { | |
317 parts[2] = "quicksave.gst"; | |
318 fname = alloc_concat_m(3, parts); | |
319 modtime = get_modification_time(fname); | |
320 free(fname); | |
321 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
|
322 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
|
323 } 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
|
324 cur += strlen(strcpy(cur, "Quick - EMPTY")); |
957 | 325 } |
326 //advance past the null terminator for this entry | |
327 cur++; | |
328 if (cur < end) { | |
329 //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
|
330 *(cur++) = 0; |
957 | 331 } |
332 } | |
333 } else { | |
334 *(cur++) = 0; | |
335 *(cur++) = 0; | |
336 } | |
337 copy_to_guest(m68k, dst, buffer, cur-buffer); | |
338 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
|
339 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
|
340 //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
|
341 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
|
342 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
|
343 } |
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
|
344 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
|
345 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
|
346 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
|
347 //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
|
348 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
|
349 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
|
350 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
|
351 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
|
352 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
|
353 } 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
|
354 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
|
355 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
|
356 } |
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
|
357 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
|
358 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
|
359 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
|
360 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
|
361 free(gstpath); |
1015
6c54d5a5c7c0
Handle failures to load save state from the menu more gracefully
Michael Pavone <pavone@retrodev.com>
parents:
1008
diff
changeset
|
362 if (!pc) { |
6c54d5a5c7c0
Handle failures to load save state from the menu more gracefully
Michael Pavone <pavone@retrodev.com>
parents:
1008
diff
changeset
|
363 break; |
6c54d5a5c7c0
Handle failures to load save state from the menu more gracefully
Michael Pavone <pavone@retrodev.com>
parents:
1008
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 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
|
366 } |
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
|
367 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
|
368 break; |
873
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
369 } |
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
|
370 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
|
371 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
|
372 } |
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
|
373 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
|
374 } 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
|
375 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
|
376 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
|
377 } |
954
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
378 if (m68k->should_return) { |
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
379 m68k->target_cycle = m68k->current_cycle; |
cbc5b39e5518
Implement "Resume" button in pause menu
Michael Pavone <pavone@retrodev.com>
parents:
949
diff
changeset
|
380 } |
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
|
381 |
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 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
|
383 } |