home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 18 / CD_ASCQ_18_111294_W.iso / dos / prg / pas / gfxfx / modex.pas < prev    next >
Pascal/Delphi Source File  |  1994-06-22  |  3KB  |  146 lines

  1.  
  2. {$g+}
  3. program mode_x;
  4. { First mode-x routines, needs optimizing, by Bas van Gaalen, Holland, PD }
  5. uses crt;
  6. const vidseg:word=$a000;
  7. var x,y:word;
  8.  
  9. procedure setpal(col,r,g,b:byte); assembler; asm
  10.   mov dx,03c8h; mov al,col; out dx,al; inc dx; mov al,r
  11.   out dx,al; mov al,g; out dx,al; mov al,b; out dx,al; end;
  12.  
  13. procedure settextmode; assembler; asm
  14.   mov ax,3; int 10h; end;
  15.  
  16. procedure vga320x200; assembler;
  17. asm
  18.   mov ax,0013h     { mode 13h, 320x200x256x1 }
  19.   int 10h
  20.   mov dx,03c4h
  21.   mov ax,0604h     { unchain stuff: 320x200x256x4 }
  22.   out dx,ax
  23.   mov ax,0f02h     { select all planes }
  24.   out dx,ax
  25.  
  26.   mov cx,320*200   { clear graphics memory }
  27.   mov es,vidseg
  28.   xor ax,ax
  29.   mov di,ax
  30.   rep stosw
  31.   mov dx,03d4h
  32.  
  33.   mov dx,03c2h     { set 'overscan' mode here! }
  34.   mov al,10100011b { 11100111b }
  35.   out dx,al
  36.  
  37.   mov dx,03d4h     { misc mode-x stuff }
  38.   mov ax,4009h
  39.   out dx,ax
  40.   mov ax,0014h
  41.   out dx,ax
  42.   mov ax,0e317h
  43.   out dx,ax
  44. end;
  45.  
  46. procedure putpixel(x,y:word; col:byte); assembler;
  47. asm
  48.   mov dx,03c4h
  49.   mov al,2
  50.   mov cx,[x]
  51.   and cx,3
  52.   mov ah,1
  53.   shl ah,cl
  54.   out dx,ax
  55.   mov es,vidseg
  56.   mov ax,[y]
  57.   shl ax,4
  58.   mov di,ax
  59.   shl ax,2
  60.   add di,ax
  61.   mov dx,[x]
  62.   shr dx,2
  63.   add di,dx
  64.   mov al,[col]
  65.   mov [es:di],al
  66. end;
  67.  
  68. procedure setaddress(ad:word); assembler;
  69. asm
  70.   mov dx,3d4h
  71.   mov al,0ch
  72.   mov ah,[byte(ad)+1]
  73.   out dx,ax
  74.   mov al,0dh
  75.   mov ah,[byte(ad)]
  76.   out dx,ax
  77. end;
  78.  
  79. procedure setlinecomp(ad:word); assembler;
  80. asm
  81.   mov dx,3d4h
  82.   mov al,18h
  83.   mov ah,[byte(ad)]
  84.   out dx,ax
  85.   mov al,7
  86.   out dx,al
  87.   inc dx
  88.   in al,dx
  89.   dec dx
  90.   mov ah,[byte(ad)+1]
  91.   and ah,00000001b
  92.   shl ah,4
  93.   and al,11101111b
  94.   or al,ah
  95.   mov ah,al
  96.   mov al,7
  97.   out dx,ax
  98.  
  99.   mov al,9
  100.   out dx,al
  101.   inc dx
  102.   in al,dx
  103.   dec dx
  104.   mov ah,[byte(ad)+1]
  105.   and ah,00000010b
  106.   shl ah,5
  107.   and al,10111111b
  108.   or al,ah
  109.   mov ah,al
  110.   mov al,9
  111.   out dx,ax
  112. end;
  113.  
  114. procedure retrace; assembler;
  115. asm
  116.   mov dx,3dah
  117.  @vert1:
  118.   in al,dx
  119.   test al,8
  120.   jz @vert1
  121.  @vert2:
  122.   in al,dx
  123.   test al,8
  124.   jnz @vert2
  125. end;
  126.  
  127. begin
  128.   vga320x200;
  129.  
  130.   for x:=1 to 127 do setpal(127+x,128-x div 2,128-x div 2,10);
  131.   for x:=1 to 128 do setpal(x,128-x div 3,128-x div 2,30);
  132.  
  133.   for x:=0 to 319 do for y:=0 to 399 do putpixel(x,400+y,128+(x*x+y*y) mod 128);
  134.   for x:=0 to 319 do for y:=0 to 399 do putpixel(x,y,(x*x-y*y) mod 128);
  135.  
  136.   repeat
  137.     for y:=0 to 99 do begin
  138.       retrace;
  139.       setaddress(400*80+80*(round(cos(pi*y/50)*80)+80));
  140.       setlinecomp(20+4*(round(sin(pi*y/50)*30)+30));
  141.     end;
  142.   until keypressed;
  143.  
  144.   settextmode;
  145. end.
  146.