1
0
mirror of https://github.com/mnaberez/py65.git synced 2024-06-06 20:29:34 +00:00

Added a new "save" command to the monitor.

This commit is contained in:
Mike Naberezny 2009-08-22 20:15:55 -07:00
parent 2b25cc9f90
commit a577c71be5
3 changed files with 61 additions and 0 deletions

View File

@ -29,6 +29,9 @@ Next Release
Overflow (V) flag. This fixes a failure in Rob Finch's test suite.
Closes #6.
- A new "save" command has been added to the monitor that will save
a range of memory to a binary file.
0.6 (2009-08-11)
- Added monitor shortcut "a" for "assemble".

View File

@ -62,6 +62,7 @@ class Monitor(cmd.Cmd):
'r': 'registers',
'ret': 'return',
'rad': 'radix',
's': 'save',
'shl': 'show_labels',
'x': 'quit',
'z': 'step'}
@ -410,6 +411,34 @@ class Monitor(cmd.Cmd):
return
self._fill(start, start, map(ord, bytes))
def do_save(self, args):
split = shlex.split(args)
if len(split) != 3:
self._output("Syntax error: %s" % args)
return
filename = split[0]
start = self._address_parser.number(split[1])
end = self._address_parser.number(split[2])
bytes = self._mpu.memory[start:end+1]
try:
f = open(filename, 'wb')
for byte in bytes:
f.write(chr(byte))
f.close()
except (OSError, IOError), why:
msg = "Cannot save file: [%d] %s" % (why[0], why[1])
self._output(msg)
return
self._output("Saved +%d bytes to %s" % (len(bytes), filename))
def help_save(self):
self._output("save \"filename\" <start> <end>")
self._output("Save the specified memory range to disk as a binary file.")
self._output("Commodore-style load address bytes are not written.")
def help_fill(self):
self._output("fill <address_range> <data_list>")

View File

@ -2,6 +2,7 @@ import unittest
import sys
import re
import os
import tempfile
from py65.monitor import Monitor
from StringIO import StringIO
@ -247,6 +248,34 @@ class MonitorTests(unittest.TestCase):
out = stdout.getvalue()
self.assertTrue(out.startswith("reset\t"))
def test_save_with_less_than_three_args_syntax_error(self):
stdout = StringIO()
mon = Monitor(stdout=stdout)
mon.do_save('filename start')
out = stdout.getvalue()
self.assertTrue(out.startswith('Syntax error'))
def test_save(self):
stdout = StringIO()
mon = Monitor(stdout=stdout)
mon._mpu.memory[0:3] = [0xAA, 0xBB, 0xCC]
f = tempfile.NamedTemporaryFile()
mon.do_save("'%s' 0 2" % f.name)
f.seek(0)
self.assertEqual(chr(0xAA) + chr(0xBB) + chr(0xCC),
f.read())
self.assertEqual('Saved +3 bytes to %s\n' % f.name,
stdout.getvalue())
f.close()
def test_help_save(self):
stdout = StringIO()
mon = Monitor(stdout=stdout)
mon.help_save()
out = stdout.getvalue()
self.assertTrue(out.startswith('save'))
# tilde
def test_tilde_shortcut_with_space(self):