Skip to content

Commit

Permalink
Add progress display
Browse files Browse the repository at this point in the history
  • Loading branch information
anacierdem committed Sep 7, 2021
1 parent 0585534 commit 65c0e54
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 15 additions & 4 deletions loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 65c0e54

Please sign in to comment.