File: asmlock.s

package info (click to toggle)
allegro4.1 2%3A4.1.15-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 19,924 kB
  • ctags: 14,030
  • sloc: ansic: 121,716; asm: 16,973; cpp: 3,840; sh: 2,114; makefile: 706; objc: 561; python: 181; pascal: 105; perl: 73
file content (299 lines) | stat: -rw-r--r-- 6,407 bytes parent folder | download | duplicates (2)
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
/*         ______   ___    ___
 *        /\  _  \ /\_ \  /\_ \
 *        \ \ \L\ \\//\ \ \//\ \      __     __   _ __   ___ 
 *         \ \  __ \ \ \ \  \ \ \   /'__`\ /'_ `\/\`'__\/ __`\
 *          \ \ \/\ \ \_\ \_ \_\ \_/\  __//\ \L\ \ \ \//\ \L\ \
 *           \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
 *            \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
 *                                           /\____/
 *                                           \_/__/
 *
 *      Asm functions for Windows bitmap locking.
 *
 *      By Isaac Cruz.
 *
 *      Improved dirty rectangles mechanism by Eric Botcazou.
 *
 *      See readme.txt for copyright information.
 */


#include "src/i386/asmdefs.inc"


.text


/* gfx_directx_write_bank:
 *  edx = bitmap
 *  eax = line
 */
FUNC (gfx_directx_write_bank)

      /* check whether bitmap is already locked */
      testl $BMP_ID_LOCKED, BMP_ID(%edx)
      jnz Locked

      /* lock the surface */
      pushl %ecx
      pushl %eax
      pushl %edx
      pushl %edx  /* argument */
      call *GLOBL(ptr_gfx_directx_autolock)
      popl %edx
      popl %edx
      popl %eax
      popl %ecx

   Locked:
      /* get pointer to the video memory */
      movl BMP_LINE(%edx,%eax,4), %eax

      ret




/* gfx_directx_unwrite_bank:
 *  edx = bmp
 */
FUNC (gfx_directx_unwrite_bank)

      /* only unlock bitmaps that were autolocked */
      testl $BMP_ID_AUTOLOCK, BMP_ID(%edx)
      jz No_unlock

      /* unlock surface */
      pushl %ecx
      pushl %eax
      pushl %edx
      pushl %edx  /* argument */
      call *GLOBL(ptr_gfx_directx_unlock)
      popl %edx
      popl %edx
      popl %eax
      popl %ecx

      /* clear the autolock flag */
      andl $~BMP_ID_AUTOLOCK, BMP_ID(%edx)

   No_unlock:
      ret




/* gfx_directx_write_bank_win:
 *  edx = bitmap
 *  eax = line
 */
FUNC (gfx_directx_write_bank_win)
      pushl %ecx

      /* clobber the line */
      movl GLOBL(wd_dirty_lines), %ecx
      addl BMP_YOFFSET(%edx), %ecx
      movb $1, (%ecx,%eax)   /* wd_dirty_lines[line] = 1; (line has changed) */

      /* check whether bitmap is already locked */
      testl $BMP_ID_LOCKED, BMP_ID(%edx)
      jnz Locked_win

      /* lock the surface */
      pushl %eax
      pushl %edx
      pushl %edx  /* argument */
      call *GLOBL(ptr_gfx_directx_autolock)
      popl %edx
      popl %edx
      popl %eax

   Locked_win:
      popl %ecx

      /* get pointer to the video memory */
      movl BMP_LINE(%edx,%eax,4), %eax

      ret



/* gfx_directx_unwrite_bank_win:
 *  edx = bmp
 */
FUNC (gfx_directx_unwrite_bank_win)

      /* only unlock bitmaps that were autolocked */
      testl $BMP_ID_AUTOLOCK, BMP_ID(%edx)
      jz No_unlock_win

      pushl %ecx
      pushl %eax

      /* unlock surface */
      pushl %edx
      pushl %edx  /* argument */
      call *GLOBL(ptr_gfx_directx_unlock)
      popl %edx
      popl %edx

      /* clear the autolock flag */
      andl $~BMP_ID_AUTOLOCK, BMP_ID(%edx)

      /* update dirty lines: this is safe because autolocking
       * is guaranteed to be the only level of locking.
       */
      movl GLOBL(forefront_bitmap), %edx
      call update_dirty_lines

      popl %eax
      popl %ecx

   No_unlock_win:
      ret


