Skip to content

Commit dc57e2a

Browse files
committed
Improved VGA palette
1 parent afd63b9 commit dc57e2a

File tree

9 files changed

+38
-38
lines changed

9 files changed

+38
-38
lines changed

GenOpCodes/My Project/AssemblyInfo.vb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Imports System.Runtime.InteropServices
3131
' by using the '*' as shown below:
3232
' <Assembly: AssemblyVersion("1.0.*")>
3333

34-
<Assembly: AssemblyVersion("2024.3.12.1277")>
35-
<Assembly: AssemblyFileVersion("2024.3.12.1277")>
34+
<Assembly: AssemblyVersion("2024.3.12.1284")>
35+
<Assembly: AssemblyFileVersion("2024.3.12.1284")>
3636

3737
<assembly: AssemblyInformationalVersion("2024.3.12")>

RunTests/My Project/AssemblyInfo.vb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Imports System.Runtime.InteropServices
3131
' by using the '*' as shown below:
3232
' <Assembly: AssemblyVersion("1.0.*")>
3333

34-
<Assembly: AssemblyVersion("2024.3.12.1683")>
35-
<Assembly: AssemblyFileVersion("2024.3.12.1683")>
34+
<Assembly: AssemblyVersion("2024.3.12.1690")>
35+
<Assembly: AssemblyFileVersion("2024.3.12.1690")>
3636

3737
<assembly: AssemblyInformationalVersion("2024.3.12")>

RunTests2/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("2024.3.12.646")]
35-
[assembly: AssemblyFileVersion("2024.3.12.646")]
34+
[assembly: AssemblyVersion("2024.3.12.652")]
35+
[assembly: AssemblyFileVersion("2024.3.12.652")]
3636

37-
[assembly: AssemblyInformationalVersion("2024.3.12.646")]
37+
[assembly: AssemblyInformationalVersion("2024.3.12.652")]

x8086NetEmu/Adapters/Audio/AdlibAdapter.vb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ Public Class AdlibAdapter ' Based on fake86's implementation
130130
waveOut.Play()
131131

132132
Dim unused = Task.Run(action:=Async Sub()
133-
Dim maxTicks As Long = Scheduler.HOSTCLOCK \ SpeakerAdpater.SampleRate
133+
Dim maxTicks As Long = Scheduler.HOSTCLOCK / SpeakerAdpater.SampleRate
134134
Dim curTick As Long
135135
Dim lastTick As Long
136136

@@ -152,7 +152,7 @@ Public Class AdlibAdapter ' Based on fake86's implementation
152152
Next
153153
End If
154154

155-
Await Task.Delay(30)
155+
Await Task.Delay(5)
156156
Loop While waveOut.PlaybackState = PlaybackState.Playing
157157
End Sub)
158158
End Sub

x8086NetEmu/Adapters/Video/VGA/VGAAdapter.vb

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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()

x8086NetEmu/Adapters/Video/VGA/VGAWinForms.vb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,9 @@
203203
Dim intensity As Integer = ((portRAM(&H3D9) >> 4) And 1) << 3
204204
Dim xDiv As Integer = If(PixelsPerByte = 4, 2, 3)
205205

206-
207206
' For modes &h12 and &h13
208207
Dim planeMode As Boolean = If(mVideoMode = &H12 OrElse mVideoMode = &H13, (VGA_SC(4) And 6) <> 0, False)
209-
Dim vgaPage As UInteger = If(mVideoMode <= 7 OrElse MyBase.mVideoMode = &H12 OrElse MyBase.mVideoMode = &H13, (CUInt(VGA_CRTC(&HC)) << 8) + VGA_CRTC(&HD), 0)
208+
Dim vgaPage As UInteger = If(mVideoMode <= 7 OrElse mVideoMode = &H12 OrElse mVideoMode = &H13, (CUInt(VGA_CRTC(&HC)) << 8) + VGA_CRTC(&HD), 0)
210209

211210
Dim address As UInteger
212211
Dim h1 As UInt32
@@ -244,7 +243,7 @@
244243
For x As Integer = 0 To GraphicsResolution.Width - 1
245244
Select Case mVideoMode
246245
Case 4, 5
247-
b0 = mCPU.Memory(mStartGraphicsVideoAddress + ((y >> 1) * mTextResolution.Width) + ((y And 1) * &H2000) + (x >> 2))
246+
b0 = mCPU.Memory(mStartGraphicsVideoAddress + ((y >> 1) * (mTextResolution.Width << 2)) + ((y And 1) * &H2000) + (x >> 2))
248247
Select Case x And 3
249248
Case 3 : b0 = b0 And 3
250249
Case 2 : b0 = (b0 >> 2) And 3
@@ -289,7 +288,7 @@
289288
videoBMP.Pixel(x, y) = vgaPalette(b0)
290289

291290
Case &H12
292-
address = (y * mTextResolution.Width) + (x / 8)
291+
address = (y * (mTextResolution.Width << 1)) + (x >> 3)
293292
h1 = (Not x) And 7
294293
b0 = (vRAM(address) >> h1) And 1
295294
b0 = b0 Or ((vRAM(address + &H10000) >> h1) And 1) << 1

x8086NetEmu/My Project/AssemblyInfo.vb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Imports System.Runtime.InteropServices
3131
' by using the '*' as shown below:
3232
' <Assembly: AssemblyVersion("1.0.*")>
3333

34-
<Assembly: AssemblyVersion("2024.3.12.10778")>
35-
<Assembly: AssemblyFileVersion("2024.3.12.10771")>
34+
<Assembly: AssemblyVersion("2024.3.12.10863")>
35+
<Assembly: AssemblyFileVersion("2024.3.12.10856")>
3636

3737
<assembly: AssemblyInformationalVersion("2024.3.12")>

x8086NetEmuConsole/My Project/AssemblyInfo.vb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Imports System.Runtime.InteropServices
3131
' by using the '*' as shown below:
3232
' <Assembly: AssemblyVersion("1.0.*")>
3333

34-
<Assembly: AssemblyVersion("2024.3.12.1793")>
35-
<Assembly: AssemblyFileVersion("2024.3.12.1788")>
34+
<Assembly: AssemblyVersion("2024.3.12.1800")>
35+
<Assembly: AssemblyFileVersion("2024.3.12.1795")>
3636

3737
<assembly: AssemblyInformationalVersion("2024.3.12")>

x8086NetEmuWinForms/My Project/AssemblyInfo.vb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Imports System.Runtime.InteropServices
3131
' by using the '*' as shown below:
3232
' <Assembly: AssemblyVersion("1.0.*")>
3333

34-
<Assembly: AssemblyVersion("2024.3.12.8727")>
35-
<Assembly: AssemblyFileVersion("2024.3.12.8725")>
34+
<Assembly: AssemblyVersion("2024.3.12.8812")>
35+
<Assembly: AssemblyFileVersion("2024.3.12.8810")>
3636

3737
<assembly: AssemblyInformationalVersion("2024.3.12")>

0 commit comments

Comments
 (0)