Subversion Repositories Kolibri OS

Rev

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

  1. {cp866}
  2.  
  3. { User interface }
  4. procedure kos_definewindow(x, y, w, h: Word; style, header, clframe: DWord); assembler; register;
  5. asm
  6.   pushl %ebx
  7.   pushl %ecx
  8.   pushl %edx
  9.   pushl %esi
  10.   pushl %edi
  11.   movl  %eax, %ebx
  12.   xchgl %edx, %ecx
  13.   movl  header, %esi
  14.   shll  $16, %ebx
  15.   shll  $16, %ecx
  16.   movl  clframe, %edi
  17.   movw  %dx, %bx
  18.   movw  h, %cx
  19.   xorl  %eax, %eax
  20.   movl  style, %edx
  21.   decl  %ebx  {㬥­ìè¨âì è¨à¨­ã ­  1}
  22.   decl  %ecx  {㬥­ìè¨âì ¢ëá®âã ­  1}
  23.   int   $0x40
  24.   popl %edi
  25.   popl %esi
  26.   popl %edx
  27.   popl %ecx
  28.   popl %ebx
  29. end;
  30.  
  31. procedure kos_movewindow(x, y, w, h: DWord); assembler; register;
  32. asm
  33.   pushl %eax
  34.   pushl %ebx
  35.   pushl %ecx
  36.   pushl %edx
  37.   pushl %esi
  38.   movl  %eax, %ebx
  39.   xchgl %ecx, %edx
  40.   movl  $67, %eax
  41.   movl  h, %esi
  42.   decl  %edx  {㬥­ìè¨âì è¨à¨­ã ­  1}
  43.   decl  %esi  {㬥­ìè¨âì ¢ëá®âã ­  1}
  44.   int   $0x40
  45.   popl  %esi
  46.   popl  %edx
  47.   popl  %ecx
  48.   popl  %ebx
  49.   popl  %eax
  50. end;
  51.  
  52. function kos_getkey(): DWord; assembler; register;
  53. asm
  54.   movl $2, %eax
  55.   int  $0x40
  56. end;
  57.  
  58. function kos_getevent(wait: Boolean = True): DWord; assembler; register;
  59. asm
  60.   andl $1, %eax
  61.   xorb $1, %al
  62.   addl $10, %eax
  63.   int  $0x40
  64. end;
  65.  
  66. function kos_waitevent(timeout: DWord): DWord; assembler; register;
  67. asm
  68.   pushl %ebx
  69.   movl  $23, %ebx
  70.   xchgl %eax, %ebx
  71.   int  $0x40
  72.   popl  %ebx
  73. end;
  74.  
  75. function kos_getbutton(): DWord; assembler; register;
  76. asm
  77.   movl  $17, %eax
  78.   int   $0x40
  79.   shrl  $8, %eax
  80.   andl  $0xFF, %eax
  81. end;
  82.  
  83. function kos_getmousepos(): TKosPoint; assembler; register;
  84. {@return: x*65536 + y}
  85. asm
  86.   pushl %eax
  87.   pushl %ebx
  88.   pushl %ecx
  89.   pushl %eax
  90.   movl  $37, %eax
  91.   xorl  %ebx, %ebx
  92.   int   $0x40
  93.   movswl %ax, %ecx
  94.   popl  %ebx
  95.   shrl  $16, %eax
  96.   movl  %ecx, TKosPoint.Y(%ebx)
  97.   movl  %eax, TKosPoint.X(%ebx)
  98.   popl  %ecx
  99.   popl  %ebx
  100.   popl  %eax
  101. end;
  102.  
  103. function kos_getmousewinpos(): TKosPoint; assembler; register;
  104. {@return: x*65536 + y}
  105. asm
  106.   pushl %eax
  107.   pushl %ebx
  108.   pushl %ecx
  109.   pushl %eax
  110.   movl  $37, %eax
  111.   movl  $1, %ebx
  112.   int   $0x40
  113.   movswl %ax, %ecx
  114.   popl  %ebx
  115.   shrl  $16, %eax
  116.   movl  %ecx, TKosPoint.Y(%ebx)
  117.   movl  %eax, TKosPoint.X(%ebx)
  118.   popl  %ecx
  119.   popl  %ebx
  120.   popl  %eax
  121. end;
  122.  
  123. function kos_getmousebuttons(): DWord; assembler; register;
  124. {@return:
  125.   ¡¨â 0 ãáâ ­®¢«¥­ = «¥¢ ï ª­®¯ª  ­ ¦ â 
  126.   ¡¨â 1 ãáâ ­®¢«¥­ = ¯à ¢ ï ª­®¯ª  ­ ¦ â 
  127.   ¡¨â 2 ãáâ ­®¢«¥­ = á।­ïï ª­®¯ª  ­ ¦ â 
  128.   ¡¨â 3 ãáâ ­®¢«¥­ = 4-ï ª­®¯ª  ­ ¦ â 
  129.   ¡¨â 4 ãáâ ­®¢«¥­ = 5-ï ª­®¯ª  ­ ¦ â }
  130. asm
  131.   pushl %ebx
  132.   movl  $37, %eax
  133.   movl  $2, %ebx
  134.   int   $0x40
  135.   popl  %ebx
  136. end;
  137.  
  138. procedure kos_maskevents(mask: DWord); assembler; register;
  139. asm
  140.   pushl %ebx
  141.   xchgl %eax, %ebx
  142.   movl  $40, %eax
  143.   int   $0x40
  144.   xchgl %eax, %ebx
  145.   popl  %ebx
  146. end;
  147.  
  148. procedure kos_setcaption(caption: PChar); assembler; register;
  149. asm
  150.   pushl %ecx
  151.   pushl %ebx
  152.   xchgl %eax, %ecx
  153.   movl $1, %ebx
  154.   movl $71, %eax
  155.   int  $0x40
  156.   xchgl %eax, %ecx
  157.   popl %ebx
  158.   popl %ecx
  159. end;
  160.  
  161.  
  162. { Graphics }
  163.  
  164. procedure kos_begindraw(); assembler; register;
  165. asm
  166.   pushl %ebx
  167.   movl  $12, %eax
  168.   movl  $1, %ebx
  169.   int   $0x40
  170.   popl  %ebx
  171. end;
  172.  
  173. procedure kos_enddraw(); assembler; register;
  174. asm
  175.   pushl %ebx
  176.   movl  $12, %eax
  177.   movl  $2, %ebx
  178.   int   $0x40
  179.   popl  %ebx
  180. end;
  181.  
  182. procedure kos_putpixel(x, y: Word; color: DWord); assembler; register;
  183. asm
  184.   pushl %ebx
  185.   movl  %eax, %ebx
  186.   xchgl %edx, %ecx
  187.   movl  $1, %eax
  188.   int   $0x40
  189.   xchgl %edx, %ecx
  190.   popl  %ebx
  191. end;
  192.  
  193. procedure kos_drawtext(x, y: Word; text: String; flags, bgcolor: DWord); assembler; register;
  194. label nobg;
  195. asm
  196.   pusha
  197.   shll  $16, %eax
  198.   pushl %ecx
  199.   movl  flags, %ecx  {ä« £¨, 梥â}
  200.   movl  bgcolor, %edi
  201.   movw  %dx, %ax
  202.   andl   $0x7FFFFFFF, %ecx
  203.   btl   $31, %edi
  204.   jnc   nobg
  205.   orl   $0x40000000, %ecx
  206. nobg:
  207.   popl  %edx
  208.   movl  %eax, %ebx    {ª®®à¤¨­ âë}
  209.   movzbl (%edx), %esi {¤«¨­  áâப¨}
  210.   movl  $4, %eax      {­®¬¥à ä㭪樨}
  211.   incl  %edx          {㪠§ â¥«ì ­  áâபã}
  212.   andl  $0xFFFFFF, %edi
  213.   int   $0x40
  214.   popa
  215. end;
  216.  
  217. procedure kos_drawrect(x, y, w, h: Word; color: DWord); assembler; register;
  218. asm
  219.   pushl %eax
  220.   pushl %ebx
  221.   pushl %ecx
  222.   pushl %edx
  223.   movl  %eax, %ebx
  224.   xchgl %edx, %ecx
  225.   shll  $16, %ebx
  226.   shll  $16, %ecx
  227.   movl  $13, %eax
  228.   movw  %dx, %bx
  229.   movw  h, %cx
  230.   movl  color, %edx
  231.   int   $0x40
  232.   popl %edx
  233.   popl %ecx
  234.   popl %ebx
  235.   popl %eax
  236. end;
  237.  
  238. procedure kos_drawline(x1, y1, x2, y2: Word; color: DWord = $000000); assembler; register;
  239. asm
  240.   pushl %eax
  241.   pushl %ebx
  242.   pushl %ecx
  243.   pushl %edx
  244.  
  245.   xchgl %eax, %ecx
  246.   xchgl %ecx, %edx
  247.   movl  color, %ebx
  248.   {eax - x2, ebx - color, ecx - y1, edx - x1}
  249.   shll  $16, %ecx
  250.   shll  $16, %edx
  251.   movw  %ax, %dx
  252.   movw  y2, %cx
  253.   movl  $38, %eax
  254.   xchgl %ebx, %edx
  255.   int   $0x40
  256.  
  257.   popl  %edx
  258.   popl  %ecx
  259.   popl  %ebx
  260.   popl  %eax
  261. end;
  262.  
  263. procedure kos_drawimage(x, y, w, h, depth: DWord; image: Pointer; palette: Pointer; xoffset: DWord); assembler; register;
  264. asm
  265.   pusha
  266.   shll  $16, %eax
  267.   shll  $16, %ecx
  268.   orl   %eax, %edx
  269.   orl   h, %ecx
  270.   movl  depth, %esi
  271.   movl  image, %ebx
  272.   movl  palette, %edi
  273.   movl  xoffset, %ebp
  274.   movl  $65, %eax
  275.   int   $0x40
  276.   popa
  277. end;
  278.  
  279. procedure kos_drawimage24(x, y, w, h: DWord; image: Pointer); assembler; register;
  280. asm
  281.   pushl %eax
  282.   pushl %ebx
  283.   pushl %ecx
  284.   pushl %edx
  285.   shll  $16, %eax
  286.   shll  $16, %ecx
  287.   orl   %eax, %edx
  288.   orl   h, %ecx
  289.   movl  image, %ebx
  290.   movl  $7, %eax
  291.   int   $0x40
  292.   popl  %edx
  293.   popl  %ecx
  294.   popl  %ebx
  295.   popl  %eax
  296. end;
  297.  
  298.  
  299. { Work with system }
  300.  
  301. { Work with system - System services }
  302.  
  303. function kos_killthread(tid: TThreadID): Boolean; assembler; register;
  304. asm
  305.   pushl %ecx
  306.   pushl %ebx
  307.   movl  $18, %ecx
  308.   movl  $18, %ebx
  309.   xchgl %eax, %ecx
  310.   int   $0x40
  311.   andl  $1, %eax
  312.   popl  %ebx
  313.   popl  %ecx
  314.   xorb  $1, %al
  315. end;
  316.  
  317. procedure kos_setactivewindow(slot: TThreadSlot); assembler; register;
  318. asm
  319.   pushl %ecx
  320.   pushl %ebx
  321.   movl  $18, %ecx
  322.   movl  $3, %ebx
  323.   xchgl %eax, %ecx
  324.   int   $0x40
  325.   xchgl %eax, %ecx
  326.   popl  %ebx
  327.   popl  %ecx
  328. end;
  329.  
  330. {$ifdef EMULATOR}
  331. function kos_getthreadslot(tid: TThreadID): TThreadSlot;
  332. var
  333.   ThreadInfo: TKosThreadInfo;
  334.   HighThreadSlot: TThreadSlot;
  335. begin
  336.   Result := 0;
  337.   repeat
  338.     Inc(Result);
  339.     HighThreadSlot := kos_threadinfo(@ThreadInfo, Result);
  340.   until (Result > HighThreadSlot) or (ThreadInfo.ThreadID = tid);
  341. end;
  342.  
  343. {$else}
  344.  
  345. function kos_getthreadslot(tid: TThreadID): TThreadSlot; assembler; register;
  346. asm
  347.   pushl %ecx
  348.   pushl %ebx
  349.   movl  $18, %ecx
  350.   movl  $21, %ebx
  351.   xchgl %eax, %ecx
  352.   int   $0x40
  353.   popl  %ebx
  354.   popl  %ecx
  355. end;
  356. {$endif}
  357.  
  358. { Work with system - Set system parameters }
  359.  
  360. procedure kos_enablepci(); assembler; register;
  361. asm
  362.   pushl %eax
  363.   pushl %ebx
  364.   pushl %ecx
  365.   movl  $21, %eax
  366.   movl  $12, %ebx
  367.   movl  $1, %ecx
  368.   int   $0x40
  369.   popl  %ecx
  370.   popl  %ebx
  371.   popl  %eax
  372. end;
  373.  
  374. { Work with system - Internal system services }
  375.  
  376. procedure kos_switchthread(); assembler; register;
  377. asm
  378.   pushl %eax
  379.   pushl %ebx
  380.   movl  $68, %eax
  381.   movl  $1, %ebx
  382.   int   $0x40
  383.   popl  %ebx
  384.   popl  %eax
  385. end;
  386.  
  387. function kos_initheap(): DWord; assembler; register;
  388. asm
  389.   pushl %ebx
  390.   movl  $68, %eax
  391.   movl  $11, %ebx
  392.   int   $0x40
  393.   popl  %ebx
  394. end;
  395.  
  396. function kos_alloc(size: DWord): Pointer; assembler; register;
  397. asm
  398.   pushl %ebx
  399.   pushl %ecx
  400.   movl  %eax, %ecx
  401.   movl  $68, %eax
  402.   movl  $12, %ebx
  403.   int   $0x40
  404.   popl  %ecx
  405.   popl  %ebx
  406. end;
  407.  
  408. function kos_free(ptr: Pointer): Boolean; assembler; register;
  409. asm
  410.   pushl %ebx
  411.   pushl %ecx
  412.   movl  %eax, %ecx
  413.   movl  $68, %eax
  414.   movl  $13, %ebx
  415.   int   $0x40
  416.   popl  %ecx
  417.   popl  %ebx
  418. end;
  419.  
  420. function kos_loaddriver(name: PChar): THandle; assembler; register;
  421. asm
  422.   pushl %ebx
  423.   pushl %ecx
  424.   movl  %eax, %ecx
  425.   movl  $68, %eax
  426.   movl  $16, %ebx
  427.   int   $0x40
  428.   popl  %ecx
  429.   popl  %ebx
  430. end;
  431.  
  432.  
  433. { Processes and threads }
  434.  
  435. function kos_threadinfo(info: PKosThreadInfo; slot: TThreadSlot): DWord; assembler; register;
  436. asm
  437.   pushl %ebx
  438.   movl  %eax, %ebx
  439.   xchgl %edx, %ecx
  440.   movl  $9, %eax
  441.   int   $0x40
  442.   xchgl %edx, %ecx
  443.   popl  %ebx
  444. end;
  445.  
  446. function kos_newthread(entry, stack: Pointer): TThreadID; assembler; register;
  447. asm
  448.   pushl %ebx
  449.   pushl %ecx
  450.   movl  $1, %ebx
  451.   movl  %eax, %ecx
  452.   movl  $51, %eax
  453.   int   $0x40
  454.   popl  %ecx
  455.   popl  %ebx
  456. end;
  457.  
  458. procedure kos_initipc(ipc: PKosIPC; size: DWord); assembler; register;
  459. asm
  460.   pushl %ebx
  461.   pushl %ecx
  462.   movl  $60, %ecx
  463.   movl  $1, %ebx
  464.   xchgl %eax, %ecx
  465.   int   $0x40
  466.   popl  %ecx
  467.   popl  %ebx
  468. end;
  469.  
  470. function kos_sendmsg(tid: TThreadID; msg: Pointer; size: DWord): DWord; assembler; register;
  471. {@return:
  472.   0 - ãᯥ譮
  473.   1 - ¯à¨ñ¬­¨ª ­¥ ®¯à¥¤¥«¨« ¡ãä¥à ¤«ï IPC-á®®¡é¥­¨©
  474.       (¬®¦¥â ¡ëâì, ¥éñ ­¥ ãᯥ«,   ¬®¦¥â ¡ëâì, íâ® ­¥ â®â ¯®â®ª, ª®â®àë© ­ã¦¥­)
  475.   2 - ¯à¨ñ¬­¨ª § ¡«®ª¨à®¢ « IPC-¡ãä¥à; ¯®¯à®¡ã©â¥ ­¥¬­®£® ¯®¤®¦¤ âì
  476.   3 - ¯¥à¥¯®«­¥­¨¥ IPC-¡ãä¥à  ¯à¨ñ¬­¨ª 
  477.   4 - ¯à®æ¥áá /¯®â®ª  á â ª¨¬ PID ­¥ áãé¥áâ¢ã¥â}
  478. asm
  479.   pushl %esi
  480.   pushl %ebx
  481.   movl  $60, %esi
  482.   movl  $2, %ebx
  483.   xchgl %ecx, %esi
  484.   xchgl %eax, %ecx
  485.   int   $0x40
  486.   xchgl %ecx, %esi
  487.   popl  %ebx
  488.   popl  %esi
  489. end;
  490.  
  491. function kos_resizemem(size: DWord): Boolean; assembler; register;
  492. asm
  493.   pushl %ebx
  494.   pushl %ecx
  495.   movl  %eax, %ecx
  496.   movl  $64, %eax
  497.   movl  $1, %ebx
  498.   int   $0x40
  499.   xorb  $1, %al
  500.   popl  %ecx
  501.   popl  %ebx
  502. end;
  503.  
  504.  
  505. { File system }
  506. { File system - Work with the current folder }
  507.  
  508. procedure kos_setdir(path: PChar); assembler; register;
  509. asm
  510.   pushl %ecx
  511.   pushl %ebx
  512.   movl  $30, %ecx
  513.   movl  $1, %ebx
  514.   xchgl %eax, %ecx
  515.   int   $0x40
  516.   popl  %ebx
  517.   popl  %ecx
  518. end;
  519.  
  520. function kos_getdir(path: PChar; size: DWord): DWord; assembler; register;
  521. asm
  522.   pushl %ecx
  523.   pushl %ebx
  524.   movl  $30, %ecx
  525.   movl  $2, %ebx
  526.   xchgl %eax, %ecx
  527.   int   $0x40
  528.   popl  %ebx
  529.   popl  %ecx
  530. end;
  531.  
  532. { File system - Work with file system with long names support }
  533.  
  534. function kos_readfile(kosfile: PKosFile; var readed: Longint): DWord; assembler; register;
  535. asm
  536.   pushl %ebx
  537.   movl  $70, %ebx
  538.   xchgl %eax, %ebx
  539.   movl  $0, (%ebx)
  540.   int   $0x40
  541.   movl  %ebx, (%edx)
  542.   popl  %ebx
  543. end;
  544.  
  545. function kos_rewritefile(kosfile: PKosFile; var writed: Longint): DWord; assembler; register;
  546. asm
  547.   pushl %ebx
  548.   movl  $70, %ebx
  549.   xchgl %eax, %ebx
  550.   movl  $2, (%ebx)
  551.   int   $0x40
  552.   movl  %ebx, (%edx)
  553.   popl  %ebx
  554. end;
  555.  
  556. function kos_writefile(kosfile: PKosFile; var writed: Longint): DWord; assembler; register;
  557. asm
  558.   pushl %ebx
  559.   movl  $70, %ebx
  560.   xchgl %eax, %ebx
  561.   movl  $3, (%ebx)
  562.   int   $0x40
  563.   movl  %ebx, (%edx)
  564.   popl  %ebx
  565. end;
  566.  
  567. function kos_fileinfo(kosfile: PKosFile): DWord; assembler; register;
  568. asm
  569.   pushl %ebx
  570.   movl  $70, %ebx
  571.   xchgl %eax, %ebx
  572.   movl  $5, (%ebx)
  573.   int   $0x40
  574.   popl  %ebx
  575. end;
  576.  
  577.  
  578. { Work with hardware }
  579.  
  580. function kos_readport(index: DWord): DWord; assembler; register;
  581. label ok, exit;
  582. asm
  583.   pushl %ecx
  584.   pushl %ebx
  585.   xchgl %eax, %ecx         {index}
  586.   movl  $43, %eax
  587.   orl   $0x80000000, %ecx  {index}
  588.   int   $0x40
  589.   orl   %eax, %eax
  590.   jzl   ok
  591.   movl  $-1, %eax
  592.   jmp   exit
  593. ok:
  594.   movl  %ebx, %eax
  595. exit:
  596.   popl  %ebx
  597.   popl  %ecx
  598. end;
  599.  
  600. procedure kos_writeport(index, value: DWord); assembler; register;
  601. asm
  602.   pushl %eax
  603.   pushl %ebx
  604.   pushl %ecx
  605.   xchgl %edx, %ebx  {value}
  606.   xchgl %eax, %ecx  {index}
  607.   movl  $43, %eax
  608.   int   $0x40
  609.   xchgl %edx, %ebx
  610.   popl  %ecx
  611.   popl  %ebx
  612.   popl  %eax
  613. end;
  614.  
  615. function kos_reserveport(port: DWord): Boolean; assembler; register;
  616. asm
  617.   pushl %ebx
  618.   pushl %ecx
  619.   pushl %edx
  620.   movl  %eax, %ecx  {port}
  621.   movl  $46, %eax
  622.   movl  %ecx, %edx  {port}
  623.   xorl  %ebx, %ebx
  624.   int   $0x40
  625.   xorb  $1, %al
  626.   popl  %edx
  627.   popl  %ecx
  628.   popl  %ebx
  629. end;
  630.  
  631. { Work with hardware - Low-level access to PCI}
  632.  
  633. function kos_lastpcibus(): Byte; assembler; register;
  634. asm
  635.   pushl %ebx
  636.   movl  $62, %eax
  637.   movl  $1, %ebx
  638.   int   $0x40
  639.   popl  %ebx
  640. end;
  641.  
  642. function kos_readpcib(bus, dev, func, reg: Byte): Byte; assembler; register;
  643. asm
  644.   pushl %ebx
  645.   pushl %ecx
  646.   pushl %edx
  647.   shlb  $3, %dl   {dev}
  648.   movb  %al, %bh  {bus}
  649.   shlw  $8, %cx   {func}
  650.   movb  $4, %bl
  651.   movb  reg, %cl  {func}
  652.   andb  $7, %ch   {func}
  653.   movl  $62, %eax
  654.   orb   %dl, %ch  {dev/func}
  655.   int   $0x40
  656.   popl  %edx
  657.   popl  %ecx
  658.   popl  %ebx
  659. end;
  660.  
  661. function kos_readpciw(bus, dev, func, reg: Byte): Word; assembler; register;
  662. asm
  663.   pushl %ebx
  664.   pushl %ecx
  665.   pushl %edx
  666.   shlb  $3, %dl   {dev}
  667.   movb  %al, %bh  {bus}
  668.   shlw  $8, %cx   {func}
  669.   movb  $5, %bl
  670.   movb  reg, %cl  {reg}
  671.   andb  $7, %ch   {func}
  672.   movl  $62, %eax
  673.   orb   %dl, %ch  {dev/func}
  674.   int   $0x40
  675.   popl  %edx
  676.   popl  %ecx
  677.   popl  %ebx
  678. end;
  679.  
  680. function kos_readpcid(bus, dev, func, reg: Byte): DWord; assembler; register;
  681. asm
  682.   pushl %ebx
  683.   pushl %ecx
  684.   pushl %edx
  685.   shlb  $3, %dl   {dev}
  686.   movb  %al, %bh  {bus}
  687.   shlw  $8, %cx   {func}
  688.   movb  $6, %bl
  689.   movb  reg, %cl  {reg}
  690.   andb  $7, %ch   {func}
  691.   movl  $62, %eax
  692.   orb   %dl, %ch  {dev/func}
  693.   int   $0x40
  694.   popl  %edx
  695.   popl  %ecx
  696.   popl  %ebx
  697. end;
  698.  
  699.  
  700. { Other }
  701. procedure kos_delay(ms: DWord); assembler; register;
  702. asm
  703.   pushl %ebx
  704.   movl  %eax, %ebx
  705.   movl  $5, %eax
  706.   int   $0x40
  707.   popl  %ebx
  708. end;
  709.