Subversion Repositories Kolibri OS

Rev

Rev 2444 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. //CODED by Veliant, Leency, Nable. GNU GPL licence.
  2.  
  3. #startaddress 0
  4. #code32 TRUE
  5.  
  6. char   os_name[8]   = {'M','E','N','U','E','T','0','1'};
  7. dword  os_version   = 0x00000001;
  8. dword  start_addr   = #main;
  9. dword  final_addr   = #stop+32;
  10. dword  alloc_mem    = #0x00100000;
  11. dword  x86esp_reg   = #0x00100000;
  12. dword  I_Param      = #param;
  13. dword  I_Path       = #program_path;
  14. char param[4096]="";
  15. char program_path[4096]="";
  16.  
  17. //Events
  18. #define evMouse 6
  19. #define evButton        3
  20. #define evKey           2
  21. #define evReDraw        1
  22.  
  23. //Button options
  24. #define BT_DEL          0x80000000
  25. #define BT_HIDE         0x40000000
  26. #define BT_NOFRAME      0x20000000
  27.  
  28. #define OLD             -1
  29. #define true            1
  30. #define false           0
  31. //-------------------------------------------------------------------------
  32.  
  33. struct mouse{
  34.  dword x,y,lkm,pkm,hor,vert;
  35.  void get();
  36. };
  37.  
  38. void mouse::get()
  39. {
  40.         EAX = 37;
  41.         EBX = 1;
  42.         $int    0x40
  43.         $mov    ebx, eax
  44.         $shr    eax, 16
  45.         $and    ebx,0x0000FFFF
  46.         x = EAX;
  47.         y = EBX;
  48.         EAX = 37;
  49.         EBX = 2;
  50.         $int    0x40
  51.         $mov    ebx, eax
  52.         $and    eax, 0x00000001
  53.         $shr    ebx, 1
  54.         $and    ebx, 0x00000001
  55.         lkm = EAX;
  56.         pkm = EBX;
  57.         EAX = 37; //áªà®««
  58.         EBX = 7;
  59.         $int    0x40
  60.         $mov    ebx, eax
  61.         $shr    eax, 16
  62.         $and    ebx,0x0000FFFF
  63.         //hor = EAX;
  64.         vert = EBX;
  65. }
  66.  
  67.  
  68. struct system_colors{
  69.         dword frame,grab,grab_button,grab_button_text,grab_text,work,work_button,work_button_text,work_text,work_graph;
  70.         void get();
  71. };
  72. void system_colors::get()
  73. {
  74.         EAX = 48;
  75.         EBX = 3;
  76.         ECX = #frame;
  77.         EDX = 40;
  78.         $int 0x40
  79. }
  80.  
  81. //------------------------------------------------------------------------------
  82.  
  83. inline fastcall dword WaitEvent(){
  84.  EAX = 10;
  85.  $int 0x40
  86. }
  87.  
  88. inline fastcall dword WaitEventTimeout(dword EBX){
  89.  EAX = 23;
  90.  $int 0x40
  91. }
  92.  
  93. inline fastcall SetEventMask(dword EBX)
  94. {
  95.  EAX = 40;
  96.  $int 0x40
  97. }
  98.  
  99. inline fastcall ScancodesGeting(){
  100.         $mov eax,66;
  101.         $mov ebx,1;
  102.         $mov ecx,1; //᪠­ª®¤ë
  103.         $int 0x40
  104. }
  105.  
  106.  
  107. inline fastcall word GetKey(){ //Gluk fix
  108.                 $push edx
  109. @getkey:
  110.                 $mov  eax,2
  111.                 $int  0x40
  112.                 $cmp eax,1
  113.                 $jne getkeyi
  114.                 $mov ah,dh
  115.                 $jmp getkeyii //jz?
  116. @getkeyi:
  117.                 $mov dh,ah
  118.                 $jmp getkey
  119. @getkeyii:
  120.                 $pop edx
  121.                 EAX = EAX >> 8;          
  122. }
  123.  
  124.  
  125. inline fastcall Pause(dword EBX)
  126. {                                       // ã§ , ¢ á®âëå ¤®«ïå ᥪ㭤ë EBX = value
  127.         $mov eax, 5
  128.         $int 0x40
  129. }
  130.  
  131. //==================================================================
  132.  
  133. inline fastcall word GetButtonID(){
  134.  EAX = 17;
  135.  $int  0x40
  136.  EAX = EAX >> 8;
  137. }
  138.  
  139. struct proc_info{
  140.         dword   use_cpu;
  141.         word    pos_in_stack,num_slot,rezerv1;
  142.         char    name[11];
  143.         char    rezerv2;
  144.         dword   adress,use_memory,ID,left,top,width,height;
  145.         word    status_slot,rezerv3;
  146.         dword   work_left,work_top,work_width,work_height;
  147.         char    status_window;
  148.         void    GetInfo(dword ECX);
  149.         byte    reserved[1024-71];
  150. #define SelfInfo -1
  151. };
  152.  
  153. void GetProcessInfo(dword EBX, ECX)
  154. {
  155.         EAX = 9;
  156.         $int  0x40
  157. }
  158.  
  159. int GetProcessSlot(ECX) //ECX = process ID
  160. {
  161.         EAX = 18;
  162.         EBX = 21;
  163.         $int 0x40;     
  164. }
  165.  
  166. inline fastcall ExitProcess(){
  167.  EAX = -1;              // close this program
  168.  $int 0x40
  169. }
  170.  
  171. inline fastcall KillProcess(dword ECX){
  172.         $mov eax,18;
  173.         $mov ebx,18;
  174.         $int 0x40
  175. }
  176.  
  177. //==================================================================
  178.  
  179. //eax = ÿçûê ñèñòåìû (1=eng, 2=fi, 3=ger, 4=rus)
  180. inline fastcall int GetSystemLanguage(){
  181.  EAX = 26;
  182.  EBX = 5;
  183.  $int 0x40
  184.  RETURN EAX;
  185. }
  186.  
  187. inline fastcall void DrawTitle(dword ECX)
  188. {
  189.         EAX = 71;
  190.         EBX = 1;
  191.         $int 0x40;
  192. }
  193.  
  194. inline fastcall dword GetSkinWidth()
  195. {
  196.         EAX = 48;
  197.         EBX = 4;
  198.         $int 0x40
  199. }
  200.  
  201. inline fastcall void SetSystemSkin(ECX){
  202.         EAX = 48;
  203.         EBX = 8;
  204.         $int 0x40
  205. }
  206.  
  207. inline fastcall dword GetScreenWidth()
  208. {
  209.         EAX = 14;
  210.         EBX = 4;
  211.         $int 0x40
  212.         $shr eax, 16
  213.         $and eax,0x0000FFFF
  214. }
  215.  
  216. inline fastcall MoveSize(dword EBX,ECX,EDX,ESI)
  217. {
  218.         EAX = 67;
  219.         $int 0x40
  220. }
  221.  
  222. inline fastcall dword LoadLibrary(dword ECX)
  223. {
  224.         $mov eax, 68
  225.         $mov ebx, 19
  226.         $int  0x40
  227. }
  228.  
  229. //------------------------------------------------------------------------------
  230. inline fastcall dword strlen(dword EDI){
  231.         EAX=0;
  232.         ECX=-1;
  233.         $REPNE $SCASB
  234.         EAX-=2+ECX;
  235. }
  236.  
  237. inline fastcall copystr(dword ESI,EDI)
  238. {
  239.         $cld
  240. l1:
  241.         $lodsb
  242.         $stosb
  243.         $test al,al
  244.         $jnz l1
  245. }
  246.  
  247.  
  248. byte fastcall TestBit(EAX, CL)
  249. {
  250.         $shr eax,cl
  251.         $and eax,1
  252. }
  253.  
  254. char buffer[11]="";
  255. inline fastcall dword IntToStr(dword ESI)
  256. {
  257.      $mov     edi, #buffer
  258.      $mov     ecx, 10
  259.      $test     esi, esi
  260.      $jns     f1
  261.      $mov     al, '-'
  262.      $stosb
  263.      $neg     esi
  264. f1:
  265.      $mov     eax, esi
  266.      $push     -'0'
  267. f2:
  268.      $xor     edx, edx
  269.      $div     ecx
  270.      $push     edx
  271.      $test     eax, eax
  272.      $jnz     f2
  273. f3:
  274.      $pop     eax
  275.      $add     al, '0'
  276.      $stosb
  277.      $jnz     f3
  278.      $mov     eax, #buffer
  279.      $ret
  280. }
  281.  
  282.  
  283. inline fastcall dword StrToInt()
  284. {
  285.         ESI=EDI=EAX;
  286.         IF(DSBYTE[ESI]=='-')ESI++;
  287.         EAX=0;
  288.         BH=AL;
  289.         do{
  290.                 BL=DSBYTE[ESI]-'0';
  291.                 EAX=EAX*10+EBX;
  292.                 ESI++;
  293.         }while(DSBYTE[ESI]>0);
  294.         IF(DSBYTE[EDI]=='-') -EAX;
  295. }
  296.  
  297.  
  298. inline fastcall int strcmp(ESI, EDI)
  299. {
  300.         loop()
  301.         {
  302.                 IF (DSBYTE[ESI]<DSBYTE[EDI]) RETURN -1;
  303.                 IF (DSBYTE[ESI]>DSBYTE[EDI]) RETURN 1;
  304.                 IF (DSBYTE[ESI]=='\0') RETURN 0;
  305.                 ESI++;
  306.                 EDI++;
  307.         }
  308. }
  309.  
  310. inline fastcall unsigned int find_symbol(ESI,BL)
  311. {
  312.         int jj=0, last=-1;
  313.         do{
  314.                 jj++;
  315.                 $lodsb
  316.                 IF(AL==BL) last=jj;
  317.         } while(AL!=0);
  318.         return last;
  319. }
  320.  
  321.  
  322. inline fastcall dword upcase(dword ESI)
  323. {
  324.         do{
  325.                 AL=DSBYTE[ESI];
  326.                 IF(AL>='a')IF(AL<='z')DSBYTE[ESI]=AL&0x5f;
  327.                 ESI++;
  328.         }while(AL!=0);
  329. }
  330.  
  331. /*inline fastcall void lowcase(ESI)
  332. {
  333.         do{
  334.                 $LODSB
  335.                 IF(AL>='A')&&(AL<='Z'){
  336.                         AL+=0x20;
  337.                         DSBYTE[ESI-1]=AL;
  338.                         CONTINUE;
  339.                 }
  340.         }while(AL!=0);
  341. }*/
  342.  
  343. inline fastcall lowcase(ESI)
  344. {
  345.         do{
  346.                 $LODSB
  347.                 IF(AL>='A')&&(AL<='Z'){
  348.                         AL+=0x20;
  349.                         DSBYTE[ESI-1]=AL;
  350.                         CONTINUE;
  351.                 }
  352.         }while(AL!=0);
  353. }
  354.  
  355.  
  356. inline fastcall wintodos (dword ESI)
  357. {
  358.    while (BL=ESBYTE[ESI])
  359.    {
  360.         IF (BL>=192)
  361.         {
  362.              IF (BL>=240) ESBYTE[ESI] = BL - 16;
  363.              ELSE ESBYTE[ESI] = BL - 64;
  364.         }
  365.         ELSE
  366.         {
  367.         IF (BL==178) ESBYTE[ESI] = 73;  //I
  368.         IF (BL==179) ESBYTE[ESI] = 105; //i
  369.         IF (BL==175) ESBYTE[ESI] = 244; //J
  370.     IF (BL==191) ESBYTE[ESI] = 245; //j
  371.         IF (BL==170) ESBYTE[ESI] = 242; //E
  372.         IF (BL==186) ESBYTE[ESI] = 243; //e
  373.     IF (BL==168) ESBYTE[ESI] = 240; //ð
  374.     IF (BL==184) ESBYTE[ESI] = 'e'; //e
  375.         IF (BL==180) ESBYTE[ESI] = 254; //ã
  376.     IF ((BL==147) || (BL==148) || (BL==171) || (BL==187)) ESBYTE[ESI] = 34;
  377.     IF ((BL==150) || (BL==151)) ESBYTE[ESI] = 45;
  378.         }
  379.         ESI++;
  380.    }
  381. }
  382.  
  383.  
  384. dword Hex2Symb(char* htmlcolor)
  385. {
  386.   dword j=0, symbol=0;
  387.   char ch=0x00;
  388.   FOR (;j<2;j++)
  389.   {
  390.     ch=ESBYTE[htmlcolor+j];
  391.     IF (ch==0x0d) || (ch=='\9') RETURN '';
  392.     IF ((ch>='0') && (ch<='9')) ch -= '0';
  393.     IF ((ch>='A') && (ch<='F')) ch -= 'A'-10;
  394.     IF ((ch>='a') && (ch<='f')) ch -= 'a'-10;
  395.     symbol = symbol*0x10 + ch;
  396.   }
  397.   wintodos(#symbol);
  398.   AL=symbol;
  399. }
  400.  
  401. /*int hex2char(char c)
  402. {
  403.   if (c <=9)
  404.     return (c+48);
  405.  
  406.   return (c - 10 + 'a');
  407. }
  408.  
  409. int hex2char(dword c)
  410. {
  411.   if (c <=9)
  412.     return (c+48);
  413.  
  414.   return (c - 10 + 'a');
  415. }*/
  416.  
  417. byte mas[66] = "椥ä£å¨©ª«¬­®¯ïàáâ㦢ìë§èíéçꞀ–„…”ƒ•ˆ‰Š‹ŒŽŸ‘’“†‚œ›‡˜™—š";
  418. inline fastcall void koitodos(dword EDI)
  419. {
  420.         WHILE (BL=ESBYTE[EDI])
  421.         {      
  422.                 IF (BL >= 0xC0)
  423.                 {
  424.                         BL -= 0xC0;
  425.                         ESBYTE[EDI] = mas[BL];
  426.                 }
  427.                 //IF (ESBYTE[EDI]=='\244') ESBYTE[EDI]='i';
  428.                 EDI++;
  429.         }
  430. }
  431.  
  432.  
  433. //Asper
  434. //uncomplete
  435. inline fastcall int utf8rutodos(dword ESI) //-
  436. {
  437.     EDI=ESI;
  438.         while (BL=ESBYTE[ESI])
  439.         {      
  440.                 IF (BL == 0xD0) || (BL == 0xD1) EDI--;
  441.         else IF (BL == 0x81) && (ESBYTE[ESI-1]==0xD0) ESBYTE[EDI] = 0xF0; //è
  442.         else IF (BL == 0x91) && (ESBYTE[ESI-1]==0xD1) ESBYTE[EDI] = 0xF1; //¬
  443.         else IF (BL == 0xE2) && (ESBYTE[ESI+1]==0x80) && (ESBYTE[ESI+2]==0x94)  //long defis
  444.         {
  445.           ESBYTE[EDI] = '-';
  446.           ESI+=2;
  447.         }  
  448.         else IF (BL == 0xE2) && (ESBYTE[ESI+1]==0x80) && (ESBYTE[ESI+2]==0xA2)  //central point
  449.         {
  450.           ESBYTE[EDI] = '*';
  451.           ESI+=2;
  452.         }  
  453.         else IF (BL == 0xC2) && (ESBYTE[ESI+1]==0xA9)  // (c)
  454.         {
  455.           ESBYTE[EDI] = '(';
  456.           ESBYTE[EDI+1] = 'c';
  457.           ESBYTE[EDI+2] = ')';
  458.           EDI+=2;
  459.           ESI++;
  460.         }  
  461.         ELSE IF (BL == 0xC2) && ((ESBYTE[ESI+1]==0xAB) || (ESBYTE[ESI+1]==0xBB))  // "
  462.         {
  463.           ESBYTE[EDI] = '\"';
  464.           ESI++;
  465.         }  
  466.         ELSE IF (BL == 0xC2) && (ESBYTE[ESI+1]==0xB7)  // _
  467.         {
  468.           ESBYTE[EDI] = '_';
  469.           ESI++;
  470.         }  
  471.         ELSE IF (BL >= 0x90) && (BL <= 0xAF)
  472.                 {
  473.             BL -= 0x10;
  474.                         ESBYTE[EDI] = BL;
  475.                 }
  476.         ELSE IF (BL >= 0x80) && (BL <= 0x8F)
  477.                 {
  478.             BL += 0x60;
  479.                         ESBYTE[EDI] = BL;            
  480.                 }
  481.         ELSE IF (BL >= 0xB0) && (BL <= 0xBF)
  482.                 {
  483.             BL -= 0x10;
  484.                         ESBYTE[EDI] = BL;
  485.                 }
  486.         ELSE ESBYTE[EDI] = BL;
  487.                 ESI++;
  488.         EDI++;
  489.         }
  490.         WHILE (EDI<ESI)
  491.         {
  492.         ESBYTE[EDI] = ' ';
  493.         EDI++;
  494.     }
  495. }
  496.  
  497. //------------------------------------------------------------------------------
  498.  
  499.  
  500. void DefineAndDrawWindow(dword x,y,sizeX,sizeY,byte mainAreaType,dword mainAreaColour,byte headerType,dword headerColour,EDI)
  501. {
  502.         EAX = 12;              // function 12:tell os about windowdraw
  503.         EBX = 1;
  504.         $int 0x40
  505.        
  506.         EBX = x << 16 + sizeX;
  507.         ECX = y << 16 + sizeY;
  508.         EDX = mainAreaType << 24 | mainAreaColour;
  509.         ESI = headerType << 24 | headerColour;
  510.         $xor eax,eax
  511.         $int 0x40
  512.  
  513.         EAX = 12;              // function 12:tell os about windowdraw
  514.         EBX = 2;
  515.         $int 0x40
  516. }
  517.  
  518.  
  519. inline fastcall dword CreateThread(dword ECX,EDX)
  520. {
  521.         EAX = 51;
  522.         EBX = 1;
  523.         $int 0x40
  524. }
  525.  
  526. inline fastcall int GetSlot(dword ECX)
  527. {
  528.         EAX = 18;
  529.         EBX = 21;
  530.         $int 0x40
  531. }
  532.  
  533. inline fastcall int GetActiveProcess()
  534. {
  535.         EAX = 18;
  536.         EBX = 7;
  537.         $int 0x40
  538. }
  539.  
  540.  
  541. void WriteText(dword x,y,byte fontType, dword color, EDX, ESI)
  542. {
  543.         EAX = 4;
  544.         EBX = x<<16+y;
  545.         ECX = fontType<<24+color;
  546.         $int 0x40;
  547. }
  548.  
  549. void CopyScreen(dword EBX, x, y, sizeX, sizeY)
  550. {
  551.   EAX = 36;
  552.   ECX = sizeX << 16 + sizeY;
  553.   EDX = x << 16 + y;
  554.   $int  0x40;
  555. }
  556.  
  557. void PutImage(dword EBX,w,h,x,y)
  558. {
  559.         EAX = 7;
  560.         ECX = w<<16+h;
  561.         EDX = x<<16+y;
  562.         $int 0x40
  563. }
  564.  
  565. void PutPaletteImage(dword EBX,w,h,x,y,ESI,EDI)
  566. {
  567.         EAX = 65;
  568.         ECX = w<<16+h;
  569.         EDX = x<<16+y;
  570.         EBP = 0;
  571.         $int 0x40
  572. }
  573.  
  574. inline fastcall void PutPixel(dword EBX,ECX,EDX){
  575.   EAX=1;
  576.   $int 0x40
  577. }
  578.  
  579. void DrawBar(dword x,y,w,h,EDX)
  580. {
  581.         EAX = 13;
  582.         EBX = x<<16+w;
  583.         ECX = y<<16+h;
  584.         $int 0x40
  585. }
  586.  
  587. void DefineButton(dword x,y,w,h,EDX,ESI)
  588. {
  589.         EAX = 8;
  590.         EBX = x<<16+w;
  591.         ECX = y<<16+h;
  592.         $int 0x40
  593. }
  594.  
  595. inline fastcall void DeleteButton(dword EDX)
  596. {
  597.         EAX = 8;
  598.         EDX += BT_DEL;
  599.         $int 0x40;
  600. }
  601.  
  602. :void DrawRegion(dword x,y,width,height,color1)
  603. {
  604.         DrawBar(x,y,width,1,color1); //¯®«®á  £®à ᢥàåã
  605.         DrawBar(x,y+height,width,1,color1); //¯®«®á  £®à á­¨§ã
  606.         DrawBar(x,y,1,height,color1); //¯®«®á  ¢¥àåã á«¥¢ 
  607.         DrawBar(x+width,y,1,height+1,color1); //¯®«®á  ¢¥àåã á¯à ¢ 
  608. }
  609.  
  610. :void DrawRegion_3D(dword x,y,width,height,color1,color2)
  611. {
  612.         DrawBar(x,y,width+1,1,color1); //¯®«®á  £®à ᢥàåã
  613.         DrawBar(x,y+1,1,height-1,color1); //¯®«®á  á«¥¢ 
  614.         DrawBar(x+width,y+1,1,height,color2); //¯®«®á  á¯à ¢ 
  615.         DrawBar(x,y+height,width,1,color2); //¯®«®á  £®à á­¨§ã
  616. }
  617.  
  618. void DrawFlatButton(dword x,y,width,height,id,color,text)
  619. {
  620.         DrawRegion_3D(x,y,width,height,0x94AECE,0x94AECE);
  621.         DrawRegion_3D(x+1,y+1,width-2,height-2,0xFFFFFF,0xC7C7C7);
  622.         DrawBar(x+2,y+2,width-3,height-3,color); //§ «¨¢ª 
  623.         IF (id<>0)      DefineButton(x,y,width,height,id+BT_HIDE,0xEFEBEF); //ª­®¯ª 
  624.         WriteText(-strlen(text)*6+width/2+x+1,height/2-3+y,0x80,0,text,0);
  625. }
  626.  
  627. :void DrawCircle(int x, y, r)
  628. {
  629.         int i; float px=0, py=r, ii = r * 3.1415926 * 2;
  630.         FOR (i = 0; i < ii; i++)
  631.         {
  632.         PutPixel(px + x, y - py, 0);
  633.         px = py / r + px;
  634.         py = -px / r + py;
  635.                 //Pause(1);
  636.         }
  637. }
  638.  
  639. //------------------------------------------------------------------------------
  640.  
  641. inline fastcall dword WriteDebug(dword EDX)
  642. {
  643.         $push ebx
  644.         $push ecx
  645.         $mov eax, 63
  646.         $mov ebx, 1
  647. next_char:
  648.         $mov ecx, DSDWORD[edx]
  649.         $or      cl, cl
  650.         $jz  done
  651.         $int 0x40
  652.         $inc edx
  653.         $jmp next_char
  654. done:
  655.         $mov cl, 13
  656.         $int 0x40
  657.         $mov cl, 10
  658.         $int 0x40
  659.         $pop ecx
  660.         $pop ebx
  661. }
  662.