summaryrefslogtreecommitdiff
path: root/decoders/z80/pd.py
diff options
context:
space:
mode:
authorDaniel Elstner <daniel.kitta@gmail.com>2014-02-27 21:31:10 +0100
committerDaniel Elstner <daniel.kitta@gmail.com>2014-02-27 21:41:56 +0100
commitaef3c1095e966212fd9a9b02cb08a0ff50e13a7b (patch)
treecf0a7c1d5b93932a9bba963979c3e0ab627ad3cf /decoders/z80/pd.py
parent31737ae022b6356eea8da9792e966b3e1d10f1c8 (diff)
downloadlibsigrokdecode-aef3c1095e966212fd9a9b02cb08a0ff50e13a7b.tar.gz
libsigrokdecode-aef3c1095e966212fd9a9b02cb08a0ff50e13a7b.zip
z80: Format hex numbers with leading zero if necessary.
Assembler syntax requires that all numbers start with a decimal digit. Introduce a custom 'H' format for prefixing a leading 0 to hexadecimal numbers that would otherwise start with a letter.
Diffstat (limited to 'decoders/z80/pd.py')
-rw-r--r--decoders/z80/pd.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/decoders/z80/pd.py b/decoders/z80/pd.py
index cd58b48..088408a 100644
--- a/decoders/z80/pd.py
+++ b/decoders/z80/pd.py
@@ -20,6 +20,7 @@
import sigrokdecode as srd
from functools import reduce
from .tables import instr_table_by_prefix
+import string
class Ann:
ADDR, MEMRD, MEMWR, IORD, IOWR, INSTR, ROP, WOP, WARN = range(9)
@@ -47,6 +48,18 @@ class OpState:
WOP2 = 'WOP2' # second byte of write operand
RESTART = 'RESTART' # restart instruction decoding
+# Provide custom format type 'H' for hexadecimal output
+# with leading decimal digit (assembler syntax).
+class AsmFormatter(string.Formatter):
+ def format_field(self, value, format_spec):
+ if format_spec.endswith('H'):
+ result = format(value, format_spec[:-1] + 'X')
+ return result if result[0] in string.digits else '0' + result
+ else:
+ return format(value, format_spec)
+
+formatter = AsmFormatter()
+
ann_data_cycle_map = {
Cycle.MEMRD: Ann.MEMRD,
Cycle.MEMWR: Ann.MEMWR,
@@ -183,9 +196,9 @@ class Decoder(srd.Decoder):
self.ann_dasm = None
def put_disasm(self):
- text = self.mnemonic.format(r=self.arg_reg, d=self.arg_dis,
- i=self.arg_imm, ro=self.arg_read,
- wo=self.arg_write)
+ text = formatter.format(self.mnemonic, r=self.arg_reg,
+ d=self.arg_dis, i=self.arg_imm,
+ ro=self.arg_read, wo=self.arg_write)
self.put_text(self.dasm_start, self.ann_dasm, text)
self.ann_dasm = None
self.dasm_start = self.samplenum