forked from ThomasTheSpaceFox/SBTCVM-Mark-2
-
Notifications
You must be signed in to change notification settings - Fork 5
/
MK2-GAT.py
executable file
·448 lines (400 loc) · 11.6 KB
/
MK2-GAT.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
#!/usr/bin/env python
#SBTCVM Mark 2 Graphics Adapter Toolkit
import os
import pygame
import time
from pygame.locals import *
import sys
import VMSYSTEM.libbaltcalc as libbaltcalc
VMSYSROMS=os.path.join("VMSYSTEM", "ROMS")
def gfxargfind(arg):
lowarg=arg.lower()
argisfile=0
qfilewasvalid=0
for extq in ["", ".png", ".PNG", ".gif", ".GIF"]:
qarg=(arg + extq)
qlowarg=(lowarg + extq.lower())
print "searching for: \"" + qarg + "\"..."
if os.path.isfile(qarg):
argisfile=1
print "found: " + qarg
elif os.path.isfile(os.path.join("VMSYSTEM", qarg)):
qarg=os.path.join("VMSYSTEM", qarg)
print "found: " + qarg
argisfile=1
elif os.path.isfile(os.path.join(VMSYSROMS, qarg)):
qarg=os.path.join(VMSYSROMS, qarg)
print "found: " + qarg
argisfile=1
elif os.path.isfile(os.path.join("VMUSER", qarg)):
qarg=os.path.join("VMUSER", qarg)
print "found: " + qarg
argisfile=1
elif os.path.isfile(os.path.join("ROMS", qarg)):
qarg=os.path.join("ROMS", qarg)
print "found: " + qarg
argisfile=1
if argisfile==1:
if os.path.isfile(qarg):
qfilewasvalid=1
return(qarg)
else:
print "not valid."
argisfile=0
if qfilewasvalid==0:
print "File not found."
sys.exit()
def trunkto3(code):
codecnt=0
for fel in code:
codecnt +=1
if codecnt<3:
if codecnt==2:
return("0" + code)
if codecnt==1:
return("00" + code)
#print code
#code=libbaltcalc.BTINVERT(code)
return((code[0]) + (code[1]) + (code[2]))
def dollytell(lookupcode):
if lookupcode=="-":
return("0")
if lookupcode=="0":
return("127")
if lookupcode=="+":
return("255")
def codeshift(colch):
colch=int(colch)
if colch<63:
return "-"
if colch<190:
return "0"
else:
return "+"
def dropshift(colch):
colch=int(colch)
if colch<63:
return 0
if colch<190:
return 127
else:
return 255
class colgroup:
def __init__(self, con, num):
self.con=con
self.num=num
try:
cmd=sys.argv[1]
except:
cmd=None
if cmd=="-h" or cmd=="--help" or cmd=="help":
print '''This is SBTCVM Mark 2's GAT toolkit.
commands:
MK2-GAT.py -h (--help) (help): this text
MK2-GAT.py -v (--version)
MK2-GAT.py -a (--about): about MK2-GAT.py
MK2-GAT.py -g0 (--modegfx0) [imagefile]: convert an (exactly) 114x81 pixel
image to a full framebuffer area (exported as a *.tasm) for the G0, 114x81,
3-trit RGB screen mode.
MK2-GAT.py -g2 (--modegfx2) [imagefile]: full framebuffer: G2 (114x81 1-trit monochrome)
MK2-GAT.py -g3 (--modegfx3) [imagefile]: full framebuffer: G3 (54x38 3-trit RGB)
MK2-GAT.py -g4 (--modegfx4) [imagefile]: full framebuffer: G4 (54x38 1-trit monochrome)'''
elif cmd=="-v" or cmd=="--version":
print "SBTCVM Mark 2 GAT toolkit v1.0.0"
elif cmd==None:
print "tip: use MK2-GAT.py -h for help."
elif cmd=="-a" or cmd=="--about":
print '''#SBTCVM Mark 2 GAT toolkit
v1.0.0
Copyright (c) 2016-2018 Thomas Leathers and Contributors
SBTCVM Mark 2 GAT toolkit is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
SBTCVM Mark 2 GAT toolkit is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with SBTCVM Mark 2 GAT toolkit. If not, see <http://www.gnu.org/licenses/>
'''
elif cmd=="-g0" or cmd=="--modegfx0":
arg=sys.argv[2]
arg=gfxargfind(arg)
pygame.display.init()
screensurf=pygame.display.set_mode((114, 81))
IMGSOURCE=pygame.image.load(arg)
IMGw=IMGSOURCE.get_width()
IMGh=IMGSOURCE.get_height()
if IMGw!=114 or IMGh!=81:
sys.exit("ERROR: Image not proper size! image MUST match mode G0 screen size! (114x81)")
HPIX=0
assmflename=arg
assmnamelst=assmflename.rsplit('.', 1)
tasmfile=(assmnamelst[0] + (".tasm"))
tasmout=open(tasmfile, "w")
tasmout.write("\n#autogenerated by SBTCVM MARK 2 GAT toolkit, from: \"" + arg + "\" \n")
tasmout.write("""setreg1|---------
IOwrite1|>dispmode
setreg1|>dispoff
IOwrite1|>dispoffset
setreg1|000000000
IOwrite1|>dispupdate
userwait
""")
chunkcnt=0
first=1
while HPIX!=IMGh:
WPIX=0
while WPIX!=IMGw:
COLLIST=IMGSOURCE.get_at((WPIX, HPIX))
Wtern=trunkto3(libbaltcalc.DECTOBT((WPIX - 13)))
Htern=trunkto3(libbaltcalc.DECTOBT((HPIX - 13)))
#print "foo"
#print COLLIST
preR=COLLIST[0]
preG=COLLIST[1]
preB=COLLIST[2]
preA=255
#print((preR, preG, preB, preA))
postR=dropshift(preR)
postG=dropshift(preG)
postB=dropshift(preB)
terR=codeshift(preR)
terG=codeshift(preG)
terB=codeshift(preB)
postA=dropshift(preA)
#print((postR, postG, postB, postA))
IMGSOURCE.set_at((WPIX, HPIX),(postR, postG, postB))
#tasmout.write("setcolorreg|000" + terR + terG + terB + "\n")
#tasmout.write("colorpixel|000" + Wtern + Htern + "\n")
if chunkcnt==0:
chunkcnt+=1
tasmout.write("null|" + terR + terG + terB)
elif chunkcnt==1:
chunkcnt+=1
tasmout.write(terR + terG + terB)
else:
chunkcnt=0
if first==1:
first=0
tasmout.write(terR + terG + terB + "|dispoff\n")
else:
tasmout.write(terR + terG + terB + "\n")
WPIX += 1
time.sleep(0.0001)
print ("line: " + str(HPIX) + " done")
screensurf.blit(IMGSOURCE, (0, 0))
pygame.display.update()
HPIX += 1
#tasmout.write("userwait")
print ("image: \"" + arg + "\" converted to: \"" + tasmfile + "\" for SBTCVM SBTGA mode G0 (full)")
#pygame.image.save(IMGSOURCE, ("imgfilter-out.png"))
#print(IMGSOURCE.get_at((639, 479)))
elif cmd=="-g2" or cmd=="--modegfx2":
arg=sys.argv[2]
arg=gfxargfind(arg)
pygame.display.init()
screensurf=pygame.display.set_mode((114, 81))
IMGSOURCE=pygame.image.load(arg)
IMGw=IMGSOURCE.get_width()
IMGh=IMGSOURCE.get_height()
if IMGw!=114 or IMGh!=81:
sys.exit("ERROR: Image not proper size! image MUST match mode G2 screen size! (114x81)")
HPIX=0
assmflename=arg
assmnamelst=assmflename.rsplit('.', 1)
tasmfile=(assmnamelst[0] + (".tasm"))
tasmout=open(tasmfile, "w")
tasmout.write("\n#autogenerated by SBTCVM MARK 2 GAT toolkit, from: \"" + arg + "\" \n")
tasmout.write("""setreg1|--------+
IOwrite1|>dispmode
setreg1|>dispoff
IOwrite1|>dispoffset
setreg1|000000000
IOwrite1|>dispupdate
userwait
""")
chunkcnt=0
first=1
while HPIX!=IMGh:
WPIX=0
while WPIX!=IMGw:
COLLIST=IMGSOURCE.get_at((WPIX, HPIX))
Wtern=trunkto3(libbaltcalc.DECTOBT((WPIX - 13)))
Htern=trunkto3(libbaltcalc.DECTOBT((HPIX - 13)))
#print "foo"
#print COLLIST
pre=COLLIST[1]
#print((preR, preG, preB, preA))
post=dropshift(pre)
ter=codeshift(pre)
#print((postR, postG, postB, postA))
IMGSOURCE.set_at((WPIX, HPIX),(post, post, post))
#tasmout.write("setcolorreg|000" + terR + terG + terB + "\n")
#tasmout.write("colorpixel|000" + Wtern + Htern + "\n")
if chunkcnt==0:
chunkcnt+=1
tasmout.write("null|" + ter)
elif chunkcnt<8:
chunkcnt+=1
tasmout.write(ter)
else:
chunkcnt=0
if first==1:
first=0
tasmout.write(ter + "|dispoff\n")
else:
tasmout.write(ter + "\n")
WPIX += 1
time.sleep(0.0001)
print ("line: " + str(HPIX) + " done")
screensurf.blit(IMGSOURCE, (0, 0))
pygame.display.update()
HPIX += 1
#tasmout.write("userwait")
print ("image: \"" + arg + "\" converted to: \"" + tasmfile + "\" for SBTCVM SBTGA mode G2 (full)")
#pygame.image.save(IMGSOURCE, ("imgfilter-out.png"))
#print(IMGSOURCE.get_at((639, 479)))
###
elif cmd=="-g3" or cmd=="--modegfx3":
arg=sys.argv[2]
arg=gfxargfind(arg)
pygame.display.init()
screensurf=pygame.display.set_mode((114, 81))
IMGSOURCE=pygame.image.load(arg)
IMGw=IMGSOURCE.get_width()
IMGh=IMGSOURCE.get_height()
if IMGw!=54 or IMGh!=38:
sys.exit("ERROR: Image not proper size! image MUST match mode G3 screen size! (54x38)")
HPIX=0
assmflename=arg
assmnamelst=assmflename.rsplit('.', 1)
tasmfile=(assmnamelst[0] + (".tasm"))
tasmout=open(tasmfile, "w")
tasmout.write("\n#autogenerated by SBTCVM MARK 2 GAT toolkit, from: \"" + arg + "\" \n")
tasmout.write("""setreg1|-------0-
IOwrite1|>dispmode
setreg1|>dispoff
IOwrite1|>dispoffset
setreg1|000000000
IOwrite1|>dispupdate
userwait
""")
chunkcnt=0
first=1
while HPIX!=IMGh:
WPIX=0
while WPIX!=IMGw:
COLLIST=IMGSOURCE.get_at((WPIX, HPIX))
Wtern=trunkto3(libbaltcalc.DECTOBT((WPIX - 13)))
Htern=trunkto3(libbaltcalc.DECTOBT((HPIX - 13)))
#print "foo"
#print COLLIST
preR=COLLIST[0]
preG=COLLIST[1]
preB=COLLIST[2]
preA=255
#print((preR, preG, preB, preA))
postR=dropshift(preR)
postG=dropshift(preG)
postB=dropshift(preB)
terR=codeshift(preR)
terG=codeshift(preG)
terB=codeshift(preB)
postA=dropshift(preA)
#print((postR, postG, postB, postA))
IMGSOURCE.set_at((WPIX, HPIX),(postR, postG, postB))
#tasmout.write("setcolorreg|000" + terR + terG + terB + "\n")
#tasmout.write("colorpixel|000" + Wtern + Htern + "\n")
if chunkcnt==0:
chunkcnt+=1
tasmout.write("null|" + terR + terG + terB)
elif chunkcnt==1:
chunkcnt+=1
tasmout.write(terR + terG + terB)
else:
chunkcnt=0
if first==1:
first=0
tasmout.write(terR + terG + terB + "|dispoff\n")
else:
tasmout.write(terR + terG + terB + "\n")
WPIX += 1
time.sleep(0.0001)
print ("line: " + str(HPIX) + " done")
screensurf.blit(IMGSOURCE, (0, 0))
pygame.display.update()
HPIX += 1
#tasmout.write("userwait")
print ("image: \"" + arg + "\" converted to: \"" + tasmfile + "\" for SBTCVM SBTGA mode G3 (full)")
#pygame.image.save(IMGSOURCE, ("imgfilter-out.png"))
#print(IMGSOURCE.get_at((639, 479)))
elif cmd=="-g4" or cmd=="--modegfx4":
arg=sys.argv[2]
arg=gfxargfind(arg)
pygame.display.init()
screensurf=pygame.display.set_mode((114, 81))
IMGSOURCE=pygame.image.load(arg)
IMGw=IMGSOURCE.get_width()
IMGh=IMGSOURCE.get_height()
if IMGw!=54 or IMGh!=38:
sys.exit("ERROR: Image not proper size! image MUST match mode G4 screen size! (54x38)")
HPIX=0
assmflename=arg
assmnamelst=assmflename.rsplit('.', 1)
tasmfile=(assmnamelst[0] + (".tasm"))
tasmout=open(tasmfile, "w")
tasmout.write("\n#autogenerated by SBTCVM MARK 2 GAT toolkit, from: \"" + arg + "\" \n")
tasmout.write("""setreg1|-------00
IOwrite1|>dispmode
setreg1|>dispoff
IOwrite1|>dispoffset
setreg1|000000000
IOwrite1|>dispupdate
userwait
""")
chunkcnt=0
first=1
while HPIX!=IMGh:
WPIX=0
while WPIX!=IMGw:
COLLIST=IMGSOURCE.get_at((WPIX, HPIX))
Wtern=trunkto3(libbaltcalc.DECTOBT((WPIX - 13)))
Htern=trunkto3(libbaltcalc.DECTOBT((HPIX - 13)))
#print "foo"
#print COLLIST
pre=COLLIST[1]
#print((preR, preG, preB, preA))
post=dropshift(pre)
ter=codeshift(pre)
#print((postR, postG, postB, postA))
IMGSOURCE.set_at((WPIX, HPIX),(post, post, post))
#tasmout.write("setcolorreg|000" + terR + terG + terB + "\n")
#tasmout.write("colorpixel|000" + Wtern + Htern + "\n")
if chunkcnt==0:
chunkcnt+=1
tasmout.write("null|" + ter)
elif chunkcnt<8:
chunkcnt+=1
tasmout.write(ter)
else:
chunkcnt=0
if first==1:
first=0
tasmout.write(ter + "|dispoff\n")
else:
tasmout.write(ter + "\n")
WPIX += 1
time.sleep(0.0001)
print ("line: " + str(HPIX) + " done")
screensurf.blit(IMGSOURCE, (0, 0))
pygame.display.update()
HPIX += 1
#tasmout.write("userwait")
print ("image: \"" + arg + "\" converted to: \"" + tasmfile + "\" for SBTCVM SBTGA mode G4 (full)")
#pygame.image.save(IMGSOURCE, ("imgfilter-out.png"))
#print(IMGSOURCE.get_at((639, 479)))
else:
print "see MK2-GAT.py -h for help."
print cmd