/
SDL_xbios_f30.c
379 lines (305 loc) · 9.18 KB
/
SDL_xbios_f30.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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
/*
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"
/*
Falcon Xbios video functions
Patrice Mandin
*/
#include <mint/cookie.h>
#include <mint/osbind.h>
#include <mint/falcon.h>
#include "../SDL_sysvideo.h"
#include "../ataricommon/SDL_atarimxalloc_c.h"
#include "SDL_xbios.h"
#include "SDL_xbios_blowup.h"
#include "SDL_xbios_sb3.h"
#include "SDL_xbios_centscreen.h"
/* Use shadow buffer on Supervidel */
/*#define ENABLE_SV_SHADOWBUF 1*/
/* Supervidel 1 byte/pixel mode */
#define BPS8c 0x07
#ifndef C_SupV
#define C_SupV 0x53757056L
#endif
static const xbiosmode_t rgb_modes[]={
{BPS16|COL80|OVERSCAN|VERTFLAG,768,480,16,0},
{BPS16|COL80|OVERSCAN,768,240,16,0},
{BPS16|COL80|VERTFLAG,640,400,16,0},
{BPS16|COL80,640,200,16,0},
{BPS16|OVERSCAN|VERTFLAG,384,480,16,0},
{BPS16|OVERSCAN,384,240,16,0},
{BPS16|VERTFLAG,320,400,16,0},
{BPS16,320,200,16,0},
{BPS8|COL80|OVERSCAN|VERTFLAG,768,480,8,XBIOSMODE_C2P},
{BPS8|COL80|OVERSCAN,768,240,8,XBIOSMODE_C2P},
{BPS8|COL80|VERTFLAG,640,400,8,XBIOSMODE_C2P},
{BPS8|COL80,640,200,8,XBIOSMODE_C2P},
{BPS8|OVERSCAN|VERTFLAG,384,480,8,XBIOSMODE_C2P},
{BPS8|OVERSCAN,384,240,8,XBIOSMODE_C2P},
{BPS8|VERTFLAG,320,400,8,XBIOSMODE_C2P},
{BPS8,320,200,8,XBIOSMODE_C2P}
};
static const xbiosmode_t vga_modes[]={
{BPS16,320,480,16,0},
{BPS16|VERTFLAG,320,240,16,0},
{BPS8|COL80,640,480,8,XBIOSMODE_C2P},
{BPS8|COL80|VERTFLAG,640,240,8,XBIOSMODE_C2P},
{BPS8,320,480,8,XBIOSMODE_C2P},
{BPS8|VERTFLAG,320,240,8,XBIOSMODE_C2P}
};
static const xbiosmode_t sv_modes[]={
{0x487D,2560,1440,32,0}, /* 32-bits */
{0x467D,1920,1200,32,0},
{0x447D,1920,1080,32,0},
{0x463D,1280,1024,32,0},
{0x443D,1024,768,32,0},
{0x423D,800,600,32,0},
{0x403D,640,480,32,0},
{0x413D,640,240,32,0},
{0x4035,320,480,32,0},
{0x4135,320,240,32,0},
{0x487C,2560,1440,16,0}, /* 16-bits */
{0x467C,1920,1200,16,0},
{0x447C,1920,1080,16,0},
{0x427C,1680,1050,16,0},
{0x463C,1280,1024,16,0},
{0x443C,1024,768,16,0},
{0x423C,800,600,16,0},
{0x403C,640,480,16,0},
{0x413C,640,240,16,0},
{0x4034,320,480,16,0},
{0x4134,320,240,16,0},
{0x487F,2560,1440,8,0}, /* 8-bits c2p */
{0x467F,1920,1200,8,0},
{0x447F,1920,1080,8,0},
{0x463f,1280,1024,8,0},
{0x443F,1024,768,8,0},
{0x423F,800,600,8,0},
{0x403F,640,480,8,0},
{0x411F,640,240,8,0},
{0x4017,320,480,8,0},
{0x4137,320,240,8,0}
};
static int has_supervidel;
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 int setColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
static int allocVbuffers_SV(_THIS, int num_buffers, int bufsize);
#ifdef ENABLE_SV_SHADOWBUF
static void updateRects_SV(_THIS, int numrects, SDL_Rect *rects);
static int flipHWSurface_SV(_THIS, SDL_Surface *surface);
#endif
void SDL_XBIOS_VideoInit_F30(_THIS)
{
long cookie_cnts, cookie_scpn, cookie_dummy;
XBIOS_listModes = listModes;
XBIOS_saveMode = saveMode;
XBIOS_setMode = setMode;
XBIOS_restoreMode = restoreMode;
this->SetColors = setColors;
/* Supervidel ? */
has_supervidel = 0;
if (Getcookie(C_SupV, &cookie_dummy) == C_FOUND) {
XBIOS_allocVbuffers = allocVbuffers_SV;
#ifdef ENABLE_SV_SHADOWBUF
XBIOS_updRects = updateRects_SV;
this->FlipHWSurface = flipHWSurface_SV;
#endif
has_supervidel = 1;
} else
/* CTPCI ? */
if ((Getcookie(C_CT60, &cookie_dummy) == C_FOUND)
&& (Getcookie(C__PCI, &cookie_dummy) == C_FOUND)
&& ((unsigned long)Physbase()>=0x01000000UL))
{
SDL_XBIOS_VideoInit_Ctpci(this);
} else
/* ScreenBlaster 3 ? */
if (Getcookie(C_SCPN, &cookie_scpn) == C_FOUND) {
SDL_XBIOS_VideoInit_SB3(this);
} else
/* Centscreen ? */
if (Getcookie(C_CNTS, &cookie_cnts) == C_FOUND) {
SDL_XBIOS_VideoInit_Centscreen(this);
}
}
static void listModes(_THIS, int actually_add)
{
long cookie_blow;
int i, max_modes = 0;
const xbiosmode_t *f30_modes = NULL;
xbiosmode_t modeinfo;
if (has_supervidel) {
/* SuperVidel specific modes */
max_modes = sizeof(sv_modes)/sizeof(xbiosmode_t);
f30_modes = sv_modes;
for (i=0; i<max_modes; i++) {
SDL_memcpy(&modeinfo, &sv_modes[i], sizeof(xbiosmode_t));
SDL_XBIOS_AddMode(this, actually_add, &modeinfo);
}
return;
}
/* Standard Videl */
switch (VgetMonitor()) {
case MONITOR_RGB:
case MONITOR_TV:
max_modes = sizeof(rgb_modes)/sizeof(xbiosmode_t);
f30_modes = rgb_modes;
break;
case MONITOR_VGA:
max_modes = sizeof(vga_modes)/sizeof(xbiosmode_t);
f30_modes = vga_modes;
break;
}
for (i=0; i<max_modes; i++) {
SDL_memcpy(&modeinfo, &f30_modes[i], sizeof(xbiosmode_t));
modeinfo.number &= ~(VGA|PAL);
modeinfo.number |= XBIOS_oldvmode & (VGA|PAL);
if (has_supervidel && (modeinfo.depth==8)) {
modeinfo.number &= ~NUMCOLS;
modeinfo.number |= BPS8c;
modeinfo.flags &= ~XBIOSMODE_C2P;
}
SDL_XBIOS_AddMode(this, actually_add, &modeinfo);
}
if (Getcookie(C_BLOW, &cookie_blow) == C_FOUND) {
SDL_XBIOS_ListBlowupModes(this, actually_add, (blow_cookie_t *)cookie_blow);
}
}
static void saveMode(_THIS, SDL_PixelFormat *vformat)
{
XBIOS_oldvbase=Physbase();
XBIOS_oldvmode=VsetMode(-1);
XBIOS_oldnumcol= 1<< (1 << (XBIOS_oldvmode & NUMCOLS));
if (XBIOS_oldnumcol > 256) {
XBIOS_oldnumcol = 256;
}
if (XBIOS_oldnumcol) {
VgetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette);
}
}
static void setMode(_THIS, xbiosmode_t *new_video_mode)
{
Setscreen(-1,XBIOS_screens[0],-1);
(void) VsetMode(new_video_mode->number);
/* Set hardware palette to black in True Colour */
if (new_video_mode->depth > 8) {
SDL_memset(F30_palette, 0, sizeof(F30_palette));
VsetRGB(0,256,F30_palette);
}
}
static void restoreMode(_THIS)
{
Setscreen(-1,XBIOS_oldvbase,-1);
(void) VsetMode(XBIOS_oldvmode);
if (XBIOS_oldnumcol) {
VsetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette);
}
}
static int setColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
{
int i, r,g,b;
for(i = 0; i < ncolors; i++) {
r = colors[i].r;
g = colors[i].g;
b = colors[i].b;
F30_palette[i]=(r<<16)|(g<<8)|b;
}
VsetRGB(firstcolor,ncolors,F30_palette);
return 1;
}
static int allocVbuffers_SV(_THIS, int num_buffers, int bufsize)
{
int i;
Uint32 tmp;
for (i=0; i<num_buffers; i++) {
XBIOS_screensmem[i] = Atari_SysMalloc(bufsize, MX_STRAM);
if (XBIOS_screensmem[i]==NULL) {
SDL_SetError("Can not allocate %d KB for buffer %d", bufsize>>10, i);
return (0);
}
SDL_memset(XBIOS_screensmem[i], 0, bufsize);
/* Align on 256byte boundary and map to Supervidel memory */
tmp = ( (Uint32) XBIOS_screensmem[i]+256) & 0xFFFFFF00UL;
tmp |= 0xA0000000UL; /* Map to SV memory */
XBIOS_screens[i] = (void *) tmp;
}
#ifdef ENABLE_SV_SHADOWBUF
/*--- Always use shadow buffer ---*/
if (XBIOS_shadowscreen) {
Mfree(XBIOS_shadowscreen);
XBIOS_shadowscreen=NULL;
}
/* allocate shadow buffer in TT-RAM */
XBIOS_shadowscreen = Atari_SysMalloc(bufsize, MX_PREFTTRAM);
if (XBIOS_shadowscreen == NULL) {
SDL_SetError("Can not allocate %d KB for shadow buffer", bufsize>>10);
return (0);
}
SDL_memset(XBIOS_shadowscreen, 0, bufsize);
#endif
return (1);
}
#ifdef ENABLE_SV_SHADOWBUF
static void updateRects_SV(_THIS, int numrects, SDL_Rect *rects)
{
SDL_Surface *surface;
int i;
surface = this->screen;
for (i=0;i<numrects;i++) {
Uint8 *blockSrcStart, *blockDstStart;
int y;
blockSrcStart = (Uint8 *) surface->pixels;
blockSrcStart += surface->pitch*rects[i].y;
blockSrcStart += surface->format->BytesPerPixel*rects[i].x;
blockDstStart = ((Uint8 *) XBIOS_screens[XBIOS_fbnum]) + surface->offset;
blockDstStart += XBIOS_pitch*rects[i].y;
blockDstStart += surface->format->BytesPerPixel*rects[i].x;
for(y=0;y<rects[i].h;y++){
SDL_memcpy(blockDstStart,blockSrcStart,surface->pitch);
blockSrcStart += surface->pitch;
blockDstStart += XBIOS_pitch;
}
}
Setscreen(-1,XBIOS_screens[XBIOS_fbnum],-1);
Vsync();
if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
XBIOS_fbnum ^= 1;
}
}
static int flipHWSurface_SV(_THIS, SDL_Surface *surface)
{
int i;
Uint8 *src, *dst;
src = surface->pixels;
dst = ((Uint8 *) XBIOS_screens[XBIOS_fbnum]) + surface->offset;
for (i=0; i<surface->h; i++) {
SDL_memcpy(dst, src, surface->w * surface->format->BytesPerPixel);
src += surface->pitch;
dst += XBIOS_pitch;
}
Setscreen(-1,XBIOS_screens[XBIOS_fbnum],-1);
Vsync();
if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
XBIOS_fbnum ^= 1;
}
return(0);
}
#endif