142
141
using this device's partial hash if appropriate
143
142
-------------------------------------------------*/
145
void device_config_image_interface::device_compute_hash(char *dest, const void *data, size_t length, unsigned int functions) const
144
void device_config_image_interface::device_compute_hash(hash_collection &hashes, const void *data, size_t length, const char *types) const
147
146
/* retrieve the partial hash func */
148
147
device_image_partialhash_func partialhash = get_partial_hash();
150
149
/* compute the hash */
152
partialhash(dest, (const unsigned char*)data, length, functions);
151
partialhash(hashes, (const unsigned char*)data, length, types);
154
hash_compute(dest, (const unsigned char*)data, length, functions);
153
hashes.compute(reinterpret_cast<const UINT8 *>(data), length, types);
395
394
if (try_change_working_directory("software"))
397
396
/* now down to a directory for this computer */
398
gamedrv = device().machine->gamedrv;
397
gamedrv = &device().machine().system();
399
398
while(gamedrv && !try_change_working_directory(gamedrv->name))
401
400
gamedrv = driver_get_compatible(gamedrv);
434
433
sprintf( full_tag, "%s:%s", device().tag(), tag );
435
return device().machine->region( full_tag )->base();
434
return device().machine().region( full_tag )->base();
445
444
char full_tag[256];
447
446
sprintf( full_tag, "%s:%s", device().tag(), tag );
448
return device().machine->region( full_tag )->bytes();
447
return device().machine().region( full_tag )->bytes();
506
505
****************************************************************************/
508
/*-------------------------------------------------
509
hash_data_extract_crc32 - extract crc32 value
511
-------------------------------------------------*/
513
static UINT32 hash_data_extract_crc32(const char *d)
518
if (hash_data_extract_binary_checksum(d, HASH_CRC, crc_bytes) == 1)
520
crc = (((UINT32) crc_bytes[0]) << 24)
521
| (((UINT32) crc_bytes[1]) << 16)
522
| (((UINT32) crc_bytes[2]) << 8)
523
| (((UINT32) crc_bytes[3]) << 0);
528
int device_image_interface::read_hash_config(const char *sysname)
530
hash_file *hashfile = NULL;
531
const hash_info *info = NULL;
533
/* open the hash file */
534
hashfile = hashfile_open(sysname, FALSE, NULL);
538
/* look up this entry in the hash file */
539
info = hashfile_lookup(hashfile, m_hash.cstr());
544
/* copy the relevant entries */
545
m_longname = info->longname ? astring(info->longname) : "";
546
m_manufacturer = info->manufacturer ? astring(info->manufacturer) : "";
547
m_year = info->year ? astring(info->year) : "";
548
m_playable = info->playable ? astring(info->playable) : "";
549
m_pcb = info->pcb ? astring(info->pcb) : "";
550
m_extrainfo = info->extrainfo ? astring(info->extrainfo) : "";
553
if (hashfile != NULL)
554
hashfile_close(hashfile);
555
return !hashfile || !info;
560
void device_image_interface::run_hash(void (*partialhash)(char *, const unsigned char *, unsigned long, unsigned int),
561
char *dest, unsigned int hash_functions)
507
void device_image_interface::run_hash(void (*partialhash)(hash_collection &, const unsigned char *, unsigned long, const char *),
508
hash_collection &hashes, const char *types)
564
511
UINT8 *buf = NULL;
567
514
size = (UINT32) length();
569
516
buf = (UINT8*)malloc(size);
574
521
fread(buf, size);
577
partialhash(dest, buf, size, hash_functions);
524
partialhash(hashes, buf, size, types);
579
hash_compute(dest, buf, size, hash_functions);
526
hashes.compute(buf, size, types);
588
535
void device_image_interface::image_checkhash()
590
const game_driver *drv;
591
char hash_string[HASH_BUF_SIZE];
592
537
device_image_partialhash_func partialhash;
595
539
/* only calculate CRC if it hasn't been calculated, and the open_mode is read only */
596
if (!m_hash && !m_writeable && !m_created)
540
if (m_hash.first() == NULL && !m_writeable && !m_created)
598
542
/* do not cause a linear read of 600 megs please */
599
543
/* TODO: use SHA/MD5 in the CHD header as the hash */
607
551
/* retrieve the partial hash func */
608
552
partialhash = get_partial_hash();
610
run_hash(partialhash, hash_string, HASH_CRC | HASH_MD5 | HASH_SHA1);
612
m_hash = hash_string;
614
/* now read the hash file */
615
drv = device().machine->gamedrv;
618
rc = read_hash_config(drv->name);
619
drv = driver_get_compatible(drv);
621
while(rc && (drv != NULL));
554
run_hash(partialhash, m_hash, hash_collection::HASH_TYPES_ALL);
650
582
-------------------------------------------------*/
651
583
void device_image_interface::battery_load(void *buffer, int length, int fill)
653
astring *fname = astring_assemble_4(astring_alloc(), device().machine->gamedrv->name, PATH_SEPARATOR, m_basename_noext, ".nv");
585
astring *fname = astring_assemble_4(astring_alloc(), device().machine().system().name, PATH_SEPARATOR, m_basename_noext, ".nv");
655
image_battery_load_by_name(astring_c(fname), buffer, length, fill);
587
image_battery_load_by_name(device().machine().options(), astring_c(fname), buffer, length, fill);
656
588
astring_free(fname);
664
596
-------------------------------------------------*/
665
597
void device_image_interface::battery_save(const void *buffer, int length)
667
astring *fname = astring_assemble_4(astring_alloc(), device().machine->gamedrv->name, PATH_SEPARATOR, m_basename_noext, ".nv");
599
astring *fname = astring_assemble_4(astring_alloc(), device().machine().system().name, PATH_SEPARATOR, m_basename_noext, ".nv");
669
image_battery_save_by_name(astring_c(fname), buffer, length);
601
image_battery_save_by_name(device().machine().options(), astring_c(fname), buffer, length);
670
602
astring_free(fname);