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