Authors: Paul Quinn <paulq@corel.ca>, Albert Den Haan <albertd@corel.ca>
[wine] / graphics / dispdib.c
1 /*
2  * DISPDIB.dll
3  * 
4  * Copyright 1998 Ove Kåven (with some help from Marcus Meissner)
5  *
6  */
7
8 #include <string.h>
9 #include "windows.h"
10 #include "miscemu.h"
11 #include "dispdib.h"
12 #include "vga.h"
13 #include "debug.h"
14
15 static int dispdib_multi = 0;
16
17 static WORD DISPDIB_Begin(WORD wFlags)
18 {
19     unsigned Xres,Yres,Depth;
20
21     switch(wFlags&DISPLAYDIB_MODE) {
22         case DISPLAYDIB_MODE_DEFAULT:
23             /* FIXME: is this supposed to autodetect? */
24         case DISPLAYDIB_MODE_320x200x8:
25             Xres=320; Yres=200; Depth=8; break;
26         case DISPLAYDIB_MODE_320x240x8:
27             Xres=320; Yres=240; Depth=8; break;
28         default:
29             return DISPLAYDIB_NOTSUPPORTED;
30     }
31     /* more or less dummy calls to Death/Resurrection, for completeness */
32     /* FIXME: what arguments should they get? */
33     Death(0);
34     if (VGA_SetMode(Xres,Yres,Depth)) {
35          Resurrection(0,0,0,0,0,0,0);
36          return DISPLAYDIB_NOTSUPPORTED;
37     }
38     return DISPLAYDIB_NOERROR;
39 }
40
41 static void DISPDIB_End(void)
42 {
43     Resurrection(0,0,0,0,0,0,0); /* FIXME: arguments */
44     VGA_Exit();
45 }
46
47 static void DISPDIB_Palette(LPBITMAPINFO lpbi)
48 {
49     VGA_SetQuadPalette(lpbi->bmiColors,0,256);
50 }
51
52 static void DISPDIB_Show(LPBITMAPINFOHEADER lpbi,LPSTR lpBits,WORD uFlags)
53 {
54     int Xofs,Yofs,Width=lpbi->biWidth,Height=lpbi->biHeight,Delta;
55     unsigned Pitch=(Width+3)&~3,sPitch,sWidth,sHeight;
56     LPSTR surf = DOSMEM_MapDosToLinear(0xa0000);
57
58     if (VGA_GetMode(&sHeight,&sWidth,NULL)) return;
59     sPitch=320;
60
61     Delta=(Height<0)*2-1;
62     Height*=-Delta; Pitch*=Delta;
63
64     if (uFlags&DISPLAYDIB_NOCENTER) {
65         Xofs=0; Yofs=0;
66     } else {
67         Xofs=(sWidth-Width)/2;
68         Yofs=(sHeight-Height)/2;
69     }
70     surf += (Yofs*sPitch)+Xofs;
71     if (Pitch<0) lpBits-=Pitch*(Height-1);
72     for (; Height; Height--,lpBits+=Pitch,surf+=sPitch) {
73         memcpy(surf,lpBits,Width);
74     }
75
76     VGA_Poll(0);
77 }
78
79 /*********************************************************************
80  *      DisplayDib      (DISPDIB.1)
81  *
82  *  Disables GDI and takes over the VGA screen to show DIBs in full screen.
83  *
84  * FLAGS
85  *
86  *  DISPLAYDIB_NOPALETTE: don't change palette
87  *  DISPLAYDIB_NOCENTER: don't center bitmap
88  *  DISPLAYDIB_NOWAIT: don't wait (for keypress) before returning
89  *  DISPLAYDIB_BEGIN: start of multiple calls (does not restore the screen)
90  *  DISPLAYDIB_END: end of multiple calls (restores the screen)
91  *  DISPLAYDIB_MODE_DEFAULT: default display mode
92  *  DISPLAYDIB_MODE_320x200x8: Standard VGA 320x200 256 colors
93  *  DISPLAYDIB_MODE_320x240x8: Tweaked VGA 320x240 256 colors
94  *
95  * RETURNS
96  *
97  *  DISPLAYDIB_NOERROR: success
98  *  DISPLAYDIB_NOTSUPPORTED: function not supported
99  *  DISPLAYDIB_INVALIDDIB: null or invalid DIB header
100  *  DISPLAYDIB_INVALIDFORMAT: invalid DIB format
101  *  DISPLAYDIB_INVALIDTASK: not called from current task
102  *
103  * BUGS
104  *
105  *  Waiting for keypresses is not implemented.
106  */
107 WORD WINAPI DisplayDib(
108                 LPBITMAPINFO lpbi, /* DIB header with resolution and palette */
109                 LPSTR lpBits, /* Bitmap bits to show */
110                 WORD wFlags
111         )
112 {
113     WORD ret;
114
115     if (wFlags&DISPLAYDIB_END) {
116         if (dispdib_multi) DISPDIB_End();
117         dispdib_multi = 0;
118         return DISPLAYDIB_NOERROR;
119     }
120     if (!dispdib_multi) {
121         ret=DISPDIB_Begin(wFlags);
122         if (ret) return ret;
123     }
124     if (wFlags&DISPLAYDIB_BEGIN) dispdib_multi = 1;
125     if (!(wFlags&DISPLAYDIB_NOPALETTE)) {
126         DISPDIB_Palette(lpbi);
127     }
128     /* FIXME: not sure if it's valid to draw images in DISPLAYDIB_BEGIN, so... */
129     if (lpBits) {
130         DISPDIB_Show(&(lpbi->bmiHeader),lpBits,wFlags);
131     }
132     if (!(wFlags&DISPLAYDIB_NOWAIT)) {
133         FIXME(ddraw,"wait not implemented\n");
134     }
135     if (!dispdib_multi) DISPDIB_End();
136     return DISPLAYDIB_NOERROR;
137 }