QB64.org Forum

Active Forums => Programs => Topic started by: Juan Tamarit on September 02, 2020, 12:48:12 am

Title: Trying to imitate TIS-100
Post by: Juan Tamarit on September 02, 2020, 12:48:12 am
As i mentioned before i got into QB64 trhu TIS-100, among other things. I'm opening this topic because ill notice that imitate such a game is a huge task and i'm gonna need a lot of learning and help. For the moment i started with an intro, but i'm having problems with CLS (and probably with _DISPLAY too). I don't clearly understand the relation between these statements. In the example i'm posting after the infect() SUB the CLS statement has no effect... why is this happening? (theres also a nice bag of snippets in the end)

Code: QB64: [Select]
  1. '
  2. ----------------------Û   SETUP   Û----------------
  3.  
  4. CONST ScreenWidth = 800 ' check if this values are ok     ÍÍÍ»
  5. CONST ScreenHeight = 608 '                                   º
  6. '                                                            º
  7. SCREEN _NEWIMAGE(ScreenWidth, ScreenHeight, 32) '            º        ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
  8. _FULLSCREEN '                                                º        º                 º
  9. '                                                            º        º1,1    TEXT       º
  10. CONST WHITE = _RGB32(255, 255, 255) '                        º VIDEO  º      SCREEN      º
  11. CONST MIDGRAY = _RGB32(127, 127, 127) '                      º        º          38y,100xº
  12. CONST DARKGRAY = _RGB32(63, 63, 63) '                        º        º                 º
  13. CONST LIGHTGRAY = _RGB32(191, 191, 191) '                    º        ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
  14. CONST RED = _RGB32(127, 0, 0) '                              º
  15. CONST GREEN = _RGB32(0, 127, 0) '                         ÍÍͼ
  16. '----------------------------------Û   PROGRAM   Û---------------------------------
  17. infect
  18. systemCheck
  19.  
  20.  
  21. '--------------------------------Û SUBROUTINES Û---------------------------
  22. SUB infect () ' intro sketch
  23.  
  24.     row% = 15
  25.     column% = 38
  26.     message1$ = "I'm taking control..."
  27.     message2$ = "And you can't stop me"
  28.  
  29.     'sayHello
  30.     COLOR GREEN
  31.     PRINTslowly row% + 3, column% + 2, message1$
  32.     PRINTslowly row% + 4, column% + 2, message2$
  33.     SLEEP 1
  34.  
  35.     'install
  36.     i% = 0
  37.     ii% = 0
  38.     loadingBar$ = CHR$(219)
  39.     DO
  40.         i% = i% + 1
  41.         ii% = INT(i% / 100)
  42.         _LIMIT 500
  43.  
  44.         COLOR MIDGRAY '                             ¿
  45.         LOCATE RND(1) * 37 + 1, RND(1) * 99 + 1 '   ³ random characthers on the back
  46.         PRINT CHR$(RND(1) * 222 + 32); '            Ù
  47.  
  48.         COLOR GREEN '    a virus is GREEN! 
  49.  
  50.         drawDoubleLineBox row%, column%, 23, 7, ""
  51.         fakeCLS row% + 1, column% + 1, 22, 6
  52.  
  53.         IF ii% MOD 2 = 0 THEN '                   ¿
  54.             LOCATE row% + 1, column% + 2 '        ³ blink: title
  55.             PRINT "CV64 VIRUS V0.2  >:-["; '      ³ underline
  56.             LOCATE row% + 2, column% + 2 '        ³ message1$
  57.             PRINT STRING$(21, CHR$(223)); '       ³ and
  58.             '                                     ³ message2$
  59.             LOCATE row% + 3, column% + 2 '        ³
  60.             PRINT message1$; '                    ³
  61.             '                                     ³
  62.             LOCATE row% + 4, column% + 2 '        ³
  63.             PRINT message2$; '                    Ù
  64.  
  65.         END IF
  66.  
  67.         LOCATE row% + 6, column% + 2 '                              ¿
  68.         IF ii% < 20 THEN PRINT "Overriding OS..."; '                ³
  69.         IF ii% < 40 AND ii% > 19 THEN PRINT "Accesing files..."; '  ³ loading messages
  70.         IF ii% < 60 AND ii% > 39 THEN PRINT "Infecting..."; '       ³
  71.         IF ii% < 80 AND ii% > 59 THEN PRINT "Replicating..."; '     ³
  72.         IF ii% < 100 AND ii% > 79 THEN PRINT "Ereasing nodes..."; ' ³
  73.         IF ii% = 100 THEN PRINT "Nodes killed "; '                 Ù
  74.  
  75.         ii$ = LTRIM$(STR$(ii%)) '                   ¿
  76.         LOCATE row% + 6, column% + 22 - LEN(ii$) '  ³ xx%
  77.         PRINT ii$ + "%"; '                          Ù
  78.  
  79.         IF i% MOD 500 = 0 THEN loadingBar$ = loadingBar$ + CHR$(219) ' ¿
  80.         LOCATE row% + 7, column% + 2 '                                 ³ loading bar
  81.         PRINT loadingBar$; '                                           Ù
  82.  
  83.         _DISPLAY
  84.     LOOP UNTIL i% = 10000
  85.     SLEEP 2 '                                       infection complete XD
  86.  
  87.  
  88. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  89. SUB systemCheck () ' fake system check as excuse to go at main menu
  90.  
  91.     COLOR LIGHTGRAY
  92.     PRINTslowly 2, 2, "Unexpected restart. Check system..."
  93.  
  94.     FOR i& = 0 TO 247483647 STEP 2048
  95.         _LIMIT 20000
  96.         LOCATE 4, 2
  97.         PRINT "CHECKSUM: ";: PRINT LTRIM$(STR$(i&));
  98.     NEXT i&
  99.     PRINT " OK"
  100.  
  101.     PRINTslowly 6, 2, "Some nodes have been corrupted..."
  102.     PRINTslowly 7, 2, "Reprogram them to recover access to OS..."
  103.     PRINTslowly 9, 2, "Starting debbuger"
  104.  
  105.     SLEEP 1
  106.  
  107.  
  108. 'ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÛ   SNIPPETS    ÛÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
  109. 'save time over recurring things
  110. '----------------------------Û  SUBROUTINES  Û-----------------------
  111. SUB drawDoubleLineBox (originY%, originX%, width%, height%, message$)
  112.  
  113.     IF originY% < 1 THEN EXIT SUB '                     ÄÄÄ¿
  114.     IF originX% < 1 THEN EXIT SUB '                        ³ check if logic
  115.     IF width% < 1 THEN EXIT SUB '                          ³
  116.     IF height% < 1 THEN EXIT SUB '                      ÄÄÄÙ
  117.  
  118.     LOCATE originY%, originX% '                         ÄÄÄ¿
  119.     PRINT CHR$(201); ' É                                   ³
  120.     LOCATE originY% + height% + 1, originX% '              ³
  121.     PRINT CHR$(200); ' È                                   ³ corners
  122.     LOCATE originY%, originX% + width% + 1 '               ³
  123.     PRINT CHR$(187); ' »                                   ³
  124.     LOCATE originY% + height% + 1, originX% + width% + 1 ' ³
  125.     PRINT CHR$(188); ' ¼                                ÄÄÄÙ
  126.  
  127.     FOR y% = 1 TO height% '                             ÄÄÄ¿
  128.         LOCATE originY% + y%, originX% '                   ³
  129.         PRINT CHR$(186); ' º                               ³ sides
  130.         LOCATE originY% + y%, originX% + width% + 1 '      ³
  131.         PRINT CHR$(186); ' º                               ³
  132.     NEXT y% '                                           ÄÄÄÙ
  133.  
  134.     FOR x% = 1 TO width% '                              ÄÄÄ¿
  135.         LOCATE originY%, originX% + x% '                   ³
  136.         PRINT CHR$(205); ' Í                               ³ top &
  137.         LOCATE originY% + height% + 1, originX% + x% '     ³ bottom
  138.         PRINT CHR$(205); ' Í                               ³
  139.     NEXT x% '                                           ÄÄÄÙ
  140.  
  141.     LOCATE originY% + 1, originX% + 1 '                 ÄÄÄ¿ message
  142.     PRINT message$ '                                    ÄÄÄÙ
  143.  
  144.  
  145. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  146. SUB PRINTslowly (originY%, originX%, message$)
  147.  
  148.     IF originY% < 1 THEN EXIT SUB '     ¿ check if logic
  149.     IF originX% < 1 THEN EXIT SUB '     Ù
  150.  
  151.     PCthinking originY%, originX%
  152.  
  153.     i% = 0 '                                                Ä¿
  154.     DO '                                                     ³
  155.         _DELAY .05 '                                         ³
  156.         i% = i% + 1 '                                        ³ print message$
  157.         buildingMessage$ = LEFT$(message$, i%) + CHR$(219) ' ³ character by character
  158.         LOCATE originY%, originX% '                          ³ and erease the cursor
  159.         PRINT buildingMessage$; '                            ³
  160.     LOOP UNTIL LEN(buildingMessage$) = LEN(message$) + 1 '  ÄÙ
  161.  
  162.     LOCATE CSRLIN, originX% + LEN(message$): PRINT " "; ' erease cursor
  163.  
  164.  
  165. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  166. SUB PCthinking (originY%, originX%)
  167.  
  168.     IF originY% < 1 THEN EXIT SUB '     ¿ check if logic
  169.     IF originX% < 1 THEN EXIT SUB '     Ù
  170.  
  171.     FOR i% = 1 TO 11 '                  ¿
  172.         _LIMIT 5 '                      ³
  173.         LOCATE originY%, originX% '     ³
  174.         IF i% MOD 2 = 0 THEN '          ³ bliking cursor
  175.             PRINT CHR$(219); '          ³
  176.         ELSE '                          ³
  177.             PRINT " "; '                ³
  178.         END IF '                        ³
  179.     NEXT i% '                           Ù
  180.  
  181.  
  182. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  183. SUB fakeCLS (originY%, originX%, width%, height%)
  184.  
  185.     IF originY% < 1 THEN EXIT SUB '               ¿
  186.     IF originX% < 1 THEN EXIT SUB '               ³ check if logic
  187.     IF width% < 1 THEN EXIT SUB '                 ³
  188.     IF height% < 1 THEN EXIT SUB '                Ù
  189.  
  190.     FOR x% = 0 TO width% '                        ¿
  191.         FOR y% = 0 TO height% '                   ³ print
  192.             LOCATE originY% + y%, originX% + x% ' ³ " " (space)
  193.             PRINT " "; '                          ³ repeatedly
  194.         NEXT y% '                                 ³
  195.     NEXT x% '                                     Ù
  196.  
  197.  
  198.  
