This message was edited by Phat Nat at 2005-6-16 18:25:40
: I would like to know the source code on how to call bitmaps images in a program and print it to the screen.
:
:
:
: TMM
Well, since eyou have that figured out, I'm gonna post some Virtual Screen Routines. This will allow you up to 10 Virtual Screens (Although memory probably won't!). Usually you only need 1-3 anyways.
Remember to Save the Code below as VSCREENS.PAS or change the unit name to match the file name.
UNIT VScreens;
INTERFACE
{ Wait for the Monitor Beam to reach the top of the screen }
PROCEDURE WaitRetrace;
{ Clears the Chosen Video Screen to the given color }
PROCEDURE CLRVID(Where : Word;Color : Byte);
{ Tries to allocate "NumPages" Virtual Screens. Returns actual # allocated }
FUNCTION GetVideoPages(NumPages : Byte) : Byte;
{ Used at the end of the program to free the Virtual Screen Memory }
PROCEDURE DisposeVideoPages;
{ Copies the Video Page from "Source" to "Dest" }
PROCEDURE CopyPage(Source,Dest : Word);
TYPE
VPage = Array[0..63999] Of Byte;
VPagePtr = ^VPage;
VAR
VirScr : Array[1..10] Of VPagePtr;
VAddr : Array[1..10] Of Word;
IMPLEMENTATION
VAR
NumVidPages : Byte;
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
END;
PROCEDURE CLRVID; Assembler;
ASM
Mov Di, Where
Mov Es, Di
Xor Di, Di
Mov Al, Color
Mov Ah, Al
Mov Cx, 32000
REP STOSW
END;
FUNCTION GetVideoPages;
Begin
NumVidPages := 0;
While (NumPages > 0) and (MaxAvail > 64000) Do
Begin
Inc(NumVidPages);
Dec(NumPages);
New(VirScr[NumVidPages]);
VAddr[NumVidPages] := Seg(VirScr[NumVidPages]^);
End;
GetVideoPages := NumVidPages;
End;
PROCEDURE DisposeVideoPages;
Begin
While NumVidPages > 0 Do
Begin
Dispose(VirScr[NumVidPages]);
Dec(NumVidPages);
End;
End;
PROCEDURE CopyPage; Assembler;
ASM
Push Ds
Cld
Mov Si, Source
Mov Ds, Si
Xor Si, Si
Mov Di, Dest
Mov Es, Di
Xor Di, Di
Mov Cx, 32000
@Transfer:
LODSW
STOSW
Loop @Transfer
Pop Ds
END;
Begin
End.
These are fairly fast routines for Virtual Screens. I've used them for a long time, so now you can enjoy too. Hmmm, just looking at my code, I think I could've made a faster CopyPage() Procedure. Here's a faster one (uses 32-bit copy instead of 16-bit copy):
PROCEDURE CopyPage; Assembler;
ASM
Push Ds
Cld
Mov Si, Source
Mov Ds, Si
Xor Si, Si
Mov Di, Dest
Mov Es, Di
Xor Di, Di
Mov Cx, 16000
@Transfer:
db $66
LODSW
db $66
STOSW
Loop @Transfer
Pop Ds
END;
>NOTE<
Just ran a test. On my computer 60,000 VScreen Copies takes 7.9 sec with the first procedure and only 4.1 sec with the new one. sweet.
>NOTE<
A Simple program that uses them would look like this:
PROGRAM TestScreens;
USES Crt, VScreens;
CONST
VGA = $A000;
VAR
X : Byte;
PROCEDURE DrawBox(X,Y : Word; Size, Color : Byte; Where : Word);
VAR
X1,Y1 : Byte;
Begin
For Y1 := 0 to Size-1 Do
For X1 := 0 to Size-1 Do
Mem[Where:X+X1+(Y+Y1)*320] := Color
End;
Begin
If GetVideoPages(1) <> 1 Then { Get Memory }
Begin
WriteLn('Not Enough Memory!');
Halt;
End;
ASM
Mov Ax, $13 { Get into Graphics 320x200x256 }
Int $10
END;
{ Draw a moving Box, no virtual Screens }
{ I am using 2 WaitRetrace, because otherwise it's too fast and You can't even see the box }
Repeat
WaitRetrace;
ClrVid(VGA,0);
WaitRetrace;
DrawBox(X,0,10,12,VGA);
Inc(X);
Until Keypressed;
While Keypressed Do Readkey;
{ Draw a moving Box, using a virtual Screen }
Repeat
ClrVid(VAddr[1],0);
DrawBox(X,0,10,12,VAddr[1]);
WaitRetrace;
CopyPage(VAddr[1],VGA);
Inc(X);
Until Keypressed;
While Keypressed Do Readkey;
ASM
Mov Ax, $3 { Return to Text Mode }
Int $10
END;
DisposeVideoPages; { Release Memory }
End.
If you have any questions, just post them.
Phat Nat