Subversion Repositories Kolibri OS

Rev

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