Skip to content

Commit 6d67a14

Browse files
authored
Merge pull request #416 from boriel/bugfix/o3_local_var_bug
Bugfix/o3 local var bug
2 parents 92427b3 + 26a5856 commit 6d67a14

3 files changed

Lines changed: 40 additions & 4 deletions

File tree

docs/released_programs.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ Year: 2013
10601060

10611061
Source: Yes
10621062

1063-
Link: [http://www.boriel.com/forum/post4353.html#p4353](http://www.boriel.com/forum/post4353.html#p4353)
1063+
Link: [https://www.boriel.com/forum/showthread.php?tid=529&pid=3334#pid3334](https://www.boriel.com/forum/showthread.php?tid=529&pid=3334#pid3334)
10641064

10651065
![P3efilebrowser.png](./img/games/p3efilebrowser.png)
10661066

@@ -1075,7 +1075,7 @@ Year: 2014
10751075

10761076
Source: Yes
10771077

1078-
Link: [http://www.boriel.com/forum/gallery/show-off-your-creativity-t578-45.html#p5341](http://www.boriel.com/forum/gallery/show-off-your-creativity-t578-45.html#p5341)
1078+
Link: [https://www.boriel.com/forum/showthread.php?tid=299&pid=4142#pid4142](https://www.boriel.com/forum/showthread.php?tid=299&pid=4142#pid4142)
10791079

10801080
![MultiIOboard.png](./img/games/multiioboard.png)
10811081

@@ -1090,7 +1090,7 @@ Year: 2015
10901090

10911091
Source: No
10921092

1093-
Link: [http://www.boriel.com/forum/gallery/the-spectrum-client-t972.html](http://www.boriel.com/forum/gallery/the-spectrum-client-t972.html)
1093+
Link: [https://www.boriel.com/forum/showthread.php?tid=644](https://www.boriel.com/forum/showthread.php?tid=644)
10941094

10951095
![TheSpectrumClient.png](./img/games/thespectrumclient.png)
10961096

src/arch/zx48k/optimizer/cpustate.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,12 +687,14 @@ def execute(self, asm_code):
687687

688688
if i == 'neg':
689689
if self.getv('a') is None:
690+
self.set('a', None)
690691
self.set_flag(None)
691692
return
692693

693694
val = -self.getv('a')
694695
self.set('a', val)
695696
self.Z = int(not val)
697+
self.C = int(not self.Z)
696698
val &= 0xFF
697699
self.S = val >> 7
698700
return

tests/arch/zx48k/optimizer/test_cpustate.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ def _eval(self, code):
1818
def regs(self):
1919
return self.cpu_state.regs
2020

21+
@property
22+
def mem(self):
23+
return self.cpu_state.mem
24+
2125
def test_cpu_state_ld_a_unknown(self):
2226
code = """
2327
ld a, (_N)
@@ -349,7 +353,7 @@ def test_ex_de_hl(self):
349353
self.assertEqual(self.regs['d'], str(0x12))
350354
self.assertEqual(self.regs['e'], str(0x34))
351355

352-
def test_ex_de_hl_unkown(self):
356+
def test_ex_de_hl_unknown(self):
353357
code = """
354358
ld hl, (x)
355359
ld de, (y)
@@ -362,3 +366,33 @@ def test_ex_de_hl_unkown(self):
362366
self.assertEqual(self.regs['l'], helpers.LO16_val(self.cpu_state.mem['y']))
363367
self.assertEqual(self.regs['d'], helpers.HI16_val(self.cpu_state.mem['x']))
364368
self.assertEqual(self.regs['e'], helpers.LO16_val(self.cpu_state.mem['x']))
369+
370+
def test_neg_nz(self):
371+
code = """
372+
xor a
373+
ld a, 1
374+
neg
375+
"""
376+
self._eval(code)
377+
self.assertEqual(self.regs['a'], str(0xFF))
378+
self.assertEqual(self.cpu_state.C, 1)
379+
self.assertEqual(self.cpu_state.Z, 0)
380+
381+
def test_neg_z(self):
382+
code = """
383+
xor a
384+
cp 1
385+
neg
386+
"""
387+
self._eval(code)
388+
self.assertEqual(self.regs['a'], str(0))
389+
self.assertEqual(self.cpu_state.C, 0)
390+
self.assertEqual(self.cpu_state.Z, 1)
391+
392+
def test_ix_neg(self):
393+
code = """
394+
ld a, (ix-1)
395+
neg
396+
"""
397+
self._eval(code)
398+
self.assertNotEqual(self.regs['a'], self.mem['ix-1'])

0 commit comments

Comments
 (0)