Subversion Repositories Kolibri OS

Rev

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