Subversion Repositories Kolibri OS

Rev

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