Subversion Repositories Kolibri OS

Rev

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