Skip to content

Commit

Permalink
Improved VGA palette
Browse files Browse the repository at this point in the history
  • Loading branch information
morphx666 committed Mar 12, 2024
1 parent afd63b9 commit dc57e2a
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 38 deletions.
4 changes: 2 additions & 2 deletions GenOpCodes/My Project/AssemblyInfo.vb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Imports System.Runtime.InteropServices
' by using the '*' as shown below:
' <Assembly: AssemblyVersion("1.0.*")>

<Assembly: AssemblyVersion("2024.3.12.1277")>
<Assembly: AssemblyFileVersion("2024.3.12.1277")>
<Assembly: AssemblyVersion("2024.3.12.1284")>
<Assembly: AssemblyFileVersion("2024.3.12.1284")>

<assembly: AssemblyInformationalVersion("2024.3.12")>
4 changes: 2 additions & 2 deletions RunTests/My Project/AssemblyInfo.vb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Imports System.Runtime.InteropServices
' by using the '*' as shown below:
' <Assembly: AssemblyVersion("1.0.*")>

<Assembly: AssemblyVersion("2024.3.12.1683")>
<Assembly: AssemblyFileVersion("2024.3.12.1683")>
<Assembly: AssemblyVersion("2024.3.12.1690")>
<Assembly: AssemblyFileVersion("2024.3.12.1690")>

<assembly: AssemblyInformationalVersion("2024.3.12")>
6 changes: 3 additions & 3 deletions RunTests2/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2024.3.12.646")]
[assembly: AssemblyFileVersion("2024.3.12.646")]
[assembly: AssemblyVersion("2024.3.12.652")]
[assembly: AssemblyFileVersion("2024.3.12.652")]

[assembly: AssemblyInformationalVersion("2024.3.12.646")]
[assembly: AssemblyInformationalVersion("2024.3.12.652")]
4 changes: 2 additions & 2 deletions x8086NetEmu/Adapters/Audio/AdlibAdapter.vb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Public Class AdlibAdapter ' Based on fake86's implementation
waveOut.Play()

Dim unused = Task.Run(action:=Async Sub()
Dim maxTicks As Long = Scheduler.HOSTCLOCK \ SpeakerAdpater.SampleRate
Dim maxTicks As Long = Scheduler.HOSTCLOCK / SpeakerAdpater.SampleRate
Dim curTick As Long
Dim lastTick As Long

Expand All @@ -152,7 +152,7 @@ Public Class AdlibAdapter ' Based on fake86's implementation
Next
End If

Await Task.Delay(30)
Await Task.Delay(5)
Loop While waveOut.PlaybackState = PlaybackState.Playing
End Sub)
End Sub
Expand Down
39 changes: 20 additions & 19 deletions x8086NetEmu/Adapters/Video/VGA/VGAAdapter.vb
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ Public MustInherit Class VGAAdapter
ValidPortAddress.Add(i)
Next
ValidPortAddress.Add(&H3DA)
'ValidPortAddress.Add(&H3BA)

For i As Integer = 0 To VGABasePalette.Length - 1
vgaPalette(i) = VGABasePalette(i)
Expand All @@ -611,6 +612,7 @@ Public MustInherit Class VGAAdapter
Select Case mode
Case X8086.MemHookMode.Read
value = VideoRAM(address - mStartGraphicsVideoAddress)

Case X8086.MemHookMode.Write
VideoRAM(address - mStartGraphicsVideoAddress) = value
End Select
Expand Down Expand Up @@ -660,18 +662,14 @@ Public MustInherit Class VGAAdapter

