Author Topic: Trying to imitate TIS-100  (Read 5987 times)

0 Members and 1 Guest are viewing this topic.

Offline Juan Tamarit

  • Newbie
  • Posts: 53
    • View Profile
Re: Trying to imitate TIS-100
« Reply #15 on: September 02, 2020, 09:26:13 pm »
Thanks for the reply, I found my way trhu back door after posting

PRINT LTRIM$(STR$(_ROUND(RND)));

=)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Trying to imitate TIS-100
« Reply #16 on: September 02, 2020, 10:11:42 pm »
Opps, missed the question. For a 50/50 chance just use:
Code: QB64: [Select]
  1. FOR i = 1 TO 1000000
  2.     IF RND < .5 THEN heads = heads + 1 ELSE tails = tails + 1
  3.     IF i MOD 1000 = 0 THEN PRINT heads / (heads + tails)

Offline Juan Tamarit

  • Newbie
  • Posts: 53
    • View Profile
Re: Trying to imitate TIS-100
« Reply #17 on: September 03, 2020, 01:01:57 am »
No problem bro, you too kind and patient already =) you a teacher too? you quite didactic.

I have condensed the SUB's drawSingleLineBox, drawDoubleLineBox and drawSolidBox into a single SUB called drawASCIIbox, that includes a style% parameter. 1= single line, 2 = double line, 3 = solid. I couldn't find a way to make it even shorter, and surely it has been made a million times before, but here's my approach.

