Of Ones and Zeros
A brief back story on how I became a software engineer.
The year was 1994, armed with a library book and the family computer in a half finished basement, I sat staring into the monochrome abyss of a DOS 6.2 command prompt. I had one mission, program this computer.
By this point in life, I was obsessed with building things. I still remember when my mom gave me my first paper airplane, here was something I could build that works. My twin brother and I shared a prolific imagination. Entire worlds could spawn from a daydream, and we shared it as if we both dreamed it. The younger of my two older sisters is a phenomenal artist, her work inspired me to draw and create things visually. My eldest sisters' love of academia pushed me to encyclopedias and libraries. My father, though absent, was present in the stories of him earning a PhD in physics and building computers the size of rooms.
Perhaps this is how I found myself designing fighter jets with a pencil, paper, and an encyclopedia. My schematic drawings brought jets, cars, and tanks to life. But I couldn't fly or drive them, I couldn't meaningfully share them with others. That's where computers came in, within those ones and zeros you could build a world, experience it, and share it.
Basic
BASIC was a strange yet simple language, the code looked like disjointed sentences, almost English but not quite. There were loops, there were variables, a program called Turtle emerged from the syntax. Imagine a little turtle, sitting on a sheet of paper, holding a pen. The user could tell this turtle to lift the pen off the paper, or press it down into the paper. They could tell the turtle to move up, left, right, or down. By combining these moves, the Turtle could draw.
I was going to build this Turtle, but I needed to find BASIC. I searched Windows 3.11, DOS, and the command prompt, only to find BASIC.COM and BASICA.COM. Unfortunately, they felt cryptic. When I pressed the arrow keys strange symbols appeared. One day, while playing a game called Gorillas, I realized that when it ends you are in a program called QBasic. Q, Basic? I found BASIC! Even better, when I pressed F1, there was help.
QBasic wasn't the same as the BASIC in the book, but I had help as well as all the BASIC code in gorillas.bas, nibbles.bas, and money.bas to get me going. I built my Turtle and started my journey into code. I built more drawing apps, I built games, I learned how to animate sprites, and play 8-bit music through the IBM PC's crude internal speaker. I even made an arcade shooter game with a submarine. In it, you could shoot torpedoes at other subs, and missiles at bomber planes, as they swooped down from above dropping torpedoes into the water. The game play was simple, shoot first and live. Shoot second and get blown up. It had a story, scenes, sound effects, and animation. I really wish I kept it.
Logic Gates
Before I was a BASIC programmer, I read a cartoonish book about logic gates, computer memory, microprocessors, and digital electronic hardware. I didn't understand the significance of this book, but learning how AND, OR, NOT, XOR and other logical operators worked, set my foundations. Learning how ones and zeros were encoded into the little rings of magnetic core memory, and sent through wires as electrical pulses, captured my imagination. By the time I found BASIC, I understood how the electronics worked. This made learning about variables and control structures much more intuitive. Years later, it would help me ace a digital electronics course at DeVry University.
C++ HTML
Eventually I hit the memory limits of QBASIC in DOS, I couldn't load a bitmap file from MS Paint. I needed more power, and the Sam's Teach Yourself C++ in 24 Hours book with Borland C++ compiler was only $30. I begged, I pleaded, I received. I started many promising projects in C++, but I finished few. In no time, I was in high school and the web was no longer a toy. We had GeoCities, Anglefire websites, AOL chat rooms, and InsideTheWeb message boards. I built my first web page on AOL, but my second, I built for my school friends on Angelfire. Web development was easier than C++. I loved making games but when I built websites I could share it immediately, get feedback immediately, and my friends liked it. QBasic faded to memory, C++ yo-yoed in the background, and websites took center stage.
College
Bill Gates didn't need it, why did I? I had to grow up, no time for kiddie websites. I discovered OpenGL and 3D programming thanks to a dorm mate in college and a website called Neon Helium. I was going to make a real game, but I still needed a real job, or whatever you call federal work study employment. I was a web developer again, but I moonlit my way through data structures and algorithms. I learned about templates, binary space partitioning trees, queues, linked lists, quad trees, n-ary trees, graphs, enough to test out of the first two years of Computer Science courses. I did this all in the name of making a video game. Why did I need school again? For Greek history?
9-11 & The Army
"Read a book," "go outside and play," my mom demanded both. By college my running shoes and bicycle turned the enormous campus of the University of Maryland, College Park, into a gym I could orbit daily. So when the towers fell, and the Army knocked, and college tuition fees piled, I made my choice. I joined for tech, and I ended up as an Army Reservist in Psychological Operations. Then the wars started. During 13 long weeks of Pysop training, I started to miss school.
Apparently, I had taken the "why do I need school" experiment too far, I needed a new school. One that focused on technology, was more modern, and had smaller class sizes. DeVry University accepted my admission; tuition rose, credit hours fell, my grades soared. I built circuits, tested out of more classes, programmed microcontrollers, joined an IT professionals club, and built content management systems on a LAMP stack. I also made lots of really awesome friends, who to this day are my extended family. Then I deployed to Iraq.
Life is short and I am really blessed.
Soldiers get free room and board in war zones, and interest rates on savings accounts were high. I was 24, cash rich, and determined. I got a full-time job as a software engineer and I needed to graduate, so I switched my education to full-time. Evening classes faded into night, I would appear in my mom's driveway with no memory of the drive home. I graduated, I left my mom's house, and I bought my own.
So there I was, a full-time engineer with a house, a car, and a career. I made it!
Code
The code sample for this entry will be an attempt to recreate the Turtle application as I remembered it. I want this recreation to capture the wonder, simplicity, and approachability of my first programming experience. This was not the first thing I ever programmed, but this was the first program that I read about and was excited to make.
Since I do not have the code from my old projects or even remember the name of the book that I got it from, I have to rebuild this from memory and use some creativity to fill in the blanks. Additionally, getting QBASIC to run on a modern computer requires a bit of work, so I included modern adaptations in Go and Python, although these don't quite capture the simplicity of the QBASIC experience.
Code Breakdown
I could not recall how moving the cursor worked or if the cursor was even visible, so I found a solution to render the cursor separately from the drawing. In QBASIC some screen modes have multiple pages of video memory.
You can think of these pages as sheets of paper where only one sheet is visible to the user. In this implementation, page 0 is used for immediate rendering. Everything that is drawn immediately shows on this page. Page 1 is used to keep a copy of the drawn image. Every time an update is made that I want to keep showing to the user, I copy it to page 1. That way, when I want to erase things that I don't want to keep, I can copy page 1 back to page 0. Finally, page 3 is the page that the user can always see. When I want the user to see what I have rendered, I copy page 0 to page 3.
So I start off by setting up the screen display to mode 8, with page 0 as the active page, and page 3 as the displayed page. Then I clear the screen.
SCREEN 8, , 0, 3
CLS
Then I render the instructions and copy that to the drawing page so it is always displayed to the user.
PRINT "Press escape to exit"
PRINT "Use arrow keys to move the cursor"
PRINT "Press space bar to toggle pen"
PCOPY 0, 1
Then I start a DO
loop which runs the primary code. This loop reads the keyboard input and updates the screen. I chose to use INKEY$
to capture input as it's very simple.
DO
a$ = INKEY$
SELECT CASE a$
CASE UpKey$
py = py - 1
CASE DownKey$
py = py + 1
CASE LeftKey$
px = px - 1
CASE RightKey$
px = px + 1
CASE " "
IF isPenDown = 1 THEN
isPenDown = 0
ELSE
isPenDown = 1
END IF
END SELECT
...
LOOP UNTIL a$ = EscKey$
This code updates the py and px coordinates as the user presses the arrow keys. It also toggles the isPenDown
variable when the user presses space bar.
Each run of the loop needs to start with a fresh copy of the current drawing from video page 1 which we get with this line.
PCOPY 1, 0
After we load the drawing we can update it if the pen is down by drawing the cursor, the current cursor coordinates and copying that to page 1.
IF isPenDown = 1 THEN
PSET (px, py)
PCOPY 0, 1
END IF
Then we draw the cursor and show the user everything we've drawn by copying page 0, the immediate rendering page, to page 3, which is the page displayed to the user.
PSET (px, py)
PCOPY 0, 3
To make the cursor easier to see, I colored the cursor differently than the line being drawn, and I change the color based on whether the pen is up or down. That changes our previous three blocks of code as follows.
PCOPY 1, 0
CursorColor = PenUpColor
IF isPenDown = 1 THEN
COLOR LineColor
PSET (px, py)
PCOPY 0, 1
CursorColor = PenDownColor
END IF
COLOR CursorColor
PSET (px, py)
PCOPY 0, 3
And now we have a working Turtle program in QBASIC, which should be suitable for a beginner programmer to learn from.
Resources
- QBasic They managed to preserve this one piece of my childhood.
- How to Use Your IBM PC in 10 Easy Video Lessons, I wish I had this 1994!
- Sam's Teach Yourself C++ in 24 Hours Not the original, but this is close.
- Neon Helium Somehow, this artifact of internet history, is still alive.