DMA. First steps
authorslack <slack@codemaniacs.com>
Mon, 14 Jul 2008 00:23:54 +0000 (02:23 +0200)
committerslack <slack@codemaniacs.com>
Mon, 14 Jul 2008 00:23:54 +0000 (02:23 +0200)
GBMemory.cc
GBMemory.h
GBVideo.cc
GBVideo.h

index ebd1b5e3fa93ad4e0f2e1990a56b320381e7e0e8..dc2cba36b0eab2299d2d779ab83a3363ee79d362 100644 (file)
@@ -6,7 +6,7 @@
 #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);
@@ -16,9 +16,18 @@ void GBMemory::write(int addr, u8 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;
@@ -30,7 +39,7 @@ void GBMemory::write(int addr, u8 value)
 }
 
 
-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);
@@ -49,7 +58,7 @@ u8  GBMemory::read(int addr) const
        }
 }
 
-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);
index 14fa201dac745be2563cf20b2fdfe02b1ee1b4d2..6e27bd4975ee8425ebc4a5cb81affa6b442d40f8 100644 (file)
@@ -36,9 +36,9 @@ class GBMemory
        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)
index ac11a1acb544a53d94c6ae1d5bf5097d508b40b6..ea8142905573bd4578e8c727ea2043e0a71773d8 100644 (file)
@@ -8,11 +8,11 @@
 
 
 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),
@@ -51,63 +51,14 @@ void GBVideo::reset()
        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
index 60471310b47cae88fc1066034ef58d486650e210..ac9f2654537412d88b634cbe644182b2b6221505 100644 (file)
--- a/GBVideo.h
+++ b/GBVideo.h
@@ -104,6 +104,10 @@ class GBVideo
                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();