Subversion Repositories Kolibri OS

Rev

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