Skip to content

Commit

Permalink
Addet sound and serial ram registers
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSorm committed Sep 14, 2018
1 parent 0239a53 commit 2016624
Show file tree
Hide file tree
Showing 33 changed files with 868 additions and 954 deletions.
4 changes: 2 additions & 2 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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:|
Expand Down Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions src/cpu/InterruptFlagRegister.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand Down
59 changes: 57 additions & 2 deletions src/gameboy/Gameboy.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -87,14 +110,39 @@ 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);
this.e = new Register8Bit((byte) 0, flags);
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();
Expand Down Expand Up @@ -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);

Expand Down
8 changes: 4 additions & 4 deletions src/ppu/LCDControlStatusRegister.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down
85 changes: 61 additions & 24 deletions src/ram/Ram.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<>();

Expand Down Expand Up @@ -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);
Expand All @@ -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));
Expand Down
41 changes: 41 additions & 0 deletions src/serial/SerialControllRegister.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
14 changes: 14 additions & 0 deletions src/serial/SerialTransferDataRegister.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
23 changes: 23 additions & 0 deletions src/sound/ChannelControlRegister.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
23 changes: 23 additions & 0 deletions src/sound/SelectionOfSoundOutputRegister.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
Loading

0 comments on commit 2016624

Please sign in to comment.