filename | src/dreamcast.c |
changeset | 1119:45602839e067 |
prev | 1109:700c5ab26a63 |
next | 1270:65fd19c07e2e |
author | nkeynes |
date | Mon Jan 30 17:47:29 2012 +1000 (12 years ago) |
permissions | -rw-r--r-- |
last change | Add include sys/socket.h to provide type definitions (needed on some platforms) |
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 /* Initialize the event queue first */
96 event_init();
98 /* Register the memory framework */
99 dreamcast_register_module( &mem_module );
101 /* Setup standard memory map */
102 mem_map_region( dc_boot_rom, 0x00000000, 2 MB, MEM_REGION_BIOS, &mem_region_bootrom, MEM_FLAG_ROM, 2 MB, 0 );
103 mem_map_region( dc_flash_ram, 0x00200000, 128 KB, MEM_REGION_FLASH, &mem_region_flashram, MEM_FLAG_RAM, 128 KB, 0 );
104 mem_map_region( aica_main_ram, 0x00800000, 2 MB, MEM_REGION_AUDIO, &mem_region_audioram, MEM_FLAG_RAM, 2 MB, 0 );
105 mem_map_region( aica_scratch_ram,0x00703000, 8 KB, MEM_REGION_AUDIO_SCRATCH,&mem_region_audioscratch, MEM_FLAG_RAM, 8 KB, 0 );
106 mem_map_region( NULL, 0x04000000, 8 MB, MEM_REGION_VIDEO64, &mem_region_vram64, 0, 8 MB, 0 );
107 mem_map_region( pvr2_main_ram, 0x05000000, 8 MB, MEM_REGION_VIDEO, &mem_region_vram32, MEM_FLAG_RAM, 8 MB, 0 );
108 mem_map_region( dc_main_ram, 0x0C000000, 16 MB, MEM_REGION_MAIN, &mem_region_sdram, MEM_FLAG_RAM, 0x01000000, 0x0F000000 );
109 mem_map_region( NULL, 0x10000000, 8 MB, MEM_REGION_PVR2TA, &mem_region_pvr2ta, 0, 0x02000000, 0x12000000 );
110 mem_map_region( NULL, 0x10800000, 8 MB, MEM_REGION_PVR2YUV, &mem_region_pvr2yuv, 0, 0x02000000, 0x12800000 );
111 mem_map_region( NULL, 0x11000000, 16 MB, MEM_REGION_PVR2VDMA1, &mem_region_pvr2vdma1, 0, 16 MB, 0 );
112 mem_map_region( NULL, 0x13000000, 16 MB, MEM_REGION_PVR2VDMA2, &mem_region_pvr2vdma2, 0, 16 MB, 0 );
114 dreamcast_use_bios = use_bootrom;
115 dreamcast_has_bios = dreamcast_load_bios( bios_path );
116 if( !dreamcast_has_bios ) {
117 dreamcast_load_fakebios();
118 }
120 if( flash_path != NULL && flash_path[0] != '\0' ) {
121 mem_load_block( flash_path, 0x00200000, 0x00020000 );
122 }
123 dreamcast_has_flash = TRUE;
125 /* Load in the rest of the core modules */
126 dreamcast_register_module( &sh4_module );
127 dreamcast_register_module( &asic_module );
128 dreamcast_register_module( &pvr2_module );
129 dreamcast_register_module( &aica_module );
130 dreamcast_register_module( &maple_module );
131 dreamcast_register_module( &ide_module );
132 dreamcast_register_module( &eventq_module );
134 g_free(bios_path);
135 g_free(flash_path);
136 }
138 gboolean dreamcast_load_bios( const gchar *filename )
139 {
140 if( dreamcast_use_bios ) {
141 dreamcast_has_bios = mem_load_rom( dc_boot_rom, filename, 2 MB, 0x89f2b1a1 );
142 } else {
143 dreamcast_has_bios = FALSE;
144 }
145 return dreamcast_has_bios;
146 }
148 static const char fakebios[] = {
149 0x00, 0xd1, /* movl $+4, r1 */
150 0x2b, 0x41, /* jmp @r1 */
151 0xa0, 0xff, /* .long 0xffffffa0 */
152 0xff, 0xff };
153 gboolean dreamcast_load_fakebios( )
154 {
155 memset( dc_boot_rom, 0, 2 MB );
156 memcpy( dc_boot_rom, fakebios, sizeof(fakebios) );
157 syscall_add_hook( 0xA0, bios_boot );
158 dreamcast_has_bios = TRUE;
159 return TRUE;
160 }
162 gboolean dreamcast_load_flash( const gchar *filename )
163 {
164 if( filename != NULL && filename[0] != '\0' ) {
165 return mem_load_block( filename, 0x00200000, 0x00020000 ) == 0;
166 }
167 return FALSE;
168 }
171 gboolean dreamcast_config_changed(void *data, struct lxdream_config_group *group, unsigned item,
172 const gchar *oldval, const gchar *newval)
173 {
174 gchar *tmp;
175 switch(item) {
176 case CONFIG_BIOS_PATH:
177 tmp = get_expanded_path(newval);
178 dreamcast_load_bios(tmp);
179 g_free(tmp);
180 break;
181 case CONFIG_FLASH_PATH:
182 tmp = get_expanded_path(newval);
183 dreamcast_load_flash(tmp);
184 g_free(tmp);
185 break;
186 }
187 reset_gui_paths();
188 return TRUE;
189 }
191 void dreamcast_save_flash()
192 {
193 if( dreamcast_has_flash ) {
194 char *file = lxdream_get_global_config_path_value(CONFIG_FLASH_PATH);
195 mem_save_block( file, 0x00200000, 0x00020000 );
196 g_free(file);
197 }
198 }
200 /**
201 * Constructs a system configuration for the AICA in standalone mode,
202 * ie sound chip only.
203 */
204 void dreamcast_configure_aica_only( )
205 {
206 dreamcast_register_module( &mem_module );
207 mem_map_region( aica_main_ram, 0x00800000, 2 MB, MEM_REGION_AUDIO, &mem_region_audioram, MEM_FLAG_RAM, 2 MB, 0 );
208 mem_map_region( aica_scratch_ram, 0x00703000, 8 KB, MEM_REGION_AUDIO_SCRATCH, &mem_region_audioscratch, MEM_FLAG_RAM, 8 KB, 0 );
209 dreamcast_register_module( &aica_module );
210 aica_enable();
211 dreamcast_state = STATE_STOPPED;
212 }
214 void dreamcast_register_module( dreamcast_module_t module )
215 {
216 modules[num_modules++] = module;
217 if( module->init != NULL )
218 module->init();
219 }
221 void dreamcast_set_run_time( uint32_t secs, uint32_t nanosecs )
222 {
223 run_time_nanosecs = (((uint64_t)secs) * 1000000000) + nanosecs;
224 }
226 void dreamcast_set_exit_on_stop( gboolean flag )
227 {
228 dreamcast_exit_on_stop = flag;
229 }
231 void dreamcast_init( gboolean use_bootrom )
232 {
233 dreamcast_configure( use_bootrom );
234 dreamcast_state = STATE_STOPPED;
235 }
237 void dreamcast_reset( void )
238 {
239 sh4_core_exit(CORE_EXIT_SYSRESET);
240 int i;
241 for( i=0; i<num_modules; i++ ) {
242 if( modules[i]->reset != NULL )
243 modules[i]->reset();
244 }
245 }
247 void dreamcast_run( void )
248 {
249 int i;
251 if( !dreamcast_can_run() ) {
252 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"));
253 return;
254 }
256 if( dreamcast_state != STATE_RUNNING ) {
257 for( i=0; i<num_modules; i++ ) {
258 if( modules[i]->start != NULL )
259 modules[i]->start();
260 }
261 }
263 if( maple_should_grab() ) {
264 gui_set_use_grab(TRUE);
265 }
267 dreamcast_state = STATE_RUNNING;
269 if( run_time_nanosecs != 0 ) {
270 while( dreamcast_state == STATE_RUNNING ) {
271 uint32_t time_to_run = timeslice_length;
272 if( run_time_nanosecs < time_to_run ) {
273 time_to_run = (uint32_t)run_time_nanosecs;
274 }
276 for( i=0; i<num_modules; i++ ) {
277 if( modules[i]->run_time_slice != NULL )
278 time_to_run = modules[i]->run_time_slice( time_to_run );
279 }
281 if( run_time_nanosecs > time_to_run ) {
282 run_time_nanosecs -= time_to_run;
283 } else {
284 run_time_nanosecs = 0; // Finished
285 break;
286 }
287 }
288 } else {
289 while( dreamcast_state == STATE_RUNNING ) {
290 int time_to_run = timeslice_length;
291 for( i=0; i<num_modules; i++ ) {
292 if( modules[i]->run_time_slice != NULL )
293 time_to_run = modules[i]->run_time_slice( time_to_run );
294 }
296 }
297 }
299 gui_set_use_grab(FALSE);
301 for( i=0; i<num_modules; i++ ) {
302 if( modules[i]->stop != NULL )
303 modules[i]->stop();
304 }
306 vmulist_save_all();
307 dreamcast_state = STATE_STOPPED;
309 if( dreamcast_exit_on_stop ) {
310 dreamcast_shutdown();
311 exit(0);
312 }
313 }
315 void dreamcast_stop( void )
316 {
317 sh4_core_exit(CORE_EXIT_HALT); // returns only if not inside SH4 core
318 if( dreamcast_state == STATE_RUNNING )
319 dreamcast_state = STATE_STOPPING;
320 }
322 void dreamcast_shutdown()
323 {
324 // Don't do a dreamcast_stop - if we're calling this out of SH4 code,
325 // it's a shutdown-and-quit event
326 if( dreamcast_state == STATE_RUNNING )
327 dreamcast_state = STATE_STOPPING;
328 dreamcast_save_flash();
329 vmulist_save_all();
330 #ifdef ENABLE_SH4STATS
331 sh4_stats_print(stdout);
332 #endif
333 }
335 void dreamcast_program_loaded( const gchar *name, sh4addr_t entry_point )
336 {
337 if( dreamcast_program_name != NULL ) {
338 g_free(dreamcast_program_name);
339 }
340 dreamcast_program_name = g_strdup(name);
341 dreamcast_entry_point = entry_point;
342 sh4_set_pc(entry_point);
343 sh4_write_sr( sh4_read_sr() & (~SR_BL) ); /* Unmask interrupts */
344 bios_install();
345 dcload_install();
346 gui_update_state();
347 }
349 gboolean dreamcast_is_running( void )
350 {
351 return dreamcast_state == STATE_RUNNING;
352 }
354 gboolean dreamcast_can_run(void)
355 {
356 return dreamcast_state != STATE_UNINIT;
357 }
359 /********************************* Save States *****************************/
361 struct save_state_header {
362 char magic[16];
363 uint32_t version;
364 uint32_t module_count;
365 };
367 struct chunk_header {
368 char marker[4]; /* Always BLCK */
369 char name[8]; /* Block (module) name */
370 uint32_t block_length;
371 };
373 /**
374 * Check the save state header to ensure that it is a valid, supported
375 * file.
376 * @return the number of blocks following, or 0 if the file is invalid.
377 */
378 int dreamcast_read_save_state_header( FILE *f, char *error, int errorlen )
379 {
380 struct save_state_header header;
381 if( fread( &header, sizeof(header), 1, f ) != 1 ) {
382 return 0;
383 }
384 if( strncmp( header.magic, DREAMCAST_SAVE_MAGIC, 16 ) != 0 ) {
385 if( error != NULL )
386 snprintf( error, errorlen, _("File is not a %s save state"), APP_NAME );
387 return 0;
388 }
389 if( header.version != DREAMCAST_SAVE_VERSION ) {
390 if( error != NULL )
391 snprintf( error, errorlen, _("Unsupported %s save state version"), APP_NAME );
392 return 0;
393 }
394 if( header.module_count > MAX_MODULES ) {
395 if( error != NULL )
396 snprintf( error, errorlen, _("%s save state is corrupted (bad module count)"), APP_NAME );
397 return 0;
398 }
399 return header.module_count;
400 }
402 int dreamcast_write_chunk_header( const gchar *name, uint32_t length, FILE *f )
403 {
404 struct chunk_header head;
406 memcpy( head.marker, "BLCK", 4 );
407 memset( head.name, 0, 8 );
408 memcpy( head.name, name, strlen(name) );
409 head.block_length = length;
410 return fwrite( &head, sizeof(head), 1, f );
411 }
414 frame_buffer_t dreamcast_load_preview( const gchar *filename )
415 {
416 int i;
417 FILE *f = fopen( filename, "r" );
418 if( f == NULL ) return NULL;
420 int module_count = dreamcast_read_save_state_header(f, NULL, 0);
421 if( module_count <= 0 ) {
422 fclose(f);
423 return NULL;
424 }
425 for( i=0; i<module_count; i++ ) {
426 struct chunk_header head;
427 if( fread( &head, sizeof(head), 1, f ) != 1 ) {
428 fclose(f);
429 return NULL;
430 }
431 if( memcmp("BLCK", head.marker, 4) != 0 ) {
432 fclose(f);
433 return NULL;
434 }
436 if( strcmp("PVR2", head.name) == 0 ) {
437 uint32_t buf_count;
438 int has_front;
439 fread( &buf_count, sizeof(buf_count), 1, f );
440 fread( &has_front, sizeof(has_front), 1, f );
441 if( buf_count != 0 && has_front ) {
442 frame_buffer_t result = read_png_from_stream(f);
443 fclose(f);
444 return result;
445 }
446 break;
447 } else {
448 fseek( f, head.block_length, SEEK_CUR );
449 }
450 }
451 return NULL;
452 }
454 gboolean dreamcast_load_state( const gchar *filename )
455 {
456 int i,j;
457 int module_count;
458 char error[128];
459 int have_read[MAX_MODULES];
461 FILE *f = fopen( filename, "r" );
462 if( f == NULL ) return FALSE;
464 module_count = dreamcast_read_save_state_header(f, error, sizeof(error));
465 if( module_count <= 0 ) {
466 ERROR( error );
467 fclose(f);
468 return FALSE;
469 }
471 for( i=0; i<MAX_MODULES; i++ ) {
472 have_read[i] = 0;
473 }
475 for( i=0; i<module_count; i++ ) {
476 struct chunk_header chunk;
477 fread( &chunk, sizeof(chunk), 1, f );
478 if( strncmp(chunk.marker, "BLCK", 4) != 0 ) {
479 ERROR( "%s save state is corrupted (missing block header %d)", APP_NAME, i );
480 fclose(f);
481 return FALSE;
482 }
484 /* Find the matching module by name */
485 for( j=0; j<num_modules; j++ ) {
486 if( strcmp(modules[j]->name,chunk.name) == 0 ) {
487 have_read[j] = 1;
488 if( modules[j]->load == NULL ) {
489 ERROR( "%s save state is corrupted (no loader for %s)", APP_NAME, modules[j]->name );
490 fclose(f);
491 return FALSE;
492 } else if( modules[j]->load(f) != 0 ) {
493 ERROR( "%s save state is corrupted (%s failed)", APP_NAME, modules[j]->name );
494 fclose(f);
495 return FALSE;
496 }
497 break;
498 }
499 }
500 if( j == num_modules ) {
501 fclose(f);
502 ERROR( "%s save state contains unrecognized section", APP_NAME );
503 return FALSE;
504 }
505 }
507 /* Any modules that we didn't load - reset to the default state.
508 * (ie it's not an error to skip a module if you don't actually
509 * care about its state).
510 */
511 for( j=0; j<num_modules; j++ ) {
512 if( have_read[j] == 0 && modules[j]->reset != NULL ) {
513 modules[j]->reset();
514 }
515 }
516 fclose(f);
517 INFO( "Save state read from %s", filename );
518 return TRUE;
519 }
521 int dreamcast_save_state( const gchar *filename )
522 {
523 int i;
524 FILE *f;
525 struct save_state_header header;
527 f = fopen( filename, "w" );
528 if( f == NULL )
529 return errno;
530 strcpy( header.magic, DREAMCAST_SAVE_MAGIC );
531 header.version = DREAMCAST_SAVE_VERSION;
532 header.module_count = 0;
534 for( i=0; i<num_modules; i++ ) {
535 if( modules[i]->save != NULL )
536 header.module_count++;
537 }
538 fwrite( &header, sizeof(header), 1, f );
539 for( i=0; i<num_modules; i++ ) {
540 if( modules[i]->save != NULL ) {
541 uint32_t blocklen, posn1, posn2;
542 dreamcast_write_chunk_header( modules[i]->name, 0, f );
543 posn1 = ftell(f);
544 modules[i]->save(f);
545 posn2 = ftell(f);
546 blocklen = posn2 - posn1;
547 fseek( f, posn1-4, SEEK_SET );
548 fwrite( &blocklen, sizeof(blocklen), 1, f );
549 fseek( f, posn2, SEEK_SET );
550 }
551 }
552 fclose( f );
553 INFO( "Save state written to %s", filename );
554 return 0;
555 }
557 /********************** Quick save state support ***********************/
558 /* This section doesn't necessarily belong here, but it probably makes the
559 * most sense here next to the regular save/load functions
560 */
562 static gchar *get_quick_state_filename( int state )
563 {
564 gchar *path = lxdream_get_global_config_path_value(CONFIG_SAVE_PATH);
565 gchar *str = g_strdup_printf( QUICK_STATE_FILENAME, path, state );
566 g_free( path );
567 return str;
568 }
571 static void dreamcast_quick_state_init()
572 {
573 const char *state = lxdream_get_global_config_value(CONFIG_QUICK_STATE);
574 if( state != NULL ) {
575 quick_save_state = atoi(state);
576 if( quick_save_state > MAX_QUICK_STATE ) {
577 quick_save_state = 0;
578 }
579 } else {
580 quick_save_state = 0;
581 }
582 }
584 void dreamcast_quick_save()
585 {
586 if( quick_save_state == -1 )
587 dreamcast_quick_state_init();
588 gchar *str = get_quick_state_filename(quick_save_state);
589 dreamcast_save_state(str);
590 g_free(str);
591 }
593 void dreamcast_quick_load()
594 {
595 if( quick_save_state == -1 )
596 dreamcast_quick_state_init();
597 gchar *str = get_quick_state_filename(quick_save_state);
598 dreamcast_load_state(str);
599 g_free(str);
600 }
602 unsigned int dreamcast_get_quick_state( )
603 {
604 if( quick_save_state == -1 )
605 dreamcast_quick_state_init();
606 return quick_save_state;
607 }
609 void dreamcast_set_quick_state( unsigned int state )
610 {
611 if( state <= MAX_QUICK_STATE && state != quick_save_state ) {
612 quick_save_state = state;
613 char buf[3];
614 sprintf( buf, "%d", quick_save_state );
615 lxdream_set_global_config_value(CONFIG_QUICK_STATE, buf);
616 lxdream_save_config();
617 }
618 }
620 gboolean dreamcast_has_quick_state( unsigned int state )
621 {
622 gchar *str = get_quick_state_filename(state);
623 int result = access(str, R_OK);
624 g_free(str);
625 return result == 0 ? TRUE : FALSE;
626 }
628 /********************* The Boot ROM address space **********************/
629 static int32_t FASTCALL ext_bootrom_read_long( sh4addr_t addr )
630 {
631 return *((int32_t *)(dc_boot_rom + (addr&0x001FFFFF)));
632 }
633 static int32_t FASTCALL ext_bootrom_read_word( sh4addr_t addr )
634 {
635 return SIGNEXT16(*((int16_t *)(dc_boot_rom + (addr&0x001FFFFF))));
636 }
637 static int32_t FASTCALL ext_bootrom_read_byte( sh4addr_t addr )
638 {
639 return SIGNEXT8(*((int16_t *)(dc_boot_rom + (addr&0x001FFFFF))));
640 }
641 static void FASTCALL ext_bootrom_read_burst( unsigned char *dest, sh4addr_t addr )
642 {
643 memcpy( dest, dc_boot_rom +(addr&0x001FFFFF), 32 );
644 }
646 struct mem_region_fn mem_region_bootrom = {
647 ext_bootrom_read_long, unmapped_write_long,
648 ext_bootrom_read_word, unmapped_write_long,
649 ext_bootrom_read_byte, unmapped_write_long,
650 ext_bootrom_read_burst, unmapped_write_burst };
652 /********************* The Flash RAM address space **********************/
653 static int32_t FASTCALL ext_flashram_read_long( sh4addr_t addr )
654 {
655 return *((int32_t *)(dc_flash_ram + (addr&0x0001FFFF)));
656 }
657 static int32_t FASTCALL ext_flashram_read_word( sh4addr_t addr )
658 {
659 return SIGNEXT16(*((int16_t *)(dc_flash_ram + (addr&0x0001FFFF))));
660 }
661 static int32_t FASTCALL ext_flashram_read_byte( sh4addr_t addr )
662 {
663 return SIGNEXT8(*((int16_t *)(dc_flash_ram + (addr&0x0001FFFF))));
664 }
665 static void FASTCALL ext_flashram_write_long( sh4addr_t addr, uint32_t val )
666 {
667 *(uint32_t *)(dc_flash_ram + (addr&0x0001FFFF)) = val;
668 asic_g2_write_word();
669 }
670 static void FASTCALL ext_flashram_write_word( sh4addr_t addr, uint32_t val )
671 {
672 *(uint16_t *)(dc_flash_ram + (addr&0x0001FFFF)) = (uint16_t)val;
673 asic_g2_write_word();
674 }
675 static void FASTCALL ext_flashram_write_byte( sh4addr_t addr, uint32_t val )
676 {
677 *(uint8_t *)(dc_flash_ram + (addr&0x0001FFFF)) = (uint8_t)val;
678 asic_g2_write_word();
679 }
680 static void FASTCALL ext_flashram_read_burst( unsigned char *dest, sh4addr_t addr )
681 {
682 memcpy( dest, dc_flash_ram+(addr&0x0001FFFF), 32 );
683 }
684 static void FASTCALL ext_flashram_write_burst( sh4addr_t addr, unsigned char *src )
685 {
686 memcpy( dc_flash_ram+(addr&0x0001FFFF), src, 32 );
687 }
689 struct mem_region_fn mem_region_flashram = { ext_flashram_read_long, ext_flashram_write_long,
690 ext_flashram_read_word, ext_flashram_write_word,
691 ext_flashram_read_byte, ext_flashram_write_byte,
692 ext_flashram_read_burst, ext_flashram_write_burst };
.