Title: Re: Trying to imitate TIS-100
Post by: bplus on September 02, 2020, 02:24:20 am
CLS is just clear screen, if want to change background color set backcolor:
Code: QB64: [Select]
  1. COLOR ,&HFFFFFF00 'yellow
  2.  
or just CLS to clear last loop

_DISPLAY ' all screen updates in usually a loop wait until it comes to _DISPLAY this prevents flashing or blinking if you CLS allot.

This means if you print something and need to see it immediately before usually the end of a loop you have to say
_DISPLAY right after the print.

So once you _DISPLAY, you have to _DISPALY every time you want a screen update but you can turn _DISPLAY off with _AUTODISPLAY which is default screen mode.
Title: Re: Trying to imitate TIS-100
Post by: Juan Tamarit on September 02, 2020, 03:30:24 am
brother!! ;-))

You are my new programming lenguage, i will call you "B+" (why QB64 wasn't named like this? It has a lot more of punch! At least phonetycally XD)

Thank you very much for your explanation, i get perfectly the idea. So _DISPLAY is like an OFF switch, _AUTODISPLAY an ON switch, and CLS just erease the screen, and i got to make combinatios of this 3 statements. If i _DISPLAY once i wont see changes until next _DISPLAY, or _AUTODISPLAY (flicker will be back if i _AUTODISPLAY). This is great info!!!

Did I understood correctly?
Title: Re: Trying to imitate TIS-100
Post by: bplus on September 02, 2020, 03:49:55 am
Pretty close, I would describe _Display as a wait until I say _Display switch :-))

_AUTODISPLAY, automatic draw or print, no waiting switch.

In main animation loop, I usually:

Code: QB64: [Select]
  1.   cls
  2.   draw and print stuff...
  3.   _limit 60 ' loop around 60 times a second or another wait to keep sequence steady
  4.                 'assuming you can draw and print faster this save CPU fan from coming on also
Title: Re: Trying to imitate TIS-100
Post by: Juan Tamarit on September 02, 2020, 04:03:54 am
Right, right... So, let me see if i get now: once _DISPLAY is found it actualizes the screen, from now on until _DISPLAY isn't found again nothing that is printed will be show in the screen until the next _DISPLAY. In the loop this happens continously. And once you leave the loop if you wanna see further printing you have to _AUTODISPLAY and CLS, keep printing and CLSing the usual newbie way (my way XD, or now that i think it you called it "Default screen mode")..., until the next loop, wich surely will contain another _DISPLAY, and then again when out of the loop for non-looping printing i come back to the _AUTODISPLAY mode.

Better? :P Or i'm messing things up? lol

Thank you for your teachings and time

Another question by the way: is there any diference between:

SUB subroutineName
    <code>
END SUB

and

SUB subroutineName ()
    <code>
END SUB

Does the parenthesis means something?
Title: Re: Trying to imitate TIS-100
Post by: Richard Frost on September 02, 2020, 07:07:01 am
You have a clear and interesting way of commenting code.  I've never seen it before.  Doesn't
it slow you down to find the right symbols? 

Most of your variables are integers.  You could save yourself a lot of typing % by starting off
your code with DEFINT A-Z.

I don't believe there's any difference with a SUB to include ().  The IDE will flag any discrepancy
if you DO have parameters and don't call the sub with parameters, or the other way around, as
you've probably noticed already.


Title: Re: Trying to imitate TIS-100
Post by: bplus on September 02, 2020, 11:02:13 am
Quote
SUB subroutineName ()
    <code>
END SUB

Does the parenthesis means something?

The (parenthesis) are meant to contain parameters for instance:
Code: QB64: [Select]
  1. SUB mySub(parameter1%, parameter2 as _UNSIGNED LONG, parameter3 AS STRING)

If the SUB does not need any, they are not used
Code: QB64: [Select]
  1. SUB Hello
  2.     PRINT "Hello World!"

One very important thing to keep in mind is if the arguments passed through the SUB with a variable of the same type as the SUB's Parameter AND that variable gets changed in the SUB, that change will be passed back into the main program with variable's value changed, some PL's (Programming Languages) dont do that.

Demo
Code: QB64: [Select]
  1. DEFINT A-Z
  2.  
  3. PRINT " Here in main x, y are integers I will modify in SUB Hello."
  4. x = 1: y = 1
  5. PRINT "x, y before call to Hello "; x; ","; y ' 1, 1
  6. Hello x, y ' 2, 2
  7. PRINT "After Hello SUB call x, y are:"; x; ","; y '1, 2    x did not get changed because different Type
  8.  
  9. SUB Hello (x AS LONG, y AS INTEGER)
  10.     PRINT "Hello World!, I am going to increment x and y you sent me but,"
  11.     PRINT "check them out back in the main program."
  12.     x = x + 1: y = y + 1
  13.     PRINT "In Hello SUB x, y are now:"; x; ","; y
  14.  
  15.  
Title: Re: Trying to imitate TIS-100
Post by: bplus on September 02, 2020, 03:18:06 pm
You have a clear and interesting way of commenting code.  I've never seen it before.  Doesn't
it slow you down to find the right symbols? 

Most of your variables are integers.  You could save yourself a lot of typing % by starting off
your code with DEFINT A-Z.

I don't believe there's any difference with a SUB to include ().  The IDE will flag any discrepancy
if you DO have parameters and don't call the sub with parameters, or the other way around, as
you've probably noticed already.

@Juan Tamarit

Yes +1, those comments may be even better than Terry's! Truly unique and it does look like it takes quite an effort unless you have shortcuts, a special editor?

Suffixes are nice for tracking Type as you code but % for integers drives me crazy (also ~&for _UNSIGNED LONG).
Title: Re: Trying to imitate TIS-100
Post by: Juan Tamarit on September 02, 2020, 05:00:39 pm
Thank you for your replies, guys. The way i comment dosnt really shine here on the forum. The "
Code: QB64: [Select]
  1.  
" dosnt show how i actually see he comments. I have an Ascii table at hand, i also use the INSERT key to change cursor function (if it fits me better) and then just Alt+ ASCII code. After doin some commenting you start to remember some combinations and turn easier.

things like:

FOR i% = 0 TO 20 ' ┐ comment entire
    array(i%) = 1 '   │ block here
NEXT i% '               ┘

i THINK them literally as "ALT191", "ALT179", and so...

But i do this lately, for a begginer commenting line by line sound lke a better idea. I have also seen a conference/class by Uncle Bob who was talking about "Clean code", and he did some mentions on comments. I recall things he said, like:

