Optimizations
authorslack <slack@Blackbird.(none)>
Tue, 1 Jul 2008 23:12:50 +0000 (01:12 +0200)
committerslack <slack@Blackbird.(none)>
Tue, 1 Jul 2008 23:12:50 +0000 (01:12 +0200)
GBMemory.cc
GBMemory.h
GBVideo.cc
GBVideo.h
Makefile
gbcore.cc

index a081d06bab5ee82a125eb7ff20ab6be92a34b5eb..5226d4b280b6f08dfad1206e4eb6e08e8f3d87ee 100644 (file)
@@ -21,13 +21,10 @@ void GBMemory::write(int addr, u8 value)
        if (addr < 0x8000)      mbc->write(addr, value);
        else if (addr < 0xA000) core->video.write_VRAM(addr, value);
        else if (addr < 0xC000) mbc->write(addr, value);
-       else if (addr < 0xD000) WRAM0[addr - WRAM0_BASE] = value;
-       else if (addr < 0xE000) WRAM1[addr - WRAM1_BASE] = value;
+       else if (addr < 0xE000) WRAM[addr - WRAM_BASE] = value;
        else if (addr < 0xFE00) write(addr-0x2000, value);
        else if (addr < 0xFEA0) core->video.write_OAM (addr, value);
-       else if (addr >= 0xFF00 && addr <= 0xFF7F) {
-               IO.write(addr,value);
-       }
+       else if (addr >= 0xFF00 && addr <= 0xFF7F) IO.write(addr, value);
        else if (addr >= 0xFF80 && addr <= 0xFFFE) HRAM[addr - HRAM_BASE]=value;
        else if (addr == 0xFFFF) IE=value;
        else {
@@ -45,12 +42,10 @@ u8  GBMemory::read(int addr) const
        if (addr < 0x8000)      return mbc->read(addr);
        else if (addr < 0xA000) return core->video.read_VRAM(addr);
        else if (addr < 0xC000) return mbc->read(addr);
-       else if (addr < 0xD000) return WRAM0[addr - WRAM0_BASE];
-       else if (addr < 0xE000) return WRAM1[addr - WRAM1_BASE];
+       else if (addr < 0xE000) return WRAM[addr - WRAM_BASE];
        else if (addr < 0xFDFF) return read(addr-0x2000);
        else if (addr < 0xFEA0) return core->video.read_OAM (addr);
-       else if (addr >= 0xFF00 && addr <= 0xFF7F) 
-               return IO.read(addr);
+       else if (addr >= 0xFF00 && addr <= 0xFF7F) return IO.read(addr);
        else if (addr >= 0xFF80 && addr <= 0xFFFE) return HRAM[addr - HRAM_BASE];
        else if (addr == 0xFFFF) return IE;
        else {
index 56bd5704f6ec81c34df7eb144fb63f81efaf4823..84065c96615715a435ae85a1cbeaf96452c3dee2 100644 (file)
@@ -8,8 +8,11 @@ class MBC;
 
 class GBIO
 {
-       u8 ports[128];
+       friend class GameBoy;
+       friend class GBVideo;
 
+       u8 ports[128];
+       
        public:
        static const u16 IO_BASE = 0xFF00;
        static const u16 LCDC = 0xFF40; // LCD Control          (R/W)
@@ -26,6 +29,22 @@ class GBIO
        static const u16 DMA  = 0xFF46; // DMA Transfer & Start addr (W)
        static const u16 IF   = 0xFF0F; // Interrupt flag       (R/W)
 
+       private:
+       static const u16 I_LCDC = 0xFF40 - IO_BASE; // LCD Control          (R/W)
+       static const u16 I_STAT = 0xFF41 - IO_BASE; // LCD Status           (R/W)
+       static const u16 I_SCY  = 0xFF42 - IO_BASE; // Scroll Y             (R/W)
+       static const u16 I_SCX  = 0xFF43 - IO_BASE; // Scroll X             (R/W)
+       static const u16 I_LY   = 0xFF44 - IO_BASE; // LCDC Y coord         (R)
+       static const u16 I_LYC  = 0xFF45 - IO_BASE; // LY Compare           (R/W)
+       static const u16 I_WY   = 0xFF4A - IO_BASE; // Window Y pos         (R/W)
+       static const u16 I_WX   = 0xFF4B - IO_BASE; // Window X pos minus 7 (R/W)
+       static const u16 I_BGP  = 0xFF47 - IO_BASE; // BG Pallette data     (R/W)
+       static const u16 I_OBP0 = 0xFF48 - IO_BASE; // Object Pallete 0 data(R/W)
+       static const u16 I_OBP1 = 0xFF49 - IO_BASE; // Object Pallete 1 data(R/W)
+       static const u16 I_DMA  = 0xFF46 - IO_BASE; // DMA Transfer & Start addr (W)
+       static const u16 I_IF   = 0xFF0F - IO_BASE; // Interrupt flag       (R/W)
+
+       public:
        u8   read(int addr) const;
        void write(int addr, u8 value);
 
@@ -33,14 +52,16 @@ class GBIO
 
 class GBMemory
 {
+       friend class GameBoy;
+       friend class GBVideo;
+
        GameBoy *core;
        MBC *mbc;
                        // 0000-3FFF: ROM Bank 0 (in cart)
                        // 4000-7FFF: Switchable ROM Bank (in cart)
                        // 8000-9FFF: Video RAM
                        // A000-BFFF: External RAM (in cart, switchable)
-       u8 WRAM0[4096]; // C000-CFFF: Work RAM Bank 0
-       u8 WRAM1[4096]; // D000-DFFF: Work RAM Bank 1 (TODO: In GBC mode switchable bank 1-7)
+       u8 WRAM[8192];  // C000-DFFF: Work RAM
                        // E000-FDFF: ECHO: Same as C000-DDFF
                        // FE00-FE9F: Sprite Attribute Table (OAM)
                        // FEA0-FEFF: Not usable
@@ -53,8 +74,7 @@ class GBMemory
 
        static const u16 VRAM_BASE  = 0x8000;
        static const u16 EXTERNAL_RAM_BASE = 0xA000;
-       static const u16 WRAM0_BASE = 0xC000;
-       static const u16 WRAM1_BASE = 0xD000;
+       static const u16 WRAM_BASE = 0xC000;
        static const u16 OAM_BASE   = 0xFE00;
        static const u16 IO_BASE    = 0xFF00;
        static const u16 HRAM_BASE  = 0xFF80;
index 97fb024c9e48319f62c7943f6f25bd1c4258dd20..2419a8cedfd5de498a725e89935acb062cdc4603 100644 (file)
@@ -9,6 +9,8 @@ GBVideo::GBVideo(GameBoy *core):
        display(0),
        core(core),
        frames_rendered(0),
+       cycles_until_next_update(0),
+       mode(2),
        display_mode(NORMAL)
 {
        SDL_Init(SDL_INIT_VIDEO);
@@ -31,7 +33,7 @@ GBVideo::~GBVideo()
 
 u8   GBVideo::read_VRAM (int addr) const
 {
-       int STAT = core->memory.read(GBIO::STAT);
+       int STAT = core->memory.IO.ports[GBIO::I_STAT];
        if ((STAT & 3) == 3)
                return 0xFF; // VRAM access disabled
        else
@@ -40,7 +42,7 @@ u8   GBVideo::read_VRAM (int addr) const
 
 u8   GBVideo::read_OAM  (int addr) const
 {
-       int STAT = core->memory.read(GBIO::STAT);
+       int STAT = core->memory.IO.ports[GBIO::I_STAT];
        if ((STAT & 3) >= 2)
                return 0xFF; // OAM access disabled
        else
@@ -49,7 +51,7 @@ u8   GBVideo::read_OAM  (int addr) const
 
 void GBVideo::write_VRAM(int addr, u8 value)
 {
-       int STAT = core->memory.read(GBIO::STAT);
+       int STAT = core->memory.IO.ports[GBIO::I_STAT];
        if ((STAT & 3) == 3)
                return; // VRAM access disabled
        else
@@ -58,7 +60,7 @@ void GBVideo::write_VRAM(int addr, u8 value)
 
 void GBVideo::write_OAM (int addr, u8 value)
 {
-       int STAT = core->memory.read(GBIO::STAT);
+       int STAT = core->memory.IO.ports[GBIO::I_STAT];
        if ((STAT & 3) >= 2)
                return; // OAM access disabled
        else
@@ -83,173 +85,197 @@ void GBVideo::update()
        // mode 0 starts at 252, 708, 1164...
        // vblank starts at 65664
 
-       u32 *pixels = static_cast<u32*>(display->pixels);
-       u32 pixels_per_line = display->pitch/display->format->BytesPerPixel;
+       if (cycles_until_next_update == 0)
+       {
+               int STAT = core->memory.IO.ports[GBIO::I_STAT];
+               int LYC  = core->memory.IO.ports[GBIO::I_LYC];
+               int LY  = core->memory.IO.ports[GBIO::I_LY];
 
-       int LCDC = core->memory.read(GBIO::LCDC);
-       int STAT = core->memory.read(GBIO::STAT);
-       int LYC  = core->memory.read(GBIO::LYC);
+               switch (mode)
+               {
+                       case 0:
+                               // HBlank (preserve bits 2-6, mode = 0)
+                               STAT = (STAT&0xFC);
+                               if (check_bit(STAT, 3))
+                               {
+                                       logger.trace("Requesting IRQ_LCD_STAT -- HBLANK");
+                                       core->irq(GameBoy::IRQ_LCD_STAT);
+                               }
+                               cycles_until_next_update = 204;
+                               if (LY == 143)
+                                       mode = 1;
+                               else
+                                       mode = 2;
+                               break;
+                       case 1:
+                               if (LY == 144)
+                               {
+                                       logger.trace("Requesting IRQ_VBLANK");
+                                       core->irq(GameBoy::IRQ_VBLANK);
 
-       int t = core->cycle_count % 70224;
-       int hline_t=-1;
-       int LY = t/456;
+                                       if (check_bit(STAT,4))
+                                       {
+                                               logger.trace("Requesting IRQ_LCD_STAT -- VBLANK");
+                                               core->irq(GameBoy::IRQ_LCD_STAT);
+                                       }
+                                       SDL_Flip(display);
+                                       frames_rendered++;
+                                       char buf[50];
+                                       sprintf(buf, "%d", frames_rendered);
+                                       SDL_WM_SetCaption(buf, 0);
 
-       if (t >= 65664)
-       {
-               if (t == 65664)
-               {
-                       logger.trace("Requesting IRQ_VBLANK");
-                       core->irq(GameBoy::IRQ_VBLANK);
+                                       // preserve bits 3-6, set mode to 1 (VBlank) and coincidence to 0
+                                       STAT = (STAT&0xF8) | 1;
+                               }
+                               cycles_until_next_update = 456;
+                               if (LY == 153)
+                                       mode = 2;
+                               else
+                                       mode = 1;
+                               break;
+                       case 2: {
+                               if (LY == LYC)
+                               {
+                                       STAT = set_bit(STAT, 2); // set coincidence flag
+                                       if (check_bit(STAT, 6))
+                                       {
+                                               logger.trace("Requesting IRQ_LCD_STAT -- LY = LYC = ", LY, " EI=", int(core->memory.IE), 
+                                                               " IME =", int(core->IME));
+                                               core->irq(GameBoy::IRQ_LCD_STAT);
+                                       }
+                               }
 
-                       if (check_bit(STAT,4))
-                       {
-                               logger.trace("Requesting IRQ_LCD_STAT -- VBLANK");
-                               core->irq(GameBoy::IRQ_LCD_STAT);
+                               if (check_bit(STAT, 5)) 
+                               {
+                                       logger.trace("Requesting IRQ_LCD_STAT -- Mode 2");
+                                       core->irq(GameBoy::IRQ_LCD_STAT);
+                               }
+
+                               // preserve bits 2-6, set mode 2
+                               STAT = (STAT&0xFC) | 2;
+                               cycles_until_next_update = 80;
+                               mode = 3;
+                               break;
                        }
-                       SDL_Flip(display);
-                       frames_rendered++;
-                       char buf[50];
-                       sprintf(buf, "%d", frames_rendered);
-                       SDL_WM_SetCaption(buf, 0);
+                       case 3:
+                               draw();
+                               // preserve bits 2-6, set mode 3
+                               STAT = (STAT&0xFC) | 3;
+                               cycles_until_next_update = 172;
+                               mode = 0;
+                               break;
                }
-
-               // preserve bits 3-6, set mode to 1 (VBlank) and coincidence to 0
-               STAT = (STAT&0xF8) | 1;
-       }
-       else
-       {
-               hline_t = t%456;
-               if (hline_t == 0 && LY == LYC)
+               
+               if (mode == 1 || mode == 2)
                {
-                       STAT = set_bit(STAT, 2); // set coincidence flag
-                       if (hline_t == 0 && check_bit(STAT, 6))
-                       {
-                               logger.trace("Requesting IRQ_LCD_STAT -- LY = LYC = ", LY, " EI=", int(core->memory.read(0xFFFF)), 
-                                               " IME =", int(core->IME));
-                               core->irq(GameBoy::IRQ_LCD_STAT);
-                       }
+                       LY = (LY+1)%154;
+                       logger.trace(LY);
+                       core->memory.IO.ports[GBIO::I_LY] = LY;
                }
 
-               if (hline_t < 80)
-               {
-                       if (hline_t == 0 && check_bit(STAT, 5)) {
-                               logger.trace("Requesting IRQ_LCD_STAT -- Mode 2");
-                               core->irq(GameBoy::IRQ_LCD_STAT);
-                       }
 
-                       // preserve bits 2-6, set mode 2
-                       STAT = (STAT&0xFC) | 2;
-               }
-               else if (hline_t < 252)
-               {
-                       // preserve bits 2-6, set mode 3
-                       STAT = (STAT&0xFC) | 3;
-               }
-               else
-               {
-                       // HBlank (preserve bits 2-6, mode = 0)
-                       STAT = (STAT&0xFC);
-                       if (hline_t == 252 && check_bit(STAT, 3))
-                       {
-                               logger.trace("Requesting IRQ_LCD_STAT -- HBLANK");
-                               core->irq(GameBoy::IRQ_LCD_STAT);
-                       }
-               }
-               
+               core->memory.IO.ports[GBIO::I_STAT] = STAT;
        }
-       
-       core->memory.write(GBIO::LY, LY);
-       core->memory.write(GBIO::STAT, STAT);
 
-       if (display_mode == NORMAL)
+       --cycles_until_next_update;
+       return;
+}
+
+void GBVideo::draw()
+{
+       u32 *pixels = static_cast<u32*>(display->pixels);
+       u32 pixels_per_line = display->pitch/display->format->BytesPerPixel;
+
+       int LCDC = core->memory.IO.ports[GBIO::I_LCDC];
+       int LY  = core->memory.IO.ports[GBIO::I_LY];
+
+       if (LY < 144 && display_mode == NORMAL)
        {
                // Draw the background
                // Draw at hline_t == 80, when the app cannot write to neither VRAM nor OAM
-               if (hline_t == 80)
+               int BGP  = core->memory.IO.ports[GBIO::I_BGP];
+               int pallette[4];
+               pallette[0] = BGP & 3;
+               pallette[1] = (BGP>>2) & 3;
+               pallette[2] = (BGP>>4) & 3;
+               pallette[3] = (BGP>>6) & 3;
+               
+               if (check_bit(LCDC, 0))  // is BG display active?
                {
-                       int BGP  = core->memory.read(GBIO::BGP);
-                       int pallette[4];
-                       pallette[0] = BGP & 3;
-                       pallette[1] = (BGP>>2) & 3;
-                       pallette[2] = (BGP>>4) & 3;
-                       pallette[3] = (BGP>>6) & 3;
-                       
-                       if (check_bit(LCDC, 0))  // is BG display active?
+                       u16 tile_map_addr  = check_bit(LCDC,3) ? 0x1C00  : 0x1800;
+                       u16 tile_data_addr = check_bit(LCDC,4) ? 0x0000 : 0x0800;
+                       int tile_data_base = (tile_data_addr == 0x0800) ? -128 : 0;
+
+                       // (vx    , vy    ) -> position of the pixel in the 256x256 bg
+                       // (map_x , map_y ) -> map coordinates of the current tile
+                       // (tile_x, tile_y) -> position of the pixel in the tile
+                       int SCX = core->memory.IO.ports[GBIO::I_SCX];
+                       int SCY = core->memory.IO.ports[GBIO::I_SCY];
+                       int vy = (LY + SCY) % 256;
+                       int map_y = vy / 8;
+                       int tile_y = vy % 8;
+                       for (int x=0; x<160; x++)
                        {
-                               u16 tile_map_addr  = check_bit(LCDC,3) ? 0x1C00  : 0x1800;
-                               u16 tile_data_addr = check_bit(LCDC,4) ? 0x0000 : 0x0800;
-                               int tile_data_base = (tile_data_addr == 0x0800) ? -128 : 0;
+                               int vx = (x+SCX) % 256;
+                               int map_x = vx/8;
+                               
+                               if (LY == 0)
+                                       logger.trace("(",map_x, ",", map_y, ")");
 
-                               // (vx    , vy    ) -> position of the pixel in the 256x256 bg
-                               // (map_x , map_y ) -> map coordinates of the current tile
-                               // (tile_x, tile_y) -> position of the pixel in the tile
-                               int SCX = core->memory.read(GBIO::SCX);
-                               int SCY = core->memory.read(GBIO::SCY);
-                               int vy = (LY + SCY) % 256;
-                               int map_y = vy / 8;
-                               int tile_y = vy % 8;
-                               for (int x=0; x<160; x++)
-                               {
-                                       int vx = (x+SCX) % 256;
-                                       int map_x = vx/8;
-                                       int tile_x = 7-(vx%8);
-                                       u8 current_tile_index = VRAM[tile_map_addr+ 32*map_y + map_x] + tile_data_base;
-                                       u16 current_tile_addr = tile_data_addr + 16*current_tile_index;
-                                       u8 current_row_low = VRAM[current_tile_addr+2*tile_y];
-                                       u8 current_row_high = VRAM[current_tile_addr+2*tile_y+1];
-                                       u32 color = colors[pallette[((current_row_high >> tile_x)&1) << 1 | 
-                                                               ((current_row_low >> tile_x)&1)]];
+                               int tile_x = 7-(vx%8);
+                               u8 current_tile_index = VRAM[tile_map_addr+ 32*map_y + map_x] + tile_data_base;
+                               u16 current_tile_addr = tile_data_addr + 16*current_tile_index;
+                               u8 current_row_low = VRAM[current_tile_addr+2*tile_y];
+                               u8 current_row_high = VRAM[current_tile_addr+2*tile_y+1];
+                               u32 color = colors[pallette[((current_row_high >> tile_x)&1) << 1 | 
+                                                       ((current_row_low >> tile_x)&1)]];
 
-                                       pixels[2*(LY*pixels_per_line+x)] = color;
-                                       pixels[2*(LY*pixels_per_line+x)+1] = color;
-                                       pixels[2*(LY*pixels_per_line+x)+320] = color;
-                                       pixels[2*(LY*pixels_per_line+x)+321] = color;
-                               }
+                               pixels[2*(LY*pixels_per_line+x)] = color;
+                               pixels[2*(LY*pixels_per_line+x)+1] = color;
+                               pixels[2*(LY*pixels_per_line+x)+320] = color;
+                               pixels[2*(LY*pixels_per_line+x)+321] = color;
                        }
-                       else
+               }
+               else
+               {
+                       for (int x=0; x<160; x++)
                        {
-                               for (int x=0; x<160; x++)
-                               {
-                                       pixels[2*(LY*pixels_per_line+x)] = colors[0];
-                                       pixels[2*(LY*pixels_per_line+x)+1] = colors[0];
-                                       pixels[2*(LY*pixels_per_line+x)+320] = colors[0];
-                                       pixels[2*(LY*pixels_per_line+x)+321] = colors[0];
-                               }
+                               pixels[2*(LY*pixels_per_line+x)] = colors[0];
+                               pixels[2*(LY*pixels_per_line+x)+1] = colors[0];
+                               pixels[2*(LY*pixels_per_line+x)+320] = colors[0];
+                               pixels[2*(LY*pixels_per_line+x)+321] = colors[0];
                        }
                }
        }
        else if (display_mode == BG_MAP)
        {
-               if (hline_t == 80)
+               int BGP  = core->memory.IO.ports[GBIO::I_BGP];
+               int pallette[4];
+               pallette[0] = BGP & 3;
+               pallette[1] = (BGP>>2) & 3;
+               pallette[2] = (BGP>>4) & 3;
+               pallette[3] = (BGP>>6) & 3;
+               u16 tile_map_addr  = check_bit(LCDC,3) ? 0x1C00  : 0x1800;
+               u16 tile_data_addr = check_bit(LCDC,4) ? 0x0000 : 0x0800;
+               int tile_data_base = (tile_data_addr == 0x0800) ? -128 : 0;
+               for (int row=0; row < 32; row++)
                {
-                       int BGP  = core->memory.read(GBIO::BGP);
-                       int pallette[4];
-                       pallette[0] = BGP & 3;
-                       pallette[1] = (BGP>>2) & 3;
-                       pallette[2] = (BGP>>4) & 3;
-                       pallette[3] = (BGP>>6) & 3;
-                       u16 tile_map_addr  = check_bit(LCDC,3) ? 0x1C00  : 0x1800;
-                       u16 tile_data_addr = check_bit(LCDC,4) ? 0x0000 : 0x0800;
-                       int tile_data_base = (tile_data_addr == 0x0800) ? -128 : 0;
-                       for (int row=0; row < 32; row++)
+                       for (int col=0; col < 32; col++)
                        {
-                               for (int col=0; col < 32; col++)
+                               int ty = row*8;
+                               int tx = col*8;
+                               for (int y=0; y<8; y++)
                                {
-                                       int ty = row*8;
-                                       int tx = col*8;
-                                       for (int y=0; y<8; y++)
+                                       for (int x=0; x<8; x++)
                                        {
-                                               for (int x=0; x<8; x++)
-                                               {
-                                                       u8 tile_x = 7-x;
-                                                       u8 current_tile_index = VRAM[tile_map_addr+32*row + col] + tile_data_base;
-                                                       u16 current_tile_addr = tile_data_addr + 16*current_tile_index;
-                                                       u8 current_row_low = VRAM[current_tile_addr+2*y];
-                                                       u8 current_row_high = VRAM[current_tile_addr+2*y+1];
-                                                       u32 color = colors[pallette[((current_row_high >> tile_x)&1) << 1 | 
-                                                                               ((current_row_low >> tile_x)&1)]];
-                                                       pixels[320*(ty+y)+(tx+x)] = color;
-                                               }
+                                               u8 tile_x = 7-x;
+                                               u8 current_tile_index = VRAM[tile_map_addr+32*row + col] + tile_data_base;
+                                               u16 current_tile_addr = tile_data_addr + 16*current_tile_index;
+                                               u8 current_row_low = VRAM[current_tile_addr+2*y];
+                                               u8 current_row_high = VRAM[current_tile_addr+2*y+1];
+                                               u32 color = colors[pallette[((current_row_high >> tile_x)&1) << 1 | 
+                                                                       ((current_row_low >> tile_x)&1)]];
+                                               pixels[320*(ty+y)+(tx+x)] = color;
                                        }
                                }
                        }
@@ -257,7 +283,6 @@ void GBVideo::update()
        }
 }
 
-
 int GBVideo::poll_event(SDL_Event *ev)
 {
        return SDL_PollEvent(ev);
index 16c21f10ded45d897744cb5cb8afbc9fd752b39a..8d2ef2c55f8333e35477e30c5754ed4ec5469f54 100644 (file)
--- a/GBVideo.h
+++ b/GBVideo.h
@@ -17,6 +17,9 @@ class GBVideo
        u32 colors[4];
        u32 frames_rendered;
 
+       int cycles_until_next_update;
+       int mode;
+
        public:
        enum DisplayMode {
                NORMAL = 0,
@@ -41,6 +44,7 @@ class GBVideo
        void write_OAM (int addr, u8 value);
 
        // drawing control
+       void draw();
        void update();
        void set_display_mode(DisplayMode mode) { display_mode = mode; }
 
index f135bf6ab7ee3d2199028d2a01c4cd64ae48ec88..e806ffee27f7f14b8d7f495e064b36d48d0898f0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-CXXFLAGS=-O2 -g -Wall -Weffc++ -Wstrict-null-sentinel -Wold-style-cast \
+CXXFLAGS=-O3 -g -Wall -Weffc++ -Wstrict-null-sentinel -Wold-style-cast \
         -Woverloaded-virtual $(shell sdl-config --cflags)
 LDFLAGS=-g $(shell sdl-config --libs)
 
index 91ec927234bd4bccffb599dcb21c1f0afe882c76..bfa4fe9f033d9d986e9ef2c1d5d9a31b6315df1d 100644 (file)
--- a/gbcore.cc
+++ b/gbcore.cc
@@ -1095,11 +1095,11 @@ GameBoy::run_status GameBoy::run_cycle()
        video.update();
 
        // Check for interrupts before opcode fetching
-       u8 IE=memory.read(0xFFFF);
+       u8 IE=memory.IE;
        //logger.trace("IME=", int(IME), " IE=", int(IE));
        if (IME && IE)
        {
-               u8 IF = memory.read(0xFF0F);
+               u8 IF = memory.IO.ports[GBIO::I_IF];
                //logger.trace("Dispatching interrupts: IE=", int(IE), " IF=", int(IF));
                if (IF)
                {
@@ -1139,7 +1139,7 @@ GameBoy::run_status GameBoy::run_cycle()
                                logger.trace("JOYPAD IRQ");
                        }
                }
-               memory.write(0xFF0F, IF);
+               memory.IO.ports[GBIO::I_IF] = IF;
        }