Skip to content

Commit

Permalink
Enable sna2skool.py to disassemble IM 0/1/2 variants
Browse files Browse the repository at this point in the history
  • Loading branch information
skoolkid committed Jun 11, 2024
1 parent b2bc5bc commit a2e1379
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
6 changes: 6 additions & 0 deletions skoolkit/disassembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ def __init__(self, snapshot, config):
self.after_ED[0x70] = (self.no_arg, 'IN F,(C)')
elif opcode == 'ED71':
self.after_ED[0x71] = (self.no_arg, 'OUT (C),0')
elif opcode == 'IM':
self.after_ED[0x4E] = (self.no_arg, 'IM 0')
self.after_ED[0x66] = (self.no_arg, 'IM 0')
self.after_ED[0x6E] = (self.no_arg, 'IM 0')
self.after_ED[0x76] = (self.no_arg, 'IM 1')
self.after_ED[0x7E] = (self.no_arg, 'IM 2')
elif opcode == 'NEG':
for i in range(0x4C, 0x7D, 8):
self.after_ED[i] = (self.no_arg, 'NEG')
Expand Down
1 change: 1 addition & 0 deletions sphinx/source/commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,7 @@ values:

* ``ED70`` - IN F,(C)
* ``ED71`` - OUT (C),0
* ``IM`` - IM 0/1/2 variants (ED followed by 4E/66/6E/76/7E)
* ``NEG`` - NEG variants (ED followed by 4C/54/5C/64/6C/74/7C)
* ``RETN`` - RETN variants (ED followed by 55/5D/65/6D/75/7D)
* ``XYCB`` - undocumented instructions with DDCB or FDCB opcode prefixes
Expand Down
9 changes: 9 additions & 0 deletions tests/test_disassembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2354,6 +2354,15 @@ def test_additional_opcodes_ed(self):
self.assertEqual(len(instructions), 1)
self.assertEqual(instructions[0][1], op)

def test_additional_opcodes_im(self):
snapshot = [0xED, 0, 0, 0]
disassembler = self._get_disassembler(snapshot, opcodes='IM')
for opcode, mode in ((0x4E, 0), (0x66, 0), (0x6E, 0), (0x76, 1), (0x7E, 2)):
snapshot[1] = opcode
instructions = disassembler.disassemble(0, 2, 'n')
self.assertEqual(len(instructions), 1)
self.assertEqual(instructions[0][1], f'IM {mode}')

def test_additional_opcodes_neg(self):
snapshot = [0xED, 0, 0, 0]
disassembler = self._get_disassembler(snapshot, opcodes='NEG')
Expand Down
10 changes: 8 additions & 2 deletions tests/test_snaskool.py
Original file line number Diff line number Diff line change
Expand Up @@ -3422,10 +3422,13 @@ def test_opcodes(self):
0xFD, 0xCB, 0x00, 0xFF, # SET 7,(IY+0),A
0xED, 0x54, # NEG
0xED, 0x55, # RETN
0xED, 0x6E, # IM 0
0xED, 0x76, # IM 1
0xED, 0x7E, # IM 2
]
ctl = """
c 00000
i 00016
i 00022
"""
exp_skool = """
; Routine at 0
Expand All @@ -3435,8 +3438,11 @@ def test_opcodes(self):
00008 SET 7,(IY+0),A ;
00012 NEG ;
00014 RETN ;
00016 IM 0 ;
00018 IM 1 ;
00020 IM 2 ;
"""
self._test_write_skool(snapshot, ctl, exp_skool, params={'Opcodes': 'ED70,ED71,NEG,RETN,XYCB'})
self._test_write_skool(snapshot, ctl, exp_skool, params={'Opcodes': 'ED70,ED71,IM,NEG,RETN,XYCB'})

def test_semicolons_bcgi(self):
snapshot = [0, 201, 0, 0, 0, 65, 0, 0, 0]
Expand Down

0 comments on commit a2e1379

Please sign in to comment.