/
SDL_xbios_nova.c
351 lines (282 loc) · 7.89 KB
/
SDL_xbios_nova.c
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2012 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
/*
Nova video card driver
Patrice Mandin
*/
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
/* Mint includes */
#include <mint/cookie.h>
#include <mint/sysvars.h>
#include <mint/osbind.h>
#include "SDL_video.h"
#include "../ataricommon/SDL_atarimxalloc_c.h"
#include "../ataricommon/SDL_atarisuper.h"
#include "SDL_xbios.h"
#include "SDL_xbios_nova.h"
#define NOVA_FILENAME "\\auto\\sta_vdi.bib"
/*--- ---*/
static nova_xcb_t *NOVA_xcb; /* Pointer to Nova infos */
static nova_resolution_t *NOVA_modes; /* Video modes loaded from a file */
static int NOVA_modecount; /* Number of loaded modes */
static unsigned char NOVA_blnk_time; /* Original blank time */
/*--- Functions ---*/
static void XBIOS_DeleteDevice_NOVA(_THIS);
static void listModes(_THIS, int actually_add);
static void saveMode(_THIS, SDL_PixelFormat *vformat);
static void setMode(_THIS, xbiosmode_t *new_video_mode);
static void restoreMode(_THIS);
static void vsync_NOVA(_THIS);
static void getScreenFormat(_THIS, int bpp, Uint32 *rmask, Uint32 *gmask, Uint32 *bmask, Uint32 *amask);
static int getLineWidth(_THIS, xbiosmode_t *new_video_mode, int width, int bpp);
static void swapVbuffers(_THIS);
static int allocVbuffers(_THIS, int num_buffers, int bufsize);
static void freeVbuffers(_THIS);
static int setColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
/* Internal functions */
static void NOVA_SetMode(_THIS, int num_mode);
static void NOVA_SetScreen(_THIS, void *screen);
static void NOVA_SetColor(_THIS, int index, int r, int g, int b);
static nova_resolution_t *NOVA_LoadModes(int *num_modes);
/* Nova driver bootstrap functions */
void SDL_XBIOS_VideoInit_Nova(_THIS, void *cookie_nova)
{
NOVA_xcb = (nova_xcb_t *) cookie_nova;
NOVA_modes = NULL;
NOVA_modecount = 0;
this->free = XBIOS_DeleteDevice_NOVA;
/* Initialize video mode list */
NOVA_modes = NOVA_LoadModes(&NOVA_modecount);
if (!NOVA_modes) {
return;
}
XBIOS_listModes = listModes;
XBIOS_saveMode = saveMode;
XBIOS_setMode = setMode;
XBIOS_restoreMode = restoreMode;
XBIOS_vsync = vsync_NOVA;
XBIOS_getScreenFormat = getScreenFormat;
XBIOS_getLineWidth = getLineWidth;
XBIOS_swapVbuffers = swapVbuffers;
XBIOS_allocVbuffers = allocVbuffers;
XBIOS_freeVbuffers = freeVbuffers;
this->SetColors = setColors;
}
static void XBIOS_DeleteDevice_NOVA(_THIS)
{
if (NOVA_modes) {
SDL_free(NOVA_modes);
}
SDL_free(this->hidden);
SDL_free(this);
}
static void listModes(_THIS, int actually_add)
{
int i;
xbiosmode_t modeinfo;
for (i=0; i<NOVA_modecount; i++) {
int width = NOVA_modes[i].max_x + 1;
int height = NOVA_modes[i].max_y + 1;
int bpp = NOVA_modes[i].planes;
/* Only 8, 16, 24, 32,bpp modes */
if ((NOVA_modes[i].mode <= 1 ) || (NOVA_modes[i].mode == 3 ))
continue;
modeinfo.number = i;
modeinfo.width = width;
modeinfo.height = height;
modeinfo.depth = bpp;
modeinfo.flags = 0;
SDL_XBIOS_AddMode(this, actually_add, &modeinfo);
}
}
static void saveMode(_THIS, SDL_PixelFormat *vformat)
{
int curwidth, curheight, curbpp;
curwidth = NOVA_xcb->max_x + 1;
curheight = NOVA_xcb->max_y + 1;
curbpp = NOVA_xcb->planes;
if (NOVA_xcb->mode == 3 ) {
curbpp = 15;
}
/* Determine the current screen size */
this->info.current_w = curwidth;
this->info.current_h = curheight;
/* Determine the screen depth (use default 8-bit depth) */
vformat->BitsPerPixel = curbpp;
/* Update hardware info */
this->info.hw_available = 1;
this->info.video_mem = NOVA_xcb->mem_size;
XBIOS_oldvmode = NOVA_xcb->resolution;
XBIOS_oldvbase = NOVA_xcb->base;
/* TODO: save palette ? */
NOVA_blnk_time = NOVA_xcb->blnk_time;
NOVA_xcb->blnk_time = 0;
}
static void setMode(_THIS, xbiosmode_t *new_video_mode)
{
NOVA_SetMode(this, new_video_mode->number);
}
static void restoreMode(_THIS)
{
NOVA_SetScreen(this, XBIOS_oldvbase);
NOVA_SetMode(this, XBIOS_oldvmode);
/* TODO: restore palette ? */
NOVA_xcb->blnk_time = NOVA_blnk_time;
}
static void vsync_NOVA(_THIS)
{
NOVA_xcb->p_vsync();
}
static void getScreenFormat(_THIS, int bpp, Uint32 *rmask, Uint32 *gmask, Uint32 *bmask, Uint32 *amask)
{
*rmask = *gmask = *bmask = *amask = 0;
switch(bpp) {
case 15:
*rmask = 31<<2;
*gmask = 3;
*bmask = 31<<8;
*amask = 1<<7;
break;
case 16:
*rmask = 31<<3;
*gmask = 7;
*bmask = 31<<8;
break;
case 24:
*rmask = 255;
*gmask = 255<<8;
*bmask = 255<<16;
break;
case 32:
*rmask = 255<<24;
*gmask = 255<<16;
*bmask = 255<<8;
*amask = 255;
break;
}
}
static int getLineWidth(_THIS, xbiosmode_t *new_video_mode, int width, int bpp)
{
return (NOVA_modes[new_video_mode->number].pitch);
}
static void swapVbuffers(_THIS)
{
NOVA_SetScreen(this, XBIOS_screens[XBIOS_fbnum]);
}
static int allocVbuffers(_THIS, int num_buffers, int bufsize)
{
XBIOS_screens[0] = NOVA_xcb->base;
if (num_buffers>1) {
XBIOS_screens[1] = XBIOS_screens[0] + NOVA_xcb->scrn_sze;
}
return(1);
}
static void freeVbuffers(_THIS)
{
}
static int setColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
{
int i;
for (i=0; i<ncolors; i++) {
NOVA_SetColor(this, firstcolor+i, colors[i].r, colors[i].g, colors[i].b);
}
return(1);
}
static void NOVA_SetMode(_THIS, int num_mode)
{
if ((num_mode<0) || (num_mode>=NOVA_modecount)) {
return;
}
__asm__ __volatile__ (
"moveql #0,d0\n\t"
"movel %0,a0\n\t"
"movel %1,a1\n\t"
"jsr a1@"
: /* no return value */
: /* input */
"g"(&NOVA_modes[num_mode]), "g"(NOVA_xcb->p_chres)
: /* clobbered registers */
"d0", "d1", "d2", "a0", "a1", "cc", "memory"
);
}
static void NOVA_SetScreen(_THIS, void *screen)
{
__asm__ __volatile__ (
"movel %0,a0\n\t"
"movel %1,a1\n\t"
"jsr a1@"
: /* no return value */
: /* input */
"g"(screen), "g"(NOVA_xcb->p_setscr)
: /* clobbered registers */
"d0", "d1", "d2", "a0", "a1", "cc", "memory"
);
}
static void NOVA_SetColor(_THIS, int index, int r, int g, int b)
{
Uint8 color[3];
color[0] = r;
color[1] = g;
color[2] = b;
__asm__ __volatile__ (
"movel %0,d0\n\t"
"movel %1,a0\n\t"
"movel %2,a1\n\t"
"jsr a1@"
: /* no return value */
: /* input */
"g"(index), "g"(color), "g"(NOVA_xcb->p_setcol)
: /* clobbered registers */
"d0", "d1", "d2", "a0", "a1", "cc", "memory"
);
}
static nova_resolution_t *NOVA_LoadModes(int *num_modes)
{
char filename[32];
unsigned char bootdrive;
void *oldstack;
int handle, length;
nova_resolution_t *buffer;
/* Find boot drive */
oldstack = (void *)Super(NULL);
bootdrive='A'+ *((volatile unsigned short *)_bootdev);
SuperToUser(oldstack);
sprintf(&filename[0], "%c:" NOVA_FILENAME, bootdrive);
/* Load file */
handle = open(filename, O_RDONLY);
if (handle<0) {
SDL_SetError("Unable to open %s\n", filename);
return NULL;
}
length = lseek(handle, 0, SEEK_END);
lseek(handle, 0, SEEK_SET);
buffer = (nova_resolution_t *)SDL_malloc(length);
if (buffer==NULL) {
SDL_SetError("Unable to allocate %d bytes\n", length);
return NULL;
}
read(handle, buffer, length);
close(handle);
if (num_modes!=NULL) {
*num_modes=length/sizeof(nova_resolution_t);
}
return buffer;
}