Rev 9917 | Rev 9926 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
9487 | rgimad | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
9925 | Doczom | 3 | ;; Copyright (C) KolibriOS team 2004-2023. All rights reserved. ;; |
9487 | rgimad | 4 | ;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa ;; |
5 | ;; Distributed under terms of the GNU General Public License ;; |
||
6 | ;; ;; |
||
7 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
8 | |||
9488 | rgimad | 9 | $Revision: 9925 $ |
9487 | rgimad | 10 | |
11 | ; Background graphics implementation |
||
12 | |||
13 | uglobal |
||
14 | ; bgrchanged dd 0x0 |
||
15 | align 4 |
||
16 | bgrlockpid dd 0 |
||
17 | bgrlock db 0 |
||
18 | endg |
||
19 | ;-------------------------------------- |
||
20 | align 4 |
||
21 | sys_background: |
||
22 | cmp ebx, 1 ; BACKGROUND SIZE |
||
9910 | Doczom | 23 | jnz .nosb1 |
9487 | rgimad | 24 | test ecx, ecx |
9910 | Doczom | 25 | jz .sbgrr |
9487 | rgimad | 26 | |
27 | test edx, edx |
||
9910 | Doczom | 28 | jz .sbgrr |
9487 | rgimad | 29 | ;-------------------------------------- |
30 | align 4 |
||
31 | @@: |
||
32 | ;;Maxis use atomic bts for mutexes 4.4.2009 |
||
33 | bts dword [bgrlock], 0 |
||
34 | jnc @f |
||
35 | call change_task |
||
36 | jmp @b |
||
37 | ;-------------------------------------- |
||
38 | align 4 |
||
39 | @@: |
||
40 | mov [BgrDataWidth], ecx |
||
41 | mov [BgrDataHeight], edx |
||
42 | ; mov [bgrchanged],1 |
||
43 | |||
44 | pushad |
||
45 | ; return memory for old background |
||
46 | mov eax, [img_background] |
||
47 | cmp eax, static_background_data |
||
48 | jz @f |
||
49 | stdcall kernel_free, eax |
||
50 | ;-------------------------------------- |
||
51 | align 4 |
||
52 | @@: |
||
53 | ; calculate RAW size |
||
54 | xor eax, eax |
||
55 | inc eax |
||
56 | cmp [BgrDataWidth], eax |
||
57 | jae @f |
||
58 | mov [BgrDataWidth], eax |
||
59 | ;-------------------------------------- |
||
60 | align 4 |
||
61 | @@: |
||
62 | cmp [BgrDataHeight], eax |
||
63 | jae @f |
||
64 | mov [BgrDataHeight], eax |
||
65 | ;-------------------------------------- |
||
66 | align 4 |
||
67 | @@: |
||
68 | mov eax, [BgrDataWidth] |
||
69 | imul eax, [BgrDataHeight] |
||
70 | lea eax, [eax*3] |
||
71 | ; it is reserved with aligned to the boundary of 4 KB pages, |
||
72 | ; otherwise there may be exceptions a page fault for vesa20_drawbackground_tiled |
||
73 | ; because the 32 bit read is used for high performance: "mov eax,[esi]" |
||
74 | shr eax, 12 |
||
75 | inc eax |
||
76 | shl eax, 12 |
||
77 | mov [mem_BACKGROUND], eax |
||
78 | ; get memory for new background |
||
79 | stdcall kernel_alloc, eax |
||
80 | test eax, eax |
||
81 | jz .memfailed |
||
82 | mov [img_background], eax |
||
83 | jmp .exit |
||
84 | ;-------------------------------------- |
||
85 | align 4 |
||
86 | .memfailed: |
||
87 | ; revert to static monotone data |
||
88 | mov [img_background], static_background_data |
||
89 | xor eax, eax |
||
90 | inc eax |
||
91 | mov [BgrDataWidth], eax |
||
92 | mov [BgrDataHeight], eax |
||
93 | mov [mem_BACKGROUND], 4 |
||
94 | ;-------------------------------------- |
||
95 | align 4 |
||
96 | .exit: |
||
97 | popad |
||
98 | mov [bgrlock], 0 |
||
99 | ;-------------------------------------- |
||
100 | align 4 |
||
9910 | Doczom | 101 | .sbgrr: |
9487 | rgimad | 102 | ret |
103 | ;-------------------------------------- |
||
104 | align 4 |
||
9910 | Doczom | 105 | .nosb1: |
9487 | rgimad | 106 | cmp ebx, 2 ; SET PIXEL |
9910 | Doczom | 107 | jnz .nosb2 |
9487 | rgimad | 108 | |
109 | mov eax, [img_background] |
||
110 | test ecx, ecx |
||
111 | jz @f |
||
112 | cmp eax, static_background_data |
||
113 | jz .ret |
||
114 | ;-------------------------------------- |
||
115 | align 4 |
||
116 | @@: |
||
117 | mov ebx, [mem_BACKGROUND] |
||
9910 | Doczom | 118 | add ebx, PAGE_SIZE-1 |
119 | and ebx, -PAGE_SIZE |
||
9487 | rgimad | 120 | sub ebx, 4 |
121 | cmp ecx, ebx |
||
122 | ja .ret |
||
123 | |||
124 | mov ebx, [eax+ecx] |
||
125 | and ebx, 0xFF000000;255*256*256*256 |
||
126 | and edx, 0x00FFFFFF;255*256*256+255*256+255 |
||
127 | add edx, ebx |
||
128 | mov [eax+ecx], edx |
||
129 | ;-------------------------------------- |
||
130 | align 4 |
||
131 | .ret: |
||
132 | ret |
||
133 | ;-------------------------------------- |
||
134 | align 4 |
||
9910 | Doczom | 135 | .nosb2: |
9487 | rgimad | 136 | cmp ebx, 3 ; DRAW BACKGROUND |
137 | jnz nosb3 |
||
138 | ;-------------------------------------- |
||
139 | align 4 |
||
140 | draw_background_temp: |
||
141 | mov [background_defined], 1 |
||
142 | call force_redraw_background |
||
143 | ;-------------------------------------- |
||
144 | align 4 |
||
145 | nosb31: |
||
146 | ret |
||
147 | ;-------------------------------------- |
||
148 | align 4 |
||
149 | nosb3: |
||
150 | cmp ebx, 4 ; TILED / STRETCHED |
||
151 | jnz nosb4 |
||
152 | cmp ecx, [BgrDrawMode] |
||
153 | je nosb41 |
||
154 | mov [BgrDrawMode], ecx |
||
155 | ;-------------------------------------- |
||
156 | align 4 |
||
157 | nosb41: |
||
158 | ret |
||
159 | ;-------------------------------------- |
||
160 | align 4 |
||
161 | nosb4: |
||
162 | cmp ebx, 5 ; BLOCK MOVE TO BGR |
||
163 | jnz nosb5 |
||
164 | |||
165 | ; add check pointer |
||
166 | stdcall is_region_userspace, ecx, esi |
||
167 | jnz .fin |
||
168 | |||
169 | cmp [img_background], static_background_data |
||
170 | jnz @f |
||
171 | test edx, edx |
||
172 | jnz .fin |
||
173 | cmp esi, 4 |
||
174 | ja .fin |
||
175 | ;-------------------------------------- |
||
176 | align 4 |
||
177 | @@: |
||
178 | ; bughere |
||
179 | mov eax, ecx |
||
180 | mov ebx, edx |
||
181 | add ebx, [img_background];IMG_BACKGROUND |
||
182 | mov ecx, esi |
||
183 | call memmove |
||
184 | ;-------------------------------------- |
||
185 | align 4 |
||
186 | .fin: |
||
187 | ret |
||
188 | ;--------------------------------------- |
||
189 | align 4 |
||
190 | nosb5: |
||
191 | cmp ebx, 6 |
||
192 | jnz nosb6 |
||
193 | ;-------------------------------------- |
||
194 | align 4 |
||
195 | ;;Maxis use atomic bts for mutex 4.4.2009 |
||
196 | @@: |
||
197 | bts dword [bgrlock], 0 |
||
198 | jnc @f |
||
199 | call change_task |
||
200 | jmp @b |
||
201 | ;-------------------------------------- |
||
202 | align 4 |
||
203 | @@: |
||
204 | mov eax, [current_slot_idx] |
||
205 | mov [bgrlockpid], eax |
||
206 | cmp [img_background], static_background_data |
||
207 | jz .nomem |
||
208 | stdcall user_alloc, [mem_BACKGROUND] |
||
9910 | Doczom | 209 | mov [esp + SYSCALL_STACK.eax], eax |
9487 | rgimad | 210 | test eax, eax |
211 | jz .nomem |
||
212 | mov ebx, eax |
||
213 | shr ebx, 12 |
||
214 | or dword [page_tabs+(ebx-1)*4], MEM_BLOCK_DONT_FREE |
||
215 | mov esi, [img_background] |
||
216 | shr esi, 12 |
||
217 | mov ecx, [mem_BACKGROUND] |
||
218 | add ecx, 0xFFF |
||
219 | shr ecx, 12 |
||
220 | ;-------------------------------------- |
||
221 | align 4 |
||
222 | .z: |
||
223 | mov eax, [page_tabs+ebx*4] |
||
224 | test al, 1 |
||
225 | jz @f |
||
226 | call free_page |
||
227 | ;-------------------------------------- |
||
228 | align 4 |
||
229 | @@: |
||
230 | mov eax, [page_tabs+esi*4] |
||
231 | or al, PG_UWR |
||
232 | mov [page_tabs+ebx*4], eax |
||
233 | mov eax, ebx |
||
234 | shl eax, 12 |
||
235 | invlpg [eax] |
||
236 | inc ebx |
||
237 | inc esi |
||
238 | loop .z |
||
239 | ret |
||
240 | ;-------------------------------------- |
||
241 | align 4 |
||
242 | .nomem: |
||
243 | and [bgrlockpid], 0 |
||
244 | mov [bgrlock], 0 |
||
245 | ;-------------------------------------- |
||
246 | align 4 |
||
247 | nosb6: |
||
248 | cmp ebx, 7 |
||
249 | jnz nosb7 |
||
250 | cmp [bgrlock], 0 |
||
251 | jz .err |
||
252 | mov eax, [current_slot_idx] |
||
253 | cmp [bgrlockpid], eax |
||
254 | jnz .err |
||
255 | mov eax, ecx |
||
256 | mov ebx, ecx |
||
257 | shr eax, 12 |
||
258 | mov ecx, [page_tabs+(eax-1)*4] |
||
259 | test cl, MEM_BLOCK_USED or MEM_BLOCK_DONT_FREE |
||
260 | jz .err |
||
261 | jnp .err |
||
262 | push eax |
||
263 | shr ecx, 12 |
||
264 | dec ecx |
||
265 | ;-------------------------------------- |
||
266 | align 4 |
||
267 | @@: |
||
268 | and dword [page_tabs+eax*4], 0 |
||
269 | mov edx, eax |
||
270 | shl edx, 12 |
||
271 | push eax |
||
272 | invlpg [edx] |
||
273 | pop eax |
||
274 | inc eax |
||
275 | loop @b |
||
276 | pop eax |
||
277 | and dword [page_tabs+(eax-1)*4], not MEM_BLOCK_DONT_FREE |
||
278 | stdcall user_free, ebx |
||
9910 | Doczom | 279 | mov [esp + SYSCALL_STACK.eax], eax |
9487 | rgimad | 280 | and [bgrlockpid], 0 |
281 | mov [bgrlock], 0 |
||
282 | ret |
||
283 | ;-------------------------------------- |
||
284 | align 4 |
||
285 | .err: |
||
9910 | Doczom | 286 | and dword [esp + SYSCALL_STACK.eax], 0 |
9487 | rgimad | 287 | ret |
288 | ;------------------------------------- |
||
289 | align 4 |
||
290 | nosb7: |
||
291 | cmp ebx, 8 |
||
292 | jnz nosb8 |
||
293 | |||
294 | mov ecx, [current_slot] |
||
295 | xor eax, eax |
||
9910 | Doczom | 296 | xchg eax, [ecx + APPDATA.draw_bgr_x] |
297 | mov [esp + SYSCALL_STACK.eax], eax ; eax = [left]*65536 + [right] |
||
9487 | rgimad | 298 | xor eax, eax |
9910 | Doczom | 299 | xchg eax, [ecx + APPDATA.draw_bgr_y] |
300 | mov [esp + SYSCALL_STACK.ebx], eax ; ebx = [top]*65536 + [bottom] |
||
9487 | rgimad | 301 | ret |
302 | ;--------------------------------------- |
||
303 | align 4 |
||
304 | nosb8: |
||
305 | cmp ebx, 9 |
||
9910 | Doczom | 306 | jnz .exit |
9487 | rgimad | 307 | ; ecx = [left]*65536 + [right] |
308 | ; edx = [top]*65536 + [bottom] |
||
309 | mov eax, [_display.width] |
||
310 | mov ebx, [_display.height] |
||
311 | ; check [right] |
||
312 | cmp cx, ax |
||
313 | jae .exit |
||
314 | ; check [left] |
||
315 | ror ecx, 16 |
||
316 | cmp cx, ax |
||
317 | jae .exit |
||
318 | ; check [bottom] |
||
319 | cmp dx, bx |
||
320 | jae .exit |
||
321 | ; check [top] |
||
322 | ror edx, 16 |
||
323 | cmp dx, bx |
||
324 | jae .exit |
||
325 | |||
326 | movzx eax, cx ; [left] |
||
327 | movzx ebx, dx ; [top] |
||
328 | |||
329 | shr ecx, 16 ; [right] |
||
330 | shr edx, 16 ; [bottom] |
||
331 | |||
332 | mov [background_defined], 1 |
||
333 | |||
9925 | Doczom | 334 | mov [draw_data + sizeof.WDATA + RECT.left], eax |
335 | mov [draw_data + sizeof.WDATA + RECT.top], ebx |
||
9487 | rgimad | 336 | |
9925 | Doczom | 337 | mov [draw_data + sizeof.WDATA + RECT.right], ecx |
338 | mov [draw_data + sizeof.WDATA + RECT.bottom], edx |
||
9487 | rgimad | 339 | |
340 | inc [REDRAW_BACKGROUND] |
||
341 | call wakeup_osloop |
||
342 | ;-------------------------------------- |
||
343 | align 4 |
||
344 | .exit: |
||
345 | ret |
||
346 | ;------------------------------------------------------------------------------ |
||
347 | |||
348 | |||
349 | align 4 |
||
350 | uglobal |
||
351 | BG_Rect_X_left_right dd 0x0 |
||
352 | BG_Rect_Y_top_bottom dd 0x0 |
||
353 | endg |
||
354 | ;------------------------------------------------------------------------------ |
||
355 | |||
356 | |||
357 | align 4 |
||
358 | force_redraw_background: |
||
9925 | Doczom | 359 | and [draw_data + sizeof.WDATA + RECT.left], 0 |
360 | and [draw_data + sizeof.WDATA + RECT.top], 0 |
||
9487 | rgimad | 361 | push eax ebx |
362 | mov eax, [_display.width] |
||
363 | mov ebx, [_display.height] |
||
364 | dec eax |
||
365 | dec ebx |
||
9925 | Doczom | 366 | mov [draw_data + sizeof.WDATA + RECT.right], eax |
367 | mov [draw_data + sizeof.WDATA + RECT.bottom], ebx |
||
9487 | rgimad | 368 | pop ebx eax |
369 | inc [REDRAW_BACKGROUND] |
||
370 | call wakeup_osloop |
||
371 | ret |
||
372 | ;------------------------------------------------------------------------------ |
||
373 | |||
374 | |||
375 | align 4 |
||
376 | sys_getbackground: ; sysfn 39 |
||
377 | dec ebx |
||
378 | jnz .nogb1 |
||
379 | ; sysfn 39.1: |
||
380 | mov eax, [BgrDataWidth] |
||
381 | shl eax, 16 |
||
382 | mov ax, word [BgrDataHeight] |
||
9910 | Doczom | 383 | mov [esp + SYSCALL_STACK.eax], eax |
9487 | rgimad | 384 | ret |
385 | ;--------------------------------------- |
||
386 | align 4 |
||
387 | .nogb1: |
||
388 | dec ebx |
||
389 | jnz .nogb2 |
||
390 | ; sysfn 39.2: |
||
391 | mov eax, [img_background] |
||
392 | test ecx, ecx |
||
393 | jz @f |
||
394 | cmp eax, static_background_data |
||
395 | jz .ret |
||
396 | align 4 |
||
397 | @@: |
||
398 | mov ebx, [mem_BACKGROUND] |
||
9910 | Doczom | 399 | add ebx, PAGE_SIZE-1 |
400 | and ebx, -PAGE_SIZE |
||
9487 | rgimad | 401 | sub ebx, 4 |
402 | cmp ecx, ebx |
||
403 | ja .ret |
||
404 | |||
405 | mov eax, [ecx+eax] |
||
406 | |||
407 | and eax, 0xFFFFFF |
||
9910 | Doczom | 408 | mov [esp + SYSCALL_STACK.eax], eax |
9487 | rgimad | 409 | align 4 |
410 | .ret: |
||
411 | ret |
||
412 | ;------------------------------------------------------------------------------ |
||
413 | align 4 |
||
414 | .x dd ? |
||
415 | .y dd ? |
||
416 | .w dd ? |
||
417 | .h dd ? |
||
418 | .subrect_startptr dd ? |
||
419 | .subrect_bytes dd ? |
||
420 | align 4 |
||
421 | .nogb2: |
||
422 | dec ebx |
||
423 | jnz .nogb3 |
||
424 | ; sysfn 39.3 read background subrect to buffer |
||
425 | ; ecx - |
||
426 | ; edx - |
||
427 | ; esi - buffer of 0x00RRGGBB |
||
428 | mov eax, [img_background] |
||
429 | cmp eax, static_background_data |
||
430 | jz .ret_39_3 |
||
431 | align 4 |
||
432 | @@: |
||
433 | movzx eax, cx ; store y in eax |
||
434 | mov [.y], eax |
||
435 | |||
436 | shr ecx, 16 ; ecx = x |
||
437 | mov [.x], ecx |
||
438 | |||
439 | imul eax, [BgrDataWidth] |
||
440 | add eax, ecx |
||
441 | imul eax, 3 |
||
442 | mov [.subrect_startptr], eax |
||
443 | |||
444 | movzx eax, dx ; store h in eax |
||
445 | mov [.h], eax |
||
446 | |||
447 | shr edx, 16 ; edx = w |
||
448 | mov [.w], edx |
||
449 | |||
450 | imul eax, edx |
||
451 | mov [.subrect_bytes], eax |
||
452 | |||
453 | ; check bounds |
||
454 | mov ebx, [mem_BACKGROUND] |
||
9910 | Doczom | 455 | add ebx, PAGE_SIZE-1 |
456 | and ebx, -PAGE_SIZE |
||
9487 | rgimad | 457 | sub ebx, 4 |
458 | add eax, [.subrect_startptr] |
||
459 | cmp eax, ebx |
||
460 | ja .fail_39_3 |
||
461 | |||
462 | ; copy contents |
||
463 | mov edi, [img_background] |
||
464 | xor ecx, ecx ; ecx - row index |
||
465 | .copy_rect: |
||
466 | cmp ecx, [.h] |
||
467 | jae .end_copy_rect |
||
468 | |||
469 | xor edx, edx ; edx - column index |
||
470 | .copy_row: |
||
471 | cmp edx, [.w] |
||
472 | jae .end_copy_row |
||
473 | |||
474 | mov ebx, ecx |
||
475 | imul ebx, [BgrDataWidth] |
||
476 | add ebx, edx |
||
477 | imul ebx, 3 |
||
478 | add ebx, [.subrect_startptr] |
||
479 | mov eax, [edi + ebx] |
||
480 | mov ebx, ecx |
||
481 | imul ebx, [.w] |
||
482 | add ebx, edx |
||
483 | and eax, 0xFFFFFF |
||
484 | mov [esi + ebx*4], eax |
||
485 | |||
486 | inc edx |
||
487 | jmp .copy_row |
||
488 | .end_copy_row: |
||
489 | |||
490 | inc ecx |
||
491 | jmp .copy_rect |
||
492 | .end_copy_rect: |
||
493 | xor eax, eax |
||
9910 | Doczom | 494 | mov [esp + SYSCALL_STACK.eax], eax |
9487 | rgimad | 495 | ;-------------------------------------- |
496 | align 4 |
||
497 | .fail_39_3: |
||
498 | mov eax, -1 |
||
499 | align 4 |
||
500 | .ret_39_3: |
||
501 | ret |
||
502 | ;-------------------------------------- |
||
503 | align 4 |
||
504 | .nogb3: |
||
505 | dec ebx |
||
506 | jnz .nogb4 |
||
507 | ; sysfn 39.4: |
||
508 | mov eax, [BgrDrawMode] |
||
509 | ;-------------------------------------- |
||
510 | align 4 |
||
511 | .nogb4: |
||
9910 | Doczom | 512 | mov [esp + SYSCALL_STACK.eax], eax |
9487 | rgimad | 513 | ret |
514 | ;----------------------------------------------------------------------------- |
||
515 | |||
516 | |||
517 | align 4 |
||
518 | syscall_putarea_backgr: ; sysfn 25 |
||
519 | ;eax = 25 |
||
520 | ;ebx = pointer to bufer for img BBGGRRBBGGRR... |
||
521 | ;ecx = [size x]*65536 + [size y] |
||
522 | ;edx = [start x]*65536 + [start y] |
||
523 | pushad |
||
524 | mov edi, ebx |
||
525 | mov eax, edx |
||
526 | shr eax, 16 |
||
527 | mov ebx, edx |
||
528 | and ebx, 0xffff |
||
529 | dec eax |
||
530 | dec ebx |
||
531 | ; eax - x, ebx - y |
||
532 | mov edx, ecx |
||
533 | shr ecx, 16 |
||
534 | and edx, 0xffff |
||
535 | mov esi, ecx |
||
536 | ; ecx - size x, edx - size y |
||
537 | mov ebp, edx |
||
538 | |||
539 | lea ebp, [ebp*4] |
||
540 | imul ebp, esi |
||
541 | stdcall is_region_userspace, edi, ebp |
||
542 | jnz .exit |
||
543 | |||
544 | mov ebp, edx |
||
545 | |||
546 | dec ebp |
||
547 | shl ebp, 2 |
||
548 | |||
549 | imul ebp, esi |
||
550 | |||
551 | mov esi, ecx |
||
552 | dec esi |
||
553 | shl esi, 2 |
||
554 | |||
555 | add ebp, esi |
||
556 | add ebp, edi |
||
557 | |||
558 | add ebx, edx |
||
559 | ;-------------------------------------- |
||
560 | align 4 |
||
561 | .start_y: |
||
562 | push ecx edx |
||
563 | ;-------------------------------------- |
||
564 | align 4 |
||
565 | .start_x: |
||
566 | push eax ecx |
||
567 | add eax, ecx |
||
568 | |||
569 | mov ecx, [ebp] |
||
570 | rol ecx, 8 |
||
571 | test cl, cl ; transparensy = 0 |
||
572 | jz .no_put |
||
573 | |||
574 | xor cl, cl |
||
575 | ror ecx, 8 |
||
576 | |||
577 | pushad |
||
578 | mov edx, [d_width_calc_area + ebx*4] |
||
579 | add edx, [_display.win_map] |
||
580 | movzx edx, byte [eax+edx] |
||
581 | cmp dl, byte 1 |
||
582 | jne @f |
||
583 | |||
584 | call dword [PUTPIXEL]; eax - x, ebx - y |
||
585 | ;-------------------------------------- |
||
586 | align 4 |
||
587 | @@: |
||
588 | popad |
||
589 | ;-------------------------------------- |
||
590 | align 4 |
||
591 | .no_put: |
||
592 | pop ecx eax |
||
593 | |||
594 | sub ebp, 4 |
||
595 | dec ecx |
||
596 | jnz .start_x |
||
597 | |||
598 | pop edx ecx |
||
599 | dec ebx |
||
600 | dec edx |
||
601 | jnz .start_y |
||
602 | |||
603 | .exit: |
||
604 | popad |
||
9925 | Doczom | 605 | ret |