home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / lib / mntc6846.zoo / patch / dftoul.s < prev    next >
Encoding:
Text File  |  1994-11-14  |  2.7 KB  |  82 lines

  1.  ! C68 8 byte floating point => 32 bit unsigned conversion routines
  2.  !-----------------------------------------------------------------------------
  3.  ! ported to 68000 by Kai-Uwe Bloem, 12/89
  4.  !  #1  original author: Peter S. Housel 6/12/89,6/14/89
  5.  !  #2  replaced shifts by swap if possible for speed increase -kub-, 01/90
  6.  !  #3  Added wrapper routine to provide C68 IEEE support
  7.  !                                             Dave & Keith Walker     02/92
  8.  !  #4    Changed entry/exit code for C68 v4.3 compatibility
  9.  !    Removed ACK entry point
  10.  !    Changed exception handling code                -djw-    09/93
  11.  !-----------------------------------------------------------------------------
  12.  
  13. BIAS8  =       0x3FF - 1
  14.  
  15.        .sect .text
  16.  
  17.        .define .Xdftoul
  18.  
  19. !----------------------------------------
  20. !      sp      Return address
  21. !      sp+4    address of float/double
  22. !----------------------------------------
  23. .Xdftoul:
  24.        move.l  4(sp),a0        ! address of value
  25.        move.w  (a0),d0         ! extract exp
  26.        move.w  d0,a1           ! extract sign
  27.        lsr.w   #4,d0
  28.        and.w   #0x07ff,d0      ! kill sign bit
  29.  
  30.        cmp.w   #BIAS8,d0       ! check exponent
  31.        blt     zer8            ! strictly factional, no integer part ?
  32.        cmp.w   #BIAS8+32,d0    ! is it too big to fit in a 32-bit integer ?
  33.        bgt     oflow
  34.  
  35.        movem.l (a0),d1-d2      ! get the value
  36.        and.l   #0x0fffff,d1    ! remove exponent from mantissa
  37.        or.l    #0x100000,d1    ! restore implied leading "1"
  38.  
  39.        sub.w   #BIAS8+21,d0    ! adjust exponent
  40.        bgt     2f              ! shift up
  41.        beq     3f              ! no shift
  42.  
  43.        cmp.w   #-8,d0          ! replace far shifts by swap
  44.        bgt     1f
  45.        move.w  d1,d2           ! shift fast, 16 bits
  46.        swap    d2
  47.        clr.w   d1
  48.        swap    d1
  49.        add.w   #16,d0          ! account for swap
  50.        bgt     2f
  51.        beq     3f
  52.  
  53. 1:     lsr.l   #1,d1           ! shift down to align radix point;
  54.        add.w   #1,d0           ! extra bits fall off the end (no rounding)
  55.        blt     1b              ! shifted all the way down yet ?
  56.        bra     3f
  57.  
  58. 2:     add.l   d2,d2           ! shift up to align radix point
  59.        addx.l  d1,d1
  60.        sub.w   #1,d0
  61.        bgt     2b
  62.        bra     3f
  63. zer8:
  64.        clr.l   d1              ! make the whole thing zero
  65.  
  66. 3:     move.l  d1,d0
  67.        move.w  a1,d2           ! get sign into d2
  68.        tst.w   d2              ! is it negative ?
  69.        bpl     finish
  70.        neg.l   d0              ! negate
  71.  
  72. finish:
  73.     move.l    (sp)+,a1    ! get return address
  74.     add.l    #4,sp        ! remove 1 parameter from stack
  75.     jmp    (a1)        ! and return to caller
  76.  
  77. oflow:
  78.     jsr    .overflow
  79.     move.l    #0xffffffff,d0    ! set ULONG_MAX as reply
  80.     bra    finish
  81.  
  82.