2 min read

Running my high-school code from 2008 again

Running my high-school code from 2008 again

The age of writing code by hand has ended. These days AI writes all of my code, and apart from the odd bit for fun, I don't expect to write another line myself. Strangely, that has left me nostalgic for all the code I did write by hand.

So I went back to the oldest programs I still have: Turbo C++ programs I wrote in high school in 2008. With AI's help they run again, right here in the browser. Nothing is rewritten. The source is byte-for-byte what I typed in 2008, compiled by a real Borland compiler from 1990 and running in DOSBox.

One of my favourite things to do was to write programs that simulated what I was learning in physics: a ball bouncing with a coefficient of restitution, waves spreading out from a point and reflecting off the edges of the screen, and electric field lines around charges placed on a 2D grid. I also wrote a sudoku solver and a tic-tac-toe game. Three of these survived in my old backups. Here are two of them.

Electric field lines (August 2008)

You place up to five point charges and it traces the electric field lines out of each one. Each step adds up the push and pull of every charge (falling off as 1/r²) and moves 3 pixels in that direction.

Try a dipole: 200, 240, 3, 1, then 440, 240, -3, 0 (x, y, charge, then 1 for another charge or 0 to draw).

Tic-tac-toe vs. the computer (September 2008)

You play X; the computer plays O. Tap a square or type its row and column (11 to 33). The computer tries every empty square, scores the board it would leave behind, and plays the best one.

How it works

Each program is compiled by Borland Turbo C++ 1.01, running inside DOSBox on my machine. The compiled EXE and Borland's graphics driver are packaged for js-dos, which runs DOSBox, compiled to WebAssembly, in your browser. The source code of the programs can be found here: FIELD.cpp (electric field lines) and ALBB4.cpp (tic-tac-toe).