static void deco_decrypt(running_machine *machine,const char *rgntag,const UINT8 *xor_table,const UINT16 *address_table,const UINT8 *swap_table,int remap_only) { UINT16 *rom = (UINT16 *)machine->region(rgntag)->base(); int len = machine->region(rgntag)->bytes()/2; UINT16 *buffer = auto_alloc_array(machine, UINT16, len); int i; /* we work on 16-bit words but data is loaded as 8-bit, so swap bytes on LSB machines */ if (ENDIANNESS_NATIVE == ENDIANNESS_LITTLE) for (i = 0;i < len;i++) rom[i] = BIG_ENDIANIZE_INT16(rom[i]); memcpy(buffer,rom,len*2); for (i = 0;i < len;i++) { int addr = (i & ~0x7ff) | address_table[i & 0x7ff]; int pat = swap_table[i & 0x7ff]; if (remap_only) rom[i] = buffer[addr]; else rom[i] = BITSWAP16(buffer[addr] ^ xor_masks[xor_table[addr & 0x7ff]], swap_patterns[pat][0], swap_patterns[pat][1], swap_patterns[pat][2], swap_patterns[pat][3], swap_patterns[pat][4], swap_patterns[pat][5], swap_patterns[pat][6], swap_patterns[pat][7], swap_patterns[pat][8], swap_patterns[pat][9], swap_patterns[pat][10], swap_patterns[pat][11], swap_patterns[pat][12], swap_patterns[pat][13], swap_patterns[pat][14], swap_patterns[pat][15]); } auto_free(machine, buffer); /* we work on 16-bit words but data is loaded as 8-bit, so swap bytes on LSB machines */ if (ENDIANNESS_NATIVE == ENDIANNESS_LITTLE) for (i = 0;i < len;i++) rom[i] = BIG_ENDIANIZE_INT16(rom[i]); }
static void deco_decrypt(running_machine &machine,std::string rgntag,const UINT8 *xor_table,const UINT16 *address_table,const UINT8 *swap_table,int remap_only) { UINT16 *rom = (UINT16 *)machine.root_device().memregion(rgntag)->base(); int len = machine.root_device().memregion(rgntag)->bytes()/2; std::vector<UINT16> buffer(len); int i; /* we work on 16-bit words but data is loaded as 8-bit, so swap bytes on LSB machines */ if (ENDIANNESS_NATIVE == ENDIANNESS_LITTLE) for (i = 0;i < len;i++) rom[i] = BIG_ENDIANIZE_INT16(rom[i]); memcpy(&buffer[0],rom,len*2); for (i = 0;i < len;i++) { int addr = (i & ~0x7ff) | address_table[i & 0x7ff]; int pat = swap_table[i & 0x7ff]; if (remap_only) rom[i] = buffer[addr]; else rom[i] = BITSWAP16(buffer[addr] ^ xor_masks[xor_table[addr & 0x7ff]], swap_patterns[pat][0], swap_patterns[pat][1], swap_patterns[pat][2], swap_patterns[pat][3], swap_patterns[pat][4], swap_patterns[pat][5], swap_patterns[pat][6], swap_patterns[pat][7], swap_patterns[pat][8], swap_patterns[pat][9], swap_patterns[pat][10], swap_patterns[pat][11], swap_patterns[pat][12], swap_patterns[pat][13], swap_patterns[pat][14], swap_patterns[pat][15]); } /* we work on 16-bit words but data is loaded as 8-bit, so swap bytes on LSB machines */ if (ENDIANNESS_NATIVE == ENDIANNESS_LITTLE) for (i = 0;i < len;i++) rom[i] = BIG_ENDIANIZE_INT16(rom[i]); }
static int c64_crt_load( device_image_interface &image ) { legacy_c64_state *state = image.device().machine().driver_data<legacy_c64_state>(); int size = image.length(), test, i = 0, ii; int _80_loaded = 0, _90_loaded = 0, a0_loaded = 0, b0_loaded = 0, e0_loaded = 0, f0_loaded = 0; const char *filetype = image.filetype(); int address = 0, new_start = 0; // int lbank_end_addr = 0, hbank_end_addr = 0; UINT8 *cart_cpy = state->memregion("user1")->base(); /* We support .crt files */ if (!mame_stricmp(filetype, "crt")) { int j; unsigned short c64_cart_type; if (i >= C64_MAX_ROMBANK) return IMAGE_INIT_FAIL; /* Start to parse the .crt header */ /* 0x16-0x17 is Hardware type */ image.fseek(0x16, SEEK_SET); image.fread(&c64_cart_type, 2); state->m_cart.mapper = BIG_ENDIANIZE_INT16(c64_cart_type); /* If it is unsupported cart type, warn the user */ switch (state->m_cart.mapper) { case SIMONS_BASIC: /* Type # 4 */ case OCEAN_1: /* Type # 5 */ case FUN_PLAY: /* Type # 7 */ case SUPER_GAMES: /* Type # 8 */ case EPYX_FASTLOAD: /* Type # 10 */ case REX: /* Type # 12 */ case C64GS: /* Type # 15 */ case DINAMIC: /* Type # 17 */ case ZAXXON: /* Type # 18 */ case DOMARK: /* Type # 19 */ case COMAL_80: /* Type # 21 */ case GENERIC_CRT: /* Type # 0 */ printf("Currently supported cart type (Type %d)\n", state->m_cart.mapper); break; default: case ACTION_REPLAY: /* Type # 1 */ case KCS_PC: /* Type # 2 */ case FINAL_CART_III: /* Type # 3 */ case EXPERT: /* Type # 6 */ case ATOMIC_POWER: /* Type # 9 */ case WESTERMANN: /* Type # 11 */ case FINAL_CART_I: /* Type # 13 */ case MAGIC_FORMEL: /* Type # 14 */ case SUPER_SNAP_5: /* Type # 20 */ printf("Currently unsupported cart type (Type %d)\n", state->m_cart.mapper); break; } /* 0x18 is EXROM */ image.fseek(0x18, SEEK_SET); image.fread(&state->m_cart.exrom, 1); /* 0x19 is GAME */ image.fread(&state->m_cart.game, 1); /* We can pass to the data: it starts from 0x40 */ image.fseek(0x40, SEEK_SET); j = 0x40; logerror("Loading cart %s size:%.4x\n", image.filename(), size); logerror("Header info: EXROM %d, GAME %d, Cart Type %d \n", state->m_cart.exrom, state->m_cart.game, c64_cart_type); /* Data in a .crt image are organized in blocks called 'CHIP': each 'CHIP' consists of a 0x10 header, which contains the actual size of the block, the loading address and info on the bankswitch, followed by the actual data */ while (j < size) { unsigned short chip_size, chip_bank_index, chip_data_size; unsigned char buffer[10]; /* Start to parse the CHIP header */ /* First 4 bytes are the string 'CHIP' */ image.fread(buffer, 6); /* 0x06-0x07 is the size of the CHIP block (header + data) */ image.fread(&chip_size, 2); chip_size = BIG_ENDIANIZE_INT16(chip_size); /* 0x08-0x09 chip type (ROM, RAM + no ROM, Flash ROM) */ image.fread(buffer + 6, 2); /* 0x0a-0x0b is the bank number of the CHIP block */ image.fread(&chip_bank_index, 2); chip_bank_index = BIG_ENDIANIZE_INT16(chip_bank_index); /* 0x0c-0x0d is the loading address of the CHIP block */ image.fread(&address, 2); address = BIG_ENDIANIZE_INT16(address); /* 0x0e-0x0f is the data size of the CHIP block (without header) */ image.fread(&chip_data_size, 2); chip_data_size = BIG_ENDIANIZE_INT16(chip_data_size); /* Print out the CHIP header! */ logerror("%.4s %.2x %.2x %.4x %.2x %.2x %.4x %.4x:%.4x\n", buffer, buffer[4], buffer[5], chip_size, buffer[6], buffer[7], chip_bank_index, address, chip_data_size); logerror("Loading CHIP data at %.4x size:%.4x\n", address, chip_data_size); /* Store data, address & size of the CHIP block */ state->m_cart.bank[i].addr = address; state->m_cart.bank[i].index = chip_bank_index; state->m_cart.bank[i].size = chip_data_size; state->m_cart.bank[i].start = new_start; test = image.fread(cart_cpy + new_start, state->m_cart.bank[i].size); new_start += state->m_cart.bank[i].size; /* Does CHIP contain any data? */ if (test != state->m_cart.bank[i].size) return IMAGE_INIT_FAIL; /* Advance to the next CHIP block */ i++; j += chip_size; } } else /* We also support .80 files for c64 & .e0/.f0 for max */ { /* Assign loading address according to extension */ if (!mame_stricmp(filetype, "80")) address = 0x8000; if (!mame_stricmp(filetype, "e0")) address = 0xe000; if (!mame_stricmp(filetype, "f0")) address = 0xf000; logerror("loading %s rom at %.4x size:%.4x\n", image.filename(), address, size); /* Store data, address & size */ state->m_cart.bank[0].addr = address; state->m_cart.bank[0].size = size; state->m_cart.bank[0].start = new_start; test = image.fread(cart_cpy + new_start, state->m_cart.bank[0].size); new_start += state->m_cart.bank[0].size; /* Does cart contain any data? */ if (test != state->m_cart.bank[0].size) return IMAGE_INIT_FAIL; } state->m_cart.n_banks = i; // this is also needed so that we only set mappers if a cart is present! /* If we load a .crt file, use EXROM & GAME from the header! */ if ((state->m_cart.exrom != -1) && (state->m_cart.game != -1)) { state->m_exrom = state->m_cart.exrom; state->m_game = state->m_cart.game; } /* Finally load the cart */ state->m_roml = state->m_c64_roml; state->m_romh = state->m_c64_romh; memset(state->m_roml, 0, 0x2000); memset(state->m_romh, 0, 0x2000); switch (state->m_cart.mapper) { default: if (!state->m_game && state->m_exrom && (state->m_cart.n_banks == 1)) { memcpy(state->m_romh, cart_cpy, 0x2000); } else { // we first attempt to load the first 'CHIPs' with address 0x8000-0xb000 and 0xe000-0xf000, otherwise we load the first (or first two) 'CHIPs' of the image for (ii = 0; ii < state->m_cart.n_banks; ii++) { if (state->m_cart.bank[ii].addr == 0x8000 && !_80_loaded) { memcpy(state->m_roml, cart_cpy + state->m_cart.bank[ii].start, state->m_cart.bank[ii].size); _80_loaded = 1; if (state->m_cart.bank[ii].size > 0x1000) _90_loaded = 1; if (state->m_cart.bank[ii].size > 0x2000) a0_loaded = 1; if (state->m_cart.bank[ii].size > 0x3000) b0_loaded = 1; // printf("addr 0x8000: 80 %d, 90 %d, a0 %d, b0 %d\n", _80_loaded, _90_loaded, a0_loaded, b0_loaded); } if (state->m_cart.bank[ii].addr == 0x9000 && !_90_loaded) { memcpy(state->m_roml + 0x1000, cart_cpy + state->m_cart.bank[ii].start, state->m_cart.bank[ii].size); _90_loaded = 1; if (state->m_cart.bank[ii].size > 0x1000) a0_loaded = 1; if (state->m_cart.bank[ii].size > 0x2000) b0_loaded = 1; // printf("addr 0x9000: 80 %d, 90 %d, a0 %d, b0 %d\n", _80_loaded, _90_loaded, a0_loaded, b0_loaded); } if (state->m_cart.bank[ii].addr == 0xa000 && !a0_loaded) { memcpy(state->m_roml + 0x2000, cart_cpy + state->m_cart.bank[ii].start, state->m_cart.bank[ii].size); a0_loaded = 1; if (state->m_cart.bank[ii].size > 0x1000) b0_loaded = 1; // printf("addr 0xa000: 80 %d, 90 %d, a0 %d, b0 %d\n", _80_loaded, _90_loaded, a0_loaded, b0_loaded); } if (state->m_cart.bank[ii].addr == 0xb000 && !b0_loaded) { memcpy(state->m_roml + 0x3000, cart_cpy + state->m_cart.bank[ii].start, state->m_cart.bank[ii].size); b0_loaded = 1; // printf("addr 0xb000: 80 %d, 90 %d, a0 %d, b0 %d\n", _80_loaded, _90_loaded, a0_loaded, b0_loaded); } if (state->m_cart.bank[ii].addr == 0xe000 && !e0_loaded) { memcpy(state->m_romh, cart_cpy + state->m_cart.bank[ii].start, state->m_cart.bank[ii].size); e0_loaded = 1; if (state->m_cart.bank[ii].size > 0x1000) f0_loaded = 1; // printf("addr 0xe000: e0 %d, f0 %d\n", e0_loaded, f0_loaded); } if (state->m_cart.bank[ii].addr == 0xf000 && !f0_loaded) { memcpy(state->m_romh + 0x1000, cart_cpy + state->m_cart.bank[ii].start, state->m_cart.bank[ii].size); f0_loaded = 1; // printf("addr 0xe000: e0 %d, f0 %d\n", e0_loaded, f0_loaded); } } } } return IMAGE_INIT_PASS; }
static void get_audio_data(cdda_info *info, stream_sample_t *bufL, stream_sample_t *bufR, UINT32 samples_wanted) { int i, sectoread, remaining; INT16 *audio_cache = (INT16 *) info->audio_cache; /* if no file, audio not playing, audio paused, or out of disc data, just zero fill */ if (!info->disc || !info->audio_playing || info->audio_pause || (!info->audio_length && !info->audio_samples)) { if( info->disc && info->audio_playing && !info->audio_pause && !info->audio_length ) { info->audio_playing = FALSE; info->audio_ended_normally = TRUE; } memset(bufL, 0, sizeof(stream_sample_t)*samples_wanted); memset(bufR, 0, sizeof(stream_sample_t)*samples_wanted); return; } /* if we've got enough samples, just feed 'em out */ if (samples_wanted <= info->audio_samples) { for (i = 0; i < samples_wanted; i++) { *bufL++ = audio_cache[ info->audio_bptr++ ]; *bufR++ = audio_cache[ info->audio_bptr++ ]; } info->audio_samples -= samples_wanted; return; } /* we don't have enough, so first feed what we've got */ for (i = 0; i < info->audio_samples; i++) { *bufL++ = audio_cache[ info->audio_bptr++ ]; *bufR++ = audio_cache[ info->audio_bptr++ ]; } /* remember how much left for later */ remaining = samples_wanted - info->audio_samples; /* reset the buffer and get what we can from the disc */ info->audio_samples = 0; if (info->audio_length >= MAX_SECTORS) { sectoread = MAX_SECTORS; } else { sectoread = info->audio_length; } for (i = 0; i < sectoread; i++) { cdrom_read_data(info->disc, info->audio_lba, &info->audio_cache[CD_MAX_SECTOR_DATA*i], CD_TRACK_AUDIO); info->audio_lba++; } info->audio_samples = (CD_MAX_SECTOR_DATA*sectoread)/4; info->audio_length -= sectoread; /* CD-DA data on the disc is big-endian, flip if we're not */ if (ENDIANNESS_NATIVE == ENDIANNESS_LITTLE) { for( i = 0; i < info->audio_samples * 2; i++ ) { audio_cache[ i ] = BIG_ENDIANIZE_INT16( audio_cache[ i ] ); } } /* reset feedout ptr */ info->audio_bptr = 0; /* we've got data, feed it out by calling ourselves recursively */ get_audio_data(info, bufL, bufR, remaining); }
static DEVICE_LOAD(cbm_rom) { int i; int size, j, read_; const char *filetype; int adr = 0; const struct IODevice *dev; for (i=0; (i<sizeof(cbm_rom) / sizeof(cbm_rom[0])) && (cbm_rom[i].size!=0); i++) ; if (i >= sizeof(cbm_rom) / sizeof(cbm_rom[0])) return INIT_FAIL; dev = cbm_rom_find_device(); size = image_length(image); filetype = image_filetype(image); if (filetype && !mame_stricmp(filetype, "prg")) { unsigned short in; image_fread (image, &in, 2); in = LITTLE_ENDIANIZE_INT16(in); logerror("rom prg %.4x\n", in); size -= 2; logerror("loading rom %s at %.4x size:%.4x\n", image_filename(image), in, size); cbm_rom[i].chip = (UINT8 *) image_malloc(image, size); if (!cbm_rom[i].chip) return INIT_FAIL; cbm_rom[i].addr=in; cbm_rom[i].size=size; read_ = image_fread (image, cbm_rom[i].chip, size); if (read_ != size) return INIT_FAIL; } else if (filetype && !mame_stricmp (filetype, "crt")) { unsigned short in; image_fseek(image, 0x18, SEEK_SET); image_fread(image, &cbm_c64_exrom, 1); image_fread(image, &cbm_c64_game, 1); image_fseek(image, 64, SEEK_SET); j = 64; logerror("loading rom %s size:%.4x\n", image_filename(image), size); while (j < size) { unsigned short segsize; unsigned char buffer[10], number; image_fread(image, buffer, 6); image_fread(image, &segsize, 2); segsize = BIG_ENDIANIZE_INT16(segsize); image_fread(image, buffer + 6, 3); image_fread(image, &number, 1); image_fread(image, &adr, 2); adr = BIG_ENDIANIZE_INT16(adr); image_fread(image, &in, 2); in = BIG_ENDIANIZE_INT16(in); logerror("%.4s %.2x %.2x %.4x %.2x %.2x %.2x %.2x %.4x:%.4x\n", buffer, buffer[4], buffer[5], segsize, buffer[6], buffer[7], buffer[8], number, adr, in); logerror("loading chip at %.4x size:%.4x\n", adr, in); cbm_rom[i].chip = (UINT8*) image_malloc(image, size); if (!cbm_rom[i].chip) return INIT_FAIL; cbm_rom[i].addr=adr; cbm_rom[i].size=in; read_ = image_fread(image, cbm_rom[i].chip, in); i++; if (read_ != in) return INIT_FAIL; j += 16 + in; } } else if (filetype) { if (mame_stricmp(filetype, "lo") == 0) adr = CBM_ROM_ADDR_LO; else if (mame_stricmp (filetype, "hi") == 0) adr = CBM_ROM_ADDR_HI; else if (mame_stricmp (filetype, "10") == 0) adr = 0x1000; else if (mame_stricmp (filetype, "20") == 0) adr = 0x2000; else if (mame_stricmp (filetype, "30") == 0) adr = 0x3000; else if (mame_stricmp (filetype, "40") == 0) adr = 0x4000; else if (mame_stricmp (filetype, "50") == 0) adr = 0x5000; else if (mame_stricmp (filetype, "60") == 0) adr = 0x6000; else if (mame_stricmp (filetype, "70") == 0) adr = 0x7000; else if (mame_stricmp (filetype, "80") == 0) adr = 0x8000; else if (mame_stricmp (filetype, "90") == 0) adr = 0x9000; else if (mame_stricmp (filetype, "a0") == 0) adr = 0xa000; else if (mame_stricmp (filetype, "b0") == 0) adr = 0xb000; else if (mame_stricmp (filetype, "e0") == 0) adr = 0xe000; else if (mame_stricmp (filetype, "f0") == 0) adr = 0xf000; else adr = CBM_ROM_ADDR_UNKNOWN; logerror("loading %s rom at %.4x size:%.4x\n", image_filename(image), adr, size); cbm_rom[i].chip = (UINT8*) image_malloc(image, size); if (!cbm_rom[i].chip) return INIT_FAIL; cbm_rom[i].addr=adr; cbm_rom[i].size=size; read_ = image_fread(image, cbm_rom[i].chip, size); if (read_ != size) return INIT_FAIL; } return INIT_PASS; }
void cdda_device::get_audio_data(stream_sample_t *bufL, stream_sample_t *bufR, UINT32 samples_wanted) { int i; INT16 *audio_cache = (INT16 *) m_audio_cache; while (samples_wanted > 0) { /* if no file, audio not playing, audio paused, or out of disc data, just zero fill */ if (!m_disc || !m_audio_playing || m_audio_pause || (!m_audio_length && !m_audio_samples)) { if( m_disc && m_audio_playing && !m_audio_pause && !m_audio_length ) { m_audio_playing = FALSE; m_audio_ended_normally = TRUE; } memset(bufL, 0, sizeof(stream_sample_t)*samples_wanted); memset(bufR, 0, sizeof(stream_sample_t)*samples_wanted); return; } int samples = samples_wanted; if (samples > m_audio_samples) { samples = m_audio_samples; } for (i = 0; i < samples; i++) { /* CD-DA data on the disc is big-endian */ *bufL++ = (INT16) BIG_ENDIANIZE_INT16( audio_cache[ m_audio_bptr ] ); m_audio_bptr++; *bufR++ = (INT16) BIG_ENDIANIZE_INT16( audio_cache[ m_audio_bptr ] ); m_audio_bptr++; } samples_wanted -= samples; m_audio_samples -= samples; if (m_audio_samples == 0) { int sectors = m_audio_length; if (sectors > MAX_SECTORS) { sectors = MAX_SECTORS; } for (i = 0; i < sectors; i++) { cdrom_read_data(m_disc, m_audio_lba, &m_audio_cache[CD_MAX_SECTOR_DATA*i], CD_TRACK_AUDIO); m_audio_lba++; } m_audio_samples = (CD_MAX_SECTOR_DATA*sectors)/4; m_audio_length -= sectors; /* reset feedout ptr */ m_audio_bptr = 0; } } }