Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!nbires!isis!udenva!cu-den!boulder!sunybcs!rutgers!cbmvax!fred From: fred@cbmvax.UUCP (Fred Bowen) Newsgroups: comp.sys.cbm Subject: Re: C Power 128 floating point to integer conversion bug Message-ID: <2691@cbmvax.UUCP> Date: Thu, 5-Nov-87 12:59:21 EST Article-I.D.: cbmvax.2691 Posted: Thu Nov 5 12:59:21 1987 Date-Received: Sun, 8-Nov-87 12:03:07 EST References: <5365@rutgers.rutgers.edu> <613@hyper.UUCP> Organization: Commodore Technology, West Chester, PA Lines: 55 In article <613@hyper.UUCP>, dean@hyper.UUCP (Dean Gahlon) writes: > In article <5365@rutgers.rutgers.edu>, prindle@NADC.ARPA writes: > > > > I have finally figured out what causes C Power 128 to incorrectly convert > > floating point values to integers (signed), and this bug could explain > > all kinds of miscellaneous problems with floating point when using this > > compiler. The problem is in library file "float1.obj". It revolves around > > a BASIC routine used to do the conversion; the library assumes this BASIC > > routine returns it's values in the A and Y registers, but it doesn't; rather > > it returns them in the floating point accumulator in bank 0. > > Are you sure that that's all of the problem? I discovered this > particular problem some time ago (by the way, it's caused, I think, by > the fact that the name in the C-128 Programmer's Reference refers to the > routine that's called incorrectly as "GIVAYF", leading one to the wrong > impression that it returns its results in the AY pair), but didn't post > any results at that time because I still seem to have problems using floating > point. Frank is correct, and Dean is confused. There is no problem that I am aware of with GIVAYF, and the C128 ROM upgrade has no changes here. The routine is the same as that of the C64, and refers to passing a signed integer in the A and Y registers (msb/lsb) and getting the floating point represntation in the FAC. The address of GIVAYF, besides being in the C128 BASIC jump table, also appears at the RAM vector ADRAY2 ($5 on the C64, $117C on the C128) for historical compatibility. GIVAYF is typically used by programmers utilizing the USR(x) BASIC function to return values. GIVAYF is documented in many, many books, dating from the PET days. This routine is described, along with an example, in the DEVpack manual. That doesn't help you now, eh? Well, for those interested, here's a simple example for the C128: $1800 A9 00 LDA #>int_val $1802 A0 46 LDY # FAC $1807 20 AF 06 JSR FOUT ;FAC -> STRING @ $100 $18OA A0 00 LDY #0 $180C B9 00 01 LDA $100,Y $180F F0 06 BEQ $1817 $1811 20 D2 FF JSR BSOUT ;PRINT STRING $1814 C8 INY $1815 D0 F5 BNE $180C $1817 60 RTS If you call this from the monitor with something like JF1800, it will print the decimal value of whatever is in A and Y ($46 here, my initial). (Betcha didn't think math hacking could be this much fun! Wanna tackle floating point multiplication and division, then, um, trig functions next? :-) -- -- Fred Bowen uucp: {ihnp4|rutgers|caip}!cbmvax!fred arpa: cbmvax!fred@RUTGERS.EDU tele: 215 431-9100 Commodore Electronics, Ltd., 1200 Wilson Drive, West Chester, PA, 19380