Skip to content

Commit afd63b9

Browse files
committed
Fixed VGA mode 6
1 parent 150ccd3 commit afd63b9

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

x8086NetEmu/Adapters/Serial/MouseAdapter.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484

8585
Public Sub HandleInput(e As ExternalInputEvent) Implements IExternalInputHandler.HandleInput
8686
Dim m As MouseEventArgs = CType(e.Event, MouseEventArgs)
87-
Dim p As New Point(m.X - MidPointOffset.X, m.Y - MidPointOffset.Y)
87+
Dim p As New Point(m.X - MidPointOffset.X, (m.Y - MidPointOffset.Y) / 1.2)
8888

8989
Dim highBits As Byte = 0
9090
If p.X < 0 Then highBits = &B11

x8086NetEmu/Adapters/Video/VGA/VGAAdapter.vb

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
' https://pdos.csail.mit.edu/6.828/2007/readings/hardware/vgadoc/VGABIOS.TXT
33
' http://stanislavs.org/helppc/ports.html
44

5-
Imports System.Runtime.InteropServices
6-
75
Public MustInherit Class VGAAdapter
86
Inherits CGAAdapter
97

@@ -626,7 +624,7 @@ Public MustInherit Class VGAAdapter
626624
mCPU.TryAttachHook(&H10, New X8086.IntHandler(Function() As Boolean
627625
Select Case mCPU.Registers.AH
628626
Case &H0
629-
VideoMode = mCPU.Registers.AL
627+
VideoMode = mCPU.Registers.AL And &H7F
630628
VGA_SC(4) = 0
631629
Return useROM ' When using ROM, prevent the BIOS from handling this function
632630
Case &H10
@@ -647,7 +645,7 @@ Public MustInherit Class VGAAdapter
647645
Case &H1A
648646
mCPU.Registers.AL = &H1A ' http://stanislavs.org/helppc/int_10-1a.html
649647
mCPU.Registers.BL = &H8
650-
Return True
648+
Return False
651649
End Select
652650

653651
Return False
@@ -752,11 +750,11 @@ Public MustInherit Class VGAAdapter
752750
portRAM(&H3D9) = 0
753751
End If
754752

755-
Case 6 ' 640x200 2 Colors
753+
Case 6 ' 640x400 2 Colors
756754
mStartTextVideoAddress = &HB8000
757755
mStartGraphicsVideoAddress = &HB8000
758756
mTextResolution = New Size(80, 25)
759-
mVideoResolution = New Size(640, 200)
757+
mVideoResolution = New Size(640, 400)
760758
mCellSize = New Size(8, 8)
761759
mMainMode = MainModes.Graphics
762760
mPixelsPerByte = 2
@@ -784,11 +782,11 @@ Public MustInherit Class VGAAdapter
784782
mUseVRAM = False
785783
portRAM(&H3D8) = portRAM(&H3D8) And &HFE
786784

787-
Case &HD ' 320x200 16 Colors
785+
Case &HD ' 640x400 16 Colors
788786
mStartTextVideoAddress = &HA0000
789787
mStartGraphicsVideoAddress = &HA0000
790788
mTextResolution = New Size(40, 25)
791-
mVideoResolution = New Size(320, 200)
789+
mVideoResolution = New Size(640, 400)
792790
mCellSize = New Size(8, 8)
793791
mMainMode = MainModes.Graphics
794792
mPixelsPerByte = 4
@@ -815,7 +813,7 @@ Public MustInherit Class VGAAdapter
815813
mPixelsPerByte = 4
816814
mUseVRAM = True
817815

818-
Case &H12
816+
Case &H12 ' 640x480 16-color
819817
mStartTextVideoAddress = &HA0000
820818
mStartGraphicsVideoAddress = &HA0000
821819
mTextResolution = New Size(80, 30)
@@ -826,7 +824,7 @@ Public MustInherit Class VGAAdapter
826824
mUseVRAM = True
827825
portRAM(&H3D8) = portRAM(&H3D8) And &HFE
828826

829-
Case &H13
827+
Case &H13 ' 320x200 256-color
830828
mStartTextVideoAddress = &HA0000
831829
mStartGraphicsVideoAddress = &HA0000
832830
mTextResolution = New Size(40, 25)
@@ -952,11 +950,13 @@ Public MustInherit Class VGAAdapter
952950
Dim cv As UInt32 = value And &H3F
953951
Select Case latchWriteRGB
954952
Case 0 ' R
955-
tmpRGB = cv << 18
953+
tmpRGB = cv << 2
956954
Case 1 ' G
957955
tmpRGB = tmpRGB Or (cv << 10)
958956
Case 2 ' B
959-
vgaPalette(latchWritePal) = Color.FromArgb(tmpRGB Or (cv << 2))
957+
tmpRGB = tmpRGB Or (cv << 18)
958+
vgaPalette(latchWritePal) = Color.FromArgb(tmpRGB)
959+
vgaPalette(latchWritePal) = Color.FromArgb(255, vgaPalette(latchWritePal))
960960
latchWritePal += 1
961961
End Select
962962
latchWriteRGB = (latchWriteRGB + 1) Mod 3
@@ -975,12 +975,9 @@ Public MustInherit Class VGAAdapter
975975
Case &H3CF
976976
VGA_GC(portRAM(&H3CE)) = value
977977

978-
'Case &H3B8
979-
' portRAM(port) = value
980-
' MyBase.Out(port, value)
981-
982978
Case Else
983979
portRAM(port) = value
980+
MyBase.Out(port, value)
984981

985982
End Select
986983
End Sub

x8086NetEmu/Adapters/Video/VGA/VGAWinForms.vb

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,12 @@
197197
End Sub
198198

199199
Private Sub RenderGraphics()
200-
Dim b0 As Byte
201-
Dim b1 As Byte
202-
Dim xDiv As Integer = If(PixelsPerByte = 4, 2, 3)
200+
Dim b0 As UInt32
201+
Dim b1 As UInt32
203202
Dim usePal As Integer = (portRAM(&H3D9) >> 5) And 1
204203
Dim intensity As Integer = ((portRAM(&H3D9) >> 4) And 1) << 3
204+
Dim xDiv As Integer = If(PixelsPerByte = 4, 2, 3)
205+
205206

206207
' For modes &h12 and &h13
207208
Dim planeMode As Boolean = If(mVideoMode = &H12 OrElse mVideoMode = &H13, (VGA_SC(4) And 6) <> 0, False)
@@ -229,7 +230,7 @@
229230
Else
230231
b1 = mCPU.Memory(address + 1) And 15
231232
End If
232-
RenderChar(b0, videoBMP, brushCache(b1.LowNib()), brushCache(b1.HighNib() And If(intensity, 7, &HF)), r.Location)
233+
RenderChar(b0, videoBMP, brushCache(b1 And &HF), brushCache(((b1 >> 8) And &HF) And If(intensity, 7, &HF)), r.Location)
233234

234235
r.X += mCellSize.Width
235236
Next
@@ -239,11 +240,11 @@
239240
Exit Sub
240241
End If
241242

242-
For y As Integer = 0 To GraphicsResolution.Height - 1
243+
For y As Integer = 0 To GraphicsResolution.Height - 1 Step If(mVideoMode = 6, 2, 1)
243244
For x As Integer = 0 To GraphicsResolution.Width - 1
244245
Select Case mVideoMode
245246
Case 4, 5
246-
b0 = mCPU.Memory(mStartGraphicsVideoAddress + (y * mTextResolution.Width) + ((y And 1) * &H2000) + (x >> 3))
247+
b0 = mCPU.Memory(mStartGraphicsVideoAddress + ((y >> 1) * mTextResolution.Width) + ((y And 1) * &H2000) + (x >> 2))
247248
Select Case x And 3
248249
Case 3 : b0 = b0 And 3
249250
Case 2 : b0 = (b0 >> 2) And 3
@@ -255,15 +256,17 @@
255256
If b0 = (usePal + intensity) Then b0 = 0
256257
Else
257258
b0 = b0 * &H3F
258-
b0 = b0 Mod CGAPalette.Length
259+
'b0 = b0 Mod CGAPalette.Length
259260
End If
260-
videoBMP.Pixel(x, y) = CGAPalette(b0 Or b1)
261+
videoBMP.Pixel(x, y) = CGAPalette(b0)
261262

262263
Case 6
263-
b0 = mCPU.Memory(mStartGraphicsVideoAddress + ((y >> 1) * mTextResolution.Width) + ((y And 1) * &H2000) + (x >> 3))
264+
h2 = y >> 1
265+
b0 = mCPU.Memory(mStartGraphicsVideoAddress + ((h2 >> 1) * mTextResolution.Width) + ((h2 And 1) * &H2000) + (x >> 3))
264266
b0 = (b0 >> (7 - (x And 7))) And 1
265267
b0 *= 15
266268
videoBMP.Pixel(x, y) = CGAPalette(b0)
269+
videoBMP.Pixel(x, y + 1) = CGAPalette(b0)
267270

268271
Case &HD, &HE
269272
h1 = x >> 1

x8086NetEmuWinForms/FormEmulator.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ Public Class FormEmulator
265265
'cpu.Adapters.Add(New CGAWinForms(cpu, videoPort, If(ConsoleCrayon.RuntimeIsMono, VideoAdapter.FontSources.TrueType, VideoAdapter.FontSources.BitmapFile), "asciivga.dat", False))
266266
cpu.Adapters.Add(New VGAWinForms(cpu, videoPort, If(ConsoleCrayon.RuntimeIsMono, VideoAdapter.FontSources.TrueType, VideoAdapter.FontSources.BitmapFile), "asciivga.dat", False))
267267
cpu.Adapters.Add(New KeyboardAdapter(cpu))
268-
cpu.Adapters.Add(New MouseAdapter(cpu)) ' This breaks many things (For example, MINIX and ELKS won't start, PC Tools' PCShell doesn't respond)
268+
cpu.Adapters.Add(New MouseAdapter(cpu))
269269

270270
#If Win32 Then
271271
cpu.Adapters.Add(New SpeakerAdpater(cpu))

0 commit comments

Comments
 (0)