Search
lxdream.org :: lxdream/src/dreamcast.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/dreamcast.c
changeset 934:3acd3b3ee6d1
prev931:430048ea8b71
next951:63483914846f
author nkeynes
date Fri Dec 26 14:25:23 2008 +0000 (11 years ago)
branchlxdream-mem
permissions -rw-r--r--
last change Change RAM regions to use static arrays rather than mmap regions, for a 2-3% performance gain.
General mem cleanups, including some save state fixes that break states again.
file annotate diff log raw
1.1 --- a/src/dreamcast.c Tue Dec 23 05:48:05 2008 +0000
1.2 +++ b/src/dreamcast.c Fri Dec 26 14:25:23 2008 +0000
1.3 @@ -29,6 +29,7 @@
1.4 #include "aica/aica.h"
1.5 #include "gdrom/ide.h"
1.6 #include "maple/maple.h"
1.7 +#include "pvr2/pvr2.h"
1.8 #include "sh4/sh4.h"
1.9 #include "sh4/sh4core.h"
1.10
1.11 @@ -70,6 +71,10 @@
1.12 extern struct mem_region_fn mem_region_pvr2vdma1;
1.13 extern struct mem_region_fn mem_region_pvr2vdma2;
1.14
1.15 +unsigned char dc_main_ram[16 MB];
1.16 +unsigned char dc_boot_rom[2 MB];
1.17 +unsigned char dc_flash_ram[128 KB];
1.18 +
1.19 /**
1.20 * This function is responsible for defining how all the pieces of the
1.21 * dreamcast actually fit together.
1.22 @@ -87,20 +92,19 @@
1.23 dreamcast_register_module( &mem_module );
1.24
1.25 /* Setup standard memory map */
1.26 - dreamcast_has_bios =
1.27 - mem_load_rom( bios_path, 0x00000000, 2 MB, 0x89f2b1a1, MEM_REGION_BIOS, &mem_region_bootrom );
1.28 - mem_create_ram_region( 0x00200000, 0x00020000, MEM_REGION_FLASH, &mem_region_flashram );
1.29 - mem_create_ram_region( 0x00800000, 2 MB, MEM_REGION_AUDIO, &mem_region_audioram );
1.30 - mem_create_ram_region( 0x00703000, 8 KB, MEM_REGION_AUDIO_SCRATCH, &mem_region_audioscratch );
1.31 - register_misc_region( 0x04000000, 8 MB, MEM_REGION_VIDEO64, &mem_region_vram64 );
1.32 - mem_create_ram_region( 0x05000000, 8 MB, MEM_REGION_VIDEO, &mem_region_vram32 );
1.33 - mem_create_repeating_ram_region( 0x0C000000, 16 MB, MEM_REGION_MAIN, &mem_region_sdram, 0x01000000, 0x0F000000 );
1.34 - register_misc_region( 0x10000000, 8 MB, "PVR2 TA Command 1", &mem_region_pvr2ta );
1.35 - register_misc_region( 0x10800000, 8 MB, "PVR2 YUV Decode 1", &mem_region_pvr2yuv );
1.36 - register_misc_region( 0x11000000, 16 MB,"PVR2 VRAM DMA 1", &mem_region_pvr2vdma1 );
1.37 - register_misc_region( 0x12000000, 8 MB, "PVR2 TA Command 2", &mem_region_pvr2ta );
1.38 - register_misc_region( 0x12800000, 8 MB, "PVR2 YUV Decode 2", &mem_region_pvr2yuv );
1.39 - register_misc_region( 0x13000000, 16 MB,"PVR2 VRAM DMA 2", &mem_region_pvr2vdma2 );
1.40 + mem_map_region( dc_boot_rom, 0x00000000, 2 MB, MEM_REGION_BIOS, &mem_region_bootrom, MEM_FLAG_ROM, 2 MB, 0 );
1.41 + mem_map_region( dc_flash_ram, 0x00200000, 128 KB, MEM_REGION_FLASH, &mem_region_flashram, MEM_FLAG_RAM, 128 KB, 0 );
1.42 + mem_map_region( aica_main_ram, 0x00800000, 2 MB, MEM_REGION_AUDIO, &mem_region_audioram, MEM_FLAG_RAM, 2 MB, 0 );
1.43 + mem_map_region( aica_scratch_ram,0x00703000, 8 KB, MEM_REGION_AUDIO_SCRATCH,&mem_region_audioscratch, MEM_FLAG_RAM, 8 KB, 0 );
1.44 + mem_map_region( NULL, 0x04000000, 8 MB, MEM_REGION_VIDEO64, &mem_region_vram64, 0, 8 MB, 0 );
1.45 + mem_map_region( pvr2_main_ram, 0x05000000, 8 MB, MEM_REGION_VIDEO, &mem_region_vram32, MEM_FLAG_RAM, 8 MB, 0 );
1.46 + mem_map_region( dc_main_ram, 0x0C000000, 16 MB, MEM_REGION_MAIN, &mem_region_sdram, MEM_FLAG_RAM, 0x01000000, 0x0F000000 );
1.47 + mem_map_region( NULL, 0x10000000, 8 MB, MEM_REGION_PVR2TA, &mem_region_pvr2ta, 0, 0x02000000, 0x12000000 );
1.48 + mem_map_region( NULL, 0x10800000, 8 MB, MEM_REGION_PVR2YUV, &mem_region_pvr2yuv, 0, 0x02000000, 0x12800000 );
1.49 + mem_map_region( NULL, 0x11000000, 16 MB, MEM_REGION_PVR2VDMA1, &mem_region_pvr2vdma1, 0, 16 MB, 0 );
1.50 + mem_map_region( NULL, 0x13000000, 16 MB, MEM_REGION_PVR2VDMA2, &mem_region_pvr2vdma2, 0, 16 MB, 0 );
1.51 +
1.52 + dreamcast_has_bios = mem_load_rom( dc_boot_rom, bios_path, 2 MB, 0x89f2b1a1 );
1.53 if( flash_path != NULL && flash_path[0] != '\0' ) {
1.54 mem_load_block( flash_path, 0x00200000, 0x00020000 );
1.55 }
1.56 @@ -119,7 +123,7 @@
1.57 {
1.58 const char *bios_path = lxdream_get_config_value(CONFIG_BIOS_PATH);
1.59 const char *flash_path = lxdream_get_config_value(CONFIG_FLASH_PATH);
1.60 - dreamcast_has_bios = mem_load_rom( bios_path, 0x00000000, 0x00200000, 0x89f2b1a1, MEM_REGION_BIOS, &mem_region_bootrom );
1.61 + dreamcast_has_bios = mem_load_rom( dc_boot_rom, bios_path, 2 MB, 0x89f2b1a1 );
1.62 if( flash_path != NULL && flash_path[0] != '\0' ) {
1.63 mem_load_block( flash_path, 0x00200000, 0x00020000 );
1.64 }
1.65 @@ -140,8 +144,8 @@
1.66 void dreamcast_configure_aica_only( )
1.67 {
1.68 dreamcast_register_module( &mem_module );
1.69 - mem_create_ram_region( 0x00800000, 2 MB, MEM_REGION_AUDIO, &mem_region_audioram );
1.70 - mem_create_ram_region( 0x00703000, 8 KB, MEM_REGION_AUDIO_SCRATCH, &mem_region_audioscratch );
1.71 + mem_map_region( aica_main_ram, 0x00800000, 2 MB, MEM_REGION_AUDIO, &mem_region_audioram, MEM_FLAG_RAM, 2 MB, 0 );
1.72 + mem_map_region( aica_scratch_ram, 0x00703000, 8 KB, MEM_REGION_AUDIO_SCRATCH, &mem_region_audioscratch, MEM_FLAG_RAM, 8 KB, 0 );
1.73 dreamcast_register_module( &aica_module );
1.74 aica_enable();
1.75 dreamcast_state = STATE_STOPPED;
1.76 @@ -487,3 +491,69 @@
1.77 return 0;
1.78 }
1.79
1.80 +/********************* The Boot ROM address space **********************/
1.81 +static int32_t FASTCALL ext_bootrom_read_long( sh4addr_t addr )
1.82 +{
1.83 + return *((int32_t *)(dc_boot_rom + (addr&0x001FFFFF)));
1.84 +}
1.85 +static int32_t FASTCALL ext_bootrom_read_word( sh4addr_t addr )
1.86 +{
1.87 + return SIGNEXT16(*((int16_t *)(dc_boot_rom + (addr&0x001FFFFF))));
1.88 +}
1.89 +static int32_t FASTCALL ext_bootrom_read_byte( sh4addr_t addr )
1.90 +{
1.91 + return SIGNEXT8(*((int16_t *)(dc_boot_rom + (addr&0x001FFFFF))));
1.92 +}
1.93 +static void FASTCALL ext_bootrom_read_burst( unsigned char *dest, sh4addr_t addr )
1.94 +{
1.95 + memcpy( dest, dc_boot_rom +(addr&0x001FFFFF), 32 );
1.96 +}
1.97 +
1.98 +struct mem_region_fn mem_region_bootrom = {
1.99 + ext_bootrom_read_long, unmapped_write_long,
1.100 + ext_bootrom_read_word, unmapped_write_long,
1.101 + ext_bootrom_read_byte, unmapped_write_long,
1.102 + ext_bootrom_read_burst, unmapped_write_burst };
1.103 +
1.104 +/********************* The Flash RAM address space **********************/
1.105 +static int32_t FASTCALL ext_flashram_read_long( sh4addr_t addr )
1.106 +{
1.107 + return *((int32_t *)(dc_flash_ram + (addr&0x0001FFFF)));
1.108 +}
1.109 +static int32_t FASTCALL ext_flashram_read_word( sh4addr_t addr )
1.110 +{
1.111 + return SIGNEXT16(*((int16_t *)(dc_flash_ram + (addr&0x0001FFFF))));
1.112 +}
1.113 +static int32_t FASTCALL ext_flashram_read_byte( sh4addr_t addr )
1.114 +{
1.115 + return SIGNEXT8(*((int16_t *)(dc_flash_ram + (addr&0x0001FFFF))));
1.116 +}
1.117 +static void FASTCALL ext_flashram_write_long( sh4addr_t addr, uint32_t val )
1.118 +{
1.119 + *(uint32_t *)(dc_flash_ram + (addr&0x0001FFFF)) = val;
1.120 + asic_g2_write_word();
1.121 +}
1.122 +static void FASTCALL ext_flashram_write_word( sh4addr_t addr, uint32_t val )
1.123 +{
1.124 + *(uint16_t *)(dc_flash_ram + (addr&0x0001FFFF)) = (uint16_t)val;
1.125 + asic_g2_write_word();
1.126 +}
1.127 +static void FASTCALL ext_flashram_write_byte( sh4addr_t addr, uint32_t val )
1.128 +{
1.129 + *(uint8_t *)(dc_flash_ram + (addr&0x0001FFFF)) = (uint8_t)val;
1.130 + asic_g2_write_word();
1.131 +}
1.132 +static void FASTCALL ext_flashram_read_burst( unsigned char *dest, sh4addr_t addr )
1.133 +{
1.134 + memcpy( dest, dc_flash_ram+(addr&0x0001FFFF), 32 );
1.135 +}
1.136 +static void FASTCALL ext_flashram_write_burst( sh4addr_t addr, unsigned char *src )
1.137 +{
1.138 + memcpy( dc_flash_ram+(addr&0x0001FFFF), src, 32 );
1.139 +}
1.140 +
1.141 +struct mem_region_fn mem_region_flashram = { ext_flashram_read_long, ext_flashram_write_long,
1.142 + ext_flashram_read_word, ext_flashram_write_word,
1.143 + ext_flashram_read_byte, ext_flashram_write_byte,
1.144 + ext_flashram_read_burst, ext_flashram_write_burst };
1.145 +
.