From 04495cf36e7e0dcc22b3f8dd5f1b5c126591077e Mon Sep 17 00:00:00 2001 From: Martin Haye Date: Thu, 14 Nov 2019 06:42:08 -0800 Subject: [PATCH] Moved tools into their own dir. --- .../Apple/virtual/{ => tools}/extractText.sh | 0 .../Apple/virtual/tools/getBlockTypes.xslt | 13 ++++ Platform/Apple/virtual/tools/prng.rb | 62 +++++++++++++++++++ .../Apple/virtual/tools/replaceGetKey.xslt | 56 +++++++++++++++++ .../Apple/virtual/{ => tools}/xformScript.rb | 0 5 files changed, 131 insertions(+) rename Platform/Apple/virtual/{ => tools}/extractText.sh (100%) create mode 100644 Platform/Apple/virtual/tools/getBlockTypes.xslt create mode 100755 Platform/Apple/virtual/tools/prng.rb create mode 100644 Platform/Apple/virtual/tools/replaceGetKey.xslt rename Platform/Apple/virtual/{ => tools}/xformScript.rb (100%) diff --git a/Platform/Apple/virtual/extractText.sh b/Platform/Apple/virtual/tools/extractText.sh similarity index 100% rename from Platform/Apple/virtual/extractText.sh rename to Platform/Apple/virtual/tools/extractText.sh diff --git a/Platform/Apple/virtual/tools/getBlockTypes.xslt b/Platform/Apple/virtual/tools/getBlockTypes.xslt new file mode 100644 index 00000000..31591c22 --- /dev/null +++ b/Platform/Apple/virtual/tools/getBlockTypes.xslt @@ -0,0 +1,13 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/Platform/Apple/virtual/tools/prng.rb b/Platform/Apple/virtual/tools/prng.rb new file mode 100755 index 00000000..743f3bf6 --- /dev/null +++ b/Platform/Apple/virtual/tools/prng.rb @@ -0,0 +1,62 @@ +#!/usr/bin/env ruby + +MULT = 32 +#BIG_NUM = 65521 # should be prime +#BIG_NUM = 65519 +BIG_NUM = 32749 + +def linCong(seed) + if seed == 0 + seed = 1 + else + seed &= 0x7FFF + seed >= BIG_NUM and seed -= BIG_NUM + 5.times { + seed <<= 1 + seed >= BIG_NUM and seed -= BIG_NUM + } + end + return seed +end + +def rnd02(seed) + magic = 0x2227 + if seed == 0 + seed = magic + elsif seed == 0x8000 + seed = 0 + else + seed <<= 1 + if (seed & 0x8000) > 0 + seed = (seed & 0x7fff) ^ magic + end + end + return seed +end + +done = {} + +minLoop = nil +(BIG_NUM..0xFFFF).each { |invalSeed| + out = linCong(invalSeed) + out >= 0 && out < BIG_NUM or raise("Bad: $%x -> $%x" % [invalSeed, out]) +} +(0..BIG_NUM-1).each { |startSeed| + next if done[startSeed] + n = 0 + seed = startSeed + loop do + print "%016b %04X -> " % [seed, seed] + seed = linCong(seed) + puts "%04X" % seed + if done[seed] + length = n - done[seed] + puts "loop at #{startSeed} -> #{seed}: length=#{length}" + minLoop = minLoop ? [minLoop, length].min : length + break + end + done[seed] = n + n += 1 + end +} +puts "minLoop=#{minLoop}" diff --git a/Platform/Apple/virtual/tools/replaceGetKey.xslt b/Platform/Apple/virtual/tools/replaceGetKey.xslt new file mode 100644 index 00000000..f9ebe100 --- /dev/null +++ b/Platform/Apple/virtual/tools/replaceGetKey.xslt @@ -0,0 +1,56 @@ + + + + + + + + + + + + 1 + + + + + + + + 0 + + + + + + + + 0 + + + + + + + + + + ... Hmm, next is: + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Platform/Apple/virtual/xformScript.rb b/Platform/Apple/virtual/tools/xformScript.rb similarity index 100% rename from Platform/Apple/virtual/xformScript.rb rename to Platform/Apple/virtual/tools/xformScript.rb