/
SDL_xbios_ctpci.c
325 lines (257 loc) · 7.66 KB
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
/*
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"
/*
CTPCI Xbios video functions
Pawel Goralski
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_milan.h"
/* use predefined, hardcoded table if CTPCI_USE_TABLE == 1
else enumerate all non virtual video modes */
#define CTPCI_USE_TABLE 1
typedef struct {
Uint16 modecode, width, height;
} predefined_mode_t;
static const predefined_mode_t mode_list[]={
{0x4260,320,200},
{0x4270,320,240},
{0x4138,640,480},
{0x4160,800,600},
{0x4188,1024,768},
{0x42c8,1280,800},
{0x41e0,1280,1024},
58
{0x4210,1600,1200}
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
};
static const Uint8 mode_bpp[]={
8, 16, 32
};
/*--- Variables ---*/
static int enum_actually_add;
static SDL_VideoDevice *enum_this;
/*--- Functions ---*/
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);
76
static int getLineWidth(_THIS, xbiosmode_t *new_video_mode, int width, int bpp);
77
78
79
80
81
82
83
84
85
86
87
static int allocVbuffers(_THIS, int num_buffers, int bufsize);
static void freeVbuffers(_THIS);
static void updateRects(_THIS, int numrects, SDL_Rect *rects);
static int flipHWSurface(_THIS, SDL_Surface *surface);
void SDL_XBIOS_VideoInit_Ctpci(_THIS)
{
XBIOS_listModes = listModes;
XBIOS_saveMode = saveMode;
XBIOS_setMode = setMode;
XBIOS_restoreMode = restoreMode;
88
XBIOS_getLineWidth = getLineWidth;
89
90
91
XBIOS_allocVbuffers = allocVbuffers;
XBIOS_freeVbuffers = freeVbuffers;
92
XBIOS_updRects = updateRects;
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
this->FlipHWSurface = flipHWSurface;
}
static unsigned long /*cdecl*/ enumfunc(SCREENINFO *inf, unsigned long flag)
{
xbiosmode_t modeinfo;
modeinfo.number = inf->devID;
modeinfo.width = inf->scrWidth;
modeinfo.height = inf->scrHeight;
modeinfo.depth = inf->scrPlanes;
modeinfo.flags = 0;
SDL_XBIOS_AddMode(enum_this, enum_actually_add, &modeinfo);
108
109
return ENUMMODE_CONT;
}
110
111
112
113
114
115
116
117
118
119
120
121
122
123
static void listModes(_THIS, int actually_add)
{
#ifdef CTPCI_USE_TABLE
int i;
/* Read validated predefined modes */
for (i=0; i<sizeof(mode_list)/sizeof(predefined_mode_t); i++) {
int j;
Uint16 deviceid = mode_list[i].modecode;
for (j=3; j<5; j++) {
if (Validmode(deviceid + j)) {
xbiosmode_t modeinfo;
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
modeinfo.number = deviceid + j;
modeinfo.width = mode_list[i].width;
modeinfo.height = mode_list[i].height;
modeinfo.depth = mode_bpp[j-3];
modeinfo.flags = 0;
SDL_XBIOS_AddMode(this, actually_add, &modeinfo);
}
}
}
#else
/* Read custom created modes */
enum_this = this;
enum_actually_add = actually_add;
VsetScreen(-1, &enumfunc, VN_MAGIC, CMD_ENUMMODES);
#endif
}
static void saveMode(_THIS, SDL_PixelFormat *vformat)
{
SCREENINFO si;
147
/* Read infos about current mode */
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
VsetScreen(-1, &XBIOS_oldvmode, VN_MAGIC, CMD_GETMODE);
si.size = sizeof(SCREENINFO);
si.devID = XBIOS_oldvmode;
si.scrFlags = 0;
VsetScreen(-1, &si, VN_MAGIC, CMD_GETINFO);
this->info.current_w = si.scrWidth;
this->info.current_h = si.scrHeight;
vformat->BitsPerPixel = si.scrPlanes;
XBIOS_oldnumcol = 0;
if (si.scrFlags & SCRINFO_OK) {
if (si.scrPlanes <= 8) {
XBIOS_oldnumcol = 1<<si.scrPlanes;
}
}
if (XBIOS_oldnumcol) {
VgetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette);
}
}
static void setMode(_THIS, xbiosmode_t *new_video_mode)
{
VsetScreen(-1, XBIOS_screens[0], VN_MAGIC, CMD_SETADR);
VsetScreen(-1, new_video_mode->number, VN_MAGIC, CMD_SETMODE);
/* 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)
{
VsetScreen(-1, &XBIOS_oldvbase, VN_MAGIC, CMD_SETADR);
VsetScreen(-1, &XBIOS_oldvmode, VN_MAGIC, CMD_SETMODE);
if (XBIOS_oldnumcol) {
VsetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette);
}
}
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
static int getLineWidth(_THIS, xbiosmode_t *new_video_mode, int width, int bpp)
{
SCREENINFO si;
int retvalue = width * (((bpp==15) ? 16 : bpp)>>3);
/* Set pitch of new mode */
si.size = sizeof(SCREENINFO);
si.devID = new_video_mode->number;
si.scrFlags = 0;
VsetScreen(-1, &si, VN_MAGIC, CMD_GETINFO);
if (si.scrFlags & SCRINFO_OK) {
retvalue = si.lineWrap;
}
return (retvalue);
}
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
static int allocVbuffers(_THIS, int num_buffers, int bufsize)
{
int i;
for (i=0; i<num_buffers; i++) {
if (i==0) {
/* Buffer 0 is current screen */
XBIOS_screensmem[i] = XBIOS_oldvbase;
} else {
VsetScreen(-1, &XBIOS_screensmem[i], VN_MAGIC, CMD_ALLOCPAGE);
}
if (!XBIOS_screensmem[i]) {
SDL_SetError("Can not allocate %d KB for buffer %d", bufsize>>10, i);
return (0);
}
SDL_memset(XBIOS_screensmem[i], 0, bufsize);
XBIOS_screens[i]=XBIOS_screensmem[i];
}
/*--- Always use shadow buffer ---*/
if (XBIOS_shadowscreen) {
Mfree(XBIOS_shadowscreen);
XBIOS_shadowscreen=NULL;
}
/* allocate shadow buffer in TT-RAM, blitting directly to screen is
damn slow, send postcards to R.Czuba for fixing TT-RAM->CTPCI burst
mode */
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);
return (1);
}
static void freeVbuffers(_THIS)
{
int i;
for (i=0;i<2;i++) {
if (XBIOS_screensmem[i]) {
if (i==1) {
VsetScreen(-1, -1, VN_MAGIC, CMD_FREEPAGE);
} else {
/* Do not touch buffer 0 */
}
XBIOS_screensmem[i]=NULL;
}
}
}
static void updateRects(_THIS, int numrects, SDL_Rect *rects)
{
SDL_Surface *surface;
int i;
271
272
273
274
275
276
surface = this->screen;
for (i=0;i<numrects;i++) {
Uint8 *blockSrcStart, *blockDstStart;
int y;
277
278
279
280
281
blockSrcStart = (Uint8 *) surface->pixels;
blockSrcStart += surface->pitch*rects[i].y;
blockSrcStart += surface->format->BytesPerPixel*rects[i].x;
282
blockDstStart = ((Uint8 *) XBIOS_screens[XBIOS_fbnum]) + surface->offset;
283
284
285
286
287
288
289
290
291
292
293
294
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;
}
}
if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
295
VsetScreen(-1L, -1L, VN_MAGIC, CMD_FLIPPAGE);
296
(*XBIOS_vsync)(this);
297
298
299
300
301
302
303
XBIOS_fbnum ^= 1;
}
}
static int flipHWSurface(_THIS, SDL_Surface *surface)
{
304
305
306
307
308
309
310
311
312
313
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;
314
315
}
316
317
if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
318
VsetScreen(-1L, -1L, VN_MAGIC, CMD_FLIPPAGE);
319
(*XBIOS_vsync)(this);
320
321
322
323
324
325
XBIOS_fbnum ^= 1;
}
return(0);
}