- Export and use IORead/WriteXX (instead of PicRead/WriteXX or VgaRead/WritePort)
- static'ify some functions.

svn path=/branches/ntvdm/; revision=61580
This commit is contained in:
Hermès Bélusca-Maïto 2014-01-11 14:40:03 +00:00
parent 49ab546ac3
commit af24ac79df
9 changed files with 501 additions and 464 deletions

View file

@ -13,6 +13,7 @@
#include "emulator.h"
#include "bios.h"
#include "io.h"
#include "vga.h"
#include "pic.h"
#include "ps2.h"
@ -867,28 +868,28 @@ static BOOLEAN VgaSetRegisters(PVGA_REGISTERS Registers)
: VGA_CRTC_INDEX_MONO;
/* Write the misc register */
VgaWritePort(VGA_MISC_WRITE, Registers->Misc);
IOWriteB(VGA_MISC_WRITE, Registers->Misc);
/* Synchronous reset on */
VgaWritePort(VGA_SEQ_INDEX, VGA_SEQ_RESET_REG);
VgaWritePort(VGA_SEQ_DATA , VGA_SEQ_RESET_AR);
IOWriteB(VGA_SEQ_INDEX, VGA_SEQ_RESET_REG);
IOWriteB(VGA_SEQ_DATA , VGA_SEQ_RESET_AR);
/* Write the sequencer registers */
for (i = 1; i < VGA_SEQ_MAX_REG; i++)
{
VgaWritePort(VGA_SEQ_INDEX, i);
VgaWritePort(VGA_SEQ_DATA, Registers->Sequencer[i]);
IOWriteB(VGA_SEQ_INDEX, i);
IOWriteB(VGA_SEQ_DATA, Registers->Sequencer[i]);
}
/* Synchronous reset off */
VgaWritePort(VGA_SEQ_INDEX, VGA_SEQ_RESET_REG);
VgaWritePort(VGA_SEQ_DATA , VGA_SEQ_RESET_SR | VGA_SEQ_RESET_AR);
IOWriteB(VGA_SEQ_INDEX, VGA_SEQ_RESET_REG);
IOWriteB(VGA_SEQ_DATA , VGA_SEQ_RESET_SR | VGA_SEQ_RESET_AR);
/* Unlock CRTC registers 0-7 */
VgaWritePort(VGA_CRTC_INDEX, VGA_CRTC_END_HORZ_BLANKING_REG);
VgaWritePort(VGA_CRTC_DATA, VgaReadPort(VGA_CRTC_DATA) | 0x80);
VgaWritePort(VGA_CRTC_INDEX, VGA_CRTC_VERT_RETRACE_END_REG);
VgaWritePort(VGA_CRTC_DATA, VgaReadPort(VGA_CRTC_DATA) & ~0x80);
IOWriteB(VGA_CRTC_INDEX, VGA_CRTC_END_HORZ_BLANKING_REG);
IOWriteB(VGA_CRTC_DATA, IOReadB(VGA_CRTC_DATA) | 0x80);
IOWriteB(VGA_CRTC_INDEX, VGA_CRTC_VERT_RETRACE_END_REG);
IOWriteB(VGA_CRTC_DATA, IOReadB(VGA_CRTC_DATA) & ~0x80);
// Make sure they remain unlocked
Registers->CRT[VGA_CRTC_END_HORZ_BLANKING_REG] |= 0x80;
Registers->CRT[VGA_CRTC_VERT_RETRACE_END_REG] &= ~0x80;
@ -896,34 +897,34 @@ static BOOLEAN VgaSetRegisters(PVGA_REGISTERS Registers)
/* Write the CRTC registers */
for (i = 0; i < VGA_CRTC_MAX_REG; i++)
{
VgaWritePort(VGA_CRTC_INDEX, i);
VgaWritePort(VGA_CRTC_DATA, Registers->CRT[i]);
IOWriteB(VGA_CRTC_INDEX, i);
IOWriteB(VGA_CRTC_DATA, Registers->CRT[i]);
}
/* Write the GC registers */
for (i = 0; i < VGA_GC_MAX_REG; i++)
{
VgaWritePort(VGA_GC_INDEX, i);
VgaWritePort(VGA_GC_DATA, Registers->Graphics[i]);
IOWriteB(VGA_GC_INDEX, i);
IOWriteB(VGA_GC_DATA, Registers->Graphics[i]);
}
/* Write the AC registers */
// DbgPrint("\n");
for (i = 0; i < VGA_AC_MAX_REG; i++)
{
VgaReadPort(VGA_INSTAT1_READ); // Put the AC register into index state
VgaWritePort(VGA_AC_INDEX, i);
VgaWritePort(VGA_AC_WRITE, Registers->Attribute[i]);
IOReadB(VGA_INSTAT1_READ); // Put the AC register into index state
IOWriteB(VGA_AC_INDEX, i);
IOWriteB(VGA_AC_WRITE, Registers->Attribute[i]);
// DbgPrint("Registers->Attribute[%d] = %d\n", i, Registers->Attribute[i]);
}
// DbgPrint("\n");
/* Set the PEL mask */
VgaWritePort(VGA_DAC_MASK, 0xFF);
IOWriteB(VGA_DAC_MASK, 0xFF);
/* Enable screen and disable palette access */
VgaReadPort(VGA_INSTAT1_READ); // Put the AC register into index state
VgaWritePort(VGA_AC_INDEX, 0x20);
IOReadB(VGA_INSTAT1_READ); // Put the AC register into index state
IOWriteB(VGA_AC_INDEX, 0x20);
/* Enable interrupts */
setIF(1);
@ -936,29 +937,29 @@ static VOID VgaSetPalette(const COLORREF* Palette, ULONG Size)
ULONG i;
// /* Disable screen and enable palette access */
// VgaReadPort(VGA_INSTAT1_READ); // Put the AC register into index state
// VgaWritePort(VGA_AC_INDEX, 0x00);
// IOReadB(VGA_INSTAT1_READ); // Put the AC register into index state
// IOWriteB(VGA_AC_INDEX, 0x00);
for (i = 0; i < Size; i++)
{
VgaWritePort(VGA_DAC_WRITE_INDEX, i);
VgaWritePort(VGA_DAC_DATA, VGA_COLOR_TO_DAC(GetRValue(Palette[i])));
VgaWritePort(VGA_DAC_DATA, VGA_COLOR_TO_DAC(GetGValue(Palette[i])));
VgaWritePort(VGA_DAC_DATA, VGA_COLOR_TO_DAC(GetBValue(Palette[i])));
IOWriteB(VGA_DAC_WRITE_INDEX, i);
IOWriteB(VGA_DAC_DATA, VGA_COLOR_TO_DAC(GetRValue(Palette[i])));
IOWriteB(VGA_DAC_DATA, VGA_COLOR_TO_DAC(GetGValue(Palette[i])));
IOWriteB(VGA_DAC_DATA, VGA_COLOR_TO_DAC(GetBValue(Palette[i])));
}
/* The following step might be optional */
for (i = Size; i < VGA_MAX_COLORS; i++)
{
VgaWritePort(VGA_DAC_WRITE_INDEX, i);
VgaWritePort(VGA_DAC_DATA, VGA_COLOR_TO_DAC(0x00));
VgaWritePort(VGA_DAC_DATA, VGA_COLOR_TO_DAC(0x00));
VgaWritePort(VGA_DAC_DATA, VGA_COLOR_TO_DAC(0x00));
IOWriteB(VGA_DAC_WRITE_INDEX, i);
IOWriteB(VGA_DAC_DATA, VGA_COLOR_TO_DAC(0x00));
IOWriteB(VGA_DAC_DATA, VGA_COLOR_TO_DAC(0x00));
IOWriteB(VGA_DAC_DATA, VGA_COLOR_TO_DAC(0x00));
}
/* Enable screen and disable palette access */
// VgaReadPort(VGA_INSTAT1_READ); // Put the AC register into index state
// VgaWritePort(VGA_AC_INDEX, 0x20);
// IOReadB(VGA_INSTAT1_READ); // Put the AC register into index state
// IOWriteB(VGA_AC_INDEX, 0x20);
}
static VOID VgaChangePalette(BYTE ModeNumber)
@ -1012,10 +1013,10 @@ static VOID BiosSetCursorPosition(BYTE Row, BYTE Column, BYTE Page)
WORD Offset = Row * Bda->ScreenColumns + Column;
/* Modify the CRTC registers */
VgaWritePort(VGA_CRTC_INDEX, VGA_CRTC_CURSOR_LOC_LOW_REG);
VgaWritePort(VGA_CRTC_DATA , LOBYTE(Offset));
VgaWritePort(VGA_CRTC_INDEX, VGA_CRTC_CURSOR_LOC_HIGH_REG);
VgaWritePort(VGA_CRTC_DATA , HIBYTE(Offset));
IOWriteB(VGA_CRTC_INDEX, VGA_CRTC_CURSOR_LOC_LOW_REG);
IOWriteB(VGA_CRTC_DATA , LOBYTE(Offset));
IOWriteB(VGA_CRTC_INDEX, VGA_CRTC_CURSOR_LOC_HIGH_REG);
IOWriteB(VGA_CRTC_DATA , HIBYTE(Offset));
}
}
@ -1057,14 +1058,14 @@ static BOOLEAN BiosSetVideoMode(BYTE ModeNumber)
Bda->VideoPageOffset = Bda->VideoPage * Bda->VideoPageSize;
/* Set the start address in the CRTC */
VgaWritePort(VGA_CRTC_INDEX, VGA_CRTC_START_ADDR_LOW_REG);
VgaWritePort(VGA_CRTC_DATA , LOBYTE(Bda->VideoPageOffset));
VgaWritePort(VGA_CRTC_INDEX, VGA_CRTC_START_ADDR_HIGH_REG);
VgaWritePort(VGA_CRTC_DATA , HIBYTE(Bda->VideoPageOffset));
IOWriteB(VGA_CRTC_INDEX, VGA_CRTC_START_ADDR_LOW_REG);
IOWriteB(VGA_CRTC_DATA , LOBYTE(Bda->VideoPageOffset));
IOWriteB(VGA_CRTC_INDEX, VGA_CRTC_START_ADDR_HIGH_REG);
IOWriteB(VGA_CRTC_DATA , HIBYTE(Bda->VideoPageOffset));
/* Get the character height */
VgaWritePort(VGA_CRTC_INDEX, VGA_CRTC_MAX_SCAN_LINE_REG);
Bda->CharacterHeight = 1 + (VgaReadPort(VGA_CRTC_DATA) & 0x1F);
IOWriteB(VGA_CRTC_INDEX, VGA_CRTC_MAX_SCAN_LINE_REG);
Bda->CharacterHeight = 1 + (IOReadB(VGA_CRTC_DATA) & 0x1F);
Resolution = VgaGetDisplayResolution();
Bda->ScreenColumns = Resolution.X;
@ -1092,10 +1093,10 @@ static BOOLEAN BiosSetVideoPage(BYTE PageNumber)
Bda->VideoPageOffset = Bda->VideoPage * Bda->VideoPageSize;
/* Set the start address in the CRTC */
VgaWritePort(VGA_CRTC_INDEX, VGA_CRTC_START_ADDR_LOW_REG);
VgaWritePort(VGA_CRTC_DATA , LOBYTE(Bda->VideoPageOffset));
VgaWritePort(VGA_CRTC_INDEX, VGA_CRTC_START_ADDR_HIGH_REG);
VgaWritePort(VGA_CRTC_DATA , HIBYTE(Bda->VideoPageOffset));
IOWriteB(VGA_CRTC_INDEX, VGA_CRTC_START_ADDR_LOW_REG);
IOWriteB(VGA_CRTC_DATA , LOBYTE(Bda->VideoPageOffset));
IOWriteB(VGA_CRTC_INDEX, VGA_CRTC_START_ADDR_HIGH_REG);
IOWriteB(VGA_CRTC_DATA , HIBYTE(Bda->VideoPageOffset));
/*
* Get the cursor location (we don't update anything on the BIOS side
@ -1126,10 +1127,10 @@ static VOID WINAPI BiosVideoService(LPWORD Stack)
Bda->CursorEndLine = getCL();
/* Modify the CRTC registers */
VgaWritePort(VGA_CRTC_INDEX, VGA_CRTC_CURSOR_START_REG);
VgaWritePort(VGA_CRTC_DATA , Bda->CursorStartLine);
VgaWritePort(VGA_CRTC_INDEX, VGA_CRTC_CURSOR_END_REG);
VgaWritePort(VGA_CRTC_DATA , Bda->CursorEndLine);
IOWriteB(VGA_CRTC_INDEX, VGA_CRTC_CURSOR_START_REG);
IOWriteB(VGA_CRTC_DATA , Bda->CursorStartLine);
IOWriteB(VGA_CRTC_INDEX, VGA_CRTC_CURSOR_END_REG);
IOWriteB(VGA_CRTC_DATA , Bda->CursorEndLine);
break;
}
@ -1251,15 +1252,15 @@ static VOID WINAPI BiosVideoService(LPWORD Stack)
case 0x00:
{
/* Write the index */
VgaReadPort(VGA_INSTAT1_READ); // Put the AC register into index state
VgaWritePort(VGA_AC_INDEX, getBL());
IOReadB(VGA_INSTAT1_READ); // Put the AC register into index state
IOWriteB(VGA_AC_INDEX, getBL());
/* Write the data */
VgaWritePort(VGA_AC_WRITE, getBH());
IOWriteB(VGA_AC_WRITE, getBH());
/* Enable screen and disable palette access */
VgaReadPort(VGA_INSTAT1_READ); // Put the AC register into index state
VgaWritePort(VGA_AC_INDEX, 0x20);
IOReadB(VGA_INSTAT1_READ); // Put the AC register into index state
IOWriteB(VGA_AC_INDEX, 0x20);
break;
}
@ -1267,15 +1268,15 @@ static VOID WINAPI BiosVideoService(LPWORD Stack)
case 0x01:
{
/* Write the index */
VgaReadPort(VGA_INSTAT1_READ); // Put the AC register into index state
VgaWritePort(VGA_AC_INDEX, VGA_AC_OVERSCAN_REG);
IOReadB(VGA_INSTAT1_READ); // Put the AC register into index state
IOWriteB(VGA_AC_INDEX, VGA_AC_OVERSCAN_REG);
/* Write the data */
VgaWritePort(VGA_AC_WRITE, getBH());
IOWriteB(VGA_AC_WRITE, getBH());
/* Enable screen and disable palette access */
VgaReadPort(VGA_INSTAT1_READ); // Put the AC register into index state
VgaWritePort(VGA_AC_INDEX, 0x20);
IOReadB(VGA_INSTAT1_READ); // Put the AC register into index state
IOWriteB(VGA_AC_INDEX, 0x20);
break;
}
@ -1289,20 +1290,20 @@ static VOID WINAPI BiosVideoService(LPWORD Stack)
for (i = 0; i <= VGA_AC_PAL_F_REG; i++)
{
/* Write the index */
VgaReadPort(VGA_INSTAT1_READ); // Put the AC register into index state
VgaWritePort(VGA_AC_INDEX, i);
IOReadB(VGA_INSTAT1_READ); // Put the AC register into index state
IOWriteB(VGA_AC_INDEX, i);
/* Write the data */
VgaWritePort(VGA_AC_WRITE, Buffer[i]);
IOWriteB(VGA_AC_WRITE, Buffer[i]);
}
/* Set the overscan register */
VgaWritePort(VGA_AC_INDEX, VGA_AC_OVERSCAN_REG);
VgaWritePort(VGA_AC_WRITE, Buffer[VGA_AC_PAL_F_REG + 1]);
IOWriteB(VGA_AC_INDEX, VGA_AC_OVERSCAN_REG);
IOWriteB(VGA_AC_WRITE, Buffer[VGA_AC_PAL_F_REG + 1]);
/* Enable screen and disable palette access */
VgaReadPort(VGA_INSTAT1_READ); // Put the AC register into index state
VgaWritePort(VGA_AC_INDEX, 0x20);
IOReadB(VGA_INSTAT1_READ); // Put the AC register into index state
IOWriteB(VGA_AC_INDEX, 0x20);
break;
}
@ -1310,15 +1311,15 @@ static VOID WINAPI BiosVideoService(LPWORD Stack)
case 0x07:
{
/* Write the index */
VgaReadPort(VGA_INSTAT1_READ); // Put the AC register into index state
VgaWritePort(VGA_AC_INDEX, getBL());
IOReadB(VGA_INSTAT1_READ); // Put the AC register into index state
IOWriteB(VGA_AC_INDEX, getBL());
/* Read the data */
setBH(VgaReadPort(VGA_AC_READ));
setBH(IOReadB(VGA_AC_READ));
/* Enable screen and disable palette access */
VgaReadPort(VGA_INSTAT1_READ); // Put the AC register into index state
VgaWritePort(VGA_AC_INDEX, 0x20);
IOReadB(VGA_INSTAT1_READ); // Put the AC register into index state
IOWriteB(VGA_AC_INDEX, 0x20);
break;
}
@ -1326,15 +1327,15 @@ static VOID WINAPI BiosVideoService(LPWORD Stack)
case 0x08:
{
/* Write the index */
VgaReadPort(VGA_INSTAT1_READ); // Put the AC register into index state
VgaWritePort(VGA_AC_INDEX, VGA_AC_OVERSCAN_REG);
IOReadB(VGA_INSTAT1_READ); // Put the AC register into index state
IOWriteB(VGA_AC_INDEX, VGA_AC_OVERSCAN_REG);
/* Read the data */
setBH(VgaReadPort(VGA_AC_READ));
setBH(IOReadB(VGA_AC_READ));
/* Enable screen and disable palette access */
VgaReadPort(VGA_INSTAT1_READ); // Put the AC register into index state
VgaWritePort(VGA_AC_INDEX, 0x20);
IOReadB(VGA_INSTAT1_READ); // Put the AC register into index state
IOWriteB(VGA_AC_INDEX, 0x20);
break;
}
@ -1348,20 +1349,20 @@ static VOID WINAPI BiosVideoService(LPWORD Stack)
for (i = 0; i <= VGA_AC_PAL_F_REG; i++)
{
/* Write the index */
VgaReadPort(VGA_INSTAT1_READ); // Put the AC register into index state
VgaWritePort(VGA_AC_INDEX, i);
IOReadB(VGA_INSTAT1_READ); // Put the AC register into index state
IOWriteB(VGA_AC_INDEX, i);
/* Read the data */
Buffer[i] = VgaReadPort(VGA_AC_READ);
Buffer[i] = IOReadB(VGA_AC_READ);
}
/* Get the overscan register */
VgaWritePort(VGA_AC_INDEX, VGA_AC_OVERSCAN_REG);
Buffer[VGA_AC_PAL_F_REG + 1] = VgaReadPort(VGA_AC_READ);
IOWriteB(VGA_AC_INDEX, VGA_AC_OVERSCAN_REG);
Buffer[VGA_AC_PAL_F_REG + 1] = IOReadB(VGA_AC_READ);
/* Enable screen and disable palette access */
VgaReadPort(VGA_INSTAT1_READ); // Put the AC register into index state
VgaWritePort(VGA_AC_INDEX, 0x20);
IOReadB(VGA_INSTAT1_READ); // Put the AC register into index state
IOWriteB(VGA_AC_INDEX, 0x20);
break;
}
@ -1370,12 +1371,12 @@ static VOID WINAPI BiosVideoService(LPWORD Stack)
{
/* Write the index */
// Certainly in BL and not in BX as said by Ralf Brown...
VgaWritePort(VGA_DAC_WRITE_INDEX, getBL());
IOWriteB(VGA_DAC_WRITE_INDEX, getBL());
/* Write the data in this order: Red, Green, Blue */
VgaWritePort(VGA_DAC_DATA, getDH());
VgaWritePort(VGA_DAC_DATA, getCH());
VgaWritePort(VGA_DAC_DATA, getCL());
IOWriteB(VGA_DAC_DATA, getDH());
IOWriteB(VGA_DAC_DATA, getCH());
IOWriteB(VGA_DAC_DATA, getCL());
break;
}
@ -1388,14 +1389,14 @@ static VOID WINAPI BiosVideoService(LPWORD Stack)
/* Write the index */
// Certainly in BL and not in BX as said by Ralf Brown...
VgaWritePort(VGA_DAC_WRITE_INDEX, getBL());
IOWriteB(VGA_DAC_WRITE_INDEX, getBL());
for (i = 0; i < getCX(); i++)
{
/* Write the data in this order: Red, Green, Blue */
VgaWritePort(VGA_DAC_DATA, *Buffer++);
VgaWritePort(VGA_DAC_DATA, *Buffer++);
VgaWritePort(VGA_DAC_DATA, *Buffer++);
IOWriteB(VGA_DAC_DATA, *Buffer++);
IOWriteB(VGA_DAC_DATA, *Buffer++);
IOWriteB(VGA_DAC_DATA, *Buffer++);
}
break;
@ -1405,12 +1406,12 @@ static VOID WINAPI BiosVideoService(LPWORD Stack)
case 0x15:
{
/* Write the index */
VgaWritePort(VGA_DAC_READ_INDEX, getBL());
IOWriteB(VGA_DAC_READ_INDEX, getBL());
/* Read the data in this order: Red, Green, Blue */
setDH(VgaReadPort(VGA_DAC_DATA));
setCH(VgaReadPort(VGA_DAC_DATA));
setCL(VgaReadPort(VGA_DAC_DATA));
setDH(IOReadB(VGA_DAC_DATA));
setCH(IOReadB(VGA_DAC_DATA));
setCL(IOReadB(VGA_DAC_DATA));
break;
}
@ -1423,14 +1424,14 @@ static VOID WINAPI BiosVideoService(LPWORD Stack)
/* Write the index */
// Certainly in BL and not in BX as said by Ralf Brown...
VgaWritePort(VGA_DAC_READ_INDEX, getBL());
IOWriteB(VGA_DAC_READ_INDEX, getBL());
for (i = 0; i < getCX(); i++)
{
/* Write the data in this order: Red, Green, Blue */
*Buffer++ = VgaReadPort(VGA_DAC_DATA);
*Buffer++ = VgaReadPort(VGA_DAC_DATA);
*Buffer++ = VgaReadPort(VGA_DAC_DATA);
*Buffer++ = IOReadB(VGA_DAC_DATA);
*Buffer++ = IOReadB(VGA_DAC_DATA);
*Buffer++ = IOReadB(VGA_DAC_DATA);
}
break;
@ -1931,24 +1932,24 @@ BOOLEAN BiosInitialize(VOID)
PS2Initialize(BiosConsoleInput);
/* Initialize the PIC */
PicWriteCommand(PIC_MASTER_CMD, PIC_ICW1 | PIC_ICW1_ICW4);
PicWriteCommand(PIC_SLAVE_CMD , PIC_ICW1 | PIC_ICW1_ICW4);
IOWriteB(PIC_MASTER_CMD, PIC_ICW1 | PIC_ICW1_ICW4);
IOWriteB(PIC_SLAVE_CMD , PIC_ICW1 | PIC_ICW1_ICW4);
/* Set the interrupt offsets */
PicWriteData(PIC_MASTER_DATA, BIOS_PIC_MASTER_INT);
PicWriteData(PIC_SLAVE_DATA , BIOS_PIC_SLAVE_INT);
IOWriteB(PIC_MASTER_DATA, BIOS_PIC_MASTER_INT);
IOWriteB(PIC_SLAVE_DATA , BIOS_PIC_SLAVE_INT);
/* Tell the master PIC there is a slave at IRQ 2 */
PicWriteData(PIC_MASTER_DATA, 1 << 2);
PicWriteData(PIC_SLAVE_DATA , 2);
IOWriteB(PIC_MASTER_DATA, 1 << 2);
IOWriteB(PIC_SLAVE_DATA , 2);
/* Make sure the PIC is in 8086 mode */
PicWriteData(PIC_MASTER_DATA, PIC_ICW4_8086);
PicWriteData(PIC_SLAVE_DATA , PIC_ICW4_8086);
IOWriteB(PIC_MASTER_DATA, PIC_ICW4_8086);
IOWriteB(PIC_SLAVE_DATA , PIC_ICW4_8086);
/* Clear the masks for both PICs */
PicWriteData(PIC_MASTER_DATA, 0x00);
PicWriteData(PIC_SLAVE_DATA , 0x00);
IOWriteB(PIC_MASTER_DATA, 0x00);
IOWriteB(PIC_SLAVE_DATA , 0x00);
PitWriteCommand(0x34);
PitWriteData(0, 0x00);
@ -2012,7 +2013,7 @@ VOID BiosHandleIrq(BYTE IrqNumber, LPWORD Stack)
WORD Character;
/* Get the scan code and virtual key code */
ScanCode = PS2ReadPort(PS2_DATA_PORT);
ScanCode = IOReadB(PS2_DATA_PORT);
VirtualKey = MapVirtualKey(ScanCode & 0x7F, MAPVK_VSC_TO_VK);
/* Check if this is a key press or release */
@ -2074,8 +2075,8 @@ VOID BiosHandleIrq(BYTE IrqNumber, LPWORD Stack)
}
/* Send End-of-Interrupt to the PIC */
if (IrqNumber >= 8) PicWriteCommand(PIC_SLAVE_CMD, PIC_OCW2_EOI);
PicWriteCommand(PIC_MASTER_CMD, PIC_OCW2_EOI);
if (IrqNumber >= 8) IOWriteB(PIC_SLAVE_CMD, PIC_OCW2_EOI);
IOWriteB(PIC_MASTER_CMD, PIC_OCW2_EOI);
}
/* EOF */

