Coverage for MC6809/components/cpu6809.py: 76%
33 statements
« prev ^ index » next coverage.py v7.2.1, created at 2023-03-06 19:50 +0100
« prev ^ index » next coverage.py v7.2.1, created at 2023-03-06 19:50 +0100
1#!/usr/bin/env python
3"""
4 MC6809 - 6809 CPU emulator in Python
5 =======================================
7 6809 is Big-Endian
9 Links:
10 http://dragondata.worldofdragon.org/Publications/inside-dragon.htm
11 http://www.burgins.com/m6809.html
12 http://koti.mbnet.fi/~atjs/mc6809/
14 :copyleft: 2013-2015 by the MC6809 team, see AUTHORS for more details.
15 :license: GNU GPL v3 or above, see LICENSE for more details.
17 Based on:
18 * ApplyPy by James Tauber (MIT license)
19 * XRoar emulator by Ciaran Anscomb (GPL license)
20 more info, see README
21"""
24import logging
26from MC6809.components.mc6809_addressing import AddressingMixin
27from MC6809.components.mc6809_base import CPUBase
28from MC6809.components.mc6809_cc_register import CPUConditionCodeRegisterMixin
29from MC6809.components.mc6809_interrupt import InterruptMixin
30from MC6809.components.mc6809_ops_branches import OpsBranchesMixin
31from MC6809.components.mc6809_ops_load_store import OpsLoadStoreMixin
32from MC6809.components.mc6809_ops_logic import OpsLogicalMixin
33from MC6809.components.mc6809_ops_test import OpsTestMixin
34from MC6809.components.mc6809_speedlimited import CPUSpeedLimitMixin
35from MC6809.components.mc6809_stack import StackMixin
36from MC6809.components.mc6809_tools import CPUThreadedStatusMixin, CPUTypeAssertMixin
37from MC6809.core.cpu_control_server import CPUControlServerMixin
40log = logging.getLogger("MC6809")
43# HTML_TRACE = True
44HTML_TRACE = False
47class CPU(CPUBase, AddressingMixin, StackMixin, InterruptMixin, OpsLoadStoreMixin, OpsBranchesMixin,
48 OpsTestMixin, OpsLogicalMixin, CPUConditionCodeRegisterMixin, CPUThreadedStatusMixin):
50 def to_speed_limit(self):
51 return change_cpu(self, CPUSpeedLimit)
54class CPUSpeedLimit(CPUSpeedLimitMixin, CPU):
56 def to_normal(self):
57 return change_cpu(self, CPU)
60class CPUTypeAssert(CPUTypeAssertMixin, CPU):
61 pass
64class CPUControlServer(CPUControlServerMixin, CPU):
65 pass
68def change_cpu(old_cpu, NewCPU):
69 old_cpu.running = False
70 cpu_state = old_cpu.get_state()
72 new_cpu = NewCPU(memory=old_cpu.memory, cfg=old_cpu.cfg)
73 new_cpu.set_state(cpu_state)
75 log.critical("Change CPU from %r to %r",
76 old_cpu.__class__.__name__,
77 new_cpu.__class__.__name__
78 )
80 return new_cpu