summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--blastem.c56
-rw-r--r--menu.c66
-rw-r--r--menu.h1
-rw-r--r--menu.s684
4 files changed, 81 insertions, 46 deletions
diff --git a/blastem.c b/blastem.c
index 3404d37..9a1b01c 100644
--- a/blastem.c
+++ b/blastem.c
@@ -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_state_path;
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 @@ static void on_drag_drop(const char *filename)
}
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 @@ int main(int argc, char ** argv)
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 @@ int main(int argc, char ** argv)
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 @@ int main(int argc, char ** argv)
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 --git a/menu.c b/menu.c
index aed7f54..f92bccf 100644
--- a/menu.c
+++ b/menu.c
@@ -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
+static menu_context *get_menu(genesis_context *gen)
+{
+ 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 * context)
+uint16_t menu_read_w(uint32_t address, void * vcontext)
{
- //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;
+ 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 @@ void * menu_write_w(uint32_t address, void * context, uint16_t value)
{
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 @@ void * menu_write_w(uint32_t address, void * context, uint16_t value)
}
copy_to_guest(m68k, dst, buffer, cur-buffer);
break;
+ }
case 5:
//save state
if (gen->header.next_context) {
@@ -405,7 +421,9 @@ void * menu_write_w(uint32_t address, void * context, uint16_t value)
}
m68k->should_return = 1;
break;
- }
+ case 7:
+ //read only port
+ break;
default:
fprintf(stderr, "WARNING: write to undefined menu port %X\n", address);
}
diff --git a/menu.h b/menu.h
index 11b5201..f558d0d 100644
--- a/menu.h
+++ b/menu.h
@@ -9,6 +9,7 @@ typedef struct {
char *curpath;
uint16_t latch;
uint16_t state;
+ uint8_t external_game_load;
} menu_context;
diff --git a/menu.s68 b/menu.s68
index 9eb8160..68c1442 100644
--- a/menu.s68
+++ b/menu.s68
@@ -214,6 +214,10 @@ int_6:
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