home *** CD-ROM | disk | FTP | other *** search
- /*
- pcopen.c
-
- % PC device interface initialization
-
- 5/16/88 by Ted.
-
- OWL 1.1
- Copyright (c) 1988, 1989 by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 8/17/88 jmd removed eNOMEM
- 1/14/89 ted extracted pc_getcurslines to pcgcursl.c for better shareability.
- 2/05/89 ted moved pc_wordcolor in from its own file.
- 3/19/89 ted made pcdata static.
- 4/04/89 ted Added FreeFont function.
- 4/24/89 ted Renamed from pcfuncs.c, moved dig funcs to pcdisp.c.
- 4/26/89 ted Moved attrmap out of info struct into pcdata.
- 5/06/89 ted Added colormap initialization.
- 7/05/89 ted Changed the display mode initialization sequence, added
- fontseg, fontoffs, dispseg initialization.
- 7/12/89 ted Added OSTATIC's and '_func' macros.
- 7/14/89 ted Added more video initialization (ilmask, ilsize, vbincr).
- */
-
- #include "pcpriv.h"
-
- OGLOBAL pcdata_struct pcdatastruc;
-
- OSTATIC boolean DIGPRIV pc_initdata(_arg1(void));
- OSTATIC boolean DIGPRIV pc_initdata2(_arg1(void));
- /* -------------------------------------------------------------------------- */
-
- boolean DIGPRIV pc_OpenDIG(digp, mode, setinfo)
- dig_struct *digp;
- int mode;
- pc_setinfo_fptr setinfo;
- /*
- Perform the initial set-up operations on the DIG structure which are common
- to all pc mode DIGs.
- */
- {
- /* Fail if the current hardware cannot support the mode requested */
- if (!pc_ModeSupport(mode)) {
- return(FALSE);
- }
- /* Don't allow the same pcdata to be initted twice */
- if (pc_inuse()) { /* (see if pcdata has already been initialized) */
- return(FALSE); /* (Note: depends on static struct initted to NULL's */
- }
- /* Point the DIG struct's DIG-specific data pointer to pcdata so it can */
- /* be saved and swapped later on. Note: pchdata not included, so it won't */
- /* be swapped. */
- digp->data = (VOID *) &pcdatastruc;
- digp->datasize = sizeof(pcdatastruc);
-
- /* Set up the generic information in pcdata */
- if (!pc_initdata()) {
- return(FALSE);
- }
- /* Set up the mode-specific information in pcdata */
- if (!(*setinfo)(mode)) {
- return(FALSE);
- }
-
- /* Finish initting data, init display mode */
- if (!pc_initdata2()) {
- pc_CloseDIG(digp);
- return(FALSE);
- }
- /* Set up the hardware-related part of the DIG structure and its data */
- pc_hOpen(digp);
-
- /* Init hardware */
- if (!(*digp->hControl)(HC_OPEN, NULL, NULL)) {
- pc_CloseDIG(digp);
- return(FALSE);
- }
- return(TRUE);
- }
- /* -------------------------------------------------------------------------- */
-
- void pc_CloseDIG(digp)
- dig_struct *digp;
- /*
- Close a DIG and free any data it might have allocated.
- */
- {
- /* Free xattrmap if present */
- if (pcdata->xattrmap != NULL) {
- ofree(OA_DIGATTRMAP, (VOID *) pcdata->xattrmap);
- }
- /* Free colormap copy if any was allocated */
- if (pcdata->colmap != NULL) {
- ofree(OA_DIGCOLMAP, (VOID *) pcdata->colmap);
- }
- /* Close down hardware funcs as well */
- (*digp->hControl)(HC_CLOSE, NULL, NULL);
-
- /* Wipe the dig data structure clean again */
- memset(pcdata, 0, sizeof(pcdata_struct));
- }
- /* -------------------------------------------------------------------------- */
-
- static boolean DIGPRIV pc_initdata()
- /*
- General initialization of the pcdata structure.
- (The info struct will be initted later - in setinfo).
- */
- {
- int i;
-
- pcdata->oldmode = pc_GetMode();
- pc_bgetcursorpos(&pcdata->oldcursx, &pcdata->oldcursy);
- pcdata->curctype = CURSOR_NONE;
-
- /* Start with fontseg, fontoffs clear so we'll know if it's set in setinfo */
- /* Start with retrace flag off. It may be set on later in the init process */
- /* (pcdata struct is guaranteed to start out cleared to 0's) */
- /* pcdata->fontseg = pcdata->fontoffs = 0; */
- /* pc_setretrace(FALSE); */
-
- /* init static dispmap space structure */
- /* width & height stay 0 for now - initted later (in setinfo) */
- pcdata->dmspace.onboard = TRUE; /* onboard */
- pcdata->dmspace.onscreen = TRUE;
- /* xpos, ypos stay 0 */
- /* xdata stays NULL */
-
- /* init attrmap assuming 4-bit color values */
- /* (this effort will be duplicated in mode 13) */
- pcdata->attrsize = 4; /* 4 bit attrmap elements */
- for (i = 0; i < 256; i++) {
- pcdata->attrmap[i] = (byte) i;
- }
- /* def_font struct should be filled in later */
- /* hardware vars handled in HC_OPEN method */
-
- pcdata->h = pchdata;
-
- return(TRUE);
- }
- /* -------------------------------------------------------------------------- */
- #define DISPWIDTH 230
- #define DISPHEIGHT 160
-
- static boolean DIGPRIV pc_initdata2()
- /*
- General initialization performed based on contents of info structure.
- Allocates system colormap copy and copies default colormap into it.
- */
- {
- /* interleave factor table: (2 ** factor) - 1 */
- static byte ilmasktab[3] = { 0, 1, 3 };
-
- unsigned short fontvec[2];
-
- /* Don't really know display size; use a guess */
- pcdata->info.xpixperm = (unsigned)
- ((long) pcdata->info.dispmap->width * 1000 / DISPWIDTH);
- pcdata->info.ypixperm = (unsigned)
- ((long) pcdata->info.dispmap->height* 1000 / DISPHEIGHT);
-
- if (pcdata->info.defcolmap != NULL) {
- /* Allocate system color map the right size. */
- /* Note: can't call ocolmap_Open because it refers to the system colmap */
- pcdata->colmap = (ocolmap_type) omalloc(OA_DIGCOLMAP,
- (SIZE_T) ocolmap_GetSize((unsigned) pcdata->info.ncolors));
- if (pcdata->colmap != NULL) {
- pcdata->colmap->firstpix = 0;
- pcdata->colmap->nentries = (unsigned) pcdata->info.ncolors;
- ocolmap_set(pcdata->colmap, pcdata->info.defcolmap);
- }
- else return(FALSE);
- }
- /* Initialize display mode to the one this DIG represents */
- pc_initmode();
-
- /* Make def_font.req = def_font.real */
- pcdata->info.def_font.req.height = pcdata->info.def_font.real.height;
-
- /* Initialize pcdata struct elements looked at in font plotting */
- pcdata->dispseg = (unsigned short) pcdata->info.dispaddr;
- pcdata->nplanes = pcdata->info.nplanes;
-
- pcdata->ilmask = ilmasktab[pc_ileave()];
- pcdata->ilsize = pc_ilsize();
- pcdata->vbincr = pc_bwidth() - pcdata->ilmask * pcdata->ilsize;
-
- /* If the setinfo func didn't set fontlines, make it the font height */
- if (pcdata->fontlines == 0) {
- pcdata->fontlines = pcdata->info.def_font.real.height;
- }
- /* If the setinfo func didn't set font addr, make it the curr. BIOS font. */
- if (pcdata->fontseg0 == 0) {
- /* Get the font address from int 43 */
- ram_segtomem(0x00, 4 * BIOS_FONTVEC, (byte *) fontvec, 4);
- pcdata->fontseg0 = fontvec[1];
- pcdata->fontoffs0 = fontvec[0];
- }
- /* Extended ASCII font pointer points to second half of font table */
- /* (Assumes 1-byte wide font characters) */
- if (pcdata->fontseg1 == 0) {
- pcdata->fontseg1 = pcdata->fontseg0;
- pcdata->fontoffs1 = pcdata->fontoffs0 + 128 * pcdata->fontlines;
- }
- return(TRUE);
- }
- /* -------------------------------------------------------------------------- */
-
-