Subversion Repositories Kolibri OS

Rev

Rev 9594 | Rev 9602 | 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.         EAX = 4;
  443.         EBX = x<<16+y;
  444.         ECX = fontType<<24+color;
  445.         EDX = str_offset;
  446.         ESI = 0;
  447.         $int 0x40;
  448.         $add ebx, 1<<16
  449.         $int 0x40
  450. }
  451.  
  452. :void WriteText(dword x,y,byte fontType, dword color, str_offset)
  453. {
  454.         EAX = 4;
  455.         EBX = x<<16+y;
  456.         ECX = fontType<<24+color;
  457.         EDX = str_offset;
  458.         $int 0x40;
  459. }
  460.  
  461. :dword WriteBufText(dword x,y,byte fontType, dword color, str_offset, buf_offset)
  462. {
  463.         EDI = buf_offset;
  464.         WriteText(x,y, fontType, color, str_offset);
  465. }
  466.  
  467. :void WriteTextWithBg(dword x,y,byte fontType, dword color, str_offset, bgcolor)
  468. {
  469.         EDI = bgcolor;
  470.         WriteText(x,y, fontType, color, str_offset);
  471. }
  472.  
  473. :void WriteNumber(dword x,y,byte fontType, dword color, count, number_or_offset)
  474. {
  475.         EAX = 47;
  476.         EBX = count<<16;
  477.         ECX = number_or_offset;
  478.         EDX = x<<16+y;
  479.         ESI = fontType<<24+color;
  480.         $int 0x40;
  481. }
  482.  
  483. :void CopyScreen(dword dst_offset, x, y, w, h)
  484. {
  485.   EAX = 36;
  486.   EBX = dst_offset;
  487.   ECX = w << 16 + h;
  488.   EDX = x << 16 + y;
  489.   $int  0x40;
  490. }
  491.  
  492. :dword GetPixelColorFromScreen(dword _x, _y)
  493. {
  494.         EAX = 35;
  495.         EBX = _y * screen.w + _x;
  496.         $int 64
  497. }
  498.  
  499. #define DRAW_DESKTOP_BG_TILE 1
  500. #define DRAW_DESKTOP_BG_STRETCH 2
  501. :void SetBackgroundImage(dword w,h, image, mode)
  502. {
  503.         $mov     eax,15      // SF_BACKGROUND_SET 15 - work with desktop background graphics
  504.         $mov     ebx,4       // SSF_MODE_BG 4 - set drawing mode for the background
  505.         $mov     ecx,mode    // drawing mode - tile (1), stretch (2)
  506.         $int     64
  507.  
  508.         $mov     eax,15      // SF_BACKGROUND_SET 15 - work with desktop background graphics
  509.         $mov     ebx,1       // SSF_SIZE_BG=1 - set a size of the background image
  510.         $mov     ecx,w       // width
  511.         $mov     edx,h       // height
  512.         $int     64
  513.  
  514.         $mov     eax,15      // SF_BACKGROUND_SET 15 - work with desktop background graphics
  515.         $mov     ebx,5       // SSF_IMAGE_BG=5 - put block of pixels on the background image
  516.         $mov     ecx,image   // pointer to the data in the format BBGGRRBBGGRR...
  517.         $mov     edx,0       // offset in data of the background image
  518.         ESI      = 3*w*h;    // size of data in bytes = 3 * number of pixels
  519.         $int     64
  520.  
  521.         $mov     eax,15      // SF_BACKGROUND_SET 15 - work with desktop background graphics
  522.         $mov     ebx,3       // SSF_REDRAW_BG=3 - redraw background
  523.         $int     64
  524. }
  525.  
  526. :void _PutImage(dword x,y, w,h, data_offset)
  527. {
  528.         EAX = 7;
  529.         EBX = data_offset;
  530.         ECX = w<<16+h;
  531.         EDX = x<<16+y;
  532.         $int 0x40
  533. }
  534.  
  535. :void PutPaletteImage(dword inbuf,w,h,x,y,bits,pal)
  536. {
  537.         if (h<1) || (w<0) return;
  538.         EAX = 65;
  539.         EBX = inbuf;
  540.         ECX = w<<16+h;
  541.         EDX = x<<16+y;
  542.         ESI = bits;
  543.         EDI = pal;
  544.         EBP = 0;
  545.         $int 0x40
  546. }
  547.  
  548. inline fastcall void PutPixel( EBX,ECX,EDX)
  549. {
  550.   EAX=1;
  551.   $int 0x40
  552. }
  553.  
  554. :void DrawBar(dword x,y,w,h,color)
  555. {
  556.         EAX = 13;
  557.         EBX = x<<16+w;
  558.         ECX = y<<16+h;
  559.         EDX = color;
  560.         $int 0x40
  561. }
  562.  
  563. :void DefineButton(dword x,y,w,h,id,color)
  564. {
  565.         EAX = 8;
  566.         EDX = id + BT_DEL;
  567.         $int 0x40;
  568.         EDX = id;
  569.         ESI = color;
  570.         EBX = x<<16+w;
  571.         ECX = y<<16+h;
  572.         $int 0x40
  573. }
  574.  
  575. :void UnsafeDefineButton(dword x,y,w,h,id,color)
  576. {
  577.         EAX = 8;
  578.         EBX = x<<16+w;
  579.         ECX = y<<16+h;
  580.         EDX = id;
  581.         ESI = color;
  582.         $int 0x40
  583. }
  584.  
  585. :void DefineDragableWindow(dword _x, _y, _w, _h)
  586. {
  587.         DefineAndDrawWindow(_x, _y, _w, _h, 0x41,0x000000,NULL,0b);
  588. }
  589.  
  590. :void DefineUnDragableWindow(dword _x, _y, _w, _h)
  591. {
  592.         DefineAndDrawWindow(_x, _y, _w, _h, 0x01, 0, 0, 0x01fffFFF);
  593. }
  594.  
  595. :void EventDragWindow()
  596. {
  597.         proc_info Form1;
  598.         dword tmp_x,tmp_y;
  599.         dword z1,z2;
  600.         tmp_x = mouse.x;
  601.         tmp_y = mouse.y;
  602.         do {
  603.                 GetProcessInfo(#Form1, SelfInfo);
  604.                 mouse.get();
  605.                 if (tmp_x!=mouse.x) || (tmp_y!=mouse.y)
  606.                 {
  607.                         z1 = Form1.left + mouse.x - tmp_x;
  608.                         z2 = Form1.top + mouse.y - tmp_y;
  609.                         if(z1<=10) || (z1>20000) z1=0; else if(z1>screen.w-Form1.width-10)z1=screen.w-Form1.width;
  610.                         if(z2<=10) || (z2>20000) z2=0; else if(z2>screen.h-Form1.height-10)z2=screen.h-Form1.height;
  611.                         MoveSize(z1 , z2, OLD, OLD);
  612.                         draw_window();
  613.                 }
  614.                 pause(1);
  615.         } while (mouse.lkm);
  616. }
  617.  
  618. :void DefineHiddenButton(dword _x, _y, _w, _h, _id)
  619. {
  620.         DefineButton(_x, _y, _w, _h, _id + BT_HIDE, 0);
  621. }
  622.  
  623. inline fastcall void DeleteButton( EDX)
  624. {
  625.         EAX = 8;
  626.         EDX += BT_DEL;
  627.         $int 0x40
  628. }
  629.  
  630. inline fastcall dword GetStartTime()
  631. {
  632.         $mov eax,26
  633.         $mov ebx,9
  634.         $int 0x40
  635. }
  636.  
  637. :dword X_EventRedrawWindow,Y_EventRedrawWindow;
  638. :void _EventRedrawWindow()
  639. {
  640.         DefineAndDrawWindow(X_EventRedrawWindow,Y_EventRedrawWindow,1,1,0x34,0xFFFFFF,NULL,0);
  641.         //pause(10);
  642.         ExitProcess();
  643. }
  644. :char REDRAW_BUFF_EVENT_[4096];
  645. :void EventRedrawWindow(dword x,y)
  646. {
  647.         X_EventRedrawWindow = x;
  648.         Y_EventRedrawWindow = y;
  649.         CreateThread(#_EventRedrawWindow,#REDRAW_BUFF_EVENT_+4092);
  650. }
  651.  
  652. :struct _screen
  653. {
  654.         dword w,h;
  655. } screen;
  656.  
  657. :byte skin_h;
  658.  
  659. dword __generator;  // random number generator init
  660.  
  661. //The initialization of the initial data before running
  662. :void ______INIT______()
  663. {
  664.         skin_h   = @GetSkinHeight();
  665.         screen.w  = @GetScreenWidth()+1;
  666.         screen.h = @GetScreenHeight()+1;
  667.         __generator = @GetStartTime(); 
  668.         mem_init();
  669.         main();
  670. }
  671. ______STOP______:
  672. #endif
  673.  
  674. #ifndef INCLUDE_MEM_H
  675. #include "../lib/mem.h"
  676. #endif
  677.  
  678. #ifndef INCLUDE_DEBUG_H
  679. #include "../lib/debug.h"
  680. #endif
  681.  
  682. #ifndef INCLUDE_IPC_H
  683. #include "../lib/ipc.h"
  684. #endif
  685.