More instructions
This commit is contained in:
parent
25d652b173
commit
174259f1ea
@ -18,6 +18,10 @@ class RNG {
|
|||||||
nextInt(min: number, max: number): number {
|
nextInt(min: number, max: number): number {
|
||||||
return Math.floor(this.next() * (max - min + 1)) + min;
|
return Math.floor(this.next() * (max - min + 1)) + min;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
next255(): number {
|
||||||
|
return Math.floor(this.next() * 255);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default RNG;
|
export default RNG;
|
68
src/cpu.ts
68
src/cpu.ts
@ -216,20 +216,28 @@ class CPU {
|
|||||||
// Vx -= Vy
|
// Vx -= Vy
|
||||||
this.registers[0xF] = this.registers[secondNibble] > this.registers[thirdNibble] ? 1 : 0;
|
this.registers[0xF] = this.registers[secondNibble] > this.registers[thirdNibble] ? 1 : 0;
|
||||||
let subs = this.registers[secondNibble] - this.registers[thirdNibble];
|
let subs = this.registers[secondNibble] - this.registers[thirdNibble];
|
||||||
|
this.registers[secondNibble] = subs;
|
||||||
this.incrementPC();
|
this.incrementPC();
|
||||||
}else if(lastNibble == 0x6) {
|
}else if(lastNibble == 0x6) {
|
||||||
// 8XY6
|
// 8XY6
|
||||||
// Vx >>= 1
|
// Vx >>= 1
|
||||||
this.registers[secondNibble] >> 1;
|
this.registers[0xF] = this.registers[0xF] & 1; // ???? // Store the least significant bit of VX prior
|
||||||
|
this.registers[secondNibble] >>= 1;
|
||||||
this.incrementPC();
|
this.incrementPC();
|
||||||
}else if(lastNibble == 0x7) {
|
}else if(lastNibble == 0x7) {
|
||||||
// 8XY7
|
// 8XY7
|
||||||
// Vx = Vy - Vx
|
// Vx = Vy - Vx
|
||||||
this.registers[0xF] = this.registers[secondNibble] > this.registers[thirdNibble] ? 1 : 0;
|
this.registers[0xF] = this.registers[thirdNibble] > this.registers[secondNibble] ? 1 : 0;
|
||||||
let subs = this.registers[secondNibble] - this.registers[thirdNibble];
|
let subs = this.registers[thirdNibble] - this.registers[secondNibble];
|
||||||
|
this.registers[secondNibble] = subs;
|
||||||
this.incrementPC();
|
this.incrementPC();
|
||||||
}else if(lastNibble == 0xE) {
|
}else if(lastNibble == 0xE) {
|
||||||
|
// 8XYE
|
||||||
|
// Vx <<= 1
|
||||||
|
// Set VF to 1 if the most significant bit of VX prior to that shift was set
|
||||||
|
this.registers[0xF] = this.registers[0xF] >> 3;
|
||||||
|
this.registers[secondNibble] <<= 1;
|
||||||
|
this.incrementPC();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -245,6 +253,58 @@ class CPU {
|
|||||||
this.incrementPC();
|
this.incrementPC();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 0xA: {
|
||||||
|
// ANNN
|
||||||
|
// Sets I to the address NNN
|
||||||
|
this.indexReg = opcode & 0x0FFF;
|
||||||
|
this.incrementPC();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 0xB:{
|
||||||
|
// BNNN
|
||||||
|
// Jumps to the address NNN plus V0
|
||||||
|
this.pc = this.registers[0] + opcode & 0x0FFF;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 0xC: {
|
||||||
|
// CXNN
|
||||||
|
// Vx = rand() & NN
|
||||||
|
let secondNibble = firstOpcode & 0xF; //0X00
|
||||||
|
this.registers[secondNibble] = this.rng.next255() & secondOpcode;
|
||||||
|
this.incrementPC();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 0xD: {
|
||||||
|
// DXYN
|
||||||
|
// draw(Vx, Vy, N)
|
||||||
|
let secondNibble = firstOpcode & 0xF; //0X00
|
||||||
|
let thirdNibble = secondOpcode >> 4; //00Y0
|
||||||
|
let fourthNibble = secondOpcode & 0xF;
|
||||||
|
|
||||||
|
this.registers[0xF] = 0;
|
||||||
|
|
||||||
|
let regX = this.registers[secondNibble];
|
||||||
|
let regY = this.registers[thirdNibble];
|
||||||
|
|
||||||
|
let y = 0;
|
||||||
|
while(y < fourthNibble) {
|
||||||
|
// A sprite is always 8 bits horizontal
|
||||||
|
let pixel = this.memory[this.indexReg + y];
|
||||||
|
let x = 0;
|
||||||
|
while(x < 8) {
|
||||||
|
const msb = 0x80;
|
||||||
|
|
||||||
|
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.incrementPC();
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user