Search
lxdream.org :: lxdream/src/dreamcast.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/dreamcast.c
changeset 1279:142110f63902
prev1270:65fd19c07e2e
author nkeynes
date Sun May 24 19:46:06 2015 +1000 (8 years ago)
permissions -rw-r--r--
last change Remove static from gl_load_frame_buffer() - also needed by video_egl.c
Fix error location in gl_frame_buffer_to_tex
view annotate diff log raw
     1 /**
     2  * $Id$
     3  * Central switchboard for the system. This pulls all the individual modules
     4  * together into some kind of coherent structure. This is also where you'd
     5  * add Naomi support, if I ever get a board to play with...
     6  *
     7  * Copyright (c) 2005 Nathan Keynes.
     8  *
     9  * This program is free software; you can redistribute it and/or modify
    10  * it under the terms of the GNU General Public License as published by
    11  * the Free Software Foundation; either version 2 of the License, or
    12  * (at your option) any later version.
    13  *
    14  * This program is distributed in the hope that it will be useful,
    15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    17  * GNU General Public License for more details.
    18  */
    20 #include <errno.h>
    21 #include <glib.h>
    22 #include <unistd.h>
    23 #include "lxdream.h"
    24 #include "lxpaths.h"
    25 #include "dream.h"
    26 #include "eventq.h"
    27 #include "mem.h"
    28 #include "dreamcast.h"
    29 #include "asic.h"
    30 #include "syscall.h"
    31 #include "gui.h"
    32 #include "aica/aica.h"
    33 #include "gdrom/ide.h"
    34 #include "maple/maple.h"
    35 #include "pvr2/pvr2.h"
    36 #include "sh4/sh4.h"
    37 #include "sh4/sh4core.h"
    38 #include "vmu/vmulist.h"
    41 static gboolean dreamcast_load_bios( const gchar *filename );
    43 /**
    44  * Current state of the DC virtual machine
    45  */
    46 typedef enum { STATE_UNINIT=0, STATE_RUNNING, 
    47                STATE_STOPPING, STATE_STOPPED } dreamcast_state_t;
    49 static volatile dreamcast_state_t dreamcast_state = STATE_UNINIT;
    50 static gboolean dreamcast_use_bios = TRUE;
    51 static gboolean dreamcast_has_bios = FALSE;
    52 static gboolean dreamcast_has_flash = FALSE;
    53 static gboolean dreamcast_exit_on_stop = FALSE;
    54 static gchar *dreamcast_program_name = NULL;
    55 static sh4addr_t dreamcast_entry_point = 0xA0000000;
    56 static uint32_t timeslice_length = DEFAULT_TIMESLICE_LENGTH;
    57 static uint64_t run_time_nanosecs = 0;
    58 static unsigned int quick_save_state = -1;
    60 #define MAX_MODULES 32
    61 static int num_modules = 0;
    62 dreamcast_module_t modules[MAX_MODULES];
    64 /**
    65  * The unknown module is used for logging files without an actual module
    66  * declaration
    67  */
    68 struct dreamcast_module unknown_module = { "****", NULL, NULL, NULL, NULL, 
    69         NULL, NULL, NULL };
    71 extern struct mem_region_fn mem_region_sdram;
    72 extern struct mem_region_fn mem_region_vram32;
    73 extern struct mem_region_fn mem_region_vram64;
    74 extern struct mem_region_fn mem_region_audioram;
    75 extern struct mem_region_fn mem_region_audioscratch;
    76 extern struct mem_region_fn mem_region_flashram;
    77 extern struct mem_region_fn mem_region_bootrom;
    78 extern struct mem_region_fn mem_region_pvr2ta;
    79 extern struct mem_region_fn mem_region_pvr2yuv;
    80 extern struct mem_region_fn mem_region_pvr2vdma1;
    81 extern struct mem_region_fn mem_region_pvr2vdma2;
    83 unsigned char dc_main_ram[16 MB];
    84 unsigned char dc_boot_rom[2 MB];
    85 unsigned char dc_flash_ram[128 KB];
    87 /**
    88  * This function is responsible for defining how all the pieces of the
    89  * dreamcast actually fit together. 
    90  *
    91  * Note currently the locations of the various MMIO pages are hard coded in
    92  * the MMIO definitions - they should probably be moved here.
    93  */
    94 void dreamcast_configure( gboolean use_bootrom )
    95 {
    96     char *bios_path = lxdream_get_global_config_path_value(CONFIG_BIOS_PATH);
    97     char *flash_path = lxdream_get_global_config_path_value(CONFIG_FLASH_PATH);
    99     /* Initialize the event queue first */
   100     event_init();
   102     /* Register the memory framework */
   103     dreamcast_register_module( &mem_module );
   105     /* Setup standard memory map */
   106     mem_map_region( dc_boot_rom,     0x00000000, 2 MB,   MEM_REGION_BIOS,         &mem_region_bootrom, MEM_FLAG_ROM, 2 MB, 0 );
   107     mem_map_region( dc_flash_ram,    0x00200000, 128 KB, MEM_REGION_FLASH,        &mem_region_flashram, MEM_FLAG_RAM, 128 KB, 0 );
   108     mem_map_region( aica_main_ram,   0x00800000, 2 MB,   MEM_REGION_AUDIO,        &mem_region_audioram, MEM_FLAG_RAM, 2 MB, 0 );
   109     mem_map_region( aica_scratch_ram,0x00703000, 8 KB,   MEM_REGION_AUDIO_SCRATCH,&mem_region_audioscratch, MEM_FLAG_RAM, 8 KB, 0 );
   110     mem_map_region( NULL,            0x04000000, 8 MB,   MEM_REGION_VIDEO64,      &mem_region_vram64, 0, 8 MB, 0 );
   111     mem_map_region( pvr2_main_ram,   0x05000000, 8 MB,   MEM_REGION_VIDEO,        &mem_region_vram32, MEM_FLAG_RAM, 8 MB, 0 ); 
   112     mem_map_region( dc_main_ram,     0x0C000000, 16 MB,  MEM_REGION_MAIN,         &mem_region_sdram, MEM_FLAG_RAM, 0x01000000, 0x0F000000 );
   113     mem_map_region( NULL,            0x10000000, 8 MB,   MEM_REGION_PVR2TA,       &mem_region_pvr2ta, 0, 0x02000000, 0x12000000 );
   114     mem_map_region( NULL,            0x10800000, 8 MB,   MEM_REGION_PVR2YUV,      &mem_region_pvr2yuv, 0, 0x02000000, 0x12800000 );
   115     mem_map_region( NULL,            0x11000000, 16 MB,  MEM_REGION_PVR2VDMA1,    &mem_region_pvr2vdma1, 0, 16 MB, 0 );
   116     mem_map_region( NULL,            0x13000000, 16 MB,  MEM_REGION_PVR2VDMA2,    &mem_region_pvr2vdma2, 0, 16 MB, 0 );
   118     dreamcast_use_bios = use_bootrom;
   119     dreamcast_has_bios = dreamcast_load_bios( bios_path );
   120     if( !dreamcast_has_bios ) {
   121         dreamcast_load_fakebios();
   122     }
   124     if( flash_path != NULL && flash_path[0] != '\0' ) {
   125         mem_load_block( flash_path, 0x00200000, 0x00020000 );
   126     }
   127     dreamcast_has_flash = TRUE;
   129     /* Load in the rest of the core modules */
   130     dreamcast_register_module( &sh4_module );
   131     dreamcast_register_module( &asic_module );
   132     dreamcast_register_module( &pvr2_module );
   133     dreamcast_register_module( &aica_module );
   134     dreamcast_register_module( &maple_module );
   135     dreamcast_register_module( &ide_module );
   136     dreamcast_register_module( &eventq_module );
   138     g_free(bios_path);
   139     g_free(flash_path);
   140 }
   142 static gboolean dreamcast_load_bios( const gchar *filename )
   143 {
   144     if( dreamcast_use_bios ) {
   145         dreamcast_has_bios = mem_load_rom( dc_boot_rom, filename, 2 MB, 0x89f2b1a1 );
   146     } else {
   147         dreamcast_has_bios = FALSE;
   148     }
   149     return dreamcast_has_bios;
   150 }
   152 static const char fakebios[] = {
   153         0x00, 0xd1, /* movl $+4, r1 */
   154         0x2b, 0x41, /* jmp @r1 */
   155         0xa0, 0xff, /* .long 0xffffffa0 */
   156         0xff, 0xff };
   157 gboolean dreamcast_load_fakebios( )
   158 {
   159     memset( dc_boot_rom, 0, 2 MB );
   160     memcpy( dc_boot_rom, fakebios, sizeof(fakebios) );
   161     syscall_add_hook( 0xA0, bios_boot );
   162     dreamcast_has_bios = TRUE;
   163     return TRUE;
   164 }
   166 gboolean dreamcast_load_flash( const gchar *filename )
   167 {
   168     if( filename != NULL && filename[0] != '\0' ) {
   169         return mem_load_block( filename, 0x00200000, 0x00020000 ) == 0;
   170     }
   171     return FALSE;
   172 }
   175 gboolean dreamcast_config_changed(void *data, struct lxdream_config_group *group, unsigned item,
   176                                        const gchar *oldval, const gchar *newval)
   177 {
   178     gchar *tmp;
   179     switch(item) {
   180     case CONFIG_BIOS_PATH:
   181         tmp = get_expanded_path(newval);
   182         dreamcast_load_bios(tmp);
   183         g_free(tmp);
   184         break;
   185     case CONFIG_FLASH_PATH:
   186         tmp = get_expanded_path(newval);
   187         dreamcast_load_flash(tmp);
   188         g_free(tmp);
   189         break;
   190     }
   191     reset_gui_paths();
   192     return TRUE;
   193 }
   195 void dreamcast_save_flash()
   196 {
   197     if( dreamcast_has_flash ) {
   198         char *file = lxdream_get_global_config_path_value(CONFIG_FLASH_PATH);
   199         mem_save_block( file, 0x00200000, 0x00020000 );
   200         g_free(file);
   201     }
   202 }
   204 /**
   205  * Constructs a system configuration for the AICA in standalone mode,
   206  * ie sound chip only.
   207  */
   208 void dreamcast_configure_aica_only( )
   209 {
   210     dreamcast_register_module( &mem_module );
   211     mem_map_region( aica_main_ram, 0x00800000, 2 MB, MEM_REGION_AUDIO, &mem_region_audioram, MEM_FLAG_RAM, 2 MB, 0 );
   212     mem_map_region( aica_scratch_ram, 0x00703000, 8 KB, MEM_REGION_AUDIO_SCRATCH, &mem_region_audioscratch, MEM_FLAG_RAM, 8 KB, 0 );
   213     dreamcast_register_module( &aica_module );
   214     aica_enable();
   215     dreamcast_state = STATE_STOPPED;
   216 }
   218 void dreamcast_register_module( dreamcast_module_t module ) 
   219 {
   220     assert( num_modules < MAX_MODULES );
   221     modules[num_modules++] = module;
   222     if( module->init != NULL )
   223         module->init();
   224 }
   226 void dreamcast_set_run_time( uint32_t secs, uint32_t nanosecs )
   227 {
   228     run_time_nanosecs = (((uint64_t)secs) * 1000000000) + nanosecs;
   229 }
   231 void dreamcast_set_exit_on_stop( gboolean flag )
   232 {
   233     dreamcast_exit_on_stop = flag;
   234 }
   236 void dreamcast_init( gboolean use_bootrom )
   237 {
   238     dreamcast_configure( use_bootrom );
   239     dreamcast_state = STATE_STOPPED;
   240 }
   242 void dreamcast_reset( void )
   243 {
   244     sh4_core_exit(CORE_EXIT_SYSRESET);
   245     int i;
   246     for( i=0; i<num_modules; i++ ) {
   247         if( modules[i]->reset != NULL )
   248             modules[i]->reset();
   249     }
   250 }
   252 void dreamcast_run( void )
   253 {
   254     int i;
   256     if( !dreamcast_can_run() ) {
   257         ERROR(_("No program is loaded, and no BIOS is configured (required to boot a CD image). To continue, either load a binary program, or set the path to your BIOS file in the Path Preferences"));
   258         return;
   259     }
   261     if( dreamcast_state != STATE_RUNNING ) {
   262         for( i=0; i<num_modules; i++ ) {
   263             if( modules[i]->start != NULL )
   264                 modules[i]->start();
   265         }
   266     }
   268     if( maple_should_grab() ) {
   269         gui_set_use_grab(TRUE);
   270     }
   272     dreamcast_state = STATE_RUNNING;
   274     if( run_time_nanosecs != 0 ) {
   275         while( dreamcast_state == STATE_RUNNING ) {
   276             uint32_t time_to_run = timeslice_length;
   277             if( run_time_nanosecs < time_to_run ) {
   278                 time_to_run = (uint32_t)run_time_nanosecs;
   279             }
   281             for( i=0; i<num_modules; i++ ) {
   282                 if( modules[i]->run_time_slice != NULL )
   283                     time_to_run = modules[i]->run_time_slice( time_to_run );
   284             }
   286             if( run_time_nanosecs > time_to_run ) {
   287                 run_time_nanosecs -= time_to_run;
   288             } else {
   289                 run_time_nanosecs = 0; // Finished
   290                 break;
   291             }
   292         }
   293     } else {
   294         while( dreamcast_state == STATE_RUNNING ) {
   295             int time_to_run = timeslice_length;
   296             for( i=0; i<num_modules; i++ ) {
   297                 if( modules[i]->run_time_slice != NULL )
   298                     time_to_run = modules[i]->run_time_slice( time_to_run );
   299             }
   301         }
   302     }
   304     gui_set_use_grab(FALSE);
   306     for( i=0; i<num_modules; i++ ) {
   307         if( modules[i]->stop != NULL )
   308             modules[i]->stop();
   309     }
   311     vmulist_save_all();
   312     dreamcast_state = STATE_STOPPED;
   314     if( dreamcast_exit_on_stop ) {
   315         dreamcast_shutdown();
   316         exit(0);
   317     }
   318 }
   320 void dreamcast_stop( void )
   321 {
   322     sh4_core_exit(CORE_EXIT_HALT); // returns only if not inside SH4 core
   323     if( dreamcast_state == STATE_RUNNING )
   324         dreamcast_state = STATE_STOPPING;
   325 }
   327 void dreamcast_shutdown()
   328 {
   329     // Don't do a dreamcast_stop - if we're calling this out of SH4 code,
   330     // it's a shutdown-and-quit event
   331     if( dreamcast_state == STATE_RUNNING )
   332         dreamcast_state = STATE_STOPPING;
   333     dreamcast_save_flash();
   334     vmulist_save_all();
   335 #ifdef ENABLE_SH4STATS
   336     sh4_stats_print(stdout);
   337 #endif
   338 }
   340 void dreamcast_program_loaded( const gchar *name, sh4addr_t entry_point )
   341 {
   342     if( dreamcast_program_name != NULL ) {
   343         g_free(dreamcast_program_name);
   344     }
   345     dreamcast_program_name = g_strdup(name);
   346     dreamcast_entry_point = entry_point;
   347     sh4_set_pc(entry_point);
   348     sh4_write_sr( sh4_read_sr() & (~SR_BL) ); /* Unmask interrupts */
   349     bios_install();
   350     dcload_install();
   351     gui_update_state();
   352 }
   354 gboolean dreamcast_is_running( void )
   355 {
   356     return dreamcast_state == STATE_RUNNING;
   357 }
   359 gboolean dreamcast_can_run(void)
   360 {
   361     return dreamcast_state != STATE_UNINIT;
   362 }
   364 /********************************* Save States *****************************/
   366 struct save_state_header {
   367     char magic[16];
   368     uint32_t version;
   369     uint32_t module_count;
   370 };
   372 struct chunk_header {
   373     char marker[4]; /* Always BLCK */
   374     char name[8]; /* Block (module) name */
   375     uint32_t block_length;
   376 };
   378 /**
   379  * Check the save state header to ensure that it is a valid, supported
   380  * file. 
   381  * @return the number of blocks following, or 0 if the file is invalid.
   382  */
   383 int dreamcast_read_save_state_header( FILE *f, char *error, int errorlen )
   384 {
   385     struct save_state_header header;
   386     if( fread( &header, sizeof(header), 1, f ) != 1 ) {
   387         return 0;
   388     }
   389     if( strncmp( header.magic, DREAMCAST_SAVE_MAGIC, 16 ) != 0 ) {
   390     	if( error != NULL )
   391     		snprintf( error, errorlen, _("File is not a %s save state"), APP_NAME );
   392         return 0;
   393     }
   394     if( header.version != DREAMCAST_SAVE_VERSION ) {
   395     	if( error != NULL )
   396     		snprintf( error, errorlen, _("Unsupported %s save state version"), APP_NAME );
   397         return 0;
   398     }
   399     if( header.module_count > MAX_MODULES ) {
   400     	if( error != NULL )
   401     		snprintf( error, errorlen, _("%s save state is corrupted (bad module count)"), APP_NAME );
   402         return 0;
   403     }
   404     return header.module_count;
   405 }
   407 int dreamcast_write_chunk_header( const gchar *name, uint32_t length, FILE *f )
   408 {
   409     struct chunk_header head;
   411     memcpy( head.marker, "BLCK", 4 );
   412     memset( head.name, 0, 8 );
   413     memcpy( head.name, name, strlen(name) );
   414     head.block_length = length;
   415     return fwrite( &head, sizeof(head), 1, f );
   416 }
   419 frame_buffer_t dreamcast_load_preview( const gchar *filename )
   420 {
   421     int i;
   422     FILE *f = fopen( filename, "r" );
   423     if( f == NULL ) return NULL;
   425     int module_count = dreamcast_read_save_state_header(f, NULL, 0);
   426     if( module_count <= 0 ) {
   427         fclose(f);
   428         return NULL;
   429     }
   430     for( i=0; i<module_count; i++ ) {
   431         struct chunk_header head;
   432         if( fread( &head, sizeof(head), 1, f ) != 1 ) {
   433             fclose(f);
   434             return NULL;
   435         }
   436         if( memcmp("BLCK", head.marker, 4) != 0 ) {
   437             fclose(f);
   438             return NULL;
   439         }
   441         if( strcmp("PVR2", head.name) == 0 ) {
   442             uint32_t buf_count;
   443             int has_front;
   444             fread( &buf_count, sizeof(buf_count), 1, f );
   445             fread( &has_front, sizeof(has_front), 1, f );
   446             if( buf_count != 0 && has_front ) {
   447                 frame_buffer_t result = read_png_from_stream(f);
   448                 fclose(f);
   449                 return result;
   450             }
   451             break;
   452         } else {
   453             fseek( f, head.block_length, SEEK_CUR );
   454         }
   455     }
   456     return NULL;
   457 }
   459 gboolean dreamcast_load_state( const gchar *filename )
   460 {
   461     int i,j;
   462     int module_count;
   463     char error[128];
   464     int have_read[MAX_MODULES];
   466     FILE *f = fopen( filename, "r" );
   467     if( f == NULL ) return FALSE;
   469     module_count = dreamcast_read_save_state_header(f, error, sizeof(error));
   470     if( module_count <= 0 ) {
   471     	ERROR( error );
   472         fclose(f);
   473         return FALSE;
   474     }
   476     for( i=0; i<MAX_MODULES; i++ ) {
   477         have_read[i] = 0;
   478     }
   480     for( i=0; i<module_count; i++ ) {
   481         struct chunk_header chunk;
   482         fread( &chunk, sizeof(chunk), 1, f );
   483         if( strncmp(chunk.marker, "BLCK", 4) != 0 ) {
   484             ERROR( "%s save state is corrupted (missing block header %d)", APP_NAME, i );
   485             fclose(f);
   486             return FALSE;
   487         }
   489         /* Find the matching module by name */
   490         for( j=0; j<num_modules; j++ ) {
   491             if( strcmp(modules[j]->name,chunk.name) == 0 ) {
   492                 have_read[j] = 1;
   493                 if( modules[j]->load == NULL ) {
   494                     ERROR( "%s save state is corrupted (no loader for %s)", APP_NAME, modules[j]->name );
   495                     fclose(f);
   496                     return FALSE;
   497                 } else if( modules[j]->load(f) != 0 ) {
   498                     ERROR( "%s save state is corrupted (%s failed)", APP_NAME, modules[j]->name );
   499                     fclose(f);
   500                     return FALSE;
   501                 }
   502                 break;
   503             }
   504         }
   505         if( j == num_modules ) {
   506             fclose(f);
   507             ERROR( "%s save state contains unrecognized section", APP_NAME );
   508             return FALSE;
   509         }
   510     }
   512     /* Any modules that we didn't load - reset to the default state.
   513      * (ie it's not an error to skip a module if you don't actually
   514      * care about its state).
   515      */
   516     for( j=0; j<num_modules; j++ ) {
   517         if( have_read[j] == 0 && modules[j]->reset != NULL ) {
   518             modules[j]->reset();
   519         }
   520     }
   521     fclose(f);
   522     INFO( "Save state read from %s", filename );
   523     return TRUE;
   524 }
   526 int dreamcast_save_state( const gchar *filename )
   527 {
   528     int i;
   529     FILE *f;
   530     struct save_state_header header;
   532     f = fopen( filename, "w" );
   533     if( f == NULL )
   534         return errno;
   535     strcpy( header.magic, DREAMCAST_SAVE_MAGIC );
   536     header.version = DREAMCAST_SAVE_VERSION;
   537     header.module_count = 0;
   539     for( i=0; i<num_modules; i++ ) {
   540         if( modules[i]->save != NULL )
   541             header.module_count++;
   542     }
   543     fwrite( &header, sizeof(header), 1, f );
   544     for( i=0; i<num_modules; i++ ) {
   545         if( modules[i]->save != NULL ) {
   546             uint32_t blocklen, posn1, posn2;
   547             dreamcast_write_chunk_header( modules[i]->name, 0, f );
   548             posn1 = ftell(f);
   549             modules[i]->save(f);
   550             posn2 = ftell(f);
   551             blocklen = posn2 - posn1;
   552             fseek( f, posn1-4, SEEK_SET );
   553             fwrite( &blocklen, sizeof(blocklen), 1, f );
   554             fseek( f, posn2, SEEK_SET );
   555         }
   556     }
   557     fclose( f );
   558     INFO( "Save state written to %s", filename );
   559     return 0;
   560 }
   562 /********************** Quick save state support ***********************/
   563 /* This section doesn't necessarily belong here, but it probably makes the
   564  * most sense here next to the regular save/load functions
   565  */
   567 static gchar *get_quick_state_filename( int state )
   568 {
   569     gchar *path = lxdream_get_global_config_path_value(CONFIG_SAVE_PATH);
   570     gchar *str = g_strdup_printf( QUICK_STATE_FILENAME, path, state );
   571     g_free( path );
   572     return str;
   573 }
   576 static void dreamcast_quick_state_init()
   577 {
   578     const char *state = lxdream_get_global_config_value(CONFIG_QUICK_STATE);
   579     if( state != NULL ) {
   580         quick_save_state = atoi(state);
   581         if( quick_save_state > MAX_QUICK_STATE ) {
   582             quick_save_state = 0;
   583         }
   584     } else {
   585         quick_save_state = 0;
   586     }
   587 }
   589 void dreamcast_quick_save()
   590 {
   591     if( quick_save_state == -1 ) 
   592         dreamcast_quick_state_init();
   593     gchar *str = get_quick_state_filename(quick_save_state);
   594     dreamcast_save_state(str);
   595     g_free(str);
   596 }
   598 void dreamcast_quick_load()
   599 {
   600     if( quick_save_state == -1 ) 
   601         dreamcast_quick_state_init();
   602     gchar *str = get_quick_state_filename(quick_save_state);
   603     dreamcast_load_state(str);
   604     g_free(str);
   605 }
   607 unsigned int dreamcast_get_quick_state( )
   608 {
   609     if( quick_save_state == -1 ) 
   610         dreamcast_quick_state_init();
   611     return quick_save_state;
   612 }
   614 void dreamcast_set_quick_state( unsigned int state )
   615 {
   616     if( state <= MAX_QUICK_STATE && state != quick_save_state ) {
   617         quick_save_state = state;
   618         char buf[3];
   619         sprintf( buf, "%d", quick_save_state );
   620         lxdream_set_global_config_value(CONFIG_QUICK_STATE, buf);
   621         lxdream_save_config();
   622     }
   623 }
   625 gboolean dreamcast_has_quick_state( unsigned int state )
   626 {
   627     gchar *str = get_quick_state_filename(state);
   628     int result = access(str, R_OK);
   629     g_free(str);
   630     return result == 0 ? TRUE : FALSE;
   631 }
   633 /********************* The Boot ROM address space **********************/
   634 static int32_t FASTCALL ext_bootrom_read_long( sh4addr_t addr )
   635 {
   636     return *((int32_t *)(dc_boot_rom + (addr&0x001FFFFF)));
   637 }
   638 static int32_t FASTCALL ext_bootrom_read_word( sh4addr_t addr )
   639 {
   640     return SIGNEXT16(*((int16_t *)(dc_boot_rom + (addr&0x001FFFFF))));
   641 }
   642 static int32_t FASTCALL ext_bootrom_read_byte( sh4addr_t addr )
   643 {
   644     return SIGNEXT8(*((int16_t *)(dc_boot_rom + (addr&0x001FFFFF))));
   645 }
   646 static void FASTCALL ext_bootrom_read_burst( unsigned char *dest, sh4addr_t addr )
   647 {
   648     memcpy( dest, dc_boot_rom +(addr&0x001FFFFF), 32 );
   649 }
   651 struct mem_region_fn mem_region_bootrom = { 
   652         ext_bootrom_read_long, unmapped_write_long, 
   653         ext_bootrom_read_word, unmapped_write_long, 
   654         ext_bootrom_read_byte, unmapped_write_long, 
   655         ext_bootrom_read_burst, unmapped_write_burst }; 
   657 /********************* The Flash RAM address space **********************/
   658 static int32_t FASTCALL ext_flashram_read_long( sh4addr_t addr )
   659 {
   660     return *((int32_t *)(dc_flash_ram + (addr&0x0001FFFF)));
   661 }
   662 static int32_t FASTCALL ext_flashram_read_word( sh4addr_t addr )
   663 {
   664     return SIGNEXT16(*((int16_t *)(dc_flash_ram + (addr&0x0001FFFF))));
   665 }
   666 static int32_t FASTCALL ext_flashram_read_byte( sh4addr_t addr )
   667 {
   668     return SIGNEXT8(*((int16_t *)(dc_flash_ram + (addr&0x0001FFFF))));
   669 }
   670 static void FASTCALL ext_flashram_write_long( sh4addr_t addr, uint32_t val )
   671 {
   672     *(uint32_t *)(dc_flash_ram + (addr&0x0001FFFF)) = val;
   673     asic_g2_write_word();
   674 }
   675 static void FASTCALL ext_flashram_write_word( sh4addr_t addr, uint32_t val )
   676 {
   677     *(uint16_t *)(dc_flash_ram + (addr&0x0001FFFF)) = (uint16_t)val;
   678     asic_g2_write_word();
   679 }
   680 static void FASTCALL ext_flashram_write_byte( sh4addr_t addr, uint32_t val )
   681 {
   682     *(uint8_t *)(dc_flash_ram + (addr&0x0001FFFF)) = (uint8_t)val;
   683     asic_g2_write_word();
   684 }
   685 static void FASTCALL ext_flashram_read_burst( unsigned char *dest, sh4addr_t addr )
   686 {
   687     memcpy( dest, dc_flash_ram+(addr&0x0001FFFF), 32 );
   688 }
   689 static void FASTCALL ext_flashram_write_burst( sh4addr_t addr, unsigned char *src )
   690 {
   691     memcpy( dc_flash_ram+(addr&0x0001FFFF), src, 32 );
   692 }
   694 struct mem_region_fn mem_region_flashram = { ext_flashram_read_long, ext_flashram_write_long, 
   695         ext_flashram_read_word, ext_flashram_write_word, 
   696         ext_flashram_read_byte, ext_flashram_write_byte, 
   697         ext_flashram_read_burst, ext_flashram_write_burst }; 
.