Subversion Repositories Kolibri OS

Rev

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

  1. ;const int
  2. KOLIBRI_BORDER_SIZE = 4;
  3. ;const int
  4. KOLIBRI_HEADER_SIZE = 20;
  5.  
  6. ;const int
  7. KOLIBRI_THREAD_DATA_USER     = 0; // Thread data begin from the user dword
  8. ;const int
  9. KOLIBRI_THREAD_DATA_ST_BEGIN = 1; // Stack beginning follows after the user dword
  10. ;const int
  11. KOLIBRI_THREAD_DATA_NEXT     = 2;
  12. ;const int
  13. KOLIBRI_THREAD_DATA_PID     = 3;
  14. ;const int
  15. KOLIBRI_THREAD_DATA_FLAG     = 4;
  16. ;const int
  17. KOLIBRI_THREAD_DATA_X       = 5;
  18. ;const int
  19. KOLIBRI_THREAD_DATA_Y       = 6;
  20. ;const int
  21. KOLIBRI_THREAD_DATA_C_WINDOW = 7;
  22. ;const int
  23. KOLIBRI_THREAD_DATA_C_HEADER = 8;
  24. ;const int
  25. KOLIBRI_THREAD_DATA_C_BORDER = 9;
  26. ;const int
  27. KOLIBRI_THREAD_DATA_C_TITLE  = 10;
  28. ;const int
  29. KOLIBRI_THREAD_DATA_TITLE    = 11;
  30. ;const int
  31. KOLIBRI_THREAD_DATA_PICTURE  = 12;
  32. ;const int
  33. KOLIBRI_THREAD_DATA_SZ_PICT  = 13;
  34. ;const int
  35. KOLIBRI_THREAD_DATA_LAST_SX  = 14;
  36. ;const int
  37. KOLIBRI_THREAD_DATA_LAST_SY  = 15;
  38. ;const int
  39. KOLIBRI_THREAD_DATA_LEN     = 16;
  40.  
  41. ;const int
  42. KOLIBRI_MUTEX_MAX_TIME_WAIT  = 20;
  43.  
  44. ;/***
  45.  
  46. macro segment name
  47. {
  48.   segment name
  49.   if name eq _init_ | name eq _INIT_
  50. Kolibri_SegmentInit:
  51.   else if name eq _exit_ | name eq _EXIT_
  52. Kolibri_SegmentExit:
  53.   end if
  54. }
  55.  
  56. macro endseg  name
  57. {
  58.   if name eq _init_ | name eq _INIT_
  59. Kolibri_SegmentInitEnd:
  60.   else if name eq _exit_ | name eq _EXIT_
  61. Kolibri_SegmentExitEnd:
  62.   end if
  63.   endseg  name
  64. }
  65.  
  66. macro Kolibri_Put_MovEaxVal_Ret address,val
  67. {
  68.   mov  byte [address],0xB8
  69.   mov  dword [address+4],0xC089C300
  70.   mov  dword [address+1],val
  71. }
  72.  
  73. proc @Kolibri@Main$qv
  74.   and  esp,not 3
  75.   sub  esp,1024
  76.   mov  eax,SF_THREAD_INFO
  77.   mov  ebx,esp
  78.   mov  ecx,-1
  79.   int  0x40
  80.   mov  ebx,[esp+26]
  81.   mov  edx,[esp+30]
  82.   lea  eax,[ebx-0x20]
  83.   add  esp,1024
  84.   cmp  esp,eax
  85.   cmova esp,eax
  86.   and  esp,not 3
  87. if defined @Kolibri@CommandLine
  88.         mov     byte [@Kolibri@CommandLine+256], 0
  89. end if
  90.   xor  eax,eax
  91.   cld
  92.   mov  edi,@Kolibri@_ThreadTable
  93.   mov  ecx,256
  94.   rep stosd
  95.   mov  esi,@Kolibri@GetPid$qv
  96.   mov  edi,@Kolibri@_ThreadSavedBegProc
  97.   movsd
  98.   movsd
  99.   mov  esi,@Kolibri@GetThreadData$qv
  100.   movsd
  101.   movsd
  102.   Kolibri_Put_MovEaxVal_Ret  @Kolibri@GetPid$qv,edx
  103. if defined KolibriHeapInit
  104.   mov  ecx,esp
  105.   push ebx
  106.   push ecx
  107.   push U_END
  108.   call KolibriHeapInit  ; Initialize a dynamic heap and create new memory in its begin.
  109.   pop  ecx              ; Parameters: begin of a new heap, end of data to create in
  110.   mov  [esp+4],eax      ; the begin of a heap. Return address of the created data.
  111.   mov  dword [esp],0
  112. else
  113.   xor  eax,eax
  114.   push eax
  115.   push eax
  116. end if
  117.   call @Kolibri@ThreadMain$qpvt1
  118. .ThreadFinish:
  119.   add  esp,8
  120. if defined KolibriHeapFreeAndThreadFinish
  121.   test eax,eax
  122.   jz   .ThreadFinish_end
  123.   push dword @Kolibri@_ExitProcessNow
  124.   push eax
  125.   call KolibriHeapFreeAndThreadFinish   ; Free the given memory and finish the thread,
  126. end if                                 ; should exit process if second argument points to not zero.
  127. .ThreadFinish_end:
  128.   or   eax,-1
  129.   int  0x40
  130. endp
  131.  
  132. proc @Kolibri@ThreadMain$qpvt1
  133.   xchg ebx,[esp+4]
  134.   xchg ebp,[esp+8]
  135.   push esi edi
  136.   sub  esp,KOLIBRI_THREAD_DATA_LEN*4
  137.   mov  [esp],ebx
  138.   mov  [esp+4],ebp
  139.   mov  eax,SF_SET_EVENTS_MASK
  140.   mov  ebx,0x27
  141.   int  0x40
  142.   mov  ebx,esp
  143.   cmp  byte [@Kolibri@_ThreadSavedBegProc],0x90
  144.   jz   .main_else_first_check
  145.   Kolibri_Put_MovEaxVal_Ret  @Kolibri@GetThreadData$qv,esp
  146. if defined Kolibri_SegmentInit & defined Kolibri_SegmentInitEnd
  147.   push Kolibri_SegmentInitEnd
  148.   push Kolibri_SegmentInit
  149.   jmp  .main_after_first_check
  150. end if
  151. .main_else_first_check:
  152.   xor  eax,eax
  153.   push eax eax
  154. .main_after_first_check:
  155.   push ebx
  156.   call @@Kolibri@_CallStart$qppvpvt2
  157.   add  esp,12
  158.   test al,al
  159.   jnz  .main_test_close_first
  160.   jmp  .main_end
  161. .main_close_first:
  162.   btr  dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],31
  163. if defined @@KolibriOnClose$qppv
  164.   push esp
  165.   call @@KolibriOnClose$qppv
  166.   pop  ecx
  167.   test al,al
  168.   jnz  .main_end
  169. end if
  170. .main_test_close_first:
  171.   cmp  dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],0
  172.   jl   .main_close_first
  173.   push esp
  174.   push dword 1
  175.   call @Kolibri@Redraw$qippv
  176.   add  esp,8
  177. .main_paint_msg:
  178.   or   dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],3
  179.   sub  esp,1024
  180.   mov  eax,SF_THREAD_INFO
  181.   mov  ebx,esp
  182.   mov  ecx,-1
  183.   int  0x40
  184.   mov  eax,[esp+34]
  185.   mov  ebx,[esp+38]
  186.   mov  ecx,[esp+42]
  187.   mov  edx,[esp+46]
  188.   add  esp,1024
  189.   cmp  ecx,[esp+KOLIBRI_THREAD_DATA_LAST_SX*4]
  190.   jnz  .main_size
  191.   cmp  edx,[esp+KOLIBRI_THREAD_DATA_LAST_SY*4]
  192.   jz   .main_paint
  193. .main_size:
  194.   mov  [esp+KOLIBRI_THREAD_DATA_LAST_SX*4],ecx
  195.   mov  [esp+KOLIBRI_THREAD_DATA_LAST_SY*4],edx
  196. if defined @@KolibriOnSize$qpippv
  197.   push edx
  198.   push ecx
  199.   push ebx
  200.   push eax
  201.   lea  ecx,[esp+16]
  202.   mov  edx,esp
  203.   push ecx
  204.   push edx
  205.   call @@KolibriOnSize$qpippv
  206.   add  esp,24
  207. end if
  208.   test dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],3
  209.   jz   .main_cycle
  210. .main_paint:
  211.   cmp  dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],0
  212.   jl   .main_close
  213.   push esp
  214.   push dword 0
  215.   call @Kolibri@Redraw$qippv
  216.   add  esp,8
  217. .main_cycle:
  218.   mov  eax,SF_CHECK_EVENT
  219. .main_message:
  220.   cmp  dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],0
  221.   jl   .main_close
  222.   int  0x40
  223.   test eax,eax
  224.   jnz  .main_on_message
  225.   cmp  dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],0
  226.   jne  .main_paint
  227. if defined @@KolibriOnIdle$qppv
  228.   push esp
  229.   call @@KolibriOnIdle$qppv
  230.   pop  ecx
  231. else
  232.   or eax,-1
  233. end if
  234.   test eax,eax
  235.   jz   .main_cycle
  236.   jl   .main_wait_message
  237.   mov  ebx,eax
  238.   mov  eax,SF_WAIT_EVENT_TIMEOUT
  239.   jmp  .main_message
  240. .main_wait_message:
  241.   mov  eax,SF_WAIT_EVENT
  242.   jmp  .main_message
  243. if defined @@KolibriOnKeyPress$qppv
  244. .main_key_press:
  245.   push esp
  246.   call @@KolibriOnKeyPress$qppv
  247.   pop  ecx
  248.   jmp  .main_cycle
  249. end if
  250. if defined @@KolibriOnMouse$qppv
  251. .main_mouse:
  252.   push esp
  253.   call @@KolibriOnMouse$qppv
  254.   pop  ecx
  255.   jmp  .main_cycle
  256. end if
  257.  
  258. align 4
  259. .main_on_message:
  260.   dec  eax
  261.   jz   .main_paint_msg
  262.   dec  eax
  263. if defined @@KolibriOnKeyPress$qppv
  264.   jz   .main_key_press
  265. else
  266.   jz   .main_cycle
  267. end if
  268.   cmp  eax,4
  269. if defined @@KolibriOnMouse$qppv
  270.   jz   .main_mouse
  271. else
  272.   jz   .main_cycle
  273. end if
  274.   dec  eax
  275.   jnz  .main_cycle
  276.  
  277. align 4
  278. .main_button:
  279.   mov  eax,SF_GET_BUTTON
  280.   int  0x40
  281.   shr  eax,8
  282.   cmp  eax,1
  283.   je   .main_close
  284. if defined @@KolibriOnButton$qlppv
  285.   push esp
  286.   push eax
  287.   call @@KolibriOnButton$qlppv
  288.   add  esp,8
  289. end if
  290.   jmp  .main_cycle
  291. .main_close:
  292.   btr  dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],31
  293. if defined @@KolibriOnClose$qppv
  294.   push esp
  295.   call @@KolibriOnClose$qppv
  296.   pop  ecx
  297.   test al,al
  298.   jz   .main_button
  299. end if
  300. .main_end:
  301.   mov  ebx,esp
  302.   lock dec dword [@Kolibri@_ThreadNumber]
  303. if defined Kolibri_SegmentExit & defined Kolibri_SegmentExitEnd
  304.   jnz  .main_else_last_check
  305.   push Kolibri_SegmentExitEnd
  306.   push Kolibri_SegmentExit
  307.   jmp  .main_after_last_check
  308. end if
  309. .main_else_last_check:
  310.   xor  eax,eax
  311.   push eax
  312.   push eax
  313. .main_after_last_check:
  314.   push ebx
  315.   call @@Kolibri@_RemoveThreadData$qppvpvt2
  316.   add  esp,12
  317.   lock inc dword [@Kolibri@_ThreadScanCount+4]
  318.   mov  ebx,1
  319.   jmp  .main_end_wait
  320. .main_end_wait_loop:
  321.   mov  eax,SF_SLEEP
  322.   int  0x40
  323.   shl  ebx,1
  324.   cmp  ebx,KOLIBRI_MUTEX_MAX_TIME_WAIT
  325.   jna  .main_end_wait
  326.   mov  ebx,KOLIBRI_MUTEX_MAX_TIME_WAIT
  327. .main_end_wait:
  328.   cmp  dword [@Kolibri@_ExitProcessNow],0
  329.   jnz  @Kolibri@ExitProcess$qv
  330.   cmp  dword [@Kolibri@_ThreadScanCount],0
  331.   jnz  .main_end_wait_loop
  332.   lock dec dword [@Kolibri@_ThreadScanCount+4]
  333.   mov  ebp,[esp+4]
  334.   mov  ebx,[esp]
  335.   add  esp,KOLIBRI_THREAD_DATA_LEN*4
  336.   mov  eax,ebp
  337.   pop  edi esi
  338.   xchg ebp,[esp+8]
  339.   xchg ebx,[esp+4]
  340.   ret
  341. endp
  342.  
  343. macro call func
  344. {
  345.   if func eq __chkstk
  346.         sub  esp,eax
  347.   else
  348.         call func
  349.   end if
  350. }
  351.  
  352. proc @Kolibri@Redraw$qippv
  353.   push ebp
  354.   mov  ebp,[esp+12]
  355.   mov  edx,[ebp+KOLIBRI_THREAD_DATA_FLAG*4]
  356.   cmp  dword [esp+8],0
  357.   jl   .redraw_only_inv
  358.   jz   .redraw_no_frame
  359.   or   dl,2
  360. .redraw_no_frame:
  361.   bt   edx,30
  362.   jnc  .redraw_begin
  363.   or   dl,1
  364.   mov  [ebp+KOLIBRI_THREAD_DATA_FLAG*4],edx
  365.   jmp  .redraw_end
  366. .redraw_only_inv:
  367.   test dl,3
  368.   jnz  .redraw_no_frame
  369. .redraw_end:
  370.   pop  ebp
  371.   ret
  372. .redraw_begin:
  373.   push ebx esi edi
  374.   and  dword [ebp+KOLIBRI_THREAD_DATA_FLAG*4],0xFFFFFFFC
  375.   test dl,2
  376.   jz   .redraw_picture
  377.   mov  eax,SF_REDRAW
  378.   mov  ebx,SSF_BEGIN_DRAW
  379.   int  0x40
  380.   xor  eax,eax
  381.   mov  ebx,[ebp+KOLIBRI_THREAD_DATA_X*4]
  382.   mov  ecx,[ebp+KOLIBRI_THREAD_DATA_Y*4]
  383.   mov  edx,[ebp+KOLIBRI_THREAD_DATA_C_WINDOW*4]
  384.   mov  esi,[ebp+KOLIBRI_THREAD_DATA_C_HEADER*4]
  385.   mov  edi,[ebp+KOLIBRI_THREAD_DATA_C_BORDER*4]
  386.   int  0x40
  387.   mov  edx,[ebp+KOLIBRI_THREAD_DATA_TITLE*4]
  388.   test edx,edx
  389.   jz   .window_defined
  390.   mov  edi,edx
  391.   mov  ecx,0xFFFFFFFF
  392.   xor  al,al
  393.   cld
  394.   repnz scas byte [edi]
  395.   not  ecx
  396.   mov  esi,ecx
  397.   dec  esi
  398.   jz   .window_defined
  399.   mov  eax,SF_DRAW_TEXT
  400.   mov  ebx,0x00070007
  401.   mov  ecx,[ebp+KOLIBRI_THREAD_DATA_C_TITLE*4]
  402.   int  0x40
  403. .window_defined:
  404. .redraw_picture:
  405.   mov  eax,SF_REDRAW
  406.   mov  ebx,SSF_END_DRAW
  407.   int  0x40
  408.   mov  esi,[ebp+KOLIBRI_THREAD_DATA_PICTURE*4]
  409.   test esi,esi
  410.   jz   .redraw_end_draw
  411.   mov  ecx,[ebp+KOLIBRI_THREAD_DATA_SZ_PICT*4]
  412.   jecxz .redraw_end_draw
  413.   mov  al,byte [ebp+KOLIBRI_THREAD_DATA_C_WINDOW*4+3]
  414.   and  al,15
  415.   mov  edx,KOLIBRI_BORDER_SIZE*65536+KOLIBRI_HEADER_SIZE
  416.   cmp  al,3
  417.   jnz  .redraw_no_skin
  418.   mov  eax,SF_STYLE_SETTINGS
  419.   mov  ebx,SSF_GET_SKIN_HEIGHT
  420.   int  0x40
  421.   mov  dx,ax
  422. .redraw_no_skin:
  423.   mov  eax,SF_PUT_IMAGE
  424.   mov  ebx,esi
  425.   int  0x40
  426. .redraw_end_draw:
  427.   pop  edi esi ebx ebp
  428.   ret
  429. endp
  430.  
  431. proc @Kolibri@MoveWindow$qxpxi uses ebx esi
  432.   mov  eax,[esp+12]
  433.   mov  ebx,[eax]
  434.   mov  ecx,[eax+4]
  435.   mov  edx,[eax+8]
  436.   mov  esi,[eax+12]
  437.   mov  eax,SF_CHANGE_WINDOW
  438.   int  0x40
  439.   ret
  440. endp
  441.  
  442. proc @Kolibri@ExitDebug$qv
  443.   push dword [@Kolibri@DebugPrefix]
  444.   call @Kolibri@DebugPutString$qpxc
  445.   mov   dword [esp],Kolibri_debug_string
  446.   call @Kolibri@DebugPutString$qpxc
  447.   pop   ecx
  448.   jmp  @Kolibri@ExitProcess$qv
  449. endp
  450.  
  451. proc @Kolibri@ExitProcess$qv
  452.   lock bts dword [@Kolibri@_ExitProcessNow],0
  453.   jc   .exit_process_wait
  454.   sub  esp,1024
  455.   mov  eax,SF_THREAD_INFO
  456.   mov  ebx,esp
  457.   mov  ecx,-1
  458.   int  0x40
  459.   mov  esi,eax
  460.   mov  edi,[esp+30]
  461. .exit_process_loop:
  462.   mov  eax,SF_THREAD_INFO
  463.   mov  ebx,esp
  464.   mov  ecx,esi
  465.   int  0x40
  466.   mov  eax,[esp+30]
  467.   cmp  eax,edi
  468.   jz   .exit_process_continue
  469.   mov  ebx,eax
  470.   or   bl,15
  471.   inc  ebx
  472.   jz   .exit_process_continue
  473.   mov  ebx,eax
  474.   call Kolibri_HashInt
  475.   movzx eax,al
  476.   mov  eax,dword [@Kolibri@_ThreadTable+eax*4]
  477.   jmp  .exit_process_test
  478. .exit_process_next:
  479.   mov  eax,dword [eax+KOLIBRI_THREAD_DATA_NEXT*4]
  480. .exit_process_test:
  481.   test eax,eax
  482.   jz   .exit_process_continue
  483.   cmp  ebx,[eax+KOLIBRI_THREAD_DATA_PID*4]
  484.   jnz  .exit_process_next
  485.   mov  eax,SF_SYSTEM
  486.   mov  ebx,SSF_TERMINATE_THREAD
  487.   mov  ecx,esi
  488.   int  0x40
  489. .exit_process_continue:
  490.   dec  esi
  491.   jnl  .exit_process_loop
  492.   add  esp,1024
  493.   mov  dword [@Kolibri@_ExitProcessNow],-1
  494. if defined EMULATOR
  495.   int3
  496.   call 0x76543210
  497. end if
  498. .exit_process_end:
  499.   mov  dword [@Kolibri@_ThreadMutex],0
  500.   or   eax,-1
  501.   int  0x40
  502. .exit_process_wait:
  503.   mov  eax,SF_SLEEP
  504.   mov  ebx,1
  505. .exit_process_wait_loop:
  506.   cmp  dword [@Kolibri@_ExitProcessNow],0
  507.   jl   .exit_process_end
  508.   int  0x40
  509.   shl  ebx,1
  510.   cmp  ebx,KOLIBRI_MUTEX_MAX_TIME_WAIT
  511.   jna  .exit_process_wait_loop
  512.   mov  ebx,KOLIBRI_MUTEX_MAX_TIME_WAIT
  513.   jmp  .exit_process_wait_loop
  514. endp
  515.  
  516. proc @Kolibri@ExitThread$qppv,@Kolibri@ThreadMain$qpvt1
  517.   mov  esp,[esp+4]
  518.   jmp  Kolibri_main_end
  519. endp
  520.  
  521. proc @Kolibri@ReturnMessageLoop$qppv,@Kolibri@ThreadMain$qpvt1
  522.   mov  esp,[esp+4]
  523.   bt   dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],30
  524.   jc   Kolibri_main_end
  525.   jmp  Kolibri_main_cycle
  526. endp
  527.  
  528. proc @Kolibri@Delay$qui uses ebx
  529.   mov  eax,SF_SLEEP
  530.   mov  ebx,[esp+8]
  531.   int  0x40
  532.   ret
  533. endp
  534.  
  535. proc @Kolibri@Clock$qv uses ebx
  536.   mov  eax,SF_SYSTEM_GET
  537.   mov  ebx,SSF_TIME_COUNT
  538.   int  0x40
  539.   ret
  540. endp
  541.  
  542. proc @Kolibri@DrawButton$qllllll uses ebx esi
  543.   mov  eax,SF_DEFINE_BUTTON
  544.   mov  ebx,[esp+12-2+8]
  545.   mov  bx,[esp+20+8]
  546.   mov  ecx,[esp+16-2+8]
  547.   mov  cx,[esp+24+8]
  548.   mov  edx,[esp+4+8]
  549.   mov  esi,[esp+8+8]
  550.   int  0x40
  551.   ret
  552. endp
  553.  
  554. proc @Kolibri@GetPackedTime$qv
  555.   mov  eax,SF_GET_SYS_TIME
  556.   int  0x40
  557.   ret
  558. endp
  559.  
  560. proc @Kolibri@GetTime$qpi
  561.   mov  eax,SF_GET_SYS_TIME
  562.   int  0x40
  563.   mov  edx,[esp+4]
  564.   movzx ecx,al
  565.   shr  ecx,4
  566.   and  al,0x0F
  567.   imul ecx,10
  568.   add  cl,al
  569.   mov  dword [edx+8],ecx
  570.   mov  cl,ah
  571.   shr  ecx,4
  572.   and  ah,0x0F
  573.   imul ecx,10
  574.   add  cl,ah
  575.   mov  dword [edx+4],ecx
  576.   bswap eax
  577.   mov  cl,ah
  578.   shr  ecx,4
  579.   and  ah,0x0F
  580.   imul ecx,10
  581.   add  cl,ah
  582.   mov  dword [edx],ecx
  583.   ret
  584. endp
  585.  
  586. proc @Kolibri@GetPackedDate$qv
  587.   mov  eax,SF_GET_SYS_DATE
  588.   int  0x40
  589.   ret
  590. endp
  591.  
  592. proc @Kolibri@GetDate$qpi
  593.   mov  eax,SF_GET_SYS_DATE
  594.   int  0x40
  595.   mov  edx,[esp+4]
  596.   movzx ecx,al
  597.   shr  ecx,4
  598.   and  al,0x0F
  599.   imul ecx,10
  600.   add  cl,al
  601.   mov  dword [edx+4],ecx
  602.   mov  cl,ah
  603.   shr  ecx,4
  604.   and  ah,0x0F
  605.   imul ecx,10
  606.   add  cl,ah
  607.   mov  dword [edx],ecx
  608.   bswap eax
  609.   mov  cl,ah
  610.   shr  ecx,4
  611.   and  ah,0x0F
  612.   imul ecx,10
  613.   add  cl,ah
  614.   mov  dword [edx+8],ecx
  615.   ret
  616. endp
  617.  
  618. proc @Kolibri@ReadCommonColors$qpui uses ebx
  619.   mov  eax,SF_STYLE_SETTINGS
  620.   mov  ebx,SSF_GET_COLORS
  621.   mov  ecx,[esp+8]
  622.   mov  edx,40
  623.   int  0x40
  624.   ret
  625. endp
  626.  
  627. proc @Kolibri@DrawText$qssipxc uses ebx
  628.   mov  eax,SF_DRAW_TEXT
  629.   mov  ebx,[esp+8-2]
  630.   mov  bx,[esp+12]
  631.   mov  ecx,[esp+16]
  632.   or   ecx,0x80000000
  633.   mov  edx,[esp+20]
  634.   int  0x40
  635.   ret
  636. endp
  637.  
  638. proc @Kolibri@SetWindowCaption$qpxc uses ebx
  639.   mov  eax,SF_SET_CAPTION
  640.   mov  ebx,2
  641.   mov  ecx,[esp+8]
  642.   int  0x40
  643.   ret
  644. endp
  645.  
  646. proc @Kolibri@GetProcessInfo$qpuipct1t1piui uses ebx esi edi
  647.   sub  esp,1024
  648.   mov  eax,SF_THREAD_INFO
  649.   mov  ebx,esp
  650.   mov  ecx,[1024+12+24+esp]
  651.   int  0x40
  652.   xor  edi,edi
  653.   or   edi,[1024+12+4+esp]
  654.   jz   .get_proc_info_no_usecpu
  655.   mov  ecx,[esp]
  656.   mov  [edi],ecx
  657.   xor  edi,edi
  658. .get_proc_info_no_usecpu:
  659.   or   edi,[1024+12+8+esp]
  660.   jz   .get_proc_info_no_name
  661.   lea  esi,[esp+10]
  662.   cld
  663.   movsd
  664.   movsd
  665.   movsd
  666.   mov  byte [edi],0
  667.   xor  edi,edi
  668. .get_proc_info_no_name:
  669.   or   edi,[1024+12+12+esp]
  670.   jz   .get_proc_info_no_mem
  671.   mov  ecx,[esp+26]
  672.   mov  [edi],ecx
  673.   xor  edi,edi
  674. .get_proc_info_no_mem:
  675.   or   edi,[1024+12+16+esp]
  676.   jz   .get_proc_info_no_pid
  677.   mov  ecx,[esp+30]
  678.   mov  [edi],ecx
  679.   xor  edi,edi
  680. .get_proc_info_no_pid:
  681.   or   edi,[1024+12+20+esp]
  682.   jz   .get_proc_info_no_rect
  683.   lea  esi,[esp+34]
  684.   cld
  685.   movsd
  686.   movsd
  687.   movsd
  688.   movsd
  689.   xor  edi,edi
  690. .get_proc_info_no_rect:
  691.   add  esp,1024
  692.   ret
  693. endp
  694.  
  695. proc @Kolibri@GetPid$qv uses ebx
  696.   sub  esp,1024
  697.   mov  eax,SF_THREAD_INFO
  698.   mov  ebx,esp
  699.   mov  ecx,-1
  700.   int  0x40
  701.   mov  eax,[esp+30]
  702.   add  esp,1024
  703.   ret
  704. endp
  705.  
  706. proc @Kolibri@GetPid$qppv
  707.   mov  ecx,[esp+4]
  708.   mov  eax,[ecx+KOLIBRI_THREAD_DATA_PID*4]
  709.   ret
  710. endp
  711.  
  712. proc @Kolibri@_HashByte$qui
  713. @Kolibri@_HashWord$qui:
  714. @Kolibri@_HashDword$qui:
  715.   mov  eax,[esp+4]
  716. Kolibri_HashInt:
  717.   mul  dword [Kolibri_hash_int_val0]
  718.   xor  eax,edx
  719.   bswap eax
  720.   mul  dword [Kolibri_hash_int_val1]
  721.   shrd eax,edx,14
  722.   bswap eax
  723.   lea  eax,[eax+4*eax]
  724.   ror  eax,9
  725.   ret
  726. endp
  727.  
  728. if defined @Kolibri@_HashByte$qui | defined @Kolibri@_HashWord$qui | defined @Kolibri@_HashDword$qui
  729. Kolibri_hash_int_val0:
  730.   dd   0xA82F94C5
  731. Kolibri_hash_int_val1:
  732.   dd   0x9193780B
  733. end if
  734.  
  735. proc @Kolibri@GetThreadData$qv
  736.   call @Kolibri@GetPid$qv
  737.   push eax
  738.   call @Kolibri@GetThreadData$qui
  739.   pop  ecx
  740.   ret
  741. endp
  742.  
  743. proc @Kolibri@GetThreadData$qui
  744.   mov  eax,[esp+4]
  745.   call Kolibri_HashInt
  746.   movzx eax,al
  747.   cmp  dword [@Kolibri@_ThreadScanCount+4],0
  748.   jnz  .get_thread_data_wait
  749. .get_thread_data_nowait:
  750.   lock inc dword [@Kolibri@_ThreadScanCount]
  751.   mov  eax,dword [@Kolibri@_ThreadTable+eax*4]
  752.   mov  ecx,[esp+4]
  753.   jmp  .get_thread_data_test
  754. .get_thread_data_loop:
  755.   mov  eax,dword [eax+KOLIBRI_THREAD_DATA_NEXT*4]
  756. .get_thread_data_test:
  757.   test eax,eax
  758.   jz   .get_thread_data_end
  759.   cmp  ecx,[eax+KOLIBRI_THREAD_DATA_PID*4]
  760.   jnz  .get_thread_data_loop
  761. .get_thread_data_end:
  762.   lock dec dword [@Kolibri@_ThreadScanCount]
  763.   ret
  764. .get_thread_data_wait:
  765.   push eax ebx
  766.   mov  eax,SF_SLEEP
  767.   mov  ebx,1
  768. .get_thread_data_wait_loop:
  769.   int  0x40
  770.   cmp  dword [@Kolibri@_ThreadScanCount+4],0
  771.   jz   .get_thread_data_wait_end
  772.   shl  ebx,1
  773.   cmp  ebx,KOLIBRI_MUTEX_MAX_TIME_WAIT
  774.   jna  .get_thread_data_wait_loop
  775.   mov  ebx,KOLIBRI_MUTEX_MAX_TIME_WAIT
  776.   jmp  .get_thread_data_wait_loop
  777. .get_thread_data_wait_end:
  778.   pop  ebx eax
  779.   jmp .get_thread_data_nowait
  780. endp
  781.  
  782. proc @Kolibri@_GetSkinHeader$qv uses ebx
  783.   mov  eax,SF_STYLE_SETTINGS
  784.   mov  ebx,SSF_GET_SKIN_HEIGHT
  785.   int  0x40
  786.   ret
  787. endp
  788.  
  789. proc @Kolibri@GetScreenSize$qrust1
  790.   mov  eax,SF_GET_SCREEN_SIZE
  791.   int  0x40
  792.   mov  ecx,[esp+8]
  793.   mov  word [ecx],ax
  794.   mov  ecx,[esp+4]
  795.   shr  eax,16
  796.   mov  word [ecx],ax
  797.   ret
  798. endp
  799.  
  800. proc Kolibri_MutexLockNoWait
  801.   pop  eax
  802.   xor  al,al
  803.   ret
  804. endp
  805.  
  806. proc Kolibri_MutexLockWait uses ebx
  807.   mov  eax,SF_SLEEP
  808.   xor  ebx,ebx
  809. .lock_wait_cycle:
  810.   int  0x40
  811.   shl  byte [ecx],1
  812.   jz   .lock_wait_cycle
  813.   mov  al,1
  814.   ret
  815. endp
  816.  
  817. proc Kolibri_MutexLockWaitTime
  818.   cmp  dword [esp+12],0
  819.   jng  .MutexLockWait
  820.   push ebx edx
  821.   mov  edx,[esp+20]
  822.   mov  eax,SF_SYSTEM_GET
  823.   mov  ebx,SSF_TIME_COUNT
  824.   int  0x40
  825.   add  edx,eax
  826. .lock_wait_time_cycle:
  827.   mov  eax,SF_SLEEP
  828.   xor  ebx,ebx
  829.   int  0x40
  830.   shl  byte [ecx],1
  831.   jnz  .lock_wait_time_ret_true
  832.   mov  eax,SF_SYSTEM_GET
  833.   mov  ebx,SSF_TIME_COUNT
  834.   int  0x40
  835.   cmp  eax,edx
  836.   js   .lock_wait_time_cycle
  837.   pop  edx ebx eax
  838.   xor  al,al
  839.   ret
  840. .lock_wait_time_ret_true:
  841.   pop  edx ebx
  842.   mov  al,1
  843.   ret
  844. endp
  845.  
  846. proc Kolibri_MutexLock
  847.   shl  byte [ecx],1
  848.   jnz  .lock_first
  849.   call eax
  850. .lock_first:
  851.   mov  al,1
  852.   ret
  853. endp
  854.  
  855. proc @Kolibri@TryLock$qp14Kolibri@TMutex
  856.   mov  eax,Kolibri_MutexLockNoWait
  857.   mov  ecx,[esp+4]
  858.   jmp  Kolibri_MutexLock
  859. endp
  860.  
  861. proc @Kolibri@Lock$qp14Kolibri@TMutex
  862.   mov  eax,Kolibri_MutexLockWait
  863.   mov  ecx,[esp+4]
  864.   jmp  Kolibri_MutexLock
  865. endp
  866.  
  867. proc @Kolibri@LockTime$qp14Kolibri@TMutexi
  868.   mov  eax,Kolibri_MutexLockWaitTime
  869.   mov  ecx,[esp+4]
  870.   jmp  Kolibri_MutexLock
  871. endp
  872.  
  873. proc @Kolibri@UnLock$qp14Kolibri@TMutex
  874.   mov  ecx,[esp+4]
  875.   shr  byte [ecx],1
  876.   jz   .unlock_pause
  877.   ret
  878. .unlock_pause:
  879.   mov  byte [ecx],0x40
  880.   push ebx
  881.   mov  eax,SF_SLEEP
  882.   xor  ebx,ebx
  883.   int  0x40
  884.   pop  ebx
  885.   ret
  886. endp
  887.  
  888. proc Kolibri_MutexLockRec
  889.   shl  byte [ecx],1
  890.   jng  .lock_first
  891.   cmp  dword [ecx+4],edx
  892.   jz   .lock_rec_self
  893.   call eax
  894. .lock_rec_first:
  895.   mov  al,1
  896.   mov  dword [ecx+4],edx
  897.   ret
  898. .lock_rec_self:
  899.   mov  al,1
  900.   add  dword [ecx],0x100
  901.   jc   .lock_rec_overflow
  902.   ret
  903. .lock_rec_overflow:
  904.   push dword [@Kolibri@DebugPrefix]
  905.   call @Kolibri@DebugPutString$qpxc
  906.   mov  dword [esp],Kolibri_try_lock_rec_overflow_string
  907.   call @Kolibri@DebugPutString$qpxc
  908.   pop  ecx
  909.   jmp  @Kolibri@ExitDebug$qv
  910. endp
  911.  
  912. proc @Kolibri@TryLock$qp16Kolibri@TRecMutexui
  913.   mov  eax,Kolibri_MutexLockNoWait
  914.   mov  ecx,[esp+4]
  915.   mov  edx,[esp+8]
  916.   jmp  Kolibri_MutexLockRec
  917. endp
  918.  
  919. proc @Kolibri@Lock$qp16Kolibri@TRecMutexui
  920.   mov  eax,Kolibri_MutexLockWait
  921.   mov  ecx,[esp+4]
  922.   mov  edx,[esp+8]
  923.   jmp  Kolibri_MutexLockRec
  924. endp
  925.  
  926. proc @Kolibri@LockTime$qp16Kolibri@TRecMutexiui
  927.   mov  eax,Kolibri_MutexLockWaitTime
  928.   mov  ecx,[esp+4]
  929.   mov  edx,[esp+12]
  930.   jmp  Kolibri_MutexLockRec
  931. endp
  932.  
  933. proc @Kolibri@UnLock$qp16Kolibri@TRecMutexui
  934.   mov  ecx,[esp+4]
  935.   mov  edx,[esp+8]
  936.   cmp  dword [ecx+4],edx
  937.   jnz  .unlock_rec_notlocked
  938.   sub  dword [ecx],0x100
  939.   jnc  .unlock_rec_end
  940.   add dword [ecx],0x100
  941.   shl byte [ecx],1
  942.   shr byte [ecx],2
  943.   jng  .unlock_rec_pause
  944. .unlock_rec_end:
  945.   ret
  946. .unlock_rec_pause:
  947.   mov  byte [ecx],0x20
  948.   push ebx
  949.   mov  eax,SF_SLEEP
  950.   xor  ebx,ebx
  951.   int  0x40
  952.   pop  ebx
  953.   ret
  954. .unlock_rec_notlocked:
  955.   push dword [@Kolibri@DebugPrefix]
  956.   call @Kolibri@DebugPutString$qpxc
  957.   mov  dword [esp],Kolibri_unlock_rec_notlocked_string
  958.   call @Kolibri@DebugPutString$qpxc
  959.   pop  ecx
  960.   jmp  @Kolibri@ExitDebug$qv
  961. endp
  962.  
  963. proc @Kolibri@DebugPutChar$qc
  964.   mov  cl,byte [esp+4]
  965.   cmp  cl,13
  966.   jz   .debug_put_char_ret
  967.   push ebx
  968.   cmp  cl,10
  969.   jz   .debug_put_char_enter
  970. .debug_put_char_after_cmp:
  971.   mov  eax,SF_BOARD
  972.   mov  ebx,SSF_DEBUG_WRITE
  973.   int  0x40
  974.   pop  ebx
  975. .debug_put_char_ret:
  976.   ret
  977. .debug_put_char_enter:
  978.   mov  cl,13
  979.   mov  eax,SF_BOARD
  980.   mov  ebx,SSF_DEBUG_WRITE
  981.   int  0x40
  982.   mov  cl,10
  983.   jmp  .debug_put_char_after_cmp
  984. endp
  985.  
  986. proc @Kolibri@DebugPutString$qpxc uses esi
  987.   push dword 0
  988.   mov  esi,dword [esp+12]
  989.   jmp  .debug_put_string_test
  990. .debug_put_string_loop:
  991.   mov  dword [esp],eax
  992.   call @Kolibri@DebugPutChar$qc
  993.   inc  esi
  994. .debug_put_string_test:
  995.   xor  eax,eax
  996.   or   al,[esi]
  997.   test al,al
  998.   jnz  .debug_put_string_loop
  999.   pop  ecx
  1000.   ret
  1001. endp
  1002.  
  1003. proc @Kolibri@GetKey$qv
  1004.   mov  eax,SF_GET_KEY
  1005.   int  0x40
  1006.   test al,al
  1007.   jnz  .get_key_eof
  1008.   movzx eax,ah
  1009.   ret
  1010. .get_key_eof:
  1011.   mov  eax,SF_TERMINATE_PROCESS
  1012.   ret
  1013. endp
  1014.  
  1015. proc @Kolibri@GetMouseButton$qv uses ebx
  1016.   mov  eax,SF_MOUSE_GET
  1017.   mov  ebx,SSF_BUTTON
  1018.   int  0x40
  1019.   ret
  1020. endp
  1021.  
  1022. proc @Kolibri@GetMousePosition$qrst1o uses ebx
  1023.   mov  eax,SF_MOUSE_GET
  1024.   xor  ebx,ebx ;SSF_SCREEN_POSITION
  1025.   cmp  byte [esp+16],0
  1026.   jnz  .get_mouse_pos_absolute
  1027.   inc  ebx
  1028. .get_mouse_pos_absolute:
  1029.   int  0x40
  1030.   mov  ecx,[esp+12]
  1031.   mov  word [ecx],ax
  1032.   mov  ecx,[esp+8]
  1033.   shr  eax,16
  1034.   mov  word [ecx],ax
  1035.   ret
  1036. endp
  1037.  
  1038. proc @Kolibri@WasThreadCreated$qv
  1039.   cmp  byte [@Kolibri@_ThreadSavedBegProc],0x90
  1040.   setz al
  1041.   ret
  1042. endp
  1043.  
  1044. proc @Kolibri@CreateThread$qpvuit1
  1045.   push ebx
  1046.   mov  edx,[esp+16]
  1047.   mov  ebx,[esp+12]
  1048.   test edx,edx
  1049.   jnz  .create_thread_after_new
  1050. if defined KolibriHeapAlloc
  1051.   cmp  ebx,4096
  1052.   jnb  .create_thread_alloc
  1053.   mov  ebx,STACKSIZE
  1054. .create_thread_alloc:
  1055.   push ebx
  1056.   call KolibriHeapAlloc  ; Create new dynamic memory of the given size
  1057.   pop  ecx
  1058.   test eax,eax
  1059.   jnz  .create_thread_mem_created
  1060. end if
  1061.   or   eax,-1
  1062.   jmp  .create_thread_end
  1063. .create_thread_mem_created:
  1064.   lea  edx,[eax+ebx]
  1065. .create_thread_after_new:
  1066.   neg  ebx
  1067.   jz   .create_thread_test_first
  1068.   add  ebx,edx
  1069. .create_thread_test_first:
  1070.   cmp  byte [@Kolibri@_ThreadSavedBegProc],0x90
  1071.   jnz  .create_thread_init
  1072. .create_thread_fill_stack:
  1073.   lock inc dword [@Kolibri@_ThreadNumber]
  1074.   and  edx,not 3
  1075.   sub  edx,12
  1076.   mov  ecx,[esp+8]
  1077.   mov  dword [edx+8],ebx
  1078.   mov  dword [edx+4],ecx
  1079.   mov  dword [edx],Kolibri_ThreadFinish
  1080.   mov  eax,SF_CREATE_THREAD
  1081.   mov  ebx,1
  1082.   mov  ecx,@Kolibri@ThreadMain$qpvt1
  1083.   int  0x40
  1084.   mov  ebx,eax
  1085.   or   bl,15
  1086.   inc  ebx
  1087.   jnz  .create_thread_end
  1088.   lock dec dword [@Kolibri@_ThreadNumber]
  1089. if defined KolibriHeapFree
  1090.   or   ebx,[edx+8]
  1091.   jz   .create_thread_end
  1092.   push ebx
  1093.   call KolibriHeapFree  ; Delete the given dynamic memory
  1094.   pop  ecx
  1095. end if
  1096. .create_thread_end:
  1097.   pop  ebx
  1098.   ret
  1099. .create_thread_init:
  1100.   push esi edi
  1101.   cld
  1102.   mov  esi,@Kolibri@_ThreadSavedBegProc
  1103.   mov  edi,@Kolibri@GetPid$qv
  1104.   movsd
  1105.   movsd
  1106.   mov  edi,@Kolibri@GetThreadData$qv
  1107.   movsd
  1108.   movsd
  1109.   mov  eax,0x90909090
  1110.   mov  edi,@Kolibri@_ThreadSavedBegProc
  1111.   stosd
  1112.   stosd
  1113.   stosd
  1114.   stosd
  1115.   pop  edi esi
  1116.   jmp  .create_thread_fill_stack
  1117. endp
  1118.  
  1119. proc @Kolibri@_FileAccess$qp21Kolibri@FileInfoBlock uses ebx
  1120.   mov  eax,SF_FILE
  1121.   mov  ebx,[esp+8]
  1122.   int  0x40
  1123.   mov  ecx,[esp+8]
  1124.   mov  [ecx],ebx
  1125.   ret
  1126. endp
  1127.  
  1128. if defined Kolibri_debug_string
  1129. Kolibri_debug_string:
  1130.   db 'Abnormal program termination.',10,0
  1131. end if
  1132.  
  1133. if defined Kolibri_MutexLockRec
  1134. Kolibri_try_lock_rec_overflow_string:
  1135.   db 'Recursive mutex lock count overflow.',10,0
  1136. end if
  1137.  
  1138. if defined @Kolibri@UnLock$qp16Kolibri@TRecMutexui
  1139. Kolibri_unlock_rec_notlocked_string:
  1140.   db 'Recursive mutex unlock error.',10,0
  1141. end if
  1142.  
  1143. include "kos_lib.inc"
  1144.  
  1145. ;/**/
  1146.  
  1147.