Repository navigation
Expand file tree
/
Copy pathblit.asm
More file actions
235 lines (199 loc) · 10.9 KB
/
Copy pathblit.asm
File metadata and controls
235 lines (199 loc) · 10.9 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
; #########################################################################
;
; blit.asm - Assembly file for EECS205 Assignment 2
;
;
; #########################################################################
.586
.MODEL FLAT,STDCALL
.STACK 4096
option casemap :none ; case sensitive
include blit.inc ; Take a look at this file to understand how
; bitmaps are declared
.DATA
;; You may declare helper variables here.
bmpX Dword 0
bmpY Dword 0
dWidth Dword ?
dHeight Dword ?
screenX Dword ?
screenY Dword ?
centerX Dword ?
centerY Dword ?
srcbitmap Dword ?
est Dword ?
.CODE
; Routine which draws a bitmap to the screen
BlitReg PROC
;; Here is some C-like pseudocode. You can use this as a starting point
;; (or start from scratch if you feel like it)
;; Feel free to declare variables (global) if it helps. There is a pretty
;; good chance that you won't fit everything in registers
;; EDX pointer to SrcBitmap
mov srcbitmap, edx
mov centerX, esi ;;centerX <-ESi
mov centerY, edi ;;centerY <- EDi
mov ebx, (EECS205BITMAP PTR [edx]).dwWidth ;;EBx<-dwWidth
mov dWidth, ebx ;;dwidth<-dwWidth
mov ebx, (EECS205BITMAP PTR [edx]).dwHeight ;;ebx<-dwHeight
mov dHeight,ebx ;;dHeight<-dwHeight
;; for(bmpY = 0; bmpY < srcBitmap->dwHeight; bmpY++)
mov bmpY, 0
jmp condition1
body1:
;; for(bmpX = 0; bmpX < srcBitmap->dwWidth; bmpX++)
mov bmpX, 0
jmp condition2
body2:
;; {
;; screenX = centerX + bmpX - srcBitmap->dwWidth/2;
;;
mov eax, bmpX
mov screenX, eax ;;ScreenX<-bmpX
mov esi, centerX ;;esi<-CenterX
add screenX, esi ;;ScreenX<-bmpX+CenterX
mov esi, screenX ;;ESI<-centerX+bmpX
mov ebx, dWidth ;;ebx<-dwWidth
shr ebx,1 ;;ebx<-dwWidth/2
sub esi, ebx ;;esi<- centerX+bmpX-dwWidth/2
mov screenX, esi
;; screenY = centerY + bmpY - srcBitmap->dwHeight/2;
mov eax, bmpY
mov screenY, eax ;;ScreenY<-bmpY
mov esi, centerY ;;esi<-centerY
add screenY, esi ;;ScreenY<-centerY+bmpY
mov esi, screenY ;;esi<-ScreenY
mov ebx, dHeight ;;ebx<-dwHeight
shr ebx,1 ;;ebx<-dwHeight/2
sub esi, ebx ;;ebx<- centerY+bmpY-dwHeight/2
mov screenY, esi
;; if (srcBitmap->lpBytes[bmpY*srcBitmap->dwWidth+bmpX] != srcBitmap->bTransparent
;; screenX >= 0 && screxenX <= 639
;; screenY >= 0 && screenY <= 479)
mov edx, srcbitmap ;;edx<- ptr to bitmap
mov cl,(EECS205BITMAP PTR [edx]).bTransparent ;;cl<-btransparent
mov esi, (EECS205BITMAP PTR [edx]).lpBytes ;;esi<- addr lpbytes
mov eax, bmpY ;;eax<-bmpy
mov edx, (EECS205BITMAP PTR [edx]).dwWidth
mov ebx, dWidth ;;ebx<-dWidth
mul ebx ;;eax<-bmpy*dwidth
add eax,bmpX ;;eax<-bmpy*width+bmpX
add esi, eax ;;esi<- esi +eax
mov al, BYTE PTR[esi] ;;al<-lpbytes[bmpY*dwidth+bmpx]
cmp cl, al
je elseskip
cmp screenX, 0 ;;screenX >= 0
jl elseskip
cmp screenX, 639 ;;screenX <= 639
jg elseskip
cmp screenY, 0 ;;screenY >= 0
jl elseskip
cmp screenY,479 ;;screenY <= 479
jg elseskip
then:
;;
;; lpDisplayBits[screenY*dwPitch + screenX] =
;; srcBitmap->lpBytes[bmpY*srcBitmap->dwWidth+bmpX];
mov eax, dwPitch ;; eax<-dwPitch
mul screenY ;; eax<-dwPitch*ScreenY
add eax, screenX ;; eax<-dwPitch*ScreenY+screenX
mov ebx, eax ;; ebx<-dwPitch*ScreenY+ScreenX
mov eax, dWidth ;;eax<- dwidth
mul bmpY ;;eax<- dwidth*bmpy
add eax, bmpX ;;eax<- dwidth*bmpY+bmpX
mov ecx, eax ;;ecx<- dwidth*bmpY+bmpX
mov edx, srcbitmap ;;edx<- ptr to bitmap
mov eax, (EECS205BITMAP PTR [edx]).lpBytes ;;EAX<- ADDR lpbytes
add eax, ecx ;;EAX<-ADDR lpbytes + dwidth*bmpY+bmpX
mov cl, BYTE PTR [eax] ;;cl<-byte at addr lpbytes + dwidth*bmpY+bmpX
mov eax, lpDisplayBits ;;eax<- lpDisplayBits
add eax, ebx ;;eax<- addr lpdisplaybits+dwPitch*ScreenY+ScreenX
mov BYTE PTR [eax], cl ;; addr at eax <- cl
elseskip:
inc bmpX
condition2:
mov ebx, dWidth
cmp bmpX, ebx
jl body2
inc bmpY
condition1:
mov ebx, dHeight
cmp bmpY, ebx
jl body1
ret ;; Don't delete this line
BlitReg ENDP
.DATA
StarBitmap EECS205BITMAP <32, 36, 0ffh,, offset StarBitmap + sizeof StarBitmap>
BYTE 0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0feh
BYTE 0feh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0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