filename | src/dreamcast.c |
changeset | 1100:50e702af9373 |
prev | 1072:d82e04e6d497 |
next | 1109:700c5ab26a63 |
author | nkeynes |
date | Mon Feb 15 17:27:14 2010 +1000 (14 years ago) |
permissions | -rw-r--r-- |
last change | Hook up the fake bios boot Use fakebios if invoked with -b, or if there's no boot rom loaded |
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_use_bios = TRUE;
47 static gboolean dreamcast_has_bios = FALSE;
48 static gboolean dreamcast_has_flash = FALSE;
49 static gboolean dreamcast_exit_on_stop = FALSE;
50 static gchar *dreamcast_program_name = NULL;
51 static sh4addr_t dreamcast_entry_point = 0xA0000000;
52 static uint32_t timeslice_length = DEFAULT_TIMESLICE_LENGTH;
53 static uint64_t run_time_nanosecs = 0;
54 static unsigned int quick_save_state = -1;
56 #define MAX_MODULES 32
57 static int num_modules = 0;
58 dreamcast_module_t modules[MAX_MODULES];
60 /**
61 * The unknown module is used for logging files without an actual module
62 * declaration
63 */
64 struct dreamcast_module unknown_module = { "****", NULL, NULL, NULL, NULL,
65 NULL, NULL, NULL };
67 extern struct mem_region_fn mem_region_sdram;
68 extern struct mem_region_fn mem_region_vram32;
69 extern struct mem_region_fn mem_region_vram64;
70 extern struct mem_region_fn mem_region_audioram;
71 extern struct mem_region_fn mem_region_audioscratch;
72 extern struct mem_region_fn mem_region_flashram;
73 extern struct mem_region_fn mem_region_bootrom;
74 extern struct mem_region_fn mem_region_pvr2ta;
75 extern struct mem_region_fn mem_region_pvr2yuv;
76 extern struct mem_region_fn mem_region_pvr2vdma1;
77 extern struct mem_region_fn mem_region_pvr2vdma2;
79 unsigned char dc_main_ram[16 MB];
80 unsigned char dc_boot_rom[2 MB];
81 unsigned char dc_flash_ram[128 KB];
83 /**
84 * This function is responsible for defining how all the pieces of the
85 * dreamcast actually fit together.
86 *
87 * Note currently the locations of the various MMIO pages are hard coded in
88 * the MMIO definitions - they should probably be moved here.
89 */
90 void dreamcast_configure( gboolean use_bootrom )
91 {
92 char *bios_path = lxdream_get_global_config_path_value(CONFIG_BIOS_PATH);
93 char *flash_path = lxdream_get_global_config_path_value(CONFIG_FLASH_PATH);
95 dreamcast_register_module( &eventq_module );
96 /* Register the memory framework */
97 dreamcast_register_module( &mem_module );
99 /* Setup standard memory map */
100 mem_map_region( dc_boot_rom, 0x00000000, 2 MB, MEM_REGION_BIOS, &mem_region_bootrom, MEM_FLAG_ROM, 2 MB, 0 );
101 mem_map_region( dc_flash_ram, 0x00200000, 128 KB, MEM_REGION_FLASH, &mem_region_flashram, MEM_FLAG_RAM, 128 KB, 0 );
102 mem_map_region( aica_main_ram, 0x00800000, 2 MB, MEM_REGION_AUDIO, &mem_region_audioram, MEM_FLAG_RAM, 2 MB, 0 );
103 mem_map_region( aica_scratch_ram,0x00703000, 8 KB, MEM_REGION_AUDIO_SCRATCH,&mem_region_audioscratch, MEM_FLAG_RAM, 8 KB, 0 );
104 mem_map_region( NULL, 0x04000000, 8 MB, MEM_REGION_VIDEO64, &mem_region_vram64, 0, 8 MB, 0 );
105 mem_map_region( pvr2_main_ram, 0x05000000, 8 MB, MEM_REGION_VIDEO, &mem_region_vram32, MEM_FLAG_RAM, 8 MB, 0 );
106 mem_map_region( dc_main_ram, 0x0C000000, 16 MB, MEM_REGION_MAIN, &mem_region_sdram, MEM_FLAG_RAM, 0x01000000, 0x0F000000 );
107 mem_map_region( NULL, 0x10000000, 8 MB, MEM_REGION_PVR2TA, &mem_region_pvr2ta, 0, 0x02000000, 0x12000000 );
108 mem_map_region( NULL, 0x10800000, 8 MB, MEM_REGION_PVR2YUV, &mem_region_pvr2yuv, 0, 0x02000000, 0x12800000 );
109 mem_map_region( NULL, 0x11000000, 16 MB, MEM_REGION_PVR2VDMA1, &mem_region_pvr2vdma1, 0, 16 MB, 0 );
110 mem_map_region( NULL, 0x13000000, 16 MB, MEM_REGION_PVR2VDMA2, &mem_region_pvr2vdma2, 0, 16 MB, 0 );
112 dreamcast_use_bios = use_bootrom;
113 dreamcast_has_bios = dreamcast_load_bios( bios_path );
114 if( !dreamcast_has_bios ) {
115 dreamcast_load_fakebios();
116 }
118 if( flash_path != NULL && flash_path[0] != '\0' ) {
119 mem_load_block( flash_path, 0x00200000, 0x00020000 );
120 }
121 dreamcast_has_flash = TRUE;
123 /* Load in the rest of the core modules */
124 dreamcast_register_module( &sh4_module );
125 dreamcast_register_module( &asic_module );
126 dreamcast_register_module( &pvr2_module );
127 dreamcast_register_module( &aica_module );
128 dreamcast_register_module( &maple_module );
129 dreamcast_register_module( &ide_module );
131 g_free(bios_path);
132 g_free(flash_path);
133 }
135 gboolean dreamcast_load_bios( const gchar *filename )
136 {
137 if( dreamcast_use_bios ) {
138 dreamcast_has_bios = mem_load_rom( dc_boot_rom, filename, 2 MB, 0x89f2b1a1 );
139 } else {
140 dreamcast_has_bios = FALSE;
141 }
142 return dreamcast_has_bios;
143 }
145 static const char fakebios[] = {
146 0x00, 0xd1, /* movl $+4, r1 */
147 0x2b, 0x41, /* jmp @r1 */
148 0xa0, 0xff, /* .long 0xffffffa0 */
149 0xff, 0xff };
150 gboolean dreamcast_load_fakebios( )
151 {
152 memset( dc_boot_rom, 0, 2 MB );
153 memcpy( dc_boot_rom, fakebios, sizeof(fakebios) );
154 syscall_add_hook( 0xA0, bios_boot );
155 dreamcast_has_bios = TRUE;
156 return TRUE;
157 }
159 gboolean dreamcast_load_flash( const gchar *filename )
160 {
161 if( filename != NULL && filename[0] != '\0' ) {
162 return mem_load_block( filename, 0x00200000, 0x00020000 ) == 0;
163 }
164 return FALSE;
165 }
168 gboolean dreamcast_config_changed(void *data, struct lxdream_config_group *group, unsigned item,
169 const gchar *oldval, const gchar *newval)
170 {
171 gchar *tmp;
172 switch(item) {
173 case CONFIG_BIOS_PATH:
174 tmp = get_expanded_path(newval);
175 dreamcast_load_bios(tmp);
176 g_free(tmp);
177 break;
178 case CONFIG_FLASH_PATH:
179 tmp = get_expanded_path(newval);
180 dreamcast_load_flash(tmp);
181 g_free(tmp);
182 break;
183 }
184 reset_gui_paths();
185 return TRUE;
186 }
188 void dreamcast_save_flash()
189 {
190 if( dreamcast_has_flash ) {
191 char *file = lxdream_get_global_config_path_value(CONFIG_FLASH_PATH);
192 mem_save_block( file, 0x00200000, 0x00020000 );
193 g_free(file);
194 }
195 }
197 /**
198 * Constructs a system configuration for the AICA in standalone mode,
199 * ie sound chip only.
200 */
201 void dreamcast_configure_aica_only( )
202 {
203 dreamcast_register_module( &mem_module );
204 mem_map_region( aica_main_ram, 0x00800000, 2 MB, MEM_REGION_AUDIO, &mem_region_audioram, MEM_FLAG_RAM, 2 MB, 0 );
205 mem_map_region( aica_scratch_ram, 0x00703000, 8 KB, MEM_REGION_AUDIO_SCRATCH, &mem_region_audioscratch, MEM_FLAG_RAM, 8 KB, 0 );
206 dreamcast_register_module( &aica_module );
207 aica_enable();
208 dreamcast_state = STATE_STOPPED;
209 }
211 void dreamcast_register_module( dreamcast_module_t module )
212 {
213 modules[num_modules++] = module;
214 if( module->init != NULL )
215 module->init();
216 }
218 void dreamcast_set_run_time( uint32_t secs, uint32_t nanosecs )
219 {
220 run_time_nanosecs = (((uint64_t)secs) * 1000000000) + nanosecs;
221 }
223 void dreamcast_set_exit_on_stop( gboolean flag )
224 {
225 dreamcast_exit_on_stop = flag;
226 }
228 void dreamcast_init( gboolean use_bootrom )
229 {
230 dreamcast_configure( use_bootrom );
231 dreamcast_state = STATE_STOPPED;
232 }
234 void dreamcast_reset( void )
235 {
236 sh4_core_exit(CORE_EXIT_SYSRESET);
237 int i;
238 for( i=0; i<num_modules; i++ ) {
239 if( modules[i]->reset != NULL )
240 modules[i]->reset();
241 }
242 }
244 void dreamcast_run( void )
245 {
246 int i;
248 if( !dreamcast_can_run() ) {
249 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"));
250 return;
251 }
253 if( dreamcast_state != STATE_RUNNING ) {
254 for( i=0; i<num_modules; i++ ) {
255 if( modules[i]->start != NULL )
256 modules[i]->start();
257 }
258 }
260 if( maple_should_grab() ) {
261 gui_set_use_grab(TRUE);
262 }
264 dreamcast_state = STATE_RUNNING;
266 if( run_time_nanosecs != 0 ) {
267 while( dreamcast_state == STATE_RUNNING ) {
268 uint32_t time_to_run = timeslice_length;
269 if( run_time_nanosecs < time_to_run ) {
270 time_to_run = (uint32_t)run_time_nanosecs;
271 }
273 for( i=0; i<num_modules; i++ ) {
274 if( modules[i]->run_time_slice != NULL )
275 time_to_run = modules[i]->run_time_slice( time_to_run );
276 }
278 if( run_time_nanosecs > time_to_run ) {
279 run_time_nanosecs -= time_to_run;
280 } else {
281 run_time_nanosecs = 0; // Finished
282 break;
283 }
284 }
285 } else {
286 while( dreamcast_state == STATE_RUNNING ) {
287 int time_to_run = timeslice_length;
288 for( i=0; i<num_modules; i++ ) {
289 if( modules[i]->run_time_slice != NULL )
290 time_to_run = modules[i]->run_time_slice( time_to_run );
291 }
293 }
294 }
296 gui_set_use_grab(FALSE);
298 for( i=0; i<num_modules; i++ ) {
299 if( modules[i]->stop != NULL )
300 modules[i]->stop();
301 }
303 vmulist_save_all();
304 dreamcast_state = STATE_STOPPED;
306 if( dreamcast_exit_on_stop ) {
307 dreamcast_shutdown();
308 exit(0);
309 }
310 }
312 void dreamcast_stop( void )
313 {
314 sh4_core_exit(CORE_EXIT_HALT); // returns only if not inside SH4 core
315 if( dreamcast_state == STATE_RUNNING )
316 dreamcast_state = STATE_STOPPING;
317 }
319 void dreamcast_shutdown()
320 {
321 // Don't do a dreamcast_stop - if we're calling this out of SH4 code,
322 // it's a shutdown-and-quit event
323 if( dreamcast_state == STATE_RUNNING )
324 dreamcast_state = STATE_STOPPING;
325 dreamcast_save_flash();
326 vmulist_save_all();
327 #ifdef ENABLE_SH4STATS
328 sh4_stats_print(stdout);
329 #endif
330 }
332 void dreamcast_program_loaded( const gchar *name, sh4addr_t entry_point )
333 {
334 if( dreamcast_program_name != NULL ) {
335 g_free(dreamcast_program_name);
336 }
337 dreamcast_program_name = g_strdup(name);
338 dreamcast_entry_point = entry_point;
339 sh4_set_pc(entry_point);
340 sh4_write_sr( sh4_read_sr() & (~SR_BL) ); /* Unmask interrupts */
341 bios_install();
342 dcload_install();
343 gui_update_state();
344 }
346 gboolean dreamcast_is_running( void )
347 {
348 return dreamcast_state == STATE_RUNNING;
349 }
351 gboolean dreamcast_can_run(void)
352 {
353 return dreamcast_state != STATE_UNINIT;
354 }
356 /********************************* Save States *****************************/
358 struct save_state_header {
359 char magic[16];
360 uint32_t version;
361 uint32_t module_count;
362 };
364 struct chunk_header {
365 char marker[4]; /* Always BLCK */
366 char name[8]; /* Block (module) name */
367 uint32_t block_length;
368 };
370 /**
371 * Check the save state header to ensure that it is a valid, supported
372 * file.
373 * @return the number of blocks following, or 0 if the file is invalid.
374 */
375 int dreamcast_read_save_state_header( FILE *f, char *error, int errorlen )
376 {
377 struct save_state_header header;
378 if( fread( &header, sizeof(header), 1, f ) != 1 ) {
379 return 0;
380 }
381 if( strncmp( header.magic, DREAMCAST_SAVE_MAGIC, 16 ) != 0 ) {
382 if( error != NULL )
383 snprintf( error, errorlen, _("File is not a %s save state"), APP_NAME );
384 return 0;
385 }
386 if( header.version != DREAMCAST_SAVE_VERSION ) {
387 if( error != NULL )
388 snprintf( error, errorlen, _("Unsupported %s save state version"), APP_NAME );
389 return 0;
390 }
391 if( header.module_count > MAX_MODULES ) {
392 if( error != NULL )
393 snprintf( error, errorlen, _("%s save state is corrupted (bad module count)"), APP_NAME );
394 return 0;
395 }
396 return header.module_count;
397 }
399 int dreamcast_write_chunk_header( const gchar *name, uint32_t length, FILE *f )
400 {
401 struct chunk_header head;
403 memcpy( head.marker, "BLCK", 4 );
404 memset( head.name, 0, 8 );
405 memcpy( head.name, name, strlen(name) );
406 head.block_length = length;
407 return fwrite( &head, sizeof(head), 1, f );
408 }
411 frame_buffer_t dreamcast_load_preview( const gchar *filename )
412 {
413 int i;
414 FILE *f = fopen( filename, "r" );
415 if( f == NULL ) return NULL;
417 int module_count = dreamcast_read_save_state_header(f, NULL, 0);
418 if( module_count <= 0 ) {
419 fclose(f);
420 return NULL;
421 }
422 for( i=0; i<module_count; i++ ) {
423 struct chunk_header head;
424 if( fread( &head, sizeof(head), 1, f ) != 1 ) {
425 fclose(f);
426 return NULL;
427 }
428 if( memcmp("BLCK", head.marker, 4) != 0 ) {
429 fclose(f);
430 return NULL;
431 }
433 if( strcmp("PVR2", head.name) == 0 ) {
434 uint32_t buf_count;
435 int has_front;
436 fread( &buf_count, sizeof(buf_count), 1, f );
437 fread( &has_front, sizeof(has_front), 1, f );
438 if( buf_count != 0 && has_front ) {
439 frame_buffer_t result = read_png_from_stream(f);
440 fclose(f);
441 return result;
442 }
443 break;
444 } else {
445 fseek( f, head.block_length, SEEK_CUR );
446 }
447 }
448 return NULL;
449 }
451 int dreamcast_load_state( const gchar *filename )
452 {
453 int i,j;
454 int module_count;
455 char error[128];
456 int have_read[MAX_MODULES];
458 FILE *f = fopen( filename, "r" );
459 if( f == NULL ) return errno;
461 module_count = dreamcast_read_save_state_header(f, error, sizeof(error));
462 if( module_count <= 0 ) {
463 ERROR( error );
464 fclose(f);
465 return 1;
466 }
468 for( i=0; i<MAX_MODULES; i++ ) {
469 have_read[i] = 0;
470 }
472 for( i=0; i<module_count; i++ ) {
473 struct chunk_header chunk;
474 fread( &chunk, sizeof(chunk), 1, f );
475 if( strncmp(chunk.marker, "BLCK", 4) != 0 ) {
476 ERROR( "%s save state is corrupted (missing block header %d)", APP_NAME, i );
477 fclose(f);
478 return 2;
479 }
481 /* Find the matching module by name */
482 for( j=0; j<num_modules; j++ ) {
483 if( strcmp(modules[j]->name,chunk.name) == 0 ) {
484 have_read[j] = 1;
485 if( modules[j]->load == NULL ) {
486 ERROR( "%s save state is corrupted (no loader for %s)", APP_NAME, modules[j]->name );
487 fclose(f);
488 return 2;
489 } else if( modules[j]->load(f) != 0 ) {
490 ERROR( "%s save state is corrupted (%s failed)", APP_NAME, modules[j]->name );
491 fclose(f);
492 return 2;
493 }
494 break;
495 }
496 }
497 if( j == num_modules ) {
498 fclose(f);
499 ERROR( "%s save state contains unrecognized section", APP_NAME );
500 return 2;
501 }
502 }
504 /* Any modules that we didn't load - reset to the default state.
505 * (ie it's not an error to skip a module if you don't actually
506 * care about its state).
507 */
508 for( j=0; j<num_modules; j++ ) {
509 if( have_read[j] == 0 && modules[j]->reset != NULL ) {
510 modules[j]->reset();
511 }
512 }
513 fclose(f);
514 INFO( "Save state read from %s", filename );
515 return 0;
516 }
518 int dreamcast_save_state( const gchar *filename )
519 {
520 int i;
521 FILE *f;
522 struct save_state_header header;
524 f = fopen( filename, "w" );
525 if( f == NULL )
526 return errno;
527 strcpy( header.magic, DREAMCAST_SAVE_MAGIC );
528 header.version = DREAMCAST_SAVE_VERSION;
529 header.module_count = 0;
531 for( i=0; i<num_modules; i++ ) {
532 if( modules[i]->save != NULL )
533 header.module_count++;
534 }
535 fwrite( &header, sizeof(header), 1, f );
536 for( i=0; i<num_modules; i++ ) {
537 if( modules[i]->save != NULL ) {
538 uint32_t blocklen, posn1, posn2;
539 dreamcast_write_chunk_header( modules[i]->name, 0, f );
540 posn1 = ftell(f);
541 modules[i]->save(f);
542 posn2 = ftell(f);
543 blocklen = posn2 - posn1;
544 fseek( f, posn1-4, SEEK_SET );
545 fwrite( &blocklen, sizeof(blocklen), 1, f );
546 fseek( f, posn2, SEEK_SET );
547 }
548 }
549 fclose( f );
550 INFO( "Save state written to %s", filename );
551 return 0;
552 }
554 /********************** Quick save state support ***********************/
555 /* This section doesn't necessarily belong here, but it probably makes the
556 * most sense here next to the regular save/load functions
557 */
559 static gchar *get_quick_state_filename( int state )
560 {
561 gchar *path = lxdream_get_global_config_path_value(CONFIG_SAVE_PATH);
562 gchar *str = g_strdup_printf( QUICK_STATE_FILENAME, path, state );
563 g_free( path );
564 return str;
565 }
568 static void dreamcast_quick_state_init()
569 {
570 const char *state = lxdream_get_global_config_value(CONFIG_QUICK_STATE);
571 if( state != NULL ) {
572 quick_save_state = atoi(state);
573 if( quick_save_state > MAX_QUICK_STATE ) {
574 quick_save_state = 0;
575 }
576 } else {
577 quick_save_state = 0;
578 }
579 }
581 void dreamcast_quick_save()
582 {
583 if( quick_save_state == -1 )
584 dreamcast_quick_state_init();
585 gchar *str = get_quick_state_filename(quick_save_state);
586 dreamcast_save_state(str);
587 g_free(str);
588 }
590 void dreamcast_quick_load()
591 {
592 if( quick_save_state == -1 )
593 dreamcast_quick_state_init();
594 gchar *str = get_quick_state_filename(quick_save_state);
595 dreamcast_load_state(str);
596 g_free(str);
597 }
599 unsigned int dreamcast_get_quick_state( )
600 {
601 if( quick_save_state == -1 )
602 dreamcast_quick_state_init();
603 return quick_save_state;
604 }
606 void dreamcast_set_quick_state( unsigned int state )
607 {
608 if( state <= MAX_QUICK_STATE && state != quick_save_state ) {
609 quick_save_state = state;
610 char buf[3];
611 sprintf( buf, "%d", quick_save_state );
612 lxdream_set_global_config_value(CONFIG_QUICK_STATE, buf);
613 lxdream_save_config();
614 }
615 }
617 gboolean dreamcast_has_quick_state( unsigned int state )
618 {
619 gchar *str = get_quick_state_filename(state);
620 int result = access(str, R_OK);
621 g_free(str);
622 return result == 0 ? TRUE : FALSE;
623 }
625 /********************* The Boot ROM address space **********************/
626 static int32_t FASTCALL ext_bootrom_read_long( sh4addr_t addr )
627 {
628 return *((int32_t *)(dc_boot_rom + (addr&0x001FFFFF)));
629 }
630 static int32_t FASTCALL ext_bootrom_read_word( sh4addr_t addr )
631 {
632 return SIGNEXT16(*((int16_t *)(dc_boot_rom + (addr&0x001FFFFF))));
633 }
634 static int32_t FASTCALL ext_bootrom_read_byte( sh4addr_t addr )
635 {
636 return SIGNEXT8(*((int16_t *)(dc_boot_rom + (addr&0x001FFFFF))));
637 }
638 static void FASTCALL ext_bootrom_read_burst( unsigned char *dest, sh4addr_t addr )
639 {
640 memcpy( dest, dc_boot_rom +(addr&0x001FFFFF), 32 );
641 }
643 struct mem_region_fn mem_region_bootrom = {
644 ext_bootrom_read_long, unmapped_write_long,
645 ext_bootrom_read_word, unmapped_write_long,
646 ext_bootrom_read_byte, unmapped_write_long,
647 ext_bootrom_read_burst, unmapped_write_burst };
649 /********************* The Flash RAM address space **********************/
650 static int32_t FASTCALL ext_flashram_read_long( sh4addr_t addr )
651 {
652 return *((int32_t *)(dc_flash_ram + (addr&0x0001FFFF)));
653 }
654 static int32_t FASTCALL ext_flashram_read_word( sh4addr_t addr )
655 {
656 return SIGNEXT16(*((int16_t *)(dc_flash_ram + (addr&0x0001FFFF))));
657 }
658 static int32_t FASTCALL ext_flashram_read_byte( sh4addr_t addr )
659 {
660 return SIGNEXT8(*((int16_t *)(dc_flash_ram + (addr&0x0001FFFF))));
661 }
662 static void FASTCALL ext_flashram_write_long( sh4addr_t addr, uint32_t val )
663 {
664 *(uint32_t *)(dc_flash_ram + (addr&0x0001FFFF)) = val;
665 asic_g2_write_word();
666 }
667 static void FASTCALL ext_flashram_write_word( sh4addr_t addr, uint32_t val )
668 {
669 *(uint16_t *)(dc_flash_ram + (addr&0x0001FFFF)) = (uint16_t)val;
670 asic_g2_write_word();
671 }
672 static void FASTCALL ext_flashram_write_byte( sh4addr_t addr, uint32_t val )
673 {
674 *(uint8_t *)(dc_flash_ram + (addr&0x0001FFFF)) = (uint8_t)val;
675 asic_g2_write_word();
676 }
677 static void FASTCALL ext_flashram_read_burst( unsigned char *dest, sh4addr_t addr )
678 {
679 memcpy( dest, dc_flash_ram+(addr&0x0001FFFF), 32 );
680 }
681 static void FASTCALL ext_flashram_write_burst( sh4addr_t addr, unsigned char *src )
682 {
683 memcpy( dc_flash_ram+(addr&0x0001FFFF), src, 32 );
684 }
686 struct mem_region_fn mem_region_flashram = { ext_flashram_read_long, ext_flashram_write_long,
687 ext_flashram_read_word, ext_flashram_write_word,
688 ext_flashram_read_byte, ext_flashram_write_byte,
689 ext_flashram_read_burst, ext_flashram_write_burst };
.