Subversion Repositories Kolibri OS

Rev

Rev 2814 | 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( EBX){                              
  157.         $mov eax, 5
  158.         $int 0x40
  159. }
  160.  
  161. //------------------------------------------------------------------------------
  162. void DefineAndDrawWindow(dword x,y,sizeX,sizeY,byte mainAreaType, dword mainAreaColour, EDI)
  163. {
  164.         EAX = 12;              // function 12:tell os about windowdraw
  165.         EBX = 1;
  166.         $int 0x40
  167.        
  168.         EBX = x << 16 + sizeX;
  169.         ECX = y << 16 + sizeY;
  170.         EDX = mainAreaType << 24 | mainAreaColour;
  171.         $xor eax,eax
  172.         $int 0x40
  173.  
  174.         EAX = 12;              // function 12:tell os about windowdraw
  175.         EBX = 2;
  176.         $int 0x40
  177. }
  178.  
  179. inline fastcall void CreateThread( ECX,EDX)
  180. {
  181.         EAX = 51;
  182.         EBX = 1;
  183.         $int 0x40
  184. }
  185.  
  186. inline fastcall void DrawTitle( ECX){
  187.         EAX = 71;
  188.         EBX = 1;
  189.         $int 0x40;
  190. }
  191.  
  192. inline fastcall dword GetSkinHeight()
  193. {
  194.         $push ebx
  195.         $mov  eax,48
  196.         $mov  ebx,4
  197.         $int 0x40
  198.         $pop  ebx
  199. }
  200.  
  201. inline fastcall dword GetScreenHeight()
  202. {
  203.         EAX = 14;
  204.         $int 0x40
  205.         $and eax,0x0000FFFF
  206. }
  207.  
  208. inline fastcall void MoveSize( EBX,ECX,EDX,ESI){
  209.         $mov eax,67;
  210.         $int 0x40
  211. }
  212.  
  213. //------------------------------------------------------------------------------
  214.  
  215. inline fastcall dword strlen( EDI)
  216. {
  217.         asm {
  218.           xor ecx, ecx
  219.           xor eax, eax
  220.           dec ecx
  221.           repne scasb
  222.           sub eax, 2
  223.           sub eax, ecx
  224.         }
  225. }
  226.  
  227.  
  228. inline fastcall copystr( ESI,EDI)
  229. {
  230.         $cld
  231. l1:
  232.         $lodsb
  233.         $stosb
  234.         $test al,al
  235.         $jnz l1
  236. }
  237.  
  238. char buffer[11];
  239. inline fastcall dword IntToStr( ESI)
  240. {
  241.      $mov     edi, #buffer
  242.      $mov     ecx, 10
  243.      $test     esi, esi
  244.      $jns     f1
  245.      $mov     al, '-'
  246.      $stosb
  247.      $neg     esi
  248. f1:
  249.      $mov     eax, esi
  250.      $push     -'0'
  251. f2:
  252.      $xor     edx, edx
  253.      $div     ecx
  254.      $push     edx
  255.      $test     eax, eax
  256.      $jnz     f2
  257. f3:
  258.      $pop     eax
  259.      $add     al, '0'
  260.      $stosb
  261.      $jnz     f3
  262.      $mov     eax, #buffer
  263.      $ret
  264. }
  265.  
  266. inline fastcall dword StrToInt()
  267. {
  268.         ESI=EDI=EAX;
  269.         IF(DSBYTE[ESI]=='-')ESI++;
  270.         EAX=0;
  271.         BH=AL;
  272.         do{
  273.                 BL=DSBYTE[ESI]-'0';
  274.                 EAX=EAX*10+EBX;
  275.                 ESI++;
  276.         }while(DSBYTE[ESI]>0);
  277.         IF(DSBYTE[EDI]=='-') -EAX;
  278. }
  279.  
  280. dword StrToCol(char* htmlcolor)
  281. {
  282.   dword j, color=0;
  283.   char ch=0x00;
  284.  
  285.   FOR (j=0; j<6; j++)
  286.   {
  287.     ch=ESBYTE[htmlcolor+j];
  288.     IF ((ch>='0') && (ch<='9')) ch -= '0';
  289.     IF ((ch>='A') && (ch<='F')) ch -= 'A'-10;
  290.     IF ((ch>='a') && (ch<='f')) ch -= 'a'-10;
  291.     color = color*0x10 + ch;
  292.   }
  293.  
  294.   return color;
  295. }
  296.  
  297. inline fastcall int strcmp(ESI, EDI)
  298. {
  299.         loop()
  300.         {
  301.                 IF (DSBYTE[ESI]<DSBYTE[EDI]) RETURN -1;
  302.                 IF (DSBYTE[ESI]>DSBYTE[EDI]) RETURN 1;
  303.                 IF (DSBYTE[ESI]=='\0') RETURN 0;
  304.                 ESI++;
  305.                 EDI++;
  306.         }
  307. }
  308.  
  309.  
  310. inline fastcall signed int strncmp( ESI, EDI, ECX)
  311. {
  312.   asm {
  313.     MOV EBX, EDI
  314.     XOR EAX, EAX
  315.     MOV EDX, ECX
  316.     OR ECX, ECX
  317.     JE L1
  318.     REPNE SCASB
  319.     SUB EDX, ECX
  320.     MOV ECX, EDX
  321.     MOV EDI, EBX
  322.     XOR EBX, EBX
  323.     REPE CMPSB
  324.     MOV AL, DSBYTE[ ESI-1]
  325.     MOV BL, DSBYTE[ EDI-1]
  326.     SUB EAX, EBX
  327. L1:
  328.   }
  329. }
  330.  
  331.  
  332. inline fastcall unsigned int strchr(ESI,BL)
  333. {
  334.         int jj=0, last=-1;
  335.         do{
  336.                 jj++;
  337.                 $lodsb
  338.                 IF(AL==BL) last=jj;
  339.         } while(AL!=0);
  340.         return last;
  341. }
  342.  
  343.  
  344. inline fastcall TitleCase( EDX)
  345. {
  346.         AL=DSBYTE[EDX];
  347.         IF(AL>='a')&&(AL<='z')DSBYTE[EDX]=AL&0x5f;
  348.         IF (AL>=160) && (AL<=175) DSBYTE[EDX] = AL - 32;        //à-ï
  349.         IF (AL>=224) && (AL<=239) DSBYTE[EDX] = AL - 80;        //à-ï
  350.         do{
  351.                 EDX++;
  352.                 AL=DSBYTE[EDX];
  353.                 IF(AL>='A')&&(AL<='Z'){DSBYTE[EDX]=AL|0x20; CONTINUE;}
  354.                 IF(AL>='€')&&(AL<='')DSBYTE[EDX]=AL|0x20; // -¯
  355.                 IF (AL>=144) && (AL<=159) DSBYTE[EDX] = AL + 80;        //à-ï
  356.         }while(AL!=0);
  357. }
  358.  
  359.  
  360. //------------------------------------------------------------------------------
  361. inline fastcall void PutPixel( EBX,ECX,EDX)
  362. {
  363.   EAX=1;
  364.   $int 0x40
  365. }
  366.  
  367. void DefineButton(dword x,y,w,h,EDX,ESI)
  368. {
  369.         EAX = 8;
  370.         $push edx
  371.         EDX += BT_DEL; //âíà÷àëå óäàëÿåì êíîïó ñ ýòè èä, ïîòîì ñîçäà¸ì
  372.         $int 0x40;
  373.         EBX = x<<16+w;
  374.         ECX = y<<16+h;
  375.         $pop edx
  376.         $int 0x40
  377. }
  378.  
  379. inline fastcall void DeleteButton( EDX)
  380. {
  381.         EAX = 8;
  382.         EDX += BT_DEL;
  383.         $int 0x40;
  384. }
  385.  
  386. void WriteText(dword x,y,byte fontType, dword color, EDX, ESI)
  387. {
  388.         EAX = 4;
  389.         EBX = x<<16+y;
  390.         ECX = fontType<<24+color;
  391.         $int 0x40;
  392. }
  393.  
  394. void DrawBar(dword x,y,w,h,EDX)
  395. {
  396.         EAX = 13;
  397.         EBX = x<<16+w;
  398.         ECX = y<<16+h;
  399.         $int 0x40
  400. }
  401.  
  402. void DrawRegion_3D(dword x,y,width,height,color1,color2)
  403. {
  404.         DrawBar(x,y,width+1,1,color1);
  405.         DrawBar(x,y+1,1,height-1,color1);
  406.         DrawBar(x+width,y+1,1,height,color2);
  407.         DrawBar(x,y+height,width,1,color2);
  408. }
  409.  
  410. void DrawFlatButton(dword x,y,width,height,id,color,text)
  411. {
  412.         DrawRegion_3D(x,y,width,height,0x94AECE,0x94AECE);
  413.         DrawRegion_3D(x+1,y+1,width-2,height-2,0xFFFFFF,0xC7C7C7);
  414.         DrawBar(x+2,y+2,width-3,height-3,color);
  415.         IF (id<>0)      DefineButton(x+1,y+1,width-2,height-2,id+BT_HIDE,0xEFEBEF);
  416.         WriteText(-strlen(text)*6+width/2+x+1,height/2-3+y,0x80,0,text,0);
  417. }
  418.  
  419. void PutPaletteImage(dword EBX,w,h,x,y, EDI)
  420. {
  421.         EAX = 65;
  422.         ECX = w<<16+h;
  423.         EDX = x<<16+y;
  424.         ESI = 8;
  425.         EBP = 0;
  426.         $int 0x40
  427. }
  428.  
  429. void PutImage(dword EBX,w,h,x,y)
  430. {
  431.         EAX = 7;
  432.         ECX = w<<16+h;
  433.         EDX = x<<16+y;
  434.         $int 0x40
  435. }
  436.  
  437. //------------------------------------------------------------------------------
  438. inline fastcall void debug( EDX)
  439. {
  440.         $push eax
  441.         $push ebx
  442.         $push ecx
  443.         $mov eax, 63
  444.         $mov ebx, 1
  445. next_char:
  446.         $mov ecx, DSDWORD[edx]
  447.         $or      cl, cl
  448.         $jz  done
  449.         $int 0x40
  450.         $inc edx
  451.         $jmp next_char
  452. done:
  453.         $mov cl, 13
  454.         $int 0x40
  455.         $mov cl, 10
  456.         $int 0x40
  457.         $pop eax
  458.         $pop ebx
  459.         $pop ecx
  460. }