1
0
Fork 0
mirror of https://github.com/notwa/mm synced 2024-11-05 03:29:02 -08:00

simplify size handling

This commit is contained in:
Connor Olding 2015-11-21 00:01:15 -08:00
parent 88b230d3c7
commit 70827cd830

View file

@ -740,7 +740,6 @@ function Parser:format_out(outformat, first, args, const, formatconst)
local lookup = { local lookup = {
[1]=self.dumper.add_instruction_26, [1]=self.dumper.add_instruction_26,
[3]=self.dumper.add_instruction_5_5_16, [3]=self.dumper.add_instruction_5_5_16,
[4]=self.dumper.add_instruction_5_5_5_11,
[5]=self.dumper.add_instruction_5_5_5_5_6, [5]=self.dumper.add_instruction_5_5_5_5_6,
} }
out = {} out = {}
@ -838,31 +837,15 @@ function Dumper:push(t)
end end
function Dumper:add_instruction_26(i, a) function Dumper:add_instruction_26(i, a)
local t = {} self:push{i, a}
t.sizes = {26}
t.data = {i, a}
self:push(t)
end end
function Dumper:add_instruction_5_5_16(i, a, b, c) function Dumper:add_instruction_5_5_16(i, a, b, c)
local t = {} self:push{i, a, b, c}
t.sizes = {5, 5, 16}
t.data = {i, a, b, c}
self:push(t)
end
function Dumper:add_instruction_5_5_5_11(i, a, b, c, d)
local t = {}
t.sizes = {5, 5, 5, 11}
t.data = {i, a, b, c, d}
self:push(t)
end end
function Dumper:add_instruction_5_5_5_5_6(i, a, b, c, d, e) function Dumper:add_instruction_5_5_5_5_6(i, a, b, c, d, e)
local t = {} self:push{i, a, b, c, d, e}
t.sizes = {5, 5, 5, 5, 6}
t.data = {i, a, b, c, d, e}
self:push(t)
end end
function Dumper:add_define(name, number) function Dumper:add_define(name, number)
@ -974,56 +957,23 @@ function Dumper:dump()
local lw = 0 local lw = 0
local val = nil local val = nil
local i = t.data[1] local i = t[1]
uw = uw + i*0x400 uw = uw + i*0x400
if #t.sizes == 1 then if #t == 2 then
if t.sizes[1] == 26 then val = self:valvar(t[2], 26)
val = self:valvar(t.data[2], 26) uw = uw + math.floor(val/0x10000)
uw = uw + math.floor(val/0x10000) lw = lw + val % 0x10000
lw = lw + val % 0x10000 elseif #t == 4 then
else uw = uw + self:valvar(t[2], 5)*0x20
self:error('bad 1-size') uw = uw + self:valvar(t[3], 5)
end lw = lw + self:valvar(t[4], 16)
elseif #t.sizes == 3 then elseif #t == 6 then
if t.sizes[1] == 5 and t.sizes[2] == 5 and t.sizes[3] == 16 then uw = uw + self:valvar(t[2], 5)*0x20
val = self:valvar(t.data[2], 5) uw = uw + self:valvar(t[3], 5)
uw = uw + val*0x20 lw = lw + self:valvar(t[4], 5)*0x800
val = self:valvar(t.data[3], 5) lw = lw + self:valvar(t[5], 5)*0x40
uw = uw + val lw = lw + self:valvar(t[6], 6)
val = self:valvar(t.data[4], 16)
lw = lw + val
else
self:error('bad 3-size')
end
elseif #t.sizes == 4 then
if t.sizes[1] == 5 and t.sizes[2] == 5 and t.sizes[3] == 5 and t.sizes[4] == 11 then
val = self:valvar(t.data[2], 5)
uw = uw + val*0x20
val = self:valvar(t.data[3], 5)
uw = uw + val
val = self:valvar(t.data[4], 5)
lw = lw + val*0x800
val = self:valvar(t.data[5], 11)
lw = lw + val
else
self:error('bad 4-size')
end
elseif #t.sizes == 5 then
if t.sizes[1] == 5 and t.sizes[2] == 5 and t.sizes[3] == 5 and t.sizes[4] == 5 and t.sizes[5] == 6 then
val = self:valvar(t.data[2], 5)
uw = uw + val*0x20
val = self:valvar(t.data[3], 5)
uw = uw + val
val = self:valvar(t.data[4], 5)
lw = lw + val*0x800
val = self:valvar(t.data[5], 5)
lw = lw + val*0x40
val = self:valvar(t.data[6], 6)
lw = lw + val
else
self:error('bad 5-size')
end
else else
self:error('unknown n-size') self:error('unknown n-size')
end end