Skip to content

Commit

Permalink
Splitted UI from the rest od the emulator
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSorm committed Sep 12, 2018
1 parent 0ed7060 commit 0239a53
Show file tree
Hide file tree
Showing 18 changed files with 369 additions and 522 deletions.
1 change: 0 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Boy is a Gamboy (dmg not 0) emulator written in Java.
### To-do
* Pass all tests for dmg (not 0)
* Implement sound
* Totally split ui from emulator
* Make implementation of MBC1 clearer
* Implement all other MBC's

Expand Down
94 changes: 94 additions & 0 deletions src/connectos/JoypadConnector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package connectos;

public class JoypadConnector
{
private boolean downIsPressed;
private boolean upIsPressed;
private boolean leftIsPressed;
private boolean rightIsPressed;
private boolean startIsPressed;
private boolean selectIsPressed;
private boolean aIsPressed;
private boolean bIsPressed;

public boolean isDownPressed()
{
return downIsPressed;
}

public void setDownPressed(boolean downIsPressed)
{
this.downIsPressed = downIsPressed;
}

public boolean isUpPressed()
{
return upIsPressed;
}

public void setUpPressed(boolean upIsPressed)
{
this.upIsPressed = upIsPressed;
}

public boolean isLeftPressed()
{
return leftIsPressed;
}

public void setLeftPressed(boolean leftIsPressed)
{
this.leftIsPressed = leftIsPressed;
}

public boolean isRightPressed()
{
return rightIsPressed;
}

public void setRightPressed(boolean rightIsPressed)
{
this.rightIsPressed = rightIsPressed;
}

public boolean isStartPressed()
{
return startIsPressed;
}

public void setStartPressed(boolean startIsPressed)
{
this.startIsPressed = startIsPressed;
}

public boolean isSelectPressed()
{
return selectIsPressed;
}

public void setSelectPressed(boolean selectIsPressed)
{
this.selectIsPressed = selectIsPressed;
}

public boolean isaPressed()
{
return aIsPressed;
}

public void setaPressed(boolean aIsPressed)
{
this.aIsPressed = aIsPressed;
}

public boolean isbPressed()
{
return bIsPressed;
}

public void setbPressed(boolean bIsPressed)
{
this.bIsPressed = bIsPressed;
}

}
37 changes: 37 additions & 0 deletions src/connectos/LcdConnector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package connectos;

import java.awt.image.BufferedImage;

import ppu.LCD;

public class LcdConnector
{
private BufferedImage lcdOutput;
private boolean isLcdOn;

public LcdConnector()
{
this.lcdOutput = new BufferedImage(LCD.LCD_WIDTH, LCD.LCD_HEIGHT, BufferedImage.TYPE_INT_RGB);
isLcdOn = false;
}

public void setImage(BufferedImage lcdOutput)
{
this.lcdOutput = lcdOutput;
}

public BufferedImage getImage()
{
return lcdOutput;
}

public void setLcdOn(boolean isOn)
{
this.isLcdOn = isOn;
}

public boolean isLcdOn()
{
return isLcdOn;
}
}
41 changes: 9 additions & 32 deletions src/gameboy/Gameboy.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

import java.awt.event.KeyListener;

import javax.swing.JPanel;

import cartridge.BootRomUnmapRegister;
import cartridge.BootRom;
import cartridge.Cartridge;
import cartridge.RomBank0;
import cartridge.SwitchableRamBank;
import cartridge.SwitchableRomBank;
import connectos.JoypadConnector;
import connectos.LcdConnector;
import cpu.Accumulator;
import cpu.CPU;
import cpu.Flags;
Expand All @@ -24,7 +21,6 @@
import ppu.DMAMecanism;
import ppu.DirectMemoryAcessRegister;
import ppu.LCD;
import ppu.LCD.Panel;
import ppu.LCDControlStatusRegister;
import ppu.LCDControllRegister;
import ppu.LCDControllYCompare;
Expand Down Expand Up @@ -83,7 +79,8 @@ public class Gameboy
private Register8Bit l;
private int baseClockHz;

public Gameboy(String RomPath, int baseClockHz)
public Gameboy(String RomPath, int baseClockHz, IPSMonitor ipsMonitor, LcdConnector lcdConnector,
JoypadConnector joypadConnector)
{
this.baseClockHz = baseClockHz;

Expand Down Expand Up @@ -140,33 +137,29 @@ public Gameboy(String RomPath, int baseClockHz)

this.cpu = new CPU(ram, accu, pc, sp, b, c, d, e, h, l, flags, interruptEnableRegister, interruptFlagRegister);

this.lcd = new LCD(lcdControll, lcdConnector);

this.ppu = new PPU(tilePatternTable, scrollX, scrollY, lcdControll, lcdControllYCompare,
lcdControlStatusRegister, lcdYCoordinate, backgroundAndWindowColorPalette, obj0, obj1,
interruptFlagRegister, tileMap, objectAtributeMap, videoRam);
interruptFlagRegister, tileMap, objectAtributeMap, videoRam, lcd);

this.timer = new Timer(timerControl, timerCounter, timerModulo, interruptFlagRegister, divider);

