annotate menu.c @ 924:1b86268a4cb3

Change the sentinel value for the hslot parameter of run_dma_src to something that is not a valid slot number and actually use it for calls during the active display period
author Michael Pavone <pavone@retrodev.com>
date Tue, 02 Feb 2016 18:33:00 -0800
parents 252dfd29831d
children f7da9b4df0e7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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>
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
5 #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
6 #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
7 #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
8 #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
9
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 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
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 //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
14 //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
15 //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
16 //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
17 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 }
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
868
1bab7e01ae98 Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
20 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
21 {
1bab7e01ae98 Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
22 const dir_entry *da, *db;
1bab7e01ae98 Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
23 da = a;
1bab7e01ae98 Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
24 db = b;
1bab7e01ae98 Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
25 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
26 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
27 }
1bab7e01ae98 Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
28 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
29 }
1bab7e01ae98 Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
30
873
91bf4d905eba Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents: 872
diff changeset
31 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
32 {
91bf4d905eba Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents: 872
diff changeset
33 char *cur;
91bf4d905eba Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents: 872
diff changeset
34 char *src = NULL;
91bf4d905eba Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents: 872
diff changeset
35 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
36 {
91bf4d905eba Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents: 872
diff changeset
37 if (!src || !(guest_addr & 0xFFFF)) {
91bf4d905eba Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents: 872
diff changeset
38 //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
39 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
40 if (!src) {
91bf4d905eba Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents: 872
diff changeset
41 break;
91bf4d905eba Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents: 872
diff changeset
42 }
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 *cur = src[1];
91bf4d905eba Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents: 872
diff changeset
45 cur[1] = *src;
91bf4d905eba Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents: 872
diff changeset
46 if (!*src || !src[1]) {
91bf4d905eba Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents: 872
diff changeset
47 break;
91bf4d905eba Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents: 872
diff changeset
48 }
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 //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
51 buf[maxchars-1] = 0;
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
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
54 #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
55 #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
56 #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
57 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
58 {
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 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
60 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
61 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
62 }
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 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
64 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
65 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
66 }
884
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 882
diff changeset
67
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
68 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
69 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
70 (*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
71 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
72 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
73 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
74 }
884
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 882
diff changeset
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 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
77 "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
78 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
79
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
80 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
81 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
82 (*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
83
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
84 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
85 (*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
86 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
87 }
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 #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
89
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
90 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
91 {
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 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
93 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
94 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
95 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
96 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
97 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
98 if (menu->curpath) {
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
99 menu->curpath = strdup(menu->curpath);
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
100 } else {
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
101 #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
102 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
103 #else
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
104 menu->curpath = strdup(get_home_dir());
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
105 #endif
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
106 }
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
107 }
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 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
109 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
110 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
111 {
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 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
113 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
114 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
115 if (entries) {
1bab7e01ae98 Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
116 qsort(entries, num_entries, sizeof(dir_entry), menu_dir_sort);
1bab7e01ae98 Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
117 }
1bab7e01ae98 Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
118 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
119 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
120 {
868
1bab7e01ae98 Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
121 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
122 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
123 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
124 }
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 *(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
126 *(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
127 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
128 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
129 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
130 {
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 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
132 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
133 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
134 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 } 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
136 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
137 }
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 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
139 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
140 //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
141 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
142 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
143 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
144 }
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 } 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
146 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
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 }
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 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
150 *(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
151 *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
152 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
153 }
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 }
868
1bab7e01ae98 Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
155 //terminate list
1bab7e01ae98 Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
156 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
157 if (dest) {
1bab7e01ae98 Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
158 *dest = dest[1] = 0;
1bab7e01ae98 Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
159 free_dir_list(entries, num_entries);
1bab7e01ae98 Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
160 }
1bab7e01ae98 Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
161 break;
1bab7e01ae98 Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
162 }
1bab7e01ae98 Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
163 case 1: {
1bab7e01ae98 Allow directory navigation in menu. Sort directory entries
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
164 char buf[4096];
873
91bf4d905eba Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents: 872
diff changeset
165 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
166 if (!strcmp(buf, "..")) {
f173317ecdb4 More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents: 868
diff changeset
167 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
168 while (len > 1) {
f173317ecdb4 More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents: 868
diff changeset
169 --len;
f173317ecdb4 More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents: 868
diff changeset
170 if (menu->curpath[len] == '/') {
f173317ecdb4 More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents: 868
diff changeset
171 menu->curpath[len] = 0;
f173317ecdb4 More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents: 868
diff changeset
172 break;
f173317ecdb4 More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents: 868
diff changeset
173 }
f173317ecdb4 More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents: 868
diff changeset
174 }
f173317ecdb4 More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents: 868
diff changeset
175 } else {
884
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 882
diff changeset
176 char *tmp = menu->curpath;
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 882
diff changeset
177 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
178 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
179 free(tmp);
870
f173317ecdb4 More efficient handling of going up one directory in menu
Michael Pavone <pavone@retrodev.com>
parents: 868
diff changeset
180 }
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
181 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
182 }
873
91bf4d905eba Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents: 872
diff changeset
183 case 2: {
91bf4d905eba Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents: 872
diff changeset
184 char buf[4096];
91bf4d905eba Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents: 872
diff changeset
185 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
186 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
187 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
188 m68k->should_return = 1;
7022ba865cfd Initial work for allowing loading a ROM from menu
Michael Pavone <pavone@retrodev.com>
parents: 870
diff changeset
189 break;
873
91bf4d905eba Retrieve ROM filename from menu port write
Michael Pavone <pavone@retrodev.com>
parents: 872
diff changeset
190 }
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
191 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
192 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
193 }
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
194 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
195 } 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
196 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
197 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
198 }
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
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 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
201 }