FPW26: possible fix to DIVIDE BY ZERO 
Author Message
 FPW26: possible fix to DIVIDE BY ZERO

this looks like it might  be useful to some FPW26 folks, so I'm posting it
here...
sorry if it has appeared here before, but as Socrates used to say, in
Plato's Dialogues, when someone complained about him repeating himself,
"DIS KAI TRIS TA KALA" .... "TWICE AND THRICE THE BEAUTIFUL"

====
The following was clipped from comp.databases.xbase.fox. The
thread was "PATCH! Divide by zero error on 333MHz and faster machines".

It's rather long, but it MIGHT just be real handy.

I HAVE NOT TRIED THIS YET! TRY AT YOUR OWN RISK!!


Apparently the procedure requires SET TALK OFF before running, by the
way.

Quote:
>-----------snip-----------<

Dear Ladies and Gents,

This is an updated patch for the divide-by-zero error on fast
machines. It now patches foxprow.exe as well as foxw2600.esl,
so us programmers can use fast, {*filter*} machines just like our customers
can.

If you've already run the patch on the ESL file it'll just refuse to
apply the patch twice when you run it the second time.

Cheers!

Andrew

*===============================================================
* FixFox.PRG
*
* Program to patch FOXW2600.ESL
* (Foxpro for Windows 2.6A Runtime)
* AND FOXPROW.EXE
* (Foxpro for Windows 2.6A Development Environment)
*
* to prevent the divide by zero error on fast machines
* (333 Megahertz Pentium II or faster)
*
* AEF, 1998.08.18
* Revised 1998.08.20 to patch FOXPROW.EXE as
* well as FOXW2600.ESL
*
* I claim no copyright on this program. Please distribute it,
* but leave it unmodified if you can, and leave my name on it because
* Mom loves to see it in print.
*
* Microsoft's license agreement
* prohibits reverse-engineering of their software.
* And of course I had to
* do disassemble about 100 bytes of code
* in order to locate
* where the problem was, and code a
* fix for it. Sorry, Mr. Gates, I didn't want
* to do it but I was between a
* rock and a hard place, and so were all of
* my Fortune-500 customers.
* Thanks to those on USENET who had the
* problem and were gracious enough to
* post the detailed de{*filter*} information (especially
* the sequence of bytes at EIS:IP)
* and examples of similar problems in
* old Borland code. You know who you are.
*
* Please distribute this freely to your fellow Foxpro folks,
* once you have satisfied yourself that it works.  Please
* don't modify the code unless you have to.
*
* Instructions:
*
* - Make a copy of FOXw2600.ESL, call it FOXW2600.NEW
* - Make a copy of Foxprow.exe, call it FOXPROW.NEW
* - Launch Foxpro and run this program
* - Quit Foxpro
* - RENAME FOXW2600.ESL to FOXW2600.OLD
* - RENAME FOXW2600.NEW to FOXW2600.ESL
* - RENAME FOXPROW.EXE TO FOXPROW.OLD
* - RENAME FOXPROW.NEW TO FOXPROW.EXE
*
*       >>>>>>>>>>>  TEST IT!!!  <<<<<<<<<<<<
*
* There is at least one other problem in Foxpro
* that appears only on fast machines, and at
* this writing I have no idea whether this
* change will introduce other problems in obscure
* parts of your programs.
*
* This is provided without guarantees, warranties,
* or anything of the sort.
* You use it *totally* at your own risk.
* I'm only releasing it because I know EXACTLY
* how frustrated you are that
* Microsoft isn't planning to release a real fix.
* Once you've applied this patch
* Microsoft will no doubt refuse to support your software.
*
* If you care, and if like me you're an assembler
* programmer of old, here's the change.
* The program is executing a timing loop to see
* how many loops it can do in
* a millisecond. To do this it counts up into
* the AX/DX register pair until the
* system's realtime clock has incremented three
* times (2 * 55 ms = 110 milliseconds)
* then it stores the number of loops per
* millisecond by dividing the loop
* count by 110. With fast machines this
* results in a divide overflow.
*
* The code here modifies the loop code
* slightly to count up instead of
* down, and uses some bytes freed up
* thereby to avoid the divide
* overflow.
*
* Original code: (code segments and offsets are fictitious here)
*1871:00F0 BB6C00        MOV     BX,006C
*1871:00F3 2BC0          SUB     AX,AX
*1871:00F5 2BD2          SUB     DX,DX
*1871:00F7 BF0200        MOV     DI,0002
*1871:00FA 26            ES:
*1871:00FB 8A2F          MOV     CH,[BX]
*1871:00FD 26            ES:
*1871:00FE 8A0F          MOV     CL,[BX]
*1871:0100 3AE9          CMP     CH,CL
*1871:0102 74F9          JZ      00FD
*1871:0104 26            ES:
*1871:0105 8A0F          MOV     CL,[BX]
*1871:0107 26            ES:
*1871:0108 3A0F          CMP     CL,[BX]
*1871:010A 7510          JNZ     011C
*1871:010C 2D0100        SUB     AX,0001
*1871:010F 83DA00        SBB     DX,+00
*1871:0112 8AEC          MOV     CH,AH
*1871:0114 0AE8          OR      CH,AL
*1871:0116 0AEE          OR      CH,DH
*1871:0118 0AEA          OR      CH,DL
*1871:011A 75EB          JNZ     0107
*1871:011C 4F            DEC     DI
*1871:011D 75E5          JNZ     0104
*1871:011F F7DA          NEG     DX
*1871:0121 F7D8          NEG     AX
*1871:0123 83DA00        SBB     DX,+00
*1871:0126 B96E00        MOV     CX,006E
*1871:0129 F7F1          DIV     CX
*1871:012B 40            INC     AX
*1871:012C A3B628        MOV     [28B6],AX
*
* New code:
*
*1871:00F0 BB6C00        MOV     BX,006C
*1871:00F3 2BC0          SUB     AX,AX
*1871:00F5 2BD2          SUB     DX,DX
*1871:00F7 BF0200        MOV     DI,0002
*1871:00FA 26            ES:
*1871:00FB 8A2F          MOV     CH,[BX]
*1871:00FD 26            ES:
*1871:00FE 8A0F          MOV     CL,[BX]
*1871:0100 3AE9          CMP     CH,CL
*1871:0102 74F9          JZ      00FD
*1871:0104 26            ES:
*1871:0105 8A0F          MOV     CL,[BX]
*1871:0107 26            ES:
*1871:0108 3A0F          CMP     CL,[BX]
*1871:010A 7510          JNZ     011C
*1871:010C 050100        ADD     AX,0001                ***** MODIFIED
*1871:010F 83D200        ADC     DX,+00         ***** MODIFIED
*1871:0112 8AEC          MOV     CH,AH
*1871:0114 0AE8          OR      CH,AL
*1871:0116 0AEE          OR      CH,DH
*1871:0118 0AEA          OR      CH,DL
*1871:011A 75EB          JNZ     0107
*1871:011C 4F            DEC     DI
*1871:011D 75E5          JNZ     0104
*1871:011F B96E00        MOV     CX,006E               ****** MODIFIED
*1871:0122 39CA          CMP     DX,CX          ******     "
*1871:0124 7203          JB      0129           ******     "
*1871:0126 BA6D00        MOV     DX,006D        ******     "
*1871:0129 F7F1          DIV     CX
*1871:012B 40            INC     AX
*1871:012C A3B628        MOV     [28B6],AX
*
* In fact the original code doesn't make sense in a
* number of respects: the OR CH,xx
* instructions to check for 32-bit wraparound, for example.
* I've not changed them because
* they affect the timing of the loop.
*=======================================================
SET TALK OFF   && Enforce proper SUBSTR behaviour

