cpu - WIP - Start re-configuring CLI interface, in order to allow passing clock speed as a CLI argument (while also keeping a defualt value in machine.config.js)
This commit is contained in:
parent
f335aba94d
commit
6545df9cfd
6
cpu.js
6
cpu.js
|
|
@ -3,7 +3,7 @@ const readlineSync = require('readline-sync');
|
|||
|
||||
const {
|
||||
INITIAL_IP_ADDRESS,
|
||||
CYCLE_LIMIT,
|
||||
DEFAULT_CYCLE_LIMIT,
|
||||
KEYPAD_ADDR,
|
||||
KEY_MAP,
|
||||
} = require('./machine.config');
|
||||
|
|
@ -340,8 +340,8 @@ async function stepCPU(debugInfo, debug = false, prettyPrintDisplay = false) {
|
|||
CPU.cycleCounter += 1;
|
||||
}
|
||||
logCPUState(debugInfo, debug, prettyPrintDisplay);
|
||||
if (CYCLE_LIMIT) { // Temporary limit as a lazy way to halt infinite loops
|
||||
if (CPU.cycleCounter >= CYCLE_LIMIT) {
|
||||
if (DEFAULT_CYCLE_LIMIT) { // Temporary limit as a lazy way to halt infinite loops
|
||||
if (CPU.cycleCounter >= DEFAULT_CYCLE_LIMIT) {
|
||||
console.warn(' HALTING - reached cycle limit');
|
||||
CPU.running = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@ For extended commentary, see [issues](issues.md).
|
|||
|
||||
### Todo
|
||||
|
||||
- Finish WIP on run-cli arg parsing
|
||||
- Pass CYCLE_COUNT as a cli arg
|
||||
|
||||
- (cpu) !! Fix overflow flag
|
||||
- Add a flag for bank-switching to the ~zero-page
|
||||
- Remove run-scripts and add the ability to run `./cpu.js` and `./assembler.js` directly -- cf. [#1](issues.md#1---improve-cli-interface)
|
||||
|
|
@ -15,6 +18,7 @@ For extended commentary, see [issues](issues.md).
|
|||
|
||||
### Features
|
||||
|
||||
- (cpu) allow arrow keys, too
|
||||
- [fix] (cpu) Execute `JMP $FF` on startup / Implement ROM — see [#2](issues.md#2---startup-execute-jmp-ff)
|
||||
- (assembler) Validate labels
|
||||
- (assembler) Extract debugging to its own module
|
||||
|
|
|
|||
40
run-cpu.js
40
run-cpu.js
|
|
@ -7,19 +7,13 @@ const computer = require('./cpu.js');
|
|||
const assembler = require('./assembler.js');
|
||||
const { logRunningHeader } = require('./logging.js');
|
||||
|
||||
|
||||
// Load file...
|
||||
|
||||
let filename = null;
|
||||
process.argv.forEach((arg, index) => {
|
||||
if (arg === '-f' && process.argv.length > (index -1)) {
|
||||
filename = process.argv[index + 1];
|
||||
}
|
||||
});
|
||||
|
||||
if (!filename) {
|
||||
console.error('Filename required');
|
||||
console.error('eg: run-cpu.js -f code.asm');
|
||||
let filename;
|
||||
try {
|
||||
filename = getArgumentValue('-f', `Missing filename`);
|
||||
} catch (error) {
|
||||
console.error(error.message);
|
||||
process.exit()
|
||||
}
|
||||
|
||||
|
|
@ -52,4 +46,26 @@ computer.runProgram(
|
|||
singleStep,
|
||||
prettyPrint,
|
||||
speed
|
||||
);
|
||||
);
|
||||
|
||||
|
||||
// CLI args TODO
|
||||
// - check if value is the name of another arg
|
||||
// - usage info
|
||||
// - catch nonexistant flags
|
||||
|
||||
/**
|
||||
* @param {string} flag - The command line flag, eg. '-f'
|
||||
* @param {string} errorMessage - The error to throw if a value isn't found
|
||||
* @returns {string}
|
||||
**/
|
||||
function getArgumentValue(flag, errorMessage) {
|
||||
let value = null;
|
||||
process.argv.forEach((arg, index) => {
|
||||
if (arg === flag && process.argv.length > (index -1)) {
|
||||
value = process.argv[index + 1];
|
||||
}
|
||||
});
|
||||
if (!value) throw new Error(errorMessage);
|
||||
return value;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue