⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 io.bas

📁 介绍用Java解析网络数据的三种特殊方法
💻 BAS
字号:
Attribute VB_Name = "io"
' This module can be used to implement
' your own external devices for Emu8086 -
' 8086 Microprocessor Emulator.
' Device can be written in Visual Basic
' (for C/C++/MS Visual C++ use "IO.H" instead).

' Supported input / output addresses:
'                  15 to 65535 (0000Fh - 0FFFFh)

' Version 2.12 of Emu8086 or above is required,
' check this URL for the latest version:
' http://www.emu8086.com

' You don't need to understand the code of this
' module, just add this file ("io.bas") into your
' project, and use these functions:
'
'    READ_IO_BYTE(lPORT_NUM As Long) As Byte
'    READ_IO_WORD(lPORT_NUM As Long) As Integer
'
' and subs:
'
'    WRITE_IO_BYTE(lPORT_NUM As Long, uValue As Byte)
'    WRITE_IO_WORD(lPORT_NUM As Long, iValue As Integer)
'
' Where:
'  lPORT_NUM - is a number in range: from 15 to 65535.
'  uValue    - unsigned byte value to be written to a port.
'  iValue    - signed word value to be written to a port.





Option Explicit

Public Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Dim sTemp As String * 500
Dim lTSize As Long

' 2.12#611
Const sIO_FILE = "EmuPort.io"

Function READ_IO_BYTE(lPORT_NUM As Long) As Byte
On Error GoTo err_rib

Dim sFileName As String
Dim tb As Byte
Dim fNum As Integer

lTSize = GetTempPath(499, sTemp)
sFileName = Mid(sTemp, 1, lTSize)
sFileName = AddTrailingSlash(sFileName) & sIO_FILE

fNum = FreeFile

Open sFileName For Random As fNum Len = 1

' File's first byte has Index 1 in VB
' compatibility for Port 0:
Get fNum, lPORT_NUM + 1, tb

Close fNum


READ_IO_BYTE = tb


Exit Function
err_rib:
Debug.Print "READ_IO_BYTE: " & Err.Description
Close fNum

End Function

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

Dim sFileName As String
Dim fNum As Integer

lTSize = GetTempPath(499, sTemp)
sFileName = Mid(sTemp, 1, lTSize)
sFileName = AddTrailingSlash(sFileName) & sIO_FILE

fNum = FreeFile


Open sFileName For Random As fNum Len = 1

' File's first byte has Index 1 in VB
' compatibility for Port 0:
Put fNum, lPORT_NUM + 1, uValue

Close fNum

Exit Sub
err_wib:
Debug.Print "WRITE_IO_BYTE: " & Err.Description
Close fNum
End Sub


Function READ_IO_WORD(lPORT_NUM As Long) As Integer
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(lPORT_NUM As Long, iValue As Integer)
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, (iValue And 65280) / 256 ' FF00 >> 8
End Sub

' This function corrects the file path by adding "\"
' in the end if required:
Function AddTrailingSlash(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 Integer
    Dim temp As Long
    
    ' 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(l As Long) As Integer
    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
        MsgBox "Wrong param calling make_signed_int(): " & l
    End If
End Function

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -