retrograph 0.2.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.
Files changed (38) hide show
  1. data/README +248 -0
  2. data/Rakefile +54 -0
  3. data/ext/extconf.rb +3 -0
  4. data/ext/retrograph.c +275 -0
  5. data/spec/image-specs/color-blue-bits.case +2 -0
  6. data/spec/image-specs/color-blue-bits.png +0 -0
  7. data/spec/image-specs/color-green-bits.case +2 -0
  8. data/spec/image-specs/color-green-bits.png +0 -0
  9. data/spec/image-specs/color-red-bits.case +2 -0
  10. data/spec/image-specs/color-red-bits.png +0 -0
  11. data/spec/image-specs/default-screen-black.case +1 -0
  12. data/spec/image-specs/default-screen-black.png +0 -0
  13. data/spec/image-specs/default-screen-color-0.case +2 -0
  14. data/spec/image-specs/default-screen-color-0.png +0 -0
  15. data/spec/image-specs/scroll-mode1.case +7 -0
  16. data/spec/image-specs/scroll-mode1.png +0 -0
  17. data/spec/image-specs/scroll-mode2.case +10 -0
  18. data/spec/image-specs/scroll-mode2.png +0 -0
  19. data/spec/image-specs/scroll-mode3.case +10 -0
  20. data/spec/image-specs/scroll-mode3.png +0 -0
  21. data/spec/image-specs/sprites-doubling.case +5 -0
  22. data/spec/image-specs/sprites-doubling.png +0 -0
  23. data/spec/image-specs/sprites-mode2.case +8 -0
  24. data/spec/image-specs/sprites-mode2.png +0 -0
  25. data/spec/image-specs/sprites-mode3.case +8 -0
  26. data/spec/image-specs/sprites-mode3.png +0 -0
  27. data/spec/image-specs/sprites-ordering.case +5 -0
  28. data/spec/image-specs/sprites-ordering.png +0 -0
  29. data/spec/image-specs/text-colors.case +5 -0
  30. data/spec/image-specs/text-colors.png +0 -0
  31. data/spec/image-specs/tile-attributes-mode2.case +9 -0
  32. data/spec/image-specs/tile-attributes-mode2.png +0 -0
  33. data/spec/image-specs/tile-attributes-mode3.case +9 -0
  34. data/spec/image-specs/tile-attributes-mode3.png +0 -0
  35. data/spec/retrograph_spec.rb +133 -0
  36. data/src/retrograph.c +695 -0
  37. data/src/retrograph.h +66 -0
  38. metadata +103 -0
