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 char synchro;
18 // � fond, � fond, � fond? (french joke ;)
19
20 int vwidth, vheight;
21 // size of visible part of the screen (I got troubles with allegro screen->* values!)
22
23 int vmode = 0;
24 // video mode to use
25 // 1 -> first 224*240 then 256*240 then 256*256 then 320*240 and 320*200
26 // 2 -> first 256*240 then 256*256 then 320*240 and 320*200
27 // 3 -> first 256*256 then 320*240 and 320*200
28 // 4 -> first 320*240 and 320*200
29 // 5 -> only try 320*200
30 // 6 -> only 800*600
31 // If you think others modes would be interesting, let me know
32
33 int *fd[4];
34 // handle for joypad devices
35
osd_init_machine()36 int osd_init_machine()
37 {
38
39 int result;
40
41 allegro_init ();
42
43 #warning check if allegro is ok when install timer here
44 #ifndef PROFILING
45 install_timer ();
46 #endif
47
48
49 Log ("\n--[ INITIALISE MACHINE ]--------------------------\n");
50 check_cpu ();
51 if (cpu_cpuid)
52 Log ("Following cpu info are exact\n");
53 else
54 Log ("Following cpu info may be inaccurate\n");
55
56 Log ("Machine is a %d56, sub model : %d\n", cpu_family, cpu_model);
57
58 if (cpu_fpu)
59 Log ("Machine got a fpu\n");
60 else
61 Log ("No fpu available\n");
62
63 if (cpu_mmx)
64 Log ("Machine got a MMX cpu\n");
65 else
66 Log ("Machine doesn't have a MMX cpu\n");
67
68 if (cpu_3dnow)
69 Log ("Machine got a 3dNow! cpu compatible\n");
70 else
71 Log ("Machine doesn't have a 3dNow! cpu compatible\n");
72
73 Log ("Vendor : %s\n", cpu_vendor);
74
75 set_gfx_mode (GFX_TEXT, 0, 0, 0, 0);
76 printf (MESSAGE[language][init_allegro]);
77
78 printf (MESSAGE[language][translated_by]);
79
80 if (!(XBuf = create_bitmap (XBUF_WIDTH, XBUF_HEIGHT)))
81 {
82 printf (MESSAGE[language][failed_init]);
83 return (0);
84 }
85
86 printf (MESSAGE[language][clear_buffer]);
87 clear (XBuf);
88
89 Log ("Allocating sprite array\n");
90 printf (MESSAGE[language][alloc_spr]);
91 {
92 UInt32 x;
93 for (x = 0; x < VRAMSIZE / 32; x++)
94 {
95 if (!(dirty_spr[x] = create_bitmap (16, 16)))
96 {
97 printf (MESSAGE[language][failed_init]);
98 return 0;
99 }
100 clear (dirty_spr[x]);
101 }
102 }
103
104 Log ("Initiating sound\n");
105 printf (MESSAGE[language][init_sound]);
106 InitSound ();
107
108 /* Opening joypad number 0 */
109 (int)fd[0] = open ("/dev/js0", O_NONBLOCK);
110
111 if (use_eagle)
112 {
113 printf (MESSAGE[language][eagle_asked]);
114 if (!set_gfx_mode (GFX_AUTODETECT, 640, 480, 0, 0))
115 {
116 vwidth = 640;
117 vheight = 480;
118 blit_x = (320 - 256) / 2;
119 blit_y = (240 - 216) / 2;
120 screen_blit_x = (WIDTH - io.screen_h) / 2;
121 screen_blit_y = (HEIGHT - io.screen_w) / 2;
122 SetPalette ();
123
124 EAGLE_buf = create_bitmap (640, 480);
125 }
126 else
127 printf (MESSAGE[language][eagle_mode_not_init]);
128 }
129 else if (!(*osd_gfx_driver_list[video_driver].init) ())
130 {
131 Log ("Can't set graphic mode\n");
132 printf (MESSAGE[language][cant_set_gmode]);
133 return 0;
134 }
135
136 text_mode (-1);
137 install_keyboard ();
138 clear (screen);
139
140 osd_gfx_buffer = XBuf->line[0];
141
142 Log ("End of initialisation of the machine\n");
143 return 1;
144
145 }
146
147 /*****************************************************************************
148
149 Function: osd_shut_machine
150
151 Description: Deinitialize all stuff that have been inited in osd_int_machine
152 Parameters: none
153 Return: nothing
154
155 *****************************************************************************/
156 void
osd_shut_machine(void)157 osd_shut_machine (void)
158 {
159
160 destroy_bitmap (XBuf);
161
162 if (OSD_MESSAGE_SPR)
163 destroy_bitmap (OSD_MESSAGE_SPR);
164
165 if (EAGLE_buf)
166 destroy_bitmap (EAGLE_buf);
167
168 if (sound_driver == 1)
169 set_volume (0, 0);
170
171 /* closing joypad device */
172 close ((int)fd[0]);
173
174 (*fade_out_proc[rand () % nb_fadeout]) (0, 0, vwidth, vheight);
175
176 {
177 UInt32 x;
178 for (x = 0; x < VRAMSIZE / 32; x++)
179 destroy_bitmap (dirty_spr[x]);
180 }
181
182 set_gfx_mode (GFX_TEXT, 0, 0, 0, 0);
183
184 TrashSound ();
185
186 allegro_exit ();
187
188 return;
189 }
190
191 /*****************************************************************************
192
193 Function: osd_keypressed
194
195 Description: Tells if a key is available for future call of osd_readkey
196 Parameters: none
197 Return: 0 is no key is available
198 else any non zero value
199
200 *****************************************************************************/
osd_keypressed(void)201 SChar osd_keypressed(void)
202 {
203 return keypressed();
204 }
205
206 /*****************************************************************************
207
208 Function: osd_readkey
209
210 Description: Return the first available key stroke, waiting if needed
211 Parameters: none
212 Return: the key value (currently, lower byte is ascii and higher is scancode)
213
214 *****************************************************************************/
osd_readkey(void)215 UInt16 osd_readkey(void)
216 {
217 return readkey();
218 }
219
220