=DoPatch("FOXW2600.ESL", "FOXW2600.NEW")
=DoPatch("FOXPROW.EXE", "FOXPROW.NEW")

PROCEDURE DoPatch
PARAMETER m.cFilename, m.cNewname

IF !FILE(m.cNewname)
        WAIT WINDOW ;
          "Copy "+m.cFilename+" To "+;
           m.cNewname+", then run this again."
        CANCEL
ENDIF

* The original code and the modified code,
* in hex form for easy verification by eye:
m.OriginalCode  = ;
        "2D010083DA008AEC0AE80AEE0AEA75EB" +;
        "4F75E5F7DAF7D883DA00B96E00F7F140"
m.NewCode               = ;
        "05010083D2008AEC0AE80AEE0AEA75EB" +;
        "4F75E5B96E0039CA7203BA6D00F7F140"

* Convert them to binary
m.OriginalCode = HexToChar(m.OriginalCode)
m.NewCode = HexToChar(m.NewCode)

* Open the runtime file for write
HFile = FOPEN(m.cNewname, 2)
IF HFile = -1
        WAIT WINDOW "Couldn't open "+m.cNewname+": "+MESSAGE()
        RETURN
ENDIF

=FSEEK(HFile, 68524)
str = FREAD(HFile, LEN(m.OriginalCode))
IF !(str == m.OriginalCode)
        =FCLOSE(HFile)
        IF str == m.NewCode
        WAIT WINDOW m.cNewname+" is already patched."+;
                " Click to continue."
        ELSE
                WAIT WINDOW m.cNewname+" isn't Version 2.6A."+;
                " Click to continue."
        ENDIF
        RETURN
ENDIF

* Apply the patch
=FSEEK(HFile, 68524)
=FWRITE(HFile, m.NewCode)
=FCLOSE(HFile)
WAIT WINDOW m.cNewname+;
         " is now patched! Click to continue"
RETURN

*===========================================
* A crude utility routine:
* Convert a string of hex characters into a
* string of the bytes they represent
*===========================================
FUNCTION HexToChar
PARAMETER input
PRIVATE i, output

output = ""
DO WHILE !EMPTY(input)
        IF input >= "A"
                i = 10 + ASC(input)-ASC("A")
        ELSE
                i = ASC(input) - ASC("0")
        ENDIF
        i = i * 16
        input = SUBSTR(input,2)
        IF input >= "A"
                i = i + 10 + ASC(input)-ASC("A")
        ELSE
                i = i + ASC(input) - ASC("0")
        ENDIF
        output = output + CHR(i)
        input = SUBSTR(input,2)
ENDDO
RETURN output

------------
Remove both s's from my email address to respond directly

Quote:
>-----------snip-----------<



Fri, 09 Feb 2001 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Foxprow 2.5 divide by zero fix?

2. Divide by Zero error can't be fixed

3. LCK divide by zero problem HELP!!!

4. Divide by zero problem when porting FoxPro 2.6 (Win) to Visual FoxPro

5. Divide by zero or overflow error

6. error "overflow or divide by zero"

7. Divide by Zero or Overflow Error

8. Divide by Zero - even with SlowStart

9. NEWS! FPW Divide By Zero Patch - Please Read

10. Divide by zero error

11. Divide by zero

12. Divide by Zero Patch FPW2.5

 

 
Powered by phpBB® Forum Software