-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblit.asm
More file actions
320 lines (237 loc) · 6.07 KB
/
Copy pathblit.asm
File metadata and controls
320 lines (237 loc) · 6.07 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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
; #########################################################################
;
; #########################################################################
.586
.MODEL FLAT,STDCALL
.STACK 4096
option casemap :none ; case sensitive
include stars.inc
include lines.inc
include trig.inc
include blit.inc
.DATA
;; If you need to, you can place global variables here
.CODE
DrawPixel PROC USES eax ebx ecx x:DWORD, y:DWORD, color:DWORD
mov ecx, color ;Store the color of th epixel
;First, Check screen boundaries
cmp y, 0 ;If out of boundary left corner
jl break
cmp x, 0
jl break
cmp y, 480 ;If out of bounadry right corner 640 x 480
jge break
cmp x, 640
jge break
;Location of the pixel (if in bound)
mov eax, y
mov ebx, 640
mul ebx ;640 (x pix) * y to figure out the y coordinate as address in array
add eax, x ; + x to figure out x coordinate as address in the array
add eax, ScreenBitsPtr ;make eax the address of corresponding element in ScreenBits array
mov BYTE PTR[eax], cl;
break:
ret ; Don't delete this line!!!
DrawPixel ENDP
BasicBlit PROC USES eax ebx ecx edx edi ptrBitmap:PTR EECS205BITMAP , xcenter:DWORD, ycenter:DWORD
LOCAL x_i:DWORD, x_f:DWORD, y_i:DWORD, y_f:DWORD, counter:DWORD, trans_color:BYTE
;Set up pointer for the bitmap
mov ecx, ptrBitmap
mov bl, (EECS205BITMAP PTR [ecx]).bTransparent
mov trans_color, bl
;Coordinate initialization (Half - Half = Initial) / (Half + Half = Final)
mov ebx, xcenter ;Set both sex initial and final to xcenter
mov x_i, ebx
mov x_f, ebx
mov ebx, (EECS205BITMAP PTR[ecx]).dwWidth ;get width
sar ebx, 1 ;width/2
sub x_i, ebx ;x initial
add x_f, ebx ;x final
;Same for Y coordinate
mov ebx, ycenter
mov y_i, ebx
mov y_f, ebx
mov ebx, (EECS205BITMAP PTR [ecx]).dwHeight
sar ebx, 1
sub y_i, ebx
add y_f, ebx
mov counter, 0 ;initialize the i value for the loop
;Looping through the bitmap
xLoop:
mov ebx, x_f
;x_i < x_f?
cmp x_i, ebx
jge yLoop ;Skip to y
;Else
mov ebx, (EECS205BITMAP PTR [ecx]).lpBytes
mov edi, counter
mov dl, BYTE PTR [ebx + edi]
mov al, trans_color
;trans_color == color?
cmp dl, al
je break
;Else
invoke DrawPixel, x_i, y_i, [ebx + edi] ;Draw a cooresponding pixel
break:
inc counter
;x_i++, for next column
inc x_i
jmp xLoop
yLoop:
inc y_i
mov ebx, y_i
;y_i >= y_f?
cmp ebx, y_f
jge break2
;Else
mov ebx, (EECS205BITMAP PTR [ecx]).dwWidth
sub x_i, ebx
jmp xLoop ;Update x
break2: ;end
ret ; Don't delete this line!!!
BasicBlit ENDP
RotateBlit PROC USES eax ebx ecx edx esi edi lpBmp:PTR EECS205BITMAP, xcenter:DWORD, ycenter:DWORD, angle:FXPT
LOCAL dstX:DWORD, dstY:DWORD, srcX:DWORD, srcY:DWORD, shiftX:DWORD, shiftY:DWORD, trans_color:BYTE, dstWidth:DWORD, dstHeight:DWORD
invoke FixedCos, angle
mov ecx, eax ;cosa = FixedCos(angle)
invoke FixedSin, angle
mov edi, eax ;sina = FixedSin(angle)
mov esi, lpBmp ;esi = lpBitmap
mov bl, (EECS205BITMAP PTR [esi]).bTransparent
mov trans_color, bl ;store the transparent color in trans_color
;shiftX Calc
mov eax, (EECS205BITMAP PTR [esi]).dwWidth
imul ecx
mov shiftX, eax
sar shiftX, 1 ;EECS205BITMAP PTR [esi]).dwWidth * cosa / 2
mov eax, (EECS205BITMAP PTR [esi]).dwHeight
imul edi
sar eax, 1 ;EECS205BITMAP PTR [esi]).dwHeight * sina / 2
sub shiftX, eax ;set shiftX
;shiftY Calc
mov eax, (EECS205BITMAP PTR [esi]).dwHeight
imul ecx
mov shiftY, eax
sar shiftY, 1 ;Divide height by 2
mov eax, (EECS205BITMAP PTR [esi]).dwWidth
imul edi
sar eax, 1 ;Divide height by 2
add shiftY, eax
;dstWidth Calc
mov eax, (EECS205BITMAP PTR [esi]).dwWidth
add eax, (EECS205BITMAP PTR [esi]).dwHeight ;(EECS205BITMAP PTR [esi]).dwWidth + (EECS205BITMAP PTR[esi]).dwHeight
;dstHeight= dstWidth
mov dstWidth, eax
mov dstHeight, eax
;Setting up forloop condition
neg eax
mov dstX, eax ;dstX = -dstWidth
mov dstY, eax ;dstY = -dstHeight
;Integer transformation
sar shiftY, 16
sar shiftX, 16
jmp x_cond ;First Loop
;Inside the second loop
yLoop:
;srcX = dstX*cosa + dstY*sina
mov eax, dstX
imul ecx
mov srcX, eax
mov eax, dstY
imul edi
add srcX, eax
;srcY = dstY*cosa – dstX*sina
mov eax, dstY
imul ecx
mov srcY, eax
mov eax, dstX
imul edi
sub srcY, eax
;Integer transformation
sar srcX, 16
sar srcY, 16
;Insde If condition
;srcX >= 0
cmp srcX, 0
jl break
;&&
;srcX < (EECS205BITMAP PTR [esi]).dwWidth
mov eax, (EECS205BITMAP PTR [esi]).dwWidth
cmp srcX, eax
jge break
;&&
;srcY >= 0
cmp srcY, 0
jl break
;&&
;srcY >= 0 && srcY < (EECS205BITMAP PTR [esi]).dwHeight
mov eax, (EECS205BITMAP PTR [esi]).dwHeight
cmp srcY, eax
jge break
;&&
;(xcenter+dstX-shiftX) >=0
mov eax, xcenter
add eax, dstX
sub eax, shiftX
cmp eax, 0
jl break
;&&
;(xcenter+dstX-shiftX) < 639
mov eax, xcenter
add eax, dstX
sub eax, shiftX
cmp eax, 639
jge break
;&&
;(ycenter+dstY-shiftY) >=0
mov eax, ycenter
add eax, dstY
sub eax, shiftY
cmp eax, 0
jl break
;&&
;(ycenter+dstY-shiftY) < 479
mov eax, ycenter
add eax, dstY
sub eax, shiftY
cmp eax, 479
jge break
;&&
;bitmap pixel (srcX,srcY) is not transparent?
mov eax, (EECS205BITMAP PTR [esi]).dwWidth ; Color (srcX, srcY)
mov edx, srcY
imul edx
add eax, srcX
add eax, (EECS205BITMAP PTR [esi]).lpBytes
mov dl, BYTE PTR [eax]
;Is it transparent?
cmp dl, trans_color
je break
;xcenter+dstX-shiftX
mov ebx, xcenter
add ebx, dstX
sub ebx, shiftX
;ycenter+dstY-shiftY
mov edx, ycenter
add edx, dstY
sub edx, shiftY
invoke DrawPixel, ebx, edx, BYTE PTR [eax] ;DrawPixel(xcenter+dstX-shiftX, ycenter+dstY-shiftY, bitmap pixel)
break:
inc dstY ;dstY++
y_cond: ;Second loop condition
;dstY < dstHeight
mov eax, dstY
cmp eax, dstHeight
jl yLoop
inc dstX ;dstX++
x_cond: ;First Loop condition
; dstX < dstWidth
mov eax, dstHeight
neg eax
mov dstY, eax
mov eax, dstX
cmp eax, dstWidth
jl y_cond
ret ; Don't delete this line!!!
RotateBlit ENDP
END