(Created page with "local p = {} local TITLE_ALIGN_SIZE = 0x8000 function roundup(num, align) return math.ceil(num / align) * align end function p.raw_blocks_to_bytes(blocks) return blocks * 128 * 1024 end function p.raw_blocks_to_kilobytes(blocks) return blocks * 128 end function p.raw_blocks_to_megabytes(blocks) return blocks / 8 end function p.raw_bytes_to_blocks(bytes) return bytes / 1024 / 128 end function p.roundup_all_sizes_to_bytes(sizes) total = 0 for i, v in ipairs(s...") |
No edit summary |
||
Line 20: | Line 20: | ||
function p.raw_bytes_to_blocks(bytes) | function p.raw_bytes_to_blocks(bytes) | ||
return bytes / 1024 / 128 | return math.ceil(bytes / 1024 / 128) | ||
end | |||
function p.raw_megabytes_to_blocks(megabytes) | |||
return math.ceil(megabytes * 8) | |||
end | end | ||
Line 29: | Line 33: | ||
end | end | ||
return total | return total | ||
end | |||
function p.blocks_to_bytes(frame) | |||
return blocks_to_bytes(frame.args[1]) | |||
end | end | ||
function p.blocks_to_kilobytes(frame) | function p.blocks_to_kilobytes(frame) | ||
return blocks_to_kilobytes(frame.args[1]) | return blocks_to_kilobytes(frame.args[1]) | ||
end | |||
function p.blocks_to_megabytes(frame) | |||
return blocks_to_megabytes(frame.args[1]) | |||
end | |||
function p.bytes_to_blocks(frame) | |||
return bytes_to_blocks(frame.args[1]) | |||
end | |||
function p.megabytes_to_blocks(frame) | |||
return megabytes_to_blocks(frame.args[1]) | |||
end | end | ||
return p | return p |
Revision as of 04:31, 18 October 2023
Convert between Nintendo blocks and standard byte units.
Examples
Wikitext | Result |
---|---|
{{#invoke:NBlocks|blocks_to_bytes|16}} |
2097152 |
{{#invoke:NBlocks|blocks_to_kib|16}} |
2048 |
{{#invoke:NBlocks|blocks_to_mib|16}} |
2 |
{{#invoke:NBlocks|bytes_to_blocks|2097152}} |
16 |
{{#invoke:NBlocks|mib_to_blocks|2}} |
16 |
{{#invoke:NBlocks|format_bytes|786333696}} |
749.91 MiB |
local p = {}
local TITLE_ALIGN_SIZE = 0x8000
function roundup(num, align)
return math.ceil(num / align) * align
end
function p.raw_blocks_to_bytes(blocks)
return blocks * 128 * 1024
end
function p.raw_blocks_to_kilobytes(blocks)
return blocks * 128
end
function p.raw_blocks_to_megabytes(blocks)
return blocks / 8
end
function p.raw_bytes_to_blocks(bytes)
return math.ceil(bytes / 1024 / 128)
end
function p.raw_megabytes_to_blocks(megabytes)
return math.ceil(megabytes * 8)
end
function p.roundup_all_sizes_to_bytes(sizes)
total = 0
for i, v in ipairs(sizes) do
total = total + roundup(v, TITLE_ALIGN_SIZE)
end
return total
end
function p.blocks_to_bytes(frame)
return blocks_to_bytes(frame.args[1])
end
function p.blocks_to_kilobytes(frame)
return blocks_to_kilobytes(frame.args[1])
end
function p.blocks_to_megabytes(frame)
return blocks_to_megabytes(frame.args[1])
end
function p.bytes_to_blocks(frame)
return bytes_to_blocks(frame.args[1])
end
function p.megabytes_to_blocks(frame)
return megabytes_to_blocks(frame.args[1])
end
return p