|
DirectDraw
based graphics engine for Freepascal
One of the massive advantages
to the pure pascal programming that represented
my first initiations into the world of programming
is the enormous degree of control one can excert
over the state of the system. Using real-mode
interupts, assembly language and direct memory
access, you can achieve almost anything, with
the incredibly pace of the unconstrained processor.
There is one major problem with Turbo pascal however,
and that is of compatability. Simple text-based
16-bit real mode programs will run under Windows
XP, but attempt anything risky; especially DOS
interupts, or access of the memory; and nearly
all functionality is lost (annoyingly this includes
Trooper II, which is, despite protracted fiddlings,
still refusing to run under XP). For those that
love the accessibility and speed of pascal programming,
help is, however, at hand. The marvelous (and
free) GNU Freepascal compiler, as well as a fully
funtional IDE and text editor, can be used with
almost complete compatability for Turbo
6.0 code to generate 32-bit windows applications,
with no restrictions on memory usage (or much
else). The power of pascal is intact; portions
of assembly language can be included in the code
as easily as before; and code runs with comparable
speed, and greatly enhanced stability. The one
area where conversion cannot occur easily is graphical
routines, where the direct-VGA access and bank-switching
code of the real-mode sVGA engine is totally inappropriate
to a windows-managed display. An innovative solution
is provided by Carsen Weachter's FPCX graphical
units, which make use of precompiled .dll files
generated from Delphi sources for the DirectX
to generate a directdraw surface, which can be
referenced and (with care) drawn onto as any other
piece of memory. Using his code as a basis, I
obtained the DirectX 9 headers for Delphi, compiled
them using the delphi 3.0 command line compiler,
and set about modifying the code to allow direct
access to the graphical memory, optimised assembler
routines for simple graphical procedures, and
more complex tools such as image display and page
flipping. All these routines are included in a
modified .dll file, which can be linked into your
freepascal programs to make these routines instantly
available. The result is an extremely powerful
graphics engine (it even seems to outclass the
sVGA routines written in Turbo); the screenshot
shows a demonstration program, displaying copies
of an image of dimensions 500x500x16 bit at a
rate of over 6000/sec (a data transfer of over
300 Mbytes/sec); coupled with almost total stability,
and integration into the windows OS (screenshots
and mouse control can be added with ease). Find
included in the downloadable package both the
DirectX9 headers (it should work with previous
versions without modification, but no promises),
the engine source (which uses the headers and
should be compiled using the delphi command line
compiler to give a .dll file), and several demonstrations
of what the engine can do. Enjoy!
Download
the Toolkit (718 kb) | Back
to News
|