Subversion Repositories Kolibri OS

Rev

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