Search
lxdream.org :: lxdream :: r15:5194dd0fdb60
lxdream 0.9.1
released Jun 29
Download Now
changeset15:5194dd0fdb60
parent14:fc481a638848
child16:f383e7640da4
authornkeynes
dateMon Dec 12 13:11:11 2005 +0000 (18 years ago)
Add dreamcast_module module structure
src/aica/aica.c
src/asic.c
src/dreamcast.c
src/dreamcast.h
src/gdrom/ide.c
src/maple/maple.c
src/maple/maple.h
src/mem.c
src/modules.h
src/pvr2/pvr2.c
src/sh4/sh4core.c
1.1 --- a/src/aica/aica.c Mon Dec 12 10:37:41 2005 +0000
1.2 +++ b/src/aica/aica.c Mon Dec 12 13:11:11 2005 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: aica.c,v 1.1 2005-12-11 12:00:09 nkeynes Exp $
1.6 + * $Id: aica.c,v 1.2 2005-12-12 13:11:11 nkeynes Exp $
1.7 *
1.8 * This is the core sound system (ie the bit which does the actual work)
1.9 *
1.10 @@ -17,6 +17,8 @@
1.11 */
1.12
1.13 #include "dream.h"
1.14 +#include "modules.h"
1.15 +#include "mem.h"
1.16 #include "aica.h"
1.17 #define MMIO_IMPL
1.18 #include "aica.h"
1.19 @@ -25,11 +27,16 @@
1.20 MMIO_REGION_READ_DEFFN( AICA1 )
1.21 MMIO_REGION_READ_DEFFN( AICA2 )
1.22
1.23 +struct dreamcast_module aica_module = { "AICA", aica_init, aica_reset, NULL, NULL,
1.24 + NULL, NULL };
1.25 +
1.26 /**
1.27 * Initialize the AICA subsystem. Note requires that
1.28 */
1.29 void aica_init( void )
1.30 {
1.31 + mem_create_ram_region( 0x00800000, 2 MB, MEM_REGION_AUDIO );
1.32 + mem_create_ram_region( 0x00703000, 8 KB, MEM_REGION_AUDIO_SCRATCH ); /*???*/
1.33 register_io_regions( mmio_list_spu );
1.34 MMIO_NOTRACE(AICA0);
1.35 MMIO_NOTRACE(AICA1);
2.1 --- a/src/asic.c Mon Dec 12 10:37:41 2005 +0000
2.2 +++ b/src/asic.c Mon Dec 12 13:11:11 2005 +0000
2.3 @@ -2,10 +2,11 @@
2.4 #include "dream.h"
2.5 #include "mem.h"
2.6 #include "sh4/intc.h"
2.7 -#include "asic.h"
2.8 #include "dreamcast.h"
2.9 +#include "modules.h"
2.10 #include "maple.h"
2.11 #include "ide.h"
2.12 +#include "asic.h"
2.13 #define MMIO_IMPL
2.14 #include "asic.h"
2.15 /*
2.16 @@ -20,6 +21,9 @@
2.17 * practically nothing is publicly known...
2.18 */
2.19
2.20 +struct dreamcast_module asic_module = { "ASIC", asic_init, NULL, NULL, NULL,
2.21 + NULL, NULL };
2.22 +
2.23 void asic_init( void )
2.24 {
2.25 register_io_region( &mmio_region_ASIC );
3.1 --- a/src/dreamcast.c Mon Dec 12 10:37:41 2005 +0000
3.2 +++ b/src/dreamcast.c Mon Dec 12 13:11:11 2005 +0000
3.3 @@ -4,35 +4,110 @@
3.4 #include "asic.h"
3.5 #include "ide.h"
3.6 #include "dreamcast.h"
3.7 +#include "modules.h"
3.8 +
3.9 /* Central switchboard for the system */
3.10
3.11 +#define MAX_MODULES 32
3.12 +static int num_modules = 0;
3.13 +static int dreamcast_state = 0;
3.14 +dreamcast_module_t modules[];
3.15 +
3.16 +void dreamcast_configure( )
3.17 +{
3.18 + dreamcast_register_module( &mem_module );
3.19 + dreamcast_register_module( &sh4_module );
3.20 + dreamcast_register_module( &asic_module );
3.21 + dreamcast_register_module( &pvr2_module );
3.22 + dreamcast_register_module( &aica_module );
3.23 + dreamcast_register_module( &maple_module );
3.24 + dreamcast_register_module( &ide_module );
3.25 +}
3.26 +
3.27 +void dreamcast_register_module( dreamcast_module_t module )
3.28 +{
3.29 + modules[num_modules++] = module;
3.30 +}
3.31 +
3.32 +
3.33 void dreamcast_init( void )
3.34 {
3.35 - mem_init();
3.36 - mem_create_ram_region( 0x0C000000, 16 MB, MEM_REGION_MAIN );
3.37 - mem_create_ram_region( 0x05000000, 8 MB, MEM_REGION_VIDEO );
3.38 - mem_create_ram_region( 0x00800000, 2 MB, MEM_REGION_AUDIO );
3.39 - mem_create_ram_region( 0x00703000, 8 KB, MEM_REGION_AUDIO_SCRATCH ); /*???*/
3.40 + int i;
3.41 + dreamcast_configure();
3.42 + for( i=0; i<num_modules; i++ ) {
3.43 + if( modules[i]->init != NULL )
3.44 + modules[i]->init();
3.45 + }
3.46 mem_load_rom( "dcboot.rom", 0x00000000, 0x00200000, 0x89f2b1a1 );
3.47 mem_load_rom( "dcflash.rom",0x00200000, 0x00020000, 0x357c3568 );
3.48 -
3.49 - sh4_init();
3.50 - asic_init();
3.51 - pvr2_init();
3.52 - aica_init();
3.53 - ide_reset();
3.54 -
3.55 }
3.56
3.57 void dreamcast_reset( void )
3.58 {
3.59 - sh4_reset();
3.60 - mem_reset();
3.61 -// pvr2_reset();
3.62 - aica_reset();
3.63 + int i;
3.64 + for( i=0; i<num_modules; i++ ) {
3.65 + if( modules[i]->reset != NULL )
3.66 + modules[i]->reset();
3.67 + }
3.68 }
3.69
3.70 +void dreamcast_start( void )
3.71 +{
3.72 + int i;
3.73 + for( i=0; i<num_modules; i++ ) {
3.74 + if( modules[i]->start != NULL )
3.75 + modules[i]->start();
3.76 + }
3.77 +}
3.78 void dreamcast_stop( void )
3.79 {
3.80 - sh4_stop();
3.81 + int i;
3.82 + for( i=0; i<num_modules; i++ ) {
3.83 + if( modules[i]->stop != NULL )
3.84 + modules[i]->stop();
3.85 + }
3.86 }
3.87 +
3.88 +struct save_state_header {
3.89 + char magic[16];
3.90 + uint32_t version;
3.91 +};
3.92 +
3.93 +void dreamcast_load_state( FILE *f )
3.94 +{
3.95 + int i;
3.96 + struct save_state_header header;
3.97 +
3.98 + fread( &header, sizeof(header), 1, f );
3.99 + if( strncmp( header.magic, DREAMCAST_SAVE_MAGIC, 16 ) != 0 ) {
3.100 + ERROR( "Not a DreamOn save state file" );
3.101 + return;
3.102 + }
3.103 + if( header.version != DREAMCAST_SAVE_VERSION ) {
3.104 + ERROR( "DreamOn save state version not supported" );
3.105 + return;
3.106 + }
3.107 +
3.108 + for( i=0; i<num_modules; i++ ) {
3.109 + if( modules[i]->load != NULL )
3.110 + modules[i]->load(f);
3.111 + else if( modules[i]->reset != NULL )
3.112 + modules[i]->reset();
3.113 + }
3.114 +}
3.115 +
3.116 +void dreamcast_save_state( FILE *f )
3.117 +{
3.118 + int i;
3.119 + struct save_state_header header;
3.120 +
3.121 + strcpy( header.magic, DREAMCAST_SAVE_MAGIC );
3.122 + header.version = DREAMCAST_SAVE_VERSION;
3.123 + fwrite( &header, sizeof(header), 1, f );
3.124 + for( i=0; i<num_modules; i++ ) {
3.125 + if( modules[i]->save != NULL ) {
3.126 + modules[i]->save(f);
3.127 + }
3.128 + }
3.129 +}
3.130 +
4.1 --- a/src/dreamcast.h Mon Dec 12 10:37:41 2005 +0000
4.2 +++ b/src/dreamcast.h Mon Dec 12 13:11:11 2005 +0000
4.3 @@ -2,8 +2,25 @@
4.4 #ifndef dreamcast_H
4.5 #define dreamcast_H 1
4.6
4.7 +#include <stdlib.h>
4.8 +#include <stdio.h>
4.9 +
4.10 +#ifdef __cplusplus
4.11 +extern "C" {
4.12 +#endif
4.13 +
4.14 void dreamcast_init(void);
4.15 void dreamcast_reset(void);
4.16 void dreamcast_stop(void);
4.17
4.18 +#define DREAMCAST_SAVE_MAGIC "%!-DreamOn!Save\0"
4.19 +#define DREAMCAST_SAVE_VERSION 0x00010000
4.20 +
4.21 +void dreamcast_save_state( FILE *f );
4.22 +void dreamcast_load_state( FILE *f );
4.23 +
4.24 +#ifdef __cplusplus
4.25 +}
4.26 +#endif
4.27 +
4.28 #endif /* !dream_machine_H */
5.1 --- a/src/gdrom/ide.c Mon Dec 12 10:37:41 2005 +0000
5.2 +++ b/src/gdrom/ide.c Mon Dec 12 13:11:11 2005 +0000
5.3 @@ -5,10 +5,17 @@
5.4 * under the terms of the GNU General Public License version 2 or later.
5.5 */
5.6 #include <stdlib.h>
5.7 +#include "modules.h"
5.8 #include "ide.h"
5.9
5.10 #define MAX_WRITE_BUF 4096;
5.11
5.12 +void ide_init( void );
5.13 +void ide_init( void );
5.14 +
5.15 +struct dreamcast_module ide_module = { "IDE", ide_init, ide_reset, NULL, NULL,
5.16 + NULL, NULL };
5.17 +
5.18 struct ide_registers idereg;
5.19
5.20 static char command_buffer[12];
5.21 @@ -45,6 +52,11 @@
5.22 /* TODO */
5.23 }
5.24
5.25 +void ide_init( void )
5.26 +{
5.27 +
5.28 +}
5.29 +
5.30 void ide_reset( void )
5.31 {
5.32 ide_clear_interrupt();
6.1 --- a/src/maple/maple.c Mon Dec 12 10:37:41 2005 +0000
6.2 +++ b/src/maple/maple.c Mon Dec 12 13:11:11 2005 +0000
6.3 @@ -1,9 +1,20 @@
6.4 #include <assert.h>
6.5 #include "dream.h"
6.6 +#include "modules.h"
6.7 #include "mem.h"
6.8 #include "asic.h"
6.9 #include "maple.h"
6.10
6.11 +void maple_init( void );
6.12 +
6.13 +struct dreamcast_module maple_module = { "Maple", maple_init, NULL, NULL, NULL,
6.14 + NULL, NULL };
6.15 +
6.16 +void maple_init( void )
6.17 +{
6.18 +
6.19 +}
6.20 +
6.21 /**
6.22 * Input data looks like this:
6.23 * 0: transfer control word
7.1 --- a/src/maple/maple.h Mon Dec 12 10:37:41 2005 +0000
7.2 +++ b/src/maple/maple.h Mon Dec 12 13:11:11 2005 +0000
7.3 @@ -44,13 +44,13 @@
7.4 int (*reset)(struct maple_device *dev);
7.5 int (*shutdown)(struct maple_device *dev);
7.6 int (*get_condition)(struct maple_device *dev,
7.7 - int function, char *outbuf, int *buflen);
7.8 + int function, unsigned char *outbuf, int *buflen);
7.9 int (*set_condition)(struct maple_device *dev,
7.10 - int function, char *inbuf, int buflen);
7.11 + int function, unsigned char *inbuf, int buflen);
7.12 int (*read_block)(struct maple_device *dev,
7.13 - int function, uint32_t block, char *outbuf, int *buflen);
7.14 + int function, uint32_t block, unsigned char *outbuf, int *buflen);
7.15 int (*write_block)(struct maple_device *dev,
7.16 - int function, uint32_t block, char *inbuf, int buflen);
7.17 + int function, uint32_t block, unsigned char *inbuf, int buflen);
7.18 void (*attach)(struct maple_device *dev);
7.19 void (*detach)(struct maple_device *dev);
7.20 } *maple_device_t;
8.1 --- a/src/mem.c Mon Dec 12 10:37:41 2005 +0000
8.2 +++ b/src/mem.c Mon Dec 12 13:11:11 2005 +0000
8.3 @@ -1,5 +1,5 @@
8.4 /**
8.5 - * $Id: mem.c,v 1.2 2005-12-11 12:00:03 nkeynes Exp $
8.6 + * $Id: mem.c,v 1.3 2005-12-12 13:11:07 nkeynes Exp $
8.7 * mem.c is responsible for creating and maintaining the overall system memory
8.8 * map, as visible from the SH4 processor.
8.9 *
8.10 @@ -29,10 +29,14 @@
8.11 #include "dream.h"
8.12 #include "mem.h"
8.13 #include "mmio.h"
8.14 +#include "modules.h"
8.15 #include "dreamcast.h"
8.16
8.17 char **page_map = NULL;
8.18
8.19 +struct dreamcast_module mem_module =
8.20 + { "MEM", mem_init, mem_reset, NULL, NULL, NULL, NULL };
8.21 +
8.22 struct mem_region mem_rgn[MAX_MEM_REGIONS];
8.23 struct mmio_region *io_rgn[MAX_IO_REGIONS];
8.24 struct mmio_region *P4_io[4096];
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
9.2 +++ b/src/modules.h Mon Dec 12 13:11:11 2005 +0000
9.3 @@ -0,0 +1,64 @@
9.4 +
9.5 +#ifndef dreamcast_modules_H
9.6 +#define dreamcast_modules_H 1
9.7 +
9.8 +#include <stdlib.h>
9.9 +#include <stdio.h>
9.10 +
9.11 +#ifdef __cplusplus
9.12 +extern "C" {
9.13 +#endif
9.14 +
9.15 +/**
9.16 + * Basic module structure defining the common operations across all
9.17 + * modules, ie start, stop, reset, etc. Nothing here is time-sensitive.
9.18 + */
9.19 +typedef struct dreamcast_module {
9.20 + char *name;
9.21 + /**
9.22 + * Perform all initial module setup (ie register / allocate any
9.23 + * memory required, etc). Only called once during DreamOn startup
9.24 + */
9.25 + void (*init)();
9.26 + /**
9.27 + * Reset the module into it's initial system boot state. Will be called
9.28 + * once after init(), as well as whenever the user requests a reset.
9.29 + */
9.30 + void (*reset)();
9.31 + /**
9.32 + * Set the module into a running state (may be NULL)
9.33 + */
9.34 + void (*start)();
9.35 + /**
9.36 + * Set the module into a stopped state (may be NULL)
9.37 + */
9.38 + void (*stop)();
9.39 + /**
9.40 + * Save the module state to the FILE stream. May be NULL, in which case
9.41 + * the module is considered to have no state.
9.42 + */
9.43 + void (*save)(FILE *);
9.44 + /**
9.45 + * Load the saved module state from the FILE stream. May be NULL, in which
9.46 + * case reset() will be called instead.
9.47 + */
9.48 + void (*load)(FILE *);
9.49 +} *dreamcast_module_t;
9.50 +
9.51 +void dreamcast_register_module( dreamcast_module_t );
9.52 +
9.53 +extern struct dreamcast_module mem_module;
9.54 +extern struct dreamcast_module sh4_module;
9.55 +extern struct dreamcast_module asic_module;
9.56 +extern struct dreamcast_module pvr2_module;
9.57 +extern struct dreamcast_module aica_module;
9.58 +extern struct dreamcast_module ide_module;
9.59 +extern struct dreamcast_module maple_module;
9.60 +extern struct dreamcast_module pvr2_module;
9.61 +extern struct dreamcast_module gui_module;
9.62 +
9.63 +#ifdef __cplusplus
9.64 +}
9.65 +#endif
9.66 +
9.67 +#endif /* !dreamcast_modules_H */
10.1 --- a/src/pvr2/pvr2.c Mon Dec 12 10:37:41 2005 +0000
10.2 +++ b/src/pvr2/pvr2.c Mon Dec 12 13:11:11 2005 +0000
10.3 @@ -2,14 +2,21 @@
10.4 #include "video.h"
10.5 #include "mem.h"
10.6 #include "asic.h"
10.7 +#include "modules.h"
10.8 #include "pvr2.h"
10.9 #define MMIO_IMPL
10.10 #include "pvr2.h"
10.11
10.12 char *video_base;
10.13
10.14 +void pvr2_init( void );
10.15 +
10.16 +struct dreamcast_module pvr2_module = { "PVR2", pvr2_init, NULL, NULL, NULL,
10.17 + NULL, NULL };
10.18 +
10.19 void pvr2_init( void )
10.20 {
10.21 + mem_create_ram_region( 0x05000000, 8 MB, MEM_REGION_VIDEO );
10.22 register_io_region( &mmio_region_PVR2 );
10.23 video_base = mem_get_region_by_name( MEM_REGION_VIDEO );
10.24 }
11.1 --- a/src/sh4/sh4core.c Mon Dec 12 10:37:41 2005 +0000
11.2 +++ b/src/sh4/sh4core.c Mon Dec 12 13:11:11 2005 +0000
11.3 @@ -1,16 +1,21 @@
11.4 #include <math.h>
11.5 #include "dream.h"
11.6 +#include "modules.h"
11.7 #include "sh4core.h"
11.8 #include "sh4mmio.h"
11.9 #include "mem.h"
11.10 #include "intc.h"
11.11
11.12 +struct dreamcast_module sh4_module = { "SH4", sh4_init, sh4_reset,
11.13 + NULL, sh4_stop,
11.14 + NULL, NULL };
11.15 +
11.16 struct sh4_registers sh4r;
11.17 -
11.18 static int running = 0;
11.19
11.20 void sh4_init(void)
11.21 {
11.22 + mem_create_ram_region( 0x0C000000, 16 MB, MEM_REGION_MAIN );
11.23 register_io_regions( mmio_list_sh4mmio );
11.24 mmu_init();
11.25 }
.