Also been doing some nice advances on the "game" (if i ever get to end it). Preview for the critic:
Code: QB64: [Select]
  1. '----------------------------------------------------------------------------------------------------------Û   SETUP   Û----------------------------------------------------------------------------------------------------------
  2.  
  3. CONST ScreenWidth = 800 '                        ¿           ÚÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  4. CONST ScreenHeight = 608 '                       ³           ³  1y,1x     ³
  5. '                                                ³ video     ³  TEXT       ³
  6. SCREEN _NEWIMAGE(ScreenWidth, ScreenHeight, 32) '³           ³    SCREEN   ³
  7. _FULLSCREEN '                                    ³           ³   38y,100x ³
  8. _MOUSEHIDE '                                     Ù           ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  9.  
  10. CONST WHITE = _RGB32(255, 255, 255) '            ¿
  11. CONST BLACK = _RGB32(0, 0, 0) '                  ³
  12. CONST MIDGRAY = _RGB32(127, 127, 127) '          ³
  13. CONST DARKGRAY = _RGB32(63, 63, 63) '            ³ colors
  14. CONST LIGHTGRAY = _RGB32(191, 191, 191) '        ³
  15. CONST RED = _RGB32(127, 0, 0) '                  ³
  16. CONST GREEN = _RGB32(0, 127, 0) '                ³
  17. CONST BLUE = _RGB32(0, 0, 127) '                 ³
  18. CONST YELLOW = _RGB32(255, 255, 0) '             Ù
  19.  
  20.  
  21. '----------------------------------------------------------------------------------------------------------Û VARIABLES Û----------------------------------------------------------------------------------------------------------
  22. 'TYPE NODEv21
  23. '    x AS INTEGER
  24. '    y AS INTEGER
  25. '    acc AS INTEGER
  26. '    bak AS INTEGER
  27. '    mode AS STRING
  28. '    last AS STRING
  29. 'END TYPE
  30.  
  31. 'DIM nodeV21(11) AS NODEV21
  32. 'DIM instructions$(11, 0) ' need a node to check how many instructions fit
  33.  
  34.  
  35.  
  36.  
  37. DIM SHARED segmentState%(34)
  38. DIM SHARED actualSegmentWorking%
  39. DIM SHARED menuHighlight%
  40.  
  41. FOR i% = 0 TO 34 '
  42.     segmentState%(i%) = 0 '
  43. NEXT i% '
  44.  
  45. menuHighlight% = 0 '
  46. actualSegmentWorking% = 0
  47.  
  48.  
  49. '---------------------------------------------------------------------------------------------------------Û   PROGRAM   Û----------------------------------------------------------------------------------------------------------
  50. infect
  51. systemCheck
  52. mainMenu
  53.  
  54. '---------------------------------------------------------------------------------------------------------Û SUBROUTINES Û----------------------------------------------------------------------------------------------------------
  55. SUB infect () ' virus intro sketch
  56.  
  57.     row% = 15
  58.     column% = 38
  59.     message1$ = "I'm taking control..."
  60.     message2$ = "And you can't stop me"
  61.  
  62.     'sayHello
  63.     COLOR GREEN
  64.     PRINTslowly row% + 3, column% + 2, message1$
  65.     PRINTslowly row% + 4, column% + 2, message2$
  66.     SLEEP 1
  67.  
  68.     'install
  69.     i% = 0
  70.     ii% = 0
  71.     loadingBar$ = CHR$(219)
  72.     DO
  73.         i% = i% + 1
  74.         ii% = INT(i% / 100)
  75.  
  76.         _LIMIT 500
  77.  
  78.         COLOR MIDGRAY '                             ¿
  79.         LOCATE RND(1) * 37 + 1, RND(1) * 99 + 1 '   ³ random characthers on the back
  80.         PRINT CHR$(RND(1) * 222 + 32); '            Ù
  81.  
  82.  
  83.         COLOR GREEN '    a virus is GREEN! 
  84.  
  85.         drawASCIIbox row%, column%, 23, 7, "", 2
  86.  
  87.         fakeCLS row% + 1, column% + 1, 22, 6
  88.  
  89.         IF ii% MOD 2 = 0 THEN '                   ¿
  90.             LOCATE row% + 1, column% + 2 '        ³ blink: title
  91.             PRINT "CV64 VIRUS V0.2  >:-["; '      ³ underline
  92.             LOCATE row% + 2, column% + 2 '        ³ message1$
  93.             PRINT STRING$(21, CHR$(223)); '       ³ and
  94.             '                                     ³ message2$
  95.             LOCATE row% + 3, column% + 2 '        ³
  96.             PRINT message1$; '                    ³
  97.             '                                     ³
  98.             LOCATE row% + 4, column% + 2 '        ³
  99.             PRINT message2$; '                    Ù
  100.  
  101.         END IF
  102.  
  103.         LOCATE row% + 6, column% + 2 '                              ¿
  104.         IF ii% < 20 THEN PRINT "Overriding OS..."; '                ³
  105.         IF ii% < 40 AND ii% > 19 THEN PRINT "Accesing files..."; '  ³ loading messages
  106.         IF ii% < 60 AND ii% > 39 THEN PRINT "Infecting..."; '       ³
  107.         IF ii% < 80 AND ii% > 59 THEN PRINT "Replicating..."; '     ³
  108.         IF ii% < 100 AND ii% > 79 THEN PRINT "Ereasing nodes..."; ' ³
  109.         IF ii% = 100 THEN PRINT "Nodes killed "; '                 Ù
  110.  
  111.         ii$ = LTRIM$(STR$(ii%)) '                   ¿
  112.         LOCATE row% + 6, column% + 22 - LEN(ii$) '  ³ xx%
  113.         PRINT ii$ + "%"; '                          Ù
  114.  
  115.         IF i% MOD 500 = 0 THEN loadingBar$ = loadingBar$ + CHR$(219) ' ¿
  116.         LOCATE row% + 7, column% + 2 '                                 ³ loading bar
  117.         PRINT loadingBar$; '                                           Ù
  118.         _DISPLAY
  119.     LOOP UNTIL i% = 10000
  120.     SLEEP 2 '                                       infection complete XD
  121.  
  122.  
  123. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  124. SUB systemCheck () ' fake system check as excuse to go at main menu
  125.  
  126.     COLOR LIGHTGRAY
  127.     PRINTslowly 2, 2, "Unexpected restart. Running system check..."
  128.  
  129.     FOR i& = 0 TO 247483647 STEP 2048
  130.         _LIMIT 20000
  131.         LOCATE 4, 2
  132.         PRINT "CHECKSUM: ";: PRINT LTRIM$(STR$(i&));
  133.     NEXT i&
  134.     PRINT " OK"
  135.  
  136.     PRINTslowly 6, 2, "Nodes have been reset..."
  137.     PRINTslowly 7, 2, "Reprogram them to recover access to OS..."
  138.     PRINTslowly 8, 2, "Please, don't shut down the equipment until reprogramming is over, or data may be lost..."
  139.     PRINTslowly 10, 2, "Starting debbuger"
  140.  
  141.     SLEEP 2
  142.  
  143.  
  144. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  145. SUB mainMenu () ' draws main menu and instructions on the bottom
  146.     DO
  147.  
  148.         DO
  149.             _LIMIT 20
  150.             CLS
  151.             drawSegments
  152.             drawMainOptions
  153.             KeyPress$ = INKEY$
  154.  
  155.             _DISPLAY
  156.         LOOP UNTIL KeyPress$ <> ""
  157.  
  158.         IF KeyPress$ = CHR$(0) + CHR$(77) AND menuHighlight% <> 34 THEN menuHighlight% = menuHighlight% + 1 '  ¿
  159.         IF KeyPress$ = CHR$(0) + CHR$(75) AND menuHighlight% <> 0 THEN menuHighlight% = menuHighlight% - 1 '   ³ ARROWS for
  160.         IF KeyPress$ = CHR$(0) + CHR$(80) AND menuHighlight% < 28 THEN menuHighlight% = menuHighlight% + 7 '   ³ navigation
  161.         IF KeyPress$ = CHR$(0) + CHR$(72) AND menuHighlight% > 6 THEN menuHighlight% = menuHighlight% - 7 '    Ù
  162.  
  163.     LOOP UNTIL KeyPress$ = CHR$(27)
  164.  
  165. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  166. SUB drawSegments () ' draw the segment on the main menu
  167.  
  168.     i% = -1
  169.  
  170.     FOR y% = 2 TO 30 STEP 7
  171.         FOR x% = 2 TO 88 STEP 14
  172.  
  173.             i% = i% + 1 ' node index number, start -1 to make it 0 here for the array
  174.             '              we add another +1 later to make em look like start at 1
  175.             COLOR DARKGRAY '                                  ¿
  176.             FOR yy% = 2 TO 5 '                                ³
  177.                 FOR xx% = 1 TO 11 '                           ³ if node is broke
  178.                     LOCATE y% + yy%, x% + xx% '               ³ random characters
  179.                     IF NOT segmentState%(i%) THEN '           ³
  180.                         PRINT CHR$(RND(1) * 200 + 32); '      ³ if fixed by
  181.                     ELSE '                                    ³ user then
  182.                         PRINT LTRIM$(STR$(_ROUND(RND))); '    ³ plain 1's and 0's
  183.                     END IF '                                  ³
  184.                 NEXT xx% '                                    ³
  185.             NEXT yy% '                                        Ù
  186.  
  187.             IF i% > 8 THEN '                                  ¿ the shown number
  188.                 segmentNumber$ = LTRIM$(STR$(i% + 1)) '       ³ of the segment,
  189.             ELSE '                                            ³ avoiding the
  190.                 segmentNumber$ = " " + LTRIM$(STR$(i% + 1)) ' ³ spaces if
  191.             END IF '                                          Ù two digits
  192.  
  193.             IF menuHighlight% = i% THEN ' ¿
  194.                 COLOR WHITE '             ³ show WHITE if
  195.             ELSE '                        ³ selected, else
  196.                 COLOR MIDGRAY '           ³ is MIDGRAY
  197.             END IF '                      Ù
  198.  
  199.             drawASCIIbox y%, x%, 11, 5, " SEGMENT" + segmentNumber$, 1 ' draw the box
  200.  
  201.             LOCATE y% + 3, x% + 2 '     ¿
  202.             IF segmentState%(i%) THEN ' ³ accordingly to
  203.                 COLOR MIDGRAY, BLACK '  ³ segmentState%()
  204.                 PRINT "-NOMINAL-" '     ³ draw -NOMINAL-
  205.             ELSE '                      ³ or   - ERROR -
  206.                 COLOR BLACK, RED '      ³
  207.                 PRINT " -ERROR- " '     ³
  208.                 COLOR , BLACK '         ³
  209.             END IF '                   Ù
  210.             ' don't conflictuate other stuff
  211.         NEXT x%
  212.     NEXT y%
  213.  
  214.  
  215. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  216. SUB drawMainOptions () ' draws a single blue line with some instruction on it at the bottom of the screen
  217.  
  218.     COLOR YELLOW, BLUE
  219.  
  220.     FOR ii% = 1 TO 99 '   ¿
  221.         LOCATE 38, ii% '  ³ blue background
  222.         PRINT " "; '      ³ line at bottom
  223.     NEXT ii% '            Ù
  224.  
  225.     LOCATE 38, 19 '            ¿
  226.     PRINT "F1 Help"; '         ³
  227.     LOCATE 38, 43 '            ³ options in
  228.     PRINT "ARROWS Navigate"; ' ³ the main menu
  229.     LOCATE 38, 72 '            ³
  230.     PRINT "ENTER Select"; '    Ù
  231.  
  232.     COLOR , BLACK ' don't conflictuate with other things
  233.  
  234.  
  235. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  236. SUB PRINTslowly (originY%, originX%, message$)
  237.  
  238.     IF originY% < 1 THEN EXIT SUB '     ¿ check if logic
  239.     IF originX% < 1 THEN EXIT SUB '     Ù
  240.  
  241.     PCthinking originY%, originX%
  242.  
  243.     i% = 0 '                                                Ä¿
  244.     DO '                                                     ³
  245.         _DELAY .05 '                                         ³
  246.         i% = i% + 1 '                                        ³ print message$
  247.         buildingMessage$ = LEFT$(message$, i%) + CHR$(219) ' ³ character by character
  248.         LOCATE originY%, originX% '                          ³ and erease the cursor
  249.         PRINT buildingMessage$; '                            ³
  250.     LOOP UNTIL LEN(buildingMessage$) = LEN(message$) + 1 '  ÄÙ
  251.  
  252.     LOCATE CSRLIN, originX% + LEN(message$): PRINT " "; ' erease cursor
  253.  
  254.  
  255. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  256. SUB PCthinking (originY%, originX%)
  257.  
  258.     IF originY% < 1 THEN EXIT SUB '     ¿ check if logic
  259.     IF originX% < 1 THEN EXIT SUB '     Ù
  260.  
  261.     FOR i% = 1 TO 11 '                  ¿
  262.         _LIMIT 5 '                      ³
  263.         LOCATE originY%, originX% '     ³
  264.         IF i% MOD 2 = 0 THEN '          ³ bliking cursor
  265.             PRINT CHR$(219); '          ³
  266.         ELSE '                          ³
  267.             PRINT " "; '                ³
  268.         END IF '                        ³
  269.     NEXT i% '                           Ù
  270.  
  271.  
  272. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  273. SUB fakeCLS (originY%, originX%, width%, height%)
  274.  
  275.     IF originY% < 1 THEN EXIT SUB '               ¿
  276.     IF originX% < 1 THEN EXIT SUB '               ³ check if logic
  277.     IF width% < 1 THEN EXIT SUB '                 ³
  278.     IF height% < 1 THEN EXIT SUB '                Ù
  279.  
  280.     FOR x% = 0 TO width% '                        ¿
  281.         FOR y% = 0 TO height% '                   ³ print
  282.             LOCATE originY% + y%, originX% + x% ' ³ " " (space)
  283.             PRINT " "; '                          ³ repeatedly
  284.         NEXT y% '                                 ³
  285.     NEXT x% '                                     Ù
  286.  
  287.  
  288. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  289. SUB drawASCIIbox (originY%, originX%, width%, height%, message$, style%)
  290.  
  291.  
  292.     IF originY% < 1 OR originX% < 1 THEN EXIT SUB '     ÄÄÄ¿
  293.     IF width% < 1 OR height% < 1 THEN EXIT SUB '           ³ check if logic
  294.     IF style% < 1 OR style% > 3 THEN EXIT SUB '         ÄÄÄÙ
  295.  
  296.  
  297.     LOCATE originY%, originX% '                         ÄÄÄ¿
  298.     IF style% = 1 THEN PRINT CHR$(218); 'Ú                 ³
  299.     IF style% = 2 THEN PRINT CHR$(201); ' É   up,left      ³
  300.     IF style% = 3 THEN PRINT CHR$(220); ' Ü                ³
  301.     '                                                      ³
  302.     LOCATE originY% + height% + 1, originX% '              ³
  303.     IF style% = 1 THEN PRINT CHR$(192); ' À                ³
  304.     IF style% = 2 THEN PRINT CHR$(200); ' È  down, left    ³ corners
  305.     IF style% = 3 THEN PRINT CHR$(223); ' ß                ³
  306.     '                                                      ³
  307.     LOCATE originY%, originX% + width% + 1 '               ³
  308.     IF style% = 1 THEN PRINT CHR$(191); ' ¿                ³
  309.     IF style% = 2 THEN PRINT CHR$(187); ' » up, right      ³
  310.     IF style% = 3 THEN PRINT CHR$(220); ' Ü                ³
  311.     '                                                      ³
  312.     LOCATE originY% + height% + 1, originX% + width% + 1 ' ³
  313.     IF style% = 1 THEN PRINT CHR$(217); ' Ù                ³
  314.     IF style% = 2 THEN PRINT CHR$(188); ' ¼ down, right    ³
  315.     IF style% = 3 THEN PRINT CHR$(223); ' ß             ÄÄÄÙ
  316.  
  317.     IF style% = 1 THEN char% = 179 ' ³                  ÄÄÄ¿
  318.     IF style% = 2 THEN char% = 186 ' º  determinate style  ³
  319.     IF style% = 3 THEN char% = 219 ' Û                     ³
  320.     FOR y% = 1 TO height% '                                ³
  321.         LOCATE originY% + y%, originX% ' locate and print  ³ sides
  322.         PRINT CHR$(char%); '                               ³
  323.         LOCATE originY% + y%, originX% + width% + 1 '      ³
  324.         PRINT CHR$(char%); '                               ³
  325.     NEXT y% '                                           ÄÄÄÙ
  326.  
  327.     IF style% < 3 THEN ' styles 1 and 2                 ÄÄÄ¿
  328.         IF style% = 1 THEN char% = 196 ' Ä                 ³
  329.         IF style% = 2 THEN char% = 205 ' Í                 ³
  330.         FOR x% = 1 TO width% '                             ³
  331.             LOCATE originY%, originX% + x% '               ³
  332.             PRINT CHR$(char%); '                           ³
  333.             LOCATE originY% + height% + 1, originX% + x% ' ³
  334.             PRINT CHR$(char%); '                           ³ top &
  335.         NEXT x% '                                          ³ bottom
  336.     ELSE ' special case of style 3                         ³
  337.         char1% = 220 ' Ü                                   ³
  338.         char2% = 223 ' ß                                   ³
  339.         FOR x% = 0 TO width% + 1 '                         ³
  340.             LOCATE originY%, originX% + x% '               ³
  341.             PRINT CHR$(char1%); '                          ³
  342.             LOCATE originY% + height% + 1, originX% + x% ' ³
  343.             PRINT CHR$(char2%); '                          ³
  344.         NEXT x% '                                          ³
  345.     END IF '                                            ÄÄÄÙ
  346.  
  347.     LOCATE originY% + 1, originX% + 1 '                 ÄÄÄ¿ message
  348.     PRINT message$ '                                    ÄÄÄÙ
  349.  

