1 /*
2  * sdl_video.c  SDL video init
3  *
4  * Copyright (C) 2000-     Fumihiko Murata       <fmurata@p1.tcnet.ne.jp>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20 */
21 /* $Id: sdl_video.c,v 1.11 2003/01/04 17:01:02 chikama Exp $ */
22 
23 #include "config.h"
24 
25 #include <stdio.h>
26 #include <SDL/SDL.h>
27 #include <glib.h>
28 
29 #include "portab.h"
30 #include "system.h"
31 #include "sdl_core.h"
32 #include "sdl_private.h"
33 #include "xsystem35.h"
34 #include "font.h"
35 #include "joystick.h"
36 #include "image.h"
37 
38 static void window_init(void);
39 static void makeDIB(int width, int height, int depth);
40 
41 struct sdl_private_data *sdl_videodev;
42 
43 boolean RawKeyInfo[256];
44 
45 
46 /* SDL �ν���� */
sdl_Initilize(void)47 int sdl_Initilize(void) {
48 	sdl_videodev = g_new0(struct sdl_private_data, 1);
49 
50 	/* make topleve window */
51 	window_init();
52 
53 	/* offscreen Pixmap */
54 	makeDIB(SYS35_DEFAULT_WIDTH, SYS35_DEFAULT_HEIGHT, SYS35_DEFAULT_DEPTH);
55 
56 	/* title */
57 	SDL_WM_SetCaption("XSystem3.5 Version "VERSION, NULL);
58 
59 	/* init cursor */
60 	sdl_cursor_init();
61 
62 	sdl_vm_init();
63 
64 	memset(RawKeyInfo, 0, sizeof(RawKeyInfo));
65 
66 	sdl_setWindowSize(0, 0, SYS35_DEFAULT_WIDTH, SYS35_DEFAULT_HEIGHT);
67 
68 	sdl_shadow_init();
69 
70 	joy_open();
71 	return 0;
72 }
73 
sdl_Remove(void)74 void sdl_Remove(void) {
75 	if (sdl_videodev == NULL) return;
76 
77 	if (sdl_display) {
78 		NOTICE("Now SDL shutdown ... ");
79 
80 		SDL_FreeSurface(sdl_dib);
81 
82 		joy_close();
83 
84 		SDL_Quit();
85 
86 		NOTICE("Done!\n");
87 	}
88 }
89 
90 /* name is EUC */
sdl_setWindowTitle(char * name)91 void sdl_setWindowTitle(char *name) {
92 	SDL_WM_SetCaption(name, NULL);
93 }
94 
95 /* Visual �˱����� Window ���������� */
window_init(void)96 static void window_init(void) {
97 	char s[256];
98 
99 	SDL_Init(SDL_INIT_VIDEO
100 #ifdef HAVE_SDLJOY
101 		 |SDL_INIT_JOYSTICK
102 #endif
103 		);
104 
105 	sdl_vinfo = SDL_GetVideoInfo();
106 
107 	SDL_VideoDriverName(s, 256);
108 
109 	NOTICE("Video Info %s\n", s);
110 	NOTICE("  hw_available %d\n", sdl_vinfo->hw_available);
111 	NOTICE("  wm_available %d\n", sdl_vinfo->wm_available);
112 	NOTICE("  Accelerated blits HW --> HW %d\n", sdl_vinfo->blit_hw);
113 	NOTICE("  Accelerated blits with Colorkey %d\n", sdl_vinfo->blit_hw_CC);
114 	NOTICE("  Accelerated blits with Alpha %d\n", sdl_vinfo->blit_hw_A);
115 	NOTICE("  Accelerated blits SW --> HW %d\n", sdl_vinfo->blit_sw);
116 	NOTICE("  Accelerated blits with Colorkey %d\n", sdl_vinfo->blit_sw_CC);
117 	NOTICE("  Accelerated blits with Alpha %d\n", sdl_vinfo->blit_sw_A);
118 	NOTICE("  Accelerated color fill %d\n", sdl_vinfo->blit_fill);
119 	NOTICE("  The total amount of video memory %dK\n", sdl_vinfo->video_mem);
120 	NOTICE("    BitsPerPixel %d\n", sdl_vinfo->vfmt->BitsPerPixel);
121 	NOTICE("    R %04x G %04x B %04x A %04x\n",
122 	       sdl_vinfo->vfmt->Rmask, sdl_vinfo->vfmt->Gmask,
123 	       sdl_vinfo->vfmt->Bmask, sdl_vinfo->vfmt->Amask);
124 
125 	sdl_vflag = SDL_HWSURFACE | SDL_ANYFORMAT;
126 
127 	sdl_display = SDL_SetVideoMode(SYS35_DEFAULT_WIDTH, SYS35_DEFAULT_HEIGHT,
128 				       sdl_vinfo->vfmt->BitsPerPixel, sdl_vflag);
129 
130 	NOTICE("Dsp_depth %d flag %x\n",
131 	       sdl_display->format->BitsPerPixel, sdl_display->flags);
132 }
133 
makeDIB(int width,int height,int depth)134 static void makeDIB(int width, int height, int depth) {
135 
136 	if (sdl_display->format->BitsPerPixel == 8 && depth != 8) {
137 		SYSERROR("You cannot play highcolor game in 256 color mode\n");
138 	}
139 
140 	if (depth == 24) {
141 		WARNING("SDL warning: if you are using SDL version 1.1.x (x<=3) and someting is wrong with graphics, please use version 1.1.4 or later\n");
142 	}
143 
144 	if (sdl_dib) {
145 		SDL_FreeSurface(sdl_dib);
146 	}
147 
148 	if (depth == 8) {
149 		if (sdl_display->format->BitsPerPixel == depth) {
150 			sdl_dib = SDL_AllocSurface(SDL_SWSURFACE, width, height,
151 						   depth, 0, 0, 0, 0);
152 		} else {
153 			sdl_dib = SDL_AllocSurface(SDL_HWSURFACE, width, height,
154 						   depth, 0, 0, 0, 0);
155 		}
156 	} else {
157 		sdl_dib = SDL_AllocSurface(SDL_HWSURFACE, width, height,
158 					   sdl_display->format->BitsPerPixel, 0, 0, 0, 0);
159 	}
160 
161 #if 0
162 	if (sdl_dib->format->BitsPerPixel == 8) {
163 		memset(sdl_dib->format->palette->colors, 0, sizeof(SDL_Color)*256);
164 	}
165 #endif
166 
167 #if 0
168 	printf("DIB depth %d\n", sdl_dib->format->BitsPerPixel);
169 	printf("  R %04x G %04x B %04x A %04x\n",
170 	       sdl_dib->format->Rmask, sdl_dib->format->Gmask,
171 	       sdl_dib->format->Bmask, sdl_dib->format->Amask);
172 #endif
173 	if (depth > 8) {
174 		sdl_white = (sdl_dib->format->Rmask | sdl_dib->format->Gmask | sdl_dib->format->Bmask);
175 	}
176 
177 	if (sdl_dibinfo) {
178 		g_free(sdl_dibinfo);
179 	}
180 
181 	sdl_dibinfo = g_new0(agsurface_t, 1);
182 	sdl_dibinfo->depth           = sdl_dib->format->BitsPerPixel;
183 	sdl_dibinfo->bytes_per_pixel = sdl_dib->format->BytesPerPixel;
184 	sdl_dibinfo->bytes_per_line  = sdl_dib->pitch;
185 	sdl_dibinfo->pixel  = sdl_dib->pixels;
186 	sdl_dibinfo->width  = width;
187 	sdl_dibinfo->height = height;
188 	sdl_dibinfo->alpha  = NULL;
189 
190 	image_setdepth(sdl_dibinfo->depth);
191 }
192 
sdl_setFontDevice(FONT * f)193 void sdl_setFontDevice(FONT *f) {
194         sdl_font = f;
195 }
196 
197 /* offscreen ������ */
sdl_setWorldSize(int width,int height,int depth)198 void sdl_setWorldSize(int width, int height, int depth) {
199 	makeDIB(width, height, depth);
200 	SDL_FillRect(sdl_dib, NULL, 0);
201 }
202 
203 /* Window�� size �� depth �μ��� */
sdl_getWindowInfo(DispInfo * info)204 void sdl_getWindowInfo(DispInfo *info) {
205 	info->width  = sdl_display->w;
206 	info->height = sdl_display->h;
207 	info->depth  = sdl_display->format->BitsPerPixel;
208 }
209 
210 /*  DIB�μ��� */
sdl_getDIB(void)211 agsurface_t *sdl_getDIB(void) {
212 	return sdl_dibinfo;
213 }
214 
215