Subversion Repositories Kolibri OS

Rev

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