forked from SBTCVM/SBTCVM-Mark-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SBTCVM_MK2.py
executable file
·2085 lines (1963 loc) · 59.2 KB
/
SBTCVM_MK2.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.libtrom as libtrom
import pygame
from pygame.locals import *
import time
import os
import VMSYSTEM.libSBTCVM as libSBTCVM
import VMSYSTEM.libbaltcalc as libbaltcalc
import VMSYSTEM.libvmui as vmui
import sys
import VMSYSTEM.libvmconf as libvmconf
from random import randint
pygame.display.init()
print "SBTCVM Mark 2 Starting up..."
#SBTCVM Mark 2
#Simple Balanced Ternary Computer Virtual Machine
#
#v2.0.2
#
# Copyright (c) 2016-2017 Thomas Leathers and Contributors
#
# SBTCVM Mark 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 Mark 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 Mark 2. If not, see <http://www.gnu.org/licenses/>
#thread data storage class
#used to store thread-specific data in BTSTACK dictionary when thread is inactive.
class BTTHREAD:
def __init__(self, qxtactg, EXECADDRg, REG1g, REG2g, contaddrg, EXECADDRrawg, regsetpointg, TTYBGCOLREGg, TTYBGCOLg, colvectorregg, monovectorregg, colorregg, tritloadleng, tritoffsetg, tritdestgndg, threadrefg, ROMFILEg, ROMLAMPFLGg, mempoint):
self.qxtact=qxtactg
self.EXECADDR=EXECADDRg
self.REG1=REG1g
self.REG2=REG2g
self.contaddr=contaddrg
self.EXECADDRraw=EXECADDRrawg
self.regsetpoint=regsetpointg
self.TTYBGCOLREG=TTYBGCOLREGg
self.TTYBGCOL=TTYBGCOLg
self.colvectorreg=colvectorregg
self.monovectorreg=monovectorregg
self.colorreg=colorregg
self.tritloadlen=tritloadleng
self.tritoffset=tritoffsetg
self.tritdestgnd=tritdestgndg
self.threadref=threadrefg
self.ROMFILE=ROMFILEg
self.ROMLAMPFLG=ROMLAMPFLGg
self.mempoint=mempoint
#ROMFILE=TROMA
#ROMLAMPFLG="A"
windowicon=pygame.image.load(os.path.join(os.path.join('VMSYSTEM', 'GFX'), 'icon64.png'))
pygame.display.set_icon(windowicon)
screensurf=pygame.display.set_mode((800, 600))
#
vmbg=pygame.image.load(os.path.join(os.path.join('VMSYSTEM', 'GFX'), 'VMBG.png')).convert()
screensurf.blit(vmbg, (0, 0))
#init in non-kiosk mode for now, SBTCVM will re-init once it knows the kioskmode state.
vmui.initui(screensurf, 0)
vmui.dummyreadouts()
pygame.display.update()
libSBTCVM.glyphoptim(screensurf)
pygame.display.set_caption("SBTCVM Mark 2", "SBTCVM Mark 2")
pygame.font.init()
simplefont = pygame.font.SysFont(None, 16)
#used for smaller data displays (inst. data etc.)
#smldispfont = pygame.font.SysFont(None, 16)
smldispfont = pygame.font.Font(os.path.join("VMSYSTEM", "SBTCVMreadout.ttf"), 16)
#used in larger data displays (register displays, etc.)
#lgdispfont = pygame.font.SysFont(None, 20)
lgdispfont = pygame.font.Font(os.path.join("VMSYSTEM", "SBTCVMreadout.ttf"), 16)
pixcnt1=40
pixjmp=14
USRYN=0
USRWAIT=0
keyintreg="0000"
#ttyfont = pygame.font.SysFont("Mono", 10)
#ttyfontB =pygame.font.SysFont("Mono", 18)
#graphics:
#background pixmap
#indicator lamps
#GREEN
LEDGREENON=pygame.image.load(os.path.join(os.path.join('VMSYSTEM', 'GFX'), 'LAMP-GREEN.png')).convert()
LEDGREENOFF=pygame.image.load(os.path.join(os.path.join('VMSYSTEM', 'GFX'), 'LAMP-GREEN-OFF.png')).convert()
#CPU
CPULEDACT=pygame.image.load(os.path.join(os.path.join('VMSYSTEM', 'GFX'), 'LAMP-BLUE.png')).convert()
CPULEDSTANDBY=pygame.image.load(os.path.join(os.path.join('VMSYSTEM', 'GFX'), 'LAMP-ORANGE.png')).convert()
COLORDISP=pygame.Surface((27, 27)).convert()
MONODISP=pygame.Surface((9, 9)).convert()
COLORDISP.fill((127, 127, 127))
MONODISP.fill((127, 127, 127))
#this list is what is displayed on the TTY on VM boot.
#the header text is so far in this list so it appears correct in 27 line mode
abt=["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "SBTCVM", "Mark 2", "v2.0.2", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "ready", ""]
abtpref=["This is different", "Mark 2", "v2.0.0", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "ready"]
abtclear=["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]
#abt54clear=["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]
#ttysize:
#0=72x54 (9x9 chars)
#1=72x27 (9x18 chars)
TTYMODE=0
TTYSIZE=1
mixrate=int(libvmconf.getconf("audio", "mixrate"))
pygame.mixer.init(frequency=mixrate , size=-16)
extradraw=0
wavsp=libSBTCVM.mk1buzz("0-----")
snf=pygame.mixer.Sound(wavsp)
snf.play()
#config defaults
TROMA="intro.trom"
#these are dud roms full of soft stops
TROMB=("DEFAULT.TROM")
TROMC=("DEFAULT.TROM")
TROMD=("DEFAULT.TROM")
TROME=("DEFAULT.TROM")
TROMF=("DEFAULT.TROM")
CPUWAIT=(0.0005)
stepbystep=0
DEFAULTSTREG="intro.streg"
tuibig=1
logromexit=0
logIOexit=0
vmexeclogflg=0
ttystyle=0
fskip=1
#set this to 1 as SBTCVM now runs too fast with default setting for these to be useful in normal execution.
#user can overide this in USERBOOT.CFG and toggle it using F4 key.
disablereadouts=1
CPUWAIT=float(libvmconf.getconf("cpu", "cpuwait"))
stepbystep=int(libvmconf.getconf("cpu", "stepbystep"))
vmexeclogflg=int(libvmconf.getconf("log", "vmexec"))
logromexit=int(libvmconf.getconf("log", "romexit"))
logIOexit=int(libvmconf.getconf("log", "ioexit"))
disablereadouts=int(libvmconf.getconf("video", "disablereadouts"))
fskip=int(libvmconf.getconf("video", "fskip"))
ttystyle=int(libvmconf.getconf("video", "ttystyle"))
DEFAULTSTREG=libvmconf.getconf("bootup", "DEFAULTSTREG")
fskipcnt=fskip
def vmexeclog(texttolog):
if vmexeclogflg==1:
vmexlogf.write(texttolog + "\n")
#vmexeclog("SYSTEM STARTUP. EXECUTION LOG ENABLED.")
key1=0
key2=0
key3=0
key4=0
key5=0
key6=0
key7=0
key8=0
key9=0
key0=0
keypos=0
keyhyp=0
keyq=0
keyw=0
keye=0
keyr=0
keyt=0
keyy=0
keyu=0
keyi=0
keyo=0
keyp=0
keya=0
keysx=0
keyd=0
keyf=0
keyg=0
keyh=0
keyj=0
keyk=0
keyl=0
keyz=0
keyx=0
keyc=0
keyv=0
keyb=0
keyn=0
keym=0
keyspace=0
keyret=0
btstopthread=0
TTYrenderflg="0"
if 'GLOBKIOSK' in globals():
print "RUNNING IN KIOSK MODE."
KIOSKMODE=GLOBKIOSK
else:
KIOSKMODE=0
stepcont=0
#initalize VMUI system
vmui.initui(screensurf, KIOSKMODE)
if 'GLOBRUNFLG' in globals():
TROMA=GLOBRUNFLG
libtrom.redefA(TROMA)
runtype=0
LOGBASE=TROMA
print ("GLOBRUNFLG found... \n running trom: \"" + TROMA + "\" as TROMA")
elif 'GLOBSTREG' in globals():
streg_subtitle="Unnamed"
#scstreg=open(GLOBSTREG, 'r')
ncstreg=libSBTCVM.stregload(GLOBSTREG)
scstreg=open(ncstreg, 'r')
exstreg=compile(scstreg.read(), ncstreg, 'exec')
exec(exstreg)
scstreg.close()
print ("streg program title:" + streg_subtitle)
libtrom.redefA(TROMA)
libtrom.redefB(TROMB)
libtrom.redefC(TROMC)
libtrom.redefD(TROMD)
libtrom.redefE(TROME)
libtrom.redefF(TROMF)
runtype=1
LOGBASE=GLOBSTREG
pygame.display.set_caption("SBTCVM Mark 2 | " + streg_subtitle, "SBTCVM Mark 2 | " + streg_subtitle)
print ("GLOBSTREG found... \n Starting SBTCVM with setup in streg file: \"" + GLOBSTREG + "\"")
else:
streg_subtitle="Unnamed"
#scstreg=open(DEFAULTSTREG, 'r')
ncstreg=libSBTCVM.stregload(DEFAULTSTREG)
scstreg=open(ncstreg, 'r')
exstreg=compile(scstreg.read(), ncstreg, 'exec')
exec(exstreg)
print ("streg program title:" + streg_subtitle)
libtrom.redefA(TROMA)
libtrom.redefB(TROMA)
libtrom.redefC(TROMA)
libtrom.redefD(TROMA)
libtrom.redefE(TROMA)
libtrom.redefF(TROMA)
runtype=1
LOGBASE=DEFAULTSTREG
pygame.display.set_caption("SBTCVM Mark 2 | " + streg_subtitle, "SBTCVM Mark 2 | " + streg_subtitle)
print ("nither GLOBSTREG or GLOBRUNFLG have been found... \nStarting SBTCVM with setup in default streg file: \"" + DEFAULTSTREG + "\"")
if vmexeclogflg==1:
vmexlogf=open(os.path.join("CAP", libSBTCVM.namecrunch(LOGBASE, "-vmexeclog.log")), "w")
if 'GLOBLOGEXEC' in globals():
if GLOBLOGEXEC==1:
vmexeclogflg=1
vmexlogf=open(os.path.join("CAP", libSBTCVM.namecrunch(LOGBASE, "-vmexeclog.log")), "w")
if 'GLOBOPSEC' in globals():
if GLOBOPSEC==1:
trackopsec=1
else:
trackopsec=0
else:
trackopsec=0
#tritlength defaults
tritloadlen=9
tritoffset=0
tritdestgnd=0
def tritlen(srcdata, destdata):
#just return srcdata if tritloadlen=9 and tritoffset=0
if tritdestgnd==1:
destdata="000000000"
if tritloadlen==9 and tritoffset==0:
#print srcdata
return (srcdata)
destdict={}
destcnt=0
tritstart=(8 - tritoffset)
tritstop=(tritstart - tritloadlen)
#print tritstop
tritstack=1
iterlist=[0, 1, 2, 3, 4, 5, 6, 7, 8]
#parse destination data into a dict
for f in destdata:
destdict[destcnt]=f
destcnt += 1
#modify destination dict
for f in iterlist:
#print tritstart
destdict[tritstart]=srcdata[tritstart]
tritstart -= 1
tritstack += 1
if tritstart==tritstop or tritstart==-1:
break
#print destdict
destdataout=""
#parse destination dict back into string and return result.
for f in iterlist:
destdataout=(destdataout + destdict[f])
#print destdataout
return destdataout
#def stactdebug1():
if 'GLOBKIOSK' in globals():
if KIOSKMODE==1:
disablereadouts=0
ttystyle=0
print "Kiosk mode active... enabling readouts and TTY mode 0..."
TTYBGCOL=libSBTCVM.colorfind("------")
TTYBGCOLREG="------"
colvectorreg="000000"
monovectorreg="000000"
if stepbystep==1:
STEPLED=LEDGREENON
else:
STEPLED=LEDGREENOFF
#keep unused events out of queue
pygame.event.set_allowed([QUIT, KEYDOWN, KEYUP])
libSBTCVMsurf=pygame.Surface((648, 486)).convert()
libSBTCVMsurf.fill(TTYBGCOL)
libSBTCVM.glyphoptim(libSBTCVMsurf)
#RAMBANK startup begin
RAMbank = {}
#calmlst = open("ORDEREDLIST6.txt")
#screensurf.fill((0,127,255))
#build IObus dictionary.
IOdumplist=list()
IOgen="---------"
RAMbank["---------"] = "000000000"
#IOdumplist.extend([IOgen])
while IOgen!="+++++++++":
IOdumplist.extend([IOgen])
IOgen=libSBTCVM.trunkto6(libbaltcalc.btadd(IOgen, "+"))
RAMbank[IOgen] = "000000000"
RAMbank["+++++++++"] = "000000000"
IOdumplist.extend([IOgen])
#set Random integer port with an inital random integer
RAMbank["--0------"]=libSBTCVM.trunkto6(libbaltcalc.DECTOBT(randint(-9841,9841)))
ttyredraw=1
#IO read only list. IO addresses in this list are treated as read only. for example:
#the random integer port is read only.
IOreadonly=["--0------"]
MONODISPBIG=pygame.transform.scale(MONODISP, (144, 144))
COLORDISPBIG=pygame.transform.scale(COLORDISP, (148, 148))
#RAMBANK startup end
colorreg="++++++"
ROMFILE=TROMA
ROMLAMPFLG="A"
stopflag=0
EXECCHANGE=0
#ROMFILE=open(BOOTUPFILE)
mempoint="---------"
EXECADDR="---------"
contaddr="---------"
EXECADDRfall=0
EXECADDRraw=EXECADDR
REG1="000000000"
REG2="000000000"
#status display optimization.
prevREG1="diff"
prevREG2="diff"
prevEXECADDR="diff"
prevROM="diff"
prevINST="diff"
prevDATA="diff"
regsetpoint="000000000"
updtcdisp=1
updtmdisp=1
updtblits=list()
updtttyprev=list()
updtrandport=1
upt=screensurf.blit(CPULEDACT, (749, 505))
updtblits.extend([upt])
upt=screensurf.blit(STEPLED, (750, 512))
updtblits.extend([upt])
print "Prep threading system..."
threadref="00"
#vmexeclog("Preping threading system...")
ttyredrawfull=1
BTSTACK={"--": BTTHREAD(1, EXECADDR, REG1, REG2, contaddr, EXECADDRraw, regsetpoint, TTYBGCOLREG, TTYBGCOL, colvectorreg, monovectorreg, colorreg, tritloadlen, tritoffset, tritdestgnd, threadref, ROMFILE, ROMLAMPFLG, mempoint)}
for cur_id in ["-0","-+","0-","00","0+","+-","+0","++"]:
BTSTACK[cur_id] = BTTHREAD(0, EXECADDR, REG1, REG2, contaddr, EXECADDRraw, regsetpoint, TTYBGCOLREG, TTYBGCOL, colvectorreg, monovectorreg, colorreg, tritloadlen, tritoffset, tritdestgnd, threadref, ROMFILE, ROMLAMPFLG, mempoint)
btthreadcnt=1
btcurthread="--"
curthrtex=lgdispfont.render(btcurthread, True, (127, 0, 255), (0, 0, 0)).convert()
upt=screensurf.blit(curthrtex, (170, 522))
updtblits.extend([upt])
ttyblitsprev=list()
ttyblits=list()
exlogclockticnum=0
#for f in BTSTACK:
# print str(BTSTACK[f].qxtact) + " " + f
#for f in BTSTACK:
# print str(BTSTACK[f].qxtact) + " " + f
print "SBTCVM Mark 2 Ready. the VM will now begin."
#vmexeclog("SBTCVM Mark 2 Ready. the VM will now begin.")
initaltime=time.time()
while stopflag==0:
#curinst=(libtrom.tromreadinst(EXECADDR,ROMFILE))
#curdata=(libtrom.tromreaddata(EXECADDR,ROMFILE))
EXECADDRNUM=libSBTCVM.numstruct(EXECADDR)
#fdelta=libtrom.ROMDICT[ROMFILE][EXECADDRNUM]
if ROMFILE==TROMA:
fdelta=libtrom.AROM[EXECADDRNUM]
elif ROMFILE==TROMB:
fdelta=libtrom.BROM[EXECADDRNUM]
elif ROMFILE==TROMC:
fdelta=libtrom.CROM[EXECADDRNUM]
elif ROMFILE==TROMD:
fdelta=libtrom.DROM[EXECADDRNUM]
elif ROMFILE==TROME:
fdelta=libtrom.EROM[EXECADDRNUM]
elif ROMFILE==TROMF:
fdelta=libtrom.FROM[EXECADDRNUM]
curinst=((fdelta[0]) + (fdelta[1]) + (fdelta[2]) + (fdelta[3]) + (fdelta[4]) + (fdelta[5]))
curdata=((fdelta[6]) + (fdelta[7]) + (fdelta[8]) + (fdelta[9]) + (fdelta[10]) + (fdelta[11]) + (fdelta[12]) + (fdelta[13]) + (fdelta[14]))
#some screen display stuff & general blitting
#screensurf.fill((0,127,255))
#draw Background
if trackopsec==1:
exlogclockticnum += 1
exlogcurtime=(time.time() - initaltime)
elif vmexeclogflg==1:
exlogclockticnum += 1
exlogcurtime=(time.time() - initaltime)
vmexeclog("data: " + curdata + " |Inst: " + curinst + " |adr: " + EXECADDR + " |Mem point: " + mempoint +" |thread: " + btcurthread + " |exec bank: " + ROMLAMPFLG + " |reg1: " + REG1 + " |reg2: " + REG2 + " |tic #: " + str(exlogclockticnum) + " |secs: " + format((exlogcurtime), '.11f'))
if fskipcnt == fskip or stepbystep==1:
if disablereadouts==0 or stepbystep==1:
#screensurf.blit(vmbg, (0, 0))
#these show the instruction and data in the instruction/data box :)
if prevINST!=curinst:
insttext=smldispfont.render(curinst, True, (0, 255, 255), (0, 0, 0)).convert()
prevINST=curinst
upt=screensurf.blit(insttext, (8, 522))
updtblits.extend([upt])
if prevDATA!=curdata:
datatext=smldispfont.render(curdata, True, (0, 255, 127), (0, 0, 0)).convert()
prevDATA=curdata
upt=screensurf.blit(datatext, (8, 566))
updtblits.extend([upt])
#these draw the register displays :)
if prevREG1!=REG1:
reg1text=lgdispfont.render(REG1, True, (255, 0, 127), (0, 0, 0)).convert()
prevREG1=REG1
upt=screensurf.blit(reg1text, (219, 521))
updtblits.extend([upt])
if prevREG2!=REG2:
reg2text=lgdispfont.render(REG2, True, (255, 127, 0), (0, 0, 0)).convert()
prevREG2=REG2
upt=screensurf.blit(reg2text, (219, 564))
updtblits.extend([upt])
#and here is what draws the ROM address display :)
ROMadrtex=lgdispfont.render(EXECADDR, True, (0, 127, 255), (0, 0, 0)).convert()
upt=screensurf.blit(ROMadrtex, (425, 564))
updtblits.extend([upt])
#and the current rom display :)
CURROMTEXT=(ROMLAMPFLG)
if prevROM!=CURROMTEXT:
curROMtex=lgdispfont.render(CURROMTEXT, True, (255, 0, 255), (0, 0, 0)).convert()
prevROM=CURROMTEXT
upt=screensurf.blit(curROMtex, (126, 522))
updtblits.extend([upt])
#LED LAMPS
#CPU
#screensurf.blit(CPULEDACT, (749, 505))
#STEP
if updtcdisp==1:
updtcdisp=0
COLORDISPBIG=pygame.transform.scale(COLORDISP, (148, 148))
upt=screensurf.blit(COLORDISPBIG, (649, 1))
updtblits.extend([upt])
if updtmdisp==1:
updtmdisp=0
MONODISPBIG=pygame.transform.scale(MONODISP, (144, 144))
upt=screensurf.blit(MONODISPBIG, (649, 150))
updtblits.extend([upt])
if abtpref!=abt or ttyredraw==1:
abtpref=abt
ttyredraw=0
lineq=0
linexq=0
if ttystyle==0:
libSBTCVMsurf.fill(TTYBGCOL)
for fnx in abt:
fnx=fnx.replace('\n', '')
colq=0
if TTYSIZE==0 or linexq>26:
for qlin in fnx:
#print qlin
charq=libSBTCVM.charlookupdict.get(qlin)
#print charq
if TTYSIZE==1:
xq=libSBTCVM.charblit2(libSBTCVMsurf, colq, lineq, charq)
else:
xq=libSBTCVM.charblit(libSBTCVMsurf, colq, lineq, charq)
ttyblits.extend([xq[1]])
colq +=1
lineq +=1
linexq +=1
upt=screensurf.blit(libSBTCVMsurf, (0, 0))
if ttyredrawfull==1:
updtblits.extend([upt])
ttyredrawfull=0
else:
updtblits = updtblits + ttyblits + ttyblitsprev
#updtblits.extend([upt])
#updtblits.append(ttyblits)
#updtblits.append(ttyblitsprev)
#print updtblits
ttyblitsprev=ttyblits
ttyblits=list()
lineq=0
linexq=0
#if ttystyle==1:
#print "-----newpage---"
#for fnx in abt:
#if TTYSIZE==0 or linexq>26:
#fnx=fnx.replace('\n', '')
#colq=0
#print ("TTY|" + fnx)
#lineq +=1
#linexq +=1
lineq=0
linexq=0
#disabled as its far too buggy
#if ttystyle==2:
#for fnx in abt:
#fnx=fnx.replace('\n', '')
#colq=0
#if TTYSIZE==0 or linexq>26:
#if TTYSIZE==1:
#ttyfn=ttyfontB.render(fnx, True, (255, 255, 255), (0, 0, 0)).convert()
#upt=screensurf.blit(ttyfn, (0, (lineq*18)))
##updtblits.extend([upt])
#else:
#ttyfn=ttyfont.render(fnx, True, (255, 255, 255), (0, 0, 0)).convert()
#upt=screensurf.blit(ttyfn, (0, (lineq*9)))
##updtblits.extend([upt])
#lineq +=1
#linexq +=1
#print ("ttystyle" + str(ttystyle))
#screensurf.blit(libSBTCVMsurf, (45, 40))
#biglibSBTCVM=pygame.transform.scale(libSBTCVMsurf, (648, 486))
if updtblits!=list():
pygame.display.update(updtblits)
updtblits=list()
fskipcnt=0
#print "sc update"
else:
fskipcnt+=1
#print "sc skip"
#ROM READ (first register)
if curinst=="------":
REG1=(tritlen(libtrom.tromreaddata(curdata,ROMFILE), REG1))
#print("----")
#ROM READ (second register)
elif curinst=="-----0":
REG2=(tritlen(libtrom.tromreaddata(curdata,ROMFILE), REG2))
#print("---0")
#IO READ REG1
elif curinst=="-----+":
REG1=tritlen(RAMbank[curdata], REG1)
if curdata=="--0------":
updtrandport=1
#print("---+")
#IO READ REG2
elif curinst=="----0-":
REG2=tritlen(RAMbank[curdata], REG2)
if curdata=="--0------":
updtrandport=1
#print("--0-")
#IO WRITE REG1
elif curinst=="----00":
if curdata not in IOreadonly:
rambnkcur=RAMbank[curdata]
RAMbank[curdata] = tritlen(REG1, rambnkcur)
else:
print "address \"" + curdata + "\" is read-only."
#IO WRITE REG2
elif curinst=="----0+":
if curdata not in IOreadonly:
rambnkcur=RAMbank[curdata]
RAMbank[curdata] = tritlen(REG2, rambnkcur)
else:
print "address \"" + curdata + "\" is read-only."
#swap primary Registers
elif curinst=="----+-":
REGTEMP = REG1
REG1 = REG2
REG2 = REGTEMP
#copy Register 1 to register 2
elif curinst=="----+0":
REG2 = REG1
#copy Register 2 to register 1
elif curinst=="----++":
REG1 = REG2
#invert register 1
elif curinst=="---0--":
REG1 = (libbaltcalc.BTINVERT(REG1))
#invert register 2
elif curinst=="---0-0":
REG2 = (libbaltcalc.BTINVERT(REG2))
#add both registers, load awnser into REG1
elif curinst=="---0-+":
#print REG1
#print REG2
#print "bla"
REG1 = (libSBTCVM.trunkto6math(libbaltcalc.btadd(REG1, REG2)))
#sub both registers, load awnser into REG1
elif curinst=="---00-":
REG1 = (libSBTCVM.trunkto6math(libbaltcalc.btsub(REG1, REG2)))
#mul both registers, load awnser into REG1
elif curinst=="---000":
REG1 = (libSBTCVM.trunkto6math(libbaltcalc.btmul(REG1, REG2)))
#div both registers, load awnser into REG1
elif curinst=="---00+":
ZDIVCHECKTMP=libbaltcalc.btdivcpu(REG1, REG2)
if ZDIVCHECKTMP=="ZDIV":
stopflag=1
abt=libSBTCVM.abtslackline(abt, "VM SYSHALT:")
abt=libSBTCVM.abtslackline(abt, "DIVIDE BY ZERO")
vmexeclog("VMSYSHALT: DIVIDE BY ZERO")
REG1=="000000000"
else:
REG1 = (libSBTCVM.trunkto6math(ZDIVCHECKTMP))
#set REG1
elif curinst=="---0+-":
REG1 = curdata
#set REG2
elif curinst=="---0+0":
REG2 = curdata
#set inst
elif curinst=="---0++":
instsetto=(REG1[0] + REG1[1] + REG1[2] + REG1[3] + REG1[4] + REG1[5])
libtrom.tromsetinst(curdata, instsetto, ROMFILE)
#set data
elif curinst=="---+--":
libtrom.tromsetdata(curdata, tritlen(REG1, libtrom.tromreaddata(curdata, ROMFILE)), ROMFILE)
#continue
elif curinst=="---+++":
EXECADDRNEXT=contaddr
EXECCHANGE=1
#color draw
elif curinst=="--0---":
updtcdisp=1
jx=libSBTCVM.drawnumstruct3((curdata[3] + curdata[4] + curdata[5]))
jy=libSBTCVM.drawnumstruct3((curdata[6] + curdata[7] + curdata[8]))
RGBcol=libSBTCVM.colorfind(colorreg)
#print monocol
pygame.draw.line(COLORDISP, RGBcol, [jx, jy], [jx, jy], 1)
#COLORDISPBIG=pygame.transform.scale(COLORDISP, (148, 148))
#set PPU color Register
elif curinst=="--0--0":
updtcdisp=1
colorreg=(curdata[3] + curdata[4] + curdata[5] + curdata[6] + curdata[7] + curdata[8])
elif curinst=="--0--+":
updtcdisp=1
RGBcol=libSBTCVM.colorfind((curdata[3] + curdata[4] + curdata[5] + curdata[6] + curdata[7] + curdata[8]))
#print monocol
COLORDISP.fill(RGBcol)
#COLORDISPBIG=pygame.transform.scale(COLORDISP, (148, 148))
#set PPU color vector Register
elif curinst=="--0-0-":
updtcdisp=1
colvectorreg=(curdata[3] + curdata[4] + curdata[5] + curdata[6] + curdata[7] + curdata[8])
elif curinst=="--0-00":
updtcdisp=1
#print curdata
jx=libSBTCVM.drawnumstruct3((curdata[3] + curdata[4] + curdata[5]))
jy=libSBTCVM.drawnumstruct3((curdata[6] + curdata[7] + curdata[8]))
kx=libSBTCVM.drawnumstruct3((colvectorreg[0] + colvectorreg[1] + colvectorreg[2]))
ky=libSBTCVM.drawnumstruct3((colvectorreg[3] + colvectorreg[4] + colvectorreg[5]))
RGBcol=libSBTCVM.colorfind(colorreg)
#print monocol
pygame.draw.line(COLORDISP, RGBcol, [jx, jy], [kx, ky], 1)
#COLORDISPBIG=pygame.transform.scale(COLORDISP, (148, 148))
#color draw rect
elif curinst=="--0-0+":
updtcdisp=1
#print curdata
jx=libSBTCVM.drawnumstruct3((curdata[3] + curdata[4] + curdata[5]))
jy=libSBTCVM.drawnumstruct3((curdata[6] + curdata[7] + curdata[8]))
kx=libSBTCVM.drawnumstruct3((colvectorreg[0] + colvectorreg[1] + colvectorreg[2]))
ky=libSBTCVM.drawnumstruct3((colvectorreg[3] + colvectorreg[4] + colvectorreg[5]))
RGBcol=libSBTCVM.colorfind(colorreg)
#print monocol
#pygame.draw.line(COLORDISP, RGBcol, [jx, jy], [kx, ky], 1)
COLORDISP.fill(RGBcol, (libSBTCVM.makerectbipoint(jx, jy, kx, ky)))
#COLORDISPBIG=pygame.transform.scale(COLORDISP, (148, 148))
#mono draw
#mono draw pixel
elif curinst=="--0-+-":
updtmdisp=1
jx=libSBTCVM.drawnumstruct2((curdata[3] + curdata[4]))
jy=libSBTCVM.drawnumstruct2((curdata[5] + curdata[6]))
monocol=(int(libSBTCVM.dollytell((curdata[7] + curdata[8]))))
#print monocol
pygame.draw.line(MONODISP, (monocol, monocol, monocol), [jx, jy], [jx, jy], 1)
#MONODISPBIG=pygame.transform.scale(MONODISP, (144, 144))
#mono fill
elif curinst=="--0-+0":
updtmdisp=1
monocol=(int(libSBTCVM.dollytell((curdata[7] + curdata[8]))))
#print monocol
MONODISP.fill((monocol, monocol, monocol))
#MONODISPBIG=pygame.transform.scale(MONODISP, (144, 144))
#set PPU mono vector Register
elif curinst=="--0-++":
updtmdisp=1
monovectorreg=(curdata[3] + curdata[4] + curdata[5] + curdata[6] + curdata[7] + curdata[8])
#draw mono line
elif curinst=="--00--":
updtmdisp=1
jx=libSBTCVM.drawnumstruct2((curdata[3] + curdata[4]))
jy=libSBTCVM.drawnumstruct2((curdata[5] + curdata[6]))
kx=libSBTCVM.drawnumstruct2((monovectorreg[0] + monovectorreg[1]))
ky=libSBTCVM.drawnumstruct2((monovectorreg[2] + monovectorreg[3]))
monocol=(int(libSBTCVM.dollytell((curdata[7] + curdata[8]))))
#print monocol
pygame.draw.line(MONODISP, (monocol, monocol, monocol), [jx, jy], [kx, ky], 1)
#MONODISPBIG=pygame.transform.scale(MONODISP, (144, 144))
#mono draw rect
elif curinst=="--00-0":
updtmdisp=1
jx=libSBTCVM.drawnumstruct2((curdata[3] + curdata[4]))
jy=libSBTCVM.drawnumstruct2((curdata[5] + curdata[6]))
kx=libSBTCVM.drawnumstruct2((monovectorreg[0] + monovectorreg[1]))
ky=libSBTCVM.drawnumstruct2((monovectorreg[2] + monovectorreg[3]))
monocol=(int(libSBTCVM.dollytell((curdata[7] + curdata[8]))))
#print monocol
#pygame.draw.line(MONODISP, (monocol, monocol, monocol), [jx, jy], [kx, ky], 1)
MONODISP.fill((monocol, monocol, monocol), (libSBTCVM.makerectbipoint(jx, jy, kx, ky)))
#MONODISPBIG=pygame.transform.scale(MONODISP, (144, 144))
#SHUTDOWN VM
elif curinst=="--000-":
stopflag=1
abt=libSBTCVM.abtslackline(abt, "VM SYSHALT:")
abt=libSBTCVM.abtslackline(abt, "soft stop.")
vmexeclog("VMSYSHALT: SOFT STOP")
ttyredraw=1
#NULL INSTRUCTION (DOES NOTHING) USE WHEN YOU WISH TO DO NOTHING :p
#elif curinst=="--0000":
#commented out due to doing nothing.
#print("")
#goto rom adress specified by CURRENT DATA
elif curinst=="--000+":
EXECADDRNEXT=curdata
EXECCHANGE=1
#goto rom adress specified by Register 1
elif curinst=="--00+-":
EXECADDRNEXT=REG1
EXECCHANGE=1
elif curinst=="--00+0":
if REG1==REG2:
EXECADDRNEXT=curdata
EXECCHANGE=1
elif curinst=="--00++":
waitchop=curdata[5]
if waitchop=="+":
waitmagn=0.3
elif waitchop=="-":
waitmagn=0.1
else:
waitmagn=0.2
time.sleep(( waitmagn))
#asks user if goto to adress is desired
elif curinst=="--0+--":
abt=libSBTCVM.abtslackline(abt, ("GOTO: (" + curdata + ") Y or N?"))
abt=libSBTCVM.abtslackline(abt, "")
ttyredraw=1
USRYN=1
extradraw=1
#user wait
elif curinst=="--0+-0":
abt=libSBTCVM.abtslackline(abt, ("Press enter to continue."))
abt=libSBTCVM.abtslackline(abt, "")
ttyredraw=1
USRWAIT=1
extradraw=1
#TTY clear
elif curinst=="--0+-+":
abt=["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]
#Goto data if Reg 1 greater
elif curinst=="--0+0-":
if libbaltcalc.BTTODEC(REG1)>libbaltcalc.BTTODEC(REG2):
EXECADDRNEXT=curdata
EXECCHANGE=1
#note these swap TROMS
#TROMA: goto rom adress on TROMA specified by CURRENT DATA
elif curinst=="--+---":
EXECADDRNEXT=curdata
EXECCHANGE=1
ROMFILE=TROMA
ROMLAMPFLG="A"
#conditional GOTO
elif curinst=="--+--0":
if REG1==REG2:
EXECADDRNEXT=curdata
EXECCHANGE=1
ROMFILE=TROMA
ROMLAMPFLG="A"
#TROMB: goto rom adress on TROMB specified by CURRENT DATA
elif curinst=="--+--+":
EXECADDRNEXT=curdata
EXECCHANGE=1
ROMFILE=TROMB
ROMLAMPFLG="B"
elif curinst=="--+-0-":
if REG1==REG2:
EXECADDRNEXT=curdata
EXECCHANGE=1
ROMFILE=TROMB
ROMLAMPFLG="B"
#TROMC: goto rom adress on TROMC specified by CURRENT DATA
elif curinst=="--+-00":
EXECADDRNEXT=curdata
EXECCHANGE=1
ROMFILE=TROMC
ROMLAMPFLG="C"
#conditional GOTO
elif curinst=="--+-0+":
if REG1==REG2:
EXECADDRNEXT=curdata
EXECCHANGE=1
ROMFILE=TROMC
ROMLAMPFLG="C"
#TROMD: goto rom adress on TROMD specified by CURRENT DATA
elif curinst=="--+-+-":
EXECADDRNEXT=curdata
EXECCHANGE=1
ROMFILE=TROMD
ROMLAMPFLG="D"
#conditional GOTO
elif curinst=="--+-+0":
if REG1==REG2:
EXECADDRNEXT=curdata
EXECCHANGE=1
ROMFILE=TROMD
ROMLAMPFLG="D"
#TROME: goto rom adress on TROME specified by CURRENT DATA
elif curinst=="--+-++":
EXECADDRNEXT=curdata
EXECCHANGE=1
ROMFILE=TROME
ROMLAMPFLG="E"
#conditional GOTO
elif curinst=="--+0--":
if REG1==REG2:
EXECADDRNEXT=curdata
EXECCHANGE=1
ROMFILE=TROME
ROMLAMPFLG="E"
#TROMF: goto rom adress on TROMF specified by CURRENT DATA
elif curinst=="--+0-0":
EXECADDRNEXT=curdata
EXECCHANGE=1
ROMFILE=TROMF
ROMLAMPFLG="F"
#conditional GOTO
elif curinst=="--+0-+":
if REG1==REG2:
EXECADDRNEXT=curdata
EXECCHANGE=1
ROMFILE=TROMF
ROMLAMPFLG="F"
#dump register 1 to TTY
elif curinst=="--++0+":
#print ("REG1 DUMP:" + REG1 + " " + str(libbaltcalc.BTTODEC(REG1)))
ttyredraw=1
abt=libSBTCVM.abtslackline(abt, ("REG1 DUMP:" + REG1 + " " + str(libbaltcalc.BTTODEC(REG1))))
#dump Register 2 to TTY
elif curinst=="--+++-":
#print ("REG2 DUMP:" + REG2 + " " + str(libbaltcalc.BTTODEC(REG2)))
ttyredraw=1
abt=libSBTCVM.abtslackline(abt, ("REG2 DUMP:" + REG2 + " " + str(libbaltcalc.BTTODEC(REG2))))
#tty write port (direct)
elif curinst=="--+++0":
abt=libSBTCVM.abtcharblit(abt, (libSBTCVM.charcodelook((curdata[3] + curdata[4] + curdata[5] + curdata[6] + curdata[7] + curdata[8]))))
if TTYrenderflg=="0":
ttyredraw=1
else:
if libSBTCVM.getnewlstate()==1:
ttyredraw=1
#Buzzer (direct)
elif curinst=="--++++":
snf.stop()
#print "derp"
wavsp=libSBTCVM.mk1buzz((curdata[3] + curdata[4] + curdata[5] + curdata[6] + curdata[7] + curdata[8]))
snf=pygame.mixer.Sound(wavsp)
snf.play()
timechop=curdata[0]
if timechop=="+":
time.sleep(0.3)
elif timechop=="-":
time.sleep(0.1)
else:
time.sleep(0.2)
#set regset pointer
elif curinst=="-0-000":
regsetpoint=curdata
#print "testtest"
#print regsetpoint
#regset
elif curinst=="-0-00+":
#print "Test0"
if regsetpoint=='---------':
TTYBGCOLREG=(curdata[3] + curdata[4] + curdata[5] + curdata[6] + curdata[7] + curdata[8])
TTYBGCOL=libSBTCVM.colorfind(TTYBGCOLREG)
ttyredraw=1
ttyredrawfull=1
#print "test2"
elif regsetpoint=='--------0':
TTYrenderflg=curdata[8]
if TTYrenderflg=="-":
TTYrenderflg="0"
elif regsetpoint=='--------+':
TTYSIZEFLG=curdata[8]
ttyredraw=1
#print "test1"
if TTYSIZEFLG=="+":
TTYSIZE=1
else:
TTYSIZE=0
#mempointer control
elif curinst=="-0-0+-":
#print mempoint