-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdebug.py
More file actions
58 lines (51 loc) · 1.81 KB
/
Copy pathdebug.py
File metadata and controls
58 lines (51 loc) · 1.81 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# This module contains functions used for debugging the CPU & video
# Generate a hexdump of the chip8's RAM
def system_memory_dump(chip8):
for i in range(0, len(chip8.system_memory), 16):
print(format(i, '04X'),":", end=" ")
for j in range(8):
print(format(chip8.system_memory[i+j], '02X'), end=" ")
print(" ", end="")
for k in range(8,16):
print(format(chip8.system_memory[i+k], '02X'), end=" ")
print("")
print(len(chip8.system_memory), "bytes")
print("\n")
# Generate a bitmap dump of the chip8's video memory
def video_memory_dump(chip8):
for i in range(32):
for j in range(64):
print(chip8.video_memory[i*64+j],end="")
print("")
print("\n")
# Generate a hexdump of the chip8's registers
def system_registers_dump(chip8):
print(" I:", format(chip8.register_I, '04X'))
print(" PC:", format(chip8.register_PC, '04X'))
print("DRAW:", format(int(chip8.video_draw_flag), "02X"))
print(" KEY:", end=" ")
for i in range(8):
print(format(chip8.keys_pressed[i],'02X'),end=" ")
print(" ", end="")
for j in range(8,16):
print(format(chip8.keys_pressed[j],'02X'),end=" ")
print("\n", end="")
print(" Vn:", end=" ")
for i in range(8):
print(format(chip8.register_V[i],'02X'),end=" ")
print(" ", end="")
for j in range(8,16):
print(format(chip8.register_V[j],'02X'),end=" ")
print("\n")
# Generate a hexdump of the chip8's stack
def system_stack_dump(chip8):
print("STACK:", end=" ")
for i in reversed(chip8.stack):
print(format(i,'04X'),end=" ")
print("\n")
# Execute all debugging functions
def dump(chip8):
video_memory_dump(chip8)
system_memory_dump(chip8)
system_registers_dump(chip8)
system_stack_dump(chip8)