#include <sstream>
#include <iomanip>
-void GBMemory::write(int addr, u8 value)
+void GBMemory::write(u16 addr, u8 value)
{
if (addr < 0x8000) mbc->write(addr, value);
else if (addr < 0xA000) core->video.write_VRAM(addr, value);
else if (addr < 0xFEA0) core->video.write_OAM (addr, value);
else if (addr >= 0xFF00) {
high[addr-0xFF00] = value;
- if (addr == DIV) {
+ if (addr == DIV)
+ {
high[I_DIV] = 0;
}
+ /*
+ else if (addr == DMA)
+ {
+ u16 dma_src = value << 8;
+ logger.warning("OAM DMA transfer from 0x", std::hex, std::setfill('0'), dma_src, " requested");
+ core->video.DMA_OAM(dma_src);
+ }
+ */
}
else {
std::ostringstream errmsg;
}
-u8 GBMemory::read(int addr) const
+u8 GBMemory::read(u16 addr) const
{
if (addr < 0x8000) return mbc->read(addr);
else if (addr < 0xA000) return core->video.read_VRAM(addr);
}
}
-u16 GBMemory::read16(int addr) const
+u16 GBMemory::read16(u16 addr) const
{
if (addr < 0x8000) return mbc->read16(addr);
else if (addr < 0xA000) return core->video.read16_VRAM(addr);
void init(MBC *mbc) { this->mbc = mbc; }
- u8 read(int addr) const;
- u16 read16(int addr) const;
- void write(int addr, u8 value);
+ u8 read (u16 addr) const;
+ u16 read16(u16 addr) const;
+ void write (u16 addr, u8 value);
public:
static const u16 DIV = 0xFF04; // Divider register (R/W)
GBVideo::GBVideo(GameBoy *core):
+ OAM(),
display(0),
core(core),
cur_window_line(0),
mode(2),
- OAM(),
OAM_BUSY(false),
VRAM_BUSY(false),
frames_rendered(0),
cycles_until_next_update = 0;
}
-#if 0
-u8 GBVideo::read_VRAM (int addr) const
-{
- //int STAT = core->memory.high[GBMemory::I_STAT];
- //if ((STAT & 3) == 3)
- // return 0xFF; // VRAM access disabled
- //else
- return VRAM[addr-VRAM_BASE];
-}
-
-u8 GBVideo::read_OAM (int addr) const
-{
- //int STAT = core->memory.high[GBMemory::I_STAT];
- //if ((STAT & 3) >= 2)
- // return 0xFF; // OAM access disabled
- //else
- return OAM.raw[addr-OAM_BASE];
-}
-
-u16 GBVideo::read16_VRAM (int addr) const
-{
- //int STAT = core->memory.high[GBMemory::I_STAT];
- //if ((STAT & 3) == 3)
- // return 0xFF; // VRAM access disabled
- //else
- return VRAM[addr-VRAM_BASE]+(VRAM[addr-VRAM_BASE+1] << 8);
-}
-
-u16 GBVideo::read16_OAM (int addr) const
-{
- //int STAT = core->memory.high[GBMemory::I_STAT];
- //if ((STAT & 3) >= 2)
- // return 0xFF; // OAM access disabled
- //else
- return OAM.raw[addr-OAM_BASE]+(OAM.raw[addr-OAM_BASE+1] << 8);
-}
-
-void GBVideo::write_VRAM(int addr, u8 value)
-{
- //int STAT = core->memory.high[GBMemory::I_STAT];
- //if ((STAT & 3) == 3)
- // return; // VRAM access disabled
- //else
- VRAM[addr-VRAM_BASE] = value;
-}
-
-void GBVideo::write_OAM (int addr, u8 value)
+void GBVideo::DMA_OAM (const u16 src)
{
- //int STAT = core->memory.high[GBMemory::I_STAT];
- //if ((STAT & 3) >= 2)
- // return; // OAM access disabled
- //else
- OAM.raw[addr-OAM_BASE] = value;
+ for (u16 i=0; i<160; i++)
+ {
+ OAM.raw[i] = core->memory.read(src+i);
+ }
}
-#endif
-
u32 GBVideo::update()
{
//Mode 0 is present between 201-207 clks, 2 about 77-83 clks, and 3
if (!OAM_BUSY) OAM.raw[addr-OAM_BASE] = value;
}
+
+ // Write the whole OAM area via DMA
+ void DMA_OAM (const u16 src);
+
// drawing control
void draw();
u32 update();