summaryrefslogtreecommitdiff
path: root/src/mesa/drivers/dos/null.c
blob: 55846299fbb9744f76d9984b8c7394af101dafd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
 * Mesa 3-D graphics library
 * Version:  4.1
 * 
 * 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 for Mesa
 *
 *  Author: Daniel Borca
 *  Email : dborca@users.sourceforge.net
 *  Web   : http://www.geocities.com/dborca
 */


#include <stdlib.h>
#include <sys/segments.h>

#include "video.h"
#include "null.h"


static vl_mode *modes;

#define null_color_precision 8


static void
null_blit_nop (void)
{
}


/* Desc: Attempts to detect NUL, check video modes and create selectors.
 *
 * In  : -
 * Out : mode array
 *
 * Note: -
 */
static vl_mode *
null_init (void)
{
   static int m[][2] = {
      {  320,  200 },
      {  320,  240 },
      {  400,  300 },
      {  512,  384 },
      {  640,  400 },
      {  640,  480 },
      {  800,  600 },
      { 1024,  768 },
      { 1280, 1024 },
      { 1600, 1200 }
   };
   static int b[] = {
      8,
      15,
      16,
      24,
      32
   };
   const unsigned int m_count = sizeof(m) / sizeof(m[0]);
   const unsigned int b_count = sizeof(b) / sizeof(b[0]);

   unsigned int i, j, k;

   if (modes == NULL) {
      modes = malloc(sizeof(vl_mode) * (1 + m_count * b_count));

      if (modes != NULL) {
         for (k = 0, i = 0; i < m_count; i++) {
            for (j = 0; j < b_count; j++, k++) {
               modes[k].xres    = m[i][0];
               modes[k].yres    = m[i][1];
               modes[k].bpp     = b[j];
               modes[k].mode    = 0x4000;
               modes[k].scanlen = m[i][0] * ((b[j] + 7) / 8);
               modes[k].sel     = -1;
               modes[k].gran    = -1;
            }
         }
         modes[k].xres    = -1;
         modes[k].yres    = -1;
         modes[k].bpp     = -1;
         modes[k].mode    = 0xffff;
         modes[k].scanlen = -1;
         modes[k].sel     = -1;
         modes[k].gran    = -1;
      }
   }

   return modes;
}


/* Desc: Frees all resources allocated by NUL init code.
 *
 * In  : -
 * Out : -
 *
 * Note: -
 */
static void
null_fini (void)
{
   if (modes != NULL) {
      free(modes);
      modes = NULL;
   }
}


/* Desc: Attempts to enter specified video mode.
 *
 * In  : ptr to mode structure, refresh rate
 * Out : 0 if success
 *
 * Note: -
 */
static int
null_entermode (vl_mode *p, int refresh, int fbbits)
{
   NUL.blit = null_blit_nop;

   return 0;

   (void)(p && refresh && fbbits); /* silence compiler warning */
}


/* Desc: Restores to the mode prior to first call to null_entermode.
 *
 * In  : -
 * Out : -
 *
 * Note: -
 */
static void
null_restore (void)
{
}


/* Desc: set one palette entry
 *
 * In  : color index, R, G, B
 * Out : -
 *
 * Note: uses integer values
 */
static void
null_setCI_i (int index, int red, int green, int blue)
{
   (void)(index && red && green && blue); /* silence compiler warning */
}


/* Desc: set one palette entry
 *
 * In  : color index, R, G, B
 * Out : -
 *
 * Note: uses normalized values
 */
static void
null_setCI_f (int index, float red, float green, float blue)
{
   float max = (1 << null_color_precision) - 1;

   null_setCI_i(index, (int)(red * max), (int)(green * max), (int)(blue * max));
}


/* Desc: state retrieval
 *
 * In  : parameter name, ptr to storage
 * Out : 0 if request successfully processed
 *
 * Note: -
 */
static int
null_get (int pname, int *params)
{
   switch (pname) {
      default:
         params[0] = params[0]; /* silence compiler warning */
         return -1;
   }
   return 0;
}


/*
 * the driver
 */
vl_driver NUL = {
   null_init,
   null_entermode,
   NULL,
   null_setCI_f,
   null_setCI_i,
   null_get,
   null_restore,
   null_fini
};