Subversion Repositories Kolibri OS

Rev

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

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