Subversion Repositories Kolibri OS

Rev

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