Skip to content

Latest commit

 

History

History
1429 lines (1169 loc) · 32.2 KB

SDL_gemvideo.c

File metadata and controls

1429 lines (1169 loc) · 32.2 KB
 
1
2
/*
SDL - Simple DirectMedia Layer
Dec 31, 2011
Dec 31, 2011
3
Copyright (C) 1997-2012 Sam Lantinga
4
5
This library is free software; you can redistribute it and/or
Feb 1, 2006
Feb 1, 2006
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
Feb 1, 2006
Feb 1, 2006
8
version 2.1 of the License, or (at your option) any later version.
9
10
11
12
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
Feb 1, 2006
Feb 1, 2006
13
Lesser General Public License for more details.
Feb 1, 2006
Feb 1, 2006
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19
20
21
Sam Lantinga
slouken@libsdl.org
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Nov 12, 2003
Nov 12, 2003
25
26
27
28
29
30
GEM video driver
Patrice Mandin
and work from
Olivier Landemarre, Johan Klockars, Xavier Joubert, Claude Attard
*/
31
32
33
34
35
/* Mint includes */
#include <gem.h>
#include <gemx.h>
#include <mint/osbind.h>
Dec 7, 2002
Dec 7, 2002
36
#include <mint/cookie.h>
Feb 10, 2006
Feb 10, 2006
38
#include "SDL_endian.h"
39
40
#include "SDL_video.h"
#include "SDL_mouse.h"
Feb 16, 2006
Feb 16, 2006
41
42
43
44
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../../events/SDL_events_c.h"
#include "../SDL_cursor_c.h"
Feb 21, 2006
Feb 21, 2006
46
47
48
49
#include "../ataricommon/SDL_ataric2p_s.h"
#include "../ataricommon/SDL_atarieddi_s.h"
#include "../ataricommon/SDL_atarimxalloc_c.h"
#include "../ataricommon/SDL_atarigl_c.h"
Nov 25, 2004
Nov 25, 2004
50
51
52
53
54
#include "SDL_gemvideo.h"
#include "SDL_gemevents_c.h"
#include "SDL_gemmouse_c.h"
#include "SDL_gemwm_c.h"
Feb 21, 2006
Feb 21, 2006
55
#include "../ataricommon/SDL_xbiosevents_c.h"
Feb 23, 2006
Feb 23, 2006
56
#include "../ataricommon/SDL_ataridevmouse_c.h"
57
58
59
/* Defines */
Nov 21, 2004
Nov 21, 2004
60
/*#define DEBUG_VIDEO_GEM 1*/
Nov 12, 2003
Nov 12, 2003
61
62
63
#define GEM_VID_DRIVER_NAME "gem"
Nov 14, 2003
Nov 14, 2003
64
65
66
67
68
#undef MIN
#define MIN(a,b) (((a)<(b)) ? (a) : (b))
#undef MAX
#define MAX(a,b) (((a)>(b)) ? (a) : (b))
69
70
/* Variables */
Oct 14, 2017
Oct 14, 2017
71
72
static short internal_ap_id;
73
74
75
76
77
static unsigned char vdi_index[256] = {
0, 2, 3, 6, 4, 7, 5, 8,
9, 10, 11, 14, 12, 15, 13, 255
};
Aug 28, 2011
Aug 28, 2011
78
static const char empty_name[]="";
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* 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);
/* Internal functions */
static void GEM_FreeBuffers(_THIS);
Mar 26, 2002
Mar 26, 2002
97
static void GEM_ClearScreen(_THIS);
Oct 6, 2017
Oct 6, 2017
98
99
static void GEM_ClearRect(_THIS, short *pxy);
static void GEM_ClearRectXYWH(_THIS, short *rect);
Jun 7, 2005
Jun 7, 2005
100
static void GEM_SetNewPalette(_THIS, Uint16 newpal[256][3]);
Mar 26, 2002
Mar 26, 2002
101
102
static void GEM_LockScreen(_THIS);
static void GEM_UnlockScreen(_THIS);
Oct 7, 2017
Oct 7, 2017
103
static void refresh_window(_THIS, int winhandle, short *rect, SDL_bool pad_only);
Feb 16, 2006
Feb 16, 2006
105
#if SDL_VIDEO_OPENGL
Nov 21, 2004
Nov 21, 2004
106
107
108
109
/* OpenGL functions */
static void GEM_GL_SwapBuffers(_THIS);
#endif
110
111
112
113
114
/* GEM driver bootstrap functions */
static int GEM_Available(void)
{
/* Test if AES available */
Oct 14, 2017
Oct 14, 2017
115
116
internal_ap_id = appl_init();
if (internal_ap_id == -1)
117
118
119
120
121
122
123
return 0;
return 1;
}
static void GEM_DeleteDevice(SDL_VideoDevice *device)
{
Feb 7, 2006
Feb 7, 2006
124
125
SDL_free(device->hidden);
SDL_free(device);
126
127
128
129
130
}
static SDL_VideoDevice *GEM_CreateDevice(int devindex)
{
SDL_VideoDevice *device;
Jan 6, 2006
Jan 6, 2006
131
int vectors_mask;
Aug 26, 2011
Aug 26, 2011
132
/* unsigned long dummy;*/
133
134
/* Initialize all variables that we clean on shutdown */
Feb 7, 2006
Feb 7, 2006
135
device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
136
if ( device ) {
Feb 7, 2006
Feb 7, 2006
137
SDL_memset(device, 0, (sizeof *device));
138
device->hidden = (struct SDL_PrivateVideoData *)
Feb 7, 2006
Feb 7, 2006
139
SDL_malloc((sizeof *device->hidden));
Nov 25, 2004
Nov 25, 2004
140
device->gl_data = (struct SDL_PrivateGLData *)
Feb 7, 2006
Feb 7, 2006
141
SDL_malloc((sizeof *device->gl_data));
142
143
144
145
}
if ( (device == NULL) || (device->hidden == NULL) ) {
SDL_OutOfMemory();
if ( device ) {
Feb 7, 2006
Feb 7, 2006
146
SDL_free(device);
147
148
149
}
return(0);
}
Feb 7, 2006
Feb 7, 2006
150
151
SDL_memset(device->hidden, 0, (sizeof *device->hidden));
SDL_memset(device->gl_data, 0, sizeof(*device->gl_data));
152
153
154
155
156
157
158
159
160
161
162
163
164
/* 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;
Sep 30, 2017
Sep 30, 2017
165
device->ToggleFullScreen = NULL;
166
167
168
/* Window manager */
device->SetCaption = GEM_SetCaption;
Nov 12, 2003
Nov 12, 2003
169
device->SetIcon = GEM_SetIcon;
170
171
172
173
174
175
176
177
178
179
180
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
181
device->WarpWMCursor = NULL /*GEM_WarpWMCursor*/;
182
183
device->CheckMouseMode = GEM_CheckMouseMode;
Feb 16, 2006
Feb 16, 2006
184
#if SDL_VIDEO_OPENGL
Nov 21, 2004
Nov 21, 2004
185
/* OpenGL functions */
Nov 25, 2004
Nov 25, 2004
186
187
188
189
device->GL_LoadLibrary = SDL_AtariGL_LoadLibrary;
device->GL_GetProcAddress = SDL_AtariGL_GetProcAddress;
device->GL_GetAttribute = SDL_AtariGL_GetAttribute;
device->GL_MakeCurrent = SDL_AtariGL_MakeCurrent;
Nov 21, 2004
Nov 21, 2004
190
191
192
device->GL_SwapBuffers = GEM_GL_SwapBuffers;
#endif
Feb 23, 2006
Feb 23, 2006
193
194
195
196
197
198
199
device->hidden->use_dev_mouse =
(SDL_AtariDevMouse_Open()!=0) ? SDL_TRUE : SDL_FALSE;
vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS; /* XBIOS joystick events */
if (!(device->hidden->use_dev_mouse)) {
vectors_mask |= ATARI_XBIOS_MOUSEEVENTS; /* XBIOS mouse events */
}
Sep 12, 2006
Sep 12, 2006
200
/* if (Getcookie(C_MiNT, &dummy)==C_FOUND) {
Jan 6, 2006
Jan 6, 2006
201
vectors_mask = 0;
Sep 12, 2006
Sep 12, 2006
202
}*/
Jan 6, 2006
Jan 6, 2006
203
204
SDL_AtariXbios_InstallVectors(vectors_mask);
Mar 10, 2002
Mar 10, 2002
205
206
207
208
209
210
211
212
213
214
215
device->free = GEM_DeleteDevice;
return device;
}
VideoBootStrap GEM_bootstrap = {
GEM_VID_DRIVER_NAME, "Atari GEM video driver",
GEM_Available, GEM_CreateDevice
};
Nov 6, 2017
Nov 6, 2017
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
static void VDI_ReadNOVAInfo(_THIS, short *work_out)
{
long cookie_nova;
/* Read NOVA informations */
if (Getcookie(C_NOVA, &cookie_nova) != C_FOUND) {
return;
}
switch(VDI_bpp) {
case 15:
VDI_redmask = 31<<2;
VDI_greenmask = 3;
VDI_bluemask = 31<<8;
VDI_alphamask = 1<<7;
break;
case 16:
VDI_redmask = 31<<3;
VDI_greenmask = 7;
VDI_bluemask = 31<<8;
break;
case 24:
VDI_redmask = 255;
VDI_greenmask = 255<<8;
VDI_bluemask = 255<<16;
break;
case 32:
VDI_redmask = 255<<24;
VDI_greenmask = 255<<16;
VDI_bluemask = 255<<8;
VDI_alphamask = 255;
break;
}
}
251
252
253
static void VDI_ReadExtInfo(_THIS, short *work_out)
{
unsigned long EdDI_version;
Aug 28, 2011
Aug 28, 2011
254
long cookie_EdDI;
Sep 3, 2011
Sep 3, 2011
255
Uint16 clut_type;
256
257
/* Read EdDI informations */
Aug 13, 2014
Aug 13, 2014
258
if (Getcookie(C_EdDI, &cookie_EdDI) != C_FOUND) {
259
260
return;
}
Sep 30, 2017
Sep 30, 2017
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
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];
/* 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(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
286
vdi_index[*tmp_p++] = i;
287
288
289
290
}
}
break;
case VDI_CLUT_SOFTWARE:
Feb 6, 2004
Feb 6, 2004
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
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
324
}
Mar 26, 2002
Mar 26, 2002
326
327
328
/* Remove lower green bits for Intel endian screen */
if ((VDI_greenmask == ((7<<13)|3)) || (VDI_greenmask == ((7<<13)|7))) {
VDI_greenmask &= ~(7<<13);
329
330
331
332
333
334
335
336
337
}
break;
case VDI_CLUT_NONE:
break;
}
}
int GEM_VideoInit(_THIS, SDL_PixelFormat *vformat)
{
Jun 6, 2005
Jun 6, 2005
338
int i, menubar_size;
339
340
341
short work_in[12], work_out[272], dummy;
/* Open AES (Application Environment Services) */
Oct 14, 2017
Oct 14, 2017
342
GEM_ap_id = internal_ap_id;
Sep 11, 2014
Sep 11, 2014
343
if (GEM_ap_id == -1) {
344
345
346
347
348
fprintf(stderr,"Can not open AES\n");
return 1;
}
/* Read version and features */
Nov 12, 2003
Nov 12, 2003
349
350
351
GEM_version = aes_global[0];
if (GEM_version >= 0x0410) {
short ap_gout[4], errorcode;
Sep 30, 2017
Sep 30, 2017
352
353
GEM_wfeatures=0;
Nov 12, 2003
Nov 12, 2003
354
355
356
errorcode=appl_getinfo(AES_WINDOW, &ap_gout[0], &ap_gout[1], &ap_gout[2], &ap_gout[3]);
if (errorcode==0) {
Sep 30, 2017
Sep 30, 2017
357
GEM_wfeatures=ap_gout[0];
Sep 30, 2017
Sep 30, 2017
359
}
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
/* 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;
}
Sep 30, 2017
Sep 30, 2017
390
391
392
393
394
GEM_work_x = GEM_desk_x;
GEM_work_y = GEM_desk_y;
GEM_work_w = GEM_desk_w;
GEM_work_h = GEM_desk_h;
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
/* 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;
}
Sep 30, 2017
Sep 30, 2017
431
432
433
434
435
436
437
438
439
440
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];
}
Jun 7, 2005
Jun 7, 2005
441
VDI_setpalette = GEM_SetNewPalette;
Feb 7, 2006
Feb 7, 2006
442
SDL_memcpy(VDI_curpalette,VDI_oldpalette,sizeof(VDI_curpalette));
443
444
445
446
447
448
449
450
/* 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;
Oct 6, 2017
Oct 6, 2017
451
GEM_iconified = SDL_FALSE;
Aug 10, 2004
Aug 10, 2004
452
GEM_fullscreen = SDL_FALSE;
Nov 6, 2004
Nov 6, 2004
453
GEM_lock_redraw = SDL_TRUE; /* Prevent redraw till buffers are setup */
454
455
VDI_screen = NULL;
Feb 6, 2004
Feb 6, 2004
456
457
458
VDI_pitch = VDI_w * VDI_pixelsize;
VDI_format = ( (VDI_bpp <= 8) ? VDI_FORMAT_INTER : VDI_FORMAT_PACK);
VDI_redmask = VDI_greenmask = VDI_bluemask = VDI_alphamask = 0;
Nov 6, 2017
Nov 6, 2017
459
VDI_ReadNOVAInfo(this, work_out);
Feb 6, 2004
Feb 6, 2004
460
461
462
463
464
465
466
467
468
VDI_ReadExtInfo(this, work_out);
#ifdef DEBUG_VIDEO_GEM
printf("sdl:video:gem: screen: address=0x%08x, pitch=%d\n", VDI_screen, VDI_pitch);
printf("sdl:video:gem: format=%d\n", VDI_format);
printf("sdl:video:gem: masks: 0x%08x, 0x%08x, 0x%08x, 0x%08x\n",
VDI_alphamask, VDI_redmask, VDI_greenmask, VDI_bluemask
);
#endif
469
470
471
472
/* Setup destination mfdb */
VDI_dst_mfdb.fd_addr = NULL;
Mar 15, 2006
Mar 15, 2006
473
474
475
/* Determine the current screen size */
this->info.current_w = VDI_w;
this->info.current_h = VDI_h;
476
477
478
479
480
481
482
/* 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);
Oct 2, 2017
Oct 2, 2017
483
GEM_cursor = GEM_prev_cursor = NULL;
484
485
/* Init chunky to planar routine */
Nov 12, 2003
Nov 12, 2003
486
487
488
489
490
491
492
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);
Jun 6, 2005
Jun 6, 2005
493
494
495
496
/* Menu bar save buffer */
menubar_size = GEM_desk_w * GEM_desk_y * VDI_pixelsize;
GEM_menubar=Atari_SysMalloc(menubar_size,MX_PREFTTRAM);
Jul 17, 2004
Jul 17, 2004
497
/* Fill video modes list */
Feb 7, 2006
Feb 7, 2006
498
SDL_modelist[0] = SDL_malloc(sizeof(SDL_Rect));
Jul 17, 2004
Jul 17, 2004
499
500
501
502
503
504
505
SDL_modelist[0]->x = 0;
SDL_modelist[0]->y = 0;
SDL_modelist[0]->w = VDI_w;
SDL_modelist[0]->h = VDI_h;
SDL_modelist[1] = NULL;
Feb 16, 2006
Feb 16, 2006
506
#if SDL_VIDEO_OPENGL
Nov 26, 2004
Nov 26, 2004
507
SDL_AtariGL_InitPointers(this);
Nov 12, 2003
Nov 12, 2003
508
#endif
May 26, 2007
May 26, 2007
510
this->info.wm_available = 1;
May 26, 2007
May 26, 2007
511
512
513
514
515
516
517
/* We're done! */
return(0);
}
SDL_Rect **GEM_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
{
Jul 17, 2004
Jul 17, 2004
518
if (format->BitsPerPixel != VDI_bpp) {
519
520
return ((SDL_Rect **)NULL);
}
Jul 17, 2004
Jul 17, 2004
521
522
523
524
525
526
if (flags & SDL_FULLSCREEN) {
return (SDL_modelist);
}
return((SDL_Rect **)-1);
527
528
529
530
531
}
static void GEM_FreeBuffers(_THIS)
{
/* Release buffer */
Nov 12, 2003
Nov 12, 2003
532
if ( GEM_buffer2 ) {
Jun 6, 2005
Jun 6, 2005
533
Mfree( GEM_buffer2 );
Nov 12, 2003
Nov 12, 2003
534
535
536
537
GEM_buffer2=NULL;
}
if ( GEM_buffer1 ) {
Jun 6, 2005
Jun 6, 2005
538
Mfree( GEM_buffer1 );
Nov 12, 2003
Nov 12, 2003
539
GEM_buffer1=NULL;
540
541
542
}
}
Oct 6, 2017
Oct 6, 2017
543
void GEM_ClearRect(_THIS, short *pxy)
Mar 26, 2002
Mar 26, 2002
544
{
Oct 12, 2017
Oct 12, 2017
545
546
547
548
549
short oldrgb[3], rgb[3]={0,0,0}, clip_pxy[4];
clip_pxy[0] = clip_pxy[1] = 0;
clip_pxy[2] = VDI_w - 1;
clip_pxy[3] = VDI_h - 1;
Mar 26, 2002
Mar 26, 2002
550
Oct 12, 2017
Oct 12, 2017
551
552
vq_color(VDI_handle, 0, 0, oldrgb);
vs_color(VDI_handle, 0, rgb);
Mar 26, 2002
Mar 26, 2002
553
554
555
556
vsf_color(VDI_handle,0);
vsf_interior(VDI_handle,1);
vsf_perimeter(VDI_handle,0);
Oct 12, 2017
Oct 12, 2017
557
558
vs_clip(VDI_handle, 1, clip_pxy);
Oct 6, 2017
Oct 6, 2017
559
v_bar(VDI_handle, pxy);
Oct 12, 2017
Oct 12, 2017
560
vs_clip(VDI_handle, 0, NULL);
Mar 26, 2002
Mar 26, 2002
561
Oct 12, 2017
Oct 12, 2017
562
vs_color(VDI_handle, 0, oldrgb);
Nov 12, 2003
Nov 12, 2003
563
564
}
Oct 6, 2017
Oct 6, 2017
565
566
567
568
569
570
571
572
573
574
575
576
void GEM_ClearRectXYWH(_THIS, short *rect)
{
short pxy[4];
pxy[0] = rect[0];
pxy[1] = rect[1];
pxy[2] = rect[0]+rect[2]-1;
pxy[3] = rect[1]+rect[3]-1;
GEM_ClearRect(this, pxy);
}
Nov 12, 2003
Nov 12, 2003
577
578
579
580
581
582
583
584
585
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;
Sep 30, 2017
Sep 30, 2017
586
GEM_ClearRect(this, pxy);
Mar 26, 2002
Mar 26, 2002
587
588
589
590
v_show_c(VDI_handle, 1);
}
Jun 7, 2005
Jun 7, 2005
591
592
593
594
595
static void GEM_SetNewPalette(_THIS, Uint16 newpal[256][3])
{
int i;
for(i = 0; i < VDI_oldnumcolors; i++) {
Oct 12, 2017
Oct 12, 2017
596
vs_color(VDI_handle, i, (short *) newpal[i]);
Jun 7, 2005
Jun 7, 2005
597
598
599
}
}
Mar 26, 2002
Mar 26, 2002
600
601
602
603
604
605
static void GEM_LockScreen(_THIS)
{
if (!GEM_locked) {
/* Lock AES */
wind_update(BEG_UPDATE);
wind_update(BEG_MCTRL);
Aug 2, 2004
Aug 2, 2004
606
607
/* Reserve memory space, used to be sure of compatibility */
form_dial( FMD_START, 0,0,0,0, 0,0,VDI_w,VDI_h);
Mar 26, 2002
Mar 26, 2002
608
Jun 6, 2005
Jun 6, 2005
609
610
611
612
613
614
615
616
/* Save menu bar */
if (GEM_menubar) {
MFDB mfdb_src;
short blitcoords[8];
mfdb_src.fd_addr=GEM_menubar;
mfdb_src.fd_w=GEM_desk_w;
mfdb_src.fd_h=GEM_desk_y;
Jun 7, 2005
Jun 7, 2005
617
mfdb_src.fd_wdwidth=GEM_desk_w>>4;
Jun 6, 2005
Jun 6, 2005
618
619
620
621
622
623
624
625
626
627
628
629
630
631
mfdb_src.fd_nplanes=VDI_bpp;
mfdb_src.fd_stand=
mfdb_src.fd_r1=
mfdb_src.fd_r2=
mfdb_src.fd_r3= 0;
blitcoords[0] = blitcoords[4] = 0;
blitcoords[1] = blitcoords[5] = 0;
blitcoords[2] = blitcoords[6] = GEM_desk_w-1;
blitcoords[3] = blitcoords[7] = GEM_desk_y-1;
vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &VDI_dst_mfdb, &mfdb_src);
}
Mar 26, 2002
Mar 26, 2002
632
633
634
635
636
637
638
GEM_locked=SDL_TRUE;
}
}
static void GEM_UnlockScreen(_THIS)
{
if (GEM_locked) {
Jun 6, 2005
Jun 6, 2005
639
640
641
642
643
644
645
646
/* Restore menu bar */
if (GEM_menubar) {
MFDB mfdb_src;
short blitcoords[8];
mfdb_src.fd_addr=GEM_menubar;
mfdb_src.fd_w=GEM_desk_w;
mfdb_src.fd_h=GEM_desk_y;
Jun 7, 2005
Jun 7, 2005
647
mfdb_src.fd_wdwidth=GEM_desk_w>>4;
Jun 6, 2005
Jun 6, 2005
648
649
650
651
652
653
654
655
656
657
658
659
660
661
mfdb_src.fd_nplanes=VDI_bpp;
mfdb_src.fd_stand=
mfdb_src.fd_r1=
mfdb_src.fd_r2=
mfdb_src.fd_r3= 0;
blitcoords[0] = blitcoords[4] = 0;
blitcoords[1] = blitcoords[5] = 0;
blitcoords[2] = blitcoords[6] = GEM_desk_w-1;
blitcoords[3] = blitcoords[7] = GEM_desk_y-1;
vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &mfdb_src, &VDI_dst_mfdb);
}
Mar 26, 2002
Mar 26, 2002
662
663
664
665
666
667
668
669
670
671
/* 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;
}
}
672
673
674
675
SDL_Surface *GEM_SetVideoMode(_THIS, SDL_Surface *current,
int width, int height, int bpp, Uint32 flags)
{
Uint32 modeflags, screensize;
Nov 12, 2003
Nov 12, 2003
676
SDL_bool use_shadow1, use_shadow2;
Feb 6, 2004
Feb 6, 2004
678
/* width must be multiple of 16, for vro_cpyfm() and c2p_convert() */
Aug 3, 2004
Aug 3, 2004
679
if ((width & 15) != 0) {
Feb 6, 2004
Feb 6, 2004
680
681
682
width = (width | 15) +1;
}
May 27, 2007
May 27, 2007
683
684
685
/*--- Verify if asked mode can be used ---*/
if (VDI_bpp != bpp) {
SDL_SetError("%d bpp mode not supported", bpp);
686
687
688
return(NULL);
}
May 27, 2007
May 27, 2007
689
690
691
692
693
694
695
if (flags & SDL_FULLSCREEN) {
if ((VDI_w < width) || (VDI_h < height)) {
SDL_SetError("%dx%d mode is too large", width, height);
return(NULL);
}
}
696
697
698
699
700
701
/*--- 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
702
703
screensize = width * height * VDI_pixelsize;
Feb 6, 2004
Feb 6, 2004
704
705
706
707
#ifdef DEBUG_VIDEO_GEM
printf("sdl:video:gem: setvideomode(): %dx%dx%d = %d\n", width, height, bpp, screensize);
#endif
Nov 12, 2003
Nov 12, 2003
708
/*--- Allocate shadow buffers if needed, and conversion operations ---*/
Aug 9, 2004
Aug 9, 2004
709
710
GEM_FreeBuffers(this);
Nov 12, 2003
Nov 12, 2003
711
712
713
714
715
716
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;
717
718
}
} else {
Nov 12, 2003
Nov 12, 2003
719
720
721
722
723
724
725
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;
}
726
727
}
Nov 12, 2003
Nov 12, 2003
728
729
730
if (use_shadow1) {
GEM_buffer1 = Atari_SysMalloc(screensize, MX_PREFTTRAM);
if (GEM_buffer1==NULL) {
Jul 27, 2005
Jul 27, 2005
731
SDL_SetError("Can not allocate %d KB for frame buffer", screensize>>10);
Nov 12, 2003
Nov 12, 2003
732
733
return NULL;
}
Feb 7, 2006
Feb 7, 2006
734
SDL_memset(GEM_buffer1, 0, screensize);
Nov 12, 2003
Nov 12, 2003
735
736
737
738
#ifdef DEBUG_VIDEO_GEM
printf("sdl:video:gem: setvideomode(): allocated buffer 1\n");
#endif
}
Nov 12, 2003
Nov 12, 2003
740
741
742
if (use_shadow2) {
GEM_buffer2 = Atari_SysMalloc(screensize, MX_PREFTTRAM);
if (GEM_buffer2==NULL) {
Jul 27, 2005
Jul 27, 2005
743
SDL_SetError("Can not allocate %d KB for shadow buffer", screensize>>10);
744
745
return NULL;
}
Feb 7, 2006
Feb 7, 2006
746
SDL_memset(GEM_buffer2, 0, screensize);
Nov 12, 2003
Nov 12, 2003
747
748
749
#ifdef DEBUG_VIDEO_GEM
printf("sdl:video:gem: setvideomode(): allocated buffer 2\n");
#endif
750
751
752
}
/*--- Initialize screen ---*/
Jul 27, 2005
Jul 27, 2005
753
modeflags = SDL_PREALLOC;
Oct 5, 2002
Oct 5, 2002
754
755
756
757
if (VDI_bpp == 8) {
modeflags |= SDL_HWPALETTE;
}
758
if (flags & SDL_FULLSCREEN) {
Mar 26, 2002
Mar 26, 2002
759
GEM_LockScreen(this);
Mar 26, 2002
Mar 26, 2002
761
GEM_ClearScreen(this);
762
763
modeflags |= SDL_FULLSCREEN;
Nov 12, 2003
Nov 12, 2003
764
if (VDI_screen && (VDI_format==VDI_FORMAT_PACK) && !use_shadow1) {
765
766
767
768
modeflags |= SDL_HWSURFACE;
} else {
modeflags |= SDL_SWSURFACE;
}
Aug 10, 2004
Aug 10, 2004
769
770
GEM_fullscreen = SDL_TRUE;
771
} else {
Aug 9, 2004
Aug 9, 2004
772
int old_win_type;
773
774
short x2,y2,w2,h2;
Mar 26, 2002
Mar 26, 2002
775
GEM_UnlockScreen(this);
Aug 5, 2004
Aug 5, 2004
777
/* Set window gadgets */
Aug 9, 2004
Aug 9, 2004
778
old_win_type = GEM_win_type;
779
780
781
782
783
784
785
786
787
788
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;
}
Aug 9, 2004
Aug 9, 2004
789
modeflags |= SDL_SWSURFACE;
Aug 9, 2004
Aug 9, 2004
791
/* Recreate window ? only for different widget or non-created window */
Oct 8, 2004
Oct 8, 2004
792
if ((old_win_type != GEM_win_type) || (GEM_handle < 0)) {
Aug 9, 2004
Aug 9, 2004
793
/* Calculate window size */
Sep 30, 2017
Sep 30, 2017
794
if (!wind_calc(WC_BORDER, GEM_win_type, 0,0,width+16,height, &x2,&y2,&w2,&h2)) {
Aug 9, 2004
Aug 9, 2004
795
796
797
798
GEM_FreeBuffers(this);
SDL_SetError("Can not calculate window attributes");
return NULL;
}
Aug 9, 2004
Aug 9, 2004
800
/* Center window */
May 27, 2007
May 27, 2007
801
802
803
804
805
806
807
808
809
810
x2 = (GEM_desk_w-w2)>>1;
y2 = (GEM_desk_h-h2)>>1;
if (x2<0) {
x2 = 0;
}
if (y2<0) {
y2 = 0;
}
x2 += GEM_desk_x;
y2 += GEM_desk_y;
Aug 5, 2004
Aug 5, 2004
811
Sep 30, 2017
Sep 30, 2017
812
813
/* Align work area on 16 pixels boundary (faster for bitplanes modes) */
wind_calc(WC_WORK, GEM_win_type, x2,y2,w2,h2, &x2,&y2,&w2,&h2);
Oct 6, 2017
Oct 6, 2017
814
x2 &= ~15;
Sep 30, 2017
Sep 30, 2017
815
x2 -= 8;
Sep 30, 2017
Sep 30, 2017
816
817
wind_calc(WC_BORDER, GEM_win_type, x2,y2,w2,h2, &x2,&y2,&w2,&h2);
Aug 9, 2004
Aug 9, 2004
818
819
820
821
822
823
824
825
826
827
828
829
830
/* Destroy existing window */
if (GEM_handle >= 0) {
wind_close(GEM_handle);
wind_delete(GEM_handle);
}
/* Create window */
GEM_handle=wind_create(GEM_win_type, x2,y2,w2,h2);
if (GEM_handle<0) {
GEM_FreeBuffers(this);
SDL_SetError("Can not create window");
return NULL;
}
Nov 12, 2003
Nov 12, 2003
832
#ifdef DEBUG_VIDEO_GEM
Aug 9, 2004
Aug 9, 2004
833
printf("sdl:video:gem: handle=%d\n", GEM_handle);
Nov 12, 2003
Nov 12, 2003
834
835
#endif
Aug 9, 2004
Aug 9, 2004
836
/* Setup window name */
Sep 30, 2017
Sep 30, 2017
837
838
839
840
wind_set(GEM_handle,WF_NAME,
(short)(((unsigned long)GEM_title_name)>>16),
(short)(((unsigned long)GEM_title_name) & 0xffff),
0,0);
Aug 9, 2004
Aug 9, 2004
841
GEM_refresh_name = SDL_FALSE;
Oct 8, 2004
Oct 8, 2004
842
843
844
/* Open the window */
wind_open(GEM_handle,x2,y2,w2,h2);
Oct 6, 2017
Oct 6, 2017
845
846
GEM_iconified = SDL_FALSE;
Jun 2, 2005
Jun 2, 2005
847
} else {
May 26, 2007
May 26, 2007
848
849
/* Resize window to fit asked video mode */
wind_get (GEM_handle, WF_WORKXYWH, &x2,&y2,&w2,&h2);
Sep 30, 2017
Sep 30, 2017
850
if (wind_calc(WC_BORDER, GEM_win_type, x2,y2,width+16,height, &x2,&y2,&w2,&h2)) {
May 26, 2007
May 26, 2007
851
wind_set (GEM_handle, WF_CURRXYWH, x2,y2,w2,h2);
Jun 2, 2005
Jun 2, 2005
852
}
Aug 9, 2004
Aug 9, 2004
853
}
Aug 10, 2004
Aug 10, 2004
854
Oct 6, 2017
Oct 6, 2017
855
GEM_align_work_area(this, GEM_handle, 0);
Aug 10, 2004
Aug 10, 2004
856
GEM_fullscreen = SDL_FALSE;
857
858
859
860
861
}
/* Set up the new mode framebuffer */
current->w = width;
current->h = height;
Nov 12, 2003
Nov 12, 2003
862
863
if (use_shadow1) {
current->pixels = GEM_buffer1;
Feb 6, 2004
Feb 6, 2004
864
current->pitch = width * VDI_pixelsize;
865
866
867
868
869
} else {
current->pixels = VDI_screen;
current->pitch = VDI_pitch;
}
Feb 16, 2006
Feb 16, 2006
870
#if SDL_VIDEO_OPENGL
Nov 21, 2004
Nov 21, 2004
871
if (flags & SDL_OPENGL) {
Nov 25, 2004
Nov 25, 2004
872
if (!SDL_AtariGL_Init(this, current)) {
Nov 21, 2004
Nov 21, 2004
873
GEM_FreeBuffers(this);
Nov 25, 2004
Nov 25, 2004
874
875
SDL_SetError("Can not create OpenGL context");
return NULL;
Nov 21, 2004
Nov 21, 2004
876
877
878
879
880
881
882
883
}
modeflags |= SDL_OPENGL;
}
#endif
current->flags = modeflags;
Feb 6, 2004
Feb 6, 2004
884
885
886
887
#ifdef DEBUG_VIDEO_GEM
printf("sdl:video:gem: surface: %dx%d\n", current->w, current->h);
#endif
888
this->UpdateRects = GEM_UpdateRects;
Nov 6, 2004
Nov 6, 2004
889
GEM_lock_redraw = SDL_FALSE; /* Enable redraw */
890
891
892
893
894
/* We're done */
return(current);
}
Oct 7, 2017
Oct 7, 2017
895
void GEM_align_work_area(_THIS, short windowid, SDL_bool clear_pads)
Sep 30, 2017
Sep 30, 2017
896
{
Oct 7, 2017
Oct 7, 2017
897
int new_x, new_w, old_x, old_w;
Sep 30, 2017
Sep 30, 2017
898
899
wind_get(windowid, WF_WORKXYWH, &GEM_work_x,&GEM_work_y,&GEM_work_w,&GEM_work_h);
Oct 6, 2017
Oct 6, 2017
900
if (GEM_iconified) {
Sep 30, 2017
Sep 30, 2017
901
902
return;
}
Sep 30, 2017
Sep 30, 2017
903
904
/* Align work area on 16 pixels boundary (faster for bitplanes modes) */
Oct 7, 2017
Oct 7, 2017
905
906
new_x = old_x = GEM_work_x;
new_w = old_w = GEM_work_w;
Sep 30, 2017
Sep 30, 2017
907
908
if (new_x & 15) {
new_x = (new_x|15)+1;
Oct 4, 2017
Oct 4, 2017
909
910
} else {
new_w -= 16;
Sep 30, 2017
Sep 30, 2017
911
912
}
new_w -= (new_x - GEM_work_x);
Oct 6, 2017
Oct 6, 2017
913
new_w &= ~15;
Sep 30, 2017
Sep 30, 2017
914
Oct 7, 2017
Oct 7, 2017
915
916
917
GEM_work_x = new_x;
GEM_work_w = new_w;
Sep 30, 2017
Sep 30, 2017
918
if (clear_pads) {
Oct 6, 2017
Oct 6, 2017
919
short rect[4];
Sep 30, 2017
Sep 30, 2017
920
Oct 6, 2017
Oct 6, 2017
921
922
rect[1] = GEM_work_y;
rect[3] = GEM_work_h;
Sep 30, 2017
Sep 30, 2017
923
924
/* Left padding */
Oct 7, 2017
Oct 7, 2017
925
926
927
rect[0] = old_x;
rect[2] = new_x-old_x+1;
GEM_wind_redraw(this, GEM_handle, rect, SDL_TRUE);
Sep 30, 2017
Sep 30, 2017
928
929
/* Right padding */
Oct 6, 2017
Oct 6, 2017
930
rect[0] = new_x + new_w;
Oct 7, 2017
Oct 7, 2017
931
932
rect[2] = (old_w-new_w)-(new_x-old_x)+1;
GEM_wind_redraw(this, GEM_handle, rect, SDL_TRUE);
Sep 30, 2017
Sep 30, 2017
933
934
935
}
}
936
937
938
939
static int GEM_AllocHWSurface(_THIS, SDL_Surface *surface)
{
return -1;
}
Feb 6, 2004
Feb 6, 2004
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
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;
Feb 6, 2004
Feb 6, 2004
959
int i, surf_width;
960
961
surface = this->screen;
Feb 6, 2004
Feb 6, 2004
962
963
/* Need to be a multiple of 16 pixels */
surf_width=surface->w;
Aug 3, 2004
Aug 3, 2004
964
if ((surf_width & 15) != 0) {
Feb 6, 2004
Feb 6, 2004
965
966
surf_width = (surf_width | 15) + 1;
}
Nov 12, 2003
Nov 12, 2003
968
969
970
971
972
if (GEM_bufops & (B2S_C2P_1TO2|B2S_C2P_1TOS)) {
void *destscr;
int destpitch;
if (GEM_bufops & B2S_C2P_1TOS) {
973
destscr = VDI_screen;
Nov 12, 2003
Nov 12, 2003
974
975
976
977
978
destpitch = VDI_pitch;
} else {
destscr = GEM_buffer2;
destpitch = surface->pitch;
}
Nov 12, 2003
Nov 12, 2003
980
981
982
for (i=0;i<numrects;i++) {
void *source,*destination;
int x1,x2;
Mar 26, 2002
Mar 26, 2002
983
Nov 12, 2003
Nov 12, 2003
984
985
986
987
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
988
989
}
Nov 12, 2003
Nov 12, 2003
990
991
992
source = surface->pixels;
source += surface->pitch * rects[i].y;
source += x1;
Nov 12, 2003
Nov 12, 2003
994
995
996
997
998
999
1000
destination = destscr;
destination += destpitch * rects[i].y;
destination += x1;
SDL_Atari_C2pConvert(
source, destination,
x2-x1, rects[i].h,