From: Hermès Bélusca-Maïto Date: Sat, 27 Sep 2014 15:33:27 +0000 (+0000) Subject: [NTVDM] X-Git-Tag: backups/0.3.17@66124~396 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=7bafd10348a8315a9a1cbb3dfd095a40e19cd2ea;hp=c1441679a5947cfbbadf4ca912c23311d1386ec6 [NTVDM] - When writing to port 61h, reset the PIT 2 gate only when needed. - When the PIT 2 out signal is set, notify the speaker when there is really a change. - PC speaker: Do not replay the same sound if it is the same. svn path=/trunk/; revision=64345 --- diff --git a/reactos/subsystems/ntvdm/emulator.c b/reactos/subsystems/ntvdm/emulator.c index 42b5f19c8d4..ff01f259810 100644 --- a/reactos/subsystems/ntvdm/emulator.c +++ b/reactos/subsystems/ntvdm/emulator.c @@ -262,7 +262,7 @@ static BYTE WINAPI Port61hRead(ULONG Port) static VOID WINAPI Port61hWrite(ULONG Port, BYTE Data) { - // BOOLEAN SpeakerChange = FALSE; + // BOOLEAN SpeakerStateChange = FALSE; BYTE OldPort61hState = Port61hState; /* Only the four lowest bytes can be written */ @@ -271,18 +271,17 @@ static VOID WINAPI Port61hWrite(ULONG Port, BYTE Data) if ((OldPort61hState ^ Port61hState) & 0x01) { DPRINT("PIT 2 Gate %s\n", Port61hState & 0x01 ? "on" : "off"); - // SpeakerChange = TRUE; + PitSetGate(2, !!(Port61hState & 0x01)); + // SpeakerStateChange = TRUE; } - PitSetGate(2, !!(Port61hState & 0x01)); - if ((OldPort61hState ^ Port61hState) & 0x02) { /* There were some change for the speaker... */ DPRINT("Speaker %s\n", Port61hState & 0x02 ? "on" : "off"); - // SpeakerChange = TRUE; + // SpeakerStateChange = TRUE; } - // if (SpeakerChange) SpeakerChange(); + // if (SpeakerStateChange) SpeakerChange(); SpeakerChange(); } @@ -316,7 +315,7 @@ static VOID WINAPI PitChan1Out(LPVOID Param, BOOLEAN State) static VOID WINAPI PitChan2Out(LPVOID Param, BOOLEAN State) { - // BYTE OldPort61hState = Port61hState; + BYTE OldPort61hState = Port61hState; #if 0 if (State) @@ -332,9 +331,12 @@ static VOID WINAPI PitChan2Out(LPVOID Param, BOOLEAN State) #else Port61hState = (Port61hState & 0xDF) | (State << 5); #endif - DPRINT("Speaker PIT out\n"); - // if ((OldPort61hState ^ Port61hState) & 0x20) - // SpeakerChange(); + + if ((OldPort61hState ^ Port61hState) & 0x20) + { + DPRINT("PitChan2Out -- Port61hState changed\n"); + SpeakerChange(); + } } diff --git a/reactos/subsystems/ntvdm/hardware/speaker.c b/reactos/subsystems/ntvdm/hardware/speaker.c index 542e57d8b93..46eb09e0672 100644 --- a/reactos/subsystems/ntvdm/hardware/speaker.c +++ b/reactos/subsystems/ntvdm/hardware/speaker.c @@ -29,6 +29,9 @@ static HANDLE hBeep = NULL; /* PRIVATE FUNCTIONS **********************************************************/ +static DWORD OldReloadValue = 0; +static PIT_MODE OldMode = 0; + /* PUBLIC FUNCTIONS ***********************************************************/ VOID SpeakerChange(VOID) @@ -47,9 +50,18 @@ VOID SpeakerChange(VOID) DWORD PitChannel2ReloadValue = PitChannel2->ReloadValue; if (PitChannel2ReloadValue == 0) PitChannel2ReloadValue = 65536; + DPRINT("(1) PitChannel2(Bcd = %s, Mode = %d ; ReloadValue = %d)\n", PitChannel2->Bcd ? "true" : "false", PitChannel2->Mode, PitChannel2ReloadValue); + + if (OldMode == PitChannel2->Mode && OldReloadValue == PitChannel2ReloadValue) + return; + + OldMode = PitChannel2->Mode; + OldReloadValue = PitChannel2ReloadValue; + + DPRINT("(2) PitChannel2(Bcd = %s, Mode = %d ; ReloadValue = %d)\n", PitChannel2->Bcd ? "true" : "false", PitChannel2->Mode, PitChannel2ReloadValue); + /* Set beep data */ - BeepSetParameters.Frequency = (PIT_BASE_FREQUENCY / PitChannel2ReloadValue) - /* * (PitChannel2->Mode == PIT_MODE_SQUARE_WAVE ? 2 : 1) */; + BeepSetParameters.Frequency = (PIT_BASE_FREQUENCY / PitChannel2ReloadValue); BeepSetParameters.Duration = INFINITE; /* Send the beep */ @@ -78,6 +90,9 @@ VOID SpeakerChange(VOID) IO_STATUS_BLOCK IoStatusBlock; BEEP_SET_PARAMETERS BeepSetParameters; + OldMode = 0; + OldReloadValue = 0; + /* Set beep data */ BeepSetParameters.Frequency = 0x00; BeepSetParameters.Duration = 0x00;