X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=decoders%2Fz80%2Fpd.py;fp=decoders%2Fz80%2Fpd.py;h=088408aaf74b0008055aba4771b3261b68e91b9f;hb=aef3c1095e966212fd9a9b02cb08a0ff50e13a7b;hp=cd58b488c5d8f939af53b79a2b9a92dedd4fc4c7;hpb=31737ae022b6356eea8da9792e966b3e1d10f1c8;p=libsigrokdecode.git 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