Category : Files from Magazines
Archive   : PCTJ8805.ZIP
Filename : 8514DEMO.C

 
Output of file : 8514DEMO.C contained in archive : PCTJ8805.ZIP
/* 8514/A Demo */
/* Requires ibmafi.h, callafi.obj, hdiload.exe, and stan1220.fnt */
#include /* DOS Memory Management interface */
#include /* C Low-Level File I/O interface */
#include /* C File Control definitions */
#include /* C Memory Allocation interface */
#include /* C String Handling interface */
#include "ibmafi.h" /* IBM Display Adapter interface */
#define FONTFILE_NAME "STAN1220.FNT"
#define COLOR_WHITE 3
#define MESSAGE "Hello, Display Adapter 8514/A!"
#define MAX_STR 40
HOPEN_DATA open_data = { 3, 0, 0 };
HCLOSE_DATA close_data = { 2, 0 };
HSCS_DATA font = { 4, 0 };
/* Local Function Prototypes */
struct CharSetDef *LoadFont (char *);
int main (void);
/* Local Functions */
struct CharSetDef *LoadFont(fileName)
char *fileName; /* Name of the font file to use */
{
word fontlen;
struct FontFileDefn *ioaddr;
int f_id;
struct CharSetDef *a_csd;
/*
Try to open the specified font file. If it can't be opened,
return an error.
*/
if ((f_id = open (fileName, O_RDONLY | O_BINARY)) == -1)
return NULL;
/*
Find the size of the font file, allocate a buffer, and load
the file into it; return an error if buffer can't be allocated.
*/
fontlen = (int) lseek (f_id, 0L, 2);
if (!(ioaddr = (struct FontFileDefn *) malloc (fontlen)))
return NULL;
lseek (f_id, 0L, 0); /* back to start of file */
read (f_id, (char *) ioaddr, fontlen);
/*
Load up the character set definition tables with the address
at which the font was loaded.
*/
a_csd = (struct CharSetDef *) (((char *) ioaddr) +
ioaddr->page_array[ioaddr->def_page].csd_offset);
a_csd->chardef1 = ((char far *) ioaddr) + ((long) a_csd->chardef1);
a_csd->chardef2 = ((char far *) ioaddr) + ((long) a_csd->chardef2);
a_csd->chardef3 = ((char far *) ioaddr) + ((long) a_csd->chardef3);
a_csd->indextbl = (int far *)
(((byte far *) ioaddr) + ((long) a_csd->indextbl));
a_csd->enveltbl = ((char far *) ioaddr) + ((long) a_csd->enveltbl);
/*
Close up and return the loaded address.
*/
close (f_id);
return a_csd;
}
int main ()
{
HINIT_DATA taskState;
HQDPS_DATA stateBufferInfo;
HQMODE_DATA modeData;
HSCOL_DATA textColor;
HCHST_DATA(MAX_STR) drawString;
int retVal;
int messageHeight, messageWidth;
union REGS inregs, outregs;
struct SREGS segregs;
/*
Check to see that the adapter interface is installed. If it is
not, we can't proceed.
*/
if (getafi () == NULL)
{
printf ("Please run HDILOAD to install the Adapter Interface.\n");
return 1;
}
/*
The adapter interface is installed, so the entry points in it
can be called safely. Open the adapter to its default state
and verify that the open worked.
*/
HOPEN (&open_data); /* Open the Adapter Interface */
if (open_data.iflags) /* If an error occurred on the open */
{
printf ("Adapter Open error: %X\n", open_data.iflags);
return 1;
}
/*
Allocate a block of memory for the task-dependent state buffer.
This buffer is filled in by a call to HINIT, and must be set up
even if the adapter's state will not be switched later.
*/
stateBufferInfo.length = 6; /* Size of the returned buffer info */
HQDPS (&stateBufferInfo);
/*
The state buffer info block now holds the size of the task-
dependent state buffer required by HINIT. Since HINIT is passed
a segment value as a pointer to the buffer and assumes that the
buffer begins at offset 0 in that segment, we'll call the DOS
memory allocation service to allocate an appropriate block.
*/
inregs.h.ah = 0x48; /* Allocate DOS memory segment */
inregs.x.bx = stateBufferInfo.size;
intdos (&inregs, &outregs);
taskState.segment = outregs.x.ax;
taskState.length = 2; /* Size of the segment pointer */
HINIT (&taskState); /* Initialize the opened adapter */
modeData.length = 18; /* Get the adapter's default mode */
HQMODE (&modeData);
/*
Now we're all set to go. Everything up to here has been
canonical code - now we get to the real application. Load the
font file and display a string on the monitor. The font file
used is the standard 12 x 20 font file supplied with the
adapter interface code.
*/
if (!(font.address = LoadFont (FONTFILE_NAME)))
{
printf ("Font file %s could not be loaded!\n", FONTFILE_NAME);
retVal = 1;
}
else
{
textColor.length = 4;
textColor.index = COLOR_WHITE;
HSCOL (&textColor); /* Set drawing color to plain white */
font.length = 4;
HSCS (&font); /* Set the character set to be used */
/*
Calculate the length and height of the message in the current
font so that we can center it properly.
*/
messageHeight = font.address->cellheight;
messageWidth = font.address->cellwidth * strlen (MESSAGE);
/*
Draw the string properly centered on the screen.
*/
drawString.coord.x_coord = (modeData.width - messageWidth) / 2;
drawString.coord.y_coord = (modeData.height - messageHeight) / 2;
drawString.length = sizeof (coord_pr) + strlen (MESSAGE);
strcpy (drawString.string,MESSAGE);
HCHST (&drawString);
retVal = 0;
}
getch (); /* Let the reader admire our work */
/*
Release the task state buffer and close the adapter.
*/
inregs.h.ah = 0x49; /* Free DOS memory segment */
segregs.es = taskState.segment;
int86x (0x21, &inregs, &outregs, &segregs);
HCLOSE (&close_data); /* Close Adapter Interface */
return 0; /* Successful operation */
}

  3 Responses to “Category : Files from Magazines
Archive   : PCTJ8805.ZIP
Filename : 8514DEMO.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/