Work around SANE bug in FX2C.

This could give incorrect results for extended-to-comp conversions of certain negative integers like -2147483648 and -53021371269120. To get a fix for the same problem with regard to long long, ORCA/C should be linked with the latest version of ORCALib (which also works around some instances of the problem at run time). There are still other cases involving code in SysFloat that has not yet been patched.
This commit is contained in:
Stephen Heumann 2021-11-28 14:28:42 -06:00
parent dda37cd17c
commit 6d8e019443
2 changed files with 36 additions and 1 deletions

35
CGC.asm
View File

@ -40,6 +40,9 @@ rec_ext equ 10 disp to extended (SANE) value
* Inputs:
* rec - pointer to a record
*
* Note: This avoids calling FX2C on negative numbers,
* because it is buggy for certain values.
*
****************************************************************
*
CnvSC start cg
@ -51,6 +54,11 @@ rec_cmp equ 20 disp to comp (SANE) value
tsc set up DP
phd
tcd
ldy #rec_real+8
lda [rec],y
pha save sign of real number
and #$7fff
sta [rec],y set sign of real number to positive
ph4 rec push addr of real number
clc push addr of SANE comp number
lda rec
@ -61,7 +69,32 @@ rec_cmp equ 20 disp to comp (SANE) value
pha
phx
fx2c convert TOS to SANE comp number
move4 0,4 return
pla
bpl ret if real number was negative
ldy #rec_real+8 restore original sign of real number
sta [rec],y
sec negate the comp value
ldy #rec_cmp
ldx #0
txa
sbc [rec],y
sta [rec],y
iny
iny
txa
sbc [rec],y
sta [rec],y
iny
iny
txa
sbc [rec],y
sta [rec],y
iny
iny
txa
sbc [rec],y
sta [rec],y
ret move4 0,4 return
pld
pla
pla

View File

@ -1575,6 +1575,8 @@ int foo(int[42]);
171. Function parameters declared with array types are adjusted to actually have pointer types, but this adjustment was not applied in some situations. Now such parameters are consistently treated as actually having pointer types. This affects their size as given by sizeof and their type as shown in debuggers.
172. When certain negative integers that are multiples of 65536 were converted from floating-point types to long, long long, or comp, an incorrect value might be produced due to a bug in SANE. ORCA/C now includes workarounds to avoid this bug in several situations, although it might still occur in certain other ones.
-- Bugs from C 2.1.0 that have been fixed -----------------------------------
1. In some situations, fread() reread the first 1K or so of the file.