Subversion Repositories Kolibri OS

Rev

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