@@ -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,133 @@
1
+ require 'sdl'
2
+ require 'retrograph'
3
+
4
+ describe Retrograph do
5
+ constants = [
6
+ [:DISPLAY_WIDTH, 256],
7
+ [:DISPLAY_HEIGHT, 224],
8
+ [:BYTES_PER_PIXEL, 4],
9
+ [:BITS_PER_PIXEL, 32],
10
+ [:RED_SHIFT, 16],
11
+ [:GREEN_SHIFT, 8],
12
+ [:BLUE_SHIFT, 0],
13
+ [:RED_MASK, 0x00ff0000],
14
+ [:GREEN_MASK, 0x0000ff00],
15
+ [:BLUE_MASK, 0x000000ff],
16
+ [:ALPHA_MASK, 0x00000000]
17
+ ]
18
+ for name, value in constants
19
+ it "should define #{name} as #{value}" do
20
+ Retrograph.const_get(name).should == value
21
+ end
22
+ end
23
+ end
24
+
25
+ module ImageTests
26
+ RMASK = Retrograph::RED_MASK
27
+ GMASK = Retrograph::GREEN_MASK
28
+ BMASK = Retrograph::BLUE_MASK
29
+ AMASK = Retrograph::ALPHA_MASK
30
+
31
+ def build_image_specs(spec_dir)
32
+ Dir.open(spec_dir) do |dir|
33
+ dir.each do |name|
34
+ parts = name.split('.')
35
+ extension = parts.pop
36
+ next unless extension == 'case'
37
+ case_file = File.join(spec_dir, name)
38
+ parts.push 'png'
39
+ image_file = File.join(spec_dir, parts.join('.'))
40
+ build_image_spec(case_file, image_file)
41
+ end
42
+ end
43
+ end
44
+
45
+ def build_image_spec(case_file, image_file)
46
+ description = nil
47
+ writes = []
48
+
49
+ File.open(case_file, "r") do |stream|
50
+ description = stream.readline.strip
51
+ stream.each_line do |line|
52
+ offset, data = line.split(':').map { |t| t.strip }
53
+ data, offset = offset, nil unless data
54
+ data = data.split(/\s+/).map { |w| w.scan(/[a-zA-Z0-9]{2}/).reverse }
55
+ data = data.map { |w| [w.join('')].pack("H*") }.join('')
56
+ offset = Integer("0x#{offset}")
57
+ unless data.empty?
58
+ if offset
59
+ writes << [offset, data]
60
+ else
61
+ writes.last[1] << data
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ it description do
68
+ vdu = Retrograph::VDU.new
69
+ for offset, data in writes
70
+ vdu.write(offset, data)
71
+ end
72
+ output_image = vdu.render_frame
73
+ output_file = image_file.sub(/\.[^.]*$/, '-output.bmp')
74
+ output_image.save_bmp(output_file)
75
+
76
+ raw_image = SDL::Surface.load(image_file)
77
+ raw_image.set_alpha(0, SDL::ALPHA_OPAQUE)
78
+ raw_image.set_color_key(0, 0)
79
+ reference_image = SDL::Surface.new(0, 256, 224, 32,
80
+ RMASK, GMASK, BMASK, AMASK)
81
+ SDL::Surface.blit(raw_image, 0, 0, 256, 224, reference_image, 0, 0)
82
+ raw_image = nil
83
+ if output_image.pixels != reference_image.pixels
84
+ raise "Output does not match."
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ describe Retrograph::VDU do
91
+ before do
92
+ @vdu = Retrograph::VDU.new
93
+ end
94
+
95
+ it "should have a surface with the right characteristics" do
96
+ surface = @vdu.surface
97
+ surface.should be_an_instance_of(SDL::Surface)
98
+ surface.flags.should == 0
99
+ surface.w.should == Retrograph::DISPLAY_WIDTH
100
+ surface.h.should == Retrograph::DISPLAY_HEIGHT
101
+ surface.bpp.should == Retrograph::BITS_PER_PIXEL
102
+ surface.Rmask.should == Retrograph::RED_MASK
103
+ surface.Gmask.should == Retrograph::GREEN_MASK
104
+ surface.Bmask.should == Retrograph::BLUE_MASK
105
+ surface.Amask.should == Retrograph::ALPHA_MASK
106
+ end
107
+
108
+ it "should return that surface each time from #render_frame" do
109
+ output = @vdu.render_frame
110
+ output.should == @vdu.surface
111
+ end
112
+
113
+ it "should not allow nested calls to #render_frame" do
114
+ lambda {
115
+ @vdu.render_frame { @vdu.render_frame }
116
+ }.should raise_error(Retrograph::RenderError, "Already in frame")
117
+ end
118
+
119
+ it "should not allow naked calls to #render_scanlines" do
120
+ lambda {
121
+ @vdu.render_scanlines(30)
122
+ }.should raise_error(Retrograph::RenderError, "Not in frame")
123
+ end
124
+
125
+ it "should allow calls to #render_scanlines within a frame" do
126
+ @vdu.render_frame { @vdu.render_scanlines(30) }
127
+ end
128
+
129
+ extend ImageTests
130
+ spec_dir = File.join(File.split(__FILE__).first,
131
+ 'image-specs')
132
+ build_image_specs(spec_dir)
133
+ end