burn 0.1.0

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 (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,180 @@
1
+ module Burn
2
+ module Util
3
+ class Pxes
4
+ include Debug
5
+ attr_reader :sexp
6
+
7
+ def initialize(sexp, context=nil, resource_name=nil)
8
+ @sexp = sexp
9
+ @context = context || self
10
+ @resource_name = resource_name
11
+ end
12
+
13
+ def to_c
14
+ parse_sexp(@sexp)
15
+ end
16
+
17
+ private
18
+ #def replace_vcall_to_symbol(sexp_array)
19
+ # sexp_array.map do |a|
20
+ # if a.instance_of?(Array) then
21
+ # replace_vcall_to_symbol(a)
22
+ # elsif a==:vcall then
23
+ # :symbol
24
+ # else
25
+ # a
26
+ # end
27
+ # end
28
+ #end
29
+
30
+ def invoke_dsl_processing(exp)
31
+ generator = Generator::CSource.new(self)
32
+ Dsl::Scene.new(@resource_name, generator).instance_eval exp
33
+ # return the result
34
+ @context.instance_exec(generator.global) do |generator_global|
35
+ @global.concat generator_global
36
+ end
37
+ generator.code_blocks.join
38
+ end
39
+
40
+ def parse_sexp(s)
41
+ if s.instance_of?(String) then
42
+ s
43
+ elsif s.instance_of?(Array) && s[0].instance_of?(Symbol) then
44
+ log "--array and symbol--"
45
+ log s[0]
46
+ case s[0]
47
+ when :assign
48
+ parse_sexp(s[1]) + "=" + parse_sexp(s[2]) + ";"
49
+
50
+ when :var_field
51
+ s[1][1]
52
+
53
+ when :var_ref
54
+ case s[1][1]
55
+ when "true", "false"
56
+ s[1][1].upcase
57
+ else
58
+ s[1][1]
59
+ end
60
+
61
+ when :void_stmt
62
+ "" # this happens when rip "if true then # do nothing end" type of code
63
+
64
+ when :binary
65
+ case s[2]
66
+ when :or
67
+ operator = "||"
68
+ when :and
69
+ operator = "&&"
70
+ else
71
+ operator = s[2].to_s
72
+ end
73
+ parse_sexp(s[1]) + operator + parse_sexp(s[3])
74
+
75
+ when :opassign
76
+ parse_sexp(s[1]) + parse_sexp(s[2]) + parse_sexp(s[3]) + ";"
77
+
78
+ when :unary
79
+ case s[1]
80
+ when :not, :!
81
+ "!" + parse_sexp(s[2])
82
+ else
83
+ parse_sexp(s[2])
84
+ end
85
+
86
+ when :paren
87
+ "(" + parse_sexp(s[1][0]) + ")"
88
+
89
+ when :symbol
90
+ ':' + s[1][1]
91
+
92
+ when :field, :call
93
+ parse_sexp(s[1]) + "." + parse_sexp(s[3])
94
+
95
+ when :@ident, :@int, :@kw, :@op
96
+ s[1]
97
+
98
+ when :@tstring_content
99
+ '"' + s[1] + '"'
100
+
101
+ # this is why you can't use pre-defined dsl name as a variable name. e.g) you are not allowed to declare variables like show or label or stop. these all are defined dsl.
102
+ when :vcall
103
+ if !Dsl::Scene.new(@resource_name,self).methods.index(s[1][1].to_sym).nil? then
104
+ invoke_dsl_processing parse_sexp(s[1])
105
+ else
106
+ parse_sexp(s[1])
107
+ end
108
+
109
+ when :command
110
+ if !Dsl::Scene.new(@resource_name,self).methods.index(s[1][1].to_sym).nil? then
111
+ #invoke_dsl_processing parse_sexp(s[1]) + "(" + parse_sexp( replace_vcall_to_symbol(s[2]) ) + ")"
112
+ invoke_dsl_processing parse_sexp(s[1]) + "(" + parse_sexp( s[2] ) + ")"
113
+ else
114
+ parse_sexp(s[1]) + "(" + parse_sexp(s[2]) + ");"
115
+ end
116
+
117
+ when :method_add_arg
118
+ command = s[1][1][1]
119
+ # check if it matches dsl.
120
+ case command
121
+ when "is_pressed"
122
+ parse_sexp(s[1]) + "(PAD_" + parse_sexp(s[2]).delete(":").upcase + ")"
123
+ when "rand"
124
+ parse_sexp(s[1]) + "8()"
125
+ else
126
+ parse_sexp(s[1]) + "(" + parse_sexp(s[2]) + ")"
127
+ end
128
+
129
+ # Currently pssing block is not supported
130
+ #when :method_add_block
131
+
132
+ when :args_add_block
133
+ a = Array.new
134
+ s[1].each_with_index do |sexp,i|
135
+ log "<<<<<<<<<<<<<<<<<<NUM #{i}>>>>>>"
136
+ log sexp
137
+ a << parse_sexp(sexp)
138
+ end
139
+ a.join(",")
140
+
141
+ when :while
142
+ "while(" + parse_sexp(s[1]) + "){" + parse_sexp(s[2]) + "}"
143
+
144
+ when :if, :if_mod, :elsif
145
+ if s[0]==:elsif then
146
+ keyword = "else if"
147
+ else
148
+ keyword = "if"
149
+ end
150
+ additional_condition = parse_sexp(s[3]) if !s[3].nil?
151
+ "#{keyword} (" + parse_sexp(s[1]) + "){" + parse_sexp(s[2]) + "} #{additional_condition}"
152
+
153
+ #when :def
154
+ # is not supported for to_c as return data type cannot be defined
155
+
156
+ when :else
157
+ "else {" + parse_sexp(s[1]) + " } "
158
+
159
+ else
160
+ parse_sexp(s[1])
161
+
162
+ end
163
+ # Safety net
164
+ elsif s.instance_of?(Array) && s[0].instance_of?(Array) then
165
+ a = Array.new
166
+ s.each_with_index do |sexp,i|
167
+ log "<<<<<<<<<<<<<<<<<<NUM #{i}>>>>>>"
168
+ log sexp
169
+ a << parse_sexp(sexp)
170
+ end
171
+ a.join("\n")
172
+ else
173
+ log "--else--"
174
+ log s.class.to_s
175
+ log s[0].class.to_s
176
+ end
177
+ end
178
+ end
179
+ end
180
+ end
@@ -0,0 +1,21 @@
1
+ module Burn
2
+ module Util
3
+ class Server
4
+ require 'webrick'
5
+
6
+ def initialize(document_root)
7
+ @server = WEBrick::HTTPServer.new({:DocumentRoot => document_root, :BindAddress => '127.0.0.1', :Port => 17890})
8
+ trap 'INT' do
9
+ @server.shutdown
10
+ end
11
+ @server.mount_proc('/shutdown'){ |req, resp|
12
+ @server.stop
13
+ }
14
+ end
15
+
16
+ def start
17
+ @server.start
18
+ end
19
+ end
20
+ end
21
+ end
data/lib/burn/util.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'burn/util/os'
2
+ require 'burn/util/patternizer'
3
+ require 'burn/util/server'
4
+ require 'burn/util/pxes'
@@ -0,0 +1,3 @@
1
+ module Burn
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,260 @@
1
+ ; Startup code for cc65 and Shiru's NES library
2
+ ; based on code by Groepaz/Hitmen <groepaz@gmx.net>, Ullrich von Bassewitz <uz@cc65.org>
3
+
4
+
5
+ NES_MAPPER =0 ;mapper number
6
+ NES_PRG_BANKS =1 ;number of 16K PRG banks, change to 2 for NROM256
7
+ NES_CHR_BANKS =1 ;number of 8K CHR banks
8
+ NES_MIRRORING =1 ;0 horizontal, 1 vertical, 8 four screen
9
+
10
+ FT_DPCM_OFF =$ffc0 ;samples offset, $c000 or higher, 64-byte steps
11
+ FT_SFX_STREAMS =4 ;number of sound effects played at once, can be 4 or less (faster)
12
+
13
+ .define FT_DPCM_ENABLE 0 ;zero to exclude all the DMC code
14
+ .define FT_SFX_ENABLE 1 ;zero to exclude all the sound effects code
15
+
16
+ .define SPEED_FIX 1 ;zero if you want to handle PAL/NTSC speed difference by yourself
17
+
18
+
19
+ .export _exit,__STARTUP__:absolute=1
20
+ .import initlib,push0,popa,popax,_main,zerobss,copydata
21
+
22
+ ; Linker generated symbols
23
+ .import __RAM_START__ ,__RAM_SIZE__
24
+ .import __ROM0_START__ ,__ROM0_SIZE__
25
+ .import __STARTUP_LOAD__,__STARTUP_RUN__,__STARTUP_SIZE__
26
+ .import __CODE_LOAD__ ,__CODE_RUN__ ,__CODE_SIZE__
27
+ .import __RODATA_LOAD__ ,__RODATA_RUN__ ,__RODATA_SIZE__
28
+
29
+ .include "zeropage.inc"
30
+
31
+
32
+ PPU_CTRL =$2000
33
+ PPU_MASK =$2001
34
+ PPU_STATUS =$2002
35
+ PPU_OAM_ADDR=$2003
36
+ PPU_OAM_DATA=$2004
37
+ PPU_SCROLL =$2005
38
+ PPU_ADDR =$2006
39
+ PPU_DATA =$2007
40
+ PPU_OAM_DMA =$4014
41
+ PPU_FRAMECNT=$4017
42
+ DMC_FREQ =$4010
43
+ CTRL_PORT1 =$4016
44
+ CTRL_PORT2 =$4017
45
+
46
+ OAM_BUF =$0200
47
+ PAL_BUF =$01c0
48
+
49
+ FRAMECNT1 =$00
50
+ FRAMECNT2 =$01
51
+ NTSCMODE =$02
52
+ VRAMUPDATE =$03
53
+ PAD_STATE =$04 ;2 bytes, one per controller
54
+ PAD_STATEP =$06 ;2 bytes
55
+ PAD_STATET =$08 ;2 bytes
56
+ FT_TEMP =$0a ;7 bytes in zeropage
57
+ SCROLL_X =$11
58
+ SCROLL_Y =$12
59
+ PPU_CTRL_VAR=$13
60
+ PPU_MASK_VAR=$14
61
+ NAME_UPD_ADR=$15 ;word
62
+ NAME_UPD_LEN=$17
63
+ PAL_PTR =$18 ;word
64
+ RAND_SEED =$1a ;word
65
+
66
+ TEMP =$1c
67
+
68
+ PAD_BUF =TEMP+1
69
+
70
+ PTR =TEMP ;word
71
+ LEN =TEMP+2 ;word
72
+ NEXTSPR =TEMP+4
73
+ SCRX =TEMP+5
74
+ SCRY =TEMP+6
75
+ SRC =TEMP+7 ;word
76
+ DST =TEMP+9 ;word
77
+
78
+ RLE_LOW =TEMP
79
+ RLE_HIGH =TEMP+1
80
+ RLE_TAG =TEMP+2
81
+ RLE_BYTE =TEMP+3
82
+
83
+
84
+ FT_BASE_ADR =$0100 ;page in RAM, should be $xx00
85
+ FT_DPCM_PTR =(FT_DPCM_OFF&$3fff)>>6
86
+
87
+ .define FT_THREAD 1;undefine if you call sound effects in the same thread as sound update
88
+
89
+
90
+
91
+ .segment "HEADER"
92
+
93
+ .byte $4e,$45,$53,$1a
94
+ .byte NES_PRG_BANKS
95
+ .byte NES_CHR_BANKS
96
+ .byte NES_MIRRORING|(NES_MAPPER<<4)
97
+ .byte NES_MAPPER&$f0
98
+ .res 8,0
99
+
100
+
101
+ .segment "STARTUP"
102
+
103
+ start:
104
+ _exit:
105
+
106
+ sei
107
+ ldx #$ff
108
+ txs
109
+ inx
110
+ stx PPU_MASK
111
+ stx DMC_FREQ
112
+ stx PPU_CTRL ;no NMI
113
+
114
+ waitSync1:
115
+ bit PPU_STATUS
116
+ @1:
117
+ bit PPU_STATUS
118
+ bpl @1
119
+
120
+ clearPalette:
121
+ ldy #$3f
122
+ sty PPU_ADDR
123
+ stx PPU_ADDR
124
+ lda #$0f
125
+ ldx #$20
126
+ @1:
127
+ sta PPU_DATA
128
+ dex
129
+ bne @1
130
+
131
+ clearVRAM:
132
+ txa
133
+ ldy #$20
134
+ sty PPU_ADDR
135
+ sta PPU_ADDR
136
+ ldy #$10
137
+ @1:
138
+ sta PPU_DATA
139
+ inx
140
+ bne @1
141
+ dey
142
+ bne @1
143
+
144
+ clearRAM:
145
+ txa
146
+ @1:
147
+ sta $000,x
148
+ sta $100,x
149
+ sta $200,x
150
+ sta $300,x
151
+ sta $400,x
152
+ sta $500,x
153
+ sta $600,x
154
+ sta $700,x
155
+ inx
156
+ bne @1
157
+
158
+ lda #4
159
+ jsr _pal_bright
160
+ jsr _pal_clear
161
+ jsr _oam_clear
162
+
163
+ jsr zerobss
164
+ jsr copydata
165
+
166
+ lda #<(__RAM_START__+__RAM_SIZE__)
167
+ sta sp
168
+ lda #>(__RAM_START__+__RAM_SIZE__)
169
+ sta sp+1 ; Set argument stack ptr
170
+
171
+ jsr initlib
172
+
173
+ waitSync2:
174
+ bit PPU_STATUS
175
+ @1:
176
+ bit PPU_STATUS
177
+ bpl @1
178
+
179
+ lda #%10000000
180
+ sta <PPU_CTRL_VAR
181
+ sta PPU_CTRL ;enable NMI
182
+ lda #%00000110
183
+ sta <PPU_MASK_VAR
184
+
185
+ waitSync3:
186
+ lda <FRAMECNT1
187
+ @1:
188
+ cmp <FRAMECNT1
189
+ beq @1
190
+
191
+ detectNTSC:
192
+ ldx #52 ;blargg's code
193
+ ldy #24
194
+ @1:
195
+ dex
196
+ bne @1
197
+ dey
198
+ bne @1
199
+
200
+ lda PPU_STATUS
201
+ and #$80
202
+ sta <NTSCMODE
203
+
204
+ jsr _ppu_off
205
+
206
+ lda <NTSCMODE
207
+ jsr FamiToneInit
208
+
209
+ .if(FT_DPCM_ENABLE)
210
+ ldx #<music_dpcm
211
+ ldy #>music_dpcm
212
+ jsr FamiToneSampleInit
213
+ .endif
214
+
215
+ .if(FT_SFX_ENABLE)
216
+ ldx #<sounds_data
217
+ ldy #>sounds_data
218
+ jsr FamiToneSfxInit
219
+ .endif
220
+
221
+ .if(!SPEED_FIX)
222
+ lda #0
223
+ sta <NTSCMODE
224
+ .endif
225
+
226
+ lda #$fd
227
+ sta <RAND_SEED
228
+ sta <RAND_SEED+1
229
+
230
+ lda #0
231
+ sta PPU_SCROLL
232
+ sta PPU_SCROLL
233
+
234
+ jmp _main ;no parameters
235
+
236
+ .include "neslib.s"
237
+
238
+ .segment "RODATA"
239
+
240
+ .include "music.s"
241
+
242
+ .if(FT_SFX_ENABLE)
243
+ sounds_data:
244
+ .include "sounds.s"
245
+ .endif
246
+
247
+ .segment "SAMPLES"
248
+
249
+ ;.incbin "music_dpcm.bin"
250
+
251
+ .segment "VECTORS"
252
+
253
+ .word nmi ;$fffa vblank nmi
254
+ .word start ;$fffc reset
255
+ .word irq ;$fffe irq / brk
256
+
257
+
258
+ .segment "CHARS"
259
+
260
+ .incbin "tileset.chr"