Subversion Repositories Kolibri OS

Rev

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