burn 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. data/LICENSE +621 -0
  2. data/README.md +467 -0
  3. data/Rakefile +1 -0
  4. data/bin/burn +14 -0
  5. data/lib/burn/builder.rb +65 -0
  6. data/lib/burn/cli.rb +187 -0
  7. data/lib/burn/debug.rb +25 -0
  8. data/lib/burn/dsl/channel_stream.rb +105 -0
  9. data/lib/burn/dsl/declare.rb +42 -0
  10. data/lib/burn/dsl/dsl_base.rb +31 -0
  11. data/lib/burn/dsl/music.rb +36 -0
  12. data/lib/burn/dsl/note.rb +125 -0
  13. data/lib/burn/dsl/scene.rb +278 -0
  14. data/lib/burn/dsl/sound.rb +30 -0
  15. data/lib/burn/dsl/sound_effect.rb +91 -0
  16. data/lib/burn/dsl.rb +8 -0
  17. data/lib/burn/generator/assembly_music.rb +47 -0
  18. data/lib/burn/generator/assembly_sound_effect.rb +33 -0
  19. data/lib/burn/generator/c_source.rb +54 -0
  20. data/lib/burn/generator/template/mus_template.s +49 -0
  21. data/lib/burn/generator/template/template.c +88 -0
  22. data/lib/burn/generator.rb +3 -0
  23. data/lib/burn/tools/mac/cc65/asminc/_file.inc +27 -0
  24. data/lib/burn/tools/mac/cc65/asminc/_heap.inc +35 -0
  25. data/lib/burn/tools/mac/cc65/asminc/apple2.inc +64 -0
  26. data/lib/burn/tools/mac/cc65/asminc/atari.inc +1175 -0
  27. data/lib/burn/tools/mac/cc65/asminc/atari.mac +59 -0
  28. data/lib/burn/tools/mac/cc65/asminc/atmos.inc +110 -0
  29. data/lib/burn/tools/mac/cc65/asminc/c128.inc +214 -0
  30. data/lib/burn/tools/mac/cc65/asminc/c16.inc +9 -0
  31. data/lib/burn/tools/mac/cc65/asminc/c64.inc +212 -0
  32. data/lib/burn/tools/mac/cc65/asminc/cbm.mac +50 -0
  33. data/lib/burn/tools/mac/cc65/asminc/cbm510.inc +182 -0
  34. data/lib/burn/tools/mac/cc65/asminc/cbm610.inc +110 -0
  35. data/lib/burn/tools/mac/cc65/asminc/cbm_filetype.inc +34 -0
  36. data/lib/burn/tools/mac/cc65/asminc/cpu.mac +24 -0
  37. data/lib/burn/tools/mac/cc65/asminc/ctype.inc +29 -0
  38. data/lib/burn/tools/mac/cc65/asminc/em-error.inc +49 -0
  39. data/lib/burn/tools/mac/cc65/asminc/em-kernel.inc +106 -0
  40. data/lib/burn/tools/mac/cc65/asminc/errno.inc +36 -0
  41. data/lib/burn/tools/mac/cc65/asminc/fcntl.inc +21 -0
  42. data/lib/burn/tools/mac/cc65/asminc/generic.mac +55 -0
  43. data/lib/burn/tools/mac/cc65/asminc/get_tv.inc +22 -0
  44. data/lib/burn/tools/mac/cc65/asminc/joy-error.inc +44 -0
  45. data/lib/burn/tools/mac/cc65/asminc/joy-kernel.inc +85 -0
  46. data/lib/burn/tools/mac/cc65/asminc/longbranch.mac +88 -0
  47. data/lib/burn/tools/mac/cc65/asminc/lynx.inc +279 -0
  48. data/lib/burn/tools/mac/cc65/asminc/modload.inc +78 -0
  49. data/lib/burn/tools/mac/cc65/asminc/mouse-kernel.inc +180 -0
  50. data/lib/burn/tools/mac/cc65/asminc/nes.inc +93 -0
  51. data/lib/burn/tools/mac/cc65/asminc/o65.inc +150 -0
  52. data/lib/burn/tools/mac/cc65/asminc/opcodes.inc +509 -0
  53. data/lib/burn/tools/mac/cc65/asminc/pet.inc +54 -0
  54. data/lib/burn/tools/mac/cc65/asminc/plus4.inc +86 -0
  55. data/lib/burn/tools/mac/cc65/asminc/ser-error.inc +54 -0
  56. data/lib/burn/tools/mac/cc65/asminc/ser-kernel.inc +162 -0
  57. data/lib/burn/tools/mac/cc65/asminc/signal.inc +57 -0
  58. data/lib/burn/tools/mac/cc65/asminc/smc.inc +245 -0
  59. data/lib/burn/tools/mac/cc65/asminc/stdio.inc +70 -0
  60. data/lib/burn/tools/mac/cc65/asminc/supervision.inc +76 -0
  61. data/lib/burn/tools/mac/cc65/asminc/tgi-error.inc +52 -0
  62. data/lib/burn/tools/mac/cc65/asminc/tgi-kernel.inc +234 -0
  63. data/lib/burn/tools/mac/cc65/asminc/tgi-vectorfont.inc +70 -0
  64. data/lib/burn/tools/mac/cc65/asminc/time.inc +59 -0
  65. data/lib/burn/tools/mac/cc65/asminc/utsname.inc +46 -0
  66. data/lib/burn/tools/mac/cc65/asminc/vic20.inc +75 -0
  67. data/lib/burn/tools/mac/cc65/asminc/zeropage.inc +26 -0
  68. data/lib/burn/tools/mac/cc65/bin/ca65 +0 -0
  69. data/lib/burn/tools/mac/cc65/bin/cc65 +0 -0
  70. data/lib/burn/tools/mac/cc65/bin/ld65 +0 -0
  71. data/lib/burn/tools/other/cc65/asminc/_file.inc +27 -0
  72. data/lib/burn/tools/other/cc65/asminc/_heap.inc +35 -0
  73. data/lib/burn/tools/other/cc65/asminc/apple2.inc +64 -0
  74. data/lib/burn/tools/other/cc65/asminc/atari.inc +1175 -0
  75. data/lib/burn/tools/other/cc65/asminc/atari.mac +59 -0
  76. data/lib/burn/tools/other/cc65/asminc/atmos.inc +110 -0
  77. data/lib/burn/tools/other/cc65/asminc/c128.inc +214 -0
  78. data/lib/burn/tools/other/cc65/asminc/c16.inc +9 -0
  79. data/lib/burn/tools/other/cc65/asminc/c64.inc +212 -0
  80. data/lib/burn/tools/other/cc65/asminc/cbm.mac +50 -0
  81. data/lib/burn/tools/other/cc65/asminc/cbm510.inc +182 -0
  82. data/lib/burn/tools/other/cc65/asminc/cbm610.inc +110 -0
  83. data/lib/burn/tools/other/cc65/asminc/cbm_filetype.inc +34 -0
  84. data/lib/burn/tools/other/cc65/asminc/cpu.mac +24 -0
  85. data/lib/burn/tools/other/cc65/asminc/ctype.inc +29 -0
  86. data/lib/burn/tools/other/cc65/asminc/em-error.inc +49 -0
  87. data/lib/burn/tools/other/cc65/asminc/em-kernel.inc +106 -0
  88. data/lib/burn/tools/other/cc65/asminc/errno.inc +36 -0
  89. data/lib/burn/tools/other/cc65/asminc/fcntl.inc +21 -0
  90. data/lib/burn/tools/other/cc65/asminc/generic.mac +55 -0
  91. data/lib/burn/tools/other/cc65/asminc/get_tv.inc +22 -0
  92. data/lib/burn/tools/other/cc65/asminc/joy-error.inc +44 -0
  93. data/lib/burn/tools/other/cc65/asminc/joy-kernel.inc +85 -0
  94. data/lib/burn/tools/other/cc65/asminc/longbranch.mac +88 -0
  95. data/lib/burn/tools/other/cc65/asminc/lynx.inc +279 -0
  96. data/lib/burn/tools/other/cc65/asminc/modload.inc +78 -0
  97. data/lib/burn/tools/other/cc65/asminc/mouse-kernel.inc +180 -0
  98. data/lib/burn/tools/other/cc65/asminc/nes.inc +93 -0
  99. data/lib/burn/tools/other/cc65/asminc/o65.inc +150 -0
  100. data/lib/burn/tools/other/cc65/asminc/opcodes.inc +509 -0
  101. data/lib/burn/tools/other/cc65/asminc/pet.inc +54 -0
  102. data/lib/burn/tools/other/cc65/asminc/plus4.inc +86 -0
  103. data/lib/burn/tools/other/cc65/asminc/ser-error.inc +54 -0
  104. data/lib/burn/tools/other/cc65/asminc/ser-kernel.inc +162 -0
  105. data/lib/burn/tools/other/cc65/asminc/signal.inc +57 -0
  106. data/lib/burn/tools/other/cc65/asminc/smc.inc +245 -0
  107. data/lib/burn/tools/other/cc65/asminc/stdio.inc +70 -0
  108. data/lib/burn/tools/other/cc65/asminc/supervision.inc +76 -0
  109. data/lib/burn/tools/other/cc65/asminc/tgi-error.inc +52 -0
  110. data/lib/burn/tools/other/cc65/asminc/tgi-kernel.inc +234 -0
  111. data/lib/burn/tools/other/cc65/asminc/tgi-vectorfont.inc +70 -0
  112. data/lib/burn/tools/other/cc65/asminc/time.inc +59 -0
  113. data/lib/burn/tools/other/cc65/asminc/utsname.inc +46 -0
  114. data/lib/burn/tools/other/cc65/asminc/vic20.inc +75 -0
  115. data/lib/burn/tools/other/cc65/asminc/zeropage.inc +26 -0
  116. data/lib/burn/tools/other/cc65/bin/ca65 +0 -0
  117. data/lib/burn/tools/other/cc65/bin/cc65 +0 -0
  118. data/lib/burn/tools/other/cc65/bin/ld65 +0 -0
  119. data/lib/burn/tools/win/cc65/asminc/_file.inc +27 -0
  120. data/lib/burn/tools/win/cc65/asminc/_heap.inc +35 -0
  121. data/lib/burn/tools/win/cc65/asminc/apple2.inc +64 -0
  122. data/lib/burn/tools/win/cc65/asminc/atari.inc +1101 -0
  123. data/lib/burn/tools/win/cc65/asminc/atmos.inc +31 -0
  124. data/lib/burn/tools/win/cc65/asminc/c128.inc +213 -0
  125. data/lib/burn/tools/win/cc65/asminc/c16.inc +9 -0
  126. data/lib/burn/tools/win/cc65/asminc/c64.inc +212 -0
  127. data/lib/burn/tools/win/cc65/asminc/cbm510.inc +182 -0
  128. data/lib/burn/tools/win/cc65/asminc/cbm610.inc +110 -0
  129. data/lib/burn/tools/win/cc65/asminc/ctype.inc +29 -0
  130. data/lib/burn/tools/win/cc65/asminc/em-error.inc +44 -0
  131. data/lib/burn/tools/win/cc65/asminc/em-kernel.inc +100 -0
  132. data/lib/burn/tools/win/cc65/asminc/errno.inc +36 -0
  133. data/lib/burn/tools/win/cc65/asminc/fcntl.inc +21 -0
  134. data/lib/burn/tools/win/cc65/asminc/get_tv.inc +22 -0
  135. data/lib/burn/tools/win/cc65/asminc/joy-error.inc +44 -0
  136. data/lib/burn/tools/win/cc65/asminc/joy-kernel.inc +85 -0
  137. data/lib/burn/tools/win/cc65/asminc/lynx.inc +273 -0
  138. data/lib/burn/tools/win/cc65/asminc/modload.inc +78 -0
  139. data/lib/burn/tools/win/cc65/asminc/mouse-kernel.inc +179 -0
  140. data/lib/burn/tools/win/cc65/asminc/nes.inc +93 -0
  141. data/lib/burn/tools/win/cc65/asminc/o65.inc +135 -0
  142. data/lib/burn/tools/win/cc65/asminc/pet.inc +45 -0
  143. data/lib/burn/tools/win/cc65/asminc/plus4.inc +87 -0
  144. data/lib/burn/tools/win/cc65/asminc/rs232.inc +19 -0
  145. data/lib/burn/tools/win/cc65/asminc/ser-error.inc +50 -0
  146. data/lib/burn/tools/win/cc65/asminc/ser-kernel.inc +161 -0
  147. data/lib/burn/tools/win/cc65/asminc/signal.inc +57 -0
  148. data/lib/burn/tools/win/cc65/asminc/stdio.inc +70 -0
  149. data/lib/burn/tools/win/cc65/asminc/supervision.inc +76 -0
  150. data/lib/burn/tools/win/cc65/asminc/tgi-error.inc +48 -0
  151. data/lib/burn/tools/win/cc65/asminc/tgi-kernel.inc +183 -0
  152. data/lib/burn/tools/win/cc65/asminc/tgi-mode.inc +48 -0
  153. data/lib/burn/tools/win/cc65/asminc/time.inc +59 -0
  154. data/lib/burn/tools/win/cc65/asminc/utsname.inc +46 -0
  155. data/lib/burn/tools/win/cc65/asminc/vic20.inc +77 -0
  156. data/lib/burn/tools/win/cc65/asminc/zeropage.inc +22 -0
  157. data/lib/burn/tools/win/cc65/bin/ca65.exe +0 -0
  158. data/lib/burn/tools/win/cc65/bin/cc65.exe +0 -0
  159. data/lib/burn/tools/win/cc65/bin/ld65.exe +0 -0
  160. data/lib/burn/util/os.rb +38 -0
  161. data/lib/burn/util/patternizer.rb +62 -0
  162. data/lib/burn/util/pxes.rb +180 -0
  163. data/lib/burn/util/server.rb +21 -0
  164. data/lib/burn/util.rb +4 -0
  165. data/lib/burn/version.rb +3 -0
  166. data/lib/burn/workspace_default/asset/crt0.s +260 -0
  167. data/lib/burn/workspace_default/asset/famitone.s +1031 -0
  168. data/lib/burn/workspace_default/asset/mus_instruments.s +50 -0
  169. data/lib/burn/workspace_default/asset/music.s +3 -0
  170. data/lib/burn/workspace_default/asset/nes.cfg +83 -0
  171. data/lib/burn/workspace_default/asset/neslib.h +213 -0
  172. data/lib/burn/workspace_default/asset/neslib.s +923 -0
  173. data/lib/burn/workspace_default/asset/runtime.lib +0 -0
  174. data/lib/burn/workspace_default/asset/sounds.s +143 -0
  175. data/lib/burn/workspace_default/asset/test.h +22 -0
  176. data/lib/burn/workspace_default/asset/tileset.chr +0 -0
  177. data/lib/burn/workspace_default/release/js/emulator.html +42 -0
  178. data/lib/burn/workspace_default/release/js/js/dynamicaudio-89ba58da476270a9b630.min.js +1 -0
  179. data/lib/burn/workspace_default/release/js/js/jquery-1.4.2.min.js +154 -0
  180. data/lib/burn/workspace_default/release/js/js/jsnes-4e7a7260aa.js +7149 -0
  181. data/lib/burn/workspace_default/release/js/swf/dynamicaudio.swf +0 -0
  182. data/lib/burn/workspace_default/scripts/compile.bat +30 -0
  183. data/lib/burn/workspace_default/scripts/compile.sh +30 -0
  184. data/lib/burn.rb +11 -0
  185. data/test/helper.rb +8 -0
  186. data/test/runner.rb +2 -0
  187. data/test/test_burn.rb +14 -0
  188. data/test/test_dsl.rb +22 -0
  189. data/test/test_pxes.rb +48 -0
  190. metadata +270 -0
