Skip to content

Instantly share code, notes, and snippets.

@dgryski
Created August 27, 2021 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgryski/b9a6333ca310f5889112990f8f87f4e1 to your computer and use it in GitHub Desktop.
Save dgryski/b9a6333ca310f5889112990f8f87f4e1 to your computer and use it in GitHub Desktop.
unit dvga;
{$G+} { generate 286 instructions -- needed for shl 6/8 }
{ for rect, should I inline the hline routine,
and convert the rest to asm? }
interface
const
maxx=319;
maxy=199;
maxcolors=256;
procedure setmcga;
procedure settext;
procedure pset(x,y:word; col:byte);
function pget(x,y:word):byte;
function kbhit:boolean;
function getkey:char;
procedure waitretrace;
procedure hline(x,y,len:word; col:byte);
procedure vline(x,y,len:word; col:byte);
procedure rect(x1,y1,x2,y2:word; col:byte);
implementation
procedure setmcga; assembler;
asm
mov ax, $0013
int $10
end;
procedure settext; assembler;
asm
mov ax, $0003
int $10
end;
procedure pset(x,y:word;col:byte); assembler;
asm
push es
mov ax, $a000
mov es, ax
mov bx, y
mov ax, bx
shl ax, 6
shl bx, 8
add ax, bx
add ax, x
mov di, ax
mov al, col
stosb
pop es
end;
function pget(x,y:word):byte; assembler;
asm
push es
mov ax, $a000
mov es, ax
mov bx, y
mov ax, bx
shl ax, 6
shl bx, 8
add ax, bx
add ax, x
mov di, ax
lodsb
pop es
end;
function kbhit:boolean; assembler;
asm
mov ax, $0100
int $16
mov al, 00
jz @done
mov ax, 1
@done:
end;
function getkey:char; assembler;
asm
xor ax, ax
int $16
xor ah, ah
end;
procedure waitretrace; assembler;
asm
mov dx,3dah
@l1:
in al,dx
and al,08h
jnz @l1
@l2:
in al,dx
and al,08h
jz @l2
ret
end;
procedure hline(x,y,len:word;col:byte); assembler;
asm
push es
mov ax, $a000
mov es, ax
mov bx, y
mov ax, bx
shl ax, 6
shl bx, 8
add ax, bx
add ax, x
mov cx, len
mov di, ax
mov al, col
rep stosb
pop es
end;
procedure vline(x,y,len:word; col:byte); assembler;
asm
push es
mov ax, $a000
mov es, ax
mov bx, y
mov ax, bx
shl ax, 6
shl bx, 8
add ax, bx
add ax, x
mov cx, len
mov di, ax
mov al, col
@l:
stosb
add di, 319
loop @l
pop es
end;
procedure rect(x1,y1,x2,y2:word; col:byte);
var i,len:word;
begin
len:=x2-x1;
for i:=y1 to y2 do
hline(x1, i, len, col);
end;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment