自定义Emu8086 8位二进制虚拟设备调试

Custom Emu8086 8-bit Binary Virtual Device debugging

我一直在尝试编写自定义 Emu8086(8086 微处理器仿真器)8 位二进制虚拟设备输出,将汇编输入显示为二进制输出:

MOV AX,0FFH -> 输出:1111 1111

我已经成功地从示例虚拟设备 Visual Basic 6.0 源代码中导出 UI,该源代码显示汇编输入的十进制输出。

Original UI from LED_Display Sample Virtual Device

Derived UI From LED_Display Sample Virtual Device (Image)

我不得不将 Visual Basic 6.0 源代码升级到 Visual Studio 2008 兼容代码,我想也许问题出在这里?

但每当我调试代码时,它都会按预期工作,在我启动模拟器时监听分配给程序集输入的端口号并显示所需的二进制等效数字。

但是,当使用独立的 .exe 文件时,它不再有效。我包含了 IO.VB(升级前 io.bas),它必须作为一个单独的模块包含在一个 VB 文件中,认为它可能是无济于事的罪魁祸首。

Option Strict Off
Option Explicit On
Module io

Const sIO_FILE As String = "C:\emu8086.io"

Function READ_IO_BYTE(ByRef lPORT_NUM As Integer) As Byte
    On Error GoTo err_rib

    Dim sFileName As String
    Dim tb As Byte
    Dim fNum As Short

    sFileName = sIO_FILE

    fNum = FreeFile()

    FileOpen(fNum, sFileName, OpenMode.Random, , OpenShare.Shared, 1)

    ' File's first byte has Index 1 in VB
    ' compatibility for Port 0:
    'UPGRADE_WARNING: Get was upgraded to FileGet and has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
    FileGet(fNum, tb, lPORT_NUM + 1)

    FileClose(fNum)


    READ_IO_BYTE = tb


    Exit Function
err_rib:
    Debug.Print("READ_IO_BYTE: " & Err.Description)
    FileClose(fNum)

End Function

Sub WRITE_IO_BYTE(ByRef lPORT_NUM As Integer, ByRef uValue As Byte)
    On Error GoTo err_wib

    Dim sFileName As String
    Dim fNum As Short

    sFileName = sIO_FILE

    fNum = FreeFile()


    FileOpen(fNum, sFileName, OpenMode.Random, , OpenShare.Shared, 1)

    ' File's first byte has Index 1 in VB
    ' compatibility for Port 0:
    'UPGRADE_WARNING: Put was upgraded to FilePut and has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
    FilePut(fNum, uValue, lPORT_NUM + 1)

    FileClose(fNum)

    Exit Sub
err_wib:
    Debug.Print("WRITE_IO_BYTE: " & Err.Description)
    FileClose(fNum)
End Sub


Function READ_IO_WORD(ByRef lPORT_NUM As Integer) As Short
    Dim tb1 As Byte
    Dim tb2 As Byte

    ' Read lower byte:
    tb1 = READ_IO_BYTE(lPORT_NUM)
    ' Write higher byte:
    tb2 = READ_IO_BYTE(lPORT_NUM + 1)

    READ_IO_WORD = make16bit_SIGNED_WORD(tb1, tb2)
End Function


Sub WRITE_IO_WORD(ByRef lPORT_NUM As Integer, ByRef iValue As Short)
    Dim tb1 As Byte
    Dim tb2 As Byte

    ' Write lower byte:
    WRITE_IO_BYTE(lPORT_NUM, iValue And 255) ' 00FF
    ' Write higher byte:
    WRITE_IO_BYTE(lPORT_NUM + 1, CShort(iValue And 65280) / 256) ' FF00 >> 8
End Sub

' This function corrects the file path by adding "\"
' in the end if required:
Function AddTrailingSlash(ByRef sPath As String) As String

    If (sPath <> "") Then
        If (Mid(sPath, Len(sPath), 1) <> "\") Then
            AddTrailingSlash = sPath & "\"
            Exit Function
        End If
    End If

    AddTrailingSlash = sPath

End Function

Function make16bit_SIGNED_WORD(ByRef byteL As Byte, ByRef byteH As Byte) As Short
    Dim temp As Integer

    ' lower byte - on lower address!
    ' byte1 - lower byte!

    temp = byteH
    temp = temp * 256 ' shift left by 8 bit.
    temp = temp + byteL


    make16bit_SIGNED_WORD = make_signed_int(temp)
End Function

' Makes a Long to be a SIGNED Integer:
Function make_signed_int(ByRef l As Integer) As Short
    If l >= -32768 And l < 65536 Then
        If l <= 32767 Then
            make_signed_int = l
        Else
            make_signed_int = l - 65536
        End If
    Else
        make_signed_int = 0
        Debug.Print("wrong param calling make_signed_int(): " & l)
    End If
End Function


End Module

这是虚拟设备的代码:

Friend Class frmLed
Inherits System.Windows.Forms.Form

Dim lPrevResult As Integer ' #1122d

Function PrevInstance() As Boolean
    If UBound(Diagnostics.Process.GetProcessesByName _
       (Diagnostics.Process.GetCurrentProcess.ProcessName)) _
       > 0 Then
        Return True
    Else
        Return False
    End If
End Function


Private Sub frmLed_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load

    ' do not allow more than one copy of this program to run simuateniously
    'UPGRADE_ISSUE: App property App.PrevInstance was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="076C26E5-B7A9-4E77-B69C-B4448DF39E58"'
    If PrevInstance() Then

        ShowPrevInstance()

        End ' terminate this instance!

    End If

    GetWindowPos(Me)

    If allow_on_top() Then set_on_top(Me)


End Sub

Private Sub frmLed_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
    SaveWindowState(Me)
End Sub

Private Sub Timer1_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer1.Tick

    On Error GoTo err1

    ' Intenger values:
    '    -32,768 to 32,767
    Dim lResult As Integer


    ' Read SIGNED WORD from port 199:
    lResult = READ_IO_WORD(199)


    If lPrevResult <> lResult Then ' #1122d
        If shall_activate(Me) Then Me.Show()
        lPrevResult = lResult
    End If

    ' Show minus if required:
    If lResult < 0 Then
        imgMINUS.Visible = True
        lResult = System.Math.Abs(lResult)
    Else
        imgMINUS.Visible = False
    End If

    ' Display 5 digits:
    Dim i As Short
    Dim v As Byte

    Dim dec, bin As Integer

    For i = 0 To 7

        v = lResult Mod 10

        bin = Fix(lResult) Mod 2

        dig(i).Image = d(bin).Image

        lResult = Int(lResult / 2)

    Next i

    Exit Sub
err1:
    Debug.Print("err1")
    Resume Next
End Sub
End Class

我很困惑为什么它在 IDE 调试状态下工作但在 运行 作为 .exe 文件时不起作用。任何见解将不胜感激!谢谢!

在我的电脑上安装了 Visual Basic 6.0,修改了其中的示例代码,一切正常。 Virtual Device in action