{$E-,G-,N-}
{$M 16384,0,65535}
unit flprvdo; {video related routines}

interface

const
  {bits for cga 3d8 Mode Control Register}
  MCR=$3d8;
  MCR_80columns      = 1; {       40 columns if cleared     (text mode) }
  MCR_graphics       = 2; {             text if cleared                 }
  MCR_blackandwhite  = 4; {   color burst on if cleared (graphics mode) }
  MCR_videoenable    = 8; {         disabled if cleared                 }
  MCR_highres        =16; {          low res if cleared (graphics mode) }
  MCR_backgroundcolor=32; { characters blink if cleared     (text mode) }

{
         Text modes:      320x200 modes:         640x200 mode:
Bit   0  Blue border      Blue background        Blue ForeGround
      1  Green border     Green background       Green ForeGround
      2  Red border       Red background         Red ForeGround
      3  Bright border    Bright background      Bright ForeGround
      4  Backgr. color    Alt. intens. colors    Alt. intens colors
      5  No func.         Selects palette
           Palette 0 is Green, red and brown,
           palette 1 is Cyan, magenta and white.
}


  {bits for cga 3d9 Color Control Register}
  CSR=$3d9;
  CSR_Blue           = 1; {       40 columns if cleared     (text mode) }
  CSR_Green          = 2; {             text if cleared                 }
  CSR_Red            = 4; {   color burst on if cleared (graphics mode) }
  CSR_Bright         = 8; {         disabled if cleared                 }
  CSR_Intensity      =16; {          low res if cleared (graphics mode) }
  CSR_PaletteSelect  =32; { characters blink if cleared     (text mode) }

var
  displayset:byte absolute $0040:$0065;

Procedure UpdateCSR(background,palette:byte);
Function ReadPixelBIOS(x,y:word):byte;
Procedure WritePixelBIOS(x,y:word;color:byte);

implementation

Procedure UpdateCSR(background,palette:byte);assembler;
{change CSR from current background and palette setting}
asm
  xor  ax,ax
  xor  bx,bx

@background:

  mov  ah,0bh
  mov  bh,00
  mov  bl,background
  and  bl,00001111b {safety first}
  {upper bit of nybble in palette has to go here for intensity -- wacky}
  mov  cl,palette
  and  cl,00000010b
  shl  cl,1
  shl  cl,1
  shl  cl,1
  or   bl,cl
  int  10h

@palette:

  mov  ah,0bh
  mov  bh,01
  mov  bl,palette
  and  bl,00000011b {safety first}
  int  10h

@end:
end;

Function ReadPixelBIOS(x,y:word):byte;assembler;
asm
  mov  ah,0dh
  xor  bh,bh
  mov  cx,x
  mov  dx,y
  int  10h
  {color should be in al}
end;

Procedure WritePixelBIOS(x,y:word;color:byte);assembler;
asm
  mov  ah,0ch
  mov  al,color
  xor  bh,bh
  mov  cx,x
  mov  dx,y
  int  10h
  {color should be in al}
end;

end.