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 (15 years ago)
permissions -rw-r--r--
last change Add dreamcast_module module structure
file annotate diff log raw
nkeynes@2
     1
#include "dream.h"
nkeynes@2
     2
#include "mem.h"
nkeynes@11
     3
#include "aica/aica.h"
nkeynes@2
     4
#include "asic.h"
nkeynes@2
     5
#include "ide.h"
nkeynes@2
     6
#include "dreamcast.h"
nkeynes@15
     7
#include "modules.h"
nkeynes@15
     8
nkeynes@2
     9
/* Central switchboard for the system */
nkeynes@2
    10
nkeynes@15
    11
#define MAX_MODULES 32
nkeynes@15
    12
static int num_modules = 0;
nkeynes@15
    13
static int dreamcast_state = 0;
nkeynes@15
    14
dreamcast_module_t modules[];
nkeynes@15
    15
nkeynes@15
    16
void dreamcast_configure( )
nkeynes@15
    17
{
nkeynes@15
    18
    dreamcast_register_module( &mem_module );
nkeynes@15
    19
    dreamcast_register_module( &sh4_module );
nkeynes@15
    20
    dreamcast_register_module( &asic_module );
nkeynes@15
    21
    dreamcast_register_module( &pvr2_module );
nkeynes@15
    22
    dreamcast_register_module( &aica_module );
nkeynes@15
    23
    dreamcast_register_module( &maple_module );
nkeynes@15
    24
    dreamcast_register_module( &ide_module );
nkeynes@15
    25
}
nkeynes@15
    26
nkeynes@15
    27
void dreamcast_register_module( dreamcast_module_t module ) 
nkeynes@15
    28
{
nkeynes@15
    29
    modules[num_modules++] = module;
nkeynes@15
    30
}
nkeynes@15
    31
nkeynes@15
    32
nkeynes@2
    33
void dreamcast_init( void )
nkeynes@2
    34
{
nkeynes@15
    35
    int i;
nkeynes@15
    36
    dreamcast_configure();
nkeynes@15
    37
    for( i=0; i<num_modules; i++ ) {
nkeynes@15
    38
	if( modules[i]->init != NULL )
nkeynes@15
    39
	    modules[i]->init();
nkeynes@15
    40
    }
nkeynes@11
    41
    mem_load_rom( "dcboot.rom", 0x00000000, 0x00200000, 0x89f2b1a1 );
nkeynes@11
    42
    mem_load_rom( "dcflash.rom",0x00200000, 0x00020000, 0x357c3568 );
nkeynes@2
    43
}
nkeynes@2
    44
nkeynes@2
    45
void dreamcast_reset( void )
nkeynes@2
    46
{
nkeynes@15
    47
    int i;
nkeynes@15
    48
    for( i=0; i<num_modules; i++ ) {
nkeynes@15
    49
	if( modules[i]->reset != NULL )
nkeynes@15
    50
	    modules[i]->reset();
nkeynes@15
    51
    }
nkeynes@2
    52
}
nkeynes@2
    53
nkeynes@15
    54
void dreamcast_start( void )
nkeynes@15
    55
{
nkeynes@15
    56
    int i;
nkeynes@15
    57
    for( i=0; i<num_modules; i++ ) {
nkeynes@15
    58
	if( modules[i]->start != NULL )
nkeynes@15
    59
	    modules[i]->start();
nkeynes@15
    60
    }
nkeynes@15
    61
}
nkeynes@2
    62
void dreamcast_stop( void )
nkeynes@2
    63
{
nkeynes@15
    64
    int i;
nkeynes@15
    65
    for( i=0; i<num_modules; i++ ) {
nkeynes@15
    66
	if( modules[i]->stop != NULL )
nkeynes@15
    67
	    modules[i]->stop();
nkeynes@15
    68
    }
nkeynes@2
    69
}
nkeynes@15
    70
nkeynes@15
    71
struct save_state_header {
nkeynes@15
    72
    char magic[16];
nkeynes@15
    73
    uint32_t version;
nkeynes@15
    74
};
nkeynes@15
    75
nkeynes@15
    76
void dreamcast_load_state( FILE *f )
nkeynes@15
    77
{
nkeynes@15
    78
    int i;
nkeynes@15
    79
    struct save_state_header header;
nkeynes@15
    80
nkeynes@15
    81
    fread( &header, sizeof(header), 1, f );
nkeynes@15
    82
    if( strncmp( header.magic, DREAMCAST_SAVE_MAGIC, 16 ) != 0 ) {
nkeynes@15
    83
	ERROR( "Not a DreamOn save state file" );
nkeynes@15
    84
	return;
nkeynes@15
    85
    }
nkeynes@15
    86
    if( header.version != DREAMCAST_SAVE_VERSION ) {
nkeynes@15
    87
	ERROR( "DreamOn save state version not supported" );
nkeynes@15
    88
	return;
nkeynes@15
    89
    }
nkeynes@15
    90
nkeynes@15
    91
    for( i=0; i<num_modules; i++ ) {
nkeynes@15
    92
	if( modules[i]->load != NULL )
nkeynes@15
    93
	    modules[i]->load(f);
nkeynes@15
    94
	else if( modules[i]->reset != NULL )
nkeynes@15
    95
	    modules[i]->reset();
nkeynes@15
    96
    }
nkeynes@15
    97
}
nkeynes@15
    98
nkeynes@15
    99
void dreamcast_save_state( FILE *f )
nkeynes@15
   100
{
nkeynes@15
   101
    int i;
nkeynes@15
   102
    struct save_state_header header;
nkeynes@15
   103
    
nkeynes@15
   104
    strcpy( header.magic, DREAMCAST_SAVE_MAGIC );
nkeynes@15
   105
    header.version = DREAMCAST_SAVE_VERSION;
nkeynes@15
   106
    fwrite( &header, sizeof(header), 1, f );
nkeynes@15
   107
    for( i=0; i<num_modules; i++ ) {
nkeynes@15
   108
	if( modules[i]->save != NULL ) {
nkeynes@15
   109
	    modules[i]->save(f);
nkeynes@15
   110
	}
nkeynes@15
   111
    }
nkeynes@15
   112
}
nkeynes@15
   113
.