-
Notifications
You must be signed in to change notification settings - Fork 3
/
hex2cine
executable file
·39 lines (36 loc) · 1.21 KB
/
hex2cine
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env ruby
# hex2cine -- script for converting a hex-dump file to a CINE file
# (for use with the appendix data in the documentation.)
#
# part of vrptools -- https://github.com/lindes/vrptools
#
# Copyright 2011 by David Lindes. All rights reserved.
#
# Available under terms in the LICENSE file that should accompany
# this file. Please consider that file to be included herein by
# reference.
ARGV.each do |filename|
outname = filename.sub(/.txt$/, '.cine')
if(File.exists?(outname))
warn "Sorry, #{outname} exists; won't convert #{filename}"
next
end
infile = File.open(filename)
outfile = File.open(outname, 'wb')
warn "Converting #{filename} from hex to binary, into #{outname}"
infile.each_line do |line|
line.sub!(/#.*/, '')
next if line =~ /^\s*$/
(addr, data) = line.split(/\s+/, 2)
if(addr !~ /^[\dA-F]{8}$/)
warn "Warning: unruly line: #{line}"
next
end
outfile.seek(addr.hex.to_i) # in case of gaps, which there are a couple of.
data = data.split(/\s+/)
if(data.size != 16 and !infile.eof?)
warn "Warning: line has bad data size #{data.size}, should be 16:\n\t#{line}"
end
outfile.syswrite(data.pack('H2' * data.size))
end
end