Stranger Things 2 and BASIC and Color BASIC

Updates:

  • 4/26/2022 – Added note about IF/ENDIF via comments. Added link to YouTube video of the segment.
  • 4/27/2022 – Updated screen shots with images taken from the YouTube video (linked in this posting).

With the season four of Stranger Things coming to Netflix soon, I have been re-watching the first three seasons.

Season one is set in 1983, and one of the characters (Joyce Byers, played by Winona Ryder) is shown working at a local general store. We see that there is a Radio Shack next door to it. We also see Radio Shack walkie talkies featured in the episodes.

In Season two we meet Joyce’s boyfriend, Bob Newby (played by Sean Astin). He works at that next-door Radio Shack. There is even one scene that shows him at work, though the environment is unlike any Radio Shack I ever saw.

In season two episode eight (“The Mind Flayer”), there is a need for them to restart a computer system. Radio Shack Bob says someone needs to know BASIC to do this. (Oh, really, writers?) This leads to a scene where Bob gets the system going by … typing in a BASIC program.

Here is the clip that someone posted to YouTube. (It starts around the 15:57 mark of the full episode.)

Here is a screen shot of the code:

Stranger Things S2E8 – Around 15:57 timecode.

It is some form of BASIC I am unfamiliar with. It allows defining variables as types (INTEGER in this case) and also appears to support functions with parameters similar to C. I am unsure if this is just Hollywood hookum or if there was actually a BASIC like this that existed in 1984 when Season 2 is set.

Here is a close-up of the code taken from the YouTube video (and apologies for the camera photo of a TV screen — Netflix blocks taking screen shots in their apps).

Stranger Things S2E8 – Around 15:57 timecode. (enhanced)

Update: Did you notice the end of line 70? You can see the lettering of the last word on TOP of the frame of the monitor. I never noticed that when watching it in full speed. The screen was probably added later as a special overlay effect and they didn’t take time to crop it in fully. But I digress…

Either the programmer used a bunch of memory typing in all the spaces to make it look nice, or this version of BASIC has pretty-output like Microware BASIC09 does.

I typed it in, trying to replicate the spacing…

10 DIM FourDigitPassword:INTEGER
20 FOR i = 0 TO 9
30     FOR j = 0 TO 9
40          FOR k = 0 to 9
50                FOR l = 0 TO 9
60                      FourDigitPassword = getFourDigits (i,j,k,l)
70                      IF checkPasswordMatch(FourDigitPassword) = TRUE THEN
80                              GOTO 140
90                      END
100                NEXT l
110          NEXT k
120     NEXT j
130 NEXT i
140 PRINT FourDigitPassword
150 END

Looking at this, I can now say it was a programmer adding the spaces. They do not follow a consistent tab value. Line 30-40 tabs in 5 spaces, then line 40-50 tabs in 6. My OCD is unhappy.

Line 10 creates a variable called FourDigitPassword. This tells us that this BASIC allows mixed case variable names. It also either support long variable names, or is like Microsoft Color BASIC where you can type them in, but the interpreter only honors the first two characters (or however many this version of BASIC supports).

This variable is declared as an INTEGER, whatever data type that is. Since an integer is a number, this four digit password must be like a PIN, consisting of numbers only. Since 0000 to 9999 is to big to fit in a byte (0-255), we’ll say INTEGER is a 16-bit value (0-65535).

Update: The Microsoft BASIC I am used to treat every numeric variable as a floating point value. I now recall that Commodore 64 had a way to declare a variable as an integer (non floating point). Perhaps that is what this is? (Though, they should have also declared I, J, K and L as INTEGERs too since none of this uses floating point values…)

Lines 30-50 are four FOR/NEXT loops using variables i, j, k and l. that cycle through 0-9 for each variable, representing each of the four digits of the password. Note that these variables are not declared in a DIM statement. Perhaps the default variable data type is a BYTE unless you otherwise specify?

In line 60, a function “getFourDigits” is called with each of the four variable values, returning something to variable “FourDigitPassword.” This looks like it would take four values like 1, 2, 3 and 4 and return them as an integer of 1234. So far, so good.

