Search
lxdream.org :: lxdream/src/dreamcast.c :: diff
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
file annotate diff log raw
1.1 --- a/src/dreamcast.c Sun Dec 11 12:00:09 2005 +0000
1.2 +++ b/src/dreamcast.c Mon Dec 12 13:11:11 2005 +0000
1.3 @@ -4,35 +4,110 @@
1.4 #include "asic.h"
1.5 #include "ide.h"
1.6 #include "dreamcast.h"
1.7 +#include "modules.h"
1.8 +
1.9 /* Central switchboard for the system */
1.10
1.11 +#define MAX_MODULES 32
1.12 +static int num_modules = 0;
1.13 +static int dreamcast_state = 0;
1.14 +dreamcast_module_t modules[];
1.15 +
1.16 +void dreamcast_configure( )
1.17 +{
1.18 + dreamcast_register_module( &mem_module );
1.19 + dreamcast_register_module( &sh4_module );
1.20 + dreamcast_register_module( &asic_module );
1.21 + dreamcast_register_module( &pvr2_module );
1.22 + dreamcast_register_module( &aica_module );
1.23 + dreamcast_register_module( &maple_module );
1.24 + dreamcast_register_module( &ide_module );
1.25 +}
1.26 +
1.27 +void dreamcast_register_module( dreamcast_module_t module )
1.28 +{
1.29 + modules[num_modules++] = module;
1.30 +}
1.31 +
1.32 +
1.33 void dreamcast_init( void )
1.34 {
1.35 - mem_init();
1.36 - mem_create_ram_region( 0x0C000000, 16 MB, MEM_REGION_MAIN );
1.37 - mem_create_ram_region( 0x05000000, 8 MB, MEM_REGION_VIDEO );
1.38 - mem_create_ram_region( 0x00800000, 2 MB, MEM_REGION_AUDIO );
1.39 - mem_create_ram_region( 0x00703000, 8 KB, MEM_REGION_AUDIO_SCRATCH ); /*???*/
1.40 + int i;
1.41 + dreamcast_configure();
1.42 + for( i=0; i<num_modules; i++ ) {
1.43 + if( modules[i]->init != NULL )
1.44 + modules[i]->init();
1.45 + }
1.46 mem_load_rom( "dcboot.rom", 0x00000000, 0x00200000, 0x89f2b1a1 );
1.47 mem_load_rom( "dcflash.rom",0x00200000, 0x00020000, 0x357c3568 );
1.48 -
1.49 - sh4_init();
1.50 - asic_init();
1.51 - pvr2_init();
1.52 - aica_init();
1.53 - ide_reset();
1.54 -
1.55 }
1.56
1.57 void dreamcast_reset( void )
1.58 {
1.59 - sh4_reset();
1.60 - mem_reset();
1.61 -// pvr2_reset();
1.62 - aica_reset();
1.63 + int i;
1.64 + for( i=0; i<num_modules; i++ ) {
1.65 + if( modules[i]->reset != NULL )
1.66 + modules[i]->reset();
1.67 + }
1.68 }
1.69
1.70 +void dreamcast_start( void )
1.71 +{
1.72 + int i;
1.73 + for( i=0; i<num_modules; i++ ) {
1.74 + if( modules[i]->start != NULL )
1.75 + modules[i]->start();
1.76 + }
1.77 +}
1.78 void dreamcast_stop( void )
1.79 {
1.80 - sh4_stop();
1.81 + int i;
1.82 + for( i=0; i<num_modules; i++ ) {
1.83 + if( modules[i]->stop != NULL )
1.84 + modules[i]->stop();
1.85 + }
1.86 }
1.87 +
1.88 +struct save_state_header {
1.89 + char magic[16];
1.90 + uint32_t version;
1.91 +};
1.92 +
1.93 +void dreamcast_load_state( FILE *f )
1.94 +{
1.95 + int i;
1.96 + struct save_state_header header;
1.97 +
1.98 + fread( &header, sizeof(header), 1, f );
1.99 + if( strncmp( header.magic, DREAMCAST_SAVE_MAGIC, 16 ) != 0 ) {
1.100 + ERROR( "Not a DreamOn save state file" );
1.101 + return;
1.102 + }
1.103 + if( header.version != DREAMCAST_SAVE_VERSION ) {
1.104 + ERROR( "DreamOn save state version not supported" );
1.105 + return;
1.106 + }
1.107 +
1.108 + for( i=0; i<num_modules; i++ ) {
1.109 + if( modules[i]->load != NULL )
1.110 + modules[i]->load(f);
1.111 + else if( modules[i]->reset != NULL )
1.112 + modules[i]->reset();
1.113 + }
1.114 +}
1.115 +
1.116 +void dreamcast_save_state( FILE *f )
1.117 +{
1.118 + int i;
1.119 + struct save_state_header header;
1.120 +
1.121 + strcpy( header.magic, DREAMCAST_SAVE_MAGIC );
1.122 + header.version = DREAMCAST_SAVE_VERSION;
1.123 + fwrite( &header, sizeof(header), 1, f );
1.124 + for( i=0; i<num_modules; i++ ) {
1.125 + if( modules[i]->save != NULL ) {
1.126 + modules[i]->save(f);
1.127 + }
1.128 + }
1.129 +}
1.130 +
.