Subversion Repositories Kolibri OS

Rev

Rev 8949 | Rev 9459 | 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 RefreshWindow(dword ID_REFRESH,ID_ACTIVE)
  236. {
  237.         ActivateWindow(ID_REFRESH);
  238.         ActivateWindow(ID_ACTIVE);
  239. }
  240.  
  241. inline fastcall int MinimizeWindow()
  242. {
  243.         EAX = 18;
  244.         EBX = 10;
  245.         $int 0x40
  246. }
  247.  
  248. inline fastcall int CreateThread(ECX,EDX)
  249. {
  250.         $mov eax,51
  251.         $mov ebx,1
  252.         $int 0x40
  253. }
  254.  
  255. inline fastcall void SwitchToAnotherThread()
  256. {
  257.         $mov eax,68
  258.         $mov ebx,1
  259.         $int 0x40
  260. }
  261.  
  262. inline fastcall int SendWindowMessage( ECX, EDX)
  263. {
  264.         $mov eax, 72
  265.         $mov ebx, 1
  266.         $int 0x40
  267. }
  268.  
  269. inline fastcall int KillProcess( ECX)
  270. {
  271.         $mov eax,18;
  272.         $mov ebx,18;
  273.         $int 0x40
  274. }
  275.  
  276. #define TURN_OFF 2
  277. #define REBOOT 3
  278. #define KERNEL 4
  279. inline fastcall int ExitSystem( ECX)
  280. {
  281.         $mov eax, 18
  282.         $mov ebx, 9
  283.         $int 0x40
  284. }
  285.  
  286. inline fastcall ExitProcess()
  287. {
  288.         $mov eax,-1;
  289.         $int 0x40
  290. }
  291.  
  292. //------------------------------------------------------------------------------
  293.  
  294. //eax = ÿçûê ñèñòåìû (1=eng, 2=fi, 3=ger, 4=rus)
  295. ///SYSFUNC DOESN'T WORK!!!  =>  https://bit.ly/2XNdiTD
  296. #define SYS_LANG_ENG 1
  297. #define SYS_LANG_FIN 2
  298. #define SYS_LANG_GER 3
  299. #define SYS_LANG_RUS 4
  300. inline fastcall int GetSystemLanguage()
  301. {
  302.         EAX = 26;
  303.         EBX = 5;
  304.         $int 0x40
  305. }
  306.  
  307. #define BUTTON_STYLE_FLAT 0
  308. #define BUTTON_STYLE_GRADIENT 1
  309. inline fastcall SetButtonStyle(ECX) //ECX - button style
  310. {
  311.         $mov eax,48
  312.         $mov ebx,1
  313.         int 64
  314. }
  315.  
  316. inline fastcall GetSkinHeight()
  317. {
  318.         $push ebx
  319.         $mov  eax,48
  320.         $mov  ebx,4
  321.         $int 0x40
  322.         $pop  ebx
  323. }
  324.  
  325. inline fastcall void SetSystemSkin( ECX)
  326. {
  327.         EAX = 48;
  328.         EBX = 8;
  329.         $int 0x40
  330. }
  331.  
  332. inline fastcall int GetScreenWidth()
  333. {
  334.         $mov eax, 14
  335.         $int 0x40
  336.         $shr eax, 16
  337. }
  338.  
  339. inline fastcall int GetScreenHeight()
  340. {
  341.         $mov eax, 14
  342.         $int 0x40
  343.         $and eax,0x0000FFFF
  344. }
  345.  
  346. inline fastcall int GetClientTop()
  347. {
  348.         $mov eax, 48
  349.         $mov ebx, 5
  350.         $int 0x40
  351.         $mov eax, ebx
  352.         $shr eax, 16
  353. }
  354.  
  355. inline fastcall int GetClientHeight()
  356. {
  357.         $mov eax, 48
  358.         $mov ebx, 5
  359.         $int 0x40
  360.         $mov eax, ebx
  361. }
  362.  
  363. inline fastcall dword LoadLibrary( ECX)
  364. {
  365.         $mov eax, 68
  366.         $mov ebx, 19
  367.         $int  0x40
  368. }
  369.  
  370. inline fastcall int TestBit( EAX, CL)
  371. {
  372.         $shr eax,cl
  373.         $and eax,1
  374. }
  375.  
  376. :void SetClientScreenArea(dword _left, _right, _top, _bottom)
  377. {
  378.         EAX = 48;
  379.         EBX = 6;
  380.         ECX = _left * 65536 + _right;
  381.         EDX = _top * 65536 + _bottom;
  382.         $int 64;
  383. }
  384.  
  385. //------------------------------------------------------------------------------
  386.  
  387. #define ROLLED_UP 0x04
  388. :void DefineAndDrawWindow(dword _x, _y, _w, _h, _window_type, _bgcolor, _title, _flags)
  389. {
  390.         EAX = 12;              // function 12:tell os about windowdraw
  391.         EBX = 1;
  392.         $int 0x40
  393.        
  394.         $xor EAX,EAX
  395.         EBX = _x << 16 + _w;
  396.         ECX = _y << 16 + _h;
  397.         EDX = _window_type << 24 | _bgcolor;
  398.         EDI = _title;
  399.         ESI = _flags;
  400.         $int 0x40
  401.  
  402.         EAX = 12;              // function 12:tell os about windowdraw
  403.         EBX = 2;
  404.         $int 0x40
  405. }
  406.  
  407. inline fastcall MoveSize( EBX,ECX,EDX,ESI)
  408. {
  409.         $mov eax, 67
  410.         $int 0x40
  411. }
  412.  
  413. inline fastcall void DrawTitle( ECX)
  414. {
  415.         EAX = 71;
  416.         EBX = 1;
  417.         $int 0x40;
  418. }
  419.  
  420. // @EDX is a process id, -1 for self
  421. // @ESI is a new LayerBehaviour
  422. // @RETURN: EAX, 0 is fail, 1 is success
  423. #define ZPOS_DESKTOP     -2
  424. #define ZPOS_ALWAYS_BACK -1
  425. #define ZPOS_NORMAL      0
  426. #define ZPOS_ALWAYS_TOP  1
  427. inline fastcall dword SetWindowLayerBehaviour(EDX, ESI)
  428. {
  429.         EAX = 18;
  430.         EBX = 25;
  431.         ECX = 2;
  432.         $int 64
  433. }
  434.  
  435. :void WriteTextB(dword x,y,byte fontType, dword color, str_offset)
  436. {
  437.         EAX = 4;
  438.         EBX = x<<16+y;
  439.         ECX = fontType<<24+color;
  440.         EDX = str_offset;
  441.         ESI = 0;
  442.         $int 0x40;
  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.width + _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.         if (h<=0) || (h>60000) || (w<=0) || (w>60000) return; //bad boy :)
  552.         EAX = 13;
  553.         EBX = x<<16+w;
  554.         ECX = y<<16+h;
  555.         EDX = color;
  556.         $int 0x40
  557. }
  558.  
  559. :void DefineButton(dword x,y,w,h,id,color)
  560. {
  561.         EAX = 8;
  562.         EDX = id + BT_DEL;
  563.         $int 0x40;
  564.         EDX = id;
  565.         ESI = color;
  566.         EBX = x<<16+w;
  567.         ECX = y<<16+h;
  568.         $int 0x40
  569. }
  570.  
  571. :void UnsafeDefineButton(dword x,y,w,h,id,color)
  572. {
  573.         EAX = 8;
  574.         EBX = x<<16+w;
  575.         ECX = y<<16+h;
  576.         EDX = id;
  577.         ESI = color;
  578.         $int 0x40
  579. }
  580.  
  581. :void DefineDragableWindow(dword _x, _y, _w, _h)
  582. {
  583.         DefineAndDrawWindow(_x, _y, _w, _h, 0x41,0x000000,NULL,0b);
  584. }
  585.  
  586. :void DefineUnDragableWindow(dword _x, _y, _w, _h)
  587. {
  588.         DefineAndDrawWindow(_x, _y, _w, _h, 0x01, 0, 0, 0x01fffFFF);
  589. }
  590.  
  591. :void EventDragWindow()
  592. {
  593.         proc_info Form1;
  594.         dword tmp_x,tmp_y;
  595.         dword z1,z2;
  596.         tmp_x = mouse.x;
  597.         tmp_y = mouse.y;
  598.         do {
  599.                 GetProcessInfo(#Form1, SelfInfo);
  600.                 mouse.get();
  601.                 if (tmp_x!=mouse.x) || (tmp_y!=mouse.y)
  602.                 {
  603.                         z1 = Form1.left + mouse.x - tmp_x;
  604.                         z2 = Form1.top + mouse.y - tmp_y;
  605.                         if(z1<=10) || (z1>20000) z1=0; else if(z1>screen.width-Form1.width-10)z1=screen.width-Form1.width;
  606.                         if(z2<=10) || (z2>20000) z2=0; else if(z2>screen.height-Form1.height-10)z2=screen.height-Form1.height;
  607.                         MoveSize(z1 , z2, OLD, OLD);
  608.                         draw_window();
  609.                 }
  610.                 pause(1);
  611.         } while (mouse.lkm);
  612. }
  613.  
  614. :void DefineHiddenButton(dword _x, _y, _w, _h, _id)
  615. {
  616.         DefineButton(_x, _y, _w, _h, _id + BT_HIDE, 0);
  617. }
  618.  
  619. inline fastcall void DeleteButton( EDX)
  620. {
  621.         EAX = 8;
  622.         EDX += BT_DEL;
  623.         $int 0x40
  624. }
  625.  
  626. inline fastcall dword GetStartTime()
  627. {
  628.         $mov eax,26
  629.         $mov ebx,9
  630.         $int 0x40
  631. }
  632.  
  633. :dword X_EventRedrawWindow,Y_EventRedrawWindow;
  634. :void _EventRedrawWindow()
  635. {
  636.         DefineAndDrawWindow(X_EventRedrawWindow,Y_EventRedrawWindow,1,1,0x34,0xFFFFFF,NULL,0);
  637.         //pause(10);
  638.         ExitProcess();
  639. }
  640. :char REDRAW_BUFF_EVENT_[4096];
  641. :void EventRedrawWindow(dword x,y)
  642. {
  643.         X_EventRedrawWindow = x;
  644.         Y_EventRedrawWindow = y;
  645.         CreateThread(#_EventRedrawWindow,#REDRAW_BUFF_EVENT_+4092);
  646. }
  647.  
  648. :struct _screen
  649. {
  650.         dword width,height;
  651. } screen;
  652.  
  653. :byte skin_height;
  654.  
  655. dword __generator;  // random number generator init
  656.  
  657. //The initialization of the initial data before running
  658. :void ______INIT______()
  659. {
  660.         skin_height   = @GetSkinHeight();
  661.         screen.width  = @GetScreenWidth()+1;
  662.         screen.height = @GetScreenHeight()+1;
  663.         __generator = @GetStartTime(); 
  664.         mem_init();
  665.         main();
  666. }
  667. ______STOP______:
  668. #endif
  669.  
  670. #ifndef INCLUDE_MEM_H
  671. #include "../lib/mem.h"
  672. #endif
  673.  
  674. #ifndef INCLUDE_DEBUG_H
  675. #include "../lib/debug.h"
  676. #endif
  677.  
  678. #ifndef INCLUDE_IPC_H
  679. #include "../lib/ipc.h"
  680. #endif
  681.