Line 70 is where things get strange. It calls a function “checkPasswordMatch” passing it this newly created integer value. If the function returns TRUE, it is intended to GOTO line 140 and print out the valid password, then end. However, since the GOTO is on a line starting with a new line number, I expect it would at the end of line 70 since nothing is after the THEN.

Let’s assume this weird BASIC will just continue parsing for more tokens on the next line, treating it as the “THEN” clause. If the compare was not valid, though, what would it do? Skip the next line? This is problematic.

Line 90 has an END, which would be problematic in BASIC. At this point, after the first unsuccessful check, this code would stop running.

Update: As noted in comments to this article by William A. and Lee, there were BASIC variants that used IF and ENDIF. If we treat that END to be intended as ENDIF, this code makes sense (but would still be a typo that would stop the code from running as presented

Conclusion: This program cannot work.

Line 100-130 are the NEXTs for the FOR loops.

Assuming functions work the way they appear and do what I assume they are meant to do, this appears to be a brute for password cracker, trying every combination of 0000 to 9999.

Make BASIC less strange…

Let’s make a real version! Here is my edit for Microsoft Color BASIC:

0 REM STRANGE.BAS
10 DIM PW
15 TP=1234
20 FOR I = 0 TO 9
30 FOR J = 0 TO 9
40 FOR K = 0 TO 9
50 FOR L = 0 TO 9
60 PW=I*1000+J*100+K*10+L
70 IF PW=TP THEN GOTO 140
100 NEXT L
110 NEXT K
120 NEXT J
130 NEXT I
140 PRINT PW
150 END

I had to change all the variables to UPPERCASE, and then shortened “FourDigitPassword” to just PW. I could have called it FOURDIGITPASSWORD since BASIC would still honor the first two letters (FO), but I find that a bad practice since it can lead to hard to track down errors latter (say, if you later used a variable called FOREVER or anything else that started with FO, thinking it was a unique variable while BASIC thought it was the same as FOURDIGITPASSWORD).

Since I do not have functions, I decided to just make a target password variable (TP) that will be the password to try to guess. I added this in LINE 15.

Line 20-50 are the same as the original program, just without the tabs (since my CoCo’s screen is only 32 characters wide and it would look messy).

In line 60, instead of calling a function that creates FourDigitPassword (PW) from four separate variables, I just build it myself. I multiply each digit out to turn 1,2,3,4 in to 1*1000 + 2*100 + 3*10 +4 (which is 1234).

Line 70 just compares the generated PW variable to the target TP variable. Again, no functions, so I just do it manually. I moved the “GOTO 140” to the end of that line (but it didn’t actually need the GOTO keyword after THEN).

I removed line 80 and 90 (since 80 is now at the end of 70).

Lines 100-150 are the same as the original program, except using uppercase and shorter variable names. Here is what it looks like, perfectly fitting a 32×16 CoCo screen. (I’ll even use the INVERSE VIDEO mode in tribute to Stranger Thing’s “upside down”):

Stranger Things Color BASIC

If I run this, it will grind away for quite some time before finally cracking the password and printing “1234”…

It would take far longer if the target password had been 9999, but hey, it works!

Make BASIC less slow…

There are some simple ways this could be sped up, such as combining lines, and removing the variables after each NEXT (so BASIC doesn’t have to look them up each time). And, the use of a variable for each of the four digits and creating an integer seems a bit pointless, since the function that checks for a match just does so with a single integer value. This whole thing could be turned in to…

0 REM STRANGE.BAS
10 DIM PW
15 TP=1234
20 FOR I = 0 TO 9999
70 IF PW=TP THEN GOTO 140
130 NEXT I
140 PRINT PW
150 END

Since I cannot resist a BASIC benchmark opportunity, I set the target password to 9999 and ran the first version. I cleared the timer (TIMER=0) at the start and printed it out just after it prints the result. The first version shows 12609.

Then I did the same with the second version, and it shows 277. (And that could be made a bit faster by removing spaces and combining lines — down to 263 in a quick test I did.

Poor Bob could have saved alot of time with that trick. It might have even saved his life ;-) (Do I need to give a spoiler warning for a show that aired in 2017? If so, spoiler warning!)

Until next time, stay strange!

12 thoughts on “Stranger Things 2 and BASIC and Color BASIC

  1. William Astle

    This looks like possibly a variation or predecessor of QBasic that supports some more advanced nesting structures. It appears to use END as the marker for the end of an aribtrary block of code, such as the statements inside the “THEN” clause of an IF statement. QBasic uses “ENDIF” to end a multi-line IF statement, but the rest of the syntax there looks like it matches.

    Reply
        1. Allen Huffman Post author

          I did not know that! I remember BASICA (?), GW-BASIC and QBASIC but I don’t remember the order that they existed or anything about them other than normal BASIC stuff. I don’t recall what was on the Tandy 1000s during the years I worked for Radio a shack (88-91 maybe).

          Reply
    1. Allen Huffman Post author

      (and I still haven’t read your comment on the horse race question. Thank you for the first sentence about not reading to avoid spoiling the answer.)

      Reply
  2. Lee

    Most versions of BASIC (and there are many flavors from that era) that I’m aware of that supported an “If block” used “End If” to end the block, not just “End”. That said, BASIC with the idea of an “If block” is not that strange (https://en.wikibooks.org/wiki/BASIC_Programming/Beginning_BASIC/Control_Structures/IF…THEN…ELSEIF…ELSE).

    Even BASIC with the concept of parameterized functions isn’t unheard of (https://en.wikibooks.org/wiki/BASIC_Programming/Subroutines_and_Functions#Functions).

    Whether these concepts were prevalent in 1984 or not until later, I’m not sure. :)

    Reply
  3. Walter Green

    Actually that whole BASIC program makes no sense. If all you need to do is compare a randomly generates password with the actually password, why now just print the variable containing the password. Other wise there should have been a routine to first print the password and THEN try the password. That way the password gets displayed, and once the password is sent, that breaks the loop leaving the last tried password on the screen at least momentarily. Then you know the password. If you are able to compare passwords in an IF statement then that means you have that password already, and only need a statement saying something like PRINT $PW;.

    Reply
    1. Allen Huffman Post author

      The GOTO when a password matches will do that. Thanks to comments here, I now think the IF and END in the middle is really an IF and ENDIF operation in this BASIC, or a typo, so that END would not actually end the program.

      Reply
  4. MiaM

    Re the Declare thing – perhaps this (probably non existing) version of basic defaulted to integers for variable names starting with I-Z and float for A-H, like Fortran. (Compare “God is real unless declared integer” ;) )

    Re functions: I thinlk functions were also a part of MacBasic and AmigaBasic, both made by Microsoft. (Sidetrack: AmigaBasic was obviously reusing the MacBasic code base, violating the programming guidelines for the Amiga making AmigaBasic not runnable on an Amiga with a wider address bus than 24 bits (i.e. it works on the original Amigas with a 68000 CPU, it runs on any DIY simple upgrade with a 68010, and it also works with the 68EC020 processor found in the A1200 and CD32, but it won’t work on any Amiga 3000 or 4000 or any of the better processor upgrades for the other Amigas)).

    Btw, re screen shots, I assume that if you can’t use the screen shot feature built in to for example Windows you could probably use OBS, the broadcast video capture thingy that most Youtubers seem to use. Afaik it can capture a display that is created using the more advanced APIs that the default screen shot function might not work with. This is just a theory though; I haven’t tried it myself.

    Reply
    1. Allen Huffman Post author

      Doesn’t Commodore BASIC also have an integer variable type? Just not declared using that syntax? Maybe default is float, and using INTEGER made it non float? Though you’d expect I, J, K and L to also want to be integers.

      Interesting about the source of AmigaBASIC. I never saw BASIC on the Amiga, since the folks I knew with them mostly were showing me MOD files, demos and mind blowing games.

      Reply
    2. Allen Huffman Post author

      I swapped out my phone screen pictures for ones taken from the YouTube video, and made a few more minor additions. I did not notice that the overlayed text actually goes on top of the right monitor bevel. Oops. :) They probably didn’t expect anyone looking at it for more than that second or two.

      Reply

Leave a Reply to MiaM Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.