Created
April 8, 2012 15:18
-
-
Save apage43/2337915 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env coffee | |
fs = require 'fs' | |
program = require 'commander' | |
tpls = { | |
pop: { | |
hdr: "" | |
word: (word) -> | |
""" | |
SET POP, 0x#{word.toString(16)}\n | |
""" | |
end:""" | |
SET SP, 0 | |
SET PC, 0\n | |
""" | |
} | |
dat: { | |
hdr: "DAT " | |
word: (word) -> "0x#{word.toString(16)}, " | |
end: "0\n" | |
} | |
} | |
program | |
.version('0.0.1') | |
.usage('[options] <image>') | |
.option('-E, --endian <fmt>', 'Word-endianness of input-image', 'little') | |
.option('-O, --outfmt <fmt>', 'Output munger', 'pop') | |
.parse(process.argv) | |
image = fs.readFileSync(program.args[0]) | |
mtpl = tpls[program.outfmt] | |
words = image.length / 2 | |
out = mtpl.hdr | |
if program.endian is 'little' | |
out += mtpl.word(image.readUInt16LE(i * 2)) for i in [0..words - 1] | |
else | |
out += mtpl.word(image.readUInt16BE(i * 2)) for i in [0..words - 1] | |
out += mtpl.end | |
console.log out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment