aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rw-r--r--bin/rand.rb12
-rwxr-xr-x[-rw-r--r--]bin/values.rb32
2 files changed, 27 insertions, 17 deletions
diff --git a/bin/rand.rb b/bin/rand.rb
index f627748..b781b6e 100644
--- a/bin/rand.rb
+++ b/bin/rand.rb
@@ -1,5 +1,15 @@
# frozen_string_literal: true
+##
+# Generate a table of 256 bytes of pseudo-random values. These values are
+# constrained with the upper and lower margins of the screen where enemies can
+# appear, and discard certain positions like platforms that can be troublesome
+# on enemy creation. All in all not exactly super pure randomness, but on the
+# other hand this game just needs a bit of randomness.
+#
+# Whenever you update values on background.s, you are supposed to call this
+# script again and replace the values on 'valid_y_rand_table' in prng.s.
+
# See values on background.s
UPPER_MARGIN_Y_COORD = 0x1A
GROUND_Y_COORD = 0xC8 - 32 # NOTE: As in background.s - twice the size of the enemy.
@@ -10,7 +20,7 @@ available = (UPPER_MARGIN_Y_COORD..GROUND_Y_COORD).to_a - (0x58..0x69).to_a - (0
# With this produce the array containing a randomized sample from the
# 'available' values.
-random_byte_array = Array.new(256) { '$%02X' % available.sample }
+random_byte_array = Array.new(256) { format('$%02X', available.sample) }
# And now print it in the assembler format.
random_byte_array.each_slice(16) do |row|
diff --git a/bin/values.rb b/bin/values.rb
index 3ff1578..e5128aa 100644..100755
--- a/bin/values.rb
+++ b/bin/values.rb
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
+# frozen_string_literal: true
##
# Generate the different values on `config/values/*.s` by parsing the values on
@@ -19,7 +20,8 @@ config = YAML.safe_load_file(File.join(config_path, 'values.yml'))
# 4.4 format.
def to_signed_fixed_point(value)
integer = value.to_i
- raise "bad signed fixed point value" if integer > 7 || integer < -7
+ raise 'bad signed fixed point value' if integer > 7 || integer < -7
+
integer &= 0b00001111
decimal = (value % 1) * 100
@@ -58,23 +60,21 @@ def to_hex(value)
end
def values_to_asm(values)
- contents = ""
- values.each { |k, v| contents << " #{k} = #{to_hex(v)}\n" }
- contents.rstrip
+ values.map { |k, v| " #{k} = #{to_hex(v)}" }.join("\n")
end
res.each do |model, formats|
path = File.join(config_path, "values/#{model}.s")
- contents = <<HERE
-;; This file has been automatically generated via bin/values.rb.
-;; DO NOT MODIFY this file directly: check config/values.yml instead.
-
-.ifdef PAL
-#{values_to_asm(formats[:pal])}
-.else
-#{values_to_asm(formats[:ntsc])}
-.endif
-HERE
-
- File.open(path, 'w') { |f| f.write(contents) }
+ contents = <<~HERE
+ ;; This file has been automatically generated via bin/values.rb.
+ ;; DO NOT MODIFY this file directly: check config/values.yml instead.
+
+ .ifdef PAL
+ #{values_to_asm(formats[:pal])}
+ .else
+ #{values_to_asm(formats[:ntsc])}
+ .endif
+ HERE
+
+ File.write(path, contents)
end