Subversion Repositories Kolibri OS

Rev

Rev 9488 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2021. All rights reserved. ;;
  4. ;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa      ;;
  5. ;; Distributed under terms of the GNU General Public License    ;;
  6. ;;                                                              ;;
  7. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8.  
  9. $Revision: 0 $
  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
  23.         jnz     nosb1
  24.         test    ecx, ecx
  25.         jz      sbgrr
  26.  
  27.         test    edx, edx
  28.         jz      sbgrr
  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
  101. sbgrr:
  102.         ret
  103. ;--------------------------------------
  104. align 4
  105. nosb1:
  106.         cmp     ebx, 2                     ; SET PIXEL
  107.         jnz     nosb2
  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]
  118.         add     ebx, 4095
  119.         and     ebx, -4096
  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
  135. nosb2:
  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]
  209.         mov     [esp+32], eax
  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
  279.         mov     [esp+32], eax
  280.         and     [bgrlockpid], 0
  281.         mov     [bgrlock], 0
  282.         ret
  283. ;--------------------------------------
  284. align 4
  285. .err:
  286.         and     dword [esp+32], 0
  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
  296.         xchg    eax, [ecx+APPDATA.draw_bgr_x]
  297.         mov     [esp + 32], eax ; eax = [left]*65536 + [right]
  298.         xor     eax, eax
  299.         xchg    eax, [ecx+APPDATA.draw_bgr_y]
  300.         mov     [esp + 20], eax ; ebx = [top]*65536 + [bottom]
  301.         ret
  302. ;---------------------------------------
  303. align 4
  304. nosb8:
  305.         cmp     ebx, 9
  306.         jnz     nosb9
  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.  
  334.         mov     [draw_data+32 + RECT.left], eax
  335.         mov     [draw_data+32 + RECT.top], ebx
  336.  
  337.         mov     [draw_data+32 + RECT.right], ecx
  338.         mov     [draw_data+32 + RECT.bottom], edx
  339.  
  340.         inc     [REDRAW_BACKGROUND]
  341.         call    wakeup_osloop
  342. ;--------------------------------------
  343. align 4
  344. .exit:
  345.         ret
  346. ;--------------------------------------
  347. align 4
  348. nosb9:
  349.         ret
  350. ;------------------------------------------------------------------------------
  351.  
  352.  
  353. align 4
  354. uglobal
  355.   BG_Rect_X_left_right  dd   0x0
  356.   BG_Rect_Y_top_bottom  dd   0x0
  357. endg
  358. ;------------------------------------------------------------------------------
  359.  
  360.  
  361. align 4
  362. force_redraw_background:
  363.         and     [draw_data+32 + RECT.left], 0
  364.         and     [draw_data+32 + RECT.top], 0
  365.         push    eax ebx
  366.         mov     eax, [_display.width]
  367.         mov     ebx, [_display.height]
  368.         dec     eax
  369.         dec     ebx
  370.         mov     [draw_data+32 + RECT.right], eax
  371.         mov     [draw_data+32 + RECT.bottom], ebx
  372.         pop     ebx eax
  373.         inc     [REDRAW_BACKGROUND]
  374.         call    wakeup_osloop
  375.         ret
  376. ;------------------------------------------------------------------------------
  377.  
  378.  
  379. align 4
  380. sys_getbackground: ; sysfn 39
  381.         dec     ebx
  382.         jnz     .nogb1
  383.         ; sysfn 39.1:
  384.         mov     eax, [BgrDataWidth]
  385.         shl     eax, 16
  386.         mov     ax, word [BgrDataHeight]
  387.         mov     [esp+32], eax
  388.         ret
  389. ;---------------------------------------
  390. align 4
  391. .nogb1:
  392.         dec     ebx
  393.         jnz     .nogb2
  394.         ; sysfn 39.2:
  395.         mov     eax, [img_background]
  396.         test    ecx, ecx
  397.         jz      @f
  398.         cmp     eax, static_background_data
  399.         jz      .ret
  400. align 4
  401. @@:
  402.         mov     ebx, [mem_BACKGROUND]
  403.         add     ebx, 4095
  404.         and     ebx, -4096
  405.         sub     ebx, 4
  406.         cmp     ecx, ebx
  407.         ja      .ret
  408.  
  409.         mov     eax, [ecx+eax]
  410.  
  411.         and     eax, 0xFFFFFF
  412.         mov     [esp+32], eax
  413. align 4
  414. .ret:
  415.         ret
  416. ;------------------------------------------------------------------------------
  417. align 4
  418.         .x      dd ?
  419.         .y      dd ?
  420.         .w      dd ?
  421.         .h      dd ?
  422.         .subrect_startptr dd ?
  423.         .subrect_bytes dd ?
  424. align 4
  425. .nogb2:
  426.         dec     ebx
  427.         jnz     .nogb3
  428.         ; sysfn 39.3 read background subrect to buffer
  429.         ; ecx - <x, y>
  430.         ; edx - <w, h>
  431.         ; esi - buffer of 0x00RRGGBB
  432.         mov     eax, [img_background]
  433.         cmp     eax, static_background_data
  434.         jz      .ret_39_3
  435. align 4
  436. @@:
  437.         movzx   eax, cx ; store y in eax
  438.         mov     [.y], eax
  439.  
  440.         shr     ecx, 16 ; ecx = x
  441.         mov     [.x], ecx
  442.  
  443.         imul    eax, [BgrDataWidth]
  444.         add     eax, ecx
  445.         imul    eax, 3
  446.         mov     [.subrect_startptr], eax
  447.  
  448.         movzx   eax, dx ; store h in eax
  449.         mov     [.h], eax
  450.  
  451.         shr     edx, 16 ; edx = w
  452.         mov     [.w], edx
  453.  
  454.         imul    eax, edx
  455.         mov     [.subrect_bytes], eax
  456.  
  457.         ; check bounds
  458.         mov     ebx, [mem_BACKGROUND]
  459.         add     ebx, 4095
  460.         and     ebx, -4096
  461.         sub     ebx, 4
  462.         add     eax, [.subrect_startptr]
  463.         cmp     eax, ebx
  464.         ja      .fail_39_3
  465.  
  466.         ; copy contents
  467.         mov     edi, [img_background]
  468.         xor     ecx, ecx ; ecx - row index
  469. .copy_rect:
  470.         cmp     ecx, [.h]
  471.         jae     .end_copy_rect
  472.        
  473.         xor     edx, edx ; edx - column index
  474. .copy_row:
  475.         cmp     edx, [.w]
  476.         jae     .end_copy_row
  477.  
  478.         mov     ebx, ecx
  479.         imul    ebx, [BgrDataWidth]
  480.         add     ebx, edx
  481.         imul    ebx, 3
  482.         add     ebx, [.subrect_startptr]
  483.         mov     eax, [edi + ebx]
  484.         mov     ebx, ecx
  485.         imul    ebx, [.w]
  486.         add     ebx, edx
  487.         and     eax, 0xFFFFFF
  488.         mov     [esi + ebx*4], eax      
  489.  
  490.         inc     edx
  491.         jmp     .copy_row
  492. .end_copy_row:        
  493.  
  494.         inc     ecx
  495.         jmp     .copy_rect
  496. .end_copy_rect:
  497.         xor     eax, eax
  498.         mov     [esp+32], eax
  499. ;--------------------------------------
  500. align 4
  501. .fail_39_3:
  502.         mov     eax, -1
  503. align 4
  504. .ret_39_3:
  505.         ret
  506. ;--------------------------------------
  507. align 4
  508. .nogb3:
  509.         dec     ebx
  510.         jnz     .nogb4
  511.         ; sysfn 39.4:
  512.         mov     eax, [BgrDrawMode]
  513. ;--------------------------------------
  514. align 4
  515. .nogb4:
  516.         mov     [esp+32], eax
  517.         ret
  518. ;-----------------------------------------------------------------------------
  519.  
  520.  
  521. align 4
  522. syscall_putarea_backgr: ; sysfn 25
  523. ;eax = 25
  524. ;ebx = pointer to bufer for img BBGGRRBBGGRR...
  525. ;ecx = [size x]*65536 + [size y]
  526. ;edx = [start x]*65536 + [start y]
  527.         pushad
  528.         mov     edi, ebx
  529.         mov     eax, edx
  530.         shr     eax, 16
  531.         mov     ebx, edx
  532.         and     ebx, 0xffff
  533.         dec     eax
  534.         dec     ebx
  535. ; eax - x, ebx - y
  536.         mov     edx, ecx
  537.         shr     ecx, 16
  538.         and     edx, 0xffff
  539.         mov     esi, ecx
  540. ; ecx - size x, edx - size y
  541.         mov     ebp, edx
  542.        
  543.         lea     ebp, [ebp*4]
  544.         imul    ebp, esi
  545.         stdcall is_region_userspace, edi, ebp
  546.         jnz     .exit
  547.  
  548.         mov     ebp, edx
  549.  
  550.         dec     ebp
  551.         shl     ebp, 2
  552.  
  553.         imul    ebp, esi
  554.  
  555.         mov     esi, ecx
  556.         dec     esi
  557.         shl     esi, 2
  558.  
  559.         add     ebp, esi
  560.         add     ebp, edi
  561.  
  562.         add     ebx, edx
  563. ;--------------------------------------
  564. align 4
  565. .start_y:
  566.         push    ecx edx
  567. ;--------------------------------------
  568. align 4
  569. .start_x:
  570.         push    eax ecx
  571.         add     eax, ecx
  572.  
  573.         mov     ecx, [ebp]
  574.         rol     ecx, 8
  575.         test    cl, cl        ; transparensy = 0
  576.         jz      .no_put
  577.  
  578.         xor     cl, cl
  579.         ror     ecx, 8
  580.  
  581.         pushad
  582.         mov     edx, [d_width_calc_area + ebx*4]
  583.         add     edx, [_display.win_map]
  584.         movzx   edx, byte [eax+edx]
  585.         cmp     dl, byte 1
  586.         jne     @f
  587.  
  588.         call    dword [PUTPIXEL]; eax - x, ebx - y
  589. ;--------------------------------------
  590. align 4
  591. @@:
  592.         popad
  593. ;--------------------------------------
  594. align 4
  595. .no_put:
  596.         pop     ecx eax
  597.  
  598.         sub     ebp, 4
  599.         dec     ecx
  600.         jnz     .start_x
  601.  
  602.         pop     edx ecx
  603.         dec     ebx
  604.         dec     edx
  605.         jnz     .start_y
  606.  
  607. .exit:
  608.         popad
  609.         ret
  610.  
  611.  
  612.  
  613.