Repository navigation
Expand file tree
/
Copy pathsprites.asm
More file actions
280 lines (240 loc) · 5.49 KB
/
Copy pathsprites.asm
File metadata and controls
280 lines (240 loc) · 5.49 KB
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
sprites:
.ball ballSprite\
c.ALPHA,\
c.LIGHTBLUE,\
c.AQUA,\
c.BLUE
.wall hvWallSprite\
c.WHITE20,\
c.WHITE40,\
c.WHITE60,\
c.WHITE80,\
c.WHITE,\
c.WHITE80,\
c.WHITE60,\
c.WHITE40,\
c.WHITE20
.lCorner leftCornerSprite\
c.WHITE20,\
c.WHITE40,\
c.WHITE60,\
c.WHITE80,\
c.WHITE,\
c.WHITE80,\
c.WHITE60,\
c.WHITE40,\
c.WHITE20
.rCorner rightCornerSprite\
c.WHITE20,\
c.WHITE40,\
c.WHITE60,\
c.WHITE80,\
c.WHITE,\
c.WHITE80,\
c.WHITE60,\
c.WHITE40,\
c.WHITE20
.lPaddle leftPaddleCapSprite\
c.ALPHA,\
c.AQUA,\
c.LIGHTBLUE,\
c.BLUE,\
c.DARKBLUE
.rPaddle rightPaddleCapSprite\
c.ALPHA,\
c.AQUA,\
c.LIGHTBLUE,\
c.BLUE,\
c.DARKBLUE
.paddle paddleBodySprite\
c.AQUA,\
c.DARKBLUE,\
c.BLUE
.brickmap brickSprite 0, 1, 2
; void drawSprite(word x, word y, word height, word width, word <si> spritePtr, word <di> colorMapPtr)
; Assumes DS is set to the data segment and ES to any video buffer
; If DI is null, no color map is used to draw the sprite.
drawSprite:
pusha
mov word [.colormap], di
push ax
call coordToPtr
mov di, ax
pop ax
.nextY:
push ax
push cx
push dx
mov cx, dx
.nextX:
cmp ax, 320
ja @f
cmp bx, 200
ja @f
mov dl, byte [ds:si]
cmp word [.colormap], 0
jz .putPixel
.loadFromMap:
push bx
mov bx, word [.colormap]
mov dh, 0
add bx, dx
mov dl, byte [ds:bx]
pop bx
.putPixel:
cmp dl, c.ALPHA
je @f
mov byte [es:di], dl
@@:
inc si
inc di
inc ax
loop .nextX
pop dx
pop cx
pop ax
add di, 320
sub di, dx
dec bx
loop .nextY
.end:
popa
ret
.colormap dw ?
; void drawBorder(void)
; Expects ES to point to buffer B
drawBorder:
pusha
xor di, di
mov ax, field.xMin - 9
mov bx, field.yMin
mov dx, vertWallSprite.width
mov si, sprites.wall
mov cx, field.yMax - field.yMin
.vert1:
push cx
mov cx, vertWallSprite.height
call drawSprite
pop cx
inc bx
loop .vert1
mov ax, field.xMax
mov bx, field.yMin
mov cx, field.yMax - field.yMin
.vert2:
push cx
mov cx, vertWallSprite.height
call drawSprite
pop cx
inc bx
loop .vert2
mov ax, field.xMin
mov bx, field.yMax + horizWallSprite.height - 1
mov dx, horizWallSprite.width
mov cx, field.xMax - field.xMin
.horiz:
push cx
mov cx, horizWallSprite.height
call drawSprite
pop cx
inc ax
loop .horiz
mov ax, field.xMin - 9
mov bx, field.yMax + leftCornerSprite.height - 1
mov cx, leftCornerSprite.height
mov dx, leftCornerSprite.width
mov si, sprites.lCorner
call drawSprite
mov ax, field.xMax
mov cx, rightCornerSprite.height
mov dx, rightCornerSprite.width
mov si, sprites.rCorner
call drawSprite
popa
ret
; void drawPaddle(word x, word y)
; Expects ES to point to buffer A
drawPaddle:
pusha
xor di, di
mov cx, leftPaddleCapSprite.height
mov dx, leftPaddleCapSprite.width
mov si, sprites.lPaddle
call drawSprite
add ax, leftPaddleCapSprite.width
mov dx, paddleBodySprite.width
mov si, sprites.paddle
mov cx, paddle.width - leftPaddleCapSprite.width - rightPaddleCapSprite.width
.drawBody:
push cx
mov cx, paddleBodySprite.height
call drawSprite
inc ax
pop cx
loop .drawBody
mov cx, rightPaddleCapSprite.height
mov dx, rightPaddleCapSprite.width
mov si, sprites.rPaddle
call drawSprite
popa
ret
; void drawBall(word x, word y)
; Expects ES to point to buffer A
drawBall:
pusha
sub ax, ballSprite.hotspot_xy
add bx, ballSprite.hotspot_xy
mov cx, ballSprite.height
mov dx, ballSprite.width
mov si, sprites.ball
xor di, di
call drawSprite
popa
ret
; void drawBrick(word x, word y, byte <cl enum btype> type)
; Expects ES to point to buffer A
drawBrick:
pusha
cmp cl, btype.RED
jne @f
mov di, cm.REDBRICK
jmp .draw
@@:
cmp cl, btype.GREEN
jne @f
mov di, cm.GREENBRICK
jmp .draw
@@:
cmp cl, btype.BLUE
jne @f
mov di, cm.BLUEBRICK
jmp .draw
@@:
xor di, di
.draw:
mov cx, brickSprite.height
mov dx, brickSprite.width
mov si, sprites.brickmap
call drawSprite
popa
ret
; void vertLine(word x, word y, word length, byte <dl> color)
vertLine:
pusha
call coordToPtr
mov di, ax
.nextY:
mov byte [es:di], dl
add di, 320
loop .nextY
popa
ret
; void horizLine(word x, word y, word length, byte <dl> color)
horizLine:
pusha
call coordToPtr
mov di, ax
mov al, dl
rep stosb
popa
ret