Subversion Repositories Kolibri OS

Rev

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