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