Merge branch 'master' into rateless_apu
This commit is contained in:
commit
258500bda3
@ -144,31 +144,29 @@ static uint32_t get_pixel(GB_gameboy_t *gb, uint8_t x, uint8_t y)
|
|||||||
return gb->sprite_palletes_rgb[sprite_palette * 4 + sprite_pixel];
|
return gb->sprite_palletes_rgb[sprite_palette * 4 + sprite_pixel];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bg_enabled) {
|
if (bg_enabled) {
|
||||||
return gb->background_palletes_rgb[0];
|
if (gb->io_registers[GB_IO_LCDC] & 0x10) {
|
||||||
}
|
tile_address = tile * 0x10;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
tile_address = (int8_t) tile * 0x10 + 0x1000;
|
||||||
|
}
|
||||||
|
if (attributes & 0x8) {
|
||||||
|
tile_address += 0x2000;
|
||||||
|
}
|
||||||
|
|
||||||
if (gb->io_registers[GB_IO_LCDC] & 0x10) {
|
if (attributes & 0x20) {
|
||||||
tile_address = tile * 0x10;
|
x = ~x;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
tile_address = (int8_t) tile * 0x10 + 0x1000;
|
|
||||||
}
|
|
||||||
if (attributes & 0x8) {
|
|
||||||
tile_address += 0x2000;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (attributes & 0x20) {
|
if (attributes & 0x40) {
|
||||||
x = ~x;
|
y = ~y;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attributes & 0x40) {
|
background_pixel = (((gb->vram[tile_address + (y & 7) * 2 ] >> ((~x)&7)) & 1 ) |
|
||||||
y = ~y;
|
((gb->vram[tile_address + (y & 7) * 2 + 1] >> ((~x)&7)) & 1) << 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
background_pixel = (((gb->vram[tile_address + (y & 7) * 2 ] >> ((~x)&7)) & 1 ) |
|
|
||||||
((gb->vram[tile_address + (y & 7) * 2 + 1] >> ((~x)&7)) & 1) << 1 );
|
|
||||||
|
|
||||||
if (priority && sprite_pixel && !background_pixel) {
|
if (priority && sprite_pixel && !background_pixel) {
|
||||||
if (!gb->cgb_mode) {
|
if (!gb->cgb_mode) {
|
||||||
sprite_pixel = (gb->io_registers[use_obp1? GB_IO_OBP1:GB_IO_OBP0] >> (sprite_pixel << 1)) & 3;
|
sprite_pixel = (gb->io_registers[use_obp1? GB_IO_OBP1:GB_IO_OBP0] >> (sprite_pixel << 1)) & 3;
|
||||||
|
@ -226,6 +226,7 @@ typedef struct GB_gameboy_s {
|
|||||||
bool stopped;
|
bool stopped;
|
||||||
bool boot_rom_finished;
|
bool boot_rom_finished;
|
||||||
bool ime_toggle; /* ei (and di in CGB) have delayed effects.*/
|
bool ime_toggle; /* ei (and di in CGB) have delayed effects.*/
|
||||||
|
bool halt_bug;
|
||||||
|
|
||||||
/* Misc state*/
|
/* Misc state*/
|
||||||
/* IR */
|
/* IR */
|
||||||
|
@ -22,6 +22,13 @@ void GB_update_joyp(GB_gameboy_t *gb)
|
|||||||
for (uint8_t i = 0; i < 4; i++) {
|
for (uint8_t i = 0; i < 4; i++) {
|
||||||
gb->io_registers[GB_IO_JOYP] |= (!gb->keys[i]) << i;
|
gb->io_registers[GB_IO_JOYP] |= (!gb->keys[i]) << i;
|
||||||
}
|
}
|
||||||
|
/* Forbid pressing two opposing keys, this breaks a lot of games; even if it's somewhat possible. */
|
||||||
|
if (!(gb->io_registers[GB_IO_JOYP] & 1)) {
|
||||||
|
gb->io_registers[GB_IO_JOYP] |= 2;
|
||||||
|
}
|
||||||
|
if (!(gb->io_registers[GB_IO_JOYP] & 4)) {
|
||||||
|
gb->io_registers[GB_IO_JOYP] |= 8;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -74,7 +74,7 @@ static uint8_t read_vram(GB_gameboy_t *gb, uint16_t addr)
|
|||||||
|
|
||||||
static uint8_t read_mbc_ram(GB_gameboy_t *gb, uint16_t addr)
|
static uint8_t read_mbc_ram(GB_gameboy_t *gb, uint16_t addr)
|
||||||
{
|
{
|
||||||
if (!gb->mbc_ram_enable) return 0xFF;
|
if (!gb->mbc_ram_enable || !gb->mbc_ram_size) return 0xFF;
|
||||||
|
|
||||||
if (gb->cartridge_type->has_rtc && gb->mbc_ram_bank >= 8 && gb->mbc_ram_bank <= 0xC) {
|
if (gb->cartridge_type->has_rtc && gb->mbc_ram_bank >= 8 && gb->mbc_ram_bank <= 0xC) {
|
||||||
/* RTC read */
|
/* RTC read */
|
||||||
@ -319,7 +319,7 @@ static void write_vram(GB_gameboy_t *gb, uint16_t addr, uint8_t value)
|
|||||||
|
|
||||||
static void write_mbc_ram(GB_gameboy_t *gb, uint16_t addr, uint8_t value)
|
static void write_mbc_ram(GB_gameboy_t *gb, uint16_t addr, uint8_t value)
|
||||||
{
|
{
|
||||||
if (!gb->mbc_ram_enable) return;
|
if (!gb->mbc_ram_enable || !gb->mbc_ram_size) return;
|
||||||
|
|
||||||
if (gb->cartridge_type->has_rtc && gb->mbc_ram_bank >= 8 && gb->mbc_ram_bank <= 0xC) {
|
if (gb->cartridge_type->has_rtc && gb->mbc_ram_bank >= 8 && gb->mbc_ram_bank <= 0xC) {
|
||||||
/* RTC read */
|
/* RTC read */
|
||||||
|
@ -684,6 +684,11 @@ static void halt(GB_gameboy_t *gb, uint8_t opcode)
|
|||||||
{
|
{
|
||||||
GB_advance_cycles(gb, 4);
|
GB_advance_cycles(gb, 4);
|
||||||
gb->halted = true;
|
gb->halted = true;
|
||||||
|
/* Despite what some online documentations say, the HALT bug also happens on a CGB, in both CGB and DMG modes. */
|
||||||
|
if (!gb->ime && (gb->interrupt_enable & gb->io_registers[GB_IO_IF] & 0x1F) != 0) {
|
||||||
|
gb->halted = false;
|
||||||
|
gb->halt_bug = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ret_cc(GB_gameboy_t *gb, uint8_t opcode)
|
static void ret_cc(GB_gameboy_t *gb, uint8_t opcode)
|
||||||
@ -1332,12 +1337,9 @@ static GB_opcode_t *opcodes[256] = {
|
|||||||
void GB_cpu_run(GB_gameboy_t *gb)
|
void GB_cpu_run(GB_gameboy_t *gb)
|
||||||
{
|
{
|
||||||
gb->vblank_just_occured = false;
|
gb->vblank_just_occured = false;
|
||||||
bool interrupt = gb->interrupt_enable & gb->io_registers[GB_IO_IF];
|
bool interrupt = gb->interrupt_enable & gb->io_registers[GB_IO_IF] & 0x1F;
|
||||||
bool halt_bug = false;
|
|
||||||
|
|
||||||
if (interrupt) {
|
if (interrupt) {
|
||||||
/* Despite what some online documentations say, the HALT bug also happens on a CGB, in both CGB and DMG modes. */
|
|
||||||
halt_bug = gb->halted;
|
|
||||||
gb->halted = false;
|
gb->halted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1354,7 +1356,7 @@ void GB_cpu_run(GB_gameboy_t *gb)
|
|||||||
|
|
||||||
if (effecitve_ime && interrupt) {
|
if (effecitve_ime && interrupt) {
|
||||||
uint8_t interrupt_bit = 0;
|
uint8_t interrupt_bit = 0;
|
||||||
uint8_t interrupt_queue = gb->interrupt_enable & gb->io_registers[GB_IO_IF];
|
uint8_t interrupt_queue = gb->interrupt_enable & gb->io_registers[GB_IO_IF] & 0x1F;
|
||||||
while (!(interrupt_queue & 1)) {
|
while (!(interrupt_queue & 1)) {
|
||||||
interrupt_queue >>= 1;
|
interrupt_queue >>= 1;
|
||||||
interrupt_bit++;
|
interrupt_bit++;
|
||||||
@ -1367,8 +1369,9 @@ void GB_cpu_run(GB_gameboy_t *gb)
|
|||||||
}
|
}
|
||||||
else if(!gb->halted && !gb->stopped) {
|
else if(!gb->halted && !gb->stopped) {
|
||||||
uint8_t opcode = GB_read_memory(gb, gb->pc++);
|
uint8_t opcode = GB_read_memory(gb, gb->pc++);
|
||||||
if (halt_bug) {
|
if (gb->halt_bug) {
|
||||||
gb->pc--;
|
gb->pc--;
|
||||||
|
gb->halt_bug = false;
|
||||||
}
|
}
|
||||||
opcodes[opcode](gb, opcode);
|
opcodes[opcode](gb, opcode);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user