/* gfx_directx_unlock_win:
 *  arg1 = bmp
 */
FUNC(gfx_directx_unlock_win)

      /* unlock surface */
      movl 4(%esp), %edx
      pushl %edx 
      pushl %edx  /* argument */
      call *GLOBL(ptr_gfx_directx_unlock)
      popl %edx
      popl %edx

      /* forefront_bitmap may still be locked in case of nested locking */
      movl GLOBL(forefront_bitmap), %edx
      testl $BMP_ID_LOCKED, BMP_ID(%edx)
      jnz No_update_win

      /* ok, we can safely update */
      call update_dirty_lines

   No_update_win:
      ret



/* update_dirty_lines
 *  edx = dd_frontbuffer
 *  clobbers: %eax, %ecx
 */

#define RECT_LEFT   (%esp)
#define RECT_TOP    4(%esp)
#define RECT_RIGHT  8(%esp)
#define RECT_BOTTOM 12(%esp)

update_dirty_lines:
      pushl %ebx
      pushl %esi
      pushl %edi
      subl $16, %esp  /* allocate a RECT structure */

      movl $0, RECT_LEFT
      movl BMP_W(%edx), %ecx           /* ecx = dd_frontbuffer->w */
      movl %ecx, RECT_RIGHT
      movl GLOBL(wd_dirty_lines), %ebx /* ebx = wd_dirty_lines   */
      movl BMP_H(%edx), %esi           /* esi = dd_frontbuffer->h */
      movl $0, %edi  

   _align_
   next_line:
      movb (%ebx,%edi), %al  /* al = wd_dirty_lines[edi] */
      testb %al, %al         /* is dirty? */
      jz test_end            /* no ! */

      movl %edi, RECT_TOP
   _align_
   loop_dirty_lines:
      movb $0, (%ebx,%edi)   /* wd_dirty_lines[edi] = 0  */
      incl %edi
      movb (%ebx,%edi), %al  /* al = wd_dirty_lines[edi] */
      testb %al, %al         /* is still dirty? */
      jnz loop_dirty_lines   /* yes ! */

      movl %edi, RECT_BOTTOM
      leal RECT_LEFT, %eax
      pushl %eax
      call *GLOBL(update_window) 
      popl %eax

   _align_
   test_end:   
      incl %edi
      cmpl %edi, %esi  /* last line? */
      jge next_line    /* no ! */

      addl $16, %esp
      popl %edi
      popl %esi
      popl %ebx
      ret



/* gfx_gdi_write_bank:
 *  edx = bitmap
 *  eax = line
 */
FUNC (gfx_gdi_write_bank)
      pushl %ecx

      /* clobber the line */
      movl GLOBL(gdi_dirty_lines), %ecx
      addl BMP_YOFFSET(%edx), %ecx
      movb $1, (%ecx,%eax)   /* gdi_dirty_lines[line] = 1; (line has changed) */

      /* check whether bitmap is already locked */
      testl $BMP_ID_LOCKED, BMP_ID(%edx)
      jnz Locked_gdi

      /* lock the surface */
      pushl %eax
      pushl %edx
      pushl %edx  /* argument */
      call *GLOBL(ptr_gfx_gdi_autolock) 
      popl %edx
      popl %edx
      popl %eax

   Locked_gdi:
      popl %ecx

      /* get pointer to the video memory */
      movl BMP_LINE(%edx,%eax,4), %eax

      ret



/* gfx_gdi_unwrite_bank:
 *  edx = bmp
 */
FUNC (gfx_gdi_unwrite_bank)

      /* only unlock bitmaps that were autolocked */
      testl $BMP_ID_AUTOLOCK, BMP_ID(%edx)
      jz No_unlock_gdi

      /* unlock surface */
      pushl %ecx
      pushl %eax
      pushl %edx
      pushl %edx  /* argument */
      call *GLOBL(ptr_gfx_gdi_unlock) 
      popl %edx
      popl %edx
      popl %eax
      popl %ecx

      /* clear the autolock flag */
      andl $~BMP_ID_AUTOLOCK, BMP_ID(%edx)

   No_unlock_gdi:
      ret