allegro4r 0.0.1-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +59 -0
- data/README.txt +94 -0
- data/examples/exdbuf.rb +58 -0
- data/examples/exfixed.rb +46 -0
- data/examples/exflame.rb +200 -0
- data/examples/exflip.rb +87 -0
- data/examples/exfont.rb +70 -0
- data/examples/exhello.rb +46 -0
- data/examples/exjoy.rb +206 -0
- data/examples/exkeys.rb +216 -0
- data/examples/exmem.rb +50 -0
- data/examples/exmidi.rb +97 -0
- data/examples/exmouse.rb +149 -0
- data/examples/expal.rb +70 -0
- data/examples/expat.rb +62 -0
- data/examples/exsample.rb +89 -0
- data/examples/extimer.rb +84 -0
- data/examples/unifont.dat +0 -0
- data/ext/a4r_API_BITMAP.c +27 -0
- data/ext/a4r_API_DIGI_DRIVER.c +14 -0
- data/ext/a4r_API_GFX_DRIVER.c +14 -0
- data/ext/a4r_API_JOYSTICK_AXIS_INFO.c +53 -0
- data/ext/a4r_API_JOYSTICK_BUTTON_INFO.c +27 -0
- data/ext/a4r_API_JOYSTICK_DRIVER.c +14 -0
- data/ext/a4r_API_JOYSTICK_INFO.c +84 -0
- data/ext/a4r_API_JOYSTICK_STICK_INFO.c +62 -0
- data/ext/a4r_API_KEYBOARD_DRIVER.c +14 -0
- data/ext/a4r_API_MIDI_DRIVER.c +14 -0
- data/ext/a4r_API_MOUSE_DRIVER.c +14 -0
- data/ext/a4r_API_PALETTE.c +63 -0
- data/ext/a4r_API_RGB.c +118 -0
- data/ext/a4r_API_TIMER_DRIVER.c +14 -0
- data/ext/a4r_API_bitmap_objects.c +310 -0
- data/ext/a4r_API_blitting_and_sprites.c +86 -0
- data/ext/a4r_API_digital_sample_routines.c +83 -0
- data/ext/a4r_API_direct_access_to_video_memory.c +102 -0
- data/ext/a4r_API_drawing_primitives.c +114 -0
- data/ext/a4r_API_file_and_compression_routines.c +27 -0
- data/ext/a4r_API_fixed_point_math_routines.c +98 -0
- data/ext/a4r_API_fonts.c +147 -0
- data/ext/a4r_API_graphics_modes.c +155 -0
- data/ext/a4r_API_joystick_routines.c +213 -0
- data/ext/a4r_API_keyboard_routines.c +420 -0
- data/ext/a4r_API_misc.c +133 -0
- data/ext/a4r_API_mouse_routines.c +220 -0
- data/ext/a4r_API_music_routines_midi.c +147 -0
- data/ext/a4r_API_palette_routines.c +112 -0
- data/ext/a4r_API_sound_init_routines.c +29 -0
- data/ext/a4r_API_text_output.c +178 -0
- data/ext/a4r_API_timer_routines.c +250 -0
- data/ext/a4r_API_transparency_and_patterned_drawing.c +87 -0
- data/ext/a4r_API_truecolor_pixel_formats.c +44 -0
- data/ext/a4r_API_unicode_routines.c +53 -0
- data/ext/a4r_API_using_allegro.c +98 -0
- data/ext/allegro4r.c +866 -0
- data/ext/allegro4r.h +311 -0
- data/ext/allegro4r.so +0 -0
- data/ext/extconf.rb +11 -0
- metadata +113 -0
@@ -0,0 +1,420 @@
|
|
1
|
+
#include "allegro4r.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
* call-seq:
|
5
|
+
* install_keyboard -> int
|
6
|
+
*
|
7
|
+
* Installs the Allegro keyboard interrupt handler. You must call this before
|
8
|
+
* using any of the keyboard input routines. Once you have set up the Allegro
|
9
|
+
* handler, you can no longer use operating system calls or C library functions
|
10
|
+
* to access the keyboard.
|
11
|
+
*
|
12
|
+
* Note that on some platforms the keyboard won't work unless you have set a
|
13
|
+
* graphics mode, even if this function returns a success value before calling
|
14
|
+
* set_gfx_mode. This can happen in environments with graphic windowed modes,
|
15
|
+
* since Allegro usually reads the keyboard through the graphical window (which
|
16
|
+
* appears after the set_gfx_mode call). Example:
|
17
|
+
* allegro_init
|
18
|
+
* install_timer
|
19
|
+
* install_keyboard
|
20
|
+
* # We are not 100% sure we can read the keyboard yet!
|
21
|
+
* if set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) != 0
|
22
|
+
* abort_on_error("Couldn't set graphic mode!")
|
23
|
+
* end
|
24
|
+
*
|
25
|
+
* # Now we are guaranteed to be able to read the keyboard.
|
26
|
+
* readkey
|
27
|
+
*
|
28
|
+
* Return value: Returns zero on success, or a negative number on failure (but
|
29
|
+
* you may decide not to check the return value as this function is very
|
30
|
+
* unlikely to fail).
|
31
|
+
*/
|
32
|
+
VALUE a4r_API_install_keyboard(VALUE self)
|
33
|
+
{
|
34
|
+
return INT2FIX(install_keyboard());
|
35
|
+
}
|
36
|
+
|
37
|
+
/*
|
38
|
+
* call-seq:
|
39
|
+
* poll_keyboard -> int
|
40
|
+
*
|
41
|
+
* Wherever possible, Allegro will read the keyboard input asynchronously (ie.
|
42
|
+
* from inside an interrupt handler), but on some platforms that may not be
|
43
|
+
* possible, in which case you must call this routine at regular intervals to
|
44
|
+
* update the keyboard state variables.
|
45
|
+
*
|
46
|
+
* To help you test your keyboard polling code even if you are programming on a
|
47
|
+
* platform that doesn't require it, after the first time that you call this
|
48
|
+
* function Allegro will switch into polling mode, so from that point onwards
|
49
|
+
* you will have to call this routine in order to get any keyboard input at all,
|
50
|
+
* regardless of whether the current driver actually needs to be polled or not.
|
51
|
+
*
|
52
|
+
* The keypressed, readkey, and ureadkey functions call poll_keyboard
|
53
|
+
* automatically, so you only need to use this function when accessing the
|
54
|
+
* key array and key_shifts variable.
|
55
|
+
*
|
56
|
+
* Return value: Returns zero on success, or a negative number on failure (ie.
|
57
|
+
* no keyboard driver installed).
|
58
|
+
*/
|
59
|
+
VALUE a4r_API_poll_keyboard(VALUE self)
|
60
|
+
{
|
61
|
+
return INT2FIX(poll_keyboard());
|
62
|
+
}
|
63
|
+
|
64
|
+
/*
|
65
|
+
* call-seq:
|
66
|
+
* key -> ary
|
67
|
+
*
|
68
|
+
* Array of flags indicating the state of each key, ordered by scancode.
|
69
|
+
* Wherever possible these values will be updated asynchronously, but if
|
70
|
+
* keyboard_needs_poll returns true, you must manually call poll_keyboard to
|
71
|
+
* update them with the current input state. The scancodes are defined as a
|
72
|
+
* series of KEY_* constants (and are also listed below). For example, you could
|
73
|
+
* write:
|
74
|
+
* printf("Space is pressed\n") if key[KEY_SPACE]
|
75
|
+
*
|
76
|
+
* Note that the array is supposed to represent which keys are physically held
|
77
|
+
* down and which keys are not, so it is semantically read-only.
|
78
|
+
*
|
79
|
+
* These are the keyboard scancodes:
|
80
|
+
* KEY_A ... KEY_Z,
|
81
|
+
* KEY_0 ... KEY_9,
|
82
|
+
* KEY_0_PAD ... KEY_9_PAD,
|
83
|
+
* KEY_F1 ... KEY_F12,
|
84
|
+
*
|
85
|
+
* KEY_ESC, KEY_TILDE, KEY_MINUS, KEY_EQUALS,
|
86
|
+
* KEY_BACKSPACE, KEY_TAB, KEY_OPENBRACE, KEY_CLOSEBRACE,
|
87
|
+
* KEY_ENTER, KEY_COLON, KEY_QUOTE, KEY_BACKSLASH,
|
88
|
+
* KEY_BACKSLASH2, KEY_COMMA, KEY_STOP, KEY_SLASH,
|
89
|
+
* KEY_SPACE,
|
90
|
+
*
|
91
|
+
* KEY_INSERT, KEY_DEL, KEY_HOME, KEY_END, KEY_PGUP,
|
92
|
+
* KEY_PGDN, KEY_LEFT, KEY_RIGHT, KEY_UP, KEY_DOWN,
|
93
|
+
*
|
94
|
+
* KEY_SLASH_PAD, KEY_ASTERISK, KEY_MINUS_PAD,
|
95
|
+
* KEY_PLUS_PAD, KEY_DEL_PAD, KEY_ENTER_PAD,
|
96
|
+
*
|
97
|
+
* KEY_PRTSCR, KEY_PAUSE,
|
98
|
+
*
|
99
|
+
* KEY_ABNT_C1, KEY_YEN, KEY_KANA, KEY_CONVERT, KEY_NOCONVERT,
|
100
|
+
* KEY_AT, KEY_CIRCUMFLEX, KEY_COLON2, KEY_KANJI,
|
101
|
+
*
|
102
|
+
* KEY_LSHIFT, KEY_RSHIFT,
|
103
|
+
* KEY_LCONTROL, KEY_RCONTROL,
|
104
|
+
* KEY_ALT, KEY_ALTGR,
|
105
|
+
* KEY_LWIN, KEY_RWIN, KEY_MENU,
|
106
|
+
* KEY_SCRLOCK, KEY_NUMLOCK, KEY_CAPSLOCK
|
107
|
+
*
|
108
|
+
* KEY_EQUALS_PAD, KEY_BACKQUOTE, KEY_SEMICOLON, KEY_COMMAND
|
109
|
+
*
|
110
|
+
* Finally, you may notice an 'odd' behaviour of the KEY_PAUSE key. This key
|
111
|
+
* only generates an interrupt when it is pressed, not when it is released. For
|
112
|
+
* this reason, Allegro pretends the pause key is a 'state' key, which is the
|
113
|
+
* only way to make it usable.
|
114
|
+
*/
|
115
|
+
VALUE a4r_API_key(VALUE self)
|
116
|
+
{
|
117
|
+
// TODO: Convert to data struct or cached or hooked variable?
|
118
|
+
// make [] access directly without array conversion?
|
119
|
+
VALUE ret = rb_ary_new2(KEY_MAX);
|
120
|
+
long x;
|
121
|
+
for (x = KEY_A; x <= KEY_MAX; x++)
|
122
|
+
rb_ary_store(ret, x, key[x] == 0 ? Qfalse : Qtrue);
|
123
|
+
return ret;
|
124
|
+
}
|
125
|
+
|
126
|
+
/*
|
127
|
+
* call-seq:
|
128
|
+
* key_shifts -> int
|
129
|
+
*
|
130
|
+
* Bitmask containing the current state of shift/ctrl/alt, the special Windows
|
131
|
+
* keys, and the accent escape characters. Wherever possible this value will be
|
132
|
+
* updated asynchronously, but if keyboard_needs_poll returns true, you must
|
133
|
+
* manually call poll_keyboard to update it with the current input state. This
|
134
|
+
* can contain any of the flags:
|
135
|
+
* KB_SHIFT_FLAG
|
136
|
+
* KB_CTRL_FLAG
|
137
|
+
* KB_ALT_FLAG
|
138
|
+
* KB_LWIN_FLAG
|
139
|
+
* KB_RWIN_FLAG
|
140
|
+
* KB_MENU_FLAG
|
141
|
+
* KB_COMMAND_FLAG
|
142
|
+
* KB_SCROLOCK_FLAG
|
143
|
+
* KB_NUMLOCK_FLAG
|
144
|
+
* KB_CAPSLOCK_FLAG
|
145
|
+
* KB_INALTSEQ_FLAG
|
146
|
+
* KB_ACCENT1_FLAG
|
147
|
+
* KB_ACCENT2_FLAG
|
148
|
+
* KB_ACCENT3_FLAG
|
149
|
+
* KB_ACCENT4_FLAG
|
150
|
+
*
|
151
|
+
* Example:
|
152
|
+
* if key[KEY_W]
|
153
|
+
* if key_shifts & KB_SHIFT_FLAG != 0
|
154
|
+
* # User is pressing shift + W.
|
155
|
+
* else
|
156
|
+
* # Hmmm... lower case W then.
|
157
|
+
* end
|
158
|
+
* end
|
159
|
+
*/
|
160
|
+
VALUE a4r_API_key_shifts(VALUE self)
|
161
|
+
{
|
162
|
+
// TODO: Convert to data struct or cached or hooked variable?
|
163
|
+
return INT2FIX(key_shifts);
|
164
|
+
}
|
165
|
+
|
166
|
+
/*
|
167
|
+
* call-seq:
|
168
|
+
* keypressed -> true or false
|
169
|
+
*
|
170
|
+
* Returns true if there are keypresses waiting in the input buffer. You can use
|
171
|
+
* this to see if the next call to readkey is going to block or to simply wait
|
172
|
+
* for the user to press a key while you still update the screen possibly
|
173
|
+
* drawing some animation. Example:
|
174
|
+
* while !keypressed do
|
175
|
+
* # Show cool animated logo.
|
176
|
+
* end
|
177
|
+
* # So he skipped our title screen.
|
178
|
+
*/
|
179
|
+
VALUE a4r_API_keypressed(VALUE self)
|
180
|
+
{
|
181
|
+
return keypressed() ? Qtrue : Qfalse;
|
182
|
+
}
|
183
|
+
|
184
|
+
/*
|
185
|
+
* call-seq:
|
186
|
+
* readkey -> int
|
187
|
+
*
|
188
|
+
* Returns the next character from the keyboard buffer, in ASCII format. If the
|
189
|
+
* buffer is empty, it waits until a key is pressed. You can see if there are
|
190
|
+
* queued keypresses with keypressed.
|
191
|
+
*
|
192
|
+
* The low byte of the return value contains the ASCII code of the key, and the
|
193
|
+
* high byte the scancode. The scancode remains the same whatever the state of
|
194
|
+
* the shift, ctrl and alt keys, while the ASCII code is affected by shift and
|
195
|
+
* ctrl in the normal way (shift changes case, ctrl+letter gives the position of
|
196
|
+
* that letter in the alphabet, eg. ctrl+A = 1, ctrl+B = 2, etc). Pressing
|
197
|
+
* alt+key returns only the scancode, with a zero ASCII code in the low byte.
|
198
|
+
* For example:
|
199
|
+
* val = readkey
|
200
|
+
* if (val & 0xff) == 'd' # by ASCII code
|
201
|
+
* allegro_message("You pressed 'd'\n")
|
202
|
+
* end
|
203
|
+
*
|
204
|
+
* if (val >> 8) == KEY_SPACE # by scancode
|
205
|
+
* allegro_message("You pressed Space\n");
|
206
|
+
* end
|
207
|
+
*
|
208
|
+
* if (val & 0xff) == 3 # ctrl+letter
|
209
|
+
* allegro_message("You pressed Control+C\n");
|
210
|
+
* end
|
211
|
+
*
|
212
|
+
* if val == (KEY_X << 8) # alt+letter
|
213
|
+
* allegro_message("You pressed Alt+X\n");
|
214
|
+
* end
|
215
|
+
*
|
216
|
+
* This function cannot return character values greater than 255. If you need to
|
217
|
+
* read Unicode input, use ureadkey instead.
|
218
|
+
*/
|
219
|
+
VALUE a4r_API_readkey(VALUE self)
|
220
|
+
{
|
221
|
+
return INT2FIX(readkey());
|
222
|
+
}
|
223
|
+
|
224
|
+
/*
|
225
|
+
* call-seq:
|
226
|
+
* ureadkey(scancode) -> int
|
227
|
+
* ureadkey(scancode) -> [int, int]
|
228
|
+
*
|
229
|
+
* Returns the next character from the keyboard buffer, in Unicode format. If
|
230
|
+
* the buffer is empty, it waits until a key is pressed. You can see if there
|
231
|
+
* are queued keypresses with keypressed. The return value contains the Unicode
|
232
|
+
* value of the key, and if not nil or false, the second return value will be
|
233
|
+
* set to the scancode. Unlike readkey, this function is able to return
|
234
|
+
* character values greater than 255. Example:
|
235
|
+
* val, scancode = ureadkey(true)
|
236
|
+
* if val == 0x00F1
|
237
|
+
* allegro_message("You pressed n with tilde\n")
|
238
|
+
* end
|
239
|
+
*
|
240
|
+
* if val == 0x00DF
|
241
|
+
* allegro_message("You pressed sharp s\n")
|
242
|
+
* end
|
243
|
+
*
|
244
|
+
* You should be able to find Unicode character maps at http://www.unicode.org/.
|
245
|
+
* Remember that on DOS you must specify a custom keyboard map (like those found
|
246
|
+
* in 'keyboard.dat') usually with the help of a configuration file specifying
|
247
|
+
* the language mapping (keyboard variable in system section of 'allegro.cfg'),
|
248
|
+
* or you will get the default US keyboard mapping.
|
249
|
+
*
|
250
|
+
* *** The Ruby method signature differs from the Allegro method signature. The
|
251
|
+
* Allegro signature takes scancode by reference, but the Ruby signature takes a
|
252
|
+
* boolean. If false or nil, the method returns only the read key, otherwise it
|
253
|
+
* returns an array containing the read key and the scancode.
|
254
|
+
*/
|
255
|
+
VALUE a4r_API_ureadkey(VALUE self, VALUE scancode)
|
256
|
+
{
|
257
|
+
int s;
|
258
|
+
int *s_p = NULL;
|
259
|
+
|
260
|
+
if (RTEST(scancode))
|
261
|
+
s_p = &s;
|
262
|
+
int u = ureadkey(s_p);
|
263
|
+
|
264
|
+
VALUE ret;
|
265
|
+
if (s_p)
|
266
|
+
ret = rb_ary_new3(2, INT2FIX(u), INT2FIX(s));
|
267
|
+
else
|
268
|
+
ret = INT2FIX(u);
|
269
|
+
|
270
|
+
return ret;
|
271
|
+
}
|
272
|
+
|
273
|
+
/*
|
274
|
+
* call-seq:
|
275
|
+
* scancode_to_name(scancode) -> str
|
276
|
+
*
|
277
|
+
* This function returns a string containing the name of they key with the given
|
278
|
+
* scancode. This is useful if you e.g. let the user choose a key for some
|
279
|
+
* action, and want to display something more meaningful than just the scancode.
|
280
|
+
* Example:
|
281
|
+
* keyname = scancode_to_name(scancode)
|
282
|
+
* allegro_message("You pressed the %s key." % keyname)
|
283
|
+
*/
|
284
|
+
VALUE a4r_API_scancode_to_name(VALUE self, VALUE scancode)
|
285
|
+
{
|
286
|
+
return rb_str_new2(scancode_to_name(FIX2INT(scancode)));
|
287
|
+
}
|
288
|
+
|
289
|
+
/*
|
290
|
+
* call-seq:
|
291
|
+
* keyboard_callback = proc
|
292
|
+
*
|
293
|
+
* If set, this function is called by the keyboard handler in response to every
|
294
|
+
* keypress. It is passed a copy of the value that is about to be added into the
|
295
|
+
* input buffer, and can either return this value unchanged, return zero to
|
296
|
+
* cause the key to be ignored, or return a modified value to change what
|
297
|
+
* readkey will later return. This routine executes in an interrupt context, so
|
298
|
+
* it must be in locked memory. Example:
|
299
|
+
* def enigma_scrambler(key)
|
300
|
+
* # Add one to both the scancode and ascii values.
|
301
|
+
* return (((key >> 8) + 1) << 8) | ((key & 0xff) + 1)
|
302
|
+
* end
|
303
|
+
*
|
304
|
+
* ...
|
305
|
+
*
|
306
|
+
* install_timer
|
307
|
+
* LOCK_FUNCTION(:enigma_scrambler)
|
308
|
+
* install_keyboard
|
309
|
+
* keyboard_callback = self.method(:enigma_scrambler)
|
310
|
+
*
|
311
|
+
* Note that this callback will be ignored if you also set the unicode keyboard
|
312
|
+
* callback.
|
313
|
+
*/
|
314
|
+
VALUE a4r_API_keyboard_callback_set(VALUE self, VALUE proc)
|
315
|
+
{
|
316
|
+
// TODO: Validate proc and maybe check for 0 in the keyboard_callback_method?
|
317
|
+
// TODO: hooked variable?
|
318
|
+
keyboard_callback_proc = proc;
|
319
|
+
if (proc == Qnil)
|
320
|
+
keyboard_callback = NULL;
|
321
|
+
else
|
322
|
+
keyboard_callback = keyboard_callback_method;
|
323
|
+
return proc;
|
324
|
+
}
|
325
|
+
|
326
|
+
/*
|
327
|
+
* call-seq:
|
328
|
+
* keyboard_lowlevel_callback = proc
|
329
|
+
*
|
330
|
+
* If set, this function is called by the keyboard handler in response to every
|
331
|
+
* keyboard event, both presses (including keyboard repeat rate) and releases.
|
332
|
+
* It will be passed a raw keyboard scancode byte (scancodes are 7 bits long),
|
333
|
+
* with the top bit (8th bit) clear if the key has been pressed or set if it was
|
334
|
+
* released. This routine executes in an interrupt context, so it must be in
|
335
|
+
* locked memory. Example:
|
336
|
+
*
|
337
|
+
* def keypress_watcher(scancode)
|
338
|
+
* if (scancode & 0x80) != 0
|
339
|
+
* key_up = 1
|
340
|
+
* else
|
341
|
+
* key_down = 1
|
342
|
+
* end
|
343
|
+
* end
|
344
|
+
*
|
345
|
+
* ...
|
346
|
+
*
|
347
|
+
* install_timer
|
348
|
+
* LOCK_FUNCTION(silence_g_key)
|
349
|
+
* LOCK_VARIABLE(key_down)
|
350
|
+
* LOCK_VARIABLE(key_up)
|
351
|
+
* install_keyboard
|
352
|
+
* keyboard_lowlevel_callback = self.method(:keypress_watcher)
|
353
|
+
* # Disable keyboard repeat to get typewriter effect.
|
354
|
+
* set_keyboard_rate(0, 0)
|
355
|
+
*
|
356
|
+
* ...
|
357
|
+
*
|
358
|
+
* while (game_loop)
|
359
|
+
* if (key_down == 1)
|
360
|
+
* key_down = 0
|
361
|
+
* # Play sample of typewriter key press.
|
362
|
+
* end
|
363
|
+
* if (key_up == 1)
|
364
|
+
* key_up = 0;
|
365
|
+
* # Play sample of typewriter key release.
|
366
|
+
* end
|
367
|
+
* end
|
368
|
+
*/
|
369
|
+
VALUE a4r_API_keyboard_lowlevel_callback_set(VALUE self, VALUE proc)
|
370
|
+
{
|
371
|
+
// TODO: Validate proc and maybe check for 0 in the keyboard_lowlevel_callback_method?
|
372
|
+
// TODO: hooked variable?
|
373
|
+
keyboard_lowlevel_callback_proc = proc;
|
374
|
+
if (proc == Qnil)
|
375
|
+
keyboard_lowlevel_callback = NULL;
|
376
|
+
else
|
377
|
+
keyboard_lowlevel_callback = keyboard_lowlevel_callback_method;
|
378
|
+
return proc;
|
379
|
+
}
|
380
|
+
|
381
|
+
/*
|
382
|
+
* call-seq:
|
383
|
+
* clear_keybuf -> nil
|
384
|
+
*
|
385
|
+
* Empties the keyboard buffer. Usually you want to use this in your program
|
386
|
+
* before reading keys to avoid previously buffered keys to be returned by calls
|
387
|
+
* to readkey or ureadkey.
|
388
|
+
*/
|
389
|
+
VALUE a4r_API_clear_keybuf(VALUE self)
|
390
|
+
{
|
391
|
+
clear_keybuf();
|
392
|
+
return Qnil;
|
393
|
+
}
|
394
|
+
|
395
|
+
/******************************************************************************/
|
396
|
+
// Predefined keyboard callback routines
|
397
|
+
/*
|
398
|
+
* TODO: The keyboard callback routines are not working as expected. I thought
|
399
|
+
* I might be able to fake things by setting a global variable to a proc, which
|
400
|
+
* then would get called by the below methods. Unfortunately, even with no code
|
401
|
+
* in the proc, it crashes ruby. I'm assuming that since these methods run
|
402
|
+
* in an interrupt context, there is a clash between the Ruby code and the
|
403
|
+
* lowlevel code.
|
404
|
+
*/
|
405
|
+
|
406
|
+
VALUE keyboard_callback_proc;
|
407
|
+
VALUE keyboard_lowlevel_callback_proc;
|
408
|
+
|
409
|
+
int keyboard_callback_method(int key)
|
410
|
+
{
|
411
|
+
return FIX2INT(rb_funcall(keyboard_callback_proc, CALL_ID, 1, INT2FIX(key)));
|
412
|
+
}
|
413
|
+
END_OF_FUNCTION(keyboard_callback_method)
|
414
|
+
|
415
|
+
void keyboard_lowlevel_callback_method(int scancode)
|
416
|
+
{
|
417
|
+
rb_funcall(keyboard_lowlevel_callback_proc, CALL_ID, 1, INT2FIX(scancode));
|
418
|
+
}
|
419
|
+
END_OF_FUNCTION(keyboard_lowlevel_callback_method)
|
420
|
+
|
data/ext/a4r_API_misc.c
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
#include "allegro4r.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
* call-seq:
|
5
|
+
* MIN(x, y) -> num
|
6
|
+
*
|
7
|
+
*/
|
8
|
+
VALUE a4r_API_MIN(VALUE self, VALUE x, VALUE y)
|
9
|
+
{
|
10
|
+
return INT2NUM(MIN(NUM2INT(x), NUM2INT(y)));
|
11
|
+
}
|
12
|
+
|
13
|
+
/*
|
14
|
+
* call-seq:
|
15
|
+
* ABS(x) -> num
|
16
|
+
*
|
17
|
+
*/
|
18
|
+
VALUE a4r_API_ABS(VALUE self, VALUE x)
|
19
|
+
{
|
20
|
+
return INT2NUM(ABS(NUM2INT(x)));
|
21
|
+
}
|
22
|
+
|
23
|
+
/*
|
24
|
+
* call-seq:
|
25
|
+
* AL_RAND -> num
|
26
|
+
*
|
27
|
+
* On platforms that require it, this macro does a simple shift transformation
|
28
|
+
* of the libc rand() function, in order to improve the perceived randomness of
|
29
|
+
* the output series in the lower 16 bits. Where not required, it directly
|
30
|
+
* translates into a rand() call.
|
31
|
+
*/
|
32
|
+
VALUE a4r_API_AL_RAND(VALUE self)
|
33
|
+
{
|
34
|
+
return INT2NUM(AL_RAND());
|
35
|
+
}
|
36
|
+
|
37
|
+
/*
|
38
|
+
* call-seq:
|
39
|
+
* gfx_driver -> gfx_driver
|
40
|
+
*
|
41
|
+
* Global reference to the graphics driver.
|
42
|
+
*/
|
43
|
+
VALUE a4r_API_gfx_driver(VALUE self)
|
44
|
+
{
|
45
|
+
// TODO: Convert to data struct or cached or hooked variable?
|
46
|
+
GFX_DRIVER *driver = gfx_driver;
|
47
|
+
VALUE obj = Data_Wrap_Struct(cAPI_GFX_DRIVER, 0, 0, driver);
|
48
|
+
return obj;
|
49
|
+
}
|
50
|
+
|
51
|
+
/*
|
52
|
+
* call-seq:
|
53
|
+
* mouse_driver -> mouse_driver
|
54
|
+
*
|
55
|
+
* Global reference to the mouse driver.
|
56
|
+
*/
|
57
|
+
VALUE a4r_API_mouse_driver(VALUE self)
|
58
|
+
{
|
59
|
+
// TODO: Convert to data struct or cached or hooked variable?
|
60
|
+
MOUSE_DRIVER *driver = mouse_driver;
|
61
|
+
VALUE obj = Data_Wrap_Struct(cAPI_MOUSE_DRIVER, 0, 0, driver);
|
62
|
+
return obj;
|
63
|
+
}
|
64
|
+
|
65
|
+
/*
|
66
|
+
* call-seq:
|
67
|
+
* timer_driver -> timer_driver
|
68
|
+
*
|
69
|
+
* Global reference to the timer driver.
|
70
|
+
*/
|
71
|
+
VALUE a4r_API_timer_driver(VALUE self)
|
72
|
+
{
|
73
|
+
// TODO: Convert to data struct or cached or hooked variable?
|
74
|
+
TIMER_DRIVER *driver = timer_driver;
|
75
|
+
VALUE obj = Data_Wrap_Struct(cAPI_TIMER_DRIVER, 0, 0, driver);
|
76
|
+
return obj;
|
77
|
+
}
|
78
|
+
|
79
|
+
/*
|
80
|
+
* call-seq:
|
81
|
+
* keyboard_driver -> keyboard_driver
|
82
|
+
*
|
83
|
+
* Global reference to the keyboard driver.
|
84
|
+
*/
|
85
|
+
VALUE a4r_API_keyboard_driver(VALUE self)
|
86
|
+
{
|
87
|
+
// TODO: Convert to data struct or cached or hooked variable?
|
88
|
+
KEYBOARD_DRIVER *driver = keyboard_driver;
|
89
|
+
VALUE obj = Data_Wrap_Struct(cAPI_KEYBOARD_DRIVER, 0, 0, driver);
|
90
|
+
return obj;
|
91
|
+
}
|
92
|
+
|
93
|
+
/*
|
94
|
+
* call-seq:
|
95
|
+
* joystick_driver -> joystick_driver
|
96
|
+
*
|
97
|
+
* Global reference to the joystick driver.
|
98
|
+
*/
|
99
|
+
VALUE a4r_API_joystick_driver(VALUE self)
|
100
|
+
{
|
101
|
+
// TODO: Convert to data struct or cached or hooked variable?
|
102
|
+
JOYSTICK_DRIVER *driver = joystick_driver;
|
103
|
+
VALUE obj = Data_Wrap_Struct(cAPI_JOYSTICK_DRIVER, 0, 0, driver);
|
104
|
+
return obj;
|
105
|
+
}
|
106
|
+
|
107
|
+
/*
|
108
|
+
* call-seq:
|
109
|
+
* digi_driver -> digi_driver
|
110
|
+
*
|
111
|
+
* Global reference to the digital driver.
|
112
|
+
*/
|
113
|
+
VALUE a4r_API_digi_driver(VALUE self)
|
114
|
+
{
|
115
|
+
// TODO: Convert to data struct or cached or hooked variable?
|
116
|
+
DIGI_DRIVER *driver = digi_driver;
|
117
|
+
VALUE obj = Data_Wrap_Struct(cAPI_DIGI_DRIVER, 0, 0, driver);
|
118
|
+
return obj;
|
119
|
+
}
|
120
|
+
|
121
|
+
/*
|
122
|
+
* call-seq:
|
123
|
+
* midi_driver -> midi_driver
|
124
|
+
*
|
125
|
+
* Global reference to the MIDI driver.
|
126
|
+
*/
|
127
|
+
VALUE a4r_API_midi_driver(VALUE self)
|
128
|
+
{
|
129
|
+
// TODO: Convert to data struct or cached or hooked variable?
|
130
|
+
MIDI_DRIVER *driver = midi_driver;
|
131
|
+
VALUE obj = Data_Wrap_Struct(cAPI_MIDI_DRIVER, 0, 0, driver);
|
132
|
+
return obj;
|
133
|
+
}
|