Subversion Repositories Kolibri OS

Rev

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