Subversion Repositories Kolibri OS

Rev

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

  1. //CODED by Veliant, Leency 2008-2012. GNU GPL licence.
  2.  
  3. #startaddress 0
  4. #code32 TRUE
  5.  
  6. byte   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    = 0x00070000;
  11. dword  x86esp_reg   = 0x00070000;
  12. dword  I_Param      = #param;
  13. dword  I_Path       = #program_path;
  14.  
  15. char param[4096];
  16. char program_path[4096];
  17.  
  18.  
  19. //Events
  20. #define evMouse         6
  21. #define evButton        3
  22. #define evKey           2
  23. #define evReDraw        1
  24.  
  25. //Button options
  26. #define BT_DEL          0x80000000
  27. #define BT_HIDE         0x40000000
  28. #define BT_NOFRAME      0x20000000
  29.  
  30. #define OLD                     -1
  31. #define true            1
  32. #define false           0
  33.  
  34.  
  35.  
  36. struct mouse
  37. {
  38.         unsigned int x,y,lkm,pkm,hor,vert;
  39.         void get();
  40. };
  41.  
  42. inline fastcall int TestBit(EAX, CL)
  43. {
  44.         $shr eax,cl
  45.         $and eax,1
  46. }
  47.  
  48. void mouse::get()
  49. {
  50.         EAX = 37;
  51.         EBX = 1;
  52.         $int    0x40
  53.         $mov    ebx, eax
  54.         $shr    eax, 16
  55.         $and    ebx,0x0000FFFF
  56.         x = EAX;
  57.         y = EBX;
  58.        
  59.         EAX = 37;
  60.         EBX = 2;
  61.         $int    0x40
  62.         $mov    ebx, eax
  63.         $and    eax, 0x00000001
  64.         $shr    ebx, 1
  65.         $and    ebx, 0x00000001
  66.         lkm = EAX;
  67.         pkm = EBX;
  68.        
  69.         EAX = 37; //scroll
  70.         EBX = 7;
  71.         $int    0x40
  72.         $mov    ebx, eax
  73.         $shr    eax, 16
  74.         $and    ebx,0x0000FFFF
  75.         //hor = EAX;
  76.         vert = EBX;
  77. }
  78.  
  79. //---------------------------------------------------------------------------
  80. struct proc_info
  81. {
  82.         #define SelfInfo -1
  83.         dword   use_cpu;
  84.         word    pos_in_stack,num_slot,rezerv1;
  85.         char    name[11];
  86.         char    rezerv2;
  87.         dword   adress,use_memory,ID,left,top,width,height;
  88.         word    status_slot,rezerv3;
  89.         dword   work_left,work_top,work_width,work_height;
  90.         char    status_window;
  91.         void    GetInfo( ECX);
  92.         byte    reserved[1024-71];
  93. };
  94.  
  95. void proc_info::GetInfo( EBX, ECX)
  96. {
  97.         $mov eax,9;
  98.         $int 0x40
  99. }
  100.  
  101. inline fastcall int GetSlot( ECX)
  102. {
  103.         $mov eax,18;
  104.         $mov ebx,21;
  105.         $int 0x40
  106. }
  107.  
  108. inline fastcall int ActiveProcess()
  109. {
  110.         $mov eax,18;
  111.         $mov ebx,7;
  112.         $int 0x40
  113. }
  114.  
  115. //-------------------------------------------------------------------------------
  116.  
  117. inline fastcall dword WaitEvent(){
  118.         $mov eax,10;
  119.         $int 0x40
  120. }
  121.  
  122. inline fastcall void SetEventMask( EBX)
  123. {
  124.         EAX = 40;
  125.         $int 0x40
  126. }
  127.  
  128. inline fastcall word GetKey(){ //+Gluk fix
  129.                 $push edx
  130. @getkey:
  131.                 $mov  eax,2
  132.                 $int  0x40
  133.                 $cmp eax,1
  134.                 $jne getkeyi
  135.                 $mov ah,dh
  136.                 $jmp getkeyii //jz?
  137. @getkeyi:
  138.                 $mov dh,ah
  139.                 $jmp getkey
  140. @getkeyii:
  141.                 $pop edx
  142.                 EAX = EAX >> 8;          
  143. }
  144.  
  145. inline fastcall word GetButtonID(){
  146.         EAX = 17;            // Get ID
  147.         $int  0x40
  148.         EAX = EAX >> 8;
  149. }
  150.  
  151. inline fastcall void ExitProcess(){
  152.         EAX = -1;            // close this program
  153.         $int 0x40
  154. }
  155.  
  156. inline fastcall void Pause(dword EBX){                         
  157.         $mov eax, 5
  158.         $int 0x40
  159. }
  160.  
  161. //------------------------------------------------------------------------------
  162. void DefineAndDrawWindow(dword x,y,sizeX,sizeY,byte mainAreaType,
  163. dword mainAreaColour,byte headerType,dword headerColour,EDI)
  164. {
  165.         EAX = 12;              // function 12:tell os about windowdraw
  166.         EBX = 1;
  167.         $int 0x40
  168.        
  169.         EBX = x << 16 + sizeX;
  170.         ECX = y << 16 + sizeY;
  171.         EDX = mainAreaType << 24 | mainAreaColour;
  172.         ESI = headerType << 24 | headerColour;
  173.         $xor eax,eax
  174.         $int 0x40
  175.  
  176.         EAX = 12;              // function 12:tell os about windowdraw
  177.         EBX = 2;
  178.         $int 0x40
  179. }
  180.  
  181. inline fastcall void CreateThread( ECX,EDX)
  182. {
  183.         EAX = 51;
  184.         EBX = 1;
  185.         $int 0x40
  186. }
  187.  
  188. inline fastcall void DrawTitle( ECX){
  189.         EAX = 71;
  190.         EBX = 1;
  191.         $int 0x40;
  192. }
  193.  
  194. inline fastcall dword GetSkinWidth(){
  195.         EAX = 48;
  196.         EBX = 4;
  197.         $int 0x40
  198. }
  199.  
  200. inline fastcall dword GetScreenHeight()
  201. {
  202.         EAX = 14;
  203.         EBX = 4;
  204.         $int 0x40
  205.         //$shr eax, 16
  206.         $and eax,0x0000FFFF
  207. }
  208.  
  209. inline fastcall void MoveSize( EBX,ECX,EDX,ESI){
  210.         $mov eax,67;
  211.         $int 0x40
  212. }
  213.  
  214. //------------------------------------------------------------------------------
  215.  
  216. inline fastcall dword strlen( EDI)
  217. {
  218.         asm {
  219.           xor ecx, ecx
  220.           xor eax, eax
  221.           dec ecx
  222.           repne scasb
  223.           sub eax, 2
  224.           sub eax, ecx
  225.         }
  226. }
  227.  
  228.  
  229. inline fastcall copystr( ESI,EDI)
  230. {
  231.         $cld
  232. l1:
  233.         $lodsb
  234.         $stosb
  235.         $test al,al
  236.         $jnz l1
  237. }
  238.  
  239. char buffer[11];
  240. inline fastcall dword IntToStr( ESI)
  241. {
  242.      $mov     edi, #buffer
  243.      $mov     ecx, 10
  244.      $test     esi, esi
  245.      $jns     f1
  246.      $mov     al, '-'
  247.      $stosb
  248.      $neg     esi
  249. f1:
  250.      $mov     eax, esi
  251.      $push     -'0'
  252. f2:
  253.      $xor     edx, edx
  254.      $div     ecx
  255.      $push     edx
  256.      $test     eax, eax
  257.      $jnz     f2
  258. f3:
  259.      $pop     eax
  260.      $add     al, '0'
  261.      $stosb
  262.      $jnz     f3
  263.      $mov     eax, #buffer
  264.      $ret
  265. }
  266.  
  267. inline fastcall dword StrToInt()
  268. {
  269.         ESI=EDI=EAX;
  270.         IF(DSBYTE[ESI]=='-')ESI++;
  271.         EAX=0;
  272.         BH=AL;
  273.         do{
  274.                 BL=DSBYTE[ESI]-'0';
  275.                 EAX=EAX*10+EBX;
  276.                 ESI++;
  277.         }while(DSBYTE[ESI]>0);
  278.         IF(DSBYTE[EDI]=='-') -EAX;
  279. }
  280.  
  281. dword StrToCol(char* htmlcolor)
  282. {
  283.   dword j, color=0;
  284.   char ch=0x00;
  285.  
  286.   FOR (j=0; j<6; j++)
  287.   {
  288.     ch=ESBYTE[htmlcolor+j];
  289.     IF ((ch>='0') && (ch<='9')) ch -= '0';
  290.     IF ((ch>='A') && (ch<='F')) ch -= 'A'-10;
  291.     IF ((ch>='a') && (ch<='f')) ch -= 'a'-10;
  292.     color = color*0x10 + ch;
  293.   }
  294.  
  295.   return color;
  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.  
  311. inline fastcall unsigned int find_symbol(ESI,BL)
  312. {
  313.         int jj=0, last=-1;
  314.         do{
  315.                 jj++;
  316.                 $lodsb
  317.                 IF(AL==BL) last=jj;
  318.         } while(AL!=0);
  319.         return last;
  320. }
  321.  
  322.  
  323. inline fastcall ChangeCase( EDX)
  324. {
  325.         AL=DSBYTE[EDX];
  326.         IF(AL>='a')&&(AL<='z')DSBYTE[EDX]=AL&0x5f;
  327.         IF (AL>=160) && (AL<=175) DSBYTE[EDX] = AL - 32;        //à-ï
  328.         IF (AL>=224) && (AL<=239) DSBYTE[EDX] = AL - 80;        //à-ï
  329.         do{
  330.                 EDX++;
  331.                 AL=DSBYTE[EDX];
  332.                 IF(AL>='A')&&(AL<='Z'){DSBYTE[EDX]=AL|0x20; CONTINUE;}
  333.                 IF(AL>='€')&&(AL<='')DSBYTE[EDX]=AL|0x20; // -¯
  334.                 IF (AL>=144) && (AL<=159) DSBYTE[EDX] = AL + 80;        //à-ï
  335.         }while(AL!=0);
  336. }
  337.  
  338.  
  339. //------------------------------------------------------------------------------
  340. inline fastcall void PutPixel( EBX,ECX,EDX)
  341. {
  342.   EAX=1;
  343.   $int 0x40
  344. }
  345.  
  346. void DefineButton(dword x,y,w,h,EDX,ESI)
  347. {
  348.         EAX = 8;
  349.         $push edx
  350.         EDX += BT_DEL; //âíà÷àëå óäàëÿåì êíîïó ñ ýòè èä, ïîòîì ñîçäà¸ì
  351.         $int 0x40;
  352.         EBX = x<<16+w;
  353.         ECX = y<<16+h;
  354.         $pop edx
  355.         $int 0x40
  356. }
  357.  
  358. inline fastcall void DeleteButton( EDX)
  359. {
  360.         EAX = 8;
  361.         EDX += BT_DEL;
  362.         $int 0x40;
  363. }
  364.  
  365. void WriteText(dword x,y,byte fontType, dword color, EDX, ESI)
  366. {
  367.         EAX = 4;
  368.         EBX = x<<16+y;
  369.         ECX = fontType<<24+color;
  370.         $int 0x40;
  371. }
  372.  
  373. void DrawBar(dword x,y,w,h,EDX)
  374. {
  375.         EAX = 13;
  376.         EBX = x<<16+w;
  377.         ECX = y<<16+h;
  378.         $int 0x40
  379. }
  380.  
  381. void DrawRegion_3D(dword x,y,width,height,color1,color2)
  382. {
  383.         DrawBar(x,y,width+1,1,color1);
  384.         DrawBar(x,y+1,1,height-1,color1);
  385.         DrawBar(x+width,y+1,1,height,color2);
  386.         DrawBar(x,y+height,width,1,color2);
  387. }
  388.  
  389. void DrawFlatButton(dword x,y,width,height,id,color,text)
  390. {
  391.         DrawRegion_3D(x,y,width,height,0x94AECE,0x94AECE);
  392.         DrawRegion_3D(x+1,y+1,width-2,height-2,0xFFFFFF,0xC7C7C7);
  393.         DrawBar(x+2,y+2,width-3,height-3,color);
  394.         IF (id<>0)      DefineButton(x+1,y+1,width-2,height-2,id+BT_HIDE,0xEFEBEF);
  395.         WriteText(-strlen(text)*6+width/2+x+1,height/2-3+y,0x80,0,text,0);
  396. }
  397.  
  398. void PutPaletteImage(dword EBX,w,h,x,y, EDI)
  399. {
  400.         EAX = 65;
  401.         ECX = w<<16+h;
  402.         EDX = x<<16+y;
  403.         ESI = 8;
  404.         EBP = 0;
  405.         $int 0x40
  406. }
  407.  
  408. void PutImage(dword EBX,w,h,x,y)
  409. {
  410.         EAX = 7;
  411.         ECX = w<<16+h;
  412.         EDX = x<<16+y;
  413.         $int 0x40
  414. }
  415.  
  416. //------------------------------------------------------------------------------
  417. inline fastcall void debug( EDX)
  418. {
  419.         $mov eax, 63
  420.         $mov ebx, 1
  421. next_char:
  422.         $mov ecx, DSDWORD[edx]
  423.         $or      cl, cl
  424.         $jz  done
  425.         $int 0x40
  426.         $inc edx
  427.         $jmp next_char
  428. done:
  429.         $mov cl, 13
  430.         $int 0x40
  431.         $mov cl, 10
  432.         $int 0x40
  433. }
  434.  
  435. inline fastcall void WriteFullDebug( ESI)
  436. {
  437.         WriteDebug("");
  438.         WriteDebug(ESI);
  439.        
  440.         WriteDebug("Number of files:");
  441.         WriteDebug(IntToStr(count));
  442.        
  443.         WriteDebug("but_num:");
  444.         WriteDebug(IntToStr(but_num));
  445.        
  446.         WriteDebug("curbtn");
  447.         WriteDebug(IntToStr(curbtn));
  448.        
  449.         WriteDebug("ra_kadrom:");
  450.         WriteDebug(IntToStr(za_kadrom));
  451.        
  452.         Pause(200);
  453. }