From 191548d9631d9c88a7e92da47ed303e686c6cce1 Mon Sep 17 00:00:00 2001 From: Xavier Flix Date: Fri, 22 Sep 2017 22:19:09 -0400 Subject: [PATCH] Removed Binary.vb dependency --- x8086NetEmu/Adapters/Disk/DiskImage.vb | 4 +- x8086NetEmu/Adapters/Video/CGA/CGAConsole.vb | 44 +-- x8086NetEmu/Adapters/Video/Image2Ascii.vb | 38 +-- x8086NetEmu/Helpers/Binary.vb | 261 ------------------ x8086NetEmu/My Project/AssemblyInfo.vb | 4 +- x8086NetEmu/x8086.vb | 42 +-- x8086NetEmu/x8086NetEmu.vbproj | 3 +- x8086NetEmuConsole/My Project/AssemblyInfo.vb | 4 +- x8086NetEmuWinForms/FormEmulator.vb | 2 +- .../My Project/AssemblyInfo.vb | 4 +- 10 files changed, 72 insertions(+), 334 deletions(-) delete mode 100644 x8086NetEmu/Helpers/Binary.vb diff --git a/x8086NetEmu/Adapters/Disk/DiskImage.vb b/x8086NetEmu/Adapters/Disk/DiskImage.vb index c4b8dd03..1e83cb80 100644 --- a/x8086NetEmu/Adapters/Disk/DiskImage.vb +++ b/x8086NetEmu/Adapters/Disk/DiskImage.vb @@ -234,8 +234,8 @@ Public Class DiskImage sector = sector And &H3F If cylinder >= mCylinders OrElse - sector < 1 OrElse sector > mSectors OrElse - head > mHeads Then + sector < 1 OrElse sector > mSectors OrElse + head > mHeads Then Return -1 End If diff --git a/x8086NetEmu/Adapters/Video/CGA/CGAConsole.vb b/x8086NetEmu/Adapters/Video/CGA/CGAConsole.vb index c5813af0..cbdd7e2c 100644 --- a/x8086NetEmu/Adapters/Video/CGA/CGAConsole.vb +++ b/x8086NetEmu/Adapters/Video/CGA/CGAConsole.vb @@ -10,8 +10,8 @@ Public Class CGAConsole Private i2a As Image2Ascii Private isRendering As Boolean - Private ratio As New Size(2, 4) - Private frameRate As Integer = 30 + Private ratio As New Size(3, 4) + Private frameRate As Integer = 27 Public Sub New(cpu As x8086) MyBase.New(cpu) @@ -22,30 +22,29 @@ Public Class CGAConsole Console.Clear() i2a = New Image2Ascii() With { - .Charset = Image2Ascii.Charsets.Advanced, + .Charset = Image2Ascii.Charsets.Standard, .ColorMode = Image2Ascii.ColorModes.Color, .GrayScaleMode = Image2Ascii.GrayscaleModes.Accuarte, - .ScanMode = Image2Ascii.ScanModes.Accurate, - .Font = New Font("Perfect DOS VGA 437", 18) + .ScanMode = Image2Ascii.ScanModes.Fast } - Dim tmp As New Threading.Thread(Sub() - Do - Thread.Sleep(1000 \ frameRate) - - Try - If MainMode = MainModes.Graphics Then - i2a.ProcessImage(False) - - For y As Integer = 0 To Console.WindowHeight - 1 - For x As Integer = 0 To Console.WindowWidth - 1 - ConsoleCrayon.WriteFast(i2a.Canvas(x)(y).Character, Image2Ascii.ToConsoleColor(i2a.Canvas(x)(y).Color), ConsoleColor.Black, x, y) - Next - Next - End If - Catch : End Try - Loop Until MyBase.cancelAllThreads - End Sub) + Dim tmp As New Thread(Sub() + Do + Thread.Sleep(1000 \ frameRate) + + Try + If MainMode = MainModes.Graphics Then + i2a.ProcessImage(False) + + For y As Integer = 0 To Console.WindowHeight - 1 + For x As Integer = 0 To Console.WindowWidth - 1 + ConsoleCrayon.WriteFast(i2a.Canvas(x)(y).Character, Image2Ascii.ToConsoleColor(i2a.Canvas(x)(y).Color), ConsoleColor.Black, x, y) + Next + Next + End If + Catch : End Try + Loop Until MyBase.cancelAllThreads + End Sub) tmp.Start() End Sub @@ -79,6 +78,7 @@ Public Class CGAConsole Case MainModes.Graphics Console.SetWindowSize(GraphicsResolution.Width / ratio.Width, GraphicsResolution.Height / ratio.Height) ResetI2A() + Console.SetWindowSize(i2a.CanvasSize.Width, i2a.CanvasSize.Height) End Select Console.SetBufferSize(Console.WindowWidth, Console.WindowHeight) #End If diff --git a/x8086NetEmu/Adapters/Video/Image2Ascii.vb b/x8086NetEmu/Adapters/Video/Image2Ascii.vb index cdac87fd..c6e81667 100644 --- a/x8086NetEmu/Adapters/Video/Image2Ascii.vb +++ b/x8086NetEmu/Adapters/Video/Image2Ascii.vb @@ -58,7 +58,7 @@ SetCharSize() End Sub - Public Property CanvasSize As Size + Public Property CanvasSize() As Size Get Return mCanvasSize End Get @@ -70,13 +70,13 @@ End Set End Property - Public ReadOnly Property DirectBitmap As DirectBitmap + Public ReadOnly Property DirectBitmap() As DirectBitmap Get Return mBitmap End Get End Property - Public Property Bitmap As Bitmap + Public Property Bitmap() As Bitmap Get Return mBitmap End Get @@ -86,13 +86,13 @@ End Set End Property - Public ReadOnly Property Surface As Bitmap + Public ReadOnly Property Surface() As Bitmap Get Return mSurface End Get End Property - Public Property GrayScaleMode As GrayscaleModes + Public Property GrayScaleMode() As GrayscaleModes Get Return mGrayScaleMode End Get @@ -102,7 +102,7 @@ End Set End Property - Public Property Charset As Charsets + Public Property Charset() As Charsets Get Return mCharset End Get @@ -113,7 +113,7 @@ End Set End Property - Public Property ColorMode As ColorModes + Public Property ColorMode() As ColorModes Get Return mColorMode End Get @@ -123,7 +123,7 @@ End Set End Property - Public Property ScanMode As ScanModes + Public Property ScanMode() As ScanModes Get Return mScanMode End Get @@ -133,13 +133,13 @@ End Set End Property - Public ReadOnly Property CharSize As Size + Public ReadOnly Property CharSize() As Size Get Return mCharSize End Get End Property - Public Property BackColor As Color + Public Property BackColor() As Color Get Return mBackColor End Get @@ -149,7 +149,7 @@ End Set End Property - Public Property Font As Font + Public Property Font() As Font Get Return mFont End Get @@ -160,7 +160,7 @@ End Set End Property - Public ReadOnly Property Canvas As ASCIIChar()() + Public ReadOnly Property Canvas() As ASCIIChar()() Get Return mCanvas End Get @@ -172,7 +172,7 @@ mCharSize.Height -= 1 End Sub - Public Sub ProcessImage(Optional gurfaceGraphics As Boolean = True) + Public Sub ProcessImage(Optional surfaceGraphics As Boolean = True) If mBitmap Is Nothing Then Exit Sub Dim sx As Integer @@ -185,9 +185,9 @@ mSurface = New DirectBitmap(mCanvasSize.Width * CharSize.Width, mCanvasSize.Height * CharSize.Height) End If - If gurfaceGraphics Then - surfaceGraphics = Graphics.FromImage(mSurface) - surfaceGraphics.Clear(Me.BackColor) + If surfaceGraphics Then + Me.surfaceGraphics = Graphics.FromImage(mSurface) + Me.surfaceGraphics.Clear(Me.BackColor) End If Dim scanStep As Size = New Size(Math.Ceiling(mBitmap.Width / mCanvasSize.Width), Math.Ceiling(mBitmap.Height / mCanvasSize.Height)) @@ -251,14 +251,14 @@ mCanvas(sx)(sy) = New ASCIIChar(ColorToASCII(r, g, b), Color.FromArgb(r, g, b)) End Select - If gurfaceGraphics Then + If surfaceGraphics Then Using sb As New SolidBrush(mCanvas(sx)(sy).Color) - surfaceGraphics.DrawString(mCanvas(sx)(sy).Character, Me.Font, sb, sx * CharSize.Width, sy * CharSize.Height) + Me.surfaceGraphics.DrawString(mCanvas(sx)(sy).Character, Me.Font, sb, sx * CharSize.Width, sy * CharSize.Height) End Using End If Next Next - If gurfaceGraphics Then surfaceGraphics.Dispose() + If surfaceGraphics Then Me.surfaceGraphics.Dispose() lastCanvasSize = mCanvasSize diff --git a/x8086NetEmu/Helpers/Binary.vb b/x8086NetEmu/Helpers/Binary.vb deleted file mode 100644 index 55d4abdf..00000000 --- a/x8086NetEmu/Helpers/Binary.vb +++ /dev/null @@ -1,261 +0,0 @@ -Public Class Binary - Public Enum Sizes - Bit = 1 - Nibble = 4 - [Byte] = 8 - Word = 16 - DoubleWord = 32 - QuadWord = 64 - 'DoubleQuadWord = 128 - Undefined = -1 - End Enum - - Private binaryValue As Long - Private mSize As Sizes - - Public Sub New() - mSize = Sizes.Word - End Sub - - Public Sub New(value As Long, Optional size As Sizes = Sizes.Undefined) - Me.New() - binaryValue = Math.Abs(value) - If size = Sizes.Undefined Then - CalculateMinimumSize() - Else - mSize = size - binaryValue = binaryValue And Mask(size) - End If - End Sub - - Public Sub New(value As String, Optional size As Sizes = Sizes.Undefined) - Dim binValue As Binary = 0 - TryParse(value, binValue) - binaryValue = binValue - - If size = Sizes.Undefined Then - mSize = binValue.Size - Else - mSize = Sizes.Word - End If - End Sub - - Public Shared Function TryParse(value As String, ByRef result As Long) As Boolean - Try - Select Case value.Last() - Case "d"c - result = Long.Parse(value.TrimEnd("d"c)) - Return True - Case "h"c - result = Convert.ToInt32(value.TrimEnd("h"c), 16) - Return True - Case "b"c - result = Convert.ToInt32(value.TrimEnd("b"c), 2) - Return True - Case "o"c - result = Convert.ToInt32(value.TrimEnd("o"c), 8) - Return True - Case Else - Dim base As Integer = 2 - For Each c As Char In value - If c <> "0" AndAlso c <> "1" Then - If c >= "A" AndAlso c <= "F" Then - base = 16 - ElseIf c < "0" OrElse c > "F" Then - base = -1 - Exit For - ElseIf base <> 16 Then - base = 10 - End If - End If - Next - - If base = -1 Then - Return False - Else - result = Convert.ToInt32(value, base) - Return True - End If - End Select - Catch - Return False - End Try - End Function - - Public Property Size As Sizes - Get - Return mSize - End Get - Set(value As Sizes) - mSize = value - End Set - End Property - - Public Shared Narrowing Operator CType(value As Long) As Binary - Return New Binary(value) - End Operator - - Public Shared Narrowing Operator CType(value As Int32) As Binary - Return New Binary(CUInt(Math.Abs(value))) - End Operator - - Public Shared Narrowing Operator CType(value As String) As Binary - Dim result As Binary = 0 - Binary.TryParse(value, result) - Return result - End Operator - - Public Shared Widening Operator CType(value As Binary) As Long - Return value.ToLong() - End Operator - - Public Shared Operator =(value1 As Binary, value2 As Binary) As Boolean - Return value1.ToLong() = value2.ToLong() - End Operator - - Public Shared Operator <>(value1 As Binary, value2 As Binary) As Boolean - Return Not value1 = value2 - End Operator - - Public Shared Operator >(value1 As Binary, value2 As Binary) As Boolean - Return value1.ToLong() > value2.ToLong() - End Operator - - Public Shared Operator <(value1 As Binary, value2 As Binary) As Boolean - Return Not value1 > value2 - End Operator - - Public Shared Operator >=(value1 As Binary, value2 As Binary) As Boolean - Return value1.ToLong() >= value2.ToLong() - End Operator - - Public Shared Operator <=(value1 As Binary, value2 As Binary) As Boolean - Return Not value1 >= value2 - End Operator - - Public Shared Operator +(value1 As Binary, value2 As Binary) As Binary - Return AdjustSize(value1.ToLong() + value2.ToLong(), value1.Size) - End Operator - - Public Shared Operator -(value1 As Binary, value2 As Binary) As Binary - Return AdjustSize(value1.ToLong() - value2.ToLong(), value1.Size) - End Operator - - Public Shared Operator *(value1 As Binary, value2 As Binary) As Binary - Return AdjustSize(value1.ToLong() * value2.ToLong(), value1.Size) - End Operator - - Public Shared Operator /(value1 As Binary, value2 As Binary) As Binary - Return AdjustSize(value1.ToLong() \ value2.ToLong(), value1.Size) - End Operator - - Public Shared Operator \(value1 As Binary, value2 As Binary) As Binary - Return value1 / value2 - End Operator - - Public Shared Operator ^(value1 As Binary, value2 As Binary) As Binary - Return AdjustSize(value1.ToLong() ^ value2.ToLong(), value1.Size) - End Operator - - Public Shared Operator Mod(value1 As Binary, value2 As Binary) As Binary - Return AdjustSize(value1.ToLong() Mod value2.ToLong(), value1.Size) - End Operator - - Public Shared Operator And(value1 As Binary, value2 As Binary) As Binary - Return value1.ToLong() And value2.ToLong() - End Operator - - Public Shared Operator Or(value1 As Binary, value2 As Binary) As Binary - Return value1.ToLong() Or value2.ToLong() - End Operator - - Public Shared Operator Xor(value1 As Binary, value2 As Binary) As Binary - Return value1.ToLong() Xor value2.ToLong() - End Operator - - Public Shared Operator Not(value1 As Binary) As Binary - Return AdjustSize(Not value1.ToLong(), value1.Size) - End Operator - - Public Shared Operator <<(value1 As Binary, value2 As Integer) As Binary - Return AdjustSize(value1.ToLong() << value2, value1.Size) - End Operator - - Public Shared Operator >>(value1 As Binary, value2 As Integer) As Binary - Return AdjustSize(value1.ToLong() >> value2, value1.Size) - End Operator - - Public Shared Function From(value As String, Optional size As Sizes = Sizes.Undefined) As Binary - Return New Binary(value, size) - End Function - - Public Shared Function From(value As Long, Optional size As Sizes = Sizes.Undefined) As Binary - Return New Binary(value, size) - End Function - - Public Shared Function From(value As Int32, Optional size As Sizes = Sizes.Undefined) As Binary - Return Binary.From(CUInt(Math.Abs(value)), size) - End Function - - Private Shared Function AdjustSize(value As Long, size As Sizes) As Binary - Return New Binary(value And Mask(size), size) - End Function - - Private Shared Function Mask(size As Sizes) As Long - Return (2 ^ size) - 1 - End Function - - Public Function ToLong() As Long - Return binaryValue - End Function - - Public Overrides Function ToString() As String - Return ConvertToBase(2).PadLeft(mSize, "0") - End Function - - Public Function ToHex() As String - Return ConvertToBase(16) - End Function - - Public Function ToOctal() As String - Return ConvertToBase(8) - End Function - - Private Sub CalculateMinimumSize() - If binaryValue <= 2 ^ 8 Then - mSize = Sizes.Byte - ElseIf binaryValue <= 2 ^ 16 Then - mSize = Sizes.Word - ElseIf binaryValue <= 2 ^ 32 Then - mSize = Sizes.DoubleWord - ElseIf binaryValue <= 2 ^ 64 Then - mSize = Sizes.QuadWord - Else - Throw New OverflowException() - End If - End Sub - - Private Function ConvertToBase(base As Short) As String - If mSize <= Sizes.DoubleWord Then - Return Convert.ToString(CType(binaryValue, Integer), base).ToUpper() - Else - If base = 10 Then - Return binaryValue - Else - Dim result As String = "" - - Dim i As Long - Dim r As Long - Dim n As Long = binaryValue - Do - i = n \ base - r = n - i * base - result = Convert.ToString(r, base) + result - n = i - Loop While n > 0 - - Return result - End If - End If - End Function -End Class \ No newline at end of file diff --git a/x8086NetEmu/My Project/AssemblyInfo.vb b/x8086NetEmu/My Project/AssemblyInfo.vb index 7243a967..891812d7 100644 --- a/x8086NetEmu/My Project/AssemblyInfo.vb +++ b/x8086NetEmu/My Project/AssemblyInfo.vb @@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices ' by using the '*' as shown below: ' - - + + diff --git a/x8086NetEmu/x8086.vb b/x8086NetEmu/x8086.vb index 5e4d3a68..2031abd2 100644 --- a/x8086NetEmu/x8086.vb +++ b/x8086NetEmu/x8086.vb @@ -231,20 +231,20 @@ Public Class x8086 If PPI Is Nothing Then Exit Sub ' http://docs.huihoo.com/help-pc/int-int_11.html - PPI.SetSwitchData(Binary.From("0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1".Replace(" ", ""))) - ' │F│E│D│C│B│A│9│8│7│6│5│4│3│2│1│0│ AX - ' │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ └──── IPL diskette installed - ' │ │ │ │ │ │ │ │ │ │ │ │ │ │ └───── math coprocessor - ' │ │ │ │ │ │ │ │ │ │ │ │ ├─┴────── old PC system board RAM < 256K - ' │ │ │ │ │ │ │ │ │ │ │ │ │ └───── pointing device installed (PS/2) - ' │ │ │ │ │ │ │ │ │ │ │ │ └────── not used on PS/2 - ' │ │ │ │ │ │ │ │ │ │ └─┴─────── initial video mode - ' │ │ │ │ │ │ │ │ └─┴────────── # of diskette drives, less 1 - ' │ │ │ │ │ │ │ └───────────── 0 if DMA installed - ' │ │ │ │ └─┴─┴────────────── number of serial ports - ' │ │ │ └─────────────────── game adapter installed - ' │ │ └──────────────────── unused, internal modem (PS/2) - ' └─┴───────────────────── number of printer ports + PPI.SetSwitchData(&B0_0_0_0_0_0_0_0_0_1_1_0_0_0_0_1) + ' │F│E│D│C│B│A│9│8│7│6│5│4│3│2│1│0│ AX + ' │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ └──── IPL diskette installed + ' │ │ │ │ │ │ │ │ │ │ │ │ │ │ └───── math coprocessor + ' │ │ │ │ │ │ │ │ │ │ │ │ ├─┴────── old PC system board RAM < 256K + ' │ │ │ │ │ │ │ │ │ │ │ │ │ └───── pointing device installed (PS/2) + ' │ │ │ │ │ │ │ │ │ │ │ │ └────── not used on PS/2 + ' │ │ │ │ │ │ │ │ │ │ └─┴─────── initial video mode + ' │ │ │ │ │ │ │ │ └─┴────────── # of diskette drives, less 1 + ' │ │ │ │ │ │ │ └───────────── 0 if DMA installed + ' │ │ │ │ └─┴─┴────────────── number of serial ports + ' │ │ │ └─────────────────── game adapter installed + ' │ │ └──────────────────── unused, internal modem (PS/2) + ' └─┴───────────────────── number of printer ports 'PPI.PortA(0) = &H30 Or &HC 'PPI.PortA(1) = &H0 @@ -2181,7 +2181,7 @@ Public Class x8086 SetAddressing() Select Case addrMode.Reg - Case 0 ' 000 -- inc reg/mem + Case 0 ' 000 inc reg/mem If addrMode.IsDirect Then mRegisters.Val(addrMode.Register2) = Eval(mRegisters.Val(addrMode.Register2), 1, Operation.Increment, addrMode.Size) clkCyc += 3 @@ -2190,7 +2190,7 @@ Public Class x8086 clkCyc += 15 End If - Case 1 ' 001 -- dec reg/mem + Case 1 ' 001 dec reg/mem If addrMode.IsDirect Then mRegisters.Val(addrMode.Register2) = Eval(mRegisters.Val(addrMode.Register2), 1, Operation.Decrement, addrMode.Size) clkCyc += 3 @@ -2199,7 +2199,7 @@ Public Class x8086 clkCyc += 15 End If - Case 2 ' 010 -- call indirect within segment + Case 2 ' 010 call indirect within segment PushIntoStack(mRegisters.IP + opCodeSize) If addrMode.IsDirect Then IPAddrOff = mRegisters.Val(addrMode.Register2) @@ -2208,14 +2208,14 @@ Public Class x8086 End If clkCyc += 11 - Case 3 ' 011 -- call indirect intersegment + Case 3 ' 011 call indirect inter-segment PushIntoStack(mRegisters.CS) PushIntoStack(mRegisters.IP + opCodeSize) IPAddrOff = addrMode.IndMem mRegisters.CS = RAM16(mRegisters.ActiveSegmentValue, addrMode.IndAdr, 2) clkCyc += 37 - Case 4 ' 100 -- jmp indirect within segment + Case 4 ' 100 jmp indirect within segment If addrMode.IsDirect Then IPAddrOff = mRegisters.Val(addrMode.Register2) Else @@ -2223,12 +2223,12 @@ Public Class x8086 End If clkCyc += 15 - Case 5 ' 101 -- jmp indirect intersegment + Case 5 ' 101 jmp indirect inter-segment IPAddrOff = addrMode.IndMem mRegisters.CS = RAM16(mRegisters.ActiveSegmentValue, addrMode.IndAdr, 2) clkCyc += 24 - Case 6 ' 110 -- push reg/mem + Case 6 ' 110 push reg/mem If addrMode.IsDirect Then If addrMode.Register2 = GPRegisters.RegistersTypes.SP Then PushIntoStack(AddValues(mRegisters.SP, -2, DataSize.Word)) diff --git a/x8086NetEmu/x8086NetEmu.vbproj b/x8086NetEmu/x8086NetEmu.vbproj index 7168e982..6461f596 100644 --- a/x8086NetEmu/x8086NetEmu.vbproj +++ b/x8086NetEmu/x8086NetEmu.vbproj @@ -158,7 +158,6 @@ - @@ -264,7 +263,7 @@ - +