@@ -588,6 +588,7 @@ Public MustInherit Class VGAAdapter
588588 ValidPortAddress.Add(i)
589589 Next
590590 ValidPortAddress.Add( &H3DA )
591+ 'ValidPortAddress.Add(&H3BA)
591592
592593 For i As Integer = 0 To VGABasePalette.Length - 1
593594 vgaPalette(i) = VGABasePalette(i)
@@ -611,6 +612,7 @@ Public MustInherit Class VGAAdapter
611612 Select Case mode
612613 Case X8086.MemHookMode.Read
613614 value = VideoRAM(address - mStartGraphicsVideoAddress)
615+
614616 Case X8086.MemHookMode.Write
615617 VideoRAM(address - mStartGraphicsVideoAddress) = value
616618 End Select
@@ -660,18 +662,14 @@ Public MustInherit Class VGAAdapter
660662
661663 Public Property VideoRAM(address As UInt16) As Byte
662664 Get
663- If Not mUseVRAM Then
664- Return mCPU.Memory(address + ramOffset)
665- ElseIf (VGA_SC( 4 ) And 6 ) = 0 AndAlso mVideoMode <> &HD AndAlso mVideoMode <> &H10 AndAlso mVideoMode <> &H12 Then
665+ If Not mUseVRAM OrElse (VGA_SC( 4 ) And 6 ) = 0 AndAlso mVideoMode <> &HD AndAlso mVideoMode <> &H10 AndAlso mVideoMode <> &H12 Then
666666 Return mCPU.Memory(address + ramOffset)
667667 Else
668668 Return Read(address)
669669 End If
670670 End Get
671671 Set (value As Byte )
672- If Not mUseVRAM Then
673- mCPU.Memory(address + ramOffset) = value
674- ElseIf (VGA_SC( 4 ) And 6 ) = 0 AndAlso mVideoMode <> &HD AndAlso mVideoMode <> &H10 AndAlso mVideoMode <> &H12 Then
672+ If Not mUseVRAM OrElse (VGA_SC( 4 ) And 6 ) = 0 AndAlso mVideoMode <> &HD AndAlso mVideoMode <> &H10 AndAlso mVideoMode <> &H12 Then
675673 mCPU.Memory(address + ramOffset) = value
676674 Else
677675 Write(address, value)
@@ -684,6 +682,10 @@ Public MustInherit Class VGAAdapter
684682 Return mVideoMode
685683 End Get
686684 Set (value As UInt32)
685+ For i As Integer = 0 To VGABasePalette.Length - 1
686+ vgaPalette(i) = VGABasePalette(i)
687+ Next
688+
687689 Select Case value >> 8 ' Mode is in AH
688690 Case 0 ' Set video mode
689691 value = value And &H7F ' http://stanislavs.org/helppc/ports.html
@@ -816,7 +818,7 @@ Public MustInherit Class VGAAdapter
816818 Case &H12 ' 640x480 16-color
817819 mStartTextVideoAddress = &HA0000
818820 mStartGraphicsVideoAddress = &HA0000
819- mTextResolution = New Size( 80 , 30 )
821+ mTextResolution = New Size( 40 , 25 )
820822 mVideoResolution = New Size( 640 , 480 )
821823 mCellSize = New Size( 8 , 16 )
822824 mMainMode = MainModes.Graphics
@@ -898,20 +900,20 @@ Public MustInherit Class VGAAdapter
898900
899901 Case &H3C9
900902 Select Case latchReadRGB
901- Case 0 ' B
902- tmpRGB = vgaPalette(latchReadPal).ToArgb() >> 2
903+ Case 0 ' R
904+ tmpRGB = ( vgaPalette(latchReadPal).ToArgb() >> 18 ) And &H3F
903905 Case 1 ' G
904- tmpRGB = vgaPalette(latchReadPal).ToArgb() >> 10
905- Case 2 ' R
906- tmpRGB = vgaPalette(latchReadPal).ToArgb() >> 18
906+ tmpRGB = ( vgaPalette(latchReadPal).ToArgb() >> 10 ) And &H3F
907+ Case 2 ' B
908+ tmpRGB = ( vgaPalette(latchReadPal).ToArgb() >> 2 ) And &H3F
907909 latchReadPal += 1
908910 latchReadRGB = - 1
909911 End Select
910912 latchReadRGB += 1
911913 Return tmpRGB And &H3F
912914
913915 Case &H3DA
914- flip3C0 = True ' https://wiki.osdev.org/VGA_Hardware#Port_0x3C0
916+ ' flip3C0 = True ' https://wiki.osdev.org/VGA_Hardware#Port_0x3C0
915917 Return MyBase .In(port)
916918
917919 End Select
@@ -950,13 +952,12 @@ Public MustInherit Class VGAAdapter
950952 Dim cv As UInt32 = value And &H3F
951953 Select Case latchWriteRGB
952954 Case 0 ' R
953- tmpRGB = cv << 2
955+ tmpRGB = cv << 18
954956 Case 1 ' G
955957 tmpRGB = tmpRGB Or (cv << 10 )
956958 Case 2 ' B
957- tmpRGB = tmpRGB Or (cv << 18 )
959+ tmpRGB = tmpRGB Or (cv << 2 )
958960 vgaPalette(latchWritePal) = Color.FromArgb(tmpRGB)
959- vgaPalette(latchWritePal) = Color.FromArgb( 255 , vgaPalette(latchWritePal))
960961 latchWritePal += 1
961962 End Select
962963 latchWriteRGB = (latchWriteRGB + 1 ) Mod 3
@@ -969,8 +970,8 @@ Public MustInherit Class VGAAdapter
969970 VGA_CRTC(portRAM( &H3D4 )) = value
970971 MyBase .Out(port, value)
971972
972- Case &H3CE ' VGA graphics index
973- portRAM(port) = value Mod &H8 ' FIXME: This is one fugly hack!
973+ ' Case &H3CE ' VGA graphics index
974+ ' portRAM(port) = value Mod &H8 ' FIXME: This is one fugly hack!
974975
975976 Case &H3CF
976977 VGA_GC(portRAM( &H3CE )) = value
@@ -1022,7 +1023,7 @@ Public MustInherit Class VGAAdapter
10221023
10231024 MyBase .InitVideoMemory(clearScreen)
10241025
1025- mEndGraphicsVideoAddress = mStartGraphicsVideoAddress + 128 * 1024 ' 128KB
1026+ mEndGraphicsVideoAddress = &HBFFFF ' mStartGraphicsVideoAddress + 128 * 1024 ' 128KB
10261027 ramOffset = If (mMainMode = MainModes.Text, mStartTextVideoAddress, mStartGraphicsVideoAddress)
10271028
10281029 AutoSize()
0 commit comments