Search
lxdream.org :: lxdream/src/dreamcast.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/dreamcast.c
changeset 15:5194dd0fdb60
prev11:0a82ef380c45
next16:f383e7640da4
author nkeynes
date Mon Dec 12 13:11:11 2005 +0000 (16 years ago)
permissions -rw-r--r--
last change Add dreamcast_module module structure
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 "modules.h"
     9 /* Central switchboard for the system */
    11 #define MAX_MODULES 32
    12 static int num_modules = 0;
    13 static int dreamcast_state = 0;
    14 dreamcast_module_t modules[];
    16 void dreamcast_configure( )
    17 {
    18     dreamcast_register_module( &mem_module );
    19     dreamcast_register_module( &sh4_module );
    20     dreamcast_register_module( &asic_module );
    21     dreamcast_register_module( &pvr2_module );
    22     dreamcast_register_module( &aica_module );
    23     dreamcast_register_module( &maple_module );
    24     dreamcast_register_module( &ide_module );
    25 }
    27 void dreamcast_register_module( dreamcast_module_t module ) 
    28 {
    29     modules[num_modules++] = module;
    30 }
    33 void dreamcast_init( void )
    34 {
    35     int i;
    36     dreamcast_configure();
    37     for( i=0; i<num_modules; i++ ) {
    38 	if( modules[i]->init != NULL )
    39 	    modules[i]->init();
    40     }
    41     mem_load_rom( "dcboot.rom", 0x00000000, 0x00200000, 0x89f2b1a1 );
    42     mem_load_rom( "dcflash.rom",0x00200000, 0x00020000, 0x357c3568 );
    43 }
    45 void dreamcast_reset( void )
    46 {
    47     int i;
    48     for( i=0; i<num_modules; i++ ) {
    49 	if( modules[i]->reset != NULL )
    50 	    modules[i]->reset();
    51     }
    52 }
    54 void dreamcast_start( void )
    55 {
    56     int i;
    57     for( i=0; i<num_modules; i++ ) {
    58 	if( modules[i]->start != NULL )
    59 	    modules[i]->start();
    60     }
    61 }
    62 void dreamcast_stop( void )
    63 {
    64     int i;
    65     for( i=0; i<num_modules; i++ ) {
    66 	if( modules[i]->stop != NULL )
    67 	    modules[i]->stop();
    68     }
    69 }
    71 struct save_state_header {
    72     char magic[16];
    73     uint32_t version;
    74 };
    76 void dreamcast_load_state( FILE *f )
    77 {
    78     int i;
    79     struct save_state_header header;
    81     fread( &header, sizeof(header), 1, f );
    82     if( strncmp( header.magic, DREAMCAST_SAVE_MAGIC, 16 ) != 0 ) {
    83 	ERROR( "Not a DreamOn save state file" );
    84 	return;
    85     }
    86     if( header.version != DREAMCAST_SAVE_VERSION ) {
    87 	ERROR( "DreamOn save state version not supported" );
    88 	return;
    89     }
    91     for( i=0; i<num_modules; i++ ) {
    92 	if( modules[i]->load != NULL )
    93 	    modules[i]->load(f);
    94 	else if( modules[i]->reset != NULL )
    95 	    modules[i]->reset();
    96     }
    97 }
    99 void dreamcast_save_state( FILE *f )
   100 {
   101     int i;
   102     struct save_state_header header;
   104     strcpy( header.magic, DREAMCAST_SAVE_MAGIC );
   105     header.version = DREAMCAST_SAVE_VERSION;
   106     fwrite( &header, sizeof(header), 1, f );
   107     for( i=0; i<num_modules; i++ ) {
   108 	if( modules[i]->save != NULL ) {
   109 	    modules[i]->save(f);
   110 	}
   111     }
   112 }
.