Subversion Repositories Kolibri OS

Rev

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