Search
lxdream.org :: lxdream/src/dreamcast.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/dreamcast.c
changeset 16:f383e7640da4
prev15:5194dd0fdb60
next17:944f75eea496
author nkeynes
date Tue Dec 13 12:17:26 2005 +0000 (14 years ago)
permissions -rw-r--r--
last change Cleanup init config => dreamcast_config
view annotate diff log raw
     1 #include "dream.h"
     2 #include "mem.h"
     3 #include "aica/aica.h"
     4 #include "asic.h"
     5 #include "ide.h"
     6 #include "dreamcast.h"
     7 #include "maple.h"
     8 #include "modules.h"
    10 /* Central switchboard for the system */
    12 #define MAX_MODULES 32
    13 static int num_modules = 0;
    14 static int dreamcast_state = 0;
    15 dreamcast_module_t modules[MAX_MODULES];
    17 /**
    18  * This function is responsible for defining how all the pieces of the
    19  * dreamcast actually fit together. Among other things, this lets us
    20  * (reasonably) easily redefine the structure for eg various versions of the
    21  * Naomi.
    22  *
    23  * Note currently the locations of the various MMIO pages are hard coded in
    24  * the MMIO definitions - they should probably be moved here.
    25  */
    26 void dreamcast_configure( )
    27 {
    28     /* Register the memory framework */
    29     dreamcast_register_module( &mem_module );
    31     /* Setup standard memory map */
    32     mem_create_ram_region( 0x0C000000, 16 MB, MEM_REGION_MAIN );
    33     mem_create_ram_region( 0x00800000, 2 MB, MEM_REGION_AUDIO );
    34     mem_create_ram_region( 0x00703000, 8 KB, MEM_REGION_AUDIO_SCRATCH );
    35     mem_create_ram_region( 0x05000000, 8 MB, MEM_REGION_VIDEO );
    36     mem_load_rom( "dcboot.rom", 0x00000000, 0x00200000, 0x89f2b1a1 );
    37     mem_load_rom( "dcflash.rom",0x00200000, 0x00020000, 0x357c3568 );
    39     /* Load in the rest of the core modules */
    40     dreamcast_register_module( &sh4_module );
    41     dreamcast_register_module( &asic_module );
    42     dreamcast_register_module( &pvr2_module );
    43     dreamcast_register_module( &aica_module );
    44     dreamcast_register_module( &maple_module );
    45     dreamcast_register_module( &ide_module );
    47     /* Attach any default maple devices, ie a pair of controllers */
    48     maple_device_t controller1 = controller_new();
    49     maple_device_t controller2 = controller_new();
    50     maple_attach_device( controller1, 0, 0 );
    51     maple_attach_device( controller2, 1, 0 );
    52 }
    54 void dreamcast_register_module( dreamcast_module_t module ) 
    55 {
    56     modules[num_modules++] = module;
    57     if( module->init != NULL )
    58 	module->init();
    59 }
    62 void dreamcast_init( void )
    63 {
    64     dreamcast_configure();
    65 }
    67 void dreamcast_reset( void )
    68 {
    69     int i;
    70     for( i=0; i<num_modules; i++ ) {
    71 	if( modules[i]->reset != NULL )
    72 	    modules[i]->reset();
    73     }
    74 }
    76 void dreamcast_start( void )
    77 {
    78     int i;
    79     for( i=0; i<num_modules; i++ ) {
    80 	if( modules[i]->start != NULL )
    81 	    modules[i]->start();
    82     }
    83 }
    84 void dreamcast_stop( void )
    85 {
    86     int i;
    87     for( i=0; i<num_modules; i++ ) {
    88 	if( modules[i]->stop != NULL )
    89 	    modules[i]->stop();
    90     }
    91 }
    93 struct save_state_header {
    94     char magic[16];
    95     uint32_t version;
    96 };
    98 void dreamcast_load_state( FILE *f )
    99 {
   100     int i;
   101     struct save_state_header header;
   103     fread( &header, sizeof(header), 1, f );
   104     if( strncmp( header.magic, DREAMCAST_SAVE_MAGIC, 16 ) != 0 ) {
   105 	ERROR( "Not a DreamOn save state file" );
   106 	return;
   107     }
   108     if( header.version != DREAMCAST_SAVE_VERSION ) {
   109 	ERROR( "DreamOn save state version not supported" );
   110 	return;
   111     }
   113     for( i=0; i<num_modules; i++ ) {
   114 	if( modules[i]->load != NULL )
   115 	    modules[i]->load(f);
   116 	else if( modules[i]->reset != NULL )
   117 	    modules[i]->reset();
   118     }
   119 }
   121 void dreamcast_save_state( FILE *f )
   122 {
   123     int i;
   124     struct save_state_header header;
   126     strcpy( header.magic, DREAMCAST_SAVE_MAGIC );
   127     header.version = DREAMCAST_SAVE_VERSION;
   128     fwrite( &header, sizeof(header), 1, f );
   129     for( i=0; i<num_modules; i++ ) {
   130 	if( modules[i]->save != NULL ) {
   131 	    modules[i]->save(f);
   132 	}
   133     }
   134 }
.