Working now on the general inside-segment drawing. I prevent that functions are gonna be a mess when the moment arrives, but i have a long road there. For the moment some opinions/suggestions/ideas will be nice. Or merly chating. I'm all ears.

Offline Juan Tamarit

  • Newbie
  • Posts: 53
    • View Profile
Re: Trying to imitate TIS-100
« Reply #18 on: September 03, 2020, 01:12:25 am »
I tried to edit last post, but never loaded. Lines 312, 317, 322, 327 of the SUB should be ereased. They job will be done in lines 348 to 357. [so SUB it's even smalle by four lines =) ]

Offline Juan Tamarit

  • Newbie
  • Posts: 53
    • View Profile
Re: Trying to imitate TIS-100
« Reply #19 on: September 04, 2020, 03:30:24 am »
Ok, the monster keeps growing, and start to take shape. We have full intro sketch, main menu, adn you can enter on SEGMENT 1 and SEGMENT 2 =). I have to say that i like to do this kind of GUIs, i never noticed how much work the programmers of the old days had to do in order of just showing a menu XD.

Here is where we are now:
Code: QB64: [Select]
  1. '----------------------------------------------------------------------------------------------------------Û   SETUP   Û----------------------------------------------------------------------------------------------------------
  2.  
  3. CONST ScreenWidth = 1024 '                       ¿           ÚÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  4. CONST ScreenHeight = 768 '                       ³           ³  1y,1x     ³
  5. '                                                ³ video     ³  TEXT       ³
  6. SCREEN _NEWIMAGE(ScreenWidth, ScreenHeight, 32) '³           ³    SCREEN   ³
  7. _FULLSCREEN '                                    ³           ³   48y,128x ³
  8. _MOUSEHIDE '                                     Ù           ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  9.  
  10. CONST WHITE = _RGB32(255, 255, 255) '            ¿
  11. CONST BLACK = _RGB32(0, 0, 0) '                  ³
  12. CONST MIDGRAY = _RGB32(127, 127, 127) '          ³
  13. CONST DARKGRAY = _RGB32(63, 63, 63) '            ³ colors
  14. CONST LIGHTGRAY = _RGB32(191, 191, 191) '        ³
  15. CONST RED = _RGB32(127, 0, 0) '                  ³
  16. CONST GREEN = _RGB32(0, 127, 0) '                ³
  17. CONST BLUE = _RGB32(0, 0, 127) '                 ³
  18. CONST YELLOW = _RGB32(255, 255, 0) '             Ù
  19.  
  20. '----------------------------------------------------------------------------------------------------------Û VARIABLES Û----------------------------------------------------------------------------------------------------------
  21. 'TYPE NODEv21
  22. '    y AS INTEGER
  23. '    x AS INTEGER
  24. '    acc AS INTEGER
  25. '    bak AS INTEGER
  26. '    mode AS STRING
  27. '    last AS STRING
  28. 'END TYPE
  29.  
  30. 'DIM nodeV21(11) AS NODEv21
  31. 'DIM instructions$(34, 11, 10) ' instructions$(segment, node, instruction line)
  32.  
  33. DIM SHARED segmentState%(34) ' is segment NOMINAL(1) or ERROR(0)?
  34. DIM SHARED segmentName$(-1 TO 34) ' names of the segments (signal multiplexer, for instance)
  35. DIM SHARED actualSegmentWorking% ' where are we?
  36. DIM SHARED menuHighlight% ' what user is selectin on main menu
  37.  
  38. FOR i% = 0 TO 34 '
  39.     segmentState%(i%) = 0 ' 'DATA? or permadeath?
  40. NEXT i% '
  41.  
  42. segmentName$(0) = "SYSTEM CLOCK"
  43. segmentName$(1) = "MULTIPLEXER"
  44.  
  45. menuHighlight% = 0 'segment 1 is index 0 on the array
  46. actualSegmentWorking% = -1 ' main menu is -1
  47.  
  48. '---------------------------------------------------------------------------------------------------------Û   PROGRAM   Û----------------------------------------------------------------------------------------------------------
  49. infect
  50. systemCheck
  51. mainMenu
  52.  
  53. '---------------------------------------------------------------------------------------------------------Û SUBROUTINES Û----------------------------------------------------------------------------------------------------------
  54. SUB mainMenu () ' draws main menu and instructions on the bottom
  55.  
  56.     DO
  57.         DO
  58.             _LIMIT 20
  59.             CLS
  60.  
  61.             SELECT CASE actualSegmentWorking%
  62.                 CASE -2: drawSegments: UsureToLeave
  63.                 CASE -1: drawSegments
  64.                 CASE 0: inSegment_1
  65.                 CASE 1: inSegment_2
  66.                 CASE 2: ' COMING SOON ; )
  67.             END SELECT
  68.  
  69.             KeyPress$ = INKEY$
  70.             _DISPLAY
  71.         LOOP UNTIL KeyPress$ <> ""
  72.  
  73.         IF actualSegmentWorking% = -1 THEN '                                                                                      ¿
  74.             IF KeyPress$ = CHR$(0) + CHR$(77) AND menuHighlight% <> 34 THEN menuHighlight% = menuHighlight% + 1 '  ¿             ³
  75.             IF KeyPress$ = CHR$(0) + CHR$(75) AND menuHighlight% <> 0 THEN menuHighlight% = menuHighlight% - 1 '   ³ ARROWS for  ³ only works
  76.             IF KeyPress$ = CHR$(0) + CHR$(80) AND menuHighlight% < 28 THEN menuHighlight% = menuHighlight% + 7 '   ³ navigation  ³ in the
  77.             IF KeyPress$ = CHR$(0) + CHR$(72) AND menuHighlight% > 6 THEN menuHighlight% = menuHighlight% - 7 '    Ù             ³ main menu
  78.             IF KeyPress$ = CHR$(13) THEN actualSegmentWorking% = menuHighlight% ' ------------------------ENTER to select         ³
  79.         END IF '                                                                                                                  Ù
  80.  
  81.         IF KeyPress$ = CHR$(0) + CHR$(68) THEN actualSegmentWorking% = -2 ' F10 to ask for leaving
  82.  
  83.         IF KeyPress$ = "y" AND actualSegmentWorking% = -2 THEN SYSTEM '                     Y ¿ YES  ¿
  84.         IF KeyPress$ = CHR$(13) AND actualSegmentWorking% = -2 THEN SYSTEM '            ENTER Ù      ³ when asked
  85.         '                                                                                            ³ to leave
  86.         IF KeyPress$ = "n" AND actualSegmentWorking% = -2 THEN actualSegmentWorking% = -1 ' N ¿ NO   ³
  87.         IF KeyPress$ = CHR$(27) THEN actualSegmentWorking% = -1 '-------------------------ESC Ù      Ù
  88.     LOOP
  89.  
  90. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  91. SUB UsureToLeave ()
  92.  
  93.     COLOR WHITE
  94.     drawASCIIbox 20, 46, 34, 2, " Are you sure you wan't to leave? ", 3
  95.     LOCATE 22, 47
  96.     PRINT "        <";
  97.     COLOR YELLOW
  98.     PRINT "Y";
  99.     COLOR WHITE
  100.     PRINT ">es         <";
  101.     COLOR YELLOW
  102.     PRINT "N";
  103.     COLOR WHITE
  104.     PRINT ">o        ";
  105.  
  106. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  107. SUB inSegment_1 () ' subroutines for each segment has the name as the user sees it (practical purposes)
  108.  
  109.     DO
  110.         _LIMIT 20
  111.         CLS
  112.         drawInsideSegment 1, 1
  113.         keyPress$ = INKEY$
  114.         _DISPLAY
  115.     LOOP UNTIL keyPress$ = CHR$(27)
  116.     actualSegmentWorking% = -1
  117.  
  118.  
  119. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  120. SUB inSegment_2 () ' subroutines for each segment has the name as the user sees it (practical purposes)
  121.  
  122.     DO
  123.         _LIMIT 20
  124.         CLS
  125.         drawInsideSegment 2, 1
  126.         keyPress$ = INKEY$
  127.         _DISPLAY
  128.     LOOP UNTIL keyPress$ = CHR$(27)
  129.     actualSegmentWorking% = -1
  130.  
  131.  
  132. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  133. SUB drawInsideSegment (ins%, outs%) ' when you get inside a segment you see this (pass in the number of inputs and outputs)
  134.  
  135.     IF ins% > 3 THEN EXIT SUB '  ¿                Ú REM if only 1 output, you can have up to 3 inputs
  136.     IF outs% < 1 THEN EXIT SUB ' ³ check if logic ³ for  2 outputs only 1 input... video thing really,
  137.     IF outs% > 2 THEN EXIT SUB ' Ù                À ELSE overprinting
  138.  
  139.     COLOR MIDGRAY '                                                      ¿
  140.     LOCATE 2, 9 '                                                        ³ title and
  141.     PRINT "- SEGMENT "; LTRIM$(STR$(actualSegmentWorking% + 1)); " -"; ' ³ segment name
  142.     LOCATE 3, 9 '                                                        ³
  143.     PRINT "- "; segmentName$(actualSegmentWorking%); " -" '              Ù
  144.  
  145.     drawASCIIbox 4, 2, 25, 6, "", 2 'draw the instructions box
  146.  
  147.     FOR nY% = 4 TO 34 STEP 15 '      ¿
  148.         FOR nX% = 31 TO 106 STEP 25 '³ draw nodes at
  149.             drawNodeV21 nY%, nX% '   ³ corresponding
  150.         NEXT nX% '                   ³ position
  151.     NEXT nY% '                       Ù
  152.  
  153.     IF ins% > 0 THEN '                                                ¿
  154.         ii% = 2 '                               ¿                     ³
  155.         FOR i% = 1 TO ins% '                    ³ print as many       ³
  156.             LOCATE 13, ii% + 1 '                ³ ASCII boxes as      ³
  157.             PRINT "IN."; CHR$(96 + i%); '       ³ inputs needed and   ³
  158.             drawASCIIbox 14, ii%, 4, 25, "", 2 '³ a title "IN" +      ³
  159.             ii% = ii% + 5 '                     ³ a, b, c, d...       ³
  160.         NEXT i% '                               Ù                     ³
  161.         '                                                             ³
  162.         IF ins% > 1 THEN '             ¿                              ³
  163.             ii% = 7 '                  ³                              ³ INPUTS
  164.             FOR i% = 1 TO ins% - 1 '   ³ correct                      ³ table
  165.                 LOCATE 14, ii% '       ³ corners                      ³
  166.                 PRINT CHR$(203); ' Ë   ³ if                           ³
  167.                 LOCATE 40, ii% '       ³ needed                       ³
  168.                 PRINT CHR$(202); ' Ê   ³                              ³
  169.                 ii% = ii% + 5 '        ³                              ³
  170.             NEXT i% '                  ³                              ³
  171.         END IF '                       Ù                              ³
  172.     END IF '                                                          Ù
  173.  
  174.     LOCATE 13, 21 '                     ¿            ¿
  175.     PRINT "OUT.x"; '                    ³ rightmost  ³
  176.     drawASCIIbox 14, 23, 4, 25, "", 2 ' ³            ³
  177.     drawASCIIbox 14, 18, 4, 25, "", 2 ' Ù            ³
  178.     '                                                ³
  179.     LOCATE 14, 23 '      ¿                           ³
  180.     PRINT CHR$(203); ' Ë ³ corner correction         ³
  181.     LOCATE 40, 23 '      ³ for rightmost             ³
  182.     PRINT CHR$(202); ' Ê Ù                           ³
  183.     '                                                ³
  184.     IF outs% = 2 THEN ' only if asked for            ³
  185.         LOCATE 13, 11 ' ¿                            ³
  186.         PRINT "OUT.x"; '³ "OUT.y" overprinted        ³
  187.         LOCATE 13, 21 ' ³ rightmost "OUT.x"          ³ OUTPUTS
  188.         PRINT "OUT.y"; 'Ù                            ³ table
  189.         drawASCIIbox 14, 13, 4, 25, "", 2 '          ³
  190.         drawASCIIbox 14, 8, 4, 25, "", 2 '           ³
  191.         '                                            ³
  192.         LOCATE 14, 18 '      ¿                       ³
  193.         PRINT CHR$(203); ' Ë ³                       ³
  194.         LOCATE 14, 13 '      ³ corner                ³
  195.         PRINT CHR$(203); ' Ë ³ correction            ³
  196.         LOCATE 40, 18 '      ³ for                   ³
  197.         PRINT CHR$(202); ' Ê ³ both                  ³
  198.         LOCATE 40, 13 '      ³                       ³
  199.         PRINT CHR$(202); ' Ê Ù                       ³
  200.     END IF '                                         Ù
  201.  
  202.     FOR k% = 9 TO 39 STEP 15 ' Y        ¿            ¿
  203.         FOR j% = 53 TO 103 STEP 25 ' X  ³            ³
  204.             LOCATE k%, j% '             ³            ³
  205.             PRINT CHR$(26); '          ³ left/right ³
  206.             LOCATE k% + 2, j% + 1 '     ³ PORTS      ³
  207.             PRINT CHR$(27); '          ³            ³
  208.         NEXT j% '                       ³            ³ PORTS
  209.     NEXT k% '                           Ù            ³ between
  210.     '                                                ³ NODES
  211.     FOR k% = 18 TO 33 STEP 15 ' Y       ¿            ³
  212.         FOR j% = 38 TO 113 STEP 25 '    ³            ³
  213.             LOCATE k%, j% '             ³ up/down    ³
  214.             PRINT CHR$(24); '          ³ PORTS      ³
  215.             LOCATE k% - 1, j% + 4 '     ³            ³
  216.             PRINT CHR$(25); '          ³            ³
  217.         NEXT j% '                       ³            ³
  218.     NEXT k% '                           Ù            Ù
  219.  
  220.     IF ins% > 0 THEN LOCATE 2, 62: PRINT "IN.a"; CHR$(25); '   ¿
  221.     IF ins% > 1 THEN LOCATE 2, 87: PRINT "IN.b"; CHR$(25); '   ³
  222.     IF ins% > 2 THEN LOCATE 2, 112: PRINT "IN.c"; CHR$(25); '  ³ IN/OUT
  223.     '                                                          ³ ports
  224.     LOCATE 47, 87: PRINT "OUT.x"; CHR$(25); '                  ³
  225.     IF outs% > 1 THEN LOCATE 47, 62: PRINT "OUT.y"; CHR$(25);
  226.  
  227.     drawASCIIbox 41, 4, 2, 1, (CHR$(16) + CHR$(16)), 1 '    ¿
  228.     drawASCIIbox 41, 14, 2, 1, (CHR$(124) + CHR$(16)), 1 '  ³
  229.     drawASCIIbox 41, 24, 2, 1, (CHR$(219) + CHR$(219)), 1 ' ³
  230.     LOCATE 44, 3 '                                          ³
  231.     PRINT "F5 Run"; '                                       ³
  232.     LOCATE 44, 12 '                                         ³ BUTTONS
  233.     PRINT "F6 Step"; '                                      ³
  234.     LOCATE 44, 22 '                                         ³
  235.     PRINT "F8 Stop"; '                                      ³
  236.     COLOR DARKGRAY '                                        ³
  237.     LOCATE 45, 9 '                                          ³
  238.     PRINT "ESC to go back"; '                               Ù
  239.  
  240.     'COLOR RED
  241.     'drawASCIIbox 46, 2, 27, 1, "", 1 this is where IDE box should appear if invalidOpcode
  242.  
  243.  
  244. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  245. SUB infect () ' virus intro sketch... base under attack!
  246.  
  247.     row% = 20
  248.     column% = 52
  249.     message1$ = "I'm taking control..."
  250.     message2$ = "And you can't stop me"
  251.  
  252.     'sayHello
  253.     COLOR GREEN '                                    ¿ try to
  254.     PRINTslowly row% + 3, column% + 2, message1$, 1 '³ psychopatiate
  255.     PRINTslowly row% + 4, column% + 2, message2$, 1 'Ù the user
  256.     SLEEP 1
  257.  
  258.     'install
  259.     i% = 0
  260.     ii% = 0
  261.     loadingBar$ = CHR$(219)
  262.     DO
  263.         _LIMIT 500
  264.         i% = i% + 1
  265.         ii% = INT(i% / 100)
  266.  
  267.         COLOR MIDGRAY '                             ¿
  268.         LOCATE RND(1) * 47 + 1, RND(1) * 127 + 1 '  ³ random characthers on the back
  269.         PRINT CHR$(RND(1) * 222 + 32); '            Ù
  270.  
  271.         COLOR GREEN '    a virus is GREEN!       ¿
  272.         '                                         ³ draw box and
  273.         drawASCIIbox row%, column%, 23, 7, "", 2 '³ CLS inside it
  274.         '                                         ³ (don't erease back)
  275.         fakeCLS row% + 1, column% + 1, 22, 6 '    Ù
  276.  
  277.         IF ii% MOD 2 = 0 THEN '                   ¿
  278.             LOCATE row% + 1, column% + 2 '        ³ blink: title
  279.             PRINT "CV64 VIRUS V0.2  >:-["; '      ³ underline
  280.             LOCATE row% + 2, column% + 2 '        ³ message1$
  281.             PRINT STRING$(21, CHR$(223)); '       ³ and
  282.             '                                     ³ message2$
  283.             LOCATE row% + 3, column% + 2 '        ³
  284.             PRINT message1$; '                    ³
  285.             '                                     ³
  286.             LOCATE row% + 4, column% + 2 '        ³
  287.             PRINT message2$; '                    ³
  288.         END IF '                                  Ù
  289.  
  290.         LOCATE row% + 6, column% + 2 '                              ¿
  291.         IF ii% < 20 THEN PRINT "Overriding OS..."; '                ³
  292.         IF ii% < 40 AND ii% > 19 THEN PRINT "Accesing files..."; '  ³ loading messages
  293.         IF ii% < 60 AND ii% > 39 THEN PRINT "Infecting..."; '       ³
  294.         IF ii% < 80 AND ii% > 59 THEN PRINT "Replicating..."; '     ³
  295.         IF ii% < 100 AND ii% > 79 THEN PRINT "Ereasing nodes..."; ' ³
  296.         IF ii% = 100 THEN PRINT "Nodes killed "; '                 Ù
  297.  
  298.         ii$ = LTRIM$(STR$(ii%)) '                   ¿
  299.         LOCATE row% + 6, column% + 22 - LEN(ii$) '  ³ xx%
  300.         PRINT ii$ + "%"; '                          Ù
  301.  
  302.         IF i% MOD 500 = 0 THEN loadingBar$ = loadingBar$ + CHR$(219) ' ¿
  303.         LOCATE row% + 7, column% + 2 '                                 ³ loading bar
  304.         PRINT loadingBar$; '                                           Ù
  305.         _DISPLAY
  306.     LOOP UNTIL i% = 10000
  307.     SLEEP 2 '                                       infection complete XD
  308.  
  309.  
  310. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  311. SUB systemCheck () ' fake system check as excuse to go at main menu
  312.  
  313.     COLOR LIGHTGRAY
  314.     PRINTslowly 2, 2, "Unexpected restart. Running system check...", 1
  315.     FOR i& = 0 TO 247483647 STEP 2048
  316.         _LIMIT 20000
  317.         LOCATE 4, 2
  318.         PRINT "CHECKSUM: ";: PRINT LTRIM$(STR$(i&));
  319.     NEXT i&
  320.     PRINT " OK"
  321.     PRINTslowly 6, 2, "Nodes have been corrupted...", 1
  322.     PRINTslowly 8, 2, "Reprogram them to recover access to OS...", 1
  323.     PRINTslowly 10, 2, "Please, don't shut down the equipment until reprogramming is over", 1
  324.     PRINTslowly 11, 2, "or all system data won't be able to recover...", 0
  325.     PRINTslowly 13, 2, "Starting debbuger", 1
  326.     SLEEP 2
  327.  
  328.  
  329. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  330. SUB drawSegments () ' draw the segment on the main menu
  331.  
  332.     i% = -1
  333.  
  334.     FOR y% = 3 TO 39 STEP 9
  335.         FOR x% = 4 TO 112 STEP 18
  336.  
  337.             i% = i% + 1 ' node index number, start -1 to make it 0 here for the array
  338.             '              we add another +1 later to make em look like start at 1
  339.             COLOR DARKGRAY '                                  ¿
  340.             FOR yy% = 2 TO 5 '                                ³
  341.                 FOR xx% = 1 TO 11 '                           ³ if node is broke
  342.                     LOCATE y% + yy%, x% + xx% '               ³ random characters
  343.                     IF NOT segmentState%(i%) THEN '           ³
  344.                         PRINT CHR$(RND(1) * 200 + 32); '      ³ if fixed by
  345.                     ELSE '                                    ³ user then
  346.                         PRINT LTRIM$(STR$(_ROUND(RND))); '    ³ plain 1's and 0's
  347.                     END IF '                                  ³
  348.                 NEXT xx% '                                    ³
  349.             NEXT yy% '                                        Ù
  350.  
  351.             IF i% > 8 THEN '                                  ¿ the shown number
  352.                 segmentNumber$ = LTRIM$(STR$(i% + 1)) '       ³ of the segment,
  353.             ELSE '                                            ³ avoiding the
  354.                 segmentNumber$ = " " + LTRIM$(STR$(i% + 1)) ' ³ spaces if
  355.             END IF '                                          Ù two digits
  356.  
  357.             IF menuHighlight% = i% THEN ' ¿
  358.                 COLOR WHITE '             ³ show WHITE if
  359.             ELSE '                        ³ selected, else
  360.                 COLOR MIDGRAY '           ³ is MIDGRAY
  361.             END IF '                      Ù
  362.  
  363.             drawASCIIbox y%, x%, 11, 5, " SEGMENT" + segmentNumber$, 1 ' draw the box
  364.  
  365.             LOCATE y% + 3, x% + 2 '     ¿
  366.             IF segmentState%(i%) THEN ' ³ accordingly to
  367.                 COLOR MIDGRAY, BLACK '  ³ segmentState%()
  368.                 PRINT "-NOMINAL-" '     ³ draw -NOMINAL-
  369.             ELSE '                      ³ or   - ERROR -
  370.                 COLOR BLACK, RED '      ³
  371.                 PRINT " -ERROR- " '     ³
  372.                 COLOR , BLACK '         ³
  373.             END IF '                   Ù
  374.             ' don't conflictuate other stuff
  375.         NEXT x%
  376.     NEXT y%
  377.  
  378.     drawMainInstructions
  379.  
  380.  
  381. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  382. SUB drawMainInstructions () ' draws a single blue line with some instruction on it at the bottom of the screen
  383.  
  384.     COLOR YELLOW, BLUE
  385.  
  386.     FOR ii% = 1 TO 127 '   ¿
  387.         LOCATE 48, ii% '   ³ blue background
  388.         PRINT " "; '       ³ line at bottom
  389.     NEXT ii% '             Ù
  390.  
  391.     LOCATE 48, 25 '             ¿
  392.     PRINT "F1 Help"; '          ³
  393.     LOCATE 48, 43 '             ³ options in
  394.     PRINT "ARROWS Navigate"; '  ³ the main menu
  395.     LOCATE 48, 71 '             ³
  396.     PRINT "ENTER Select"; '     ³
  397.     LOCATE 48, 92 '             ³
  398.     PRINT "F10 Save and Exit";
  399.  
  400.     COLOR , BLACK ' don't conflictuate with other things
  401.  
  402.  
  403. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  404. SUB drawNodeV21 (nodeY%, nodeX%)
  405.  
  406.     COLOR MIDGRAY
  407.  
  408.     drawASCIIbox nodeY%, nodeX%, 14, 11, "", 1 ' user input instructions box
  409.     drawASCIIbox nodeY%, nodeX% + 15, 4, 2, "ACC", 1 '     ¿
  410.     drawASCIIbox nodeY% + 3, nodeX% + 15, 4, 2, "BAK", 1 ' ³ box over
  411.     drawASCIIbox nodeY% + 6, nodeX% + 15, 4, 2, "MODE", 1 '³ box
  412.     drawASCIIbox nodeY% + 9, nodeX% + 15, 4, 2, "LAST", 1
  413.  
  414.     LOCATE nodeY%, nodeX% + 15 '            ¿
  415.     PRINT CHR$(194); ' Â                    ³
  416.     LOCATE nodeY% + 12, nodeX% + 15 '       ³
  417.     PRINT CHR$(193); ' Á                    ³
  418.     '                                       ³ then correct
  419.     FOR i% = 3 TO 9 STEP 3 '                ³ the corners
  420.         LOCATE nodeY% + i%, nodeX% + 15 '   ³ nedded
  421.         PRINT CHR$(195); ' Ã                ³
  422.     NEXT i% '                               ³ (the usual
  423.     '                                       ³ deciving)
  424.     FOR i% = 3 TO 9 STEP 3 '                ³
  425.         LOCATE nodeY% + i%, nodeX% + 20 '   ³
  426.         PRINT CHR$(180); ' ´                ³
  427.     NEXT i% '                               Ù
  428.  
  429.  
  430. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  431. SUB PRINTslowly (originY%, originX%, message$, preBlink%)
  432.  
  433.     IF originY% < 1 THEN EXIT SUB '     ¿ check if logic
  434.     IF originX% < 1 THEN EXIT SUB '     Ù
  435.  
  436.     IF preBlink% = 1 THEN PCthinking originY%, originX% ' wanna see some blinking before start writing?
  437.  
  438.     i% = 0 '                                                Ä¿
  439.     DO '                                                     ³
  440.         _DELAY .05 '                                         ³
  441.         i% = i% + 1 '                                        ³ print message$
  442.         buildingMessage$ = LEFT$(message$, i%) + CHR$(219) ' ³ character by character
  443.         LOCATE originY%, originX% '                          ³ and erease the cursor
  444.         PRINT buildingMessage$; '                            ³
  445.     LOOP UNTIL LEN(buildingMessage$) = LEN(message$) + 1 '  ÄÙ
  446.  
  447.     LOCATE CSRLIN, originX% + LEN(message$): PRINT " "; ' erease cursor
  448.  
  449.  
  450. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  451. SUB PCthinking (originY%, originX%)
  452.  
  453.     IF originY% < 1 THEN EXIT SUB '     ¿ check if logic
  454.     IF originX% < 1 THEN EXIT SUB '     Ù
  455.  
  456.     FOR i% = 1 TO 11 '                  ¿
  457.         _LIMIT 5 '                      ³
  458.         LOCATE originY%, originX% '     ³
  459.         IF i% MOD 2 = 0 THEN '          ³ bliking cursor
  460.             PRINT CHR$(219); '          ³
  461.         ELSE '                          ³
  462.             PRINT " "; '                ³
  463.         END IF '                        ³
  464.     NEXT i% '                           Ù
  465.  
  466.  
  467. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  468. SUB fakeCLS (originY%, originX%, width%, height%)
  469.  
  470.     IF originY% < 1 THEN EXIT SUB '               ¿
  471.     IF originX% < 1 THEN EXIT SUB '               ³ check if logic
  472.     IF width% < 1 THEN EXIT SUB '                 ³
  473.     IF height% < 1 THEN EXIT SUB '                Ù
  474.  
  475.     FOR x% = 0 TO width% '                        ¿
  476.         FOR y% = 0 TO height% '                   ³ print
  477.             LOCATE originY% + y%, originX% + x% ' ³ " " (space)
  478.             PRINT " "; '                          ³ repeatedly
  479.         NEXT y% '                                 ³
  480.     NEXT x% '                                     Ù
  481.  
  482.  
  483. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  484. SUB drawASCIIbox (originY%, originX%, width%, height%, message$, style%)
  485.  
  486.     IF originY% < 1 OR originX% < 1 THEN EXIT SUB '     ÄÄÄ¿
  487.     IF width% < 1 OR height% < 1 THEN EXIT SUB '           ³ check if logic
  488.     IF style% < 1 OR style% > 3 THEN EXIT SUB '         ÄÄÄÙ
  489.  
  490.     LOCATE originY%, originX% '                         ÄÄÄ¿
  491.     IF style% = 1 THEN PRINT CHR$(218); 'Ú                 ³
  492.     IF style% = 2 THEN PRINT CHR$(201); ' É   up,left      ³
  493.     '                                                      ³
  494.     LOCATE originY% + height% + 1, originX% '              ³
  495.     IF style% = 1 THEN PRINT CHR$(192); ' À                ³
  496.     IF style% = 2 THEN PRINT CHR$(200); ' È  down, left    ³ corners
  497.     '                                                      ³
  498.     LOCATE originY%, originX% + width% + 1 '               ³
  499.     IF style% = 1 THEN PRINT CHR$(191); ' ¿                ³
  500.     IF style% = 2 THEN PRINT CHR$(187); ' » up, right      ³
  501.     '                                                      ³
  502.     LOCATE originY% + height% + 1, originX% + width% + 1 ' ³
  503.     IF style% = 1 THEN PRINT CHR$(217); ' Ù                ³
  504.     IF style% = 2 THEN PRINT CHR$(188); ' ¼ down, right ÄÄÄÙ
  505.  
  506.     IF style% = 1 THEN char% = 179 ' ³                  ÄÄÄ¿
  507.     IF style% = 2 THEN char% = 186 ' º  determinate style  ³
  508.     IF style% = 3 THEN char% = 219 ' Û                     ³
  509.     FOR y% = 1 TO height% '                                ³
  510.         LOCATE originY% + y%, originX% ' locate and print  ³ sides
  511.         PRINT CHR$(char%); '                               ³
  512.         LOCATE originY% + y%, originX% + width% + 1 '      ³
  513.         PRINT CHR$(char%); '                               ³
  514.     NEXT y% '                                           ÄÄÄÙ
  515.  
  516.     IF style% < 3 THEN ' styles 1 and 2                 ÄÄÄ¿
  517.         IF style% = 1 THEN char% = 196 ' Ä                 ³
  518.         IF style% = 2 THEN char% = 205 ' Í                 ³
  519.         FOR x% = 1 TO width% '                             ³
  520.             LOCATE originY%, originX% + x% '               ³
  521.             PRINT CHR$(char%); '                           ³
  522.             LOCATE originY% + height% + 1, originX% + x% ' ³
  523.             PRINT CHR$(char%); '                           ³ top &
  524.         NEXT x% '                                          ³ bottom
  525.     ELSE ' special case of style 3                         ³
  526.         char1% = 220 ' Ü                                   ³
  527.         char2% = 223 ' ß                                   ³
  528.         FOR x% = 0 TO width% + 1 '                         ³
  529.             LOCATE originY%, originX% + x% '               ³
  530.             PRINT CHR$(char1%); '                          ³
  531.             LOCATE originY% + height% + 1, originX% + x% ' ³
  532.             PRINT CHR$(char2%); '                          ³
  533.         NEXT x% '                                          ³
  534.     END IF '                                            ÄÄÄÙ
  535.  
  536.     LOCATE originY% + 1, originX% + 1 '                 ÄÄÄ¿ message
  537.     PRINT message$; '                                   ÄÄÄÙ
  538.  

