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