static unsigned int mon_register_get_val(int mem, int reg_id) { mos6510_regs_t *reg_ptr; if (monitor_diskspace_dnr(mem) >= 0) { if (!check_drive_emu_level_ok(monitor_diskspace_dnr(mem) + 8)) { return 0; } } reg_ptr = mon_interfaces[mem]->cpu_regs; switch(reg_id) { case e_A: return MOS6510_REGS_GET_A(reg_ptr); case e_X: return MOS6510_REGS_GET_X(reg_ptr); case e_Y: return MOS6510_REGS_GET_Y(reg_ptr); case e_PC: return MOS6510_REGS_GET_PC(reg_ptr); case e_SP: return MOS6510_REGS_GET_SP(reg_ptr); case e_FLAGS: return MOS6510_REGS_GET_FLAGS(reg_ptr) | MOS6510_REGS_GET_SIGN(reg_ptr) | (MOS6510_REGS_GET_ZERO(reg_ptr) << 1); default: log_error(LOG_ERR, "Unknown register!"); } return 0; }
/* Handle a ROM trap. */ inline static DWORD drive_trap_handler(drive_context_t *drv) { if (MOS6510_REGS_GET_PC(&(drv->cpu->cpu_regs)) == (WORD)drv->drive->trap) { MOS6510_REGS_SET_PC(&(drv->cpu->cpu_regs), drv->drive->trapcont); if (drv->drive->idling_method == DRIVE_IDLE_TRAP_IDLE) { CLOCK next_clk; next_clk = alarm_context_next_pending_clk(drv->cpu->alarm_context); if (next_clk > drv->cpu->stop_clk) { next_clk = drv->cpu->stop_clk; } *(drv->clk_ptr) = next_clk; } return 0; } return (DWORD)-1; }
int maincpu_snapshot_write_module(snapshot_t *s) { snapshot_module_t *m; m = snapshot_module_create(s, snap_module_name, ((BYTE)SNAP_MAJOR), ((BYTE)SNAP_MINOR)); if (m == NULL) { return -1; } if (0 || SMW_DW(m, maincpu_clk) < 0 || SMW_B(m, MOS6510_REGS_GET_A(&maincpu_regs)) < 0 || SMW_B(m, MOS6510_REGS_GET_X(&maincpu_regs)) < 0 || SMW_B(m, MOS6510_REGS_GET_Y(&maincpu_regs)) < 0 || SMW_B(m, MOS6510_REGS_GET_SP(&maincpu_regs)) < 0 || SMW_W(m, (WORD)MOS6510_REGS_GET_PC(&maincpu_regs)) < 0 || SMW_B(m, (BYTE)MOS6510_REGS_GET_STATUS(&maincpu_regs)) < 0 || SMW_DW(m, (DWORD)last_opcode_info) < 0) { goto fail; } if (interrupt_write_snapshot(maincpu_int_status, m) < 0) { goto fail; } if (interrupt_write_new_snapshot(maincpu_int_status, m) < 0) { goto fail; } return snapshot_module_close(m); fail: if (m != NULL) { snapshot_module_close(m); } return -1; }
DWORD traps_handler(void) { traplist_t *p = traplist; unsigned int pc; int result; if (machine_class == VICE_MACHINE_C64DTV) { pc = MOS6510DTV_REGS_GET_PC(&maincpu_regs); } else if (machine_class == VICE_MACHINE_SCPU64) { /* FIXME: PBR also needed ?? */ pc = WDC65816_REGS_GET_PC(&maincpu_regs); } else { pc = MOS6510_REGS_GET_PC(&maincpu_regs); } while (p) { if (p->trap->address == pc) { /* This allows the trap function to remove traps. */ WORD resume_address = p->trap->resume_address; result = (*p->trap->func)(); if (!result) { return (p->trap->check[0] | (p->trap->check[1] << 8) | (p->trap->check[2] << 16)); } /* XXX ALERT! `p' might not be valid anymore here, because `p->trap->func()' might have removed all the traps. */ if (machine_class == VICE_MACHINE_C64DTV) { MOS6510DTV_REGS_SET_PC(&maincpu_regs, resume_address); } else { MOS6510_REGS_SET_PC(&maincpu_regs, resume_address); } return 0; } p = p->next; } return (DWORD)-1; }
unsigned int maincpu_get_pc(void) { return MOS6510_REGS_GET_PC(&maincpu_regs); }
int drivecpu_snapshot_write_module(drive_context_t *drv, snapshot_t *s) { snapshot_module_t *m; drivecpu_context_t *cpu; cpu = drv->cpu; m = snapshot_module_create(s, drv->cpu->snap_module_name, ((BYTE)(SNAP_MAJOR)), ((BYTE)(SNAP_MINOR))); if (m == NULL) { return -1; } if (0 || SMW_DW(m, (DWORD) *(drv->clk_ptr)) < 0 || SMW_B(m, (BYTE)MOS6510_REGS_GET_A(&(cpu->cpu_regs))) < 0 || SMW_B(m, (BYTE)MOS6510_REGS_GET_X(&(cpu->cpu_regs))) < 0 || SMW_B(m, (BYTE)MOS6510_REGS_GET_Y(&(cpu->cpu_regs))) < 0 || SMW_B(m, (BYTE)MOS6510_REGS_GET_SP(&(cpu->cpu_regs))) < 0 || SMW_W(m, (WORD)MOS6510_REGS_GET_PC(&(cpu->cpu_regs))) < 0 || SMW_B(m, (BYTE)MOS6510_REGS_GET_STATUS(&(cpu->cpu_regs))) < 0 || SMW_DW(m, (DWORD)(cpu->last_opcode_info)) < 0 || SMW_DW(m, (DWORD)(cpu->last_clk)) < 0 || SMW_DW(m, (DWORD)(cpu->cycle_accum)) < 0 || SMW_DW(m, (DWORD)(cpu->last_exc_cycles)) < 0 || SMW_DW(m, (DWORD)(cpu->stop_clk)) < 0 ) { goto fail; } if (interrupt_write_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 (SMW_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 (SMW_BA(m, drv->drive->drive_ram, 0x2000) < 0) { goto fail; } } if (drive_check_old(drv->drive->type)) { if (SMW_BA(m, drv->drive->drive_ram, 0x1100) < 0) { goto fail; } } if (interrupt_write_new_snapshot(cpu->int_status, m) < 0) { goto fail; } return snapshot_module_close(m); fail: if (m != NULL) { snapshot_module_close(m); } return -1; }