Next step is start working on the nodes themselves (i still have no idea of how to do this, but i take suggestions). I unfortunately found that ASCII characters 30 and 31 (▲▼) cannot be printed by QB64, so i took the arrows instead (24 to 27).


Offline Juan Tamarit

  • Newbie
  • Posts: 53
    • View Profile
Re: Trying to imitate TIS-100
« Reply #20 on: September 04, 2020, 03:52:29 am »
Thank God i did everything by SUBs, cause i had to change the screen siza, but was no problem this way. But the thing is getting into a huge web of SUBs (lots of recurrent work).

So here goes my question: now i need a way to inset instructions on the nodes. Besides the pain it will be the cursor position and stuff ¿do you guys think we may achive something usefull with straight INPUT using CSV to hold on the instructions$ array? Or should i look to a more INKEY$ orientated thing?

Consider that the instructions (as i concieve them) are like:

mov,acc,down
sub,acc,1
mov,left,acc

this instructs to move the value from the down port into the accumulator, substratc 1 to it, and then moving the new value to the left port. Synthax would be:

<instruction>,<destination>,<source>

As in original Assembly order (and i think the commas were part of the lenguage too)

If there are other ideas on this too i gladly hear them.

Cheers bros! =)

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Trying to imitate TIS-100
« Reply #21 on: September 04, 2020, 04:54:37 am »
If you’re going to use CSV, you’d probably be better served to use LINE INPUT, instead of just INPUT.  :)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Juan Tamarit

  • Newbie
  • Posts: 53
    • View Profile
