1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
org 0x7C00
init:
mov word [body_start], 2000
mov word [body_end], 2000
mov word [head_dir], -160
; clear the screen
mov ax, 0xB800
mov es, ax
mov cx, (80 * 25)
xor ax, ax
mov di, ax
rep stosw
; clear the game memory
mov es, ax
mov di, 0x0500
mov cx, (80 * 25)
rep stosw
call game_tick
; store the original timer isr
cli
xor ax, ax
mov ax, [32]
mov [orig_isr8], ax
mov ax, [34]
mov [orig_isr8 + 2], ax
; install our timer isr
mov word [32], timer_tick
mov word [34], 0
sti
.loop:
jmp .loop
orig_isr8: dd 0
tick_count: db 0
timer_tick:
mov al, [tick_count]
inc al
cmp al, 9
jl .nogametick
call game_tick
.nogametick:
mov [tick_count], al
jmp far [orig_isr8]
game_tick:
; grab some vars before switching to game seg
mov si, [body_start]
mov di, [body_end]
mov dx, [head_dir]
mov ax, 0x0050
mov ds, ax
mov es, ax
.noinit:
; update head position
mov ax, si
add ax, dx
mov [si], ax
mov si, ax
mov bx, [di]
mov word [di], 0
mov di, bx
; check if body overlapping
cmp word [si], 0
je .nodie
add sp, 2
jmp init
.nodie:
.end:
xor ax, ax
mov ds, ax
mov es, ax
mov [body_start], si
mov [body_end], di
ret
head_dir: dw 0
body_start: dw 0
body_end: dw 0
; Pad out the rest of the boot sector and add magic bytes
times 510 - ($ - $$) db 0
dw 0xAA55
; Pad out the rest of a 1.44MB floppy image
times (2880 * 512) - ($ - $$) db 0
|