diff --git a/CHANGELOG.md b/CHANGELOG.md index f404f82..0f19ad9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ command - Implement UNFLoader text display support - Automated native executable build - Proper command line argument handling +- Progress display ## [1.2.5] - 2021-07-27 diff --git a/loader.js b/loader.js index c4bd78c..0ec4f79 100644 --- a/loader.js +++ b/loader.js @@ -9,9 +9,9 @@ const fs = require('fs'); const ACK = Buffer.from('cmdr\0', 'ascii'); const TIMEOUT = 1000; -// TODO: add progress support -// const MEG = 1024 * 1024; -// const STATUS_UPDATE_AT = MEG; +const MEG = 1024 * 1024; +// This should be a multiple of 512 +const STATUS_UPDATE_AT = MEG; const ROM_START_ADDRESS = 0x10000000; const CRC_AREA = 0x100000 + 4096; @@ -83,7 +83,18 @@ async function sendData(port, data) { console.log('Sending...'); - await writeToPort(port, data); + async function continueUpload(offset = 0) { + const remainingBytes = size - offset; + if (remainingBytes > 0) { + const amount = Math.min(STATUS_UPDATE_AT, remainingBytes); + const nextOffset = offset + amount; + await writeToPort(port, data.slice(offset, nextOffset)); + console.log(`Uploaded ${((nextOffset / size) * 100).toFixed(2)}%`); + await continueUpload(nextOffset); + } + } + + await continueUpload(); console.log('Now booting...'); await writeToPort(port, prepareCommand(commands.ROM_START, 0, 0, 1));