Re: Trying to imitate TIS-100
« Reply #22 on: September 04, 2020, 01:27:53 pm »
Thanks for your reply, Mr.McNeill. I'll review the LINE INPUT statement... Have you ever played TIS-100? You know the game? =)

I having more troubles dimensioning things in my mind. Let me explain you guys: we have 35 segments, each one containing 12 nodes, and each node can contain as much as 11 instructions.

So i came up with a 3d array: array(segment,node,instruction)

But i also was considering in using a TYPE for values as ACC,BAK, x, y, etc...

And then again, i can't find the proper way (or neves look logical to me) of doing this. My dream was to include an array for the instruction inside the TYPE (dosn't seem to be possible), an then have a 2d array, just for segment and nodes.

The other day i saw someone using a TYPE inside a TYPE! Pretty interesting, but i dont know if that's the answer for this proyect...

Any opinions on how to make a good variable "thing" for this so called game XD

Offline Juan Tamarit

  • Newbie
  • Posts: 53
    • View Profile
Re: Trying to imitate TIS-100
« Reply #23 on: September 06, 2020, 09:26:08 pm »
ok, i've stepped in the moment when i need to make some sor of text processor to program the nodes, but i till can find a way that fits suitable for making the nodes instruction and the nodes themselves as objetcs (i don't know if what im saying is correct, but im trying). The best i could figura out to the moment was this:

