# HG changeset patch # User Michael Pavone # Date 1498873372 25200 # Node ID 9a3e003bdcb36086c080448c101814285ee9df13 # Parent 2b34469e3f81e4ec85db7979740f8b1f737336d0 Make drag and drop play nice with the menu diff -r 2b34469e3f81 -r 9a3e003bdcb3 blastem.c --- a/blastem.c Fri Jun 30 00:36:18 2017 -0700 +++ b/blastem.c Fri Jun 30 18:42:52 2017 -0700 @@ -23,6 +23,7 @@ #include "terminal.h" #include "arena.h" #include "config.h" +#include "menu.h" #define BLASTEM_VERSION "0.5.1-pre" @@ -116,14 +117,14 @@ char * save_filename; system_header *current_system; -system_header *menu_context; -system_header *game_context; +system_header *menu_system; +system_header *game_system; void persist_save() { - if (!game_context) { + if (!game_system) { return; } - game_context->persist_save(game_context); + game_system->persist_save(game_system); } char *title; @@ -189,6 +190,17 @@ } current_system->next_rom = strdup(filename); current_system->request_exit(current_system); + if (menu_system && menu_system->type == SYSTEM_GENESIS) { + genesis_context *gen = (genesis_context *)menu_system; + if (gen->extra) { + menu_context *menu = gen->extra; + menu->external_game_load = 1; + } else { + puts("No extra"); + } + } else { + puts("no menu"); + } } int main(int argc, char ** argv) @@ -408,9 +420,9 @@ setup_saves(&cart, &info, current_system); update_title(info.name); if (menu) { - menu_context = current_system; + menu_system = current_system; } else { - game_context = current_system; + game_system = current_system; } current_system->debugger_type = dtype; @@ -424,14 +436,14 @@ if (current_system->next_rom) { char *next_rom = current_system->next_rom; current_system->next_rom = NULL; - if (game_context) { - game_context->persist_save(game_context); + if (game_system) { + game_system->persist_save(game_system); //swap to game context arena and mark all allocated pages in it free if (menu) { - current_system->arena = set_current_arena(game_context->arena); + current_system->arena = set_current_arena(game_system->arena); } mark_all_free(); - game_context->free_context(game_context); + game_system->free_context(game_system); } else { //start a new arena and save old one in suspended genesis context current_system->arena = start_new_arena(); @@ -449,28 +461,28 @@ fatal_error("Failed to detect system type for %s\n", next_rom); } //allocate new system context - game_context = alloc_config_system(stype, &cart, opts,force_region, &info); - if (!game_context) { + game_system = alloc_config_system(stype, &cart, opts,force_region, &info); + if (!game_system) { fatal_error("Failed to configure emulated machine for %s\n", next_rom); } - menu_context->next_context = game_context; - game_context->next_context = menu_context; - setup_saves(&cart, &info, game_context); + menu_system->next_context = game_system; + game_system->next_context = menu_system; + setup_saves(&cart, &info, game_system); update_title(info.name); free(next_rom); menu = 0; - current_system = game_context; + current_system = game_system; current_system->debugger_type = dtype; current_system->enter_debugger = start_in_debugger && menu == debug_target; current_system->start_context(current_system, statefile); - } else if (menu && game_context) { - current_system->arena = set_current_arena(game_context->arena); - current_system = game_context; + } else if (menu && game_system) { + current_system->arena = set_current_arena(game_system->arena); + current_system = game_system; menu = 0; current_system->resume_context(current_system); - } else if (!menu && menu_context) { - current_system->arena = set_current_arena(menu_context->arena); - current_system = menu_context; + } else if (!menu && menu_system) { + current_system->arena = set_current_arena(menu_system->arena); + current_system = menu_system; menu = 1; current_system->resume_context(current_system); } else { diff -r 2b34469e3f81 -r 9a3e003bdcb3 menu.c --- a/menu.c Fri Jun 30 00:36:18 2017 -0700 +++ b/menu.c Fri Jun 30 18:42:52 2017 -0700 @@ -10,14 +10,45 @@ #include "gst.h" #include "m68k_internal.h" //needed for get_native_address_trans, should be eliminated once handling of PC is cleaned up - -uint16_t menu_read_w(uint32_t address, void * context) +static menu_context *get_menu(genesis_context *gen) { - //This should return the status of the last request with 0 - //meaning either the request is complete or no request is pending - //in the current implementation, the operations happen instantly - //in emulated time so we can always return 0 - return 0; + menu_context *menu = gen->extra; + if (!menu) { + gen->extra = menu = calloc(1, sizeof(menu_context)); + menu->curpath = tern_find_path(config, "ui\0initial_path\0", TVAL_PTR).ptrval; + if (!menu->curpath){ +#ifdef __ANDROID__ + menu->curpath = get_external_storage_path(); +#else + menu->curpath = "$HOME"; +#endif + } + tern_node *vars = tern_insert_ptr(NULL, "HOME", get_home_dir()); + vars = tern_insert_ptr(vars, "EXEDIR", get_exe_dir()); + menu->curpath = replace_vars(menu->curpath, vars, 1); + tern_free(vars); + } + return menu; +} + +uint16_t menu_read_w(uint32_t address, void * vcontext) +{ + if ((address >> 1) == 14) { + m68k_context *context = vcontext; + menu_context *menu = get_menu(context->system); + uint16_t value = menu->external_game_load; + if (value) { + printf("Read: %X\n", value); + } + menu->external_game_load = 0; + return value; + } else { + //This should return the status of the last request with 0 + //meaning either the request is complete or no request is pending + //in the current implementation, the operations happen instantly + //in emulated time so we can always return 0 + return 0; + } } int menu_dir_sort(const void *a, const void *b) @@ -163,23 +194,7 @@ { m68k_context *m68k = context; genesis_context *gen = m68k->system; - menu_context *menu = gen->extra; - if (!menu) { - gen->extra = menu = calloc(1, sizeof(menu_context)); - menu->curpath = tern_find_path(config, "ui\0initial_path\0", TVAL_PTR).ptrval; - if (!menu->curpath){ -#ifdef __ANDROID__ - menu->curpath = get_external_storage_path(); -#else - menu->curpath = "$HOME"; -#endif - } - tern_node *vars = tern_insert_ptr(NULL, "HOME", get_home_dir()); - vars = tern_insert_ptr(vars, "EXEDIR", get_exe_dir()); - menu->curpath = replace_vars(menu->curpath, vars, 1); - tern_free(vars); - - } + menu_context *menu = get_menu(gen); if (menu->state) { uint32_t dst = menu->latch << 16 | value; switch (address >> 2) @@ -375,6 +390,7 @@ } copy_to_guest(m68k, dst, buffer, cur-buffer); break; + } case 5: //save state if (gen->header.next_context) { @@ -405,7 +421,9 @@ } m68k->should_return = 1; break; - } + case 7: + //read only port + break; default: fprintf(stderr, "WARNING: write to undefined menu port %X\n", address); } diff -r 2b34469e3f81 -r 9a3e003bdcb3 menu.h --- a/menu.h Fri Jun 30 00:36:18 2017 -0700 +++ b/menu.h Fri Jun 30 18:42:52 2017 -0700 @@ -9,6 +9,7 @@ char *curpath; uint16_t latch; uint16_t state; + uint8_t external_game_load; } menu_context; diff -r 2b34469e3f81 -r 9a3e003bdcb3 menu.s68 --- a/menu.s68 Fri Jun 30 00:36:18 2017 -0700 +++ b/menu.s68 Fri Jun 30 18:42:52 2017 -0700 @@ -214,6 +214,10 @@ move.b d1, d0 move.l d0, (a1) startdma $C000, VDP_VRAM_WRITE + + move.w (menu_port+4*7), d0 + btst #0, d0 + bne show_pause_menu ;read gamepad/mouse in port 1 lea PAD1_DATA, a2