this.joypad = new JoyPad(joypadInformation, interruptFlagRegister);

this.lcd = new LCD(ppu.getPixelFifo(), lcdControll);
this.joypad = new JoyPad(joypadInformation, interruptFlagRegister, joypadConnector);

this.dma = new DMAMecanism(dmaRegister, ram, objectAtributeMap);

this.cardridgeOverBootRomMapper = new CardridgeOverBootRomMapper(cartridge, unusableMemory1, ram,
bootRomTurnOff);

this.ipsMonitor = new IPSMonitor();
this.ipsMonitor = ipsMonitor;

instructionCount = 0;
elapsedTime = System.nanoTime();
}

public void start()
{
// CPUDataScreen cpuScreen = new CPUDataScreen(ram, accu, pc, sp, b, c,
// d, e, h, l, flags);

// new Thread(cpuScreen).start();
while (true)
{
tick();
Expand Down Expand Up @@ -200,24 +193,8 @@ public Ram getRam()
return ram;
}

public Panel getPanel()
{
return lcd.getPanel();
}

public KeyListener getKeyListener()
{
return joypad;
}

public CPU getCpu()
{
return cpu;
}

public IPSMonitor getIPSMonitor()
{
return ipsMonitor;
}

}
105 changes: 16 additions & 89 deletions src/joypad/JoyPad.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,97 +3,24 @@
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import connectos.JoypadConnector;
import cpu.InterruptFlagRegister;
import gameboy.MegiHertz;
import gameboy.TickBasedComponend;

public class JoyPad extends TickBasedComponend implements KeyListener
public class JoyPad extends TickBasedComponend
{
private JoypadInformationRegister joypadInformation;
private InterruptFlagRegister interruptFlag;
private JoypadConnector joypadConnector;

private boolean downIsPressed;
private boolean upIsPressed;
private boolean leftIsPressed;
private boolean rightIsPressed;
private boolean startIsPressed;
private boolean selectIsPressed;
private boolean aIsPressed;
private boolean bIsPressed;

public JoyPad(JoypadInformationRegister joypadInformation, InterruptFlagRegister interruptFlag)
public JoyPad(JoypadInformationRegister joypadInformation, InterruptFlagRegister interruptFlag,
JoypadConnector joypadConnector)
{
super(4194304);
super(MegiHertz.get(4));
this.joypadInformation = joypadInformation;
this.interruptFlag = interruptFlag;
}

@Override
public void keyPressed(KeyEvent event)
{
switch (event.getKeyCode())
{
case KeyEvent.VK_DOWN:
downIsPressed = true;
break;
case KeyEvent.VK_UP:
upIsPressed = true;
break;
case KeyEvent.VK_LEFT:
leftIsPressed = true;
break;
case KeyEvent.VK_RIGHT:
rightIsPressed = true;
break;
case KeyEvent.VK_SPACE:
startIsPressed = true;
break;
case KeyEvent.VK_ENTER:
selectIsPressed = true;
break;
case KeyEvent.VK_B:
bIsPressed = true;
break;
case KeyEvent.VK_A:
aIsPressed = true;
break;
}
}

@Override
public void keyReleased(KeyEvent event)
{
switch (event.getKeyCode())
{
case KeyEvent.VK_DOWN:
downIsPressed = false;
break;
case KeyEvent.VK_UP:
upIsPressed = false;
break;
case KeyEvent.VK_LEFT:
leftIsPressed = false;
break;
case KeyEvent.VK_RIGHT:
rightIsPressed = false;
break;
case KeyEvent.VK_SPACE:
startIsPressed = false;
break;
case KeyEvent.VK_ENTER:
selectIsPressed = false;
break;
case KeyEvent.VK_B:
bIsPressed = false;
break;
case KeyEvent.VK_A:
aIsPressed = false;
break;
}
}

@Override
public void keyTyped(KeyEvent event)
{
this.joypadConnector = joypadConnector;
}

@Override
Expand All @@ -106,42 +33,42 @@ public boolean tick()

boolean isAnyButtonPressed = joypadInformation.isButtonPressed();

if (downIsPressed)
if (joypadConnector.isDownPressed())
{
joypadInformation.setInputDown(true);
}

if (upIsPressed)
if (joypadConnector.isUpPressed())
{
joypadInformation.setInputUp(true);
}

if (leftIsPressed)
if (joypadConnector.isLeftPressed())
{
joypadInformation.setInputLeft(true);
}

if (rightIsPressed)
if (joypadConnector.isRightPressed())
{
joypadInformation.setInputRight(true);
}

if (startIsPressed)
if (joypadConnector.isStartPressed())
{
joypadInformation.setInputStart(true);
}

if (selectIsPressed)
if (joypadConnector.isSelectPressed())
{
joypadInformation.setInputSelect(true);
}

if (aIsPressed)
if (joypadConnector.isaPressed())
{
joypadInformation.setInputA(true);
}

if (bIsPressed)
if (joypadConnector.isbPressed())
{
joypadInformation.setInputB(true);
}
Expand Down
Loading

0 comments on commit 0239a53

Please sign in to comment.