2017-09-07 00:15:28 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-10-05 10:24:36 +00:00
|
|
|
#include <cstdint>
|
|
|
|
#include <vector>
|
2017-10-23 23:04:13 +00:00
|
|
|
#include <string>
|
2017-09-14 22:48:49 +00:00
|
|
|
|
2017-09-07 00:15:28 +00:00
|
|
|
#include <Rom.h>
|
|
|
|
#include <Ram.h>
|
|
|
|
#include <Bus.h>
|
2017-10-23 23:04:13 +00:00
|
|
|
#include <Register.h>
|
2017-10-05 10:24:36 +00:00
|
|
|
|
2017-10-19 21:43:09 +00:00
|
|
|
#include "LR35902.h"
|
2017-10-05 10:24:36 +00:00
|
|
|
#include "IoRegisters.h"
|
2017-09-07 00:15:28 +00:00
|
|
|
|
|
|
|
namespace EightBit {
|
|
|
|
namespace GameBoy {
|
|
|
|
class Bus : public EightBit::Bus {
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum CartridgeType {
|
|
|
|
ROM = 0,
|
|
|
|
ROM_MBC1 = 1,
|
|
|
|
ROM_MBC1_RAM = 2,
|
|
|
|
ROM_MBC1_RAM_BATTERY = 3,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
2017-09-21 19:08:37 +00:00
|
|
|
CyclesPerSecond = 4 * 1024 * 1024,
|
|
|
|
FramesPerSecond = 60,
|
|
|
|
CyclesPerFrame = CyclesPerSecond / FramesPerSecond,
|
2017-09-07 00:15:28 +00:00
|
|
|
TotalLineCount = 154,
|
2017-09-21 19:08:37 +00:00
|
|
|
CyclesPerLine = CyclesPerFrame / TotalLineCount,
|
2017-09-07 00:15:28 +00:00
|
|
|
RomPageSize = 0x4000
|
|
|
|
};
|
|
|
|
|
2018-08-11 20:19:19 +00:00
|
|
|
Bus() noexcept;
|
2017-09-07 00:15:28 +00:00
|
|
|
|
2017-10-19 21:43:09 +00:00
|
|
|
LR35902& CPU() { return m_cpu; }
|
2017-10-04 14:37:11 +00:00
|
|
|
Ram& VRAM() { return m_videoRam; }
|
|
|
|
Ram& OAMRAM() { return m_oamRam; }
|
2017-10-05 10:24:36 +00:00
|
|
|
IoRegisters& IO() { return m_ioPorts; }
|
2017-10-04 14:37:11 +00:00
|
|
|
|
2017-09-07 00:15:28 +00:00
|
|
|
void reset();
|
|
|
|
|
|
|
|
void disableGameRom() { m_disableGameRom = true; }
|
|
|
|
void enableGameRom() { m_disableGameRom = false; }
|
|
|
|
|
|
|
|
bool gameRomDisabled() const { return m_disableGameRom; }
|
|
|
|
bool gameRomEnabled() const { return !gameRomDisabled(); }
|
|
|
|
|
|
|
|
void loadBootRom(const std::string& path);
|
|
|
|
void loadGameRom(const std::string& path);
|
|
|
|
|
2017-10-23 23:04:13 +00:00
|
|
|
int runRasterLines();
|
|
|
|
int runVerticalBlankLines();
|
|
|
|
|
2017-09-07 00:15:28 +00:00
|
|
|
protected:
|
2018-06-24 19:58:20 +00:00
|
|
|
virtual uint8_t& reference(uint16_t address);
|
2017-09-07 00:15:28 +00:00
|
|
|
|
|
|
|
private:
|
2017-10-19 21:43:09 +00:00
|
|
|
LR35902 m_cpu;
|
|
|
|
|
2017-11-11 11:12:09 +00:00
|
|
|
Rom m_bootRom = 0x100; // 0x0000 - 0x00ff
|
2017-09-07 00:15:28 +00:00
|
|
|
std::vector<Rom> m_gameRomBanks; // 0x0000 - 0x3fff, 0x4000 - 0x7fff (switchable)
|
2017-11-11 11:12:09 +00:00
|
|
|
Ram m_videoRam = 0x2000; // 0x8000 - 0x9fff
|
2017-09-07 00:15:28 +00:00
|
|
|
std::vector<Ram> m_ramBanks; // 0xa000 - 0xbfff (switchable)
|
2017-11-11 11:12:09 +00:00
|
|
|
Ram m_lowInternalRam = 0x2000; // 0xc000 - 0xdfff (mirrored at 0xe000)
|
|
|
|
Ram m_oamRam = 0xa0; // 0xfe00 - 0xfe9f
|
2017-10-05 10:24:36 +00:00
|
|
|
IoRegisters m_ioPorts; // 0xff00 - 0xff7f
|
2017-11-11 11:12:09 +00:00
|
|
|
Ram m_highInternalRam = 0x80; // 0xff80 - 0xffff
|
2017-09-07 00:15:28 +00:00
|
|
|
|
2017-11-11 11:12:09 +00:00
|
|
|
bool m_enabledLCD = false;
|
2017-10-23 23:04:13 +00:00
|
|
|
|
2017-11-11 11:12:09 +00:00
|
|
|
bool m_disableGameRom = false;
|
2017-09-07 00:15:28 +00:00
|
|
|
|
2017-11-11 11:12:09 +00:00
|
|
|
bool m_rom = false;
|
|
|
|
bool m_banked = false;
|
|
|
|
bool m_ram = false;
|
|
|
|
bool m_battery = false;
|
2017-09-07 00:15:28 +00:00
|
|
|
|
2017-11-11 11:12:09 +00:00
|
|
|
bool m_higherRomBank = true;
|
|
|
|
bool m_ramBankSwitching = false;
|
2017-09-07 00:15:28 +00:00
|
|
|
|
2017-11-11 11:12:09 +00:00
|
|
|
int m_romBank = 1;
|
|
|
|
int m_ramBank = 0;
|
2017-09-07 00:15:28 +00:00
|
|
|
|
|
|
|
void validateCartridgeType();
|
2017-09-14 22:48:49 +00:00
|
|
|
|
2018-06-10 21:00:52 +00:00
|
|
|
void Bus_WrittenByte(EightBit::EventArgs);
|
2017-10-23 23:04:13 +00:00
|
|
|
|
|
|
|
int runRasterLines(int lines);
|
|
|
|
int runVerticalBlankLines(int lines);
|
|
|
|
int runRasterLine(int limit);
|
2017-09-07 00:15:28 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|