Search
lxdream.org :: lxdream/src/dreamcast.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/dreamcast.c
changeset 1067:d3c00ffccfcd
prev1065:bc1cc0c54917
prev951:63483914846f
next1072:d82e04e6d497
author nkeynes
date Tue Jul 21 20:21:52 2009 +1000 (14 years ago)
permissions -rw-r--r--
last change Fix assorted -Wall warnings
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 "mem.h"
    27 #include "dreamcast.h"
    28 #include "asic.h"
    29 #include "syscall.h"
    30 #include "gui.h"
    31 #include "aica/aica.h"
    32 #include "gdrom/ide.h"
    33 #include "maple/maple.h"
    34 #include "pvr2/pvr2.h"
    35 #include "sh4/sh4.h"
    36 #include "sh4/sh4core.h"
    37 #include "vmu/vmulist.h"
    39 /**
    40  * Current state of the DC virtual machine
    41  */
    42 typedef enum { STATE_UNINIT=0, STATE_RUNNING, 
    43                STATE_STOPPING, STATE_STOPPED } dreamcast_state_t;
    45 static volatile dreamcast_state_t dreamcast_state = STATE_UNINIT;
    46 static gboolean dreamcast_has_bios = FALSE;
    47 static gboolean dreamcast_has_flash = FALSE;
    48 static gboolean dreamcast_exit_on_stop = FALSE;
    49 static gchar *dreamcast_program_name = NULL;
    50 static sh4addr_t dreamcast_entry_point = 0xA0000000;
    51 static uint32_t timeslice_length = DEFAULT_TIMESLICE_LENGTH;
    52 static uint64_t run_time_nanosecs = 0;
    53 static unsigned int quick_save_state = -1;
    55 #define MAX_MODULES 32
    56 static int num_modules = 0;
    57 dreamcast_module_t modules[MAX_MODULES];
    59 /**
    60  * The unknown module is used for logging files without an actual module
    61  * declaration
    62  */
    63 struct dreamcast_module unknown_module = { "****", NULL, NULL, NULL, NULL, 
    64         NULL, NULL, NULL };
    66 extern struct mem_region_fn mem_region_sdram;
    67 extern struct mem_region_fn mem_region_vram32;
    68 extern struct mem_region_fn mem_region_vram64;
    69 extern struct mem_region_fn mem_region_audioram;
    70 extern struct mem_region_fn mem_region_audioscratch;
    71 extern struct mem_region_fn mem_region_flashram;
    72 extern struct mem_region_fn mem_region_bootrom;
    73 extern struct mem_region_fn mem_region_pvr2ta;
    74 extern struct mem_region_fn mem_region_pvr2yuv;
    75 extern struct mem_region_fn mem_region_pvr2vdma1;
    76 extern struct mem_region_fn mem_region_pvr2vdma2;
    78 unsigned char dc_main_ram[16 MB];
    79 unsigned char dc_boot_rom[2 MB];
    80 unsigned char dc_flash_ram[128 KB];
    82 /**
    83  * This function is responsible for defining how all the pieces of the
    84  * dreamcast actually fit together. 
    85  *
    86  * Note currently the locations of the various MMIO pages are hard coded in
    87  * the MMIO definitions - they should probably be moved here.
    88  */
    89 void dreamcast_configure( )
    90 {
    91     char *bios_path = lxdream_get_global_config_path_value(CONFIG_BIOS_PATH);
    92     char *flash_path = lxdream_get_global_config_path_value(CONFIG_FLASH_PATH);
    94     dreamcast_register_module( &eventq_module );
    95     /* Register the memory framework */
    96     dreamcast_register_module( &mem_module );
    98     /* Setup standard memory map */
    99     mem_map_region( dc_boot_rom,     0x00000000, 2 MB,   MEM_REGION_BIOS,         &mem_region_bootrom, MEM_FLAG_ROM, 2 MB, 0 );
   100     mem_map_region( dc_flash_ram,    0x00200000, 128 KB, MEM_REGION_FLASH,        &mem_region_flashram, MEM_FLAG_RAM, 128 KB, 0 );
   101     mem_map_region( aica_main_ram,   0x00800000, 2 MB,   MEM_REGION_AUDIO,        &mem_region_audioram, MEM_FLAG_RAM, 2 MB, 0 );
   102     mem_map_region( aica_scratch_ram,0x00703000, 8 KB,   MEM_REGION_AUDIO_SCRATCH,&mem_region_audioscratch, MEM_FLAG_RAM, 8 KB, 0 );
   103     mem_map_region( NULL,            0x04000000, 8 MB,   MEM_REGION_VIDEO64,      &mem_region_vram64, 0, 8 MB, 0 );
   104     mem_map_region( pvr2_main_ram,   0x05000000, 8 MB,   MEM_REGION_VIDEO,        &mem_region_vram32, MEM_FLAG_RAM, 8 MB, 0 ); 
   105     mem_map_region( dc_main_ram,     0x0C000000, 16 MB,  MEM_REGION_MAIN,         &mem_region_sdram, MEM_FLAG_RAM, 0x01000000, 0x0F000000 );
   106     mem_map_region( NULL,            0x10000000, 8 MB,   MEM_REGION_PVR2TA,       &mem_region_pvr2ta, 0, 0x02000000, 0x12000000 );
   107     mem_map_region( NULL,            0x10800000, 8 MB,   MEM_REGION_PVR2YUV,      &mem_region_pvr2yuv, 0, 0x02000000, 0x12800000 );
   108     mem_map_region( NULL,            0x11000000, 16 MB,  MEM_REGION_PVR2VDMA1,    &mem_region_pvr2vdma1, 0, 16 MB, 0 );
   109     mem_map_region( NULL,            0x13000000, 16 MB,  MEM_REGION_PVR2VDMA2,    &mem_region_pvr2vdma2, 0, 16 MB, 0 );
   111     dreamcast_has_bios = mem_load_rom( dc_boot_rom, bios_path, 2 MB, 0x89f2b1a1 );
   112     if( flash_path != NULL && flash_path[0] != '\0' ) {
   113         mem_load_block( flash_path, 0x00200000, 0x00020000 );
   114     }
   115     dreamcast_has_flash = TRUE;
   117     /* Load in the rest of the core modules */
   118     dreamcast_register_module( &sh4_module );
   119     dreamcast_register_module( &asic_module );
   120     dreamcast_register_module( &pvr2_module );
   121     dreamcast_register_module( &aica_module );
   122     dreamcast_register_module( &maple_module );
   123     dreamcast_register_module( &ide_module );
   125     g_free(bios_path);
   126     g_free(flash_path);
   127 }
   129 void dreamcast_config_changed(void)
   130 {
   131     char *bios_path = lxdream_get_global_config_path_value(CONFIG_BIOS_PATH);
   132     char *flash_path = lxdream_get_global_config_path_value(CONFIG_FLASH_PATH);
   133     dreamcast_has_bios = mem_load_rom( dc_boot_rom, bios_path, 2 MB, 0x89f2b1a1 );
   134     if( flash_path != NULL && flash_path[0] != '\0' ) {
   135         mem_load_block( flash_path, 0x00200000, 0x00020000 );
   136     }
   137     g_free(bios_path);
   138     g_free(flash_path);
   139     reset_gui_paths();
   140 }
   142 void dreamcast_save_flash()
   143 {
   144     if( dreamcast_has_flash ) {
   145         char *file = lxdream_get_global_config_path_value(CONFIG_FLASH_PATH);
   146         mem_save_block( file, 0x00200000, 0x00020000 );
   147         g_free(file);
   148     }
   149 }
   151 /**
   152  * Constructs a system configuration for the AICA in standalone mode,
   153  * ie sound chip only.
   154  */
   155 void dreamcast_configure_aica_only( )
   156 {
   157     dreamcast_register_module( &mem_module );
   158     mem_map_region( aica_main_ram, 0x00800000, 2 MB, MEM_REGION_AUDIO, &mem_region_audioram, MEM_FLAG_RAM, 2 MB, 0 );
   159     mem_map_region( aica_scratch_ram, 0x00703000, 8 KB, MEM_REGION_AUDIO_SCRATCH, &mem_region_audioscratch, MEM_FLAG_RAM, 8 KB, 0 );
   160     dreamcast_register_module( &aica_module );
   161     aica_enable();
   162     dreamcast_state = STATE_STOPPED;
   163 }
   165 void dreamcast_register_module( dreamcast_module_t module ) 
   166 {
   167     modules[num_modules++] = module;
   168     if( module->init != NULL )
   169         module->init();
   170 }
   172 void dreamcast_set_run_time( uint32_t secs, uint32_t nanosecs )
   173 {
   174     run_time_nanosecs = (((uint64_t)secs) * 1000000000) + nanosecs;
   175 }
   177 void dreamcast_set_exit_on_stop( gboolean flag )
   178 {
   179     dreamcast_exit_on_stop = flag;
   180 }
   182 void dreamcast_init( void )
   183 {
   184     dreamcast_configure();
   185     dreamcast_state = STATE_STOPPED;
   186 }
   188 void dreamcast_reset( void )
   189 {
   190     sh4_core_exit(CORE_EXIT_SYSRESET);
   191     int i;
   192     for( i=0; i<num_modules; i++ ) {
   193         if( modules[i]->reset != NULL )
   194             modules[i]->reset();
   195     }
   196 }
   198 void dreamcast_run( void )
   199 {
   200     int i;
   202     if( !dreamcast_can_run() ) {
   203         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"));
   204         return;
   205     }
   207     if( dreamcast_state != STATE_RUNNING ) {
   208         for( i=0; i<num_modules; i++ ) {
   209             if( modules[i]->start != NULL )
   210                 modules[i]->start();
   211         }
   212     }
   214     if( maple_should_grab() ) {
   215         gui_set_use_grab(TRUE);
   216     }
   218     dreamcast_state = STATE_RUNNING;
   220     if( run_time_nanosecs != 0 ) {
   221         while( dreamcast_state == STATE_RUNNING ) {
   222             uint32_t time_to_run = timeslice_length;
   223             if( run_time_nanosecs < time_to_run ) {
   224                 time_to_run = (uint32_t)run_time_nanosecs;
   225             }
   227             for( i=0; i<num_modules; i++ ) {
   228                 if( modules[i]->run_time_slice != NULL )
   229                     time_to_run = modules[i]->run_time_slice( time_to_run );
   230             }
   232             if( run_time_nanosecs > time_to_run ) {
   233                 run_time_nanosecs -= time_to_run;
   234             } else {
   235                 run_time_nanosecs = 0; // Finished
   236                 break;
   237             }
   238         }
   239     } else {
   240         while( dreamcast_state == STATE_RUNNING ) {
   241             int time_to_run = timeslice_length;
   242             for( i=0; i<num_modules; i++ ) {
   243                 if( modules[i]->run_time_slice != NULL )
   244                     time_to_run = modules[i]->run_time_slice( time_to_run );
   245             }
   247         }
   248     }
   250     gui_set_use_grab(FALSE);
   252     for( i=0; i<num_modules; i++ ) {
   253         if( modules[i]->stop != NULL )
   254             modules[i]->stop();
   255     }
   257     vmulist_save_all();
   258     dreamcast_state = STATE_STOPPED;
   260     if( dreamcast_exit_on_stop ) {
   261         dreamcast_shutdown();
   262         exit(0);
   263     }
   264 }
   266 void dreamcast_stop( void )
   267 {
   268     sh4_core_exit(CORE_EXIT_HALT); // returns only if not inside SH4 core
   269     if( dreamcast_state == STATE_RUNNING )
   270         dreamcast_state = STATE_STOPPING;
   271 }
   273 void dreamcast_shutdown()
   274 {
   275     // Don't do a dreamcast_stop - if we're calling this out of SH4 code,
   276     // it's a shutdown-and-quit event
   277     if( dreamcast_state == STATE_RUNNING )
   278         dreamcast_state = STATE_STOPPING;
   279     dreamcast_save_flash();
   280     vmulist_save_all();
   281 #ifdef ENABLE_SH4STATS
   282     sh4_stats_print(stdout);
   283 #endif
   284 }
   286 void dreamcast_program_loaded( const gchar *name, sh4addr_t entry_point )
   287 {
   288     if( dreamcast_program_name != NULL ) {
   289         g_free(dreamcast_program_name);
   290     }
   291     dreamcast_program_name = g_strdup(name);
   292     dreamcast_entry_point = entry_point;
   293     sh4_set_pc(entry_point);
   294     sh4_write_sr( sh4_read_sr() & (~SR_BL) ); /* Unmask interrupts */
   295     bios_install();
   296     dcload_install();
   297     gui_update_state();
   298 }
   300 gboolean dreamcast_is_running( void )
   301 {
   302     return dreamcast_state == STATE_RUNNING;
   303 }
   305 gboolean dreamcast_can_run(void)
   306 {
   307     return dreamcast_state != STATE_UNINIT &&
   308     (dreamcast_has_bios || dreamcast_program_name != NULL);
   309 }
   311 /********************************* Save States *****************************/
   313 struct save_state_header {
   314     char magic[16];
   315     uint32_t version;
   316     uint32_t module_count;
   317 };
   319 struct chunk_header {
   320     char marker[4]; /* Always BLCK */
   321     char name[8]; /* Block (module) name */
   322     uint32_t block_length;
   323 };
   325 /**
   326  * Check the save state header to ensure that it is a valid, supported
   327  * file. 
   328  * @return the number of blocks following, or 0 if the file is invalid.
   329  */
   330 int dreamcast_read_save_state_header( FILE *f, char *error, int errorlen )
   331 {
   332     struct save_state_header header;
   333     if( fread( &header, sizeof(header), 1, f ) != 1 ) {
   334         return 0;
   335     }
   336     if( strncmp( header.magic, DREAMCAST_SAVE_MAGIC, 16 ) != 0 ) {
   337     	if( error != NULL )
   338     		snprintf( error, errorlen, _("File is not a %s save state"), APP_NAME );
   339         return 0;
   340     }
   341     if( header.version != DREAMCAST_SAVE_VERSION ) {
   342     	if( error != NULL )
   343     		snprintf( error, errorlen, _("Unsupported %s save state version"), APP_NAME );
   344         return 0;
   345     }
   346     if( header.module_count > MAX_MODULES ) {
   347     	if( error != NULL )
   348     		snprintf( error, errorlen, _("%s save state is corrupted (bad module count)"), APP_NAME );
   349         return 0;
   350     }
   351     return header.module_count;
   352 }
   354 int dreamcast_write_chunk_header( const gchar *name, uint32_t length, FILE *f )
   355 {
   356     struct chunk_header head;
   358     memcpy( head.marker, "BLCK", 4 );
   359     memset( head.name, 0, 8 );
   360     memcpy( head.name, name, strlen(name) );
   361     head.block_length = length;
   362     return fwrite( &head, sizeof(head), 1, f );
   363 }
   366 frame_buffer_t dreamcast_load_preview( const gchar *filename )
   367 {
   368     int i;
   369     FILE *f = fopen( filename, "r" );
   370     if( f == NULL ) return NULL;
   372     int module_count = dreamcast_read_save_state_header(f, NULL, 0);
   373     if( module_count <= 0 ) {
   374         fclose(f);
   375         return NULL;
   376     }
   377     for( i=0; i<module_count; i++ ) {
   378         struct chunk_header head;
   379         if( fread( &head, sizeof(head), 1, f ) != 1 ) {
   380             fclose(f);
   381             return NULL;
   382         }
   383         if( memcmp("BLCK", head.marker, 4) != 0 ) {
   384             fclose(f);
   385             return NULL;
   386         }
   388         if( strcmp("PVR2", head.name) == 0 ) {
   389             uint32_t buf_count;
   390             int has_front;
   391             fread( &buf_count, sizeof(buf_count), 1, f );
   392             fread( &has_front, sizeof(has_front), 1, f );
   393             if( buf_count != 0 && has_front ) {
   394                 frame_buffer_t result = read_png_from_stream(f);
   395                 fclose(f);
   396                 return result;
   397             }
   398             break;
   399         } else {
   400             fseek( f, head.block_length, SEEK_CUR );
   401         }
   402     }
   403     return NULL;
   404 }
   406 int dreamcast_load_state( const gchar *filename )
   407 {
   408     int i,j;
   409     int module_count;
   410     char error[128];
   411     int have_read[MAX_MODULES];
   413     FILE *f = fopen( filename, "r" );
   414     if( f == NULL ) return errno;
   416     module_count = dreamcast_read_save_state_header(f, error, sizeof(error));
   417     if( module_count <= 0 ) {
   418     	ERROR( error );
   419         fclose(f);
   420         return 1;
   421     }
   423     for( i=0; i<MAX_MODULES; i++ ) {
   424         have_read[i] = 0;
   425     }
   427     for( i=0; i<module_count; i++ ) {
   428         struct chunk_header chunk;
   429         fread( &chunk, sizeof(chunk), 1, f );
   430         if( strncmp(chunk.marker, "BLCK", 4) != 0 ) {
   431             ERROR( "%s save state is corrupted (missing block header %d)", APP_NAME, i );
   432             fclose(f);
   433             return 2;
   434         }
   436         /* Find the matching module by name */
   437         for( j=0; j<num_modules; j++ ) {
   438             if( strcmp(modules[j]->name,chunk.name) == 0 ) {
   439                 have_read[j] = 1;
   440                 if( modules[j]->load == NULL ) {
   441                     ERROR( "%s save state is corrupted (no loader for %s)", APP_NAME, modules[j]->name );
   442                     fclose(f);
   443                     return 2;
   444                 } else if( modules[j]->load(f) != 0 ) {
   445                     ERROR( "%s save state is corrupted (%s failed)", APP_NAME, modules[j]->name );
   446                     fclose(f);
   447                     return 2;
   448                 }
   449                 break;
   450             }
   451         }
   452         if( j == num_modules ) {
   453             fclose(f);
   454             ERROR( "%s save state contains unrecognized section", APP_NAME );
   455             return 2;
   456         }
   457     }
   459     /* Any modules that we didn't load - reset to the default state.
   460      * (ie it's not an error to skip a module if you don't actually
   461      * care about its state).
   462      */
   463     for( j=0; j<num_modules; j++ ) {
   464         if( have_read[j] == 0 && modules[j]->reset != NULL ) {
   465             modules[j]->reset();
   466         }
   467     }
   468     fclose(f);
   469     INFO( "Save state read from %s", filename );
   470     return 0;
   471 }
   473 int dreamcast_save_state( const gchar *filename )
   474 {
   475     int i;
   476     FILE *f;
   477     struct save_state_header header;
   479     f = fopen( filename, "w" );
   480     if( f == NULL )
   481         return errno;
   482     strcpy( header.magic, DREAMCAST_SAVE_MAGIC );
   483     header.version = DREAMCAST_SAVE_VERSION;
   484     header.module_count = 0;
   486     for( i=0; i<num_modules; i++ ) {
   487         if( modules[i]->save != NULL )
   488             header.module_count++;
   489     }
   490     fwrite( &header, sizeof(header), 1, f );
   491     for( i=0; i<num_modules; i++ ) {
   492         if( modules[i]->save != NULL ) {
   493             uint32_t blocklen, posn1, posn2;
   494             dreamcast_write_chunk_header( modules[i]->name, 0, f );
   495             posn1 = ftell(f);
   496             modules[i]->save(f);
   497             posn2 = ftell(f);
   498             blocklen = posn2 - posn1;
   499             fseek( f, posn1-4, SEEK_SET );
   500             fwrite( &blocklen, sizeof(blocklen), 1, f );
   501             fseek( f, posn2, SEEK_SET );
   502         }
   503     }
   504     fclose( f );
   505     INFO( "Save state written to %s", filename );
   506     return 0;
   507 }
   509 /********************** Quick save state support ***********************/
   510 /* This section doesn't necessarily belong here, but it probably makes the
   511  * most sense here next to the regular save/load functions
   512  */
   514 static gchar *get_quick_state_filename( int state )
   515 {
   516     gchar *path = lxdream_get_global_config_path_value(CONFIG_SAVE_PATH);
   517     gchar *str = g_strdup_printf( QUICK_STATE_FILENAME, path, state );
   518     g_free( path );
   519     return str;
   520 }
   523 static void dreamcast_quick_state_init()
   524 {
   525     const char *state = lxdream_get_global_config_value(CONFIG_QUICK_STATE);
   526     if( state != NULL ) {
   527         quick_save_state = atoi(state);
   528         if( quick_save_state > MAX_QUICK_STATE ) {
   529             quick_save_state = 0;
   530         }
   531     } else {
   532         quick_save_state = 0;
   533     }
   534 }
   536 void dreamcast_quick_save()
   537 {
   538     if( quick_save_state == -1 ) 
   539         dreamcast_quick_state_init();
   540     gchar *str = get_quick_state_filename(quick_save_state);
   541     dreamcast_save_state(str);
   542     g_free(str);
   543 }
   545 void dreamcast_quick_load()
   546 {
   547     if( quick_save_state == -1 ) 
   548         dreamcast_quick_state_init();
   549     gchar *str = get_quick_state_filename(quick_save_state);
   550     dreamcast_load_state(str);
   551     g_free(str);
   552 }
   554 unsigned int dreamcast_get_quick_state( )
   555 {
   556     if( quick_save_state == -1 ) 
   557         dreamcast_quick_state_init();
   558     return quick_save_state;
   559 }
   561 void dreamcast_set_quick_state( unsigned int state )
   562 {
   563     if( state <= MAX_QUICK_STATE && state != quick_save_state ) {
   564         quick_save_state = state;
   565         char buf[3];
   566         sprintf( buf, "%d", quick_save_state );
   567         lxdream_set_global_config_value(CONFIG_QUICK_STATE, buf);
   568         lxdream_save_config();
   569     }
   570 }
   572 gboolean dreamcast_has_quick_state( unsigned int state )
   573 {
   574     gchar *str = get_quick_state_filename(state);
   575     int result = access(str, R_OK);
   576     g_free(str);
   577     return result == 0 ? TRUE : FALSE;
   578 }
   580 /********************* The Boot ROM address space **********************/
   581 static int32_t FASTCALL ext_bootrom_read_long( sh4addr_t addr )
   582 {
   583     return *((int32_t *)(dc_boot_rom + (addr&0x001FFFFF)));
   584 }
   585 static int32_t FASTCALL ext_bootrom_read_word( sh4addr_t addr )
   586 {
   587     return SIGNEXT16(*((int16_t *)(dc_boot_rom + (addr&0x001FFFFF))));
   588 }
   589 static int32_t FASTCALL ext_bootrom_read_byte( sh4addr_t addr )
   590 {
   591     return SIGNEXT8(*((int16_t *)(dc_boot_rom + (addr&0x001FFFFF))));
   592 }
   593 static void FASTCALL ext_bootrom_read_burst( unsigned char *dest, sh4addr_t addr )
   594 {
   595     memcpy( dest, dc_boot_rom +(addr&0x001FFFFF), 32 );
   596 }
   598 struct mem_region_fn mem_region_bootrom = { 
   599         ext_bootrom_read_long, unmapped_write_long, 
   600         ext_bootrom_read_word, unmapped_write_long, 
   601         ext_bootrom_read_byte, unmapped_write_long, 
   602         ext_bootrom_read_burst, unmapped_write_burst }; 
   604 /********************* The Flash RAM address space **********************/
   605 static int32_t FASTCALL ext_flashram_read_long( sh4addr_t addr )
   606 {
   607     return *((int32_t *)(dc_flash_ram + (addr&0x0001FFFF)));
   608 }
   609 static int32_t FASTCALL ext_flashram_read_word( sh4addr_t addr )
   610 {
   611     return SIGNEXT16(*((int16_t *)(dc_flash_ram + (addr&0x0001FFFF))));
   612 }
   613 static int32_t FASTCALL ext_flashram_read_byte( sh4addr_t addr )
   614 {
   615     return SIGNEXT8(*((int16_t *)(dc_flash_ram + (addr&0x0001FFFF))));
   616 }
   617 static void FASTCALL ext_flashram_write_long( sh4addr_t addr, uint32_t val )
   618 {
   619     *(uint32_t *)(dc_flash_ram + (addr&0x0001FFFF)) = val;
   620     asic_g2_write_word();
   621 }
   622 static void FASTCALL ext_flashram_write_word( sh4addr_t addr, uint32_t val )
   623 {
   624     *(uint16_t *)(dc_flash_ram + (addr&0x0001FFFF)) = (uint16_t)val;
   625     asic_g2_write_word();
   626 }
   627 static void FASTCALL ext_flashram_write_byte( sh4addr_t addr, uint32_t val )
   628 {
   629     *(uint8_t *)(dc_flash_ram + (addr&0x0001FFFF)) = (uint8_t)val;
   630     asic_g2_write_word();
   631 }
   632 static void FASTCALL ext_flashram_read_burst( unsigned char *dest, sh4addr_t addr )
   633 {
   634     memcpy( dest, dc_flash_ram+(addr&0x0001FFFF), 32 );
   635 }
   636 static void FASTCALL ext_flashram_write_burst( sh4addr_t addr, unsigned char *src )
   637 {
   638     memcpy( dc_flash_ram+(addr&0x0001FFFF), src, 32 );
   639 }
   641 struct mem_region_fn mem_region_flashram = { ext_flashram_read_long, ext_flashram_write_long, 
   642         ext_flashram_read_word, ext_flashram_write_word, 
   643         ext_flashram_read_byte, ext_flashram_write_byte, 
   644         ext_flashram_read_burst, ext_flashram_write_burst }; 
.