Code: QB64: [Select]
  1. TYPE NODEv21 '                               ¿
  2.     y AS INTEGER '                           ³
  3.     x AS INTEGER '                           ³
  4.     acc AS INTEGER '                         ³
  5.     bak AS INTEGER '                         ³
  6.     mode AS STRING '                         ³
  7.     last AS STRING '                         ³
  8.     inst1 AS STRING '                        ³
  9.     inst2 AS STRING '                        ³
  10.     inst3 AS STRING '                        ³
  11.     inst4 AS STRING '                        ³
  12.     inst5 AS STRING '                        ³
  13.     inst6 AS STRING '                        ³
  14.     inst7 AS STRING '                        ³
  15.     inst8 AS STRING '                        ³
  16.     inst9 AS STRING '                        ³
  17.     inst10 AS STRING '                       ³
  18.     inst11 AS STRING '                       ³
  19. END TYPE '                                   ³
  20. '                                            ³
  21. DIM SHARED nodeV21(34, 11) AS NODEv21 '      ³ NODES
  22. 'nodeV21(segment, node).type                 ³
  23.  

But there's no need to be a programmer to see that this is awfull! Any other form that someone my think? A 3d array was also an option, but it lacks from the 6 first types of variables that are also needed!

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Trying to imitate TIS-100
« Reply #24 on: September 06, 2020, 10:02:16 pm »
Say, ever heard of linked lists? Might wanna go that way on this...
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Trying to imitate TIS-100
« Reply #25 on: September 06, 2020, 10:41:55 pm »
You can save a tiny little program as a single string by Joining the lines using CHR$(10) or CHR$(13) or both to separate the lines. BTW if you PRINT the string the CHR$(10) will separate the lines out on screen.

