retrograph 0.5-x86-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/COPYING +19 -0
  2. data/README +264 -0
  3. data/Rakefile +71 -0
  4. data/ext/retrograph/extconf.rb +6 -0
  5. data/ext/retrograph/retrograph.c +324 -0
  6. data/lib/retrograph/sdl.rb +26 -0
  7. data/lib/retrograph.rb +29 -0
  8. data/lib/retrograph.so +0 -0
  9. data/spec/image-specs/color-blue-bits.case +2 -0
  10. data/spec/image-specs/color-blue-bits.png +0 -0
  11. data/spec/image-specs/color-green-bits.case +2 -0
  12. data/spec/image-specs/color-green-bits.png +0 -0
  13. data/spec/image-specs/color-red-bits.case +2 -0
  14. data/spec/image-specs/color-red-bits.png +0 -0
  15. data/spec/image-specs/default-screen-black.case +1 -0
  16. data/spec/image-specs/default-screen-black.png +0 -0
  17. data/spec/image-specs/default-screen-color-0.case +2 -0
  18. data/spec/image-specs/default-screen-color-0.png +0 -0
  19. data/spec/image-specs/scroll-mode1.case +7 -0
  20. data/spec/image-specs/scroll-mode1.png +0 -0
  21. data/spec/image-specs/scroll-mode2.case +10 -0
  22. data/spec/image-specs/scroll-mode2.png +0 -0
  23. data/spec/image-specs/scroll-mode3.case +10 -0
  24. data/spec/image-specs/scroll-mode3.png +0 -0
  25. data/spec/image-specs/sprites-doubling.case +5 -0
  26. data/spec/image-specs/sprites-doubling.png +0 -0
  27. data/spec/image-specs/sprites-mode2.case +8 -0
  28. data/spec/image-specs/sprites-mode2.png +0 -0
  29. data/spec/image-specs/sprites-mode3.case +8 -0
  30. data/spec/image-specs/sprites-mode3.png +0 -0
  31. data/spec/image-specs/sprites-ordering.case +5 -0
  32. data/spec/image-specs/sprites-ordering.png +0 -0
  33. data/spec/image-specs/text-colors.case +5 -0
  34. data/spec/image-specs/text-colors.png +0 -0
  35. data/spec/image-specs/tile-attributes-mode2.case +9 -0
  36. data/spec/image-specs/tile-attributes-mode2.png +0 -0
  37. data/spec/image-specs/tile-attributes-mode3.case +9 -0
  38. data/spec/image-specs/tile-attributes-mode3.png +0 -0
  39. data/spec/retrograph_spec.rb +134 -0
  40. data/src/retrograph.c +697 -0
  41. data/src/retrograph.h +67 -0
  42. metadata +99 -0
