A Conversation With My 35-year-old Chatbot (Part 2 — Technical Details)
In Part 1, I introduced the chatbot I programmed when I was 12, on my Commodore 64. It includes a video demo of the chatbot in action.
This post is all about the technical side of things: how the program worked, and how I was able to run it, 35 years later.
The Conversation program itself is only 36 lines of code. The rest is composed of DATA statements, where the query / responses are stored. Here’s the whole program (minus the DATA statements):
10 rem ** conversation **
30 dl= 1342
80 print”30 dl=”;dl+2
120 print:print”? “;:gosub470:a$=in$:ifa$=””thena$=x$:print”? “;a$
340 print:print”i don’t understand.”
350 print”please enter three answers at the”:print”prompt:”
360 print”1: “;:gosub470:ifin$=””then120
380 print”2: “;:gosub470:c$=in$
390 print”3: “;:gosub470:e$=in$
410 open 15,8,15: print#15,”s0:conversation”:close15:save”0:conversation”,8:end
500 print” “;:in=asc(i$):ifin=13thenprint:return
Line 20 sets the screen and border colors. Line 30 keeps track of what line of code to start at for the next new DATA statement.
Line 120 prints the opening “?” and gets the user input.
Lines 300–320 begin reading in the responses in the DATA statements, and compares whether the user input matches; if yes, it goes to line 420, which chooses one of the three responses at random, and prints it.
If nothing matches, lines 340–400 ask the user for the new responses, then goes to line 60 to add them to the code.
Lines 60–70 print the new DATA statement with responses the user has added, then modifies line 30 with the new next line number to start with.
Here are some of the DATA statements:
1001 data"hi there!","good evening!"
1002 data"how are you?","fine! and you?"
1003 data"great.. i think.","fine, if you like being me, which i don't."
The user string, plus three possible responses, are stored across two lines of code. In this example,“hi” is the string a user might type in, followed by three possible responses (“hello!”, “hi there”, and “good evening”). The next user string is “how are you?” followed by its three possible responses. I had about 170 possible user responses programmed in.
Running the Code on a PC in 2019
I used to have a lot of Commodore 64s. I had the one from my childhood, plus a bunch of them given to me by people who knew I had an interest. My husband began to ask me if we were going to be opening our own Computer History Museum.
In 2007, I finally managed to transfer all my old files to my PC, and get rid of all of the original hardware. I used an X1541 cable that I bought from a guy in Hungary. It connected the Commodore’s disk drive to my PC’s serial port, and I was able to copy all my disks.
Recently I started to wonder about the chatbot I’d written all those years ago. I installed the C64 Forever emulator, which allowed me to load in those disk images…and run them! One of fun things about the emulator is that it simulates the sound of the disk drive as the files are loading.
Now I was able to run the chatbot. But how could I look at the code? I could type LIST in the emulator and watch a screenful of code at a time, but there was no way to export it. To make it a readable text file, I used DirMaster, which lets you load in a program from the disk file, and convert it into ASCII.
Now I could examine the data statements and peer into my teenage brain. I could also break down the mechanics of the code.
I hope you’ve enjoyed this little trip down nostalgia lane with me, especially if you were a Commodore programmer. Those early days of learning BASIC lit a fire in me, and though I didn’t know it at the time, led to a career teaching computers how to talk.
Cathy Pearl is the author of the book “Designing Voice User Interfaces: Principles of Conversational Experiences” from O’Reilly Media, and is head of conversation design outreach at Google. She’s been working on voice user interfaces for 20 years, but is still waiting for her computer to be able to have a chat about life, the universe, and everything.