From f0466501fca78e53655c85857a908a7c4bdb0c39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Sat, 11 Jan 2014 21:45:01 +0000 Subject: [PATCH] [NTVDM] - Do not export (for the PIC/PIT/Speaker) the port functions but use instead the common port interface. - In bios.c : IOWriteB(PIC_MASTER_DATA, PIC_ICW4_8086 /* | PIC_ICW4_AEOI */); (line 377) : in NXVM they add PIC_ICW4_AEOI; [TheFlash], can you have a look at this and see whether it is required for the master PIC only, otherwise remove this comment. svn path=/branches/ntvdm/; revision=61590 --- subsystems/ntvdm/bios/bios.c | 15 ++++++++------- subsystems/ntvdm/hardware/pic.h | 28 ++++++++++++++++------------ subsystems/ntvdm/hardware/ps2.h | 1 + subsystems/ntvdm/hardware/speaker.c | 12 +++++++----- subsystems/ntvdm/hardware/speaker.h | 2 -- subsystems/ntvdm/hardware/timer.c | 10 ++++++---- subsystems/ntvdm/hardware/timer.h | 4 +--- 7 files changed, 39 insertions(+), 33 deletions(-) diff --git a/subsystems/ntvdm/bios/bios.c b/subsystems/ntvdm/bios/bios.c index 0d91b7a5d86..9c8039de024 100644 --- a/subsystems/ntvdm/bios/bios.c +++ b/subsystems/ntvdm/bios/bios.c @@ -361,29 +361,30 @@ BOOLEAN BiosInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput) * The POST (Power On-Self Test) */ - /* Initialize the PIC */ + /* Initialize the master and the slave PICs */ IOWriteB(PIC_MASTER_CMD, PIC_ICW1 | PIC_ICW1_ICW4); IOWriteB(PIC_SLAVE_CMD , PIC_ICW1 | PIC_ICW1_ICW4); /* Set the interrupt offsets */ IOWriteB(PIC_MASTER_DATA, BIOS_PIC_MASTER_INT); - IOWriteB(PIC_SLAVE_DATA , BIOS_PIC_SLAVE_INT); + IOWriteB(PIC_SLAVE_DATA , BIOS_PIC_SLAVE_INT ); /* Tell the master PIC there is a slave at IRQ 2 */ IOWriteB(PIC_MASTER_DATA, 1 << 2); IOWriteB(PIC_SLAVE_DATA , 2); - /* Make sure the PIC is in 8086 mode */ - IOWriteB(PIC_MASTER_DATA, PIC_ICW4_8086); + /* Make sure both PICs are in 8086 mode */ + IOWriteB(PIC_MASTER_DATA, PIC_ICW4_8086 /* | PIC_ICW4_AEOI */); IOWriteB(PIC_SLAVE_DATA , PIC_ICW4_8086); /* Clear the masks for both PICs */ IOWriteB(PIC_MASTER_DATA, 0x00); IOWriteB(PIC_SLAVE_DATA , 0x00); - PitWriteCommand(0x34); - PitWriteData(0, 0x00); - PitWriteData(0, 0x00); + /* Initialize the PIT */ + IOWriteB(PIT_COMMAND_PORT, 0x34); + IOWriteB(PIT_DATA_PORT(0), 0x00); + IOWriteB(PIT_DATA_PORT(0), 0x00); return TRUE; } diff --git a/subsystems/ntvdm/hardware/pic.h b/subsystems/ntvdm/hardware/pic.h index f838dd5b52f..03d7dd1738e 100644 --- a/subsystems/ntvdm/hardware/pic.h +++ b/subsystems/ntvdm/hardware/pic.h @@ -16,20 +16,23 @@ /* DEFINES ********************************************************************/ -#define PIC_MASTER_CMD 0x20 +#define PIC_MASTER_CMD 0x20 #define PIC_MASTER_DATA 0x21 -#define PIC_SLAVE_CMD 0xA0 -#define PIC_SLAVE_DATA 0xA1 -#define PIC_ICW1 0x10 -#define PIC_ICW1_ICW4 (1 << 0) +#define PIC_SLAVE_CMD 0xA0 +#define PIC_SLAVE_DATA 0xA1 + +#define PIC_ICW1 0x10 +#define PIC_ICW1_ICW4 (1 << 0) #define PIC_ICW1_SINGLE (1 << 1) -#define PIC_ICW4_8086 (1 << 0) -#define PIC_ICW4_AEOI (1 << 1) -#define PIC_OCW2_NUM_MASK 0x07 -#define PIC_OCW2_EOI (1 << 5) -#define PIC_OCW2_SL (1 << 6) -#define PIC_OCW3 (1 << 3) -#define PIC_OCW3_READ_ISR 0x0B +#define PIC_ICW4_8086 (1 << 0) +#define PIC_ICW4_AEOI (1 << 1) + +#define PIC_OCW2_NUM_MASK 0x07 +#define PIC_OCW2_EOI (1 << 5) +#define PIC_OCW2_SL (1 << 6) + +#define PIC_OCW3 (1 << 3) +#define PIC_OCW3_READ_ISR 0x0B typedef struct _PIC { @@ -50,6 +53,7 @@ typedef struct _PIC VOID PicInterruptRequest(BYTE Number); BYTE PicGetInterrupt(VOID); + VOID PicInitialize(VOID); #endif // _PIC_H_ diff --git a/subsystems/ntvdm/hardware/ps2.h b/subsystems/ntvdm/hardware/ps2.h index 369422ab7c1..103aa02404e 100644 --- a/subsystems/ntvdm/hardware/ps2.h +++ b/subsystems/ntvdm/hardware/ps2.h @@ -25,6 +25,7 @@ /* FUNCTIONS ******************************************************************/ VOID GenerateKeyboardInterrupts(VOID); + BOOLEAN PS2Initialize(HANDLE ConsoleInput); VOID PS2Cleanup(VOID); diff --git a/subsystems/ntvdm/hardware/speaker.c b/subsystems/ntvdm/hardware/speaker.c index 84a81322975..4bd9af8e40e 100644 --- a/subsystems/ntvdm/hardware/speaker.c +++ b/subsystems/ntvdm/hardware/speaker.c @@ -28,14 +28,14 @@ static BYTE Port61hState = 0x00; HANDLE hBeep = NULL; -/* PUBLIC FUNCTIONS ***********************************************************/ +/* PRIVATE FUNCTIONS **********************************************************/ -BYTE SpeakerReadStatus(VOID) +static BYTE SpeakerReadStatus(VOID) { return Port61hState; } -VOID SpeakerWriteCommand(BYTE Value) +static VOID SpeakerWriteCommand(BYTE Value) { BOOLEAN IsConnectedToPITChannel2; UCHAR SpeakerData; @@ -121,16 +121,18 @@ VOID SpeakerWriteCommand(BYTE Value) } } -BYTE WINAPI SpeakerReadPort(ULONG Port) +static BYTE WINAPI SpeakerReadPort(ULONG Port) { return SpeakerReadStatus(); } -VOID WINAPI SpeakerWritePort(ULONG Port, BYTE Data) +static VOID WINAPI SpeakerWritePort(ULONG Port, BYTE Data) { SpeakerWriteCommand(Data); } +/* PUBLIC FUNCTIONS ***********************************************************/ + VOID SpeakerInitialize(VOID) { NTSTATUS Status; diff --git a/subsystems/ntvdm/hardware/speaker.h b/subsystems/ntvdm/hardware/speaker.h index 9f2dc107e75..166c63e0528 100644 --- a/subsystems/ntvdm/hardware/speaker.h +++ b/subsystems/ntvdm/hardware/speaker.h @@ -21,8 +21,6 @@ VOID SpeakerInitialize(VOID); VOID SpeakerCleanup(VOID); -BYTE SpeakerReadStatus(VOID); -VOID SpeakerWriteCommand(BYTE Value); #endif // _SPEAKER_H_ diff --git a/subsystems/ntvdm/hardware/timer.c b/subsystems/ntvdm/hardware/timer.c index 111a54a76e3..b46dcb40606 100644 --- a/subsystems/ntvdm/hardware/timer.c +++ b/subsystems/ntvdm/hardware/timer.c @@ -20,9 +20,9 @@ static PIT_CHANNEL PitChannels[PIT_CHANNELS]; PPIT_CHANNEL PitChannel2 = &PitChannels[2]; -/* PUBLIC FUNCTIONS ***********************************************************/ +/* PRIVATE FUNCTIONS **********************************************************/ -VOID PitWriteCommand(BYTE Value) +static VOID PitWriteCommand(BYTE Value) { BYTE Channel = Value >> 6; BYTE Mode = (Value >> 1) & 0x07; @@ -69,7 +69,7 @@ VOID PitWriteCommand(BYTE Value) } } -BYTE PitReadData(BYTE Channel) +static BYTE PitReadData(BYTE Channel) { WORD CurrentValue = PitChannels[Channel].CurrentValue; BYTE AccessMode = PitChannels[Channel].AccessMode; @@ -119,7 +119,7 @@ BYTE PitReadData(BYTE Channel) return 0; } -VOID PitWriteData(BYTE Channel, BYTE Value) +static VOID PitWriteData(BYTE Channel, BYTE Value) { BYTE AccessMode = PitChannels[Channel].AccessMode; @@ -184,6 +184,8 @@ static VOID WINAPI PitWritePort(ULONG Port, BYTE Data) } } +/* PUBLIC FUNCTIONS ***********************************************************/ + VOID PitDecrementCount(DWORD Count) { INT i; diff --git a/subsystems/ntvdm/hardware/timer.h b/subsystems/ntvdm/hardware/timer.h index 0383a3e8f59..a15c9a1572b 100644 --- a/subsystems/ntvdm/hardware/timer.h +++ b/subsystems/ntvdm/hardware/timer.h @@ -47,11 +47,9 @@ extern PPIT_CHANNEL PitChannel2; // Needed for PC Speaker /* FUNCTIONS ******************************************************************/ -VOID PitWriteCommand(BYTE Value); -VOID PitWriteData(BYTE Channel, BYTE Value); - VOID PitDecrementCount(DWORD Count); DWORD PitGetResolution(VOID); + VOID PitInitialize(VOID); #endif // _TIMER_H_