Implement CCF (Clear Carry Flag) and CHP (Carry Hop)
This commit is contained in:
parent
890bb16145
commit
d1a84748fc
|
|
@ -103,9 +103,20 @@ function CPU(mem) {
|
||||||
this.instructionPointer = this.memory[addr];
|
this.instructionPointer = this.memory[addr];
|
||||||
},
|
},
|
||||||
|
|
||||||
// TODO: UNIMPLEMENTED
|
carry_clear: () => {
|
||||||
carry_toggle: () => { return; },
|
console.log("CFC");
|
||||||
carry_hop: () => { return; },
|
this.carryFlag = 0;
|
||||||
|
this.instructionPointer += 1;
|
||||||
|
},
|
||||||
|
|
||||||
|
carry_hop: () => {
|
||||||
|
console.log("CHP");
|
||||||
|
if (this.carryFlag != 0) {
|
||||||
|
this.instructionPointer += 2;
|
||||||
|
} else {
|
||||||
|
this.instructionPointer += 1;
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
this.perform_operation = (opcode, arg) => {
|
this.perform_operation = (opcode, arg) => {
|
||||||
|
|
@ -162,6 +173,14 @@ function CPU(mem) {
|
||||||
this.instructions.jump_addr(arg);
|
this.instructions.jump_addr(arg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 13:
|
||||||
|
this.instructions.carry_clear(arg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 14:
|
||||||
|
this.instructions.carry_hop(arg);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
console.error( `Invalid opcode: ${opcode} with argument ${arg}` );
|
console.error( `Invalid opcode: ${opcode} with argument ${arg}` );
|
||||||
}
|
}
|
||||||
|
|
@ -205,7 +224,7 @@ function CPU(mem) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// TEST
|
// TESTS
|
||||||
|
|
||||||
let halt_and_catch_fire = [
|
let halt_and_catch_fire = [
|
||||||
[0, 0],
|
[0, 0],
|
||||||
|
|
@ -219,8 +238,6 @@ let test_lda_sto = [
|
||||||
[2, 6], // STO addr
|
[2, 6], // STO addr
|
||||||
[0, 0], // END
|
[0, 0], // END
|
||||||
];
|
];
|
||||||
// let comp = new CPU(test_lda_sto);
|
|
||||||
// comp.run_program();
|
|
||||||
|
|
||||||
let test_add_sub_nocarry = [
|
let test_add_sub_nocarry = [
|
||||||
[5, 6], // ADD lit ... acc = 6
|
[5, 6], // ADD lit ... acc = 6
|
||||||
|
|
@ -234,8 +251,6 @@ let test_add_sub = [
|
||||||
[5, 26], // ADD lit
|
[5, 26], // ADD lit
|
||||||
[0, 0], // END
|
[0, 0], // END
|
||||||
]
|
]
|
||||||
// let comp = new CPU(test_add_sub);
|
|
||||||
//comp.run_program();
|
|
||||||
|
|
||||||
let test_hop = [
|
let test_hop = [
|
||||||
[5, 8], // ADD lit ... acc = 8
|
[5, 8], // ADD lit ... acc = 8
|
||||||
|
|
@ -244,10 +259,6 @@ let test_hop = [
|
||||||
[7, 8], // SUB lit ... acc = 0
|
[7, 8], // SUB lit ... acc = 0
|
||||||
[0, 0]
|
[0, 0]
|
||||||
]
|
]
|
||||||
//let comp = new CPU(test_hop);
|
|
||||||
//comp.run_program();
|
|
||||||
|
|
||||||
// TODO: TEST HOP_addr
|
|
||||||
|
|
||||||
let test_jmp = [
|
let test_jmp = [
|
||||||
[11, 4], // 0
|
[11, 4], // 0
|
||||||
|
|
@ -257,6 +268,24 @@ let test_jmp = [
|
||||||
[5, 8], // 4 ... ADD lit ... acc = 8
|
[5, 8], // 4 ... ADD lit ... acc = 8
|
||||||
[0, 0], // 5 ... END
|
[0, 0], // 5 ... END
|
||||||
]
|
]
|
||||||
let comp = new CPU(test_jmp);
|
|
||||||
comp.run_program();
|
let test_chp = [
|
||||||
console.table(comp.memory);
|
[5, 8], // ADD lit ... acc = 8
|
||||||
|
[14, 0], // CHP ... shouldn't hop (CF = 0)
|
||||||
|
[5, 1], // ADD lit ... acc = 9
|
||||||
|
[5, 8], // ADD lit ... acc = 1 and CF = 1
|
||||||
|
[14, 0], // CHP ... hop! (CF = 1)
|
||||||
|
[0, 0], // END
|
||||||
|
[7, 1], // SUB lit ... acc = 0
|
||||||
|
[13, 0], // CFC ... CF = 0
|
||||||
|
[0, 0], // END
|
||||||
|
]
|
||||||
|
|
||||||
|
//let comp = new CPU(test_chp);
|
||||||
|
|
||||||
|
let comp = new CPU(test_lda_sto);
|
||||||
|
let memory_snapshots = comp.run_program();
|
||||||
|
log_table_with_title(memory_snapshots.memoryAtEnd, 'Memory after running');
|
||||||
|
log_table_with_title(memory_snapshots.memoryAtStart, 'Memory before running');
|
||||||
|
|
||||||
|
// TODO: TEST HOP_addr
|
||||||
Loading…
Reference in New Issue