diff --git a/core/cpu/opcodes.ts b/core/cpu/opcodes.ts index 0d6d9a0..fc0669a 100644 --- a/core/cpu/opcodes.ts +++ b/core/cpu/opcodes.ts @@ -2208,7 +2208,8 @@ function handleOpcodeFx(opcode: i32): i32 { let registerAF1: i32 = sixteenBitLoadSyncCycles(stackPointer); Cpu.stackPointer = u16Portable(stackPointer + 2); Cpu.registerA = splitHighByte(registerAF1); - Cpu.registerF = splitLowByte(registerAF1); + // The low four bits of F always read 0 + Cpu.registerF = (splitLowByte(registerAF1) & 0xf0); return 4; } case 0xf2: { diff --git a/core/graphics/graphics.ts b/core/graphics/graphics.ts index 13d70d6..1f58d1a 100644 --- a/core/graphics/graphics.ts +++ b/core/graphics/graphics.ts @@ -118,7 +118,7 @@ export class Graphics { static loadState(): void { // Graphics Graphics.scanlineCycleCounter = load(getSaveStateMemoryOffset(0x00, Graphics.saveStateSlot)); - Graphics.scanlineRegister = load(getSaveStateMemoryOffset(0x04, Graphics.scanlineRegister)); + Graphics.scanlineRegister = load(getSaveStateMemoryOffset(0x04, Graphics.saveStateSlot)); Graphics.scrollX = load(getSaveStateMemoryOffset(0x05, Graphics.saveStateSlot)); Graphics.scrollY = load(getSaveStateMemoryOffset(0x06, Graphics.saveStateSlot)); Graphics.windowX = load(getSaveStateMemoryOffset(0x07, Graphics.saveStateSlot)); diff --git a/core/graphics/lcd.ts b/core/graphics/lcd.ts index 446b0c8..2dd06d5 100644 --- a/core/graphics/lcd.ts +++ b/core/graphics/lcd.ts @@ -133,7 +133,7 @@ export function setLcdStatus(): void { if (scanlineCycleCounter >= MIN_CYCLES_SPRITES_LCD_MODE) { // Searching Sprites Atts newLcdMode = 2; - } else if (scanlineCycleCounter >= MIN_CYCLES_SPRITES_LCD_MODE) { + } else if (scanlineCycleCounter >= Graphics.MIN_CYCLES_TRANSFER_DATA_LCD_MODE()) { // Transferring data to lcd newLcdMode = 3; } diff --git a/core/memory/writeTraps.ts b/core/memory/writeTraps.ts index c14f5b4..6aa2b7b 100644 --- a/core/memory/writeTraps.ts +++ b/core/memory/writeTraps.ts @@ -98,8 +98,10 @@ export function checkWriteTraps(offset: i32, value: i32): boolean { // Serial if (offset === Serial.memoryLocationSerialTransferControl) { - // SC - return Serial.updateTransferControl(value); + // SC: unused bits read 1 (6-1 on DMG, 6-2 on CGB) + Serial.updateTransferControl(value); + eightBitStoreIntoGBMemory(offset, value | (Cpu.GBCEnabled ? 0x7c : 0x7e)); + return false; } // Sound diff --git a/core/sound/channel1.ts b/core/sound/channel1.ts index e7f85a8..a45bcfe 100644 --- a/core/sound/channel1.ts +++ b/core/sound/channel1.ts @@ -245,7 +245,7 @@ export class Channel1 { // Function to load the save state from memory static loadState(): void { // Cycle Counter - Channel1.cycleCounter = load(getSaveStateMemoryOffset(0x00, Channel1.cycleCounter)); + Channel1.cycleCounter = load(getSaveStateMemoryOffset(0x00, Channel1.saveStateSlot)); // NRx0 Channel1.NRx0SweepPeriod = load(getSaveStateMemoryOffset(0x04, Channel1.saveStateSlot)); diff --git a/core/sound/channel2.ts b/core/sound/channel2.ts index 27278bc..4841a7b 100644 --- a/core/sound/channel2.ts +++ b/core/sound/channel2.ts @@ -204,7 +204,7 @@ export class Channel2 { // Function to load the save state from memory static loadState(): void { // Cycle Counter - Channel2.cycleCounter = load(getSaveStateMemoryOffset(0x00, Channel2.cycleCounter)); + Channel2.cycleCounter = load(getSaveStateMemoryOffset(0x00, Channel2.saveStateSlot)); // NRx0 // No NRx0 diff --git a/core/sound/channel3.ts b/core/sound/channel3.ts index 1c6fd18..19a21e9 100644 --- a/core/sound/channel3.ts +++ b/core/sound/channel3.ts @@ -191,7 +191,7 @@ export class Channel3 { // Function to load the save state from memory static loadState(): void { // Cycle Counter - Channel3.cycleCounter = load(getSaveStateMemoryOffset(0x00, Channel3.cycleCounter)); + Channel3.cycleCounter = load(getSaveStateMemoryOffset(0x00, Channel3.saveStateSlot)); // NRx0 // No NRx0 diff --git a/core/sound/channel4.ts b/core/sound/channel4.ts index 378414a..531213d 100644 --- a/core/sound/channel4.ts +++ b/core/sound/channel4.ts @@ -194,7 +194,7 @@ export class Channel4 { // Function to load the save state from memory static loadState(): void { // Cycle Counter - Channel4.cycleCounter = load(getSaveStateMemoryOffset(0x00, Channel4.cycleCounter)); + Channel4.cycleCounter = load(getSaveStateMemoryOffset(0x00, Channel4.saveStateSlot)); // NRx0 // No NRx0