Subversion Repositories Kolibri OS

Rev

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