More .obj file diving
This commit is contained in:
@@ -42,6 +42,9 @@ The `view-map` binary attempts to render a map, and is the current focus of
|
||||
effort. Once I can render a whole map, including pre-placed characters (cultist
|
||||
scum), things can start to get more interesting.
|
||||
|
||||
Current status: map tiles are rendered at correct offsets. Some center objects
|
||||
are rendered. Pixel data is not 100% accurate, left & right objects don't render
|
||||
|
||||
To run:
|
||||
|
||||
```
|
||||
|
@@ -262,6 +262,117 @@ Hurrah!
|
||||
|
||||

|
||||
|
||||
It's still not perfect. Comparing the records in sprite 0 (blank) with those in
|
||||
sprite 1 (diamond)....
|
||||
|
||||
|
||||
Blank:
|
||||
```
|
||||
0x0000 d1 00 42 01
|
||||
0x0004 80 00 3f 00
|
||||
0x0008 00 00 00 00
|
||||
b7 01 00 00
|
||||
0x0010 00 00 00 00
|
||||
00 00 00 00
|
||||
|
||||
jungtil sprite 0 (blank, draws nothing to screen
|
||||
|
||||
0x0018 80 3e 04 1f 80 3e 00 = row 1
|
||||
80 3c 08 1f 80 3c 00
|
||||
80 3a 0c 1f 80 3a 00
|
||||
80 38 10 1f 80 38 00
|
||||
80 36 14 1f 80 36 00
|
||||
80 34 18 1f 80 34 00
|
||||
80 32 1c 1f 80 32 00
|
||||
80 30 20 1f 80 30 00
|
||||
0x0050 80 2e 24 1f 80 2e 00
|
||||
80 2c 28 1f 80 2c 00
|
||||
80 2a 2c 1f 80 2a 00
|
||||
80 28 30 1f 80 28 00
|
||||
80 26 34 1f 80 26 00
|
||||
80 24 38 1f 80 24 00
|
||||
80 22 3c 1f 80 22 00
|
||||
0x0080 80 20 40 1f 80 20 00
|
||||
0x0088 80 1e 44 1f 80 1e 00
|
||||
80 1c 48 1f 80 1c 00
|
||||
80 1a 4c 1f 80 1a 00
|
||||
80 18 50 1f 80 18 00
|
||||
80 16 54 1f 80 16 00
|
||||
80 14 58 1f 80 14 00
|
||||
80 12 5c 1f 80 12 00
|
||||
80 10 60 1f 80 10 00
|
||||
0x00c0 80 0e 64 1f 80 0e 00
|
||||
80 0c 68 1f 80 0c 00
|
||||
80 0a 6c 1f 80 0a 00
|
||||
80 08 70 1f 80 08 00
|
||||
80 06 74 1f 80 06 00
|
||||
80 04 78 1f 80 04 00
|
||||
80 02 7c 1f 80 02 00
|
||||
7f 1f 01 1f 00 = row 32
|
||||
80 02 7c 1f 80 02 00
|
||||
80 04 78 1f 80 04 00
|
||||
80 06 74 1f 80 06 00
|
||||
80 08 70 1f 80 08 00
|
||||
80 0a 6c 1f 80 0a 00
|
||||
80 0c 68 1f 80 0c 00
|
||||
0x0120 80 0e 64 1f 80 0e 00
|
||||
80 10 60 1f 80 10 00
|
||||
80 12 5c 1f 80 12 00
|
||||
80 14 58 1f 80 14 00
|
||||
80 16 54 1f 80 16 00
|
||||
80 18 50 1f 80 18 00
|
||||
80 1a 4c 1f 80 1a 00
|
||||
80 1c 48 1f 80 1c 00
|
||||
0x0158 80 1e 44 1f 80 1e 00
|
||||
80 20 40 1f 80 20 00
|
||||
80 22 3c 1f 80 22 00
|
||||
80 24 38 1f 80 24 00
|
||||
80 26 34 1f 80 26 00
|
||||
80 28 30 1f 80 28 00
|
||||
80 2a 2c 1f 80 2a 00
|
||||
80 2c 28 1f 80 2c 00
|
||||
0x0190 80 2e 24 1f 80 2e 00
|
||||
80 30 20 1f 80 30 00
|
||||
80 32 1c 1f 80 32 00
|
||||
80 34 18 1f 80 34 00
|
||||
80 36 14 1f 80 36 00
|
||||
80 38 10 1f 80 38 00
|
||||
80 3a 0c 1f 80 3a 00
|
||||
80 3c 08 1f 80 3c 00
|
||||
0x01c8 80 3e 04 1f 80 3e 00 = row 63
|
||||
```
|
||||
|
||||
Sprite 1:
|
||||
|
||||
```
|
||||
0x0000 d1 00 42 01 80 00 3f 00
|
||||
0x0008 00 00 00 00 5a 11 00 00
|
||||
0x0010 00 00 00 00 00 00 00 00
|
||||
|
||||
0x0018 80 3e 84 6d 6c 6e 1e 80 3e 00
|
||||
80 3c 88 bf 76 6e 6d 6e 76 76 6e 80 3c 00
|
||||
0x0030 80 3a 84 bf 76 6e 76 04 6d 84 6e 76 7d 97 80 3a 00
|
||||
80 38 86 6d 76 6e 76 6e 87 04 6d 86 6e 97 1e 6e 6e 97 80 38 00
|
||||
80 36 85 bf 76 1d 97 96 04 6d 8b 87 76 6e 97 97 6d 87 6d 1c 97 97 80 36 00
|
||||
80 34 90 76 6e 97 76 6e 6d 6e 97 6c 6d 6e 76 6e 97 97 1e 03 6d 85 97 97 6e 6c 6c 80 34 00
|
||||
80 32 89 6d 6e 1e 97 97 1e 6d 6d 6e 03 6d 90 97 6e 76 6e 97 76 6e 6e 6d 97 6c 96 6d 6e 97 1c 80 32 00
|
||||
80 30 a0 bf 1e 97 76 1e 97 1e bf 6e 6d 6d 8f 6e 8f 1c 76 97 6d 6e 76 6e 96 6e 97 1d 6c 97 6d 6e 97 97 87 80 30 00
|
||||
80 2e a4 1c af 7e 7d 97 97 7f 6e 97 1e 1e 6e 87 6c 8f 6c 8e 6e 76 1e 6e 97 6d 1c 97 97 76 6e 6d 97 97 6e 87 6e 87 6e 80 2e 00
|
||||
80 2c a8 bf 1e bf 97 6e 1e 1e 87 6d 6e 96 6e 97 1e 6d 6d 6e 6d 1c 97 7d 97 6e 1e 76 6e 76 97 97 6d 6e 6d 97 96 6e 6e 87 96 97 6e 80 2c 00
|
||||
80 2a a0 bf 97 97 6e 97 1c 97 1e 6d 6e 97 76 6d 6d 6e 97 6e 6d 76 6e 6e 76 6e 97 7f 1d 6e 97 76 1d 97 6e 03 97 89 6e 87 6e 6e 96 97 96 97 6d 80 2a 00
|
||||
80 28 b0 bf 97 6e 97 6e 97 1e 6e 87 6e 97 97 1e 76 6e 6d 6e 97 6e 1d 1e 75 1e 1e 7f 1e 6e 97 1e 97 76 97 1d 97 6e 97 87 6e 6e 96 96 8f 6e 97 97 6d 6e 97 80 28 00
|
||||
80 26 87 bf 6e 97 97 6e 97 6e 03 97 a2 1c 1e 6e 1e 97 1c 97 6d 6e 97 1c 97 1c 7f 97 6e 76 97 1c 97 76 97 6e 97 1c 6e 6e 97 6e 87 6d 96 97 ad 03 97 85 6e 97 76 6e 6e 80 26 00
|
||||
80 24 81 76 03 97 b4 6e 97 97 6e 97 6e 97 97 1d 97 7f 6e 97 6e 1c 6e 97 6e 1e 76 7f bf 6e 97 1e 76 6e 6e 1e 97 6d 6e 97 1e 97 6e 97 6d 97 be 6e 87 6e 97 1c 97 1d 97 97 6c 97 6d 80 24 00
|
||||
80 22 b7 bf 1e 6d 6d 6e 97 97 96 76 5f 1c 87 97 97 1e 97 6e 4f 1e 76 97 1e 97 1e 7e 97 1c 1e 1e 6c 6d 97 6d 76 6e 97 1e 1e 7e 1e 97 6d 76 6e ad 87 1c 6d 87 97 1d 87 97 be 97 03 6d 82 6e 97 80 22 00
|
||||
80 20 81 bf 03 97 83 6e 97 6e 03 97 b6 1c 1c 6d ad 6e 97 1e 6e 97 76 6c 8f 6d 6c 96 97 1e 97 1d 97 1e 76 6e 6d 76 6e 6d 97 1e bf 1d 76 6e 97 6e 76 87 6e 87 97 96 97 6e 97 6d 6e 6e 76 6e 87 6c 6d 6d 6e 80 20 00
|
||||
0x298 ...
|
||||
```
|
||||
|
||||
So the first *and last* two bytes in each record are invariant between the two
|
||||
tiles, but the interstitial data differs. So we can make a first pass at
|
||||
improving matters by just ignoring those extra bytes for now. Do they say what
|
||||
the Y offset is? Why repeat it?
|
||||
|
||||
## Debugger
|
||||
|
||||
|
||||
|
@@ -19,6 +19,7 @@ module Obj
|
||||
|
||||
def self.parse(data)
|
||||
hdr = new(*data[0..SIZE - 1].unpack("V*"))
|
||||
pp hdr
|
||||
hdr.validate!(data.bytes.size)
|
||||
hdr
|
||||
end
|
||||
@@ -81,6 +82,8 @@ module Obj
|
||||
DirEntry.parse(rel_data.byteslice(rel_offset, DirEntry::SIZE))
|
||||
end
|
||||
|
||||
pp entries
|
||||
|
||||
new(entries)
|
||||
end
|
||||
|
||||
@@ -128,18 +131,21 @@ module Obj
|
||||
end
|
||||
|
||||
class Sprite
|
||||
attr_reader :header, :data, :raw
|
||||
attr_reader :header, :records, :raw
|
||||
|
||||
def self.parse(rel_data)
|
||||
hdr = SpriteHeader.parse(rel_data)
|
||||
sprite_pixels = rel_data[hdr.pixel_range]
|
||||
|
||||
new(hdr, sprite_pixels, rel_data)
|
||||
records = sprite_pixels.split("\x00")
|
||||
records.map { |record| record += "\x00" }
|
||||
|
||||
new(hdr, records, rel_data)
|
||||
end
|
||||
|
||||
def initialize(header, data, raw = nil)
|
||||
def initialize(header, records, raw = nil)
|
||||
@header = header
|
||||
@data = data
|
||||
@records = records
|
||||
@raw = raw
|
||||
end
|
||||
end
|
||||
@@ -208,11 +214,11 @@ def display(data, blocksize=8, skip=0, header: false)
|
||||
block.concat([nil]*(blocksize-block.size)) if block.size < blocksize
|
||||
|
||||
out = [
|
||||
# "0x#{hex(i*blocksize, 4)}",
|
||||
"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
|
||||
# "",# decimal 2-bytes
|
||||
" | " + block.map { |b| text(b) }.join("") + " |", # ascii
|
||||
block.map { |b| ascii(b) } ,# decimal bytes
|
||||
"",# decimal 2-bytes
|
||||
# decimal 4-bytes
|
||||
]
|
||||
|
||||
@@ -231,7 +237,7 @@ def dump(filename, spriteno = -1)
|
||||
|
||||
if spriteno == -1
|
||||
puts "Dumping all sprites for #{filename}"
|
||||
obj.sprites.each { |sprite| display(sprite.raw, 2, header: true) }
|
||||
obj.sprites.each_with_index { |sprite, i| puts "Sprite #{i}\n" ; display(sprite.raw, 8, header: true) }
|
||||
else
|
||||
puts "Dumping sprite #{spriteno} for #{filename}"
|
||||
display(obj.sprites[spriteno])
|
||||
@@ -260,7 +266,7 @@ def decompress(filename)
|
||||
print "Sprite %02d... x=#{hdr.width} y=#{hdr.height}"%i
|
||||
|
||||
decompressed = []
|
||||
data = sprite.data.bytes
|
||||
data = sprite.raw[24..-1].bytes
|
||||
hdr = sprite.header
|
||||
|
||||
loop do
|
||||
@@ -331,6 +337,8 @@ def sprites(filename)
|
||||
obj.sprites.each_with_index do |spr, i|
|
||||
hdr = spr.header
|
||||
px = hdr.width * hdr.height
|
||||
pp hdr
|
||||
pp spr
|
||||
|
||||
|
||||
puts "%s %03d: %02x %02x %02x %02x %3d %3d %5d %5d %.2f %02x %02x ... %02x"%[
|
||||
|
Reference in New Issue
Block a user