| 1 |
|
| #include "rumble.h" |
| 2 |
|
| #include "gb.h" |
| 3 |
|
| |
| 4 |
0 |
| void GB_set_rumble_mode(GB_gameboy_t *gb, GB_rumble_mode_t mode) |
| 5 |
|
| { |
| 6 |
0 |
| gb->rumble_mode = mode; |
| 7 |
0 |
▶ | if (gb->rumble_callback) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (gb->rumble_callback) { |
0 |
0 |
0 |
|
| 8 |
0 |
| gb->rumble_callback(gb, 0); |
| 9 |
|
| } |
| 10 |
0 |
| } |
| 11 |
|
| |
| 12 |
291 |
| void GB_handle_rumble(GB_gameboy_t *gb) |
| 13 |
|
| { |
| 14 |
291 |
▶ | if (gb->rumble_callback) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (gb->rumble_callback) { |
0 |
291 |
291 |
|
| 15 |
0 |
▶ | if (gb->rumble_mode == GB_RUMBLE_DISABLED) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (gb->rumble_mode == GB_RUMBLE_DISABLED) { |
0 |
0 |
0 |
|
| 16 |
0 |
| return; |
| 17 |
|
| } |
| 18 |
0 |
▶ | if (gb->cartridge_type->has_rumble && |
Branch: 1 branch
| Branch | True | False | Total |
| if (gb->cartridge_type->has_rumble && |
0 |
0 |
0 |
|
| 19 |
0 |
▶ | (gb->cartridge_type->mbc_type != GB_TPP1 || (gb->rom[0x153] & 1))) { |
Branch: 2 branches
| Branch | True | False | Total |
| (gb->cartridge_type->mbc_type != GB_TPP1 || (gb->rom[0x153] & 1))) { |
0 |
0 |
0 |
| (gb->cartridge_type->mbc_type != GB_TPP1 || (gb->rom[0x153] & 1))) { |
0 |
0 |
0 |
|
| 20 |
0 |
▶ | if (gb->rumble_on_cycles + gb->rumble_off_cycles) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (gb->rumble_on_cycles + gb->rumble_off_cycles) { |
0 |
0 |
0 |
|
| 21 |
0 |
| gb->rumble_callback(gb, gb->rumble_on_cycles / (double)(gb->rumble_on_cycles + gb->rumble_off_cycles)); |
| 22 |
0 |
| gb->rumble_on_cycles = gb->rumble_off_cycles = 0; |
| 23 |
|
| } |
| 24 |
|
| } |
| 25 |
0 |
▶ | else if (gb->rumble_mode == GB_RUMBLE_ALL_GAMES) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (gb->rumble_mode == GB_RUMBLE_ALL_GAMES) { |
0 |
0 |
0 |
|
| 26 |
0 |
| unsigned volume = (gb->io_registers[GB_IO_NR50] & 7) + 1 + ((gb->io_registers[GB_IO_NR50] >> 4) & 7) + 1; |
| 27 |
0 |
| unsigned ch4_volume = volume * (!!(gb->io_registers[GB_IO_NR51] & 8) + !!(gb->io_registers[GB_IO_NR51] & 0x80)); |
| 28 |
0 |
| unsigned ch1_volume = volume * (!!(gb->io_registers[GB_IO_NR51] & 1) + !!(gb->io_registers[GB_IO_NR51] & 0x10)); |
| 29 |
0 |
| unsigned ch4_divisor = (gb->io_registers[GB_IO_NR43] & 0x07) << 1; |
| 30 |
0 |
▶ | if (!ch4_divisor) ch4_divisor = 1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!ch4_divisor) ch4_divisor = 1; |
0 |
0 |
0 |
|
| 31 |
0 |
| unsigned ch4_sample_length = (ch4_divisor << (gb->io_registers[GB_IO_NR43] >> 4)) - 1; |
| 32 |
|
| |
| 33 |
0 |
▶ | double ch4_rumble = (MIN(ch4_sample_length * (gb->apu.noise_channel.narrow? 8 : 1) , 4096) * ((signed) gb->apu.noise_channel.current_volume * gb->apu.noise_channel.current_volume * ch4_volume / 32.0 - 50) - 2048) / 2048.0; |
Branch: 1 branch
| Branch | True | False | Total |
| double ch4_rumble = (MIN(ch4_sample_length * (gb->apu.noise_channel.narrow? 8 : 1) , 4096) * ((signed) gb->apu.noise_channel.current_volume * gb->apu.noise_channel.current_volume * ch4_volume / 32.0 - 50) - 2048) / 2048.0; |
0 |
0 |
0 |
|
| 34 |
|
| |
| 35 |
0 |
▶ | ch4_rumble = MIN(ch4_rumble, 1.0); |
Branch: 1 branch
| Branch | True | False | Total |
| ch4_rumble = MIN(ch4_rumble, 1.0); |
0 |
0 |
0 |
|
| 36 |
0 |
▶ | ch4_rumble = MAX(ch4_rumble, 0.0); |
Branch: 1 branch
| Branch | True | False | Total |
| ch4_rumble = MAX(ch4_rumble, 0.0); |
0 |
0 |
0 |
|
| 37 |
|
| |
| 38 |
0 |
| double ch1_rumble = 0; |
| 39 |
0 |
▶ | if ((gb->io_registers[GB_IO_NR10] & 0x7) && (gb->io_registers[GB_IO_NR10] & 0x70)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ((gb->io_registers[GB_IO_NR10] & 0x7) && (gb->io_registers[GB_IO_NR10] & 0x70)) { |
0 |
0 |
0 |
| if ((gb->io_registers[GB_IO_NR10] & 0x7) && (gb->io_registers[GB_IO_NR10] & 0x70)) { |
0 |
0 |
0 |
|
| 40 |
0 |
| double sweep_speed = (gb->io_registers[GB_IO_NR10] & 7) / (double)((gb->io_registers[GB_IO_NR10] >> 4) & 7); |
| 41 |
0 |
| ch1_rumble = gb->apu.square_channels[GB_SQUARE_1].current_volume * ch1_volume / 32.0 * sweep_speed / 8.0 - 0.5; |
| 42 |
0 |
▶ | ch1_rumble = MIN(ch1_rumble, 1.0); |
Branch: 1 branch
| Branch | True | False | Total |
| ch1_rumble = MIN(ch1_rumble, 1.0); |
0 |
0 |
0 |
|
| 43 |
0 |
▶ | ch1_rumble = MAX(ch1_rumble, 0.0); |
Branch: 1 branch
| Branch | True | False | Total |
| ch1_rumble = MAX(ch1_rumble, 0.0); |
0 |
0 |
0 |
|
| 44 |
|
| } |
| 45 |
|
| |
| 46 |
0 |
▶ | if (!gb->apu.is_active[GB_NOISE]) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!gb->apu.is_active[GB_NOISE]) { |
0 |
0 |
0 |
|
| 47 |
0 |
| ch4_rumble = 0; |
| 48 |
|
| } |
| 49 |
|
| |
| 50 |
0 |
▶ | if (!gb->apu.is_active[GB_SQUARE_1]) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!gb->apu.is_active[GB_SQUARE_1]) { |
0 |
0 |
0 |
|
| 51 |
0 |
| ch1_rumble = 0; |
| 52 |
|
| } |
| 53 |
|
| |
| 54 |
0 |
▶ | gb->rumble_callback(gb, MIN(MAX(ch1_rumble / 2 + ch4_rumble, 0.0), 1.0)); |
Branch: 2 branches
| Branch | True | False | Total |
| gb->rumble_callback(gb, MIN(MAX(ch1_rumble / 2 + ch4_rumble, 0.0), 1.0)); |
0 |
0 |
0 |
| gb->rumble_callback(gb, MIN(MAX(ch1_rumble / 2 + ch4_rumble, 0.0), 1.0)); |
0 |
0 |
0 |
|
| 55 |
|
| } |
| 56 |
|
| } |
| 57 |
|
| } |