Subversion Repositories Kolibri OS

Rev

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