git.y1.nz

SameBoy

Accurate GB/GBC emulator
download: https://git.y1.nz/archives/sameboy.tar.gz
README | Files | Log | Refs | LICENSE

commit 5c17c0ec3bc5dc1456628158f55d1d38284d56f1
parent cd16431699efd159a36557322d550b42e2786ad9
Author: Lior Halphon <LIJI32@gmail.com>
Date:   Mon,  3 Jan 2022 17:17:35 +0200

unreachable fun

Diffstat:
MCore/apu.c7++++++-
MCore/defs.h3+++
MCore/display.c2++
MCore/joypad.c4+---
MCore/mbc.c2++
MCore/memory.c9+++++----
MCore/sm83_cpu.c2+-
7 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/Core/apu.c b/Core/apu.c @@ -40,6 +40,8 @@ bool GB_apu_is_DAC_enabled(GB_gameboy_t *gb, unsigned index) case GB_NOISE: return gb->io_registers[GB_IO_NR42] & 0xF8; + + nodefault; } return false; @@ -58,6 +60,8 @@ static uint8_t agb_bias_for_channel(GB_gameboy_t *gb, unsigned index) return 0; case GB_NOISE: return gb->apu.noise_channel.current_volume; + + nodefault; } return 0; } @@ -257,7 +261,8 @@ static void render(GB_gameboy_t *gb) {left_volume * (1 - gb->apu_output.highpass_rate) + gb->apu_output.highpass_diff.left * gb->apu_output.highpass_rate, right_volume * (1 - gb->apu_output.highpass_rate) + gb->apu_output.highpass_diff.right * gb->apu_output.highpass_rate}; - case GB_HIGHPASS_MAX:; + case GB_HIGHPASS_MAX: + nodefault; } } diff --git a/Core/defs.h b/Core/defs.h @@ -17,6 +17,9 @@ #define unrolled #endif +#define unreachable() __builtin_unreachable(); +#define nodefault default: unreachable() + #ifdef GB_BIG_ENDIAN #define LE16(x) __builtin_bswap16(x) #define LE32(x) __builtin_bswap32(x) diff --git a/Core/display.c b/Core/display.c @@ -834,6 +834,8 @@ static void advance_fetcher_state_machine(GB_gameboy_t *gb) gb->fetcher_state++; } break; + + nodefault; } } diff --git a/Core/joypad.c b/Core/joypad.c @@ -53,9 +53,7 @@ void GB_update_joyp(GB_gameboy_t *gb) } break; - default: - __builtin_unreachable(); - break; + nodefault; } /* Todo: This assumes the keys *always* bounce, which is incorrect when emulating an SGB */ diff --git a/Core/mbc.c b/Core/mbc.c @@ -77,6 +77,7 @@ void GB_update_mbc_mappings(GB_gameboy_t *gb) gb->mbc_rom_bank++; } break; + nodefault; } break; case GB_MBC2: @@ -121,6 +122,7 @@ void GB_update_mbc_mappings(GB_gameboy_t *gb) gb->mbc_ram_bank = gb->tpp1.ram_bank; gb->mbc_ram_enable = (gb->tpp1.mode == 2) || (gb->tpp1.mode == 3); break; + nodefault; } } diff --git a/Core/memory.c b/Core/memory.c @@ -360,6 +360,7 @@ static uint8_t read_mbc_ram(GB_gameboy_t *gb, uint16_t addr) case 1: return gb->tpp1.rom_bank >> 8; case 2: return gb->tpp1.ram_bank; case 3: return gb->rumble_strength | gb->tpp1_mr4; + nodefault; } case 2: case 3: @@ -533,8 +534,7 @@ static uint8_t read_high_memory(GB_gameboy_t *gb, uint16_t addr) oam[target >> 1] = bitwise_glitch_read(a, b, c); break; - default: - __builtin_unreachable(); + nodefault; } for (unsigned i = 0; i < 8; i++) { @@ -706,7 +706,7 @@ static uint8_t read_high_memory(GB_gameboy_t *gb, uint16_t addr) } return 0xFF; } - __builtin_unreachable(); + unreachable(); } if (addr == 0xFFFF) { @@ -899,6 +899,7 @@ static void write_mbc(GB_gameboy_t *gb, uint16_t addr, uint8_t value) } } break; + nodefault; } GB_update_mbc_mappings(gb); } @@ -1243,7 +1244,7 @@ static void write_high_memory(GB_gameboy_t *gb, uint16_t addr, uint8_t value) case GB_MODEL_SGB_PAL_NO_SFC: case GB_MODEL_SGB2: case GB_MODEL_SGB2_NO_SFC: - __builtin_unreachable(); + unreachable(); } return; } diff --git a/Core/sm83_cpu.c b/Core/sm83_cpu.c @@ -658,8 +658,8 @@ static bool condition_code(GB_gameboy_t *gb, uint8_t opcode) return !(gb->af & GB_CARRY_FLAG); case 3: return (gb->af & GB_CARRY_FLAG); + nodefault; } - __builtin_unreachable(); return false; }

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.