Search
lxdream.org :: lxdream/src/dreamcast.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/dreamcast.c
changeset 953:f4a156508ad1
prev892:126aa7db6162
next1034:7044e01148f0
author nkeynes
date Tue Jan 13 11:56:28 2009 +0000 (13 years ago)
permissions -rw-r--r--
last change Merge lxdream-mem branch back to trunk
file annotate diff log raw
1.1 --- a/src/dreamcast.c Fri Oct 24 03:46:53 2008 +0000
1.2 +++ b/src/dreamcast.c Tue Jan 13 11:56:28 2009 +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 @@ -58,6 +59,22 @@
1.12 struct dreamcast_module unknown_module = { "****", NULL, NULL, NULL, NULL,
1.13 NULL, NULL, NULL };
1.14
1.15 +extern struct mem_region_fn mem_region_sdram;
1.16 +extern struct mem_region_fn mem_region_vram32;
1.17 +extern struct mem_region_fn mem_region_vram64;
1.18 +extern struct mem_region_fn mem_region_audioram;
1.19 +extern struct mem_region_fn mem_region_audioscratch;
1.20 +extern struct mem_region_fn mem_region_flashram;
1.21 +extern struct mem_region_fn mem_region_bootrom;
1.22 +extern struct mem_region_fn mem_region_pvr2ta;
1.23 +extern struct mem_region_fn mem_region_pvr2yuv;
1.24 +extern struct mem_region_fn mem_region_pvr2vdma1;
1.25 +extern struct mem_region_fn mem_region_pvr2vdma2;
1.26 +
1.27 +unsigned char dc_main_ram[16 MB];
1.28 +unsigned char dc_boot_rom[2 MB];
1.29 +unsigned char dc_flash_ram[128 KB];
1.30 +
1.31 /**
1.32 * This function is responsible for defining how all the pieces of the
1.33 * dreamcast actually fit together.
1.34 @@ -75,12 +92,19 @@
1.35 dreamcast_register_module( &mem_module );
1.36
1.37 /* Setup standard memory map */
1.38 - mem_create_repeating_ram_region( 0x0C000000, 16 MB, MEM_REGION_MAIN, 0x01000000, 0x0F000000 );
1.39 - mem_create_ram_region( 0x00800000, 2 MB, MEM_REGION_AUDIO );
1.40 - mem_create_ram_region( 0x00703000, 8 KB, MEM_REGION_AUDIO_SCRATCH );
1.41 - mem_create_ram_region( 0x05000000, 8 MB, MEM_REGION_VIDEO );
1.42 - dreamcast_has_bios = mem_load_rom( bios_path, 0x00000000, 0x00200000, 0x89f2b1a1, MEM_REGION_BIOS );
1.43 - mem_create_ram_region( 0x00200000, 0x00020000, MEM_REGION_FLASH );
1.44 + mem_map_region( dc_boot_rom, 0x00000000, 2 MB, MEM_REGION_BIOS, &mem_region_bootrom, MEM_FLAG_ROM, 2 MB, 0 );
1.45 + mem_map_region( dc_flash_ram, 0x00200000, 128 KB, MEM_REGION_FLASH, &mem_region_flashram, MEM_FLAG_RAM, 128 KB, 0 );
1.46 + mem_map_region( aica_main_ram, 0x00800000, 2 MB, MEM_REGION_AUDIO, &mem_region_audioram, MEM_FLAG_RAM, 2 MB, 0 );
1.47 + mem_map_region( aica_scratch_ram,0x00703000, 8 KB, MEM_REGION_AUDIO_SCRATCH,&mem_region_audioscratch, MEM_FLAG_RAM, 8 KB, 0 );
1.48 + mem_map_region( NULL, 0x04000000, 8 MB, MEM_REGION_VIDEO64, &mem_region_vram64, 0, 8 MB, 0 );
1.49 + mem_map_region( pvr2_main_ram, 0x05000000, 8 MB, MEM_REGION_VIDEO, &mem_region_vram32, MEM_FLAG_RAM, 8 MB, 0 );
1.50 + mem_map_region( dc_main_ram, 0x0C000000, 16 MB, MEM_REGION_MAIN, &mem_region_sdram, MEM_FLAG_RAM, 0x01000000, 0x0F000000 );
1.51 + mem_map_region( NULL, 0x10000000, 8 MB, MEM_REGION_PVR2TA, &mem_region_pvr2ta, 0, 0x02000000, 0x12000000 );
1.52 + mem_map_region( NULL, 0x10800000, 8 MB, MEM_REGION_PVR2YUV, &mem_region_pvr2yuv, 0, 0x02000000, 0x12800000 );
1.53 + mem_map_region( NULL, 0x11000000, 16 MB, MEM_REGION_PVR2VDMA1, &mem_region_pvr2vdma1, 0, 16 MB, 0 );
1.54 + mem_map_region( NULL, 0x13000000, 16 MB, MEM_REGION_PVR2VDMA2, &mem_region_pvr2vdma2, 0, 16 MB, 0 );
1.55 +
1.56 + dreamcast_has_bios = mem_load_rom( dc_boot_rom, bios_path, 2 MB, 0x89f2b1a1 );
1.57 if( flash_path != NULL && flash_path[0] != '\0' ) {
1.58 mem_load_block( flash_path, 0x00200000, 0x00020000 );
1.59 }
1.60 @@ -99,7 +123,7 @@
1.61 {
1.62 const char *bios_path = lxdream_get_config_value(CONFIG_BIOS_PATH);
1.63 const char *flash_path = lxdream_get_config_value(CONFIG_FLASH_PATH);
1.64 - dreamcast_has_bios = mem_load_rom( bios_path, 0x00000000, 0x00200000, 0x89f2b1a1, MEM_REGION_BIOS );
1.65 + dreamcast_has_bios = mem_load_rom( dc_boot_rom, bios_path, 2 MB, 0x89f2b1a1 );
1.66 if( flash_path != NULL && flash_path[0] != '\0' ) {
1.67 mem_load_block( flash_path, 0x00200000, 0x00020000 );
1.68 }
1.69 @@ -120,8 +144,8 @@
1.70 void dreamcast_configure_aica_only( )
1.71 {
1.72 dreamcast_register_module( &mem_module );
1.73 - mem_create_ram_region( 0x00800000, 2 MB, MEM_REGION_AUDIO );
1.74 - mem_create_ram_region( 0x00703000, 8 KB, MEM_REGION_AUDIO_SCRATCH );
1.75 + mem_map_region( aica_main_ram, 0x00800000, 2 MB, MEM_REGION_AUDIO, &mem_region_audioram, MEM_FLAG_RAM, 2 MB, 0 );
1.76 + mem_map_region( aica_scratch_ram, 0x00703000, 8 KB, MEM_REGION_AUDIO_SCRATCH, &mem_region_audioscratch, MEM_FLAG_RAM, 8 KB, 0 );
1.77 dreamcast_register_module( &aica_module );
1.78 aica_enable();
1.79 dreamcast_state = STATE_STOPPED;
1.80 @@ -253,6 +277,7 @@
1.81 dreamcast_program_name = g_strdup(name);
1.82 dreamcast_entry_point = entry_point;
1.83 sh4_set_pc(entry_point);
1.84 + sh4_write_sr( sh4_read_sr() & (~SR_BL) ); /* Unmask interrupts */
1.85 bios_install();
1.86 dcload_install();
1.87 gui_update_state();
1.88 @@ -467,3 +492,69 @@
1.89 return 0;
1.90 }
1.91
1.92 +/********************* The Boot ROM address space **********************/
1.93 +static int32_t FASTCALL ext_bootrom_read_long( sh4addr_t addr )
1.94 +{
1.95 + return *((int32_t *)(dc_boot_rom + (addr&0x001FFFFF)));
1.96 +}
1.97 +static int32_t FASTCALL ext_bootrom_read_word( sh4addr_t addr )
1.98 +{
1.99 + return SIGNEXT16(*((int16_t *)(dc_boot_rom + (addr&0x001FFFFF))));
1.100 +}
1.101 +static int32_t FASTCALL ext_bootrom_read_byte( sh4addr_t addr )
1.102 +{
1.103 + return SIGNEXT8(*((int16_t *)(dc_boot_rom + (addr&0x001FFFFF))));
1.104 +}
1.105 +static void FASTCALL ext_bootrom_read_burst( unsigned char *dest, sh4addr_t addr )
1.106 +{
1.107 + memcpy( dest, dc_boot_rom +(addr&0x001FFFFF), 32 );
1.108 +}
1.109 +
1.110 +struct mem_region_fn mem_region_bootrom = {
1.111 + ext_bootrom_read_long, unmapped_write_long,
1.112 + ext_bootrom_read_word, unmapped_write_long,
1.113 + ext_bootrom_read_byte, unmapped_write_long,
1.114 + ext_bootrom_read_burst, unmapped_write_burst };
1.115 +
1.116 +/********************* The Flash RAM address space **********************/
1.117 +static int32_t FASTCALL ext_flashram_read_long( sh4addr_t addr )
1.118 +{
1.119 + return *((int32_t *)(dc_flash_ram + (addr&0x0001FFFF)));
1.120 +}
1.121 +static int32_t FASTCALL ext_flashram_read_word( sh4addr_t addr )
1.122 +{
1.123 + return SIGNEXT16(*((int16_t *)(dc_flash_ram + (addr&0x0001FFFF))));
1.124 +}
1.125 +static int32_t FASTCALL ext_flashram_read_byte( sh4addr_t addr )
1.126 +{
1.127 + return SIGNEXT8(*((int16_t *)(dc_flash_ram + (addr&0x0001FFFF))));
1.128 +}
1.129 +static void FASTCALL ext_flashram_write_long( sh4addr_t addr, uint32_t val )
1.130 +{
1.131 + *(uint32_t *)(dc_flash_ram + (addr&0x0001FFFF)) = val;
1.132 + asic_g2_write_word();
1.133 +}
1.134 +static void FASTCALL ext_flashram_write_word( sh4addr_t addr, uint32_t val )
1.135 +{
1.136 + *(uint16_t *)(dc_flash_ram + (addr&0x0001FFFF)) = (uint16_t)val;
1.137 + asic_g2_write_word();
1.138 +}
1.139 +static void FASTCALL ext_flashram_write_byte( sh4addr_t addr, uint32_t val )
1.140 +{
1.141 + *(uint8_t *)(dc_flash_ram + (addr&0x0001FFFF)) = (uint8_t)val;
1.142 + asic_g2_write_word();
1.143 +}
1.144 +static void FASTCALL ext_flashram_read_burst( unsigned char *dest, sh4addr_t addr )
1.145 +{
1.146 + memcpy( dest, dc_flash_ram+(addr&0x0001FFFF), 32 );
1.147 +}
1.148 +static void FASTCALL ext_flashram_write_burst( sh4addr_t addr, unsigned char *src )
1.149 +{
1.150 + memcpy( dc_flash_ram+(addr&0x0001FFFF), src, 32 );
1.151 +}
1.152 +
1.153 +struct mem_region_fn mem_region_flashram = { ext_flashram_read_long, ext_flashram_write_long,
1.154 + ext_flashram_read_word, ext_flashram_write_word,
1.155 + ext_flashram_read_byte, ext_flashram_write_byte,
1.156 + ext_flashram_read_burst, ext_flashram_write_burst };
1.157 +
.