aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/build.yml12
-rw-r--r--.rubocop.yml3
-rw-r--r--bin/rand.rb12
-rwxr-xr-x[-rw-r--r--]bin/values.rb32
-rw-r--r--src/prng.s2
5 files changed, 43 insertions, 18 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index b81bc3e..4de3241 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -16,7 +16,17 @@ jobs:
uses: actions/checkout@v4
- name: Install dependencies from Ubuntu sources
- run: sudo apt-get install cc65 ruby
+ run: sudo apt-get install cc65
+
+ - name: Set up Ruby
+ uses: ruby/setup-ruby@v1
+ with:
+ ruby-version: 'ruby'
+
+ - name: Lint scripts on bin/
+ run: |
+ gem install rubocop
+ rubocop bin/ --format github
- name: Main task
run: V=1 make all
diff --git a/.rubocop.yml b/.rubocop.yml
new file mode 100644
index 0000000..f4a1205
--- /dev/null
+++ b/.rubocop.yml
@@ -0,0 +1,3 @@
+AllCops:
+ SuggestExtensions: false
+ NewCops: enable
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
diff --git a/src/prng.s b/src/prng.s
index 8211957..d62392e 100644
--- a/src/prng.s
+++ b/src/prng.s
@@ -23,6 +23,8 @@
;; The pre-computed table.
+;;
+;; NOTE: generated via bin/rand.rb; read more on this there.
valid_y_rand_table:
.byte $25, $87, $B7, $6A, $23, $77, $6D, $71, $6D, $B6, $86, $93, $2B, $97, $A8, $39
.byte $26, $AE, $A6, $70, $9F, $2D, $74, $B2, $8E, $A5, $33, $3E, $6D, $75, $91, $6B