Mike Chambers
Veteran Member
- Joined
- Sep 2, 2006
- Messages
- 2,621
i know this is quite an ambitious project, but i was wondering if anybody who knows what they're talking about can tell me if i'm headed in the right direction so far or if i've been wasting my time? (so i know to stop now)
programming it in VB6... here is a copy and paste of my core.bas module which is, obviously, the core subs and functions of the 8086 emulation.
yes, i know VB6 is crud but regardless... am i on the right track?
i've only written code to support 5 opcodes so far.
programming it in VB6... here is a copy and paste of my core.bas module which is, obviously, the core subs and functions of the 8086 emulation.
yes, i know VB6 is crud but regardless... am i on the right track?
i've only written code to support 5 opcodes so far.
Code:
Public RAM(1048576) As Integer
Public PC As Long
Public AH, AL, BH, BL, CH, CL, DH, DL 'General purpose registers
Public CS, DS, SS, ES 'Segment registers
Public SI, DI, IP 'Pointer registers
Public SP, BP 'Stack registers
Public CF, PF, AF, ZF, SF, TF, fIF, DF, OF 'Flag registers
Public Sub LoadBIN(offset As Long, BINfile As String)
pos = offset
Open BINfile For Binary As #1
Do Until EOF(1)
getbyte$ = Space$(1)
Get #1, , getbyte$
RAM(pos) = Asc(getbyte$)
pos = pos + 1
Loop
MsgBox "Loaded " + BINfile + " into RAM." + Str$(LOF(1)) + " bytes."
Close #1
End Sub
Public Sub Exec()
opcode = RAM(PC)
Select Case opcode
Case &H37 'AAA
If ((AL And &HF) > 9) Or (AF = 1) Then
AL = AL + 6
Else
CF = 0
AF = 0
End If
IncPC 1
Case &HD5 'AAD imm8
val1 = RAM(PC + 1)
AL = (AH * val1)
AH = 0
IncPC 2
Case &HD4 'AAM imm8
val1 = RAM(PC + 1)
AH = AL / val1
AL = Fix(AL / val1)
IncPC 2
Case &HD6 'SETALC - Set AL to carry flag
AL = CF
IncPC 1
Case &H3F 'AAS - ASCII adjust after subtraction
If LowNib(AL) > 9 Or AF = 1 Then
AL = AL - 6
AH = AH - 1
AF = 1
CF = 1
Else
AF = 0
CF = 0
End If
IncPC 1
Case Else
MsgBox "UNKNOWN OPCODE!" + vbCrLf + "Decimal:" + Str$(opcode) + vbCrLf + "Hexadecimal: " + Hex$(opcode)
End Select
Form1.Label1 = "PC:" + Str$(PC)
End Sub
Public Sub IncPC(incval)
PC = PC + incval
End Sub
Public Function FullReg(RegHigh, RegLow)
'encode binary
bcode$ = ""
curcnt = 128
tmp2 = RegHigh
For tmp = 1 To 8
If tmp2 - curcnt >= 0 Then
bcode$ = bcode$ + "1"
tmp2 = tmp2 - curcnt
Else
bcode$ = bcode$ + "0"
End If
curcnt = curcnt / 2
Next tmp
curcnt = 128
tmp2 = RegLow
For tmp = 1 To 8
If tmp2 - curcnt >= 0 Then
bcode$ = bcode$ + "1"
tmp2 = tmp2 - curcnt
Else
bcode$ = bcode$ + "0"
End If
curcnt = curcnt / 2
Next tmp
'decode binary
curcnt = 32768
newnum = 0
For tmp = 1 To 16
If Mid$(bcode$, tmp, 1) = "1" Then newnum = newnum + curcnt
curcnt = curcnt / 2
Next tmp
FullReg = newnum
End Function
Public Function LowNib(NumVal)
'encode bianry
bcode$ = ""
curcnt = 128
tmp2 = NumVal
For tmp = 1 To 8
If tmp2 - curcnt >= 0 Then
bcode$ = bcode$ + "1"
tmp2 = tmp2 - curcnt
Else
bcode$ = bcode$ + "0"
End If
curcnt = curcnt / 2
Next tmp
'decode binary
curcnt = 8
newnum = 0
For tmp = 1 To 4
If Mid$(bcode$, tmp, 1) = "1" Then newnum = newnum + curcnt
curcnt = curcnt / 2
Next tmp
End Function
Public Function HighNib(NumVal)
'encode bianry
bcode$ = ""
curcnt = 128
tmp2 = NumVal
For tmp = 1 To 8
If tmp2 - curcnt >= 0 Then
bcode$ = bcode$ + "1"
tmp2 = tmp2 - curcnt
Else
bcode$ = bcode$ + "0"
End If
curcnt = curcnt / 2
Next tmp
'decode binary
curcnt = 8
newnum = 0
For tmp = 5 To 8
If Mid$(bcode$, tmp, 1) = "1" Then newnum = newnum + curcnt
curcnt = curcnt / 2
Next tmp
End Function
Last edited: