Subversion Repositories Kolibri OS

Rev

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

  1. //CODED by Veliant, Leency, Nable. GNU GPL licence.
  2. #ifndef INCLUDE_KOLIBRI_H
  3. #define INCLUDE_KOLIBRI_H
  4. #print "[include <kolibri.h>]\n"
  5.  
  6. #pragma option OST
  7. #pragma option ON
  8. #pragma option cri-
  9. #pragma option -CPA
  10. #initallvar 0
  11. #jumptomain FALSE
  12.  
  13. #startaddress 0
  14.  
  15. #code32 TRUE
  16.  
  17. char   os_name[8]   = {'M','E','N','U','E','T','0','1'};
  18. dword  os_version   = 0x00000001;
  19. dword  start_addr   = #______INIT______;
  20. dword  final_addr   = #______STOP______+32;
  21. dword  alloc_mem    = MEMSIZE;
  22. dword  x86esp_reg   = MEMSIZE;
  23. dword  I_Param      = #param;
  24. dword  I_Path       = #program_path;
  25. char param[4096];
  26. char program_path[4096];
  27.  
  28. #define NULL      0
  29. #define OLD      -1
  30. #define true      1
  31. #define false     0
  32.  
  33. //Events
  34.  
  35. #define evReDraw  1
  36. #define evKey     2
  37. #define evButton  3
  38. #define evDesktop 5
  39. #define evMouse   6
  40. #define evIPC     7
  41. #define evNetwork 8
  42. #define evDebug   9
  43.  
  44. #define EVENT_MOUSE case 6: mouse.get();
  45.  
  46. //Button options
  47. #define BT_DEL      0x80000000
  48. #define BT_HIDE     0x40000000
  49. #define BT_NOFRAME  0x20000000
  50.  
  51. //ASCII KEYS
  52. #define ASCII_KEY_BS    008
  53. #define ASCII_KEY_TAB   009
  54. #define ASCII_KEY_ENTER 013
  55. #define ASCII_KEY_ESC   027
  56. #define ASCII_KEY_DEL   182
  57. #define ASCII_KEY_INS   185
  58. #define ASCII_KEY_SPACE 032
  59.  
  60. #define ASCII_KEY_LEFT  176
  61. #define ASCII_KEY_RIGHT 179
  62. #define ASCII_KEY_DOWN  177
  63. #define ASCII_KEY_UP    178
  64. #define ASCII_KEY_HOME  180
  65. #define ASCII_KEY_END   181
  66. #define ASCII_KEY_PGDN  183
  67. #define ASCII_KEY_PGUP  184
  68.  
  69. //allow event mask
  70. #define EVENT_MASK_REDRAW   000000001b
  71. #define EVENT_MASK_KEYBOARD 000000010b
  72. #define EVENT_MASK_BUTTONS  000000100b
  73. #define EVENT_MASK_DESKTOP  000010000b
  74. #define EVENT_MASK_MOUSE    000100000b
  75. #define EVENT_MASK_IPC      001000000b
  76. #define EVENT_MASK_NETWORK  010000000b
  77. #define EVENT_MASK_DEBUG    100000000b
  78.  
  79. //ARGS FUNCTION
  80. #define END_ARGS 0xFF00FF
  81. //-------------------------------------------------------------------------
  82.  
  83. #ifndef INCLUDE_SYSTEM_H
  84. #include "../lib/system.h"
  85. #endif
  86.  
  87. #ifndef INCLUDE_MOUSE_H
  88. #include "../lib/mouse.h"
  89. #endif
  90.  
  91. :struct raw_image {
  92.         dword w, h, data;
  93. };
  94.  
  95.  
  96.  
  97. //------------------------------------------------------------------------------
  98. :dword wait_event_code;
  99. inline fastcall dword WaitEvent()
  100. {
  101.         $mov eax,10
  102.         $int 0x40
  103.         wait_event_code = EAX;
  104.         //if(wait_event_code==evMouse) MOUSE.get();
  105.         //return wait_event_code;
  106. }
  107.  
  108. inline fastcall dword CheckEvent()
  109. {
  110.         $mov eax,11
  111.         $int 0x40
  112. }
  113.  
  114. inline fastcall dword WaitEventTimeout(EBX)
  115. {
  116.         $mov eax,23
  117.         $int 0x40
  118. }
  119.  
  120. inline fastcall SetEventMask(EBX)
  121. {
  122.         $mov eax,40
  123.         $int 0x40
  124. }
  125.  
  126. inline fastcall ScancodesGeting(){
  127.         $mov eax,66
  128.         $mov ebx,1
  129.         $mov ecx,1 //᪠­ª®¤ë
  130.         $int 0x40
  131. }
  132.  
  133. inline fastcall word GetKey()  //+Gluk fix
  134. {
  135.                 $push edx
  136. GETKEY:
  137.                 $mov  eax,2
  138.                 $int  0x40
  139.                 $cmp eax,1
  140.                 $jne GETKEYI
  141.                 $mov ah,dh
  142.                 $jmp GETKEYII //jz?
  143. GETKEYI:
  144.                 $mov dh,ah
  145.                 $jmp GETKEY
  146. GETKEYII:
  147.                 $pop edx
  148.                 $shr eax,8
  149. }
  150.  
  151. inline fastcall int GetFullKey()
  152. {
  153.         $mov  eax,2
  154.         $int  0x40
  155. }
  156.  
  157.  
  158. inline fastcall pause(EBX)
  159. {
  160.         $mov eax, 5
  161.         $int 0x40
  162. }
  163.  
  164. inline fastcall word GetButtonID()
  165. {
  166.         $mov eax,17
  167.         $int  0x40
  168.         $shr eax,8
  169. }
  170.  
  171. inline fastcall dword GetFreeRAM()
  172. {
  173.         $mov eax, 18
  174.         $mov ebx, 16
  175.         $int 0x40
  176.         //return eax = ðàçìåð ñâîáîäíîé ïàìÿòè â êèëîáàéòàõ
  177. }
  178.  
  179. inline void draw_line(dword x1,y1,x2,y2,color)
  180. {
  181.         x2--;y2--;y1--;
  182.         $mov EAX,38
  183.         EBX = x1<<16;
  184.         EBX |= x2;
  185.         ECX = y1<<16;
  186.         ECX |= y2;
  187.         $mov EDX,color
  188.         $int 0x40
  189. }
  190.  
  191. inline fastcall dword LoadDriver(ECX) //ECX - èìÿ äðàéâåðà
  192. {
  193.         $mov eax, 68
  194.         $mov ebx, 16
  195.         $int 0x40
  196.         //return 0 - íåóäà÷à, èíà÷å eax = õýíäë äðàéâåðà
  197. }
  198.  
  199. inline fastcall dword RuleDriver(ECX) //óêàçàòåëü íà óïðàâëÿþùóþ ñòðóêòóðó
  200. {
  201.         $mov eax, 68
  202.         $mov ebx, 17
  203.         $int 0x40
  204.         //return eax = îïðåäåëÿåòñÿ äðàéâåðîì
  205. }
  206.  
  207. struct proc_info
  208. {
  209.         #define SelfInfo -1
  210.         dword   use_cpu;
  211.         word    pos_in_stack,num_slot,rezerv1;
  212.         unsigned char name[11];
  213.         char    rezerv2;
  214.         dword   adress,use_memory,ID,left,top,width,height;
  215.         word    status_slot,rezerv3;
  216.         dword   work_left,work_top,work_width,work_height;
  217.         char    status_window;
  218.         dword   cwidth,cheight;
  219.         byte    reserved[1024-71-8];
  220. };
  221.  
  222. inline fastcall void GetProcessInfo(EBX, ECX)
  223. {
  224.         $mov eax,9;
  225.         $int  0x40
  226.         DSDWORD[EBX+71] = DSDWORD[EBX+42] - 9; //set cwidth
  227.         DSDWORD[EBX+75] = DSDWORD[EBX+46] - GetSkinHeight() - 4; //set cheight
  228. }
  229.  
  230. inline fastcall int GetPointOwner( EBX, ECX) //ebx=m.x, ecx=m.y
  231. {
  232.         $mov eax,34
  233.         $int 0x40
  234. }
  235.  
  236. inline fastcall int GetProcessSlot( ECX)
  237. {
  238.         EAX = 18;
  239.         EBX = 21;
  240.         $int 0x40
  241. }
  242.  
  243. inline fastcall int GetActiveProcess()
  244. {
  245.         EAX = 18;
  246.         EBX = 7;
  247.         $int 0x40
  248. }
  249.  
  250. :int CheckActiveProcess(int Form_ID)
  251. {
  252.         int id9=GetProcessSlot(Form_ID);
  253.         if (id9==GetActiveProcess()) return 1;
  254.         return 0;
  255. }
  256.  
  257. inline fastcall void ActivateWindow( ECX)
  258. {
  259.         EAX = 18;
  260.         EBX = 3;
  261.         $int 0x40
  262. }
  263.  
  264. inline fastcall int MinimizeWindow()
  265. {
  266.         EAX = 18;
  267.         EBX = 10;
  268.         $int 0x40
  269. }
  270.  
  271. inline fastcall int CreateThread(ECX,EDX)
  272. {
  273.         $mov eax,51
  274.         $mov ebx,1
  275.         $int 0x40
  276. }
  277.  
  278. inline fastcall void SwitchToAnotherThread()
  279. {
  280.         $mov eax,68
  281.         $mov ebx,1
  282.         $int 0x40
  283. }
  284.  
  285. inline fastcall int SendWindowMessage( ECX, EDX)
  286. {
  287.         $mov eax, 72
  288.         $mov ebx, 1
  289.         $int 0x40
  290. }
  291.  
  292. inline fastcall int KillProcess( ECX)
  293. {
  294.         $mov eax,18;
  295.         $mov ebx,18;
  296.         $int 0x40
  297. }
  298.  
  299. #define TURN_OFF 2
  300. #define REBOOT 3
  301. #define KERNEL 4
  302. inline fastcall int ExitSystem( ECX)
  303. {
  304.         $mov eax, 18
  305.         $mov ebx, 9
  306.         $int 0x40
  307. }
  308.  
  309. inline fastcall ExitProcess()
  310. {
  311.         $mov eax,-1;
  312.         $int 0x40
  313. }
  314.  
  315. //------------------------------------------------------------------------------
  316.  
  317. //eax = ÿçûê ñèñòåìû (1=eng, 2=fi, 3=ger, 4=rus)
  318. inline fastcall int GetSystemLanguage()
  319. {
  320.         EAX = 26;
  321.         EBX = 5;
  322.         $int 0x40
  323. }
  324.  
  325. inline fastcall GetSkinHeight()
  326. {
  327.         $push ebx
  328.         $mov  eax,48
  329.         $mov  ebx,4
  330.         $int 0x40
  331.         $pop  ebx
  332. }
  333.  
  334. inline fastcall void SetSystemSkin( ECX)
  335. {
  336.         EAX = 48;
  337.         EBX = 8;
  338.         $int 0x40
  339. }
  340.  
  341. inline fastcall int GetScreenWidth()
  342. {
  343.         $mov eax, 14
  344.         $int 0x40
  345.         $shr eax, 16
  346. }
  347.  
  348. inline fastcall int GetScreenHeight()
  349. {
  350.         $mov eax, 14
  351.         $int 0x40
  352.         $and eax,0x0000FFFF
  353. }
  354.  
  355. inline fastcall int GetClientTop()
  356. {
  357.         $mov eax, 48
  358.         $mov ebx, 5
  359.         $int 0x40
  360.     $mov eax, ebx
  361.     $shr eax, 16
  362. }
  363.  
  364. inline fastcall int GetClientHeight()
  365. {
  366.         $mov eax, 48
  367.         $mov ebx, 5
  368.         $int 0x40
  369.     $mov eax, ebx
  370. }
  371.  
  372.  
  373. inline fastcall dword LoadLibrary( ECX)
  374. {
  375.         $mov eax, 68
  376.         $mov ebx, 19
  377.         $int  0x40
  378. }
  379.  
  380. inline fastcall int TestBit( EAX, CL)
  381. {
  382.         $shr eax,cl
  383.         $and eax,1
  384. }
  385.  
  386. inline fastcall int PlaySpeaker( ESI)
  387. {
  388.         $mov eax, 55
  389.         $mov ebx, 55
  390.         $int 0x40
  391. }
  392.  
  393. inline fastcall void debugln( EDX)
  394. {
  395.         $push eax
  396.         $push ebx
  397.         $push ecx
  398.         $mov eax, 63
  399.         $mov ebx, 1
  400. NEXT_CHAR:
  401.         $mov ecx, DSDWORD[edx]
  402.         $or      cl, cl
  403.         $jz  DONE
  404.         $int 0x40
  405.         $inc edx
  406.         $jmp NEXT_CHAR
  407. DONE:
  408.         $mov cl, 13
  409.         $int 0x40
  410.         $mov cl, 10
  411.         $int 0x40
  412.         $pop ecx
  413.         $pop ebx
  414.         $pop eax
  415. }
  416.  
  417. inline fastcall void debug( EDX)
  418. {
  419.         $push eax
  420.         $push ebx
  421.         $push ecx
  422.         $mov eax, 63
  423.         $mov ebx, 1
  424. NEXT_CHAR:
  425.         $mov ecx, DSDWORD[edx]
  426.         $or      cl, cl
  427.         $jz  DONE
  428.         $int 0x40
  429.         $inc edx
  430.         $jmp NEXT_CHAR
  431. DONE:
  432.         $pop ecx
  433.         $pop ebx
  434.         $pop eax
  435. }
  436.  
  437.  
  438. inline fastcall void debugch( ECX)
  439. {
  440.         $push eax
  441.         $push ebx
  442.         $mov eax,63
  443.         $mov ebx,1
  444.         $int 0x40
  445.         $pop ebx
  446.         $pop eax
  447. }
  448. //------------------------------------------------------------------------------
  449.  
  450. void DefineAndDrawWindow(dword x, y, size_w, size_h, byte WindowType,dword WindowAreaColor, EDI, ESI)
  451. {
  452.         EAX = 12;              // function 12:tell os about windowdraw
  453.         EBX = 1;
  454.         $int 0x40
  455.        
  456.         $xor EAX,EAX
  457.         EBX = x << 16 + size_w;
  458.         ECX = y << 16 + size_h;
  459.  
  460.         EDX = WindowType << 24 | WindowAreaColor;
  461.         $int 0x40
  462.  
  463.         EAX = 12;              // function 12:tell os about windowdraw
  464.         EBX = 2;
  465.         $int 0x40
  466. }
  467.  
  468. inline fastcall MoveSize( EBX,ECX,EDX,ESI)
  469. {
  470.         $mov eax, 67
  471.         $int 0x40
  472. }
  473.  
  474. inline fastcall void DrawTitle( ECX)
  475. {
  476.         EAX = 71;
  477.         EBX = 1;
  478.         $int 0x40;
  479. }
  480.  
  481. void WriteTextB(dword x,y,byte fontType, dword color, EDX)
  482. {
  483.         EAX = 4;
  484.         EBX = x<<16+y;
  485.         ECX = fontType<<24+color;
  486.         ESI = 0;
  487.         $int 0x40;
  488.         $add ebx, 1<<16
  489.         $int 0x40
  490. }
  491.  
  492. void WriteText(dword x,y,byte fontType, dword color, EDX)
  493. {
  494.         EAX = 4;
  495.         EBX = x<<16+y;
  496.         ECX = fontType<<24+color;
  497.         $int 0x40;
  498. }
  499.  
  500. dword WriteBufText(dword x,y,byte fontType, dword color, EDX, EDI)
  501. {
  502.         EAX = 4;
  503.         EBX = x<<16+y;
  504.         ECX = fontType<<24+color;
  505.         $int 0x40;
  506. }
  507.  
  508. void WriteNumber(dword x,y,byte fontType, dword color, count, ECX)
  509. {
  510.         EAX = 47;
  511.         EBX = count<<16;
  512.         EDX = x<<16+y;
  513.         ESI = fontType<<24+color;
  514.         $int 0x40;
  515. }
  516.  
  517. void CopyScreen(dword EBX, x, y, w, h)
  518. {
  519.   EAX = 36;
  520.   ECX = w << 16 + h;
  521.   EDX = x << 16 + y;
  522.   $int  0x40;
  523. }
  524.  
  525. :dword GetPixelColor(dword x, x_size, y)
  526. {
  527.         $mov eax, 35
  528.         EBX= y*x_size+x;
  529.         $int 0x40
  530. }
  531.  
  532.  
  533. void _PutImage(dword x,y, w,h, EBX)
  534. {
  535.         EAX = 7;
  536.         ECX = w<<16+h;
  537.         EDX = x<<16+y;
  538.         $int 0x40
  539. }
  540.  
  541. void PutPaletteImage(dword EBX,w,h,x,y,ESI,EDI)
  542. {
  543.         EAX = 65;
  544.         ECX = w<<16+h;
  545.         EDX = x<<16+y;
  546.         EBP = 0;
  547.         $int 0x40
  548. }
  549.  
  550. inline fastcall void PutPixel( EBX,ECX,EDX)
  551. {
  552.   EAX=1;
  553.   $int 0x40
  554. }
  555.  
  556. void DrawBar(dword x,y,w,h,EDX)
  557. {
  558.         if (h<=0) || (h>60000) || (w<=0) || (w>60000) return; //bad boy :)
  559.         EAX = 13;
  560.         EBX = x<<16+w;
  561.         ECX = y<<16+h;
  562.         $int 0x40
  563. }
  564.  
  565. void DefineButton(dword x,y,w,h,EDX,ESI)
  566. {
  567.         EAX = 8;
  568.         $push edx
  569.         EDX += BT_DEL;
  570.         $int 0x40;
  571.         $pop edx
  572.         EBX = x<<16+w;
  573.         ECX = y<<16+h;
  574.         $int 0x40
  575. }
  576.  
  577. inline RefreshWindow(dword ID_REFRESH,ID_ACTIVE)
  578. {
  579.         EAX = 18;
  580.         EBX = 22;
  581.         ECX = 3;
  582.         EDX = ID_REFRESH;
  583.         $int 0x40
  584.         EAX = 18;
  585.         EBX = 3;
  586.         EDX = ID_ACTIVE;
  587.         $int 0x40
  588. }
  589.  
  590. inline getIPC(ECX,EDX)
  591. {
  592.         $mov EAX,60
  593.         $mov EBX,2
  594.         $int 0x40
  595. }
  596.  
  597. inline sendIPC(ECX,EDX,ESI)
  598. {
  599.         $mov EAX,60
  600.         $mov EBX,1
  601.         $int 0x40
  602. }
  603.  
  604. void UnsafeDefineButton(dword x,y,w,h,EDX,ESI)
  605. {
  606.         EAX = 8;
  607.         EBX = x<<16+w;
  608.         ECX = y<<16+h;
  609.         $int 0x40
  610. }
  611.  
  612. inline fastcall void DeleteButton( EDX)
  613. {
  614.         EAX = 8;
  615.         EDX += BT_DEL;
  616.         $int 0x40
  617. }
  618.  
  619. inline fastcall dword GetStartTime()
  620. {
  621.         $mov eax,26
  622.         $mov ebx,9
  623.         $int 0x40
  624. }
  625.  
  626. :dword X_EventRedrawWindow,Y_EventRedrawWindow;
  627. :void _EventRedrawWindow()
  628. {
  629.         loop()switch(WaitEvent())
  630.         {
  631.                 case evReDraw:
  632.                         DefineAndDrawWindow(X_EventRedrawWindow,Y_EventRedrawWindow,100,1,1,0x34,0xFFFFFF,"");
  633.                         pause(10);
  634.                         ExitProcess();
  635.                         break;
  636.         }
  637. }
  638. :void EventRedrawWindow(dword x,y)
  639. {
  640.         dword mem = malloc(4096);
  641.         X_EventRedrawWindow = x;
  642.         Y_EventRedrawWindow = y;
  643.         CreateThread(#_EventRedrawWindow,mem+4092);
  644. }
  645.  
  646. :dword ALERT_TEXT;
  647. :void dialog_alert()
  648. {
  649.         byte id;
  650.         loop()switch(WaitEvent())
  651.         {
  652.                 case evReDraw:
  653.                         DefineAndDrawWindow(215,100,250,200,0x34,0xFFFFFF,"Alert");
  654.                         WriteTextB(5,5,0x90,0x0,ALERT_TEXT);
  655.                 break;
  656.                 case evKey:
  657.                 case evButton:
  658.                         id=GetButtonID();
  659.                         if (id==1) ExitProcess();
  660.                 break;
  661.         }
  662. }
  663. :dword alert(dword text)
  664. {
  665.         dword mem = malloc(4096);
  666.         ALERT_TEXT = text;
  667.         CreateThread(#dialog_alert,mem+4092);
  668.         return mem;
  669. }
  670.  
  671. :struct _screen
  672. {
  673.         dword width,height;
  674. } screen;
  675.  
  676. :struct _skin
  677. {
  678.         dword width,height;
  679. } SKIN;
  680.  
  681. :void DrawDate(dword x, y, color, in_date)
  682. {
  683.         //char text[15];
  684.         EDI = in_date;
  685.         EAX = 47;
  686.         EBX = 2<<16;
  687.         EDX = x<<16+y;
  688.         ESI = 0x80<<24+color;
  689.         ECX = EDI.date.day;
  690.         $int 0x40;
  691.         EDX += 18<<16;
  692.         ECX = EDI.date.month;
  693.         $int 0x40;
  694.         EDX += 18<<16;
  695.         EBX = 4<<16;
  696.         ECX = EDI.date.year;
  697.         $int 0x40;
  698.         PutPixel(x+14,y+6,color);
  699.         PutPixel(x+32,y+6,color);
  700.         //sprintf(#text,"%d",EDI.date.year);
  701.         //WriteText(x, y, 0x80, 0x000000, #text);
  702. }
  703.  
  704. :void __path_name__(dword BUF,PATH)
  705. {
  706.         dword beg = PATH;
  707.         dword pos = PATH;
  708.         dword sav = PATH;
  709.         dword i;
  710.         while(DSBYTE[pos])
  711.         {
  712.                 if(DSBYTE[pos]=='/')sav = pos;
  713.                 pos++;
  714.         }
  715.         i = sav-beg;
  716.         while(i)
  717.         {
  718.                 DSBYTE[BUF] = DSBYTE[beg];
  719.                 beg++;
  720.                 BUF++;
  721.                 i--;
  722.         }
  723.         /*while(DSBYTE[beg])
  724.         {
  725.                 DSBYTE[BUF1] = DSBYTE[beg];
  726.                 beg++;
  727.                 BUF1++;
  728.         }*/
  729.         //DSBYTE[BUF1] = 0;
  730.         DSBYTE[BUF] = 0;
  731. }
  732. char __BUF_DIR__[4096];
  733. :struct SELF
  734. {
  735.         dword dir;
  736.         dword file;
  737.         dword path;
  738. } self;
  739.  
  740. dword __generator;  // random number generator - äëÿ ãåíåðàöèè ñëó÷àéíûõ ÷èñåë
  741.  
  742. :dword program_path_length;
  743.  
  744. //The initialization of the initial data before running
  745. void ______INIT______()
  746. {
  747.         self.dir = #__BUF_DIR__;
  748.         self.file = 0;
  749.         self.path = I_Path;
  750.         __path_name__(#__BUF_DIR__,I_Path);
  751.        
  752.         SKIN.height   = GetSkinHeight();
  753.         screen.width  = GetScreenWidth();
  754.         screen.height = GetScreenHeight();
  755.        
  756.         //program_path_length = strlen(I_Path);
  757.         MOUSE_TIME = 50; //Default 500 ms.
  758.         __generator = GetStartTime();
  759.        
  760.         $push    ebx
  761.         $mov     eax, 68
  762.         $mov     ebx, 11
  763.         $int     0x40
  764.        
  765.         $pop     ebx
  766.  
  767.         main();
  768. }
  769. ______STOP______:
  770. #endif