{$F-,I-,S-,O+}
unit TextSet;

{written by Pedt Scragg <newsmaster@pedt.demon.co.uk>
Code is released into the Public Domain - please leave
this notice intact if redistributed}


interface

const

  BW40     =   0;
  CO40     =   1;
  BW80     =   2;
  CO80     =   3;
  Mono     =   7;
  Font8x8  = 256;
  C40      =   1;
  C80      =   3;

var
  LastMode : Integer;

procedure TextMode(Mode: Integer);

implementation

Procedure Int10h; assembler;
asm
   push di
   push si
   push es
   push bp
   int  10h
   pop  bp
   pop  es
   pop  si
   pop  di
end;

procedure Variable; assembler;
asm
   mov  ah, 0fh
   call int10h
   xor  dl, dl
   xor  bh, bh
   push ax
   mov  ax, 1130h
   call int10h
   pop  ax
   or   dl, dl
   jne  @@3
   mov  dl, 18h
@@3:
   mov  dh, dl
   xor  ah, ah
   cmp  dh, 18h
   jbe  @@4
   inc  ah
@@4:
   mov  LastMode, ax
end;

procedure TextMode; assembler;
asm
   mov  ax, mode
   push dx
   mov  dx, 0040h
   mov  es, dx
   pop  dx
   mov  di, 87h
   and  byte ptr es:[di], 0FEh
   cmp  al, 7
   je   @@1
   cmp  al, 4
   jb   @@1
   mov  al, 3
@@1:
   push ax
   xor  ah, ah
   call int10h
   pop  ax
   or   ah, ah
   je   @@2
   mov  ax, 1112h
   xor  bl, bl
   call int10h
   mov  ax, 1130h
   xor  bh, bh
   xor  dl, dl
   call int10h
   cmp  dl, 2Ah
   jne  @@2
   mov  di, 87h
   or   byte ptr es:[di],1
   mov  ax, 100h
   mov  cx, 600h
   call int10h
   mov  ah, 12h
   mov  bl, 20h
   call int10h
@@2:
   call Variable
end;

begin
     Variable;
end.
