[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

TXTEXT Implementation

The TXTEXT performs that same housekeeping tasks (determining size, saving data segment, clearing playground) that all other extensions do.

The TXTEXT also draws heavily from many of the techniques outlined in RANDEXT Implementation. See that section for discussion on the getrandom() macro, the structure of for loops that plot pixels, how to randomly select white or black pixels, and how to use the argument buffer for temporary storage between calls.

Features specific to the TXTEXT extension are really only those operations that actually draw text. Cogsys uses the third party library BGI Font Toolkit from Ryle Design to plot text. While the BGI Font Toolkit was designed to be used with the Borland Graphics Interface, Cogsys instead uses it with a homegrown graphics library called GUBS(3) The GUBS library lets the user specify a slate to draw to, which may be the actual video buffer, or, as is the case in the TXTEXT, a virtual buffer that is copied to video memory later. Consider these lines of code from `txtext.c':

 
asm mov ds, oldseg;
SetGubs(GUBS_SLATE3, A);
resetbounds();

which restore the original data segment and switch the slate to the current playground, `A'. Note also the resetbounds() function, which explicity resets the text bounds before new text is drawn.

Text itself is drawn with the Ryle Design replacements for the classic BGI text functions:

 
/* gx and gy are specified by user to be the CENTER of the character */
/* but bgi_outtextxy wants the top left corner. we adjust here */
gx -= bgi_textwidth(arg+22)/2;
gy -= bgi_textheight(arg+22)/2;
bgi_outtextxy(gx, gy, arg+22); 

Finally, the bounds (which are available as external variables) are saved locally, the slate is reset to the video buffer, and the data segment is brought back to the extension scope:

 
minx = bound_minx;
maxx = bound_maxx;
miny = bound_miny;
maxy = bound_maxy;
SetGubs(GUBS_SLATE2, NULL);
asm mov ds, myseg;

On a final note, in subfunction 4, the "flipping" is neatly accomplished by using the C exclusive-or operator, `^':

 
for (i=minx; i<=maxx; i++)
  for (j=miny; j<=maxy; j++)
    {
      getrandom();
      if (r < q)
        A[j*320 + i] ^= WHITE;
    }


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Usman Muzaffar on June, 28 2000 using texi2html