Changeset 4f508e6 in buchla-68k for ram/tofpu.s
- Timestamp:
- 07/01/2017 02:34:46 PM (7 years ago)
- Branches:
- master
- Children:
- 08e1da1
- Parents:
- f40a309
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ram/tofpu.s
rf40a309 r4f508e6 1 *------------------------------------------------------------------------------2 *tofpu.s -- convert between millisecond time interval and FPU increment formats3 *Version 9 -- 1987-12-21 -- D.N. Lynx Crowe4 * 5 *unsigned short6 *tofpu(time)7 *unsigned short time;8 * 9 *Converts 'time' in milliseconds to FPU format.10 * 11 *unsigned short12 *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 | ------------------------------------------------------------------------------ 17 17 .text 18 * 18 19 19 .xdef _tofpu 20 20 .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 22 TIME = 8 | WORD - time argument (either format) 23 24 TCYCL = 0x3B000000 | LONG - scaled FPU cycle time (.4608) 25 26 26 .page 27 _tofpu: link a6,#0 *link stack frames28 move.w TIME(a6),d1 *get time interval29 beq notime *jump if zero time30 * 31 clr.w d2 *clear shift count32 * 33 sloop: btst #15,d1 *see if MSB is set yet34 bne gotexp *jump if so35 * 36 lsl.w d1 *shift time left a bit37 addq.w #1,d2 *increment the shift count38 cmpi.w #15,d2 *see if we've hit the maximum39 bne sloop *try again if not40 * 41 gotexp: move.l #TCYCL,d0 *divide FPU cycle time by shifted value42 divu d1,d0 *...43 andi.w # $FFF0,d0 *mask result44 or.w d2,d0 *set the exponent45 * 46 finis: unlk a6 *unlink stack frames47 rts *return to caller48 * 49 notime: clr.w d0 *zero time is zero ...50 bra finis *return value for zero time51 * 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 52 52 .page 53 _fromfpu: link a6,#0 *link stack frames54 move.w TIME(a6),d1 *get FPU formatted time55 beq zerotime *done if it's zero56 * 57 move.w d1,d2 *extract shift count58 andi.w # $000F,d2 *...59 andi.w # $FFF0,d1 *extract mantissa60 beq zerotime *... just in case it's zero (an error)61 * 62 move.l #TCYCL,d0 *get FPU cycle time63 divu d1,d0 *divide by mantissa64 bvc divok *jump if divide ok65 * 66 move.w # $FFFF,d0 *jam maximum value for overflow67 * 68 divok: lsr.w d2,d0 *shift result into position69 * 70 byebye: unlk a6 *unlink stack frames71 rts *return to caller72 * 73 zerotime: clr.l d0 *return a zero result74 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 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 76 76 .end
Note:
See TracChangeset
for help on using the changeset viewer.