1 #include "osd_machine.h"
2 UChar* osd_gfx_buffer = NULL;
3 
4 UChar gamepad = 0;
5 // gamepad detected ?
6 
7 BITMAP *XBuf;
8 // The screen buffer where we draw before blitting it on screen
9 
10 int gamepad_driver = 0;
11 // what kind of jypad must we have to handle
12 
13 char dump_snd = 0;
14 // Do we write sound to file
15 
16 char synchro;
17 // � fond, � fond, � fond? (french joke ;)
18 
19 int vwidth, vheight;
20 // size of visible part of the screen (I got troubles with allegro screen->* values!)
21 
22 int vmode = 0;
23 // video mode to use
24 // 1 -> first 224*240 then 256*240 then 256*256 then 320*240 and 320*200
25 // 2 -> first 256*240 then 256*256 then 320*240 and 320*200
26 // 3 -> first 256*256 then 320*240 and 320*200
27 // 4 -> first 320*240 and 320*200
28 // 5 -> only try 320*200
29 // 6 -> only 800*600
30 // If you think others modes would be interesting, let me know
31 
osd_init_machine()32 int osd_init_machine()
33 {
34 
35   int result;
36 
37   Log ("\n--[ INITIALISE MACHINE ]--------------------------\n");
38   check_cpu ();
39   if (cpu_cpuid)
40     Log ("Following cpu info are exact\n");
41   else
42     Log ("Following cpu info may be inaccurate\n");
43 
44   Log ("Machine is a %d56, sub model : %d\n", cpu_family, cpu_model);
45 
46   if (cpu_fpu)
47     Log ("Machine got a fpu\n");
48   else
49     Log ("No fpu available\n");
50 
51   if (cpu_mmx)
52     Log ("Machine got a MMX cpu\n");
53   else
54     Log ("Machine doesn't have a MMX cpu\n");
55 
56   if (cpu_3dnow)
57     Log ("Machine got a 3dNow! cpu compatible\n");
58   else
59     Log ("Machine doesn't have a 3dNow! cpu compatible\n");
60 
61   Log ("Vendor : %s\n", cpu_vendor);
62 
63   set_gfx_mode (GFX_TEXT, 0, 0, 0, 0);
64   printf (MESSAGE[language][init_allegro]);
65 
66   printf (MESSAGE[language][translated_by]);
67 
68   if (!(XBuf = create_bitmap (XBUF_WIDTH, XBUF_HEIGHT)))
69     {
70       printf (MESSAGE[language][failed_init]);
71       return (0);
72     }
73 
74   printf (MESSAGE[language][clear_buffer]);
75   clear (XBuf);
76 
77 /*
78  switch (gamepad_driver)
79    {
80     case 0:
81          result = install_joystick(JOY_TYPE_NONE);
82          break;
83     case 1:
84          result = install_joystick(JOY_TYPE_STANDARD);
85          break;
86     case 2:
87          result = install_joystick(JOY_TYPE_2PADS);
88          break;
89     case 3:
90          result = install_joystick(JOY_TYPE_4BUTTON);
91          break;
92     case 4:
93          result = install_joystick(JOY_TYPE_6BUTTON);
94          break;
95     case 5:
96          result = install_joystick(JOY_TYPE_8BUTTON);
97          break;
98     case 6:
99          result = install_joystick(JOY_TYPE_FSPRO);
100          break;
101     case 7:
102          result = install_joystick(JOY_TYPE_WINGEX);
103          break;
104     case 8:
105          result = install_joystick(JOY_TYPE_SIDEWINDER);
106          break;
107     case 9:
108          result = install_joystick(JOY_TYPE_GAMEPAD_PRO);
109          break;
110     case 10:
111          result = install_joystick(JOY_TYPE_SNESPAD_LPT1);
112          break;
113     case 11:
114          result = install_joystick(JOY_TYPE_SNESPAD_LPT2);
115          break;
116     case 12:
117          result = install_joystick(JOY_TYPE_SNESPAD_LPT3);
118          break;
119     case 13:
120          result = install_joystick(JOY_TYPE_WINGWARRIOR);
121          break;
122 
123     default: // in particular, for gamepad_driver == -1
124     result = install_joystick(JOY_TYPE_AUTODETECT);
125    }
126 */
127   result = install_joystick (gamepad_driver);
128 
129   if ((!result) && (joy_type != JOY_TYPE_NONE))
130     {
131       Log ("Joypad %d detected\n", joy_type);
132       printf (MESSAGE[language][joy_detected]);
133       gamepad = 1;
134     }
135   else
136     {
137       Log ("Joypad type %d NOT detected\n", joy_type);
138       printf (MESSAGE[language][joy_no_detected]);
139       gamepad = 0;
140     }
141 
142   Log ("Allocating sprite array\n");
143   printf (MESSAGE[language][alloc_spr]);
144   {
145     UInt32 x;
146     for (x = 0; x < VRAMSIZE / 32; x++)
147       {
148 	if (!(dirty_spr[x] = create_bitmap (16, 16)))
149 	  {
150 	    printf (MESSAGE[language][failed_init]);
151 	    return 0;
152 	  }
153 	clear (dirty_spr[x]);
154       }
155   }
156 
157   Log ("Initiating sound\n");
158   printf (MESSAGE[language][init_sound]);
159   InitSound ();
160 
161   if (use_eagle)
162     {
163       printf (MESSAGE[language][eagle_asked]);
164       if (!set_gfx_mode (GFX_AUTODETECT, 640, 480, 0, 0))
165 	{
166 	  vwidth = 640;
167 	  vheight = 480;
168 	  blit_x = (320 - 256) / 2;
169 	  blit_y = (240 - 216) / 2;
170 	  screen_blit_x = (WIDTH - io.screen_h) / 2;
171 	  screen_blit_y = (HEIGHT - io.screen_w) / 2;
172 	  SetPalette ();
173 
174 	  EAGLE_buf = create_bitmap (640, 480);
175 	}
176       else
177 	printf (MESSAGE[language][eagle_mode_not_init]);
178     }
179   else if (!(*osd_gfx_driver_list[video_driver].init) ())
180     {
181       Log ("Can't set graphic mode\n");
182       printf (MESSAGE[language][cant_set_gmode]);
183       return 0;
184     }
185 
186   text_mode (-1);
187   install_keyboard ();
188   clear (screen);
189 
190   osd_gfx_buffer = XBuf->line[0];
191 
192   Log ("End of initialisation of the machine\n");
193   return 1;
194 
195 }
196 
197 /*****************************************************************************
198 
199     Function: osd_shut_machine
200 
201     Description: Deinitialize all stuff that have been inited in osd_int_machine
202     Parameters: none
203     Return: nothing
204 
205 *****************************************************************************/
206 void
osd_shut_machine(void)207 osd_shut_machine (void)
208 {
209 
210   destroy_bitmap (XBuf);
211 
212   if (OSD_MESSAGE_SPR)
213     destroy_bitmap (OSD_MESSAGE_SPR);
214 
215   if (EAGLE_buf)
216     destroy_bitmap (EAGLE_buf);
217 
218   if (sound_driver == 1)
219     set_volume (0, 0);
220 
221   (*fade_out_proc[rand () % nb_fadeout]) (0, 0, vwidth, vheight);
222 
223   {
224     UInt32 x;
225     for (x = 0; x < VRAMSIZE / 32; x++)
226       destroy_bitmap (dirty_spr[x]);
227   }
228 
229   set_gfx_mode (GFX_TEXT, 0, 0, 0, 0);
230 
231   TrashSound ();
232 
233   allegro_exit ();
234 
235   return;
236 }
237 
238 /*****************************************************************************
239 
240     Function: osd_keypressed
241 
242     Description: Tells if a key is available for future call of osd_readkey
243     Parameters: none
244     Return: 0 is no key is available
245             else any non zero value
246 
247 *****************************************************************************/
osd_keypressed(void)248 SChar osd_keypressed(void)
249 {
250  return keypressed();
251  }
252 
253 /*****************************************************************************
254 
255     Function: osd_readkey
256 
257     Description: Return the first available key stroke, waiting if needed
258     Parameters: none
259     Return: the key value (currently, lower byte is ascii and higher is scancode)
260 
261 *****************************************************************************/
osd_readkey(void)262 UInt16 osd_readkey(void)
263 {
264  return readkey();
265  }
266 
267