← jukimv1986 Classics revisited

Puzzle

2008 · x86 ASM
MS-DOS Prompt - PUZZLE

// How to play

The command is already typed at the C:\> prompt: press Enter to run PUZZLE. The blinking underline, the DOS text cursor, is your pointer: move it with i (up), j (left), k (down) and l (right). Put it on a letter next to the empty square and press Space to slide that letter into the gap. Sort the letters (A B C D / F G H I / J K M N / O P Z) with the gap in the bottom-right corner.

You have 99 moves (Moviments counts down) and the Segons clock runs up to 99. The clock is only checked when you press a key. q quits. When the program ends you are back at the C:\> prompt: press F3 (or type PUZZLE) and Enter to play again. Only lower-case keys count; the arrow keys and capitals do nothing, as in the original. On a touchscreen use the keys under the window; PUZZLE ↵ types the command for you.

// Revisited

Puzzle is a Quinze-Puzle (15-puzzle) Joaquim wrote in x86 assembly for DOS as a university assignment, a pràctica, around 2008. It clears the 80×25 text screen, draws the board with code-page 437 line characters, reads keys through DOS and hooks the PC's clock interrupt to count the seconds. The assignment fixed the starting position, so every game starts from the same board:

;AETC Pràctica: Quinze-Puzle
;Cognoms i Nom: Virgili Llop, Joaquim
...
  ;Quan lliureu la pràctica deixeu la matriu inicialitzada amb aquests valors.
  Fitxa  db 'ABCD' ;Matriu 4x4 on tenim les fitxes
         db 'FGHI'
         db 'JK Z'
         db 'OPNM'

The comment says: “When you hand in the assignment, leave the matrix initialised with these values.” This page was rebuilt from that original puzzle.asm. Every routine (MostraTauler, PosIni, ActualitzaTauler, LlegirTecla, MouCursor, MouFitxa, VerificaFi and the RAIrellotge clock handler) is ported line by line into JavaScript and keeps its Catalan name. Its BIOS and DOS calls write into an emulated VGA text screen drawn with the VGA 8×16 font and the 16-colour palette. The clock runs at the PC timer's 18.2 ticks per second and, like the original, advances one “second” every 19 ticks. The only additions are the minimal C:\> prompt around it (it understands PUZZLE, CLS and F3) so you can run it again, the touch keys, and a pause of the clock while the tab is hidden.