forked from whaleygeek/MyLittleComputer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinteractive.py
39 lines (26 loc) · 862 Bytes
/
interactive.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# interactive.py 03/11/2014 D.J.Whale
#
# A simple interactive shell
import instruction
import parser
import simulator
def todec(n):
return str(n).zfill(3)
simulator.memory = [0 for i in range(99)]
def main():
while not simulator.halt_flag:
line = raw_input("instruction? ")
label, operator, operand, labelref = parser.parseLine(line)
instr = instruction.build(operator, operand)
print("instr:" + instruction.toString(instr))
simulator.memory[simulator.program_counter] = instr
simulator.cycle()
#TODO: Somehow adding b_reg functionality needs to add b display here too?
print(" pc:" + todec(simulator.program_counter)
+ " a:" + todec(simulator.accumulator)
+ " z:" + str(simulator.z_flag)
+ " p:" + str(simulator.p_flag)
+ " halt:" + str(simulator.halt_flag))
if __name__ == "__main__":
main()
# END