Skip to content

Commit

Permalink
update code with SD card logic, port to new cart design and teensy 4.1 (
Browse files Browse the repository at this point in the history
  • Loading branch information
DiscoStarslayer authored Aug 1, 2021
1 parent 2097ad1 commit 128f889
Show file tree
Hide file tree
Showing 5 changed files with 437 additions and 109 deletions.
98 changes: 78 additions & 20 deletions manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { argv } = yargs(hideBin(process.argv))

const portPath = argv.port || 'COM3';

const port = new SerialPort(portPath, { baudRate: 9600 });
const port = new SerialPort(portPath, { baudRate: 4608000 });

const dumpBuffer = [];

Expand All @@ -21,27 +21,73 @@ const read = index => {
port.write(readCommandFromIndex(index));
}

let limit = argv.limit ? parseInt(argv.limit, 16) : 0x1F_FFFF;
const writeCommandFromIndex = (index, write) => {
const str = `W${index.toString(16)}:${write.toString(16)}%`
return str;
}

port.on('data', data => {
const number = data.toString('ASCII');
const write = (index, write) => {
port.write(writeCommandFromIndex(index, write));
}

const bin = Buffer.alloc(2);
bin.writeUInt16LE(parseInt(number, 16));
dumpBuffer.push(bin);
const erase = () => {
port.write('ERS%');
}

if (index % 0x00_FFFF === 0) {
console.log('Dumping...', `${Math.round(index / limit * 100)}%`);
}
let limit = argv.limit ? parseInt(argv.limit, 16) : 0x1F_FFFF;

if (index === limit) {
const completeBuffer = Buffer.concat(dumpBuffer);
const start = Date.now();
let timeElapsed = 0;

fs.writeFileSync(out, completeBuffer);
process.exit(0);
} else {
index += 1;
read(index);
port.on('data', data => {
if (argv.mode === 'dump') {
const number = data.toString('ASCII');
const bin = Buffer.alloc(2);
bin.writeUInt16LE(parseInt(number, 16));
dumpBuffer.push(bin);

if (index % 0x00_FFF === 0) {
timeElapsed = Date.now() - start;
const percentCompleted = index / limit;

const estTimeRemaining = Math.round((timeElapsed / percentCompleted) * (1 - percentCompleted));
console.log('Dumping...', `${Math.round(index / limit * 100)}%,`, Math.round(estTimeRemaining / 1000 / 60), "minutes left");
}

if (index === limit) {
const completeBuffer = Buffer.concat(dumpBuffer);

fs.writeFileSync(out, completeBuffer);
console.log('Done');
process.exit(0);
} else {
index += 1;
read(index);
}
} else if (argv.mode === 'write') {
if (!erased) {
console.log('Done');
erased = true;
}

if (index % 0x00_FFFF === 0) {
console.log('Writing...', `${Math.round((index / (rom.length / 2) * 100))}%`)
}

if (index === rom.length / 2) {
console.log('Done');
process.exit(0);
} else {
write(index, rom.readUInt16LE(index * 2));
index++;
}
} else if (argv.mode === 'sddump') {
const result = data.toString('ASCII');
console.log(result);

if (result.includes('Done!')) {
process.exit(0);
}
}
})

Expand All @@ -53,6 +99,18 @@ if (argv.bank === 'HIGH') {
}

let index = 0x00_0000

// Read first word
read(index);
let erased = false;
let rom;

if (argv.mode === 'dump') {
// Read first word
read(index);
} else if (argv.mode === 'write') {
rom = fs.readFileSync(argv.rom);

console.log('Erasing...');
erase();
} else if (argv.mode === 'sddump') {
console.log(`Dumping file ${argv.name}:${argv.length}`);
port.write(`D${argv.name}:${argv.length}`);
}
39 changes: 0 additions & 39 deletions manager/readOne.js

This file was deleted.

3 changes: 2 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@

[env:teensy40]
platform = teensy
board = teensy40
board = teensy41
framework = arduino
lib_deps = greiman/SdFat@^2.0.6
Loading

0 comments on commit 128f889

Please sign in to comment.