allegro4r 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +4 -0
- data/Manifest.txt +58 -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/extconf.rb +11 -0
- metadata +112 -0
@@ -0,0 +1,112 @@
|
|
1
|
+
#include "allegro4r.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
* call-seq:
|
5
|
+
* set_palette(p) -> nil
|
6
|
+
*
|
7
|
+
* Sets the entire palette of 256 colors. You should provide an array of 256 RGB
|
8
|
+
* structures. Unlike set_color, there is no need to call vsync before this
|
9
|
+
* function. Example:
|
10
|
+
* palette = PALETTE.new
|
11
|
+
* ...
|
12
|
+
* bmp = load_bitmap(filename, palette)
|
13
|
+
* abort_on_error("Couldn't load bitmap!") if bmp.nil?
|
14
|
+
* set_palette(palette)
|
15
|
+
*/
|
16
|
+
VALUE a4r_API_set_palette(VALUE self, VALUE p)
|
17
|
+
{
|
18
|
+
// TODO: Check data type of palette? Also, allow array of 256 RGBs
|
19
|
+
PALETTE *pal;
|
20
|
+
Data_Get_Struct(p, PALETTE, pal);
|
21
|
+
set_palette(*pal);
|
22
|
+
return Qnil;
|
23
|
+
}
|
24
|
+
|
25
|
+
/*
|
26
|
+
* call_seq:
|
27
|
+
* get_palette(p) -> nil
|
28
|
+
*
|
29
|
+
* Retrieves the entire palette of 256 colors. You should provide an array of
|
30
|
+
* 256 RGB structures to store it in. Example:
|
31
|
+
* pal = PALETTE.new
|
32
|
+
* ...
|
33
|
+
* get_palette(pal)
|
34
|
+
*/
|
35
|
+
VALUE a4r_API_get_palette(VALUE self, VALUE p)
|
36
|
+
{
|
37
|
+
// TODO: Check data type of p?
|
38
|
+
PALETTE *pal;
|
39
|
+
Data_Get_Struct(p, PALETTE, pal);
|
40
|
+
get_palette(*pal);
|
41
|
+
return Qnil;
|
42
|
+
}
|
43
|
+
|
44
|
+
/*
|
45
|
+
* call-seq:
|
46
|
+
* default_palette -> pal
|
47
|
+
*
|
48
|
+
* The default IBM BIOS palette. This will be automatically selected whenever
|
49
|
+
* you set a new graphics mode. The palette contains 16 basic colors plus many
|
50
|
+
* gradients between them. If you want to see the values, you can write a small
|
51
|
+
* Allegro program which saves a screenshot with this palette, or open the
|
52
|
+
* grabber tool provided with Allegro and create a new palette object, which
|
53
|
+
* will use this palette by default.
|
54
|
+
*/
|
55
|
+
VALUE a4r_API_default_palette(VALUE self)
|
56
|
+
{
|
57
|
+
// TODO: Convert to data struct or cached or hooked variable?
|
58
|
+
PALETTE *pal = &default_palette;
|
59
|
+
VALUE obj = Data_Wrap_Struct(cAPI_PALETTE, 0, 0, pal);
|
60
|
+
return obj;
|
61
|
+
}
|
62
|
+
|
63
|
+
/*
|
64
|
+
* call-seq:
|
65
|
+
* black_palette -> pal
|
66
|
+
*
|
67
|
+
* A palette containing solid black colors, used by the fade routines.
|
68
|
+
*/
|
69
|
+
VALUE a4r_API_black_palette(VALUE self)
|
70
|
+
{
|
71
|
+
// TODO: Convert to data struct or cached or hooked variable?
|
72
|
+
PALETTE *pal = &black_palette;
|
73
|
+
VALUE obj = Data_Wrap_Struct(cAPI_PALETTE, 0, 0, pal);
|
74
|
+
return obj;
|
75
|
+
}
|
76
|
+
|
77
|
+
/*
|
78
|
+
* call-seq:
|
79
|
+
* desktop_palette -> pal
|
80
|
+
*
|
81
|
+
* The palette used by the Atari ST low resolution desktop. I'm not quite sure
|
82
|
+
* why this is still here, except that the grabber and test programs use it. It
|
83
|
+
* is probably the only Atari legacy code left in Allegro, and it would be a
|
84
|
+
* shame to remove it :-)
|
85
|
+
*
|
86
|
+
* The contents of this palette are 16 colors repeated 16 times. Color entry
|
87
|
+
* zero is equal to color entry 16, which is equal to color entry 24, etc.
|
88
|
+
* Index Color RGB values
|
89
|
+
* 0 White 63 63 63
|
90
|
+
* 1 Red 63 0 0
|
91
|
+
* 2 Green 0 63 0
|
92
|
+
* 3 Yellow 63 63 0
|
93
|
+
* 4 Blue 0 0 63
|
94
|
+
* 5 Pink 63 0 63
|
95
|
+
* 6 Cyan 0 63 63
|
96
|
+
* 7 Grey 16 16 16
|
97
|
+
* 8 Light grey 31 31 31
|
98
|
+
* 9 Light red 63 31 31
|
99
|
+
* 10 Light green 31 63 31
|
100
|
+
* 11 Light yellow 63 63 31
|
101
|
+
* 12 Light blue 31 31 63
|
102
|
+
* 13 Light pink 63 31 63
|
103
|
+
* 14 Light cyan 31 63 63
|
104
|
+
* 15 Black 0 0 0
|
105
|
+
*/
|
106
|
+
VALUE a4r_API_desktop_palette(VALUE self)
|
107
|
+
{
|
108
|
+
// TODO: Convert to data struct or cached or hooked variable?
|
109
|
+
PALETTE *pal = &desktop_palette;
|
110
|
+
VALUE obj = Data_Wrap_Struct(cAPI_PALETTE, 0, 0, pal);
|
111
|
+
return obj;
|
112
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#include "allegro4r.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
* call-seq:
|
5
|
+
* install_sound(digi, midi, cfg_path) -> int
|
6
|
+
*
|
7
|
+
* Initialises the sound module. You should normally pass DIGI_AUTODETECT and
|
8
|
+
* MIDI_AUTODETECT as the driver parameters to this function, in which case
|
9
|
+
* Allegro will read hardware settings from the current configuration file. This
|
10
|
+
* allows the user to select different values with the setup utility: see the
|
11
|
+
* config section for details. Alternatively, see the platform specific
|
12
|
+
* documentation for a list of the available drivers. The cfg_path parameter is
|
13
|
+
* only present for compatibility with previous versions of Allegro, and has no
|
14
|
+
* effect on anything.
|
15
|
+
*
|
16
|
+
* Return value: Returns zero if the sound is successfully installed, and -1 on
|
17
|
+
* failure. If it fails it will store a description of the problem in
|
18
|
+
* allegro_error.
|
19
|
+
*/
|
20
|
+
VALUE a4r_API_install_sound(VALUE self, VALUE digi, VALUE midi, VALUE cfg_path)
|
21
|
+
{
|
22
|
+
char *c;
|
23
|
+
if (cfg_path == Qnil)
|
24
|
+
c = NULL;
|
25
|
+
else
|
26
|
+
c = StringValuePtr(cfg_path);
|
27
|
+
|
28
|
+
return INT2FIX(install_sound(FIX2INT(digi), FIX2INT(midi), c));
|
29
|
+
}
|
@@ -0,0 +1,178 @@
|
|
1
|
+
#include "allegro4r.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
* call-seq:
|
5
|
+
* font -> a_fnt
|
6
|
+
*
|
7
|
+
* A simple 8x8 fixed size font (the mode 13h BIOS default). If you want to
|
8
|
+
* alter the font used by the GUI routines, change this to point to one of your
|
9
|
+
* own fonts. This font contains the standard ASCII (U+20 to U+7F), Latin-1
|
10
|
+
* (U+A1 to U+FF), and Latin Extended-A (U+0100 to U+017F) character ranges.
|
11
|
+
*/
|
12
|
+
VALUE a4r_API_font(VALUE self)
|
13
|
+
{
|
14
|
+
// TODO: Convert to data struct or cached or hooked variable?
|
15
|
+
FONT *fnt = font;
|
16
|
+
VALUE obj = Data_Wrap_Struct(cAPI_FONT, 0, 0, fnt);
|
17
|
+
return obj;
|
18
|
+
}
|
19
|
+
|
20
|
+
/*
|
21
|
+
* call-seq:
|
22
|
+
* font = fnt -> fnt
|
23
|
+
*
|
24
|
+
* See font.
|
25
|
+
*/
|
26
|
+
VALUE a4r_API_font_set(VALUE self, VALUE f)
|
27
|
+
{
|
28
|
+
FONT *fnt;
|
29
|
+
Data_Get_Struct(f, FONT, fnt);
|
30
|
+
font = fnt;
|
31
|
+
return f;
|
32
|
+
}
|
33
|
+
|
34
|
+
/*
|
35
|
+
* call-seq:
|
36
|
+
* text_length(f, str) -> int
|
37
|
+
*
|
38
|
+
* Returns the length (in pixels) of a string in the specified font. Example:
|
39
|
+
* width = text_length(font, "I love spam")
|
40
|
+
* ...
|
41
|
+
* bmp = create_bitmap(width, height)
|
42
|
+
*/
|
43
|
+
VALUE a4r_API_text_length(VALUE self, VALUE f, VALUE str)
|
44
|
+
{
|
45
|
+
FONT *fnt;
|
46
|
+
Data_Get_Struct(f, FONT, fnt);
|
47
|
+
return INT2FIX(text_length(fnt, StringValuePtr(str)));
|
48
|
+
}
|
49
|
+
|
50
|
+
/*
|
51
|
+
* call-seq:
|
52
|
+
* text_height(f) -> int
|
53
|
+
*
|
54
|
+
* Returns the height (in pixels) of the specified font. Example:
|
55
|
+
* height = text_height(font)
|
56
|
+
* ...
|
57
|
+
* bmp = create_bitmap(width, height)
|
58
|
+
*/
|
59
|
+
VALUE a4r_API_text_height(VALUE self, VALUE f)
|
60
|
+
{
|
61
|
+
FONT *fnt;
|
62
|
+
Data_Get_Struct(f, FONT, fnt);
|
63
|
+
return INT2FIX(text_height(fnt));
|
64
|
+
}
|
65
|
+
|
66
|
+
/*
|
67
|
+
* call-seq:
|
68
|
+
* textout_ex(bmp, f, s, x, y, color, bg) -> nil
|
69
|
+
*
|
70
|
+
* Writes the string 's' onto the bitmap at position x, y, using the specified
|
71
|
+
* font, foreground color and background color. If the background color is -1,
|
72
|
+
* then the text is written transparently. If the foreground color is -1 and a
|
73
|
+
* color font is in use, it will be drawn using the colors from the original
|
74
|
+
* font bitmap (the one you imported into the grabber program), which allows
|
75
|
+
* multicolored text output. For high and true color fonts, the foreground color
|
76
|
+
* is ignored and always treated as -1. Example:
|
77
|
+
* # Show the program's version in blue letters.
|
78
|
+
* textout_ex(screen, font, "v4.2.0-beta2", 10, 10,
|
79
|
+
* makecol(0, 0, 255), -1)
|
80
|
+
*/
|
81
|
+
VALUE a4r_API_textout_ex(VALUE self, VALUE bmp, VALUE f, VALUE s, VALUE x, VALUE y, VALUE color, VALUE bg)
|
82
|
+
{
|
83
|
+
BITMAP *b;
|
84
|
+
Data_Get_Struct(bmp, BITMAP, b);
|
85
|
+
FONT *fnt;
|
86
|
+
Data_Get_Struct(f, FONT, fnt);
|
87
|
+
textout_ex(b, fnt, StringValuePtr(s), FIX2INT(x), FIX2INT(y), FIX2INT(color), FIX2INT(bg));
|
88
|
+
return Qnil;
|
89
|
+
}
|
90
|
+
|
91
|
+
/*
|
92
|
+
* call-seq:
|
93
|
+
* textout_centre_ex(bmp, f, s, x, y, color, bg) -> nil
|
94
|
+
*
|
95
|
+
* Like textout_ex, but interprets the x coordinate as the centre rather than
|
96
|
+
* the left edge of the string. Example:
|
97
|
+
* # Important texts go in the middle.
|
98
|
+
* width = text_length("GAME OVER")
|
99
|
+
* textout_centre_ex(screen, font, "GAME OVER",
|
100
|
+
* SCREEN_W / 2, SCREEN_H / 2,
|
101
|
+
* makecol(255, 0, 0), makecol(0, 0, 0))
|
102
|
+
*/
|
103
|
+
VALUE a4r_API_textout_centre_ex(VALUE self, VALUE bmp, VALUE f, VALUE s, VALUE x, VALUE y, VALUE color, VALUE bg)
|
104
|
+
{
|
105
|
+
BITMAP *b;
|
106
|
+
Data_Get_Struct(bmp, BITMAP, b);
|
107
|
+
FONT *fnt;
|
108
|
+
Data_Get_Struct(f, FONT, fnt);
|
109
|
+
textout_centre_ex(b, fnt, StringValuePtr(s), FIX2INT(x), FIX2INT(y), FIX2INT(color), FIX2INT(bg));
|
110
|
+
return Qnil;
|
111
|
+
}
|
112
|
+
|
113
|
+
/*
|
114
|
+
* call-seq:
|
115
|
+
* textprintf_ex(bmp, f, x, y, color, by, fmt) -> nil
|
116
|
+
*
|
117
|
+
* Formatted text output, using a printf style format string. Due to an internal
|
118
|
+
* limitation, this function can't be used for extremely long texts. If you
|
119
|
+
* happen to reach this limit, you can work around it by using uszprintf and
|
120
|
+
* textout_ex, which don't have any. Example:
|
121
|
+
* textprintf_ex(screen, font, 10, 10, makecol(255, 100, 200),
|
122
|
+
* -1, "Score: %d" % player_score)
|
123
|
+
*/
|
124
|
+
VALUE a4r_API_textprintf_ex(VALUE self, VALUE bmp, VALUE f, VALUE x, VALUE y, VALUE color, VALUE bg, VALUE fmt)
|
125
|
+
{
|
126
|
+
// TODO: Make this actually work like printf with arbitrary number of parameters
|
127
|
+
BITMAP *b;
|
128
|
+
Data_Get_Struct(bmp, BITMAP, b);
|
129
|
+
FONT *fnt;
|
130
|
+
Data_Get_Struct(f, FONT, fnt);
|
131
|
+
textprintf_ex(b, fnt, FIX2INT(x), FIX2INT(y), FIX2INT(color), FIX2INT(bg), StringValuePtr(fmt));
|
132
|
+
return Qnil;
|
133
|
+
}
|
134
|
+
|
135
|
+
/*
|
136
|
+
* call-seq:
|
137
|
+
* textprintf_centre_ex(bmp, f, x, y, color, bg, fmt) -> nil
|
138
|
+
*
|
139
|
+
* Like textprintf_ex, but interprets the x coordinate as the centre rather than
|
140
|
+
* the left edge of the string. This function shares the text length limitation
|
141
|
+
* of textprintf_ex. Example:
|
142
|
+
* textprintf_centre_ex(screen, font, SCREEN_W / 2, 120,
|
143
|
+
* makecol(0, 100, 243), -1,
|
144
|
+
* "Your best score so far was %d!" %
|
145
|
+
* total_max_points)
|
146
|
+
*/
|
147
|
+
VALUE a4r_API_textprintf_centre_ex(VALUE self, VALUE bmp, VALUE f, VALUE x, VALUE y, VALUE color, VALUE bg, VALUE fmt)
|
148
|
+
{
|
149
|
+
// TODO: Make this actually work like printf with arbitrary number of parameters
|
150
|
+
BITMAP *b;
|
151
|
+
Data_Get_Struct(bmp, BITMAP, b);
|
152
|
+
FONT *fnt;
|
153
|
+
Data_Get_Struct(f, FONT, fnt);
|
154
|
+
textprintf_centre_ex(b, fnt, FIX2INT(x), FIX2INT(y), FIX2INT(color), FIX2INT(bg), StringValuePtr(fmt));
|
155
|
+
return Qnil;
|
156
|
+
}
|
157
|
+
|
158
|
+
/*
|
159
|
+
* call-seq:
|
160
|
+
* textprintf_right_ex(bmp, f, x, y, color, bg, fmt) -> nil
|
161
|
+
*
|
162
|
+
* Like textprintf_ex, but interprets the x coordinate as the right rather than
|
163
|
+
* the left edge of the string. This function shares the text length limitation
|
164
|
+
* of textprintf_ex. Example:
|
165
|
+
* textprintf_right_ex(screen, font, SCREEN_W - 10, 10,
|
166
|
+
* makecol(200, 200, 20), -1,
|
167
|
+
* "%d bullets left" % player_ammo)
|
168
|
+
*/
|
169
|
+
VALUE a4r_API_textprintf_right_ex(VALUE self, VALUE bmp, VALUE f, VALUE x, VALUE y, VALUE color, VALUE bg, VALUE fmt)
|
170
|
+
{
|
171
|
+
// TODO: Make this actually work like printf with arbitrary number of parameters
|
172
|
+
BITMAP *b;
|
173
|
+
Data_Get_Struct(bmp, BITMAP, b);
|
174
|
+
FONT *fnt;
|
175
|
+
Data_Get_Struct(f, FONT, fnt);
|
176
|
+
textprintf_right_ex(b, fnt, FIX2INT(x), FIX2INT(y), FIX2INT(color), FIX2INT(bg), StringValuePtr(fmt));
|
177
|
+
return Qnil;
|
178
|
+
}
|
@@ -0,0 +1,250 @@
|
|
1
|
+
#include "allegro4r.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
* call-seq:
|
5
|
+
* install_timer -> int
|
6
|
+
*
|
7
|
+
* Installs the Allegro timer interrupt handler. You must do this before
|
8
|
+
* installing any user timer routines, and also before displaying a mouse
|
9
|
+
* pointer, playing FLI animations or MIDI music, and using any of the GUI
|
10
|
+
* routines.
|
11
|
+
*
|
12
|
+
* Return value: Returns zero on success, or a negative number on failure (but
|
13
|
+
* you may decide not to check the return value as this function is very
|
14
|
+
* unlikely to fail).
|
15
|
+
*/
|
16
|
+
VALUE a4r_API_install_timer(VALUE self)
|
17
|
+
{
|
18
|
+
return INT2FIX(install_timer());
|
19
|
+
}
|
20
|
+
|
21
|
+
/*
|
22
|
+
* call-seq:
|
23
|
+
* install_int(name, speed) -> int
|
24
|
+
*
|
25
|
+
* Installs a user timer handler, with the speed given as the number of
|
26
|
+
* milliseconds between ticks. This is the same thing as install_int_ex(name,
|
27
|
+
* MSEC_TO_TIMER(speed)). If you call this routine without having first
|
28
|
+
* installed the timer module, install_timer will be called automatically.
|
29
|
+
* Calling again this routine with the same timer handler as parameter allows
|
30
|
+
* you to adjust its speed.
|
31
|
+
*
|
32
|
+
* Return value: Returns zero on success, or a negative number if there is no
|
33
|
+
* room to add a new user timer.
|
34
|
+
*
|
35
|
+
* *** The Ruby method differs from the Allegro method. The Allegro method takes
|
36
|
+
* a function pointer as the first parameter, which it will use as the timer
|
37
|
+
* interrupt callback. The Ruby method takes a name which will be used to
|
38
|
+
* identify a predefined counter routine which will be used as the interrupt
|
39
|
+
* callback. To get the value for that counter, call timer_counter_get with the
|
40
|
+
* name.
|
41
|
+
*/
|
42
|
+
VALUE a4r_API_install_int(VALUE self, VALUE name, VALUE speed)
|
43
|
+
{
|
44
|
+
VALUE t_speed = LONG2NUM(MSEC_TO_TIMER(FIX2INT(speed)));
|
45
|
+
return a4r_API_install_int_ex(self, name, t_speed);
|
46
|
+
}
|
47
|
+
|
48
|
+
/*
|
49
|
+
* call-seq:
|
50
|
+
* install_int_ex(name, speed) -> int
|
51
|
+
*
|
52
|
+
* Adds a function to the list of user timer handlers or, if it is already
|
53
|
+
* installed, retroactively adjusts its speed (i.e makes as though the speed
|
54
|
+
* change occurred precisely at the last tick). The speed is given in hardware
|
55
|
+
* clock ticks, of which there are 1193181 a second. You can convert from other
|
56
|
+
* time formats to hardware clock ticks with the macros:
|
57
|
+
* SECS_TO_TIMER(secs) - give the number of seconds between each tick
|
58
|
+
* MSEC_TO_TIMER(msec) - give the number of milliseconds between ticks
|
59
|
+
* BPS_TO_TIMER(bps) - give the number of ticks each second
|
60
|
+
* BPM_TO_TIMER(bpm) - give the number of ticks per minute
|
61
|
+
*
|
62
|
+
* There can only be sixteen timers in use at a time, and some other parts of
|
63
|
+
* Allegro (the GUI code, the mouse pointer display routines, rest, the FLI
|
64
|
+
* player, and the MIDI player) need to install handlers of their own, so you
|
65
|
+
* should avoid using too many at the same time. If you call this routine
|
66
|
+
* without having first installed the timer module, install_timer will be called
|
67
|
+
* automatically.
|
68
|
+
*
|
69
|
+
* Return value: Returns zero on success, or a negative number if there is no
|
70
|
+
* room to add a new user timer.
|
71
|
+
*
|
72
|
+
* *** The Ruby method differs from the Allegro method. The Allegro method takes
|
73
|
+
* a function pointer as the first parameter, which it will use as the timer
|
74
|
+
* interrupt callback. The Ruby method takes a name which will be used to
|
75
|
+
* identify a predefined counter routine which will be used as the interrupt
|
76
|
+
* callback. To get the value for that counter, call timer_counter_get with the
|
77
|
+
* name.
|
78
|
+
*/
|
79
|
+
VALUE a4r_API_install_int_ex(VALUE self, VALUE name, VALUE speed)
|
80
|
+
{
|
81
|
+
VALUE i = find_timer_counter(name);
|
82
|
+
if (i == Qnil)
|
83
|
+
{
|
84
|
+
i = find_free_timer_counter();
|
85
|
+
rb_hash_aset(timer_counter_names, name, i);
|
86
|
+
timer_counters[FIX2INT(i)] = 0;
|
87
|
+
}
|
88
|
+
|
89
|
+
return INT2FIX(install_param_int_ex(&timer_counter_incr, (void *)&(timer_counters[FIX2INT(i)]), NUM2INT(speed)));
|
90
|
+
}
|
91
|
+
|
92
|
+
/*
|
93
|
+
* call-seq:
|
94
|
+
* LOCK_VARIABLE(variable_name) -> nil
|
95
|
+
*
|
96
|
+
* Due to interrupts, you are required to lock all the memory used by your timer
|
97
|
+
* routines. See the description of install_int_ex for a more detailed
|
98
|
+
* explanation and usage example.
|
99
|
+
*
|
100
|
+
* *** The Ruby method differs from the Allegro method. Due to the use of
|
101
|
+
* predefined timer routines, LOCK_VARIABLE and LOCK_FUNCTION do nothing, and
|
102
|
+
* are here simply for API consistency. They will raise warnings if the Ruby
|
103
|
+
* script is run with -w.
|
104
|
+
*/
|
105
|
+
VALUE a4r_API_LOCK_VARIABLE(VALUE self, VALUE variable_name)
|
106
|
+
{
|
107
|
+
rb_warning("Allegro4r::API::LOCK_VARIABLE does nothing.");
|
108
|
+
return Qnil;
|
109
|
+
}
|
110
|
+
|
111
|
+
/*
|
112
|
+
* call-seq:
|
113
|
+
* LOCK_FUNCTION(function_name) -> nil
|
114
|
+
*
|
115
|
+
* See LOCK_VARIABLE.
|
116
|
+
*/
|
117
|
+
VALUE a4r_API_LOCK_FUNCTION(VALUE self, VALUE function_name)
|
118
|
+
{
|
119
|
+
rb_warning("Allegro4r::API::LOCK_FUNCTION does nothing.");
|
120
|
+
return Qnil;
|
121
|
+
}
|
122
|
+
|
123
|
+
/*
|
124
|
+
* call-seq:
|
125
|
+
* retrace_count -> int
|
126
|
+
*
|
127
|
+
* If the retrace simulator is installed, this count is incremented on each
|
128
|
+
* vertical retrace; otherwise, if the refresh rate is known, the count is
|
129
|
+
* incremented at the same rate (ignoring retraces); otherwise, it is
|
130
|
+
* incremented 70 times a second. This provides a way of controlling the speed
|
131
|
+
* of your program without installing user timer functions.
|
132
|
+
*/
|
133
|
+
VALUE a4r_API_retrace_count(VALUE self)
|
134
|
+
{
|
135
|
+
// TODO: Convert to data struct or cached or hooked variable?
|
136
|
+
return INT2FIX(retrace_count);
|
137
|
+
}
|
138
|
+
|
139
|
+
/*
|
140
|
+
* call-seq:
|
141
|
+
* rest(time) -> nil
|
142
|
+
*
|
143
|
+
* This function waits for the specified number of milliseconds.
|
144
|
+
*
|
145
|
+
* Passing 0 as parameter will not wait, but just yield. This can be useful in
|
146
|
+
* order to "play nice" with other processes. Other values will cause CPU time
|
147
|
+
* to be dropped on most platforms. This will look better to users, and also
|
148
|
+
* does things like saving battery power and making fans less noisy.
|
149
|
+
*
|
150
|
+
* Note that calling this inside your active game loop is a bad idea, as you
|
151
|
+
* never know when the OS will give you the CPU back, so you could end up
|
152
|
+
* missing the vertical retrace and skipping frames. On the other hand, on
|
153
|
+
* multitasking operating systems it is good form to give up the CPU for a while
|
154
|
+
* if you will not be using it.
|
155
|
+
*/
|
156
|
+
VALUE a4r_API_rest(VALUE self, VALUE time)
|
157
|
+
{
|
158
|
+
rest(NUM2UINT(time));
|
159
|
+
return Qnil;
|
160
|
+
}
|
161
|
+
|
162
|
+
/*
|
163
|
+
* call-seq:
|
164
|
+
* SECS_TO_TIMER(secs) -> num
|
165
|
+
*
|
166
|
+
* Give the number of seconds between each tick
|
167
|
+
*/
|
168
|
+
VALUE a4r_API_SECS_TO_TIMER(VALUE self, VALUE secs)
|
169
|
+
{
|
170
|
+
return LONG2NUM(SECS_TO_TIMER(NUM2LONG(secs)));
|
171
|
+
}
|
172
|
+
|
173
|
+
/*
|
174
|
+
* call-seq:
|
175
|
+
* MSEC_TO_TIMER(msec) -> num
|
176
|
+
*
|
177
|
+
* Give the number of milliseconds between ticks
|
178
|
+
*/
|
179
|
+
VALUE a4r_API_MSEC_TO_TIMER(VALUE self, VALUE msec)
|
180
|
+
{
|
181
|
+
return LONG2NUM(MSEC_TO_TIMER(NUM2LONG(msec)));
|
182
|
+
}
|
183
|
+
|
184
|
+
/*
|
185
|
+
* call-seq:
|
186
|
+
* BPS_TO_TIMER(bps) -> num
|
187
|
+
*
|
188
|
+
* Give the number of ticks each second
|
189
|
+
*/
|
190
|
+
VALUE a4r_API_BPS_TO_TIMER(VALUE self, VALUE bps)
|
191
|
+
{
|
192
|
+
return LONG2NUM(BPS_TO_TIMER(NUM2LONG(bps)));
|
193
|
+
}
|
194
|
+
|
195
|
+
/*
|
196
|
+
* call-seq:
|
197
|
+
* BPM_TO_TIMER(bpm) -> num
|
198
|
+
*
|
199
|
+
* Give the number of ticks per minute
|
200
|
+
*/
|
201
|
+
VALUE a4r_API_BPM_TO_TIMER(VALUE self, VALUE bpm)
|
202
|
+
{
|
203
|
+
return LONG2NUM(BPM_TO_TIMER(NUM2LONG(bpm)));
|
204
|
+
}
|
205
|
+
|
206
|
+
/******************************************************************************/
|
207
|
+
// Predefined timer counter routines
|
208
|
+
|
209
|
+
VALUE timer_counter_names;
|
210
|
+
volatile int timer_counters[MAX_TIMER_COUNTERS];
|
211
|
+
|
212
|
+
void timer_counter_incr(void *param)
|
213
|
+
{
|
214
|
+
*((int *)param) += 1;
|
215
|
+
}
|
216
|
+
END_OF_FUNCTION(timer_counter_incr)
|
217
|
+
|
218
|
+
VALUE find_timer_counter(VALUE name)
|
219
|
+
{
|
220
|
+
return rb_hash_aref(timer_counter_names, name);
|
221
|
+
}
|
222
|
+
|
223
|
+
VALUE find_free_timer_counter()
|
224
|
+
{
|
225
|
+
int i;
|
226
|
+
ID f = rb_intern("has_value?");
|
227
|
+
for (i = 0; i < MAX_TIMER_COUNTERS; i++)
|
228
|
+
if (rb_funcall(timer_counter_names, f, 1, INT2FIX(i)) == Qfalse)
|
229
|
+
break;
|
230
|
+
|
231
|
+
if (i == MAX_TIMER_COUNTERS)
|
232
|
+
return Qnil;
|
233
|
+
return INT2FIX(i);
|
234
|
+
}
|
235
|
+
|
236
|
+
/*
|
237
|
+
* call-seq:
|
238
|
+
* timer_counter_get(name) -> int
|
239
|
+
*
|
240
|
+
* Returns the value of the specified timer counter.
|
241
|
+
*
|
242
|
+
* *** This is not an Allegro method. See the Ruby note under install_int_ex.
|
243
|
+
*/
|
244
|
+
VALUE a4r_API_timer_counter_get(VALUE self, VALUE name)
|
245
|
+
{
|
246
|
+
VALUE i = find_timer_counter(name);
|
247
|
+
if (i == Qnil)
|
248
|
+
return i;
|
249
|
+
return INT2FIX(timer_counters[FIX2INT(i)]);
|
250
|
+
}
|