"If you see "for i = 0, i = 23, i++  ' increase counter" it's rather a stupid comment, and unnecessary. Comment things that really need to be commented. Else, read the code... the code is self explainatorie (and if not it's a disaster)."

Also i'm a hobbist, i don't have any rush to finish anything. I can sit for half hour just watching the code and thinking how can i say and ask for things in the most short and easier way, as long as they are self explainatorie. If it's a cryptic mess i try to rearrenge it to looks cleaner at view... and for the processor too.

About variable types with suffixes, i feel more comftable with them, i feel that i can keep track not just the variable name BUT ALSO IT'S TYPE, so i may have a variable name "number$" and another called "number%" (even this is dangerous)

B+: what you told me about SUB's make me remember about the SHARED stuff, so my question would be ¿If you have a variable on main program and another with same name, but inside a SUB, does the variable in main program seems affected by this other one? (as if the variable in the SUB were the main program one)?
Title: Re: Trying to imitate TIS-100
Post by: bplus on September 02, 2020, 06:01:17 pm
Quote
B+: what you told me about SUB's make me remember about the SHARED stuff, so my question would be ¿If you have a variable on main program and another with same name, but inside a SUB, does the variable in main program seems affected by this other one? (as if the variable in the SUB were the main program one)?

Yes a variable x say, in a SUB is private to an x in the main and other subs unless:
The variable is DIM SHARED in the main or the SUB shares with the main.
Or it is passed to the SUB (or FUNCTION) in the arguments list.
CONST declared in main is shared throughout file.

I feel like I am forgetting something? about a sub sharing with Main. I don't usually use that option, I usually go completely private or completely shared for a variable. But I imagine in extremely large programs one may want to have limited sharing.
Title: Re: Trying to imitate TIS-100
Post by: Juan Tamarit on September 02, 2020, 06:23:16 pm
Or it is passed to the SUB (or FUNCTION) in the arguments list.

Now this is interesting. So if i pass a variable to a SUB (i won't consider the FUNCTION case for now) and the names are the same in main code AND in the argument list of the SUB (next to the SUB name) the variable on main code will be affected by whatever happens inside the SUB?

PD: Terry can't be superated!!! XD I was thinking in starting a topic for a program that teaches QB64, said like an asistant/teacher, following more or less Terrie's didactic sequence. I'm also a teacher, you know? I teach Chemistry at high-school =)
Title: Re: Trying to imitate TIS-100
Post by: bplus on September 02, 2020, 06:46:57 pm
Quote
Now this is interesting. So if i pass a variable to a SUB (i won't consider the FUNCTION case for now) and the names are the same in main code AND in the argument list of the SUB (next to the SUB name) the variable on main code will be affected by whatever happens inside the SUB?

Yes if the name and TYPE is the same, see the Hello demo above, same with FUNCTION.

Keep this in mind if you plan on changing the value in the SUB or FUNCTION, this BTW can be an advantage making a SUB behave a bit like a FUNCTION by returning output stuff in the variables that match Type as defined in parameters list.

I wonder what happened to Terry, he asked about using a Pong paddle modification some months ago, haven't heard from him since?
Title: Re: Trying to imitate TIS-100
Post by: Juan Tamarit on September 02, 2020, 07:28:04 pm
I didn't knew about this DEFINT statement, i will try it in further proyetcs.

ok, the Hello Demo was clear, tried changing it and works the same, ill have this into consideration. Thanks for the warning or bad unexplainable things couuld have happened.

By the way, you may found this interesting. I did a small snippet for the INKEY$. It's a function that get no parameters, but return the INKEY$      =)

Code: QB64: [Select]
  1. FUNCTION getINKEY$ ()
  2.  
  3.     DO
  4.         _LIMIT 20
  5.         keyPress$ = INKEY$
  6.     LOOP UNTIL keyPress$ <> ""
  7.  
  8.     getINKEY$ = keyPress$
  9.  
  10.  

But shurely you already knew this.

Another question! How can i get a 1 or 0 50/50 chance? I seem to be missin something about RND(). I never understand the parameter inside it. I only have seen Terry using it like:

RND(1) * 256

to get a random number between 1 (or 0?) to 256 (or 255?)

Why is the the multiplication necesary?

About the parenthesis on subs: ¿can i say that if they aren't present the SUB recibes no parameters, but if they are there the parameter is null? I'm getting to much phylosophycal here? XD
   
Title: Re: Trying to imitate TIS-100
Post by: Juan Tamarit on September 02, 2020, 07:33:08 pm
Or should i say null parameters?
   
Title: Re: Trying to imitate TIS-100
Post by: bplus on September 02, 2020, 08:45:31 pm
RND returns a real number from 0 to almost 1 so RND * 256 returns anything from 0 to 255.99???

and Int(RND * 256) returns integers in range 0 to 255. INT() always rounds down.

RND(n) not normally used, I don't use it and I am normal ;-))
Title: Re: Trying to imitate TIS-100
Post by: Juan Tamarit 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)));

=)
Title: Re: Trying to imitate TIS-100
Post by: bplus 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)
Title: Re: Trying to imitate TIS-100
Post by: Juan Tamarit 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.
Title: Re: Trying to imitate TIS-100
Post by: Juan Tamarit 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 =) ]
Title: Re: Trying to imitate TIS-100
Post by: Juan Tamarit 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).

Title: Re: Trying to imitate TIS-100
Post by: Juan Tamarit 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! =)
Title: Re: Trying to imitate TIS-100
Post by: SMcNeill 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.  :)
Title: Re: Trying to imitate TIS-100
Post by: Juan Tamarit 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
Title: Re: Trying to imitate TIS-100
Post by: Juan Tamarit 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!
Title: Re: Trying to imitate TIS-100
Post by: STxAxTIC on September 06, 2020, 10:02:16 pm
Say, ever heard of linked lists? Might wanna go that way on this...
Title: Re: Trying to imitate TIS-100
Post by: bplus 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.  
Title: Re: Trying to imitate TIS-100
Post by: Richard Frost 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.
Title: Re: Trying to imitate TIS-100
Post by: Juan Tamarit 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?
Title: Re: Trying to imitate TIS-100
Post by: bplus 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.

