Subversion Repositories Kolibri OS

Rev

Rev 1001 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;================================================================================================;;
  2. ;;//// libgfx.asm //// (c) mike.dld, 2006-2008 ///////////////////////////////////////////////////;;
  3. ;;================================================================================================;;
  4. ;;                                                                                                ;;
  5. ;; This file is part of Common development libraries (Libs-Dev).                                  ;;
  6. ;;                                                                                                ;;
  7. ;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;;
  8. ;; Lesser General Public License as published by the Free Software Foundation, either version 2.1 ;;
  9. ;; of the License, or (at your option) any later version.                                         ;;
  10. ;;                                                                                                ;;
  11. ;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without  ;;
  12. ;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  ;;
  13. ;; Lesser General Public License for more details.                                                ;;
  14. ;;                                                                                                ;;
  15. ;; You should have received a copy of the GNU Lesser General Public License along with Libs-Dev.  ;;
  16. ;; If not, see <http://www.gnu.org/licenses/>.                                                    ;;
  17. ;;                                                                                                ;;
  18. ;;================================================================================================;;
  19.  
  20.  
  21. format MS COFF
  22.  
  23. public @EXPORT as 'EXPORTS'
  24.  
  25. include '../../../../proc32.inc'
  26. include '../../../../macros.inc'
  27. purge section;mov,add,sub
  28.  
  29. include 'libgfx_p.inc'
  30.  
  31. section '.flat' code readable align 16
  32.  
  33. mem.alloc   dd ?
  34. mem.free    dd ?
  35. mem.realloc dd ?
  36. dll.load    dd ?
  37.  
  38. ;;================================================================================================;;
  39. proc lib_init ;///////////////////////////////////////////////////////////////////////////////////;;
  40. ;;------------------------------------------------------------------------------------------------;;
  41. ;? Library entry point (called after library load)                                                ;;
  42. ;;------------------------------------------------------------------------------------------------;;
  43. ;> eax = pointer to memory allocation routine                                                     ;;
  44. ;> ebx = pointer to memory freeing routine                                                        ;;
  45. ;> ecx = pointer to memory reallocation routine                                                   ;;
  46. ;> edx = pointer to library loading routine                                                       ;;
  47. ;;------------------------------------------------------------------------------------------------;;
  48. ;< eax = 1 (fail) / 0 (ok) (library initialization result)                                        ;;
  49. ;;================================================================================================;;
  50.         mov     [mem.alloc], eax
  51.         mov     [mem.free], ebx
  52.         mov     [mem.realloc], ecx
  53.         mov     [dll.load], edx
  54.         xor     eax,eax
  55.         ret
  56. endp
  57.  
  58. ;;================================================================================================;;
  59. proc gfx.open _open? ;////////////////////////////////////////////////////////////////////////////;;
  60. ;;------------------------------------------------------------------------------------------------;;
  61. ;? --- TBD ---                                                                                    ;;
  62. ;;------------------------------------------------------------------------------------------------;;
  63. ;> --- TBD ---                                                                                    ;;
  64. ;;------------------------------------------------------------------------------------------------;;
  65. ;< --- TBD ---                                                                                    ;;
  66. ;;================================================================================================;;
  67.         push    ebx ecx
  68.         xor     ecx, ecx
  69.         cmp     byte[_open?], 0
  70.         je      .lp1
  71.         mov     eax, 12
  72.         mov     ebx, 1
  73.         int     0x40
  74.         jmp     @f
  75.   .lp1: or      ecx, GFX_FLAG_DONT_CLOSE
  76.     @@: invoke  mem.alloc, sizeof.AGfxContext
  77.         xor     ebx,ebx
  78.         mov     [eax + AGfxContext.Flags], ecx
  79.         mov     [eax + AGfxContext.NullPoint.X], ebx
  80.         mov     [eax + AGfxContext.NullPoint.Y], ebx
  81.         mov     [eax + AGfxContext.Caret.X], ebx
  82.         mov     [eax + AGfxContext.Caret.Y], ebx
  83.         mov     [eax + AGfxContext.Pen.Color], ebx
  84.         mov     [eax + AGfxContext.Brush.Color], 0x00FFFFFF
  85.         pop     ecx ebx
  86.         ret
  87. endp
  88.  
  89. ;;================================================================================================;;
  90. proc gfx.close _ctx ;/////////////////////////////////////////////////////////////////////////////;;
  91. ;;------------------------------------------------------------------------------------------------;;
  92. ;? --- TBD ---                                                                                    ;;
  93. ;;------------------------------------------------------------------------------------------------;;
  94. ;> --- TBD ---                                                                                    ;;
  95. ;;------------------------------------------------------------------------------------------------;;
  96. ;< --- TBD ---                                                                                    ;;
  97. ;;================================================================================================;;
  98.         push    eax ebx
  99.         mov     ebx, [_ctx]
  100.         mov     ebx, [ebx + AGfxContext.Flags]
  101.         invoke  mem.free, [_ctx]
  102.         test    ebx, GFX_FLAG_DONT_CLOSE
  103.         jnz     @f
  104.         mov     eax, 12
  105.         mov     ebx, 2
  106.         int     0x40
  107.     @@: pop     ebx eax
  108.         ret
  109. endp
  110.  
  111. ;;================================================================================================;;
  112. proc gfx.pen.color _ctx, _color ;/////////////////////////////////////////////////////////////////;;
  113. ;;------------------------------------------------------------------------------------------------;;
  114. ;? --- TBD ---                                                                                    ;;
  115. ;;------------------------------------------------------------------------------------------------;;
  116. ;> --- TBD ---                                                                                    ;;
  117. ;;------------------------------------------------------------------------------------------------;;
  118. ;< --- TBD ---                                                                                    ;;
  119. ;;================================================================================================;;
  120.         push    eax
  121.         mov     eax, [_ctx]
  122.         push    [_color]
  123.         pop     [eax + AGfxContext.Pen.Color]
  124.         pop     eax
  125.         ret
  126. endp
  127.  
  128. ;;================================================================================================;;
  129. proc gfx.brush.color _ctx, _color ;///////////////////////////////////////////////////////////////;;
  130. ;;------------------------------------------------------------------------------------------------;;
  131. ;? --- TBD ---                                                                                    ;;
  132. ;;------------------------------------------------------------------------------------------------;;
  133. ;> --- TBD ---                                                                                    ;;
  134. ;;------------------------------------------------------------------------------------------------;;
  135. ;< --- TBD ---                                                                                    ;;
  136. ;;================================================================================================;;
  137.         push    eax
  138.         mov     eax, [_ctx]
  139.         push    [_color]
  140.         pop     [eax + AGfxContext.Brush.Color]
  141.         pop     eax
  142.         ret
  143. endp
  144.  
  145. ;;================================================================================================;;
  146. proc gfx.pixel _ctx, _x, _y ;/////////////////////////////////////////////////////////////////////;;
  147. ;;------------------------------------------------------------------------------------------------;;
  148. ;? --- TBD ---                                                                                    ;;
  149. ;;------------------------------------------------------------------------------------------------;;
  150. ;> --- TBD ---                                                                                    ;;
  151. ;;------------------------------------------------------------------------------------------------;;
  152. ;< --- TBD ---                                                                                    ;;
  153. ;;================================================================================================;;
  154.         push    eax ebx ecx edx
  155.         mov     eax, 1
  156.         mov     ebx, [_x]
  157.         mov     ecx, [_y]
  158.         mov     edx, [_ctx]
  159.         mov     edx, [edx + AGfxContext.Pen.Color]
  160.         int     0x40
  161.         pop     edx ecx ebx eax
  162.         ret
  163. endp
  164.  
  165. ;;================================================================================================;;
  166. proc gfx.move.to _ctx, _x, _y ;///////////////////////////////////////////////////////////////////;;
  167. ;;------------------------------------------------------------------------------------------------;;
  168. ;? --- TBD ---                                                                                    ;;
  169. ;;------------------------------------------------------------------------------------------------;;
  170. ;> --- TBD ---                                                                                    ;;
  171. ;;------------------------------------------------------------------------------------------------;;
  172. ;< --- TBD ---                                                                                    ;;
  173. ;;================================================================================================;;
  174.         push    eax
  175.         mov     eax, [_ctx]
  176.         push    [_x] [_y]
  177.         pop     [eax + AGfxContext.Caret.Y] [eax+AGfxContext.Caret.X]
  178.         pop     eax
  179.         ret
  180. endp
  181.  
  182. ;;================================================================================================;;
  183. proc gfx.line.to _ctx, _x, _y ;///////////////////////////////////////////////////////////////////;;
  184. ;;------------------------------------------------------------------------------------------------;;
  185. ;? --- TBD ---                                                                                    ;;
  186. ;;------------------------------------------------------------------------------------------------;;
  187. ;> --- TBD ---                                                                                    ;;
  188. ;;------------------------------------------------------------------------------------------------;;
  189. ;< --- TBD ---                                                                                    ;;
  190. ;;================================================================================================;;
  191.         push    eax
  192.         mov     eax, [_ctx]
  193.         stdcall gfx.line, eax, [eax + AGfxContext.Caret.X], [eax + AGfxContext.Caret.Y], [_x], [_y]
  194.         pop     eax
  195.         stdcall gfx.move.to, [_ctx], [_x], [_y]
  196.         ret
  197. endp
  198.  
  199. ;;================================================================================================;;
  200. proc gfx.line _ctx, _x1, _y1, _x2, _y2 ;//////////////////////////////////////////////////////////;;
  201. ;;------------------------------------------------------------------------------------------------;;
  202. ;? --- TBD ---                                                                                    ;;
  203. ;;------------------------------------------------------------------------------------------------;;
  204. ;> --- TBD ---                                                                                    ;;
  205. ;;------------------------------------------------------------------------------------------------;;
  206. ;< --- TBD ---                                                                                    ;;
  207. ;;================================================================================================;;
  208.         push    eax ebx ecx edx
  209.         mov     eax, 38
  210.         mov     ebx, [_x1 - 2]
  211.         mov     bx, word[_x2]
  212.         mov     ecx, [_y1 - 2]
  213.         mov     cx, word[_y2]
  214.         mov     edx, [_ctx]
  215.         mov     edx, [edx + AGfxContext.Pen.Color]
  216.         int     0x40
  217.         pop     edx ecx ebx eax
  218.         stdcall gfx.move.to, [_ctx], [_x2], [_y2]
  219.         ret
  220. endp
  221.  
  222. ;;================================================================================================;;
  223. proc gfx.polyline _ctx, _points, _count ;/////////////////////////////////////////////////////////;;
  224. ;;------------------------------------------------------------------------------------------------;;
  225. ;? --- TBD ---                                                                                    ;;
  226. ;;------------------------------------------------------------------------------------------------;;
  227. ;> --- TBD ---                                                                                    ;;
  228. ;;------------------------------------------------------------------------------------------------;;
  229. ;< --- TBD ---                                                                                    ;;
  230. ;;================================================================================================;;
  231.         push    eax ecx
  232.         mov     eax, [_points]
  233.         stdcall gfx.move.to, [_ctx], [eax + 0], [eax + 4]
  234.         mov     ecx, [_count]
  235.         dec     ecx
  236.         add     eax, 8
  237.         stdcall gfx.polyline.to, [_ctx], eax, ecx
  238.         pop     ecx eax
  239.         ret
  240. endp
  241.  
  242. ;;================================================================================================;;
  243. proc gfx.polyline.to _ctx, _points, _count ;//////////////////////////////////////////////////////;;
  244. ;;------------------------------------------------------------------------------------------------;;
  245. ;? --- TBD ---                                                                                    ;;
  246. ;;------------------------------------------------------------------------------------------------;;
  247. ;> --- TBD ---                                                                                    ;;
  248. ;;------------------------------------------------------------------------------------------------;;
  249. ;< --- TBD ---                                                                                    ;;
  250. ;;================================================================================================;;
  251.         push    eax ecx
  252.         mov     eax, [_points]
  253.         mov     ecx, [_count]
  254.     @@: stdcall gfx.line.to, [_ctx], [eax + 0], [eax + 4]
  255.         add     eax, 8
  256.         loop    @b
  257.         pop     ecx eax
  258.         ret
  259. endp
  260.  
  261. ;;================================================================================================;;
  262. proc gfx.fillrect _ctx, _x1, _y1, _x2, _y2 ;//////////////////////////////////////////////////////;;
  263. ;;------------------------------------------------------------------------------------------------;;
  264. ;? --- TBD ---                                                                                    ;;
  265. ;;------------------------------------------------------------------------------------------------;;
  266. ;> --- TBD ---                                                                                    ;;
  267. ;;------------------------------------------------------------------------------------------------;;
  268. ;< --- TBD ---                                                                                    ;;
  269. ;;================================================================================================;;
  270.         push    eax ebx ecx edx
  271.         mov     eax, 13
  272.         mov     ebx, [_x1 - 2]
  273.         mov     bx, word[_x2]
  274.         sub     bx, word[_x1]
  275.         inc     bx
  276.         mov     ecx, [_y1 - 2]
  277.         mov     cx, word[_y2]
  278.         sub     cx, word[_y1]
  279.         inc     cx
  280.         mov     edx, [_ctx]
  281.         mov     edx, [edx + AGfxContext.Brush.Color]
  282.         int     0x40
  283.         pop     edx ecx ebx eax
  284.         ret
  285. endp
  286.  
  287. ;;================================================================================================;;
  288. proc gfx.fillrect.ex _ctx, _rect ;////////////////////////////////////////////////////////////////;;
  289. ;;------------------------------------------------------------------------------------------------;;
  290. ;? --- TBD ---                                                                                    ;;
  291. ;;------------------------------------------------------------------------------------------------;;
  292. ;> --- TBD ---                                                                                    ;;
  293. ;;------------------------------------------------------------------------------------------------;;
  294. ;< --- TBD ---                                                                                    ;;
  295. ;;================================================================================================;;
  296.         push    eax
  297.         mov     eax, [_rect]
  298.         stdcall gfx.fillrect, [_ctx], [eax + ARect.Left], [eax + ARect.Top], \
  299.                               [eax + ARect.Right], [eax + ARect.Bottom]
  300.         pop     eax
  301.         ret
  302. endp
  303.  
  304. ;;================================================================================================;;
  305. proc gfx.framerect _ctx, _x1, _y1, _x2, _y2 ;/////////////////////////////////////////////////////;;
  306. ;;------------------------------------------------------------------------------------------------;;
  307. ;? --- TBD ---                                                                                    ;;
  308. ;;------------------------------------------------------------------------------------------------;;
  309. ;> --- TBD ---                                                                                    ;;
  310. ;;------------------------------------------------------------------------------------------------;;
  311. ;< --- TBD ---                                                                                    ;;
  312. ;;================================================================================================;;
  313.         stdcall gfx.move.to, [_ctx], [_x1], [_y1]
  314.         stdcall gfx.line.to, [_ctx], [_x2], [_y1]
  315.         stdcall gfx.line.to, [_ctx], [_x2], [_y2]
  316.         stdcall gfx.line.to, [_ctx], [_x1], [_y2]
  317.         stdcall gfx.line.to, [_ctx], [_x1], [_y1]
  318.         pop     edx ecx ebx eax
  319.         ret
  320. endp
  321.  
  322. ;;================================================================================================;;
  323. proc gfx.framerect.ex _ctx, _rect ;///////////////////////////////////////////////////////////////;;
  324. ;;------------------------------------------------------------------------------------------------;;
  325. ;? --- TBD ---                                                                                    ;;
  326. ;;------------------------------------------------------------------------------------------------;;
  327. ;> --- TBD ---                                                                                    ;;
  328. ;;------------------------------------------------------------------------------------------------;;
  329. ;< --- TBD ---                                                                                    ;;
  330. ;;================================================================================================;;
  331.         push    eax
  332.         mov     eax, [_rect]
  333.         stdcall gfx.framerect, [_ctx], [eax + ARect.Left], [eax + ARect.Top], \
  334.                                [eax + ARect.Right], [eax + ARect.Bottom]
  335.         pop     eax
  336.         ret
  337. endp
  338.  
  339. ;;================================================================================================;;
  340. proc gfx.rectangle _ctx, _x1, _y1, _x2, _y2 ;/////////////////////////////////////////////////////;;
  341. ;;------------------------------------------------------------------------------------------------;;
  342. ;? --- TBD ---                                                                                    ;;
  343. ;;------------------------------------------------------------------------------------------------;;
  344. ;> --- TBD ---                                                                                    ;;
  345. ;;------------------------------------------------------------------------------------------------;;
  346. ;< --- TBD ---                                                                                    ;;
  347. ;;================================================================================================;;
  348.         stdcall gfx.framerect, [_ctx], [_x1], [_y1], [_x2], [_y2]
  349.         push    [_y2] [_x2] [_y1] [_x1]
  350.         inc     dword[esp + 0x00]
  351.         inc     dword[esp + 0x04]
  352.         dec     dword[esp + 0x08]
  353.         dec     dword[esp + 0x0C]
  354.         stdcall gfx.fillrect, [_ctx]
  355.         ret
  356. endp
  357.  
  358. ;;================================================================================================;;
  359. proc gfx.rectangle.ex _ctx, _rect ;///////////////////////////////////////////////////////////////;;
  360. ;;------------------------------------------------------------------------------------------------;;
  361. ;? --- TBD ---                                                                                    ;;
  362. ;;------------------------------------------------------------------------------------------------;;
  363. ;> --- TBD ---                                                                                    ;;
  364. ;;------------------------------------------------------------------------------------------------;;
  365. ;< --- TBD ---                                                                                    ;;
  366. ;;================================================================================================;;
  367.         push    eax
  368.         mov     eax, [_rect]
  369.         stdcall gfx.rectangle, [_ctx], [eax + ARect.Left], [eax + ARect.Top], \
  370.                                [eax + ARect.Right], [eax + ARect.Bottom]
  371.         pop     eax
  372.         ret
  373. endp
  374.  
  375. ;;================================================================================================;;
  376. proc gfx.text _ctx, _text, _len, _x, _y ;/////////////////////////////////////////////////////////;;
  377. ;;------------------------------------------------------------------------------------------------;;
  378. ;? --- TBD ---                                                                                    ;;
  379. ;;------------------------------------------------------------------------------------------------;;
  380. ;> --- TBD ---                                                                                    ;;
  381. ;;------------------------------------------------------------------------------------------------;;
  382. ;< --- TBD ---                                                                                    ;;
  383. ;;================================================================================================;;
  384.         ret
  385. endp
  386.  
  387. ;;================================================================================================;;
  388. proc gfx.text.width _ctx, _text, _len ;///////////////////////////////////////////////////////////;;
  389. ;;------------------------------------------------------------------------------------------------;;
  390. ;? --- TBD ---                                                                                    ;;
  391. ;;------------------------------------------------------------------------------------------------;;
  392. ;> --- TBD ---                                                                                    ;;
  393. ;;------------------------------------------------------------------------------------------------;;
  394. ;< --- TBD ---                                                                                    ;;
  395. ;;================================================================================================;;
  396.         ret
  397. endp
  398.  
  399. ;;================================================================================================;;
  400. proc gfx.text.height _ctx, _text, _len ;//////////////////////////////////////////////////////////;;
  401. ;;------------------------------------------------------------------------------------------------;;
  402. ;? --- TBD ---                                                                                    ;;
  403. ;;------------------------------------------------------------------------------------------------;;
  404. ;> --- TBD ---                                                                                    ;;
  405. ;;------------------------------------------------------------------------------------------------;;
  406. ;< --- TBD ---                                                                                    ;;
  407. ;;================================================================================================;;
  408.         ret
  409. endp
  410.  
  411.  
  412. ;;================================================================================================;;
  413. ;;////////////////////////////////////////////////////////////////////////////////////////////////;;
  414. ;;================================================================================================;;
  415. ;! Exported functions section                                                                     ;;
  416. ;;================================================================================================;;
  417. ;;////////////////////////////////////////////////////////////////////////////////////////////////;;
  418. ;;================================================================================================;;
  419.  
  420.  
  421. align 16
  422. @EXPORT:
  423.  
  424. export                                          \
  425.         lib_init         , 'lib_init'         , \
  426.         0x00020002       , 'version'          , \
  427.         gfx.open         , 'gfx_open'         , \
  428.         gfx.close        , 'gfx_close'        , \
  429.         gfx.pen.color    , 'gfx_pen_color'    , \
  430.         gfx.brush.color  , 'gfx_brush_color'  , \
  431.         gfx.pixel        , 'gfx_pixel'        , \
  432.         gfx.move.to      , 'gfx_move_to'      , \
  433.         gfx.line.to      , 'gfx_line_to'      , \
  434.         gfx.line         , 'gfx_line'         , \
  435.         gfx.polyline     , 'gfx_polyline'     , \
  436.         gfx.polyline.to  , 'gfx_polyline_to'  , \
  437.         gfx.fillrect     , 'gfx_fillrect'     , \
  438.         gfx.fillrect.ex  , 'gfx_fillrect_ex'  , \
  439.         gfx.framerect    , 'gfx_framerect'    , \
  440.         gfx.framerect.ex , 'gfx_framerect_ex' , \
  441.         gfx.rectangle    , 'gfx_rectangle'    , \
  442.         gfx.rectangle.ex , 'gfx_rectangle_ex'
  443.