Subversion Repositories Kolibri OS

Rev

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