Fix some comments. Some instructions are still failing

This commit is contained in:
Miguel Angel 2024-09-06 13:20:10 +02:00
parent 6535ef4dc3
commit a1cedd91ef

View File

@ -11,15 +11,15 @@ const STACK_SIZE = 16;
const REGISTERS = 16; const REGISTERS = 16;
class CPU { class CPU {
pc: number; // 16b pc: number; // 16b
indexReg: number; // 16b indexReg: number; // 16b
regs: Uint8Array; regs: Uint8Array;
delayTimer: number; // 8b delayTimer: number; // 8b
soundTimer: number; // 8b soundTimer: number; // 8b
stackPointer: number; // 16b stackPointer: number; // 16b
stack: Uint16Array; stack: Uint16Array; // 16b
memory: Uint8Array; memory: Uint8Array;
displayMemory: Uint8Array; displayMemory: Uint8Array;
@ -27,9 +27,7 @@ class CPU {
keyboard: Keyboard; keyboard: Keyboard;
audio: Chip8Audio; audio: Chip8Audio;
rng: RNG;
rng: RNG;
constructor(keyboard: Keyboard, audio: Chip8Audio) { constructor(keyboard: Keyboard, audio: Chip8Audio) {
this.memory = new Uint8Array(MEMORY_SIZE); this.memory = new Uint8Array(MEMORY_SIZE);
@ -77,7 +75,7 @@ class CPU {
private setupFont() { private setupFont() {
// Using address from 050 - 09F ?? // Using address from 050 - 09F
let addressFont = 0x050; let addressFont = 0x050;
// Every character has 5 Bytes // Every character has 5 Bytes
@ -104,7 +102,7 @@ class CPU {
} }
public loadRom(rom: Uint8Array) { public loadRom(rom: Uint8Array) {
// Loads a ROM into starting PC addres?? // Loads a ROM into starting PC address
console.log(rom); console.log(rom);
for(let i = 0; i < rom.length; i++) { for(let i = 0; i < rom.length; i++) {
this.memory[this.pc+i] = rom[i]; this.memory[this.pc+i] = rom[i];
@ -283,8 +281,8 @@ class CPU {
// Vx <<= 1 // Vx <<= 1
// Set VF to 1 if the most significant bit of VX. // Set VF to 1 if the most significant bit of VX.
// Then shift to the left Vx // Then shift to the left Vx
this.regs[0xF] = (this.regs[nib2]) >> 7; this.regs[0xF] = (this.regs[nib2]) >> 7; // Get msb
this.regs[nib2] = (this.regs[nib2] << 1); this.regs[nib2] = (this.regs[nib2] << 1) & 0xFF;
this.incrementPC(); this.incrementPC();
} }
@ -391,7 +389,7 @@ class CPU {
} }
if(!keyPressed) if(!keyPressed)
return; // NOT INCREMENT PC SO WE ARE STUCK IN THIS WAITING return; // NOT INCREMENT PC SO WE ARE STUCK IN THIS WAITING (also don't decrement timers???)
this.incrementPC(); this.incrementPC();
}else if(secondOpcode == 0x15) { }else if(secondOpcode == 0x15) {