function parse_code(code) {
var bin = []
var bin_pos = -1
while (code.length > 0) {
if (bin.length == bin_pos) {
console.error("Can't continue, op_code all not match")
break
} else {
bin_pos = bin.length
}
for (var o of op_code) {
var op = Object.assign({}, o)
if (btoc(op.op_list) == code.substr(0, op.op_list.length)) {
code = code.slice(op.op_list.length)
if (op.data_bytes > 0) {
if (code.length < op.data_bytes) {
console.warn("op_code %s need %d bytes, but left %d", op.handler, op.data_bytes, code.length)
}
op.data = [].concat(ctob(code.substr(0, op.data_bytes)))
code = code.slice(op.data.length)
}
bin.push(op)
}
}
}
console.log("Parsed code\n===\n%s\n===\nUnparsed bytes: (%d) [ %s ]", bin.map(b => b.log.replace(/%value/, (b.data || []).map(hex).join(', ')) + '\n\tcomment: ' + b.comment).join('\n'), code.length, Array.from(code).map(hexString).join(', '))
return bin
}
parse_code(code)