2023-09-12 00:07:33 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <SFML/Graphics.hpp>
|
|
|
|
#include <memory/device.h>
|
|
|
|
#include <misc/types.h>
|
|
|
|
#include <lcd/palette.h>
|
|
|
|
#include <cpu/cpu.h>
|
|
|
|
|
|
|
|
class LCD;
|
|
|
|
|
|
|
|
enum LCDMode : u8 {
|
|
|
|
ModeHBlank = 0b000000000,
|
|
|
|
ModeVBlank = 0b000000001,
|
|
|
|
ModeOAMSearch = 0b000000010,
|
|
|
|
ModeTransferring = 0b000000011,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum RegStat : u8 {
|
|
|
|
LycEqual = 0b000000100,
|
|
|
|
IntSourceHBlank = 0b000001000,
|
|
|
|
IntSourceVBlank = 0b000010000,
|
|
|
|
IntSourceOAM = 0b000100000,
|
|
|
|
IntSourceLYC = 0b001000000,
|
|
|
|
};
|
|
|
|
|
|
|
|
class LCD : public Mem_device {
|
|
|
|
private:
|
|
|
|
// Graphics
|
|
|
|
sf::RenderTexture screenbuffer;
|
2023-09-18 23:33:39 +02:00
|
|
|
sf::Image tiles[384];
|
2023-09-19 23:21:15 +02:00
|
|
|
unsigned int tilemap[2][32*32];
|
2023-09-12 00:07:33 +02:00
|
|
|
|
|
|
|
// Emulated device
|
|
|
|
u8 regLY;
|
|
|
|
u8 regLYC;
|
|
|
|
bool intHBlank;
|
|
|
|
bool intVBlank;
|
|
|
|
bool intOAM;
|
|
|
|
bool intLYC;
|
|
|
|
LCDMode currentMode;
|
|
|
|
Palette bgp;
|
|
|
|
Palette obp[2];
|
|
|
|
|
|
|
|
u8 vram_raw[0x2000];
|
|
|
|
|
|
|
|
// misc
|
|
|
|
Cpu& cpu;
|
|
|
|
bool enabled;
|
|
|
|
bool vram_dirty;
|
|
|
|
|
2023-09-18 23:33:39 +02:00
|
|
|
void vram_write(u16 addr, u8 data);
|
|
|
|
void generate_tile(int idx);
|
2023-09-12 00:07:33 +02:00
|
|
|
public:
|
|
|
|
LCD(Cpu& cpu);
|
|
|
|
|
|
|
|
virtual void write8(u16 addr, u8 data);
|
|
|
|
virtual u8 read8(u16 addr);
|
2023-09-18 23:33:39 +02:00
|
|
|
|
|
|
|
void render(sf::RenderTarget& target);
|
2023-09-12 00:07:33 +02:00
|
|
|
};
|