-
Notifications
You must be signed in to change notification settings - Fork 2
/
gen.py
executable file
·117 lines (94 loc) · 2.89 KB
/
gen.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/python
#
# This script is used to generate contents of docs/ folder. This script assumes
# that it is launched from the repository root.
#
import os
import os.path
import subprocess
from string import Template
roms = os.path.join('.', "roms")
docs_dir = os.path.join('.', "docs")
if not os.path.isdir('Chip8-Disassembler') or not os.path.isdir('binaryen'):
print(
"""Chip8-Disassembler directory is not found.
Try updating submodules with command:
git submodule update --init""")
exit()
chip8_disassembler_bin = 'Chip8-Disassembler/Chip8-Disassembler'
if not os.path.isfile(chip8_disassembler_bin):
print(
"""Chip8-Disassembler executable is not found.
Try to build it with:
cd Chip8-Disassembler && make""")
exit()
wasm_disassembler_bin = 'binaryen/bin/wasm-dis'
if not os.path.isfile(wasm_disassembler_bin):
print(
"""Binaryen wasm-dis executable is not found.
Try to build it with:
cd binaryen && cmake . && make""")
exit()
if not os.path.isdir('docs'):
os.mkdir('docs')
ROMS = [
"15PUZZLE",
"BLINKY",
"BLITZ",
"BRIX",
"CONNECT4",
"GUESS",
"HIDDEN",
# "INVADERS", endless loop
"KALEID",
"MAZE",
"MERLIN",
"MISSILE",
"PONG",
"PONG2",
"PUZZLE",
"SYZYGY",
"TANK",
"TETRIS",
"TICTAC",
"UFO",
"VBRIX",
"VERS",
"WIPEOFF",
# "ZERO", unexpected EOF
]
index = '''
<html>
<head></head>
<body>
<a href="https://github.com/pepyakin/emchipten">GitHub</a><br/>
<h3>Choose ROM:</h3>
'''
with open("player_template.html") as player_template_file:
player_template = Template(player_template_file.read())
for rom_name in ROMS:
rom_path = os.path.join(roms, rom_name)
player_filename = rom_name + '.html'
rom_disasm_filename = rom_name + '.ch8.txt'
rom_disasm_path = os.path.join(docs_dir, rom_disasm_filename)
compiled_wasm_filename = rom_name + '.wasm'
compiled_wasm_path = os.path.join(docs_dir, compiled_wasm_filename)
wasm_disasm_filename = rom_name + '.wast.txt'
wasm_disasm_path = os.path.join(docs_dir, wasm_disasm_filename)
# Translate ROM into .wasm binary located at `compiled_wasm_path`.
subprocess.call("cargo run -- -o %s %s" % (compiled_wasm_path, rom_path), shell=True)
subprocess.call("%s %s > %s" % (chip8_disassembler_bin, rom_path, rom_disasm_path), shell=True)
subprocess.call("%s -o %s %s" % (wasm_disassembler_bin, wasm_disasm_path, compiled_wasm_path), shell=True)
index += '<a href="%s">%s</a><br/>\n' % (player_filename, rom_name)
player_html = player_template.substitute(
rom_name=compiled_wasm_filename,
rom_disasm_filename=rom_disasm_filename,
wasm_disasm_filename=wasm_disasm_filename)
with open('docs/' + player_filename, 'w') as player_html_file:
player_html_file.write(player_html)
index += '''
</body>
</html>
'''
with open('docs/index.html', 'w') as f:
f.write(index)