View file

@ -55,32 +55,33 @@ typedef struct _EMULATOR_IOPORT_HANDLERS
*/
EMULATOR_IOPORT_HANDLERS IoPortProc[EMULATOR_MAX_IOPORTS_NUM] = {{NULL}};
/* PRIVATE FUNCTIONS **********************************************************/
/* PUBLIC FUNCTIONS ***********************************************************/
static VOID
IOReadB(ULONG Port,
PUCHAR Buffer)
UCHAR
IOReadB(ULONG Port)
{
if (IoPortProc[Port].hVdd == INVALID_HANDLE_VALUE &&
IoPortProc[Port].IoHandlers.InB)
{
*Buffer = IoPortProc[Port].IoHandlers.InB(Port);
return IoPortProc[Port].IoHandlers.InB(Port);
}
else if (IoPortProc[Port].hVdd > 0 &&
IoPortProc[Port].VddIoHandlers.inb_handler)
{
UCHAR Data;
ASSERT(Port <= MAXWORD);
IoPortProc[Port].VddIoHandlers.inb_handler((WORD)Port, Buffer);
IoPortProc[Port].VddIoHandlers.inb_handler((WORD)Port, &Data);
return Data;
}
else
{
/* Return an empty port byte value */
DPRINT("Read from unknown port: 0x%X\n", Port);
*Buffer = 0xFF;
return 0xFF;
}
}
static VOID
VOID
IOReadStrB(ULONG Port,
PUCHAR Buffer,
ULONG Count)
@ -99,24 +100,25 @@ IOReadStrB(ULONG Port,
}
else
{
while (Count--) IOReadB(Port, Buffer++);
while (Count--)
*Buffer++ = IOReadB(Port);
}
}
static VOID
IOWriteB(ULONG Port,
PUCHAR Buffer)
VOID
IOWriteB(ULONG Port,
UCHAR Buffer)
{
if (IoPortProc[Port].hVdd == INVALID_HANDLE_VALUE &&
IoPortProc[Port].IoHandlers.OutB)
{
IoPortProc[Port].IoHandlers.OutB(Port, *Buffer);
IoPortProc[Port].IoHandlers.OutB(Port, Buffer);
}
else if (IoPortProc[Port].hVdd > 0 &&
IoPortProc[Port].VddIoHandlers.outb_handler)
{
ASSERT(Port <= MAXWORD);
IoPortProc[Port].VddIoHandlers.outb_handler((WORD)Port, *Buffer);
IoPortProc[Port].VddIoHandlers.outb_handler((WORD)Port, Buffer);
}
else
{
@ -125,7 +127,7 @@ IOWriteB(ULONG Port,
}
}
static VOID
VOID
IOWriteStrB(ULONG Port,
PUCHAR Buffer,
ULONG Count)
@ -144,37 +146,38 @@ IOWriteStrB(ULONG Port,
}
else
{
while (Count--) IOWriteB(Port, Buffer++);
while (Count--) IOWriteB(Port, *Buffer++);
}
}
static VOID
IOReadW(ULONG Port,
PUSHORT Buffer)
USHORT
IOReadW(ULONG Port)
{
if (IoPortProc[Port].hVdd == INVALID_HANDLE_VALUE &&
IoPortProc[Port].IoHandlers.InW)
{
*Buffer = IoPortProc[Port].IoHandlers.InW(Port);
return IoPortProc[Port].IoHandlers.InW(Port);
}
else if (IoPortProc[Port].hVdd > 0 &&
IoPortProc[Port].VddIoHandlers.inw_handler)
{
USHORT Data;
ASSERT(Port <= MAXWORD);
IoPortProc[Port].VddIoHandlers.inw_handler((WORD)Port, Buffer);
IoPortProc[Port].VddIoHandlers.inw_handler((WORD)Port, &Data);
return Data;
}
else
{
UCHAR Low, High;
// FIXME: Is it ok on Little endian and Big endian ??
IOReadB(Port, &Low);
IOReadB(Port + sizeof(UCHAR), &High);
*Buffer = MAKEWORD(Low, High);
Low = IOReadB(Port);
High = IOReadB(Port + sizeof(UCHAR));
return MAKEWORD(Low, High);
}
}
static VOID
VOID
IOReadStrW(ULONG Port,
PUSHORT Buffer,
ULONG Count)
@ -193,38 +196,35 @@ IOReadStrW(ULONG Port,
}
else
{
while (Count--) IOReadW(Port, Buffer++);
while (Count--)
*Buffer++ = IOReadW(Port);
}
}
static VOID
IOWriteW(ULONG Port,
PUSHORT Buffer)
VOID
IOWriteW(ULONG Port,
USHORT Buffer)
{
if (IoPortProc[Port].hVdd == INVALID_HANDLE_VALUE &&
IoPortProc[Port].IoHandlers.OutW)
{
IoPortProc[Port].IoHandlers.OutW(Port, *Buffer);
IoPortProc[Port].IoHandlers.OutW(Port, Buffer);
}
else if (IoPortProc[Port].hVdd > 0 &&
IoPortProc[Port].VddIoHandlers.outw_handler)
{
ASSERT(Port <= MAXWORD);
IoPortProc[Port].VddIoHandlers.outw_handler((WORD)Port, *Buffer);
IoPortProc[Port].VddIoHandlers.outw_handler((WORD)Port, Buffer);
}
else
{
UCHAR Low, High;
// FIXME: Is it ok on Little endian and Big endian ??
Low = LOBYTE(*Buffer);
High = HIBYTE(*Buffer);
IOWriteB(Port, &Low);
IOWriteB(Port + sizeof(UCHAR), &High);
IOWriteB(Port, LOBYTE(Buffer));
IOWriteB(Port + sizeof(UCHAR), HIBYTE(Buffer));
}
}
static VOID
VOID
IOWriteStrW(ULONG Port,
PUSHORT Buffer,
ULONG Count)
@ -243,31 +243,30 @@ IOWriteStrW(ULONG Port,
}
else
{
while (Count--) IOWriteW(Port, Buffer++);
while (Count--) IOWriteW(Port, *Buffer++);
}
}
static VOID
IOReadD(ULONG Port,
PULONG Buffer)
ULONG
IOReadD(ULONG Port)
{
if (IoPortProc[Port].hVdd == INVALID_HANDLE_VALUE &&
IoPortProc[Port].IoHandlers.InD)
{
*Buffer = IoPortProc[Port].IoHandlers.InD(Port);
return IoPortProc[Port].IoHandlers.InD(Port);
}
else
{
USHORT Low, High;
// FIXME: Is it ok on Little endian and Big endian ??
IOReadW(Port, &Low);
IOReadW(Port + sizeof(USHORT), &High);
*Buffer = MAKELONG(Low, High);
Low = IOReadW(Port);
High = IOReadW(Port + sizeof(USHORT));
return MAKELONG(Low, High);
}
}
static VOID
VOID
IOReadStrD(ULONG Port,
PULONG Buffer,
ULONG Count)
@ -279,32 +278,29 @@ IOReadStrD(ULONG Port,
}
else
{
while (Count--) IOReadD(Port, Buffer++);
while (Count--)
*Buffer++ = IOReadD(Port);
}
}
static VOID
IOWriteD(ULONG Port,
PULONG Buffer)
VOID
IOWriteD(ULONG Port,
ULONG Buffer)
{
if (IoPortProc[Port].hVdd == INVALID_HANDLE_VALUE &&
IoPortProc[Port].IoHandlers.OutD)
{
IoPortProc[Port].IoHandlers.OutD(Port, *Buffer);
IoPortProc[Port].IoHandlers.OutD(Port, Buffer);
}
else
{
USHORT Low, High;
// FIXME: Is it ok on Little endian and Big endian ??
Low = LOWORD(*Buffer);
High = HIWORD(*Buffer);
IOWriteW(Port, &Low);
IOWriteW(Port + sizeof(USHORT), &High);
IOWriteW(Port, LOWORD(Buffer));
IOWriteW(Port + sizeof(USHORT), HIWORD(Buffer));
}
}
static VOID
VOID
IOWriteStrD(ULONG Port,
PULONG Buffer,
ULONG Count)
@ -316,11 +312,10 @@ IOWriteStrD(ULONG Port,
}
else
{
while (Count--) IOWriteD(Port, Buffer++);
while (Count--) IOWriteD(Port, *Buffer++);
}
}
/* PUBLIC FUNCTIONS ***********************************************************/
VOID RegisterIoPort(ULONG Port,
EMULATOR_INB_PROC InHandler,
@ -364,21 +359,21 @@ EmulatorReadIo(PFAST486_STATE State,
if (DataSize == sizeof(UCHAR))
{
if (DataCount == 1)
IOReadB(Port, Buffer);
*(PUCHAR)Buffer = IOReadB(Port);
else
IOReadStrB(Port, Buffer, DataCount);
}
else if (DataSize == sizeof(USHORT))
{
if (DataCount == 1)
IOReadW(Port, Buffer);
*(PUSHORT)Buffer = IOReadW(Port);
else
IOReadStrW(Port, Buffer, DataCount);
}
else if (DataSize == sizeof(ULONG))
{
if (DataCount == 1)
IOReadD(Port, Buffer);
*(PULONG)Buffer = IOReadD(Port);
else
IOReadStrD(Port, Buffer, DataCount);
}
@ -397,7 +392,7 @@ EmulatorReadIo(PFAST486_STATE State,
NewDataSize = NewDataSize % sizeof(ULONG);
while (Count--)
{
IOReadD(CurrentPort, (PULONG)Address);
*(PULONG)Address = IOReadD(CurrentPort);
CurrentPort += sizeof(ULONG);
Address += sizeof(ULONG);
}
@ -407,7 +402,7 @@ EmulatorReadIo(PFAST486_STATE State,
NewDataSize = NewDataSize % sizeof(USHORT);
while (Count--)
{
IOReadW(CurrentPort, (PUSHORT)Address);
*(PUSHORT)Address = IOReadW(CurrentPort);
CurrentPort += sizeof(USHORT);
Address += sizeof(USHORT);
}
@ -417,7 +412,7 @@ EmulatorReadIo(PFAST486_STATE State,
NewDataSize = NewDataSize % sizeof(UCHAR);
while (Count--)
{
IOReadB(CurrentPort, (PUCHAR)Address);
*(PUCHAR)Address = IOReadB(CurrentPort);
CurrentPort += sizeof(UCHAR);
Address += sizeof(UCHAR);
}
@ -442,21 +437,21 @@ EmulatorWriteIo(PFAST486_STATE State,
if (DataSize == sizeof(UCHAR))
{
if (DataCount == 1)
IOWriteB(Port, Buffer);
IOWriteB(Port, *(PUCHAR)Buffer);
else
IOWriteStrB(Port, Buffer, DataCount);
}
else if (DataSize == sizeof(USHORT))
{
if (DataCount == 1)
IOWriteW(Port, Buffer);
IOWriteW(Port, *(PUSHORT)Buffer);
else
IOWriteStrW(Port, Buffer, DataCount);
}
else if (DataSize == sizeof(ULONG))
{
if (DataCount == 1)
IOWriteD(Port, Buffer);
IOWriteD(Port, *(PULONG)Buffer);
else
IOWriteStrD(Port, Buffer, DataCount);
}
@ -475,7 +470,7 @@ EmulatorWriteIo(PFAST486_STATE State,
NewDataSize = NewDataSize % sizeof(ULONG);
while (Count--)
{
IOWriteD(CurrentPort, (PULONG)Address);
IOWriteD(CurrentPort, *(PULONG)Address);
CurrentPort += sizeof(ULONG);
Address += sizeof(ULONG);
}
@ -485,7 +480,7 @@ EmulatorWriteIo(PFAST486_STATE State,
NewDataSize = NewDataSize % sizeof(USHORT);
while (Count--)
{
IOWriteW(CurrentPort, (PUSHORT)Address);
IOWriteW(CurrentPort, *(PUSHORT)Address);
CurrentPort += sizeof(USHORT);
Address += sizeof(USHORT);
}
@ -495,7 +490,7 @@ EmulatorWriteIo(PFAST486_STATE State,
NewDataSize = NewDataSize % sizeof(UCHAR);
while (Count--)
{
IOWriteB(CurrentPort, (PUCHAR)Address);
IOWriteB(CurrentPort, *(PUCHAR)Address);
CurrentPort += sizeof(UCHAR);
Address += sizeof(UCHAR);
}

View file

@ -33,6 +33,52 @@ typedef VOID (WINAPI *EMULATOR_OUTSW_PROC)(ULONG Port, PUSHORT Buffer, ULONG Cou
typedef VOID (WINAPI *EMULATOR_OUTSD_PROC)(ULONG Port, PULONG Buffer, ULONG Count);
UCHAR
IOReadB(ULONG Port);
VOID
IOReadStrB(ULONG Port,
PUCHAR Buffer,
ULONG Count);
VOID
IOWriteB(ULONG Port,
UCHAR Buffer);
VOID
IOWriteStrB(ULONG Port,
PUCHAR Buffer,
ULONG Count);
USHORT
IOReadW(ULONG Port);
VOID
IOReadStrW(ULONG Port,
PUSHORT Buffer,
ULONG Count);
VOID
IOWriteW(ULONG Port,
USHORT Buffer);
VOID
IOWriteStrW(ULONG Port,
PUSHORT Buffer,
ULONG Count);
ULONG
IOReadD(ULONG Port);
VOID
IOReadStrD(ULONG Port,
PULONG Buffer,
ULONG Count);
VOID
IOWriteD(ULONG Port,
ULONG Buffer);
VOID
IOWriteStrD(ULONG Port,
PULONG Buffer,
ULONG Count);
VOID RegisterIoPort(ULONG Port,
EMULATOR_INB_PROC InHandler,
EMULATOR_OUTB_PROC OutHandler);

View file

@ -19,9 +19,9 @@
static PIC MasterPic, SlavePic;
/* PUBLIC FUNCTIONS ***********************************************************/
/* PRIVATE FUNCTIONS **********************************************************/
BYTE PicReadCommand(BYTE Port)
static BYTE PicReadCommand(BYTE Port)
{
PPIC Pic;
@ -42,7 +42,7 @@ BYTE PicReadCommand(BYTE Port)
}
}
VOID PicWriteCommand(BYTE Port, BYTE Value)
static VOID PicWriteCommand(BYTE Port, BYTE Value)
{
PPIC Pic;
@ -88,14 +88,14 @@ VOID PicWriteCommand(BYTE Port, BYTE Value)
}
}
BYTE PicReadData(BYTE Port)
static BYTE PicReadData(BYTE Port)
{
/* Read the mask register */
if (Port == PIC_MASTER_DATA) return MasterPic.MaskRegister;
else return SlavePic.MaskRegister;
}
VOID PicWriteData(BYTE Port, BYTE Value)
static VOID PicWriteData(BYTE Port, BYTE Value)
{
PPIC Pic;
@ -154,7 +154,7 @@ VOID PicWriteData(BYTE Port, BYTE Value)
Pic->Initialization = FALSE;
}
BYTE WINAPI PicReadPort(ULONG Port)
static BYTE WINAPI PicReadPort(ULONG Port)
{
switch (Port)
{
@ -174,7 +174,7 @@ BYTE WINAPI PicReadPort(ULONG Port)
return 0;
}
VOID WINAPI PicWritePort(ULONG Port, BYTE Data)
static VOID WINAPI PicWritePort(ULONG Port, BYTE Data)
{
switch (Port)
{
@ -194,11 +194,13 @@ VOID WINAPI PicWritePort(ULONG Port, BYTE Data)
}
}
/* PUBLIC FUNCTIONS ***********************************************************/
VOID PicInterruptRequest(BYTE Number)
{
BYTE i;
if (Number >= 0 && Number < 8)
if (/* Number >= 0 && */ Number < 8)
{
/* Check if any of the higher-priority interrupts are busy */
for (i = 0; i <= Number; i++)

View file

@ -48,8 +48,6 @@ typedef struct _PIC
/* FUNCTIONS ******************************************************************/
VOID PicWriteCommand(BYTE Port, BYTE Value);
VOID PicWriteData(BYTE Port, BYTE Value);
VOID PicInterruptRequest(BYTE Number);
BYTE PicGetInterrupt(VOID);
BOOLEAN PicInitialize(VOID);

View file

@ -92,9 +92,7 @@ Done:
return Result;
}
/* PUBLIC FUNCTIONS ***********************************************************/
BYTE WINAPI PS2ReadPort(ULONG Port)
static BYTE WINAPI PS2ReadPort(ULONG Port)
{
if (Port == PS2_CONTROL_PORT)
{
@ -125,7 +123,7 @@ BYTE WINAPI PS2ReadPort(ULONG Port)
else return 0;
}
VOID WINAPI PS2WritePort(ULONG Port, BYTE Data)
static VOID WINAPI PS2WritePort(ULONG Port, BYTE Data)
{
if (Port == PS2_CONTROL_PORT)
{
@ -283,16 +281,7 @@ VOID WINAPI PS2WritePort(ULONG Port, BYTE Data)
}
}
VOID GenerateKeyboardInterrupts(VOID)
{
if (KeyboardQueuePop(&KeyboardData))
{
/* IRQ 1 */
PicInterruptRequest(1);
}
}
DWORD WINAPI InputThreadProc(LPVOID Parameter)
static DWORD WINAPI InputThreadProc(LPVOID Parameter)
{
INT i;
HANDLE ConsoleInput = (HANDLE)Parameter;
@ -348,6 +337,17 @@ DWORD WINAPI InputThreadProc(LPVOID Parameter)
return 0;
}
/* PUBLIC FUNCTIONS ***********************************************************/
VOID GenerateKeyboardInterrupts(VOID)
{
if (KeyboardQueuePop(&KeyboardData))
{
/* IRQ 1 */
PicInterruptRequest(1);
}
}
BOOLEAN PS2Initialize(HANDLE ConsoleInput)
{
/* Create the mutex */

View file

@ -24,11 +24,9 @@
/* FUNCTIONS ******************************************************************/
VOID GenerateKeyboardInterrupts(VOID);
BOOLEAN PS2Initialize(HANDLE ConsoleInput);
VOID PS2Cleanup(VOID);
BYTE WINAPI PS2ReadPort(ULONG Port);
VOID WINAPI PS2WritePort(ULONG Port, BYTE Data);
VOID GenerateKeyboardInterrupts(VOID);
#endif // _PS2_H_

View file

@ -1004,6 +1004,253 @@ static VOID VgaUpdateTextCursor(VOID)
CursorMoved = FALSE;
}
static BYTE WINAPI VgaReadPort(ULONG Port)
{
DPRINT("VgaReadPort: Port 0x%X\n", Port);
switch (Port)
{
case VGA_MISC_READ:
return VgaMiscRegister;
case VGA_INSTAT0_READ:
return 0; // Not implemented
case VGA_INSTAT1_READ_MONO:
case VGA_INSTAT1_READ_COLOR:
{
BYTE Result = 0;
/* Reset the AC latch */
VgaAcLatch = FALSE;
/* Set a flag if there is a vertical or horizontal retrace */
if (InVerticalRetrace || InHorizontalRetrace) Result |= VGA_STAT_DD;
/* Set an additional flag if there was a vertical retrace */
if (InVerticalRetrace) Result |= VGA_STAT_VRETRACE;
/* Clear the flags */
InHorizontalRetrace = InVerticalRetrace = FALSE;
return Result;
}
case VGA_FEATURE_READ:
return VgaFeatureRegister;
case VGA_AC_INDEX:
return VgaAcIndex;
case VGA_AC_READ:
return VgaAcRegisters[VgaAcIndex];
case VGA_SEQ_INDEX:
return VgaSeqIndex;
case VGA_SEQ_DATA:
return VgaSeqRegisters[VgaSeqIndex];
case VGA_DAC_MASK:
return VgaDacMask;
case VGA_DAC_READ_INDEX:
/* This returns the read/write state */
return (VgaDacReadWrite ? 0 : 3);
case VGA_DAC_WRITE_INDEX:
return (VgaDacIndex / 3);
case VGA_DAC_DATA:
{
/* Ignore reads in write mode */
if (!VgaDacReadWrite)
{
BYTE Data = VgaDacRegisters[VgaDacIndex++];
VgaDacIndex %= VGA_PALETTE_SIZE;
return Data;
}
break;
}
case VGA_CRTC_INDEX_MONO:
case VGA_CRTC_INDEX_COLOR:
return VgaCrtcIndex;
case VGA_CRTC_DATA_MONO:
case VGA_CRTC_DATA_COLOR:
return VgaCrtcRegisters[VgaCrtcIndex];
case VGA_GC_INDEX:
return VgaGcIndex;
case VGA_GC_DATA:
return VgaGcRegisters[VgaGcIndex];
default:
DPRINT1("VgaReadPort: Unknown port 0x%X\n", Port);
break;
}
return 0;
}
static VOID WINAPI VgaWritePort(ULONG Port, BYTE Data)
{
DPRINT("VgaWritePort: Port 0x%X, Data 0x%02X\n", Port, Data);
switch (Port)
{
case VGA_MISC_WRITE:
{
VgaMiscRegister = Data;
if (VgaMiscRegister & 0x01)
{
/* Color emulation */
DPRINT1("Color emulation\n");
/* Register the new I/O Ports */
RegisterIoPort(0x3D4, VgaReadPort, VgaWritePort); // VGA_CRTC_INDEX_COLOR
RegisterIoPort(0x3D5, VgaReadPort, VgaWritePort); // VGA_CRTC_DATA_COLOR
RegisterIoPort(0x3DA, VgaReadPort, VgaWritePort); // VGA_INSTAT1_READ_COLOR, VGA_FEATURE_WRITE_COLOR
/* Unregister the old ones */
UnregisterIoPort(0x3B4); // VGA_CRTC_INDEX_MONO
UnregisterIoPort(0x3B5); // VGA_CRTC_DATA_MONO
UnregisterIoPort(0x3BA); // VGA_INSTAT1_READ_MONO, VGA_FEATURE_WRITE_MONO
}
else
{
/* Monochrome emulation */
DPRINT1("Monochrome emulation\n");
/* Register the new I/O Ports */
RegisterIoPort(0x3B4, VgaReadPort, VgaWritePort); // VGA_CRTC_INDEX_MONO
RegisterIoPort(0x3B5, VgaReadPort, VgaWritePort); // VGA_CRTC_DATA_MONO
RegisterIoPort(0x3BA, VgaReadPort, VgaWritePort); // VGA_INSTAT1_READ_MONO, VGA_FEATURE_WRITE_MONO
/* Unregister the old ones */
UnregisterIoPort(0x3D4); // VGA_CRTC_INDEX_COLOR
UnregisterIoPort(0x3D5); // VGA_CRTC_DATA_COLOR
UnregisterIoPort(0x3DA); // VGA_INSTAT1_READ_COLOR, VGA_FEATURE_WRITE_COLOR
}
// if (VgaMiscRegister & 0x02) { /* Enable RAM access */ } else { /* Disable RAM access */ }
break;
}
case VGA_FEATURE_WRITE_MONO:
case VGA_FEATURE_WRITE_COLOR:
{
VgaFeatureRegister = Data;
break;
}
case VGA_AC_INDEX:
// case VGA_AC_WRITE:
{
if (!VgaAcLatch)
{
/* Change the index */
BYTE Index = Data & 0x1F;
if (Index < VGA_AC_MAX_REG) VgaAcIndex = Index;
/*
* Change palette protection by checking for
* the Palette Address Source bit.
*/
VgaAcPalDisable = (Data & 0x20) ? TRUE : FALSE;
}
else
{
/* Write the data */
VgaWriteAc(Data);
}
/* Toggle the latch */
VgaAcLatch = !VgaAcLatch;
break;
}
case VGA_SEQ_INDEX:
{
/* Set the sequencer index register */
if (Data < VGA_SEQ_MAX_REG) VgaSeqIndex = Data;
break;
}
case VGA_SEQ_DATA:
{
/* Call the sequencer function */
VgaWriteSequencer(Data);
break;
}
case VGA_DAC_MASK:
{
VgaDacMask = Data;
break;
}
case VGA_DAC_READ_INDEX:
{
VgaDacReadWrite = FALSE;
VgaDacIndex = Data * 3;
break;
}
case VGA_DAC_WRITE_INDEX:
{
VgaDacReadWrite = TRUE;
VgaDacIndex = Data * 3;
break;
}
case VGA_DAC_DATA:
{
/* Ignore writes in read mode */
if (VgaDacReadWrite) VgaWriteDac(Data & 0x3F);
break;
}
case VGA_CRTC_INDEX_MONO:
case VGA_CRTC_INDEX_COLOR:
{
/* Set the CRTC index register */
if (Data < VGA_CRTC_MAX_REG) VgaCrtcIndex = Data;
break;
}
case VGA_CRTC_DATA_MONO:
case VGA_CRTC_DATA_COLOR:
{
/* Call the CRTC function */
VgaWriteCrtc(Data);
break;
}
case VGA_GC_INDEX:
{
/* Set the GC index register */
if (Data < VGA_GC_MAX_REG) VgaGcIndex = Data;
break;
}
case VGA_GC_DATA:
{
/* Call the GC function */
VgaWriteGc(Data);
break;
}
default:
DPRINT1("VgaWritePort: Unknown port 0x%X\n", Port);
break;
}
}
/* PUBLIC FUNCTIONS ***********************************************************/
DWORD VgaGetVideoBaseAddress(VOID)
@ -1226,253 +1473,6 @@ VOID VgaWriteMemory(DWORD Address, LPBYTE Buffer, DWORD Size)
}
}
BYTE WINAPI VgaReadPort(ULONG Port)
{
DPRINT("VgaReadPort: Port 0x%X\n", Port);
switch (Port)
{
case VGA_MISC_READ:
return VgaMiscRegister;
case VGA_INSTAT0_READ:
return 0; // Not implemented
case VGA_INSTAT1_READ_MONO:
case VGA_INSTAT1_READ_COLOR:
{
BYTE Result = 0;
/* Reset the AC latch */
VgaAcLatch = FALSE;
/* Set a flag if there is a vertical or horizontal retrace */
if (InVerticalRetrace || InHorizontalRetrace) Result |= VGA_STAT_DD;
/* Set an additional flag if there was a vertical retrace */
if (InVerticalRetrace) Result |= VGA_STAT_VRETRACE;
/* Clear the flags */
InHorizontalRetrace = InVerticalRetrace = FALSE;
return Result;
}
case VGA_FEATURE_READ:
return VgaFeatureRegister;
case VGA_AC_INDEX:
return VgaAcIndex;
case VGA_AC_READ:
return VgaAcRegisters[VgaAcIndex];
case VGA_SEQ_INDEX:
return VgaSeqIndex;
case VGA_SEQ_DATA:
return VgaSeqRegisters[VgaSeqIndex];
case VGA_DAC_MASK:
return VgaDacMask;
case VGA_DAC_READ_INDEX:
/* This returns the read/write state */
return (VgaDacReadWrite ? 0 : 3);
case VGA_DAC_WRITE_INDEX:
return (VgaDacIndex / 3);
case VGA_DAC_DATA:
{
/* Ignore reads in write mode */
if (!VgaDacReadWrite)
{
BYTE Data = VgaDacRegisters[VgaDacIndex++];
VgaDacIndex %= VGA_PALETTE_SIZE;
return Data;
}
break;
}
case VGA_CRTC_INDEX_MONO:
case VGA_CRTC_INDEX_COLOR:
return VgaCrtcIndex;
case VGA_CRTC_DATA_MONO:
case VGA_CRTC_DATA_COLOR:
return VgaCrtcRegisters[VgaCrtcIndex];
case VGA_GC_INDEX:
return VgaGcIndex;
case VGA_GC_DATA:
return VgaGcRegisters[VgaGcIndex];
default:
DPRINT1("VgaReadPort: Unknown port 0x%X\n", Port);
break;
}
return 0;
}
VOID WINAPI VgaWritePort(ULONG Port, BYTE Data)
{
DPRINT("VgaWritePort: Port 0x%X, Data 0x%02X\n", Port, Data);
switch (Port)
{
case VGA_MISC_WRITE:
{
VgaMiscRegister = Data;
if (VgaMiscRegister & 0x01)
{
/* Color emulation */
DPRINT1("Color emulation\n");
/* Register the new I/O Ports */
RegisterIoPort(0x3D4, VgaReadPort, VgaWritePort); // VGA_CRTC_INDEX_COLOR
RegisterIoPort(0x3D5, VgaReadPort, VgaWritePort); // VGA_CRTC_DATA_COLOR
RegisterIoPort(0x3DA, VgaReadPort, VgaWritePort); // VGA_INSTAT1_READ_COLOR, VGA_FEATURE_WRITE_COLOR
/* Unregister the old ones */
UnregisterIoPort(0x3B4); // VGA_CRTC_INDEX_MONO
UnregisterIoPort(0x3B5); // VGA_CRTC_DATA_MONO
UnregisterIoPort(0x3BA); // VGA_INSTAT1_READ_MONO, VGA_FEATURE_WRITE_MONO
}
else
{
/* Monochrome emulation */
DPRINT1("Monochrome emulation\n");
/* Register the new I/O Ports */
RegisterIoPort(0x3B4, VgaReadPort, VgaWritePort); // VGA_CRTC_INDEX_MONO
RegisterIoPort(0x3B5, VgaReadPort, VgaWritePort); // VGA_CRTC_DATA_MONO
RegisterIoPort(0x3BA, VgaReadPort, VgaWritePort); // VGA_INSTAT1_READ_MONO, VGA_FEATURE_WRITE_MONO
/* Unregister the old ones */
UnregisterIoPort(0x3D4); // VGA_CRTC_INDEX_COLOR
UnregisterIoPort(0x3D5); // VGA_CRTC_DATA_COLOR
UnregisterIoPort(0x3DA); // VGA_INSTAT1_READ_COLOR, VGA_FEATURE_WRITE_COLOR
}
// if (VgaMiscRegister & 0x02) { /* Enable RAM access */ } else { /* Disable RAM access */ }
break;
}
case VGA_FEATURE_WRITE_MONO:
case VGA_FEATURE_WRITE_COLOR:
{
VgaFeatureRegister = Data;
break;
}
case VGA_AC_INDEX:
// case VGA_AC_WRITE:
{
if (!VgaAcLatch)
{
/* Change the index */
BYTE Index = Data & 0x1F;
if (Index < VGA_AC_MAX_REG) VgaAcIndex = Index;
/*
* Change palette protection by checking for
* the Palette Address Source bit.
*/
VgaAcPalDisable = (Data & 0x20) ? TRUE : FALSE;
}
else
{
/* Write the data */
VgaWriteAc(Data);
}
/* Toggle the latch */
VgaAcLatch = !VgaAcLatch;
break;
}
case VGA_SEQ_INDEX:
{
/* Set the sequencer index register */
if (Data < VGA_SEQ_MAX_REG) VgaSeqIndex = Data;
break;
}
case VGA_SEQ_DATA:
{
/* Call the sequencer function */
VgaWriteSequencer(Data);
break;
}
case VGA_DAC_MASK:
{
VgaDacMask = Data;
break;
}
case VGA_DAC_READ_INDEX:
{
VgaDacReadWrite = FALSE;
VgaDacIndex = Data * 3;
break;
}
case VGA_DAC_WRITE_INDEX:
{
VgaDacReadWrite = TRUE;
VgaDacIndex = Data * 3;
break;
}
case VGA_DAC_DATA:
{
/* Ignore writes in read mode */
if (VgaDacReadWrite) VgaWriteDac(Data & 0x3F);
break;
}
case VGA_CRTC_INDEX_MONO:
case VGA_CRTC_INDEX_COLOR:
{
/* Set the CRTC index register */
if (Data < VGA_CRTC_MAX_REG) VgaCrtcIndex = Data;
break;
}
case VGA_CRTC_DATA_MONO:
case VGA_CRTC_DATA_COLOR:
{
/* Call the CRTC function */
VgaWriteCrtc(Data);
break;
}
case VGA_GC_INDEX:
{
/* Set the GC index register */
if (Data < VGA_GC_MAX_REG) VgaGcIndex = Data;
break;
}
case VGA_GC_DATA:
{
/* Call the GC function */
VgaWriteGc(Data);
break;
}
default:
DPRINT1("VgaWritePort: Unknown port 0x%X\n", Port);
break;
}
}
VOID VgaClearMemory(VOID)
{
ZeroMemory(VgaMemory, sizeof(VgaMemory));

View file

@ -260,9 +260,6 @@ VOID VgaWriteMemory(DWORD Address, LPBYTE Buffer, DWORD Size);
VOID VgaClearMemory(VOID);
BOOLEAN VgaInitialize(HANDLE TextHandle);
BYTE WINAPI VgaReadPort(ULONG Port);
VOID WINAPI VgaWritePort(ULONG Port, BYTE Data);
#endif // _VGA_H_
/* EOF */