File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -541,7 +541,21 @@ static void tick_square_envelope(GB_gameboy_t *gb, GB_channel_t index)
541541 gb -> apu .pcm_mask [0 ] &= gb -> apu .square_channels [GB_SQUARE_1 ].current_volume | 0xF1 ;
542542 }
543543 else {
544- gb -> apu .pcm_mask [0 ] &= (gb -> apu .square_channels [GB_SQUARE_2 ].current_volume << 4 ) | (gb -> model == GB_MODEL_CGB_0 ? 0x3F : 0x1F );
544+ /* Note: CGB-0 behavior is instance specific and non-deterministic. Emulated behavior follows my CGB-0,
545+ except that my CGB-0 sometimes yields "1" for 8->7 and 4->3 transitions. */
546+ uint8_t mask ;
547+ if (unlikely (gb -> model == GB_MODEL_CGB_0 )) {
548+ if (gb -> apu .square_channels [GB_SQUARE_2 ].current_volume == 1 && (gb -> io_registers [GB_IO_NR22 ] & 8 )) {
549+ mask = 0x1F ;
550+ }
551+ else {
552+ mask = 0x3F ;
553+ }
554+ }
555+ else {
556+ mask = 0x3F ;
557+ }
558+ gb -> apu .pcm_mask [0 ] &= (gb -> apu .square_channels [GB_SQUARE_2 ].current_volume << 4 ) | mask ;
545559 }
546560 }
547561
You can’t perform that action at this time.
0 commit comments