peanut_gb.h
/**
 * Internal function used to read bytes.
 */
Internal function used to read bytes.
Internal function used to read bytes .
uint8_t __gb_read(struct gb_s *gb, const uint_fast16_t addr){
    switch(addr >> 12){
    case 0x0:
    case 0x1:
    case 0x2:
    case 0x3:
    	return gb->rom[addr];
	case 0x4:
	case 0x5:
	case 0x6:
	case 0x7:
    	return gb->rom[addr + ((gb->selected_rom_bank - 1) << 14)];
    case 0x8:
    case 0x9:
        return 0;
    case 0xA:
    case 0xB:
        return gb->sram[addr - gb->cart_ram_bank_offset];
    case 0xC:
    case 0xD:
        return gb->wram[addr - WRAM_0_ADDR];
    case 0xE:
        return gb->wram[addr - ECHO_ADDR];
    case 0xF:
        if(addr < OAM_ADDR)
            return gb->wram[addr - ECHO_ADDR];
        if(addr < IO_ADDR)
            return 0xFF;
        if(HRAM_ADDR <= addr && addr < INTR_EN_ADDR)
            return gb->hram[addr - IO_ADDR];
        if((addr >= 0xFF10) && (addr <= 0xFF3F)){
            return gb->hram[addr - IO_ADDR] & APU_READ_MASK[addr - IO_ADDR];
        }
        switch(addr & 0xFF){
        case 0x00:
            return 0xC0 | gb->gb_reg.P1;
        case 0x01:
            return gb->gb_reg.SB;
        case 0x02:
            return gb->gb_reg.SC;
        case 0x04:
            return gb->gb_reg.DIV;
        case 0x05:
            return gb->gb_reg.TIMA;
        case 0x06:
            return gb->gb_reg.TMA;
        case 0x07:
            return gb->gb_reg.TAC;
        case 0x0F:
            return gb->gb_reg.IF;
        case 0x40:
            return gb->gb_reg.LCDC;
        case 0x41:
            return (gb->gb_reg.STAT & STAT_USER_BITS) |
                   (gb->gb_reg.LCDC & LCDC_ENABLE ? gb->lcd_mode : LCD_VBLANK);
        case 0x42:
            return gb->gb_reg.SCY;
        case 0x43:
            return gb->gb_reg.SCX;
        case 0x44:
            return gb->gb_reg.LY;
        case 0x45:
            return gb->gb_reg.LYC;
        case 0x46:
            return gb->gb_reg.DMA;
        case 0x47:
            return gb->gb_reg.BGP;
        case 0x48:
            return gb->gb_reg.OBP0;
        case 0x49:
            return gb->gb_reg.OBP1;
        case 0x4A:
            return gb->gb_reg.WY;
    case 0x4B:
      return gb->gb_reg.WX;
        case 0xFF:
            return gb->gb_reg.IE;
        default:
            return 0xFF;
        }
    }
    return 0xFF;
}
uint8_t __gb_read ( struct gb_s * gb , const uint_fast16_t addr ) { switch ( addr >> 12 ) { case 0x0 : case 0x1 : case 0x2 : case 0x3 : return gb -> rom [ addr ] ; case 0x4 : case 0x5 : case 0x6 : case 0x7 : return gb -> rom [ addr + ( ( gb -> selected_rom_bank - 1 ) << 14 ) ] ; case 0x8 : case 0x9 : return 0 ; case 0xA : case 0xB : return gb -> sram [ addr - gb -> cart_ram_bank_offset ] ; case 0xC : case 0xD : return gb -> wram [ addr - WRAM_0_ADDR ] ; case 0xE : return gb -> wram [ addr - ECHO_ADDR ] ; case 0xF : if ( addr < OAM_ADDR ) return gb -> wram [ addr - ECHO_ADDR ] ; if ( addr < IO_ADDR ) return 0xFF ; if ( HRAM_ADDR <= addr && addr < INTR_EN_ADDR ) return gb -> hram [ addr - IO_ADDR ] ; if ( ( addr >= 0xFF10 ) && ( addr <= 0xFF3F ) ) { return gb -> hram [ addr - IO_ADDR ] & APU_READ_MASK [ addr - IO_ADDR ] ; } switch ( addr & 0xFF ) { case 0x00 : return 0xC0 | gb -> gb_reg . P1 ; case 0x01 : return gb -> gb_reg . SB ; case 0x02 : return gb -> gb_reg . SC ; case 0x04 : return gb -> gb_reg . DIV ; case 0x05 : return gb -> gb_reg . TIMA ; case 0x06 : return gb -> gb_reg . TMA ; case 0x07 : return gb -> gb_reg . TAC ; case 0x0F : return gb -> gb_reg . IF ; case 0x40 : return gb -> gb_reg . LCDC ; case 0x41 : return ( gb -> gb_reg . STAT & STAT_USER_BITS ) | ( gb -> gb_reg . LCDC & LCDC_ENABLE ? gb -> lcd_mode : LCD_VBLANK ) ; case 0x42 : return gb -> gb_reg . SCY ; case 0x43 : return gb -> gb_reg . SCX ; case 0x44 : return gb -> gb_reg . LY ; case 0x45 : return gb -> gb_reg . LYC ; case 0x46 : return gb -> gb_reg . DMA ; case 0x47 : return gb -> gb_reg . BGP ; case 0x48 : return gb -> gb_reg . OBP0 ; case 0x49 : return gb -> gb_reg . OBP1 ; case 0x4A : return gb -> gb_reg . WY ; case 0x4B : return gb -> gb_reg . WX ; case 0xFF : return gb -> gb_reg . IE ; default : return 0xFF ; } } return 0xFF ; }
Internal function used to read bytes.
Internal function used to read bytes .
/* Unusable memory area */ /* HRAM */ /* IO and Interrupts. */ /* IO Registers */ /* Timer Registers */ /* Interrupt Flag Register */ /* LCD Registers */ /* DMA Register */ /* DMG Palette Registers */ /* Window Position Registers */ /* Interrupt Enable Register */ /* Unused registers return 1 */