source: buchla-68k/orig/RAM/TOFPU.S@ 4f508e6

Last change on this file since 4f508e6 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Imported original source code.

  • Property mode set to 100755
File size: 2.1 KB
Line 
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 .text
18*
19 .xdef _tofpu
20 .xdef _fromfpu
21*
22TIME .equ 8 * WORD - time argument (either format)
23*
24TCYCL .equ $3B000000 * LONG - scaled FPU cycle time (.4608)
25*
26 .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*
33sloop: 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*
41gotexp: 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*
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*
52 .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*
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*
76 .end
Note: See TracBrowser for help on using the repository browser.