Search
lxdream.org :: lxdream/src/dreamcast.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/dreamcast.c
changeset 543:361ec0a70cf2
prev480:d28c2992f5ee
next561:533f6b478071
next586:2a3ba82cf243
author nkeynes
date Thu Nov 22 11:10:15 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change Re-add "Load Binary" menu item (misplaced in GUI rewrite)
Prevent running with no code loaded
file annotate diff log raw
1.1 --- a/src/dreamcast.c Wed Oct 31 11:53:35 2007 +0000
1.2 +++ b/src/dreamcast.c Thu Nov 22 11:10:15 2007 +0000
1.3 @@ -18,6 +18,7 @@
1.4 */
1.5
1.6 #include <errno.h>
1.7 +#include <glib.h>
1.8 #include "dream.h"
1.9 #include "config.h"
1.10 #include "mem.h"
1.11 @@ -30,13 +31,14 @@
1.12 /**
1.13 * Current state of the DC virtual machine
1.14 */
1.15 -#define STATE_UNINIT 0
1.16 -#define STATE_RUNNING 1
1.17 -#define STATE_STOPPING 2
1.18 -#define STATE_STOPPED 3
1.19 -static volatile int dreamcast_state = STATE_UNINIT;
1.20 +typedef enum { STATE_UNINIT=0, STATE_RUNNING,
1.21 + STATE_STOPPING, STATE_STOPPED } dreamcast_state_t;
1.22 +
1.23 +static volatile dreamcast_state_t dreamcast_state = STATE_UNINIT;
1.24 +static gboolean dreamcast_has_bios = FALSE;
1.25 +static gchar *dreamcast_program_name = NULL;
1.26 +static sh4addr_t dreamcast_entry_point = 0xA0000000;
1.27 static uint32_t timeslice_length = DEFAULT_TIMESLICE_LENGTH;
1.28 -const char *dreamcast_config = "DEFAULT";
1.29
1.30 #define MAX_MODULES 32
1.31 static int num_modules = 0;
1.32 @@ -67,8 +69,9 @@
1.33 mem_create_ram_region( 0x00800000, 2 MB, MEM_REGION_AUDIO );
1.34 mem_create_ram_region( 0x00703000, 8 KB, MEM_REGION_AUDIO_SCRATCH );
1.35 mem_create_ram_region( 0x05000000, 8 MB, MEM_REGION_VIDEO );
1.36 - mem_load_rom( lxdream_get_config_value(CONFIG_BIOS_PATH),
1.37 - 0x00000000, 0x00200000, 0x89f2b1a1, MEM_REGION_BIOS );
1.38 + dreamcast_has_bios = mem_load_rom( lxdream_get_config_value(CONFIG_BIOS_PATH),
1.39 + 0x00000000, 0x00200000, 0x89f2b1a1,
1.40 + MEM_REGION_BIOS );
1.41 mem_create_ram_region( 0x00200000, 0x00020000, MEM_REGION_FLASH );
1.42 mem_load_block( lxdream_get_config_value(CONFIG_FLASH_PATH),
1.43 0x00200000, 0x00020000 );
1.44 @@ -84,8 +87,9 @@
1.45
1.46 void dreamcast_config_changed(void)
1.47 {
1.48 - mem_load_rom( lxdream_get_config_value(CONFIG_BIOS_PATH),
1.49 - 0x00000000, 0x00200000, 0x89f2b1a1, MEM_REGION_BIOS );
1.50 + dreamcast_has_bios = mem_load_rom( lxdream_get_config_value(CONFIG_BIOS_PATH),
1.51 + 0x00000000, 0x00200000, 0x89f2b1a1,
1.52 + MEM_REGION_BIOS );
1.53 mem_load_block( lxdream_get_config_value(CONFIG_FLASH_PATH),
1.54 0x00200000, 0x00020000 );
1.55 }
1.56 @@ -207,11 +211,32 @@
1.57 dreamcast_save_flash();
1.58 }
1.59
1.60 +void dreamcast_program_loaded( const gchar *name, sh4addr_t entry_point )
1.61 +{
1.62 + if( dreamcast_program_name != NULL ) {
1.63 + g_free(dreamcast_program_name);
1.64 + }
1.65 + dreamcast_program_name = g_strdup(name);
1.66 + dreamcast_entry_point = entry_point;
1.67 + sh4_set_pc(entry_point);
1.68 + if( !dreamcast_has_bios ) {
1.69 + bios_install();
1.70 + }
1.71 + dcload_install();
1.72 + gui_update_state();
1.73 +}
1.74 +
1.75 gboolean dreamcast_is_running( void )
1.76 {
1.77 return dreamcast_state == STATE_RUNNING;
1.78 }
1.79
1.80 +gboolean dreamcast_can_run(void)
1.81 +{
1.82 + return dreamcast_state != STATE_UNINIT &&
1.83 + (dreamcast_has_bios || dreamcast_program_name != NULL);
1.84 +}
1.85 +
1.86 /********************************* Save States *****************************/
1.87
1.88 struct save_state_header {
.