diff --git a/README.markdown b/README.markdown index c09d379..2f9a354 100644 --- a/README.markdown +++ b/README.markdown @@ -55,7 +55,7 @@ Boy is a Gamboy (dmg not 0) emulator written in Java. |-----------------------|----| |add sp e timing |:+1:| |boot div dmgABCmgb |:x: | -|boot hwio dmgABCmgb |:x: | +|boot hwio dmgABCmgb |:+1:| |boot regs dmgABC |:+1:| |call timing |:+1:| |call timing2 |:+1:| @@ -92,7 +92,7 @@ Boy is a Gamboy (dmg not 0) emulator written in Java. |--------------|----| |mem oam |:+1:| |reg f |:+1:| -|unused_hwio GS|:x: | +|unused_hwio GS|:+1:| #### Instructions diff --git a/src/cpu/InterruptFlagRegister.java b/src/cpu/InterruptFlagRegister.java index 53ebc90..1823a06 100644 --- a/src/cpu/InterruptFlagRegister.java +++ b/src/cpu/InterruptFlagRegister.java @@ -9,6 +9,9 @@ public class InterruptFlagRegister extends RamRegister { private static final int IF_ADRESS = 0xFF0F; + private static final int UNUSED_BIT_7 = 7; + private static final int UNUSED_BIT_6 = 6; + private static final int UNUSED_BIT_5 = 5; private static final int BUTTON_PRESSED_POSITION = 4; private static final int SERIAL_IO_TRANSFER_COMPLETE_POSITION = 3; private static final int TIMER_OVERFLOW_POSITION = 2; @@ -24,6 +27,9 @@ public class InterruptFlagRegister extends RamRegister public InterruptFlagRegister() { super(IF_ADRESS); + setBit(UNUSED_BIT_7, true); + setBit(UNUSED_BIT_6, true); + setBit(UNUSED_BIT_5, true); } public boolean getButtonPressedPending() diff --git a/src/gameboy/Gameboy.java b/src/gameboy/Gameboy.java index 482fe0b..200b74d 100644 --- a/src/gameboy/Gameboy.java +++ b/src/gameboy/Gameboy.java @@ -42,6 +42,29 @@ import ram.UnusableMemory1; import ram.VideoRam; import ram.WavePatternRam; +import serial.SerialControllRegister; +import serial.SerialTransferDataRegister; +import sound.ChannelControlRegister; +import sound.SelectionOfSoundOutputRegister; +import sound.SoundMode1Envelope; +import sound.SoundMode1FrequencyHigh; +import sound.SoundMode1FrequencyLow; +import sound.SoundMode1SweepRegister; +import sound.SoundMode1WavePatternDutyAndSoundLength; +import sound.SoundMode2Envelope; +import sound.SoundMode2FrequencyHigh; +import sound.SoundMode2FrequencyLow; +import sound.SoundMode2WavePatternDutyAndSoundLength; +import sound.SoundMode3FrequencyHigh; +import sound.SoundMode3FrequencyLow; +import sound.SoundMode3SelectOutputLevel; +import sound.SoundMode3SoundLength; +import sound.SoundMode3SoundOnOrOff; +import sound.SoundMode4CounterOrConsecutiveSelection; +import sound.SoundMode4Envelope; +import sound.SoundMode4PolynomialCounter; +import sound.SoundMode4SoundLength; +import sound.SoundOnOrOffRegister; import timer.DividerRegister; import timer.Timer; import timer.TimerControlRegister; @@ -87,7 +110,7 @@ public Gameboy(String RomPath, int baseClockHz, IPSMonitor ipsMonitor, LcdConnec this.flags = new Flags(false, false, false, false); this.pc = new ProgrammCounter((short) 0, flags); this.accu = new Accumulator((byte) 0, flags); - this.sp = new Register16bit((short) 0xFFFE, flags); + this.sp = new Register16bit((short) 0x0000, flags); this.b = new Register8Bit((byte) 0, flags); this.c = new Register8Bit((byte) 0, flags); this.d = new Register8Bit((byte) 0, flags); @@ -95,6 +118,31 @@ public Gameboy(String RomPath, int baseClockHz, IPSMonitor ipsMonitor, LcdConnec this.h = new Register8Bit((byte) 0, flags); this.l = new Register8Bit((byte) 0, flags); + SerialControllRegister serialControllRegister = new SerialControllRegister(); + SerialTransferDataRegister serialTransferDataRegister = new SerialTransferDataRegister(); + + SoundOnOrOffRegister soundOnOrOffRegister = new SoundOnOrOffRegister(); + SoundMode1Envelope soundMode1Envelope = new SoundMode1Envelope(); + SoundMode1FrequencyHigh soundMode1FrequencyHigh = new SoundMode1FrequencyHigh(soundOnOrOffRegister); + SoundMode1FrequencyLow soundMode1FrequencyLow = new SoundMode1FrequencyLow(); + SoundMode1SweepRegister soundMode1SweepRegister = new SoundMode1SweepRegister(); + SoundMode1WavePatternDutyAndSoundLength soundMode1WavePatternDutyAndSoundLength = new SoundMode1WavePatternDutyAndSoundLength(); + SoundMode2Envelope soundMode2Envelope = new SoundMode2Envelope(); + SoundMode2FrequencyHigh soundMode2FrequencyHigh = new SoundMode2FrequencyHigh(soundOnOrOffRegister); + SoundMode2FrequencyLow soundMode2FrequencyLow = new SoundMode2FrequencyLow(); + SoundMode2WavePatternDutyAndSoundLength soundMode2WavePatternDutyAndSoundLength = new SoundMode2WavePatternDutyAndSoundLength(); + SoundMode3FrequencyHigh soundMode3FrequencyHigh = new SoundMode3FrequencyHigh(soundOnOrOffRegister); + SoundMode3FrequencyLow soundMode3FrequencyLow = new SoundMode3FrequencyLow(); + SoundMode3SelectOutputLevel soundMode3SelectOutputLevel = new SoundMode3SelectOutputLevel(); + SoundMode3SoundLength soundMode3SoundLength = new SoundMode3SoundLength(); + SoundMode3SoundOnOrOff soundMode3SoundOnOrOff = new SoundMode3SoundOnOrOff(); + SoundMode4CounterOrConsecutiveSelection soundMode4CounterOrConsecutiveSelection = new SoundMode4CounterOrConsecutiveSelection(soundOnOrOffRegister); + SoundMode4Envelope soundMode4Envelope = new SoundMode4Envelope(); + SoundMode4PolynomialCounter soundMode4PolynomialCounter = new SoundMode4PolynomialCounter(); + SoundMode4SoundLength soundMode4SoundLength = new SoundMode4SoundLength(); + SelectionOfSoundOutputRegister selectionOfSoundOutputRegister = new SelectionOfSoundOutputRegister(); + ChannelControlRegister channelControlRegister = new ChannelControlRegister(); + LCDControllRegister lcdControll = new LCDControllRegister(); BootRomUnmapRegister bootRomTurnOff = new BootRomUnmapRegister(); ScrollXRegister scrollX = new ScrollXRegister(); @@ -133,7 +181,14 @@ public Gameboy(String RomPath, int baseClockHz, IPSMonitor ipsMonitor, LcdConnec unusableMemory, joypadInformation, divider, timerCounter, timerModulo, timerControl, interruptFlagRegister, wavePattern, lcdControll, lcdControlStatusRegister, scrollY, scrollX, lcdYCoordinate, lcdControllYCompare, dmaRegister, backgroundAndWindowColorPalette, obj0, obj1, - unusableMemory1, bootRomTurnOff, highRam, interruptEnableRegister); + unusableMemory1, bootRomTurnOff, highRam, interruptEnableRegister, soundMode1Envelope, + soundMode1FrequencyHigh, soundMode1FrequencyLow, soundMode1SweepRegister, + soundMode1WavePatternDutyAndSoundLength, soundMode2Envelope, soundMode2FrequencyHigh, + soundMode2FrequencyLow, soundMode2WavePatternDutyAndSoundLength, soundMode3FrequencyHigh, + soundMode3FrequencyLow, soundMode3SelectOutputLevel, soundMode3SoundLength, soundMode3SoundOnOrOff, + soundMode4CounterOrConsecutiveSelection, soundMode4Envelope, soundMode4PolynomialCounter, + soundMode4SoundLength, selectionOfSoundOutputRegister, channelControlRegister, soundOnOrOffRegister, + serialTransferDataRegister, serialControllRegister); this.cpu = new CPU(ram, accu, pc, sp, b, c, d, e, h, l, flags, interruptEnableRegister, interruptFlagRegister); diff --git a/src/ppu/LCDControlStatusRegister.java b/src/ppu/LCDControlStatusRegister.java index 59d31bc..911fdc8 100644 --- a/src/ppu/LCDControlStatusRegister.java +++ b/src/ppu/LCDControlStatusRegister.java @@ -7,7 +7,7 @@ public class LCDControlStatusRegister extends RamRegister private static final int STAT_ADRESS = 0xFF41; - private static final int LYC_UNUSED_BIT__POSITION = 7; + private static final int UNUSED_BIT_7_POSITION = 7; private static final int LYC_LY_COINCIDENCE_INTERRUPT_ENABLED_POSITION = 6; private static final int OAM_INTERRUPT_ENABLED_POSITION = 5; private static final int V_BLANK_INTERRUPT_ENABLED_POSITION = 4; @@ -28,7 +28,7 @@ public LCDControlStatusRegister(LCDControllRegister lcdControll) super(STAT_ADRESS); this.lcdControll = lcdControll; - setBit(LYC_UNUSED_BIT__POSITION, true); + setBit(UNUSED_BIT_7_POSITION, true); } public boolean isLYCEqualsLYInterruptEnabled() @@ -137,14 +137,14 @@ public void setModePixelTransfer() public void put(int adress, byte input) { super.put(adress, (byte) ((Byte.toUnsignedInt(input) | 0b0000_0111) & (getValue() | 0b1111_1000)) ); - setBit(LYC_UNUSED_BIT__POSITION, true); + setBit(UNUSED_BIT_7_POSITION, true); } @Override protected void putValue(byte value) { super.putValue(value); - setBit(LYC_UNUSED_BIT__POSITION, true); + setBit(UNUSED_BIT_7_POSITION, true); } @Override diff --git a/src/ram/Ram.java b/src/ram/Ram.java index c330631..9ced7da 100644 --- a/src/ram/Ram.java +++ b/src/ram/Ram.java @@ -22,6 +22,29 @@ import ppu.ObjectsAttributeMap; import ppu.ScrollXRegister; import ppu.ScrollYRegister; +import serial.SerialControllRegister; +import serial.SerialTransferDataRegister; +import sound.ChannelControlRegister; +import sound.SelectionOfSoundOutputRegister; +import sound.SoundMode1Envelope; +import sound.SoundMode1FrequencyHigh; +import sound.SoundMode1FrequencyLow; +import sound.SoundMode1SweepRegister; +import sound.SoundMode1WavePatternDutyAndSoundLength; +import sound.SoundMode2Envelope; +import sound.SoundMode2FrequencyHigh; +import sound.SoundMode2FrequencyLow; +import sound.SoundMode2WavePatternDutyAndSoundLength; +import sound.SoundMode3FrequencyHigh; +import sound.SoundMode3FrequencyLow; +import sound.SoundMode3SelectOutputLevel; +import sound.SoundMode3SoundLength; +import sound.SoundMode3SoundOnOrOff; +import sound.SoundMode4CounterOrConsecutiveSelection; +import sound.SoundMode4Envelope; +import sound.SoundMode4PolynomialCounter; +import sound.SoundMode4SoundLength; +import sound.SoundOnOrOffRegister; import timer.DividerRegister; import timer.TimerControlRegister; import timer.TimerCounterRegister; @@ -41,7 +64,21 @@ public Ram(BootRom bootUpRom, Cartridge cartridge, VideoRam videoRam, InternalRa DirectMemoryAcessRegister directMemoryAcess, BackgroundAndWindowColorPalette backgroundAndWindowColorPalette, ObjectColorPalette0 objectColorPalette0, ObjectColorPalette1 objectColorPalette1, UnusableMemory1 unusableMemory1, - BootRomUnmapRegister bootRomTurnOff, HighRam highRam, InterruptEnableRegister interruptEnable) + BootRomUnmapRegister bootRomTurnOff, HighRam highRam, InterruptEnableRegister interruptEnable, + SoundMode1Envelope soundMode1Envelope, SoundMode1FrequencyHigh soundMode1FrequencyHigh, + SoundMode1FrequencyLow soundMode1FrequencyLow, SoundMode1SweepRegister soundMode1SweepRegister, + SoundMode1WavePatternDutyAndSoundLength soundMode1WavePatternDutyAndSoundLength, + SoundMode2Envelope soundMode2Envelope, SoundMode2FrequencyHigh soundMode2FrequencyHigh, + SoundMode2FrequencyLow soundMode2FrequencyLow, + SoundMode2WavePatternDutyAndSoundLength soundMode2WavePatternDutyAndSoundLength, + SoundMode3FrequencyHigh soundMode3FrequencyHigh, SoundMode3FrequencyLow soundMode3FrequencyLow, + SoundMode3SelectOutputLevel soundMode3SelectOutputLevel, SoundMode3SoundLength soundMode3SoundLength, + SoundMode3SoundOnOrOff soundMode3SoundOnOrOff, + SoundMode4CounterOrConsecutiveSelection soundMode4CounterOrConsecutiveSelection, + SoundMode4Envelope soundMode4Envelope, SoundMode4PolynomialCounter soundMode4PolynomialCounter, + SoundMode4SoundLength soundMode4SoundLength, SelectionOfSoundOutputRegister selectionOfSoundOutputRegister, + ChannelControlRegister channelControlRegister, SoundOnOrOffRegister soundOnOrOffRegister, + SerialTransferDataRegister serialTransferDataRegister, SerialControllRegister serialControllRegister) { memoryMap = new HashMap<>(); @@ -86,8 +123,8 @@ public Ram(BootRom bootUpRom, Cartridge cartridge, VideoRam videoRam, InternalRa } memoryMap.put(joypadInformationRegister.adress, joypadInformationRegister); - memoryMap.put(0xFF01, new RamRegisterPlaceHolder(0xFF01)); - memoryMap.put(0xFF02, new RamRegisterPlaceHolder(0xFF02)); + memoryMap.put(serialTransferDataRegister.adress, serialTransferDataRegister); + memoryMap.put(serialControllRegister.adress, serialControllRegister); memoryMap.put(0xFF03, new UnusableRamRegister(0xFF03)); memoryMap.put(dividerRegister.adress, dividerRegister); memoryMap.put(timerCounter.adress, timerCounter); @@ -103,29 +140,29 @@ public Ram(BootRom bootUpRom, Cartridge cartridge, VideoRam videoRam, InternalRa memoryMap.put(0xFF0E, new UnusableRamRegister(0xFF0e)); memoryMap.put(interruptFlag.adress, interruptFlag); - memoryMap.put(0xFF10, new RamRegisterPlaceHolder(0xFF10)); - memoryMap.put(0xFF11, new RamRegisterPlaceHolder(0xFF11)); - memoryMap.put(0xFF12, new RamRegisterPlaceHolder(0xFF12)); - memoryMap.put(0xFF13, new RamRegisterPlaceHolder(0xFF13)); - memoryMap.put(0xFF14, new RamRegisterPlaceHolder(0xFF14)); + memoryMap.put(soundMode1SweepRegister.adress, soundMode1SweepRegister); + memoryMap.put(soundMode1WavePatternDutyAndSoundLength.adress, soundMode1WavePatternDutyAndSoundLength); + memoryMap.put(soundMode1Envelope.adress, soundMode1Envelope); + memoryMap.put(soundMode1FrequencyLow.adress, soundMode1FrequencyLow); + memoryMap.put(soundMode1FrequencyHigh.adress, soundMode1FrequencyHigh); memoryMap.put(0xFF15, new UnusableRamRegister(0xFF15)); - memoryMap.put(0xFF16, new RamRegisterPlaceHolder(0xFF16)); - memoryMap.put(0xFF17, new RamRegisterPlaceHolder(0xFF17)); - memoryMap.put(0xFF18, new RamRegisterPlaceHolder(0xFF18)); - memoryMap.put(0xFF19, new RamRegisterPlaceHolder(0xFF19)); - memoryMap.put(0xFF1A, new RamRegisterPlaceHolder(0xFF1A)); - memoryMap.put(0xFF1B, new RamRegisterPlaceHolder(0xFF1B)); - memoryMap.put(0xFF1C, new RamRegisterPlaceHolder(0xFF1C)); - memoryMap.put(0xFF1D, new RamRegisterPlaceHolder(0xFF1D)); - memoryMap.put(0xFF1E, new RamRegisterPlaceHolder(0xFF1E)); + memoryMap.put(soundMode2WavePatternDutyAndSoundLength.adress, soundMode2WavePatternDutyAndSoundLength); + memoryMap.put(soundMode2Envelope.adress, soundMode2Envelope); + memoryMap.put(soundMode2FrequencyLow.adress, soundMode2FrequencyLow); + memoryMap.put(soundMode2FrequencyHigh.adress, soundMode2FrequencyHigh); + memoryMap.put(soundMode3SoundOnOrOff.adress, soundMode3SoundOnOrOff); + memoryMap.put(soundMode3SoundLength.adress, soundMode3SoundLength); + memoryMap.put(soundMode3SelectOutputLevel.adress, soundMode3SelectOutputLevel); + memoryMap.put(soundMode3FrequencyLow.adress, soundMode3FrequencyLow); + memoryMap.put(soundMode3FrequencyHigh.adress, soundMode3FrequencyHigh); memoryMap.put(0xFF1F, new UnusableRamRegister(0xFF1F)); - memoryMap.put(0xFF20, new RamRegisterPlaceHolder(0xFF20)); - memoryMap.put(0xFF21, new RamRegisterPlaceHolder(0xFF21)); - memoryMap.put(0xFF22, new RamRegisterPlaceHolder(0xFF22)); - memoryMap.put(0xFF23, new RamRegisterPlaceHolder(0xFF23)); - memoryMap.put(0xFF24, new RamRegisterPlaceHolder(0xFF24)); - memoryMap.put(0xFF25, new RamRegisterPlaceHolder(0xFF25)); - memoryMap.put(0xFF26, new RamRegisterPlaceHolder(0xFF26)); + memoryMap.put(soundMode4SoundLength.adress, soundMode4SoundLength); + memoryMap.put(soundMode4Envelope.adress, soundMode4Envelope); + memoryMap.put(soundMode4PolynomialCounter.adress, soundMode4PolynomialCounter); + memoryMap.put(soundMode4CounterOrConsecutiveSelection.adress, soundMode4CounterOrConsecutiveSelection); + memoryMap.put(channelControlRegister.adress, channelControlRegister); + memoryMap.put(selectionOfSoundOutputRegister.adress, selectionOfSoundOutputRegister); + memoryMap.put(soundOnOrOffRegister.adress, soundOnOrOffRegister); memoryMap.put(0xFF27, new UnusableRamRegister(0xFF27)); memoryMap.put(0xFF28, new UnusableRamRegister(0xFF28)); memoryMap.put(0xFF29, new UnusableRamRegister(0xFF29)); diff --git a/src/serial/SerialControllRegister.java b/src/serial/SerialControllRegister.java new file mode 100644 index 0000000..06f9f0d --- /dev/null +++ b/src/serial/SerialControllRegister.java @@ -0,0 +1,41 @@ +package serial; + +import ram.RamRegister; + +public class SerialControllRegister extends RamRegister +{ + private static final int SC_ADRESS = 0xFF02; + + private static final int TRANSFER_START_FLAG = 7; + private static final int UNUSED_BIT_6 = 6; + private static final int UNUSED_BIT_5 = 5; + private static final int UNUSED_BIT_4 = 4; + private static final int UNUSED_BIT_3 = 3; + private static final int UNUSED_BIT_2 = 2; + private static final int UNUSED_BIT_1 = 1; + private static final int SHIFT_CLOCK = 0; + + public SerialControllRegister() + { + super(SC_ADRESS); + setBit(UNUSED_BIT_6, true); + setBit(UNUSED_BIT_5, true); + setBit(UNUSED_BIT_4, true); + setBit(UNUSED_BIT_3, true); + setBit(UNUSED_BIT_2, true); + setBit(UNUSED_BIT_1, true); + } + + @Override + public void put(int adress, byte input) + { + super.put(adress, input); + setBit(UNUSED_BIT_6, true); + setBit(UNUSED_BIT_5, true); + setBit(UNUSED_BIT_4, true); + setBit(UNUSED_BIT_3, true); + setBit(UNUSED_BIT_2, true); + setBit(UNUSED_BIT_1, true); + } + +} diff --git a/src/serial/SerialTransferDataRegister.java b/src/serial/SerialTransferDataRegister.java new file mode 100644 index 0000000..ddbf671 --- /dev/null +++ b/src/serial/SerialTransferDataRegister.java @@ -0,0 +1,14 @@ +package serial; + +import ram.RamRegister; + +public class SerialTransferDataRegister extends RamRegister +{ + private static final int SB_ADRESS = 0xFF01; + + public SerialTransferDataRegister() + { + super(SB_ADRESS); + } + +} diff --git a/src/sound/ChannelControlRegister.java b/src/sound/ChannelControlRegister.java new file mode 100644 index 0000000..0ffa802 --- /dev/null +++ b/src/sound/ChannelControlRegister.java @@ -0,0 +1,23 @@ +package sound; + +import ram.RamRegister; + +public class ChannelControlRegister extends RamRegister +{ + private static final int NR50_ADRESS = 0xFF24; + + private static final int CARDRIDGE_SOUND_SIGNAL_TO_SPEAKER_2 = 7; + private static final int SPEAKER_2_OUTPUT_LEVEL_BIT_2 = 6; + private static final int SPEAKER_2_OUTPUT_LEVEL_BIT_1 = 5; + private static final int SPEAKER_2_OUTPUT_LEVEL_BIT_0 = 4; + private static final int CARDRIDGE_SOUND_SIGNAL_TO_SPEAKER_1 = 3; + private static final int SPEAKER_1_OUTPUT_LEVEL_BIT_2 = 2; + private static final int SPEAKER_1_OUTPUT_LEVEL_BIT_1 = 1; + private static final int SPEAKER_1_OUTPUT_LEVEL_BIT_0 = 0; + + public ChannelControlRegister() + { + super(NR50_ADRESS); + } + +} diff --git a/src/sound/SelectionOfSoundOutputRegister.java b/src/sound/SelectionOfSoundOutputRegister.java new file mode 100644 index 0000000..4d2d21d --- /dev/null +++ b/src/sound/SelectionOfSoundOutputRegister.java @@ -0,0 +1,23 @@ +package sound; + +import ram.RamRegister; + +public class SelectionOfSoundOutputRegister extends RamRegister +{ + private static final int NR51_ADRESS = 0xFF25; + + private static final int OUTPUT_SOUND_4_TO_SPEAKER_2 = 7; + private static final int OUTPUT_SOUND_3_TO_SPEAKER_2 = 6; + private static final int OUTPUT_SOUND_2_TO_SPEAKER_2 = 5; + private static final int OUTPUT_SOUND_1_TO_SPEAKER_2 = 4; + private static final int OUTPUT_SOUND_4_TO_SPEAKER_1 = 3; + private static final int OUTPUT_SOUND_3_TO_SPEAKER_1 = 2; + private static final int OUTPUT_SOUND_2_TO_SPEAKER_1 = 1; + private static final int OUTPUT_SOUND_1_TO_SPEAKER_1 = 0; + + public SelectionOfSoundOutputRegister() + { + super(NR51_ADRESS); + } + +} diff --git a/src/sound/SoundMode1Envelope.java b/src/sound/SoundMode1Envelope.java new file mode 100644 index 0000000..bb247e8 --- /dev/null +++ b/src/sound/SoundMode1Envelope.java @@ -0,0 +1,23 @@ +package sound; + +import ram.RamRegister; + +public class SoundMode1Envelope extends RamRegister +{ + private static final int NR12_ADRESS = 0xFF12; + + private static final int INITIAL_VOLUME_BIT_3 = 7; + private static final int INITIAL_VOLUME_BIT_2 = 6; + private static final int INITIAL_VOLUME_BIT_1 = 5; + private static final int INITIAL_VOLUME_BIT_0 = 4; + private static final int ENVELOPE_UP_OR_DOWN = 3; + private static final int NUMBER_OF_ENVELOPE_SWEEP_BIT_2 = 2; + private static final int NUMBER_OF_ENVELOPE_SWEEP_BIT_1 = 1; + private static final int NUMBER_OF_ENVELOPE_SWEEP_BIT_0 = 0; + + public SoundMode1Envelope() + { + super(NR12_ADRESS); + } + +} diff --git a/src/sound/SoundMode1FrequencyHigh.java b/src/sound/SoundMode1FrequencyHigh.java new file mode 100644 index 0000000..692f735 --- /dev/null +++ b/src/sound/SoundMode1FrequencyHigh.java @@ -0,0 +1,52 @@ +package sound; + +import ram.RamRegister; + +public class SoundMode1FrequencyHigh extends RamRegister +{ + private static final int LOAD_MASK = 0b1011_1111; + + private static final int NR14_ADRESS = 0xFF14; + + private static final int INITIAL = 7; + private static final int COUNTER_OR_CONSECUTIVE_SELECTION = 6; + private static final int UNUSED_BIT_5 = 5; + private static final int UNUSED_BIT_4 = 4; + private static final int UNUSED_BIT_3 = 3; + private static final int FREQUENCY_HIGH_BIT_2 = 2; + private static final int FREQUENCY_HIGH_BIT_1 = 1; + private static final int FREQUENCY_HIGH_BIT_0 = 0; + + private SoundOnOrOffRegister soundOnOrOffRegister; + + public SoundMode1FrequencyHigh(SoundOnOrOffRegister soundOnOrOffRegister) + { + super(NR14_ADRESS); + setBit(UNUSED_BIT_5, true); + setBit(UNUSED_BIT_4, true); + setBit(UNUSED_BIT_3, true); + + this.soundOnOrOffRegister = soundOnOrOffRegister; + } + + @Override + public void put(int adress, byte input) + { + super.put(adress, input); + + if (getBit(INITIAL)) + { + soundOnOrOffRegister.setSound1On(); + } + + setBit(UNUSED_BIT_5, true); + setBit(UNUSED_BIT_4, true); + setBit(UNUSED_BIT_3, true); + } + + @Override + public byte load(int adress) + { + return (byte) (super.load(adress) | LOAD_MASK); + } +} \ No newline at end of file diff --git a/src/sound/SoundMode1FrequencyLow.java b/src/sound/SoundMode1FrequencyLow.java new file mode 100644 index 0000000..7c97243 --- /dev/null +++ b/src/sound/SoundMode1FrequencyLow.java @@ -0,0 +1,20 @@ +package sound; + +import ram.RamRegister; + +public class SoundMode1FrequencyLow extends RamRegister +{ + private static final int NR13_ADRESS = 0xFF13; + + public SoundMode1FrequencyLow() + { + super(NR13_ADRESS); + } + + @Override + public byte load(int adress) + { + return (byte) 0xFF; + } + +} diff --git a/src/sound/SoundMode1SweepRegister.java b/src/sound/SoundMode1SweepRegister.java new file mode 100644 index 0000000..3a0ca43 --- /dev/null +++ b/src/sound/SoundMode1SweepRegister.java @@ -0,0 +1,32 @@ +package sound; + +import ram.RamRegister; + +public class SoundMode1SweepRegister extends RamRegister +{ + + private static final int NR10_ADRESS = 0xFF10; + + private static final int UNUSED_BIT_7 = 7; + private static final int SWEEP_TIME_BIT_2 = 6; + private static final int SWEEP_TIME_BIT_1 = 5; + private static final int SWEEP_TIME_BIT_0 = 4; + private static final int SWEEP_INCREASES_OR_DECREASES = 3; + private static final int NUMBER_OF_SEEP_SHIFT_BIT_2 = 2; + private static final int NUMBER_OF_SEEP_SHIFT_BIT_1 = 1; + private static final int NUMBER_OF_SEEP_SHIFT_BIT_0 = 0; + + public SoundMode1SweepRegister() + { + super(NR10_ADRESS); + setBit(UNUSED_BIT_7, true); + } + + @Override + public void put(int adress, byte input) + { + super.put(adress, input); + setBit(UNUSED_BIT_7, true); + } + +} diff --git a/src/sound/SoundMode1WavePatternDutyAndSoundLength.java b/src/sound/SoundMode1WavePatternDutyAndSoundLength.java new file mode 100644 index 0000000..f2c5670 --- /dev/null +++ b/src/sound/SoundMode1WavePatternDutyAndSoundLength.java @@ -0,0 +1,31 @@ +package sound; + +import ram.RamRegister; + +public class SoundMode1WavePatternDutyAndSoundLength extends RamRegister +{ + private static final int LOAD_MASK = 0b0011_1111; + + private static final int NR11_ADRESS = 0xFF11; + + private static final int WAVE_PATTERN_DUTY_BIT_1 = 7; + private static final int WAVE_PATTERN_DUTY_BIT_0 = 6; + private static final int SOUND_LENGTH_BIT_5 = 5; + private static final int SOUND_LENGTH_BIT_4 = 4; + private static final int SOUND_LENGTH_BIT_3 = 3; + private static final int SOUND_LENGTH_BIT_2 = 2; + private static final int SOUND_LENGTH_BIT_1 = 1; + private static final int SOUND_LENGTH_BIT_0 = 0; + + public SoundMode1WavePatternDutyAndSoundLength() + { + super(NR11_ADRESS); + } + + @Override + public byte load(int adress) + { + return (byte) (super.load(adress) | LOAD_MASK); + } + +} diff --git a/src/sound/SoundMode2Envelope.java b/src/sound/SoundMode2Envelope.java new file mode 100644 index 0000000..de75b74 --- /dev/null +++ b/src/sound/SoundMode2Envelope.java @@ -0,0 +1,23 @@ +package sound; + +import ram.RamRegister; + +public class SoundMode2Envelope extends RamRegister +{ + private static final int NR22_ADRESS = 0xFF17; + + private static final int INITIAL_VOLUME_BIT_3 = 7; + private static final int INITIAL_VOLUME_BIT_2 = 6; + private static final int INITIAL_VOLUME_BIT_1 = 5; + private static final int INITIAL_VOLUME_BIT_0 = 4; + private static final int ENVELOPE_UP_OR_DOWN = 3; + private static final int NUMBER_OF_ENVELOPE_SWEEP_BIT_2 = 2; + private static final int NUMBER_OF_ENVELOPE_SWEEP_BIT_1 = 1; + private static final int NUMBER_OF_ENVELOPE_SWEEP_BIT_0 = 0; + + public SoundMode2Envelope() + { + super(NR22_ADRESS); + } + +} diff --git a/src/sound/SoundMode2FrequencyHigh.java b/src/sound/SoundMode2FrequencyHigh.java new file mode 100644 index 0000000..48a4c15 --- /dev/null +++ b/src/sound/SoundMode2FrequencyHigh.java @@ -0,0 +1,42 @@ +package sound; + +import ram.RamRegister; + +public class SoundMode2FrequencyHigh extends RamRegister +{ + private static final int LOAD_MASK = 0b1011_1111; + + private static final int NR24_ADRESS = 0xFF19; + + private static final int INITIAL = 7; + private static final int COUNTER_OR_CONSECUTIVE_SELECTION = 6; + private static final int UNUSED_BIT_5 = 5; + private static final int UNUSED_BIT_4 = 4; + private static final int UNUSED_BIT_3 = 3; + private static final int FREQUENCY_HIGH_BIT_2 = 2; + private static final int FREQUENCY_HIGH_BIT_1 = 1; + private static final int FREQUENCY_HIGH_BIT_0 = 0; + + public SoundMode2FrequencyHigh(SoundOnOrOffRegister soundOnOrOffRegister) + { + super(NR24_ADRESS); + setBit(UNUSED_BIT_5, true); + setBit(UNUSED_BIT_4, true); + setBit(UNUSED_BIT_3, true); + } + + @Override + public byte load(int adress) + { + return (byte) (super.load(adress) | LOAD_MASK); + } + + @Override + public void put(int adress, byte input) + { + super.put(adress, input); + setBit(UNUSED_BIT_5, true); + setBit(UNUSED_BIT_4, true); + setBit(UNUSED_BIT_3, true); + } +} \ No newline at end of file diff --git a/src/sound/SoundMode2FrequencyLow.java b/src/sound/SoundMode2FrequencyLow.java new file mode 100644 index 0000000..c0d1af6 --- /dev/null +++ b/src/sound/SoundMode2FrequencyLow.java @@ -0,0 +1,20 @@ +package sound; + +import ram.RamRegister; + +public class SoundMode2FrequencyLow extends RamRegister +{ + private static final int NR23_ADRESS = 0xFF18; + + public SoundMode2FrequencyLow() + { + super(NR23_ADRESS); + } + + @Override + public byte load(int adress) + { + return (byte) 0xFF; + } + +} diff --git a/src/sound/SoundMode2WavePatternDutyAndSoundLength.java b/src/sound/SoundMode2WavePatternDutyAndSoundLength.java new file mode 100644 index 0000000..c6fc6d8 --- /dev/null +++ b/src/sound/SoundMode2WavePatternDutyAndSoundLength.java @@ -0,0 +1,31 @@ +package sound; + +import ram.RamRegister; + +public class SoundMode2WavePatternDutyAndSoundLength extends RamRegister +{ + private static final int LOAD_MASK = 0b0011_1111; + + private static final int NR21_ADRESS = 0xFF16; + + private static final int WAVE_PATTERN_DUTY_BIT_1 = 7; + private static final int WAVE_PATTERN_DUTY_BIT_0 = 6; + private static final int SOUND_LENGTH_BIT_5 = 5; + private static final int SOUND_LENGTH_BIT_4 = 4; + private static final int SOUND_LENGTH_BIT_3 = 3; + private static final int SOUND_LENGTH_BIT_2 = 2; + private static final int SOUND_LENGTH_BIT_1 = 1; + private static final int SOUND_LENGTH_BIT_0 = 0; + + public SoundMode2WavePatternDutyAndSoundLength() + { + super(NR21_ADRESS); + } + + @Override + public byte load(int adress) + { + return (byte) (super.load(adress) | LOAD_MASK); + } + +} diff --git a/src/sound/SoundMode3FrequencyHigh.java b/src/sound/SoundMode3FrequencyHigh.java new file mode 100644 index 0000000..a426617 --- /dev/null +++ b/src/sound/SoundMode3FrequencyHigh.java @@ -0,0 +1,42 @@ +package sound; + +import ram.RamRegister; + +public class SoundMode3FrequencyHigh extends RamRegister +{ + private static final int LOAD_MASK = 0b1011_1111; + + private static final int NR34_ADRESS = 0xFF1E; + + private static final int INITIAL = 7; + private static final int COUNTER_OR_CONSECUTIVE_SELECTION = 6; + private static final int UNUSED_BIT_5 = 5; + private static final int UNUSED_BIT_4 = 4; + private static final int UNUSED_BIT_3 = 3; + private static final int FREQUENCY_HIGH_BIT_2 = 2; + private static final int FREQUENCY_HIGH_BIT_1 = 1; + private static final int FREQUENCY_HIGH_BIT_0 = 0; + + public SoundMode3FrequencyHigh(SoundOnOrOffRegister soundOnOrOffRegister) + { + super(NR34_ADRESS); + setBit(UNUSED_BIT_5, true); + setBit(UNUSED_BIT_4, true); + setBit(UNUSED_BIT_3, true); + } + + @Override + public byte load(int adress) + { + return (byte) (super.load(adress) | LOAD_MASK); + } + + @Override + public void put(int adress, byte input) + { + super.put(adress, input); + setBit(UNUSED_BIT_5, true); + setBit(UNUSED_BIT_4, true); + setBit(UNUSED_BIT_3, true); + } +} \ No newline at end of file diff --git a/src/sound/SoundMode3FrequencyLow.java b/src/sound/SoundMode3FrequencyLow.java new file mode 100644 index 0000000..432525c --- /dev/null +++ b/src/sound/SoundMode3FrequencyLow.java @@ -0,0 +1,19 @@ +package sound; + +import ram.RamRegister; + +public class SoundMode3FrequencyLow extends RamRegister +{ + private static final int NR33_ADRESS = 0xFF1D; + + public SoundMode3FrequencyLow() + { + super(NR33_ADRESS); + } + + @Override + public byte load(int adress) + { + return (byte) 0xFF; + } +} diff --git a/src/sound/SoundMode3SelectOutputLevel.java b/src/sound/SoundMode3SelectOutputLevel.java new file mode 100644 index 0000000..0e44319 --- /dev/null +++ b/src/sound/SoundMode3SelectOutputLevel.java @@ -0,0 +1,41 @@ +package sound; + +import ram.RamRegister; + +public class SoundMode3SelectOutputLevel extends RamRegister +{ + + private static final int NR32_ADRESS = 0xFF1C; + + private static final int UNUSED_BIT_7 = 7; + private static final int SELECT_OUTPUT_LEVEL_BIT_1 = 6; + private static final int SELECT_OUTPUT_LEVEL_BIT_0 = 5; + private static final int UNUSED_BIT_4 = 4; + private static final int UNUSED_BIT_3 = 3; + private static final int UNUSED_BIT_2 = 2; + private static final int UNUSED_BIT_1 = 1; + private static final int UNUSED_BIT_0 = 0; + + public SoundMode3SelectOutputLevel() + { + super(NR32_ADRESS); + setBit(UNUSED_BIT_7, true); + setBit(UNUSED_BIT_4, true); + setBit(UNUSED_BIT_3, true); + setBit(UNUSED_BIT_2, true); + setBit(UNUSED_BIT_1, true); + setBit(UNUSED_BIT_0, true); + } + + @Override + public void put(int adress, byte input) + { + super.put(adress, input); + setBit(UNUSED_BIT_7, true); + setBit(UNUSED_BIT_4, true); + setBit(UNUSED_BIT_3, true); + setBit(UNUSED_BIT_2, true); + setBit(UNUSED_BIT_1, true); + setBit(UNUSED_BIT_0, true); + } +} diff --git a/src/sound/SoundMode3SoundLength.java b/src/sound/SoundMode3SoundLength.java new file mode 100644 index 0000000..d191d44 --- /dev/null +++ b/src/sound/SoundMode3SoundLength.java @@ -0,0 +1,20 @@ +package sound; + +import ram.RamRegister; + +public class SoundMode3SoundLength extends RamRegister +{ + private static final int NR31_ADRESS = 0xFF1B; + + public SoundMode3SoundLength() + { + super(NR31_ADRESS); + } + + @Override + public byte load(int adress) + { + return (byte) 0xFF; + } + +} diff --git a/src/sound/SoundMode3SoundOnOrOff.java b/src/sound/SoundMode3SoundOnOrOff.java new file mode 100644 index 0000000..9156fa4 --- /dev/null +++ b/src/sound/SoundMode3SoundOnOrOff.java @@ -0,0 +1,43 @@ +package sound; + +import ram.RamRegister; + +public class SoundMode3SoundOnOrOff extends RamRegister +{ + + private static final int NR30_ADRESS = 0xFF1A; + + private static final int SOUND_OFF_OR_ON = 7; + private static final int UNUSED_BIT_6 = 6; + private static final int UNUSED_BIT_5 = 5; + private static final int UNUSED_BIT_4 = 4; + private static final int UNUSED_BIT_3 = 3; + private static final int UNUSED_BIT_2 = 2; + private static final int UNUSED_BIT_1 = 1; + private static final int UNUSED_BIT_0 = 0; + + public SoundMode3SoundOnOrOff() + { + super(NR30_ADRESS); + setBit(UNUSED_BIT_6, true); + setBit(UNUSED_BIT_5, true); + setBit(UNUSED_BIT_4, true); + setBit(UNUSED_BIT_3, true); + setBit(UNUSED_BIT_2, true); + setBit(UNUSED_BIT_1, true); + setBit(UNUSED_BIT_0, true); + } + + @Override + public void put(int adress, byte input) + { + super.put(adress, input); + setBit(UNUSED_BIT_6, true); + setBit(UNUSED_BIT_5, true); + setBit(UNUSED_BIT_4, true); + setBit(UNUSED_BIT_3, true); + setBit(UNUSED_BIT_2, true); + setBit(UNUSED_BIT_1, true); + setBit(UNUSED_BIT_0, true); + } +} diff --git a/src/sound/SoundMode4CounterOrConsecutiveSelection.java b/src/sound/SoundMode4CounterOrConsecutiveSelection.java new file mode 100644 index 0000000..ab11c13 --- /dev/null +++ b/src/sound/SoundMode4CounterOrConsecutiveSelection.java @@ -0,0 +1,48 @@ +package sound; + +import ram.RamRegister; + +public class SoundMode4CounterOrConsecutiveSelection extends RamRegister +{ + private static final int LOAD_MASK = 0b1011_1111; + + private static final int NR44_ADRESS = 0xFF23; + + private static final int INITIAL = 7; + private static final int COUNTER_OR_CONSECUTIVE_SELECTION = 6; + private static final int UNUSED_BIT_5 = 5; + private static final int UNUSED_BIT_4 = 4; + private static final int UNUSED_BIT_3 = 3; + private static final int UNUSED_BIT_2 = 2; + private static final int UNUSED_BIT_1 = 1; + private static final int UNUSED_BIT_0 = 0; + + public SoundMode4CounterOrConsecutiveSelection(SoundOnOrOffRegister soundOnOrOffRegister) + { + super(NR44_ADRESS); + setBit(UNUSED_BIT_5, true); + setBit(UNUSED_BIT_4, true); + setBit(UNUSED_BIT_3, true); + setBit(UNUSED_BIT_2, true); + setBit(UNUSED_BIT_1, true); + setBit(UNUSED_BIT_0, true); + } + + @Override + public byte load(int adress) + { + return (byte) (super.load(adress) | LOAD_MASK); + } + + @Override + public void put(int adress, byte input) + { + super.put(adress, input); + setBit(UNUSED_BIT_5, true); + setBit(UNUSED_BIT_4, true); + setBit(UNUSED_BIT_3, true); + setBit(UNUSED_BIT_2, true); + setBit(UNUSED_BIT_1, true); + setBit(UNUSED_BIT_0, true); + } +} diff --git a/src/sound/SoundMode4Envelope.java b/src/sound/SoundMode4Envelope.java new file mode 100644 index 0000000..79169e0 --- /dev/null +++ b/src/sound/SoundMode4Envelope.java @@ -0,0 +1,23 @@ +package sound; + +import ram.RamRegister; + +public class SoundMode4Envelope extends RamRegister +{ + private static final int NR42_ADRESS = 0xFF21; + + private static final int INITIAL_VOLUME_BIT_3 = 7; + private static final int INITIAL_VOLUME_BIT_2 = 6; + private static final int INITIAL_VOLUME_BIT_1 = 5; + private static final int INITIAL_VOLUME_BIT_0 = 4; + private static final int ENVELOPE_UP_OR_DOWN = 3; + private static final int NUMBER_OF_ENVELOPE_SWEEP_BIT_2 = 2; + private static final int NUMBER_OF_ENVELOPE_SWEEP_BIT_1 = 1; + private static final int NUMBER_OF_ENVELOPE_SWEEP_BIT_0 = 0; + + public SoundMode4Envelope() + { + super(NR42_ADRESS); + } + +} diff --git a/src/sound/SoundMode4PolynomialCounter.java b/src/sound/SoundMode4PolynomialCounter.java new file mode 100644 index 0000000..d91d78c --- /dev/null +++ b/src/sound/SoundMode4PolynomialCounter.java @@ -0,0 +1,23 @@ +package sound; + +import ram.RamRegister; + +public class SoundMode4PolynomialCounter extends RamRegister +{ + private static final int NR43_ADRESS = 0xFF22; + + private static final int SELECTION_OF_SHIFT_CLOCK_FREQUENCY_BIT_3 = 7; + private static final int SELECTION_OF_SHIFT_CLOCK_FREQUENCY_BIT_2 = 6; + private static final int SELECTION_OF_SHIFT_CLOCK_FREQUENCY_BIT_1 = 5; + private static final int SELECTION_OF_SHIFT_CLOCK_FREQUENCY_BIT_0 = 4; + private static final int SELECTION_OFPOLYNOMIAL_COUNTER_STEP = 3; + private static final int SELECTION_OF_DIVIDING_RATIO_OF_FREQUENCIES_BIT_2 = 2; + private static final int SELECTION_OF_DIVIDING_RATIO_OF_FREQUENCIES_BIT_1 = 1; + private static final int SELECTION_OF_DIVIDING_RATIO_OF_FREQUENCIES_BIT_0 = 0; + + public SoundMode4PolynomialCounter() + { + super(NR43_ADRESS); + } + +} diff --git a/src/sound/SoundMode4SoundLength.java b/src/sound/SoundMode4SoundLength.java new file mode 100644 index 0000000..2b0c186 --- /dev/null +++ b/src/sound/SoundMode4SoundLength.java @@ -0,0 +1,38 @@ +package sound; + +import ram.RamRegister; + +public class SoundMode4SoundLength extends RamRegister +{ + private static final int NR41_ADRESS = 0xFF20; + + private static final int UNUSED_BIT_7 = 7; + private static final int UNUSED_BIT_6 = 6; + private static final int SOUND_LENGTH_BIT_5 = 5; + private static final int SOUND_LENGTH_BIT_4 = 4; + private static final int SOUND_LENGTH_BIT_3 = 3; + private static final int SOUND_LENGTH_BIT_2 = 2; + private static final int SOUND_LENGTH_BIT_1 = 1; + private static final int SOUND_LENGTH_BIT_0 = 0; + + public SoundMode4SoundLength() + { + super(NR41_ADRESS); + setBit(UNUSED_BIT_7, true); + setBit(UNUSED_BIT_6, true); + } + + @Override + public byte load(int adress) + { + return (byte) 0xFF; + } + + @Override + public void put(int adress, byte input) + { + super.put(adress, input); + setBit(UNUSED_BIT_7, true); + setBit(UNUSED_BIT_6, true); + } +} diff --git a/src/sound/SoundOnOrOffRegister.java b/src/sound/SoundOnOrOffRegister.java new file mode 100644 index 0000000..d0dc436 --- /dev/null +++ b/src/sound/SoundOnOrOffRegister.java @@ -0,0 +1,54 @@ +package sound; + +import ram.RamRegister; + +public class SoundOnOrOffRegister extends RamRegister +{ + private static final int NR52_ADRESS = 0xFF26; + + private static final int SOUND_OFF_OR_ON = 7; + private static final int UNUSED_BIT_6 = 6; + private static final int UNUSED_BIT_5 = 5; + private static final int UNUSED_BIT_4 = 4; + private static final int SOUND_4_ON = 3; + private static final int SOUND_3_ON = 2; + private static final int SOUND_2_ON = 1; + private static final int SOUND_1_ON = 0; + + public SoundOnOrOffRegister() + { + super(NR52_ADRESS); + setBit(UNUSED_BIT_6, true); + setBit(UNUSED_BIT_5, true); + setBit(UNUSED_BIT_4, true); + } + + @Override + public void put(int adress, byte input) + { + super.put(adress, input); + setBit(UNUSED_BIT_6, true); + setBit(UNUSED_BIT_5, true); + setBit(UNUSED_BIT_4, true); + } + + public void setSound4On() + { + setBit(SOUND_4_ON, true); + } + + public void setSound3On() + { + setBit(SOUND_3_ON, true); + } + + public void setSound2On() + { + setBit(SOUND_2_ON, true); + } + + public void setSound1On() + { + setBit(SOUND_1_ON, true); + } +} diff --git a/src/timer/TimerControlRegister.java b/src/timer/TimerControlRegister.java index 85abd2d..b5b0216 100644 --- a/src/timer/TimerControlRegister.java +++ b/src/timer/TimerControlRegister.java @@ -28,6 +28,11 @@ public class TimerControlRegister extends RamRegister public TimerControlRegister() { super(TAC_ADRESS); + setBit(CONSTANTLY_SETTED_3_POSITION, true); + setBit(CONSTANTLY_SETTED_4_POSITION, true); + setBit(CONSTANTLY_SETTED_5_POSITION, true); + setBit(CONSTANTLY_SETTED_6_POSITION, true); + setBit(CONSTANTLY_SETTED_7_POSITION, true); } public boolean isTimerStarted() diff --git a/tests/cpuTests/CPUTest.java b/tests/cpuTests/CPUTest.java deleted file mode 100644 index 4fa0e95..0000000 --- a/tests/cpuTests/CPUTest.java +++ /dev/null @@ -1,916 +0,0 @@ -package cpuTests; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.lang.reflect.Method; - -import org.junit.Before; -import org.junit.Test; - -import cartridge.BootRomUnmapRegister; -import cartridge.BootRom; -import cartridge.Cartridge; -import cartridge.RomBank0; -import cartridge.SwitchableRamBank; -import cartridge.SwitchableRomBank; -import cpu.Accumulator; -import cpu.CPU; -import cpu.Flags; -import cpu.InterruptEnableRegister; -import cpu.InterruptFlagRegister; -import cpu.ProgrammCounter; -import cpu.Register16bit; -import cpu.Register8Bit; -import joypad.JoypadInformationRegister; -import ppu.BackgroundAndWindowColorPalette; -import ppu.DirectMemoryAcessRegister; -import ppu.LCDControlStatusRegister; -import ppu.LCDControllRegister; -import ppu.LCDControllYCompare; -import ppu.LCDControllYCoordinateRegister; -import ppu.ObjectColorPalette0; -import ppu.ObjectColorPalette1; -import ppu.ObjectsAttributeMap; -import ppu.ScrollXRegister; -import ppu.ScrollYRegister; -import ppu.TileMap; -import ppu.TilePatternTable; -import ram.HighRam; -import ram.InternalRam; -import ram.InternalRamEcho; -import ram.Ram; -import ram.UnusableMemory0; -import ram.UnusableMemory1; -import ram.VideoRam; -import ram.WavePatternRam; -import timer.DividerRegister; -import timer.TimerControlRegister; -import timer.TimerCounterRegister; -import timer.TimerModuloRegister; - -public class CPUTest -{ - private CPU cpu; - private Ram ram; - - private Register8Bit b; - private Register8Bit c; - private Register8Bit d; - private Register8Bit e; - private Register8Bit h; - private Register8Bit l; - private Register16bit sp; - private ProgrammCounter pc; - private Accumulator accu; - private Flags flags; - - @Before - public void initialize() - { - - LCDControllRegister lcdControll = new LCDControllRegister(); - BootRomUnmapRegister bootRomTurnOff = new BootRomUnmapRegister(); - ScrollXRegister scrollX = new ScrollXRegister(); - ScrollYRegister scrollY = new ScrollYRegister(); - LCDControllYCoordinateRegister lcdYCoordinate = new LCDControllYCoordinateRegister(); - BackgroundAndWindowColorPalette backgroundAndWindowColorPalette = new BackgroundAndWindowColorPalette(); - InterruptEnableRegister interruptEnableRegister = new InterruptEnableRegister(); - InterruptFlagRegister interruptFlagRegister = new InterruptFlagRegister(); - LCDControllYCompare lcdControllYCompare = new LCDControllYCompare(); - LCDControlStatusRegister lcdControlStatusRegister = new LCDControlStatusRegister(lcdControll); - TimerControlRegister timerControl = new TimerControlRegister(); - TimerCounterRegister timerCounter = new TimerCounterRegister(); - TimerModuloRegister timerModulo = new TimerModuloRegister(); - JoypadInformationRegister joypadInformation = new JoypadInformationRegister(); - DirectMemoryAcessRegister dmaRegister = new DirectMemoryAcessRegister(); - DividerRegister divider = new DividerRegister(); - ObjectColorPalette0 obj0 = new ObjectColorPalette0(); - ObjectColorPalette1 obj1 = new ObjectColorPalette1(); - - BootRom bootUpRom = new BootRom(); - - InternalRam internalRam = new InternalRam(); - InternalRamEcho internalRamEcho = new InternalRamEcho(internalRam); - ObjectsAttributeMap objectAtributeMap = new ObjectsAttributeMap(dmaRegister, lcdControlStatusRegister); - UnusableMemory0 unusableMemory = new UnusableMemory0(); - WavePatternRam wavePattern = new WavePatternRam(); - UnusableMemory1 unusableMemory1 = new UnusableMemory1(); - HighRam highRam = new HighRam(); - TileMap tileMap = new TileMap(lcdControll, scrollX, scrollY); - TilePatternTable tilePatternTable = new TilePatternTable(); - VideoRam videoRam = new VideoRam(tileMap, tilePatternTable, lcdControlStatusRegister); - - Cartridge cartridge = Cartridge.getCartridge(""); - - this.ram = new Ram(bootUpRom, cartridge, videoRam, internalRam, internalRamEcho, objectAtributeMap, - unusableMemory, joypadInformation, divider, timerCounter, timerModulo, timerControl, - interruptFlagRegister, wavePattern, lcdControll, lcdControlStatusRegister, scrollY, scrollX, - lcdYCoordinate, lcdControllYCompare, dmaRegister, backgroundAndWindowColorPalette, obj0, obj1, - unusableMemory1, bootRomTurnOff, highRam, interruptEnableRegister); - - this.flags = new Flags(false, false, false, false); - - this.b = new Register8Bit((byte) 0, flags); - this.c = new Register8Bit((byte) 0, flags); - this.d = new Register8Bit((byte) 0, flags); - this.e = new Register8Bit((byte) 0, flags); - this.h = new Register8Bit((byte) 0, flags); - this.l = new Register8Bit((byte) 0, flags); - this.accu = new Accumulator((byte) 0, flags); - this.sp = new Register16bit((short) 0xDFFF, flags); - this.pc = new ProgrammCounter((short) 0, flags); - - cpu = new CPU(ram, accu, pc, sp, b, c, d, e, h, l, flags, interruptEnableRegister, interruptFlagRegister); - - } - - private void tick1Mhz() - { - cpu.tick(); - cpu.tick(); - cpu.tick(); - cpu.tick(); - } - - @Test - public void testPutImmediate8InRegister() - { - ram.put((byte) 0, (byte) 0, (byte) 0x06); - ram.put((byte) 0, (byte) 1, (byte) 0b10010101); - - tick1Mhz(); - tick1Mhz(); - - assertEquals(0b10010101, Byte.toUnsignedLong(b.load())); - assertEquals(2, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testPutRegisterInRegister() - { - e.put((byte) 6); - ram.put((byte) 0, (byte) 0, (byte) 0x4b); - - tick1Mhz(); - - assertEquals(Byte.toUnsignedLong(e.load()), Byte.toUnsignedLong(c.load())); - assertEquals(1, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testLoadRamAdressedByRegisterInRegister() - { - h.put((byte) 32); - l.put((byte) 111); - ram.put((byte) 0, (byte) 0, (byte) 0x46); - ram.put((byte) 32, (byte) 111, (byte) 0b01000110); - - tick1Mhz(); - tick1Mhz(); - - assertEquals(0b01000110, Byte.toUnsignedLong(b.load())); - assertEquals(1, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testPutRegisterInRamAdressedByRegister() - { - e.put((byte) 6); - h.put((byte) 32); - l.put((byte) 111); - - ram.put((byte) 0, (byte) 0, (byte) 0x73); - - tick1Mhz(); - tick1Mhz(); - - assertEquals(Byte.toUnsignedLong(e.load()), Byte.toUnsignedLong(ram.load((byte) 32, (byte) 111))); - assertEquals(1, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testLoadRamAdressedByImmediate16InRegister() - { - ram.put((byte) 0, (byte) 0, (byte) 0xfa); - ram.put((byte) 0, (byte) 1, (byte) 111); - ram.put((byte) 0, (byte) 2, (byte) 32); - - ram.put((byte) 32, (byte) 111, (byte) 0b01010110); - - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - - assertEquals(0b01010110, Byte.toUnsignedLong(accu.load())); - assertEquals(3, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testPutRegisterInRamAdressedByImmediate16() - { - - accu.put((byte) 232); - ram.put((byte) 0, (byte) 0, (byte) 0xea); - ram.put((byte) 0, (byte) 1, (byte) 15); - ram.put((byte) 0, (byte) 2, (byte) 34); - - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - - assertEquals(Byte.toUnsignedLong(accu.load()), Byte.toUnsignedLong(ram.load((byte) 34, (byte) 15))); - assertEquals(3, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testPutAccuInRamAdressedInUpperSpacePlusRegisterC() - { - - accu.put((byte) 123); - c.put((byte) 34); - ram.put((byte) 0, (byte) 0, (byte) 0xe2); - - tick1Mhz(); - tick1Mhz(); - - assertEquals(Byte.toUnsignedLong(accu.load()), Byte.toUnsignedLong(ram.load((byte) 255, (byte) 34))); - assertEquals(1, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testLoadRamAdressedInUpperSpacePlusRegisterCinAccu() - { - - c.put((byte) 122); - ram.put((byte) 0, (byte) 0, (byte) 0xf2); - ram.put((byte) 255, (byte) 122, (byte) 0b01100110); - - tick1Mhz(); - tick1Mhz(); - - assertEquals(0b01100110, Byte.toUnsignedLong(accu.load())); - assertEquals(1, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testLoadRamAdressedByHLinAccuAndDcrHL() - { - - h.put((byte) 255); - l.put((byte) 122); - - ram.put((byte) 0, (byte) 0, (byte) 0x3a); - ram.put((byte) 255, (byte) 122, (byte) 0b01100110); - - tick1Mhz(); - tick1Mhz(); - - assertEquals(0b01100110, Byte.toUnsignedLong(accu.load())); - assertEquals(121, Byte.toUnsignedLong(l.load())); - assertEquals(255, Byte.toUnsignedLong(h.load())); - assertEquals(1, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testPutAccuInRamAdressedByHLAndDcrHL() - { - - h.put((byte) 123); - l.put((byte) 0); - accu.put((byte) 10); - - ram.put((byte) 0, (byte) 0, (byte) 0x32); - ram.put((byte) 255, (byte) 122, (byte) 0b01100110); - - tick1Mhz(); - tick1Mhz(); - - assertEquals(Byte.toUnsignedLong(accu.load()), Byte.toUnsignedLong(ram.load((byte) 123, (byte) 0))); - assertEquals(255, Byte.toUnsignedLong(l.load())); - assertEquals(122, Byte.toUnsignedLong(h.load())); - assertEquals(1, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testLoadRamAdressedByHLinAccuAndIncHL() - { - - h.put((byte) 255); - l.put((byte) 255); - - ram.put((byte) 0, (byte) 0, (byte) 0x2a); - ram.put((byte) 255, (byte) 255, (byte) 0b01100110); - - tick1Mhz(); - tick1Mhz(); - - assertEquals(0b01100110, Byte.toUnsignedLong(accu.load())); - assertEquals(0, Byte.toUnsignedLong(l.load())); - assertEquals(0, Byte.toUnsignedLong(h.load())); - assertEquals(1, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testPutAccuInRamAdressedByHLAndIncHL() - { - - h.put((byte) 123); - l.put((byte) 0); - accu.put((byte) 10); - - ram.put((byte) 0, (byte) 0, (byte) 0x22); - ram.put((byte) 255, (byte) 122, (byte) 0b01100110); - - tick1Mhz(); - tick1Mhz(); - - assertEquals(Byte.toUnsignedLong(accu.load()), Byte.toUnsignedLong(ram.load((byte) 123, (byte) 0))); - assertEquals(1, Byte.toUnsignedLong(l.load())); - assertEquals(123, Byte.toUnsignedLong(h.load())); - assertEquals(1, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testPutAccuInRamAdressedInUpperSpacePlusImmediate() - { - - accu.put((byte) 123); - - ram.put((byte) 0, (byte) 0, (byte) 0xe0); - ram.put((byte) 0, (byte) 1, (byte) 122); - - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - - assertEquals(Byte.toUnsignedLong(accu.load()), Byte.toUnsignedLong(ram.load((byte) 255, (byte) 122))); - assertEquals(2, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testLoadRamAdressedInUpperSpacePlusImmediateInAccu() - { - - ram.put((byte) 0, (byte) 0, (byte) 0xf0); - ram.put((byte) 0, (byte) 1, (byte) 122); - ram.put((byte) 255, (byte) 122, (byte) 0b01100110); - - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - - assertEquals(0b01100110, Byte.toUnsignedLong(accu.load())); - assertEquals(2, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testLoadImmediate16InRegisterPair() - { - - ram.put((byte) 0, (byte) 0, (byte) 0x11); - ram.put((byte) 0, (byte) 1, (byte) 0b01100110); - ram.put((byte) 0, (byte) 2, (byte) 0b01101110); - - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - - assertEquals(0b01101110, Byte.toUnsignedLong(d.load())); - assertEquals(0b01100110, Byte.toUnsignedLong(e.load())); - assertEquals(3, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testLoadImmediate16InSP() - { - - ram.put((byte) 0, (byte) 0, (byte) 0x31); - ram.put((byte) 0, (byte) 1, (byte) 0b01100110); - ram.put((byte) 0, (byte) 2, (byte) 0b01101110); - - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - - assertEquals(3, Short.toUnsignedInt(pc.loadWithoutInc())); - assertEquals(0b0110111001100110, Short.toUnsignedInt(sp.load())); - - } - - @Test - public void testLoadHLinSP() - { - h.put((byte) 0b10010110); - l.put((byte) 0b10010110); - ram.put((byte) 0, (byte) 0, (byte) 0xF9); - - tick1Mhz(); - tick1Mhz(); - - assertEquals(0b1001011010010110, Short.toUnsignedLong(sp.load())); - assertEquals(1, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testLoadSPPlusImmediate8InHL() - { - - h.put((byte) 12); - l.put((byte) 20); - sp.put((short) 20); - ram.put((byte) 0, (byte) 0, (byte) 0xF8); - ram.put((byte) 0, (byte) 1, (byte) -10); - - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - - assertEquals((byte) 10, Byte.toUnsignedLong(l.load())); - assertEquals((byte) 0, Byte.toUnsignedLong(h.load())); - assertEquals(2, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testPutSPInRamAdressedByImmediate16() - { - - sp.put((short) 0b1001011010010110); - ram.put((byte) 0, (byte) 0, (byte) 0x08); - ram.put((byte) 0, (byte) 1, (byte) 15); - ram.put((byte) 0, (byte) 2, (byte) 34); - - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - - assertEquals(Byte.toUnsignedLong(sp.loadLow()), Byte.toUnsignedLong(ram.load((byte) 34, (byte) 15))); - assertEquals(Byte.toUnsignedLong(sp.loadHigh()), Byte.toUnsignedLong(ram.load((byte) 34, (byte) 16))); - assertEquals(3, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testPushRegisterPairOntoStack() - { - - sp.put((short) 0xdfff); - d.put((byte) 122); - e.put((byte) 69); - ram.put((byte) 0, (byte) 0, (byte) 0xD5); - - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - - assertEquals(0xdfff - 2, Short.toUnsignedLong(sp.load())); - assertEquals(Byte.toUnsignedLong(e.load()), Byte.toUnsignedLong(ram.load(sp.loadHigh(), sp.loadLow()))); - assertEquals(Byte.toUnsignedLong(d.load()), - Byte.toUnsignedLong(ram.load(sp.loadHigh(), (byte) (sp.loadLow() + 1)))); - assertEquals(1, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testPopRegisterPairOffStack() - { - sp.put((short) 0xdffd); - ram.put(0xdffd, (byte) 45); - ram.put(0xdffe, (byte) 254); - ram.put((byte) 0, (byte) 0, (byte) 0xE1); - - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - - assertEquals(0xdfff, Short.toUnsignedLong(sp.load())); - assertEquals(254, Byte.toUnsignedLong(h.load())); - assertEquals(45, Byte.toUnsignedLong(l.load())); - assertEquals(1, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testNOP() - { - ram.put((byte) 0, (byte) 0, (byte) 0x00); - - tick1Mhz(); - - assertEquals(1, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testHALT() - { - ram.put((byte) 0, (byte) 0, (byte) 0x76); - - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - - assertEquals(1, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testSTOP() - { - ram.put((byte) 0, (byte) 0, (byte) 0x10); - - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - - assertEquals(1, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testJump() - { - ram.put((byte) 0, (byte) 0, (byte) 0xc3); - ram.put((byte) 0, (byte) 1, (byte) 0x04); - ram.put((byte) 0, (byte) 2, (byte) 0xff); - - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - - assertEquals(0xff04, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testconditionalJumpTrue() - { - flags.setZeroFlag(true); - ram.put((byte) 0, (byte) 0, (byte) 0xCA); - ram.put((byte) 0, (byte) 1, (byte) 0x99); - ram.put((byte) 0, (byte) 2, (byte) 0x00); - - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - - assertEquals(0x0099, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testconditionalJumpFalse() - { - flags.setZeroFlag(true); - ram.put((byte) 0, (byte) 0, (byte) 0xC2); - ram.put((byte) 0, (byte) 1, (byte) 0x99); - ram.put((byte) 0, (byte) 2, (byte) 0x00); - - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - - assertEquals(3, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testJumpToHL() - { - h.put((byte) 0xfe); - l.put((byte) 0x04); - ram.put((byte) 0, (byte) 0, (byte) 0xE9); - - tick1Mhz(); - - assertEquals(0xfe04, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testAddJumpPositive() - { - ram.put((byte) 0, (byte) 0, (byte) 0x18); - ram.put((byte) 0, (byte) 1, (byte) 24); - - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - - assertEquals(26, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testAddJumpNegative() - { - pc.put((byte) 0, (byte) 44); - ram.put((byte) 0, (byte) 45, (byte) 0x18); - ram.put((byte) 0, (byte) 46, (byte) -12); - - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - - assertEquals(35, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testConditionalAddJumpTrue() - { - ram.put((byte) 0, (byte) 0, (byte) 0x20); - ram.put((byte) 0, (byte) 1, (byte) 122); - - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - - assertEquals(124, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testConditionalAddJumpFalse() - { - ram.put((byte) 0, (byte) 0, (byte) 0x38); - ram.put((byte) 0, (byte) 1, (byte) 78); - - tick1Mhz(); - tick1Mhz(); - - assertEquals(2, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testCall() - { - sp.put((short) 0xdffd); - ram.put((byte) 0, (byte) 0, (byte) 0xCD); - ram.put((byte) 0, (byte) 1, (byte) 0x11); - ram.put((byte) 0, (byte) 2, (byte) 0xfe); - - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - - assertEquals(0xfe11, Short.toUnsignedInt(pc.loadWithoutInc())); - assertEquals(0, Byte.toUnsignedInt(ram.load(0xdffc))); - assertEquals(3, Byte.toUnsignedInt(ram.load(0xdffb))); - assertEquals(0xdffb, Short.toUnsignedInt(sp.load())); - } - - @Test - public void testConditionalCallTrue() - { - sp.put((short) 0xdffd); - ram.put((byte) 0, (byte) 0, (byte) 0xD4); - ram.put((byte) 0, (byte) 1, (byte) 0x11); - ram.put((byte) 0, (byte) 2, (byte) 0x11); - - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - - assertEquals(0x1111, Short.toUnsignedInt(pc.loadWithoutInc())); - assertEquals(0, Byte.toUnsignedInt(ram.load(0xdffc))); - assertEquals(3, Byte.toUnsignedInt(ram.load(0xdffb))); - assertEquals(0xdffb, Short.toUnsignedInt(sp.load())); - } - - @Test - public void testConditionalCallFalse() - { - sp.put((short) 0xdffd); - ram.put((byte) 0, (byte) 0, (byte) 0xCC); - - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - - assertEquals(3, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testRestart() - { - sp.put((short) 0xdffd); - ram.put((byte) 0, (byte) 0, (byte) 0xDF); - - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - - assertEquals(0x18, Short.toUnsignedInt(pc.loadWithoutInc())); - assertEquals(0, Byte.toUnsignedInt(ram.load(0xdffc))); - assertEquals(1, Byte.toUnsignedInt(ram.load(0xdffb))); - assertEquals(0xdffb, Short.toUnsignedInt(sp.load())); - } - - @Test - public void testReturn() - { - sp.put((short) 0xdffb); - ram.put(0xdffc, (byte) 0x11); - ram.put(0xdffb, (byte) 0x85); - ram.put((byte) 0, (byte) 0, (byte) 0xC9); - - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - - assertEquals(0x1185, Short.toUnsignedInt(pc.loadWithoutInc())); - assertEquals(0xdffd, Short.toUnsignedInt(sp.load())); - } - - @Test - public void testConditionalReturnTrue() - { - sp.put((short) 0xdffb); - ram.put(0xdffc, (byte) 0x11); - ram.put(0xdffb, (byte) 0x85); - ram.put((byte) 0, (byte) 0, (byte) 0xD0); - - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - - assertEquals(0x1185, Short.toUnsignedInt(pc.loadWithoutInc())); - assertEquals(0xdffd, Short.toUnsignedInt(sp.load())); - } - - @Test - public void testConditionalReturnfalse() - { - ram.put((byte) 0, (byte) 0, (byte) 0xC8); - - tick1Mhz(); - tick1Mhz(); - - assertEquals(1, Short.toUnsignedInt(pc.loadWithoutInc())); - } - - @Test - public void testLoadimediate8toRamAdressedByHL() - { - h.put((byte) 0x22); - l.put((byte) 0x22); - ram.put((byte) 0, (byte) 0, (byte) 0x36); - ram.put((byte) 0, (byte) 1, (byte) 0x24); - - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - - assertEquals(2, Short.toUnsignedInt(pc.loadWithoutInc())); - assertEquals(0x24, Byte.toUnsignedInt(ram.load(h.load(), l.load()))); - } - - @Test - public void testIncRegisterPair() - { - b.put((byte) 111); - c.put((byte) 255); - ram.put((byte) 0, (byte) 0, (byte) 0x03); - - tick1Mhz(); - tick1Mhz(); - - assertEquals(1, Short.toUnsignedInt(pc.loadWithoutInc())); - assertEquals(0, Byte.toUnsignedInt(c.load())); - assertEquals(112, Byte.toUnsignedInt(b.load())); - } - - @Test - public void testIncSP() - { - sp.put((short) 0xff11); - ram.put((byte) 0, (byte) 0, (byte) 0x33); - - tick1Mhz(); - tick1Mhz(); - - assertEquals(1, Short.toUnsignedInt(pc.loadWithoutInc())); - assertEquals(0xff12, Short.toUnsignedInt(sp.load())); - } - - @Test - public void testDcrRegisterPair() - { - b.put((byte) 111); - c.put((byte) 255); - ram.put((byte) 0, (byte) 0, (byte) 0x0b); - - tick1Mhz(); - tick1Mhz(); - - assertEquals(1, Short.toUnsignedInt(pc.loadWithoutInc())); - assertEquals(254, Byte.toUnsignedInt(c.load())); - assertEquals(111, Byte.toUnsignedInt(b.load())); - } - - @Test - public void testDcrSP() - { - sp.put((short) 0x0); - ram.put((byte) 0, (byte) 0, (byte) 0x3b); - - tick1Mhz(); - tick1Mhz(); - - assertEquals(1, Short.toUnsignedInt(pc.loadWithoutInc())); - assertEquals(0xffff, Short.toUnsignedInt(sp.load())); - } - - @Test - public void testIncRamAdressedByHL() - { - h.put((byte) 0x23); - l.put((byte) 0x22); - ram.put((byte) 0, (byte) 0, (byte) 0x34); - - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - - assertEquals(1, Short.toUnsignedInt(pc.loadWithoutInc())); - assertEquals(1, Byte.toUnsignedInt(ram.load(h.load(), l.load()))); - } - - @Test - public void testDcrRamAdressedByHL() - { - h.put((byte) 0x23); - l.put((byte) 0x22); - ram.put((byte) 0, (byte) 0, (byte) 0x35); - - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - - assertEquals(1, Short.toUnsignedInt(pc.loadWithoutInc())); - assertEquals(255, Byte.toUnsignedInt(ram.load(h.load(), l.load()))); - } - - @Test - public void testAddRegisterPairToHL() - { - d.put((byte) 111); - e.put((byte) 255); - ram.put((byte) 0, (byte) 0, (byte) 0x19); - - tick1Mhz(); - tick1Mhz(); - - assertEquals(1, Short.toUnsignedInt(pc.loadWithoutInc())); - assertEquals(111, Byte.toUnsignedInt(h.load())); - assertEquals(255, Byte.toUnsignedInt(l.load())); - } - - @Test - public void testAddSPtoHL() - { - sp.put((short) 0xff00); - h.put((byte) 0); - l.put((byte) 0xf1); - ram.put((byte) 0, (byte) 0, (byte) 0x39); - - tick1Mhz(); - tick1Mhz(); - - assertEquals(1, Short.toUnsignedInt(pc.loadWithoutInc())); - assertEquals(0xff, Byte.toUnsignedInt(h.load())); - assertEquals(0xf1, Byte.toUnsignedInt(l.load())); - } - - @Test - public void testAddSignedImediate8toSP() - { - sp.put((short) 424); - ram.put((byte) 0, (byte) 0, (byte) 0xe8); - ram.put((byte) 0, (byte) 1, (byte) -10); - - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - tick1Mhz(); - - assertEquals(2, Short.toUnsignedInt(pc.loadWithoutInc())); - assertEquals(414, Short.toUnsignedInt(sp.load())); - } -} diff --git a/tests/general/BlarggsRomsTest.java b/tests/general/BlarggsRomsTest.java index 49800db..e63ee8a 100644 --- a/tests/general/BlarggsRomsTest.java +++ b/tests/general/BlarggsRomsTest.java @@ -60,12 +60,13 @@ public void test() while (result.indexOf("Failed") == -1 && result.indexOf("Passed") == -1) { gameboy.tick(); - if (Byte.toUnsignedInt(gameboy.getRam().load(0xFF02)) == 0x81 + if (Byte.toUnsignedInt(gameboy.getRam().load(0xFF02)) == 0xFF && Byte.toUnsignedInt(gameboy.getRam().load(0xFF01)) != 0) { result.append((char) Byte.toUnsignedInt(gameboy.getRam().load(0xFF01))); gameboy.getRam().put(0xFF01, 0); } + } assertTrue(result.toString() + "\n" + fInput, result.indexOf("Passed") != -1); diff --git a/tests/general/SingleBlarggsTest.java b/tests/general/SingleBlarggsTest.java index 72c0fb2..0ebb7c9 100644 --- a/tests/general/SingleBlarggsTest.java +++ b/tests/general/SingleBlarggsTest.java @@ -46,15 +46,16 @@ public void test() while (result.indexOf("Failed") == -1 && result.indexOf("Passed") == -1) { gameboy.tick(); - if (Byte.toUnsignedInt(gameboy.getRam().load(0xFF02)) == 0x81 + if (Byte.toUnsignedInt(gameboy.getRam().load(0xFF02)) == 0xFF && Byte.toUnsignedInt(gameboy.getRam().load(0xFF01)) != 0) { result.append((char) Byte.toUnsignedInt(gameboy.getRam().load(0xFF01))); gameboy.getRam().put(0xFF01, 0); } + } - assertTrue(result.toString(), result.indexOf("Passed") != -1); + assertTrue(result.toString() + "\n" + fInput, result.indexOf("Passed") != -1); } } diff --git a/tests/general/SingleMoonEyeTest.java b/tests/general/SingleMoonEyeTest.java index e38ef8f..650213f 100644 --- a/tests/general/SingleMoonEyeTest.java +++ b/tests/general/SingleMoonEyeTest.java @@ -27,7 +27,7 @@ public static List data() List files = new ArrayList<>(); String[] input = new String[2]; - input[0] = "resources\\TestData\\mooneye-gb_hwtests\\manual-only\\sprite_priority.gb"; + input[0] = "resources\\TestData\\mooneye-gb_hwtests\\acceptance\\bits\\unused_hwio-GS.gb"; input[1] = "add_sp_e_timing.gb"; files.add(input); @@ -47,8 +47,7 @@ public void test() LcdConnector lcdConnector = new LcdConnector(); JoypadConnector joypadConnector = new JoypadConnector(); IPSMonitor ipsMonitor = new IPSMonitor(); - Gameboy gameboy = new Gameboy("resources/Roms/SuperMarioLand.gb", MegiHertz.get(4), ipsMonitor, lcdConnector, - joypadConnector); + Gameboy gameboy = new Gameboy(fInput, 0, ipsMonitor, lcdConnector, joypadConnector); Window window = new Window(ipsMonitor, lcdConnector, joypadConnector); new Thread(window).start();