Skip to content

Latest commit

 

History

History
1232 lines (1012 loc) · 27.9 KB

SDL_gemvideo.c

File metadata and controls

1232 lines (1012 loc) · 27.9 KB
 
1
2
/*
SDL - Simple DirectMedia Layer
Mar 6, 2002
Mar 6, 2002
3
Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga
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
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
*/
#ifdef SAVE_RCSID
static char rcsid =
"@(#) $Id$";
#endif
/*
Nov 12, 2003
Nov 12, 2003
29
30
31
32
33
34
GEM video driver
Patrice Mandin
and work from
Olivier Landemarre, Johan Klockars, Xavier Joubert, Claude Attard
*/
35
36
37
38
39
40
41
42
43
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Mint includes */
#include <gem.h>
#include <gemx.h>
#include <mint/osbind.h>
Dec 7, 2002
Dec 7, 2002
44
#include <mint/cookie.h>
45
46
47
48
49
50
51
52
#include "SDL.h"
#include "SDL_error.h"
#include "SDL_video.h"
#include "SDL_mouse.h"
#include "SDL_sysvideo.h"
#include "SDL_pixels_c.h"
#include "SDL_events_c.h"
Mar 26, 2002
Mar 26, 2002
53
#include "SDL_cursor_c.h"
54
55
56
57
58
59
60
61
#include "SDL_ataric2p_s.h"
#include "SDL_atarieddi_s.h"
#include "SDL_atarimxalloc_c.h"
#include "SDL_gemvideo.h"
#include "SDL_gemevents_c.h"
#include "SDL_gemmouse_c.h"
#include "SDL_gemwm_c.h"
Mar 10, 2002
Mar 10, 2002
62
#include "SDL_xbiosevents_c.h"
63
64
65
/* Defines */
Nov 12, 2003
Nov 12, 2003
66
67
/*#define DEBUG_VIDEO_GEM 1*/
68
69
#define GEM_VID_DRIVER_NAME "gem"
Nov 14, 2003
Nov 14, 2003
70
71
72
73
74
#undef MIN
#define MIN(a,b) (((a)<(b)) ? (a) : (b))
#undef MAX
#define MAX(a,b) (((a)>(b)) ? (a) : (b))
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
/* Variables */
static unsigned char vdi_index[256] = {
0, 2, 3, 6, 4, 7, 5, 8,
9, 10, 11, 14, 12, 15, 13, 255
};
static const unsigned char empty_name[]="";
/* Initialization/Query functions */
static int GEM_VideoInit(_THIS, SDL_PixelFormat *vformat);
static SDL_Rect **GEM_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
static SDL_Surface *GEM_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
static int GEM_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
static void GEM_VideoQuit(_THIS);
/* Hardware surface functions */
static int GEM_AllocHWSurface(_THIS, SDL_Surface *surface);
static int GEM_LockHWSurface(_THIS, SDL_Surface *surface);
static int GEM_FlipHWSurface(_THIS, SDL_Surface *surface);
static void GEM_UnlockHWSurface(_THIS, SDL_Surface *surface);
static void GEM_FreeHWSurface(_THIS, SDL_Surface *surface);
static void GEM_UpdateRects(_THIS, int numrects, SDL_Rect *rects);
#if 0
static int GEM_ToggleFullScreen(_THIS, int on);
#endif
/* Internal functions */
static void GEM_FreeBuffers(_THIS);
Mar 26, 2002
Mar 26, 2002
104
static void GEM_ClearScreen(_THIS);
Nov 12, 2003
Nov 12, 2003
105
static void GEM_ClearRect(_THIS, short *rect);
Mar 26, 2002
Mar 26, 2002
106
107
static void GEM_LockScreen(_THIS);
static void GEM_UnlockScreen(_THIS);
108
109
110
111
112
113
114
static void refresh_window(_THIS, int winhandle, short *rect);
/* GEM driver bootstrap functions */
static int GEM_Available(void)
{
/* Test if AES available */
Dec 7, 2002
Dec 7, 2002
115
if (appl_init() == -1)
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
return 0;
appl_exit();
return 1;
}
static void GEM_DeleteDevice(SDL_VideoDevice *device)
{
free(device->hidden);
free(device);
}
static SDL_VideoDevice *GEM_CreateDevice(int devindex)
{
SDL_VideoDevice *device;
/* Initialize all variables that we clean on shutdown */
device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
if ( device ) {
memset(device, 0, (sizeof *device));
device->hidden = (struct SDL_PrivateVideoData *)
malloc((sizeof *device->hidden));
}
if ( (device == NULL) || (device->hidden == NULL) ) {
SDL_OutOfMemory();
if ( device ) {
free(device);
}
return(0);
}
memset(device->hidden, 0, (sizeof *device->hidden));
/* Set the function pointers */
device->VideoInit = GEM_VideoInit;
device->ListModes = GEM_ListModes;
device->SetVideoMode = GEM_SetVideoMode;
device->SetColors = GEM_SetColors;
device->UpdateRects = NULL /*GEM_UpdateRects*/;
device->VideoQuit = GEM_VideoQuit;
device->AllocHWSurface = GEM_AllocHWSurface;
device->LockHWSurface = GEM_LockHWSurface;
device->UnlockHWSurface = GEM_UnlockHWSurface;
device->FlipHWSurface = GEM_FlipHWSurface;
device->FreeHWSurface = GEM_FreeHWSurface;
device->ToggleFullScreen = NULL /*GEM_ToggleFullScreen*/;
/* Window manager */
device->SetCaption = GEM_SetCaption;
Nov 12, 2003
Nov 12, 2003
164
device->SetIcon = GEM_SetIcon;
165
166
167
168
169
170
171
172
173
174
175
device->IconifyWindow = GEM_IconifyWindow;
device->GrabInput = GEM_GrabInput;
/* Events */
device->InitOSKeymap = GEM_InitOSKeymap;
device->PumpEvents = GEM_PumpEvents;
/* Mouse */
device->FreeWMCursor = GEM_FreeWMCursor;
device->CreateWMCursor = GEM_CreateWMCursor;
device->ShowWMCursor = GEM_ShowWMCursor;
Mar 26, 2002
Mar 26, 2002
176
device->WarpWMCursor = NULL /*GEM_WarpWMCursor*/;
177
178
device->CheckMouseMode = GEM_CheckMouseMode;
Mar 26, 2002
Mar 26, 2002
179
180
/* Joystick + Mouse relative motion */
SDL_AtariXbios_InstallVectors(ATARI_XBIOS_MOUSEEVENTS|ATARI_XBIOS_JOYSTICKEVENTS);
Mar 10, 2002
Mar 10, 2002
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
device->free = GEM_DeleteDevice;
return device;
}
VideoBootStrap GEM_bootstrap = {
GEM_VID_DRIVER_NAME, "Atari GEM video driver",
GEM_Available, GEM_CreateDevice
};
static void VDI_ReadExtInfo(_THIS, short *work_out)
{
unsigned long EdDI_version;
unsigned long cookie_EdDI;
Uint32 num_colours;
Uint16 clut_type, num_bits;
/* Read EdDI informations */
if (Getcookie(C_EdDI, &cookie_EdDI) == C_NOTFOUND) {
return;
}
EdDI_version = Atari_get_EdDI_version( (void *)cookie_EdDI);
vq_scrninfo(VDI_handle, work_out);
VDI_format = work_out[0];
clut_type = work_out[1];
num_bits = work_out[2];
num_colours = *((Uint32 *) &work_out[3]);
/* With EdDI>=1.1, we can have screen pitch, address and format
* so we can directly write to screen without using vro_cpyfm
*/
if (EdDI_version >= EDDI_11) {
VDI_pitch = work_out[5];
VDI_screen = (void *) *((unsigned long *) &work_out[6]);
switch(num_colours) {
case 32768UL:
if (work_out[14] & (1<<7)) {
/* Little endian */
if (work_out[14] & (1<<1)) {
Nov 12, 2003
Nov 12, 2003
225
VDI_FBMASK(1<<13, 31<<3, (3<<14)|7, 31<<8);
226
} else {
Nov 12, 2003
Nov 12, 2003
227
VDI_FBMASK(1<<7, 31<<2, (7<<13)|3, 31<<8);
228
229
230
231
}
} else {
/* Big endian */
if (work_out[14] & (1<<1)) {
Nov 12, 2003
Nov 12, 2003
232
VDI_FBMASK(1<<5, 31<<11, 31<<6, 31);
233
} else {
Nov 12, 2003
Nov 12, 2003
234
VDI_FBMASK(1<<15, 31<<10, 31<<5, 31);
235
236
237
238
239
240
}
}
break;
case 65536UL:
if (work_out[14] & (1<<7)) {
/* Little endian */
Nov 12, 2003
Nov 12, 2003
241
VDI_FBMASK(0, 31<<3, (7<<13)|7, 31<<8);
242
243
} else {
/* Big endian */
Nov 12, 2003
Nov 12, 2003
244
VDI_FBMASK(0, 31<<11, 63<<5, 31);
245
246
247
248
249
250
251
}
break;
case 16777216UL:
if (work_out[14] & (1<<7)) {
/* Little endian */
switch(num_bits) {
case 24:
Nov 12, 2003
Nov 12, 2003
252
VDI_FBMASK(0, 255, 255<<8, 255<<16);
253
254
break;
case 32:
Nov 12, 2003
Nov 12, 2003
255
VDI_FBMASK(255, 255<<8, 255<<16, 255<<24);
256
257
258
259
260
261
break;
}
} else {
/* Big endian */
switch(num_bits) {
case 24:
Nov 12, 2003
Nov 12, 2003
262
VDI_FBMASK(0, 255<<16, 255<<8, 255);
263
264
break;
case 32:
Nov 12, 2003
Nov 12, 2003
265
VDI_FBMASK(255<<24, 255<<16, 255<<8, 255);
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
break;
}
}
break;
}
}
switch(clut_type) {
case VDI_CLUT_HARDWARE:
{
int i;
Uint16 *tmp_p;
tmp_p = (Uint16 *)&work_out[16];
for (i=0;i<256;i++) {
Mar 26, 2002
Mar 26, 2002
282
vdi_index[*tmp_p++] = i;
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
}
}
break;
case VDI_CLUT_SOFTWARE:
if (EdDI_version < EDDI_11) {
int component; /* red, green, blue, alpha, overlay */
int num_bit;
unsigned short *tmp_p;
/* We can build masks with info here */
tmp_p = (unsigned short *) &work_out[16];
for (component=0;component<5;component++) {
for (num_bit=0;num_bit<16;num_bit++) {
unsigned short valeur;
valeur = *tmp_p++;
if (valeur == 0xffff) {
continue;
}
switch(component) {
case 0:
VDI_redmask |= 1<< valeur;
break;
case 1:
VDI_greenmask |= 1<< valeur;
break;
case 2:
VDI_bluemask |= 1<< valeur;
break;
case 3:
VDI_alphamask |= 1<< valeur;
break;
}
}
}
Mar 26, 2002
Mar 26, 2002
320
}
Mar 26, 2002
Mar 26, 2002
322
323
324
/* Remove lower green bits for Intel endian screen */
if ((VDI_greenmask == ((7<<13)|3)) || (VDI_greenmask == ((7<<13)|7))) {
VDI_greenmask &= ~(7<<13);
325
326
327
328
329
330
331
332
333
334
335
336
337
}
break;
case VDI_CLUT_NONE:
break;
}
}
int GEM_VideoInit(_THIS, SDL_PixelFormat *vformat)
{
int i;
short work_in[12], work_out[272], dummy;
/* Open AES (Application Environment Services) */
Dec 7, 2002
Dec 7, 2002
338
if (appl_init() == -1) {
339
340
341
342
343
fprintf(stderr,"Can not open AES\n");
return 1;
}
/* Read version and features */
Nov 12, 2003
Nov 12, 2003
344
345
346
GEM_version = aes_global[0];
if (GEM_version >= 0x0410) {
short ap_gout[4], errorcode;
Nov 12, 2003
Nov 12, 2003
348
349
350
351
#ifdef DEBUG_VIDEO_GEM
printf("sdl:video:gem: AES %02x.%02x\n", (GEM_version>>8) & 0xff, GEM_version & 0xff);
#endif
352
GEM_wfeatures=0;
Nov 12, 2003
Nov 12, 2003
353
354
355
356
357
358
errorcode=appl_getinfo(AES_WINDOW, &ap_gout[0], &ap_gout[1], &ap_gout[2], &ap_gout[3]);
#ifdef DEBUG_VIDEO_GEM
printf("sdl:video:gem: appl_getinfo() returned 0x%04x\n", errorcode);
#endif
if (errorcode==0) {
359
GEM_wfeatures=ap_gout[0];
Nov 12, 2003
Nov 12, 2003
360
361
362
363
364
365
366
367
368
#ifdef DEBUG_VIDEO_GEM
printf("sdl:video:gem: AES wind_*() modes: 0x%04x\n", GEM_wfeatures);
printf("sdl:video:gem: AES window behaviours: 0x%04x\n", ap_gout[3]);
} else {
printf("sdl:video:gem: apgout[]={0x%04x,0x%04x,0x%04x,0x%04x}\n",
ap_gout[0], ap_gout[1], ap_gout[1], ap_gout[3]
);
#endif
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
}
}
/* Ask VDI physical workstation handle opened by AES */
VDI_handle = graf_handle(&dummy, &dummy, &dummy, &dummy);
if (VDI_handle<1) {
fprintf(stderr,"Wrong VDI handle %d returned by AES\n",VDI_handle);
return 1;
}
/* Open virtual VDI workstation */
work_in[0]=Getrez()+2;
for(i = 1; i < 10; i++)
work_in[i] = 1;
work_in[10] = 2;
v_opnvwk(work_in, &VDI_handle, work_out);
if (VDI_handle == 0) {
fprintf(stderr,"Can not open VDI virtual workstation\n");
return 1;
}
/* Read fullscreen size */
VDI_w = work_out[0] + 1;
VDI_h = work_out[1] + 1;
/* Read desktop size and position */
if (!wind_get(DESKTOP_HANDLE, WF_WORKXYWH, &GEM_desk_x, &GEM_desk_y, &GEM_desk_w, &GEM_desk_h)) {
fprintf(stderr,"Can not read desktop properties\n");
return 1;
}
/* Read bit depth */
vq_extnd(VDI_handle, 1, work_out);
VDI_bpp = work_out[4];
VDI_oldnumcolors=0;
switch(VDI_bpp) {
case 8:
VDI_pixelsize=1;
break;
case 15:
case 16:
VDI_pixelsize=2;
break;
case 24:
VDI_pixelsize=3;
break;
case 32:
VDI_pixelsize=4;
break;
default:
fprintf(stderr,"%d bits colour depth not supported\n",VDI_bpp);
return 1;
}
/* Setup hardware -> VDI palette mapping */
for(i = 16; i < 255; i++) {
vdi_index[i] = i;
}
vdi_index[255] = 1;
/* Save current palette */
if (VDI_bpp>8) {
VDI_oldnumcolors=1<<8;
} else {
VDI_oldnumcolors=1<<VDI_bpp;
}
for(i = 0; i < VDI_oldnumcolors; i++) {
short rgb[3];
vq_color(VDI_handle, i, 0, rgb);
VDI_oldpalette[i][0] = rgb[0];
VDI_oldpalette[i][1] = rgb[1];
VDI_oldpalette[i][2] = rgb[2];
}
/* Setup screen info */
GEM_title_name = empty_name;
GEM_icon_name = empty_name;
GEM_handle = -1;
GEM_locked = SDL_FALSE;
GEM_win_fulled = SDL_FALSE;
VDI_screen = NULL;
VDI_ReadExtInfo(this, work_out);
if (VDI_screen == NULL) {
Mar 26, 2002
Mar 26, 2002
459
VDI_pitch = VDI_w * VDI_pixelsize;
Nov 12, 2003
Nov 12, 2003
460
461
462
463
VDI_format = VDI_FORMAT_PACK;
if (VDI_bpp <= 8) {
VDI_format = VDI_FORMAT_INTER;
}
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
VDI_redmask = VDI_greenmask = VDI_bluemask = VDI_alphamask = 0;
}
/* Setup destination mfdb */
VDI_dst_mfdb.fd_addr = NULL;
/* Update hardware info */
this->info.hw_available = 0;
this->info.video_mem = 0;
/* Determine the screen depth */
/* we change this during the SDL_SetVideoMode implementation... */
vformat->BitsPerPixel = VDI_bpp;
/* Set mouse cursor to arrow */
graf_mouse(ARROW, NULL);
/* Init chunky to planar routine */
Nov 12, 2003
Nov 12, 2003
482
483
484
485
486
487
488
489
490
491
SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8;
/* Setup VDI fill functions */
vsf_color(VDI_handle,0);
vsf_interior(VDI_handle,1);
vsf_perimeter(VDI_handle,0);
#ifdef DEBUG_VIDEO_GEM
printf("sdl:video:gem: VideoInit(): done\n");
#endif
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
/* We're done! */
return(0);
}
SDL_Rect **GEM_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
{
if (format->BitsPerPixel == VDI_bpp) {
return((SDL_Rect **)-1);
} else {
return ((SDL_Rect **)NULL);
}
}
static void GEM_FreeBuffers(_THIS)
{
/* Release buffer */
Nov 12, 2003
Nov 12, 2003
509
510
511
512
513
514
515
516
if ( GEM_buffer2 ) {
free( GEM_buffer2 );
GEM_buffer2=NULL;
}
if ( GEM_buffer1 ) {
free( GEM_buffer1 );
GEM_buffer1=NULL;
517
518
519
520
521
522
523
524
525
526
}
/* Destroy window */
if (GEM_handle>=0) {
wind_close(GEM_handle);
wind_delete(GEM_handle);
GEM_handle=-1;
}
}
Nov 12, 2003
Nov 12, 2003
527
static void GEM_ClearRect(_THIS, short *rect)
Mar 26, 2002
Mar 26, 2002
528
{
Nov 12, 2003
Nov 12, 2003
529
short oldrgb[3], rgb[3]={0,0,0};
Mar 26, 2002
Mar 26, 2002
530
531
532
533
534
535
536
vq_color(VDI_handle, vdi_index[0], 0, oldrgb);
vs_color(VDI_handle, vdi_index[0], rgb);
vsf_color(VDI_handle,0);
vsf_interior(VDI_handle,1);
vsf_perimeter(VDI_handle,0);
Nov 12, 2003
Nov 12, 2003
537
v_bar(VDI_handle, rect);
Mar 26, 2002
Mar 26, 2002
538
539
vs_color(VDI_handle, vdi_index[0], oldrgb);
Nov 12, 2003
Nov 12, 2003
540
541
542
543
544
545
546
547
548
549
550
551
}
static void GEM_ClearScreen(_THIS)
{
short pxy[4];
v_hide_c(VDI_handle);
pxy[0] = pxy[1] = 0;
pxy[2] = VDI_w - 1;
pxy[3] = VDI_h - 1;
GEM_ClearRect(this, pxy);
Mar 26, 2002
Mar 26, 2002
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
v_show_c(VDI_handle, 1);
}
static void GEM_LockScreen(_THIS)
{
if (!GEM_locked) {
/* Reserve memory space, used to be sure of compatibility */
form_dial( FMD_START, 0,0,0,0, 0,0,VDI_w,VDI_h);
/* Lock AES */
wind_update(BEG_UPDATE);
wind_update(BEG_MCTRL);
GEM_locked=SDL_TRUE;
}
}
static void GEM_UnlockScreen(_THIS)
{
if (GEM_locked) {
/* Restore screen memory, and send REDRAW to all apps */
form_dial( FMD_FINISH, 0,0,0,0, 0,0,VDI_w,VDI_h);
/* Unlock AES */
wind_update(END_MCTRL);
wind_update(END_UPDATE);
GEM_locked=SDL_FALSE;
}
}
582
583
584
585
586
SDL_Surface *GEM_SetVideoMode(_THIS, SDL_Surface *current,
int width, int height, int bpp, Uint32 flags)
{
int maxwidth, maxheight;
Uint32 modeflags, screensize;
Nov 12, 2003
Nov 12, 2003
587
SDL_bool use_shadow1, use_shadow2;
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
GEM_FreeBuffers(this);
/*--- Verify if asked mode can be used ---*/
if (flags & SDL_FULLSCREEN) {
maxwidth=VDI_w;
maxheight=VDI_h;
} else {
/* Windowed mode */
maxwidth=GEM_desk_w;
maxheight=GEM_desk_h;
}
if ((maxwidth < width) || (maxheight < height) || (VDI_bpp != bpp)) {
SDL_SetError("Couldn't find requested mode in list");
return(NULL);
}
/*--- Allocate the new pixel format for the screen ---*/
if ( ! SDL_ReallocFormat(current, VDI_bpp, VDI_redmask, VDI_greenmask, VDI_bluemask, VDI_alphamask) ) {
SDL_SetError("Couldn't allocate new pixel format for requested mode");
return(NULL);
}
Nov 12, 2003
Nov 12, 2003
612
613
614
615
616
617
618
619
620
screensize = width * height * VDI_pixelsize;
/*--- Allocate shadow buffers if needed, and conversion operations ---*/
GEM_bufops=0;
use_shadow1=use_shadow2=SDL_FALSE;
if (VDI_screen && (flags & SDL_FULLSCREEN)) {
if (VDI_format==VDI_FORMAT_INTER) {
use_shadow1=SDL_TRUE;
GEM_bufops = B2S_C2P_1TOS;
621
622
}
} else {
Nov 12, 2003
Nov 12, 2003
623
624
625
626
627
628
629
use_shadow1=SDL_TRUE;
if (VDI_format==VDI_FORMAT_PACK) {
GEM_bufops = B2S_VROCPYFM_1TOS;
} else {
use_shadow2=SDL_TRUE;
GEM_bufops = B2S_C2P_1TO2|B2S_VROCPYFM_2TOS;
}
630
631
}
Nov 12, 2003
Nov 12, 2003
632
633
634
635
636
637
638
639
640
641
642
if (use_shadow1) {
GEM_buffer1 = Atari_SysMalloc(screensize, MX_PREFTTRAM);
if (GEM_buffer1==NULL) {
fprintf(stderr,"Unable to allocate shadow buffer\n");
return NULL;
}
memset(GEM_buffer1, 0, screensize);
#ifdef DEBUG_VIDEO_GEM
printf("sdl:video:gem: setvideomode(): allocated buffer 1\n");
#endif
}
Nov 12, 2003
Nov 12, 2003
644
645
646
if (use_shadow2) {
GEM_buffer2 = Atari_SysMalloc(screensize, MX_PREFTTRAM);
if (GEM_buffer2==NULL) {
647
648
649
fprintf(stderr,"Unable to allocate shadow buffer\n");
return NULL;
}
Nov 12, 2003
Nov 12, 2003
650
651
652
653
memset(GEM_buffer2, 0, screensize);
#ifdef DEBUG_VIDEO_GEM
printf("sdl:video:gem: setvideomode(): allocated buffer 2\n");
#endif
654
655
656
}
/*--- Initialize screen ---*/
Oct 5, 2002
Oct 5, 2002
657
658
659
660
661
modeflags = 0;
if (VDI_bpp == 8) {
modeflags |= SDL_HWPALETTE;
}
662
if (flags & SDL_FULLSCREEN) {
Mar 26, 2002
Mar 26, 2002
663
GEM_LockScreen(this);
Mar 26, 2002
Mar 26, 2002
665
GEM_ClearScreen(this);
666
667
modeflags |= SDL_FULLSCREEN;
Nov 12, 2003
Nov 12, 2003
668
if (VDI_screen && (VDI_format==VDI_FORMAT_PACK) && !use_shadow1) {
669
670
671
672
673
674
675
676
modeflags |= SDL_HWSURFACE;
} else {
modeflags |= SDL_SWSURFACE;
}
} else {
int posx,posy;
short x2,y2,w2,h2;
Mar 26, 2002
Mar 26, 2002
677
GEM_UnlockScreen(this);
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
/* Center our window */
posx = GEM_desk_x;
posy = GEM_desk_y;
if (width<GEM_desk_w)
posx += (GEM_desk_w - width) >> 1;
if (height<GEM_desk_h)
posy += (GEM_desk_h - height) >> 1;
/* Calculate our window size and position */
if (!(flags & SDL_NOFRAME)) {
GEM_win_type=NAME|MOVER|CLOSER|SMALLER;
if (flags & SDL_RESIZABLE) {
GEM_win_type |= FULLER|SIZER;
modeflags |= SDL_RESIZABLE;
}
} else {
GEM_win_type=0;
modeflags |= SDL_NOFRAME;
}
if (!wind_calc(0, GEM_win_type, posx, posy, width, height, &x2, &y2, &w2, &h2)) {
GEM_FreeBuffers(this);
fprintf(stderr,"Can not calculate window attributes\n");
return NULL;
}
/* Create window */
GEM_handle=wind_create(GEM_win_type, x2, y2, w2, h2);
if (GEM_handle<0) {
GEM_FreeBuffers(this);
fprintf(stderr,"Can not create window\n");
return NULL;
}
Nov 12, 2003
Nov 12, 2003
713
714
715
716
#ifdef DEBUG_VIDEO_GEM
printf("sdl:video:gem: handle=%d\n", GEM_handle);
#endif
717
718
/* Setup window name */
wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_title_name)>>16),(short)(((unsigned long)GEM_title_name) & 0xffff),0,0);
Nov 12, 2003
Nov 12, 2003
719
GEM_refresh_name = SDL_FALSE;
720
721
722
723
724
725
726
727
728
729
730
/* Open the window */
wind_open(GEM_handle,x2,y2,w2,h2);
modeflags |= SDL_SWSURFACE;
}
/* Set up the new mode framebuffer */
current->flags = modeflags;
current->w = width;
current->h = height;
Nov 12, 2003
Nov 12, 2003
731
732
if (use_shadow1) {
current->pixels = GEM_buffer1;
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
current->pitch = width * (VDI_bpp >> 3);
} else {
current->pixels = VDI_screen;
current->pixels += VDI_pitch * ((VDI_h - height) >> 1);
current->pixels += VDI_pixelsize * ((VDI_w - width) >> 1);
current->pitch = VDI_pitch;
}
this->UpdateRects = GEM_UpdateRects;
/* We're done */
return(current);
}
static int GEM_AllocHWSurface(_THIS, SDL_Surface *surface)
{
return -1;
}
static void GEM_FreeHWSurface(_THIS, SDL_Surface *surface)
{
return;
}
static int GEM_LockHWSurface(_THIS, SDL_Surface *surface)
{
return(0);
}
static void GEM_UnlockHWSurface(_THIS, SDL_Surface *surface)
{
return;
}
static void GEM_UpdateRectsFullscreen(_THIS, int numrects, SDL_Rect *rects)
{
SDL_Surface *surface;
Mar 26, 2002
Mar 26, 2002
769
int i;
770
771
772
surface = this->screen;
Nov 12, 2003
Nov 12, 2003
773
774
775
776
777
if (GEM_bufops & (B2S_C2P_1TO2|B2S_C2P_1TOS)) {
void *destscr;
int destpitch;
if (GEM_bufops & B2S_C2P_1TOS) {
778
int destx;
Nov 12, 2003
Nov 12, 2003
779
780
781
782
783
destscr = VDI_screen;
destscr += VDI_pitch * ((VDI_h - surface->h) >> 1);
destx = (VDI_w - surface->w) >> 1;
destx &= ~15;
Mar 26, 2002
Mar 26, 2002
784
destscr += destx;
Nov 12, 2003
Nov 12, 2003
785
786
787
788
789
destpitch = VDI_pitch;
} else {
destscr = GEM_buffer2;
destpitch = surface->pitch;
}
Nov 12, 2003
Nov 12, 2003
791
792
793
for (i=0;i<numrects;i++) {
void *source,*destination;
int x1,x2;
Mar 26, 2002
Mar 26, 2002
794
Nov 12, 2003
Nov 12, 2003
795
796
797
798
x1 = rects[i].x & ~15;
x2 = rects[i].x+rects[i].w;
if (x2 & 15) {
x2 = (x2 | 15) +1;
Mar 26, 2002
Mar 26, 2002
799
800
}
Nov 12, 2003
Nov 12, 2003
801
802
803
source = surface->pixels;
source += surface->pitch * rects[i].y;
source += x1;
Nov 12, 2003
Nov 12, 2003
805
806
807
808
809
810
811
812
813
814
destination = destscr;
destination += destpitch * rects[i].y;
destination += x1;
SDL_Atari_C2pConvert(
source, destination,
x2-x1, rects[i].h,
SDL_FALSE,
surface->pitch, destpitch
);
815
816
}
}
Mar 26, 2002
Mar 26, 2002
817
Nov 12, 2003
Nov 12, 2003
818
819
820
if (GEM_bufops & (B2S_VROCPYFM_1TOS|B2S_VROCPYFM_2TOS)) {
MFDB mfdb_src;
short blitcoords[8];
Mar 26, 2002
Mar 26, 2002
821
Nov 12, 2003
Nov 12, 2003
822
823
824
825
826
827
828
829
830
831
832
833
mfdb_src.fd_addr=surface->pixels;
mfdb_src.fd_w=surface->w;
mfdb_src.fd_h=surface->h;
mfdb_src.fd_wdwidth=(surface->w) >> 4;
mfdb_src.fd_nplanes=surface->format->BitsPerPixel;
mfdb_src.fd_stand=
mfdb_src.fd_r1=
mfdb_src.fd_r2=
mfdb_src.fd_r3= 0;
if (GEM_bufops & B2S_VROCPYFM_2TOS) {
mfdb_src.fd_addr=GEM_buffer2;
}
Mar 26, 2002
Mar 26, 2002
834
Nov 12, 2003
Nov 12, 2003
835
836
837
838
839
for ( i=0; i<numrects; ++i ) {
blitcoords[0] = rects[i].x;
blitcoords[1] = rects[i].y;
blitcoords[2] = blitcoords[0] + rects[i].w - 1;
blitcoords[3] = blitcoords[1] + rects[i].h - 1;
Mar 26, 2002
Mar 26, 2002
840
Nov 12, 2003
Nov 12, 2003
841
842
843
844
845
846
847
blitcoords[4] = rects[i].x + ((VDI_w - surface->w) >> 1);
blitcoords[5] = rects[i].y + ((VDI_h - surface->h) >> 1);
blitcoords[6] = blitcoords[4] + rects[i].w - 1;
blitcoords[7] = blitcoords[5] + rects[i].h - 1;
vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &mfdb_src, &VDI_dst_mfdb);
}
Mar 26, 2002
Mar 26, 2002
848
}
849
850
851
852
}
static void GEM_UpdateRectsWindowed(_THIS, int numrects, SDL_Rect *rects)
{
Nov 12, 2003
Nov 12, 2003
853
short pxy[4], wind_pxy[4];
854
855
int i;
Nov 12, 2003
Nov 12, 2003
856
857
858
if (wind_get(GEM_handle, WF_WORKXYWH, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2], &wind_pxy[3])==0) {
return;
}
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
for ( i=0; i<numrects; ++i ) {
pxy[0] = wind_pxy[0] + rects[i].x;
pxy[1] = wind_pxy[1] + rects[i].y;
pxy[2] = rects[i].w;
pxy[3] = rects[i].h;
GEM_wind_redraw(this, GEM_handle, pxy);
}
}
static void GEM_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
{
SDL_Surface *surface;
surface = this->screen;
if (surface->flags & SDL_FULLSCREEN) {
GEM_UpdateRectsFullscreen(this, numrects, rects);
} else {
GEM_UpdateRectsWindowed(this, numrects, rects);
}
}
static int GEM_FlipHWSurfaceFullscreen(_THIS, SDL_Surface *surface)
{
Nov 12, 2003
Nov 12, 2003
885
886
887
if (GEM_bufops & (B2S_C2P_1TO2|B2S_C2P_1TOS)) {
void *destscr;
int destpitch;
Mar 26, 2002
Mar 26, 2002
888
Nov 12, 2003
Nov 12, 2003
889
if (GEM_bufops & B2S_C2P_1TOS) {
890
int destx;
Nov 12, 2003
Nov 12, 2003
891
892
893
894
895
destscr = VDI_screen;
destscr += VDI_pitch * ((VDI_h - surface->h) >> 1);
destx = (VDI_w - surface->w) >> 1;
destx &= ~15;
Mar 26, 2002
Mar 26, 2002
896
destscr += destx;
Nov 12, 2003
Nov 12, 2003
897
898
899
900
901
destpitch = VDI_pitch;
} else {
destscr = GEM_buffer2;
destpitch = surface->pitch;
}
Nov 12, 2003
Nov 12, 2003
903
904
905
906
907
908
909
SDL_Atari_C2pConvert(
surface->pixels, destscr,
surface->w, surface->h,
SDL_FALSE,
surface->pitch, destpitch
);
}
Mar 26, 2002
Mar 26, 2002
910
Nov 12, 2003
Nov 12, 2003
911
912
913
if (GEM_bufops & (B2S_VROCPYFM_1TOS|B2S_VROCPYFM_2TOS)) {
MFDB mfdb_src;
short blitcoords[8];
Nov 12, 2003
Nov 12, 2003
915
916
917
918
919
920
921
922
923
924
925
926
mfdb_src.fd_w=surface->w;
mfdb_src.fd_h=surface->h;
mfdb_src.fd_wdwidth=(surface->w) >> 4;
mfdb_src.fd_nplanes=surface->format->BitsPerPixel;
mfdb_src.fd_stand=
mfdb_src.fd_r1=
mfdb_src.fd_r2=
mfdb_src.fd_r3= 0;
if (GEM_bufops & B2S_VROCPYFM_1TOS) {
mfdb_src.fd_addr=surface->pixels;
} else {
mfdb_src.fd_addr=GEM_buffer2;
Mar 26, 2002
Mar 26, 2002
927
}
Nov 12, 2003
Nov 12, 2003
928
929
930
931
932
933
934
935
936
937
938
939
blitcoords[0] = 0;
blitcoords[1] = 0;
blitcoords[2] = surface->w - 1;
blitcoords[3] = surface->h - 1;
blitcoords[4] = (VDI_w - surface->w) >> 1;
blitcoords[5] = (VDI_h - surface->h) >> 1;
blitcoords[6] = blitcoords[4] + surface->w - 1;
blitcoords[7] = blitcoords[5] + surface->h - 1;
vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &mfdb_src, &VDI_dst_mfdb);
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
}
return(0);
}
static int GEM_FlipHWSurfaceWindowed(_THIS, SDL_Surface *surface)
{
short pxy[8];
/* Update the whole window */
wind_get(GEM_handle, WF_WORKXYWH, &pxy[0], &pxy[1], &pxy[2], &pxy[3]);
GEM_wind_redraw(this, GEM_handle, pxy);
return(0);
}
static int GEM_FlipHWSurface(_THIS, SDL_Surface *surface)
{
if (surface->flags & SDL_FULLSCREEN) {
return GEM_FlipHWSurfaceFullscreen(this, surface);
} else {
return GEM_FlipHWSurfaceWindowed(this, surface);
}
}
static int GEM_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
{
int i;
SDL_Surface *surface;
Nov 12, 2003
Nov 12, 2003
971
972
973
974
#ifdef DEBUG_VIDEO_GEM
printf("sdl:video:gem: setcolors()\n");
#endif
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Do not change palette in True Colour */
surface = this->screen;
if (surface->format->BitsPerPixel > 8) {
return 1;
}
for(i = 0; i < ncolors; i++)
{
int r, g, b;
short rgb[3];
r = colors[i].r;
g = colors[i].g;
b = colors[i].b;
rgb[0] = (1000 * r) / 255;
rgb[1] = (1000 * g) / 255;
rgb[2] = (1000 * b) / 255;
vs_color(VDI_handle, vdi_index[firstcolor+i], rgb);
}
return(1);
}
#if 0