[TRANSLATION] Polish translation update (#781)
[reactos.git] / subsystems / mvdm / ntvdm / hardware / ppi.c
1 /*
2 * COPYRIGHT: GPL - See COPYING in the top level directory
3 * PROJECT: ReactOS Virtual DOS Machine
4 * FILE: subsystems/mvdm/ntvdm/hardware/ppi.c
5 * PURPOSE: Programmable Peripheral Interface emulation -
6 * i8255A-5 compatible
7 * PROGRAMMERS: Hermes Belusca-Maito (hermes.belusca@sfr.fr)
8 *
9 * NOTES: - Most of its functionality as keyboard controller is replaced
10 * by the PS/2 controller.
11 * - This controller is here only for having ports 61h and 62h working.
12 */
13
14 /* INCLUDES *******************************************************************/
15
16 #include "ntvdm.h"
17
18 #define NDEBUG
19 #include <debug.h>
20
21 #include "emulator.h"
22 #include "ppi.h"
23
24 #include "hardware/pit.h"
25 #include "hardware/sound/speaker.h"
26
27 #include "io.h"
28
29 /* PRIVATE VARIABLES **********************************************************/
30
31 /*static*/ BYTE Port61hState = 0x00; // Used in emulator.c
32 static BYTE Port62hState = 0x00;
33
34 /* PRIVATE FUNCTIONS **********************************************************/
35
36 static BYTE WINAPI PpiReadPort(USHORT Port)
37 {
38 if (Port == PPI_PORT_61H)
39 return Port61hState;
40 else if (Port == PPI_PORT_62H)
41 return Port62hState;
42
43 return 0x00;
44 }
45
46 static VOID WINAPI Port61hWrite(USHORT Port, BYTE Data)
47 {
48 // BOOLEAN SpeakerStateChange = FALSE;
49 BYTE OldPort61hState = Port61hState;
50
51 /* Only the four lowest bytes can be written */
52 Port61hState = (Port61hState & 0xF0) | (Data & 0x0F);
53
54 if ((OldPort61hState ^ Port61hState) & 0x01)
55 {
56 DPRINT("PIT 2 Gate %s\n", Port61hState & 0x01 ? "on" : "off");
57 PitSetGate(2, !!(Port61hState & 0x01));
58 // SpeakerStateChange = TRUE;
59 }
60
61 if ((OldPort61hState ^ Port61hState) & 0x02)
62 {
63 /* There were some change for the speaker... */
64 DPRINT("Speaker %s\n", Port61hState & 0x02 ? "on" : "off");
65 // SpeakerStateChange = TRUE;
66 }
67 // if (SpeakerStateChange) SpeakerChange(Port61hState);
68 SpeakerChange(Port61hState);
69 }
70
71 static VOID WINAPI Port62hWrite(USHORT Port, BYTE Data)
72 {
73 Port62hState = Data;
74 }
75
76 /* PUBLIC FUNCTIONS ***********************************************************/
77
78 VOID PpiInitialize(VOID)
79 {
80 /* Register the I/O Ports */
81 // Port 0x60 is now used by the PS/2 controller
82 RegisterIoPort(PPI_PORT_61H, PpiReadPort, Port61hWrite);
83 RegisterIoPort(PPI_PORT_62H, PpiReadPort, Port62hWrite);
84 // Port 0x63 is unused
85 }
86
87 /* EOF */