@@ -0,0 +1,278 @@
1
+ module Burn
2
+ module Dsl
3
+ class Scene < DslBase
4
+ # Where to draw
5
+ BG = 0 # background palette (0x00-0x0f)
6
+ TEXT = 1 # background palette (0x00-0x0f)
7
+ PALETTE_X1 = 5 # palette A for #screen and #paint method (whcih is a part background palette)
8
+ PALETTE_X2 = 6
9
+ PALETTE_X3 = 7
10
+ PALETTE_Y1 = 9
11
+ PALETTE_Y2 = 10
12
+ PALETTE_Y3 = 11
13
+ PALETTE_Z1 = 13
14
+ PALETTE_Z2 = 14
15
+ PALETTE_Z3 = 15
16
+ SPRITE = 17 # sprite palette (0x10-0x1f)
17
+
18
+ PALETTE_DEFAULT = 0
19
+ PALETTE_X = 85 # palette expression for PPU Attribute table
20
+ PALETTE_Y = 170 # palette expression for PPU Attribute table
21
+ PALETTE_Z = 255 # palette expression for PPU Attribute table
22
+
23
+ # Color Control
24
+ WHITE = 0
25
+ LIGHTBLUE = 1
26
+ BLUE = 2
27
+ PURPLE = 3
28
+ PINK = 4
29
+ RED = 5
30
+ DEEPRED = 6
31
+ ORANGE = 7
32
+ LIGHTORANGE = 8
33
+ DARKGREEN = 9
34
+ GREEN = 10
35
+ LIGHTGREEN = 11
36
+ BLUEGREEN = 12
37
+ GRAY = 13
38
+ BLACK = 14
39
+
40
+ # Light Control
41
+ DARKEST = 0
42
+ DARKER = 16
43
+ LIGHTER = 32
44
+ LIGHTEST = 48
45
+
46
+ def initialize(resource_name, context)
47
+ super(resource_name, context)
48
+ end
49
+
50
+ def label(string, x=0, y=1)
51
+ @context.instance_exec {@code_blocks.push sprintf("put_str(NTADR(%d,%d),\"%s\");", x, y, string.upcase)}
52
+ end
53
+
54
+ def fade_in
55
+ @context.instance_exec do
56
+ [
57
+ "ppu_on_all();",
58
+ "screen_fade_in();"
59
+ ].each {|p| @code_blocks.push p}
60
+ end
61
+ end
62
+
63
+ def fade_out(sec=3)
64
+ @context.instance_exec {@code_blocks.push "screen_fade_out(#{sec.to_s});"}
65
+ end
66
+
67
+ def color(palette, color, lightness=:lighter)
68
+ palette=Scene.const_get(palette.upcase)
69
+ color=Scene.const_get(color.upcase)
70
+ lightness=Scene.const_get(lightness.upcase)
71
+
72
+ @context.instance_exec {@code_blocks.push "pal_col(#{palette},0x#{(lightness+color).to_s(16)});"}
73
+ end
74
+
75
+ def play(song_title)
76
+ @context.instance_exec do
77
+ @global << "extern const unsigned char music_#{song_title}[];"
78
+ @code_blocks << "music_play(music_#{song_title});"
79
+ end
80
+ end
81
+
82
+ def stop
83
+ @context.instance_exec {@code_blocks.push "music_stop();"}
84
+ end
85
+
86
+ def show(string, x=0, y=0, *args)
87
+ @context.instance_exec(@resource_name) do |resource|
88
+ nmi_plots = Array.new
89
+ iChrCount=0
90
+ isRequireArgs=false
91
+ vname = resource+"_nmi_list"
92
+ init_name = resource+"_nmi_init"
93
+
94
+ string.split(//).each do |c|
95
+ if c=='%' then
96
+ isRequireArgs=true
97
+ next
98
+ end
99
+ nmi_plots.push [x+iChrCount,y] if nmi_plots.index([x+iChrCount, y]).nil?
100
+ if !isRequireArgs then
101
+ @code_blocks.push sprintf("#{vname}[%d]=%s;", nmi_plots.index([x+iChrCount,y])*3+2, sprintf("%#x", c.bytes.to_a[0]-32))
102
+ iChrCount+=1
103
+ else
104
+ if c=='d' then
105
+ @code_blocks.push sprintf("#{vname}[%d]=0x10+%s;", nmi_plots.index([x+iChrCount,y])*3+2, args.shift)
106
+ iChrCount+=1
107
+ elsif c=='s' then
108
+ args.shift.split(//).each do |d|
109
+ nmi_plots.push [x+iChrCount,y] if nmi_plots.index([x+iChrCount, y]).nil?
110
+ @code_blocks.push sprintf("#{vname}[%d]=%s;", nmi_plots.index([x+iChrCount,y])*3+2, sprintf("%#x", d.bytes.to_a[0]-32))
111
+ iChrCount+=1
112
+ end
113
+ else
114
+ raise "method #show can't take any data except for %d or %s. Please make sure you are passing correct 4th parameter."
115
+ end
116
+ end
117
+ isRequireArgs=false
118
+ end
119
+
120
+ if nmi_plots.count>0 then
121
+ # declaration for show method
122
+ @global.push sprintf("static unsigned char #{vname}[%d*3];", nmi_plots.count)
123
+ @global.push sprintf("const unsigned char #{init_name}[%d*3]={", nmi_plots.count)
124
+ nmi_plots.each_with_index do |plot,i|
125
+ @global.push sprintf("MSB(NTADR(%d,%d)),LSB(NTADR(%d,%d)),0%s", plot[0],plot[1],plot[0],plot[1],i<(nmi_plots.count-1)?",":"")
126
+ end
127
+ @global.push "};"
128
+ @code_blocks.unshift "memcpy(#{vname},#{init_name},sizeof(#{init_name}));", sprintf("set_vram_update(%d,#{vname});", nmi_plots.count)
129
+ end
130
+
131
+ end
132
+ end
133
+
134
+ def wait(interval)
135
+ #@context.instance_exec do
136
+ # [
137
+ # "while(1){",
138
+ # "ppu_on_all();",
139
+ # "delay(#{interval});",
140
+ # "ppu_off();",
141
+ # "break;",
142
+ # "}"
143
+ # ].each {|p| @code_blocks.push p}
144
+ #end
145
+ @context.instance_exec {@code_blocks.push "delay(#{interval});"}
146
+ end
147
+
148
+ def goto(scene_name)
149
+ @context.instance_exec do
150
+ [
151
+ "ppu_off();",
152
+ "set_vram_update(0,0);", #clear vram condition for #show
153
+ "vram_adr(0x2000);", #clear nametable
154
+ "vram_fill(0,1024);", #clear nametable
155
+ "goto #{scene_name};"
156
+ ].each {|p| @code_blocks.push p}
157
+ end
158
+ end
159
+
160
+ def main_loop(rrb_source=nil)
161
+ rrb_source = File.open("#{@resource_name}.rrb").read if rrb_source.nil? || File.extname(rrb_source) == "#{@resource_name}.rrb"
162
+
163
+ # preprocess - for show method, all parameters after the 3rd parameter must be converted to String.
164
+ rrb_source = rrb_source.lines.map{|line|
165
+ if /^[\s\t]*show/ =~ line then
166
+ line.chomp.split(",").each_with_index.map{|data, i|
167
+ if i>2 then
168
+ '"' + data + '"'
169
+ else
170
+ data
171
+ end
172
+ }.join(",")
173
+ else
174
+ line.chomp
175
+ end
176
+ }.join("\n")
177
+
178
+ @context.instance_exec(@context,@resource_name) do |c, resource|
179
+ # preprocess
180
+ [
181
+ "ppu_on_all();",
182
+ "while(1){",
183
+ "ppu_waitnmi(); //wait for next TV frame",
184
+ ].each {|p| @code_blocks.push p}
185
+
186
+ # parse ruby source code and process them partially
187
+ p = Burn::Util::Pxes.new(Ripper.sexp(rrb_source),c,resource)
188
+ #require 'pp'
189
+ #pp p
190
+ @code_blocks.push p.to_c
191
+
192
+ # postprocess
193
+ @code_blocks.push "}"
194
+ end
195
+
196
+ end
197
+
198
+ def inline(code)
199
+ @context.instance_exec {@code_blocks.push code}
200
+ end
201
+
202
+ #def sprite_set(x,y,tile_number,palette=0)
203
+ # @context.instance_exec {@code_blocks.push "oam_spr(#{x},#{y},0x"+tile_number.to_s(16)+",#{palette},0);//0x40 is tile number, i&3 is palette"}
204
+ #end
205
+
206
+ def sprite(resource)
207
+ @context.instance_exec {@code_blocks.push "sprite(&#{resource});"}
208
+ end
209
+
210
+ def screen(map, vars)
211
+ @context.instance_exec(@resource_name) do |resource|
212
+ current_char = nil
213
+ consective_count = 0
214
+ output = Array.new
215
+ # the last character "\b" is just a dummy to finialize loop process
216
+ (map.gsub(/(\r\n|\r|\n)/,"")+"\b").chars do |c|
217
+ if current_char != c then
218
+ if !current_char.nil? then
219
+ if vars.keys.include?(current_char.to_sym) then
220
+ output.push @pattern_table_index[vars[current_char.to_sym].to_sym] # user defined specific pattern
221
+ else
222
+ output.push 0 # blank pattern
223
+ end
224
+ # repeat to draw same pattern
225
+ output.push 1, consective_count if consective_count>0
226
+ end
227
+ current_char = c
228
+ consective_count = 0
229
+ else
230
+ consective_count += 1
231
+ end
232
+ end
233
+ @global.push "const unsigned char screen_#{resource}["+(output.count+3).to_s+"]={0x01,"+output.map{|p| sprintf "0x%.2x", p}.join(",")+",0x01,0x00};"
234
+ # "unrle_vram" means "decode Run Length Encoding and set them to vram".
235
+ @code_blocks.push "unrle_vram(screen_#{resource},0x2020);" # previously used 0x2000 but it doesn't display very first line of screen.
236
+ end
237
+ end
238
+
239
+ def paint(dest, palette)
240
+ @context.instance_exec(@resource_name) do |resource|
241
+ var_name="screen_#{resource}_color_#{@global.count}"
242
+ @global.push "const unsigned char #{var_name}[6]={0x01,0x"+Scene.const_get(palette.upcase).to_s(16)+",0x01,"+sprintf("0x%.2x",dest.end-dest.begin)+",0x01,0x00};"
243
+ @code_blocks.push "unrle_vram(#{var_name},0x"+(9152+dest.begin).to_s(16)+");" # 9152 is equivalent to 23C0
244
+ end
245
+ end
246
+
247
+ def sound(effect_name)
248
+ @context.instance_exec {@code_blocks.push "sfx_play(SFX_#{effect_name.upcase},0);"}
249
+ end
250
+
251
+
252
+ # vcall-ish methods
253
+ def rand
254
+ @context.instance_exec {@code_blocks.push "rand8()"}
255
+ end
256
+
257
+ alias_method :play_sound, :sound
258
+ alias_method :play_music, :play
259
+
260
+ # utility methods
261
+ def range(x_from, y_from, x_to, y_to)
262
+ x_to = x_from if x_to.nil?
263
+ y_to = y_from if y_to.nil?
264
+
265
+ plots = [x_from,y_from,x_to,y_to].map do |v|
266
+ if v.is_a?(String) && v.end_with?("px") then # x:0-255, y:0:239
267
+ v.to_i / 32
268
+ else
269
+ v.to_i / 4
270
+ end
271
+ end
272
+
273
+ plots[1]*8+plots[0]..plots[3]*8+plots[2]
274
+ end
275
+
276
+ end
277
+ end
278
+ end
@@ -0,0 +1,30 @@
1
+ module Burn
2
+ module Dsl
3
+ class Sound < DslBase
4
+ def initialize(resource_name, context)
5
+ super(resource_name, context)
6
+
7
+ if resource_name.nil? then
8
+ raise Exception.new "Resource name for Sound class must be provided."
9
+ else
10
+ @resource_name = resource_name
11
+ end
12
+
13
+ @context.instance_exec resource_name, &lambda{|resource_name|
14
+ @resources["#{resource_name}"] = Array.new
15
+ }
16
+
17
+ @se = SoundEffect.new
18
+
19
+ end
20
+
21
+ def effect(&block)
22
+ @context.instance_exec(@resource_name,@se) do |resource_name,se|
23
+ se.load(&block)
24
+ @resources["#{resource_name}"] << se.generate
25
+ end
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,91 @@
1
+ module Burn
2
+ module Dsl
3
+ class SoundEffect
4
+ # duty cycle: 00�F12.5%�@01�F25%�@10�F50%�@11�F75%
5
+ LOWEST = 0
6
+ LOWER = 1
7
+ HIGHER = 2
8
+ HIGHEST = 3
9
+
10
+ def initialize
11
+ @output_buffer = Array.new
12
+ end
13
+
14
+ def load(&block)
15
+ self.instance_eval &block
16
+ end
17
+
18
+ # $4000 related
19
+ def duty_cycle(ratio)
20
+ @duty_cycle = SoundEffect.const_get(ratio.upcase)
21
+ end
22
+
23
+ def velocity(level)
24
+ @velocity = level
25
+ end
26
+
27
+ def envelope_decay(flag)
28
+ @envelope_decay = flag==:enable ? 0 : 1
29
+ end
30
+
31
+ def envelope_decay_loop(flag)
32
+ @envelope_decay_loop = flag==:enable ? 1 : 0
33
+ end
34
+
35
+ def length_counter_clock(flag)
36
+ @envelope_decay_loop = flag==:enable ? 0 : 1
37
+ end
38
+
39
+ # $4001 related
40
+ def pitch(i)
41
+ @pitch = i
42
+ end
43
+
44
+ def length(i)
45
+ @length = i + 15
46
+ end
47
+
48
+ alias_method :envelope_decay_rate, :velocity
49
+ alias_method :volume, :velocity
50
+ alias_method :envelope, :envelope_decay
51
+ alias_method :envelope_loop, :envelope_decay_loop
52
+ alias_method :key_off_counter, :length_counter_clock
53
+
54
+ def generate
55
+ if !@duty_cycle.nil? || !@velocity.nil? || @envelope_decay.nil? || @envelope_decay_loop.nil? then
56
+ @duty_cycle = HIGHER if !@duty_cycle.nil?
57
+ @velocity = 7 if @velocity.nil?
58
+ @envelope_decay = 0 if @envelope_decay.nil?
59
+ @envelope_decay_loop = 0 if @envelope_decay_loop.nil?
60
+
61
+ reg = @duty_cycle*64 + @envelope_decay*32 + @envelope_decay_loop*16 + @velocity
62
+ if @reg4000 != reg then
63
+ @output_buffer << " .byte $00,$%02x" % reg
64
+ @reg4000 = reg
65
+ end
66
+ end
67
+
68
+ if !@pitch.nil? then
69
+ if @reg4001 != @pitch then
70
+ @output_buffer << " .byte $01,$%02x" % @pitch
71
+ @reg4001 = @pitch
72
+ end
73
+ end
74
+
75
+ @length = 16 if @length.nil?
76
+ @output_buffer << " .byte $%02x" % @length
77
+
78
+ # return result
79
+ @output_buffer.join("\n") + "\n"
80
+
81
+ #" .byte $00,$7f\n .byte $01,$ab\n .byte $02,$01\n .byte $13\n .byte $01,$3f\n .byte $39\n .byte $01,$1c\n .byte $13\n .byte $ff\n"
82
+ end
83
+
84
+ private
85
+ def __translate
86
+ " .byte " + @notes.map{|p| "$%02x" % p}.join(",")
87
+ end
88
+
89
+ end
90
+ end
91
+ end
data/lib/burn/dsl.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'burn/dsl/sound_effect'
2
+ require 'burn/dsl/note'
3
+ require 'burn/dsl/channel_stream'
4
+ require 'burn/dsl/dsl_base'
5
+ require 'burn/dsl/declare'
6
+ require 'burn/dsl/sound'
7
+ require 'burn/dsl/music'
8
+ require 'burn/dsl/scene'
@@ -0,0 +1,47 @@
1
+ module Burn
2
+ module Generator
3
+ class AssemblyMusic
4
+ include Debug
5
+
6
+ def initialize(workspace_root)
7
+ # Generic
8
+ @workspace_root = workspace_root
9
+
10
+ # Music related
11
+ @resources = {}
12
+
13
+ #@channels = Array.new
14
+
15
+ end
16
+
17
+ def get_context
18
+ self
19
+ end
20
+
21
+ def generate
22
+ # prepare music.s - music assembler file
23
+ File.write(
24
+ "#{@workspace_root}/tmp/burn/asset/music.s",
25
+ File.read(File.dirname(__FILE__)+"/../workspace_default/asset/music.s")
26
+ .gsub(/__@__EXPORT__@__/, @resources.keys.map{|p| " .export _music_#{p}"}.join("\n"))
27
+ .gsub(/__@__INCLUDE__@__/, @resources.keys.map{|p| "_music_#{p}: .include \"mus_#{p}.s\""}.join("\n"))
28
+ )
29
+
30
+ # preparing each song file
31
+ @resources.each {|resource_name, channels|
32
+ # prepare other music resources
33
+ File.write( "#{@workspace_root}/tmp/burn/asset/mus_#{resource_name}.s",
34
+ File.read(File.dirname(__FILE__)+"/template/mus_template.s")
35
+ .gsub(/__@__NAME__@__/, resource_name)
36
+ .gsub(/__@__CHANNEL1__@__/, channels.shift || "")
37
+ .gsub(/__@__CHANNEL2__@__/, channels.shift || "")
38
+ .gsub(/__@__CHANNEL3__@__/, channels.shift || "")
39
+ .gsub(/__@__CHANNEL4__@__/, channels.shift || "")
40
+ .gsub(/__@__CHANNEL5__@__/, channels.shift || "")
41
+ )
42
+ }
43
+
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,33 @@
1
+ module Burn
2
+ module Generator
3
+ class AssemblySoundEffect
4
+ include Debug
5
+ attr_reader :resources
6
+
7
+ def initialize(workspace_root)
8
+ # Generic
9
+ @workspace_root = workspace_root
10
+
11
+ # Music related
12
+ @resources = {}
13
+
14
+ end
15
+
16
+ def get_context
17
+ self
18
+ end
19
+
20
+ def generate
21
+ # prepare sound.s - sound effect assembler file
22
+ File.write(
23
+ "#{@workspace_root}/tmp/burn/asset/sounds.s",
24
+ "sounds:\n" \
25
+ + @resources.keys.map{|p| " .word @#{p}"}.join("\n") \
26
+ + "\n" \
27
+ + @resources.map{|key,value| "@#{key}:\n#{value.join} .byte $ff\n" }.join
28
+ )
29
+
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,54 @@
1
+ module Burn
2
+ module Generator
3
+ class CSource
4
+ include Debug
5
+ attr_reader :global, :code_blocks
6
+
7
+ def initialize(workspace_root)
8
+ # Generic
9
+ @workspace_root = workspace_root
10
+ @global = Array.new
11
+ @code_blocks = Array.new
12
+
13
+ # Scene related
14
+ @pattern_tables = Array.new
15
+ @pattern_table_pointer = 80 #0x50 equivalent
16
+ @pattern_table_index = Hash.new
17
+ end
18
+
19
+ def get_context
20
+ self
21
+ end
22
+
23
+ def generate
24
+ # Initialization for codeblocks
25
+ @code_blocks.unshift "init();"
26
+
27
+ # generate source code
28
+ File.write(
29
+ "#{@workspace_root}/tmp/burn/main.c",
30
+ File.read(File.dirname(__FILE__) + "/template/template.c")
31
+ .gsub(/__@__MAIN__@__/, @code_blocks.join("\n"))
32
+ .gsub(/__@__GLOBAL__@__/, @global.join("\n"))
33
+ )
34
+
35
+ # save pattern tables associated with source code
36
+ pattern_header = []
37
+ File.open("#{@workspace_root}/tmp/burn/asset/tileset.chr", "rb") do |f|
38
+ pattern_header << f.read(16*80)
39
+ end
40
+ File.open("#{@workspace_root}/tmp/burn/asset/tileset.chr", "wb") do |f|
41
+ f << pattern_header[0]
42
+ @pattern_tables.each do |p|
43
+ f << p
44
+ end
45
+ (8192-16*80-@pattern_tables.count*16).times do |i|
46
+ f << ["0x00"].pack("B*")
47
+ end
48
+ end
49
+
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,49 @@
1
+ __@__NAME__@__:
2
+ .word @chn0,@chn1,@chn2,@chn3,@chn4,music_instruments
3
+ .byte $03
4
+
5
+ @chn0:
6
+ @chn0_0:
7
+ __@__CHANNEL1__@__
8
+ @chn0_loop:
9
+ @chn0_1:
10
+ .byte $9f
11
+ .byte $fe
12
+ .word @chn0_loop
13
+
14
+ @chn1:
15
+ @chn1_0:
16
+ __@__CHANNEL2__@__
17
+ @chn1_loop:
18
+ @chn1_1:
19
+ .byte $9f
20
+ .byte $fe
21
+ .word @chn1_loop
22
+
23
+ @chn2:
24
+ @chn2_0:
25
+ __@__CHANNEL3__@__
26
+ .byte $89
27
+ @chn2_loop:
28
+ @chn2_1:
29
+ .byte $9f
30
+ .byte $fe
31
+ .word @chn2_loop
32
+
33
+ @chn3:
34
+ @chn3_0:
35
+ __@__CHANNEL4__@__
36
+ @chn3_loop:
37
+ @chn3_1:
38
+ .byte $9f
39
+ .byte $fe
40
+ .word @chn3_loop
41
+
42
+ @chn4:
43
+ @chn4_0:
44
+ __@__CHANNEL5__@__
45
+ @chn4_loop:
46
+ @chn4_1:
47
+ .byte $9f
48
+ .byte $fe
49
+ .word @chn4_loop
@@ -0,0 +1,88 @@
1
+ #include "neslib.h"
2
+ #include "test.h"
3
+
4
+ #define NTADR(x,y) ((0x2000|((y)<<5)|x))
5
+ #define MSB(x) (((x)>>8))
6
+ #define LSB(x) (((x)&0xff))
7
+
8
+ const unsigned char palSprites[16]={
9
+ 0x0f,0x17,0x27,0x37,
10
+ 0x0f,0x11,0x21,0x31,
11
+ 0x0f,0x15,0x25,0x35,
12
+ 0x0f,0x19,0x29,0x39
13
+ };
14
+
15
+ static unsigned char vram_buffer[896]; // 896:32*28
16
+ static unsigned char spr;
17
+
18
+ void put_str(unsigned int adr,const char *str)
19
+ {
20
+ vram_adr(adr);
21
+
22
+ while(1)
23
+ {
24
+ if(!*str) break;
25
+ vram_put((*str++)-0x20); //-0x20 because ASCII code 0x20 is placed in tile 0 of the CHR
26
+ }
27
+ }
28
+
29
+ void screen_fade_out(interval){
30
+ unsigned char i=0x05;
31
+ while(1){
32
+ //ppu_waitnmi();//wait for next TV frame
33
+ i--;
34
+ pal_bright(i);
35
+ delay(interval);
36
+ if (i==0){
37
+ break;
38
+ }
39
+ }
40
+ }
41
+
42
+ void screen_fade_in(){
43
+ unsigned char i=0x00;
44
+ while(1){
45
+ //ppu_waitnmi();//wait for next TV frame
46
+ i++;
47
+ pal_bright(i);
48
+ delay(5);
49
+ if (i==4){
50
+ break;
51
+ //goto mystart;
52
+ }
53
+ }
54
+ }
55
+
56
+ void init_screen(){
57
+ memfill(vram_buffer, 0, 896); // 896:32*28
58
+ vram_write((unsigned char *)vram_buffer, NTADR(0, 1), 32 * 28);
59
+ }
60
+
61
+ void init(){
62
+ pal_spr(palSprites);//set palette for sprites
63
+ pal_col(1,0x30);//set while color
64
+ }
65
+
66
+ int is_pressed(unsigned char pad){
67
+ unsigned char i;
68
+ i=pad_poll(0);
69
+ return i&pad;
70
+ }
71
+
72
+ typedef struct {
73
+ int x;
74
+ int y;
75
+ unsigned char pattern[];
76
+ } sprite_schema;
77
+
78
+ __@__GLOBAL__@__
79
+
80
+ void sprite(sprite_schema *data){
81
+ spr=oam_meta_spr(data->x,data->y,spr,data->pattern);
82
+ }
83
+
84
+ void main(void)
85
+ {
86
+
87
+ }
88
+
@@ -0,0 +1,3 @@
1
+ require 'burn/generator/assembly_sound_effect'
2
+ require 'burn/generator/assembly_music'
3
+ require 'burn/generator/c_source'