Subversion Repositories Kolibri OS

Rev

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