51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
// Input file must contain a binary string with no spaces, linebreaks, etc.
|
|
|
|
const fs = require('fs');
|
|
const filename = process.argv[2];
|
|
const inputFile_str = fs.readFileSync(filename, 'utf8');
|
|
|
|
const create_square_wave_string = (s) => {
|
|
s = s.replace(/1/g, '▀');
|
|
return s = s.replace(/0/g, '▄');
|
|
}
|
|
|
|
const number_hex_string = (quantity) => {
|
|
let output = '';
|
|
let current_digit = 0;
|
|
for (let i = 0; i < quantity; i++) {
|
|
current_digit = i % 8;
|
|
output = output + current_digit;
|
|
}
|
|
return output;
|
|
}
|
|
|
|
const binary_string_to_bus_strings = (input) => {
|
|
let output = ['','','','','','','',''];
|
|
let input_bytes = input.match(/.{1,8}/g);
|
|
|
|
input_bytes.forEach( (byte) => {
|
|
let byte_array = byte.split('');
|
|
for (let i = 0; i < 8; i++) {
|
|
output[i] = output[i] + byte_array[i];
|
|
}
|
|
});
|
|
|
|
|
|
// Print output
|
|
let nums = number_hex_string(output[0].length);
|
|
let spaced_nums = nums.match(/.{1,8}/g).join(' ');
|
|
console.log();
|
|
console.log(spaced_nums);
|
|
|
|
output.forEach( (s) => {
|
|
let spaced = s.match(/.{1,8}/g).join(' ');
|
|
console.log(create_square_wave_string(spaced));
|
|
console.log();
|
|
});
|
|
console.log(spaced_nums);
|
|
console.log();
|
|
}
|
|
|
|
binary_string_to_bus_strings(inputFile_str); |