allegro4r 0.0.1-x86-mswin32-60
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 +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
data/examples/exmouse.rb
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
#
|
2
|
+
# Example program (C Version) for the Allegro library, by Shawn Hargreaves.
|
3
|
+
# (Ruby port by Jason Frey)
|
4
|
+
#
|
5
|
+
# This program demonstrates how to get mouse input. The
|
6
|
+
# first part of the test retrieves the raw mouse input data
|
7
|
+
# and displays it on the screen without using any mouse
|
8
|
+
# cursor. When you press a key the standard arrow-like mouse
|
9
|
+
# cursor appears. You are not restricted to this shape,
|
10
|
+
# and a second key press modifies the cursor to be several
|
11
|
+
# concentric colored circles. They are not joined together,
|
12
|
+
# so you can still see bits of what's behind when you move the
|
13
|
+
# cursor over the printed text message.
|
14
|
+
#
|
15
|
+
|
16
|
+
require 'rubygems'
|
17
|
+
require 'allegro4r'
|
18
|
+
include Allegro4r::API
|
19
|
+
|
20
|
+
def print_all_buttons
|
21
|
+
fc = makecol(0, 0, 0)
|
22
|
+
bc = makecol(255, 255, 255)
|
23
|
+
textprintf_right_ex(screen, font, 320, 50, fc, bc, "buttons")
|
24
|
+
(0...8).each do |i|
|
25
|
+
x = 320
|
26
|
+
y = 60 + i * 10
|
27
|
+
if (mouse_b & (1 << i)) != 0
|
28
|
+
textprintf_right_ex(screen, font, x, y, fc, bc, "%2d" % (1 + i))
|
29
|
+
else
|
30
|
+
textprintf_right_ex(screen, font, x, y, fc, bc, " ")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
mickeyx = 0
|
36
|
+
mickeyy = 0
|
37
|
+
c = 0
|
38
|
+
|
39
|
+
exit 1 if allegro_init != 0
|
40
|
+
install_keyboard
|
41
|
+
install_timer
|
42
|
+
|
43
|
+
if set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0
|
44
|
+
if set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0
|
45
|
+
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0)
|
46
|
+
allegro_message("Unable to set any graphic mode\n%s\n" % allegro_error)
|
47
|
+
exit 1
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
set_palette(desktop_palette)
|
52
|
+
clear_to_color(screen, makecol(255, 255, 255))
|
53
|
+
|
54
|
+
# Detect mouse presence
|
55
|
+
if install_mouse < 0
|
56
|
+
textout_centre_ex(screen, font, "No mouse detected, but you need one!", SCREEN_W()/2, SCREEN_H()/2, makecol(0, 0, 0), makecol(255, 255, 255))
|
57
|
+
readkey
|
58
|
+
exit 0
|
59
|
+
end
|
60
|
+
|
61
|
+
textprintf_centre_ex(screen, font, SCREEN_W()/2, 8, makecol(0, 0, 0), makecol(255, 255, 255), "Driver: %s" % mouse_driver.name)
|
62
|
+
|
63
|
+
loop do
|
64
|
+
# On most platforms (eg. DOS) things will still work correctly
|
65
|
+
# without this call, but it is a good idea to include it in any
|
66
|
+
# programs that you want to be portable, because on some platforms
|
67
|
+
# you may not be able to get any mouse input without it.
|
68
|
+
poll_mouse
|
69
|
+
|
70
|
+
acquire_screen
|
71
|
+
|
72
|
+
# the mouse position is stored in the variables mouse_x and mouse_y
|
73
|
+
textprintf_ex(screen, font, 16, 48, makecol(0, 0, 0), makecol(255, 255, 255), "mouse_x = %-5d" % mouse_x)
|
74
|
+
textprintf_ex(screen, font, 16, 64, makecol(0, 0, 0), makecol(255, 255, 255), "mouse_y = %-5d" % mouse_y)
|
75
|
+
|
76
|
+
# or you can use this function to measure the speed of movement.
|
77
|
+
# Note that we only call it every fourth time round the loop:
|
78
|
+
# there's no need for that other than to slow the numbers down
|
79
|
+
# a bit so that you will have time to read them...
|
80
|
+
c += 1
|
81
|
+
mickeyx, mickeyy = get_mouse_mickeys if (c & 3) == 0
|
82
|
+
|
83
|
+
textprintf_ex(screen, font, 16, 88, makecol(0, 0, 0), makecol(255, 255, 255), "mickey_x = %-7d" % mickeyx)
|
84
|
+
textprintf_ex(screen, font, 16, 104, makecol(0, 0, 0), makecol(255, 255, 255), "mickey_y = %-7d" % mickeyy)
|
85
|
+
|
86
|
+
# the mouse button state is stored in the variable mouse_b
|
87
|
+
if (mouse_b & 1) != 0
|
88
|
+
textout_ex(screen, font, "left button is pressed ", 16, 128, makecol(0, 0, 0), makecol(255, 255, 255))
|
89
|
+
else
|
90
|
+
textout_ex(screen, font, "left button not pressed", 16, 128, makecol(0, 0, 0), makecol(255, 255, 255))
|
91
|
+
end
|
92
|
+
|
93
|
+
if (mouse_b & 2) != 0
|
94
|
+
textout_ex(screen, font, "right button is pressed ", 16, 144, makecol(0, 0, 0), makecol(255, 255, 255))
|
95
|
+
else
|
96
|
+
textout_ex(screen, font, "right button not pressed", 16, 144, makecol(0, 0, 0), makecol(255, 255, 255))
|
97
|
+
end
|
98
|
+
|
99
|
+
if (mouse_b & 4) != 0
|
100
|
+
textout_ex(screen, font, "middle button is pressed ", 16, 160, makecol(0, 0, 0), makecol(255, 255, 255))
|
101
|
+
else
|
102
|
+
textout_ex(screen, font, "middle button not pressed", 16, 160, makecol(0, 0, 0), makecol(255, 255, 255))
|
103
|
+
end
|
104
|
+
|
105
|
+
# the wheel position is stored in the variable mouse_z
|
106
|
+
textprintf_ex(screen, font, 16, 184, makecol(0, 0, 0), makecol(255, 255, 255), "mouse_z = %-5d mouse_w = %-5d" % [mouse_z, mouse_w])
|
107
|
+
|
108
|
+
print_all_buttons
|
109
|
+
|
110
|
+
release_screen
|
111
|
+
|
112
|
+
vsync
|
113
|
+
|
114
|
+
break if keypressed
|
115
|
+
end
|
116
|
+
|
117
|
+
clear_keybuf
|
118
|
+
|
119
|
+
# To display a mouse pointer, call show_mouse(). There are several
|
120
|
+
# things you should be aware of before you do this, though. For one,
|
121
|
+
# it won't work unless you call install_timer() first. For another,
|
122
|
+
# you must never draw anything onto the screen while the mouse
|
123
|
+
# pointer is visible. So before you draw anything, be sure to turn
|
124
|
+
# the mouse off with show_mouse(NULL), and turn it back on again when
|
125
|
+
# you are done.
|
126
|
+
clear_to_color(screen, makecol(255, 255, 255))
|
127
|
+
textout_centre_ex(screen, font, "Press a key to change cursor", SCREEN_W()/2, SCREEN_H()/2, makecol(0, 0, 0), makecol(255, 255, 255))
|
128
|
+
show_mouse(screen)
|
129
|
+
readkey
|
130
|
+
show_mouse(nil)
|
131
|
+
|
132
|
+
# create a custom mouse cursor bitmap...
|
133
|
+
custom_cursor = create_bitmap(32, 32)
|
134
|
+
clear_to_color(custom_cursor, bitmap_mask_color(screen))
|
135
|
+
(0...8).each do |c|
|
136
|
+
circle(custom_cursor, 16, 16, c * 2, palette_color[c])
|
137
|
+
end
|
138
|
+
|
139
|
+
# select the custom cursor and set the focus point to the middle of it
|
140
|
+
set_mouse_sprite(custom_cursor)
|
141
|
+
set_mouse_sprite_focus(16, 16)
|
142
|
+
|
143
|
+
clear_to_color(screen, makecol(255, 255, 255))
|
144
|
+
textout_centre_ex(screen, font, "Press a key to quit", SCREEN_W()/2, SCREEN_H()/2, makecol(0, 0, 0), makecol(255, 255, 255))
|
145
|
+
show_mouse(screen)
|
146
|
+
readkey
|
147
|
+
show_mouse(nil)
|
148
|
+
|
149
|
+
destroy_bitmap(custom_cursor)
|
data/examples/expal.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
#
|
2
|
+
# Example program (C Version) for the Allegro library, by Shawn Hargreaves.
|
3
|
+
# (Ruby port by Jason Frey)
|
4
|
+
#
|
5
|
+
# This program demonstrates how to manipulate the palette. It draws
|
6
|
+
# a set of concentric circles onto the screen and animates them by
|
7
|
+
# cycling the palette.
|
8
|
+
#
|
9
|
+
|
10
|
+
require 'rubygems'
|
11
|
+
require 'allegro4r'
|
12
|
+
include Allegro4r::API
|
13
|
+
|
14
|
+
palette = PALETTE.new
|
15
|
+
|
16
|
+
exit 1 if allegro_init != 0
|
17
|
+
install_keyboard
|
18
|
+
if set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0
|
19
|
+
if set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) != 0
|
20
|
+
allegro_message("Error setting graphics mode\n%s\n" % allegro_error)
|
21
|
+
exit 1
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# first set the palette to black to hide what we are doing
|
26
|
+
set_palette(black_palette)
|
27
|
+
|
28
|
+
# draw some circles onto the screen
|
29
|
+
acquire_screen
|
30
|
+
|
31
|
+
255.downto(1) do |c|
|
32
|
+
circlefill(screen, SCREEN_W()/2, SCREEN_H()/2, c, c)
|
33
|
+
end
|
34
|
+
|
35
|
+
release_screen
|
36
|
+
|
37
|
+
install_mouse
|
38
|
+
show_mouse(screen)
|
39
|
+
|
40
|
+
# fill our palette with a gradually altering sequence of colors
|
41
|
+
(0...64).each do |c|
|
42
|
+
palette[c].r = c;
|
43
|
+
palette[c].g = 0;
|
44
|
+
palette[c].b = 0;
|
45
|
+
end
|
46
|
+
(64...128).each do |c|
|
47
|
+
palette[c].r = 127 - c;
|
48
|
+
palette[c].g = c - 64;
|
49
|
+
palette[c].b = 0;
|
50
|
+
end
|
51
|
+
(128...192).each do |c|
|
52
|
+
palette[c].r = 0;
|
53
|
+
palette[c].g = 191 - c;
|
54
|
+
palette[c].b = c - 128;
|
55
|
+
end
|
56
|
+
(192...256).each do |c|
|
57
|
+
palette[c].r = 0;
|
58
|
+
palette[c].g = 0;
|
59
|
+
palette[c].b = 255 - c;
|
60
|
+
end
|
61
|
+
|
62
|
+
# animate the image by rotating the palette
|
63
|
+
while !keypressed do
|
64
|
+
temp = palette[255].dup
|
65
|
+
255.downto(1) do |c|
|
66
|
+
palette[c] = palette[c - 1]
|
67
|
+
end
|
68
|
+
palette[0] = temp
|
69
|
+
set_palette(palette)
|
70
|
+
end
|
data/examples/expat.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
#
|
2
|
+
# Example program (C Version) for the Allegro library, by Shawn Hargreaves.
|
3
|
+
# (Ruby port by Jason Frey)
|
4
|
+
#
|
5
|
+
# This program demonstrates the use of patterned drawing and sub-bitmaps.
|
6
|
+
#
|
7
|
+
|
8
|
+
require 'rubygems'
|
9
|
+
require 'allegro4r'
|
10
|
+
include Allegro4r::API
|
11
|
+
|
12
|
+
def draw_pattern(bitmap, message, color)
|
13
|
+
acquire_bitmap(bitmap)
|
14
|
+
|
15
|
+
# create a pattern bitmap
|
16
|
+
pattern = create_bitmap(text_length(font, message), text_height(font))
|
17
|
+
clear_to_color(pattern, bitmap_mask_color(pattern))
|
18
|
+
textout_ex(pattern, font, message, 0, 0, palette_color[255], bitmap_mask_color(screen))
|
19
|
+
|
20
|
+
# cover the bitmap with the pattern
|
21
|
+
drawing_mode(DRAW_MODE_MASKED_PATTERN, pattern, 0, 0)
|
22
|
+
rectfill(bitmap, 0, 0, bitmap.w, bitmap.h, palette_color[color])
|
23
|
+
solid_mode
|
24
|
+
|
25
|
+
# destroy the pattern bitmap
|
26
|
+
destroy_bitmap(pattern)
|
27
|
+
|
28
|
+
release_bitmap(bitmap)
|
29
|
+
end
|
30
|
+
|
31
|
+
exit 1 if allegro_init != 0
|
32
|
+
install_keyboard
|
33
|
+
|
34
|
+
if set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0
|
35
|
+
if set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0
|
36
|
+
allegro_message("Unable to set any graphic mode\n%s\n" % allegro_error)
|
37
|
+
exit 1
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
set_palette(desktop_palette)
|
42
|
+
clear_to_color(screen, makecol(255, 255, 255))
|
43
|
+
|
44
|
+
# first cover the whole screen with a pattern
|
45
|
+
draw_pattern(screen, "<screen>", 255)
|
46
|
+
|
47
|
+
# draw the pattern onto a memory bitmap and then blit it to the screen
|
48
|
+
bitmap = create_bitmap(128, 32)
|
49
|
+
clear_to_color(bitmap, makecol(255, 255, 255))
|
50
|
+
draw_pattern(bitmap, "<memory>", 1)
|
51
|
+
masked_blit(bitmap, screen, 0, 0, 32, 32, 128, 32)
|
52
|
+
destroy_bitmap(bitmap)
|
53
|
+
|
54
|
+
# or we could use a sub-bitmap. These share video memory with their
|
55
|
+
# parent, so the drawing will be visible without us having to blit it
|
56
|
+
# across onto the screen.
|
57
|
+
bitmap = create_sub_bitmap(screen, 224, 64, 64, 128)
|
58
|
+
rectfill(screen, 224, 64, 286, 192, makecol(255, 255, 255))
|
59
|
+
draw_pattern(bitmap, "<subbmp>", 4)
|
60
|
+
destroy_bitmap(bitmap)
|
61
|
+
|
62
|
+
readkey
|
@@ -0,0 +1,89 @@
|
|
1
|
+
#
|
2
|
+
# Example program (C Version) for the Allegro library, by Shawn Hargreaves.
|
3
|
+
# (Ruby port by Jason Frey)
|
4
|
+
#
|
5
|
+
# This program demonstrates how to play samples. You have to
|
6
|
+
# use this example from the command line to specify as first
|
7
|
+
# parameter a WAV or VOC sound file to play. If the file is
|
8
|
+
# loaded successfully, the sound will be played in an infinite
|
9
|
+
# loop. While it is being played, you can use the left and right
|
10
|
+
# arrow keys to modify the panning of the sound. You can also
|
11
|
+
# use the up and down arrow keys to modify the pitch.
|
12
|
+
#
|
13
|
+
|
14
|
+
require 'rubygems'
|
15
|
+
require 'allegro4r'
|
16
|
+
include Allegro4r::API
|
17
|
+
|
18
|
+
pan = 128
|
19
|
+
pitch = 1000
|
20
|
+
|
21
|
+
exit 1 if allegro_init != 0
|
22
|
+
|
23
|
+
if ARGV.length != 1
|
24
|
+
allegro_message("Usage: 'ruby exsample.rb filename.[wav|voc]'\n")
|
25
|
+
exit 1
|
26
|
+
end
|
27
|
+
|
28
|
+
install_keyboard
|
29
|
+
install_timer
|
30
|
+
|
31
|
+
# install a digital sound driver
|
32
|
+
if install_sound(DIGI_AUTODETECT, MIDI_NONE, nil) != 0
|
33
|
+
allegro_message("Error initialising sound system\n%s\n" % allegro_error)
|
34
|
+
exit 1
|
35
|
+
end
|
36
|
+
|
37
|
+
# read in the WAV file
|
38
|
+
the_sample = load_sample(ARGV[0])
|
39
|
+
if the_sample.nil?
|
40
|
+
allegro_message("Error reading WAV file '%s'\n" % ARGV[0])
|
41
|
+
exit 1
|
42
|
+
end
|
43
|
+
|
44
|
+
if set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0
|
45
|
+
if set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0
|
46
|
+
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0)
|
47
|
+
allegro_message("Unable to set any graphic mode\n%s\n" % allegro_error)
|
48
|
+
exit 1
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
set_palette(desktop_palette)
|
53
|
+
clear_to_color(screen, makecol(255,255,255))
|
54
|
+
|
55
|
+
textprintf_centre_ex(screen, font, SCREEN_W()/2, SCREEN_H()/3, makecol(0, 0, 0), -1, "Driver: %s" % digi_driver.name)
|
56
|
+
textprintf_centre_ex(screen, font, SCREEN_W()/2, SCREEN_H()/2, makecol(0, 0, 0), -1, "Playing %s" % ARGV[0])
|
57
|
+
textprintf_centre_ex(screen, font, SCREEN_W()/2, SCREEN_H()*2/3, makecol(0, 0, 0), -1, "Use the arrow keys to adjust it")
|
58
|
+
|
59
|
+
# start up the sample
|
60
|
+
play_sample(the_sample, 255, pan, pitch, true)
|
61
|
+
|
62
|
+
loop do
|
63
|
+
poll_keyboard
|
64
|
+
|
65
|
+
# alter the pan position?
|
66
|
+
if key[KEY_LEFT] && pan > 0
|
67
|
+
pan -= 1
|
68
|
+
elsif key[KEY_RIGHT] && pan < 255
|
69
|
+
pan += 1
|
70
|
+
end
|
71
|
+
|
72
|
+
# alter the pitch?
|
73
|
+
if key[KEY_UP] && pitch < 16384
|
74
|
+
pitch = ((pitch * 513) / 512) + 1
|
75
|
+
elsif key[KEY_DOWN] && pitch > 64
|
76
|
+
pitch = ((pitch * 511) / 512) - 1
|
77
|
+
end
|
78
|
+
|
79
|
+
# adjust the sample
|
80
|
+
adjust_sample(the_sample, 255, pan, pitch, true)
|
81
|
+
|
82
|
+
# delay a bit
|
83
|
+
rest(2)
|
84
|
+
|
85
|
+
break unless !key[KEY_ESC] && !key[KEY_SPACE]
|
86
|
+
end
|
87
|
+
|
88
|
+
# destroy the sample
|
89
|
+
destroy_sample(the_sample)
|
data/examples/extimer.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
#
|
2
|
+
# Example program (C Version) for the Allegro library, by Shawn Hargreaves.
|
3
|
+
# (Ruby port by Jason Frey)
|
4
|
+
#
|
5
|
+
# This program demonstrates how to use the timer routines.
|
6
|
+
# These can be a bit of a pain, because you have to be sure
|
7
|
+
# you lock all the memory that is used inside your interrupt
|
8
|
+
# handlers. The first part of the example shows a basic use of
|
9
|
+
# timing using the blocking function rest(). The second part
|
10
|
+
# shows how to use three timers with different frequencies in
|
11
|
+
# a non blocking way.
|
12
|
+
#
|
13
|
+
# JF - Counters based on timer interrupts cannot be done directly though Ruby,
|
14
|
+
# so instead, we can use predefined timer counters. They can be installed by
|
15
|
+
# name with install_int or install_int_ex. The values can be retrieved through
|
16
|
+
# timer_counter_get.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'rubygems'
|
20
|
+
require 'allegro4r'
|
21
|
+
include Allegro4r::API
|
22
|
+
|
23
|
+
exit 1 if allegro_init != 0
|
24
|
+
install_keyboard
|
25
|
+
install_timer
|
26
|
+
|
27
|
+
if set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0
|
28
|
+
if set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0
|
29
|
+
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0)
|
30
|
+
allegro_message("Unable to set any graphic mode\n%s\n" % allegro_error)
|
31
|
+
exit 1
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
set_palette(desktop_palette)
|
36
|
+
clear_to_color(screen, makecol(255, 255, 255))
|
37
|
+
|
38
|
+
textprintf_centre_ex(screen, font, SCREEN_W()/2, 8, makecol(0, 0, 0), makecol(255, 255, 255), "Driver: %s" % timer_driver.name)
|
39
|
+
|
40
|
+
# use rest to delay for a specified number of milliseconds
|
41
|
+
textprintf_centre_ex(screen, font, SCREEN_W()/2, 48, makecol(0, 0, 0), makecol(255, 255, 255), "Timing five seconds:")
|
42
|
+
|
43
|
+
(1..5).each do |c|
|
44
|
+
textprintf_centre_ex(screen, font, SCREEN_W()/2, 62 + c * 10, makecol(0, 0, 0), makecol(255, 255, 255), "%d" % c)
|
45
|
+
rest(1000)
|
46
|
+
end
|
47
|
+
|
48
|
+
textprintf_centre_ex(screen, font, SCREEN_W()/2, 142, makecol(0, 0, 0), makecol(255, 255, 255), "Press a key to set up interrupts")
|
49
|
+
readkey
|
50
|
+
|
51
|
+
# JF - Since we are using predefined timer routines, LOCK_VARIABLE and
|
52
|
+
# LOCK_FUNCTION do nothing, and are here simply for API consistency. They will
|
53
|
+
# raise warnings if the Ruby script is run with -w.
|
54
|
+
|
55
|
+
# all variables and code used inside interrupt handlers must be locked
|
56
|
+
LOCK_VARIABLE(:x)
|
57
|
+
LOCK_VARIABLE(:y)
|
58
|
+
LOCK_VARIABLE(:z)
|
59
|
+
LOCK_FUNCTION(:inc_x)
|
60
|
+
LOCK_FUNCTION(:inc_y)
|
61
|
+
LOCK_FUNCTION(:inc_z)
|
62
|
+
|
63
|
+
# JF - install_int and install_int_ex take a name as their first parameter
|
64
|
+
# which can then be used to subsequent calls to timer_counter_get.
|
65
|
+
|
66
|
+
# the speed can be specified in milliseconds (this is once a second)
|
67
|
+
install_int(:inc_x, 1000)
|
68
|
+
|
69
|
+
# or in beats per second (this is 10 ticks a second)
|
70
|
+
install_int_ex(:inc_y, BPS_TO_TIMER(10))
|
71
|
+
|
72
|
+
# or in seconds (this is 10 seconds a tick)
|
73
|
+
install_int_ex(:inc_z, SECS_TO_TIMER(10))
|
74
|
+
|
75
|
+
# the interrupts are now active...
|
76
|
+
while !keypressed
|
77
|
+
# JF - Get the values from the timer interrupt counters with
|
78
|
+
# timer_counter_get
|
79
|
+
x = timer_counter_get(:inc_x)
|
80
|
+
y = timer_counter_get(:inc_y)
|
81
|
+
z = timer_counter_get(:inc_z)
|
82
|
+
|
83
|
+
textprintf_centre_ex(screen, font, SCREEN_W()/2, 176, makecol(0, 0, 0), makecol(255, 255, 255), "x=%d, y=%d, z=%d" % [x, y, z])
|
84
|
+
end
|
Binary file
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#include "allegro4r.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
* call-seq:
|
5
|
+
* bmp.h -> int
|
6
|
+
*
|
7
|
+
* Returns the height of the BITMAP in pixels.
|
8
|
+
*/
|
9
|
+
VALUE a4r_API_BITMAP_h_get(VALUE self)
|
10
|
+
{
|
11
|
+
BITMAP *bitmap;
|
12
|
+
Data_Get_Struct(self, BITMAP, bitmap);
|
13
|
+
return INT2FIX(bitmap->h);
|
14
|
+
}
|
15
|
+
|
16
|
+
/*
|
17
|
+
* call-seq:
|
18
|
+
* bmp.w -> int
|
19
|
+
*
|
20
|
+
* Returns the width of the BITMAP in pixels.
|
21
|
+
*/
|
22
|
+
VALUE a4r_API_BITMAP_w_get(VALUE self)
|
23
|
+
{
|
24
|
+
BITMAP *bitmap;
|
25
|
+
Data_Get_Struct(self, BITMAP, bitmap);
|
26
|
+
return INT2FIX(bitmap->w);
|
27
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#include "allegro4r.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
* call-seq:
|
5
|
+
* driver.name -> str
|
6
|
+
*
|
7
|
+
* Driver name
|
8
|
+
*/
|
9
|
+
VALUE a4r_API_DIGI_DRIVER_name_get(VALUE self)
|
10
|
+
{
|
11
|
+
DIGI_DRIVER *driver;
|
12
|
+
Data_Get_Struct(self, DIGI_DRIVER, driver);
|
13
|
+
return rb_str_new2(driver->name);
|
14
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#include "allegro4r.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
* call-seq:
|
5
|
+
* driver.name -> str
|
6
|
+
*
|
7
|
+
* Returns the name of the graphics driver.
|
8
|
+
*/
|
9
|
+
VALUE a4r_API_GFX_DRIVER_name_get(VALUE self)
|
10
|
+
{
|
11
|
+
GFX_DRIVER *driver;
|
12
|
+
Data_Get_Struct(self, GFX_DRIVER, driver);
|
13
|
+
return rb_str_new2(driver->name);
|
14
|
+
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#include "allegro4r.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
* call-seq:
|
5
|
+
* jai.pos -> int
|
6
|
+
*
|
7
|
+
* Analogue axis position
|
8
|
+
*/
|
9
|
+
VALUE a4r_API_JOYSTICK_AXIS_INFO_pos(VALUE self)
|
10
|
+
{
|
11
|
+
JOYSTICK_AXIS_INFO *jai;
|
12
|
+
Data_Get_Struct(self, JOYSTICK_AXIS_INFO, jai);
|
13
|
+
return INT2FIX(jai->pos);
|
14
|
+
}
|
15
|
+
|
16
|
+
/*
|
17
|
+
* call-seq:
|
18
|
+
* jai.d1 -> true or false
|
19
|
+
*
|
20
|
+
* Digital axis position
|
21
|
+
*/
|
22
|
+
VALUE a4r_API_JOYSTICK_AXIS_INFO_d1(VALUE self)
|
23
|
+
{
|
24
|
+
JOYSTICK_AXIS_INFO *jai;
|
25
|
+
Data_Get_Struct(self, JOYSTICK_AXIS_INFO, jai);
|
26
|
+
return jai->d1 ? Qtrue : Qfalse;
|
27
|
+
}
|
28
|
+
|
29
|
+
/*
|
30
|
+
* call-seq:
|
31
|
+
* jai.d2 -> true or false
|
32
|
+
*
|
33
|
+
* Digital axis position
|
34
|
+
*/
|
35
|
+
VALUE a4r_API_JOYSTICK_AXIS_INFO_d2(VALUE self)
|
36
|
+
{
|
37
|
+
JOYSTICK_AXIS_INFO *jai;
|
38
|
+
Data_Get_Struct(self, JOYSTICK_AXIS_INFO, jai);
|
39
|
+
return jai->d2 ? Qtrue : Qfalse;
|
40
|
+
}
|
41
|
+
|
42
|
+
/*
|
43
|
+
* call-seq:
|
44
|
+
* jai.name -> int
|
45
|
+
*
|
46
|
+
* Description of this axis
|
47
|
+
*/
|
48
|
+
VALUE a4r_API_JOYSTICK_AXIS_INFO_name(VALUE self)
|
49
|
+
{
|
50
|
+
JOYSTICK_AXIS_INFO *jai;
|
51
|
+
Data_Get_Struct(self, JOYSTICK_AXIS_INFO, jai);
|
52
|
+
return rb_str_new2(jai->name);
|
53
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#include "allegro4r.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
* call-seq:
|
5
|
+
* jbi.b -> true or false
|
6
|
+
*
|
7
|
+
* Boolean on/off flag
|
8
|
+
*/
|
9
|
+
VALUE a4r_API_JOYSTICK_BUTTON_INFO_b(VALUE self)
|
10
|
+
{
|
11
|
+
JOYSTICK_BUTTON_INFO *jbi;
|
12
|
+
Data_Get_Struct(self, JOYSTICK_BUTTON_INFO, jbi);
|
13
|
+
return jbi->b ? Qtrue : Qfalse;
|
14
|
+
}
|
15
|
+
|
16
|
+
/*
|
17
|
+
* call-seq:
|
18
|
+
* jbi.name -> str
|
19
|
+
*
|
20
|
+
* Description of this button
|
21
|
+
*/
|
22
|
+
VALUE a4r_API_JOYSTICK_BUTTON_INFO_name(VALUE self)
|
23
|
+
{
|
24
|
+
JOYSTICK_BUTTON_INFO *jbi;
|
25
|
+
Data_Get_Struct(self, JOYSTICK_BUTTON_INFO, jbi);
|
26
|
+
return rb_str_new2(jbi->name);
|
27
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#include "allegro4r.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
* call-seq:
|
5
|
+
* driver.name -> str
|
6
|
+
*
|
7
|
+
* Returns the name of the joystick driver.
|
8
|
+
*/
|
9
|
+
VALUE a4r_API_JOYSTICK_DRIVER_name_get(VALUE self)
|
10
|
+
{
|
11
|
+
JOYSTICK_DRIVER *driver;
|
12
|
+
Data_Get_Struct(self, JOYSTICK_DRIVER, driver);
|
13
|
+
return rb_str_new2(driver->name);
|
14
|
+
}
|
@@ -0,0 +1,84 @@
|
|
1
|
+
#include "allegro4r.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
* call-seq:
|
5
|
+
* ji.flags -> int
|
6
|
+
*
|
7
|
+
* Status flags for this joystick
|
8
|
+
*/
|
9
|
+
VALUE a4r_API_JOYSTICK_INFO_flags(VALUE self)
|
10
|
+
{
|
11
|
+
JOYSTICK_INFO *ji;
|
12
|
+
Data_Get_Struct(self, JOYSTICK_INFO, ji);
|
13
|
+
return INT2NUM(ji->flags);
|
14
|
+
}
|
15
|
+
|
16
|
+
/*
|
17
|
+
* call-seq:
|
18
|
+
* ji.num_sticks -> int
|
19
|
+
*
|
20
|
+
* How many stick inputs?
|
21
|
+
*/
|
22
|
+
VALUE a4r_API_JOYSTICK_INFO_num_sticks(VALUE self)
|
23
|
+
{
|
24
|
+
JOYSTICK_INFO *ji;
|
25
|
+
Data_Get_Struct(self, JOYSTICK_INFO, ji);
|
26
|
+
return INT2FIX(ji->num_sticks);
|
27
|
+
}
|
28
|
+
|
29
|
+
/*
|
30
|
+
* call-seq:
|
31
|
+
* ji.num_buttons -> int
|
32
|
+
*
|
33
|
+
* How many buttons?
|
34
|
+
*/
|
35
|
+
VALUE a4r_API_JOYSTICK_INFO_num_buttons(VALUE self)
|
36
|
+
{
|
37
|
+
JOYSTICK_INFO *ji;
|
38
|
+
Data_Get_Struct(self, JOYSTICK_INFO, ji);
|
39
|
+
return INT2FIX(ji->num_buttons);
|
40
|
+
}
|
41
|
+
|
42
|
+
/*
|
43
|
+
* call-seq:
|
44
|
+
* ji.stick -> ary
|
45
|
+
*
|
46
|
+
* Stick state information
|
47
|
+
*/
|
48
|
+
VALUE a4r_API_JOYSTICK_INFO_stick(VALUE self)
|
49
|
+
{
|
50
|
+
JOYSTICK_INFO *ji;
|
51
|
+
Data_Get_Struct(self, JOYSTICK_INFO, ji);
|
52
|
+
|
53
|
+
VALUE ret = rb_ary_new2(ji->num_sticks);
|
54
|
+
long x;
|
55
|
+
for (x = 0; x < ji->num_sticks; x++)
|
56
|
+
{
|
57
|
+
VALUE obj = Data_Wrap_Struct(cAPI_JOYSTICK_STICK_INFO, 0, 0, &(ji->stick[x]));
|
58
|
+
rb_ary_store(ret, x, obj);
|
59
|
+
}
|
60
|
+
|
61
|
+
return ret;
|
62
|
+
}
|
63
|
+
|
64
|
+
/*
|
65
|
+
* call-seq:
|
66
|
+
* ji.button -> ary
|
67
|
+
*
|
68
|
+
* Button state information
|
69
|
+
*/
|
70
|
+
VALUE a4r_API_JOYSTICK_INFO_button(VALUE self)
|
71
|
+
{
|
72
|
+
JOYSTICK_INFO *ji;
|
73
|
+
Data_Get_Struct(self, JOYSTICK_INFO, ji);
|
74
|
+
|
75
|
+
VALUE ret = rb_ary_new2(ji->num_buttons);
|
76
|
+
long x;
|
77
|
+
for (x = 0; x < ji->num_buttons; x++)
|
78
|
+
{
|
79
|
+
VALUE obj = Data_Wrap_Struct(cAPI_JOYSTICK_BUTTON_INFO, 0, 0, &(ji->button[x]));
|
80
|
+
rb_ary_store(ret, x, obj);
|
81
|
+
}
|
82
|
+
|
83
|
+
return ret;
|
84
|
+
}
|