Subversion Repositories Kolibri OS

Rev

Rev 8165 | Rev 8196 | 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.   mov  eax,SF_REDRAW
  376.   mov  ebx,SSF_BEGIN_DRAW
  377.   int  0x40
  378.   test dl,2
  379.   jz   .redraw_picture
  380.   mov  eax,SF_STYLE_SETTINGS
  381.   mov  ebx,SSF_GET_SKIN_HEIGHT
  382.   int  0x40
  383.   mov  ebx,[ebp+KOLIBRI_THREAD_DATA_X*4]
  384.   add  ebx,2*5-1
  385.   mov  ecx,[ebp+KOLIBRI_THREAD_DATA_Y*4]
  386.   add  cx,ax
  387.   add  ecx,5-1
  388.   mov  edx,[ebp+KOLIBRI_THREAD_DATA_C_WINDOW*4]
  389.   mov  edi,[ebp+KOLIBRI_THREAD_DATA_TITLE*4]
  390.   xor  eax,eax
  391.   int  0x40
  392. .redraw_picture:
  393.   call  @@KolibriOnPaint$qv
  394. .redraw_end_draw:
  395.   mov  eax,SF_REDRAW
  396.   mov  ebx,SSF_END_DRAW
  397.   int  0x40
  398.   pop  edi esi ebx ebp
  399.   ret
  400. endp
  401.  
  402. proc @Kolibri@MoveWindow$qxpxi uses ebx esi
  403.   mov  eax,[esp+12]
  404.   mov  ebx,[eax]
  405.   mov  ecx,[eax+4]
  406.   mov  edx,[eax+8]
  407.   mov  esi,[eax+12]
  408.   mov  eax,SF_CHANGE_WINDOW
  409.   int  0x40
  410.   ret
  411. endp
  412.  
  413. proc @Kolibri@ExitDebug$qv
  414.   push dword [@Kolibri@DebugPrefix]
  415.   call @Kolibri@DebugPutString$qpxc
  416.   mov   dword [esp],Kolibri_debug_string
  417.   call @Kolibri@DebugPutString$qpxc
  418.   pop   ecx
  419.   jmp  @Kolibri@ExitProcess$qv
  420. endp
  421.  
  422. proc @Kolibri@ExitProcess$qv
  423.   lock bts dword [@Kolibri@_ExitProcessNow],0
  424.   jc   .exit_process_wait
  425.   sub  esp,1024
  426.   mov  eax,SF_THREAD_INFO
  427.   mov  ebx,esp
  428.   mov  ecx,-1
  429.   int  0x40
  430.   mov  esi,eax
  431.   mov  edi,[esp+30]
  432. .exit_process_loop:
  433.   mov  eax,SF_THREAD_INFO
  434.   mov  ebx,esp
  435.   mov  ecx,esi
  436.   int  0x40
  437.   mov  eax,[esp+30]
  438.   cmp  eax,edi
  439.   jz   .exit_process_continue
  440.   mov  ebx,eax
  441.   or   bl,15
  442.   inc  ebx
  443.   jz   .exit_process_continue
  444.   mov  ebx,eax
  445.   call Kolibri_HashInt
  446.   movzx eax,al
  447.   mov  eax,dword [@Kolibri@_ThreadTable+eax*4]
  448.   jmp  .exit_process_test
  449. .exit_process_next:
  450.   mov  eax,dword [eax+KOLIBRI_THREAD_DATA_NEXT*4]
  451. .exit_process_test:
  452.   test eax,eax
  453.   jz   .exit_process_continue
  454.   cmp  ebx,[eax+KOLIBRI_THREAD_DATA_PID*4]
  455.   jnz  .exit_process_next
  456.   mov  eax,SF_SYSTEM
  457.   mov  ebx,SSF_TERMINATE_THREAD
  458.   mov  ecx,esi
  459.   int  0x40
  460. .exit_process_continue:
  461.   dec  esi
  462.   jnl  .exit_process_loop
  463.   add  esp,1024
  464.   mov  dword [@Kolibri@_ExitProcessNow],-1
  465. if defined EMULATOR
  466.   int3
  467.   call 0x76543210
  468. end if
  469. .exit_process_end:
  470.   mov  dword [@Kolibri@_ThreadMutex],0
  471.   or   eax,-1
  472.   int  0x40
  473. .exit_process_wait:
  474.   mov  eax,SF_SLEEP
  475.   mov  ebx,1
  476. .exit_process_wait_loop:
  477.   cmp  dword [@Kolibri@_ExitProcessNow],0
  478.   jl   .exit_process_end
  479.   int  0x40
  480.   shl  ebx,1
  481.   cmp  ebx,KOLIBRI_MUTEX_MAX_TIME_WAIT
  482.   jna  .exit_process_wait_loop
  483.   mov  ebx,KOLIBRI_MUTEX_MAX_TIME_WAIT
  484.   jmp  .exit_process_wait_loop
  485. endp
  486.  
  487. proc @Kolibri@ExitThread$qppv,@Kolibri@ThreadMain$qpvt1
  488.   mov  esp,[esp+4]
  489.   jmp  Kolibri_main_end
  490. endp
  491.  
  492. proc @Kolibri@ReturnMessageLoop$qppv,@Kolibri@ThreadMain$qpvt1
  493.   mov  esp,[esp+4]
  494.   bt   dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],30
  495.   jc   Kolibri_main_end
  496.   jmp  Kolibri_main_cycle
  497. endp
  498.  
  499. proc @Kolibri@Delay$qui uses ebx
  500.   mov  eax,SF_SLEEP
  501.   mov  ebx,[esp+8]
  502.   int  0x40
  503.   ret
  504. endp
  505.  
  506. proc @Kolibri@Clock$qv uses ebx
  507.   mov  eax,SF_SYSTEM_GET
  508.   mov  ebx,SSF_TIME_COUNT
  509.   int  0x40
  510.   ret
  511. endp
  512.  
  513. proc @Kolibri@DrawButton$qllllll uses ebx esi
  514.   mov  eax,SF_DEFINE_BUTTON
  515.   mov  ebx,[esp+12-2+8]
  516.   mov  bx,[esp+20+8]
  517.   mov  ecx,[esp+16-2+8]
  518.   mov  cx,[esp+24+8]
  519.   mov  edx,[esp+4+8]
  520.   mov  esi,[esp+8+8]
  521.   int  0x40
  522.   ret
  523. endp
  524.  
  525. proc @Kolibri@GetPackedTime$qv
  526.   mov  eax,SF_GET_SYS_TIME
  527.   int  0x40
  528.   ret
  529. endp
  530.  
  531. proc @Kolibri@GetTime$qpi
  532.   mov  eax,SF_GET_SYS_TIME
  533.   int  0x40
  534.   mov  edx,[esp+4]
  535.   movzx ecx,al
  536.   shr  ecx,4
  537.   and  al,0x0F
  538.   imul ecx,10
  539.   add  cl,al
  540.   mov  dword [edx+8],ecx
  541.   mov  cl,ah
  542.   shr  ecx,4
  543.   and  ah,0x0F
  544.   imul ecx,10
  545.   add  cl,ah
  546.   mov  dword [edx+4],ecx
  547.   bswap eax
  548.   mov  cl,ah
  549.   shr  ecx,4
  550.   and  ah,0x0F
  551.   imul ecx,10
  552.   add  cl,ah
  553.   mov  dword [edx],ecx
  554.   ret
  555. endp
  556.  
  557. proc @Kolibri@GetPackedDate$qv
  558.   mov  eax,SF_GET_SYS_DATE
  559.   int  0x40
  560.   ret
  561. endp
  562.  
  563. proc @Kolibri@GetDate$qpi
  564.   mov  eax,SF_GET_SYS_DATE
  565.   int  0x40
  566.   mov  edx,[esp+4]
  567.   movzx ecx,al
  568.   shr  ecx,4
  569.   and  al,0x0F
  570.   imul ecx,10
  571.   add  cl,al
  572.   mov  dword [edx+4],ecx
  573.   mov  cl,ah
  574.   shr  ecx,4
  575.   and  ah,0x0F
  576.   imul ecx,10
  577.   add  cl,ah
  578.   mov  dword [edx],ecx
  579.   bswap eax
  580.   mov  cl,ah
  581.   shr  ecx,4
  582.   and  ah,0x0F
  583.   imul ecx,10
  584.   add  cl,ah
  585.   mov  dword [edx+8],ecx
  586.   ret
  587. endp
  588.  
  589. proc @Kolibri@ReadCommonColors$qpui uses ebx
  590.   mov  eax,SF_STYLE_SETTINGS
  591.   mov  ebx,SSF_GET_COLORS
  592.   mov  ecx,[esp+8]
  593.   mov  edx,40
  594.   int  0x40
  595.   ret
  596. endp
  597.  
  598. proc @Kolibri@DrawText$qssipxc uses ebx
  599.   mov  eax,SF_DRAW_TEXT
  600.   mov  ebx,[esp+8-2]
  601.   mov  bx,[esp+12]
  602.   mov  ecx,[esp+16]
  603.   or   ecx,0x80000000
  604.   mov  edx,[esp+20]
  605.   int  0x40
  606.   ret
  607. endp
  608.  
  609. proc @Kolibri@SetWindowCaption$qpxc uses ebx
  610.   mov  eax,SF_SET_CAPTION
  611.   mov  ebx,2
  612.   mov  ecx,[esp+8]
  613.   int  0x40
  614.   ret
  615. endp
  616.  
  617. proc @Kolibri@GetProcessInfo$qpuipct1t1piui uses ebx esi edi
  618.   sub  esp,1024
  619.   mov  eax,SF_THREAD_INFO
  620.   mov  ebx,esp
  621.   mov  ecx,[1024+12+24+esp]
  622.   int  0x40
  623.   xor  edi,edi
  624.   or   edi,[1024+12+4+esp]
  625.   jz   .get_proc_info_no_usecpu
  626.   mov  ecx,[esp]
  627.   mov  [edi],ecx
  628.   xor  edi,edi
  629. .get_proc_info_no_usecpu:
  630.   or   edi,[1024+12+8+esp]
  631.   jz   .get_proc_info_no_name
  632.   lea  esi,[esp+10]
  633.   cld
  634.   movsd
  635.   movsd
  636.   movsd
  637.   mov  byte [edi],0
  638.   xor  edi,edi
  639. .get_proc_info_no_name:
  640.   or   edi,[1024+12+12+esp]
  641.   jz   .get_proc_info_no_mem
  642.   mov  ecx,[esp+26]
  643.   mov  [edi],ecx
  644.   xor  edi,edi
  645. .get_proc_info_no_mem:
  646.   or   edi,[1024+12+16+esp]
  647.   jz   .get_proc_info_no_pid
  648.   mov  ecx,[esp+30]
  649.   mov  [edi],ecx
  650.   xor  edi,edi
  651. .get_proc_info_no_pid:
  652.   or   edi,[1024+12+20+esp]
  653.   jz   .get_proc_info_no_rect
  654.   lea  esi,[esp+34]
  655.   cld
  656.   movsd
  657.   movsd
  658.   movsd
  659.   movsd
  660.   xor  edi,edi
  661. .get_proc_info_no_rect:
  662.   add  esp,1024
  663.   ret
  664. endp
  665.  
  666. proc @Kolibri@GetPid$qv uses ebx
  667.   sub  esp,1024
  668.   mov  eax,SF_THREAD_INFO
  669.   mov  ebx,esp
  670.   mov  ecx,-1
  671.   int  0x40
  672.   mov  eax,[esp+30]
  673.   add  esp,1024
  674.   ret
  675. endp
  676.  
  677. proc @Kolibri@GetPid$qppv
  678.   mov  ecx,[esp+4]
  679.   mov  eax,[ecx+KOLIBRI_THREAD_DATA_PID*4]
  680.   ret
  681. endp
  682.  
  683. proc @Kolibri@_HashByte$qui
  684. @Kolibri@_HashWord$qui:
  685. @Kolibri@_HashDword$qui:
  686.   mov  eax,[esp+4]
  687. Kolibri_HashInt:
  688.   mul  dword [Kolibri_hash_int_val0]
  689.   xor  eax,edx
  690.   bswap eax
  691.   mul  dword [Kolibri_hash_int_val1]
  692.   shrd eax,edx,14
  693.   bswap eax
  694.   lea  eax,[eax+4*eax]
  695.   ror  eax,9
  696.   ret
  697. endp
  698.  
  699. if defined @Kolibri@_HashByte$qui | defined @Kolibri@_HashWord$qui | defined @Kolibri@_HashDword$qui
  700. Kolibri_hash_int_val0:
  701.   dd   0xA82F94C5
  702. Kolibri_hash_int_val1:
  703.   dd   0x9193780B
  704. end if
  705.  
  706. proc @Kolibri@GetThreadData$qv
  707.   call @Kolibri@GetPid$qv
  708.   push eax
  709.   call @Kolibri@GetThreadData$qui
  710.   pop  ecx
  711.   ret
  712. endp
  713.  
  714. proc @Kolibri@GetThreadData$qui
  715.   mov  eax,[esp+4]
  716.   call Kolibri_HashInt
  717.   movzx eax,al
  718.   cmp  dword [@Kolibri@_ThreadScanCount+4],0
  719.   jnz  .get_thread_data_wait
  720. .get_thread_data_nowait:
  721.   lock inc dword [@Kolibri@_ThreadScanCount]
  722.   mov  eax,dword [@Kolibri@_ThreadTable+eax*4]
  723.   mov  ecx,[esp+4]
  724.   jmp  .get_thread_data_test
  725. .get_thread_data_loop:
  726.   mov  eax,dword [eax+KOLIBRI_THREAD_DATA_NEXT*4]
  727. .get_thread_data_test:
  728.   test eax,eax
  729.   jz   .get_thread_data_end
  730.   cmp  ecx,[eax+KOLIBRI_THREAD_DATA_PID*4]
  731.   jnz  .get_thread_data_loop
  732. .get_thread_data_end:
  733.   lock dec dword [@Kolibri@_ThreadScanCount]
  734.   ret
  735. .get_thread_data_wait:
  736.   push eax ebx
  737.   mov  eax,SF_SLEEP
  738.   mov  ebx,1
  739. .get_thread_data_wait_loop:
  740.   int  0x40
  741.   cmp  dword [@Kolibri@_ThreadScanCount+4],0
  742.   jz   .get_thread_data_wait_end
  743.   shl  ebx,1
  744.   cmp  ebx,KOLIBRI_MUTEX_MAX_TIME_WAIT
  745.   jna  .get_thread_data_wait_loop
  746.   mov  ebx,KOLIBRI_MUTEX_MAX_TIME_WAIT
  747.   jmp  .get_thread_data_wait_loop
  748. .get_thread_data_wait_end:
  749.   pop  ebx eax
  750.   jmp .get_thread_data_nowait
  751. endp
  752.  
  753. proc @Kolibri@_GetSkinHeader$qv uses ebx
  754.   mov  eax,SF_STYLE_SETTINGS
  755.   mov  ebx,SSF_GET_SKIN_HEIGHT
  756.   int  0x40
  757.   ret
  758. endp
  759.  
  760. proc @Kolibri@GetScreenSize$qrust1
  761.   mov  eax,SF_GET_SCREEN_SIZE
  762.   int  0x40
  763.   mov  ecx,[esp+8]
  764.   mov  word [ecx],ax
  765.   mov  ecx,[esp+4]
  766.   shr  eax,16
  767.   mov  word [ecx],ax
  768.   ret
  769. endp
  770.  
  771. proc Kolibri_MutexLockNoWait
  772.   pop  eax
  773.   xor  al,al
  774.   ret
  775. endp
  776.  
  777. proc Kolibri_MutexLockWait uses ebx
  778.   mov  eax,SF_SLEEP
  779.   xor  ebx,ebx
  780. .lock_wait_cycle:
  781.   int  0x40
  782.   shl  byte [ecx],1
  783.   jz   .lock_wait_cycle
  784.   mov  al,1
  785.   ret
  786. endp
  787.  
  788. proc Kolibri_MutexLockWaitTime
  789.   cmp  dword [esp+12],0
  790.   jng  .MutexLockWait
  791.   push ebx edx
  792.   mov  edx,[esp+20]
  793.   mov  eax,SF_SYSTEM_GET
  794.   mov  ebx,SSF_TIME_COUNT
  795.   int  0x40
  796.   add  edx,eax
  797. .lock_wait_time_cycle:
  798.   mov  eax,SF_SLEEP
  799.   xor  ebx,ebx
  800.   int  0x40
  801.   shl  byte [ecx],1
  802.   jnz  .lock_wait_time_ret_true
  803.   mov  eax,SF_SYSTEM_GET
  804.   mov  ebx,SSF_TIME_COUNT
  805.   int  0x40
  806.   cmp  eax,edx
  807.   js   .lock_wait_time_cycle
  808.   pop  edx ebx eax
  809.   xor  al,al
  810.   ret
  811. .lock_wait_time_ret_true:
  812.   pop  edx ebx
  813.   mov  al,1
  814.   ret
  815. endp
  816.  
  817. proc Kolibri_MutexLock
  818.   shl  byte [ecx],1
  819.   jnz  .lock_first
  820.   call eax
  821. .lock_first:
  822.   mov  al,1
  823.   ret
  824. endp
  825.  
  826. proc @Kolibri@TryLock$qp14Kolibri@TMutex
  827.   mov  eax,Kolibri_MutexLockNoWait
  828.   mov  ecx,[esp+4]
  829.   jmp  Kolibri_MutexLock
  830. endp
  831.  
  832. proc @Kolibri@Lock$qp14Kolibri@TMutex
  833.   mov  eax,Kolibri_MutexLockWait
  834.   mov  ecx,[esp+4]
  835.   jmp  Kolibri_MutexLock
  836. endp
  837.  
  838. proc @Kolibri@LockTime$qp14Kolibri@TMutexi
  839.   mov  eax,Kolibri_MutexLockWaitTime
  840.   mov  ecx,[esp+4]
  841.   jmp  Kolibri_MutexLock
  842. endp
  843.  
  844. proc @Kolibri@UnLock$qp14Kolibri@TMutex
  845.   mov  ecx,[esp+4]
  846.   shr  byte [ecx],1
  847.   jz   .unlock_pause
  848.   ret
  849. .unlock_pause:
  850.   mov  byte [ecx],0x40
  851.   push ebx
  852.   mov  eax,SF_SLEEP
  853.   xor  ebx,ebx
  854.   int  0x40
  855.   pop  ebx
  856.   ret
  857. endp
  858.  
  859. proc Kolibri_MutexLockRec
  860.   shl  byte [ecx],1
  861.   jng  .lock_first
  862.   cmp  dword [ecx+4],edx
  863.   jz   .lock_rec_self
  864.   call eax
  865. .lock_rec_first:
  866.   mov  al,1
  867.   mov  dword [ecx+4],edx
  868.   ret
  869. .lock_rec_self:
  870.   mov  al,1
  871.   add  dword [ecx],0x100
  872.   jc   .lock_rec_overflow
  873.   ret
  874. .lock_rec_overflow:
  875.   push dword [@Kolibri@DebugPrefix]
  876.   call @Kolibri@DebugPutString$qpxc
  877.   mov  dword [esp],Kolibri_try_lock_rec_overflow_string
  878.   call @Kolibri@DebugPutString$qpxc
  879.   pop  ecx
  880.   jmp  @Kolibri@ExitDebug$qv
  881. endp
  882.  
  883. proc @Kolibri@TryLock$qp16Kolibri@TRecMutexui
  884.   mov  eax,Kolibri_MutexLockNoWait
  885.   mov  ecx,[esp+4]
  886.   mov  edx,[esp+8]
  887.   jmp  Kolibri_MutexLockRec
  888. endp
  889.  
  890. proc @Kolibri@Lock$qp16Kolibri@TRecMutexui
  891.   mov  eax,Kolibri_MutexLockWait
  892.   mov  ecx,[esp+4]
  893.   mov  edx,[esp+8]
  894.   jmp  Kolibri_MutexLockRec
  895. endp
  896.  
  897. proc @Kolibri@LockTime$qp16Kolibri@TRecMutexiui
  898.   mov  eax,Kolibri_MutexLockWaitTime
  899.   mov  ecx,[esp+4]
  900.   mov  edx,[esp+12]
  901.   jmp  Kolibri_MutexLockRec
  902. endp
  903.  
  904. proc @Kolibri@UnLock$qp16Kolibri@TRecMutexui
  905.   mov  ecx,[esp+4]
  906.   mov  edx,[esp+8]
  907.   cmp  dword [ecx+4],edx
  908.   jnz  .unlock_rec_notlocked
  909.   sub  dword [ecx],0x100
  910.   jnc  .unlock_rec_end
  911.   add dword [ecx],0x100
  912.   shl byte [ecx],1
  913.   shr byte [ecx],2
  914.   jng  .unlock_rec_pause
  915. .unlock_rec_end:
  916.   ret
  917. .unlock_rec_pause:
  918.   mov  byte [ecx],0x20
  919.   push ebx
  920.   mov  eax,SF_SLEEP
  921.   xor  ebx,ebx
  922.   int  0x40
  923.   pop  ebx
  924.   ret
  925. .unlock_rec_notlocked:
  926.   push dword [@Kolibri@DebugPrefix]
  927.   call @Kolibri@DebugPutString$qpxc
  928.   mov  dword [esp],Kolibri_unlock_rec_notlocked_string
  929.   call @Kolibri@DebugPutString$qpxc
  930.   pop  ecx
  931.   jmp  @Kolibri@ExitDebug$qv
  932. endp
  933.  
  934. proc @Kolibri@DebugPutChar$qc
  935.   mov  cl,byte [esp+4]
  936.   cmp  cl,13
  937.   jz   .debug_put_char_ret
  938.   push ebx
  939.   cmp  cl,10
  940.   jz   .debug_put_char_enter
  941. .debug_put_char_after_cmp:
  942.   mov  eax,SF_BOARD
  943.   mov  ebx,SSF_DEBUG_WRITE
  944.   int  0x40
  945.   pop  ebx
  946. .debug_put_char_ret:
  947.   ret
  948. .debug_put_char_enter:
  949.   mov  cl,13
  950.   mov  eax,SF_BOARD
  951.   mov  ebx,SSF_DEBUG_WRITE
  952.   int  0x40
  953.   mov  cl,10
  954.   jmp  .debug_put_char_after_cmp
  955. endp
  956.  
  957. proc @Kolibri@DebugPutString$qpxc uses esi
  958.   push dword 0
  959.   mov  esi,dword [esp+12]
  960.   jmp  .debug_put_string_test
  961. .debug_put_string_loop:
  962.   mov  dword [esp],eax
  963.   call @Kolibri@DebugPutChar$qc
  964.   inc  esi
  965. .debug_put_string_test:
  966.   xor  eax,eax
  967.   or   al,[esi]
  968.   test al,al
  969.   jnz  .debug_put_string_loop
  970.   pop  ecx
  971.   ret
  972. endp
  973.  
  974. proc @Kolibri@GetKey$qv
  975.   mov  eax,SF_GET_KEY
  976.   int  0x40
  977.   test al,al
  978.   jnz  .get_key_eof
  979.   movzx eax,ah
  980.   ret
  981. .get_key_eof:
  982.   mov  eax,SF_TERMINATE_PROCESS
  983.   ret
  984. endp
  985.  
  986. proc @Kolibri@GetMouseButton$qv uses ebx
  987.   mov  eax,SF_MOUSE_GET
  988.   mov  ebx,SSF_BUTTON
  989.   int  0x40
  990.   ret
  991. endp
  992.  
  993. proc @Kolibri@GetMousePosition$qrst1o uses ebx
  994.   mov  eax,SF_MOUSE_GET
  995.   xor  ebx,ebx ;SSF_SCREEN_POSITION
  996.   cmp  byte [esp+16],0
  997.   jnz  .get_mouse_pos_absolute
  998.   inc  ebx
  999. .get_mouse_pos_absolute:
  1000.   int  0x40
  1001.   mov  ecx,[esp+12]
  1002.   mov  word [ecx],ax
  1003.   mov  ecx,[esp+8]
  1004.   shr  eax,16
  1005.   mov  word [ecx],ax
  1006.   ret
  1007. endp
  1008.  
  1009. proc @Kolibri@WasThreadCreated$qv
  1010.   cmp  byte [@Kolibri@_ThreadSavedBegProc],0x90
  1011.   setz al
  1012.   ret
  1013. endp
  1014.  
  1015. proc @Kolibri@CreateThread$qpvuit1
  1016.   push ebx
  1017.   mov  edx,[esp+16]
  1018.   mov  ebx,[esp+12]
  1019.   test edx,edx
  1020.   jnz  .create_thread_after_new
  1021. if defined KolibriHeapAlloc
  1022.   cmp  ebx,4096
  1023.   jnb  .create_thread_alloc
  1024.   mov  ebx,STACKSIZE
  1025. .create_thread_alloc:
  1026.   push ebx
  1027.   call KolibriHeapAlloc  ; Create new dynamic memory of the given size
  1028.   pop  ecx
  1029.   test eax,eax
  1030.   jnz  .create_thread_mem_created
  1031. end if
  1032.   or   eax,-1
  1033.   jmp  .create_thread_end
  1034. .create_thread_mem_created:
  1035.   lea  edx,[eax+ebx]
  1036. .create_thread_after_new:
  1037.   neg  ebx
  1038.   jz   .create_thread_test_first
  1039.   add  ebx,edx
  1040. .create_thread_test_first:
  1041.   cmp  byte [@Kolibri@_ThreadSavedBegProc],0x90
  1042.   jnz  .create_thread_init
  1043. .create_thread_fill_stack:
  1044.   lock inc dword [@Kolibri@_ThreadNumber]
  1045.   and  edx,not 3
  1046.   sub  edx,12
  1047.   mov  ecx,[esp+8]
  1048.   mov  dword [edx+8],ebx
  1049.   mov  dword [edx+4],ecx
  1050.   mov  dword [edx],Kolibri_ThreadFinish
  1051.   mov  eax,SF_CREATE_THREAD
  1052.   mov  ebx,1
  1053.   mov  ecx,@Kolibri@ThreadMain$qpvt1
  1054.   int  0x40
  1055.   mov  ebx,eax
  1056.   or   bl,15
  1057.   inc  ebx
  1058.   jnz  .create_thread_end
  1059.   lock dec dword [@Kolibri@_ThreadNumber]
  1060. if defined KolibriHeapFree
  1061.   or   ebx,[edx+8]
  1062.   jz   .create_thread_end
  1063.   push ebx
  1064.   call KolibriHeapFree  ; Delete the given dynamic memory
  1065.   pop  ecx
  1066. end if
  1067. .create_thread_end:
  1068.   pop  ebx
  1069.   ret
  1070. .create_thread_init:
  1071.   push esi edi
  1072.   cld
  1073.   mov  esi,@Kolibri@_ThreadSavedBegProc
  1074.   mov  edi,@Kolibri@GetPid$qv
  1075.   movsd
  1076.   movsd
  1077.   mov  edi,@Kolibri@GetThreadData$qv
  1078.   movsd
  1079.   movsd
  1080.   mov  eax,0x90909090
  1081.   mov  edi,@Kolibri@_ThreadSavedBegProc
  1082.   stosd
  1083.   stosd
  1084.   stosd
  1085.   stosd
  1086.   pop  edi esi
  1087.   jmp  .create_thread_fill_stack
  1088. endp
  1089.  
  1090. proc @Kolibri@_FileAccess$qp21Kolibri@FileInfoBlock uses ebx
  1091.   mov  eax,SF_FILE
  1092.   mov  ebx,[esp+8]
  1093.   int  0x40
  1094.   mov  ecx,[esp+8]
  1095.   mov  [ecx],ebx
  1096.   ret
  1097. endp
  1098.  
  1099. if defined Kolibri_debug_string
  1100. Kolibri_debug_string:
  1101.   db 'Abnormal program termination.',10,0
  1102. end if
  1103.  
  1104. if defined Kolibri_MutexLockRec
  1105. Kolibri_try_lock_rec_overflow_string:
  1106.   db 'Recursive mutex lock count overflow.',10,0
  1107. end if
  1108.  
  1109. if defined @Kolibri@UnLock$qp16Kolibri@TRecMutexui
  1110. Kolibri_unlock_rec_notlocked_string:
  1111.   db 'Recursive mutex unlock error.',10,0
  1112. end if
  1113.  
  1114. include "kos_lib.inc"
  1115.  
  1116. ;/**/
  1117.  
  1118.