📜 ⬆️ ⬇️

The smallest game in the world (58 bytes)

For those who read the article in the sandbox: added the section "Can I make the game smaller?".

After reading the story of one byte , I remembered my story.

When I was in school and was just starting to program, I was very attracted to assembler and optimization. Namely - painstaking optimization, with clock and byte counts. During the summer holidays, my cousin and I had the idea to write the smallest game in the world.

The first prototype, 80 bytes in size, was ready the next day. (Since I didn’t even guess about version control, it remains to believe the memories). From that moment on, my fight for bytes began. I remember that quite quickly the size was reduced to 65 (or so), then every byte was given more and more with great difficulty. By the end of the summer, the result was 58 bytes.
')

Plot and management


You are driving along the highway in a truck with two trailers. To your left is a dividing strip, to the right is a grassside curb. On the road there are people and trees (maybe pits). Your task: do not shoot down people and do not crash into trees (do not fall into the pits).
Control: left-right arrows - turn; Esc - pause.


Screenshot




Source


begin: <br>
; ds <br>
push 0b800H <br>
pop ds <br>
; 40×25 <br>
int 10H <br>
; bx = 700H - , <br>
mov bh, 7H <br>
<br>
main_loop: <br>
; <br>
xchg cx, ax ; mov ah, 0 <br>
int 1AH <br>
mov [bx], dl <br>
delay: <br>
int 1AH <br>
cmp [bx], dl <br>
je delay <br>
<br>
; si - <br>
xchg ax, si <br>
add al, dl <br>
xchg ax, si <br>
<br>
xchg ax, cx ; mov cx, 0 <br>
<br>
; <br>
in al, 60H <br>
cmp al, 77 <br>
jnz keytest1 <br>
; <br>
inc bx <br>
inc bx <br>
keytest1: <br>
; <br>
ja keytest2 <br>
dec bx <br>
dec bx <br>
keytest2: <br>
; <br>
mov ah, 0CH <br>
int 21H <br>
; 1 <br>
mov ax, 0701H <br>
mov dx, 1827H <br>
int 10H <br>
<br>
; <br>
mov [si], ax <br>
; <br>
mov [di+51], dx <br>
; <br>
cmp [bx], dh <br>
ja main_loop <br>
<br>
ret <br>

Archive with source code and binary (Tasm was used for compilation)

Comments


In XP, the program works, but the timer does not work smoothly and at first the keyboard state is not reset. DosBox works without problems.

In the source code, two instructions (push 0b800H and mov [di + 51], dx) are written in machine code (db 68H, 00H, 0b8H and db 89H, 55H, 51H), this is due to the fact that Tasm did not perceive them in compilation by default. In my opinion, he demanded the inclusion of x386 instructions, although I could be wrong.

Is it possible to make the game smaller?


Probably yes. A lot of space is occupied by the screen scrolling (8 bytes) and delay (10 bytes). If you change the direction of movement (obstacles to move up from the bottom up), then the scroll can be replaced with a fast output of the line feed character ( mov al, 0Ch; int 29h ). Delay can be replaced by checking the status of a double word at 0040: 006Ch. There should be a timer counting counter from midnight (Timer ticks since midnight).

UPD: Thank you! Transferred to the blog "Assembler"

UPD2: Imp5 tells me that I’m not quite right. Shifticida - a game for two players, which occupies 32 bytes. So the correct name of the topic: "The smallest racing game in the world"

Source: https://habr.com/ru/post/64254/


All Articles