{$N+,A+,G+,F+,D-,E-,L-,R-,S-,Q-,Y-,I-}

unit text;

interface
procedure DrawString_6x6(s:string; x,y:integer; color:byte; seg_font6x6,ofs_font6x6,where:word);
procedure DrawString_12x12(s:string; x,y:integer; color:byte; seg_font12x12,ofs_font12x12, where:word);
procedure DrawString_6x6_d(s:string; x,y:integer; color:byte; where:word);


implementation

uses global;

procedure DrawChar_6x6(ch:char; x,y:integer; color:byte; seg_font,ofs_font, where:word);
var vsi,height:word;
begin
if (y<=-6) or (y>199) then exit;
vsi:=(ord(ch)-32)*36 + ofs_font;

if y<0 then begin height:=6+y; vsi:=vsi-6*y; y:=0; end
else if y>200-6 then height:=6-(y-(200-6))
else height:=6;
asm
mov es, where
mov si, vsi

{call x+y*320}
mov ax, y
xchg ah, al
mov  di, ax
shr  di, 2
add  di, ax
add  di, x

mov al, color
mov ah, al
mov dx, ax
db $66; shl dx, 16
mov dx, ax

mov cx, height

push ds
mov ds, seg_font
@y:
   db $66; mov ax, ds:[si]
           mov bx, ds:[si+4]
   db $66; and ax, dx  {set color}
           and bx, dx
   db $66; mov es:[di], ax
           mov es:[di+4], bx
   add di, 320
   add si, 6
dec cx
jnz @y
pop ds
end;
end;

procedure DrawChar_12x12(ch:char; x,y:integer; color:byte; seg_font,ofs_font, where:word);
var vsi,height:word;
begin
if (y<=-12) or (y>199) then exit;
vsi:=(ord(ch)-32)*144 + ofs_font;

if y<0 then begin height:=12+y; vsi:=vsi-12*y; y:=0; end
else if y>200-12 then height:=12-(y-(200-12))
else height:=12;
asm
mov es, where
mov si, vsi

{call x+y*320}
mov ax, y
xchg ah, al
mov  di, ax
shr  di, 2
add  di, ax
add  di, x

mov al, color
mov ah, al
mov dx, ax
db $66; shl dx, 16
mov dx, ax

push bp
push ds
mov cx, height
mov ds, seg_font
@y:
   db $66; mov ax, ds:[si]
   db $66; mov bx, ds:[si+4]
   db $66; mov bp, ds:[si+8]

   db $66; and ax, dx  {set color}
   db $66; and bx, dx
   db $66; and bp, dx

   db $66; mov es:[di], ax
   db $66; mov es:[di+4], bx
   db $66; mov es:[di+8], bp

   add di, 320
   add si, 12
dec cx
jnz @y
pop ds
pop bp
end;
end;


procedure DrawString_6x6(s:string; x,y:integer; color:byte; seg_font6x6,ofs_font6x6,where:word);
var h,n:word;
begin
h:=0;
   for n:=1 to Length(s) do begin
      DrawChar_6x6(s[n], x+h,y,color, seg_font6x6,ofs_font6x6, where);
      h:=h+6;
   end;
end;


procedure DrawString_12x12(s:string; x,y:integer; color:byte; seg_font12x12,ofs_font12x12, where:word);
var h,n:word;
begin
h:=0;
   for n:=1 to Length(s) do begin
      DrawChar_12x12(s[n], x+h,y,color, seg_font12x12,ofs_font12x12, where);
      h:=h+12;
   end;
end;


procedure DrawString_6x6_d(s:string; x,y:integer; color:byte; where:word);
var h,n:word;
begin
h:=0;
   for n:=1 to Length(s) do begin
      DrawChar_6x6(s[n], x+h,y,color, seg_font6x6_d,ofs_font6x6_d, where);
      h:=h+6;
   end;
end;


end.