Public Property VideoRAM(address As UInt16) As Byte
Get
If Not mUseVRAM Then
Return mCPU.Memory(address + ramOffset)
ElseIf (VGA_SC(4) And 6) = 0 AndAlso mVideoMode <> &HD AndAlso mVideoMode <> &H10 AndAlso mVideoMode <> &H12 Then
If Not mUseVRAM OrElse (VGA_SC(4) And 6) = 0 AndAlso mVideoMode <> &HD AndAlso mVideoMode <> &H10 AndAlso mVideoMode <> &H12 Then
Return mCPU.Memory(address + ramOffset)
Else
Return Read(address)
End If
End Get
Set(value As Byte)
If Not mUseVRAM Then
mCPU.Memory(address + ramOffset) = value
ElseIf (VGA_SC(4) And 6) = 0 AndAlso mVideoMode <> &HD AndAlso mVideoMode <> &H10 AndAlso mVideoMode <> &H12 Then
If Not mUseVRAM OrElse (VGA_SC(4) And 6) = 0 AndAlso mVideoMode <> &HD AndAlso mVideoMode <> &H10 AndAlso mVideoMode <> &H12 Then
mCPU.Memory(address + ramOffset) = value
Else
Write(address, value)
Expand All @@ -684,6 +682,10 @@ Public MustInherit Class VGAAdapter
Return mVideoMode
End Get
Set(value As UInt32)
For i As Integer = 0 To VGABasePalette.Length - 1
vgaPalette(i) = VGABasePalette(i)
Next

Select Case value >> 8 ' Mode is in AH
Case 0 ' Set video mode
value = value And &H7F ' http://stanislavs.org/helppc/ports.html
Expand Down Expand Up @@ -816,7 +818,7 @@ Public MustInherit Class VGAAdapter
Case &H12 ' 640x480 16-color
mStartTextVideoAddress = &HA0000
mStartGraphicsVideoAddress = &HA0000
mTextResolution = New Size(80, 30)
mTextResolution = New Size(40, 25)
mVideoResolution = New Size(640, 480)
mCellSize = New Size(8, 16)
mMainMode = MainModes.Graphics
Expand Down Expand Up @@ -898,20 +900,20 @@ Public MustInherit Class VGAAdapter

Case &H3C9
Select Case latchReadRGB
Case 0 ' B
tmpRGB = vgaPalette(latchReadPal).ToArgb() >> 2
Case 0 ' R
tmpRGB = (vgaPalette(latchReadPal).ToArgb() >> 18) And &H3F
Case 1 ' G
tmpRGB = vgaPalette(latchReadPal).ToArgb() >> 10
Case 2 ' R
tmpRGB = vgaPalette(latchReadPal).ToArgb() >> 18
tmpRGB = (vgaPalette(latchReadPal).ToArgb() >> 10) And &H3F
Case 2 ' B
tmpRGB = (vgaPalette(latchReadPal).ToArgb() >> 2) And &H3F
latchReadPal += 1
latchReadRGB = -1
End Select
latchReadRGB += 1
Return tmpRGB And &H3F

Case &H3DA
flip3C0 = True ' https://wiki.osdev.org/VGA_Hardware#Port_0x3C0
'flip3C0 = True ' https://wiki.osdev.org/VGA_Hardware#Port_0x3C0
Return MyBase.In(port)

End Select
Expand Down Expand Up @@ -950,13 +952,12 @@ Public MustInherit Class VGAAdapter
Dim cv As UInt32 = value And &H3F
Select Case latchWriteRGB
Case 0 ' R
tmpRGB = cv << 2
tmpRGB = cv << 18
Case 1 ' G
tmpRGB = tmpRGB Or (cv << 10)
Case 2 ' B
tmpRGB = tmpRGB Or (cv << 18)
tmpRGB = tmpRGB Or (cv << 2)
vgaPalette(latchWritePal) = Color.FromArgb(tmpRGB)
vgaPalette(latchWritePal) = Color.FromArgb(255, vgaPalette(latchWritePal))
latchWritePal += 1
End Select
latchWriteRGB = (latchWriteRGB + 1) Mod 3
Expand All @@ -969,8 +970,8 @@ Public MustInherit Class VGAAdapter
VGA_CRTC(portRAM(&H3D4)) = value
MyBase.Out(port, value)

Case &H3CE ' VGA graphics index
portRAM(port) = value Mod &H8 ' FIXME: This is one fugly hack!
'Case &H3CE ' VGA graphics index
' portRAM(port) = value Mod &H8 ' FIXME: This is one fugly hack!

