diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-04-01 21:19:45 +0200 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-04-02 21:23:51 +0200 |
| commit | 88728b89fed87326dae23619e2e93d4bd060a3ea (patch) | |
| tree | 4c1bf3af96e1e1ea200f9e5c08e3a672f5c4fe54 /bin | |
| parent | 2f140cfb7ea73e631fce086327bcb3a674758b0e (diff) | |
| download | jetpac.nes-88728b89fed87326dae23619e2e93d4bd060a3ea.tar.gz jetpac.nes-88728b89fed87326dae23619e2e93d4bd060a3ea.zip | |
Adapt velocity constants for PAL
In 2f140cfb7ea7 ("player: First PAL implementation") the rate of
acceleration was adapted for PAL. Now the values for velocities have
been adapted as well, in a way that we get (virtually) the same
experience in PAL and in NTSC.
This has been done by moving the velocity constants into configurable
values, which are then picked up by a new bin/values.rb script. This
script allows us to write the constants in plain floating point numbers,
does the conversion to fixed point numbers as expected, and it also does
the same for PAL by applying the proper NTSC to PAL conversion.
As a cherry on top, some values have also been tuned to match the
original game more closely, even if some more fine tuning might still be
needed here and there.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'bin')
| -rw-r--r-- | bin/values.rb | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/bin/values.rb b/bin/values.rb new file mode 100644 index 0000000..3ff1578 --- /dev/null +++ b/bin/values.rb @@ -0,0 +1,80 @@ +#!/usr/bin/env ruby + +## +# Generate the different values on `config/values/*.s` by parsing the values on +# `config/values.yml`. The values on that file are agnostic to NTSC or PAL, and +# it's up to this script to produce constants which make sense for NTSC and PAL. +# That is, it's a way to ensure that both NTSC and PAL have the same experience +# (or at least as close as possible). + +## +# Parse the configuration. + +require 'yaml' + +config_path = File.join("#{File.dirname(__FILE__)}/..", 'config/') +config = YAML.safe_load_file(File.join(config_path, 'values.yml')) + +# Converts the given floating point value into a signed fixed point value in the +# 4.4 format. +def to_signed_fixed_point(value) + integer = value.to_i + raise "bad signed fixed point value" if integer > 7 || integer < -7 + integer &= 0b00001111 + + decimal = (value % 1) * 100 + decimal = ((decimal * 15) / 100.0).round & 0b00001111 + + (integer << 4) | decimal +end + +## +# Loop through the configuration and fetch values for NTSC and PAL. + +res = {} +config.each do |model, properties| + res[model] ||= { ntsc: {}, pal: {} } + + properties.each do |name, ntsc| + name = name.upcase + pal = (ntsc * 6) / 5.0 + + res[model][:ntsc][name] = to_signed_fixed_point(ntsc) + res[model][:pal][name] = to_signed_fixed_point(pal) + end +end + +## +# Generate each model as expected. + +def to_hex(value) + hex = value.to_s(16).upcase + + if hex.size == 1 + "$0#{hex}" + else + "$#{hex}" + end +end + +def values_to_asm(values) + contents = "" + values.each { |k, v| contents << " #{k} = #{to_hex(v)}\n" } + contents.rstrip +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) } +end |
