-
Notifications
You must be signed in to change notification settings - Fork 0
/
pong.inc
237 lines (183 loc) · 2.6 KB
/
pong.inc
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
ballx db 40
bally db 12
velx db 1
vely db 1
%define bat1x 1
%define bat2x 78
%define batheight 9
bat1 db 0
bat2 db 0
reset:
pusha
mov byte [es:ballx], 40
; mov byte [es:bally], 12 ; for some randomness
popa
ret
update_ball:
pusha
call .updatey
call .updatex
popa
ret
.updatey:
mov dl, byte [es:vely]
mov dh, byte [es:bally]
cmp dl, 0
jg .ygoindown
; Goin' up
dec dh
cmp dh, 0
je .yhitt
jmp .yapply
.yhitt:
mov byte [es:vely], 1
jmp .yapply
.ygoindown:
; Goin' down
inc dh
cmp dh, 24
je .yhitb
jmp .yapply
.yhitb:
mov byte [es:vely], 0
jmp .yapply
.yapply:
mov byte [es:bally], dh
.ydone:
ret
.updatex:
mov dl, byte [es:velx]
mov dh, byte [es:ballx]
cmp dl, 0
jg .xgoinright
; Goin' left
dec dh
cmp dh, bat1x
je .xhitl
jl .xmissl
jmp .xapply
.xhitl:
mov cl, byte[es:bally]
mov ch, byte [es:bat1]
cmp ch, cl
jg .xmissl
add ch, batheight
cmp ch, cl
jl .xmissl
mov byte [es:velx], 1
mov dh, bat1x+2
jmp .xapply
.xmissl: ; increment score plox
call reset
jmp .xdone
.xgoinright:
; Goin' right
inc dh
cmp dh, bat2x
je .xhitr
jg .xmissr
jmp .xapply
.xhitr:
mov cl, byte[es:bally]
mov ch, byte [es:bat2]
cmp ch, cl
jg .xmissr
add ch, batheight
cmp ch, cl
jl .xmissr
mov byte [es:velx], 0
mov dh, bat2x-2
jmp .xapply
.xmissr: ; increment score plox
call reset
jmp .xdone
.xapply:
mov byte [es:ballx], dh
.xdone:
ret
draw_all:
call draw_bat1
call draw_bat2
call draw_ball
ret
draw_bat1:
pusha
mov dh, bat1x
mov dl, [es:bat1]
mov cl, 0x0F
mov ch, 219 ; The block character
call putc
xor ax, ax
mov al, dl
add al, batheight
.dloop:
inc dl
call putc
cmp dl, al
jne .dloop
popa
ret
draw_bat2:
pusha
mov dh, bat2x
mov dl, [es:bat2]
mov cl, 0x0F
mov ch, 219 ; The block character
call putc
xor ax, ax
mov al, dl
add al, batheight
.dloop:
inc dl
call putc
cmp dl, al
jne .dloop
popa
ret
draw_ball:
pusha
mov dh, [es:ballx]
mov dl, [es:bally]
mov cl, 0x07
mov ch, 219 ; The block character
call putc
popa
ret
move_bat1_up:
pusha
mov al, byte [es:bat1]
or al, al
jz .end
dec byte [es:bat1]
.end:
popa
ret
move_bat1_down:
pusha
mov al, byte [es:bat1]
add al, batheight
cmp al, 24
je .end
inc byte [es:bat1]
.end:
popa
ret
move_bat2_up:
pusha
mov al, byte [es:bat2]
or al, al
jz .end
dec byte [es:bat2]
.end:
popa
ret
move_bat2_down:
pusha
mov al, byte [es:bat2]
add al, batheight
cmp al, 24
je .end
inc byte [es:bat2]
.end:
popa
ret