summaryrefslogtreecommitdiffstats
path: root/src/mesa/drivers/dos/video.c
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2002-09-03 18:11:32 +0000
committerBrian Paul <[email protected]>2002-09-03 18:11:32 +0000
commit05ed911aca5ad0a6842ea0d6f3ac99b79ec752db (patch)
tree3eab5e0bb8d2d90f3076a0c48679b7f08674ba73 /src/mesa/drivers/dos/video.c
parentb9f75444e60477e7a523e7eec1bb49a8232fd4e7 (diff)
updates from Daniel Borca
Diffstat (limited to 'src/mesa/drivers/dos/video.c')
-rw-r--r--src/mesa/drivers/dos/video.c439
1 files changed, 55 insertions, 384 deletions
diff --git a/src/mesa/drivers/dos/video.c b/src/mesa/drivers/dos/video.c
index d31037de616..16e72cf5810 100644
--- a/src/mesa/drivers/dos/video.c
+++ b/src/mesa/drivers/dos/video.c
@@ -23,7 +23,7 @@
*/
/*
- * DOS/DJGPP device driver v1.0 for Mesa 4.0
+ * DOS/DJGPP device driver v1.1 for Mesa 4.0
*
* Copyright (C) 2002 - Borca Daniel
* Email : [email protected]
@@ -31,52 +31,29 @@
*/
-#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"
+#include "videoint.h"
+#include "vesa/vesa.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];
-
+static vl_driver *drv = &VESA;
/* card specific: valid forever */
-static word16 vesa_ver;
-static word32 hw_granularity, hw_linearfb;
+word32 vl_hw_granularity;
static unsigned int gran_shift, gran_mask;
/* based upon mode specific data: valid entire session */
-static int video_selector, banked_selector, linear_selector;
+int vl_video_selector;
static int video_scanlen, video_bypp;
/* valid until next buffer */
-static int current_offset, current_delta, current_width;
+int vl_current_offset, vl_current_delta;
+static int current_width;
/* lookup table for scaling 5 bit colors up to 8 bits */
-static int _rgb_scale_5[32] =
-{
+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,
@@ -84,8 +61,7 @@ static int _rgb_scale_5[32] =
};
/* lookup table for scaling 6 bit colors up to 8 bits */
-static int _rgb_scale_6[64] =
-{
+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,
@@ -98,69 +74,17 @@ static int _rgb_scale_6[64] =
-/*
- * 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");
+void (*vl_clear) (void *buffer, int bytes, int color);
+void (*vl_flip) (void *buffer, int stride, int height);
+int (*vl_mixrgba) (const unsigned char rgba[]);
+int (*vl_mixrgb) (const unsigned char rgb[]);
+void (*vl_putpixel) (void *buffer, int offset, int color);
+void (*vl_getrgba) (void *buffer, int offset, unsigned char rgba[4]);
-/*
- * virtual rectangle clearing
+/* vl_rect:
+ * Clears a rectange with specified color.
*/
void vl_rect (void *buffer, int x, int y, int width, int height, int color)
{
@@ -177,114 +101,9 @@ void vl_rect (void *buffer, int x, int y, int width, int height, int color)
-/*
- * virtual dumping:
+/* vl_mixrgba*:
+ * Color composition (w/ ALPHA).
*/
-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
@@ -295,11 +114,9 @@ static int vl_mixrgba32 (const unsigned char rgba[])
-/*
- * mix RGB components
+/* vl_mixrgb*:
+ * Color composition (w/o ALPHA).
*/
-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);
@@ -316,60 +133,8 @@ static int vl_mixrgb32 (const unsigned char rgb[])
-/*
- * 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*
+/* v_getrgba*:
+ * Color decomposition.
*/
static void v_getrgba15 (void *buffer, int offset, unsigned char rgba[4])
{
@@ -406,8 +171,8 @@ static void v_getrgba32 (void *buffer, int offset, unsigned char rgba[4])
-/*
- * sync buffer with video hardware
+/* vl_sync_buffer:
+ * Syncs buffer with video hardware. Returns NULL in case of failure.
*/
void *vl_sync_buffer (void *buffer, int x, int y, int width, int height)
{
@@ -417,9 +182,9 @@ void *vl_sync_buffer (void *buffer, int x, int y, int width, int height)
return NULL;
} else {
if ((newbuf=realloc(buffer, width*height*video_bypp))!=NULL) {
- current_offset = video_scanlen * y + video_bypp * x;
+ vl_current_offset = video_scanlen * y + video_bypp * x;
current_width = width;
- current_delta = video_scanlen - video_bypp * width;
+ vl_current_delta = video_scanlen - video_bypp * width;
}
return newbuf;
}
@@ -427,102 +192,22 @@ void *vl_sync_buffer (void *buffer, int x, int y, int width, int height)
-/*
- * 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
+/* vl_setup_mode:
+ *
+ * success: 0
+ * failure: -1
*/
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) ; }
+ { int n; for (gran_shift=0, n=p->gran; n; gran_shift++, n>>=1) ; }
gran_mask = (1<<(--gran_shift)) - 1;
- if (hw_granularity!=(gran_mask+1)) {
+ if ((unsigned)p->gran != (gran_mask+1)) {
return -1;
}
- video_selector = banked_selector;
+ vl_hw_granularity = p->gran;
vl_flip = b_dump_virtual;
}
@@ -554,56 +239,44 @@ static int vl_setup_mode (vl_mode *p)
video_bypp = (p->bpp+7)/8;
video_scanlen = p->scanlen;
+ vl_video_selector = p->sel;
return 0;
}
-/*
- * shutdown the video engine
+/* vl_video_exit:
+ * Shutdown the video engine.
+ * Restores to the mode prior to first call to `vl_video_init'.
*/
-void vl_video_exit (int textmode)
+void vl_video_exit (void)
{
- if (init) {
- if (textmode) {
- __asm__("movw $0x3, %%ax; int $0x10":::"%eax");
- }
-
- _remove_selector(&linear_selector);
- _remove_selector(&banked_selector);
-
- init = !init;
- }
+ drv->restore();
+ drv->finit();
}
-/*
- * initialize video engine
+/* vl_video_init:
+ * Enter mode.
*
- * success: 0
- * failure: -1
+ * success: 0
+ * failure: -1
*/
-int vl_video_init (int width, int height, int bpp)
+int vl_video_init (int width, int height, int bpp, int refresh)
{
vl_mode *p, *q;
unsigned int min;
- /* check for prior initialization */
- if (init) {
- return 0;
- }
-
/* initialize hardware */
- if (!(vesa_ver=vl_vesa_init())) {
+ if ((q=drv->getmodes()) == NULL) {
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)) {
+ for (min=-1, p=NULL; 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;
@@ -611,13 +284,11 @@ int vl_video_init (int width, int height, int bpp)
}
}
- if (p) {
- vl_setup_mode(p);
- __asm__("movw $0x4f02, %%ax; int $0x10"::"b"(p->mode):"%eax");
+ /* check, setup and enter mode */
+ if ((p!=NULL) && (vl_setup_mode(p) == 0) && (drv->entermode(p, refresh) == 0)) {
return 0;
- } else {
- /* no suitable mode found, abort */
- vl_video_exit(0);
- return -1;
}
+
+ /* abort */
+ return -1;
}