~ubuntu-branches/debian/wheezy/mame/wheezy

« back to all changes in this revision

Viewing changes to src/emu/diimage.c

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach, Emmanuel Kasper, Félix Arreola Rodríguez, Jordi Mallach
  • Date: 2011-05-11 21:06:50 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110511210650-jizvh8a6x117y9hr
Tags: 0.142-1
[ Emmanuel Kasper ]
* New upstream release
* Set NOWERROR=1 to allow compiling with gcc-4.6
* Remove fix_powerpc_build.patch, as upstream has taken it in this release
* Add gnome-video-arcade front end as a suggested package

[ Félix Arreola Rodríguez ]
* Add kfreebsd-build.patch to quilt series, to fix build on kfreebsd

[ Jordi Mallach ]
* Remove unneeded and bogus addition of --with-quilt to the dh invocation.
* Add Cesare Falco (long time Ubuntu maintainer) to Uploaders, and wrap
  them into multiple lines.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
#include "ui.h"
42
42
#include "pool.h"
43
43
#include "zippath.h"
44
 
#include "hashfile.h"
45
44
 
46
45
 
47
46
//**************************************************************************
142
141
    using this device's partial hash if appropriate
143
142
-------------------------------------------------*/
144
143
 
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
146
145
{
147
146
        /* retrieve the partial hash func */
148
147
        device_image_partialhash_func partialhash = get_partial_hash();
149
148
 
150
149
        /* compute the hash */
151
150
        if (partialhash)
152
 
                partialhash(dest, (const unsigned char*)data, length, functions);
 
151
                partialhash(hashes, (const unsigned char*)data, length, types);
153
152
        else
154
 
                hash_compute(dest, (const unsigned char*)data, length, functions);
 
153
                hashes.compute(reinterpret_cast<const UINT8 *>(data), length, types);
155
154
}
156
155
 
157
156
 
395
394
    if (try_change_working_directory("software"))
396
395
    {
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))
400
399
        {
401
400
            gamedrv = driver_get_compatible(gamedrv);
432
431
                return NULL;
433
432
 
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();
436
435
}
437
436
 
438
437
 
445
444
    char full_tag[256];
446
445
 
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();
449
448
}
450
449
 
451
450
 
505
504
  to be loaded
506
505
****************************************************************************/
507
506
 
508
 
/*-------------------------------------------------
509
 
    hash_data_extract_crc32 - extract crc32 value
510
 
    from hash string
511
 
-------------------------------------------------*/
512
 
 
513
 
static UINT32 hash_data_extract_crc32(const char *d)
514
 
{
515
 
        UINT32 crc = 0;
516
 
        UINT8 crc_bytes[4];
517
 
 
518
 
        if (hash_data_extract_binary_checksum(d, HASH_CRC, crc_bytes) == 1)
519
 
        {
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);
524
 
        }
525
 
        return crc;
526
 
}
527
 
 
528
 
int device_image_interface::read_hash_config(const char *sysname)
529
 
{
530
 
    hash_file *hashfile = NULL;
531
 
    const hash_info *info = NULL;
532
 
 
533
 
    /* open the hash file */
534
 
    hashfile = hashfile_open(sysname, FALSE, NULL);
535
 
    if (!hashfile)
536
 
        goto done;
537
 
 
538
 
    /* look up this entry in the hash file */
539
 
    info = hashfile_lookup(hashfile, m_hash.cstr());
540
 
 
541
 
    if (!info)
542
 
        goto done;
543
 
 
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)     : "";
551
 
 
552
 
done:
553
 
    if (hashfile != NULL)
554
 
        hashfile_close(hashfile);
555
 
    return !hashfile || !info;
556
 
}
557
 
 
558
 
 
559
 
 
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)
562
509
{
563
510
    UINT32 size;
564
511
    UINT8 *buf = NULL;
565
512
 
566
 
    *dest = '\0';
 
513
    hashes.reset();
567
514
    size = (UINT32) length();
568
515
 
569
516
    buf = (UINT8*)malloc(size);
574
521
    fread(buf, size);
575
522
 
576
523
    if (partialhash)
577
 
        partialhash(dest, buf, size, hash_functions);
 
524
        partialhash(hashes, buf, size, types);
578
525
    else
579
 
        hash_compute(dest, buf, size, hash_functions);
 
526
        hashes.compute(buf, size, types);
580
527
 
581
528
    /* cleanup */
582
529
    free(buf);
587
534
 
588
535
void device_image_interface::image_checkhash()
589
536
{
590
 
    const game_driver *drv;
591
 
    char hash_string[HASH_BUF_SIZE];
592
537
    device_image_partialhash_func partialhash;
593
 
    int rc;
594
538
 
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)
597
541
    {
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();
609
553
 
610
 
        run_hash(partialhash, hash_string, HASH_CRC | HASH_MD5 | HASH_SHA1);
611
 
 
612
 
        m_hash = hash_string;
613
 
 
614
 
        /* now read the hash file */
615
 
        drv = device().machine->gamedrv;
616
 
        do
617
 
        {
618
 
            rc = read_hash_config(drv->name);
619
 
            drv = driver_get_compatible(drv);
620
 
        }
621
 
        while(rc && (drv != NULL));
 
554
        run_hash(partialhash, m_hash, hash_collection::HASH_TYPES_ALL);
622
555
    }
623
556
    return;
624
557
}
628
561
    UINT32 crc = 0;
629
562
 
630
563
        image_checkhash();
631
 
    if (m_hash)
632
 
        crc = hash_data_extract_crc32(m_hash.cstr());
 
564
    m_hash.crc(crc);
633
565
 
634
566
    return crc;
635
567
}
650
582
-------------------------------------------------*/
651
583
void device_image_interface::battery_load(void *buffer, int length, int fill)
652
584
{
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");
654
586
 
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);
657
589
}
658
590
 
664
596
-------------------------------------------------*/
665
597
void device_image_interface::battery_save(const void *buffer, int length)
666
598
{
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");
668
600
 
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);
671
603
}
672
604