我正在尝试创建一个Z80偏移指针转换器,但是当我编译程序并对其进行测试时,输出变量就会变为零。
背后的数学是这样的:
单击转换按钮时调用的事件代码如下:
Private Sub ConvertButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConvertButton.Click
If GetOffsetRadioButton.Checked Then
If OffsetTextBox.TextLength > 0 Then
CoreActions.OffsetToPointer()
PointerTextBox.Text = CoreActions.NewOffset
PointerBankTextBox.Text = CoreActions.NewBank
End If
End If
End Sub
此外,这里是CoreActions模块中转换背后的代码
Module CoreActions
Friend HexOffset As String = CoreForm.OffsetTextBox.Text
Friend PointerOffset As UInteger
Friend PointerBank As UInteger
Friend NewBank As String
Friend NewOffset As String
Friend Sub OffsetToPointer()
Dim DecOffset As Integer = Val("&H" & HexOffset)
PointerBank = DecOffset Mod 16384 ' 16384 = &H4000
PointerOffset = DecOffset Mod 65536 ' 65536 = &H10000
NewBank = Convert.ToString(PointerBank, 16)
NewOffset = Convert.ToString(PointerOffset, 16)
End Sub
End Module
输出结果是什么,究竟出了什么问题?我在运行时没有得到任何异常或警告......
答案 0 :(得分:1)
基本上,这会得到你想要的结果。
Dim FixedOffset As Integer = (DecOffset And &H3FFF) Or &H4000