Case &H3CF
VGA_GC(portRAM(&H3CE)) = value
Expand Down Expand Up @@ -1022,7 +1023,7 @@ Public MustInherit Class VGAAdapter

MyBase.InitVideoMemory(clearScreen)

mEndGraphicsVideoAddress = mStartGraphicsVideoAddress + 128 * 1024 ' 128KB
mEndGraphicsVideoAddress = &HBFFFF ' mStartGraphicsVideoAddress + 128 * 1024 ' 128KB
ramOffset = If(mMainMode = MainModes.Text, mStartTextVideoAddress, mStartGraphicsVideoAddress)

AutoSize()
Expand Down
7 changes: 3 additions & 4 deletions x8086NetEmu/Adapters/Video/VGA/VGAWinForms.vb
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,9 @@
Dim intensity As Integer = ((portRAM(&H3D9) >> 4) And 1) << 3
Dim xDiv As Integer = If(PixelsPerByte = 4, 2, 3)


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

Dim address As UInteger
Dim h1 As UInt32
Expand Down Expand Up @@ -244,7 +243,7 @@
For x As Integer = 0 To GraphicsResolution.Width - 1
Select Case mVideoMode
Case 4, 5
b0 = mCPU.Memory(mStartGraphicsVideoAddress + ((y >> 1) * mTextResolution.Width) + ((y And 1) * &H2000) + (x >> 2))
b0 = mCPU.Memory(mStartGraphicsVideoAddress + ((y >> 1) * (mTextResolution.Width << 2)) + ((y And 1) * &H2000) + (x >> 2))
Select Case x And 3
Case 3 : b0 = b0 And 3
Case 2 : b0 = (b0 >> 2) And 3
Expand Down Expand Up @@ -289,7 +288,7 @@
videoBMP.Pixel(x, y) = vgaPalette(b0)

Case &H12
address = (y * mTextResolution.Width) + (x / 8)
address = (y * (mTextResolution.Width << 1)) + (x >> 3)
h1 = (Not x) And 7
b0 = (vRAM(address) >> h1) And 1
b0 = b0 Or ((vRAM(address + &H10000) >> h1) And 1) << 1
Expand Down
4 changes: 2 additions & 2 deletions x8086NetEmu/My Project/AssemblyInfo.vb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Imports System.Runtime.InteropServices
' by using the '*' as shown below:
' <Assembly: AssemblyVersion("1.0.*")>

<Assembly: AssemblyVersion("2024.3.12.10778")>
<Assembly: AssemblyFileVersion("2024.3.12.10771")>
<Assembly: AssemblyVersion("2024.3.12.10863")>
<Assembly: AssemblyFileVersion("2024.3.12.10856")>

<assembly: AssemblyInformationalVersion("2024.3.12")>
4 changes: 2 additions & 2 deletions x8086NetEmuConsole/My Project/AssemblyInfo.vb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Imports System.Runtime.InteropServices
' by using the '*' as shown below:
' <Assembly: AssemblyVersion("1.0.*")>

<Assembly: AssemblyVersion("2024.3.12.1793")>
<Assembly: AssemblyFileVersion("2024.3.12.1788")>
<Assembly: AssemblyVersion("2024.3.12.1800")>
<Assembly: AssemblyFileVersion("2024.3.12.1795")>

<assembly: AssemblyInformationalVersion("2024.3.12")>
4 changes: 2 additions & 2 deletions x8086NetEmuWinForms/My Project/AssemblyInfo.vb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Imports System.Runtime.InteropServices
' by using the '*' as shown below:
' <Assembly: AssemblyVersion("1.0.*")>

<Assembly: AssemblyVersion("2024.3.12.8727")>
<Assembly: AssemblyFileVersion("2024.3.12.8725")>
<Assembly: AssemblyVersion("2024.3.12.8812")>
<Assembly: AssemblyFileVersion("2024.3.12.8810")>

<assembly: AssemblyInformationalVersion("2024.3.12")>

0 comments on commit dc57e2a

Please sign in to comment.