# SPDX-License-Identifier: MIT """PCM unit tests. The behaviour is OBSERVED (MAME rf5c68.cpp, ares pcm.cpp); Sega's PCM manual (a scan) has not been read for these yet.""" from __future__ import annotations from segacd_python.pcm import PCM def test_sign_magnitude_and_loop() -> None: pcm = PCM() pcm.ram[0x0000] = 0x81 # +1 pcm.ram[0x0001] = 0x01 # -1 pcm.ram[0x0002] = 0xFF # loop marker pcm.write(7, 0xC0) # sounding, select channel 0 pcm.write(0, 0xFF) # ENV pcm.write(1, 0x11) # PAN: 1 left, 1 right pcm.write(2, 0x00) pcm.write(3, 0x08) # FD = $0800: one sample a step pcm.write(4, 0x00) pcm.write(5, 0x00) # loop start 0 pcm.write(6, 0x00) # start page 0 pcm.write(8, 0xFE) # channel 0 on first, second, third = pcm.sample(), pcm.sample(), pcm.sample() assert first[0] > 0 > second[0] assert third == first # $FF sends the channel back to the loop start def test_wave_bank_window() -> None: pcm = PCM() pcm.write(7, 0x03) # bank 3 pcm.write(0x1005, 0x42) assert pcm.ram[0x3005] == 0x42 assert pcm.read(0x1005) == 0x42