[NTVDM]
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sat, 11 Jan 2014 14:40:03 +0000 (14:40 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sat, 11 Jan 2014 14:40:03 +0000 (14:40 +0000)
- Export and use IORead/WriteXX (instead of PicRead/WriteXX or VgaRead/WritePort)
- static'ify some functions.

svn path=/branches/ntvdm/; revision=61580

subsystems/ntvdm/bios.c
subsystems/ntvdm/io.c
subsystems/ntvdm/io.h
subsystems/ntvdm/pic.c
subsystems/ntvdm/pic.h
subsystems/ntvdm/ps2.c
subsystems/ntvdm/ps2.h
subsystems/ntvdm/vga.c
subsystems/ntvdm/vga.h

index 9c060be..0282498 100644 (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 */
index f54ddf0..a450922 100644 (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);
             }
index 205be02..9ed80ec 100644 (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);
index d955220..d820cb6 100644 (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++)
index f24f31c..829d2e4 100644 (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);
index cc72ae6..2a9f2f8 100644 (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 */
index 312a57e..369422a 100644 (file)
 
 /* 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_
 
index 7702446..56bdee3 100644 (file)
@@ -1004,229 +1004,7 @@ static VOID VgaUpdateTextCursor(VOID)
     CursorMoved = FALSE;
 }
 
-/* PUBLIC FUNCTIONS ***********************************************************/
-
-DWORD VgaGetVideoBaseAddress(VOID)
-{
-    return MemoryBase[(VgaGcRegisters[VGA_GC_MISC_REG] >> 2) & 0x03];
-}
-
-DWORD VgaGetVideoLimitAddress(VOID)
-{
-    return MemoryLimit[(VgaGcRegisters[VGA_GC_MISC_REG] >> 2) & 0x03];
-}
-
-COORD VgaGetDisplayResolution(VOID)
-{
-    COORD Resolution;
-    BYTE MaximumScanLine = 1 + (VgaCrtcRegisters[VGA_CRTC_MAX_SCAN_LINE_REG] & 0x1F);
-
-    /* The low 8 bits are in the display registers */
-    Resolution.X = VgaCrtcRegisters[VGA_CRTC_END_HORZ_DISP_REG];
-    Resolution.Y = VgaCrtcRegisters[VGA_CRTC_VERT_DISP_END_REG];
-
-    /* Set the top bits from the overflow register */
-    if (VgaCrtcRegisters[VGA_CRTC_OVERFLOW_REG] & VGA_CRTC_OVERFLOW_VDE8)
-    {
-        Resolution.Y |= 1 << 8;
-    }
-    if (VgaCrtcRegisters[VGA_CRTC_OVERFLOW_REG] & VGA_CRTC_OVERFLOW_VDE9)
-    {
-        Resolution.Y |= 1 << 9;
-    }
-
-    /* Increase the values by 1 */
-    Resolution.X++;
-    Resolution.Y++;
-
-    if (VgaGcRegisters[VGA_GC_MISC_REG] & VGA_GC_MISC_NOALPHA)
-    {
-        /* Multiply the horizontal resolution by the 9/8 dot mode */
-        Resolution.X *= (VgaSeqRegisters[VGA_SEQ_CLOCK_REG] & VGA_SEQ_CLOCK_98DM)
-                        ? 8 : 9;
-
-        /* The horizontal resolution is halved in 8-bit mode */
-        if (VgaAcRegisters[VGA_AC_CONTROL_REG] & VGA_AC_CONTROL_8BIT) Resolution.X /= 2;
-    }
-
-    if (VgaCrtcRegisters[VGA_CRTC_MAX_SCAN_LINE_REG] & VGA_CRTC_MAXSCANLINE_DOUBLE)
-    {
-        /* Halve the vertical resolution */
-        Resolution.Y >>= 1;
-    }
-    else
-    {
-        /* Divide the vertical resolution by the maximum scan line (== font size in text mode) */
-        Resolution.Y /= MaximumScanLine;
-    }
-
-    /* Return the resolution */
-    return Resolution;
-}
-
-VOID VgaRefreshDisplay(VOID)
-{
-    HANDLE ConsoleBufferHandle = NULL;
-    COORD Resolution;
-
-    /* Set the vertical retrace flag */
-    InVerticalRetrace = TRUE;
-
-    /* If nothing has changed, just return */
-    if (!ModeChanged && !CursorMoved && !PaletteChanged && !NeedsUpdate)
-        return;
-
-    /* Change the display mode */
-    if (ModeChanged) VgaChangeMode();
-
-    /* Change the text cursor location */
-    if (CursorMoved) VgaUpdateTextCursor();
-
-    /* Retrieve the current resolution */
-    Resolution = VgaGetDisplayResolution();
-
-    if (PaletteChanged)
-    {
-        /* Trigger a full update of the screen */
-        NeedsUpdate = TRUE;
-        UpdateRectangle.Left = 0;
-        UpdateRectangle.Top = 0;
-        UpdateRectangle.Right = Resolution.X;
-        UpdateRectangle.Bottom = Resolution.Y;
-
-        PaletteChanged = FALSE;
-    }
-
-    /* Update the contents of the framebuffer */
-    VgaUpdateFramebuffer();
-
-    /* Ignore if there's nothing to update */
-    if (!NeedsUpdate) return;
-
-    DPRINT("Updating screen rectangle (%d, %d, %d, %d)\n",
-           UpdateRectangle.Left,
-           UpdateRectangle.Top,
-           UpdateRectangle.Right,
-           UpdateRectangle.Bottom);
-
-    /* Check if this is text mode or graphics mode */
-    if (VgaGcRegisters[VGA_GC_MISC_REG] & VGA_GC_MISC_NOALPHA)
-    {
-        /* Graphics mode */
-        ConsoleBufferHandle = GraphicsConsoleBuffer;
-    }
-    else
-    {
-        /* Text mode */
-        COORD Origin = { UpdateRectangle.Left, UpdateRectangle.Top };
-        ConsoleBufferHandle = TextConsoleBuffer;
-
-        /* Write the data to the console */
-        WriteConsoleOutputA(TextConsoleBuffer,
-                            (PCHAR_INFO)ConsoleFramebuffer,
-                            Resolution,
-                            Origin,
-                            &UpdateRectangle);
-    }
-
-    /* In DoubleVision mode, scale the update rectangle */
-    if (DoubleVision)
-    {
-        UpdateRectangle.Left *= 2;
-        UpdateRectangle.Top  *= 2;
-        UpdateRectangle.Right  = UpdateRectangle.Right  * 2 + 1;
-        UpdateRectangle.Bottom = UpdateRectangle.Bottom * 2 + 1;
-    }
-
-    /* Redraw the screen */
-    InvalidateConsoleDIBits(ConsoleBufferHandle, &UpdateRectangle);
-
-    /* Clear the update flag */
-    NeedsUpdate = FALSE;
-}
-
-VOID VgaHorizontalRetrace(VOID)
-{
-    /* Set the flag */
-    InHorizontalRetrace = TRUE;
-}
-
-VOID VgaReadMemory(DWORD Address, LPBYTE Buffer, DWORD Size)
-{
-    DWORD i;
-    DWORD VideoAddress;
-
-    DPRINT("VgaReadMemory: Address 0x%08X, Size %lu\n", Address, Size);
-
-    /* Ignore if video RAM access is disabled */
-    if ((VgaMiscRegister & VGA_MISC_RAM_ENABLED) == 0) return;
-
-    /* Loop through each byte */
-    for (i = 0; i < Size; i++)
-    {
-        VideoAddress = VgaTranslateReadAddress(Address + i);
-
-        /* Load the latch registers */
-        VgaLatchRegisters[0] = VgaMemory[LOWORD(VideoAddress)];
-        VgaLatchRegisters[1] = VgaMemory[VGA_BANK_SIZE + LOWORD(VideoAddress)];
-        VgaLatchRegisters[2] = VgaMemory[(2 * VGA_BANK_SIZE) + LOWORD(VideoAddress)];
-        VgaLatchRegisters[3] = VgaMemory[(3 * VGA_BANK_SIZE) + LOWORD(VideoAddress)];
-
-        /* Copy the value to the buffer */
-        Buffer[i] = VgaMemory[VideoAddress];
-    }
-}
-
-VOID VgaWriteMemory(DWORD Address, LPBYTE Buffer, DWORD Size)
-{
-    DWORD i, j;
-    DWORD VideoAddress;
-
-    DPRINT("VgaWriteMemory: Address 0x%08X, Size %lu\n", Address, Size);
-
-    /* Ignore if video RAM access is disabled */
-    if ((VgaMiscRegister & VGA_MISC_RAM_ENABLED) == 0) return;
-
-    /* Also ignore if write access to all planes is disabled */
-    if ((VgaSeqRegisters[VGA_SEQ_MASK_REG] & 0x0F) == 0x00) return;
-
-    /* Loop through each byte */
-    for (i = 0; i < Size; i++)
-    {
-        VideoAddress = VgaTranslateWriteAddress(Address + i);
-
-        for (j = 0; j < VGA_NUM_BANKS; j++)
-        {
-            /* Make sure the page is writeable */
-            if (!(VgaSeqRegisters[VGA_SEQ_MASK_REG] & (1 << j))) continue;
-
-            /* Check if this is chain-4 mode */
-            if (VgaSeqRegisters[VGA_SEQ_MEM_REG] & VGA_SEQ_MEM_C4)
-            {
-                if (((Address + i) & 3) != j)
-                {
-                    /* This plane will not be accessed */
-                    continue;
-                }
-            }
-
-            /* Check if this is odd-even mode */
-            if (VgaGcRegisters[VGA_GC_MODE_REG] & VGA_GC_MODE_OE)
-            {
-                if (((Address + i) & 1) != (j & 1))
-                {
-                    /* This plane will not be accessed */
-                    continue;
-                }
-            }
-
-            /* Copy the value to the VGA memory */
-            VgaMemory[VideoAddress + j * VGA_BANK_SIZE] = VgaTranslateByteForWriting(Buffer[i], j);
-        }
-    }
-}
-
-BYTE WINAPI VgaReadPort(ULONG Port)
+static BYTE WINAPI VgaReadPort(ULONG Port)
 {
     DPRINT("VgaReadPort: Port 0x%X\n", Port);
 
@@ -1318,7 +1096,7 @@ BYTE WINAPI VgaReadPort(ULONG Port)
     return 0;
 }
 
-VOID WINAPI VgaWritePort(ULONG Port, BYTE Data)
+static VOID WINAPI VgaWritePort(ULONG Port, BYTE Data)
 {
     DPRINT("VgaWritePort: Port 0x%X, Data 0x%02X\n", Port, Data);
 
@@ -1473,6 +1251,228 @@ VOID WINAPI VgaWritePort(ULONG Port, BYTE Data)
     }
 }
 
+/* PUBLIC FUNCTIONS ***********************************************************/
+
+DWORD VgaGetVideoBaseAddress(VOID)
+{
+    return MemoryBase[(VgaGcRegisters[VGA_GC_MISC_REG] >> 2) & 0x03];
+}
+
+DWORD VgaGetVideoLimitAddress(VOID)
+{
+    return MemoryLimit[(VgaGcRegisters[VGA_GC_MISC_REG] >> 2) & 0x03];
+}
+
+COORD VgaGetDisplayResolution(VOID)
+{
+    COORD Resolution;
+    BYTE MaximumScanLine = 1 + (VgaCrtcRegisters[VGA_CRTC_MAX_SCAN_LINE_REG] & 0x1F);
+
+    /* The low 8 bits are in the display registers */
+    Resolution.X = VgaCrtcRegisters[VGA_CRTC_END_HORZ_DISP_REG];
+    Resolution.Y = VgaCrtcRegisters[VGA_CRTC_VERT_DISP_END_REG];
+
+    /* Set the top bits from the overflow register */
+    if (VgaCrtcRegisters[VGA_CRTC_OVERFLOW_REG] & VGA_CRTC_OVERFLOW_VDE8)
+    {
+        Resolution.Y |= 1 << 8;
+    }
+    if (VgaCrtcRegisters[VGA_CRTC_OVERFLOW_REG] & VGA_CRTC_OVERFLOW_VDE9)
+    {
+        Resolution.Y |= 1 << 9;
+    }
+
+    /* Increase the values by 1 */
+    Resolution.X++;
+    Resolution.Y++;
+
+    if (VgaGcRegisters[VGA_GC_MISC_REG] & VGA_GC_MISC_NOALPHA)
+    {
+        /* Multiply the horizontal resolution by the 9/8 dot mode */
+        Resolution.X *= (VgaSeqRegisters[VGA_SEQ_CLOCK_REG] & VGA_SEQ_CLOCK_98DM)
+                        ? 8 : 9;
+
+        /* The horizontal resolution is halved in 8-bit mode */
+        if (VgaAcRegisters[VGA_AC_CONTROL_REG] & VGA_AC_CONTROL_8BIT) Resolution.X /= 2;
+    }
+
+    if (VgaCrtcRegisters[VGA_CRTC_MAX_SCAN_LINE_REG] & VGA_CRTC_MAXSCANLINE_DOUBLE)
+    {
+        /* Halve the vertical resolution */
+        Resolution.Y >>= 1;
+    }
+    else
+    {
+        /* Divide the vertical resolution by the maximum scan line (== font size in text mode) */
+        Resolution.Y /= MaximumScanLine;
+    }
+
+    /* Return the resolution */
+    return Resolution;
+}
+
+VOID VgaRefreshDisplay(VOID)
+{
+    HANDLE ConsoleBufferHandle = NULL;
+    COORD Resolution;
+
+    /* Set the vertical retrace flag */
+    InVerticalRetrace = TRUE;
+
+    /* If nothing has changed, just return */
+    if (!ModeChanged && !CursorMoved && !PaletteChanged && !NeedsUpdate)
+        return;
+
+    /* Change the display mode */
+    if (ModeChanged) VgaChangeMode();
+
+    /* Change the text cursor location */
+    if (CursorMoved) VgaUpdateTextCursor();
+
+    /* Retrieve the current resolution */
+    Resolution = VgaGetDisplayResolution();
+
+    if (PaletteChanged)
+    {
+        /* Trigger a full update of the screen */
+        NeedsUpdate = TRUE;
+        UpdateRectangle.Left = 0;
+        UpdateRectangle.Top = 0;
+        UpdateRectangle.Right = Resolution.X;
+        UpdateRectangle.Bottom = Resolution.Y;
+
+        PaletteChanged = FALSE;
+    }
+
+    /* Update the contents of the framebuffer */
+    VgaUpdateFramebuffer();
+
+    /* Ignore if there's nothing to update */
+    if (!NeedsUpdate) return;
+
+    DPRINT("Updating screen rectangle (%d, %d, %d, %d)\n",
+           UpdateRectangle.Left,
+           UpdateRectangle.Top,
+           UpdateRectangle.Right,
+           UpdateRectangle.Bottom);
+
+    /* Check if this is text mode or graphics mode */
+    if (VgaGcRegisters[VGA_GC_MISC_REG] & VGA_GC_MISC_NOALPHA)
+    {
+        /* Graphics mode */
+        ConsoleBufferHandle = GraphicsConsoleBuffer;
+    }
+    else
+    {
+        /* Text mode */
+        COORD Origin = { UpdateRectangle.Left, UpdateRectangle.Top };
+        ConsoleBufferHandle = TextConsoleBuffer;
+
+        /* Write the data to the console */
+        WriteConsoleOutputA(TextConsoleBuffer,
+                            (PCHAR_INFO)ConsoleFramebuffer,
+                            Resolution,
+                            Origin,
+                            &UpdateRectangle);
+    }
+
+    /* In DoubleVision mode, scale the update rectangle */
+    if (DoubleVision)
+    {
+        UpdateRectangle.Left *= 2;
+        UpdateRectangle.Top  *= 2;
+        UpdateRectangle.Right  = UpdateRectangle.Right  * 2 + 1;
+        UpdateRectangle.Bottom = UpdateRectangle.Bottom * 2 + 1;
+    }
+
+    /* Redraw the screen */
+    InvalidateConsoleDIBits(ConsoleBufferHandle, &UpdateRectangle);
+
+    /* Clear the update flag */
+    NeedsUpdate = FALSE;
+}
+
+VOID VgaHorizontalRetrace(VOID)
+{
+    /* Set the flag */
+    InHorizontalRetrace = TRUE;
+}
+
+VOID VgaReadMemory(DWORD Address, LPBYTE Buffer, DWORD Size)
+{
+    DWORD i;
+    DWORD VideoAddress;
+
+    DPRINT("VgaReadMemory: Address 0x%08X, Size %lu\n", Address, Size);
+
+    /* Ignore if video RAM access is disabled */
+    if ((VgaMiscRegister & VGA_MISC_RAM_ENABLED) == 0) return;
+
+    /* Loop through each byte */
+    for (i = 0; i < Size; i++)
+    {
+        VideoAddress = VgaTranslateReadAddress(Address + i);
+
+        /* Load the latch registers */
+        VgaLatchRegisters[0] = VgaMemory[LOWORD(VideoAddress)];
+        VgaLatchRegisters[1] = VgaMemory[VGA_BANK_SIZE + LOWORD(VideoAddress)];
+        VgaLatchRegisters[2] = VgaMemory[(2 * VGA_BANK_SIZE) + LOWORD(VideoAddress)];
+        VgaLatchRegisters[3] = VgaMemory[(3 * VGA_BANK_SIZE) + LOWORD(VideoAddress)];
+
+        /* Copy the value to the buffer */
+        Buffer[i] = VgaMemory[VideoAddress];
+    }
+}
+
+VOID VgaWriteMemory(DWORD Address, LPBYTE Buffer, DWORD Size)
+{
+    DWORD i, j;
+    DWORD VideoAddress;
+
+    DPRINT("VgaWriteMemory: Address 0x%08X, Size %lu\n", Address, Size);
+
+    /* Ignore if video RAM access is disabled */
+    if ((VgaMiscRegister & VGA_MISC_RAM_ENABLED) == 0) return;
+
+    /* Also ignore if write access to all planes is disabled */
+    if ((VgaSeqRegisters[VGA_SEQ_MASK_REG] & 0x0F) == 0x00) return;
+
+    /* Loop through each byte */
+    for (i = 0; i < Size; i++)
+    {
+        VideoAddress = VgaTranslateWriteAddress(Address + i);
+
+        for (j = 0; j < VGA_NUM_BANKS; j++)
+        {
+            /* Make sure the page is writeable */
+            if (!(VgaSeqRegisters[VGA_SEQ_MASK_REG] & (1 << j))) continue;
+
+            /* Check if this is chain-4 mode */
+            if (VgaSeqRegisters[VGA_SEQ_MEM_REG] & VGA_SEQ_MEM_C4)
+            {
+                if (((Address + i) & 3) != j)
+                {
+                    /* This plane will not be accessed */
+                    continue;
+                }
+            }
+
+            /* Check if this is odd-even mode */
+            if (VgaGcRegisters[VGA_GC_MODE_REG] & VGA_GC_MODE_OE)
+            {
+                if (((Address + i) & 1) != (j & 1))
+                {
+                    /* This plane will not be accessed */
+                    continue;
+                }
+            }
+
+            /* Copy the value to the VGA memory */
+            VgaMemory[VideoAddress + j * VGA_BANK_SIZE] = VgaTranslateByteForWriting(Buffer[i], j);
+        }
+    }
+}
+
 VOID VgaClearMemory(VOID)
 {
     ZeroMemory(VgaMemory, sizeof(VgaMemory));
index 2294a6d..859f091 100644 (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 */