Then use Split1000 to split the string back out into an array of line or triplets of commands or whatever each string is.
https://www.qb64.org/forum/index.php?topic=1607.0

I've done this with Text from .txt files.

Update with demo:
Code: QB64: [Select]
  1. REDIM s$(2)
  2. s$(0) = "mov,acc,down"
  3. s$(1) = "sub,acc,1"
  4. s$(2) = "mov,left,acc"
  5. jp$ = join$(s$())
  6. PRINT "Here is jp$, a long string (storable in User Defined Type):"
  7. PRINT jp$
  8. REDIM b$(0)
  9. Split jp$, CHR$(10), b$()
  10. PRINT: PRINT "Here is the program in b$() unpacked from long string :"
  11. FOR i = LBOUND(b$) TO UBOUND(b$)
  12.     PRINT b$(i)
  13.  
  14.  
  15. FUNCTION join$ (a() AS STRING)
  16.     FOR i = LBOUND(a) TO UBOUND(a)
  17.         join$ = join$ + a(i) + CHR$(10)
  18.     NEXT
  19.  
  20. 'This SUB will take a given N delimited string, and delimiter$ and creates an array of N+1 strings using the LBOUND of the given dynamic array to load.
  21. 'notes: the loadMeArray() needs to be dynamic string array and will not change the LBOUND of the array it is given.
  22. SUB Split (SplitMeString AS STRING, delim AS STRING, loadMeArray() AS STRING)
  23.     DIM curpos AS LONG, arrpos AS LONG, LD AS LONG, dpos AS LONG 'fix use the Lbound the array already has
  24.     curpos = 1: arrpos = LBOUND(loadMeArray): LD = LEN(delim)
  25.     dpos = INSTR(curpos, SplitMeString, delim)
  26.     DO UNTIL dpos = 0
  27.         loadMeArray(arrpos) = MID$(SplitMeString, curpos, dpos - curpos)
  28.         arrpos = arrpos + 1
  29.         IF arrpos > UBOUND(loadMeArray) THEN REDIM _PRESERVE loadMeArray(LBOUND(loadMeArray) TO UBOUND(loadMeArray) + 1000) AS STRING
  30.         curpos = dpos + LD
  31.         dpos = INSTR(curpos, SplitMeString, delim)
  32.     LOOP
  33.     loadMeArray(arrpos) = MID$(SplitMeString, curpos)
  34.     REDIM _PRESERVE loadMeArray(LBOUND(loadMeArray) TO arrpos) AS STRING 'get the ubound correct
  35.  
  36.  
  37.  
