1 #include "osd_gfx.h"
2
3 /* TEST, to handle allegro wip errors .. */
4 #define GFX_SVGALIB AL_ID('S','V','G','A')
5
6 BITMAP* OSD_MESSAGE_SPR = NULL;
7
8 int blit_x,blit_y;
9 // where must we blit the screen buffer on screen
10
11 int screen_blit_x, screen_blit_y;
12 // where on the screen we must blit XBuf
13
14 BITMAP *EAGLE_buf=NULL;
15 // the buffer where we will put eagleized video
16
17 int osd_gfx_init_normal_mode();
18 void osd_gfx_put_image_normal();
19
20 int osd_gfx_init_eagle_mode();
21 void osd_gfx_put_image_eagle();
22
23 int osd_gfx_init_scanline_mode();
24 void osd_gfx_put_image_scanline();
25
26 void osd_gfx_dummy_func();
27
28 osd_gfx_driver osd_gfx_driver_list[3] =
29 {
30 {osd_gfx_init_normal_mode, osd_gfx_put_image_normal, osd_gfx_dummy_func},
31 {osd_gfx_init_eagle_mode, osd_gfx_put_image_eagle, osd_gfx_dummy_func},
32 {osd_gfx_init_scanline_mode, osd_gfx_put_image_scanline, osd_gfx_dummy_func}
33 };
34
osd_gfx_dummy_func(void)35 void osd_gfx_dummy_func(void)
36 {
37 return;
38 }
39
40 /*****************************************************************************
41
42 Function: osd_gfx_put_image_normal
43
44 Description: draw the raw computed picture to screen, without any effect
45 trying to center it (I bet there is still some work on this, maybe not
46 in this function)
47 Parameters: none
48 Return: nothing
49
50 *****************************************************************************/
osd_gfx_put_image_normal(void)51 void osd_gfx_put_image_normal(void)
52 {
53
54 int dum;
55
56 if (message_delay)
57 draw_sprite(XBuf,OSD_MESSAGE_SPR,screen_blit_x + 8,min(io.screen_h,vheight)-16);
58
59 blit(XBuf,screen,screen_blit_x,screen_blit_y,blit_x,blit_y - 8,io.screen_w,io.screen_h);
60
61 }/*****************************************************************************
62
63 Function: osd_gfx_put_image_scanline
64
65 Description: draw the raw computed picture to the screen using a 50% scanline algo
66 Parameters: none
67 Return: nothing
68 Remark: Adapted from Vlendr'it 's code
69 *****************************************************************************/
osd_gfx_put_image_scanline(void)70 void osd_gfx_put_image_scanline(void)
71 {
72 int dum;
73 int i,y = 0;
74
75 BITMAP *temp = create_bitmap((io.screen_w << 1), (io.screen_h << 1));
76
77 if (message_delay)
78 draw_sprite(XBuf,OSD_MESSAGE_SPR,screen_blit_x+8,min(io.screen_h,vheight)-16);
79
80 clear(temp);
81
82 for(i = 0; i < io.screen_h; i++)
83 {
84 stretch_blit(XBuf, temp, screen_blit_x - 8, i, io.screen_w, 1, 0, y, io.screen_w << 1, 1);
85 y += 2;
86 }
87
88 /* blit the bitmap onto the screen */
89
90 blit(temp, screen, 0, 0, blit_x ,
91 blit_y, temp->w, temp->h);
92 destroy_bitmap(temp);
93
94 }
95
96 /*****************************************************************************
97
98 Function: osd_gfx_put_image_eagle
99
100 Description: draw the raw computed image on screen using the eagle lib
101 Parameters: none
102 Return: nothing
103
104 *****************************************************************************/
105
osd_gfx_put_image_eagle(void)106 void osd_gfx_put_image_eagle(void)
107 {
108 int dum;
109
110 if (message_delay)
111 draw_sprite(XBuf,OSD_MESSAGE_SPR,screen_blit_x+8,min(io.screen_h,vheight)-16);
112
113 for (dum=0;dum<io.screen_h-1;dum++)
114 {
115 // Eagle-blit piccy to the screen
116 _eagle (
117 (unsigned long*)(XBuf->line[dum]+screen_blit_x - 8) // First line of piccy (320 pixels)
118 ,(unsigned long*)(XBuf->line[dum+1]+screen_blit_x - 8) // 2nd line of piccy (320 pixels)
119 ,io.screen_w
120 ,EAGLE_buf->seg
121 ,(int)EAGLE_buf->line[dum<<1] // + ( ( (x <<1) * piccy->w ) << 1) // First eagled line = 320x2 = 640 pixels
122 ,(int)EAGLE_buf->line[1+(dum<<1)] // + (( ( (x+1)<<1) * piccy->w ) << 1) // 2nd eagled line = 320x2 = 640 pixels
123 );
124 }
125
126 blit(EAGLE_buf,screen,0,0,blit_x,blit_y,io.screen_w<<1,(io.screen_h-1)<<1);
127
128 }
129
130 /*****************************************************************************
131
132 Function: osd_gfx_set_message
133
134 Description: compute the message that will be displayed to create a sprite
135 to blit on screen
136 Parameters: char* mess, the message to display
137 Return: nothing but set OSD_MESSAGE_SPR
138
139 *****************************************************************************/
osd_gfx_set_message(char * mess)140 void osd_gfx_set_message(char* mess)
141 {
142
143 if (OSD_MESSAGE_SPR)
144 destroy_bitmap(OSD_MESSAGE_SPR);
145
146 OSD_MESSAGE_SPR=create_bitmap(text_length(font,mess)+1,text_height(font)+1);
147 clear(OSD_MESSAGE_SPR);
148 textout(OSD_MESSAGE_SPR,font,mess,1,1,3);
149 textout(OSD_MESSAGE_SPR,font,mess,0,0,255);
150 return;
151
152 }
153
154 /*****************************************************************************
155
156 Function: osd_gfx_init_normal_mode
157
158 Description: initialize the classic 256*224 video mode for normal video_driver
159 Parameters: none
160 Return: 0 on error
161 1 on success
162
163 *****************************************************************************/
osd_gfx_init_normal_mode()164 int osd_gfx_init_normal_mode()
165 {
166 if (vmode==5)
167 return !osd_gfx_set_hugo_mode(GFX_SVGALIB,800,600);
168
169 if (io.screen_w==40*8)
170 {
171 if (!osd_gfx_set_hugo_mode(GFX_SVGALIB,320,240))
172 return 1;
173 }
174
175 if (io.screen_w>40*8)
176 {
177 if (!osd_gfx_set_hugo_mode(GFX_SVGALIB,360,240))
178 return 1;
179 }
180
181 if ((vmode==0) && (!osd_gfx_set_hugo_mode(GFX_VGA,256,224)));
182 else
183 if ((vmode<=1) && (!osd_gfx_set_hugo_mode(GFX_SVGALIB,256,240)));
184 else
185 if ((vmode<=2) && (!osd_gfx_set_hugo_mode(GFX_SVGALIB,256,256)));
186 else
187 if ((vmode<=3) && (!osd_gfx_set_hugo_mode(GFX_SVGALIB,320,240)));
188 else
189 if ((vmode<=4) && (!osd_gfx_set_hugo_mode(GFX_SVGALIB,320,200)));
190 else
191 return 0;
192
193 return 1;
194 }
195
196 /*****************************************************************************
197
198 Function: osd_gfx_init_scanline_mode
199
200 Description: Initialize screen for use with the scanline displaying
201 Parameters: none
202 Return: nothing
203
204 *****************************************************************************/
osd_gfx_init_scanline_mode(void)205 int osd_gfx_init_scanline_mode(void)
206 {
207 if (!(set_gfx_mode(GFX_SVGALIB,640,480,0,0)))
208 {
209 vwidth=640;
210 vheight=480;
211 blit_x=(320-io.screen_w);
212 blit_y=(240-io.screen_h);
213 screen_blit_x=((WIDTH-io.screen_h) >> 1);
214 screen_blit_y=((HEIGHT-io.screen_w) >> 1);
215
216 SetPalette();
217 return 1;
218 }
219 return 0;
220 }
221
222 /*****************************************************************************
223
224 Function: osd_gfx_init_eagle_mode
225
226 Description: Initialize the screen for use with eagle displaying (i.e. 640x480x8)
227 Parameters: none
228 Return: 1 on success
229 0 on error
230
231 *****************************************************************************/
232
osd_gfx_init_eagle_mode(void)233 int osd_gfx_init_eagle_mode(void)
234 {
235 if (!(set_gfx_mode(GFX_SVGALIB,640,480,0,0)))
236 {
237 vwidth=640;
238 vheight=480;
239 blit_x=(320-io.screen_w);
240 blit_y=(240-io.screen_h) + 1;
241 screen_blit_x=((WIDTH-io.screen_h) >> 1);
242 screen_blit_y=((HEIGHT-io.screen_w) >> 1);
243
244 SetPalette();
245 return 1;
246 }
247 return 0;
248
249 }
250
251 /*****************************************************************************
252
253 Function: osd_gfx_savepict
254
255 Description: save a picture in the current directory
256 Parameters: none
257 Return: the numeric part of the created filename, 0xFFFF meaning that no more
258 names were available
259
260 *****************************************************************************/
osd_gfx_savepict()261 UInt16 osd_gfx_savepict()
262 {
263 BITMAP *bmp;
264 PALETTE pal;
265 char* final="PICT0000.PCX";
266 short unsigned tmp=0;
267
268 while ((tmp!=0xFFFF) && (exists(final)))
269 sprintf(final,"PICT%04X.PCX",++tmp);
270 if (tmp==0xFFFF)
271 return tmp;
272
273 get_palette(pal);
274
275 if ((use_eagle) || (use_scanline))
276 bmp = create_sub_bitmap(screen,
277 blit_x,
278 blit_y,
279 io.screen_w * 2,
280 io.screen_h * 2);
281 else
282 bmp = create_sub_bitmap(screen,
283 blit_x,
284 blit_y,
285 io.screen_w,
286 io.screen_h);
287
288 save_bitmap(final, bmp, pal);
289
290 destroy_bitmap(bmp);
291
292 return tmp;
293 }
294
295 /*****************************************************************************
296
297 Function: osd_gfx_set_hugo_mode
298
299 Description: change the video mode
300 Parameters: mode : mode of video screen
301 width, height : minimum size of screen required
302 Return: 0 on success
303 1 on error
304
305 *****************************************************************************/
osd_gfx_set_hugo_mode(SInt32 mode,SInt32 width,SInt32 height)306 SInt32 osd_gfx_set_hugo_mode(SInt32 mode,SInt32 width,SInt32 height)
307 {
308
309 if (!set_gfx_mode(mode,width,height,0,0))
310 {
311 Log("Changing video mode to %dx%d\nPCE screen size is %dx%d\n",
312 width,
313 height,
314 io.screen_w,
315 io.screen_h);
316 vwidth=width;
317 vheight=height;
318
319 blit_x=(width-io.screen_w)/2;
320 blit_y=(height-io.screen_h)/2;
321
322 screen_blit_x=(WIDTH-io.screen_w)/2;
323 screen_blit_y=(224-io.screen_h)/2;
324
325 Log("Now blit_x = %d\nblit_y = %d\nscreen_blit_x = %d\nscreen_blit_y = %d\n\n",
326 blit_x,
327 blit_y,
328 screen_blit_x,
329 screen_blit_y);
330
331 SetPalette();
332 return 0;
333 }
334 return 1;
335 }
336
337 /*****************************************************************************
338
339 Function: osd_gfx_set_color
340
341 Description: Change the component of the choosen color
342 Parameters: UChar index : index of the color to change
343 UChar r : new red component of the color
344 UChar g : new green component of the color
345 UChar b : new blue component of the color
346 Return:
347
348 *****************************************************************************/
osd_gfx_set_color(UChar index,UChar r,UChar g,UChar b)349 void osd_gfx_set_color(UChar index,
350 UChar r,
351 UChar g,
352 UChar b)
353 {
354
355 RGB R;
356 R.r=r;
357 R.g=g;
358 R.b=b;
359
360 set_color(index, &R);
361
362 }
363