From d34fb08d1373aaa11c90654773d38ee1ef457e9f Mon Sep 17 00:00:00 2001 From: Aleksandar Andrejevic Date: Fri, 9 May 2014 21:56:40 +0000 Subject: [PATCH] [NTVDM] Replace the temporary CGA hack with a working solution. CORE-8177 #comment CGA should work as of r63208. svn path=/trunk/; revision=63208 --- reactos/subsystems/ntvdm/hardware/vga.c | 44 +++++++++++++++---------- reactos/subsystems/ntvdm/hardware/vga.h | 2 +- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/reactos/subsystems/ntvdm/hardware/vga.c b/reactos/subsystems/ntvdm/hardware/vga.c index 050b5f34801..47fe3a64507 100644 --- a/reactos/subsystems/ntvdm/hardware/vga.c +++ b/reactos/subsystems/ntvdm/hardware/vga.c @@ -1146,7 +1146,19 @@ static VOID VgaUpdateFramebuffer(VOID) /* Loop through the scanlines */ for (i = 0; i < Resolution.Y; i++) { - BOOL RepeatScanline = FALSE; + DWORD InterlaceHighBit = VGA_INTERLACE_HIGH_BIT; + + if (VgaGcRegisters[VGA_GC_MODE_REG] & VGA_GC_MODE_OE) + { + /* Shift the high bit right by 1 in odd/even mode */ + InterlaceHighBit >>= 1; + } + + if ((VgaGcRegisters[VGA_GC_MISC_REG] & VGA_GC_MISC_OE) && (i & 1)) + { + /* Odd-numbered line in interlaced mode - set the high bit */ + Address |= InterlaceHighBit; + } /* Loop through the pixels */ for (j = 0; j < Resolution.X; j++) @@ -1203,21 +1215,8 @@ static VOID VgaUpdateFramebuffer(VOID) */ DWORD BankNumber = (j / 4) % 2; DWORD Offset = Address + (j / 8); - BYTE LowPlaneData, HighPlaneData; - - if (i % 2 != 0) - { - /* Odd-numbered line - add the CGA emulation offset */ - Offset += VGA_CGA_ODD_LINE_OFFSET; - } - else - { - /* Even-numbered line - use the same scanline */ - RepeatScanline = TRUE; - } - - LowPlaneData = VgaMemory[BankNumber * VGA_BANK_SIZE + Offset * AddressSize]; - HighPlaneData = VgaMemory[(BankNumber + 2) * VGA_BANK_SIZE + Offset * AddressSize]; + BYTE LowPlaneData = VgaMemory[BankNumber * VGA_BANK_SIZE + Offset * AddressSize]; + BYTE HighPlaneData = VgaMemory[(BankNumber + 2) * VGA_BANK_SIZE + Offset * AddressSize]; /* Extract the two bits from each plane */ LowPlaneData = (LowPlaneData >> (6 - ((j % 4) * 2))) & 3; @@ -1310,8 +1309,17 @@ static VOID VgaUpdateFramebuffer(VOID) } } - /* Move to the next scanline */ - if (!RepeatScanline) Address += ScanlineSize; + if (VgaGcRegisters[VGA_GC_MISC_REG] & VGA_GC_MISC_OE && (i & 1)) + { + /* Clear the high bit */ + Address &= ~InterlaceHighBit; + } + + if (!(VgaGcRegisters[VGA_GC_MISC_REG] & VGA_GC_MISC_OE) || (i & 1)) + { + /* Move to the next scanline */ + Address += ScanlineSize; + } } /* diff --git a/reactos/subsystems/ntvdm/hardware/vga.h b/reactos/subsystems/ntvdm/hardware/vga.h index ba7884ee430..ca6de8d4bb2 100644 --- a/reactos/subsystems/ntvdm/hardware/vga.h +++ b/reactos/subsystems/ntvdm/hardware/vga.h @@ -24,7 +24,7 @@ #define VGA_MINIMUM_HEIGHT 300 #define VGA_DAC_TO_COLOR(x) (((x) << 2) | ((x) >> 4)) #define VGA_COLOR_TO_DAC(x) ((x) >> 2) -#define VGA_CGA_ODD_LINE_OFFSET 0x1000 +#define VGA_INTERLACE_HIGH_BIT (1 << 13) /* Register I/O ports */