예제 #1
0
int interrupt_read_snapshot(interrupt_cpu_status_t *cs, snapshot_module_t *m)
{
    unsigned int i;
    DWORD dw;

    for (i = 0; i < cs->num_ints; i++) {
        cs->pending_int[i] = IK_NONE;
    }

    cs->global_pending_int = IK_NONE;
    cs->nirq = cs->nnmi = cs->reset = cs->trap = 0;

    if (SMR_DW(m, &cs->irq_clk) < 0
        || SMR_DW(m, &cs->nmi_clk) < 0
        || SMR_DW(m, &cs->irq_pending_clk) < 0) {
        return -1;
    }

    if (SMR_DW(m, &dw) < 0) {
        return -1;
    }
    cs->num_last_stolen_cycles = dw;

    if (SMR_DW(m, &dw) < 0) {
        return -1;
    }
    cs->last_stolen_cycles_clk = dw;

    return 0;
}
예제 #2
0
int interrupt_read_snapshot(interrupt_cpu_status_t *cs, snapshot_module_t *m)
{
    unsigned int i;
    DWORD dw;

    for (i = 0; i < cs->num_ints; i++)
        cs->pending_int[i] = IK_NONE;
    cs->global_pending_int = IK_NONE;
    cs->nirq = cs->nnmi = cs->reset = cs->trap = 0;

    if (SMR_DW(m, &cs->irq_clk) < 0
        || SMR_DW(m, &cs->nmi_clk) < 0)
        return -1;

    if (SMR_DW(m, &dw) < 0)
        return -1;
    cs->num_last_stolen_cycles = dw;

    if (SMR_DW(m, &dw) < 0)
        return -1;
    cs->last_stolen_cycles_clk = dw;

    /* old-style snapshot need restore of the global interrupt settings */
    cs->needs_global_restore = 1;

    return 0;
}
예제 #3
0
파일: fdc.c 프로젝트: bobsummerwill/VICE
int fdc_snapshot_read_module(snapshot_t *p, int fnum)
{
    BYTE vmajor, vminor;
    BYTE byte, ndrv;
    DWORD dword;
    snapshot_module_t *m;
    char *name;

    name = lib_msprintf("FDC%d", fnum);

    m = snapshot_module_open(p, name, &vmajor, &vminor);
    lib_free(name);

    if (m == NULL) {
        log_message(fdc_log, "Could not find snapshot module %s", name);
        return -1;
    }

    if (vmajor != FDC_DUMP_VER_MAJOR) {
        log_error(fdc_log,
                  "Snapshot module version (%d.%d) newer than %d.%d.",
                  vmajor, vminor, FDC_DUMP_VER_MAJOR, FDC_DUMP_VER_MINOR);
        snapshot_module_close(m);
        return -1;
    }

    SMR_B(m, &byte);
    if (byte > FDC_LAST_STATE) {
        snapshot_module_close(m);
        return -1;
    }
    fdc[fnum].fdc_state = byte;

    /* clk till next invocation */
    SMR_DW(m, &dword);

    fdc[fnum].alarm_clk = drive_clk[fnum] + dword;
    alarm_set(fdc[fnum].fdc_alarm, fdc[fnum].alarm_clk);

    /* number of drives - so far 1 only */
    SMR_B(m, &ndrv);

    /* last accessed track/sector */
    SMR_B(m, &byte);
    fdc[fnum].last_track = byte;
    SMR_B(m, &byte);
    fdc[fnum].last_sector = byte;

    if (ndrv > 1) {
        /* ignore drv 0 values */
        SMR_B(m, &byte);
        SMR_B(m, &byte);
    }

    if (snapshot_module_close(m) < 0)
        return -1;

    return 0;
}
예제 #4
0
int interrupt_read_new_snapshot(interrupt_cpu_status_t *cs, snapshot_module_t *m)
{
    DWORD dw;

    if (SMR_DW(m, &dw) < 0)
        return 0;
    cs->nirq = dw;

    if (SMR_DW(m, &dw) < 0)
        return 0;
    cs->nnmi = dw;

    if (SMR_DW(m, &dw) < 0)
        return 0;
    cs->global_pending_int = dw;

    /* new-style snapshot need no restore of the global interrupt settings */
    cs->needs_global_restore = 0;

    return 0;
}
예제 #5
0
int maincpu_snapshot_read_module(snapshot_t *s)
{
    BYTE a, x, y, sp, status;
    WORD pc;
    BYTE major, minor;
    snapshot_module_t *m;

    m = snapshot_module_open(s, snap_module_name, &major, &minor);
    if (m == NULL) {
        return -1;
    }

    /* FIXME: This is a mighty kludge to prevent VIC-II from stealing the
       wrong number of cycles.  */
    maincpu_rmw_flag = 0;

    /* XXX: Assumes `CLOCK' is the same size as a `DWORD'.  */
    if (0
        || SMR_DW(m, &maincpu_clk) < 0
        || SMR_B(m, &a) < 0
        || SMR_B(m, &x) < 0
        || SMR_B(m, &y) < 0
        || SMR_B(m, &sp) < 0
        || SMR_W(m, &pc) < 0
        || SMR_B(m, &status) < 0
        || SMR_DW_UINT(m, &last_opcode_info) < 0) {
        goto fail;
    }

    MOS6510_REGS_SET_A(&maincpu_regs, a);
    MOS6510_REGS_SET_X(&maincpu_regs, x);
    MOS6510_REGS_SET_Y(&maincpu_regs, y);
    MOS6510_REGS_SET_SP(&maincpu_regs, sp);
    MOS6510_REGS_SET_PC(&maincpu_regs, pc);
    MOS6510_REGS_SET_STATUS(&maincpu_regs, status);

    if (interrupt_read_snapshot(maincpu_int_status, m) < 0) {
        goto fail;
    }

    if (interrupt_read_new_snapshot(maincpu_int_status, m) < 0) {
        goto fail;
    }

    return snapshot_module_close(m);

fail:
    if (m != NULL) {
        snapshot_module_close(m);
    }
    return -1;
}
예제 #6
0
int rtc72421_read_snapshot(rtc_72421_t *context, snapshot_t *s)
{
    DWORD latch_lo = 0;
    DWORD latch_hi = 0;
    DWORD offset_lo = 0;
    DWORD offset_hi = 0;
    DWORD old_offset_lo = 0;
    DWORD old_offset_hi = 0;
    BYTE vmajor, vminor;
    snapshot_module_t *m;

    m = snapshot_module_open(s, snap_module_name, &vmajor, &vminor);

    if (m == NULL) {
        return -1;
    }

    /* Do not accept versions higher than current */
    if (vmajor > SNAP_MAJOR || vminor > SNAP_MINOR) {
        snapshot_set_error(SNAPSHOT_MODULE_HIGHER_VERSION);
        goto fail;
    }

    if (0
        || SMR_B_INT(m, &context->stop) < 0
        || SMR_B_INT(m, &context->hour24) < 0
        || SMR_DW(m, &latch_hi) < 0
        || SMR_DW(m, &latch_lo) < 0
        || SMR_DW(m, &offset_hi) < 0
        || SMR_DW(m, &offset_lo) < 0
        || SMR_DW(m, &old_offset_hi) < 0
        || SMR_DW(m, &old_offset_lo) < 0
        || SMR_STR(m, &context->device) < 0) {
        goto fail;
    }

#if (SIZE_OF_TIME_T == 8)
    context->latch = (time_t)(latch_hi) << 32;
    context->latch |= latch_lo;
    context->offset = (time_t)(offset_hi) << 32;
    context->offset |= offset_lo;
    context->old_offset = (time_t)(old_offset_hi) << 32;
    context->old_offset |= old_offset_lo;
#else
    context->latch = latch_lo;
    context->offset = offset_lo;
    context->old_offset = old_offset_lo;
#endif

    return snapshot_module_close(m);

fail:
    snapshot_module_close(m);
    return -1;
}
예제 #7
0
파일: cbm5x0.c 프로젝트: SMTDDR/droidsound
int cbm2_c500_snapshot_read_module(snapshot_t *p)
{
    BYTE vmajor, vminor;
    snapshot_module_t *m;
    DWORD dword;

    m = snapshot_module_open(p, module_name, &vmajor, &vminor);
    if (m == NULL)
        return -1;

    if (vmajor != C500DATA_DUMP_VER_MAJOR) {
        snapshot_module_close(m);
        return -1;
    }

    SMR_DW(m, &dword);
    c500_powerline_clk = maincpu_clk + dword;
    alarm_set(c500_powerline_clk_alarm, c500_powerline_clk);

    snapshot_module_close(m);

    return 0;
}
예제 #8
0
int epyxfastload_snapshot_read_module(snapshot_t *s)
{
    BYTE vmajor, vminor;
    snapshot_module_t *m;

    CLOCK temp_clk;

    m = snapshot_module_open(s, SNAP_MODULE_NAME, &vmajor, &vminor);
    if (m == NULL) {
        return -1;
    }

    if ((vmajor != CART_DUMP_VER_MAJOR) || (vminor != CART_DUMP_VER_MINOR)) {
        snapshot_module_close(m);
        return -1;
    }

    if (0
        || (SMR_DW(m, &temp_clk) < 0)
        || (SMR_BA(m, roml_banks, 0x2000) < 0)) {
        snapshot_module_close(m);
        return -1;
    }

    snapshot_module_close(m);

    if (epyxfastload_common_attach() < 0) {
        return -1;
    }

    if (temp_clk < CLOCK_MAX) {
        epyxrom_alarm_time = temp_clk;
        alarm_set(epyxrom_alarm, epyxrom_alarm_time);
    }

    return 0;
}
예제 #9
0
static int drive_snapshot_read_gcrimage_module(snapshot_t *s, unsigned int dnr)
{
    BYTE major_version, minor_version;
    snapshot_module_t *m;
    char snap_module_name[10];
    BYTE *data;
    unsigned int i;
    drive_t *drive;
    DWORD num_half_tracks, track_size;

    drive = drive_context[dnr]->drive;
    sprintf(snap_module_name, "GCRIMAGE%i", dnr);

    m = snapshot_module_open(s, snap_module_name,
                             &major_version, &minor_version);
    if (m == NULL) {
        return 0;
    }

    if (major_version != GCRIMAGE_SNAP_MAJOR
        || minor_version != GCRIMAGE_SNAP_MINOR) {
        log_error(drive_snapshot_log,
                  "Snapshot module version (%d.%d) not supported.",
                  major_version, minor_version);
        snapshot_module_close(m);
        return -1;
    }


    if (0
        || SMR_DW(m, &num_half_tracks) < 0
        || num_half_tracks > MAX_GCR_TRACKS) {
        snapshot_module_close(m);
        return -1;
    }

    for (i = 0; i < num_half_tracks; i++) {
        if (SMR_DW(m, &track_size) < 0
            || track_size > NUM_MAX_MEM_BYTES_TRACK) {
            snapshot_module_close(m);
            return -1;
        }

        if (track_size) {
            if (drive->gcr->tracks[i].data == NULL) {
                drive->gcr->tracks[i].data = lib_calloc(1, track_size);
            } else if (drive->gcr->tracks[i].size != (int)track_size) {
                drive->gcr->tracks[i].data = lib_realloc(drive->gcr->tracks[i].data, track_size);
            }
            memset(drive->gcr->tracks[i].data, 0, track_size);
        } else {
            if (drive->gcr->tracks[i].data) {
                lib_free(drive->gcr->tracks[i].data);
                drive->gcr->tracks[i].data = NULL;
            }
        }
        data = drive->gcr->tracks[i].data;
        drive->gcr->tracks[i].size = track_size;

        if (track_size && SMR_BA(m, data, track_size) < 0) {
            snapshot_module_close(m);
            return -1;
        }
    }
    for (; i < MAX_GCR_TRACKS; i++) {
        if (drive->gcr->tracks[i].data) {
            lib_free(drive->gcr->tracks[i].data);
            drive->gcr->tracks[i].data = NULL;
            drive->gcr->tracks[i].size = 0;
        }
    }
    snapshot_module_close(m);

    drive->GCR_image_loaded = 1;
    drive->complicated_image_loaded = 1; /* TODO: verify if it's really like this */
    drive->image = NULL;

    return 0;
}
예제 #10
0
int drive_snapshot_read_module(snapshot_t *s)
{
    BYTE major_version, minor_version;
    int i;
    snapshot_module_t *m;
    char snap_module_name[] = "DRIVE";
    DWORD rotation_table_ptr[DRIVE_NUM];
    CLOCK attach_clk[DRIVE_NUM];
    CLOCK detach_clk[DRIVE_NUM];
    CLOCK attach_detach_clk[DRIVE_NUM];
    int drive_true_emulation;
    int sync_factor;
    drive_t *drive;
    int dummy;
    int half_track[DRIVE_NUM];

    m = snapshot_module_open(s, snap_module_name,
                             &major_version, &minor_version);
    if (m == NULL) {
        /* If this module is not found true emulation is off.  */
        resources_set_int("DriveTrueEmulation", 0);
        return 0;
    }

    drive_gcr_data_writeback_all();

    if (major_version > DRIVE_SNAP_MAJOR || minor_version > DRIVE_SNAP_MINOR) {
        log_error(drive_snapshot_log,
                  "Snapshot module version (%d.%d) newer than %d.%d.",
                  major_version, minor_version,
                  DRIVE_SNAP_MAJOR, DRIVE_SNAP_MINOR);
    }

    /* If this module exists true emulation is enabled.  */
    /* XXX drive_true_emulation = 1 */
    resources_set_int("DriveTrueEmulation", 1);

    if (SMR_DW_INT(m, &sync_factor) < 0) {
        snapshot_module_close(m);
        return -1;
    }

    /* TODO: NUM_DRIVES drives instead of 2 */
    for (i = 0; i < 2; i++) {
        drive = drive_context[i]->drive;

        /* Partially read 1.0 snapshots */
        if (major_version == 1 && minor_version == 0) {
            if (0
                || SMR_DW_UL(m, &(drive->snap_accum)) < 0
                || SMR_DW(m, &(attach_clk[i])) < 0
                || SMR_DW_INT(m, &dummy) < 0
                || SMR_B_INT(m, (int *)&(drive->byte_ready_level)) < 0
                || SMR_B_INT(m, &(drive->clock_frequency)) < 0
                || SMR_W_INT(m, &half_track[i]) < 0
                || SMR_DW(m, &(detach_clk[i])) < 0
                || SMR_B(m, (BYTE *)&dummy) < 0
                || SMR_B(m, (BYTE *)&dummy) < 0
                || SMR_B_INT(m, &(drive->extend_image_policy)) < 0
                || SMR_B_INT(m, &dummy) < 0
                || SMR_DW_UINT(m, &(drive->GCR_head_offset)) < 0
                || SMR_B(m, &(drive->GCR_read)) < 0
                || SMR_B(m, &(drive->GCR_write_value)) < 0
                || SMR_B_INT(m, &(drive->idling_method)) < 0
                || SMR_B_INT(m, &dummy) < 0
                || SMR_B_INT(m, &(drive->parallel_cable)) < 0
                || SMR_B_INT(m, &(drive->read_only)) < 0
                || SMR_DW(m, &(drive->snap_rotation_last_clk)) < 0
                || SMR_DW(m, &rotation_table_ptr[i]) < 0
                || SMR_DW_UINT(m, &(drive->type)) < 0
                ) {
                snapshot_module_close(m);
                return -1;
            }

            /* Partially read 1.1 snapshots */
        } else if (major_version == 1 && minor_version == 1) {
            if (0
                || SMR_DW(m, &(attach_clk[i])) < 0
                || SMR_B_INT(m, (int *)&(drive->byte_ready_level)) < 0
                || SMR_B_INT(m, &(drive->clock_frequency)) < 0
                || SMR_W_INT(m, &half_track[i]) < 0
                || SMR_DW(m, &(detach_clk[i])) < 0
                || SMR_B(m, (BYTE *)&dummy) < 0
                || SMR_B(m, (BYTE *)&dummy) < 0
                || SMR_B_INT(m, &(drive->extend_image_policy)) < 0
                || SMR_DW_UINT(m, &(drive->GCR_head_offset)) < 0
                || SMR_B(m, &(drive->GCR_read)) < 0
                || SMR_B(m, &(drive->GCR_write_value)) < 0
                || SMR_B_INT(m, &(drive->idling_method)) < 0
                || SMR_B_INT(m, &(drive->parallel_cable)) < 0
                || SMR_B_INT(m, &(drive->read_only)) < 0
                || SMR_DW(m, &rotation_table_ptr[i]) < 0
                || SMR_DW_UINT(m, &(drive->type)) < 0

                || SMR_DW_UL(m, &(drive->snap_accum)) < 0
                || SMR_DW(m, &(drive->snap_rotation_last_clk)) < 0
                || SMR_DW_INT(m, &(drive->snap_bit_counter)) < 0
                || SMR_DW_INT(m, &(drive->snap_zero_count)) < 0
                || SMR_W_INT(m, &(drive->snap_last_read_data)) < 0
                || SMR_B(m, &(drive->snap_last_write_data)) < 0
                || SMR_DW_INT(m, &(drive->snap_seed)) < 0
                ) {
                snapshot_module_close(m);
                return -1;
            }

            /* Partially read 1.2 snapshots */
        } else if (major_version == 1 && minor_version == 2) {
            if (0
                || SMR_DW(m, &(attach_clk[i])) < 0
                || SMR_B_INT(m, (int *)&(drive->byte_ready_level)) < 0
                || SMR_B_INT(m, &(drive->clock_frequency)) < 0
                || SMR_W_INT(m, &half_track[i]) < 0
                || SMR_DW(m, &(detach_clk[i])) < 0
                || SMR_B(m, (BYTE *)&dummy) < 0
                || SMR_B(m, (BYTE *)&dummy) < 0
                || SMR_B_INT(m, &(drive->extend_image_policy)) < 0
                || SMR_DW_UINT(m, &(drive->GCR_head_offset)) < 0
                || SMR_B(m, &(drive->GCR_read)) < 0
                || SMR_B(m, &(drive->GCR_write_value)) < 0
                || SMR_B_INT(m, &(drive->idling_method)) < 0
                || SMR_B_INT(m, &(drive->parallel_cable)) < 0
                || SMR_B_INT(m, &(drive->read_only)) < 0
                || SMR_DW(m, &rotation_table_ptr[i]) < 0
                || SMR_DW_UINT(m, &(drive->type)) < 0

                || SMR_DW_UL(m, &(drive->snap_accum)) < 0
                || SMR_DW(m, &(drive->snap_rotation_last_clk)) < 0
                || SMR_DW_INT(m, &(drive->snap_bit_counter)) < 0
                || SMR_DW_INT(m, &(drive->snap_zero_count)) < 0
                || SMR_W_INT(m, &(drive->snap_last_read_data)) < 0
                || SMR_B(m, &(drive->snap_last_write_data)) < 0
                || SMR_DW_INT(m, &(drive->snap_seed)) < 0
                || SMR_DW(m, &(drive->snap_speed_zone)) < 0
                || SMR_DW(m, &(drive->snap_ue7_dcba)) < 0
                || SMR_DW(m, &(drive->snap_ue7_counter)) < 0
                || SMR_DW(m, &(drive->snap_uf4_counter)) < 0
                || SMR_DW(m, &(drive->snap_fr_randcount)) < 0
                || SMR_DW(m, &(drive->snap_filter_counter)) < 0
                || SMR_DW(m, &(drive->snap_filter_state)) < 0
                || SMR_DW(m, &(drive->snap_filter_last_state)) < 0
                || SMR_DW(m, &(drive->snap_write_flux)) < 0
                || SMR_DW(m, &(drive->snap_PulseHeadPosition)) < 0
                || SMR_DW(m, &(drive->snap_xorShift32)) < 0
                ) {
                snapshot_module_close(m);
                return -1;
            }
        } else if (major_version == 1 && minor_version == 3) {
            if (0
                || SMR_DW(m, &(attach_clk[i])) < 0
                || SMR_B_INT(m, (int *)&(drive->byte_ready_level)) < 0
                || SMR_B_INT(m, &(drive->clock_frequency)) < 0
                || SMR_W_INT(m, &half_track[i]) < 0
                || SMR_DW(m, &(detach_clk[i])) < 0
                || SMR_B(m, (BYTE *)&dummy) < 0
                || SMR_B(m, (BYTE *)&dummy) < 0
                || SMR_B_INT(m, &(drive->extend_image_policy)) < 0
                || SMR_DW_UINT(m, &(drive->GCR_head_offset)) < 0
                || SMR_B(m, &(drive->GCR_read)) < 0
                || SMR_B(m, &(drive->GCR_write_value)) < 0
                || SMR_B_INT(m, &(drive->idling_method)) < 0
                || SMR_B_INT(m, &(drive->parallel_cable)) < 0
                || SMR_B_INT(m, &(drive->read_only)) < 0
                || SMR_DW(m, &rotation_table_ptr[i]) < 0
                || SMR_DW_UINT(m, &(drive->type)) < 0

                || SMR_DW_UL(m, &(drive->snap_accum)) < 0
                || SMR_DW(m, &(drive->snap_rotation_last_clk)) < 0
                || SMR_DW_INT(m, &(drive->snap_bit_counter)) < 0
                || SMR_DW_INT(m, &(drive->snap_zero_count)) < 0
                || SMR_W_INT(m, &(drive->snap_last_read_data)) < 0
                || SMR_B(m, &(drive->snap_last_write_data)) < 0
                || SMR_DW_INT(m, &(drive->snap_seed)) < 0
                || SMR_DW(m, &(drive->snap_speed_zone)) < 0
                || SMR_DW(m, &(drive->snap_ue7_dcba)) < 0
                || SMR_DW(m, &(drive->snap_ue7_counter)) < 0
                || SMR_DW(m, &(drive->snap_uf4_counter)) < 0
                || SMR_DW(m, &(drive->snap_fr_randcount)) < 0
                || SMR_DW(m, &(drive->snap_filter_counter)) < 0
                || SMR_DW(m, &(drive->snap_filter_state)) < 0
                || SMR_DW(m, &(drive->snap_filter_last_state)) < 0
                || SMR_DW(m, &(drive->snap_write_flux)) < 0
                || SMR_DW(m, &(drive->snap_PulseHeadPosition)) < 0
                || SMR_DW(m, &(drive->snap_xorShift32)) < 0
                || SMR_DW(m, &(drive->snap_so_delay)) < 0
                ) {
                snapshot_module_close(m);
                return -1;
            }
        } else {
            if (0
                || SMR_DW(m, &(attach_clk[i])) < 0
                || SMR_B_INT(m, (int *)&(drive->byte_ready_level)) < 0
                || SMR_B_INT(m, &(drive->clock_frequency)) < 0
                || SMR_W_INT(m, &half_track[i]) < 0
                || SMR_DW(m, &(detach_clk[i])) < 0
                || SMR_B(m, (BYTE *)&dummy) < 0
                || SMR_B(m, (BYTE *)&dummy) < 0
                || SMR_B_INT(m, &(drive->extend_image_policy)) < 0
                || SMR_DW_UINT(m, &(drive->GCR_head_offset)) < 0
                || SMR_B(m, &(drive->GCR_read)) < 0
                || SMR_B(m, &(drive->GCR_write_value)) < 0
                || SMR_B_INT(m, &(drive->idling_method)) < 0
                || SMR_B_INT(m, &(drive->parallel_cable)) < 0
                || SMR_B_INT(m, &(drive->read_only)) < 0
                || SMR_DW(m, &rotation_table_ptr[i]) < 0
                || SMR_DW_UINT(m, &(drive->type)) < 0

                || SMR_DW_UL(m, &(drive->snap_accum)) < 0
                || SMR_DW(m, &(drive->snap_rotation_last_clk)) < 0
                || SMR_DW_INT(m, &(drive->snap_bit_counter)) < 0
                || SMR_DW_INT(m, &(drive->snap_zero_count)) < 0
                || SMR_W_INT(m, &(drive->snap_last_read_data)) < 0
                || SMR_B(m, &(drive->snap_last_write_data)) < 0
                || SMR_DW_INT(m, &(drive->snap_seed)) < 0
                || SMR_DW(m, &(drive->snap_speed_zone)) < 0
                || SMR_DW(m, &(drive->snap_ue7_dcba)) < 0
                || SMR_DW(m, &(drive->snap_ue7_counter)) < 0
                || SMR_DW(m, &(drive->snap_uf4_counter)) < 0
                || SMR_DW(m, &(drive->snap_fr_randcount)) < 0
                || SMR_DW(m, &(drive->snap_filter_counter)) < 0
                || SMR_DW(m, &(drive->snap_filter_state)) < 0
                || SMR_DW(m, &(drive->snap_filter_last_state)) < 0
                || SMR_DW(m, &(drive->snap_write_flux)) < 0
                || SMR_DW(m, &(drive->snap_PulseHeadPosition)) < 0
                || SMR_DW(m, &(drive->snap_xorShift32)) < 0
                || SMR_DW(m, &(drive->snap_so_delay)) < 0
                || SMR_DW(m, &(drive->snap_cycle_index)) < 0
                || SMR_DW(m, &(drive->snap_ref_advance)) < 0
                || SMR_DW(m, &(drive->snap_req_ref_cycles)) < 0
                ) {
                snapshot_module_close(m);
                return -1;
            }
        }
    }

    /* this one is new, so don't test so stay compatible with old snapshots */
    for (i = 0; i < 2; i++) {
        drive = drive_context[i]->drive;
        SMR_DW(m, &(attach_detach_clk[i]));
    }

    /* these are even newer */
    for (i = 0; i < 2; i++) {
        drive = drive_context[i]->drive;
        SMR_B_INT(m, (int *)&(drive->byte_ready_edge));
        SMR_B_INT(m, (int *)&(drive->byte_ready_active));
    }

    snapshot_module_close(m);
    m = NULL;

    rotation_table_set(rotation_table_ptr);

    drive = drive_context[0]->drive;
    switch (drive->type) {
        case DRIVE_TYPE_1540:
        case DRIVE_TYPE_1541:
        case DRIVE_TYPE_1541II:
        case DRIVE_TYPE_1551:
        case DRIVE_TYPE_1570:
        case DRIVE_TYPE_1571:
        case DRIVE_TYPE_1571CR:
        case DRIVE_TYPE_1581:
        case DRIVE_TYPE_2000:
        case DRIVE_TYPE_4000:
        case DRIVE_TYPE_2031:
        case DRIVE_TYPE_1001:
        case DRIVE_TYPE_2040:
        case DRIVE_TYPE_3040:
        case DRIVE_TYPE_4040:
        case DRIVE_TYPE_8050:
        case DRIVE_TYPE_8250:
            drive->enable = 1;
            machine_drive_rom_setup_image(0);
            drivemem_init(drive_context[0], drive->type);
            resources_set_int("Drive8IdleMethod", drive->idling_method);
            driverom_initialize_traps(drive);
            drive_set_active_led_color(drive->type, 0);
            machine_bus_status_drivetype_set(8, 1);
            break;
        case DRIVE_TYPE_NONE:
            drive_disable(drive_context[0]);
            machine_bus_status_drivetype_set(8, 0);
            break;
        default:
            return -1;
    }

    drive = drive_context[1]->drive;
    switch (drive->type) {
        case DRIVE_TYPE_1540:
        case DRIVE_TYPE_1541:
        case DRIVE_TYPE_1541II:
        case DRIVE_TYPE_1551:
        case DRIVE_TYPE_1570:
        case DRIVE_TYPE_1571:
        case DRIVE_TYPE_1581:
        case DRIVE_TYPE_2000:
        case DRIVE_TYPE_4000:
        case DRIVE_TYPE_2031:
        case DRIVE_TYPE_1001:
            /* drive 1 does not allow dual disk drive */
            drive->enable = 1;
            machine_drive_rom_setup_image(1);
            drivemem_init(drive_context[1], drive->type);
            resources_set_int("Drive9IdleMethod", drive->idling_method);
            driverom_initialize_traps(drive);
            drive_set_active_led_color(drive->type, 1);
            machine_bus_status_drivetype_set(9, 1);
            break;
        case DRIVE_TYPE_NONE:
        case DRIVE_TYPE_8050:
        case DRIVE_TYPE_8250:
            drive_disable(drive_context[1]);
            machine_bus_status_drivetype_set(9, 0);
            break;
        default:
            return -1;
    }

    /* Clear parallel cable before undumping parallel port values.  */
    for (i = 0; i < DRIVE_PC_NUM; i++) {
        parallel_cable_drive_write(i, 0xff, PARALLEL_WRITE, 0);
        parallel_cable_drive_write(i, 0xff, PARALLEL_WRITE, 1);
    }

    for (i = 0; i < 2; i++) {
        drive = drive_context[i]->drive;
        if (drive->enable) {
            if (drive->type == DRIVE_TYPE_2000 || drive->type == DRIVE_TYPE_4000) {
                if (drivecpu65c02_snapshot_read_module(drive_context[i], s) < 0) {
                    return -1;
                }
            } else {
                if (drivecpu_snapshot_read_module(drive_context[i], s) < 0) {
                    return -1;
                }
            }
            if (machine_drive_snapshot_read(drive_context[i], s) < 0) {
                return -1;
            }
        }
    }

    if (drive_snapshot_read_image_module(s, 0) < 0
        || drive_snapshot_read_gcrimage_module(s, 0) < 0
        || drive_snapshot_read_p64image_module(s, 0) < 0) {
        return -1;
    }
    if (drive_snapshot_read_image_module(s, 1) < 0
        || drive_snapshot_read_gcrimage_module(s, 1) < 0
        || drive_snapshot_read_p64image_module(s, 1) < 0) {
        return -1;
    }
    if (driverom_snapshot_read(s, drive_context[0]->drive) < 0) {
        return -1;
    }
    if (driverom_snapshot_read(s, drive_context[1]->drive) < 0) {
        return -1;
    }

    for (i = 0; i < 2; i++) {
        drive = drive_context[i]->drive;
        if (drive->type != DRIVE_TYPE_NONE) {
            drive_enable(drive_context[i]);
            drive->attach_clk = attach_clk[i];
            drive->detach_clk = detach_clk[i];
            drive->attach_detach_clk = attach_detach_clk[i];
        }
    }

    for (i = 0; i < 2; i++) {
        int side = 0;
        drive = drive_context[i]->drive;
        if (drive->type == DRIVE_TYPE_1570
            || drive->type == DRIVE_TYPE_1571
            || drive->type == DRIVE_TYPE_1571CR) {
            if (half_track[i] > (DRIVE_HALFTRACKS_1571 + 1)) {
                side = 1;
                half_track[i] -= DRIVE_HALFTRACKS_1571;
            }
        }
        drive_set_half_track(half_track[i], side, drive);
        resources_set_int("MachineVideoStandard", sync_factor);
    }

    /* stop currently active drive sounds (bug #3539422)
     * FIXME: when the drive sound emulation becomes more precise, we might
     *        want/need to save a snapshot of its current state too
     */
    drive_sound_stop();

    iec_update_ports_embedded();
    drive_update_ui_status();

    resources_get_int("DriveTrueEmulation", &drive_true_emulation);

    if (vdrive_snapshot_module_read(s, drive_true_emulation ? 10 : 8) < 0) {
        return -1;
    }

    return 0;
}
예제 #11
0
static int drive_snapshot_read_p64image_module(snapshot_t *s, unsigned int dnr)
{
    BYTE major_version, minor_version;
    snapshot_module_t *m;
    char snap_module_name[10];
    BYTE *tmpbuf;
    drive_t *drive;
    TP64MemoryStream P64MemoryStreamInstance;
    PP64Image P64Image;
    DWORD size;

    drive = drive_context[dnr]->drive;
    sprintf(snap_module_name, "P64IMAGE%i", dnr);

    m = snapshot_module_open(s, snap_module_name,
                             &major_version, &minor_version);
    if (m == NULL) {
        return 0;
    }

    P64Image = (void*)drive->p64;

    if (P64Image == NULL) {
        if (m != NULL) {
            snapshot_module_close(m);
        }
        return -1;
    }

    if (major_version > P64IMAGE_SNAP_MAJOR
        || minor_version > P64IMAGE_SNAP_MINOR) {
        log_error(drive_snapshot_log,
                  "Snapshot module version (%d.%d) newer than %d.%d.",
                  major_version, minor_version,
                  P64IMAGE_SNAP_MAJOR, P64IMAGE_SNAP_MINOR);
    }

    if (SMR_DW(m, &size) < 0) {
        if (m != NULL) {
            snapshot_module_close(m);
        }
        return -1;
    }

    tmpbuf = lib_malloc(size);

    if (SMR_BA(m, tmpbuf, size) < 0) {
        if (m != NULL) {
            snapshot_module_close(m);
        }
        lib_free(tmpbuf);
        return -1;
    }

    P64MemoryStreamCreate(&P64MemoryStreamInstance);
    P64MemoryStreamClear(&P64MemoryStreamInstance);
    P64MemoryStreamWrite(&P64MemoryStreamInstance, tmpbuf, size);
    P64MemoryStreamSeek(&P64MemoryStreamInstance, 0);
    if (!P64ImageReadFromStream(P64Image, &P64MemoryStreamInstance)) {
        if (m != NULL) {
            snapshot_module_close(m);
        }
        lib_free(tmpbuf);
        P64MemoryStreamDestroy(&P64MemoryStreamInstance);
        return -1;
    }

    P64MemoryStreamDestroy(&P64MemoryStreamInstance);

    snapshot_module_close(m);
    m = NULL;

    lib_free(tmpbuf);

    drive->P64_image_loaded = 1;
    drive->complicated_image_loaded = 1;
    drive->image = NULL;

    return 0;
}
예제 #12
0
int ds1216e_read_snapshot(rtc_ds1216e_t *context, snapshot_t *s)
{
    DWORD latch_lo = 0;
    DWORD latch_hi = 0;
    DWORD offset_lo = 0;
    DWORD offset_hi = 0;
    DWORD old_offset_lo = 0;
    DWORD old_offset_hi = 0;
    BYTE vmajor, vminor;
    snapshot_module_t *m;

    m = snapshot_module_open(s, snap_module_name, &vmajor, &vminor);

    if (m == NULL) {
        return -1;
    }

    /* Do not accept versions higher than current */
    if (vmajor > SNAP_MAJOR || vminor > SNAP_MINOR) {
        snapshot_set_error(SNAPSHOT_MODULE_HIGHER_VERSION);
        goto fail;
    }

    if (0
        || SMR_B_INT(m, &context->reset) < 0
        || SMR_B_INT(m, &context->inactive) < 0
        || SMR_B_INT(m, &context->hours12) < 0
        || SMR_B_INT(m, &context->pattern_pos) < 0
        || SMR_B_INT(m, &context->pattern_ignore) < 0
        || SMR_B_INT(m, &context->output) < 0
        || SMR_B_INT(m, &context->output_pos) < 0
        || SMR_DW(m, &latch_hi) < 0
        || SMR_DW(m, &latch_lo) < 0
        || SMR_DW(m, &offset_hi) < 0
        || SMR_DW(m, &offset_lo) < 0
        || SMR_DW(m, &old_offset_hi) < 0
        || SMR_DW(m, &old_offset_lo) < 0
        || SMR_BA(m, context->clock_regs, DS1216E_REG_SIZE) < 0
        || SMR_BA(m, context->old_clock_regs, DS1216E_REG_SIZE) < 0
        || SMR_BA(m, context->clock_regs_changed, DS1216E_REG_SIZE) < 0
        || SMR_STR(m, &context->device) < 0) {
        goto fail;
    }

#if (SIZE_OF_TIME_T == 8)
    context->latch = (time_t)(latch_hi) << 32;
    context->latch |= latch_lo;
    context->offset = (time_t)(offset_hi) << 32;
    context->offset |= offset_lo;
    context->old_offset = (time_t)(old_offset_hi) << 32;
    context->old_offset |= old_offset_lo;
#else
    context->latch = latch_lo;
    context->offset = offset_lo;
    context->old_offset = old_offset_lo;
#endif

    return snapshot_module_close(m);

fail:
    snapshot_module_close(m);
    return -1;
}
예제 #13
0
int tape_snapshot_read_module(snapshot_t *s)
{
    BYTE major_version, minor_version;
    snapshot_module_t *m;
    unsigned int snap_type;
    char snap_module_name[] = "TAPE";
    tap_t *tap;
    t64_t *t64;


    if (tape_snapshot_read_tapimage_module(s) < 0
        || tape_snapshot_read_t64image_module(s) < 0)
        return -1;


    m = snapshot_module_open(s, snap_module_name,
                             &major_version, &minor_version);

    if (m == NULL) {
        /* no tape attached */
        tape_image_detach_internal(1);
        return 0;
    }

    if (0
        || SMR_B_INT(m, (int *)&tape_image_dev1->read_only) < 0 
        || SMR_B_INT(m, (int *)&snap_type) < 0) 
    {
        snapshot_module_close(m);
        return -1;
    }

    if (snap_type != tape_image_dev1->type) {
        /* attached image type is not correct */
        log_error(tape_snapshot_log,
            "No tape image attached or type not correct.");
        snapshot_module_close(m);
        return -1;
    }

    switch (tape_image_dev1->type) {
        case TAPE_TYPE_T64:
            t64 = (t64_t*)tape_image_dev1->data;
            break;
        case TAPE_TYPE_TAP:
            tap = (tap_t*)tape_image_dev1->data;
            if (tap == NULL
                || SMR_DW(m, (DWORD*)&tap->size) < 0
                || SMR_B(m, &tap->version) < 0
                || SMR_B(m, &tap->system) < 0
                || SMR_DW(m, (DWORD*)&tap->current_file_seek_position) < 0
                || SMR_DW(m, (DWORD*)&tap->offset) < 0
                || SMR_DW(m, (DWORD*)&tap->cycle_counter) < 0
                || SMR_DW(m, (DWORD*)&tap->cycle_counter_total) < 0
                || SMR_DW(m, (DWORD*)&tap->counter) < 0
                || SMR_DW(m, (DWORD*)&tap->mode) < 0
                || SMR_DW(m, (DWORD*)&tap->read_only) < 0
                || SMR_DW(m, (DWORD*)&tap->has_changed) < 0)
            {
                snapshot_module_close(m);
                return -1;
            }

            break;
        default:
            break;
    }

    snapshot_module_close(m);

    if (datasette_read_snapshot(s) < 0)
        return -1;

    return 0;
}
예제 #14
0
/*! \brief Read the snapshot module for the ACIA

 \param p
   Pointer to the snapshot data

 \return
   0 on success, -1 on error

 \remark
   The format has been extended in VICE 2.0.9.
   However, the version number remained the same.
   This function tries to read the new values.
   If they are not available, it mimics the old
   behaviour and reports success, anyway.

 \remark
   It is unclear if it is sensible to mimic the
   old behaviour, as the old implementation was
   severely broken.
*/
int myacia_snapshot_read_module(snapshot_t *p)
{
    BYTE vmajor, vminor;
    BYTE byte;
    DWORD dword;
    snapshot_module_t *m;

    alarm_unset(acia.alarm_tx);   /* just in case we don't find module */
    alarm_unset(acia.alarm_rx);   /* just in case we don't find module */
    acia.alarm_active_tx = 0;
    acia.alarm_active_rx = 0;

    mycpu_set_int_noclk(acia.int_num, 0);

    m = snapshot_module_open(p, module_name, &vmajor, &vminor);
    if (m == NULL) {
        return -1;
    }

    if (vmajor != ACIA_DUMP_VER_MAJOR) {
        snapshot_module_close(m);
        return -1;
    }

    SMR_B(m, &acia.txdata);
    SMR_B(m, &acia.rxdata);

    acia.irq = 0;
    SMR_B(m, &acia.status);
    if (acia.status & ACIA_SR_BITS_IRQ) {
        acia.status &= ~ACIA_SR_BITS_IRQ;
        acia.irq = 1;
        mycpu_set_int_noclk(acia.int_num, acia.irq_type);
    } else {
        mycpu_set_int_noclk(acia.int_num, 0);
    }

    SMR_B(m, &acia.cmd);
    if ((acia.cmd & ACIA_CMD_BITS_DTR_ENABLE_RECV_AND_IRQ) && (acia.fd < 0)) {
        acia.fd = rs232drv_open(acia.device);
        acia_set_handshake_lines();
    } else {
        if ((acia.fd >= 0) && !(acia.cmd & ACIA_CMD_BITS_DTR_ENABLE_RECV_AND_IRQ)) {
            rs232drv_close(acia.fd);
            acia.fd = -1;
        }
    }

    SMR_B(m, &acia.ctrl);
    set_acia_ticks();

    SMR_B(m, &byte);
    acia.in_tx = byte;

    SMR_DW(m, &dword);
    if (dword) {
        acia.alarm_clk_tx = myclk + dword;
        alarm_set(acia.alarm_tx, acia.alarm_clk_tx);
        acia.alarm_active_tx = 1;

        /*
         * for compatibility reasons of old snapshots with new ones,
         * set the RX alarm to the same value.
         * if we have a new snapshot (2.0.9 and up), this will be
         * overwritten directly afterwards.
         */
        acia.alarm_clk_rx = myclk + dword;
        alarm_set(acia.alarm_rx, acia.alarm_clk_rx);
        acia.alarm_active_rx = 1;
    }

    /*
     * this is new with VICE 2.0.9; thus, only use the settings
     * if it does exist.
     */
    if (SMR_DW(m, &dword) >= 0) {
        if (dword) {
            acia.alarm_clk_rx = myclk + dword;
            alarm_set(acia.alarm_rx, acia.alarm_clk_rx);
            acia.alarm_active_rx = 1;
        } else {
            alarm_unset(acia.alarm_rx);
            acia.alarm_active_rx = 0;
        }
    }

    if (snapshot_module_close(m) < 0) {
        return -1;
    }

    return 0;
}
예제 #15
0
int drivecpu_snapshot_read_module(drive_context_t *drv, snapshot_t *s)
{
    BYTE major, minor;
    snapshot_module_t *m;
    BYTE a, x, y, sp, status;
    WORD pc;
    drivecpu_context_t *cpu;

    cpu = drv->cpu;

    m = snapshot_module_open(s, drv->cpu->snap_module_name, &major, &minor);
    if (m == NULL) {
        return -1;
    }

    /* Before we start make sure all devices are reset.  */
    drivecpu_reset(drv);

    /* XXX: Assumes `CLOCK' is the same size as a `DWORD'.  */
    if (0
        || SMR_DW(m, drv->clk_ptr) < 0
        || SMR_B(m, &a) < 0
        || SMR_B(m, &x) < 0
        || SMR_B(m, &y) < 0
        || SMR_B(m, &sp) < 0
        || SMR_W(m, &pc) < 0
        || SMR_B(m, &status) < 0
        || SMR_DW_UINT(m, &(cpu->last_opcode_info)) < 0
        || SMR_DW(m, &(cpu->last_clk)) < 0
        || SMR_DW(m, &(cpu->cycle_accum)) < 0
        || SMR_DW(m, &(cpu->last_exc_cycles)) < 0
        || SMR_DW(m, &(cpu->stop_clk)) < 0
        ) {
        goto fail;
    }

    MOS6510_REGS_SET_A(&(cpu->cpu_regs), a);
    MOS6510_REGS_SET_X(&(cpu->cpu_regs), x);
    MOS6510_REGS_SET_Y(&(cpu->cpu_regs), y);
    MOS6510_REGS_SET_SP(&(cpu->cpu_regs), sp);
    MOS6510_REGS_SET_PC(&(cpu->cpu_regs), pc);
    MOS6510_REGS_SET_STATUS(&(cpu->cpu_regs), status);

    log_message(drv->drive->log, "RESET (For undump).");

    interrupt_cpu_status_reset(cpu->int_status);

    machine_drive_reset(drv);

    if (interrupt_read_snapshot(cpu->int_status, m) < 0) {
        goto fail;
    }

    if (drv->drive->type == DRIVE_TYPE_1540
        || drv->drive->type == DRIVE_TYPE_1541
        || drv->drive->type == DRIVE_TYPE_1541II
        || drv->drive->type == DRIVE_TYPE_1551
        || drv->drive->type == DRIVE_TYPE_1570
        || drv->drive->type == DRIVE_TYPE_1571
        || drv->drive->type == DRIVE_TYPE_1571CR
        || drv->drive->type == DRIVE_TYPE_2031) {
        if (SMR_BA(m, drv->drive->drive_ram, 0x800) < 0) {
            goto fail;
        }
    }

    if (drv->drive->type == DRIVE_TYPE_1581
        || drv->drive->type == DRIVE_TYPE_2000
        || drv->drive->type == DRIVE_TYPE_4000) {
        if (SMR_BA(m, drv->drive->drive_ram, 0x2000) < 0) {
            goto fail;
        }
    }

    if (drive_check_old(drv->drive->type)) {
        if (SMR_BA(m, drv->drive->drive_ram, 0x1100) < 0) {
            goto fail;
        }
    }

    /* Update `*bank_base'.  */
    JUMP(reg_pc);

    if (interrupt_read_new_snapshot(drv->cpu->int_status, m) < 0) {
        goto fail;
    }

    return snapshot_module_close(m);

fail:
    if (m != NULL) {
        snapshot_module_close(m);
    }
    return -1;
}
int vicii_snapshot_read_module(snapshot_t *s)
{
    BYTE major_version, minor_version;
    int i;
    snapshot_module_t *m;
    BYTE color_ram[0x400];

    m = snapshot_module_open(s, snap_module_name,
                             &major_version, &minor_version);
    if (m == NULL) {
        return -1;
    }

    if (major_version > SNAP_MAJOR || minor_version > SNAP_MINOR) {
        log_error(vicii.log,
                  "Snapshot module version (%d.%d) newer than %d.%d.",
                  major_version, minor_version,
                  SNAP_MAJOR, SNAP_MINOR);
        goto fail;
    }

    /* FIXME: initialize changes?  */

    if (0
        /* AllowBadLines */
        || SMR_B_INT(m, &vicii.allow_bad_lines) < 0
        /* BadLine */
        || SMR_B_INT(m, &vicii.bad_line) < 0
        /* Blank */
        || SMR_B_INT(m, &vicii.raster.blank_enabled) < 0
        /* ColorBuf */
        || SMR_BA(m, vicii.cbuf, 40) < 0
        /* ColorRam */
        || SMR_BA(m, color_ram, 1024) < 0
        /* IdleState */
        || SMR_B_INT(m, &vicii.idle_state) < 0
        /* LPTrigger */
        || SMR_B_INT(m, &vicii.light_pen.triggered) < 0
        /* LPX */
        || SMR_B_INT(m, &vicii.light_pen.x) < 0
        /* LPY */
        || SMR_B_INT(m, &vicii.light_pen.y) < 0
        /* MatrixBuf */
        || SMR_BA(m, vicii.vbuf, 40) < 0
        /* NewSpriteDmaMask */
        || SMR_B(m, &vicii.raster.sprite_status->new_dma_msk) < 0) {
        goto fail;
    }

    mem_color_ram_from_snapshot(color_ram);

    {
        DWORD RamBase;

        if (SMR_DW(m, &RamBase) < 0) {
            goto fail;
        }
        vicii.ram_base_phi1 = mem_ram + RamBase;
    }

    /* Read the current raster line and the current raster cycle.  As they
       are a function of `clk', this is just a sanity check.  */
    {
        WORD RasterLine;
        BYTE RasterCycle;

        if (SMR_B(m, &RasterCycle) < 0
            || SMR_W(m, &RasterLine) < 0) {
            goto fail;
        }

        if (RasterCycle != (BYTE)VICII_RASTER_CYCLE(maincpu_clk)) {
            log_error(vicii.log,
                      "Not matching raster cycle (%d) in snapshot; should be %d.",
                      RasterCycle, VICII_RASTER_CYCLE(maincpu_clk));
            goto fail;
        }

        if (RasterLine != (WORD)VICII_RASTER_Y(maincpu_clk)) {
            log_error(vicii.log,
                      "VIC-II: Not matching raster line (%d) in snapshot; should be %d.",
                      RasterLine, VICII_RASTER_Y(maincpu_clk));
            goto fail;
        }
    }

    for (i = 0; i < 0x40; i++) {
        if (SMR_B(m, &vicii.regs[i]) < 0 /* Registers */) {
            goto fail;
        }
    }

    if (0
        /* SbCollMask */
        || SMR_B(m, &vicii.sprite_background_collisions) < 0
        /* SpriteDmaMask */
        || SMR_B(m, &vicii.raster.sprite_status->dma_msk) < 0
        /* SsCollMask */
        || SMR_B(m, &vicii.sprite_sprite_collisions) < 0
        /* VBank */
        || SMR_W_INT(m, &vicii.vbank_phi1) < 0
        /* Vc */
        || SMR_W_INT(m, &vicii.mem_counter) < 0
        /* VcInc */
        || SMR_B_INT(m, &vicii.mem_counter_inc) < 0
        /* VcBase */
        || SMR_W_INT(m, &vicii.memptr) < 0
        /* VideoInt */
        || SMR_B_INT(m, &vicii.irq_status) < 0) {
        goto fail;
    }

    for (i = 0; i < 8; i++) {
        if (0
            /* SpriteXMemPtr */
            || SMR_B_INT(m, &vicii.raster.sprite_status->sprites[i].memptr) < 0
            /* SpriteXMemPtrInc */
            || SMR_B_INT(m, &vicii.raster.sprite_status->sprites[i].memptr_inc) < 0
            /* SpriteXExpFlipFlop */
            || SMR_B_INT(m, &vicii.raster.sprite_status->sprites[i].exp_flag) < 0
            ) {
            goto fail;
        }
    }

    /* FIXME: Recalculate alarms and derived values.  */
#if 1
    {
        /*
            We cannot use vicii_irq_set_raster_line as this would delay
            an alarm on line 0 for one frame
        */
        unsigned int line = vicii.regs[0x12] | ((vicii.regs[0x11] & 0x80) << 1);

        if (line < (unsigned int)vicii.screen_height) {
            vicii.raster_irq_clk = (VICII_LINE_START_CLK(maincpu_clk)
                                    + VICII_RASTER_IRQ_DELAY - INTERRUPT_DELAY
                                    + (vicii.cycles_per_line * line));

            /* Raster interrupts on line 0 are delayed by 1 cycle.  */
            if (line == 0) {
                vicii.raster_irq_clk++;
            }

            alarm_set(vicii.raster_irq_alarm, vicii.raster_irq_clk);
        } else {
            vicii.raster_irq_clk = CLOCK_MAX;
            alarm_unset(vicii.raster_irq_alarm);
        }
        vicii.raster_irq_line = line;
    }

#else
    vicii_irq_set_raster_line(vicii.regs[0x12]
                              | ((vicii.regs[0x11] & 0x80) << 1));
#endif

    /* compatibility with older versions */
    vicii.ram_base_phi2 = vicii.ram_base_phi1;
    vicii.vbank_phi2 = vicii.vbank_phi1;

    vicii_update_memory_ptrs(VICII_RASTER_CYCLE(maincpu_clk));

    /* Update sprite parameters.  We had better do this manually, or the
       VIC-II emulation could be quite upset.  */
    {
        BYTE msk;

        for (i = 0, msk = 0x1; i < 8; i++, msk <<= 1) {
            raster_sprite_t *sprite;
            int tmp;

            sprite = vicii.raster.sprite_status->sprites + i;

            /* X/Y coordinates.  */
            tmp = vicii.regs[i * 2] + ((vicii.regs[0x10] & msk) ? 0x100 : 0);

            /* (-0xffff makes sure it's updated NOW.) */
            vicii_sprites_set_x_position(i, tmp, -0xffff);

            sprite->y = (int)vicii.regs[i * 2 + 1];
            sprite->x_expanded = (int)(vicii.regs[0x1d] & msk);
            sprite->y_expanded = (int)(vicii.regs[0x17] & msk);
            sprite->multicolor = (int)(vicii.regs[0x1c] & msk);
            sprite->in_background = (int)(vicii.regs[0x1b] & msk);
            sprite->color = (int) vicii.regs[0x27 + i] & 0xf;
            sprite->dma_flag = (int)(vicii.raster.sprite_status->new_dma_msk & msk);
        }
    }

    vicii.sprite_fetch_msk = vicii.raster.sprite_status->new_dma_msk;
    vicii.sprite_fetch_clk = VICII_LINE_START_CLK(maincpu_clk)
                             + vicii.sprite_fetch_cycle
                             - vicii.cycles_per_line;

    /* calculate the sprite_fetch_idx */
    {
        const vicii_sprites_fetch_t *sf;

        sf = vicii_sprites_fetch_table[vicii.sprite_fetch_msk];
        i = 0;
        while (sf[i].cycle >= 0 && sf[i].cycle + vicii.sprite_fetch_cycle <= vicii.cycles_per_line) {
            i++;
        }
        vicii.sprite_fetch_idx = i;
    }

    vicii.raster.xsmooth = vicii.regs[0x16] & 0x7;
    vicii.raster.sprite_xsmooth = vicii.regs[0x16] & 0x7;
    vicii.raster.ysmooth = vicii.regs[0x11] & 0x7;
    vicii.raster.current_line = VICII_RASTER_Y(maincpu_clk); /* FIXME? */

    vicii.raster.sprite_status->visible_msk = vicii.regs[0x15];

    /* Update colors.  */
    vicii.raster.border_color = vicii.regs[0x20] & 0xf;
    vicii.raster.background_color = vicii.regs[0x21] & 0xf;
    vicii.ext_background_color[0] = vicii.regs[0x22] & 0xf;
    vicii.ext_background_color[1] = vicii.regs[0x23] & 0xf;
    vicii.ext_background_color[2] = vicii.regs[0x24] & 0xf;
    vicii.raster.sprite_status->mc_sprite_color_1 = vicii.regs[0x25] & 0xf;
    vicii.raster.sprite_status->mc_sprite_color_2 = vicii.regs[0x26] & 0xf;

    vicii.raster.blank = !(vicii.regs[0x11] & 0x10);

    if (VICII_IS_ILLEGAL_MODE(vicii.raster.video_mode)) {
        vicii.raster.idle_background_color = 0;
        vicii.force_black_overscan_background_color = 1;
    } else {
        vicii.raster.idle_background_color
            = vicii.raster.background_color;
        vicii.force_black_overscan_background_color = 0;
    }

    if (vicii.regs[0x11] & 0x8) {
        vicii.raster.display_ystart = vicii.row_25_start_line;
        vicii.raster.display_ystop = vicii.row_25_stop_line;
    } else {
        vicii.raster.display_ystart = vicii.row_24_start_line;
        vicii.raster.display_ystop = vicii.row_24_stop_line;
    }

    if (vicii.regs[0x16] & 0x8) {
        vicii.raster.display_xstart = VICII_40COL_START_PIXEL;
        vicii.raster.display_xstop = VICII_40COL_STOP_PIXEL;
    } else {
        vicii.raster.display_xstart = VICII_38COL_START_PIXEL;
        vicii.raster.display_xstop = VICII_38COL_STOP_PIXEL;
    }

    /* `vicii.raster.draw_idle_state', `vicii.raster.open_right_border' and
       `vicii.raster.open_left_border' should be needed, but they would only
       affect the current vicii.raster line, and would not cause any
       difference in timing.  So who cares.  */

    /* FIXME: `vicii.ycounter_reset_checked'?  */
    /* FIXME: `vicii.force_display_state'?  */

    vicii.memory_fetch_done = 0; /* FIXME? */

    vicii_update_video_mode(VICII_RASTER_CYCLE(maincpu_clk));

    vicii.draw_clk = maincpu_clk + (vicii.draw_cycle - VICII_RASTER_CYCLE(maincpu_clk));
    vicii.last_emulate_line_clk = vicii.draw_clk - vicii.cycles_per_line;
    alarm_set(vicii.raster_draw_alarm, vicii.draw_clk);

    {
        DWORD dw;
        BYTE b;

        if (0
            || SMR_DW(m, &dw) < 0  /* FetchEventTick */
            || SMR_B(m, &b) < 0    /* FetchEventType */
            ) {
            goto fail;
        }

        vicii.fetch_clk = maincpu_clk + dw;
        vicii.fetch_idx = b;

        alarm_set(vicii.raster_fetch_alarm, vicii.fetch_clk);
    }

    if (vicii.irq_status & 0x80) {
        interrupt_restore_irq(maincpu_int_status, vicii.int_num, 1);
    }

    /* added in version 1.1 of snapshot format */
    if (minor_version > 0) {
        DWORD RamBase;

        if (0
            || SMR_DW(m, &RamBase) < 0
            || SMR_W_INT(m, &vicii.vbank_phi2) < 0 /* VBank */
            ) {
            goto fail;
        }
        vicii.ram_base_phi2 = mem_ram + RamBase;

        vicii_update_memory_ptrs(VICII_RASTER_CYCLE(maincpu_clk));
    }

    raster_force_repaint(&vicii.raster);
    snapshot_module_close(m);
    return 0;

fail:
    if (m != NULL) {
        snapshot_module_close(m);
    }
    return -1;
}
예제 #17
0
int ted_snapshot_read_module(snapshot_t *s)
{
    BYTE major_version, minor_version;
    int i;
    snapshot_module_t *m;

    m = snapshot_module_open(s, snap_module_name,
                             &major_version, &minor_version);
    if (m == NULL) {
        return -1;
    }

    if (major_version > SNAP_MAJOR || minor_version > SNAP_MINOR) {
        log_error(ted.log,
                  "Snapshot module version (%d.%d) newer than %d.%d.",
                  major_version, minor_version,
                  SNAP_MAJOR, SNAP_MINOR);
        goto fail;
    }

    /* FIXME: initialize changes?  */

    if (0
        || SMR_DW(m, &ted.last_emulate_line_clk) < 0
        /* AllowBadLines */
        || SMR_B_INT(m, &ted.allow_bad_lines) < 0
        /* BadLine */
        || SMR_B_INT(m, &ted.bad_line) < 0
        /* Blank */
        || SMR_B_INT(m, &ted.raster.blank_enabled) < 0
        /* ColorBuf */
        || SMR_BA(m, ted.cbuf, 40) < 0
        /* IdleState */
        || SMR_B_INT(m, &ted.idle_state) < 0
        /* MatrixBuf */
        || SMR_BA(m, ted.vbuf, 40) < 0
        ) {
        goto fail;
    }

    /* Read the current raster line and the current raster cycle.  As they
       are a function of `clk', this is just a sanity check.  */
    {
        WORD RasterLine;
        BYTE RasterCycle;

        if (SMR_B(m, &RasterCycle) < 0 || SMR_W(m, &RasterLine) < 0) {
            goto fail;
        }

        DBG(("TED read snapshot at clock: %d cycle: %d (%d) tedline: %d (%d) rasterline: %d\n",
             maincpu_clk, TED_RASTER_CYCLE(maincpu_clk), RasterCycle, TED_RASTER_Y(maincpu_clk),
             RasterLine, ted.raster.current_line));

        if (RasterCycle != (BYTE)TED_RASTER_CYCLE(maincpu_clk)) {
            log_error(ted.log,
                      "Not matching raster cycle (%d) in snapshot; should be %d.",
                      RasterCycle, TED_RASTER_CYCLE(maincpu_clk));
            goto fail;
        }

        if (RasterLine != (WORD)TED_RASTER_Y(maincpu_clk)) {
            log_error(ted.log,
                      "Not matching raster line (%d) in snapshot; should be %d.",
                      RasterLine, TED_RASTER_Y(maincpu_clk));
            goto fail;
        }
    }

    for (i = 0; i < 0x40; i++) {
        if (SMR_B(m, &ted.regs[i]) < 0 /* Registers */) {
            goto fail;
        }
    }

    if (0
        || SMR_DW_INT(m, (int*)&ted.ted_raster_counter) < 0
        /* Vc */
        || SMR_W_INT(m, &ted.mem_counter) < 0
        /* VcInc */
        || SMR_B_INT(m, &ted.mem_counter_inc) < 0
        /* VcBase */
        || SMR_W_INT(m, &ted.memptr) < 0
        /* VideoInt */
        || SMR_B_INT(m, &ted.irq_status) < 0) {
        goto fail;
    }

    /* FIXME: Recalculate alarms and derived values.  */

    ted_irq_set_raster_line(ted.regs[0x0b] | ((ted.regs[0x0a] & 1) << 8));

    ted_update_memory_ptrs(TED_RASTER_CYCLE(maincpu_clk));

    ted.raster.xsmooth = ted.regs[0x07] & 0x7;
    ted.raster.ysmooth = ted.regs[0x06] & 0x7;
    ted.raster.current_line = TED_RASTER_Y(maincpu_clk); /* FIXME? */

    /* Update colors.  */
    ted.raster.border_color = ted.regs[0x19];
    ted.raster.background_color = ted.regs[0x15];
    ted.ext_background_color[0] = ted.regs[0x16];
    ted.ext_background_color[1] = ted.regs[0x17];
    ted.ext_background_color[2] = ted.regs[0x18];

    ted.raster.blank = !(ted.regs[0x06] & 0x10);

    if (TED_IS_ILLEGAL_MODE (ted.raster.video_mode)) {
        ted.raster.idle_background_color = 0;
        ted.force_black_overscan_background_color = 1;
    } else {
        ted.raster.idle_background_color = ted.raster.background_color;
        ted.force_black_overscan_background_color = 0;
    }

    if (ted.regs[0x06] & 0x8) {
        ted.raster.display_ystart = ted.row_25_start_line;
        ted.raster.display_ystop = ted.row_25_stop_line;
    } else {
        ted.raster.display_ystart = ted.row_24_start_line;
        ted.raster.display_ystop = ted.row_24_stop_line;
    }

    if (ted.regs[0x07] & 0x8) {
        ted.raster.display_xstart = TED_40COL_START_PIXEL;
        ted.raster.display_xstop = TED_40COL_STOP_PIXEL;
    } else {
        ted.raster.display_xstart = TED_38COL_START_PIXEL;
        ted.raster.display_xstop = TED_38COL_STOP_PIXEL;
    }

    /* `ted.raster.draw_idle_state', `ted.raster.open_right_border' and
       `ted.raster.open_left_border' should be needed, but they would only
       affect the current ted.raster line, and would not cause any
       difference in timing.  So who cares.  */

    /* FIXME: `ted.ycounter_reset_checked'?  */
    /* FIXME: `ted.force_display_state'?  */

    ted.memory_fetch_done = 0; /* FIXME? */

    ted_update_video_mode(TED_RASTER_CYCLE(maincpu_clk));

    ted.draw_clk = maincpu_clk + (ted.draw_cycle - TED_RASTER_CYCLE(maincpu_clk));
    ted.last_emulate_line_clk = ted.draw_clk - ted.cycles_per_line;
    alarm_set(ted.raster_draw_alarm, ted.draw_clk);

    {
        DWORD dw;

        if (SMR_DW(m, &dw) < 0) {  /* FetchEventTick */
            goto fail;
        }

        ted.fetch_clk = maincpu_clk + dw;

        alarm_set(ted.raster_fetch_alarm, ted.fetch_clk);
    }

    if (ted.irq_status & 0x80) {
        interrupt_restore_irq(maincpu_int_status, ted.int_num, 1);
    }

    raster_force_repaint(&ted.raster);
    DBG(("TED: snapshot loaded.\n"));
    return 0;

fail:
    if (m != NULL) {
        snapshot_module_close(m);
    }
    log_error(ted.log, "could not load TED snapshot.");
    return -1;
}
예제 #18
0
int vic_snapshot_read_module(snapshot_t *s)
{
    WORD i;
    snapshot_module_t *m;
    BYTE major_version, minor_version;
    WORD w;
    BYTE b;

    sound_close();

    m = snapshot_module_open(s, snap_module_name,
                             &major_version, &minor_version);
    if (m == NULL) {
        return -1;
    }

    if (major_version > SNAP_MAJOR || minor_version > SNAP_MINOR) {
        log_error(vic.log, "Snapshot module version (%d.%d) newer than %d.%d.",
                  major_version, minor_version,
                  SNAP_MAJOR, SNAP_MINOR);
        goto fail;
    }

    if (SMR_B(m, &b) < 0) {
        goto fail;
    }
    if (b != VIC_RASTER_CYCLE(maincpu_clk)) {
        log_error(vic.log, "Cycle value (%d) incorrect; should be %d.",
                  (int)b, VIC_RASTER_CYCLE(maincpu_clk));
        goto fail;
    }
    vic.raster_cycle = (unsigned int)b;

    if (SMR_W(m, &w) < 0) {
        goto fail;
    }
    if (w != VIC_RASTER_Y(maincpu_clk)) {
          log_error(vic.log, "Raster line value (%d) incorrect; should be %d.",
                    (int)w, VIC_RASTER_Y(maincpu_clk));
        goto fail;
    }

    if (SMR_W(m, &w) < 0) {
        goto fail;
    }
    vic.area = (vic_area_state_t)w;

    if (SMR_W(m, &w) < 0) {
        goto fail;
    }
    vic.fetch_state = (vic_fetch_state_t)w;

    if (0
        || (SMR_DW_UINT(m, &vic.raster_line) < 0)
        || (SMR_DW_UINT(m, &vic.text_cols) < 0)
        || (SMR_DW_UINT(m, &vic.text_lines) < 0)
        || (SMR_DW_UINT(m, &vic.pending_text_cols) < 0)
        || (SMR_DW_UINT(m, &vic.line_was_blank) < 0)
        || (SMR_DW_UINT(m, &vic.memptr) < 0)
        || (SMR_DW_UINT(m, &vic.memptr_inc) < 0)
        || (SMR_DW_UINT(m, &vic.row_counter) < 0)
        || (SMR_DW_UINT(m, &vic.buf_offset) < 0)
        || SMR_B_INT(m, &vic.light_pen.state) < 0
        || SMR_B_INT(m, &vic.light_pen.triggered) < 0
        || SMR_DW_INT(m, &vic.light_pen.x) < 0
        || SMR_DW_INT(m, &vic.light_pen.y) < 0
        || SMR_DW_INT(m, &vic.light_pen.x_extra_bits) < 0
        || SMR_DW(m, &vic.light_pen.trigger_cycle) < 0
        || (SMR_B(m, &vic.vbuf) < 0)) {
        goto fail;
    }

    /* Color RAM.  */
    if (SMR_BA(m, mem_ram + 0x9400, 0x400) < 0) {
        goto fail;
    }

    for (i = 0; i < 0x10; i++) {
        if (SMR_B(m, &b) < 0) {
            goto fail;
        }

        /* XXX: This assumes that there are no side effects.  */
        vic_store(i, b);
    }

    raster_force_repaint(&vic.raster);
    return snapshot_module_close(m);

fail:
    if (m != NULL)
        snapshot_module_close(m);
    return -1;
}
예제 #19
0
static int sid_snapshot_read_module_extended(snapshot_t *s)
{
    BYTE major_version, minor_version;
    snapshot_module_t *m;
    sid_snapshot_state_t sid_state;
    int sound, sid_engine;

    memset(&sid_state, 0, sizeof(sid_state));

    resources_get_int("Sound", &sound);

    if (sound == 0) {
        return 0;
    }

    resources_get_int("SidEngine", &sid_engine);

    if (sid_engine != SID_ENGINE_FASTSID
#ifdef HAVE_RESID
        && sid_engine != SID_ENGINE_RESID
#endif
        ) {
        return 0;
    }

    m = snapshot_module_open(s, snap_module_name_extended,
                             &major_version, &minor_version);
    if (m == NULL) {
        return -1;
    }

    if (major_version > SNAP_MAJOR_EXTENDED
        || minor_version > SNAP_MINOR_EXTENDED) {
        log_error(LOG_DEFAULT,
                  "SID: Snapshot module version (%d.%d) newer than %d.%d.\n",
                  major_version, minor_version,
                  SNAP_MAJOR_EXTENDED, SNAP_MINOR_EXTENDED);
        return snapshot_module_close(m);
    }

    if (SMR_BA(m, sid_state.sid_register, 32) < 0
        || SMR_B(m, &(sid_state.bus_value)) < 0
        || SMR_DW(m, &(sid_state.bus_value_ttl)) < 0
        || SMR_DWA(m, sid_state.accumulator, 3) < 0
        || SMR_DWA(m, sid_state.shift_register, 3) < 0
        || SMR_WA(m, sid_state.rate_counter, 3) < 0
        || SMR_WA(m, sid_state.exponential_counter, 3) < 0
        || SMR_BA(m, sid_state.envelope_counter, 3) < 0
        || SMR_BA(m, sid_state.envelope_state, 3) < 0
        || SMR_BA(m, sid_state.hold_zero, 3) < 0) {
        snapshot_module_close(m);
        return -1;
    }

    SMR_WA(m, sid_state.rate_counter_period, 3);
    SMR_WA(m, sid_state.exponential_counter_period, 3);

    SMR_BA(m, sid_state.envelope_pipeline, 3);
    SMR_BA(m, sid_state.shift_pipeline, 3);
    SMR_DWA(m, sid_state.shift_register_reset, 3);
    SMR_DWA(m, sid_state.floating_output_ttl, 3);
    SMR_WA(m, sid_state.pulse_output, 3);
    SMR_B(m, &(sid_state.write_pipeline));
    SMR_B(m, &(sid_state.write_address));

    sid_state_write(0, &sid_state);

    return snapshot_module_close(m);
}