-
Notifications
You must be signed in to change notification settings - Fork 1
/
gentap.py
executable file
·92 lines (76 loc) · 2.45 KB
/
gentap.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
sys.path.append('./extra')
import basic
import scr
def read_bin_file(fname):
with open(fname, 'rb') as f:
return bytearray(f.read()) # PY: 'return f.read()' in Python 3
def get_str(chars):
return [ord(c) for c in chars]
def get_word(word):
return (word % 256, word // 256)
def get_parity(data):
parity = 0
for b in data[2:]:
parity ^= b
return parity
def gen_basic_loader(title):
header = []
header.extend(get_word(19)) # Length of header block
header.append(0) # Header block marker
header.append(0) # BASIC program follows
header.extend(get_str(title[:10].ljust(10))) # Title padded with spaces
header.extend(get_word(len(basic.basic_data)))
header.extend(get_word(10)) # RUN 10 after LOADing
#header.extend(get_word(32768)) # Nao autoloada
header.extend(get_word(len(basic.basic_data)))
header.append(get_parity(header))
data = []
data.extend(get_word(len(basic.basic_data)+2))
data.append(255)
for i in basic.basic_data:
data.append(i)
data.append(get_parity(data))
return header + data
def gen_screen(title):
header = []
header.extend(get_word(19))
header.append(0)
header.append(3)
header.extend(get_str(title[:10].ljust(10)))
header.extend(get_word(6912))
header.extend(get_word(16384))
header.extend(get_word(0))
header.append(get_parity(header))
data = []
data.extend(get_word(len(scr.screen_data)+2))
data.append(255)
for i in scr.screen_data:
data.append(i)
data.append(get_parity(data))
return header + data
def gen_code(title):
bin_data = read_bin_file("ParadiseCafe.bin")
header = []
header.extend(get_word(19))
header.append(0)
header.append(3)
header.extend(get_str(title[:10].ljust(10)))
header.extend(get_word(len(bin_data)))
header.extend(get_word(30000))
header.extend(get_word(0))
header.append(get_parity(header))
data = []
data.extend(get_word(len(bin_data)+2))
data.append(255)
for i in bin_data:
data.append(i)
data.append(get_parity(data))
return header + data
tap_data = gen_basic_loader("benfica")
tap_data.extend(gen_screen("glorioso"))
tap_data.extend(gen_code("barbas"))
with open("ParadiseCafe.tap", 'wb') as f:
f.write(bytearray(tap_data))