annotate src/video/caca/SDL_cacavideo.c @ 4372:ca91f36ef3de SDL-1.2

1.2 branch: fixed assembly code register clobbering.
author Ryan C. Gordon <icculus@icculus.org>
date Sun, 01 Nov 2009 17:51:39 +0000
parents d1c0ac95d023
children
rev   line source
4315
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 Copyright (C) 2003 Sam Hocevar
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Library General Public
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2 of the License, or (at your option) any later version.
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Library General Public License for more details.
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Library General Public
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Hocevar
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 sam@zoy.org
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23 #ifdef SAVE_RCSID
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 static char rcsid =
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 "@(#) $Id: libsdl-1.2.11-libcaca.patch,v 1.1 2006/09/18 16:06:06 mr_bones_ Exp $";
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 #endif
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 /* libcaca based SDL video driver implementation.
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 */
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 #include <stdlib.h>
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 #include <stdio.h>
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 #include <string.h>
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 #include <unistd.h>
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 #include <sys/stat.h>
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 #include "SDL.h"
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 #include "SDL_error.h"
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 #include "SDL_video.h"
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 #include "SDL_mouse.h"
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 #include "../SDL_sysvideo.h"
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 #include "../SDL_pixels_c.h"
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 #include "../../events/SDL_events_c.h"
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 #include "SDL_cacavideo.h"
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 #include "SDL_cacaevents_c.h"
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 #include <caca.h>
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 #ifdef CACA_API_VERSION_1
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 #include <caca0.h>
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 #endif
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 /* Initialization/Query functions */
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 static int Caca_VideoInit(_THIS, SDL_PixelFormat *vformat);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 static SDL_Rect **Caca_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 static SDL_Surface *Caca_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 static void Caca_VideoQuit(_THIS);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 /* Hardware surface functions */
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 static int Caca_AllocHWSurface(_THIS, SDL_Surface *surface);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 static int Caca_LockHWSurface(_THIS, SDL_Surface *surface);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 static int Caca_FlipHWSurface(_THIS, SDL_Surface *surface);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 static void Caca_UnlockHWSurface(_THIS, SDL_Surface *surface);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 static void Caca_FreeHWSurface(_THIS, SDL_Surface *surface);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 /* Cache the VideoDevice struct */
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 static struct SDL_VideoDevice *local_this;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 /* libcaca driver bootstrap functions */
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 static int Caca_Available(void)
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 {
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 return 1; /* Always available ! */
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 }
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 static void Caca_DeleteDevice(SDL_VideoDevice *device)
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 {
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 free(device->hidden);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 free(device);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 }
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 static SDL_VideoDevice *Caca_CreateDevice(int devindex)
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 {
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 SDL_VideoDevice *device;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 /* Initialize all variables that we clean on shutdown */
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 if ( device ) {
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 memset(device, 0, (sizeof *device));
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 device->hidden = (struct SDL_PrivateVideoData *)
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 malloc((sizeof *device->hidden));
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 }
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 if ( (device == NULL) || (device->hidden == NULL) ) {
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 SDL_OutOfMemory();
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 if ( device ) {
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 free(device);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 }
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 return(0);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 }
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 memset(device->hidden, 0, (sizeof *device->hidden));
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 /* Set the function pointers */
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103 device->VideoInit = Caca_VideoInit;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 device->ListModes = Caca_ListModes;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 device->SetVideoMode = Caca_SetVideoMode;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 device->CreateYUVOverlay = NULL;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 device->SetColors = NULL;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 device->UpdateRects = NULL;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 device->VideoQuit = Caca_VideoQuit;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 device->AllocHWSurface = Caca_AllocHWSurface;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 device->CheckHWBlit = NULL;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 device->FillHWRect = NULL;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 device->SetHWColorKey = NULL;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 device->SetHWAlpha = NULL;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115 device->LockHWSurface = Caca_LockHWSurface;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 device->UnlockHWSurface = Caca_UnlockHWSurface;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 device->FlipHWSurface = NULL;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 device->FreeHWSurface = Caca_FreeHWSurface;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 device->SetCaption = NULL;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 device->SetIcon = NULL;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 device->IconifyWindow = NULL;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 device->GrabInput = NULL;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 device->GetWMInfo = NULL;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 device->InitOSKeymap = Caca_InitOSKeymap;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 device->PumpEvents = Caca_PumpEvents;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 device->free = Caca_DeleteDevice;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 return device;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 }
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 VideoBootStrap CACA_bootstrap = {
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 "caca", "Color ASCII Art Library",
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 Caca_Available, Caca_CreateDevice
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 };
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 int Caca_VideoInit(_THIS, SDL_PixelFormat *vformat)
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 {
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 int i;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 /* Initialize all variables that we clean on shutdown */
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 for ( i=0; i<SDL_NUMMODES; ++i ) {
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 SDL_modelist[i] = malloc(sizeof(SDL_Rect));
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144 SDL_modelist[i]->x = SDL_modelist[i]->y = 0;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 }
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146 /* Modes sorted largest to smallest */
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 SDL_modelist[0]->w = 1024; SDL_modelist[0]->h = 768;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 SDL_modelist[1]->w = 800; SDL_modelist[1]->h = 600;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 SDL_modelist[2]->w = 640; SDL_modelist[2]->h = 480;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 SDL_modelist[3]->w = 320; SDL_modelist[3]->h = 400;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 SDL_modelist[4]->w = 320; SDL_modelist[4]->h = 240;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 SDL_modelist[5]->w = 320; SDL_modelist[5]->h = 200;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 SDL_modelist[6] = NULL;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155 Caca_mutex = SDL_CreateMutex();
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 /* Initialize the library */
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 if ( caca_init() != 0 ) {
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 SDL_SetError("Unable to initialize libcaca");
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 return(-1);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 }
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 /* Initialize private variables */
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 Caca_lastkey = 0;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 Caca_bitmap = NULL;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166 Caca_buffer = NULL;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 local_this = this;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 /* Determine the screen depth (use default 8-bit depth) */
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 vformat->BitsPerPixel = 8;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 vformat->BytesPerPixel = 1;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 /* We're done! */
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 return(0);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 }
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 SDL_Rect **Caca_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 {
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 if(format->BitsPerPixel != 8)
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 return NULL;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 if ( flags & SDL_FULLSCREEN ) {
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 return SDL_modelist;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 } else {
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 return (SDL_Rect **) -1;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 }
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188 }
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 /* Various screen update functions available */
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 static void Caca_DirectUpdate(_THIS, int numrects, SDL_Rect *rects);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 SDL_Surface *Caca_SetVideoMode(_THIS, SDL_Surface *current,
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194 int width, int height, int bpp, Uint32 flags)
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195 {
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 if ( Caca_buffer ) {
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 free( Caca_buffer );
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 Caca_buffer = NULL;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 }
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 if ( Caca_bitmap ) {
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202 caca_free_bitmap( Caca_bitmap );
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 Caca_bitmap = NULL;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 }
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 Caca_buffer = malloc(2 * ((width + 15) & ~15) * height);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 if ( ! Caca_buffer ) {
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208 SDL_SetError("Couldn't allocate buffer for requested mode");
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209 return(NULL);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 }
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 memset(Caca_buffer, 0, 2 * ((width + 15) & ~15) * height);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214 /* Allocate the new pixel format for the screen */
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 if ( ! SDL_ReallocFormat(current, 16, 0xf800, 0x07e0, 0x001f, 0) ) {
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216 return(NULL);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217 }
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219 /* Set up the new mode framebuffer */
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
220 current->flags = SDL_FULLSCREEN;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221 Caca_w = current->w = width;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 Caca_h = current->h = height;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
223 current->pitch = 2 * ((width + 15) & ~15);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224 current->pixels = Caca_buffer;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226 /* Create the libcaca bitmap */
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227 Caca_bitmap = caca_create_bitmap( 16, width, height, current->pitch, 0xf800, 0x07e0, 0x001f, 0x0000 );
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228 if ( ! Caca_bitmap ) {
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
229 SDL_SetError("Couldn't allocate libcaca bitmap");
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230 return(NULL);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231 }
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233 /* Set the blit function */
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 this->UpdateRects = Caca_DirectUpdate;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
235
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
236 /* We're done */
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
237 return(current);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
238 }
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
239
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
240 /* We don't actually allow hardware surfaces other than the main one */
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241 static int Caca_AllocHWSurface(_THIS, SDL_Surface *surface)
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242 {
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243 return(-1);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
244 }
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245 static void Caca_FreeHWSurface(_THIS, SDL_Surface *surface)
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
246 {
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
247 return;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
248 }
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
250 /* We need to wait for vertical retrace on page flipped displays */
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
251 static int Caca_LockHWSurface(_THIS, SDL_Surface *surface)
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
252 {
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
253 /* TODO ? */
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
254 return(0);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
255 }
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
256 static void Caca_UnlockHWSurface(_THIS, SDL_Surface *surface)
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
257 {
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
258 return;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259 }
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
261 /* FIXME: How is this done with libcaca? */
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
262 static int Caca_FlipHWSurface(_THIS, SDL_Surface *surface)
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
263 {
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
264 SDL_mutexP(Caca_mutex);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265 caca_refresh();
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
266 SDL_mutexV(Caca_mutex);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267 return(0);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268 }
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 static void Caca_DirectUpdate(_THIS, int numrects, SDL_Rect *rects)
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
271 {
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
272 SDL_mutexP(Caca_mutex);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
273 caca_draw_bitmap( 0, 0, caca_get_width() - 1, caca_get_height() - 1,
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
274 Caca_bitmap, Caca_buffer );
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
275 caca_refresh();
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
276 SDL_mutexV(Caca_mutex);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
277 return;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
278 }
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
279
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
280 /* Note: If we are terminated, this could be called in the middle of
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
281 another SDL video routine -- notably UpdateRects.
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
282 */
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
283 void Caca_VideoQuit(_THIS)
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
284 {
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
285 int i;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
286
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
287 /* Free video mode lists */
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
288 for ( i=0; i<SDL_NUMMODES; ++i ) {
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
289 if ( SDL_modelist[i] != NULL ) {
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
290 free(SDL_modelist[i]);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
291 SDL_modelist[i] = NULL;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
292 }
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
293 }
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
294
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
295 if ( Caca_bitmap ) {
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
296 caca_free_bitmap( Caca_bitmap );
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
297 Caca_bitmap = NULL;
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
298 }
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
299
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
300 caca_end();
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
301
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
302 SDL_DestroyMutex(Caca_mutex);
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
303 }
d1c0ac95d023 Added missing caca files
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
304