More .obj investigating. 0x80 seems to be a special value

This commit is contained in:
2018-03-24 21:47:34 +00:00
parent 6ba93486a1
commit 4d4c4da892
10 changed files with 269 additions and 99 deletions

View File

@@ -138,7 +138,7 @@ module Obj
sprite_pixels = rel_data[hdr.pixel_range]
records = sprite_pixels.split("\x00")
records.map { |record| record += "\x00" }
records.map! { |record| record += "\x00" }
new(hdr, records, rel_data)
end
@@ -216,8 +216,8 @@ def display(data, blocksize=8, skip=0, header: false)
out = [
"0x#{hex(i*blocksize, 4)}",
block.map { |b| hex(b, 2) }, # hex
" | " + block.map { |b| text(b) }.join("") + " |", # ascii
block.map { |b| ascii(b) } ,# decimal bytes
# " | " + block.map { |b| text(b) }.join("") + " |", # ascii
# block.map { |b| ascii(b) } ,# decimal bytes
"",# decimal 2-bytes
# decimal 4-bytes
]
@@ -273,7 +273,6 @@ def decompress(filename)
break if data.empty?
right = data.index(0)
if right.nil?
print "error! end of chunk not found"
@@ -360,9 +359,35 @@ def sprites(filename)
end
end
def sprite(filename, i)
obj = load_obj(filename)
puts filename + ":"
spr = obj.sprites[i]
raise "No sprite #{i}" unless spr
# Show the header
display(spr.raw[0...24], 4, header: true)
spr.records.each_with_index do |record, i|
str =
if record.size > 40
record[0...20].bytes.map { |b| hex(b, 2) }.join(" ") +
" ... " +
record[-20..-1].bytes.map { |b| hex(b, 2) }.join(" ")
else
record.bytes.map { |b| hex(b, 2) }.join(" ")
end
puts "%4d: %4d bytes: %s"%[i,record.size, str]
end
end
case command = ARGV.shift
when "sprites" then
ARGV.each { |filename| sprites(filename) }
when "sprite" then
sprite(ARGV[0], ARGV[1].to_i)
when "dump" then
ARGV.each { |filename| dump(filename) }
when "compare" then