Mercurial > repos > blastem
annotate menu.c @ 953:08346262990b
Remove the int number argument to vdp_int_ack since it is no longer used
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 12 Apr 2016 21:38:24 -0700 |
parents | 5e4fb650de58 |
children | cbc5b39e5518 |
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> |
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
|
6 #include "blastem.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
|
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" |
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
|
10 |
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
|
11 |
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 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
|
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 //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
|
15 //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
|
16 //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
|
17 //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
|
18 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
|
19 } |
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 |
868
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
21 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
|
22 { |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
23 const dir_entry *da, *db; |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
24 da = a; |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
25 db = b; |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
26 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
|
27 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
|
28 } |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
29 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
|
30 } |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
31 |
873
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
32 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
|
33 { |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
34 char *cur; |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
35 char *src = NULL; |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
36 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
|
37 { |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
38 if (!src || !(guest_addr & 0xFFFF)) { |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
39 //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
|
40 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
|
41 if (!src) { |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
42 break; |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
43 } |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
44 } |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
45 *cur = src[1]; |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
46 cur[1] = *src; |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
47 if (!*src || !src[1]) { |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
48 break; |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
49 } |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
50 } |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
51 //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
|
52 buf[maxchars-1] = 0; |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
53 } |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
54 |
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
|
55 #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
|
56 #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
|
57 #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
|
58 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
|
59 { |
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
|
60 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
|
61 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
|
62 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
|
63 } |
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
|
64 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
|
65 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
|
66 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
|
67 } |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
882
diff
changeset
|
68 |
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
|
69 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
|
70 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
|
71 (*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
|
72 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
|
73 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
|
74 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
|
75 } |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
882
diff
changeset
|
76 |
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
|
77 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
|
78 "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
|
79 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
|
80 |
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
|
81 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
|
82 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
|
83 (*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
|
84 |
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
|
85 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
|
86 (*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
|
87 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
|
88 } |
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
|
89 #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
|
90 |
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
|
91 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
|
92 { |
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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 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
|
98 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
|
99 if (menu->curpath) { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
100 menu->curpath = strdup(menu->curpath); |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
101 } else { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
102 #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
|
103 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
|
104 #else |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
105 menu->curpath = strdup(get_home_dir()); |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
106 #endif |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
107 } |
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
|
108 } |
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
|
109 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
|
110 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
|
111 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
|
112 { |
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
|
113 case 0: { |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 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
|
115 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
|
116 if (entries) { |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
117 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
|
118 } else { |
934
05b0a0d4fa40
Add strerror output to menu dir open failure message
Michael Pavone <pavone@retrodev.com>
parents:
933
diff
changeset
|
119 warning("Failed to open directory %s: %s\n", menu->curpath, strerror(errno)); |
868
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
120 } |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
121 uint8_t *dest; |
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
|
122 for (size_t i = 0; i < num_entries; i++) |
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
|
123 { |
868
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
124 dest = get_native_pointer(dst, (void **)m68k->mem_pointers, &m68k->options->gen); |
866
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
125 if (!dest) { |
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
|
126 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
|
127 } |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
128 *(dest++) = entries[i].is_dir; |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
129 *(dest++) = 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
|
130 dst += 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
|
131 uint8_t term = 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
|
132 for (char *cpos = entries[i].name; *cpos; cpos++) |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
133 { |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
134 dest[1] = *cpos; |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
135 dest[0] = cpos[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
|
136 if (cpos[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
|
137 cpos++; |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 } 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
|
139 term = 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
|
140 } |
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
|
141 dst += 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
|
142 if (!(dst & 0xFFFF)) { |
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
|
143 //we may have walked off the end of a memory block, get a fresh native pointer |
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
|
144 dest = get_native_pointer(dst, (void **)m68k->mem_pointers, &m68k->options->gen); |
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
|
145 if (!dest) { |
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
|
146 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
|
147 } |
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
|
148 } 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
|
149 dest += 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
|
150 } |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 } |
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
|
152 if (!term) { |
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
|
153 *(dest++) = 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
|
154 *dest = 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
|
155 dst += 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
|
156 } |
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 } |
868
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
158 //terminate list |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
159 dest = get_native_pointer(dst, (void **)m68k->mem_pointers, &m68k->options->gen); |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
160 if (dest) { |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
161 *dest = dest[1] = 0; |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
162 free_dir_list(entries, num_entries); |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
163 } |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
164 break; |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
165 } |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
166 case 1: { |
1bab7e01ae98
Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
167 char buf[4096]; |
873
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
168 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
|
169 if (!strcmp(buf, "..")) { |
f173317ecdb4
More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents:
868
diff
changeset
|
170 size_t len = strlen(menu->curpath); |
f173317ecdb4
More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents:
868
diff
changeset
|
171 while (len > 1) { |
f173317ecdb4
More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents:
868
diff
changeset
|
172 --len; |
f173317ecdb4
More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents:
868
diff
changeset
|
173 if (menu->curpath[len] == '/') { |
f173317ecdb4
More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents:
868
diff
changeset
|
174 menu->curpath[len] = 0; |
f173317ecdb4
More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents:
868
diff
changeset
|
175 break; |
f173317ecdb4
More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents:
868
diff
changeset
|
176 } |
f173317ecdb4
More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents:
868
diff
changeset
|
177 } |
f173317ecdb4
More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents:
868
diff
changeset
|
178 } else { |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
882
diff
changeset
|
179 char *tmp = menu->curpath; |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
882
diff
changeset
|
180 char const *pieces[] = {menu->curpath, "/", buf}; |
870
f173317ecdb4
More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents:
868
diff
changeset
|
181 menu->curpath = alloc_concat_m(3, pieces); |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
882
diff
changeset
|
182 free(tmp); |
870
f173317ecdb4
More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents:
868
diff
changeset
|
183 } |
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
|
184 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
|
185 } |
873
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
186 case 2: { |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
187 char buf[4096]; |
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
188 copy_string_from_guest(m68k, dst, buf, sizeof(buf)); |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
882
diff
changeset
|
189 char const *pieces[] = {menu->curpath, "/", buf}; |
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
|
190 gen->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
|
191 m68k->should_return = 1; |
7022ba865cfd
Initial work for allowing loading a ROM from menu
Michael Pavone <pavone@retrodev.com>
parents:
870
diff
changeset
|
192 break; |
949
5e4fb650de58
Make Exit option in menu work
Michael Pavone <pavone@retrodev.com>
parents:
934
diff
changeset
|
193 case 3: { |
5e4fb650de58
Make Exit option in menu work
Michael Pavone <pavone@retrodev.com>
parents:
934
diff
changeset
|
194 m68k->should_return = 1; |
5e4fb650de58
Make Exit option in menu work
Michael Pavone <pavone@retrodev.com>
parents:
934
diff
changeset
|
195 gen->should_exit = 1; |
5e4fb650de58
Make Exit option in menu work
Michael Pavone <pavone@retrodev.com>
parents:
934
diff
changeset
|
196 break; |
5e4fb650de58
Make Exit option in menu work
Michael Pavone <pavone@retrodev.com>
parents:
934
diff
changeset
|
197 } |
873
91bf4d905eba
Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
198 } |
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
|
199 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
|
200 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
|
201 } |
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
|
202 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
|
203 } 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
|
204 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
|
205 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
|
206 } |
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 |
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
|
208 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
|
209 } |