Subversion Repositories Kolibri OS

Rev

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

  1. //#startaddress 0
  2. #code32 TRUE
  3.  
  4. char   os_name[8]   = {'M','E','N','U','E','T','0','1'};
  5. dword  os_version   = 0x00000001;
  6. dword  start_addr   = #main;
  7. dword  final_addr   = #stop+32;
  8. dword  alloc_mem    = 0x00100000;
  9. dword  x86esp_reg   = 0x0007fff0;
  10. dword  I_Param      = 0x0;
  11. dword  I_Icon       = 0x0;
  12. dword                   skin_width;
  13.  
  14. // KeyCode constant
  15. #define UP_KEY     130+48
  16. #define DOWN_KEY   129+48
  17. #define LEFT_KEY   128+48
  18. #define RIGHT_KEY  131+48
  19. #define RETURN_KEY 13
  20.  
  21. // Color constant
  22. #define clWhite 0x00ffffff
  23. #define clBlack 0x00000000
  24. #define clRed   0x00ff0000
  25. #define clGreen 0x0000ff00
  26. #define clBlue  0x000000ff
  27.  
  28. #define evButton  3
  29. #define evKey     2
  30. #define evReDraw  1
  31. #define evNet     8
  32.  
  33. #define BT_DEL          0x80000000
  34. #define BT_HIDE         0x40000000
  35. #define BT_NOFRAME      0x20000000
  36.  
  37. #define OLD                     -1
  38.  
  39. struct FileInfo{
  40.  dword read, firstBlock, qnBlockRead, retPtr, Work;
  41.  byte  filedir;
  42. };
  43. //-------------------------------------------------------------------------
  44. struct system_colors{
  45.         dword frame,grab,grab_button,grab_button_text,grab_text,work,work_button,work_button_text,work_text,work_graph;
  46.         void get();
  47. };
  48. void system_colors::get()
  49. {
  50.         EAX = 48;
  51.         EBX = 3;
  52.         ECX = #frame;
  53.         EDX = 40;
  54.         $int    0x40
  55. }
  56.  
  57. struct mouse
  58. {
  59.  dword x,y,lkm,pkm;
  60.  void get();
  61. };
  62.  
  63. void mouse::get()
  64. {
  65.         EAX = 37;
  66.         EBX = 1;
  67.         $int    0x40
  68.         $mov    ebx, eax
  69.         $shr    eax, 16
  70.         $and    ebx,0x0000FFFF
  71.         x = EAX;
  72.         y = EBX;
  73.         EAX = 37;
  74.         EBX = 2;
  75.         $int    0x40
  76.         $mov    ebx, eax
  77.         $and    eax, 0x00000001
  78.         $shr    ebx, 1
  79.         $and    ebx, 0x00000001
  80.         lkm = EAX;
  81.         pkm = EBX;
  82.        
  83. }
  84. //---------------------------------------------------------------------------
  85. struct f70{
  86.         dword   func;
  87.         dword   param1;
  88.         dword   param2;
  89.         dword   param3;
  90.         dword   param4;
  91.         char    rezerv;
  92.         dword   name;
  93. };
  94. //---------------------------------------------------------------------------
  95. struct BDVK{
  96.         dword   attr;
  97.         byte    type_name;
  98.         byte    rez1, rez2, rez3;
  99.         dword   timecreate;
  100.         dword   datecreate;
  101.         dword   timelastaccess;
  102.         dword   datelastaccess;
  103.         dword   timelastedit;
  104.         dword   datelastedit;
  105.         dword   sizelo;
  106.         dword   sizehi;
  107.         char    name[518];
  108. };
  109. //---------------------------------------------------------------------------
  110. struct proc_info{
  111.         dword   use_cpu;
  112.         word    pos_in_stack,num_slot,rezerv1;
  113.         char    name[11];
  114.         char    rezerv2;
  115.         dword   adress,use_memory,ID,left,top,width,height;
  116.         word    status_slot,rezerv3;
  117.         dword   work_left,work_top,work_width,work_height;
  118.         char    status_window;
  119.         void    getme();
  120. };
  121.  
  122. void proc_info::getme()
  123. {
  124.         EAX = 9;
  125.         EBX = #use_cpu;
  126.         ECX = -1;
  127.         $int    0x40
  128. }
  129. //-------------------------------------------------------------------------------
  130.  
  131. inline fastcall void begin_paint(){
  132. #speed
  133.  EAX = 12;              // function 12:tell os about windowdraw
  134.  EBX = 1;               // 1, start of draw
  135.  $int 0x40
  136. #codesize
  137. }
  138.  
  139. inline fastcall void end_paint(){
  140. #speed
  141.  EAX = 12;              // function 12:tell os about windowdraw
  142.  EBX = 2;               // 1, start of draw
  143.  $int 0x40
  144. #codesize
  145. }
  146.  
  147. /*
  148.  Žâà¨á®¢ª  ®ª­ 
  149.   {x_start|y_start}, {x_size|y_size}, color_back, color_title, color_frames
  150.  
  151.  DrawWindow(
  152.              EBX = [x_start][x_size]
  153.              ECX = [y_start][y_size]
  154.              EDX, ESI, EDI = [00RRGGBB]
  155.            )
  156. */
  157.  
  158. inline fastcall void DrawWindow(dword EBX, ECX, EDX, ESI, EDI){
  159. #speed
  160.  EAX = 0;               // function 0 : define and draw window
  161.  $int 0x40
  162. #codesize
  163. }
  164.  
  165. inline fastcall void DrawButton(dword EBX, ECX, EDX, ESI){
  166. #speed
  167.  EAX = 8;
  168.  $int 0x40
  169. #codesize
  170. }
  171.  
  172. inline fastcall dword WaitEvent(){
  173. #speed
  174.  EAX = 10;              // wait here for event
  175.  $int 0x40
  176. #codesize
  177. }
  178.  
  179. inline fastcall void ExitProcess(){
  180. #speed
  181.  EAX = -1;              // close this program
  182.  $int 0x40
  183. #codesize
  184. }
  185.  
  186. /*
  187. 02 = GET KEY
  188.  
  189.      ret: al 0 successful -> ah = key
  190.           al 1 no key in buffer
  191. */
  192. inline fastcall word GetKey(){
  193. #speed
  194.  EAX = 2;              // just read it key from buffer
  195.  $int  0x40
  196.  EAX = EAX >> 8;
  197. #codesize
  198. }
  199.  
  200. /*
  201. 17 = GET PRESSED BUTTON ID
  202.  
  203.      ret: al 0 successful -> ah = id number
  204.           al 1 no key in buffer
  205. */
  206. inline fastcall word GetButtonID(){
  207. #speed
  208.  EAX = 17;            // Get ID
  209.  $int  0x40
  210.  EAX = EAX >> 8;
  211. #codesize
  212. }
  213.  
  214. /*
  215. 58 = SYSTEM TREE ACCESS
  216.  
  217.      ebx    pointer to fileinfo block
  218.  
  219.      fileinfo:
  220.  
  221.      dd   0x0                  ; 0=read (/write/delete/append)
  222.      dd   0x0                  ; 512 block to read 0+
  223.      dd   0x1                  ; blocks to read (/bytes to write/append)
  224.      dd   0x20000              ; return data pointer
  225.      dd   0x10000              ; work area for os - 16384 bytes
  226.      db   '/RAMDISK/FIRST/KERNEL.ASM',0  ; ASCIIZ dir & filename
  227. */
  228. inline fastcall void AccessSystemTree(dword EBX){
  229. #speed
  230.  EAX = 58;
  231.  $int 0x40
  232. #codesize
  233. }
  234.  
  235. /*
  236. 04 = WRITE TEXT TO WINDOW
  237.  
  238.      ebx [x start]*65536 + [y start]
  239.      ecx text color 0x00RRGGBB
  240.      edx pointer to text beginning
  241.      esi text length
  242.      ret: nothing changed
  243. */
  244. inline fastcall void WriteTextXY(dword EBX, ECX, EDX, ESI){
  245. #speed
  246.  EAX = 4;
  247.  $int 0x40;
  248. #codesize
  249. }
  250.  
  251. /*
  252. 13 = DRAW BAR
  253.  
  254.      ebx [x start]*65536 + [x size]
  255.      ecx [y start]*65536 + [y size]
  256.      edx color 0x00RRGGBB
  257.      ret: nothing changed
  258. */
  259. inline fastcall void kos_DrawBar(dword EBX, ECX, EDX){
  260. #speed
  261.  EAX = 13;
  262.  $int 0x40
  263. #codesize
  264. }
  265.  
  266. //CODED by Veliant
  267. /*eax = 38 - íîìåð ôóíêöèè
  268. ebx = [êîîðäèíàòà íà÷àëà ïî îñè x]*65536 + [êîîðäèíàòà êîíöà ïî îñè x]
  269. ecx = [êîîðäèíàòà íà÷àëà ïî îñè y]*65536 + [êîîðäèíàòà êîíöà ïî îñè y]
  270. edx = 0x00RRGGBB - öâåò
  271. edx = 0x01xxxxxx - ðèñîâàòü èíâåðñíûé îòðåçîê (ìëàäøèå 24 áèòà èãíîðèðóþòñÿ) */
  272. inline fastcall void DrawLine(dword EBX, ECX, EDX){
  273. #speed
  274.  EAX = 38;
  275.  $int 0x40
  276. #codesize
  277. }
  278.  
  279. inline fastcall void DrawTitle(dword ECX)
  280. {
  281. #speed
  282.         EAX = 71;
  283.         EBX = 1;
  284.         $int 0x40;
  285. #codesize
  286. }
  287.  
  288. inline fastcall dword GetSkinWidth()
  289. {
  290. #speed
  291.         EAX = 48;
  292.         EBX = 4;
  293.         $int 0x40
  294. #codesize
  295. }
  296.  
  297. inline fastcall dword GetScreenWidth()
  298. {
  299. #speed
  300.         EAX = 14;
  301.         EBX = 4;
  302.         $int 0x40
  303.         $shr eax, 16
  304.         $and eax,0x0000FFFF
  305. #codesize
  306. }
  307.  
  308. inline fastcall void DeleteButton(dword EDX)
  309. {
  310. #speed
  311.         EAX = 8;
  312.         EDX = EDX + BT_DEL;
  313.         $int 0x40;
  314. #codesize
  315. }
  316.  
  317. inline fastcall dword LoadLibrary(dword ECX)
  318. {
  319. #speed
  320.         $mov eax, 68
  321.         $mov ebx, 19
  322.         $int  0x40
  323. #codesize
  324. }
  325.  
  326. //function GetProcAdress(hLib:integer; name:string):integer;
  327. inline fastcall dword GetProcAdress(dword ECX, EAX)
  328. {
  329. #speed
  330. #codesize
  331. }
  332.  
  333. inline fastcall dword strlen(dword ESI)
  334. {
  335. #speed
  336.         int len=0;
  337.         while (AL=ESBYTE[ESI])
  338.         {
  339.                 len++;
  340.                 ESI++;
  341.         }
  342.         EAX=len;
  343. #codesize
  344. }
  345.  
  346. //-1 - íå ðàâíû
  347. // 0 - ðàâíû
  348. inline fastcall dword strcmp(dword ESI,EDI)
  349. {
  350. #speed
  351.         dword strcmp_i,ret,len1,len2,sovpadenij,str1,str2;
  352.         str1=ESI;
  353.         str2=EDI;
  354.         ret=-1;
  355.         sovpadenij=0;
  356.         len1=strlen(str1);
  357.         len2=strlen(str2);
  358.         if (len1==len2)
  359.         {
  360.                 for (strcmp_i=0;strcmp_i<len1;strcmp_i++)
  361.                 {
  362.                         EAX = str1+strcmp_i;
  363.                         EAX = ESBYTE[EAX];
  364.                         EBX = str2+strcmp_i;
  365.                         EBX = ESBYTE[EBX];
  366.                         if (EAX==EBX) sovpadenij++;
  367.                 }
  368.                 if (sovpadenij==len1) ret=0;
  369.         }
  370.         else ret=-1;
  371.         EAX = ret;
  372. #codesize
  373. }
  374.  
  375. inline fastcall dword upcase(dword ESI)
  376. {
  377. #speed
  378.         dword str, i;
  379.         str = ESI;
  380.         for (i=0;i<strlen(i);i++)
  381.         {
  382.                 EAX = str+i;
  383.                 EDX = ESBYTE[EAX];
  384.                 if (EDX>=97) && (EDX<=122) ESBYTE[str+i] = DL - 32;     //a-z
  385.                 if (EDX>=160) && (EDX<=175) ESBYTE[str+i] = DL - 32;    //à-ï
  386.                 if (EDX>=224) && (EDX<=239) ESBYTE[str+i] = DL - 80;    //ð-ÿ
  387.                 if (EDX == 241) ESBYTE[EAX] = 240;                                      //¸
  388.         }
  389.         EAX = str;
  390.         //EAX = ESDWORD[EAX];
  391.         //if (EAX != 0x5249443C) $int 3;
  392. #codesize
  393. }
  394.  
  395. inline fastcall dword lowcase(dword ESI)
  396. {
  397. #speed
  398.         dword str, i;
  399.         str = ESI;
  400.         for (i=0;i<strlen(i);i++)
  401.         {
  402.                 EAX = str+i;
  403.                 EDX = ESBYTE[EAX];
  404.                 if (EDX>=65) && (EDX<=90) ESBYTE[str+i] = DL + 32;      //a-z
  405.                 if (EDX>=128) && (EDX<=143) ESBYTE[str+i] = DL + 32;    //à-ï
  406.                 if (EDX>=144) && (EDX<=159) ESBYTE[str+i] = DL + 80;    //ð-ÿ
  407.                 if (EDX == 240) ESBYTE[EAX] = 241;                                      //¸
  408.         }
  409.         EAX = str;
  410.         //EAX = ESDWORD[EAX];
  411.         //if (EAX != 0x5249443C) $int 3;
  412. #codesize
  413. }
  414.  
  415. inline fastcall void dostowin (dword ESI)
  416. {
  417. #speed
  418.         dword stroka,dlina;
  419.         stroka = ESI;
  420.         while (BL=ESBYTE[ESI])
  421.         {
  422.                 if (BL>128)
  423.                         if (BL>=240)
  424.                                 ESBYTE[ESI] = BL - 16;
  425.                         else
  426.                                 ESBYTE[ESI] = BL - 64;
  427.                 ESI++;
  428.         }
  429. #codesize
  430. }
  431.  
  432. void WindowRedrawStatus(dword i)
  433. {
  434.         EAX = 12;              // function 12:tell os about windowdraw
  435.         EBX = i;               // 1, start of draw
  436.         $int 0x40
  437. }
  438.  
  439. void DefineAndDrawWindow(dword x,y,sizeX,sizeY,byte mainAreaType,dword mainAreaColour,byte headerType,dword headerColour,borderColour)
  440. {
  441.         dword arg1, arg2, arg3, arg4;
  442.  
  443.         //
  444.         arg1 = x << 16 + sizeX;
  445.         arg2 = y << 16 + sizeY;
  446.         arg3 = mainAreaType << 24 | mainAreaColour;
  447.         arg4 = headerType << 24 | headerColour;
  448.         //
  449.         $mov eax, 0
  450.         $mov ebx, arg1
  451.         $mov ecx, arg2
  452.         $mov edx, arg3
  453.         $mov esi, arg4
  454.         $mov edi, borderColour
  455.         $int 0x40
  456. }
  457. void DefineButton(dword x,y,w,h,id,color)
  458. {
  459.         DrawButton(x<<16+w, skin_width+y<<16+h, id, color);
  460. }
  461. void WriteText(dword x,y,byte fontType, dword color, text, len)
  462. {
  463.         EBX = x<<16+skin_width+y;
  464.         ECX = fontType<<24+color;
  465.         EDX = text;
  466.         ESI = len;
  467.         EAX = 4;
  468.         $int 0x40;
  469. }
  470. void DrawBar(dword x,y,w,h,color)
  471. {
  472.         kos_DrawBar(x<<16+w,skin_width+y<<16+h,color);
  473. }
  474.  
  475. void DrawRegion(dword x,y,width,height,color1)
  476. {
  477.         DrawBar(x,y,width,1,color1); //ïîëîñà ãîð ñâåðõó
  478.         DrawBar(x,y+height,width,1,color1); //ïîëîñà ãîð ñíèçó
  479.         DrawBar(x,y,1,height,color1); //ïîëîñà âåðò ñëåâà
  480.         DrawBar(x+width,y,1,height+1,color1); //ïîëîñà âåðò ñïðàâà
  481. }
  482.  
  483. void DrawFlatButton(dword x,y,width,height,id,color)
  484. {
  485.         DrawRegion(x,y,width,height,0x94AECE);
  486.         DrawBar(x+1,y+1,width-1,1,0xFFFFFF); //ïîëîñà ãîð áåëàÿ
  487.         DrawBar(x+1,y+height-1,width-2,1,0xC0C0C0); //òåíü âåðò
  488.         DrawBar(x+1,y+1,1,height-1,0xFFFFFF); //ïîëîñà âåðò áåëàÿ
  489.         DrawBar(x+width-1,y+2,1,height-2,0xC0C0C0); //òåíü âåðò
  490.         DrawBar(x+2,y+2,width-3,height-3,color); //çàëèâêà
  491.         if (id<>0)
  492.         {
  493.         DefineButton(x,y,width,height,id+BT_DEL,0xEFEBEF); //óäàëÿåì êíîïêó
  494.         DefineButton(x,y,width,height,id+BT_HIDE,0xEFEBEF); //îïðåäåëÿåì êíîïêó
  495.         }
  496. }
  497.  
  498. void PutImage(dword buf,w,h,x,y)
  499. {
  500.         int i,r,g,b;
  501.         EDI=buf;
  502.         EAX = 7;
  503.         EBX = buf;
  504.         ECX = w<<16+h;
  505.         EDX = x<<16+y+skin_width;
  506.         $int 0x40
  507. }
  508.  
  509. void copystr(dword s,d)
  510. {
  511.         ECX=strlen(d);//î÷èùàåì ñòàðîå
  512.         $mov edi,d
  513.         $xor al,al
  514.         $cld
  515.         $rep $stosb
  516.        
  517.         ECX=strlen(s);//êîïèðóåì
  518.         $mov esi,s
  519.         $mov edi,d
  520.         $cld
  521.         $rep $movsb
  522. }
  523. int             pos,razr,backup,j=0;
  524. char    buffer[11]="";
  525. int             chislo;
  526. inline fastcall dword IntToStr(dword ESI)
  527. {
  528. #speed
  529.         chislo=ESI;
  530.         ECX=12;
  531.         $push edi
  532.         $mov edi,#buffer
  533.         $xor al,al
  534.         $cld
  535.         $rep $stosb
  536.         pos=razr=backup=j=0;
  537.         if (chislo<0)
  538.         {
  539.                 buffer[pos]='-';
  540.                 chislo=-1*chislo;
  541.                 pos++;
  542.         }
  543.         backup=chislo;
  544.         do
  545.         {
  546.                 backup=backup/10;
  547.                 razr++;
  548.         }
  549.         while (backup!=0);
  550.         razr--;
  551.         for (j=razr+pos;j>pos-1;j--)
  552.         {
  553.                 backup=chislo/10;
  554.                 backup=backup*10;
  555.                 buffer[j]=chislo-backup+48;
  556.                 chislo=chislo/10;
  557.         }
  558.         //return #buffer;
  559.         $pop edi;
  560.         EAX = #buffer;
  561. #codesize
  562. }
  563.  
  564. inline fastcall dword MoveSize(dword EBX,ECX,EDX,ESI)
  565. {
  566. #speed
  567.         EAX = 67;
  568.         $int 0x40
  569. #codesize
  570. }
  571.  
  572. f70     CopyFile_f;
  573. BDVK CopyFile_atr;
  574. inline fastcall dword CopyFile(dword EBX,ECX)
  575. {
  576. #speed
  577.         dword s, d, buf;
  578.         s = EBX;
  579.         d = ECX;
  580.        
  581.         CopyFile_f.func = 5;
  582.         CopyFile_f.param1 = 0;
  583.         CopyFile_f.param2 = 0;
  584.         CopyFile_f.param3 = 0;
  585.         CopyFile_f.param4 = #CopyFile_atr;
  586.         CopyFile_f.rezerv = 0;
  587.         CopyFile_f.name = s;
  588.         $mov    eax, 70
  589.         $mov    ebx, #CopyFile_f
  590.         $int    0x40
  591.        
  592.         if (EAX == 0)
  593.         {      
  594.                 buf = malloc(CopyFile_atr.sizelo);     
  595.                 CopyFile_f.func = 0;
  596.                 CopyFile_f.param1 = 0;
  597.                 CopyFile_f.param2 = 0;
  598.                 CopyFile_f.param3 = CopyFile_atr.sizelo;
  599.                 CopyFile_f.param4 = buf;
  600.                 CopyFile_f.rezerv = 0;
  601.                 CopyFile_f.name = s;
  602.                 $mov    eax, 70
  603.                 $mov    ebx, #CopyFile_f
  604.                 $int    0x40
  605.        
  606.                 if (EAX == 0)
  607.                 {
  608.                         CopyFile_f.func = 2;
  609.                         CopyFile_f.param1 = 0;
  610.                         CopyFile_f.param2 = 0;
  611.                         CopyFile_f.param3 = CopyFile_atr.sizelo;
  612.                         CopyFile_f.param4 = buf;
  613.                         CopyFile_f.rezerv = 0;
  614.                         CopyFile_f.name = d;
  615.                         $mov    eax, 70
  616.                         $mov    ebx, #CopyFile_f
  617.                         $int    0x40
  618.                 }
  619.         }
  620. #codesize
  621. }
  622.