static void nvram_handler_at28c16( int chip, mame_file *file, int read_or_write ) { struct at28c16_chip *c; if( chip >= MAX_AT28C16_CHIPS ) { logerror( "at28c16_nvram_handler: invalid chip %d\n", chip ); return; } c = &at28c16[ chip ]; if( read_or_write ) { mame_fwrite( file, c->data, DATA_SIZE ); mame_fwrite( file, c->id, ID_SIZE ); } else { at28c16_init( chip ); if( file ) { mame_fread( file, c->data, DATA_SIZE ); mame_fread( file, c->id, ID_SIZE ); } } }
UINT32 mame_fwrite_swap(mame_file *file, const void *buffer, size_t length) { UINT8 *buf; UINT8 temp; int res; size_t i; /* swap the data first */ buf = (UINT8 *)buffer; for (i = 0; i < length; i += 2) { temp = buf[i]; buf[i] = buf[i + 1]; buf[i + 1] = temp; } /* do the write */ res = mame_fwrite(file, buffer, length); /* swap the data back */ for (i = 0; i < length; i += 2) { temp = buf[i]; buf[i] = buf[i + 1]; buf[i + 1] = temp; } return res; }
static DEVICE_NVRAM(x2212) { x2212_state *c = get_safe_token(device); if( read_or_write ) { mame_fwrite( file, c->sram, SIZE_DATA ); } else { if( file ) { mame_fread( file, c->e2prom, SIZE_DATA ); } else { if( c->default_data != NULL ) { memcpy( c->e2prom, c->default_data, SIZE_DATA ); } else { memset( c->e2prom, 0xff, SIZE_DATA ); } } memcpy( c->sram, c->e2prom, SIZE_DATA ); } }
static NVRAM_HANDLER( bmc_nvram ) { int i; if (read_or_write) mame_fwrite(file, stats_ram, stats_ram_size); else #ifdef NVRAM_HACK for (i = 0; i < stats_ram_size; i++) { stats_ram[i] = 0xff; init_stats(bmc_nv1,0); init_stats(bmc_nv2,0x3b0); init_stats(bmc_nv3,0xfe2); } #else if (file) mame_fread(file, stats_ram, stats_ram_size); else for (i = 0; i < stats_ram_size; i++) stats_ram[i] = 0xff; #endif }
static DEVICE_NVRAM(timekeeper) { timekeeper_state *c = get_safe_token(device); if( read_or_write ) { mame_fwrite( file, c->data, c->size ); } else { if( file ) { mame_fread( file, c->data, c->size ); } else { if( c->default_data != NULL ) { memcpy( c->data, c->default_data, c->size ); } else { memset( c->data, 0xff, c->size ); } } counters_to_ram( c ); } }
static NVRAM_HANDLER( namcosna1 ) { if( read_or_write ) { mame_fwrite( file, namcona1_nvmem, NA1_NVRAM_SIZE ); } else { if (file) { mame_fread( file, namcona1_nvmem, NA1_NVRAM_SIZE ); } else { memset( namcona1_nvmem, 0x00, NA1_NVRAM_SIZE ); switch( namcona1_gametype ) { case NAMCO_EXBANIA: memcpy( namcona1_nvmem, ExvaniaDefaultNvMem, sizeof(ExvaniaDefaultNvMem) ); break; case NAMCO_QUIZTOU: memcpy( namcona1_nvmem, QuiztouDefaultNvMem, sizeof(QuiztouDefaultNvMem) ); break; } } } } /* namcosna1_nvram_handler */
static void hs_save (void) { mame_file *f = mame_fopen (Machine->gamedrv->name, 0, FILETYPE_HIGHSCORE, 1); LOG(("hs_save\n")); if (f) { struct mem_range *mem_range = state.mem_range; LOG(("saving...\n")); while (mem_range) { UINT8 *data = osd_malloc (mem_range->num_bytes); if (data) { /* this buffer will almost certainly be small enough to be dynamically allocated, but let's avoid memory trashing just in case */ copy_from_memory (mem_range->cpu, mem_range->addr, data, mem_range->num_bytes); mame_fwrite(f, data, mem_range->num_bytes); } mem_range = mem_range->next; } mame_fclose(f); } }
static int ti99_hsgpl_file_save(mame_file *file) { UINT8 version; /* version flag */ version = 0; if (mame_fwrite(file, & version, 1) != 1) return 1; /* save DSR */ if (at29c040a_file_save(feeprom_dsr, file)) return 1; /* save GROM 0 */ if (at29c040a_file_save(feeprom_grom0, file)) return 1; /* save GROM 1 */ if (at29c040a_file_save(feeprom_grom1, file)) return 1; /* save ROM6 */ if (at29c040a_file_save(feeprom_rom6, file)) return 1; return 0; }
static NVRAM_HANDLER( bmcbowl ) { int i; if (read_or_write) mame_fwrite(file, stats_ram, stats_ram_size); else #ifdef NVRAM_HACK for (i = 0; i < stats_ram_size; i++) stats_ram[i] = 0xff; init_stats(bmc_nv1,ARRAY_LENGTH(bmc_nv1),0); init_stats(bmc_nv2,ARRAY_LENGTH(bmc_nv2),0x3b0); init_stats(bmc_nv3,ARRAY_LENGTH(bmc_nv3),0xfe2); #else if (file) mame_fread(file, stats_ram, stats_ram_size); else for (i = 0; i < stats_ram_size; i++) stats_ram[i] = 0xff; #endif }
void state_save_save_finish(void) { UINT32 signature; UINT8 flags = 0; TRACE(logerror("Finishing save\n")); /* compute the flags */ #ifndef LSB_FIRST flags |= SS_MSB_FIRST; #endif /* build up the header */ memcpy(ss_dump_array, ss_magic_num, 8); ss_dump_array[8] = SAVE_VERSION; ss_dump_array[9] = flags; memset(ss_dump_array+0xa, 0, 10); strcpy((char *)ss_dump_array+0xa, Machine->gamedrv->name); /* copy in the signature */ signature = get_signature(); *(UINT32 *)&ss_dump_array[0x14] = LITTLE_ENDIANIZE_INT32(signature); /* write the file */ mame_fwrite(ss_dump_file, ss_dump_array, ss_dump_size); /* free memory and reset the global states */ free(ss_dump_array); ss_dump_array = NULL; ss_dump_size = 0; ss_dump_file = NULL; }
static NVRAM_HANDLER( hyperspt ) { if (read_or_write) mame_fwrite(file,nvram,nvram_size); else if (file) mame_fread(file,nvram,nvram_size); }
void nvram_handler_intelflash(int chip,mame_file *file,int read_or_write) { struct flash_chip *c; if( chip >= FLASH_CHIPS_MAX ) { logerror( "intelflash_nvram: invalid chip %d\n", chip ); return; } c = &chips[ chip ]; switch( c->bits ) { case 8: if (read_or_write) { mame_fwrite( file, c->flash_memory, c->size ); } else if (file) { mame_fread( file, c->flash_memory, c->size ); } break; case 16: if (read_or_write) { mame_fwrite_lsbfirst( file, c->flash_memory, c->size ); } else if (file) { mame_fread_lsbfirst( file, c->flash_memory, c->size ); } break; } }
static void jchan_mcu_run(running_machine *machine) { UINT16 mcu_command = mcu_ram[0x0010/2]; /* command nb */ UINT16 mcu_offset = mcu_ram[0x0012/2] / 2; /* offset in shared RAM where MCU will write */ UINT16 mcu_subcmd = mcu_ram[0x0014/2]; /* sub-command parameter, happens only for command #4 */ logerror("%s : MCU executed command: %04X %04X %04X ",cpuexec_describe_context(machine),mcu_command,mcu_offset*2,mcu_subcmd); /* the only MCU commands found in program code are: - 0x04: protection: provide data (see below) and code - 0x03: read DSW - 0x02: load game settings \ stored in ATMEL AT93C46 chip, - 0x42: save game settings / 128 bytes serial EEPROM */ switch (mcu_command >> 8) { case 0x04: /* Protection: during self-test for mcu_subcmd = 0x3d, 0x3e, 0x3f */ { toxboy_handle_04_subcommand(machine,mcu_subcmd,mcu_ram); } break; case 0x03: // DSW { mcu_ram[mcu_offset] = input_port_read(machine, "DSW"); logerror("%s : MCU executed command: %04X %04X (read DSW)\n",cpuexec_describe_context(machine),mcu_command,mcu_offset*2); } break; case 0x02: /* load game settings from 93C46 EEPROM ($1090-$10dc) */ { mame_file *f; if ((f = nvram_fopen(machine, OPEN_FLAG_READ)) != 0) { mame_fread(f,&mcu_ram[mcu_offset], 128); mame_fclose(f); } logerror("(load NVRAM settings)\n"); } break; case 0x42: /* save game settings to 93C46 EEPROM ($50d4) */ { mame_file *f; if ((f = nvram_fopen(machine, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS)) != 0) { mame_fwrite(f,&mcu_ram[mcu_offset], 128); mame_fclose(f); } logerror("(save NVRAM settings)\n"); } break; default: logerror("- UNKNOWN COMMAND!!!\n"); } }
void intelfsh_device::nvram_write(mame_file &file) { UINT8 *buffer = global_alloc_array(UINT8, m_config.m_size); for (int byte = 0; byte < m_config.m_size; byte++) buffer[byte] = m_addrspace[0]->read_byte(byte); mame_fwrite(&file, buffer, m_config.m_size); global_free(buffer); }
static void coco_vhd_readwrite(UINT8 data) { mame_file *vhdfile; int result; int phyOffset; long nBA = bufferAddress; vhdfile = image_fp(vhd_image()); if (!vhdfile) { vhdStatus = 2; /* No VHD attached */ return; } result = mame_fseek(vhdfile, ((logicalRecordNumber)) * 256, SEEK_SET); if (result < 0) { vhdStatus = 5; /* access denied */ return; } phyOffset = coco3_mmu_translate( (nBA >> 12 ) / 2, nBA % 8192 ); switch(data) { case 0: /* Read sector */ result = mame_fread(vhdfile, &(mess_ram[phyOffset]), 256); if( result != 256 ) { vhdStatus = 5; /* access denied */ return; } vhdStatus = 0; /* Aok */ break; case 1: /* Write Sector */ result = mame_fwrite(vhdfile, &(mess_ram[phyOffset]), 256); if (result != 256) { vhdStatus = 5; /* access denied */ return; } vhdStatus = 0; /* Aok */ break; case 2: /* Flush file cache */ vhdStatus = 0; /* Aok */ break; default: vhdStatus = 0xfe; /* -2, Unknown command */ break; } }
void nvram_handler_generic_1fill(mame_file *file, int read_or_write) { if (read_or_write) mame_fwrite(file, generic_nvram, generic_nvram_size); else if (file) mame_fread(file, generic_nvram, generic_nvram_size); else memset(generic_nvram, 0xff, generic_nvram_size); }
void nvram_handler_generic_0fill(mame_file *file, int read_or_write) { if (read_or_write) mame_fwrite(file, nvram_select(), generic_nvram_size); else if (file) mame_fread(file, nvram_select(), generic_nvram_size); else memset(nvram_select(), 0, generic_nvram_size); }
static MEMCARD_HANDLER( neogeo ) { switch (action) { case MEMCARD_CREATE: memset(memcard_data, 0, MEMCARD_SIZE); mame_fwrite(file, memcard_data, MEMCARD_SIZE); break; case MEMCARD_INSERT: mame_fread(file, memcard_data, MEMCARD_SIZE); break; case MEMCARD_EJECT: mame_fwrite(file, memcard_data, MEMCARD_SIZE); break; } }
static NVRAM_HANDLER (quaquiz2) { if (read_or_write) mame_fwrite(file, generic_nvram, generic_nvram_size); else if (file) mame_fread(file, generic_nvram, generic_nvram_size); else memcpy ( generic_nvram, quaquiz2_default_eeprom, 0x100 ); }
static NVRAM_HANDLER(tomcat) { if (read_or_write) mame_fwrite(file, tomcat_nvram, 0x800); else if (file) mame_fread(file, tomcat_nvram, 0x800); else memset(tomcat_nvram, 0x00, 0x800); }
void eeprom_device::nvram_write(mame_file &file) { UINT32 eeprom_length = 1 << m_config.m_address_bits; UINT32 eeprom_bytes = eeprom_length * m_config.m_data_bits / 8; UINT8 *buffer = auto_alloc_array(&m_machine, UINT8, eeprom_bytes); for (offs_t offs = 0; offs < eeprom_bytes; offs++) buffer[offs] = m_addrspace[0]->read_byte(offs); mame_fwrite(&file, buffer, eeprom_bytes); auto_free(&m_machine, buffer); }
void mc146818_save(void) { mame_file *file; file = mame_fopen(Machine->gamedrv->name, 0, FILETYPE_NVRAM, 1); if (file) { mame_fwrite(file, mc146818->data, sizeof(mc146818->data)); mame_fclose(file); } }
static NVRAM_HANDLER( goldstar ) { if (read_or_write) mame_fwrite(file,nvram,nvram_size); else { if (file) mame_fread(file,nvram,nvram_size); else memset(nvram,0xff,nvram_size); } }
static NVRAM_HANDLER( bbusters ) { if( read_or_write ) { mame_fwrite (file, eprom_data, 0x80); } else { if (file) mame_fread (file, eprom_data, 0x80); else memset (eprom_data, 0xff, 0x80); } }
static void d88image_write_sector_data_from_buffer(mess_image *img, int side, int index1, const char *ptr, int length, int ddam) { d88image *w = get_d88image(img); d88sect *s = &(w->sects[w->track*2+side][index1]); if (d88image_seek(w, w->track, side, index1)) { mame_fwrite(w->image_file, ptr, length); } s->flags = ddam ? ID_FLAG_DELETED_DATA : 0; }
state_save_error state_save_write_file(running_machine *machine, mame_file *file) { state_private *global = machine->state_data; UINT32 signature = get_signature(machine); UINT8 header[HEADER_SIZE]; state_callback *func; state_entry *entry; /* if we have illegal registrations, return an error */ if (global->illegal_regs > 0) return STATERR_ILLEGAL_REGISTRATIONS; /* generate the header */ memcpy(&header[0], ss_magic_num, 8); header[8] = SAVE_VERSION; header[9] = NATIVE_ENDIAN_VALUE_LE_BE(0, SS_MSB_FIRST); strncpy((char *)&header[0x0a], machine->gamedrv->name, 0x1c - 0x0a); *(UINT32 *)&header[0x1c] = LITTLE_ENDIANIZE_INT32(signature); /* write the header and turn on compression for the rest of the file */ mame_fcompress(file, FCOMPRESS_NONE); mame_fseek(file, 0, SEEK_SET); if (mame_fwrite(file, header, sizeof(header)) != sizeof(header)) return STATERR_WRITE_ERROR; mame_fcompress(file, FCOMPRESS_MEDIUM); /* call the pre-save functions */ for (func = global->prefunclist; func != NULL; func = func->next) (*func->func.presave)(machine, func->param); /* then write all the data */ for (entry = global->entrylist; entry != NULL; entry = entry->next) { UINT32 totalsize = entry->typesize * entry->typecount; if (mame_fwrite(file, entry->data, totalsize) != totalsize) return STATERR_WRITE_ERROR; } return STATERR_NONE; }
void at28c16_device::nvram_write( mame_file &file ) { UINT8 *buffer = auto_alloc_array( &m_machine, UINT8, AT28C16_TOTAL_BYTES ); for( offs_t offs = 0; offs < AT28C16_TOTAL_BYTES; offs++ ) { buffer[ offs ] = m_addrspace[ 0 ]->read_byte( offs ); } mame_fwrite( &file, buffer, AT28C16_TOTAL_BYTES ); auto_free( &m_machine, buffer ); }
static NVRAM_HANDLER( cloud9 ) { if (read_or_write) { /* on power down, the EAROM is implicitly stored */ memcpy(generic_nvram, nvram_stage, generic_nvram_size); mame_fwrite(file, generic_nvram, generic_nvram_size); } else if (file) mame_fread(file, generic_nvram, generic_nvram_size); else memset(generic_nvram, 0, generic_nvram_size); }
static DEVICE_NVRAM(at28c16) { at28c16_state *c = get_safe_token(device); if( read_or_write ) { mame_fwrite( file, c->data, SIZE_DATA ); mame_fwrite( file, c->id, SIZE_ID ); } else { if( file ) { mame_fread( file, c->data, SIZE_DATA ); mame_fread( file, c->id, SIZE_ID ); } else { if( c->default_data != NULL ) { memcpy( c->data, c->default_data, SIZE_DATA ); } else { memset( c->data, 0xff, SIZE_DATA ); } if( c->default_id != NULL ) { memcpy( c->id, c->default_id, SIZE_ID ); } else { memset( c->id, 0xff, SIZE_ID ); } } } }
static NVRAM_HANDLER( capbowl ) { if (read_or_write) mame_fwrite(file, generic_nvram, generic_nvram_size); else if (file) mame_fread(file, generic_nvram, generic_nvram_size); else { /* invalidate nvram to make the game initialize it. A 0xff fill will cause the game to malfunction, so we use a 0x01 fill which seems OK */ memset(generic_nvram,0x01,generic_nvram_size); } }