Skip to content

Commit

Permalink
Various optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
LIJI32 committed Nov 22, 2024
1 parent 7e071e4 commit a0c5b6f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Core/apu.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ static void render(GB_gameboy_t *gb)
if (gb->sgb && gb->sgb->intro_animation < GB_SGB_INTRO_ANIMATION_LENGTH) return;

GB_sample_t filtered_output = gb->apu_output.highpass_mode?
(GB_sample_t) {output.left - gb->apu_output.highpass_diff.left,
output.right - gb->apu_output.highpass_diff.right} :
(GB_sample_t) {output.left - (int16_t)gb->apu_output.highpass_diff.left,
output.right - (int16_t)gb->apu_output.highpass_diff.right} :
output;

switch (gb->apu_output.highpass_mode) {
Expand Down
9 changes: 6 additions & 3 deletions Core/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ static void add_object_from_index(GB_gameboy_t *gb, unsigned index)
gb->mode2_x_bus = oam_read(gb, index * 4 + 1);
}

if (gb->n_visible_objs == 10) return;
if (unlikely(gb->n_visible_objs == 10)) return;

/* TODO: It appears that DMA blocks PPU access to OAM, but it needs verification. */
if (unlikely(GB_is_dma_active(gb) && (gb->halted || gb->stopped))) {
Expand Down Expand Up @@ -1903,8 +1903,11 @@ void GB_display_run(GB_gameboy_t *gb, unsigned cycles, bool force)
}
}

if ((!GB_is_cgb(gb) || gb->io_registers[GB_IO_WX] == 0) && gb->wx_triggered && !gb->window_is_being_fetched &&
gb->fetcher_state == GB_FETCHER_GET_TILE_T1 && gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 7) && gb->bg_fifo.size == 8) {
if (unlikely(gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 7) &&
(!GB_is_cgb(gb) || gb->io_registers[GB_IO_WX] == 0) &&
gb->wx_triggered && !gb->window_is_being_fetched &&
gb->fetcher_state == GB_FETCHER_GET_TILE_T1 &&
gb->bg_fifo.size == 8)) {
// Insert a pixel right at the FIFO's end
gb->insert_bg_pixel = true;
}
Expand Down
4 changes: 4 additions & 0 deletions Core/save_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,10 @@ static void sanitize_state(GB_gameboy_t *gb)
gb->apu.apu_cycles >>= 2;
gb->apu.apu_cycles_in_2mhz = true;
}

if (gb->n_visible_objs > 10) {
gb->n_visible_objs = 10;
}
}

static bool dump_section(virtual_file_t *file, const void *src, uint32_t size)
Expand Down
8 changes: 4 additions & 4 deletions Core/timing.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,22 +226,22 @@ void GB_set_internal_div_counter(GB_gameboy_t *gb, uint16_t value)
{
/* TIMA increases when a specific high-bit becomes a low-bit. */
uint16_t triggers = gb->div_counter & ~value;
if ((gb->io_registers[GB_IO_TAC] & 4) && (triggers & TAC_TRIGGER_BITS[gb->io_registers[GB_IO_TAC] & 3])) {
if ((gb->io_registers[GB_IO_TAC] & 4) && unlikely(triggers & TAC_TRIGGER_BITS[gb->io_registers[GB_IO_TAC] & 3])) {
increase_tima(gb);
}

if (triggers & gb->serial_mask) {
if (unlikely(triggers & gb->serial_mask)) {
GB_serial_master_edge(gb);
}

/* TODO: Can switching to double speed mode trigger an event? */
uint16_t apu_bit = gb->cgb_double_speed? 0x2000 : 0x1000;
if (triggers & apu_bit) {
if (unlikely(triggers & apu_bit)) {
GB_apu_div_event(gb);
}
else {
uint16_t secondary_triggers = ~gb->div_counter & value;
if (secondary_triggers & apu_bit) {
if (unlikely(secondary_triggers & apu_bit)) {
GB_apu_div_secondary_event(gb);
}
}
Expand Down

0 comments on commit a0c5b6f

Please sign in to comment.