diff options
| author | Brian Paul <brian.paul@tungstengraphics.com> | 2002-03-08 19:24:56 +0000 | 
|---|---|---|
| committer | Brian Paul <brian.paul@tungstengraphics.com> | 2002-03-08 19:24:56 +0000 | 
| commit | 7fd50afbbf8bb36642efe0254706039af3c9c588 (patch) | |
| tree | 20a4cc89467a6d50ac26e675dd6255c0092b325f /src | |
| parent | 2b9ba3f84f98d81ab6af55d292499b44f92b7cad (diff) | |
new DOS driver files from Daniel Borca
Diffstat (limited to 'src')
| -rw-r--r-- | src/mesa/drivers/dos/dpmi.c | 123 | ||||
| -rw-r--r-- | src/mesa/drivers/dos/dpmiint.h | 48 | ||||
| -rw-r--r-- | src/mesa/drivers/dos/vbeaf.c | 607 | ||||
| -rw-r--r-- | src/mesa/drivers/dos/vbeaf.h | 813 | ||||
| -rw-r--r-- | src/mesa/drivers/dos/vbeafint.h | 50 | ||||
| -rw-r--r-- | src/mesa/drivers/dos/video.c | 625 | ||||
| -rw-r--r-- | src/mesa/drivers/dos/video.h | 52 | 
7 files changed, 2318 insertions, 0 deletions
| diff --git a/src/mesa/drivers/dos/dpmi.c b/src/mesa/drivers/dos/dpmi.c new file mode 100644 index 0000000000..26400ac3af --- /dev/null +++ b/src/mesa/drivers/dos/dpmi.c @@ -0,0 +1,123 @@ +/*
 + * Mesa 3-D graphics library
 + * Version:  4.0
 + * 
 + * Copyright (C) 1999  Brian Paul   All Rights Reserved.
 + * 
 + * Permission is hereby granted, free of charge, to any person obtaining a
 + * copy of this software and associated documentation files (the "Software"),
 + * to deal in the Software without restriction, including without limitation
 + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 + * and/or sell copies of the Software, and to permit persons to whom the
 + * Software is furnished to do so, subject to the following conditions:
 + * 
 + * The above copyright notice and this permission notice shall be included
 + * in all copies or substantial portions of the Software.
 + * 
 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 + */
 +
 +/*
 + * DOS/DJGPP device driver v0.3 for Mesa 4.0
 + *
 + *  Copyright (C) 2002 - Borca Daniel
 + *  Email : dborca@yahoo.com
 + *  Web   : http://www.geocities.com/dborca
 + */
 +
 +
 +#include <dpmi.h>
 +
 +#include "dpmiint.h"
 +
 +
 +
 +/* _create_linear_mapping:
 + *  Maps a physical address range into linear memory.
 + */
 +static int _create_linear_mapping (unsigned long *linear, unsigned long physaddr, int size)
 +{
 + __dpmi_meminfo meminfo;
 +
 + if (physaddr >= 0x100000) {
 +    /* map into linear memory */
 +    meminfo.address = physaddr;
 +    meminfo.size = size;
 +    if (__dpmi_physical_address_mapping(&meminfo) != 0)
 +       return -1;
 +
 +    *linear = meminfo.address;
 + } else {
 +    /* exploit 1 -> 1 physical to linear mapping in low megabyte */
 +    *linear = physaddr;
 + }
 +
 + return 0;
 +}
 +
 +
 +
 +/* _remove_linear_mapping:
 + *  Frees the DPMI resources being used to map a linear address range.
 + */
 +static void _remove_linear_mapping (unsigned long *linear)
 +{
 + __dpmi_meminfo meminfo;
 +
 + if (*linear) {
 +    if (*linear >= 0x100000) {
 +       meminfo.address = *linear;
 +       __dpmi_free_physical_address_mapping(&meminfo);
 +    }
 +
 +    *linear = 0;
 + }
 +}
 +
 +
 +
 +/* _create_selector:
 + *  Allocates a selector to access a region of linear memory.
 + */
 +int _create_selector (int *segment, unsigned long base, int size)
 +{
 + /* allocate an ldt descriptor */
 + if ((*segment=__dpmi_allocate_ldt_descriptors(1)) < 0) {
 +    *segment = 0;
 +    return -1;
 + }
 +
 + /* create the linear mapping */
 + if (_create_linear_mapping(&base, base, size)) {
 +    __dpmi_free_ldt_descriptor(*segment);
 +    *segment = 0;
 +    return -1;
 + }
 +
 + /* set the descriptor base and limit */
 + __dpmi_set_segment_base_address(*segment, base);
 + __dpmi_set_segment_limit(*segment, MAX(size-1, 0xFFFF));
 +
 + return 0;
 +}
 +
 +
 +
 +/* _remove_selector:
 + *  Frees a DPMI segment selector.
 + */
 +void _remove_selector (int *segment)
 +{
 + if (*segment) {
 +    unsigned long base;
 +    __dpmi_get_segment_base_address(*segment, &base);
 +    _remove_linear_mapping(&base);
 +    __dpmi_free_ldt_descriptor(*segment);
 +    *segment = 0;
 + }
 +}
 diff --git a/src/mesa/drivers/dos/dpmiint.h b/src/mesa/drivers/dos/dpmiint.h new file mode 100644 index 0000000000..8494ee6bb2 --- /dev/null +++ b/src/mesa/drivers/dos/dpmiint.h @@ -0,0 +1,48 @@ +/*
 + * Mesa 3-D graphics library
 + * Version:  4.0
 + * 
 + * Copyright (C) 1999  Brian Paul   All Rights Reserved.
 + * 
 + * Permission is hereby granted, free of charge, to any person obtaining a
 + * copy of this software and associated documentation files (the "Software"),
 + * to deal in the Software without restriction, including without limitation
 + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 + * and/or sell copies of the Software, and to permit persons to whom the
 + * Software is furnished to do so, subject to the following conditions:
 + * 
 + * The above copyright notice and this permission notice shall be included
 + * in all copies or substantial portions of the Software.
 + * 
 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 + */
 +
 +/*
 + * DOS/DJGPP device driver v0.3 for Mesa 4.0
 + *
 + *  Copyright (C) 2002 - Borca Daniel
 + *  Email : dborca@yahoo.com
 + *  Web   : http://www.geocities.com/dborca
 + */
 +
 +
 +#ifndef DPMIINT_H_included
 +#define DPMIINT_H_included
 +
 +#ifndef NULL
 +#define NULL 0
 +#endif
 +
 +#ifndef MAX
 +#define MAX(x, y) (((x)<(y))?(y):(x))
 +#endif
 +
 +int _create_selector (int *segment, unsigned long base, int size);
 +void _remove_selector (int *segment);
 +
 +#endif
 diff --git a/src/mesa/drivers/dos/vbeaf.c b/src/mesa/drivers/dos/vbeaf.c new file mode 100644 index 0000000000..eef1793985 --- /dev/null +++ b/src/mesa/drivers/dos/vbeaf.c @@ -0,0 +1,607 @@ +/*
 + * Mesa 3-D graphics library
 + * Version:  4.0
 + * 
 + * Copyright (C) 1999  Brian Paul   All Rights Reserved.
 + * 
 + * Permission is hereby granted, free of charge, to any person obtaining a
 + * copy of this software and associated documentation files (the "Software"),
 + * to deal in the Software without restriction, including without limitation
 + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 + * and/or sell copies of the Software, and to permit persons to whom the
 + * Software is furnished to do so, subject to the following conditions:
 + * 
 + * The above copyright notice and this permission notice shall be included
 + * in all copies or substantial portions of the Software.
 + * 
 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 + */
 +
 +/*
 + * DOS/DJGPP device driver v0.2 for Mesa 4.0
 + *
 + *  Copyright (C) 2002 - Borca Daniel
 + *  Email : dborca@yahoo.com
 + *  Web   : http://www.geocities.com/dborca
 + */
 +
 +
 +#include <ctype.h>
 +#include <dpmi.h>
 +#include <stdio.h>
 +#include <stdlib.h>
 +#include <sys/exceptn.h>
 +#include <sys/nearptr.h>
 +
 +#include "dpmiint.h"
 +#include "vbeaf.h"
 +
 +
 +
 +#define MMAP      unsigned long
 +#define NOMM      0
 +#define MVAL(a)   (void *)((a)-__djgpp_base_address)
 +
 +
 +
 +#define SAFE_CALL(FUNC)\
 +{					\
 + int _ds, _es, _ss;			\
 +					\
 + __asm__ __volatile__(			\
 +	" movw %%ds, %w0 ; "		\
 +	" movw %%es, %w1 ; "		\
 +	" movw %%ss, %w2 ; "		\
 +	" movw %w3, %%ds ; "		\
 +	" movw %w3, %%es ; "		\
 +	" movw %w3, %%ss ; "		\
 +					\
 +	: "=&q" (_ds),			\
 +	"=&q" (_es),			\
 +	"=&q" (_ss)			\
 +	: "q" (__djgpp_ds_alias)	\
 + );					\
 +					\
 + FUNC					\
 +					\
 + __asm__ __volatile__(			\
 +	"movw %w0, %%ds ; "		\
 +	"movw %w1, %%es ; "		\
 +	"movw %w2, %%ss ; "		\
 +	:				\
 +	: "q" (_ds),			\
 +	"q" (_es),			\
 +	"q" (_ss)			\
 + );					\
 +}
 +
 +#define SAFISH_CALL(FUNC)  FUNC
 +
 +
 +
 +extern void _af_int86(), _af_call_rm(), _af_wrapper_end();
 +
 +
 +
 +static AF_DRIVER *af_driver = NULL;    /* the VBE/AF driver */
 +int _accel_active = FALSE;             /* is the accelerator busy? */
 +static FAF_HWPTR_DATA *faf_farptr;     /* FreeBE/AF farptr data */
 +static MMAP af_memmap[4] = { NOMM, NOMM, NOMM, NOMM };
 +static MMAP af_banked_mem = NOMM;
 +static MMAP af_linear_mem = NOMM;
 +
 +
 +
 +__inline__ fixed itofix (int x)
 +{
 + return x << 16;
 +}
 +
 +
 +
 +/*
 + * loads the driver from disk
 + */
 +static int load_driver (char *filename)
 +{
 + FILE *f;
 + size_t size;
 +
 + if ((f=fopen(filename, "rb"))!=NULL) {
 +    fseek(f, 0, SEEK_END);
 +    size = ftell(f);
 +    fseek(f, 0, SEEK_SET);
 +    if ((af_driver=(AF_DRIVER *)malloc(size))!=NULL) {
 +       if (fread(af_driver, size, 1, f)) {
 +          return 0;
 +       } else {
 +          free(af_driver);
 +       }
 +    }
 +    fclose(f);
 + }
 +
 + return -1;
 +}
 +
 +
 +
 +/*
 + *  Calls a VBE/AF function using the version 1.0 style asm interface.
 + */
 +static int call_vbeaf_asm (void *proc)
 +{
 + int ret;
 +
 + proc = (void *)((long)af_driver + (long)proc);
 +
 + /* use gcc-style inline asm */
 + __asm__("\n\
 +		pushl	%%ebx		\n\
 +		movl	%%ecx, %%ebx	\n\
 +		call	*%%edx		\n\
 +		popl	%%ebx		\n\
 + ": "=&a" (ret)                       /* return value in eax */
 +  : "c" (af_driver),                  /* VBE/AF driver in ds:ebx */
 +    "d" (proc)                        /* function ptr in edx */
 +  : "memory"                          /* assume everything is clobbered */
 + );
 +
 + return ret;
 +}
 +
 +
 +
 +/*
 + * prepares the FreeBE/AF extension functions.
 + */
 +static int initialise_freebeaf_extensions (void)
 +{
 + typedef unsigned long (*EXT_INIT_FUNC)(AF_DRIVER *af, unsigned long id);
 + EXT_INIT_FUNC ext_init;
 + unsigned long magic;
 + int v1, v2;
 + void *ptr;
 +
 + /* safety check */
 + if (!af_driver->OemExt) {
 +    return 0;
 + }
 +
 + /* call the extension init function */
 + ext_init = (EXT_INIT_FUNC)((long)af_driver + (long)af_driver->OemExt);
 +
 + magic = ext_init(af_driver, FAFEXT_INIT);
 +
 + /* check that it returned a nice magic number */
 + v1 = (magic>>8)&0xFF;
 + v2 = magic&0xFF;
 +
 + if (((magic&0xFFFF0000) != FAFEXT_MAGIC) || (!isdigit(v1)) || (!isdigit(v2))) {
 +    return 0;
 + }
 +
 + /* export libc and pmode functions if the driver wants them */
 + ptr = af_driver->OemExt(af_driver, FAFEXT_LIBC);
 +#ifdef _FAFEXT_LIBC
 + if (ptr)
 +    _fill_vbeaf_libc_exports(ptr);
 +#endif
 +
 + ptr = af_driver->OemExt(af_driver, FAFEXT_PMODE);
 +#ifdef _FAFEXT_PMODE
 + if (ptr)
 +    _fill_vbeaf_pmode_exports(ptr);
 +#endif
 +
 + return (v1-'0')*10 + (v2-'0');
 +}
 +
 +
 +
 +/*
 + *  Sets up the DPMI memory mappings required by the VBE/AF driver, 
 + *  returning zero on success.
 + */
 +static int initialise_vbeaf_driver (int faf_ext)
 +{
 + int c;
 +
 + /* query driver for the FreeBE/AF farptr extension */
 + if (faf_ext > 0)
 +    faf_farptr = af_driver->OemExt(af_driver, FAFEXT_HWPTR);
 + else
 +    faf_farptr = NULL;
 +
 + if (faf_farptr) {
 +    /* use farptr access */
 +    for (c=0; c<4; c++) {
 +        faf_farptr->IOMemMaps[c].sel = 0;
 +        faf_farptr->IOMemMaps[c].offset = 0;
 +    }
 +
 +    faf_farptr->BankedMem.sel = 0;
 +    faf_farptr->BankedMem.offset = 0;
 +
 +    faf_farptr->LinearMem.sel = 0;
 +    faf_farptr->LinearMem.offset = 0;
 + } else {
 +    /* enable nearptr access */
 +    return -5;
 + }
 +
 + /* create mapping for MMIO ports */
 + for (c=0; c<4; c++) {
 +     if (af_driver->IOMemoryBase[c]) {
 +        if ((af_memmap[c]=_create_linear_mapping(af_driver->IOMemoryBase[c], af_driver->IOMemoryLen[c]))==NULL)
 +           return -4;
 +
 +        if (faf_farptr) {
 +           /* farptr IO mapping */
 +           if ((faf_farptr->IOMemMaps[c].sel=_create_selector(af_memmap[c], af_driver->IOMemoryLen[c]))<0) {
 +              _remove_linear_mapping(af_memmap+c);
 +              return -4;
 +           }
 +           faf_farptr->IOMemMaps[c].offset = 0;
 +           af_driver->IOMemMaps[c] = NULL;
 +        } else {
 +           /* nearptr IO mapping */
 +           af_driver->IOMemMaps[c] = MVAL(af_memmap[c]);
 +        }
 +     }
 + }
 +
 + /* create mapping for banked video RAM */
 + if (af_driver->BankedBasePtr) {
 +    if ((af_banked_mem=_create_linear_mapping(af_driver->BankedBasePtr, 0x10000))==NULL)
 +       return -4;
 +
 +    if (faf_farptr) {
 +       /* farptr banked vram mapping */
 +       if ((faf_farptr->BankedMem.sel=_create_selector(af_banked_mem, 0x10000))<0) {
 +          _remove_linear_mapping(&af_banked_mem);
 +          return -4;
 +       }
 +       faf_farptr->BankedMem.offset = 0;
 +       af_driver->BankedMem = NULL;
 +    } else {
 +       /* nearptr banked vram mapping */
 +       af_driver->BankedMem = MVAL(af_banked_mem);
 +    }
 + }
 +
 + /* create mapping for linear video RAM */
 + if (af_driver->LinearBasePtr) {
 +    if ((af_linear_mem=_create_linear_mapping(af_driver->LinearBasePtr, af_driver->LinearSize*1024))==NULL)
 +       return -4;
 +
 +    if (faf_farptr) {
 +       /* farptr linear vram mapping */
 +       if ((faf_farptr->LinearMem.sel=_create_selector(af_linear_mem, af_driver->LinearSize*1024))<0) {
 +          _remove_linear_mapping(&af_linear_mem);
 +          return -4;
 +       }
 +       faf_farptr->LinearMem.offset = 0;
 +       af_driver->LinearMem = NULL;
 +    } else {
 +       /* nearptr linear vram mapping */
 +       af_driver->LinearMem  = MVAL(af_linear_mem);
 +    }
 + }
 +
 + /* callback functions: why are these needed? ugly, IMHO */
 + af_driver->Int86 = (void *)_af_int86;
 + af_driver->CallRealMode = (void *)_af_call_rm;
 +
 + return 0;
 +}
 +
 +
 +
 +/* go_accel:
 + *  Prepares the hardware for an accelerated drawing operation.
 + */
 +static __inline__ void go_accel (void)
 +{
 +   /* turn on the accelerator */
 +   if (!_accel_active) {
 +      if (af_driver->DisableDirectAccess)
 +	 af_driver->DisableDirectAccess(af_driver);
 +
 +      _accel_active = TRUE;
 +   }
 +}
 +
 +
 +
 +void af_exit (void)
 +{
 + int c;
 +
 + /* undo memory mappings */
 + if (faf_farptr) {
 +    for (c=0; c<4; c++)
 +        _remove_selector(&faf_farptr->IOMemMaps[c].sel);
 +
 +    _remove_selector(&faf_farptr->BankedMem.sel);
 +    _remove_selector(&faf_farptr->LinearMem.sel);
 + }
 +
 + for (c=0; c<4; c++)
 +     _remove_linear_mapping(af_memmap+c);
 +
 + _remove_linear_mapping(&af_banked_mem);
 + _remove_linear_mapping(&af_linear_mem);
 +
 + if (af_driver) {
 +    free(af_driver);
 + }
 +}
 +
 +
 +
 +int af_init (char *filename)
 +{
 + int faf_ext, r;
 +
 + if (load_driver(filename)) {
 +    /* driver not found */
 +    return -1;
 + }
 +
 + faf_ext = initialise_freebeaf_extensions();
 +
 + /* special setup for Plug and Play hardware */
 + if (call_vbeaf_asm(af_driver->PlugAndPlayInit)) {
 +    af_exit();
 +    /* Plug and Play initialisation failed */
 +    return -2;
 + }
 +
 + if ((r=initialise_vbeaf_driver(faf_ext))) {
 +    af_exit();
 +    /* -4, ... */
 +    return r;
 + }
 +
 + /* low level driver initialisation */
 + if (call_vbeaf_asm(af_driver->InitDriver)) {
 +    af_exit();
 +    /* VBE/AF device not present */
 +    return -3;
 + }
 +
 + _go32_dpmi_lock_code((void *)_af_int86, (long)_af_wrapper_end-(long)_af_int86);
 +
 + return 0;
 +}
 +
 +
 +
 +#include "video.h"
 +
 +
 +
 +static long page, xres, startx, starty;
 +
 +
 +
 +AF_MODE_INFO *af_getmode (int i, int *granularity)
 +{
 + static AF_MODE_INFO info;
 + int mode = af_driver->AvailableModes[i];
 +
 + if ((mode==-1)||af_driver->GetVideoModeInfo(af_driver, mode, &info)) {
 +    return NULL;
 + } else {
 +    *granularity = af_driver->BankSize * 1024;
 +    return &info;
 + }
 +}
 +
 +
 +
 +void *af_dump_virtual (void *buffer, int width, int height, int pitch)
 +{
 + SAFISH_CALL(
 +             go_accel();
 +
 +             af_driver->BitBltSys(af_driver, buffer, pitch, 0, 0, width, height, startx, starty, 0);
 + );
 + return buffer;
 +}
 +
 +
 +
 +void af_switch_bank (int bank)
 +{
 + af_driver->SetBank(af_driver, bank);
 +}
 +
 +
 +
 +int af_flip (void)
 +{
 + SAFISH_CALL(
 +             go_accel();
 + 
 +             af_driver->SetDisplayStart(af_driver, page*xres, 0, 1);
 + );
 + if (page ^= 1) {
 +    startx += xres;
 + } else {
 +    startx -= xres;
 + }
 +
 + return page;
 +}
 +
 +
 +
 +void af_fillrect (void *buffer, int x, int y, int width, int height, int color)
 +{
 + (void)buffer;
 + SAFISH_CALL(
 +             go_accel();
 +
 +             af_driver->DrawRect(af_driver, color, startx+x, starty+y, width, height);
 + );
 +}
 +
 +
 +
 +void af_triangle (int x1, int y1, int x2, int y2, int x3, int y3, int color)
 +{
 + AF_TRAP trap;
 +
 + /* sort along the vertical axis */
 + #define TRI_SWAP(a, b)		\
 + {				\
 +  int tmp = x##a;		\
 +  x##a = x##b;			\
 +  x##b = tmp;			\
 +				\
 +  tmp = y##a;			\
 +  y##a = y##b;			\
 +  y##b = tmp;			\
 + }
 +
 + if (y2 < y1)
 +    TRI_SWAP(1, 2);
 +
 + if (y3 < y1) {
 +    TRI_SWAP(1, 3);
 +    TRI_SWAP(2, 3);
 + } else if (y3 < y2)
 +    TRI_SWAP(2, 3);
 +
 + SAFISH_CALL(
 +             go_accel();
 +
 +             if (y2 > y1) {
 +	        /* draw the top half of the triangle as one trapezoid */
 +	        trap.y = y1+starty;
 +	        trap.count = y2-y1;
 +	        trap.x1 = trap.x2 = itofix(x1+startx);
 +	        trap.slope1 = itofix(x2-x1) / (y2-y1);
 +	        trap.slope2 = itofix(x3-x1) / (y3-y1);
 +
 +                if (trap.slope1 < 0)
 +                   trap.x1 += MIN(trap.slope1+itofix(1), 0);
 +
 +                if (trap.slope2 < 0)
 +	           trap.x2 += MIN(trap.slope2+itofix(1), 0);
 +
 +                if (trap.slope1 > trap.slope2)
 +	           trap.x1 += MAX(ABS(trap.slope1), itofix(1));
 +                else
 +	           trap.x2 += MAX(ABS(trap.slope2), itofix(1));
 +
 +                af_driver->DrawTrap(af_driver, color, &trap);
 +
 +                if (y3 > y2) {
 +	           /* draw the bottom half as a second trapezoid */
 +	           if (trap.slope1 < 0)
 +	              trap.x1 -= MIN(trap.slope1+itofix(1), 0);
 +
 +                   if (trap.slope1 > trap.slope2)
 +	              trap.x1 -= MAX(ABS(trap.slope1), itofix(1));
 +
 +                   trap.count = y3-y2;
 +	           trap.slope1 = itofix(x3-x2) / (y3-y2);
 +
 +                   if (trap.slope1 < 0)
 +	              trap.x1 += MIN(trap.slope1+itofix(1), 0);
 +
 +                   if (trap.x1 > trap.x2)
 +	              trap.x1 += MAX(ABS(trap.slope1), itofix(1));
 +
 +                   af_driver->DrawTrap(af_driver, color, &trap);
 +                }
 +             } else if (y3 > y2) {
 +                /* we can draw the entire thing with a single trapezoid */
 +                trap.y = y1+starty;
 +                trap.count = y3-y2;
 +                trap.x1 = itofix(x2+startx);
 +                trap.x2 = itofix(x1+startx);
 +                trap.slope1 = itofix(x3-x2) / (y3-y2);
 +                trap.slope2 = (y3 > y1) ? (itofix(x3-x1) / (y3-y1)) : 0;
 +
 +                if (trap.slope1 < 0)
 +                   trap.x1 += MIN(trap.slope1+itofix(1), 0);
 +
 +                if (trap.slope2 < 0)
 +                   trap.x2 += MIN(trap.slope2+itofix(1), 0);
 +
 +                if (trap.x1 > trap.x2)
 +                   trap.x1 += MAX(ABS(trap.slope1), itofix(1));
 +                else
 +                   trap.x2 += MAX(ABS(trap.slope2), itofix(1));
 +
 +                af_driver->DrawTrap(af_driver, color, &trap);
 +             }
 + );
 +}
 +
 +
 +
 +int af_setup_mode (int mode, int caps)
 +{
 + if (CHECK_SOFTDB(caps) && af_driver->BitBltSys) {
 +    vl_flip = af_dump_virtual;
 + }
 + if (af_driver->SetBank) {
 +    vl_switch_bank = af_switch_bank;
 + }
 + if (!CHECK_SOFTDB(caps) && af_driver->DrawRect) {
 +    vl_clear = af_fillrect;
 + }
 +
 + if (CHECK_SINGLE(caps) || CHECK_SOFTDB(caps)) {
 +    page = 0;
 + } else {
 +    page = 1;
 + }
 +
 + return (mode&0x4000)?faf_farptr->LinearMem.sel:faf_farptr->BankedMem.sel;
 +}
 +
 +
 +
 +int af_setup_buffer (int x, int y)
 +{
 + startx = x + page*xres;
 + starty = y;
 +
 + return page;
 +}
 +
 +
 +
 +void *af_getprim (int primitive)
 +{
 + switch (primitive) {
 +        case TRI_RGB_FLAT:
 +             return af_driver->DrawTrap?(void *)af_triangle:NULL;
 +        default:
 +             return NULL;
 + }
 +}
 +
 +
 +
 +int af_enter_mode (int mode, int width, int height)
 +{
 + long wret;
 + if (!af_driver->SetVideoMode(af_driver, mode, width, height, &wret, 1, NULL)) {
 +    xres = width/2;
 +    return wret;
 + } else {
 +    return -1;
 + }
 +}
 diff --git a/src/mesa/drivers/dos/vbeaf.h b/src/mesa/drivers/dos/vbeaf.h new file mode 100644 index 0000000000..70ab669b48 --- /dev/null +++ b/src/mesa/drivers/dos/vbeaf.h @@ -0,0 +1,813 @@ +/*
 + *       ______             ____  ______     _____  ______ 
 + *      |  ____|           |  _ \|  ____|   / / _ \|  ____|
 + *      | |__ _ __ ___  ___| |_) | |__     / / |_| | |__ 
 + *      |  __| '__/ _ \/ _ \  _ <|  __|   / /|  _  |  __|
 + *      | |  | | |  __/  __/ |_) | |____ / / | | | | |
 + *      |_|  |_|  \___|\___|____/|______/_/  |_| |_|_|
 + *
 + *
 + *      VBE/AF structure definitions and constants.
 + *
 + *      See freebe.txt for copyright information.
 + */
 +
 +
 +#define FREEBE_VERSION     "v1.2"
 +
 +
 +#ifndef ALLEGRO_H
 +
 +
 +#include <pc.h>
 +
 +
 +#define NULL   0
 +
 +#define TRUE   1
 +#define FALSE  0
 +
 +#define MIN(x,y)     (((x) < (y)) ? (x) : (y))
 +#define MAX(x,y)     (((x) > (y)) ? (x) : (y))
 +#define MID(x,y,z)   MAX((x), MIN((y), (z)))
 +
 +#define ABS(x)       (((x) >= 0) ? (x) : (-(x)))
 +
 +#define BYTES_PER_PIXEL(bpp)     (((int)(bpp) + 7) / 8)
 +
 +typedef long fixed;
 +
 +
 +#endif
 +
 +
 +
 +/* mode attribute flags */
 +#define afHaveMultiBuffer        0x0001  /* multiple buffers */
 +#define afHaveVirtualScroll      0x0002  /* virtual scrolling */
 +#define afHaveBankedBuffer       0x0004  /* supports banked framebuffer */
 +#define afHaveLinearBuffer       0x0008  /* supports linear framebuffer */
 +#define afHaveAccel2D            0x0010  /* supports 2D acceleration */
 +#define afHaveDualBuffers        0x0020  /* uses dual buffers */
 +#define afHaveHWCursor           0x0040  /* supports a hardware cursor */
 +#define afHave8BitDAC            0x0080  /* 8 bit palette DAC */
 +#define afNonVGAMode             0x0100  /* not a VGA mode */
 +#define afHaveDoubleScan         0x0200  /* supports double scanning */
 +#define afHaveInterlaced         0x0400  /* supports interlacing */
 +#define afHaveTripleBuffer       0x0800  /* supports triple buffering */
 +#define afHaveStereo             0x1000  /* supports stereo LCD glasses */
 +#define afHaveROP2               0x2000  /* supports ROP2 mix codes */
 +#define afHaveHWStereoSync       0x4000  /* hardware stereo signalling */
 +#define afHaveEVCStereoSync      0x8000  /* HW stereo sync via EVC connector */
 +
 +
 +
 +/* drawing modes */
 +typedef enum 
 +{ 
 +   AF_FORE_MIX = 0,           /* background pixels use the foreground mix */
 +   AF_REPLACE_MIX = 0,        /* solid drawing mode */
 +   AF_AND_MIX,                /* bitwise AND mode */
 +   AF_OR_MIX,                 /* bitwise OR mode */
 +   AF_XOR_MIX,                /* bitwise XOR mode */
 +   AF_NOP_MIX,                /* nothing is drawn */
 +
 +   /* below here need only be supported if you set the afHaveROP2 flag */
 +   AF_R2_BLACK = 0x10, 
 +   AF_R2_NOTMERGESRC, 
 +   AF_R2_MASKNOTSRC, 
 +   AF_R2_NOTCOPYSRC, 
 +   AF_R2_MASKSRCNOT, 
 +   AF_R2_NOT, 
 +   AF_R2_XORSRC, 
 +   AF_R2_NOTMASKSRC, 
 +   AF_R2_MASKSRC, 
 +   AF_R2_NOTXORSRC, 
 +   AF_R2_NOP, 
 +   AF_R2_MERGENOTSRC, 
 +   AF_R2_COPYSRC, 
 +   AF_R2_MERGESRCNOT, 
 +   AF_R2_MERGESRC, 
 +   AF_R2_WHITE, 
 +} AF_mixModes;
 +
 +
 +
 +/* fixed point coordinate pair */
 +typedef struct AF_FIX_POINT 
 +{
 +   fixed x;
 +   fixed y;
 +} AF_FIX_POINT;
 +
 +
 +
 +/* trapezium information block */
 +typedef struct AF_TRAP 
 +{
 +   unsigned long y;
 +   unsigned long count;
 +   fixed x1;
 +   fixed x2;
 +   fixed slope1;
 +   fixed slope2;
 +} AF_TRAP;
 +
 +
 +
 +/* hardware cursor description */
 +typedef struct AF_CURSOR 
 +{
 +   unsigned long xorMask[32];
 +   unsigned long andMask[32];
 +   unsigned long hotx;
 +   unsigned long hoty;
 +} AF_CURSOR;
 +
 +
 +
 +/* color value */
 +typedef struct AF_PALETTE 
 +{
 +   unsigned char blue;
 +   unsigned char green;
 +   unsigned char red;
 +   unsigned char alpha;
 +} AF_PALETTE;
 +
 +
 +
 +/* CRTC information block for refresh rate control */
 +typedef struct AF_CRTCInfo
 +{
 +   unsigned short HorizontalTotal      __attribute__ ((packed));  /* horizontal total (pixels) */
 +   unsigned short HorizontalSyncStart  __attribute__ ((packed));  /* horizontal sync start position */
 +   unsigned short HorizontalSyncEnd    __attribute__ ((packed));  /* horizontal sync end position */
 +   unsigned short VerticalTotal        __attribute__ ((packed));  /* vertical total (lines) */
 +   unsigned short VerticalSyncStart    __attribute__ ((packed));  /* vertical sync start position */
 +   unsigned short VerticalSyncEnd      __attribute__ ((packed));  /* vertical sync end position */
 +   unsigned char  Flags                __attribute__ ((packed));  /* initialisation flags for mode */
 +   unsigned int   PixelClock           __attribute__ ((packed));  /* pixel clock in units of Hz */
 +   unsigned short RefreshRate          __attribute__ ((packed));  /* expected refresh rate in .01Hz */
 +   unsigned short NumBuffers           __attribute__ ((packed));  /* number of display buffers */
 +} AF_CRTCInfo;
 +
 +
 +
 +/* definitions for CRTC information block flags */
 +#define afDoubleScan             0x0001  /* enable double scanned mode */
 +#define afInterlaced             0x0002  /* enable interlaced mode */
 +#define afHSyncNeg               0x0004  /* horizontal sync is negative */
 +#define afVSyncNeg               0x0008  /* vertical sync is negative */
 +
 +
 +
 +typedef unsigned char AF_PATTERN;      /* pattern array elements */
 +typedef unsigned AF_STIPPLE;           /* 16 bit line stipple pattern */
 +typedef unsigned AF_COLOR;             /* packed color values */
 +
 +
 +
 +/* mode information structure */
 +typedef struct AF_MODE_INFO 
 +{
 +   unsigned short Attributes              __attribute__ ((packed));
 +   unsigned short XResolution             __attribute__ ((packed));
 +   unsigned short YResolution             __attribute__ ((packed));
 +   unsigned short BytesPerScanLine        __attribute__ ((packed));
 +   unsigned short BitsPerPixel            __attribute__ ((packed));
 +   unsigned short MaxBuffers              __attribute__ ((packed));
 +   unsigned char  RedMaskSize             __attribute__ ((packed));
 +   unsigned char  RedFieldPosition        __attribute__ ((packed));
 +   unsigned char  GreenMaskSize           __attribute__ ((packed));
 +   unsigned char  GreenFieldPosition      __attribute__ ((packed));
 +   unsigned char  BlueMaskSize            __attribute__ ((packed));
 +   unsigned char  BlueFieldPosition       __attribute__ ((packed));
 +   unsigned char  RsvdMaskSize            __attribute__ ((packed));
 +   unsigned char  RsvdFieldPosition       __attribute__ ((packed));
 +   unsigned short MaxBytesPerScanLine     __attribute__ ((packed));
 +   unsigned short MaxScanLineWidth        __attribute__ ((packed));
 +
 +   /* VBE/AF 2.0 extensions */
 +   unsigned short LinBytesPerScanLine     __attribute__ ((packed));
 +   unsigned char  BnkMaxBuffers           __attribute__ ((packed));
 +   unsigned char  LinMaxBuffers           __attribute__ ((packed));
 +   unsigned char  LinRedMaskSize          __attribute__ ((packed));
 +   unsigned char  LinRedFieldPosition     __attribute__ ((packed));
 +   unsigned char  LinGreenMaskSize        __attribute__ ((packed));
 +   unsigned char  LinGreenFieldPosition   __attribute__ ((packed));
 +   unsigned char  LinBlueMaskSize         __attribute__ ((packed));
 +   unsigned char  LinBlueFieldPosition    __attribute__ ((packed));
 +   unsigned char  LinRsvdMaskSize         __attribute__ ((packed));
 +   unsigned char  LinRsvdFieldPosition    __attribute__ ((packed));
 +   unsigned long  MaxPixelClock           __attribute__ ((packed));
 +   unsigned long  VideoCapabilities       __attribute__ ((packed));
 +   unsigned short VideoMinXScale          __attribute__ ((packed));
 +   unsigned short VideoMinYScale          __attribute__ ((packed));
 +   unsigned short VideoMaxXScale          __attribute__ ((packed));
 +   unsigned short VideoMaxYScale          __attribute__ ((packed));
 +
 +   unsigned char  reserved[76]            __attribute__ ((packed));
 +
 +} AF_MODE_INFO;
 +
 +
 +
 +#define DC  struct AF_DRIVER *dc
 +
 +
 +
 +/* main VBE/AF driver structure */
 +typedef struct AF_DRIVER 
 +{
 +   /* header */
 +   char           Signature[12]           __attribute__ ((packed));
 +   unsigned long  Version                 __attribute__ ((packed));
 +   unsigned long  DriverRev               __attribute__ ((packed));
 +   char           OemVendorName[80]       __attribute__ ((packed));
 +   char           OemCopyright[80]        __attribute__ ((packed));
 +   short          *AvailableModes         __attribute__ ((packed));
 +   unsigned long  TotalMemory             __attribute__ ((packed));
 +   unsigned long  Attributes              __attribute__ ((packed));
 +   unsigned long  BankSize                __attribute__ ((packed));
 +   unsigned long  BankedBasePtr           __attribute__ ((packed));
 +   unsigned long  LinearSize              __attribute__ ((packed));
 +   unsigned long  LinearBasePtr           __attribute__ ((packed));
 +   unsigned long  LinearGranularity       __attribute__ ((packed));
 +   unsigned short *IOPortsTable           __attribute__ ((packed));
 +   unsigned long  IOMemoryBase[4]         __attribute__ ((packed));
 +   unsigned long  IOMemoryLen[4]          __attribute__ ((packed));
 +   unsigned long  LinearStridePad         __attribute__ ((packed));
 +   unsigned short PCIVendorID             __attribute__ ((packed));
 +   unsigned short PCIDeviceID             __attribute__ ((packed));
 +   unsigned short PCISubSysVendorID       __attribute__ ((packed));
 +   unsigned short PCISubSysID             __attribute__ ((packed));
 +   unsigned long  Checksum                __attribute__ ((packed));
 +   unsigned long  res2[6]                 __attribute__ ((packed));
 +
 +   /* near pointers mapped by the application */
 +   void           *IOMemMaps[4]           __attribute__ ((packed));
 +   void           *BankedMem              __attribute__ ((packed));
 +   void           *LinearMem              __attribute__ ((packed));
 +   unsigned long  res3[5]                 __attribute__ ((packed));
 +
 +   /* driver state variables */
 +   unsigned long  BufferEndX              __attribute__ ((packed));
 +   unsigned long  BufferEndY              __attribute__ ((packed));
 +   unsigned long  OriginOffset            __attribute__ ((packed));
 +   unsigned long  OffscreenOffset         __attribute__ ((packed));
 +   unsigned long  OffscreenStartY         __attribute__ ((packed));
 +   unsigned long  OffscreenEndY           __attribute__ ((packed));
 +   unsigned long  res4[10]                __attribute__ ((packed));
 +
 +   /* relocatable 32 bit bank switch routine, for Windows (ugh!) */
 +   unsigned long  SetBank32Len            __attribute__ ((packed));
 +   void           *SetBank32              __attribute__ ((packed));
 +
 +   /* callback functions provided by the application */
 +   void           *Int86                  __attribute__ ((packed));
 +   void           *CallRealMode           __attribute__ ((packed));
 +
 +   /* main driver setup routine */
 +   void           *InitDriver             __attribute__ ((packed));
 +
 +   /* VBE/AF 1.0 asm interface (obsolete and not supported by Allegro) */
 +   void           *af10Funcs[40]          __attribute__ ((packed));
 +
 +   /* VBE/AF 2.0 extensions */
 +   void           *PlugAndPlayInit        __attribute__ ((packed));
 +
 +   /* extension query function, specific to FreeBE/AF */
 +   void           *(*OemExt)(DC, unsigned long id);
 +
 +   /* extension hook for implementing additional VESA interfaces */
 +   void           *SupplementalExt        __attribute__ ((packed));
 +
 +   /* device driver functions */
 +   long  (*GetVideoModeInfo)(DC, short mode, AF_MODE_INFO *modeInfo);
 +   long  (*SetVideoMode)(DC, short mode, long virtualX, long virtualY, long *bytesPerLine, int numBuffers, AF_CRTCInfo *crtc);
 +   void  (*RestoreTextMode)(DC);
 +   long  (*GetClosestPixelClock)(DC, short mode, unsigned long pixelClock);
 +   void  (*SaveRestoreState)(DC, int subfunc, void *saveBuf);
 +   void  (*SetDisplayStart)(DC, long x, long y, long waitVRT);
 +   void  (*SetActiveBuffer)(DC, long index);
 +   void  (*SetVisibleBuffer)(DC, long index, long waitVRT);
 +   int   (*GetDisplayStartStatus)(DC);
 +   void  (*EnableStereoMode)(DC, int enable);
 +   void  (*SetPaletteData)(DC, AF_PALETTE *pal, long num, long index, long waitVRT);
 +   void  (*SetGammaCorrectData)(DC, AF_PALETTE *pal, long num, long index);
 +   void  (*SetBank)(DC, long bank);
 +
 +   /* hardware cursor functions */
 +   void  (*SetCursor)(DC, AF_CURSOR *cursor);
 +   void  (*SetCursorPos)(DC, long x, long y);
 +   void  (*SetCursorColor)(DC, unsigned char red, unsigned char green, unsigned char blue);
 +   void  (*ShowCursor)(DC, long visible);
 +
 +   /* 2D rendering functions */
 +   void  (*WaitTillIdle)(DC);
 +   void  (*EnableDirectAccess)(DC);
 +   void  (*DisableDirectAccess)(DC);
 +   void  (*SetMix)(DC, long foreMix, long backMix);
 +   void  (*Set8x8MonoPattern)(DC, unsigned char *pattern);
 +   void  (*Set8x8ColorPattern)(DC, int index, unsigned long *pattern);
 +   void  (*Use8x8ColorPattern)(DC, int index);
 +   void  (*SetLineStipple)(DC, unsigned short stipple);
 +   void  (*SetLineStippleCount)(DC, unsigned long count);
 +   void  (*SetClipRect)(DC, long minx, long miny, long maxx, long maxy);
 +   void  (*DrawScan)(DC, long color, long y, long x1, long x2);
 +   void  (*DrawPattScan)(DC, long foreColor, long backColor, long y, long x1, long x2);
 +   void  (*DrawColorPattScan)(DC, long y, long x1, long x2);
 +   void  (*DrawScanList)(DC, unsigned long color, long y, long length, short *scans);
 +   void  (*DrawPattScanList)(DC, unsigned long foreColor, unsigned long backColor, long y, long length, short *scans);
 +   void  (*DrawColorPattScanList)(DC, long y, long length, short *scans);
 +   void  (*DrawRect)(DC, unsigned long color, long left, long top, long width, long height);
 +   void  (*DrawPattRect)(DC, unsigned long foreColor, unsigned long backColor, long left, long top, long width, long height);
 +   void  (*DrawColorPattRect)(DC, long left, long top, long width, long height);
 +   void  (*DrawLine)(DC, unsigned long color, fixed x1, fixed y1, fixed x2, fixed y2);
 +   void  (*DrawStippleLine)(DC, unsigned long foreColor, unsigned long backColor, fixed x1, fixed y1, fixed x2, fixed y2);
 +   void  (*DrawTrap)(DC, unsigned long color, AF_TRAP *trap);
 +   void  (*DrawTri)(DC, unsigned long color, AF_FIX_POINT *v1, AF_FIX_POINT *v2, AF_FIX_POINT *v3, fixed xOffset, fixed yOffset);
 +   void  (*DrawQuad)(DC, unsigned long color, AF_FIX_POINT *v1, AF_FIX_POINT *v2, AF_FIX_POINT *v3, AF_FIX_POINT *v4, fixed xOffset, fixed yOffset);
 +   void  (*PutMonoImage)(DC, long foreColor, long backColor, long dstX, long dstY, long byteWidth, long srcX, long srcY, long width, long height, unsigned char *image);
 +   void  (*PutMonoImageLin)(DC, long foreColor, long backColor, long dstX, long dstY, long byteWidth, long srcX, long srcY, long width, long height, long imageOfs);
 +   void  (*PutMonoImageBM)(DC, long foreColor, long backColor, long dstX, long dstY, long byteWidth, long srcX, long srcY, long width, long height, long imagePhysAddr);
 +   void  (*BitBlt)(DC, long left, long top, long width, long height, long dstLeft, long dstTop, long op);
 +   void  (*BitBltSys)(DC, void *srcAddr, long srcPitch, long srcLeft, long srcTop, long width, long height, long dstLeft, long dstTop, long op);
 +   void  (*BitBltLin)(DC, long srcOfs, long srcPitch, long srcLeft, long srcTop, long width, long height, long dstLeft, long dstTop, long op);
 +   void  (*BitBltBM)(DC, long srcPhysAddr, long srcPitch, long srcLeft, long srcTop, long width, long height, long dstLeft, long dstTop, long op);
 +   void  (*SrcTransBlt)(DC, long left, long top, long width, long height, long dstLeft, long dstTop, long op, unsigned long transparent);
 +   void  (*SrcTransBltSys)(DC, void *srcAddr, long srcPitch, long srcLeft, long srcTop, long width, long height, long dstLeft, long dstTop, long op, unsigned long transparent);
 +   void  (*SrcTransBltLin)(DC, long srcOfs, long srcPitch, long srcLeft, long srcTop, long width, long height, long dstLeft, long dstTop, long op, unsigned long transparent);
 +   void  (*SrcTransBltBM)(DC, long srcPhysAddr, long srcPitch, long srcLeft, long srcTop, long width, long height, long dstLeft, long dstTop, long op, unsigned long transparent);
 +   void  (*DstTransBlt)(DC, long left, long top, long width, long height, long dstLeft, long dstTop, long op, unsigned long transparent);
 +   void  (*DstTransBltSys)(DC, void *srcAddr, long srcPitch, long srcLeft, long srcTop, long width, long height, long dstLeft, long dstTop, long op, unsigned long transparent);
 +   void  (*DstTransBltLin)(DC, long srcOfs, long srcPitch, long srcLeft, long srcTop, long width, long height, long dstLeft, long dstTop, long op, unsigned long transparent);
 +   void  (*DstTransBltBM)(DC, long srcPhysAddr, long srcPitch, long srcLeft, long srcTop, long width, long height, long dstLeft, long dstTop, long op, unsigned long transparent);
 +   void  (*StretchBlt)(DC, long srcLeft, long srcTop, long srcWidth, long srcHeight, long dstLeft, long dstTop, long dstWidth, long dstHeight, long flags, long op);
 +   void  (*StretchBltSys)(DC, void *srcAddr, long srcPitch, long srcLeft, long srcTop, long srcWidth, long srcHeight, long dstLeft, long dstTop, long dstWidth, long dstHeight, long flags, long op);
 +   void  (*StretchBltLin)(DC, long srcOfs, long srcPitch, long srcLeft, long srcTop, long srcWidth, long srcHeight, long dstLeft, long dstTop, long dstWidth, long dstHeight, long flags, long op);
 +   void  (*StretchBltBM)(DC, long srcPhysAddr, long srcPitch, long srcLeft, long srcTop, long srcWidth, long srcHeight, long dstLeft, long dstTop, long dstWidth, long dstHeight, long flags, long op);
 +   void  (*SrcTransStretchBlt)(DC, long srcLeft, long srcTop, long srcWidth, long srcHeight, long dstLeft, long dstTop, long dstWidth, long dstHeight, long flags, long op, unsigned long transparent);
 +   void  (*SrcTransStretchBltSys)(DC, void *srcAddr, long srcPitch, long srcLeft, long srcTop, long srcWidth, long srcHeight, long dstLeft, long dstTop, long dstWidth, long dstHeight, long flags, long op, unsigned long transparent);
 +   void  (*SrcTransStretchBltLin)(DC, long srcOfs, long srcPitch, long srcLeft, long srcTop, long srcWidth, long srcHeight, long dstLeft, long dstTop, long dstWidth, long dstHeight, long flags, long op, unsigned long transparent);
 +   void  (*SrcTransStretchBltBM)(DC, long srcPhysAddr, long srcPitch, long srcLeft, long srcTop, long srcWidth, long srcHeight, long dstLeft, long dstTop, long dstWidth, long dstHeight, long flags, long op, unsigned long transparent);
 +   void  (*DstTransStretchBlt)(DC, long srcLeft, long srcTop, long srcWidth, long srcHeight, long dstLeft, long dstTop, long dstWidth, long dstHeight, long flags, long op, unsigned long transparent);
 +   void  (*DstTransStretchBltSys)(DC, void *srcAddr, long srcPitch, long srcLeft, long srcTop, long srcWidth, long srcHeight, long dstLeft, long dstTop, long dstWidth, long dstHeight, long flags, long op, unsigned long transparent);
 +   void  (*DstTransStretchBltLin)(DC, long srcOfs, long srcPitch, long srcLeft, long srcTop, long srcWidth, long srcHeight, long dstLeft, long dstTop, long dstWidth, long dstHeight, long flags, long op, unsigned long transparent);
 +   void  (*DstTransStretchBltBM)(DC, long srcPhysAddr, long srcPitch, long srcLeft, long srcTop, long srcWidth, long srcHeight, long dstLeft, long dstTop, long dstWidth, long dstHeight, long flags, long op, unsigned long transparent);
 +
 +   /* hardware video functions */
 +   void  (*SetVideoInput)(DC, long width, long height, long format);
 +   void *(*SetVideoOutput)(DC, long left, long top, long width, long height);
 +   void  (*StartVideoFrame)(DC);
 +   void  (*EndVideoFrame)(DC);
 +
 +} AF_DRIVER;
 +
 +
 +
 +#undef DC
 +
 +
 +
 +/* register data for calling real mode interrupts (DPMI format) */
 +typedef union 
 +{
 +   struct {
 +      unsigned long edi;
 +      unsigned long esi;
 +      unsigned long ebp;
 +      unsigned long res;
 +      unsigned long ebx;
 +      unsigned long edx;
 +      unsigned long ecx;
 +      unsigned long eax;
 +   } d;
 +   struct {
 +      unsigned short di, di_hi;
 +      unsigned short si, si_hi;
 +      unsigned short bp, bp_hi;
 +      unsigned short res, res_hi;
 +      unsigned short bx, bx_hi;
 +      unsigned short dx, dx_hi;
 +      unsigned short cx, cx_hi;
 +      unsigned short ax, ax_hi;
 +      unsigned short flags;
 +      unsigned short es;
 +      unsigned short ds;
 +      unsigned short fs;
 +      unsigned short gs;
 +      unsigned short ip;
 +      unsigned short cs;
 +      unsigned short sp;
 +      unsigned short ss;
 +   } x;
 +   struct {
 +      unsigned char edi[4];
 +      unsigned char esi[4];
 +      unsigned char ebp[4];
 +      unsigned char res[4];
 +      unsigned char bl, bh, ebx_b2, ebx_b3;
 +      unsigned char dl, dh, edx_b2, edx_b3;
 +      unsigned char cl, ch, ecx_b2, ecx_b3;
 +      unsigned char al, ah, eax_b2, eax_b3;
 +   } h;
 +} RM_REGS;
 +
 +
 +
 +/* our API extensions use 32 bit magic numbers */
 +#define FAF_ID(a,b,c,d)    ((a<<24) | (b<<16) | (c<<8) | d)
 +
 +
 +
 +/* ID code and magic return value for initialising the extensions */
 +#define FAFEXT_INIT     FAF_ID('I','N','I','T')
 +#define FAFEXT_MAGIC    FAF_ID('E','X', 0,  0)
 +#define FAFEXT_MAGIC1   FAF_ID('E','X','0','1')
 +
 +
 +
 +/* extension providing a hardware-specific way to access video memory */
 +#define FAFEXT_HWPTR    FAF_ID('H','P','T','R')
 +
 +
 +#if (defined __i386__) && (!defined NO_HWPTR)
 +
 +
 +/* use seg+offset far pointers on i386 */
 +typedef struct FAF_HWPTR
 +{
 +   int sel;
 +   unsigned long offset;
 +} FAF_HWPTR;
 +
 +#include <sys/farptr.h>
 +#include <sys/segments.h>
 +
 +#define hwptr_init(ptr, addr)                \
 +   if ((addr) && (!(ptr).sel)) {             \
 +      (ptr).sel = _my_ds();                  \
 +      (ptr).offset = (unsigned long)(addr);  \
 +   }
 +
 +#define hwptr_pokeb(ptr, off, val)     _farpokeb((ptr).sel, (ptr).offset+(off), (val))
 +#define hwptr_pokew(ptr, off, val)     _farpokew((ptr).sel, (ptr).offset+(off), (val))
 +#define hwptr_pokel(ptr, off, val)     _farpokel((ptr).sel, (ptr).offset+(off), (val))
 +
 +#define hwptr_peekb(ptr, off)          _farpeekb((ptr).sel, (ptr).offset+(off))
 +#define hwptr_peekw(ptr, off)          _farpeekw((ptr).sel, (ptr).offset+(off))
 +#define hwptr_peekl(ptr, off)          _farpeekl((ptr).sel, (ptr).offset+(off))
 +
 +#define hwptr_select(ptr)              _farsetsel((ptr).sel)
 +#define hwptr_unselect(ptr)            (ptr).sel = _fargetsel()
 +
 +#define hwptr_nspokeb(ptr, off, val)   _farnspokeb((ptr).offset+(off), (val))
 +#define hwptr_nspokew(ptr, off, val)   _farnspokew((ptr).offset+(off), (val))
 +#define hwptr_nspokel(ptr, off, val)   _farnspokel((ptr).offset+(off), (val))
 +
 +#define hwptr_nspeekb(ptr, off)        _farnspeekb((ptr).offset+(off))
 +#define hwptr_nspeekw(ptr, off)        _farnspeekw((ptr).offset+(off))
 +#define hwptr_nspeekl(ptr, off)        _farnspeekl((ptr).offset+(off))
 +
 +
 +#else
 +
 +
 +/* use regular C pointers on other platforms or if hwptr is disabled */
 +typedef void *FAF_HWPTR;
 +
 +#define hwptr_init(ptr, addr)          ptr = (FAF_HWPTR)(addr)
 +
 +#define hwptr_pokeb(ptr, off, val)     *((volatile unsigned char *)((ptr)+(off))) = (val)
 +#define hwptr_pokew(ptr, off, val)     *((volatile unsigned short *)((ptr)+(off))) = (val)
 +#define hwptr_pokel(ptr, off, val)     *((volatile unsigned long *)((ptr)+(off))) = (val)
 +
 +#define hwptr_peekb(ptr, off)          (*((volatile unsigned char *)((ptr)+(off))))
 +#define hwptr_peekw(ptr, off)          (*((volatile unsigned short *)((ptr)+(off))))
 +#define hwptr_peekl(ptr, off)          (*((volatile unsigned long *)((ptr)+(off))))
 +
 +#define hwptr_select(ptr)
 +#define hwptr_unselect(ptr)            (ptr) = NULL
 +
 +#define hwptr_nspokeb(ptr, off, val)   *((volatile unsigned char *)((ptr)+(off))) = (val)
 +#define hwptr_nspokew(ptr, off, val)   *((volatile unsigned short *)((ptr)+(off))) = (val)
 +#define hwptr_nspokel(ptr, off, val)   *((volatile unsigned long *)((ptr)+(off))) = (val)
 +
 +#define hwptr_nspeekb(ptr, off)        (*((volatile unsigned char *)((ptr)+(off))))
 +#define hwptr_nspeekw(ptr, off)        (*((volatile unsigned short *)((ptr)+(off))))
 +#define hwptr_nspeekl(ptr, off)        (*((volatile unsigned long *)((ptr)+(off))))
 +
 +
 +#endif      /* hwptr structure definitions */
 +
 +
 +/* interface structure containing hardware pointer data */
 +typedef struct FAF_HWPTR_DATA
 +{
 +   FAF_HWPTR IOMemMaps[4];
 +   FAF_HWPTR BankedMem;
 +   FAF_HWPTR LinearMem;
 +} FAF_HWPTR_DATA;
 +
 +
 +
 +/* extension providing a way for the config program to set driver variables */
 +#define FAFEXT_CONFIG   FAF_ID('C','O','N','F')
 +
 +
 +
 +/* config variable, so the install program can communicate with the driver */
 +typedef struct FAF_CONFIG_DATA
 +{
 +   unsigned long id;
 +   unsigned long value;
 +} FAF_CONFIG_DATA;
 +
 +
 +
 +/* config variable ID used to enable/disable specific hardware functions */
 +#define FAF_CFG_FEATURES    FAF_ID('F','E','A','T')
 +
 +
 +
 +/* bitfield values for the FAF_CFG_FEATURES variable */
 +#define fafLinear                      0x00000001
 +#define fafBanked                      0x00000002
 +#define fafHWCursor                    0x00000004
 +#define fafDrawScan                    0x00000008
 +#define fafDrawPattScan                0x00000010
 +#define fafDrawColorPattScan           0x00000020
 +#define fafDrawScanList                0x00000040
 +#define fafDrawPattScanList            0x00000080
 +#define fafDrawColorPattScanList       0x00000100
 +#define fafDrawRect                    0x00000200
 +#define fafDrawPattRect                0x00000400
 +#define fafDrawColorPattRect           0x00000800
 +#define fafDrawLine                    0x00001000
 +#define fafDrawStippleLine             0x00002000
 +#define fafDrawTrap                    0x00004000
 +#define fafDrawTri                     0x00008000
 +#define fafDrawQuad                    0x00010000
 +#define fafPutMonoImage                0x00020000
 +#define fafPutMonoImageLin             0x00040000
 +#define fafPutMonoImageBM              0x00080000
 +#define fafBitBlt                      0x00100000
 +#define fafBitBltSys                   0x00200000
 +#define fafBitBltLin                   0x00400000
 +#define fafBitBltBM                    0x00800000
 +#define fafSrcTransBlt                 0x01000000
 +#define fafSrcTransBltSys              0x02000000
 +#define fafSrcTransBltLin              0x04000000
 +#define fafSrcTransBltBM               0x08000000
 +
 +
 +
 +/* helper function for enabling/disabling driver routines */
 +void fixup_feature_list(AF_DRIVER *af, unsigned long flags);
 +
 +
 +
 +/* extension providing libc exports (needed for Nucleus compatibility) */
 +#define FAFEXT_LIBC     FAF_ID('L','I','B','C')
 +
 +
 +typedef struct FAF_LIBC_DATA
 +{
 +   long  size;
 +   void  (*abort)();
 +   void *(*calloc)(unsigned long num_elements, unsigned long size);
 +   void  (*exit)(int status);
 +   void  (*free)(void *ptr);
 +   char *(*getenv)(const char *name);
 +   void *(*malloc)(unsigned long size);
 +   void *(*realloc)(void *ptr, unsigned long size);
 +   int   (*system)(const char *s);
 +   int   (*putenv)(const char *val);
 +   int   (*open)(const char *file, int mode, int permissions);
 +   int   (*access)(const char *filename, int flags);
 +   int   (*close)(int fd);
 +   int   (*lseek)(int fd, int offset, int whence);
 +   int   (*read)(int fd, void *buffer, unsigned long count);
 +   int   (*unlink)(const char *file);
 +   int   (*write)(int fd, const void *buffer, unsigned long count);
 +   int   (*isatty)(int fd);
 +   int   (*remove)(const char *file);
 +   int   (*rename)(const char *oldname, const char *newname);
 +   unsigned int (*time)(unsigned int *t);
 +   void  (*setfileattr)(const char *filename, unsigned attrib);
 +   unsigned long (*getcurrentdate)();
 +} FAF_LIBC_DATA;
 +
 +
 +
 +/* extension providing pmode exports (needed for Nucleus compatibility) */
 +#define FAFEXT_PMODE    FAF_ID('P','M','O','D')
 +
 +
 +
 +/* It has to be said, having this many exported functions is truly insane.
 + * How on earth can SciTech need this much crap just to write a simple
 + * video driver? Unfortunately we have to include it all in order to 
 + * support their Nucleus drivers...
 + */
 +
 +typedef union
 +{
 +   struct {
 +      unsigned long eax, ebx, ecx, edx, esi, edi, cflag;
 +   } e;
 +   struct {
 +      unsigned short ax, ax_hi;
 +      unsigned short bx, bx_hi;
 +      unsigned short cx, cx_hi;
 +      unsigned short dx, dx_hi;
 +      unsigned short si, si_hi;
 +      unsigned short di, di_hi;
 +      unsigned short cflag, cflag_hi;
 +   } x;
 +   struct {
 +      unsigned char   al, ah; unsigned short ax_hi;
 +      unsigned char   bl, bh; unsigned short bx_hi;
 +      unsigned char   cl, ch; unsigned short cx_hi;
 +      unsigned char   dl, dh; unsigned short dx_hi;
 +   } h;
 +} SILLY_SCITECH_REGS;
 +
 +
 +
 +typedef struct
 +{
 +   unsigned short es, cs, ss, ds, fs, gs;
 +} SILLY_SCITECH_SREGS;
 +
 +
 +
 +typedef struct FAF_PMODE_DATA
 +{
 +   long  size;
 +   int   (*getModeType)();
 +   void *(*getBIOSPointer)();
 +   void *(*getA0000Pointer)();
 +   void *(*mapPhysicalAddr)(unsigned long base, unsigned long limit);
 +   void *(*mallocShared)(long size);
 +   int   (*mapShared)(void *ptr);
 +   void  (*freeShared)(void *ptr);
 +   void *(*mapToProcess)(void *linear, unsigned long limit);
 +   void  (*loadDS)();
 +   void  (*saveDS)();
 +   void *(*mapRealPointer)(unsigned int r_seg, unsigned int r_off);
 +   void *(*allocRealSeg)(unsigned int size, unsigned int *r_seg, unsigned int *r_off);
 +   void  (*freeRealSeg)(void *mem);
 +   void *(*allocLockedMem)(unsigned int size, unsigned long *physAddr);
 +   void  (*freeLockedMem)(void *p);
 +   void  (*callRealMode)(unsigned int seg, unsigned int off, SILLY_SCITECH_REGS *regs, SILLY_SCITECH_SREGS *sregs);
 +   int   (*int86)(int intno, SILLY_SCITECH_REGS *in, SILLY_SCITECH_REGS *out);
 +   int   (*int86x)(int intno, SILLY_SCITECH_REGS *in, SILLY_SCITECH_REGS *out, SILLY_SCITECH_SREGS *sregs);
 +   void  (*DPMI_int86)(int intno, RM_REGS *regs);
 +   void  (*segread)(SILLY_SCITECH_SREGS *sregs);
 +   int   (*int386)(int intno, SILLY_SCITECH_REGS *in, SILLY_SCITECH_REGS *out);
 +   int   (*int386x)(int intno, SILLY_SCITECH_REGS *in, SILLY_SCITECH_REGS *out, SILLY_SCITECH_SREGS *sregs);
 +   void  (*availableMemory)(unsigned long *physical, unsigned long *total);
 +   void *(*getVESABuf)(unsigned int *len, unsigned int *rseg, unsigned int *roff);
 +   long  (*getOSType)();
 +   void  (*fatalError)(const char *msg);
 +   void  (*setBankA)(int bank);
 +   void  (*setBankAB)(int bank);
 +   const char *(*getCurrentPath)();
 +   const char *(*getVBEAFPath)();
 +   const char *(*getNucleusPath)();
 +   const char *(*getNucleusConfigPath)();
 +   const char *(*getUniqueID)();
 +   const char *(*getMachineName)();
 +   int   (*VF_available)();
 +   void *(*VF_init)(unsigned long baseAddr, int bankSize, int codeLen, void *bankFunc);
 +   void  (*VF_exit)();
 +   int   (*kbhit)();
 +   int   (*getch)();
 +   int   (*openConsole)();
 +   int   (*getConsoleStateSize)();
 +   void  (*saveConsoleState)(void *stateBuf, int console_id);
 +   void  (*restoreConsoleState)(const void *stateBuf, int console_id);
 +   void  (*closeConsole)(int console_id);
 +   void  (*setOSCursorLocation)(int x, int y);
 +   void  (*setOSScreenWidth)(int width, int height);
 +   int   (*enableWriteCombine)(unsigned long base, unsigned long length);
 +   void  (*backslash)(char *filename);
 +} FAF_PMODE_DATA;
 +
 +
 +
 +/* assorted helper functions */
 +void trace_putc(char c);
 +void trace_printf(char *msg, ...);
 +
 +void rm_int(int num, RM_REGS *regs);
 +
 +int allocate_dos_memory(int size, int *sel);
 +void free_dos_memory(int sel);
 +
 +int allocate_selector(int addr, int size);
 +void free_selector(int sel);
 +
 +int get_vesa_info(int *vram_size, unsigned long *linear_addr, void (*callback)(int vesa_num, int linear, int w, int h, int bpp, int bytes_per_scanline, int redsize, int redpos, int greensize, int greenpos, int bluesize, int bluepos, int rsvdsize, int rsvdpos));
 +
 +
 +
 +/* read_vga_register:
 + *  Reads the contents of a VGA hardware register.
 + */
 +extern inline int read_vga_register(int port, int index)
 +{
 +   if (port==0x3C0)
 +      inportb(0x3DA); 
 +
 +   outportb(port, index);
 +   return inportb(port+1);
 +}
 +
 +
 +
 +/* write_vga_register:
 + *  Writes a byte to a VGA hardware register.
 + */
 +extern inline void write_vga_register(int port, int index, int v) 
 +{
 +   if (port==0x3C0) {
 +      inportb(0x3DA);
 +      outportb(port, index);
 +      outportb(port, v);
 +   }
 +   else {
 +      outportb(port, index);
 +      outportb(port+1, v);
 +   }
 +}
 +
 +
 +
 +/* alter_vga_register:
 + *  Alters specific bits of a VGA hardware register.
 + */
 +extern inline void alter_vga_register(int port, int index, int mask, int v)
 +{
 +   int temp;
 +   temp = read_vga_register(port, index);
 +   temp &= (~mask);
 +   temp |= (v & mask);
 +   write_vga_register(port, index, temp);
 +}
 +
 +
 +
 +/* test_vga_register:
 + *  Tests whether specific bits of a VGA hardware register can be changed.
 + */
 +extern inline int test_vga_register(int port, int index, int mask)
 +{
 +   int old, nw1, nw2;
 +
 +   old = read_vga_register(port, index);
 +   write_vga_register(port, index, old & (~mask));
 +   nw1 = read_vga_register(port, index) & mask;
 +   write_vga_register(port, index, old | mask);
 +   nw2 = read_vga_register(port, index) & mask;
 +   write_vga_register(port, index, old);
 +
 +   return ((nw1==0) && (nw2==mask));
 +}
 +
 +
 +
 +/* test_register:
 + *  Tests whether specific bits of a hardware register can be changed.
 + */
 +extern inline int test_register(int port, int mask)
 +{
 +   int old, nw1, nw2;
 +
 +   old = inportb(port);
 +   outportb(port, old & (~mask));
 +   nw1 = inportb(port) & mask;
 +   outportb(port, old | mask);
 +   nw2 = inportb(port) & mask;
 +   outportb(port, old);
 +
 +   return ((nw1==0) && (nw2==mask));
 +}
 +
 +
 +
 +/* PCI routines added by SET */
 +#define PCIConfigurationAddress  0xCF8
 +#define PCIConfigurationData     0xCFC
 +#define PCIEnable                0x80000000
 +
 +extern int FindPCIDevice(int deviceID, int vendorID, int deviceIndex, int *handle);
 +
 +extern inline unsigned PCIReadLong(int handle, int index)
 +{
 +   outportl(PCIConfigurationAddress, PCIEnable | handle | index);
 +   return inportl(PCIConfigurationData);
 +}
 diff --git a/src/mesa/drivers/dos/vbeafint.h b/src/mesa/drivers/dos/vbeafint.h new file mode 100644 index 0000000000..5e636f08d3 --- /dev/null +++ b/src/mesa/drivers/dos/vbeafint.h @@ -0,0 +1,50 @@ +/*
 + * Mesa 3-D graphics library
 + * Version:  4.0
 + * 
 + * Copyright (C) 1999  Brian Paul   All Rights Reserved.
 + * 
 + * Permission is hereby granted, free of charge, to any person obtaining a
 + * copy of this software and associated documentation files (the "Software"),
 + * to deal in the Software without restriction, including without limitation
 + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 + * and/or sell copies of the Software, and to permit persons to whom the
 + * Software is furnished to do so, subject to the following conditions:
 + * 
 + * The above copyright notice and this permission notice shall be included
 + * in all copies or substantial portions of the Software.
 + * 
 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 + */
 +
 +/*
 + * DOS/DJGPP device driver v0.2 for Mesa 4.0
 + *
 + *  Copyright (C) 2002 - Borca Daniel
 + *  Email : dborca@yahoo.com
 + *  Web   : http://www.geocities.com/dborca
 + */
 +
 +
 +#ifndef VBEAFINT_H_included
 +#define VBEAFINT_H_included
 +
 +#include "vbeaf.h"
 +
 +int af_init (char *filename);
 +void af_exit (void);
 +
 +AF_MODE_INFO *af_getmode (int i, int *granularity);
 +int af_setup_mode (int mode, int caps);
 +int af_enter_mode (int mode, int width, int height);
 +int af_setup_buffer (int x, int y);
 +int af_flip (void);
 +
 +void *af_getprim (int primitive);
 +
 +#endif
 diff --git a/src/mesa/drivers/dos/video.c b/src/mesa/drivers/dos/video.c new file mode 100644 index 0000000000..5c2c84a84f --- /dev/null +++ b/src/mesa/drivers/dos/video.c @@ -0,0 +1,625 @@ +/*
 + * Mesa 3-D graphics library
 + * Version:  4.0
 + * 
 + * Copyright (C) 1999  Brian Paul   All Rights Reserved.
 + * 
 + * Permission is hereby granted, free of charge, to any person obtaining a
 + * copy of this software and associated documentation files (the "Software"),
 + * to deal in the Software without restriction, including without limitation
 + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 + * and/or sell copies of the Software, and to permit persons to whom the
 + * Software is furnished to do so, subject to the following conditions:
 + * 
 + * The above copyright notice and this permission notice shall be included
 + * in all copies or substantial portions of the Software.
 + * 
 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 + */
 +
 +/*
 + * DOS/DJGPP device driver v0.3 for Mesa 4.0
 + *
 + *  Copyright (C) 2002 - Borca Daniel
 + *  Email : dborca@yahoo.com
 + *  Web   : http://www.geocities.com/dborca
 + */
 +
 +
 +#include <dpmi.h>
 +#include <stdlib.h>
 +#include <string.h>
 +#include <stubinfo.h>
 +#include <sys/exceptn.h>
 +#include <sys/segments.h>
 +#include <sys/farptr.h>
 +
 +#include "video.h"
 +#include "dpmiint.h"
 +
 +
 +
 +typedef unsigned char word8;
 +typedef unsigned short word16;
 +typedef unsigned long word32;
 +
 +typedef struct vl_mode {
 +        int mode;
 +        int xres, yres;
 +        int scanlen;
 +        int bpp;
 +} vl_mode;
 +
 +#define _16_ *(word16 *)&
 +#define _32_ *(word32 *)&
 +
 +static int init;
 +
 +static vl_mode modes[64];
 +
 +/* card specific: valid forever */
 +static word16 vesa_ver;
 +static word32 hw_granularity, hw_linearfb;
 +static unsigned int gran_shift, gran_mask;
 +/* based upon mode specific data: valid entire session */
 +static int video_selector, banked_selector, linear_selector;
 +static int video_scanlen, video_bypp;
 +/* valid until next buffer */
 +static int current_offset, current_delta, current_width;
 +
 +
 +
 +/* lookup table for scaling 5 bit colors up to 8 bits */
 +static int _rgb_scale_5[32] =
 +{
 +   0,   8,   16,  24,  32,  41,  49,  57,
 +   65,  74,  82,  90,  98,  106, 115, 123,
 +   131, 139, 148, 156, 164, 172, 180, 189,
 +   197, 205, 213, 222, 230, 238, 246, 255
 +};
 +
 +/* lookup table for scaling 6 bit colors up to 8 bits */
 +static int _rgb_scale_6[64] =
 +{
 +   0,   4,   8,   12,  16,  20,  24,  28,
 +   32,  36,  40,  44,  48,  52,  56,  60,
 +   64,  68,  72,  76,  80,  85,  89,  93,
 +   97,  101, 105, 109, 113, 117, 121, 125,
 +   129, 133, 137, 141, 145, 149, 153, 157,
 +   161, 165, 170, 174, 178, 182, 186, 190,
 +   194, 198, 202, 206, 210, 214, 218, 222,
 +   226, 230, 234, 238, 242, 246, 250, 255
 +};
 +
 +
 +
 +/*
 + * virtual clearing
 + */
 +void (*vl_clear) (void *buffer, int len, int color);
 +
 +#define v_clear15 v_clear16
 +extern void v_clear16 (void *buffer, int len, int color);
 +extern void v_clear32 (void *buffer, int len, int color);
 +__asm__("\n\
 +		.text				\n\
 +		.balign	4			\n\
 +		.global	_v_clear16		\n\
 +_v_clear16:					\n\
 +		movl	12(%esp), %eax		\n\
 +		pushw	%ax			\n\
 +		pushw	%ax			\n\
 +		popl	%eax			\n\
 +		jmp	_v_clear_common		\n\
 +		.balign	4			\n\
 +		.global	_v_clear32		\n\
 +_v_clear32:					\n\
 +		movl	12(%esp), %eax		\n\
 +		.balign	4			\n\
 +_v_clear_common:				\n\
 +		movl	8(%esp), %ecx		\n\
 +		movl	4(%esp), %edx		\n\
 +		shrl	$2, %ecx		\n\
 +	0:					\n\
 +		.balign	4			\n\
 +		movl	%eax, (%edx)		\n\
 +		addl	$4, %edx		\n\
 +		decl	%ecx			\n\
 +		jnz	0b			\n\
 +		ret");
 +extern void v_clear24 (void *buffer, int len, int color);
 +__asm__("\n\
 +		.text				\n\
 +		.balign	4			\n\
 +		.global	_v_clear24		\n\
 +_v_clear24:					\n\
 +		movl	8(%esp), %edx		\n\
 +		movl	$0xaaaaaaab, %eax	\n\
 +		mull	%edx			\n\
 +		movl	12(%esp), %eax		\n\
 +		movl	%edx, %ecx		\n\
 +		movl	4(%esp), %edx		\n\
 +		pushl	%ebx			\n\
 +		shrl	%ecx			\n\
 +		movb	18(%esp), %bl		\n\
 +		.balign	4			\n\
 +	0:					\n\
 +		movw	%ax, (%edx)		\n\
 +		movb	%bl, 2(%edx)		\n\
 +		addl	$3, %edx		\n\
 +		decl	%ecx			\n\
 +		jnz	0b			\n\
 +		popl	%ebx			\n\
 +		ret");
 +
 +
 +
 +/*
 + * virtual rectangle clearing
 + */
 +void vl_rect (void *buffer, int x, int y, int width, int height, int color)
 +{
 + int offset = y*current_width + x;
 + int delta = current_width - width;
 +
 + for (y=0; y<height; y++) {
 +     for (x=0; x<width; x++, offset++) {
 +         vl_putpixel(buffer, offset, color);
 +     }
 +     offset += delta;
 + }
 +}
 +
 +
 +
 +/*
 + * virtual dumping:
 + */
 +void *(*vl_flip) (void *buffer, int width, int height);
 +
 +extern void *b_dump_virtual (void *buffer, int width, int height);
 +__asm__("\n\
 +		.text				\n\
 +		.balign	4			\n\
 +		.global	_b_dump_virtual		\n\
 +_b_dump_virtual:				\n\
 +		pushl	%ebx			\n\
 +		pushl	%esi			\n\
 +		pushl	%edi			\n\
 +		pushl	%ebp			\n\
 +		movl	_video_selector, %fs	\n\
 +		movl	4*4+4+0(%esp), %esi	\n\
 +		movl	_hw_granularity, %ebp	\n\
 +		xorl	%edx, %edx		\n\
 +		movl	_current_offset, %eax	\n\
 +		divl	%ebp			\n\
 +		movl	%edx, %edi		\n\
 +		pushl	%eax			\n\
 +		movl	%eax, %edx		\n\
 +		xorl	%ebx, %ebx		\n\
 +		movw	$0x4f05, %ax		\n\
 +		int	$0x10			\n\
 +		movl	_current_delta, %ebx	\n\
 +		movl	5*4+4+4(%esp), %ecx	\n\
 +		movl	5*4+4+8(%esp), %edx	\n\
 +		shrl	$2, %ecx		\n\
 +		.balign	4			\n\
 +	0:					\n\
 +		pushl	%ecx			\n\
 +		.balign	4			\n\
 +	1:					\n\
 +		cmpl	%ebp, %edi		\n\
 +		jb	2f			\n\
 +		pushl	%ebx			\n\
 +		pushl	%edx			\n\
 +		incl	12(%esp)		\n\
 +		movw	$0x4f05, %ax		\n\
 +		movl	12(%esp), %edx		\n\
 +		xorl	%ebx, %ebx		\n\
 +		int	$0x10			\n\
 +		popl	%edx			\n\
 +		popl	%ebx			\n\
 +		subl	%ebp, %edi		\n\
 +	2:					\n\
 +		movl	(%esi), %eax		\n\
 +		addl	$4, %esi		\n\
 +		movl	%eax, %fs:(%edi)	\n\
 +		addl	$4, %edi		\n\
 +		decl	%ecx			\n\
 +		jnz	1b			\n\
 +		popl	%ecx			\n\
 +		addl	%ebx, %edi		\n\
 +		decl	%edx			\n\
 +		jnz	0b			\n\
 +		popl	%eax			\n\
 +		popl	%ebp			\n\
 +		popl	%edi			\n\
 +		popl	%esi			\n\
 +		popl	%ebx			\n\
 +		ret");
 +extern void *l_dump_virtual (void *buffer, int width, int height);
 +__asm__("\n\
 +		.text				\n\
 +		.balign	4			\n\
 +		.global	_l_dump_virtual		\n\
 +_l_dump_virtual:				\n\
 +		pushl	%ebx			\n\
 +		pushl	%esi			\n\
 +		pushl	%edi			\n\
 +		movl	_video_selector, %fs	\n\
 +		movl	3*4+4+0(%esp), %esi	\n\
 +		movl	_current_offset, %edi	\n\
 +		movl	3*4+4+4(%esp), %ecx	\n\
 +		movl	3*4+4+8(%esp), %edx	\n\
 +		movl	_current_delta, %ebx	\n\
 +		shrl	$2, %ecx		\n\
 +		.balign	4			\n\
 +	0:					\n\
 +		pushl	%ecx			\n\
 +		.balign	4			\n\
 +	1:					\n\
 +		movl	(%esi), %eax		\n\
 +		addl	$4, %esi		\n\
 +		movl	%eax, %fs:(%edi)	\n\
 +		addl	$4, %edi		\n\
 +		decl	%ecx			\n\
 +		jnz	1b			\n\
 +		popl	%ecx			\n\
 +		addl	%ebx, %edi		\n\
 +		decl	%edx			\n\
 +		jnz	0b			\n\
 +		popl	%edi			\n\
 +		popl	%esi			\n\
 +		popl	%ebx			\n\
 +		ret");
 +
 +
 +
 +/*
 + * mix RGBA components
 + */
 +int (*vl_mixrgba) (const unsigned char rgba[]);
 + 
 +#define vl_mixrgba15 vl_mixrgb15
 +#define vl_mixrgba16 vl_mixrgb16
 +#define vl_mixrgba24 vl_mixrgb24
 +static int vl_mixrgba32 (const unsigned char rgba[])
 +{
 + return (rgba[3]<<24)|(rgba[0]<<16)|(rgba[1]<<8)|(rgba[2]);
 +}
 +
 +
 +
 +/*
 + * mix RGB components
 + */
 +int (*vl_mixrgb) (const unsigned char rgb[]);
 + 
 +static int vl_mixrgb15 (const unsigned char rgb[])
 +{
 + return ((rgb[0]>>3)<<10)|((rgb[1]>>3)<<5)|(rgb[2]>>3);
 +}
 +static int vl_mixrgb16 (const unsigned char rgb[])
 +{
 + return ((rgb[0]>>3)<<11)|((rgb[1]>>2)<<5)|(rgb[2]>>3);
 +}
 +#define vl_mixrgb24 vl_mixrgb32
 +static int vl_mixrgb32 (const unsigned char rgb[])
 +{
 + return (rgb[0]<<16)|(rgb[1]<<8)|(rgb[2]);
 +}
 +
 +
 +
 +/*
 + * vl_putpixel*
 + */
 +void (*vl_putpixel) (void *buffer, int offset, int color);
 + 
 +#define v_putpixel15 v_putpixel16
 +extern void v_putpixel16 (void *buffer, int offset, int color);
 +__asm__("\n\
 +		.text				\n\
 +		.balign	4			\n\
 +		.global	_v_putpixel16		\n\
 +_v_putpixel16:					\n\
 +		movl	8(%esp), %edx		\n\
 +		shll	%edx			\n\
 +		movl	12(%esp), %eax		\n\
 +		addl	4(%esp), %edx		\n\
 +		movw	%ax, (%edx)		\n\
 +		ret");
 +extern void v_putpixel24 (void *buffer, int offset, int color);
 +__asm__("\n\
 +		.text				\n\
 +		.balign	4			\n\
 +		.global	_v_putpixel24		\n\
 +_v_putpixel24:					\n\
 +		movl	8(%esp), %edx		\n\
 +		leal	(%edx, %edx, 2), %edx	\n\
 +		movl	12(%esp), %eax		\n\
 +		addl	4(%esp), %edx		\n\
 +		movw	%ax, (%edx)		\n\
 +		shrl	$16, %eax		\n\
 +		movb	%al, 2(%edx)		\n\
 +		ret");
 +extern void v_putpixel32 (void *buffer, int offset, int color);
 +__asm__("\n\
 +		.text				\n\
 +		.balign	4			\n\
 +		.global	_v_putpixel32		\n\
 +_v_putpixel32:					\n\
 +		movl	8(%esp), %edx		\n\
 +		shll	$2, %edx		\n\
 +		movl	12(%esp), %eax		\n\
 +		addl	4(%esp), %edx		\n\
 +		movl	%eax, (%edx)		\n\
 +		ret");
 +
 +
 +
 +/*
 + * get pixel and decompose R, G, B, A
 + */
 +void (*vl_getrgba) (void *buffer, int offset, unsigned char rgba[4]);
 +
 +/*
 + * v_getrgba*
 + */
 +static void v_getrgba15 (void *buffer, int offset, unsigned char rgba[4])
 +{
 + int c = ((word16 *)buffer)[offset];
 + rgba[0] = _rgb_scale_5[(c >> 10) & 0x1F];
 + rgba[1] = _rgb_scale_5[(c >> 5) & 0x1F];
 + rgba[2] = _rgb_scale_5[c & 0x1F];
 + rgba[3] = 255;
 +}
 +static void v_getrgba16 (void *buffer, int offset, unsigned char rgba[4])
 +{
 + int c = ((word16 *)buffer)[offset];
 + rgba[0] = _rgb_scale_5[(c >> 11) & 0x1F];
 + rgba[1] = _rgb_scale_6[(c >> 5) & 0x3F];
 + rgba[2] = _rgb_scale_5[c & 0x1F];
 + rgba[3] = 255;
 +}
 +static void v_getrgba24 (void *buffer, int offset, unsigned char rgba[4])
 +{
 + int c = *(word32 *)((long)buffer+offset*3);
 + rgba[0] = c >> 16;
 + rgba[1] = c >> 8;
 + rgba[2] = c;
 + rgba[3] = 255;
 +}
 +static void v_getrgba32 (void *buffer, int offset, unsigned char rgba[4])
 +{
 + int c = ((word32 *)buffer)[offset];
 + rgba[0] = c >> 16;
 + rgba[1] = c >> 8;
 + rgba[2] = c; 
 + rgba[3] = c >> 24;
 +}
 +
 +
 +
 +/*
 + * sync buffer with video hardware
 + */
 +void *vl_sync_buffer (void *buffer, int x, int y, int width, int height)
 +{
 + void *newbuf;
 +
 + if (width&3) {
 +    return NULL;
 + } else {
 +    current_offset = video_scanlen * y + video_bypp * x;
 +    if ((newbuf=realloc(buffer, width*height*video_bypp))!=NULL) {
 +       current_width = width;
 +       current_delta = video_scanlen - video_bypp * width;
 +       return newbuf;
 +    } else {
 +       return NULL;
 +    }
 + }
 +}
 +
 +
 +
 +/*
 + * attempts to detect VESA and video modes
 + */
 +static word16 vl_vesa_init (void)
 +{
 + __dpmi_regs r;
 + unsigned short *p;
 + vl_mode *q;
 + char vesa_info[512], tmp[512];
 + int maxsize = 0;
 +
 + _farpokel(_stubinfo->ds_selector, 0, 0x32454256);
 + r.x.ax = 0x4f00;
 + r.x.di = 0;
 + r.x.es = _stubinfo->ds_segment;
 + __dpmi_int(0x10, &r);
 + if (r.x.ax==0x004f) {
 +    movedata(_stubinfo->ds_selector, 0, _my_ds(), (unsigned)vesa_info, 512);
 +    if ((_32_ vesa_info[0])==0x41534556) {
 +       p = (unsigned short *)(((_16_ vesa_info[0x10])<<4) + (_16_ vesa_info[0x0e]));
 +       q = modes;
 +       do {
 +           if ((q->mode=_farpeekw(__djgpp_dos_sel, (unsigned long)(p++)))==0xffff) {
 +              break;
 +           }
 +
 +           r.x.ax = 0x4f01;
 +           r.x.cx = q->mode;
 +           r.x.di = 512;
 +           r.x.es = _stubinfo->ds_segment;
 +           __dpmi_int(0x10, &r);
 +           movedata(_stubinfo->ds_selector, 512, _my_ds(), (unsigned)tmp, 256);
 +           switch (tmp[0x19]) {
 +                  case 16:
 +                       q->bpp = tmp[0x1f] + tmp[0x21] + tmp[0x23];
 +                       break;
 +                  case 15:
 +                  case 24:
 +                  case 32:
 +                       q->bpp = tmp[0x19];
 +                       break;
 +                  default:
 +                       q->bpp = 0;
 +           }
 +           if ((r.x.ax==0x004f)&&((tmp[0]&0x11)==0x11)&&q->bpp) {
 +              q->xres = _16_ tmp[0x12];
 +              q->yres = _16_ tmp[0x14];
 +              q->scanlen = _16_ tmp[0x10];
 +              hw_granularity = (_16_ tmp[4])<<10;
 +              if (tmp[0]&0x80) {
 +                 *(q+1) = *q++;
 +                 hw_linearfb = _32_ tmp[0x28];
 +                 q->mode |= 0x4000;
 +              }
 +              if (maxsize<(q->scanlen*q->yres)) {
 +                 maxsize = q->scanlen*q->yres;
 +              }
 +              q++;
 +           }
 +       } while (!0);
 +
 +       if (hw_linearfb) {
 +          maxsize = ((maxsize+0xfffUL)&~0xfffUL);
 +          if (_create_selector(&linear_selector, hw_linearfb, maxsize)) {
 +             return 0;
 +          }
 +       }
 +       if (_create_selector(&banked_selector, 0xa0000, hw_granularity)) {
 +          _remove_selector(&linear_selector);
 +          return 0;
 +       }
 +
 +       return _16_ vesa_info[4];
 +    }
 + }
 +
 + return 0;
 +}
 +
 +
 +
 +/*
 + * setup mode
 + */
 +static int vl_setup_mode (vl_mode *p)
 +{
 + if (p->mode&0x4000) {
 +    video_selector = linear_selector;
 +    vl_flip = l_dump_virtual;
 + } else {
 +    { int n; for (gran_shift=0, n=hw_granularity; n; gran_shift++, n>>=1) ; }
 +    gran_mask = (1<<(--gran_shift)) - 1;
 +    if (hw_granularity!=(gran_mask+1)) {
 +       return -1;
 +    }
 +    video_selector = banked_selector;
 +    vl_flip = b_dump_virtual;
 + }
 +
 +#define INITPTR(bpp) \
 +        vl_putpixel = v_putpixel##bpp; \
 +        vl_getrgba = v_getrgba##bpp;   \
 +        vl_clear = v_clear##bpp;       \
 +        vl_mixrgb = vl_mixrgb##bpp;    \
 +        vl_mixrgba = vl_mixrgba##bpp;
 +
 + switch (p->bpp) {
 +        case 15:
 +             INITPTR(15);
 +             break;
 +        case 16:
 +             INITPTR(16);
 +             break;
 +        case 24:
 +             INITPTR(24);
 +             break;
 +        case 32:
 +             INITPTR(32);
 +             break;
 +        default:
 +             return -1;
 + }
 +
 +#undef INITPTR
 +
 + video_bypp = (p->bpp+7)/8;
 + video_scanlen = p->scanlen;
 +
 + return 0;
 +}
 +
 +
 +
 +/*
 + * shutdown the video engine
 + */
 +void vl_video_exit (int textmode)
 +{
 + if (init) {
 +    if (textmode) {
 +       __asm__("movw $0x3, %%ax; int  $0x10":::"%eax");
 +    }
 +    
 +    _remove_selector(&linear_selector);
 +    _remove_selector(&banked_selector);
 +   
 +    init = !init;
 + }
 +}
 +
 +
 +
 +/*
 + * initialize video engine
 + *
 + * success: 0
 + * failure: -1
 + */
 +int vl_video_init (int width, int height, int bpp)
 +{
 + vl_mode *p, *q;
 + unsigned int min;
 +
 + /* check for prior initialization */
 + if (init) {
 +    return 0;
 + }
 +
 + /* initialize hardware */
 + if (!(vesa_ver=vl_vesa_init())) {
 +    return -1;
 + }
 + init = !init;
 +
 + /* search for a mode that fits our request */
 + for (min=-1, p=NULL, q=modes; q->mode!=0xffff; q++) {
 +     if ((q->xres>=width)&&(q->yres>=height)&&(q->bpp==bpp)) {
 +        if (min>=(unsigned)(q->xres*q->yres)) {
 +           min = q->xres*q->yres;
 +           p = q;
 +        }
 +     }
 + }
 +
 + if (p) {
 +    vl_setup_mode(p);
 +    __asm__("movw $0x4f02, %%ax; int  $0x10"::"b"(p->mode):"%eax");
 +    return 0;
 + } else {
 +    /* no suitable mode found, abort */
 +    vl_video_exit(0);
 +    return -1;
 + }
 +}
 diff --git a/src/mesa/drivers/dos/video.h b/src/mesa/drivers/dos/video.h new file mode 100644 index 0000000000..ff81ac9d2e --- /dev/null +++ b/src/mesa/drivers/dos/video.h @@ -0,0 +1,52 @@ +/*
 + * Mesa 3-D graphics library
 + * Version:  4.0
 + * 
 + * Copyright (C) 1999  Brian Paul   All Rights Reserved.
 + * 
 + * Permission is hereby granted, free of charge, to any person obtaining a
 + * copy of this software and associated documentation files (the "Software"),
 + * to deal in the Software without restriction, including without limitation
 + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 + * and/or sell copies of the Software, and to permit persons to whom the
 + * Software is furnished to do so, subject to the following conditions:
 + * 
 + * The above copyright notice and this permission notice shall be included
 + * in all copies or substantial portions of the Software.
 + * 
 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 + */
 +
 +/*
 + * DOS/DJGPP device driver v0.3 for Mesa 4.0
 + *
 + *  Copyright (C) 2002 - Borca Daniel
 + *  Email : dborca@yahoo.com
 + *  Web   : http://www.geocities.com/dborca
 + */
 +
 +
 +#ifndef VIDEO_H_included
 +#define VIDEO_H_included
 +
 +int vl_video_init (int width, int height, int bpp);
 +void vl_video_exit (int textmode);
 +
 +void *vl_sync_buffer (void *buffer, int x, int y, int width, int height);
 +
 +extern void (*vl_clear) (void *buffer, int len, int color);
 +void vl_rect (void *buffer, int x, int y, int width, int height, int color);
 +
 +void *(*vl_flip) (void *buffer, int width, int height);
 +
 +extern int (*vl_mixrgba) (const unsigned char rgba[]);
 +extern int (*vl_mixrgb) (const unsigned char rgb[]);
 +extern void (*vl_putpixel) (void *buffer, int offset, int color);
 +extern void (*vl_getrgba) (void *buffer, int offset, unsigned char rgba[4]);
 +
 +#endif
 | 
