Changeset 4f508e6 in buchla-68k for ram/tofpu.s


Ignore:
Timestamp:
07/01/2017 02:34:46 PM (7 years ago)
Author:
Thomas Lopatic <thomas@…>
Branches:
master
Children:
08e1da1
Parents:
f40a309
Message:

Converted assembly language files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ram/tofpu.s

    rf40a309 r4f508e6  
    1 * ------------------------------------------------------------------------------
    2 * tofpu.s -- convert between millisecond time interval and FPU increment formats
    3 * Version 9 -- 1987-12-21 -- D.N. Lynx Crowe
    4 *
    5 *       unsigned short
    6 *       tofpu(time)
    7 *       unsigned short time;
    8 *
    9 *               Converts 'time' in milliseconds to FPU format.
    10 *
    11 *       unsigned short
    12 *       fromfpu(fputime)
    13 *       unsigned short fputime;
    14 *
    15 *               Converts 'fputime' from FPU format to milliseconds.
    16 * ------------------------------------------------------------------------------
     1| ------------------------------------------------------------------------------
     2| tofpu.s -- convert between millisecond time interval and FPU increment formats
     3| Version 9 -- 1987-12-21 -- D.N. Lynx Crowe
     4
     5|       unsigned short
     6|       tofpu(time)
     7|       unsigned short time;
     8
     9|               Converts 'time' in milliseconds to FPU format.
     10
     11|       unsigned short
     12|       fromfpu(fputime)
     13|       unsigned short fputime;
     14
     15|               Converts 'fputime' from FPU format to milliseconds.
     16| ------------------------------------------------------------------------------
    1717                .text
    18 *
     18
    1919                .xdef   _tofpu
    2020                .xdef   _fromfpu
    21 *
    22 TIME            .equ    8               * WORD - time argument  (either format)
    23 *
    24 TCYCL           .equ    $3B000000       * LONG - scaled FPU cycle time  (.4608)
    25 *
     21
     22TIME            =       8               | WORD - time argument  (either format)
     23
     24TCYCL           =       0x3B000000      | LONG - scaled FPU cycle time  (.4608)
     25
    2626                .page
    27 _tofpu:         link    a6,#0           * link stack frames
    28                 move.w  TIME(a6),d1     * get time interval
    29                 beq     notime          * jump if zero time
    30 *
    31                 clr.w   d2              * clear shift count
    32 *
    33 sloop:          btst    #15,d1          * see if MSB is set yet
    34                 bne     gotexp          * jump if so
    35 *
    36                 lsl.w   d1              * shift time left a bit
    37                 addq.w  #1,d2           * increment the shift count
    38                 cmpi.w  #15,d2          * see if we've hit the maximum
    39                 bne     sloop           * try again if not
    40 *
    41 gotexp:         move.l  #TCYCL,d0       * divide FPU cycle time by shifted value
    42                 divu    d1,d0           * ...
    43                 andi.w  #$FFF0,d0       * mask result
    44                 or.w    d2,d0           * set the exponent
    45 *
    46 finis:          unlk    a6              * unlink stack frames
    47                 rts                     * return to caller
    48 *
    49 notime:         clr.w   d0              * zero time is zero ...
    50                 bra     finis           * return value for zero time
    51 *
     27_tofpu:         link    a6,#0           | link stack frames
     28                move.w  TIME(a6),d1     | get time interval
     29                beq     notime          | jump if zero time
     30
     31                clr.w   d2              | clear shift count
     32
     33sloop:          btst    #15,d1          | see if MSB is set yet
     34                bne     gotexp          | jump if so
     35
     36                lsl.w   #1,d1           | shift time left a bit
     37                addq.w  #1,d2           | increment the shift count
     38                cmpi.w  #15,d2          | see if we've hit the maximum
     39                bne     sloop           | try again if not
     40
     41gotexp:         move.l  #TCYCL,d0       | divide FPU cycle time by shifted value
     42                divu    d1,d0           | ...
     43                andi.w  #0xFFF0,d0      | mask result
     44                or.w    d2,d0           | set the exponent
     45
     46finis:          unlk    a6              | unlink stack frames
     47                rts                     | return to caller
     48
     49notime:         clr.w   d0              | zero time is zero ...
     50                bra     finis           | return value for zero time
     51
    5252                .page
    53 _fromfpu:       link    a6,#0           * link stack frames
    54                 move.w  TIME(a6),d1     * get FPU formatted time
    55                 beq     zerotime        * done if it's zero
    56 *
    57                 move.w  d1,d2           * extract shift count
    58                 andi.w  #$000F,d2       * ...
    59                 andi.w  #$FFF0,d1       * extract mantissa
    60                 beq     zerotime        * ... just in case it's zero  (an error)
    61 *
    62                 move.l  #TCYCL,d0       * get FPU cycle time
    63                 divu    d1,d0           * divide by mantissa
    64                 bvc     divok           * jump if divide ok
    65 *
    66                 move.w  #$FFFF,d0       * jam maximum value for overflow
    67 *
    68 divok:          lsr.w   d2,d0           * shift result into position
    69 *
    70 byebye:         unlk    a6              * unlink stack frames
    71                 rts                     * return to caller
    72 *
    73 zerotime:       clr.l   d0              * return a zero result
    74                 bra     byebye          * ...
    75 *
     53_fromfpu:       link    a6,#0           | link stack frames
     54                move.w  TIME(a6),d1     | get FPU formatted time
     55                beq     zerotime        | done if it's zero
     56
     57                move.w  d1,d2           | extract shift count
     58                andi.w  #0x000F,d2      | ...
     59                andi.w  #0xFFF0,d1      | extract mantissa
     60                beq     zerotime        | ... just in case it's zero  (an error)
     61
     62                move.l  #TCYCL,d0       | get FPU cycle time
     63                divu    d1,d0           | divide by mantissa
     64                bvc     divok           | jump if divide ok
     65
     66                move.w  #0xFFFF,d0      | jam maximum value for overflow
     67
     68divok:          lsr.w   d2,d0           | shift result into position
     69
     70byebye:         unlk    a6              | unlink stack frames
     71                rts                     | return to caller
     72
     73zerotime:       clr.l   d0              | return a zero result
     74                bra     byebye          | ...
     75
    7676                .end
Note: See TracChangeset for help on using the changeset viewer.