Subversion Repositories Kolibri OS

Rev

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