Skip to content

Commit b288c30

Browse files
committed
Fix cpu state for in and out
These should not affect nothing except the register used in IN
1 parent 764a219 commit b288c30

6 files changed

Lines changed: 138 additions & 1 deletion

File tree

arch/zx48k/optimizer/cpustate.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,13 @@ def execute(self, asm_code):
736736
self.Z = int(val == 0)
737737
return
738738

739+
if i == 'out':
740+
return
741+
742+
if i == 'in':
743+
self.set(o[0], None)
744+
return
745+
739746
# Unknown. Resets ALL
740747
self.reset()
741748

tests/arch/zx48k/optimizer/test_cpustate.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,4 +305,25 @@ def test_xor_a(self):
305305
self.assertEqual(self.regs['a'], '0')
306306
self.assertEqual(self.cpu_state.C, 0)
307307
self.assertEqual(self.cpu_state.Z, 1)
308-
# Must not crash
308+
309+
def test_out_c_a(self):
310+
code = """
311+
xor a
312+
out (c), a
313+
"""
314+
self._eval(code)
315+
self.assertEqual(self.regs['a'], '0')
316+
self.assertEqual(self.cpu_state.C, 0)
317+
self.assertEqual(self.cpu_state.Z, 1)
318+
319+
def test_in_a_c(self):
320+
code = """
321+
xor a
322+
in a, (c)
323+
"""
324+
self._eval(code)
325+
self.assertNotEqual(self.regs['a'], '0')
326+
self.assertTrue(helpers.is_unknown8(self.regs['a']))
327+
self.assertEqual(self.cpu_state.C, 0)
328+
self.assertEqual(self.cpu_state.Z, 1)
329+

tests/functional/opt3_inout.asm

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
org 32768
2+
__START_PROGRAM:
3+
di
4+
push ix
5+
push iy
6+
exx
7+
push hl
8+
exx
9+
ld hl, 0
10+
add hl, sp
11+
ld (__CALL_BACK__), hl
12+
ei
13+
xor a
14+
ld bc, 32768
15+
out (c), a
16+
out (c), a
17+
in a, (c)
18+
ld (_a), a
19+
in a, (c)
20+
ld (_a), a
21+
ld (0), a
22+
ld bc, 0
23+
__END_PROGRAM:
24+
di
25+
ld hl, (__CALL_BACK__)
26+
ld sp, hl
27+
exx
28+
pop hl
29+
pop iy
30+
pop ix
31+
exx
32+
ei
33+
ret
34+
__CALL_BACK__:
35+
DEFW 0
36+
37+
ZXBASIC_USER_DATA:
38+
_a:
39+
DEFB 00
40+
; Defines DATA END --> HEAP size is 0
41+
ZXBASIC_USER_DATA_END EQU ZXBASIC_MEM_HEAP
42+
; Defines USER DATA Length in bytes
43+
ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA
44+
END

tests/functional/opt3_inout.bas

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
DIM a as UByte
3+
4+
out 32768, 0
5+
out 32768, 0
6+
7+
a = in 32768
8+
a = in 32768
9+
10+
poke 0, a
11+

tests/functional/opt4_inout.asm

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
org 32768
2+
__START_PROGRAM:
3+
di
4+
push ix
5+
push iy
6+
exx
7+
push hl
8+
exx
9+
ld hl, 0
10+
add hl, sp
11+
ld (__CALL_BACK__), hl
12+
ei
13+
xor a
14+
ld bc, 32768
15+
out (c), a
16+
out (c), a
17+
in a, (c)
18+
in a, (c)
19+
ld (_a), a
20+
ld (0), a
21+
ld bc, 0
22+
__END_PROGRAM:
23+
di
24+
ld hl, (__CALL_BACK__)
25+
ld sp, hl
26+
exx
27+
pop hl
28+
pop iy
29+
pop ix
30+
exx
31+
ei
32+
ret
33+
__CALL_BACK__:
34+
DEFW 0
35+
36+
ZXBASIC_USER_DATA:
37+
_a:
38+
DEFB 00
39+
; Defines DATA END --> HEAP size is 0
40+
ZXBASIC_USER_DATA_END EQU ZXBASIC_MEM_HEAP
41+
; Defines USER DATA Length in bytes
42+
ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA
43+
END

tests/functional/opt4_inout.bas

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
DIM a as UByte
3+
4+
out 32768, 0
5+
out 32768, 0
6+
7+
a = in 32768
8+
a = in 32768
9+
10+
poke 0, a
11+

0 commit comments

Comments
 (0)