Subversion Repositories Kolibri OS

Rev

Rev 7373 | Rev 7590 | 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 size in Kb
  131. }
  132.  
  133. inline fastcall dword GetTotalRAM()
  134. {
  135.         $mov eax, 18
  136.         $mov ebx, 17
  137.         $int 0x40
  138.         //return eax = total RAM size in Kb
  139. }
  140.  
  141. inline fastcall int GetCpuIdleCount()
  142. {
  143.         EAX = 18;
  144.         EBX = 4;
  145.         $int 0x40
  146. }
  147.  
  148. inline fastcall int GetCpuFrequency()
  149. {
  150.         EAX = 18;
  151.         EBX = 5;
  152.         $int 0x40
  153. }
  154.  
  155. inline fastcall dword LoadDriver(ECX) //ECX - èìÿ äðàéâåðà
  156. {
  157.         $mov eax, 68
  158.         $mov ebx, 16
  159.         $int 0x40
  160.         //return 0 - íåóäà÷à, èíà÷å eax = õýíäë äðàéâåðà
  161. }
  162.  
  163. inline fastcall dword RuleDriver(ECX) //óêàçàòåëü íà óïðàâëÿþùóþ ñòðóêòóðó
  164. {
  165.         $mov eax, 68
  166.         $mov ebx, 17
  167.         $int 0x40
  168.         //return eax = îïðåäåëÿåòñÿ äðàéâåðîì
  169. }
  170.  
  171. struct proc_info
  172. {
  173.         #define SelfInfo -1
  174.         dword   use_cpu;
  175.         word    pos_in_stack,slot,rezerv1;
  176.         unsigned char name[11];
  177.         char    rezerv2;
  178.         dword   adress,use_memory,ID,left,top,width,height;
  179.         word    status_slot,rezerv3;
  180.         dword   work_left,work_top,work_width,work_height;
  181.         char    status_window;
  182.         dword   cwidth,cheight;
  183.         byte    reserved[1024-71-8];
  184. };
  185.  
  186. :void GetProcessInfo(dword _process_struct_pointer, _process_id)
  187. {
  188.         skin_height = GetSkinHeight();
  189.         EAX = 9;
  190.         EBX = _process_struct_pointer;
  191.         ECX = _process_id;
  192.         $int  0x40
  193.         DSDWORD[EBX+71] = DSDWORD[EBX+42] - 9; //set cwidth
  194.         DSDWORD[EBX+75] = DSDWORD[EBX+46] - skin_height - 4; //set cheight
  195. }
  196.  
  197. inline fastcall int GetPointOwner( EBX, ECX) //ebx=m.x, ecx=m.y
  198. {
  199.         $mov eax,34
  200.         $int 0x40
  201. }
  202.  
  203. inline fastcall int GetProcessSlot( ECX)
  204. {
  205.         EAX = 18;
  206.         EBX = 21;
  207.         $int 0x40
  208. }
  209.  
  210. inline fastcall int GetActiveProcess()
  211. {
  212.         EAX = 18;
  213.         EBX = 7;
  214.         $int 0x40
  215. }
  216.  
  217. :int CheckActiveProcess(int Form_ID)
  218. {
  219.         int id9=GetProcessSlot(Form_ID);
  220.         if (id9==GetActiveProcess()) return 1;
  221.         return 0;
  222. }
  223.  
  224. inline fastcall void ActivateWindow( ECX) //ECX - slot
  225. {
  226.         EAX = 18;
  227.         EBX = 3;
  228.         $int 0x40
  229. }
  230.  
  231. :void RefreshWindow(dword ID_REFRESH,ID_ACTIVE)
  232. {
  233.         ActivateWindow(ID_REFRESH);
  234.         ActivateWindow(ID_ACTIVE);
  235. }
  236.  
  237. inline fastcall int MinimizeWindow()
  238. {
  239.         EAX = 18;
  240.         EBX = 10;
  241.         $int 0x40
  242. }
  243.  
  244. inline fastcall int CreateThread(ECX,EDX)
  245. {
  246.         $mov eax,51
  247.         $mov ebx,1
  248.         $int 0x40
  249. }
  250.  
  251. inline fastcall void SwitchToAnotherThread()
  252. {
  253.         $mov eax,68
  254.         $mov ebx,1
  255.         $int 0x40
  256. }
  257.  
  258. inline fastcall int SendWindowMessage( ECX, EDX)
  259. {
  260.         $mov eax, 72
  261.         $mov ebx, 1
  262.         $int 0x40
  263. }
  264.  
  265. inline fastcall int KillProcess( ECX)
  266. {
  267.         $mov eax,18;
  268.         $mov ebx,18;
  269.         $int 0x40
  270. }
  271.  
  272. #define TURN_OFF 2
  273. #define REBOOT 3
  274. #define KERNEL 4
  275. inline fastcall int ExitSystem( ECX)
  276. {
  277.         $mov eax, 18
  278.         $mov ebx, 9
  279.         $int 0x40
  280. }
  281.  
  282. inline fastcall ExitProcess()
  283. {
  284.         $mov eax,-1;
  285.         $int 0x40
  286. }
  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.         EDI = buf_offset;
  454.         WriteText(x,y, fontType, color, str_offset);
  455. }
  456.  
  457. :void WriteTextWithBg(dword x,y,byte fontType, dword color, str_offset, bgcolor)
  458. {
  459.         EDI = bgcolor;
  460.         WriteText(x,y, fontType, color, str_offset);
  461. }
  462.  
  463. :void WriteNumber(dword x,y,byte fontType, dword color, count, number_or_offset)
  464. {
  465.         EAX = 47;
  466.         EBX = count<<16;
  467.         ECX = number_or_offset;
  468.         EDX = x<<16+y;
  469.         ESI = fontType<<24+color;
  470.         $int 0x40;
  471. }
  472.  
  473. :void CopyScreen(dword dst_offset, x, y, w, h)
  474. {
  475.   EAX = 36;
  476.   EBX = dst_offset;
  477.   ECX = w << 16 + h;
  478.   EDX = x << 16 + y;
  479.   $int  0x40;
  480. }
  481.  
  482. :dword GetPixelColorFromScreen(dword _x, _y)
  483. {
  484.         EAX = 35;
  485.         EBX = _y * screen.width + _x;
  486.         $int 64
  487. }
  488.  
  489. #define DRAW_DESKTOP_BG_TILE 1
  490. #define DRAW_DESKTOP_BG_STRETCH 2
  491. :void SetBackgroundImage(dword w,h, image, mode)
  492. {
  493.         $mov     eax,15      // SF_BACKGROUND_SET 15 - work with desktop background graphics
  494.         $mov     ebx,4       // SSF_MODE_BG 4 - set drawing mode for the background
  495.         $mov     ecx,mode    // drawing mode - tile (1), stretch (2)
  496.         $int     64
  497.  
  498.         $mov     eax,15      // SF_BACKGROUND_SET 15 - work with desktop background graphics
  499.         $mov     ebx,1       // SSF_SIZE_BG=1 - set a size of the background image
  500.         $mov     ecx,w       // width
  501.         $mov     edx,h       // height
  502.         $int     64
  503.  
  504.         $mov     eax,15      // SF_BACKGROUND_SET 15 - work with desktop background graphics
  505.         $mov     ebx,5       // SSF_IMAGE_BG=5 - put block of pixels on the background image
  506.         $mov     ecx,image   // pointer to the data in the format BBGGRRBBGGRR...
  507.         $mov     edx,0       // offset in data of the background image
  508.         ESI      = 3*w*h;    // size of data in bytes = 3 * number of pixels
  509.         $int     64
  510.  
  511.         $mov     eax,15      // SF_BACKGROUND_SET 15 - work with desktop background graphics
  512.         $mov     ebx,3       // SSF_REDRAW_BG=3 - redraw background
  513.         $int     64
  514. }
  515.  
  516. :void _PutImage(dword x,y, w,h, data_offset)
  517. {
  518.         EAX = 7;
  519.         EBX = data_offset;
  520.         ECX = w<<16+h;
  521.         EDX = x<<16+y;
  522.         $int 0x40
  523. }
  524.  
  525. :void PutPaletteImage(dword inbuf,w,h,x,y,bits,pal)
  526. {
  527.         EAX = 65;
  528.         EBX = inbuf;
  529.         ECX = w<<16+h;
  530.         EDX = x<<16+y;
  531.         ESI = bits;
  532.         EDI = pal;
  533.         EBP = 0;
  534.         $int 0x40
  535. }
  536.  
  537. inline fastcall void PutPixel( EBX,ECX,EDX)
  538. {
  539.   EAX=1;
  540.   $int 0x40
  541. }
  542.  
  543. :void DrawBar(dword x,y,w,h,color)
  544. {
  545.         if (h<=0) || (h>60000) || (w<=0) || (w>60000) return; //bad boy :)
  546.         EAX = 13;
  547.         EBX = x<<16+w;
  548.         ECX = y<<16+h;
  549.         EDX = color;
  550.         $int 0x40
  551. }
  552.  
  553. :void DefineButton(dword x,y,w,h,id,color)
  554. {
  555.         EAX = 8;
  556.         EDX = id + BT_DEL;
  557.         $int 0x40;
  558.         EDX = id;
  559.         ESI = color;
  560.         EBX = x<<16+w;
  561.         ECX = y<<16+h;
  562.         $int 0x40
  563. }
  564.  
  565. :void UnsafeDefineButton(dword x,y,w,h,id,color)
  566. {
  567.         EAX = 8;
  568.         EBX = x<<16+w;
  569.         ECX = y<<16+h;
  570.         EDX = id;
  571.         ESI = color;
  572.         $int 0x40
  573. }
  574.  
  575. :void DefineDragableWindow(dword _x, _y, _w, _h)
  576. {
  577.         DefineAndDrawWindow(_x, _y, _w, _h, 0x41,0x000000,NULL,0b);
  578. }
  579.  
  580. :void DefineUnDragableWindow(dword _x, _y, _w, _h)
  581. {
  582.         DefineAndDrawWindow(_x, _y, _w, _h, 0x01, 0, 0, 0x01fffFFF);
  583. }
  584.  
  585. :void EventDragWindow()
  586. {
  587.         proc_info Form1;
  588.         dword tmp_x,tmp_y;
  589.         dword z1,z2;
  590.         tmp_x = mouse.x;
  591.         tmp_y = mouse.y;
  592.         do {
  593.                 GetProcessInfo(#Form1, SelfInfo);
  594.                 mouse.get();
  595.                 if (tmp_x!=mouse.x) || (tmp_y!=mouse.y)
  596.                 {
  597.                         z1 = Form1.left + mouse.x - tmp_x;
  598.                         z2 = Form1.top + mouse.y - tmp_y;
  599.                         if(z1<=10) || (z1>20000) z1=0; else if(z1>screen.width-Form1.width-10)z1=screen.width-Form1.width;
  600.                         if(z2<=10) || (z2>20000) z2=0; else if(z2>screen.height-Form1.height-10)z2=screen.height-Form1.height;
  601.                         MoveSize(z1 , z2, OLD, OLD);
  602.                         draw_window();
  603.                 }
  604.                 pause(1);
  605.         } while (mouse.lkm);
  606. }
  607.  
  608. :void DefineHiddenButton(dword _x, _y, _w, _h, _id)
  609. {
  610.         DefineButton(_x, _y, _w, _h, _id + BT_HIDE, 0);
  611. }
  612.  
  613. inline fastcall void DeleteButton( EDX)
  614. {
  615.         EAX = 8;
  616.         EDX += BT_DEL;
  617.         $int 0x40
  618. }
  619.  
  620. inline fastcall dword GetStartTime()
  621. {
  622.         $mov eax,26
  623.         $mov ebx,9
  624.         $int 0x40
  625. }
  626.  
  627. :dword X_EventRedrawWindow,Y_EventRedrawWindow;
  628. :void _EventRedrawWindow()
  629. {
  630.         DefineAndDrawWindow(X_EventRedrawWindow,Y_EventRedrawWindow,1,1,0x34,0xFFFFFF,NULL,0);
  631.         //pause(10);
  632.         ExitProcess();
  633. }
  634. :char REDRAW_BUFF_EVENT_[4096];
  635. :void EventRedrawWindow(dword x,y)
  636. {
  637.         X_EventRedrawWindow = x;
  638.         Y_EventRedrawWindow = y;
  639.         CreateThread(#_EventRedrawWindow,#REDRAW_BUFF_EVENT_+4092);
  640. }
  641.  
  642. :struct _screen
  643. {
  644.         dword width,height;
  645. } screen;
  646.  
  647. :byte skin_height;
  648.  
  649. :void DrawDate(dword x, y, color, in_date)
  650. {
  651.         EDI = in_date;
  652.         EAX = 47;
  653.         EBX = 2<<16;
  654.         EDX = x<<16+y;
  655.         ESI = 0x90<<24+color;
  656.         ECX = EDI.date.day;
  657.         $int 0x40;
  658.         EDX += 20<<16;
  659.         ECX = EDI.date.month;
  660.         $int 0x40;
  661.         EDX += 20<<16;
  662.         EBX = 4<<16;
  663.         ECX = EDI.date.year;
  664.         $int 0x40;
  665.         DrawBar(x+17,y+10,2,2,color);
  666.         DrawBar(x+37,y+10,2,2,color);
  667. }
  668.  
  669. :void __path_name__(dword BUF,PATH)
  670. {
  671.         dword beg = PATH;
  672.         dword pos = PATH;
  673.         dword sav = PATH;
  674.         dword i;
  675.         while(DSBYTE[pos])
  676.         {
  677.                 if(DSBYTE[pos]=='/')sav = pos;
  678.                 pos++;
  679.         }
  680.         i = sav-beg;
  681.         while(i)
  682.         {
  683.                 DSBYTE[BUF] = DSBYTE[beg];
  684.                 beg++;
  685.                 BUF++;
  686.                 i--;
  687.         }
  688.         /*while(DSBYTE[beg])
  689.         {
  690.                 DSBYTE[BUF1] = DSBYTE[beg];
  691.                 beg++;
  692.                 BUF1++;
  693.         }*/
  694.         //DSBYTE[BUF1] = 0;
  695.         DSBYTE[BUF] = 0;
  696. }
  697. char __BUF_DIR__[4096];
  698. :struct SELF
  699. {
  700.         dword dir;
  701.         dword file;
  702.         dword path;
  703. } self;
  704.  
  705. dword __generator;  // random number generator - äëÿ ãåíåðàöèè ñëó÷àéíûõ ÷èñåë
  706.  
  707. :dword program_path_length;
  708.  
  709. //The initialization of the initial data before running
  710. void ______INIT______()
  711. {
  712.         //if (program_path[0]!='/') I_Path++;
  713.        
  714.         self.dir = #__BUF_DIR__;
  715.         self.file = 0;
  716.         self.path = I_Path;
  717.         __path_name__(#__BUF_DIR__,I_Path);
  718.        
  719.         skin_height   = GetSkinHeight();
  720.         screen.width  = GetScreenWidth()+1;
  721.         screen.height = GetScreenHeight()+1;
  722.        
  723.         __generator = GetStartTime();
  724.        
  725.         mem_init();
  726.  
  727.  
  728.         main();
  729.         ExitProcess();
  730. }
  731. ______STOP______:
  732. #endif
  733.  
  734. #ifndef INCLUDE_MEM_H
  735. #include "../lib/mem.h"
  736. #endif
  737.  
  738. #ifndef INCLUDE_DEBUG_H
  739. #include "../lib/debug.h"
  740. #endif