Subversion Repositories Kolibri OS

Rev

Rev 2875 | 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. #define NULL            0
  35.  
  36.  
  37. struct mouse
  38. {
  39.         unsigned int x,y,lkm,pkm,hor,vert;
  40.         void get();
  41. };
  42.  
  43. inline fastcall int TestBit(EAX, CL)
  44. {
  45.         $shr eax,cl
  46.         $and eax,1
  47. }
  48.  
  49. void mouse::get()
  50. {
  51.         EAX = 37;
  52.         EBX = 1;
  53.         $int    0x40
  54.         $mov    ebx, eax
  55.         $shr    eax, 16
  56.         $and    ebx,0x0000FFFF
  57.         x = EAX;
  58.         y = EBX;
  59.        
  60.         EAX = 37;
  61.         EBX = 2;
  62.         $int    0x40
  63.         $mov    ebx, eax
  64.         $and    eax, 0x00000001
  65.         $shr    ebx, 1
  66.         $and    ebx, 0x00000001
  67.         lkm = EAX;
  68.         pkm = EBX;
  69.        
  70.         EAX = 37; //scroll
  71.         EBX = 7;
  72.         $int    0x40
  73.         $mov    ebx, eax
  74.         $shr    eax, 16
  75.         $and    ebx,0x0000FFFF
  76.         //hor = EAX;
  77.         vert = EBX;
  78. }
  79.  
  80. //---------------------------------------------------------------------------
  81. struct proc_info
  82. {
  83.         #define SelfInfo -1
  84.         dword   use_cpu;
  85.         word    pos_in_stack,num_slot,rezerv1;
  86.         char    name[11];
  87.         char    rezerv2;
  88.         dword   adress,use_memory,ID,left,top,width,height;
  89.         word    status_slot,rezerv3;
  90.         dword   work_left,work_top,work_width,work_height;
  91.         char    status_window;
  92.         void    GetInfo( ECX);
  93.         byte    reserved[1024-71];
  94. };
  95.  
  96. void proc_info::GetInfo( EBX, ECX)
  97. {
  98.         $mov eax,9;
  99.         $int 0x40
  100. }
  101.  
  102. inline fastcall int GetSlot( ECX)
  103. {
  104.         $mov eax,18;
  105.         $mov ebx,21;
  106.         $int 0x40
  107. }
  108.  
  109. inline fastcall int ActiveProcess()
  110. {
  111.         $mov eax,18;
  112.         $mov ebx,7;
  113.         $int 0x40
  114. }
  115.  
  116. //-------------------------------------------------------------------------------
  117.  
  118. inline fastcall dword WaitEvent(){
  119.         $mov eax,10;
  120.         $int 0x40
  121. }
  122.  
  123. inline fastcall void SetEventMask( EBX)
  124. {
  125.         EAX = 40;
  126.         $int 0x40
  127. }
  128.  
  129. inline fastcall word GetKey(){ //+Gluk fix
  130.                 $push edx
  131. @getkey:
  132.                 $mov  eax,2
  133.                 $int  0x40
  134.                 $cmp eax,1
  135.                 $jne getkeyi
  136.                 $mov ah,dh
  137.                 $jmp getkeyii //jz?
  138. @getkeyi:
  139.                 $mov dh,ah
  140.                 $jmp getkey
  141. @getkeyii:
  142.                 $pop edx
  143.                 EAX = EAX >> 8;          
  144. }
  145.  
  146. inline fastcall word GetButtonID(){
  147.         EAX = 17;            // Get ID
  148.         $int  0x40
  149.         EAX = EAX >> 8;
  150. }
  151.  
  152. inline fastcall void ExitProcess(){
  153.         EAX = -1;            // close this program
  154.         $int 0x40
  155. }
  156.  
  157. inline fastcall void Pause( EBX){                              
  158.         $mov eax, 5
  159.         $int 0x40
  160. }
  161.  
  162. //------------------------------------------------------------------------------
  163. void DefineAndDrawWindow(dword x,y,sizeX,sizeY,byte mainAreaType, dword mainAreaColour, 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.         $xor eax,eax
  173.         $int 0x40
  174.  
  175.         EAX = 12;              // function 12:tell os about windowdraw
  176.         EBX = 2;
  177.         $int 0x40
  178. }
  179.  
  180. inline fastcall void CreateThread( ECX,EDX)
  181. {
  182.         EAX = 51;
  183.         EBX = 1;
  184.         $int 0x40
  185. }
  186.  
  187. inline fastcall void DrawTitle( ECX){
  188.         EAX = 71;
  189.         EBX = 1;
  190.         $int 0x40;
  191. }
  192.  
  193. inline fastcall dword GetSkinHeight()
  194. {
  195.         $push ebx
  196.         $mov  eax,48
  197.         $mov  ebx,4
  198.         $int 0x40
  199.         $pop  ebx
  200. }
  201.  
  202. inline fastcall dword GetScreenHeight()
  203. {
  204.         EAX = 14;
  205.         $int 0x40
  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 signed int strncmp( ESI, EDI, ECX)
  312. {
  313.   asm {
  314.     MOV EBX, EDI
  315.     XOR EAX, EAX
  316.     MOV EDX, ECX
  317.     OR ECX, ECX
  318.     JE L1
  319.     REPNE SCASB
  320.     SUB EDX, ECX
  321.     MOV ECX, EDX
  322.     MOV EDI, EBX
  323.     XOR EBX, EBX
  324.     REPE CMPSB
  325.     MOV AL, DSBYTE[ ESI-1]
  326.     MOV BL, DSBYTE[ EDI-1]
  327.     SUB EAX, EBX
  328. L1:
  329.   }
  330. }
  331.  
  332.  
  333. inline fastcall unsigned int strchr(ESI,BL)
  334. {
  335.         int jj=0, last=-1;
  336.         do{
  337.                 jj++;
  338.                 $lodsb
  339.                 IF(AL==BL) last=jj;
  340.         } while(AL!=0);
  341.         return last;
  342. }
  343.  
  344.  
  345. inline fastcall TitleCase( EDX)
  346. {
  347.         AL=DSBYTE[EDX];
  348.         IF(AL>='a')&&(AL<='z')DSBYTE[EDX]=AL&0x5f;
  349.         IF (AL>=160) && (AL<=175) DSBYTE[EDX] = AL - 32;        //à-ï
  350.         IF (AL>=224) && (AL<=239) DSBYTE[EDX] = AL - 80;        //à-ï
  351.         do{
  352.                 EDX++;
  353.                 AL=DSBYTE[EDX];
  354.                 IF(AL>='A')&&(AL<='Z'){DSBYTE[EDX]=AL|0x20; CONTINUE;}
  355.                 IF(AL>='€')&&(AL<='')DSBYTE[EDX]=AL|0x20; // -¯
  356.                 IF (AL>=144) && (AL<=159) DSBYTE[EDX] = AL + 80;        //à-ï
  357.         }while(AL!=0);
  358. }
  359.  
  360.  
  361. //------------------------------------------------------------------------------
  362. inline fastcall void PutPixel( EBX,ECX,EDX)
  363. {
  364.   EAX=1;
  365.   $int 0x40
  366. }
  367.  
  368. void DefineButton(dword x,y,w,h,EDX,ESI)
  369. {
  370.         EAX = 8;
  371.         $push edx
  372.         EDX += BT_DEL; //âíà÷àëå óäàëÿåì êíîïó ñ ýòè èä, ïîòîì ñîçäà¸ì
  373.         $int 0x40;
  374.         EBX = x<<16+w;
  375.         ECX = y<<16+h;
  376.         $pop edx
  377.         $int 0x40
  378. }
  379.  
  380. inline fastcall void DeleteButton( EDX)
  381. {
  382.         EAX = 8;
  383.         EDX += BT_DEL;
  384.         $int 0x40;
  385. }
  386.  
  387. void WriteText(dword x,y,byte fontType, dword color, EDX, ESI)
  388. {
  389.         EAX = 4;
  390.         EBX = x<<16+y;
  391.         ECX = fontType<<24+color;
  392.         $int 0x40;
  393. }
  394.  
  395. void DrawBar(dword x,y,w,h,EDX)
  396. {
  397.         EAX = 13;
  398.         EBX = x<<16+w;
  399.         ECX = y<<16+h;
  400.         $int 0x40
  401. }
  402.  
  403. void DrawRegion_3D(dword x,y,width,height,color1,color2)
  404. {
  405.         DrawBar(x,y,width+1,1,color1);
  406.         DrawBar(x,y+1,1,height-1,color1);
  407.         DrawBar(x+width,y+1,1,height,color2);
  408.         DrawBar(x,y+height,width,1,color2);
  409. }
  410.  
  411. void DrawFlatButton(dword x,y,width,height,id,color,text)
  412. {
  413.         DrawRegion_3D(x,y,width,height,0x94AECE,0x94AECE);
  414.         DrawRegion_3D(x+1,y+1,width-2,height-2,0xFFFFFF,0xC7C7C7);
  415.         DrawBar(x+2,y+2,width-3,height-3,color);
  416.         IF (id<>0)      DefineButton(x+1,y+1,width-2,height-2,id+BT_HIDE,0xEFEBEF);
  417.         WriteText(-strlen(text)*6+width/2+x+1,height/2-3+y,0x80,0,text,0);
  418. }
  419.  
  420. void PutPaletteImage(dword EBX,w,h,x,y, EDI)
  421. {
  422.         EAX = 65;
  423.         ECX = w<<16+h;
  424.         EDX = x<<16+y;
  425.         ESI = 8;
  426.         EBP = 0;
  427.         $int 0x40
  428. }
  429.  
  430. void PutImage(dword EBX,w,h,x,y)
  431. {
  432.         EAX = 7;
  433.         ECX = w<<16+h;
  434.         EDX = x<<16+y;
  435.         $int 0x40
  436. }
  437.  
  438. //------------------------------------------------------------------------------
  439. inline fastcall void debug( EDX)
  440. {
  441.         $push eax
  442.         $push ebx
  443.         $push ecx
  444.         $mov eax, 63
  445.         $mov ebx, 1
  446. next_char:
  447.         $mov ecx, DSDWORD[edx]
  448.         $or      cl, cl
  449.         $jz  done
  450.         $int 0x40
  451.         $inc edx
  452.         $jmp next_char
  453. done:
  454.         $mov cl, 13
  455.         $int 0x40
  456.         $mov cl, 10
  457.         $int 0x40
  458.         $pop eax
  459.         $pop ebx
  460.         $pop ecx
  461. }