Tried to pass the test but failed
This commit is contained in:
parent
26774f49af
commit
bc0f326bcc
13
src/cpu.ts
13
src/cpu.ts
@ -327,11 +327,15 @@ class CPU {
|
||||
case 0xD: {
|
||||
// DXYN
|
||||
// draw(Vx, Vy, N)
|
||||
// Draws a sprite at coordinate (VX, VY) that has a width of 8 pixels and a height of N pixels
|
||||
this.regs[0xF] = 0; // Reset register VF
|
||||
|
||||
let regX = this.regs[nib2];
|
||||
let regY = this.regs[nib3];
|
||||
|
||||
regX = regX % 64;
|
||||
regY = regY % 32;
|
||||
|
||||
for(let y = 0; y < nib4; y++) {
|
||||
// A sprite is always 8 bits horizontal
|
||||
let pixel = this.memory[this.indexReg + y]; // Fetch pixel from memory starting at I reg
|
||||
@ -340,7 +344,14 @@ class CPU {
|
||||
const MSB = 0x80; // 0b10000000
|
||||
|
||||
if((pixel & (MSB >> x)) != 0) {
|
||||
let mem = x + regX + ((y + regY) * SCREEN_WIDTH);
|
||||
let r = x + regX;
|
||||
let c = ((y + regY) * SCREEN_WIDTH);
|
||||
let mem = r + c;
|
||||
|
||||
if(r+c > 64*32) {
|
||||
mem = mem % (64*32);
|
||||
}
|
||||
|
||||
if(this.displayMemory[mem] == 1) {
|
||||
this.regs[0xF] = 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user