Skip to content

Commit 65c0e54

Browse files
committed
Add progress display
1 parent 0585534 commit 65c0e54

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ command
1616
- Implement UNFLoader text display support
1717
- Automated native executable build
1818
- Proper command line argument handling
19+
- Progress display
1920

2021
## [1.2.5] - 2021-07-27
2122

loader.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ const fs = require('fs');
99
const ACK = Buffer.from('cmdr\0', 'ascii');
1010
const TIMEOUT = 1000;
1111

12-
// TODO: add progress support
13-
// const MEG = 1024 * 1024;
14-
// const STATUS_UPDATE_AT = MEG;
12+
const MEG = 1024 * 1024;
13+
// This should be a multiple of 512
14+
const STATUS_UPDATE_AT = MEG;
1515

1616
const ROM_START_ADDRESS = 0x10000000;
1717
const CRC_AREA = 0x100000 + 4096;
@@ -83,7 +83,18 @@ async function sendData(port, data) {
8383

8484
console.log('Sending...');
8585

86-
await writeToPort(port, data);
86+
async function continueUpload(offset = 0) {
87+
const remainingBytes = size - offset;
88+
if (remainingBytes > 0) {
89+
const amount = Math.min(STATUS_UPDATE_AT, remainingBytes);
90+
const nextOffset = offset + amount;
91+
await writeToPort(port, data.slice(offset, nextOffset));
92+
console.log(`Uploaded ${((nextOffset / size) * 100).toFixed(2)}%`);
93+
await continueUpload(nextOffset);
94+
}
95+
}
96+
97+
await continueUpload();
8798

8899
console.log('Now booting...');
89100
await writeToPort(port, prepareCommand(commands.ROM_START, 0, 0, 1));

0 commit comments

Comments
 (0)