Subversion Repositories Kolibri OS

Rev

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