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 (message_delay)
54    draw_sprite(XBuf,OSD_MESSAGE_SPR,screen_blit_x + 8,min(io.screen_h,vheight)-16);
55 
56  blit(XBuf,screen,screen_blit_x,screen_blit_y,blit_x,blit_y - 8,io.screen_w,io.screen_h);
57 
58 }
59 
60 /*****************************************************************************
61 
62     Function: osd_gfx_put_image_scanline
63 
64     Description: draw the raw computed picture to the screen using a 50% scanline algo
65     Parameters: none
66     Return: nothing
67     Remark: Adapted from Vlendr'it 's code
68 *****************************************************************************/
osd_gfx_put_image_scanline(void)69 void osd_gfx_put_image_scanline(void)
70 {
71  int dum;
72  int i,y = 0;
73 
74  BITMAP *temp = create_bitmap(io.screen_w * 2, io.screen_h * 2);
75 
76  if (message_delay)
77    draw_sprite(XBuf,OSD_MESSAGE_SPR,screen_blit_x+8,min(io.screen_h,vheight)-16);
78 
79    clear(temp);
80 
81    for(i = 0; i < io.screen_h; i++)
82    {
83       stretch_blit(XBuf, temp, screen_blit_x - 8, i, io.screen_w, 1, 0, y, io.screen_w << 1, 1);
84       y += 2;
85    }
86 
87    /* blit the bitmap onto the screen */
88 
89    blit(temp, screen, 0, 0, blit_x ,
90              blit_y, temp->w, temp->h);
91    destroy_bitmap(temp);
92 
93  }
94 
95 /*****************************************************************************
96 
97     Function: osd_gfx_put_image_eagle
98 
99     Description: draw the raw computed image on screen using the eagle lib
100     Parameters: none
101     Return: nothing
102 
103 *****************************************************************************/
osd_gfx_put_image_eagle(void)104 void osd_gfx_put_image_eagle(void)
105 {
106  int dum;
107 
108  if (message_delay)
109    draw_sprite(XBuf,OSD_MESSAGE_SPR,screen_blit_x+8,min(io.screen_h,vheight)-16);
110 
111      for (dum=0;dum<io.screen_h-1;dum++)
112     {
113       // Eagle-blit piccy to the screen
114       eagle (
115              (unsigned long*)(XBuf->line[dum]+screen_blit_x - 8)                  // First line of piccy  (320 pixels)
116             ,(unsigned long*)(XBuf->line[dum+1]+screen_blit_x - 8)              // 2nd line of piccy (320 pixels)
117             ,io.screen_w
118             ,EAGLE_buf->seg
119             ,(int)EAGLE_buf->line[dum*2] //  + ( ( (x   <<1) * piccy->w ) << 1)           // First eagled line = 320x2 = 640 pixels
120             ,(int)EAGLE_buf->line[1+(dum*2)] // + (( ( (x+1)<<1) * piccy->w ) << 1)       // 2nd eagled line = 320x2 = 640 pixels
121            );
122     }
123 
124     blit(EAGLE_buf,screen,0,0,blit_x,blit_y,io.screen_w<<1,(io.screen_h-1)<<1);
125 
126  }
127 
128 
129 /*****************************************************************************
130 
131     Function: osd_gfx_set_message
132 
133     Description: compute the message that will be displayed to create a sprite
134        to blit on screen
135     Parameters: char* mess, the message to display
136     Return: nothing but set OSD_MESSAGE_SPR
137 
138 *****************************************************************************/
osd_gfx_set_message(char * mess)139 void osd_gfx_set_message(char* mess)
140 {
141 
142  if (OSD_MESSAGE_SPR)
143    destroy_bitmap(OSD_MESSAGE_SPR);
144 
145  OSD_MESSAGE_SPR=create_bitmap(text_length(font,mess)+1,text_height(font)+1);
146  clear(OSD_MESSAGE_SPR);
147  textout(OSD_MESSAGE_SPR,font,mess,1,1,3);
148  textout(OSD_MESSAGE_SPR,font,mess,0,0,255);
149  return;
150 
151  }
152 
153 /*****************************************************************************
154 
155     Function:  osd_gfx_init_normal_mode
156 
157     Description: initialize the classic 256*224 video mode for normal video_driver
158     Parameters: none
159     Return: 0 on error
160             1 on success
161 
162 *****************************************************************************/
osd_gfx_init_normal_mode()163 int osd_gfx_init_normal_mode()
164 {
165   if (vmode==5)
166     return !osd_gfx_set_hugo_mode(GFX_AUTODETECT,800,600);
167 
168   if (io.screen_w==40*8)
169     {
170       if (!osd_gfx_set_hugo_mode(GFX_AUTODETECT,320,240))
171         return 1;
172     }
173 
174   if (io.screen_w>40*8)
175     {
176       if (!osd_gfx_set_hugo_mode(GFX_AUTODETECT,360,240))
177         return 1;
178     }
179 
180   if ((vmode==0) && (!osd_gfx_set_hugo_mode(GFX_SAFE,256,224)));
181    else
182   if ((vmode<=1) && (!osd_gfx_set_hugo_mode(GFX_AUTODETECT,256,240)));
183    else
184   if ((vmode<=2) && (!osd_gfx_set_hugo_mode(GFX_AUTODETECT,256,256)));
185    else
186   if ((vmode<=3) && (!osd_gfx_set_hugo_mode(GFX_AUTODETECT,320,240)));
187    else
188   if ((vmode<=4) && (!osd_gfx_set_hugo_mode(GFX_AUTODETECT,320,200)));
189    else
190           return 0;
191 
192  return 1;
193  }
194 
195 /*****************************************************************************
196 
197     Function: osd_gfx_init_scanline_mode
198 
199     Description: Initialize screen for use with the scanline displaying
200     Parameters: none
201     Return: nothing
202 
203 *****************************************************************************/
osd_gfx_init_scanline_mode(void)204 int osd_gfx_init_scanline_mode(void)
205 {
206   if (!(set_gfx_mode(GFX_AUTODETECT,640,480,0,0)))
207             {
208              vwidth=640;
209              vheight=480;
210              blit_x=(320-io.screen_w);
211              blit_y=(240-io.screen_h);
212              screen_blit_x=(WIDTH-io.screen_h)/2;
213              screen_blit_y=(HEIGHT-io.screen_w)/2;
214 
215              SetPalette();
216              return 1;
217              }
218   return 0;
219  }
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 *****************************************************************************/
osd_gfx_init_eagle_mode(void)232 int osd_gfx_init_eagle_mode(void)
233 {
234   if (!(set_gfx_mode(GFX_AUTODETECT,640,480,0,0)))
235             {
236              vwidth=640;
237              vheight=480;
238              blit_x=(320-io.screen_w);
239              blit_y=(240-io.screen_h) + 1;
240              screen_blit_x=(WIDTH-io.screen_h)/2;
241              screen_blit_y=(HEIGHT-io.screen_w)/2;
242 
243              SetPalette();
244              return 1;
245              }
246   return 0;
247 
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 */ GFX_DIRECTX_WIN ,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