diff options
author | Paul Duncan <pabs@pablotron.org> | 2018-05-26 09:26:37 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2018-05-26 09:26:37 -0400 |
commit | f9008bcfed2537bf2e4d6d33a98a72a115388d93 (patch) | |
tree | 9771e10dd915aa44be1c461ee3afdb25d53a29fc /gen.rb | |
parent | 9ac78d307fda9bc6ea0ed2684d60dd86ecd89429 (diff) | |
download | gb-c-f9008bcfed2537bf2e4d6d33a98a72a115388d93.tar.bz2 gb-c-f9008bcfed2537bf2e4d6d33a98a72a115388d93.zip |
separate op switches, remove inline op code, strip whitespace
Diffstat (limited to 'gen.rb')
-rw-r--r-- | gen.rb | 17 |
1 files changed, 9 insertions, 8 deletions
@@ -6,14 +6,15 @@ require 'erb' # load template data DATA = YAML.load_file(File.join(__dir__, 'ops.yaml')) -switches = DATA['ops'].reduce([]) do |r, set| - prefix = (set.first == 'cb') ? 0xCB00 : 0x0000 - - set.last.reduce(r) do |r, op| +switches = Hash.new { |h, k| h[k] = [] } +DATA['ops'].each do |set_id, ops| + switches[set_id] = ops.select { |op| + op['op'] != 'PREFIX' + }.map { |op| # op hex string - hex = (prefix + op['hex']).to_s(16).upcase.rjust(4, '0') + hex = op['hex'].to_s(16).upcase.rjust(2, '0') - r << case op['op'] + case op['op'] when 'XX' [ "case 0x%s: /* op: %s, cat: %s */", @@ -50,8 +51,8 @@ switches = DATA['ops'].reduce([]) do |r, set| time_expr, ] end - end -end.join("\n") + }.join("\n") +end t = ERB.new(DATA['templates']['main']) puts t.run(binding) |