forked from natdan/PyZX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
screen.py
147 lines (110 loc) · 3.94 KB
/
screen.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
from PIL import Image
from PIL import ImagePalette
name = '.\\games\\Storm Lord.Sna'
f = open(name, 'rb')
f.seek(27)
buf = f.read(6912)
# background = Image.new("RGB", (w, h), (r, g, b))
# img = Image.new("RGB", (256, 192), (0, 0, 0))
# colorz = [(0, 0, 0), # Black Bright Off
# (0, 0, 192), # Blue Bright Off
# (192, 0, 0), # Red Bright Off
# (192, 0, 192), # Magenta Bright Off
# (0, 192, 0), # Green Bright Off
# (0, 192, 192), # Cyan Bright Off
# (192, 192, 0), # Yellow Bright Off
# (192, 192, 192), # White Bright Off
#
# (0, 0, 0), # Black Bright On
# (0, 0, 255), # Blue Bright On
# (255, 0, 0), # Red Bright On
# (255, 0, 255), # Magenta Bright On
# (0, 255, 0), # Green Bright On
# (0, 255, 255), # Cyan Bright On
# (255, 255, 0), # Yellow Bright On
# (255, 255, 255)] # White Bright On
colors = [0, 0, 0, # Black Bright Off
0, 0, 192, # Blue Bright Off
192, 0, 0, # Red Bright Off
192, 0, 192, # Magenta Bright Off
0, 192, 0, # Green Bright Off
0, 192, 192, # Cyan Bright Off
192, 192, 0, # Yellow Bright Off
192, 192, 192, # White Bright Off
0, 0, 0, # Black Bright On
0, 0, 255, # Blue Bright On
255, 0, 0, # Red Bright On
255, 0, 255, # Magenta Bright On
0, 255, 0, # Green Bright On
0, 255, 255, # Cyan Bright On
255, 255, 0, # Yellow Bright On
255, 255, 255] # White Bright On
img = Image.new("P", (256, 192), 0)
img.putpalette(colors, 'RGB')
pixels = img.load()
# colors = [0, # Black Bright Off
# 1, # Blue Bright Off
# 2, # Red Bright Off
# 3, # Magenta Bright Off
# 4, # Green Bright Off
# 5, # Cyan Bright Off
# 6, # Yellow Bright Off
# 7, # White Bright Off
# 8, # Black Bright On
# 9, # Blue Bright On
# 10, # Red Bright On
# 11, # Magenta Bright On
# 12, # Green Bright On
# 13, # Cyan Bright On
# 14, # Yellow Bright On
# 15] # White Bright On
# ImagePalette.ImagePalette("RGB", palette=colorz, size=16*3)
pix_num = 0
coord_y = 0
for counter_y in range(0, 192):
zx_row = ((coord_y & 0b111) << 3) + ((coord_y & 0b111000) >> 3) + (coord_y & 0b11000000)
for counter_x in range(0, 256, 8):
attr_adr = 0x1800 + zx_row // 8 * 32 + counter_x // 8
attr = buf[attr_adr]
# color_ink = colors[(attr & 0b1111000) >> 3]
# color_paper = colors[((attr & 0b1000000) >> 3) + (attr & 0b111)]
color_ink = (attr & 0b1111000) >> 3
color_paper = ((attr & 0b1000000) >> 3) + (attr & 0b111)
pix_group = [0, 0, 0, 0, 0, 0, 0, 0]
pix = buf[pix_num]
if pix & 0b00000001:
pix_group[7] = 1
if pix & 0b00000010:
pix_group[6] = 1
if pix & 0b00000100:
pix_group[5] = 1
if pix & 0b00001000:
pix_group[4] = 1
if pix & 0b00010000:
pix_group[3] = 1
if pix & 0b00100000:
pix_group[2] = 1
if pix & 0b01000000:
pix_group[1] = 1
if pix & 0b10000000:
pix_group[0] = 1
coord_x = 0
for pixt in pix_group:
if pixt:
pixels[counter_x + coord_x, zx_row] = color_paper
else:
pixels[counter_x + coord_x, zx_row] = color_ink
coord_x += 1
pix_num += 1
coord_y += 1
# img.putpalette(colorz, 'RGB')
# a = img.getpalette()
# print(a)
# for j in range(192):
# for i in range(256):
# pixels[i, j] = i
#
#
#
img.save('zx-image.png')
img.show()