Subversion Repositories Kolibri OS

Rev

Rev 6285 | Rev 6562 | 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. //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. :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. inline fastcall int GetSystemLanguage()
  260. {
  261.         EAX = 26;
  262.         EBX = 5;
  263.         $int 0x40
  264. }
  265.  
  266. inline fastcall GetSkinHeight()
  267. {
  268.         $push ebx
  269.         $mov  eax,48
  270.         $mov  ebx,4
  271.         $int 0x40
  272.         $pop  ebx
  273. }
  274.  
  275. inline fastcall void SetSystemSkin( ECX)
  276. {
  277.         EAX = 48;
  278.         EBX = 8;
  279.         $int 0x40
  280. }
  281.  
  282. inline fastcall int GetScreenWidth()
  283. {
  284.         $mov eax, 14
  285.         $int 0x40
  286.         $shr eax, 16
  287. }
  288.  
  289. inline fastcall int GetScreenHeight()
  290. {
  291.         $mov eax, 14
  292.         $int 0x40
  293.         $and eax,0x0000FFFF
  294. }
  295.  
  296. inline fastcall int GetClientTop()
  297. {
  298.         $mov eax, 48
  299.         $mov ebx, 5
  300.         $int 0x40
  301.         $mov eax, ebx
  302.         $shr eax, 16
  303. }
  304.  
  305. inline fastcall int GetClientHeight()
  306. {
  307.         $mov eax, 48
  308.         $mov ebx, 5
  309.         $int 0x40
  310.         $mov eax, ebx
  311. }
  312.  
  313. inline fastcall dword LoadLibrary( ECX)
  314. {
  315.         $mov eax, 68
  316.         $mov ebx, 19
  317.         $int  0x40
  318. }
  319.  
  320. inline fastcall int TestBit( EAX, CL)
  321. {
  322.         $shr eax,cl
  323.         $and eax,1
  324. }
  325.  
  326. //------------------------------------------------------------------------------
  327.  
  328. void DefineAndDrawWindow(dword x, y, size_w, size_h, byte WindowType,dword WindowAreaColor, EDI, ESI)
  329. {
  330.         EAX = 12;              // function 12:tell os about windowdraw
  331.         EBX = 1;
  332.         $int 0x40
  333.        
  334.         $xor EAX,EAX
  335.         EBX = x << 16 + size_w;
  336.         ECX = y << 16 + size_h;
  337.  
  338.         EDX = WindowType << 24 | WindowAreaColor;
  339.         $int 0x40
  340.  
  341.         EAX = 12;              // function 12:tell os about windowdraw
  342.         EBX = 2;
  343.         $int 0x40
  344. }
  345.  
  346. inline fastcall MoveSize( EBX,ECX,EDX,ESI)
  347. {
  348.         $mov eax, 67
  349.         $int 0x40
  350. }
  351.  
  352. inline fastcall void DrawTitle( ECX)
  353. {
  354.         EAX = 71;
  355.         EBX = 1;
  356.         $int 0x40;
  357. }
  358.  
  359. void WriteTextB(dword x,y,byte fontType, dword color, EDX)
  360. {
  361.         EAX = 4;
  362.         EBX = x<<16+y;
  363.         ECX = fontType<<24+color;
  364.         ESI = 0;
  365.         $int 0x40;
  366.         $add ebx, 1<<16
  367.         $int 0x40
  368. }
  369.  
  370. void WriteText(dword x,y,byte fontType, dword color, EDX)
  371. {
  372.         EAX = 4;
  373.         EBX = x<<16+y;
  374.         ECX = fontType<<24+color;
  375.         $int 0x40;
  376. }
  377.  
  378. dword WriteBufText(dword x,y,byte fontType, dword color, EDX, EDI)
  379. {
  380.         EAX = 4;
  381.         EBX = x<<16+y;
  382.         ECX = fontType<<24+color;
  383.         $int 0x40;
  384. }
  385.  
  386. void WriteNumber(dword x,y,byte fontType, dword color, count, ECX)
  387. {
  388.         EAX = 47;
  389.         EBX = count<<16;
  390.         EDX = x<<16+y;
  391.         ESI = fontType<<24+color;
  392.         $int 0x40;
  393. }
  394.  
  395. void CopyScreen(dword EBX, x, y, w, h)
  396. {
  397.   EAX = 36;
  398.   ECX = w << 16 + h;
  399.   EDX = x << 16 + y;
  400.   $int  0x40;
  401. }
  402.  
  403. :dword GetPixelColor(dword x, x_size, y)
  404. {
  405.         $mov eax, 35
  406.         EBX= y*x_size+x;
  407.         $int 0x40
  408. }
  409.  
  410.  
  411. void _PutImage(dword x,y, w,h, EBX)
  412. {
  413.         EAX = 7;
  414.         ECX = w<<16+h;
  415.         EDX = x<<16+y;
  416.         $int 0x40
  417. }
  418.  
  419. void PutPaletteImage(dword EBX,w,h,x,y,ESI,EDI)
  420. {
  421.         EAX = 65;
  422.         ECX = w<<16+h;
  423.         EDX = x<<16+y;
  424.         EBP = 0;
  425.         $int 0x40
  426. }
  427.  
  428. inline fastcall void PutPixel( EBX,ECX,EDX)
  429. {
  430.   EAX=1;
  431.   $int 0x40
  432. }
  433.  
  434. void DrawBar(dword x,y,w,h,EDX)
  435. {
  436.         if (h<=0) || (h>60000) || (w<=0) || (w>60000) return; //bad boy :)
  437.         EAX = 13;
  438.         EBX = x<<16+w;
  439.         ECX = y<<16+h;
  440.         $int 0x40
  441. }
  442.  
  443. void DefineButton(dword x,y,w,h,EDX,ESI)
  444. {
  445.         EAX = 8;
  446.         $push edx
  447.         EDX += BT_DEL;
  448.         $int 0x40;
  449.         $pop edx
  450.         EBX = x<<16+w;
  451.         ECX = y<<16+h;
  452.         $int 0x40
  453. }
  454.  
  455. inline RefreshWindow(dword ID_REFRESH,ID_ACTIVE)
  456. {
  457.         EAX = 18;
  458.         EBX = 22;
  459.         ECX = 3;
  460.         EDX = ID_REFRESH;
  461.         $int 0x40
  462.         EAX = 18;
  463.         EBX = 3;
  464.         EDX = ID_ACTIVE;
  465.         $int 0x40
  466. }
  467.  
  468. void UnsafeDefineButton(dword x,y,w,h,EDX,ESI)
  469. {
  470.         EAX = 8;
  471.         EBX = x<<16+w;
  472.         ECX = y<<16+h;
  473.         $int 0x40
  474. }
  475.  
  476. inline fastcall void DeleteButton( EDX)
  477. {
  478.         EAX = 8;
  479.         EDX += BT_DEL;
  480.         $int 0x40
  481. }
  482.  
  483. inline fastcall dword GetStartTime()
  484. {
  485.         $mov eax,26
  486.         $mov ebx,9
  487.         $int 0x40
  488. }
  489.  
  490. :dword X_EventRedrawWindow,Y_EventRedrawWindow;
  491. :void _EventRedrawWindow()
  492. {
  493.         loop()switch(WaitEvent())
  494.         {
  495.                 case evReDraw:
  496.                         DefineAndDrawWindow(X_EventRedrawWindow,Y_EventRedrawWindow,100,1,1,0x34,0xFFFFFF,"");
  497.                         pause(10);
  498.                         ExitProcess();
  499.                         break;
  500.         }
  501. }
  502. :char REDRAW_BUFF_EVENT_[4096];
  503. :void EventRedrawWindow(dword x,y)
  504. {
  505.         X_EventRedrawWindow = x;
  506.         Y_EventRedrawWindow = y;
  507.         CreateThread(#_EventRedrawWindow,#REDRAW_BUFF_EVENT_+4092);
  508. }
  509.  
  510. :struct obj
  511. {
  512.         dword x,y,w,h;
  513.         void size();
  514. };
  515.  
  516. :void obj::size(dword _x, _y, _w, _h)
  517. {
  518.         x=_x;
  519.         y=_y;
  520.         w=_w;
  521.         h=_h;
  522. }
  523.  
  524. :struct _screen
  525. {
  526.         dword width,height;
  527. } screen;
  528.  
  529. :byte skin_height;
  530.  
  531. :void DrawDate(dword x, y, color, in_date)
  532. {
  533.         EDI = in_date;
  534.         EAX = 47;
  535.         EBX = 2<<16;
  536.         EDX = x<<16+y;
  537.         ESI = 0x90<<24+color;
  538.         ECX = EDI.date.day;
  539.         $int 0x40;
  540.         EDX += 20<<16;
  541.         ECX = EDI.date.month;
  542.         $int 0x40;
  543.         EDX += 20<<16;
  544.         EBX = 4<<16;
  545.         ECX = EDI.date.year;
  546.         $int 0x40;
  547.         DrawBar(x+17,y+10,2,2,color);
  548.         DrawBar(x+37,y+10,2,2,color);
  549. }
  550.  
  551. :void __path_name__(dword BUF,PATH)
  552. {
  553.         dword beg = PATH;
  554.         dword pos = PATH;
  555.         dword sav = PATH;
  556.         dword i;
  557.         while(DSBYTE[pos])
  558.         {
  559.                 if(DSBYTE[pos]=='/')sav = pos;
  560.                 pos++;
  561.         }
  562.         i = sav-beg;
  563.         while(i)
  564.         {
  565.                 DSBYTE[BUF] = DSBYTE[beg];
  566.                 beg++;
  567.                 BUF++;
  568.                 i--;
  569.         }
  570.         /*while(DSBYTE[beg])
  571.         {
  572.                 DSBYTE[BUF1] = DSBYTE[beg];
  573.                 beg++;
  574.                 BUF1++;
  575.         }*/
  576.         //DSBYTE[BUF1] = 0;
  577.         DSBYTE[BUF] = 0;
  578. }
  579. char __BUF_DIR__[4096];
  580. :struct SELF
  581. {
  582.         dword dir;
  583.         dword file;
  584.         dword path;
  585. } self;
  586.  
  587. dword __generator;  // random number generator - äëÿ ãåíåðàöèè ñëó÷àéíûõ ÷èñåë
  588.  
  589. :dword program_path_length;
  590.  
  591. //The initialization of the initial data before running
  592. void ______INIT______()
  593. {
  594.         self.dir = #__BUF_DIR__;
  595.         self.file = 0;
  596.         self.path = I_Path;
  597.         __path_name__(#__BUF_DIR__,I_Path);
  598.        
  599.         skin_height   = GetSkinHeight();
  600.         screen.width  = GetScreenWidth();
  601.         screen.height = GetScreenHeight();
  602.        
  603.         //program_path_length = strlen(I_Path);
  604.         DOUBLE_CLICK_DELAY = GetMouseDoubleClickDelay();
  605.         __generator = GetStartTime();
  606.        
  607.         mem_init();
  608.  
  609.         main();
  610.         ExitProcess();
  611. }
  612. ______STOP______:
  613. #endif
  614.  
  615. #ifndef INCLUDE_MEM_H
  616. #include "../lib/mem.h"
  617. #endif
  618.  
  619. #ifndef INCLUDE_DEBUG_H
  620. #include "../lib/debug.h"
  621. #endif