Subversion Repositories Kolibri OS

Rev

Rev 5658 | Rev 5676 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. //CODED by Veliant, Leency, Nable. GNU GPL licence.
  2. #ifndef INCLUDE_KOLIBRI_H
  3. #define INCLUDE_KOLIBRI_H
  4.  
  5. #startaddress 0
  6. #code32 TRUE
  7. char   os_name[8]   = {'M','E','N','U','E','T','0','1'};
  8. dword  os_version   = 0x00000001;
  9. dword  start_addr   = #______INIT______;
  10. dword  final_addr   = #______STOP______+32;
  11. dword  alloc_mem    = MEMSIZE;
  12. dword  x86esp_reg   = MEMSIZE;
  13. dword  I_Param      = #param;
  14. dword  I_Path       = #program_path;
  15. char param[4096];
  16. char program_path[4096];
  17.  
  18. #define NULL      0
  19. #define OLD      -1
  20. #define true      1
  21. #define false     0
  22.  
  23. //Events
  24. #define evReDraw  1
  25. #define evKey     2
  26. #define evButton  3
  27. #define evDesktop 5
  28. #define evMouse   6
  29. #define evIPC     7
  30. #define evNetwork 8
  31. #define evDebug   9
  32.  
  33. #define EVENT_MOUSE case 6: mouse.get();
  34.  
  35. //Button options
  36. #define BT_DEL      0x80000000
  37. #define BT_HIDE     0x40000000
  38. #define BT_NOFRAME  0x20000000
  39.  
  40. //ASCII KEYS
  41. #define ASCII_KEY_BS    008
  42. #define ASCII_KEY_TAB   009
  43. #define ASCII_KEY_ENTER 013
  44. #define ASCII_KEY_ESC   027
  45. #define ASCII_KEY_DEL   182
  46. #define ASCII_KEY_INS   185
  47. #define ASCII_KEY_SPACE 032
  48.  
  49. #define ASCII_KEY_LEFT  176
  50. #define ASCII_KEY_RIGHT 179
  51. #define ASCII_KEY_DOWN  177
  52. #define ASCII_KEY_UP    178
  53. #define ASCII_KEY_HOME  180
  54. #define ASCII_KEY_END   181
  55. #define ASCII_KEY_PGDN  183
  56. #define ASCII_KEY_PGUP  184
  57.  
  58. //allow event mask
  59. #define EVENT_MASK_REDRAW   000000001b
  60. #define EVENT_MASK_KEYBOARD 000000010b
  61. #define EVENT_MASK_BUTTONS  000000100b
  62. #define EVENT_MASK_DESKTOP  000010000b
  63. #define EVENT_MASK_MOUSE    000100000b
  64. #define EVENT_MASK_IPC      001000000b
  65. #define EVENT_MASK_NETWORK  010000000b
  66. #define EVENT_MASK_DEBUG    100000000b
  67.  
  68. //ARGS FUNCTION
  69. #define END_ARGS 0xFF00FF
  70. //-------------------------------------------------------------------------
  71.  
  72. #ifndef INCLUDE_SYSTEM_H
  73. #include "../lib/system.h"
  74. #endif
  75.  
  76. #ifndef INCLUDE_MOUSE_H
  77. #include "../lib/mouse.h"
  78. #endif
  79.  
  80. :struct raw_image {
  81.         dword w, h, data;
  82. };
  83.  
  84.  
  85.  
  86. //------------------------------------------------------------------------------
  87. :dword wait_event_code;
  88. inline fastcall dword WaitEvent()
  89. {
  90.         $mov eax,10
  91.         $int 0x40
  92.         wait_event_code = EAX;
  93.         //if(wait_event_code==evMouse) MOUSE.get();
  94.         //return wait_event_code;
  95. }
  96.  
  97. inline fastcall dword CheckEvent()
  98. {
  99.         $mov eax,11
  100.         $int 0x40
  101. }
  102.  
  103. inline fastcall dword WaitEventTimeout(EBX)
  104. {
  105.         $mov eax,23
  106.         $int 0x40
  107. }
  108.  
  109. inline fastcall SetEventMask(EBX)
  110. {
  111.         $mov eax,40
  112.         $int 0x40
  113. }
  114.  
  115. inline fastcall ScancodesGeting(){
  116.         $mov eax,66
  117.         $mov ebx,1
  118.         $mov ecx,1 //᪠­ª®¤ë
  119.         $int 0x40
  120. }
  121.  
  122. inline fastcall word GetKey()  //+Gluk fix
  123. {
  124.                 $push edx
  125. GETKEY:
  126.                 $mov  eax,2
  127.                 $int  0x40
  128.                 $cmp eax,1
  129.                 $jne GETKEYI
  130.                 $mov ah,dh
  131.                 $jmp GETKEYII //jz?
  132. GETKEYI:
  133.                 $mov dh,ah
  134.                 $jmp GETKEY
  135. GETKEYII:
  136.                 $pop edx
  137.                 $shr eax,8
  138. }
  139.  
  140. inline fastcall int GetFullKey()
  141. {
  142.         $mov  eax,2
  143.         $int  0x40
  144. }
  145.  
  146.  
  147. inline fastcall pause(EBX)
  148. {
  149.         $mov eax, 5
  150.         $int 0x40
  151. }
  152.  
  153. inline fastcall word GetButtonID()
  154. {
  155.         $mov eax,17
  156.         $int  0x40
  157.         $shr eax,8
  158. }
  159.  
  160. inline fastcall dword GetFreeRAM()
  161. {
  162.         $mov eax, 18
  163.         $mov ebx, 16
  164.         $int 0x40
  165.         //return eax = ðàçìåð ñâîáîäíîé ïàìÿòè â êèëîáàéòàõ
  166. }
  167.  
  168. inline void draw_line(dword x1,y1,x2,y2,color)
  169. {
  170.         x2--;y2--;y1--;
  171.         $mov EAX,38
  172.         EBX = x1<<16;
  173.         EBX |= x2;
  174.         ECX = y1<<16;
  175.         ECX |= y2;
  176.         $mov EDX,color
  177.         $int 0x40
  178. }
  179.  
  180. inline fastcall dword LoadDriver(ECX) //ECX - èìÿ äðàéâåðà
  181. {
  182.         $mov eax, 68
  183.         $mov ebx, 16
  184.         $int 0x40
  185.         //return 0 - íåóäà÷à, èíà÷å eax = õýíäë äðàéâåðà
  186. }
  187.  
  188. inline fastcall dword RuleDriver(ECX) //óêàçàòåëü íà óïðàâëÿþùóþ ñòðóêòóðó
  189. {
  190.         $mov eax, 68
  191.         $mov ebx, 17
  192.         $int 0x40
  193.         //return eax = îïðåäåëÿåòñÿ äðàéâåðîì
  194. }
  195.  
  196. struct proc_info
  197. {
  198.         #define SelfInfo -1
  199.         dword   use_cpu;
  200.         word    pos_in_stack,num_slot,rezerv1;
  201.         unsigned char name[11];
  202.         char    rezerv2;
  203.         dword   adress,use_memory,ID,left,top,width,height;
  204.         word    status_slot,rezerv3;
  205.         dword   work_left,work_top,work_width,work_height;
  206.         char    status_window;
  207.         dword   cwidth,cheight;
  208.         byte    reserved[1024-71-8];
  209. };
  210.  
  211. inline fastcall void GetProcessInfo(EBX, ECX)
  212. {
  213.         $mov eax,9;
  214.         $int  0x40
  215.         DSDWORD[EBX+71] = DSDWORD[EBX+42] - 9; //set cwidth
  216.         DSDWORD[EBX+75] = DSDWORD[EBX+46] - GetSkinHeight() - 4; //set cheight
  217. }
  218.  
  219. inline fastcall int GetPointOwner( EBX, ECX) //ebx=m.x, ecx=m.y
  220. {
  221.         $mov eax,34
  222.         $int 0x40
  223. }
  224.  
  225. inline fastcall int GetProcessSlot( ECX)
  226. {
  227.         EAX = 18;
  228.         EBX = 21;
  229.         $int 0x40
  230. }
  231.  
  232. inline fastcall int GetActiveProcess()
  233. {
  234.         EAX = 18;
  235.         EBX = 7;
  236.         $int 0x40
  237. }
  238.  
  239. :int CheckActiveProcess(int Form_ID)
  240. {
  241.         int id9=GetProcessSlot(Form_ID);
  242.         if (id9==GetActiveProcess()) return 1;
  243.         return 0;
  244. }
  245.  
  246. inline fastcall void ActivateWindow( ECX)
  247. {
  248.         EAX = 18;
  249.         EBX = 3;
  250.         $int 0x40
  251. }
  252.  
  253. inline fastcall int MinimizeWindow()
  254. {
  255.         EAX = 18;
  256.         EBX = 10;
  257.         $int 0x40
  258. }
  259.  
  260. inline fastcall int CreateThread(ECX,EDX)
  261. {
  262.         $mov eax,51
  263.         $mov ebx,1
  264.         $int 0x40
  265. }
  266.  
  267. inline fastcall void SwitchToAnotherThread()
  268. {
  269.         $mov eax,68
  270.         $mov ebx,1
  271.         $int 0x40
  272. }
  273.  
  274. inline fastcall int SendWindowMessage( ECX, EDX)
  275. {
  276.         $mov eax, 72
  277.         $mov ebx, 1
  278.         $int 0x40
  279. }
  280.  
  281. inline fastcall int KillProcess( ECX)
  282. {
  283.         $mov eax,18;
  284.         $mov ebx,18;
  285.         $int 0x40
  286. }
  287.  
  288. #define TURN_OFF 2
  289. #define REBOOT 3
  290. #define KERNEL 4
  291. inline fastcall int ExitSystem( ECX)
  292. {
  293.         $mov eax, 18
  294.         $mov ebx, 9
  295.         $int 0x40
  296. }
  297.  
  298. inline fastcall ExitProcess()
  299. {
  300.         $mov eax,-1;
  301.         $int 0x40
  302. }
  303.  
  304. //------------------------------------------------------------------------------
  305.  
  306. //eax = ÿçûê ñèñòåìû (1=eng, 2=fi, 3=ger, 4=rus)
  307. inline fastcall int GetSystemLanguage()
  308. {
  309.         EAX = 26;
  310.         EBX = 5;
  311.         $int 0x40
  312. }
  313.  
  314. inline fastcall GetSkinHeight()
  315. {
  316.         $push ebx
  317.         $mov  eax,48
  318.         $mov  ebx,4
  319.         $int 0x40
  320.         $pop  ebx
  321. }
  322.  
  323. inline fastcall void SetSystemSkin( ECX)
  324. {
  325.         EAX = 48;
  326.         EBX = 8;
  327.         $int 0x40
  328. }
  329.  
  330. inline fastcall int GetScreenWidth()
  331. {
  332.         $mov eax, 14
  333.         $int 0x40
  334.         $shr eax, 16
  335. }
  336.  
  337. inline fastcall int GetScreenHeight()
  338. {
  339.         $mov eax, 14
  340.         $int 0x40
  341.         $and eax,0x0000FFFF
  342. }
  343.  
  344. inline fastcall int GetClientTop()
  345. {
  346.         $mov eax, 48
  347.         $mov ebx, 5
  348.         $int 0x40
  349.     $mov eax, ebx
  350.     $shr eax, 16
  351. }
  352.  
  353. inline fastcall int GetClientHeight()
  354. {
  355.         $mov eax, 48
  356.         $mov ebx, 5
  357.         $int 0x40
  358.     $mov eax, ebx
  359. }
  360.  
  361.  
  362. inline fastcall dword LoadLibrary( ECX)
  363. {
  364.         $mov eax, 68
  365.         $mov ebx, 19
  366.         $int  0x40
  367. }
  368.  
  369. inline fastcall int TestBit( EAX, CL)
  370. {
  371.         $shr eax,cl
  372.         $and eax,1
  373. }
  374.  
  375. inline fastcall int PlaySpeaker( ESI)
  376. {
  377.         $mov eax, 55
  378.         $mov ebx, 55
  379.         $int 0x40
  380. }
  381.  
  382. inline fastcall void debugln( EDX)
  383. {
  384.         $push eax
  385.         $push ebx
  386.         $push ecx
  387.         $mov eax, 63
  388.         $mov ebx, 1
  389. NEXT_CHAR:
  390.         $mov ecx, DSDWORD[edx]
  391.         $or      cl, cl
  392.         $jz  DONE
  393.         $int 0x40
  394.         $inc edx
  395.         $jmp NEXT_CHAR
  396. DONE:
  397.         $mov cl, 13
  398.         $int 0x40
  399.         $mov cl, 10
  400.         $int 0x40
  401.         $pop ecx
  402.         $pop ebx
  403.         $pop eax
  404. }
  405.  
  406. inline fastcall void debug( EDX)
  407. {
  408.         $push eax
  409.         $push ebx
  410.         $push ecx
  411.         $mov eax, 63
  412.         $mov ebx, 1
  413. NEXT_CHAR:
  414.         $mov ecx, DSDWORD[edx]
  415.         $or      cl, cl
  416.         $jz  DONE
  417.         $int 0x40
  418.         $inc edx
  419.         $jmp NEXT_CHAR
  420. DONE:
  421.         $pop ecx
  422.         $pop ebx
  423.         $pop eax
  424. }
  425.  
  426.  
  427. inline fastcall void debugch( ECX)
  428. {
  429.         $push eax
  430.         $push ebx
  431.         $mov eax,63
  432.         $mov ebx,1
  433.         $int 0x40
  434.         $pop ebx
  435.         $pop eax
  436. }
  437. //------------------------------------------------------------------------------
  438.  
  439. void DefineAndDrawWindow(dword x, y, size_w, size_h, byte WindowType,dword WindowAreaColor, EDI, ESI)
  440. {
  441.         EAX = 12;              // function 12:tell os about windowdraw
  442.         EBX = 1;
  443.         $int 0x40
  444.        
  445.         $xor EAX,EAX
  446.         EBX = x << 16 + size_w;
  447.         ECX = y << 16 + size_h;
  448.  
  449.         EDX = WindowType << 24 | WindowAreaColor;
  450.         $int 0x40
  451.  
  452.         EAX = 12;              // function 12:tell os about windowdraw
  453.         EBX = 2;
  454.         $int 0x40
  455. }
  456.  
  457. inline fastcall MoveSize( EBX,ECX,EDX,ESI)
  458. {
  459.         $mov eax, 67
  460.         $int 0x40
  461. }
  462.  
  463. inline fastcall void DrawTitle( ECX)
  464. {
  465.         EAX = 71;
  466.         EBX = 1;
  467.         $int 0x40;
  468. }
  469.  
  470. void WriteTextB(dword x,y,byte fontType, dword color, EDX)
  471. {
  472.         EAX = 4;
  473.         EBX = x<<16+y;
  474.         ECX = fontType<<24+color;
  475.         ESI = 0;
  476.         $int 0x40;
  477.         $add ebx, 1<<16
  478.         $int 0x40
  479. }
  480.  
  481. void WriteText(dword x,y,byte fontType, dword color, EDX)
  482. {
  483.         EAX = 4;
  484.         EBX = x<<16+y;
  485.         ECX = fontType<<24+color;
  486.         $int 0x40;
  487. }
  488.  
  489. dword WriteBufText(dword x,y,byte fontType, dword color, EDX, EDI)
  490. {
  491.         EAX = 4;
  492.         EBX = x<<16+y;
  493.         ECX = fontType<<24+color;
  494.         $int 0x40;
  495. }
  496.  
  497. void WriteNumber(dword x,y,byte fontType, dword color, count, ECX)
  498. {
  499.         EAX = 47;
  500.         EBX = count<<16;
  501.         EDX = x<<16+y;
  502.         ESI = fontType<<24+color;
  503.         $int 0x40;
  504. }
  505.  
  506. void CopyScreen(dword EBX, x, y, w, h)
  507. {
  508.   EAX = 36;
  509.   ECX = w << 16 + h;
  510.   EDX = x << 16 + y;
  511.   $int  0x40;
  512. }
  513.  
  514. :dword GetPixelColor(dword x, x_size, y)
  515. {
  516.         $mov eax, 35
  517.         EBX= y*x_size+x;
  518.         $int 0x40
  519. }
  520.  
  521.  
  522. void _PutImage(dword x,y, w,h, EBX)
  523. {
  524.         EAX = 7;
  525.         ECX = w<<16+h;
  526.         EDX = x<<16+y;
  527.         $int 0x40
  528. }
  529.  
  530. void PutPaletteImage(dword EBX,w,h,x,y,ESI,EDI)
  531. {
  532.         EAX = 65;
  533.         ECX = w<<16+h;
  534.         EDX = x<<16+y;
  535.         EBP = 0;
  536.         $int 0x40
  537. }
  538.  
  539. inline fastcall void PutPixel( EBX,ECX,EDX)
  540. {
  541.   EAX=1;
  542.   $int 0x40
  543. }
  544.  
  545. void DrawBar(dword x,y,w,h,EDX)
  546. {
  547.         if (h<=0) || (h>60000) || (w<=0) || (w>60000) return; //bad boy :)
  548.         EAX = 13;
  549.         EBX = x<<16+w;
  550.         ECX = y<<16+h;
  551.         $int 0x40
  552. }
  553.  
  554. void DefineButton(dword x,y,w,h,EDX,ESI)
  555. {
  556.         EAX = 8;
  557.         $push edx
  558.         EDX += BT_DEL;
  559.         $int 0x40;
  560.         $pop edx
  561.         EBX = x<<16+w;
  562.         ECX = y<<16+h;
  563.         $int 0x40
  564. }
  565.  
  566. inline RefreshWindow(dword ID_REFRESH,ID_ACTIVE)
  567. {
  568.         EAX = 18;
  569.         EBX = 22;
  570.         ECX = 3;
  571.         EDX = ID_REFRESH;
  572.         $int 0x40
  573.         EAX = 18;
  574.         EBX = 3;
  575.         EDX = ID_ACTIVE;
  576.         $int 0x40
  577. }
  578.  
  579. inline getIPC(ECX,EDX)
  580. {
  581.         $mov EAX,60
  582.         $mov EBX,2
  583.         $int 0x40
  584. }
  585.  
  586. inline sendIPC(ECX,EDX,ESI)
  587. {
  588.         $mov EAX,60
  589.         $mov EBX,1
  590.         $int 0x40
  591. }
  592.  
  593. void UnsafeDefineButton(dword x,y,w,h,EDX,ESI)
  594. {
  595.         EAX = 8;
  596.         EBX = x<<16+w;
  597.         ECX = y<<16+h;
  598.         $int 0x40
  599. }
  600.  
  601. inline fastcall void DeleteButton( EDX)
  602. {
  603.         EAX = 8;
  604.         EDX += BT_DEL;
  605.         $int 0x40
  606. }
  607.  
  608. inline fastcall dword GetStartTime()
  609. {
  610.         $mov eax,26
  611.         $mov ebx,9
  612.         $int 0x40
  613. }
  614.  
  615. :dword X_EventRedrawWindow,Y_EventRedrawWindow;
  616. :void _EventRedrawWindow()
  617. {
  618.         loop()switch(WaitEvent())
  619.         {
  620.                 case evReDraw:
  621.                         DefineAndDrawWindow(X_EventRedrawWindow,Y_EventRedrawWindow,100,1,1,0x34,0xFFFFFF,"");
  622.                         pause(10);
  623.                         ExitProcess();
  624.                         break;
  625.         }
  626. }
  627. :void EventRedrawWindow(dword x,y)
  628. {
  629.         dword mem = malloc(4096);
  630.         X_EventRedrawWindow = x;
  631.         Y_EventRedrawWindow = y;
  632.         CreateThread(#_EventRedrawWindow,mem+4092);
  633. }
  634.  
  635. :dword ALERT_TEXT;
  636. :void dialog_alert()
  637. {
  638.         byte id;
  639.         loop()switch(WaitEvent())
  640.         {
  641.                 case evReDraw:
  642.                         DefineAndDrawWindow(215,100,250,200,0x34,0xFFFFFF,"Alert");
  643.                         WriteTextB(5,5,0x90,0x0,ALERT_TEXT);
  644.                 break;
  645.                 case evKey:
  646.                 case evButton:
  647.                         id=GetButtonID();
  648.                         if (id==1) ExitProcess();
  649.                 break;
  650.         }
  651. }
  652. :dword alert(dword text)
  653. {
  654.         dword mem = malloc(4096);
  655.         ALERT_TEXT = text;
  656.         CreateThread(#dialog_alert,mem+4092);
  657.         return mem;
  658. }
  659.  
  660. :struct _screen
  661. {
  662.         dword width,height;
  663. } screen;
  664.  
  665. :struct _skin
  666. {
  667.         dword width,height;
  668. } SKIN;
  669.  
  670. :void DrawDate(dword x, y, color, in_date)
  671. {
  672.         //char text[15];
  673.         EDI = in_date;
  674.         EAX = 47;
  675.         EBX = 2<<16;
  676.         EDX = x<<16+y;
  677.         ESI = 0x80<<24+color;
  678.         ECX = EDI.date.day;
  679.         $int 0x40;
  680.         EDX += 18<<16;
  681.         ECX = EDI.date.month;
  682.         $int 0x40;
  683.         EDX += 18<<16;
  684.         EBX = 4<<16;
  685.         ECX = EDI.date.year;
  686.         $int 0x40;
  687.         PutPixel(x+14,y+6,color);
  688.         PutPixel(x+32,y+6,color);
  689.         //sprintf(#text,"%d",EDI.date.year);
  690.         //WriteText(x, y, 0x80, 0x000000, #text);
  691. }
  692.  
  693. :void __path_name__(dword BUF,PATH)
  694. {
  695.         dword beg = PATH;
  696.         dword pos = PATH;
  697.         dword sav = PATH;
  698.         dword i;
  699.         while(DSBYTE[pos])
  700.         {
  701.                 if(DSBYTE[pos]=='/')sav = pos;
  702.                 pos++;
  703.         }
  704.         i = sav-beg;
  705.         while(i)
  706.         {
  707.                 DSBYTE[BUF] = DSBYTE[beg];
  708.                 beg++;
  709.                 BUF++;
  710.                 i--;
  711.         }
  712.         /*while(DSBYTE[beg])
  713.         {
  714.                 DSBYTE[BUF1] = DSBYTE[beg];
  715.                 beg++;
  716.                 BUF1++;
  717.         }*/
  718.         //DSBYTE[BUF1] = 0;
  719.         DSBYTE[BUF] = 0;
  720. }
  721. char __BUF_DIR__[4096];
  722. :struct SELF
  723. {
  724.         dword dir;
  725.         dword file;
  726.         dword path;
  727. } self;
  728.  
  729. dword __generator;  // random number generator - äëÿ ãåíåðàöèè ñëó÷àéíûõ ÷èñåë
  730.  
  731. :dword program_path_length;
  732.  
  733. //The initialization of the initial data before running
  734. void ______INIT______()
  735. {
  736.         self.dir = #__BUF_DIR__;
  737.         self.file = 0;
  738.         self.path = I_Path;
  739.         __path_name__(#__BUF_DIR__,I_Path);
  740.        
  741.         SKIN.height   = GetSkinHeight();
  742.         screen.width  = GetScreenWidth();
  743.         screen.height = GetScreenHeight();
  744.        
  745.         //program_path_length = strlen(I_Path);
  746.         MOUSE_TIME = 50; //Default 500 ms.
  747.         __generator = GetStartTime();
  748.        
  749.         $push    ebx
  750.         $mov     eax, 68
  751.         $mov     ebx, 11
  752.         $int     0x40
  753.        
  754.         $pop     ebx
  755.  
  756.         main();
  757. }
  758. ______STOP______:
  759. #endif