Vintage computing, old video games

This is a game of Tetris written in x86 assembly, in a personal effort to learn more about the instruction set. It uses mode 13h for all drawing, writing directly to address 0xA000 to plot. The index written for each pixel determines the color in a 256-indexed color palette.

It uses DOS interrupts for other functionality like random number generation, and keyboard interaction. For random numbers, it uses the modulus of the current system time. The game keeps going until pieces reach the top of the screen.

The keys i,j,k, and l (or arrow keys for the Win32 version) are used to move the pieces.

In the normal way, rows are cleared when pieces occupy the entire row with no holes.

The form of each ‘tetrad’ (piece) is hardcoded at the top of the source file, and used for drawing the grid and checking for collisions. The walls of the game are fixed. An array called ‘predict’ is used to foreshadow where the user is trying to move the tetrad, so that it cannot be moved through a wall or other landed pieces.

After every ‘tick’ of the game, the current tetrad in play is moved down by one square if possible, or committed to the grid if there are other pieces blocking the way. The game determines the timing using an interrupt, and advances the game after 10 time units, which is around every half a second.

Download binary (DOS com executable)

The source code was assembled using the A86 assembler.

View Source File


Update (5/14/2018): Since the time of writing and building this program, the binary has rotted 🙁

However, I ported the code to Win32 with GDI and built it as a 32-bit PE executable.

Here’s the newly updated Windows version:

Download binary (32-bit Windows executable)

The Win32 source code was assembled using MASM.

View Source File or Download Visual Studio 2018 Project (zip)

The Windows version also has the following changes:

  • Different colors for the different pieces
  • Fixed a bug where rows would sometimes not get cleared correctly
  • Added a ‘next piece’ UI
  • When you get game over instead of crashing it displays a message and you can press Escape to start again

Besides i,j,k,l you can also use the arrow keys.

November 15th, 2006 at 4:04 pm