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