Title: Re: Trying to imitate TIS-100
Post by: Juan Tamarit on September 07, 2020, 11:25:20 pm
U2pro bro =)
Title: Re: Trying to imitate TIS-100
Post by: Juan Tamarit on September 10, 2020, 11:16:10 pm
OK, i keep doing some nice advances: SUB textProccesor() works fine to input the instructions, but im having some troubles realizing how can i achieve the SUB IDE(). I did a horrible IF statement filled with ORs (very noob aproach), but didn't work. Any suggestions about this point? I can't figure out the logic for this, even with separeted IF statements



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.  
  22. DIM SHARED segmentState%(34) ' is segment NOMINAL(1) or ERROR(0)?   ¿
  23. DIM SHARED actualSegmentWorking% ' where are we?                    ³ SEGMENTS
  24. DIM SHARED segmentName$(34) ' names of the segments                 Ù
  25.  
  26. TYPE NODEv21 '                               ¿
  27.     y AS INTEGER '                           ³
  28.     x AS INTEGER '                           ³
  29.     acc AS INTEGER '                         ³
  30.     bak AS INTEGER '                         ³
  31.     mode AS STRING '                         ³
  32.     last AS STRING '                         ³ NODES
  33. END TYPE '                                   ³
  34. '                                            ³
  35. DIM SHARED nodeV21(34, 11) AS NODEv21 '      ³
  36. '          nodeV21(segment, node).type       ³
  37. '                                            ³
  38. DIM SHARED actualNodeWorking% ' where are we?³
  39. '                                            Ù
  40. DIM SHARED inst$(34, 11, 10) '               ¿
  41. '          inst$(segment, node, instruction) ³ INSTRUCTIONS
  42. DIM SHARED actualLineWorking% '              Ù
  43.  
  44. DIM SHARED IDEcomplains%
  45.  
  46. DIM SHARED menuHighlight% ' <----------------- MAIN MENU only
  47. DIM SHARED blink% ' <--------------------blinking CURSOR
  48. '---------------------------------------------------------------------------------------------------------Û PRE-PROGRAM Û----------------------------------------------------------------------------------------------------------
  49. FOR i% = 0 TO 33 '          ¿
  50.     segmentState%(i%) = 0 ' ³ SEGMENTS
  51. NEXT i% '                   Ù
  52. segmentState%(34) = -1 ' SANDBOX
  53.  
  54.  
  55. FOR i% = 0 TO 34 '                                  ¿
  56.     FOR j% = 0 TO 11 '                              ³
  57.         SELECT CASE j% '                            ³
  58.             CASE 0 TO 3: nodeV21(i%, j%).y = 4 '    ³
  59.             CASE 4 TO 7: nodeV21(i%, j%).y = 19 '   ³
  60.             CASE 8 TO 11: nodeV21(i%, j%).y = 34 '  ³
  61.         END SELECT '                                ³ NODES
  62.         SELECT CASE j% '                            ³ positions
  63.             CASE 0, 4, 8: nodeV21(i%, j%).x = 31 '  ³
  64.             CASE 1, 5, 9: nodeV21(i%, j%).x = 56 '  ³
  65.             CASE 2, 6, 10: nodeV21(i%, j%).x = 81 ' ³
  66.             CASE 3, 7, 11: nodeV21(i%, j%).x = 106
  67.         END SELECT '                                ³
  68.     NEXT j% '                                       ³
  69. NEXT i% '                                           Ù
  70.  
  71. FOR i% = 0 TO 34 '                                 ¿
  72.     FOR j% = 0 TO 11 '                             ³
  73.         nodeV21(i%, j%).acc = 0 '                  ³
  74.         nodeV21(i%, j%).bak = 0 '                  ³ NODES
  75.         nodeV21(i%, j%).mode = "IDLE" '            ³ registers
  76.         nodeV21(i%, j%).last = "NONE" '            ³
  77.     NEXT j% '                                      ³
  78. NEXT i% '                                          Ù
  79.  
  80. FOR i% = 0 TO 34 ' setear las instrucciones a null ¿
  81.     FOR j% = 0 TO 11 '                             ³
  82.         FOR k% = 0 TO 10 '                         ³
  83.             inst$(i%, j%, k%) = "" '               ³ INSTRUCTIONS
  84.         NEXT k% '                                  ³
  85.     NEXT j% '                                      ³
  86. NEXT i% '                                          Ù
  87.  
  88. 'infect                                                                ¿
  89. 'CLS _AUTODISPLAY                                                      ³
  90. 'systemCheck                                                           ³
  91. '                                                                      ³
  92. segmentName$(0) = "SYSTEM CLOCK" '                                     ³
  93. segmentName$(1) = "MULTIPLEXER" '                                      ³ INITIALIZE (at least for testing)
  94. segmentName$(34) = "SANDBOX" '                                         ³
  95. '                                                                      ³
  96. menuHighlight% = 0 '            segment 1 is index 0 on the array      ³
  97. actualSegmentWorking% = -1 '    main menu is -1                        ³
  98. actualNodeWorking% = -1 '       on main menu no node is being operated Ù
  99. actualLineWorking% = -1
  100. IDEcomplains% = 0
  101.  
  102. '---------------------------------------------------------------------------------------------------------Û   PROGRAM   Û----------------------------------------------------------------------------------------------------------
  103. mainMenu
  104.  
  105. '---------------------------------------------------------------------------------------------------------Û SUBROUTINES Û----------------------------------------------------------------------------------------------------------
  106. SUB mainMenu () ' draws main menu and instructions on the bottom
  107.  
  108.     DIM KeyPress$
  109.  
  110.     DO
  111.         DO
  112.             _LIMIT 20
  113.             CLS
  114.             SELECT CASE actualSegmentWorking%
  115.                 CASE -2: drawSegments: UsureToLeave
  116.                 CASE -1: drawSegments
  117.                 CASE 0: inSegment_1
  118.                 CASE 1: inSegment_2
  119.                 CASE 34: sandBox
  120.  
  121.             END SELECT
  122.  
  123.             KeyPress$ = INKEY$
  124.             _DISPLAY
  125.         LOOP UNTIL KeyPress$ <> ""
  126.  
  127.         IF actualSegmentWorking% = -1 THEN '                                                                                      ¿
  128.             IF KeyPress$ = CHR$(0) + CHR$(77) AND menuHighlight% <> 34 THEN menuHighlight% = menuHighlight% + 1 '  ¿             ³
  129.             IF KeyPress$ = CHR$(0) + CHR$(75) AND menuHighlight% <> 0 THEN menuHighlight% = menuHighlight% - 1 '   ³ ARROWS for  ³ only works
  130.             IF KeyPress$ = CHR$(0) + CHR$(80) AND menuHighlight% < 28 THEN menuHighlight% = menuHighlight% + 7 '   ³ navigation  ³ in the
  131.             IF KeyPress$ = CHR$(0) + CHR$(72) AND menuHighlight% > 6 THEN menuHighlight% = menuHighlight% - 7 '    Ù             ³ main menu
  132.             IF KeyPress$ = CHR$(13) THEN actualSegmentWorking% = menuHighlight% '                              ENTER to select    ³
  133.         END IF '                                                                                                                  Ù
  134.  
  135.         IF KeyPress$ = CHR$(0) + CHR$(68) THEN actualSegmentWorking% = -2 ' F10 to ask for leaving
  136.  
  137.         IF KeyPress$ = "y" AND actualSegmentWorking% = -2 THEN SYSTEM '                     Y ¿ YES  ¿
  138.         IF KeyPress$ = CHR$(13) AND actualSegmentWorking% = -2 THEN SYSTEM '            ENTER Ù      ³ when asked
  139.         '                                                                                            ³ to leave
  140.         IF KeyPress$ = "n" AND actualSegmentWorking% = -2 THEN actualSegmentWorking% = -1 ' N ¿ NO   ³
  141.         IF KeyPress$ = CHR$(27) THEN actualSegmentWorking% = -1 '-------------------------ESC Ù      Ù
  142.     LOOP
  143.  
  144. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  145. SUB UsureToLeave ()
  146.  
  147.     COLOR WHITE
  148.     drawASCIIbox 20, 46, 34, 2, " Are you sure you wan't to leave? ", 3
  149.     LOCATE 22, 47
  150.     PRINT "        <";
  151.     COLOR YELLOW
  152.     PRINT "Y";
  153.     COLOR WHITE
  154.     PRINT ">es         <";
  155.     COLOR YELLOW
  156.     PRINT "N";
  157.     COLOR WHITE
  158.     PRINT ">o        ";
  159.  
  160. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  161. SUB displayInstructions
  162.  
  163.     DIM i%
  164.     DIM ii%
  165.  
  166.     FOR i% = 0 TO 11
  167.         FOR ii% = 0 TO 10
  168.             LOCATE nodeV21(actualSegmentWorking%, i%).y + ii% + 1, nodeV21(actualSegmentWorking%, i%).x + 1
  169.             PRINT inst$(actualSegmentWorking%, i%, ii%)
  170.         NEXT ii%
  171.     NEXT i%
  172.  
  173. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  174. SUB IDE () ' checks the instructions spelling and warns if incorrect
  175.  
  176.     DIM i%
  177.     DIM j%
  178.     DIM analyzing$
  179.     DIM opCode$
  180.     DIM subComplaint%
  181.  
  182.     FOR i% = 0 TO 11 ' for all the nodes
  183.         FOR j% = 0 TO 10 ' for all the instructions
  184.  
  185.             analyzing$ = _TRIM$(inst$(actualSegmentWorking%, i%, j%))
  186.  
  187.             IF LEN(analyzing$) THEN ' cases that are not null
  188.                 opCode$ = LEFT$(analyzing$, 3)
  189.                 IF NOT opCode$ = "NOP"_
  190.                 OR NOT opCode$ = "MOV"_
  191.                 OR NOT opCode$ = "SWP"_
  192.                 OR NOT opCode$ = "SAV"_
  193.                 OR NOT opCode$ = "ADD"_
  194.                 OR NOT opCode$ = "SUB"_
  195.                 OR NOT opCode$ = "NEG"_
  196.                 OR NOT opCode$ = "JMP"_
  197.                 OR NOT opCode$ = "JEZ"_
  198.                 OR NOT opCode$ = "JNZ"_
  199.                 OR NOT opCode$ = "JGZ"_
  200.                 OR NOT opCode$ = "JLZ"_
  201.                 OR NOT opCode$ = "JRO" THEN
  202.                     IDEcomplains% = -1
  203.                 ELSE
  204.                     IDEcomplains% = 0
  205.                 END IF
  206.  
  207.                 IF IDEcomplains% THEN
  208.                     COLOR RED
  209.                     drawASCIIbox 46, 2, 27, 1, "      INVALID  OPCODE", 2
  210.                     COLOR MIDGRAY
  211.                 END IF
  212.  
  213.             END IF
  214.         NEXT j%
  215.     NEXT i%
  216.  
  217.     '       - INSTRUCTION SET QUICK REFERENCE -
  218.     '
  219.     'NOP                       NO OPERATION
  220.     'MOV <DST>, <SRC>       MOVE <SRC> TO <DST>
  221.     'SWP                    SWAP ACC AND BAK
  222.     'SAV                    SAVE ACC TO BAK
  223.     'ADD <SRC>              ADD <SRC> TO ACC
  224.     'SUB <SRC>              SUBSTRACT <SRC> FROM ACC
  225.     'NEG                    NEGATE ACC
  226.     'JMP <LABEL>            JUMP TO <LABEL>
  227.     'JEZ <LABEL>            JUMP TO <LABEL> IF ACC = 0
  228.     'JNZ <LABEL>            JUMP TO <LABEL> IF ACC != 0
  229.     'JGZ <LABEL>            JUMP TO <LABEL> IF ACC > 0
  230.     'JLZ <LABEL>            JUMP TO <LABEL> IF ACC < 0
  231.     'JRO <SRC>              JUMP TO RELATIVE OFFSET <SRC>
  232.  
  233.  
  234. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  235. SUB sandBox () ' subroutines for each segment has the name as the user sees it (practical purposes)
  236.  
  237.     DIM keyPress$
  238.  
  239.     actualNodeWorking% = 0
  240.     actualLineWorking% = 0
  241.     DO
  242.         _LIMIT 20
  243.         CLS
  244.         drawInsideSegment 1, 1
  245.         COLOR MIDGRAY
  246.         displayInstructions
  247.         textProccesor keyPress$
  248.         IDE
  249.         keyPress$ = UCASE$(INKEY$)
  250.         _DISPLAY
  251.     LOOP UNTIL keyPress$ = CHR$(27)
  252.     actualSegmentWorking% = -1
  253.     actualNodeWorking% = -1
  254.     actualLineWorking% = -1
  255.  
  256.  
  257. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  258. SUB inSegment_1 () ' subroutines for each segment has the name as the user sees it (practical purposes)
  259.  
  260.     DIM keyPress$
  261.  
  262.     actualNodeWorking% = 0
  263.     actualLineWorking% = 0
  264.     DO
  265.         _LIMIT 20
  266.         CLS
  267.         drawInsideSegment 1, 1
  268.         COLOR MIDGRAY
  269.         displayInstructions
  270.         textProccesor keyPress$
  271.         keyPress$ = UCASE$(INKEY$)
  272.         _DISPLAY
  273.     LOOP UNTIL keyPress$ = CHR$(27)
  274.     actualSegmentWorking% = -1
  275.     actualNodeWorking% = -1
  276.     actualLineWorking% = -1
  277.  
  278.  
  279. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  280. SUB inSegment_2 () ' subroutines for each segment has the name as the user sees it (practical purposes)
  281.  
  282.     DIM keyPress$
  283.  
  284.     DO
  285.         _LIMIT 20
  286.         CLS
  287.         drawInsideSegment 2, 1
  288.         keyPress$ = INKEY$
  289.         _DISPLAY
  290.     LOOP UNTIL keyPress$ = CHR$(27)
  291.     actualSegmentWorking% = -1
  292.     actualNodeWorking% = -1
  293.  
  294. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  295. SUB drawInsideSegment (ins%, outs%) ' when you get inside a segment you see this (pass in the number of inputs and outputs)
  296.  
  297.     DIM nY%
  298.     DIM nX%
  299.     DIM i%
  300.     DIM ii%
  301.     DIM j%
  302.     DIM k%
  303.  
  304.     IF ins% > 3 THEN EXIT SUB '  ¿                Ú REM if only 1 output, you can have up to 3 inputs
  305.     IF outs% < 1 THEN EXIT SUB ' ³ check if logic ³ for  2 outputs only 1 input... video thing really,
  306.     IF outs% > 2 THEN EXIT SUB ' Ù                À ELSE overprinting
  307.  
  308.     COLOR MIDGRAY '                                                      ¿
  309.     LOCATE 2, 9 '                                                        ³ title and
  310.     PRINT "- SEGMENT "; LTRIM$(STR$(actualSegmentWorking% + 1)); " -"; ' ³ segment name
  311.     LOCATE 3, 9 '                                                        ³                  °°°°°°°°°°°°°°°°°°°°°°°°°°°°°
  312.     'PRINT "- "; segmentName$(actualSegmentWorking%); " -" ' ------------Ù---------------- °  UNCOMMENT AFTER TESTINGS °
  313.     '                                                                                       °°°°°°°°°°°°°°°°°°°°°°°°°°°°°
  314.     drawASCIIbox 4, 2, 25, 6, "", 2 'draw the instructions box
  315.  
  316.     FOR nY% = 4 TO 34 STEP 15 '      ¿
  317.         FOR nX% = 31 TO 106 STEP 25 '³ draw nodes at
  318.             drawNodeV21 nY%, nX% '   ³ corresponding
  319.         NEXT nX% '                   ³ position
  320.     NEXT nY% '                       Ù
  321.  
  322.     IF NOT actualSegmentWorking% = 34 THEN ' <------ NOT the SANDBOX
  323.  
  324.         IF ins% > 0 THEN '                                                ¿
  325.             ii% = 2 '                               ¿                     ³
  326.             FOR i% = 1 TO ins% '                    ³ print as many       ³
  327.                 LOCATE 13, ii% + 1 '                ³ ASCII boxes as      ³
  328.                 PRINT "IN."; CHR$(96 + i%); '       ³ inputs needed and   ³
  329.                 drawASCIIbox 14, ii%, 4, 25, "", 2 '³ a title "IN" +      ³
  330.                 ii% = ii% + 5 '                     ³ a, b, c, d...       ³
  331.             NEXT i% '                               Ù                     ³
  332.             '                                                             ³
  333.             IF ins% > 1 THEN '             ¿                              ³
  334.                 ii% = 7 '                  ³                              ³ INPUTS
  335.                 FOR i% = 1 TO ins% - 1 '   ³ correct                      ³ table
  336.                     LOCATE 14, ii% '       ³ corners                      ³
  337.                     PRINT CHR$(203); ' Ë   ³ if                           ³
  338.                     LOCATE 40, ii% '       ³ needed                       ³
  339.                     PRINT CHR$(202); ' Ê   ³                              ³
  340.                     ii% = ii% + 5 '        ³                              ³
  341.                 NEXT i% '                  ³                              ³
  342.             END IF '                       Ù                              ³
  343.         END IF '                                                          Ù
  344.  
  345.         LOCATE 13, 21 '                     ¿            ¿
  346.         PRINT "OUT.x"; '                    ³ rightmost  ³
  347.         drawASCIIbox 14, 23, 4, 25, "", 2 ' ³            ³
  348.         drawASCIIbox 14, 18, 4, 25, "", 2 ' Ù            ³
  349.         '                                                ³
  350.         LOCATE 14, 23 '      ¿                           ³
  351.         PRINT CHR$(203); ' Ë ³ corner correction         ³
  352.         LOCATE 40, 23 '      ³ for rightmost             ³
  353.         PRINT CHR$(202); ' Ê Ù                           ³
  354.         '                                                ³
  355.         IF outs% = 2 THEN ' only if asked for            ³
  356.             LOCATE 13, 11 ' ¿                            ³
  357.             PRINT "OUT.x"; '³ "OUT.y" overprinted        ³
  358.             LOCATE 13, 21 ' ³ rightmost "OUT.x"          ³ OUTPUTS
  359.             PRINT "OUT.y"; 'Ù                            ³ table
  360.             drawASCIIbox 14, 13, 4, 25, "", 2 '          ³
  361.             drawASCIIbox 14, 8, 4, 25, "", 2 '           ³
  362.             '                                            ³
  363.             LOCATE 14, 18 '      ¿                       ³
  364.             PRINT CHR$(203); ' Ë ³                       ³
  365.             LOCATE 14, 13 '      ³ corner                ³
  366.             PRINT CHR$(203); ' Ë ³ correction            ³
  367.             LOCATE 40, 18 '      ³ for                   ³
  368.             PRINT CHR$(202); ' Ê ³ both                  ³
  369.             LOCATE 40, 13 '      ³                       ³
  370.             PRINT CHR$(202); ' Ê Ù                       ³
  371.         END IF '                                         Ù
  372.  
  373.     ELSE '                                          ¿
  374.         drawASCIIbox 12, 4, 7, 1, "CONSOLE", 2 '    ³
  375.         drawASCIIbox 14, 4, 7, 23, "", 2 '          ³
  376.         drawASCIIbox 38, 4, 7, 1, ">", 2 '          ³
  377.         LOCATE 14, 4 '                              ³
  378.         PRINT CHR$(204); ' Ì                        ³
  379.         LOCATE 14, 12 '                             ³ SANDBOX
  380.         PRINT CHR$(185); ' ¹                        ³ CONSOLE
  381.         LOCATE 38, 4 '                              ³
  382.         PRINT CHR$(204); ' Ì                        ³
  383.         LOCATE 38, 12 '                             ³
  384.         PRINT CHR$(185); ' ¹                        ³
  385.     END IF '                                        Ù
  386.  
  387.     FOR k% = 9 TO 39 STEP 15 ' Y        ¿            ¿
  388.         FOR j% = 53 TO 103 STEP 25 ' X  ³            ³
  389.             LOCATE k%, j% '             ³            ³
  390.             PRINT CHR$(26); '          ³ left/right ³
  391.             LOCATE k% + 2, j% + 1 '     ³ PORTS      ³
  392.             PRINT CHR$(27); '          ³            ³
  393.         NEXT j% '                       ³            ³ PORTS
  394.     NEXT k% '                           Ù            ³ between
  395.     '                                                ³ NODES
  396.     FOR k% = 18 TO 33 STEP 15 ' Y       ¿            ³
  397.         FOR j% = 38 TO 113 STEP 25 '    ³            ³
  398.             LOCATE k%, j% '             ³ up/down    ³
  399.             PRINT CHR$(24); '          ³ PORTS      ³
  400.             LOCATE k% - 1, j% + 4 '     ³            ³
  401.             PRINT CHR$(25); '          ³            ³
  402.         NEXT j% '                       ³            ³
  403.     NEXT k% '                           Ù            Ù
  404.  
  405.     IF ins% > 0 THEN LOCATE 3, 62: PRINT "IN.a"; CHR$(25); '   ¿
  406.     IF ins% > 1 THEN LOCATE 3, 87: PRINT "IN.b"; CHR$(25); '   ³
  407.     IF ins% > 2 THEN LOCATE 3, 112: PRINT "IN.c"; CHR$(25); '  ³
  408.     '                                                          ³
  409.     IF actualSegmentWorking% = 34 THEN '         ¿             ³
  410.         LOCATE 3, 61: PRINT "CNS.a"; CHR$(25); ' ³ SANDBOX     ³
  411.     END IF '                                     Ù             ³ IN/OUT
  412.     '                                                          ³ ports
  413.     LOCATE 47, 87 '                                            ³
  414.     IF NOT actualSegmentWorking% = 34 THEN '                   ³
  415.         PRINT "OUT.x"; CHR$(25); '                             ³
  416.     ELSE '                                                     ³
  417.         PRINT "CNS.x"; CHR$(25); ' <---------SANDBOX           ³
  418.     END IF '                                                   ³
  419.     IF outs% > 1 THEN LOCATE 47, 62: PRINT "OUT.y"; CHR$(25);
  420.  
  421.     drawASCIIbox 41, 4, 2, 1, (CHR$(16) + CHR$(16)), 1 '    ¿
  422.     drawASCIIbox 41, 14, 2, 1, (CHR$(124) + CHR$(16)), 1 '  ³
  423.     drawASCIIbox 41, 24, 2, 1, (CHR$(219) + CHR$(219)), 1 ' ³
  424.     LOCATE 44, 3 '                                          ³
  425.     PRINT "F5 Run"; '                                       ³
  426.     LOCATE 44, 12 '                                         ³ BUTTONS
  427.     PRINT "F6 Step"; '                                      ³
  428.     LOCATE 44, 22 '                                         ³
  429.     PRINT "F8 Stop"; '                                      ³
  430.     COLOR DARKGRAY '                                        ³
  431.     LOCATE 45, 9 '                                          ³
  432.     PRINT "ESC to go back"; '                               Ù
  433.  
  434. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  435. SUB textProccesor (key$)
  436.  
  437.     blink% = blink% - 16 '                                                                                                               ¿
  438.     IF blink% < 0 THEN blink% = 255 '                                                                                                    ³
  439.     COLOR _RGB32(blink%, blink%, blink%) '                                                                                               ³ CURSOR
  440.     LOCATE nodeV21(actualSegmentWorking%, actualNodeWorking%).y + actualLineWorking% + 1,_
  441.     nodeV21(actualSegmentWorking%, actualNodeWorking%).x + LEN(inst$(actualSegmentWorking%, actualNodeWorking%, actualLineWorking%)) + 1
  442.     PRINT CHR$(219) '                                                                                                                    Ù
  443.  
  444.     IF LEN(key$) THEN ' B+ avoided the null =)
  445.  
  446.         IF LEN(inst$(actualSegmentWorking%, actualNodeWorking%, actualLineWorking%)) < 13 THEN ' ¿ PRINTABLE
  447.             IF ASC(key$) > 31 AND ASC(key$) < 127 THEN '                                         ³ CHARACTERS
  448.                 inst$(actualSegmentWorking%, actualNodeWorking%, actualLineWorking%) =_
  449.                 inst$(actualSegmentWorking%, actualNodeWorking%, actualLineWorking%) + key$ '    ³ can't write more than
  450.             END IF '                                                                             ³ 13 characters
  451.         END IF '                                                                                 Ù
  452.  
  453.         IF ASC(key$) = 8 THEN '                                                                             ¿  BACKSPACE
  454.             inst$(actualSegmentWorking%, actualNodeWorking%, actualLineWorking%) =_
  455.             LEFT$(inst$(actualSegmentWorking%, actualNodeWorking%, actualLineWorking%),_
  456.             LEN(inst$(actualSegmentWorking%, actualNodeWorking%, actualLineWorking%)) - 1) '                ³
  457.         END IF '                                                                                            Ù
  458.  
  459.         IF ASC(key$) = 13 AND actualLineWorking% < 10 AND inst$(actualSegmentWorking%, actualNodeWorking%, 10) = "" THEN '¿
  460.             actualLineWorking% = actualLineWorking% + 1 '                                                                 ³ ENTER
  461.         END IF '                                                                                                          Ù
  462.  
  463.         IF ASC(key$) = 9 THEN '                               ¿
  464.             IF actualNodeWorking% < 11 THEN '                 ³
  465.                 actualNodeWorking% = actualNodeWorking% + 1 ' ³
  466.             ELSE '                                            ³ TAB
  467.                 actualNodeWorking% = 0 '                      ³
  468.             END IF '                                          ³
  469.             actualLineWorking% = 0 '                          ³
  470.         END IF '                                              Ù
  471.  
  472.     END IF ' B+ avoid null ; -) U2pro bro
  473.  
  474.     IF key$ = CHR$(0) + CHR$(72) AND actualLineWorking% > 0 THEN ' UP        ¿
  475.         actualLineWorking% = actualLineWorking% - 1 '                        ³
  476.     ELSEIF key$ = CHR$(0) + CHR$(80) AND actualLineWorking% < 10 THEN 'DOWN  ³ ARROWS
  477.         actualLineWorking% = actualLineWorking% + 1 '                        ³
  478.     END IF '                                                                 Ù
  479.  
  480.  
  481.  
  482. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  483. SUB infect () ' virus intro sketch... base under attack!
  484.  
  485.     DIM row%
  486.     DIM column%
  487.     DIM message1$
  488.     DIM message2$
  489.     DIM i%
  490.     DIM ii%
  491.     DIM loadingBar$
  492.  
  493.     row% = 20
  494.     column% = 52
  495.     message1$ = "I'm taking control..."
  496.     message2$ = "And you can't stop me"
  497.  
  498.     'sayHello
  499.     COLOR GREEN '                                    ¿ try to
  500.     PRINTslowly row% + 3, column% + 2, message1$, 1 '³ psychopatiate
  501.     PRINTslowly row% + 4, column% + 2, message2$, 1 'Ù the user
  502.     SLEEP 1
  503.  
  504.     'install
  505.     i% = 0
  506.     ii% = 0
  507.     loadingBar$ = CHR$(219)
  508.     DO
  509.         _LIMIT 500
  510.         i% = i% + 1
  511.         ii% = INT(i% / 100)
  512.  
  513.         COLOR MIDGRAY '                             ¿
  514.         LOCATE RND(1) * 47 + 1, RND(1) * 127 + 1 '  ³ random characthers on the back
  515.         PRINT CHR$(RND(1) * 222 + 32); '            Ù
  516.  
  517.         COLOR GREEN '    a virus is GREEN!       ¿
  518.         '                                         ³ draw box and
  519.         drawASCIIbox row%, column%, 23, 7, "", 2 '³ CLS inside it
  520.         '                                         ³ (don't erease back)
  521.         fakeCLS row% + 1, column% + 1, 22, 6 '    Ù
  522.  
  523.         IF ii% MOD 2 = 0 THEN '                   ¿
  524.             LOCATE row% + 1, column% + 2 '        ³ blink: title
  525.             PRINT "CV64 VIRUS V0.2  >:-["; '      ³ underline
  526.             LOCATE row% + 2, column% + 2 '        ³ message1$
  527.             PRINT STRING$(21, CHR$(223)); '       ³ and
  528.             '                                     ³ message2$
  529.             LOCATE row% + 3, column% + 2 '        ³
  530.             PRINT message1$; '                    ³
  531.             '                                     ³
  532.             LOCATE row% + 4, column% + 2 '        ³
  533.             PRINT message2$; '                    ³
  534.         END IF '                                  Ù
  535.  
  536.         LOCATE row% + 6, column% + 2 '                              ¿
  537.         IF ii% < 20 THEN PRINT "Overriding OS..."; '                ³
  538.         IF ii% < 40 AND ii% > 19 THEN PRINT "Accesing files..."; '  ³ loading messages
  539.         IF ii% < 60 AND ii% > 39 THEN PRINT "Infecting..."; '       ³
  540.         IF ii% < 80 AND ii% > 59 THEN PRINT "Replicating..."; '     ³
  541.         IF ii% < 100 AND ii% > 79 THEN PRINT "Ereasing nodes..."; ' ³
  542.         IF ii% = 100 THEN PRINT "Nodes killed "; '                 Ù
  543.  
  544.         ii$ = LTRIM$(STR$(ii%)) '                   ¿
  545.         LOCATE row% + 6, column% + 22 - LEN(ii$) '  ³ xx%
  546.         PRINT ii$ + "%"; '                          Ù
  547.  
  548.         IF i% MOD 500 = 0 THEN loadingBar$ = loadingBar$ + CHR$(219) ' ¿
  549.         LOCATE row% + 7, column% + 2 '                                 ³ loading bar
  550.         PRINT loadingBar$; '                                           Ù
  551.         _DISPLAY
  552.     LOOP UNTIL i% = 10000
  553.     SLEEP 2 '                                       infection complete XD
  554.  
  555.  
  556. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  557. SUB systemCheck () ' fake system check as excuse to go at main menu
  558.  
  559.     DIM i&
  560.  
  561.     COLOR LIGHTGRAY
  562.     PRINTslowly 2, 2, "Unexpected restart. Running system check...", 1
  563.     FOR i& = 0 TO 247483647 STEP 2048
  564.         _LIMIT 20000
  565.         LOCATE 4, 2
  566.         PRINT "CHECKSUM: ";: PRINT LTRIM$(STR$(i&));
  567.     NEXT i&
  568.     PRINT " OK"
  569.     PRINTslowly 6, 2, "Nodes have been corrupted...", 1
  570.     PRINTslowly 8, 2, "Reprogram them to recover access to OS...", 1
  571.     PRINTslowly 10, 2, "Please, don't shut down the equipment until reprogramming is over", 1
  572.     PRINTslowly 11, 2, "or all system data won't be able to recover...", 0
  573.     PRINTslowly 13, 2, "Starting debbuger", 1
  574.     SLEEP 2
  575.  
  576.  
  577. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  578. SUB drawSegments () ' draw the segment on the main menu
  579.  
  580.     DIM i%
  581.     DIM y%
  582.     DIM x%
  583.     DIM yy%
  584.     DIM xx%
  585.     DIM segmentNumber$
  586.  
  587.     i% = -1
  588.  
  589.     FOR y% = 3 TO 39 STEP 9
  590.         FOR x% = 4 TO 112 STEP 18
  591.  
  592.             i% = i% + 1 ' node index number, start -1 to make it 0 here for the array
  593.             '              we add another +1 later to make em look like start at 1
  594.             COLOR DARKGRAY '                                  ¿
  595.             FOR yy% = 2 TO 5 '                                ³
  596.                 FOR xx% = 1 TO 11 '                           ³ if node is broke
  597.                     LOCATE y% + yy%, x% + xx% '               ³ random characters
  598.                     IF NOT segmentState%(i%) THEN '           ³
  599.                         PRINT CHR$(RND(1) * 200 + 32); '      ³ if fixed by
  600.                     ELSE '                                    ³ user then
  601.                         PRINT LTRIM$(STR$(_ROUND(RND))); '    ³ plain 1's and 0's
  602.                     END IF '                                  ³
  603.                 NEXT xx% '                                    ³
  604.             NEXT yy% '                                        Ù
  605.  
  606.             IF i% > 8 THEN '                                  ¿ the shown number
  607.                 segmentNumber$ = LTRIM$(STR$(i% + 1)) '       ³ of the segment,
  608.             ELSE '                                            ³ avoiding the
  609.                 segmentNumber$ = " " + LTRIM$(STR$(i% + 1)) ' ³ spaces if
  610.             END IF '                                          Ù two digits
  611.  
  612.             IF menuHighlight% = i% THEN ' ¿
  613.                 COLOR WHITE '             ³ show WHITE if
  614.             ELSE '                        ³ selected, else
  615.                 COLOR MIDGRAY '           ³ is MIDGRAY
  616.             END IF '                      Ù
  617.  
  618.             drawASCIIbox y%, x%, 11, 5, " SEGMENT" + segmentNumber$, 1 ' draw the box
  619.  
  620.             LOCATE 40, 113: PRINT "  SANDBOX  "; ' <---------------SANDBOX CASE (overprinted over SEGMENT 35)
  621.  
  622.             LOCATE y% + 3, x% + 2 '     ¿
  623.             IF segmentState%(i%) THEN ' ³ accordingly to
  624.                 COLOR MIDGRAY, GREEN '  ³ segmentState%()
  625.                 PRINT "-NOMINAL-" '     ³ draw -NOMINAL-
  626.             ELSE '                      ³ or   - ERROR -
  627.                 COLOR BLACK, RED '      ³
  628.                 PRINT " -ERROR- " '     ³
  629.             END IF '                    Ù
  630.  
  631.             COLOR , BLACK '  don't conflictuate other stuff
  632.  
  633.         NEXT x%
  634.     NEXT y%
  635.  
  636.     drawMainInstructions
  637.  
  638.  
  639. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  640. SUB drawMainInstructions () ' draws a single blue line with some instruction on it at the bottom of the screen
  641.  
  642.     DIM ii%
  643.  
  644.     COLOR YELLOW, BLUE
  645.  
  646.     FOR ii% = 1 TO 127 '   ¿
  647.         LOCATE 48, ii% '   ³ blue background
  648.         PRINT " "; '       ³ line at bottom
  649.     NEXT ii% '             Ù
  650.  
  651.     LOCATE 48, 25 '             ¿
  652.     PRINT "F1 Help"; '          ³
  653.     LOCATE 48, 43 '             ³ options in
  654.     PRINT "ARROWS Navigate"; '  ³ the main menu
  655.     LOCATE 48, 71 '             ³
  656.     PRINT "ENTER Select"; '     ³
  657.     LOCATE 48, 92 '             ³
  658.     PRINT "F10 Save and Exit";
  659.  
  660.     COLOR , BLACK ' don't conflictuate with other things
  661.  
  662.  
  663. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  664. SUB drawNodeV21 (nodeY%, nodeX%)
  665.  
  666.     DIM i%
  667.  
  668.     FOR i% = 0 TO 11 '                                                                               ¿
  669.         COLOR DARKGRAY '                                                                             ³
  670.         LOCATE nodeV21(actualSegmentWorking%, i%).y + 2, nodeV21(actualSegmentWorking%, i%).x + 16 ' ³
  671.         PRINT nodeV21(actualSegmentWorking%, i%).acc; '                                              ³ show
  672.         LOCATE nodeV21(actualSegmentWorking%, i%).y + 5, nodeV21(actualSegmentWorking%, i%).x + 16 ' ³ information
  673.         PRINT nodeV21(actualSegmentWorking%, i%).bak; '                                              ³ of node
  674.         LOCATE nodeV21(actualSegmentWorking%, i%).y + 8, nodeV21(actualSegmentWorking%, i%).x + 16 ' ³ registers
  675.         PRINT nodeV21(actualSegmentWorking%, i%).mode; '                                             ³ (acc, bak,
  676.         LOCATE nodeV21(actualSegmentWorking%, i%).y + 11, nodeV21(actualSegmentWorking%, i%).x + 16 '³ mode, last)
  677.         PRINT nodeV21(actualSegmentWorking%, i%).last; '                                             ³
  678.     NEXT i% '                                                                                        Ù
  679.  
  680.     COLOR MIDGRAY
  681.  
  682.     drawASCIIbox nodeY%, nodeX%, 14, 11, "", 1 ' user input instructions box
  683.     drawASCIIbox nodeY%, nodeX% + 15, 4, 2, "ACC", 1 '     ¿
  684.     drawASCIIbox nodeY% + 3, nodeX% + 15, 4, 2, "BAK", 1 ' ³ box over
  685.     drawASCIIbox nodeY% + 6, nodeX% + 15, 4, 2, "MODE", 1 '³ box
  686.     drawASCIIbox nodeY% + 9, nodeX% + 15, 4, 2, "LAST", 1
  687.  
  688.     LOCATE nodeY%, nodeX% + 15 '            ¿
  689.     PRINT CHR$(194); ' Â                    ³
  690.     LOCATE nodeY% + 12, nodeX% + 15 '       ³
  691.     PRINT CHR$(193); ' Á                    ³
  692.     '                                       ³ then correct
  693.     FOR i% = 3 TO 9 STEP 3 '                ³ the corners
  694.         LOCATE nodeY% + i%, nodeX% + 15 '   ³ nedded
  695.         PRINT CHR$(195); ' Ã                ³
  696.     NEXT i% '                               ³ (the usual
  697.     '                                       ³ deciving)
  698.     FOR i% = 3 TO 9 STEP 3 '                ³
  699.         LOCATE nodeY% + i%, nodeX% + 20 '   ³
  700.         PRINT CHR$(180); ' ´                ³
  701.     NEXT i% '                               Ù
  702.  
  703.  
  704. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  705. SUB PRINTslowly (originY%, originX%, message$, preBlink%)
  706.  
  707.     DIM i%
  708.     DIM buildingMessage$
  709.  
  710.     IF originY% < 1 THEN EXIT SUB '     ¿ check if logic
  711.     IF originX% < 1 THEN EXIT SUB '     Ù
  712.  
  713.     IF preBlink% = 1 THEN PCthinking originY%, originX% ' wanna see some blinking before start writing?
  714.  
  715.     i% = 0 '                                                Ä¿
  716.     DO '                                                     ³
  717.         _DELAY .05 '                                         ³
  718.         i% = i% + 1 '                                        ³ print message$
  719.         buildingMessage$ = LEFT$(message$, i%) + CHR$(219) ' ³ character by character
  720.         LOCATE originY%, originX% '                          ³ and erease the cursor
  721.         PRINT buildingMessage$; '                            ³
  722.     LOOP UNTIL LEN(buildingMessage$) = LEN(message$) + 1 '  ÄÙ
  723.  
  724.     LOCATE CSRLIN, originX% + LEN(message$): PRINT " "; ' erease cursor
  725.  
  726.  
  727. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  728. SUB PCthinking (originY%, originX%)
  729.  
  730.     DIM i%
  731.  
  732.     IF originY% < 1 THEN EXIT SUB '     ¿ check if logic
  733.     IF originX% < 1 THEN EXIT SUB '     Ù
  734.  
  735.     FOR i% = 1 TO 11 '                  ¿
  736.         _LIMIT 5 '                      ³
  737.         LOCATE originY%, originX% '     ³
  738.         IF i% MOD 2 = 0 THEN '          ³ bliking cursor
  739.             PRINT CHR$(219); '          ³
  740.         ELSE '                          ³
  741.             PRINT " "; '                ³
  742.         END IF '                        ³
  743.     NEXT i% '                           Ù
  744.  
  745.  
  746. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  747. SUB fakeCLS (originY%, originX%, width%, height%)
  748.  
  749.     DIM y%
  750.     DIM x%
  751.  
  752.     IF originY% < 1 THEN EXIT SUB '               ¿
  753.     IF originX% < 1 THEN EXIT SUB '               ³ check if logic
  754.     IF width% < 1 THEN EXIT SUB '                 ³
  755.     IF height% < 1 THEN EXIT SUB '                Ù
  756.  
  757.     FOR x% = 0 TO width% '                        ¿
  758.         FOR y% = 0 TO height% '                   ³ print
  759.             LOCATE originY% + y%, originX% + x% ' ³ " " (space)
  760.             PRINT " "; '                          ³ repeatedly
  761.         NEXT y% '                                 ³
  762.     NEXT x% '                                     Ù
  763.  
  764.  
  765. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  766. SUB drawASCIIbox (originY%, originX%, width%, height%, message$, style%)
  767.  
  768.     DIM char%
  769.     DIM char1%
  770.     DIM char2%
  771.     DIM y%
  772.     DIM x%
  773.  
  774.     IF originY% < 1 OR originX% < 1 THEN EXIT SUB '     ÄÄÄ¿
  775.     IF width% < 1 OR height% < 1 THEN EXIT SUB '           ³ check if logic
  776.     IF style% < 1 OR style% > 3 THEN EXIT SUB '         ÄÄÄÙ
  777.  
  778.     LOCATE originY%, originX% '                         ÄÄÄ¿
  779.     IF style% = 1 THEN PRINT CHR$(218); 'Ú                 ³
  780.     IF style% = 2 THEN PRINT CHR$(201); ' É   up,left      ³
  781.     '                                                      ³
  782.     LOCATE originY% + height% + 1, originX% '              ³
  783.     IF style% = 1 THEN PRINT CHR$(192); ' À                ³
  784.     IF style% = 2 THEN PRINT CHR$(200); ' È  down, left    ³ corners
  785.     '                                                      ³
  786.     LOCATE originY%, originX% + width% + 1 '               ³
  787.     IF style% = 1 THEN PRINT CHR$(191); ' ¿                ³
  788.     IF style% = 2 THEN PRINT CHR$(187); ' » up, right      ³
  789.     '                                                      ³
  790.     LOCATE originY% + height% + 1, originX% + width% + 1 ' ³
  791.     IF style% = 1 THEN PRINT CHR$(217); ' Ù                ³
  792.     IF style% = 2 THEN PRINT CHR$(188); ' ¼ down, right ÄÄÄÙ
  793.  
  794.     IF style% = 1 THEN char% = 179 ' ³                  ÄÄÄ¿
  795.     IF style% = 2 THEN char% = 186 ' º  determinate style  ³
  796.     IF style% = 3 THEN char% = 219 ' Û                     ³
  797.     FOR y% = 1 TO height% '                                ³
  798.         LOCATE originY% + y%, originX% ' locate and print  ³ sides
  799.         PRINT CHR$(char%); '                               ³
  800.         LOCATE originY% + y%, originX% + width% + 1 '      ³
  801.         PRINT CHR$(char%); '                               ³
  802.     NEXT y% '                                           ÄÄÄÙ
  803.  
  804.     IF style% < 3 THEN ' styles 1 and 2                 ÄÄÄ¿
  805.         IF style% = 1 THEN char% = 196 ' Ä                 ³
  806.         IF style% = 2 THEN char% = 205 ' Í                 ³
  807.         FOR x% = 1 TO width% '                             ³
  808.             LOCATE originY%, originX% + x% '               ³
  809.             PRINT CHR$(char%); '                           ³
  810.             LOCATE originY% + height% + 1, originX% + x% ' ³
  811.             PRINT CHR$(char%); '                           ³ top &
  812.         NEXT x% '                                          ³ bottom
  813.     ELSE ' special case of style 3                         ³
  814.         char1% = 220 ' Ü                                   ³
  815.         char2% = 223 ' ß                                   ³
  816.         FOR x% = 0 TO width% + 1 '                         ³
  817.             LOCATE originY%, originX% + x% '               ³
  818.             PRINT CHR$(char1%); '                          ³
  819.             LOCATE originY% + height% + 1, originX% + x% ' ³
  820.             PRINT CHR$(char2%); '                          ³
  821.         NEXT x% '                                          ³
  822.     END IF '                                            ÄÄÄÙ
  823.  
  824.     LOCATE originY% + 1, originX% + 1 '                 ÄÄÄ¿ message
  825.     PRINT message$; '                                   ÄÄÄÙ
  826.  
  827.  
  828.  

textProccesor() could have some improvement, but for the moment it acomplish its work
Title: Re: Trying to imitate TIS-100
Post by: bplus on September 10, 2020, 11:38:24 pm
String those 3 letter guys up with some char like * after each including the last.
 StrungUp3LetterGuys$ = "NOP*MOV*SWP*..... JRO*"

Match$ =  LEFT$(analyzing$, 3) + "*"

find = INSTR(StrungUp3LetterGuys$, Match$)

if find then no complaints else complain