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