trunk/src/mess/drivers/gba.c
| r20847 | r20848 | |
| 35 | 35 | va_start( v, s_fmt ); |
| 36 | 36 | vsprintf( buf, s_fmt, v ); |
| 37 | 37 | va_end( v ); |
| 38 | | logerror( "%08x: %s", machine.device("maincpu")->safe_pc(), buf ); |
| 38 | logerror( "%08x: %s", machine.driver_data<gba_state>()->m_maincpu->pc(), buf ); |
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
| r20847 | r20848 | |
| 2957 | 2957 | |
| 2958 | 2958 | DEVICE_IMAGE_LOAD_MEMBER( gba_state, gba_cart ) |
| 2959 | 2959 | { |
| 2960 | | UINT8 *ROM = image.device().machine().root_device().memregion("cartridge")->base(); |
| 2960 | UINT8 *ROM = memregion("cartridge")->base(); |
| 2961 | 2961 | UINT32 cart_size; |
| 2962 | 2962 | UINT32 chip = 0; |
| 2963 | | gba_state *state = image.device().machine().driver_data<gba_state>(); |
| 2964 | 2963 | |
| 2965 | | state->m_nvsize = 0; |
| 2966 | | state->m_flash_size = 0; |
| 2967 | | state->m_nvptr = (UINT8 *)NULL; |
| 2968 | | state->m_flash_battery_load = 0; |
| 2964 | m_nvsize = 0; |
| 2965 | m_flash_size = 0; |
| 2966 | m_nvptr = (UINT8 *)NULL; |
| 2967 | m_flash_battery_load = 0; |
| 2969 | 2968 | |
| 2970 | 2969 | if (image.software_entry() == NULL) |
| 2971 | 2970 | { |
| r20847 | r20848 | |
| 2994 | 2993 | mame_printf_info( "GBA: Detected (ROM) %s\n", gba_chip_string( chip).cstr()); |
| 2995 | 2994 | |
| 2996 | 2995 | // fix the previous value when possible |
| 2997 | | chip = gba_fix_wrong_chip(image.device().machine(), cart_size, chip); |
| 2996 | chip = gba_fix_wrong_chip(machine(), cart_size, chip); |
| 2998 | 2997 | } |
| 2999 | 2998 | |
| 3000 | 2999 | mame_printf_info( "GBA: Emulate %s\n", gba_chip_string( chip).cstr()); |
| 3001 | 3000 | |
| 3002 | 3001 | if ((chip & (GBA_CHIP_EEPROM | GBA_CHIP_EEPROM_4K | GBA_CHIP_EEPROM_64K)) != 0) |
| 3003 | 3002 | { |
| 3004 | | state->m_nvptr = (UINT8 *)&state->m_gba_eeprom; |
| 3005 | | state->m_nvsize = (chip & GBA_CHIP_EEPROM_64K) ? 0x2000 : 0x200; |
| 3003 | m_nvptr = (UINT8 *)m_gba_eeprom; |
| 3004 | m_nvsize = (chip & GBA_CHIP_EEPROM_64K) ? 0x2000 : 0x200; |
| 3006 | 3005 | |
| 3007 | | state->m_eeprom_addr_bits = (chip & GBA_CHIP_EEPROM_64K) ? 14 : 6; |
| 3006 | m_eeprom_addr_bits = (chip & GBA_CHIP_EEPROM_64K) ? 14 : 6; |
| 3008 | 3007 | |
| 3009 | 3008 | if (cart_size <= (16 * 1024 * 1024)) |
| 3010 | 3009 | { |
| 3011 | | image.device().machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0xd000000, 0xdffffff, read32_delegate(FUNC(gba_state::eeprom_r),state)); |
| 3012 | | image.device().machine().device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0xd000000, 0xdffffff, write32_delegate(FUNC(gba_state::eeprom_w),state)); |
| 3010 | m_maincpu->space(AS_PROGRAM).install_read_handler(0xd000000, 0xdffffff, read32_delegate(FUNC(gba_state::eeprom_r),this)); |
| 3011 | m_maincpu->space(AS_PROGRAM).install_write_handler(0xd000000, 0xdffffff, write32_delegate(FUNC(gba_state::eeprom_w),this)); |
| 3013 | 3012 | } |
| 3014 | 3013 | else |
| 3015 | 3014 | { |
| 3016 | | image.device().machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0xdffff00, 0xdffffff, read32_delegate(FUNC(gba_state::eeprom_r),state)); |
| 3017 | | image.device().machine().device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0xdffff00, 0xdffffff, write32_delegate(FUNC(gba_state::eeprom_w),state)); |
| 3015 | m_maincpu->space(AS_PROGRAM).install_read_handler(0xdffff00, 0xdffffff, read32_delegate(FUNC(gba_state::eeprom_r),this)); |
| 3016 | m_maincpu->space(AS_PROGRAM).install_write_handler(0xdffff00, 0xdffffff, write32_delegate(FUNC(gba_state::eeprom_w),this)); |
| 3018 | 3017 | } |
| 3019 | 3018 | } |
| 3020 | 3019 | |
| 3021 | 3020 | if (chip & GBA_CHIP_SRAM) |
| 3022 | 3021 | { |
| 3023 | | state->m_nvptr = (UINT8 *)&state->m_gba_sram; |
| 3024 | | state->m_nvsize = 0x10000; |
| 3022 | m_nvptr = (UINT8 *)&m_gba_sram; |
| 3023 | m_nvsize = 0x10000; |
| 3025 | 3024 | |
| 3026 | | image.device().machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0xe000000, 0xe00ffff, read32_delegate(FUNC(gba_state::sram_r),state)); |
| 3027 | | image.device().machine().device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0xe000000, 0xe00ffff, write32_delegate(FUNC(gba_state::sram_w),state)); |
| 3025 | m_maincpu->space(AS_PROGRAM).install_read_handler(0xe000000, 0xe00ffff, read32_delegate(FUNC(gba_state::sram_r),this)); |
| 3026 | m_maincpu->space(AS_PROGRAM).install_write_handler(0xe000000, 0xe00ffff, write32_delegate(FUNC(gba_state::sram_w),this)); |
| 3028 | 3027 | } |
| 3029 | 3028 | |
| 3030 | 3029 | if (chip & GBA_CHIP_FLASH_1M) |
| 3031 | 3030 | { |
| 3032 | | state->m_nvptr = NULL; |
| 3033 | | state->m_nvsize = 0; |
| 3034 | | state->m_flash_size = 0x20000; |
| 3035 | | state->m_flash_mask = 0x1ffff/4; |
| 3031 | m_nvptr = NULL; |
| 3032 | m_nvsize = 0; |
| 3033 | m_flash_size = 0x20000; |
| 3034 | m_flash_mask = 0x1ffff/4; |
| 3036 | 3035 | |
| 3037 | | image.device().machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0xe000000, 0xe01ffff, read32_delegate(FUNC(gba_state::flash_r),state)); |
| 3038 | | image.device().machine().device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0xe000000, 0xe01ffff, write32_delegate(FUNC(gba_state::flash_w),state)); |
| 3036 | m_maincpu->space(AS_PROGRAM).install_read_handler(0xe000000, 0xe01ffff, read32_delegate(FUNC(gba_state::flash_r),this)); |
| 3037 | m_maincpu->space(AS_PROGRAM).install_write_handler(0xe000000, 0xe01ffff, write32_delegate(FUNC(gba_state::flash_w),this)); |
| 3039 | 3038 | } |
| 3040 | 3039 | |
| 3041 | 3040 | if ((chip & GBA_CHIP_FLASH) || (chip & GBA_CHIP_FLASH_512)) |
| 3042 | 3041 | { |
| 3043 | | state->m_nvptr = NULL; |
| 3044 | | state->m_nvsize = 0; |
| 3045 | | state->m_flash_size = 0x10000; |
| 3046 | | state->m_flash_mask = 0xffff/4; |
| 3042 | m_nvptr = NULL; |
| 3043 | m_nvsize = 0; |
| 3044 | m_flash_size = 0x10000; |
| 3045 | m_flash_mask = 0xffff/4; |
| 3047 | 3046 | |
| 3048 | | image.device().machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0xe000000, 0xe00ffff, read32_delegate(FUNC(gba_state::flash_r),state)); |
| 3049 | | image.device().machine().device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0xe000000, 0xe00ffff, write32_delegate(FUNC(gba_state::flash_w),state)); |
| 3047 | m_maincpu->space(AS_PROGRAM).install_read_handler(0xe000000, 0xe00ffff, read32_delegate(FUNC(gba_state::flash_r),this)); |
| 3048 | m_maincpu->space(AS_PROGRAM).install_write_handler(0xe000000, 0xe00ffff, write32_delegate(FUNC(gba_state::flash_w),this)); |
| 3050 | 3049 | } |
| 3051 | 3050 | |
| 3052 | 3051 | if (chip & GBA_CHIP_RTC) |
| r20847 | r20848 | |
| 3055 | 3054 | } |
| 3056 | 3055 | |
| 3057 | 3056 | // if save media was found, reload it |
| 3058 | | if (state->m_nvsize > 0) |
| 3057 | if (m_nvsize > 0) |
| 3059 | 3058 | { |
| 3060 | | image.battery_load(state->m_nvptr, state->m_nvsize, 0x00); |
| 3061 | | state->m_nvimage = image; |
| 3059 | image.battery_load(m_nvptr, m_nvsize, 0x00); |
| 3060 | m_nvimage = image; |
| 3062 | 3061 | } |
| 3063 | 3062 | else |
| 3064 | 3063 | { |
| 3065 | | state->m_nvimage = NULL; |
| 3066 | | state->m_nvsize = 0; |
| 3064 | m_nvimage = NULL; |
| 3065 | m_nvsize = 0; |
| 3067 | 3066 | } |
| 3068 | 3067 | |
| 3069 | 3068 | // init the flash here so it gets the contents from the battery_load above |
| 3070 | | if (state->m_flash_size > 0) |
| 3069 | if (m_flash_size > 0) |
| 3071 | 3070 | { |
| 3072 | | if (state->m_flash_size == 0x10000) |
| 3073 | | state->m_mFlashDev = image.device().machine().device<intelfsh8_device>("pflash"); |
| 3071 | if (m_flash_size == 0x10000) |
| 3072 | m_mFlashDev = machine().device<intelfsh8_device>("pflash"); |
| 3074 | 3073 | else |
| 3075 | | state->m_mFlashDev = image.device().machine().device<intelfsh8_device>("sflash"); |
| 3076 | | state->m_flash_battery_load = 1; |
| 3077 | | state->m_nvimage = image; |
| 3074 | m_mFlashDev = machine().device<intelfsh8_device>("sflash"); |
| 3075 | m_flash_battery_load = 1; |
| 3076 | m_nvimage = image; |
| 3078 | 3077 | } |
| 3079 | 3078 | |
| 3080 | 3079 | // mirror the ROM |