mirror of
https://github.com/mnaberez/py65.git
synced 2025-08-08 13:25:01 +00:00
Added new "mpu" command to the monitor.
This commit is contained in:
@@ -6,7 +6,8 @@ import re
|
|||||||
import shlex
|
import shlex
|
||||||
import asyncore
|
import asyncore
|
||||||
import sys
|
import sys
|
||||||
from py65.devices.mpu65c02 import MPU
|
from py65.devices.mpu6502 import MPU as NMOS6502
|
||||||
|
from py65.devices.mpu65c02 import MPU as CMOS65C02
|
||||||
from py65.disassembler import Disassembler
|
from py65.disassembler import Disassembler
|
||||||
from py65.assembler import Assembler
|
from py65.assembler import Assembler
|
||||||
from py65.utils.addressing import AddressParser
|
from py65.utils.addressing import AddressParser
|
||||||
@@ -16,16 +17,11 @@ from py65.memory import ObservableMemory
|
|||||||
|
|
||||||
class Monitor(cmd.Cmd):
|
class Monitor(cmd.Cmd):
|
||||||
|
|
||||||
def __init__(self, options={}, completekey='tab', stdin=None, stdout=None):
|
def __init__(self, mpu_type=NMOS6502, completekey='tab', stdin=None, stdout=None):
|
||||||
self.options = options
|
self._reset(mpu_type)
|
||||||
self._width = 78
|
self._width = 78
|
||||||
self._mpu = MPU()
|
|
||||||
self._install_mpu_observers()
|
|
||||||
self._update_prompt()
|
self._update_prompt()
|
||||||
self._add_shortcuts()
|
self._add_shortcuts()
|
||||||
self._address_parser = AddressParser()
|
|
||||||
self._disassembler = Disassembler(self._mpu, self._address_parser)
|
|
||||||
self._assembler = Assembler(self._mpu, self._address_parser)
|
|
||||||
cmd.Cmd.__init__(self, completekey, stdin, stdout)
|
cmd.Cmd.__init__(self, completekey, stdin, stdout)
|
||||||
|
|
||||||
def onecmd(self, line):
|
def onecmd(self, line):
|
||||||
@@ -44,6 +40,13 @@ class Monitor(cmd.Cmd):
|
|||||||
self._update_prompt()
|
self._update_prompt()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def _reset(self, mpu_type):
|
||||||
|
self._mpu = mpu_type()
|
||||||
|
self._install_mpu_observers()
|
||||||
|
self._address_parser = AddressParser()
|
||||||
|
self._disassembler = Disassembler(self._mpu, self._address_parser)
|
||||||
|
self._assembler = Assembler(self._mpu, self._address_parser)
|
||||||
|
|
||||||
def _add_shortcuts(self):
|
def _add_shortcuts(self):
|
||||||
self._shortcuts = {'~': 'tilde',
|
self._shortcuts = {'~': 'tilde',
|
||||||
'?': 'help',
|
'?': 'help',
|
||||||
@@ -117,8 +120,32 @@ class Monitor(cmd.Cmd):
|
|||||||
self._output("reset\t\tReset the microprocessor")
|
self._output("reset\t\tReset the microprocessor")
|
||||||
|
|
||||||
def do_reset(self, args):
|
def do_reset(self, args):
|
||||||
self._mpu = MPU()
|
klass = self._mpu.__class__
|
||||||
self._install_mpu_observers()
|
self._reset(mpu_type=klass)
|
||||||
|
|
||||||
|
def do_mpu(self, args):
|
||||||
|
mpus = {'6502': NMOS6502, '65C02': CMOS65C02}
|
||||||
|
|
||||||
|
def available_mpus():
|
||||||
|
mpu_list = ', '.join(mpus.keys())
|
||||||
|
self._output("Available MPUs: %s" % mpu_list)
|
||||||
|
|
||||||
|
if args == '':
|
||||||
|
self._output("Current MPU is %s" % self._mpu.name)
|
||||||
|
available_mpus()
|
||||||
|
else:
|
||||||
|
requested = args.upper()
|
||||||
|
new_mpu = mpus.get(requested, None)
|
||||||
|
if new_mpu is None:
|
||||||
|
self._output("Unknown MPU: %s" % args)
|
||||||
|
available_mpus()
|
||||||
|
else:
|
||||||
|
self._reset(new_mpu)
|
||||||
|
self._output("Reset with new MPU %s" % self._mpu.name)
|
||||||
|
|
||||||
|
def help_mpu(self):
|
||||||
|
self._output("mpu\t\tPrint available microprocessors.")
|
||||||
|
self._output("mpu <type>\tSelect a new microprocessor.")
|
||||||
|
|
||||||
def do_EOF(self, args):
|
def do_EOF(self, args):
|
||||||
self._output('')
|
self._output('')
|
||||||
@@ -440,8 +467,8 @@ class Monitor(cmd.Cmd):
|
|||||||
self._output("Set the width used by some commands to wrap output.")
|
self._output("Set the width used by some commands to wrap output.")
|
||||||
self._output("With no argument, the current width is printed.")
|
self._output("With no argument, the current width is printed.")
|
||||||
|
|
||||||
def main(args=None, options=None):
|
def main(args=None):
|
||||||
c = Monitor(options)
|
c = Monitor()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import readline
|
import readline
|
||||||
|
@@ -67,6 +67,59 @@ class MonitorTests(unittest.TestCase):
|
|||||||
out = stdout.getvalue()
|
out = stdout.getvalue()
|
||||||
self.assertTrue(out.startswith("assemble <address>"))
|
self.assertTrue(out.startswith("assemble <address>"))
|
||||||
|
|
||||||
|
# mpu
|
||||||
|
|
||||||
|
def test_mpu_with_no_args_prints_current_lists_available_mpus(self):
|
||||||
|
stdout = StringIO()
|
||||||
|
mon = Monitor(stdout=stdout)
|
||||||
|
mon.do_mpu('')
|
||||||
|
|
||||||
|
lines = stdout.getvalue().splitlines()
|
||||||
|
self.assertEqual(2, len(lines))
|
||||||
|
self.assertTrue(lines[0].startswith('Current MPU is '))
|
||||||
|
self.assertTrue(lines[1].startswith('Available MPUs:'))
|
||||||
|
|
||||||
|
def test_mpu_with_bad_arg_gives_error_lists_available_mpus(self):
|
||||||
|
stdout = StringIO()
|
||||||
|
mon = Monitor(stdout=stdout)
|
||||||
|
mon.do_mpu('z80')
|
||||||
|
|
||||||
|
lines = stdout.getvalue().splitlines()
|
||||||
|
self.assertEqual(2, len(lines))
|
||||||
|
self.assertEqual('Unknown MPU: z80', lines[0])
|
||||||
|
self.assertTrue(lines[1].startswith('Available MPUs:'))
|
||||||
|
|
||||||
|
def test_mpu_selects_6502(self):
|
||||||
|
stdout = StringIO()
|
||||||
|
mon = Monitor(stdout=stdout)
|
||||||
|
mon.do_mpu('6502')
|
||||||
|
|
||||||
|
lines = stdout.getvalue().splitlines()
|
||||||
|
self.assertEqual(1, len(lines))
|
||||||
|
self.assertEqual('Reset with new MPU 6502', lines[0])
|
||||||
|
self.assertEqual('6502', mon._mpu.name)
|
||||||
|
|
||||||
|
def test_mpu_selects_65C02(self):
|
||||||
|
stdout = StringIO()
|
||||||
|
mon = Monitor(stdout=stdout)
|
||||||
|
mon.do_mpu('65C02')
|
||||||
|
|
||||||
|
lines = stdout.getvalue().splitlines()
|
||||||
|
self.assertEqual(1, len(lines))
|
||||||
|
self.assertEqual('Reset with new MPU 65C02', lines[0])
|
||||||
|
self.assertEqual('65C02', mon._mpu.name)
|
||||||
|
|
||||||
|
def test_help_mpu(self):
|
||||||
|
stdout = StringIO()
|
||||||
|
mon = Monitor(stdout=stdout)
|
||||||
|
mon.help_mpu()
|
||||||
|
|
||||||
|
lines = stdout.getvalue().splitlines()
|
||||||
|
self.assertEqual("mpu\t\tPrint available microprocessors.",
|
||||||
|
lines[0])
|
||||||
|
self.assertEqual("mpu <type>\tSelect a new microprocessor.",
|
||||||
|
lines[1])
|
||||||
|
|
||||||
# pwd
|
# pwd
|
||||||
|
|
||||||
def test_pwd_shows_os_getcwd(self):
|
def test_pwd_shows_os_getcwd(self):
|
||||||
@@ -135,8 +188,10 @@ class MonitorTests(unittest.TestCase):
|
|||||||
stdout = StringIO()
|
stdout = StringIO()
|
||||||
mon = Monitor(stdout=stdout)
|
mon = Monitor(stdout=stdout)
|
||||||
old_mpu = mon._mpu
|
old_mpu = mon._mpu
|
||||||
|
old_name = mon._mpu.name
|
||||||
mon.do_reset('')
|
mon.do_reset('')
|
||||||
self.assertNotEqual(old_mpu, mon._mpu)
|
self.assertNotEqual(old_mpu, mon._mpu)
|
||||||
|
self.assertEqual(old_name, mon._mpu.name)
|
||||||
|
|
||||||
def test_help_reset(self):
|
def test_help_reset(self):
|
||||||
stdout = StringIO()
|
stdout = StringIO()
|
||||||
|
Reference in New Issue
Block a user