comparison menu.c @ 1423:9a3e003bdcb3

Make drag and drop play nice with the menu
author Michael Pavone <pavone@retrodev.com>
date Fri, 30 Jun 2017 18:42:52 -0700
parents 62ec8be376be
children 4e5797b3935a
comparison
equal deleted inserted replaced
1422:2b34469e3f81 1423:9a3e003bdcb3
8 #include "backend.h" 8 #include "backend.h"
9 #include "util.h" 9 #include "util.h"
10 #include "gst.h" 10 #include "gst.h"
11 #include "m68k_internal.h" //needed for get_native_address_trans, should be eliminated once handling of PC is cleaned up 11 #include "m68k_internal.h" //needed for get_native_address_trans, should be eliminated once handling of PC is cleaned up
12 12
13 13 static menu_context *get_menu(genesis_context *gen)
14 uint16_t menu_read_w(uint32_t address, void * context) 14 {
15 { 15 menu_context *menu = gen->extra;
16 //This should return the status of the last request with 0 16 if (!menu) {
17 //meaning either the request is complete or no request is pending 17 gen->extra = menu = calloc(1, sizeof(menu_context));
18 //in the current implementation, the operations happen instantly 18 menu->curpath = tern_find_path(config, "ui\0initial_path\0", TVAL_PTR).ptrval;
19 //in emulated time so we can always return 0 19 if (!menu->curpath){
20 return 0; 20 #ifdef __ANDROID__
21 menu->curpath = get_external_storage_path();
22 #else
23 menu->curpath = "$HOME";
24 #endif
25 }
26 tern_node *vars = tern_insert_ptr(NULL, "HOME", get_home_dir());
27 vars = tern_insert_ptr(vars, "EXEDIR", get_exe_dir());
28 menu->curpath = replace_vars(menu->curpath, vars, 1);
29 tern_free(vars);
30 }
31 return menu;
32 }
33
34 uint16_t menu_read_w(uint32_t address, void * vcontext)
35 {
36 if ((address >> 1) == 14) {
37 m68k_context *context = vcontext;
38 menu_context *menu = get_menu(context->system);
39 uint16_t value = menu->external_game_load;
40 if (value) {
41 printf("Read: %X\n", value);
42 }
43 menu->external_game_load = 0;
44 return value;
45 } else {
46 //This should return the status of the last request with 0
47 //meaning either the request is complete or no request is pending
48 //in the current implementation, the operations happen instantly
49 //in emulated time so we can always return 0
50 return 0;
51 }
21 } 52 }
22 53
23 int menu_dir_sort(const void *a, const void *b) 54 int menu_dir_sort(const void *a, const void *b)
24 { 55 {
25 const dir_entry *da, *db; 56 const dir_entry *da, *db;
161 192
162 void * menu_write_w(uint32_t address, void * context, uint16_t value) 193 void * menu_write_w(uint32_t address, void * context, uint16_t value)
163 { 194 {
164 m68k_context *m68k = context; 195 m68k_context *m68k = context;
165 genesis_context *gen = m68k->system; 196 genesis_context *gen = m68k->system;
166 menu_context *menu = gen->extra; 197 menu_context *menu = get_menu(gen);
167 if (!menu) {
168 gen->extra = menu = calloc(1, sizeof(menu_context));
169 menu->curpath = tern_find_path(config, "ui\0initial_path\0", TVAL_PTR).ptrval;
170 if (!menu->curpath){
171 #ifdef __ANDROID__
172 menu->curpath = get_external_storage_path();
173 #else
174 menu->curpath = "$HOME";
175 #endif
176 }
177 tern_node *vars = tern_insert_ptr(NULL, "HOME", get_home_dir());
178 vars = tern_insert_ptr(vars, "EXEDIR", get_exe_dir());
179 menu->curpath = replace_vars(menu->curpath, vars, 1);
180 tern_free(vars);
181
182 }
183 if (menu->state) { 198 if (menu->state) {
184 uint32_t dst = menu->latch << 16 | value; 199 uint32_t dst = menu->latch << 16 | value;
185 switch (address >> 2) 200 switch (address >> 2)
186 { 201 {
187 case 0: { 202 case 0: {
373 *(cur++) = 0; 388 *(cur++) = 0;
374 *(cur++) = 0; 389 *(cur++) = 0;
375 } 390 }
376 copy_to_guest(m68k, dst, buffer, cur-buffer); 391 copy_to_guest(m68k, dst, buffer, cur-buffer);
377 break; 392 break;
393 }
378 case 5: 394 case 5:
379 //save state 395 //save state
380 if (gen->header.next_context) { 396 if (gen->header.next_context) {
381 gen->header.next_context->save_state = dst + 1; 397 gen->header.next_context->save_state = dst + 1;
382 } 398 }
403 } 419 }
404 next->m68k->resume_pc = get_native_address_trans(next->m68k, pc); 420 next->m68k->resume_pc = get_native_address_trans(next->m68k, pc);
405 } 421 }
406 m68k->should_return = 1; 422 m68k->should_return = 1;
407 break; 423 break;
408 } 424 case 7:
425 //read only port
426 break;
409 default: 427 default:
410 fprintf(stderr, "WARNING: write to undefined menu port %X\n", address); 428 fprintf(stderr, "WARNING: write to undefined menu port %X\n", address);
411 } 429 }
412 menu->state = 0; 430 menu->state = 0;
413 } else { 431 } else {