home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Pascal / Samples / VIDEO.ARJ / VIDEO.PAS
Encoding:
Pascal/Delphi Source File  |  1992-07-20  |  6.1 KB  |  245 lines

  1.  
  2. program DCFG;    {dirt cheap frame grabber}
  3. uses crt, dos;
  4.  
  5. type screenarray = array[0..65000] of byte;
  6.      bytearray = array[0..65000] of byte;
  7.      vptr=^bytearray;
  8. var
  9.      xx,yy,i:integer;
  10.      oldmode:byte;
  11.      crtmode:byte absolute $40:$49;
  12.      s:screenarray absolute $A000:0;
  13.      prnarray:array[0..3] of word absolute $40:$08;
  14.      prnport:word;
  15.      prnbase,inport:word;
  16.      regs:registers;
  17.      cx,ch:char;
  18.      vary:vptr;
  19.      framesize:word;
  20.  
  21. const  homekey = char($80+71);
  22.        endkey = char($80+79);
  23.        pageup = char($80+73);
  24.        pagedn = char($80+81);
  25.        uparrow = char($80+72);
  26.        dnarrow = char($80+80);
  27.        leftarrow = char($80+75);
  28.        rightarrow = char($80+77);
  29.  
  30. begin
  31.      new(vary);
  32.      
  33.      prnport := 0;       {find out what port they want}
  34.      if ParamCount > 0 then
  35.      begin
  36.        if ParamStr(1) = '2' then
  37.          prnport := 1
  38.        else if ParamStr(2) = '3' then
  39.          prnport := 2
  40.        else if ParamStr(3) = '4' then
  41.          prnport := 3;
  42.      end;
  43.      prnbase := prnarray[prnport];   {init port base addr}
  44.      
  45.      port[prnbase] := $ff;           {set data lines high}
  46.      port[prnbase+2] := $04;         {init output control lines}
  47.      inport := prnbase+1;
  48.      directvideo := false;
  49.      
  50.      OldMode := CrtMode;
  51.      regs.ax := $0013;
  52.      regs.bx := 0;
  53.      intr($10,regs);
  54.      ch := #$55;
  55.      cx := #$55;
  56.  
  57.      xx := 45;                        {init X sample size}
  58.      yy := 82;                        {init Y sample size}
  59.  
  60.      Write('loading ');               {load the palette registers}
  61.  
  62.        asm
  63.          mov ax,1010h                 {sync level - 143}
  64.          mov ch,0                     {green}
  65.          mov cl,0                     {blue}
  66.          mov dh,0                     {red}
  67.          mov bx,143
  68.          int 10h
  69.      end;
  70.      asm
  71.          mov ax,1010h                 {level 1 - 127}
  72.          mov ch,03fh                  {green}
  73.          mov cl,03fh                  {blue}
  74.          mov dh,03fh                  {red}
  75.          mov bx,127
  76.          int 10h
  77.      end;
  78.      
  79.      asm
  80.          mov ax,1010h                 {level 2 - 63}
  81.          mov ch,01fh                  {green}
  82.          mov cl,01fh                  {blue}
  83.          mov dh,01fh                  {red}
  84.          mov dx,63
  85.          int 10h
  86.      end;
  87.  
  88.      asm
  89.          mov ax,1010h                 {level 3 - 31}
  90.          mov ch,0fh                   {green}
  91.          mov cl,0fh                   {blue}
  92.          mov dh,0fh                   {red}
  93.          mov bx,31
  94.          int 10h
  95.      end;
  96.      
  97.      asm
  98.          mov ax,1010h                 {level 4 - 15}
  99.          mov ch,0                     {green}
  100.          mov cl,0                     {blue}
  101.          mov dh,0                     {red}
  102.          mov bx,15
  103.          int 10h
  104.      end;
  105.      Write('ready ');                       {all done, start collecting data}
  106. gotoxy(1,20);
  107.  
  108.      Write('xx:',xx,' yy:',yy,'......');
  109.  
  110. framesize := 30000;                  {how many bytes to collect for a frame}
  111.  
  112. repeat
  113.                 {grab a video frame from the printer port}  
  114.      asm
  115.          mov bx,0
  116.          les di,[vary]         {point es:di to frame buffer}
  117.          mov cx,[framesize]    {get number bytes to grab}
  118.         @lp:
  119.          dec bx                {don't get hung up here}
  120.          jz @stopit
  121.          mov dx,[inport]
  122.          in al,dx
  123.          cmp al,143             {wait for the vert sync}
  124.          jnz @lp
  125.          in al,dx
  126.          cmp al,143
  127.          jnz @lp
  128.          in al,dx
  129.          cmp al,143
  130.          jnz @lp
  131.          in al,dx
  132.          cmp al,143
  133.          jnz @lp
  134.          in al,dx
  135.          cmp al,143
  136.          jnz @lp
  137.      
  138.          cli                      {disable ints while we do this}
  139.          rep
  140.          db 6ch                   {grab a frame of video in one chunk}
  141.          sti                      {ok, you can have ints again}
  142.         @stopit:
  143.      end;
  144.      
  145.           {now we are gonna display the video on the screen}
  146.      asm
  147.          mov dx,[yy]
  148.          mov cx,[framesize]
  149.      
  150.          mov ax,0A000h
  151.          mov es,ax
  152.          mov di,0
  153.          mov bx,0
  154.          push bp
  155.          mov bp,[xx]
  156.          push ds
  157.          lds si,[vary]
  158.          add si,bp
  159.          add si,bp
  160.          add si,bp
  161.          add si,bp
  162.          add si,bp
  163.          add si,bp
  164.          add si,bp
  165.          add si,bp
  166.          add si,bp
  167.          add si,bp
  168.          add si,bp
  169.          add si,bp
  170.          add si,bp
  171.          add si,bp
  172.          add si,bp
  173.          add si,bp
  174.          add si,bp
  175.          add si,bp
  176.          add si,bp
  177.         @tsi:
  178.          dec cx
  179.          jz @done
  180.          mov al,ds:[si]
  181.          or al,$0f;
  182.          inc si
  183.          cmp al,143
  184.          jnz @tsi
  185.      
  186.         @t2:
  187.          mov cx,bp
  188.          mov ah,0
  189.         @tlp:
  190.          dec ah
  191.          jz @done
  192.          mov al,ds:[si]
  193.          or al,$0f;
  194.          inc si
  195.          cmp al,143
  196.          jz @tlp
  197.      
  198.          mov es:[di],al
  199.          inc di
  200.          mov es:[di],al
  201.          inc di
  202.          loop @tlp
  203.      
  204.          add bx,320
  205.          add si,bp
  206.          add si,bp
  207.          mov di,bx
  208.          dec dx
  209.          jnz @t2
  210.         @done:
  211.          pop ds
  212.          pop bp
  213.      end;
  214. {    write(port[inport],' '); }
  215.  
  216.      if keypressed then
  217.      begin
  218.        cx := readkey;
  219.        if cx = #0 then cx := char($80+ord(readkey));
  220.        
  221.        if cx = homekey then xx := xx -10;
  222.        if cx = endkey then xx := xx +10;
  223.        if cx = leftarrow then xx := xx -1;
  224.        if cx = rightarrow then xx := xx +1;
  225.        if cx = pageup then yy := yy -10;
  226.        if cx = pagedn then yy := yy +10;
  227.        if cx = uparrow then yy := yy -1;
  228.        if cx = dnarrow then yy := yy +1;
  229.        if xx < 0 then xx := 1;
  230.        if yy < 0 then yy := 1;
  231.        if xx > 160 then xx := 159;
  232.        if yy > 200 then yy := 199;
  233.        gotoxy(1,20);
  234.        write('xx:',xx,' yy:',yy,'......');
  235.      end;
  236. until cx < #32;
  237.  
  238. regs.ah := $00;
  239. regs.al := oldmode;
  240. regs.bx := 0;
  241. intr($10,regs);
  242. end.
  243.  
  244.  
  245.