[4f508e6] | 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 | | ------------------------------------------------------------------------------
|
---|
[f40a309] | 17 | .text
|
---|
[4f508e6] | 18 |
|
---|
[f40a309] | 19 | .xdef _tofpu
|
---|
| 20 | .xdef _fromfpu
|
---|
[4f508e6] | 21 |
|
---|
| 22 | TIME = 8 | WORD - time argument (either format)
|
---|
| 23 |
|
---|
| 24 | TCYCL = 0x3B000000 | LONG - scaled FPU cycle time (.4608)
|
---|
| 25 |
|
---|
[f40a309] | 26 | .page
|
---|
[4f508e6] | 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 #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 |
|
---|
| 41 | gotexp: 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 |
|
---|
| 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 |
|
---|
[f40a309] | 52 | .page
|
---|
[4f508e6] | 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 |
|
---|
| 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 |
|
---|
[f40a309] | 76 | .end
|
---|