FACINX

From C64-Wiki
Jump to navigationJump to search

Note: This article describes the numeric FACINX routine in BASIC-ROM.

Name: FACINX
Description: Convert number in Floating point register FAC into 16-bit integer (Y=LB, A=HB).
Entry point: $B1AA / 45482
Passed arguments:
Return values:
Accumulator: Low-Byte of the integer
Y register: High-byte of the integer
Negative flag: set if and only if the integer is negative

FACINX converts the contents of the floating point register FAC into a signed 16-bit integer, which is then stored in the accumulator (Low-Byte) and in the Y register (High -Byte). Negative integers are encoded in the two's complement representation. The floating point number passed in FAC must be in the interval [ -32768; 32768 [, otherwise FACINX triggers an ?ILLEGAL QUANTITY ERROR.

FACINX only changes the contents of the floating point register FAC in memory. It is not called by any other routine in the BASIC ROM, but can be helpful for your own numerical programs.

Algorithm[edit | edit source]

FACINX does not implement an independent conversion, but only checks that the number in the floating point register FAC can be represented as a 16-bit integer. If this requirement is met, FACINX calls the ROM routine QINT to convert FAC to a 32-bit integer and then loads the lower two bytes of the result into the accumulator (low byte) and into the Y register (high byte). Otherwise FACINX reports an ?ILLEGAL QUANTITY ERROR.


Runtime behavior

The running time of FACINX consists of the computing time for the area check and loading the result into the registers (134 cycles if FAC = -32768, otherwise 29 cycles) and the running time of the routine QINT. In total, the ROM routine FACINX requires between 61 and 8273 cycles.

On the Commodore 64, one system clock corresponds to around one microsecond (μs). In the worst case, the FACINX routine requires around 8 milliseconds (ms) for the conversion.

Links[edit | edit source]