@@ -0,0 +1,26 @@
1
+ # retrograph/sdl
2
+ #
3
+ # Copyright (c) 2009 MenTaLguY <mental@rydia.net>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require 'retrograph'
24
+ require 'sdl'
25
+
26
+ Retrograph._init_sdl
data/lib/retrograph.rb ADDED
@@ -0,0 +1,29 @@
1
+ # retrograph
2
+ #
3
+ # Copyright (c) 2009 MenTaLguY <mental@rydia.net>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+ #
23
+
24
+ # augment search path for fat binary gems
25
+ ruby_version = /^\d+\.\d+/.match(RUBY_VERSION)[0]
26
+ base_dir = File.dirname(__FILE__)
27
+ $:.push File.join(base_dir, ruby_version)
28
+
29
+ require 'retrograph.so'
data/lib/retrograph.so ADDED
Binary file
@@ -0,0 +1,2 @@
1
+ should use color bits 0-1 for blue
2
+ 7f00: 03
@@ -0,0 +1,2 @@
1
+ should use color bits 2-3 for green
2
+ 7f00: 0c
@@ -0,0 +1,2 @@
1
+ should use color bits 4-5 for red
2
+ 7f00: 30
Binary file
@@ -0,0 +1 @@
1
+ should fill the screen with black by default
@@ -0,0 +1,2 @@
1
+ should fill the screen with color 0 by default
2
+ 7f00: ff
@@ -0,0 +1,7 @@
1
+ should support text-style scrolling in mode 1
2
+ 7ff8: 05
3
+ 7ffc: 0c 0c
4
+ 7f00: 00 ff
5
+ 0008: 01 03 07 0f 1f 3f 7f ff ff 7f 3f 1f 0f 07 03 01
6
+ 0800: 0101
7
+ 0840: 0102
Binary file
@@ -0,0 +1,10 @@
1
+ should support smooth scrolling in mode 2
2
+ 7ff8: 06
3
+ 7ffc: 0c 84
4
+ 7f00: 00 ff
5
+ 0010: 0001 0005 0015 0055 0155 0555 1555 5555
6
+ 0020: 5555 1555 0555 0155 0055 0015 0005 0001
7
+ 0030: 1111 4444 1111 4444 1111 4444 1111 4444
8
+ 0c00: 0002
9
+ 0ac0: 0001
10
+ 0b00: 0003
Binary file
@@ -0,0 +1,10 @@
1
+ should support smooth scrolling in mode 3
2
+ 7ff8: 07
3
+ 7ffc: 0c 84
4
+ 7f00: 00 ff
5
+ 0020: 00000001 00000011 00000111 00001111 00011111 00111111 01111111 11111111
6
+ 0040: 11111111 01111111 00111111 00011111 00001111 00000111 00000011 00000001
7
+ 0060: 01010101 10101010 01010101 10101010 01010101 10101010 01010101 10101010
8
+ 0c00: 0002
9
+ 0ac0: 0001
10
+ 0b00: 0003
Binary file
@@ -0,0 +1,5 @@
1
+ should render doubled sprites
2
+ 7ff8: 0b
3
+ 7f10: 00 3f
4
+ 7e00: 00 01 0001 10 01 0801 00 11 0401 10 11 0c01
5
+ 2020: 10101010 01010101 10101010 01010101 10101010 01010101 10101010 01010101
@@ -0,0 +1,8 @@
1
+ should show first 8 sprites per line in mode 2
2
+ 7ff8: 0a
3
+ 7f10: 00 02 08 0a 20 22 38 2a 15 17 1d 1f 35 37 3d 3f
4
+ 7e00: 00 01 0001 08 01 0002 10 01 0101 18 01 0102
5
+ 7e10: 20 01 0201 28 01 0202 30 01 0301 38 01 0302
6
+ 7e20: 40 01 0001 48 01 0002 50 01 0001 58 01 0002
7
+ 2020: 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111
8
+ 2040: 20202020 02020202 20202020 02020202 20202020 02020202 20202020 02020202
Binary file
@@ -0,0 +1,8 @@
1
+ should show first 8 sprites per line in mode 3
2
+ 7ff8: 0b
3
+ 7f10: 00 02 08 0a 20 22 38 2a 15 17 1d 1f 35 37 3d 3f
4
+ 7e00: 00 01 0001 08 01 0002 10 01 0101 18 01 0102
5
+ 7e10: 20 01 0201 28 01 0202 30 01 0301 38 01 0302
6
+ 7e20: 40 01 0001 48 01 0002 50 01 0001 58 01 0002
7
+ 2020: 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111
8
+ 2040: 20202020 02020202 20202020 02020202 20202020 02020202 20202020 02020202
Binary file
@@ -0,0 +1,5 @@
1
+ should render lower-numbered sprites over higher-numbered ones
2
+ 7ff8: 0b
3
+ 7f10: 00 30 00 00 00 0c 00 00
4
+ 7e00: 00 01 0001 04 05 0101
5
+ 2020: 10101010 01010101 10101010 01010101 10101010 01010101 10101010 01010101
@@ -0,0 +1,5 @@
1
+ should allow setting cell fg and bg colors in text mode
2
+ 7ff8: 05
3
+ 7f00: 03 0c 30
4
+ 0000: ff ff ff ff 00 00 00 00
5
+ 0800: 1200
Binary file
@@ -0,0 +1,9 @@
1
+ should implement tile attributes in mode 2
2
+ 7ff8: 06
3
+ 7f00: 00 02 08 0a 20 22 38 2a 15 17 1d 1f 35 37 3d 3f
4
+ 7f10: 3f 3d 37 35 1f 1d 17 15 2a 38 22 20 0a 08 02 00
5
+ 0010: 5500 5500 5500 5500 ffaa ffaa ffaa ffaa
6
+ 0800: 0001 0201 0401 0601 0801 0a01 0c01 0e01
7
+ 0840: 1001 1201 1401 1601 1801 1a01 1c01 1e01
8
+ 0880: 2001 2201 2401 2601 2801 2a01 2c01 2e01
9
+ 08c0: 3001 3201 3401 3601 3801 3a01 3c01 3e01
@@ -0,0 +1,9 @@
1
+ should implement tile attributes in mode 3
2
+ 7ff8: 07
3
+ 7f00: 00 02 08 0a 20 22 38 2a 15 17 1d 1f 35 37 3d 3f
4
+ 7f10: 3f 3d 37 35 1f 1d 17 15 2a 38 22 20 0a 08 02 00
5
+ 0020: 33221100 33221100 77665544 77665544 bbaa9988 bbaa9988 ffeeddcc ffeeddcc
6
+ 0800: 0001 0201 0401 0601 0801 0a01 0c01 0e01
7
+ 0840: 1001 1201 1401 1601 1801 1a01 1c01 1e01
8
+ 0880: 2001 2201 2401 2601 2801 2a01 2c01 2e01
9
+ 08c0: 3001 3201 3401 3601 3801 3a01 3c01 3e01
@@ -0,0 +1,134 @@
1
+ require 'retrograph/sdl'
2
+
3
+ describe Retrograph do
4
+ constants = [
5
+ [:DISPLAY_WIDTH, 256],
6
+ [:DISPLAY_HEIGHT, 224],
7
+ [:OUTPUT_WIDTH, 512],
8
+ [:OUTPUT_HEIGHT, 448],
9
+ [:BYTES_PER_PIXEL, 4],
10
+ [:BITS_PER_PIXEL, 32],
11
+ [:RED_SHIFT, 16],
12
+ [:GREEN_SHIFT, 8],
13
+ [:BLUE_SHIFT, 0],
14
+ [:RED_MASK, 0x00ff0000],
15
+ [:GREEN_MASK, 0x0000ff00],
16
+ [:BLUE_MASK, 0x000000ff],
17
+ [:ALPHA_MASK, 0x00000000]
18
+ ]
19
+ for name, value in constants
20
+ it "should define #{name} as #{value}" do
21
+ Retrograph.const_get(name).should == value
22
+ end
23
+ end
24
+ end
25
+
26
+ module ImageTests
27
+ RMASK = Retrograph::RED_MASK
28
+ GMASK = Retrograph::GREEN_MASK
29
+ BMASK = Retrograph::BLUE_MASK
30
+ AMASK = Retrograph::ALPHA_MASK
31
+
32
+ def build_image_specs(spec_dir)
33
+ Dir.open(spec_dir) do |dir|
34
+ dir.each do |name|
35
+ parts = name.split('.')
36
+ extension = parts.pop
37
+ next unless extension == 'case'
38
+ case_file = File.join(spec_dir, name)
39
+ parts.push 'png'
40
+ image_file = File.join(spec_dir, parts.join('.'))
41
+ build_image_spec(case_file, image_file)
42
+ end
43
+ end
44
+ end
45
+
46
+ def build_image_spec(case_file, image_file)
47
+ description = nil
48
+ writes = []
49
+
50
+ File.open(case_file, "r") do |stream|
51
+ description = stream.readline.strip
52
+ stream.each_line do |line|
53
+ offset, data = line.split(':').map { |t| t.strip }
54
+ data, offset = offset, nil unless data
55
+ data = data.split(/\s+/).map { |w| w.scan(/[a-zA-Z0-9]{2}/).reverse }
56
+ data = data.map { |w| [w.join('')].pack("H*") }.join('')
57
+ offset = Integer("0x#{offset}")
58
+ unless data.empty?
59
+ if offset
60
+ writes << [offset, data]
61
+ else
62
+ writes.last[1] << data
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ it description do
69
+ vdu = Retrograph::VDU.new
70
+ for offset, data in writes
71
+ vdu.write(offset, data)
72
+ end
73
+ output_image = vdu.render_frame_sdl
74
+ output_file = image_file.sub(/\.[^.]*$/, '-output.bmp')
75
+ output_image.save_bmp(output_file)
76
+
77
+ raw_image = SDL::Surface.load(image_file)
78
+ raw_image.set_alpha(0, SDL::ALPHA_OPAQUE)
79
+ raw_image.set_color_key(0, 0)
80
+ reference_image = SDL::Surface.new(0, raw_image.w, raw_image.h, 32,
81
+ RMASK, GMASK, BMASK, AMASK)
82
+ SDL::Surface.blit(raw_image, 0, 0, 0, 0, reference_image, 0, 0)
83
+ raw_image = nil
84
+ if output_image.pixels != reference_image.pixels
85
+ raise "Output does not match."
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ describe Retrograph::VDU do
92
+ before do
93
+ @vdu = Retrograph::VDU.new
94
+ end
95
+
96
+ it "should render to a surface with the right characteristics" do
97
+ surface = @vdu.render_frame_sdl
98
+ surface.should be_an_instance_of(SDL::Surface)
99
+ surface.flags.should == 0
100
+ surface.w.should == Retrograph::OUTPUT_WIDTH
101
+ surface.h.should == Retrograph::OUTPUT_HEIGHT
102
+ surface.bpp.should == Retrograph::BITS_PER_PIXEL
103
+ surface.Rmask.should == Retrograph::RED_MASK
104
+ surface.Gmask.should == Retrograph::GREEN_MASK
105
+ surface.Bmask.should == Retrograph::BLUE_MASK
106
+ surface.Amask.should == Retrograph::ALPHA_MASK
107
+ end
108
+
109
+ it "should have a write method which takes an offset and a byte string" do
110
+ @vdu.write(0x0001, "foobar")
111
+ end
112
+
113
+ it "should have a write_bytes method which takes an offset and a byte" do
114
+ @vdu.write_byte(0x0001, 42)
115
+ end
116
+
117
+ it "should not allow nested calls to #render_frame_sdl" do
118
+ lambda {
119
+ @vdu.render_frame_sdl { @vdu.render_frame_sdl }
120
+ }.should raise_error(Retrograph::RenderError, "Already in frame")
121
+ end
122
+
123
+ it "should allow naked calls to #wait_scanlines (as a noop)" do
124
+ @vdu.wait_scanlines(30)
125
+ end
126
+
127
+ it "should allow calls to #wait_scanlines within a frame" do
128
+ @vdu.render_frame_sdl { @vdu.wait_scanlines(30) }
129
+ end
130
+
131
+ extend ImageTests
132
+ spec_dir = File.join(File.split(__FILE__).first, 'image-specs')
133
+ build_image_specs(spec_dir)
134
+ end