Skip to content

Commit a1fc0e2

Browse files
committed
[#65][Python] Support enitering and exiting the halted mode manually.
And give an example.
1 parent bb0cbcb commit a1fc0e2

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

examples/exit_halted_state.oy

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python3
2+
3+
import z80
4+
5+
6+
def main():
7+
INC_A = 0x3c
8+
HALT = 0x76
9+
10+
code = bytes([INC_A, HALT, INC_A])
11+
12+
m = z80.Z80Machine()
13+
m.set_memory_block(0x0000, code)
14+
15+
def step():
16+
m.ticks_to_stop = 1
17+
m.run()
18+
19+
print(f'pc={m.pc:04x} a={m.a:02x} halted={m.halted}')
20+
21+
# Execute the first 'inc a'.
22+
step()
23+
24+
# Execute the halt.
25+
# From now on, stepping will not progress until we exit the halted mode.
26+
step()
27+
step()
28+
step()
29+
30+
# Exit the halted mode and execute the second 'inc a'.
31+
m.halted = False
32+
step()
33+
34+
35+
if __name__ == "__main__":
36+
main()

z80/_machine.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,11 @@ def int_disabled(self):
298298

299299
@property
300300
def halted(self):
301-
return self.__halted[0]
301+
return bool(self.__halted[0])
302+
303+
@halted.setter
304+
def halted(self, value):
305+
self.__halted[0] = int(value)
302306

303307
@property
304308
def index_rp_kind(self):

0 commit comments

Comments
 (0)