Subversion Repositories Kolibri OS

Rev

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