{--------------------------------------------------------------}
{                          PlotTest                            }
{                                                              }
{           INLINE-from-EXTERNAL demonstration program         }
{                                                              }
{                             by Jeff Duntemann                }
{                             Turbo Pascal V3.0                }
{                             Last update 6/19/86              }
{                                                              }
{    From the book, COMPLETE TURBO PASCAL, by Jeff Duntemann   }
{    Scott, Foresman & Co. (c) 1986,1987  ISBN 0-673-18600-8   }
{--------------------------------------------------------------}

PROGRAM PlotTest;

VAR
  I : Integer;

PROCEDURE Plot(X,Y,Color : INTEGER);

BEGIN

INLINE
  ($1E /             { PUSH DS }

  { First we calculate the Y offset into the video buffer: }

  $8B / $46 / <Y /   { MOV AX,Y       ; Put Y in AL.. }
  $8A / $E0 /        { MOV AH,AL      ; ..and AH too }
  $25 / $FE / $01 /  { AND AX,01FEH   ; Mask AX with $01FE }
  $B1 / $03 /        { MOV CL,3       ; Multiply AX by 8.. }
  $D3 / $E0 /        { SHL AX,CL      ; ..by shifting left 3X }
  $8B / $D8 /        { MOV BX,AX      ; Copy new value into BX }
  $80 / $E7 / $07 /  { AND BH,7       ; Zero out hi 5 bits of BH }
  $B1 / $02 /        { MOV CL,2       ; By now AX has been }
  $D3 / $E0 /        { SHL AX,CL      ; multiplied by 32; add AX }
  $03 / $D8 /        { ADD BX,AX      ; to BX; BX now contains Y }
                                    { ; multiplied by 40 }

  { Now we calculate the X offset into the video buffer: }

  $8B / $46 / <X /   { MOV AX,X       ; Put X in AX.. }
  $8B / $C8 /        { MOV CX,AX      ; ..and CX too }
  $D1 / $E8 /        { SHR AX,1       ; Divide AX by 8 by shifting }
  $D1 / $E8 /        { SHR AX,1       ; right 3X...can't use CX! }
  $D1 / $E8 /        { SHR AX,1       ; To get byte offset we add }
  $03 / $D8 /        { ADD BX,AX      ; X offset to Y offset. }
                                    { ; Now DS:BX contains the byte }
                                    { ; that contains our pixel! }

  { Here we fetch the video buffer byte and modify the }
  { appropriate pixel: }

  $81 / $E1 / $07 / $00 /  { AND CX,7      ; Lo 3 bits of CX are bit # }
                                         { ; of desired pixel }
  $B0 / $80 /              { MOV AL,080H   ; Store hi bit into AL bit 7 }
  $D2 / $E8 /              { SHR AL,CL     ; Shift bit down by pixel # }
  $BA / $00 / $B8 /        { MOV DX,B800H  ; Set DS to video segment }
  $8E / $DA /              { MOV DS,DX }
  $8A / $0F /              { MOV CL,[DS:BX] ; Bring byte in from buffer }
  $8B / $56 / <Color /     { MOV DX,Color   ; Color parm in DX for test }
  $80 / $FA / $00 /        { CMP DL,0       ; Is color parm = 0? }
  $74 / $07 /              { JE PRESET      ; If so, jump to clr pixel }
                                { PSET: }
  $0A / $C8 /              { OR CL,AL       ; OR new pixel into byte }
  $88 / $0F /              { MOV [DS:BX],CL ; put it back into buffer }
  $EB / $07 / $90 /        { JMP BYE        ; and go home }
                                { PRESET: }
  $34 / $FF /              { XOR AL,0FFH    ; Invert the pixel mask }
  $22 / $C8 /              { AND CL,AL      ; AND mask against byte }
  $88 / $0F /              { MOV [DS:BX],CL ; put it back into buffer }

  { Pop DS off the stack and go home: }

                           { BYE: }
  $1F )                    { POP DS }

END;




BEGIN
  HiResColor(15);
  HiRes;
  Readln;
  FOR I := 0 TO 639 DO PLOT(I,0,1);  { Draw a line }
  Readln;
  FOR I := 0 TO 639 DO PLOT(I,0,0);  { and erase it again }
  Readln;
  TextMode
END.
