-
Notifications
You must be signed in to change notification settings - Fork 7
/
SBTCVM-asm2.py
executable file
·1016 lines (981 loc) · 32.4 KB
/
SBTCVM-asm2.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
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
import VMSYSTEM.libSBTCVM as libSBTCVM
import VMSYSTEM.libbaltcalc as libbaltcalc
import sys
import os
assmoverrun=19683
instcnt=0
txtblk=0
VMSYSROMS=os.path.join("VMSYSTEM", "ROMS")
critcomperr=0
compvers="v2.2.0"
outfile="assmout.trom"
#define IOmaps
IOmapread={"random": "--0------"}
IOmapwrite={}
#populate IOmaps with memory pointers
scratchmap={}
scratchstart="---------"
shortsccnt=1
scratchstop="---++++++"
IOgen=scratchstart
while IOgen!=scratchstop:
#scratchmap[("mem" + str(shortsccnt))] = IOgen
IOmapread[("mem" + str(shortsccnt))] = IOgen
IOmapwrite[("mem" + str(shortsccnt))] = IOgen
IOgen=libSBTCVM.trunkto6(libbaltcalc.btadd(IOgen, "+"))
shortsccnt += 1
#scratchmap[("mem" + str(shortsccnt))] = scratchstop
IOmapread[("mem" + str(shortsccnt))] = scratchstop
IOmapwrite[("mem" + str(shortsccnt))] = scratchstop
def getlinetern(line):
line=(line-9841)
tline=libSBTCVM.trunkto6(libbaltcalc.DECTOBT(line))
return tline
tracecomp=0
#used to write to the compiler log if the compiler is in tracelog mode
def complog(textis):
if tracecomp==1:
compilerlog.write(textis)
#class used by the goto refrence system
class gotoref:
def __init__(self, line, gtname):
self.line=line
self.tline=getlinetern(line)
self.gtname=gtname
#begin by reading command line arguments
try:
cmd=sys.argv[1]
except:
cmd=None
if "GLOBASMFLG" in globals():
cmd=GLOBASMFLG
if cmd=="-h" or cmd=="--help" or cmd=="help":
print '''This is SBTCVM-asm2.py, SBTCVM Mark 2's assembler.
commands:
SBTCVM-asm2.py -h (--help) (help): this text
SBTCVM-asm2.py -v (--version)
SBTCVM-asm2.py -a (--about): about SBTCVM-asm2.py
SBTCVM-asm2.py -c (--compile) [sourcefile]: build a tasm source into a trom
SBTCVM-asm2.py -t (--tracecompile) [sourcefile]: same as -c but logs the compiling process in detail in the CAP directory.
SBTCVM-asm2.py [sourcefile]: build a tasm source into a trom
'''
elif cmd=="-v" or cmd=="--version":
print ("SBTCVM Assember" + compvers)
elif cmd=="-a" or cmd=="--about":
print '''SBTCVM Assembler 2
''' + compvers + '''
(c)2016-2017 Thomas Leathers and Contributors
SBTCVM Assembler 2 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 Assembler 2 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 Assembler 2. If not, see <http://www.gnu.org/licenses/>
'''
elif cmd==None:
print "tip: use SBTCVM-asm2.py -h for help."
elif cmd=="-c" or cmd=="--compile" or cmd[0]!="-" or cmd=="-t" or cmd=="--tracecompile":
print("SBTCVM-asm " + compvers + " starting")
if "GLOBASMFLG" in globals():
arg=GLOBASMFLG
else:
if cmd[0]!="-":
arg=sys.argv[1]
else:
arg=sys.argv[2]
print arg
lowarg=arg.lower()
argisfile=0
argistasm=0
for extq in ["", ".tasm", ".TASM"]:
qarg=(arg + extq)
qlowarg=(lowarg + extq.lower())
print "searching for: \"" + qarg + "\"..."
argisfile
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 qlowarg.endswith(".tasm") and os.path.isfile(qarg):
print "tasm source found."
arg=qarg
argistasm=1
break
else:
print "Not valid."
argisfile=0
if argisfile==0 or argistasm==0:
#print "ERROR: file not found, or is not a tasm file STOP"
sys.exit("ERROR: SBTCVM assembler was unable to load the specified filename. STOP")
#generate a name for logs in case its needed
#logsub=arg.replace("/", "-")
#logsub=logsub.replace("~", "")
#logsub=logsub.split(".")
logsub=libSBTCVM.namecrunch(arg, "-tasm-comp.log")
#detect if command line options specify tracelog compile mode:
if cmd=="-t" or cmd=="--tracecompile":
tracecomp=1
compilerlog=open(os.path.join('CAP', logsub), "w")
else:
tracecomp=0
#arg=arg.replace("./", "")
#print arg
complog("starting up compiler...\n")
complog("TASM VERSION: SBTCVM-asm " + compvers + "\n")
complog("source: " + arg + "\n")
complog("---------\n\n")
#open 2 instances of source. one per pass.
sourcefile=open(arg, 'r')
sourcefileB=open(arg, 'r')
#open(arg, 'r') as sourcefile
gotoreflist=list()
print "preforming prescan & prep pass"
complog("preforming prescan & prep pass\n")
srcline=0
for linen in sourcefile:
srcline += 1
lined=linen
linen=linen.replace("\n", "")
linen=linen.replace(" ", "")
linenraw=linen
linen=(linen.split("#"))[0]
linelist=linen.split("|")
if (len(linelist))==2:
instword=(linelist[0])
instdat=(linelist[1])
else:
instword=(linelist[0])
instdat="000000000"
if instword=="textstop":
txtblk=0
complog("TEXTBLOCK END\n")
gtflag=1
if txtblk==1:
for f in lined:
instcnt += 1
elif instword=="textstart":
txtblk=1
complog("TEXTBLOCK START\n")
#raw class
elif instword=="romread1":
instcnt += 1
elif instword=="romread2":
instcnt += 1
elif instword=="IOread1":
instcnt += 1
elif instword=="IOread2":
instcnt += 1
elif instword=="IOwrite1":
instcnt += 1
elif instword=="IOwrite2":
instcnt += 1
elif instword=="regswap":
instcnt += 1
elif instword=="copy1to2":
instcnt += 1
elif instword=="copy2to1":
instcnt += 1
elif instword=="invert1":
instcnt += 1
elif instword=="invert2":
instcnt += 1
elif instword=="add":
instcnt += 1
elif instword=="subtract":
instcnt += 1
elif instword=="multiply":
instcnt += 1
elif instword=="divide":
instcnt += 1
elif instword=="setreg1":
instcnt += 1
elif instword=="setreg2":
instcnt += 1
elif instword=="setinst":
instcnt += 1
elif instword=="setdata":
instcnt += 1
#----jump in used opcodes----
#color drawing
elif instword=="continue":
instcnt += 1
elif instword=="colorpixel":
instcnt += 1
elif instword=="setcolorreg":
instcnt += 1
elif instword=="colorfill":
instcnt += 1
elif instword=="setcolorvect":
instcnt += 1
elif instword=="colorline":
instcnt += 1
elif instword=="colorrect":
instcnt += 1
#mono drawing
elif instword=="monopixel":
instcnt += 1
elif instword=="monofill":
instcnt += 1
elif instword=="setmonovect":
instcnt += 1
elif instword=="monoline":
instcnt += 1
elif instword=="monorect":
instcnt += 1
#----opcode --00-+ unused----
elif instword=="stop":
instcnt += 1
elif instword=="null":
instcnt += 1
elif instword=="gotodata":
instcnt += 1
elif instword=="gotoreg1":
instcnt += 1
elif instword=="gotodataif":
instcnt += 1
elif instword=="wait":
instcnt += 1
elif instword=="YNgoto":
instcnt += 1
elif instword=="userwait":
instcnt += 1
elif instword=="TTYclear":
instcnt += 1
#----gap in used opcodes----
elif instword=="gotoA":
instcnt += 1
autostpflg=1
elif instword=="gotoAif":
instcnt += 1
elif instword=="gotoB":
instcnt += 1
autostpflg=1
elif instword=="gotoBif":
instcnt += 1
elif instword=="gotoC":
instcnt += 1
elif instword=="gotoCif":
instcnt += 1
elif instword=="gotoD":
instcnt += 1
elif instword=="gotoDif":
instcnt += 1
elif instword=="gotoE":
instcnt += 1
elif instword=="gotoEif":
instcnt += 1
elif instword=="gotoF":
instcnt += 1
elif instword=="gotoFif":
instcnt += 1
#----gap in used opcodes----
elif instword=="dumpreg1":
instcnt += 1
elif instword=="dumpreg2":
instcnt += 1
elif instword=="TTYwrite":
instcnt += 1
elif instword=="buzzer":
instcnt += 1
elif instword=="setregset":
instcnt += 1
elif instword=="regset":
instcnt += 1
elif instword=="setkeyint":
instcnt += 1
elif instword=="keyint":
instcnt += 1
elif instword=="offsetlen":
instcnt += 1
elif instword=="clearkeyint":
instcnt += 1
elif instword=="gotoifgreater":
instcnt += 1
elif instword=="TTYbg":
instcnt += 2
elif instword=="TTYlinedraw":
instcnt += 2
elif instword=="TTYmode":
instcnt += 2
elif instword=="threadref":
instcnt += 1
elif instword=="threadstart":
instcnt += 1
elif instword=="threadstop":
instcnt += 1
elif instword=="threadkill":
instcnt += 1
else:
gtflag=0
if gtflag==1 and (txtblk==0 or linenraw=="textstart"):
complog("pass 1: srcline:" + str(srcline) + " instcnt:" + str(instcnt) + " inst:" + instword + " instdat:" + instdat + "\n")
elif gtflag==1 and txtblk==1:
complog("TEXTBLOCK: pass 1 : srcline:" + str(srcline) + " instcnt:" + str(instcnt) + " textline: \"" + linenraw + "\"\n")
if (len(linelist))==3 and gtflag==1 and txtblk==0 and instword[0]!="#":
if instword=="textstart":
instcnt += 1
gtox=gotoref((instcnt - 1), linelist[2])
gotoreflist.extend([gtox])
print ("found gotoref: \"" + linelist[2] + "\", at instruction:\"" + str((instcnt - 1)) + "\", Source line:\"" + str(srcline) + "\"")
complog("found gotoref: \"" + linelist[2] + "\", at instruction:\"" + str((instcnt - 1)) + "\", Source line:\"" + str(srcline) + "\"\n")
if instword=="textstart":
instcnt -= 1
#print gotoreflist
instcnt=0
firstloop=1
srcline=0
for linen in sourcefileB:
srcline += 1
if firstloop==1:
print "preforming compileloop startup..."
complog("\n\npreforming compileloop startup...\n")
assmflename=arg
complog("source file: \"" + assmflename + "\"\n")
assmnamelst=assmflename.rsplit('.', 1)
outfile=(assmnamelst[0] + (".trom"))
complog("output file: \"" + outfile + "\"\n")
outn = open(outfile, 'w')
firstloop=0
print "done. begin compile."
complog("done. begin compile.\n")
lined=linen
linen=linen.replace("\n", "")
linen=linen.replace(" ", "")
linenraw=linen
linen=(linen.split("#"))[0]
linelist=linen.split("|")
autostpflg=0
gtflag=1
if (len(linelist))==2 or (len(linelist))==3:
instword=(linelist[0])
instdat=(linelist[1])
else:
instword=(linelist[0])
instdat="000000000"
if instdat=="":
instdat="000000000"
print "NOTICE: data portion at source line:\"" + str(srcline) + "\" blank, defaulting to ground..."
complog("NOTICE: data portion at source line:\"" + str(srcline) + "\" blank, defaulting to ground...\n")
#if len(instdat)==6 and instdat[0]!=">" and instdat[0]!=":":
# print "Mark 1.x legacy NOTICE: instruction \"" + instword + "\" at \"" + str(srcline) + "\" did not have 9 trits data. it has been padded far from radix. please pad any legacy instructions manually."
# complog("Mark 1.x legacy NOTICE: instruction \"" + instword + "\" at \"" + str(srcline) + "\" did not have 9 trits data. it has been padded far from radix. please pad any legacy instructions manually.\n")
# instdat=("000" + instdat)
if instword=="textstop":
txtblk=0
complog("TEXTBLOCK END\n")
if txtblk==1:
for f in lined:
texchout=libSBTCVM.charlook(f)
texchout=("000" + texchout)
outn.write("--+++0" + (texchout) + "\n")
instcnt += 1
elif instword=="textstart":
txtblk=1
complog("TEXTBLOCK START\n")
#raw class
elif instword=="romread1":
instgpe=instdat.split(">")
if (len(instgpe))==1:
outn.write("------" + instdat + "\n")#
instcnt += 1
autostpflg=1
else:
gtpoint=instgpe[1]
gtmatch=0
instcnt += 1
for fx in gotoreflist:
if fx.gtname==gtpoint:
outn.write("------" + fx.tline + "\n")
gtmatch=1
if gtmatch==0:
#print "ERROR: pointer: \"" + gtpoint + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP"
complog("ERROR: pointer: \"" + gtpoint + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP \n")
sys.exit("ERROR: pointer: \"" + gtpoint + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP")
elif instword=="romread2":
instgpe=instdat.split(">")
if (len(instgpe))==1:
outn.write("-----0" + instdat + "\n")#
instcnt += 1
autostpflg=1
else:
gtpoint=instgpe[1]
gtmatch=0
instcnt += 1
for fx in gotoreflist:
if fx.gtname==gtpoint:
outn.write("-----0" + fx.tline + "\n")
gtmatch=1
if gtmatch==0:
#print "ERROR: pointer: \"" + gtpoint + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP"
complog("ERROR: pointer: \"" + gtpoint + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP \n")
sys.exit("ERROR: pointer: \"" + gtpoint + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP")
elif instword=="IOread1":
instgpe=instdat.split(">")
if (len(instgpe))==1:
outn.write("-----+" + instdat + "\n")#
instcnt += 1
autostpflg=1
else:
try:
IOpnk=IOmapread[instgpe[1]]
outn.write("-----+" + IOpnk + "\n")
except KeyError:
#print "ERROR: IO read shortcut: \"" + instgpe[1] + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP"
complog("ERROR: IO read shortcut: \"" + instgpe[1] + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP \n")
sys.exit("ERROR: IO read shortcut: \"" + instgpe[1] + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP")
instcnt += 1
#outn.write("-----+" + instdat + "\n")
#instcnt += 1
elif instword=="IOread2":
#outn.write("----0-" + instdat + "\n")
instgpe=instdat.split(">")
if (len(instgpe))==1:
outn.write("----0-" + instdat + "\n")#
instcnt += 1
autostpflg=1
else:
try:
IOpnk=IOmapread[instgpe[1]]
outn.write("----0-" + IOpnk + "\n")
except KeyError:
#print "ERROR: IO read shortcut: \"" + instgpe[1] + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP"
complog("ERROR: IO read shortcut: \"" + instgpe[1] + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP \n")
sys.exit("ERROR: IO read shortcut: \"" + instgpe[1] + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP")
instcnt += 1
#instcnt += 1
elif instword=="IOwrite1":
instgpe=instdat.split(">")
if (len(instgpe))==1:
outn.write("----00" + instdat + "\n")#
instcnt += 1
autostpflg=1
else:
try:
IOpnk=IOmapwrite[instgpe[1]]
outn.write("----00" + IOpnk + "\n")
except KeyError:
#print "ERROR: IO write shortcut: \"" + instgpe[1] + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP"
complog("ERROR: IO write shortcut: \"" + instgpe[1] + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP \n")
sys.exit("ERROR: IO write shortcut: \"" + instgpe[1] + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP")
instcnt += 1
#instcnt += 1
elif instword=="IOwrite2":
#outn.write("----0+" + instdat + "\n")
#instcnt += 1
instgpe=instdat.split(">")
if (len(instgpe))==1:
outn.write("----0+" + instdat + "\n")#
instcnt += 1
autostpflg=1
else:
try:
IOpnk=IOmapwrite[instgpe[1]]
outn.write("----0+" + IOpnk + "\n")
except KeyError:
#print "ERROR: IO write shortcut: \"" + instgpe[1] + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP"
complog("ERROR: IO write shortcut: \"" + instgpe[1] + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP \n")
sys.exit("ERROR: IO write shortcut: \"" + instgpe[1] + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP")
instcnt += 1
elif instword=="regswap":
outn.write("----+-" + instdat + "\n")
instcnt += 1
elif instword=="copy1to2":
outn.write("----+0" + instdat + "\n")
instcnt += 1
elif instword=="copy2to1":
outn.write("----++" + instdat + "\n")
instcnt += 1
elif instword=="invert1":
outn.write("---0--" + instdat + "\n")
instcnt += 1
elif instword=="invert2":
outn.write("---0-0" + instdat + "\n")
instcnt += 1
elif instword=="add":
outn.write("---0-+" + instdat + "\n")
instcnt += 1
elif instword=="subtract":
outn.write("---00-" + instdat + "\n")
instcnt += 1
elif instword=="multiply":
outn.write("---000" + instdat + "\n")
instcnt += 1
elif instword=="divide":
outn.write("---00+" + instdat + "\n")
instcnt += 1
elif instword=="setreg1":
outn.write("---0+-" + instdat + "\n")
instcnt += 1
elif instword=="setreg2":
outn.write("---0+0" + instdat + "\n")
instcnt += 1
elif instword=="setinst":
instgpe=instdat.split(">")
if (len(instgpe))==1:
outn.write("---0++" + instdat + "\n")#
instcnt += 1
autostpflg=1
else:
gtpoint=instgpe[1]
gtmatch=0
instcnt += 1
for fx in gotoreflist:
if fx.gtname==gtpoint:
outn.write("---0++" + fx.tline + "\n")
gtmatch=1
if gtmatch==0:
#print "ERROR: pointer: \"" + gtpoint + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP"
complog("ERROR: pointer: \"" + gtpoint + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP \n")
sys.exit("ERROR: pointer: \"" + gtpoint + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP")
elif instword=="setdata":
instgpe=instdat.split(">")
if (len(instgpe))==1:
outn.write("---+--" + instdat + "\n")#
instcnt += 1
autostpflg=1
else:
gtpoint=instgpe[1]
gtmatch=0
instcnt += 1
for fx in gotoreflist:
if fx.gtname==gtpoint:
outn.write("---+--" + fx.tline + "\n")
gtmatch=1
if gtmatch==0:
#print "ERROR: pointer: \"" + gtpoint + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP"
complog("ERROR: pointer: \"" + gtpoint + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP \n")
sys.exit("ERROR: pointer: \"" + gtpoint + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP")
#----jump in used opcodes----
elif instword=="continue":
outn.write("---+++" + instdat + "\n")
instcnt += 1
#color drawing
elif instword=="colorpixel":
outn.write("--0---" + instdat + "\n")
instcnt += 1
elif instword=="setcolorreg":
instclst=instdat.split(',')
if len(instclst)==3:
vxR=libSBTCVM.codeshift(instclst[0])
vxB=libSBTCVM.codeshift(instclst[1])
vxG=libSBTCVM.codeshift(instclst[2])
outn.write("--0--0" + ("000" + vxR + vxB + vxG) + "\n")
else:
outn.write("--0--0" + instdat + "\n")
instcnt += 1
elif instword=="colorfill":
instclst=instdat.split(',')
if len(instclst)==3:
vxR=libSBTCVM.codeshift(instclst[0])
vxB=libSBTCVM.codeshift(instclst[1])
vxG=libSBTCVM.codeshift(instclst[2])
outn.write("--0--+" + ("000" + vxR + vxB + vxG) + "\n")
else:
outn.write("--0--+" + instdat + "\n")
instcnt += 1
elif instword=="setcolorvect":
outn.write("--0-0-" + instdat + "\n")
instcnt += 1
elif instword=="colorline":
outn.write("--0-00" + instdat + "\n")
instcnt += 1
elif instword=="colorrect":
outn.write("--0-0+" + instdat + "\n")
instcnt += 1
#mono drawing
elif instword=="monopixel":
outn.write("--0-+-" + instdat + "\n")
instcnt += 1
elif instword=="monofill":
outn.write("--0-+0" + instdat + "\n")
instcnt += 1
elif instword=="setmonovect":
outn.write("--0-++" + instdat + "\n")
instcnt += 1
elif instword=="monoline":
outn.write("--00--" + instdat + "\n")
instcnt += 1
elif instword=="monorect":
outn.write("--00-0" + instdat + "\n")
instcnt += 1
#----opcode --00-+ unused----
elif instword=="stop":
outn.write("--000-" + instdat + "\n")
instcnt += 1
autostpflg=1
elif instword=="null":
outn.write("000000" + instdat + "\n")
instcnt += 1
elif instword=="gotodata":
instgpe=instdat.split(">")
autostpflg=1
if (len(instgpe))==1:
outn.write("--000+" + instdat + "\n")#
instcnt += 1
else:
gtpoint=instgpe[1]
gtmatch=0
instcnt += 1
for fx in gotoreflist:
if fx.gtname==gtpoint:
outn.write("--000+" + fx.tline + "\n")
gtmatch=1
if gtmatch==0:
#print "ERROR: pointer: \"" + gtpoint + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP"
complog("ERROR: pointer: \"" + gtpoint + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP \n")
sys.exit("ERROR: pointer: \"" + gtpoint + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP")
elif instword=="gotoreg1":
outn.write("--00+-" + instdat + "\n")
instcnt += 1
autostpflg=1
elif instword=="gotodataif":
instgpe=instdat.split(">")
autostpflg=1
if (len(instgpe))==1:
outn.write("--00+0" + instdat + "\n")#
instcnt += 1
else:
gtpoint=instgpe[1]
gtmatch=0
instcnt += 1
for fx in gotoreflist:
if fx.gtname==gtpoint:
outn.write("--00+0" + fx.tline + "\n")
gtmatch=1
if gtmatch==0:
#print "ERROR: pointer: \"" + gtpoint + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP"
complog("ERROR: pointer: \"" + gtpoint + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP \n")
sys.exit("ERROR: pointer: \"" + gtpoint + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP")
elif instword=="gotoifgreater":
instgpe=instdat.split(">")
autostpflg=1
if (len(instgpe))==1:
outn.write("--0+0-" + instdat + "\n")#
instcnt += 1
else:
gtpoint=instgpe[1]
gtmatch=0
instcnt += 1
for fx in gotoreflist:
if fx.gtname==gtpoint:
outn.write("--0+0-" + fx.tline + "\n")
gtmatch=1
if gtmatch==0:
#print "ERROR: pointer: \"" + gtpoint + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP"
complog("ERROR: pointer: \"" + gtpoint + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP \n")
sys.exit("ERROR: pointer: \"" + gtpoint + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP")
#instcnt += 1
elif instword=="wait":
outn.write("--00++" + instdat + "\n")
instcnt += 1
elif instword=="YNgoto":
instgpe=instdat.split(">")
if (len(instgpe))==1:
outn.write("--0+--" + instdat + "\n")#
instcnt += 1
autostpflg=1
else:
gtpoint=instgpe[1]
gtmatch=0
instcnt += 1
for fx in gotoreflist:
if fx.gtname==gtpoint:
outn.write("--0+--" + fx.tline + "\n")
gtmatch=1
if gtmatch==0:
#print "ERROR: pointer: \"" + gtpoint + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP"
complog("ERROR: pointer: \"" + gtpoint + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP \n")
sys.exit("ERROR: pointer: \"" + gtpoint + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP")
elif instword=="userwait":
outn.write("--0+-0" + instdat + "\n")
instcnt += 1
elif instword=="TTYclear":
outn.write("--0+-+" + instdat + "\n")
instcnt += 1
#----gap in used opcodes----
elif instword=="gotoA":
outn.write("--+---" + instdat + "\n")
instcnt += 1
autostpflg=1
elif instword=="gotoAif":
outn.write("--+--0" + instdat + "\n")
instcnt += 1
elif instword=="gotoB":
outn.write("--+--+" + instdat + "\n")
instcnt += 1
autostpflg=1
elif instword=="gotoBif":
outn.write("--+-0-" + instdat + "\n")
instcnt += 1
elif instword=="gotoC":
outn.write("--+-00" + instdat + "\n")
instcnt += 1
autostpflg=1
elif instword=="gotoCif":
outn.write("--+-0+" + instdat + "\n")
instcnt += 1
elif instword=="gotoD":
outn.write("--+-+-" + instdat + "\n")
instcnt += 1
autostpflg=1
elif instword=="gotoDif":
outn.write("--+-+0" + instdat + "\n")
instcnt += 1
elif instword=="gotoE":
outn.write("--+-++" + instdat + "\n")
instcnt += 1
autostpflg=1
elif instword=="gotoEif":
outn.write("--+0--" + instdat + "\n")
instcnt += 1
elif instword=="gotoF":
outn.write("--+0-0" + instdat + "\n")
instcnt += 1
autostpflg=1
elif instword=="gotoFif":
outn.write("--+0-+" + instdat + "\n")
instcnt += 1
#----gap in used opcodes----
elif instword=="dumpreg1":
outn.write("--++0+" + instdat + "\n")
instcnt += 1
elif instword=="dumpreg2":
outn.write("--+++-" + instdat + "\n")
instcnt += 1
elif instword=="TTYwrite":
#outn.write("--+++0" + instdat + "\n")
#instcnt += 1
instgpe=instdat.split(":")
if (len(instgpe))==1:
outn.write("--+++0" + instdat + "\n")
instcnt += 1
else:
if instgpe[1]=="enter":
ksc=" "
elif instgpe[1]=="space":
ksc="\n"
else:
ksc=(instgpe[1])[0]
outn.write("--+++0" + "000" + (libSBTCVM.charlook(ksc)) + "\n")
instcnt += 1
elif instword=="buzzer":
outn.write("--++++" + instdat + "\n")
instcnt += 1
elif instword=="setregset":
outn.write("-0-000" + instdat + "\n")
instcnt += 1
elif instword=="regset":
outn.write("-0-00+" + instdat + "\n")
instcnt += 1
elif instword=="setkeyint":
instgpe=instdat.split(":")
if (len(instgpe))==1:
outn.write("-0-+++" + instdat + "\n")
instcnt += 1
else:
if instgpe[1]=="space":
ksc=" "
elif instgpe[1]=="enter":
ksc="\n"
else:
ksc=(instgpe[1])[0]
outn.write("-0-+++" + "00000" + (libSBTCVM.texttoscan[ksc]) + "\n")
instcnt += 1
elif instword=="keyint":
instgpe=instdat.split(">")
if (len(instgpe))==1:
outn.write("-00---" + instdat + "\n")#
instcnt += 1
else:
gtpoint=instgpe[1]
gtmatch=0
instcnt += 1
for fx in gotoreflist:
if fx.gtname==gtpoint:
outn.write("-00---" + fx.tline + "\n")
gtmatch=1
if gtmatch==0:
#print "ERROR: pointer: \"" + gtpoint + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP"
complog("ERROR: pointer: \"" + gtpoint + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP \n")
sys.exit("ERROR: pointer: \"" + gtpoint + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP")
elif instword=="clearkeyint":
outn.write("-00--0" + instdat + "\n")
instcnt += 1
elif instword=="offsetlen":
instclst=instdat.split(",")
if len(instclst)==3:
tritgnd=instclst[0]
tritoffset=int(instclst[1])
tritlen=int(instclst[2])
if tritgnd=="on":
tritgndpar="+"
else:
tritgndpar="0"
if tritoffset==0:
tritoffsetpar="--"
elif tritoffset==1:
tritoffsetpar="-0"
elif tritoffset==2:
tritoffsetpar="-+"
elif tritoffset==3:
tritoffsetpar="0-"
elif tritoffset==4:
tritoffsetpar="00"
elif tritoffset==5:
tritoffsetpar="0+"
elif tritoffset==6:
tritoffsetpar="+-"
elif tritoffset==7:
tritoffsetpar="+0"
elif tritoffset==8:
tritoffsetpar="++"
else:
tritoffsetpar="--"
if tritlen==1:
tritlenpar="--"
elif tritlen==2:
tritlenpar="-0"
elif tritlen==3:
tritlenpar="-+"
elif tritlen==4:
tritlenpar="0-"
elif tritlen==5:
tritlenpar="00"
elif tritlen==6:
tritlenpar="0+"
elif tritlen==7:
tritlenpar="+-"
elif tritlen==8:
tritlenpar="+0"
elif tritlen==9:
tritlenpar="++"
else:
tritlenpar="++"
outn.write("-0-++0" + "0000" + tritgndpar + tritoffsetpar + tritlenpar + "\n")
else:
outn.write("-0-++0" + instdat + "\n")
instcnt += 1
#special regset shortcut commands
elif instword=="TTYbg":
instclst=instdat.split(",")
if len(instclst)==3:
vxR=libSBTCVM.codeshift(instclst[0])
vxB=libSBTCVM.codeshift(instclst[1])
vxG=libSBTCVM.codeshift(instclst[2])
outn.write("-0-000" + "---------" + "\n")
outn.write("-0-00+" + ("000" + vxR + vxB + vxG) + "\n")
else:
outn.write("-0-000" + "---------" + "\n")
outn.write("-0-00+" + instdat + "\n")
instcnt += 2
elif instword=="TTYlinedraw":
if instdat=="on":
outn.write("-0-000" + "--------0" + "\n")
outn.write("-0-00+" + "00000000+" + "\n")
elif instdat=="off":
outn.write("-0-000" + "--------0" + "\n")
outn.write("-0-00+" + "000000000" + "\n")
else:
outn.write("-0-000" + "--------0" + "\n")
outn.write("-0-00+" + "00000000+" + "\n")
instcnt += 2
elif instword=="TTYmode":
if instdat=="27":
outn.write("-0-000" + "--------+" + "\n")
outn.write("-0-00+" + "00000000+" + "\n")
elif instdat=="54":
outn.write("-0-000" + "--------+" + "\n")
outn.write("-0-00+" + "000000000" + "\n")
else:
outn.write("-0-000" + "--------+" + "\n")
outn.write("-0-00+" + "000000000" + "\n")
instcnt += 2
elif instword=="threadref":
instcnt += 1
if len(instdat)==2:
outn.write("--+00-" + "0000000" + instdat + "\n")
else:
outn.write("--+00-" + instdat + "\n")
elif instword=="threadstart":
instgpe=instdat.split(">")
if (len(instgpe))==1:
outn.write("--+000" + instdat + "\n")#
instcnt += 1
autostpflg=1
else:
gtpoint=instgpe[1]
gtmatch=0
instcnt += 1
for fx in gotoreflist:
if fx.gtname==gtpoint:
outn.write("--+000" + fx.tline + "\n")
gtmatch=1
if gtmatch==0:
#print "ERROR: pointer: \"" + gtpoint + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP"
complog("ERROR: pointer: \"" + gtpoint + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP \n")
sys.exit("ERROR: pointer: \"" + gtpoint + "\" Pointed at by: \"" + instword + "\" At line: \"" + str(srcline) + "\", not found. STOP")
elif instword=="threadstop":
instcnt += 1
outn.write("--+00+" + instdat + "\n")
elif instword=="threadkill":
instcnt += 1
outn.write("--+0+-" + instdat + "\n")
else:
gtflag=0
if gtflag==1 and (txtblk==0 or linenraw=="textstart"):
complog("pass 2: srcline:" + str(srcline) + " instcnt:" + str(instcnt) + " inst:" + instword + " instdat:" + instdat + "\n")
elif gtflag==1 and txtblk==1:
complog("TEXTBLOCK: pass 2 : srcline:" + str(srcline) + " instcnt:" + str(instcnt) + " textline: \"" + linenraw + "\"\n")
if instcnt>assmoverrun:
#print("ERROR!: assembler has exceded rom size limit of 19683!")
complog("ERROR!: assembler has exceded rom size limit of 19683! \n")
sys.exit("ERROR!: assembler has exceded rom size limit of 19683!")
if txtblk==1:
print "WARNING: unclosed Text block!"
complog("WARNING: unclosed Text block!\n")
if instcnt==0:
#print "ERROR: No instructions found. nothing to compile."
complog("ERROR: No instructions found. nothing to compile. /n")
sys.exit("ERROR: No instructions found. nothing to compile.")
if autostpflg==0 and instcnt<19683:
print "NOTICE: no explicit goto or stop instruction at end of program. SBTCVM-asm will add a stop automatically."
complog("NOTICE: no explicit goto or stop instruction at end of program. SBTCVM-asm will add a stop automatically.\n")
outn.write("--000-" + "000000000" + "\n")
instcnt += 1
instpad=instcnt