Mike Chambers
Veteran Member
- Joined
- Sep 2, 2006
- Messages
- 2,621
i decided to have another look at the x86 emulator i've been working on today after a bit of a break, and i'm certain i've got my problem narrowed down to buggy DIV/IDIV emulation and i was wondering if anybody might be able to have a peek at this code here and see where my problem lies..
i know i can make big optimizations there, but i'm trying to determine the actual problem first. any ideas, guys? thanks.
Code:
Case 6: 'DIV
If oper1 = 0 Then intcall86 0: Exit Sub 'division by zero
If word Then
temp1 = (getreg16(dx) Shl 16) Or getreg16(ax)
temp2 = temp1 \ oper1
If (temp2 And &hFFFF0000) Then intcall86 0: Exit Sub 'divide overflow
putreg16 dx, getreg16(ax) Mod oper1
putreg16 ax, temp2
Else
temp1 = getreg16(ax) \ oper1
temp2 = getreg16(ax) Mod oper1
If (temp1 And &hFF00) Then intcall86 0: Exit Sub
al = temp1
ah = temp2
End If
Case 7: 'IDIV
If oper1 = 0 Then intcall86 0: Exit Sub
If word Then
temp1 = (getreg16(dx) Shl 16) Or getreg16(ax)
tempoper = oper1
If temp1 >= &h8000& Then temp1 = -temp1
If tempoper >= &h8000& Then tempoper = -tempoper
temp2 = temp1 \ tempoper
If temp2 > &h7fff Then intcall86 0: Exit Sub
putreg16 dx, temp1 Mod oper1
putreg16 ax, temp2
Else
temp1 = getreg16(ax)
tempoper = oper1
If temp1 >= &h80& Then temp1 = -temp1
If tempoper >= &h80& Then tempoper = -tempoper
temp2 = temp1 \ tempoper
If temp2 > &h7f Then intcall86 0: Exit Sub 'divide overflow
al = temp1 Mod oper1
ah = temp2
End If
i know i can make big optimizations there, but i'm trying to determine the actual problem first. any ideas, guys? thanks.