Subversion Repositories Kolibri OS

Rev

Rev 6771 | Rev 6794 | 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      int
  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. //allow event mask
  52. #define EVENT_MASK_REDRAW   000000001b
  53. #define EVENT_MASK_KEYBOARD 000000010b
  54. #define EVENT_MASK_BUTTONS  000000100b
  55. #define EVENT_MASK_DESKTOP  000010000b
  56. #define EVENT_MASK_MOUSE    000100000b
  57. #define EVENT_MASK_IPC      001000000b
  58. #define EVENT_MASK_NETWORK  010000000b
  59. #define EVENT_MASK_DEBUG    100000000b
  60.  
  61. //-------------------------------------------------------------------------
  62.  
  63. #include "../lib/system.h"
  64. #include "../lib/mouse.h"
  65. #include "../lib/keyboard.h"
  66.  
  67. inline fastcall dword calc(EAX) { return EAX; }
  68.  
  69. :struct raw_image {
  70.         dword w, h, data;
  71. };
  72.  
  73. //------------------------------------------------------------------------------
  74. :dword wait_event_code;
  75. inline fastcall dword WaitEvent()
  76. {
  77.         $mov eax,10
  78.         $int 0x40
  79.         wait_event_code = EAX;
  80.         //if(wait_event_code==evMouse) MOUSE.get();
  81.         //return wait_event_code;
  82. }
  83.  
  84. inline fastcall dword CheckEvent()
  85. {
  86.         $mov eax,11
  87.         $int 0x40
  88. }
  89.  
  90. inline fastcall dword WaitEventTimeout(EBX)
  91. {
  92.         $mov eax,23
  93.         $int 0x40
  94. }
  95.  
  96. inline fastcall SetEventMask(EBX)
  97. {
  98.         $mov eax,40
  99.         $int 0x40
  100. }
  101.  
  102.  
  103. inline fastcall pause(EBX)
  104. {
  105.         $mov eax, 5
  106.         $int 0x40
  107. }
  108.  
  109. inline fastcall word GetButtonID()
  110. {
  111.         $mov eax,17
  112.         $int  0x40
  113.         $shr eax,8
  114. }
  115.  
  116. inline fastcall dword GetFreeRAM()
  117. {
  118.         $mov eax, 18
  119.         $mov ebx, 16
  120.         $int 0x40
  121.         //return eax = ðàçìåð ñâîáîäíîé ïàìÿòè â êèëîáàéòàõ
  122. }
  123.  
  124. inline fastcall dword LoadDriver(ECX) //ECX - èìÿ äðàéâåðà
  125. {
  126.         $mov eax, 68
  127.         $mov ebx, 16
  128.         $int 0x40
  129.         //return 0 - íåóäà÷à, èíà÷å eax = õýíäë äðàéâåðà
  130. }
  131.  
  132. inline fastcall dword RuleDriver(ECX) //óêàçàòåëü íà óïðàâëÿþùóþ ñòðóêòóðó
  133. {
  134.         $mov eax, 68
  135.         $mov ebx, 17
  136.         $int 0x40
  137.         //return eax = îïðåäåëÿåòñÿ äðàéâåðîì
  138. }
  139.  
  140. struct proc_info
  141. {
  142.         #define SelfInfo -1
  143.         dword   use_cpu;
  144.         word    pos_in_stack,num_slot,rezerv1;
  145.         unsigned char name[11];
  146.         char    rezerv2;
  147.         dword   adress,use_memory,ID,left,top,width,height;
  148.         word    status_slot,rezerv3;
  149.         dword   work_left,work_top,work_width,work_height;
  150.         char    status_window;
  151.         dword   cwidth,cheight;
  152.         byte    reserved[1024-71-8];
  153. };
  154.  
  155. inline fastcall void GetProcessInfo(EBX, ECX)
  156. {
  157.         $mov eax,9;
  158.         $int  0x40
  159.         DSDWORD[EBX+71] = DSDWORD[EBX+42] - 9; //set cwidth
  160.         DSDWORD[EBX+75] = DSDWORD[EBX+46] - GetSkinHeight() - 4; //set cheight
  161. }
  162.  
  163. inline fastcall int GetPointOwner( EBX, ECX) //ebx=m.x, ecx=m.y
  164. {
  165.         $mov eax,34
  166.         $int 0x40
  167. }
  168.  
  169. inline fastcall int GetProcessSlot( ECX)
  170. {
  171.         EAX = 18;
  172.         EBX = 21;
  173.         $int 0x40
  174. }
  175.  
  176. inline fastcall int GetActiveProcess()
  177. {
  178.         EAX = 18;
  179.         EBX = 7;
  180.         $int 0x40
  181. }
  182.  
  183. :int CheckActiveProcess(int Form_ID)
  184. {
  185.         int id9=GetProcessSlot(Form_ID);
  186.         if (id9==GetActiveProcess()) return 1;
  187.         return 0;
  188. }
  189.  
  190. inline fastcall void ActivateWindow( ECX)
  191. {
  192.         EAX = 18;
  193.         EBX = 3;
  194.         $int 0x40
  195. }
  196.  
  197. inline fastcall int MinimizeWindow()
  198. {
  199.         EAX = 18;
  200.         EBX = 10;
  201.         $int 0x40
  202. }
  203.  
  204. inline fastcall int CreateThread(ECX,EDX)
  205. {
  206.         $mov eax,51
  207.         $mov ebx,1
  208.         $int 0x40
  209. }
  210.  
  211. inline fastcall void SwitchToAnotherThread()
  212. {
  213.         $mov eax,68
  214.         $mov ebx,1
  215.         $int 0x40
  216. }
  217.  
  218. inline fastcall int SendWindowMessage( ECX, EDX)
  219. {
  220.         $mov eax, 72
  221.         $mov ebx, 1
  222.         $int 0x40
  223. }
  224.  
  225. inline fastcall int KillProcess( ECX)
  226. {
  227.         $mov eax,18;
  228.         $mov ebx,18;
  229.         $int 0x40
  230. }
  231.  
  232. #define TURN_OFF 2
  233. #define REBOOT 3
  234. #define KERNEL 4
  235. inline fastcall int ExitSystem( ECX)
  236. {
  237.         $mov eax, 18
  238.         $mov ebx, 9
  239.         $int 0x40
  240. }
  241.  
  242. inline fastcall ExitProcess()
  243. {
  244.         $mov eax,-1;
  245.         $int 0x40
  246. }
  247.  
  248. //------------------------------------------------------------------------------
  249.  
  250. inline fastcall void SetCurDir( ECX)
  251. {
  252.   EAX=30;
  253.   EBX=1;
  254.   $int 0x40
  255. }
  256.  
  257.  
  258. //eax = ÿçûê ñèñòåìû (1=eng, 2=fi, 3=ger, 4=rus)
  259. #define SYS_LANG_ENG 1
  260. #define SYS_LANG_FIN 2
  261. #define SYS_LANG_GER 3
  262. #define SYS_LANG_RUS 4
  263. inline fastcall int GetSystemLanguage()
  264. {
  265.         EAX = 26;
  266.         EBX = 5;
  267.         $int 0x40
  268. }
  269.  
  270. inline fastcall GetSkinHeight()
  271. {
  272.         $push ebx
  273.         $mov  eax,48
  274.         $mov  ebx,4
  275.         $int 0x40
  276.         $pop  ebx
  277. }
  278.  
  279. inline fastcall void SetSystemSkin( ECX)
  280. {
  281.         EAX = 48;
  282.         EBX = 8;
  283.         $int 0x40
  284. }
  285.  
  286. inline fastcall int GetScreenWidth()
  287. {
  288.         $mov eax, 14
  289.         $int 0x40
  290.         $shr eax, 16
  291. }
  292.  
  293. inline fastcall int GetScreenHeight()
  294. {
  295.         $mov eax, 14
  296.         $int 0x40
  297.         $and eax,0x0000FFFF
  298. }
  299.  
  300. inline fastcall int GetClientTop()
  301. {
  302.         $mov eax, 48
  303.         $mov ebx, 5
  304.         $int 0x40
  305.         $mov eax, ebx
  306.         $shr eax, 16
  307. }
  308.  
  309. inline fastcall int GetClientHeight()
  310. {
  311.         $mov eax, 48
  312.         $mov ebx, 5
  313.         $int 0x40
  314.         $mov eax, ebx
  315. }
  316.  
  317. inline fastcall dword LoadLibrary( ECX)
  318. {
  319.         $mov eax, 68
  320.         $mov ebx, 19
  321.         $int  0x40
  322. }
  323.  
  324. inline fastcall int TestBit( EAX, CL)
  325. {
  326.         $shr eax,cl
  327.         $and eax,1
  328. }
  329.  
  330. //------------------------------------------------------------------------------
  331.  
  332. :void DefineAndDrawWindow(dword _x, _y, _w, _h, _window_type, _bgcolor, _title, _flags)
  333. {
  334.         EAX = 12;              // function 12:tell os about windowdraw
  335.         EBX = 1;
  336.         $int 0x40
  337.        
  338.         $xor EAX,EAX
  339.         EBX = _x << 16 + _w;
  340.         ECX = _y << 16 + _h;
  341.         EDX = _window_type << 24 | _bgcolor;
  342.         EDI = _title;
  343.         ESI = _flags;
  344.         $int 0x40
  345.  
  346.  
  347.         EAX = 12;              // function 12:tell os about windowdraw
  348.         EBX = 2;
  349.         $int 0x40
  350. }
  351.  
  352. inline fastcall MoveSize( EBX,ECX,EDX,ESI)
  353. {
  354.         $mov eax, 67
  355.         $int 0x40
  356. }
  357.  
  358. inline fastcall void DrawTitle( ECX)
  359. {
  360.         EAX = 71;
  361.         EBX = 1;
  362.         $int 0x40;
  363. }
  364.  
  365. // @EDX is a procewss id, -1 for self
  366. // @ESI is a new LayerBehaviour
  367. // @RETURN: EAX, 0 is fail, 1 is success
  368. #define WINDOW_LAYER_ALWAYS_ON_TOP 1
  369. inline fastcall dword SetWindowLayerBehaviour(EDX, ESI)
  370. {
  371.         EAX = 18;
  372.         EBX = 25;
  373.         ECX = 2;
  374.         $int 64
  375. }
  376.  
  377. :void WriteTextB(dword x,y,byte fontType, dword color, str_offset)
  378. {
  379.         EAX = 4;
  380.         EBX = x<<16+y;
  381.         ECX = fontType<<24+color;
  382.         EDX = str_offset;
  383.         ESI = 0;
  384.         $int 0x40;
  385.         $add ebx, 1<<16
  386.         $int 0x40
  387. }
  388.  
  389. :void WriteText(dword x,y,byte fontType, dword color, str_offset)
  390. {
  391.         EAX = 4;
  392.         EBX = x<<16+y;
  393.         ECX = fontType<<24+color;
  394.         EDX = str_offset;
  395.         $int 0x40;
  396. }
  397.  
  398. :dword WriteBufText(dword x,y,byte fontType, dword color, str_offset, buf_offset)
  399. {
  400.         EAX = 4;
  401.         EBX = x<<16+y;
  402.         ECX = fontType<<24+color;
  403.         EDX = str_offset;
  404.         EDI = buf_offset;
  405.         $int 0x40;
  406. }
  407.  
  408. :void WriteNumber(dword x,y,byte fontType, dword color, count, number_or_offset)
  409. {
  410.         EAX = 47;
  411.         EBX = count<<16;
  412.         ECX = number_or_offset;
  413.         EDX = x<<16+y;
  414.         ESI = fontType<<24+color;
  415.         $int 0x40;
  416. }
  417.  
  418. :void CopyScreen(dword dst_offset, x, y, w, h)
  419. {
  420.   EAX = 36;
  421.   EBX = dst_offset;
  422.   ECX = w << 16 + h;
  423.   EDX = x << 16 + y;
  424.   $int  0x40;
  425. }
  426.  
  427. :dword GetPixelColorFromScreen(dword _x, _y)
  428. {
  429.         EAX = 35;
  430.         EBX = _y * screen.width + _x;
  431.         $int 64
  432. }
  433.  
  434. :void _PutImage(dword x,y, w,h, data_offset)
  435. {
  436.         EAX = 7;
  437.         EBX = data_offset;
  438.         ECX = w<<16+h;
  439.         EDX = x<<16+y;
  440.         $int 0x40
  441. }
  442.  
  443. void PutPaletteImage(dword EBX,w,h,x,y,ESI,EDI)
  444. {
  445.         EAX = 65;
  446.         ECX = w<<16+h;
  447.         EDX = x<<16+y;
  448.         EBP = 0;
  449.         $int 0x40
  450. }
  451.  
  452. inline fastcall void PutPixel( EBX,ECX,EDX)
  453. {
  454.   EAX=1;
  455.   $int 0x40
  456. }
  457.  
  458. :void DrawBar(dword x,y,w,h,color)
  459. {
  460.         if (h<=0) || (h>60000) || (w<=0) || (w>60000) return; //bad boy :)
  461.         EAX = 13;
  462.         EBX = x<<16+w;
  463.         ECX = y<<16+h;
  464.         EDX = color;
  465.         $int 0x40
  466. }
  467.  
  468. void DefineButton(dword x,y,w,h,EDX,ESI)
  469. {
  470.         EAX = 8;
  471.         $push edx
  472.         EDX += BT_DEL;
  473.         $int 0x40;
  474.         $pop edx
  475.         EBX = x<<16+w;
  476.         ECX = y<<16+h;
  477.         $int 0x40
  478. }
  479.  
  480. inline RefreshWindow(dword ID_REFRESH,ID_ACTIVE)
  481. {
  482.         EAX = 18;
  483.         EBX = 22;
  484.         ECX = 3;
  485.         EDX = ID_REFRESH;
  486.         $int 0x40
  487.         EAX = 18;
  488.         EBX = 3;
  489.         EDX = ID_ACTIVE;
  490.         $int 0x40
  491. }
  492.  
  493. :void UnsafeDefineButton(dword x,y,w,h,id,color)
  494. {
  495.         EAX = 8;
  496.         EBX = x<<16+w;
  497.         ECX = y<<16+h;
  498.         EDX = id;
  499.         ESI = color;
  500.         $int 0x40
  501. }
  502.  
  503. void DefineDragableWindow(dword _x, _y, _w, _h)
  504. {
  505.         DefineAndDrawWindow(_x, _y, _w, _h, 0x41,0x000000,NULL,0b);
  506. }
  507.  
  508. :void EventDragWindow()
  509. {
  510.         dword tmp_x,tmp_y;
  511.         dword z1,z2;
  512.         tmp_x = mouse.x;
  513.         tmp_y = mouse.y;
  514.         do {
  515.                 mouse.get();
  516.                 if (tmp_x!=mouse.x) || (tmp_y!=mouse.y)
  517.                 {
  518.                         z1 = Form.left + mouse.x - tmp_x;
  519.                         z2 = Form.top + mouse.y - tmp_y;
  520.                         if(z1<=10) || (z1>20000) z1=0; else if(z1>screen.width-Form.width-10)z1=screen.width-Form.width;
  521.                         if(z2<=10) || (z2>20000) z2=0; else if(z2>screen.height-Form.height-10)z2=screen.height-Form.height;
  522.                         MoveSize(z1 , z2, OLD, OLD);
  523.                         draw_window();
  524.                 }
  525.                 pause(1);
  526.         } while (mouse.lkm);
  527. }
  528.  
  529. :void DefineHiddenButton(dword _x, _y, _w, _h, _id)
  530. {
  531.         DefineButton(_x, _y, _w, _h, _id + BT_HIDE, 0);
  532. }
  533.  
  534. inline fastcall void DeleteButton( EDX)
  535. {
  536.         EAX = 8;
  537.         EDX += BT_DEL;
  538.         $int 0x40
  539. }
  540.  
  541. inline fastcall dword GetStartTime()
  542. {
  543.         $mov eax,26
  544.         $mov ebx,9
  545.         $int 0x40
  546. }
  547.  
  548. :dword X_EventRedrawWindow,Y_EventRedrawWindow;
  549. :void _EventRedrawWindow()
  550. {
  551.         loop()switch(WaitEvent())
  552.         {
  553.                 case evReDraw:
  554.                         DefineAndDrawWindow(X_EventRedrawWindow,Y_EventRedrawWindow,100,1,0x34,0xFFFFFF,NULL,0);
  555.                         pause(10);
  556.                         ExitProcess();
  557.                         break;
  558.         }
  559. }
  560. :char REDRAW_BUFF_EVENT_[4096];
  561. :void EventRedrawWindow(dword x,y)
  562. {
  563.         X_EventRedrawWindow = x;
  564.         Y_EventRedrawWindow = y;
  565.         CreateThread(#_EventRedrawWindow,#REDRAW_BUFF_EVENT_+4092);
  566. }
  567.  
  568. :struct obj
  569. {
  570.         dword x,y,w,h;
  571.         void set_size();
  572. };
  573.  
  574. :void obj::set_size(dword _x, _y, _w, _h)
  575. {
  576.         x=_x;
  577.         y=_y;
  578.         w=_w;
  579.         h=_h;
  580. }
  581.  
  582. :struct _screen
  583. {
  584.         dword width,height;
  585. } screen;
  586.  
  587. :byte skin_height;
  588.  
  589. :void DrawDate(dword x, y, color, in_date)
  590. {
  591.         EDI = in_date;
  592.         EAX = 47;
  593.         EBX = 2<<16;
  594.         EDX = x<<16+y;
  595.         ESI = 0x90<<24+color;
  596.         ECX = EDI.date.day;
  597.         $int 0x40;
  598.         EDX += 20<<16;
  599.         ECX = EDI.date.month;
  600.         $int 0x40;
  601.         EDX += 20<<16;
  602.         EBX = 4<<16;
  603.         ECX = EDI.date.year;
  604.         $int 0x40;
  605.         DrawBar(x+17,y+10,2,2,color);
  606.         DrawBar(x+37,y+10,2,2,color);
  607. }
  608.  
  609. :void __path_name__(dword BUF,PATH)
  610. {
  611.         dword beg = PATH;
  612.         dword pos = PATH;
  613.         dword sav = PATH;
  614.         dword i;
  615.         while(DSBYTE[pos])
  616.         {
  617.                 if(DSBYTE[pos]=='/')sav = pos;
  618.                 pos++;
  619.         }
  620.         i = sav-beg;
  621.         while(i)
  622.         {
  623.                 DSBYTE[BUF] = DSBYTE[beg];
  624.                 beg++;
  625.                 BUF++;
  626.                 i--;
  627.         }
  628.         /*while(DSBYTE[beg])
  629.         {
  630.                 DSBYTE[BUF1] = DSBYTE[beg];
  631.                 beg++;
  632.                 BUF1++;
  633.         }*/
  634.         //DSBYTE[BUF1] = 0;
  635.         DSBYTE[BUF] = 0;
  636. }
  637. char __BUF_DIR__[4096];
  638. :struct SELF
  639. {
  640.         dword dir;
  641.         dword file;
  642.         dword path;
  643. } self;
  644.  
  645. dword __generator;  // random number generator - äëÿ ãåíåðàöèè ñëó÷àéíûõ ÷èñåë
  646.  
  647. :dword program_path_length;
  648.  
  649. //The initialization of the initial data before running
  650. void ______INIT______()
  651. {
  652.         //if (program_path[0]!='/') I_Path++;
  653.        
  654.         self.dir = #__BUF_DIR__;
  655.         self.file = 0;
  656.         self.path = I_Path;
  657.         __path_name__(#__BUF_DIR__,I_Path);
  658.        
  659.         skin_height   = GetSkinHeight();
  660.         screen.width  = GetScreenWidth()+1;
  661.         screen.height = GetScreenHeight()+1;
  662.        
  663.         DOUBLE_CLICK_DELAY = GetMouseDoubleClickDelay();
  664.         __generator = GetStartTime();
  665.        
  666.         mem_init();
  667.  
  668.  
  669.         main();
  670.         ExitProcess();
  671. }
  672. ______STOP______:
  673. #endif
  674.  
  675. #ifndef INCLUDE_MEM_H
  676. #include "../lib/mem.h"
  677. #endif
  678.  
  679. #ifndef INCLUDE_DEBUG_H
  680. #include "../lib/debug.h"
  681. #endif