« Last Edit: September 06, 2020, 11:57:45 pm by bplus »

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Trying to imitate TIS-100
« Reply #26 on: September 06, 2020, 11:42:49 pm »
50/50 can be accomplished with:

Code: QB64: [Select]
  1. if rnd > .5 then
  2.      print "You win a banana!"
  3.      print "You win a lemon!"
  4.  

The random number generator is commonly seeded with RANDOMIZE TIMER.
« Last Edit: September 06, 2020, 11:43:50 pm by Richard Frost »
It works better if you plug it in.

Offline Juan Tamarit

  • Newbie
  • Posts: 53
    • View Profile
Re: Trying to imitate TIS-100
« Reply #27 on: September 07, 2020, 10:53:35 pm »
Thank you very much for your replies, good fellas. I keep doing slow and steady progress. I never heard about "linked lists", are these those famous .dll files? The Split-1000 looks very interesting, i'l keep trying to figure out it's logic and see how can i apply it. For the moment im working on the textProcessor(key$) SUB, and this line gives me an "Unhandled error #5, Illegal function call" when it recibes null from INKEY$

    keyAsInteger% = ASC(key$)

Shouldn't it return 0?

I won't post the last code cause still in progress, but you guys would like it. I has some 600 decent lines so far! =) (i'll do some optimization later, FIRST I GOT TO MAKE IT WORK!)

Cheers!

'------- EDIT-------
Posted again before watching the Wiki, sorry.

FROM WIKI: If the function is used to read an empty string value an illegal function call error will occur. INKEY$ returns an empty string when a key is not pressed.

Any ideas on how to make this line to work?:
IF ASC(key$) > 31 AND ASC(key$) < 127 THEN inst$(actualSegmentWorking%, actualNodeWorking%, actualLineWorking%) = inst$(actualSegmentWorking%, actualNodeWorking%, actualLineWorking%) + key$

Some alternate way to ask it?
« Last Edit: September 07, 2020, 11:06:24 pm by Juan Tamarit »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Trying to imitate TIS-100
« Reply #28 on: September 07, 2020, 11:18:53 pm »
Quote
Any ideas on how to make this line to work?:
IF ASC(key$) > 31 AND ASC(key$) < 127 THEN inst$(actualSegmentWorking%, actualNodeWorking%, actualLineWorking%) = inst$(actualSegmentWorking%, actualNodeWorking%, actualLineWorking%) + key$

Code: QB64: [Select]
  1.     IF ASC(key$) > 31 AND ASC(key$) < 127 THEN
  2.         inst$(actualSegmentWorking%, actualNodeWorking%, actualLineWorking%) =_
  3.          inst$(actualSegmentWorking%, actualNodeWorking%, actualLineWorking%) + key$
  4.     END IF

You have to do the same thing when there is a chance you ask an array of an index number outside it's upper or lower bounds. You can't say "IF key$ <> "" and Asc(key$) > 31.... on same line, it has to be separate IF.

« Last Edit: September 07, 2020, 11:23:11 pm by bplus »

Offline Juan Tamarit

  • Newbie
  • Posts: 53
    • View Profile
Re: Trying to imitate TIS-100
« Reply #29 on: September 07, 2020, 11:25:20 pm »
U2pro bro =)