1: ldfps = 170100^tst 2: stfps = 170200^tst 3: / 4: .globl atan, _atan 5: .globl atan2, _atan2 6: / 7: / floating-point arctangent 8: / 9: / atan replaces the value in fr0 by its arctangent 10: / in the range [-pi/2,pi/2]. 11: / 12: / atan2 places in fr0 the arctangent of fr0/fr1 13: / in the range [-pi,pi]. 14: / 15: / there are no error exits 16: / 17: / coefficients are #5076 from Hart & Cheney. 18: / 19: / 20: 21: _atan: 22: mov r5,-(sp) 23: mov sp,r5 24: movf 4(r5),fr0 25: jsr pc,atan 26: br 1f 27: 28: _atan2: 29: mov r5,-(sp) 30: mov sp,r5 31: movf 4(r5),fr0 32: movf 12.(r5),fr1 33: jsr pc,atan2 34: 1: 35: mov (sp)+,r5 36: rts pc 37: atan: 38: jsr r0,save 39: tstf fr0 40: cfcc 41: blt 1f 42: jsr pc,satan 43: br ret 44: 1: 45: negf fr0 46: jsr pc,satan 47: negf fr0 48: br ret 49: / 50: atan2: 51: jsr r0,save 52: clr -(sp) 53: tstf fr0 54: cfcc 55: bge 1f 56: inc (sp) 57: negf fr0 58: 1: 59: tstf fr1 60: cfcc 61: beq 2f 62: bgt 1f 63: add $2,(sp) 64: negf fr1 65: 1: 66: divf fr1,fr0 67: jsr pc,satan 68: br 1f 69: 2: 70: movf pi2,fr0 71: 1: 72: bit $2,(sp) 73: beq 1f 74: negf fr0 75: addf pi2,fr0 76: addf pi2,fr0 77: 1: 78: bit $1,(sp)+ 79: beq 1f 80: negf fr0 81: 1: 82: 83: ret: 84: ldfps (sp)+ 85: movf (sp)+,fr3 86: movf (sp)+,fr2 87: movf (sp)+,fr1 88: mov (sp)+,r0 89: rts pc 90: 91: save: 92: movf fr1,-(sp) 93: movf fr2,-(sp) 94: movf fr3,-(sp) 95: stfps -(sp) 96: ldfps $40200 / DP, no interrupt 97: jmp (r0) 98: 99: satan: 100: cmpf sq2m1,fr0 101: cfcc 102: bge arctan 103: cmpf sq2p1,fr0 104: cfcc 105: bgt 1f 106: movf one,fr1 107: divf fr0,fr1 108: movf fr1,fr0 109: jsr pc,arctan 110: negf fr0 111: addf pi2,fr0 112: rts pc 113: 1: 114: movf fr0,fr1 115: subf one,fr0 116: addf one,fr1 117: divf fr1,fr0 118: jsr pc,arctan 119: addf pi4,fr0 120: rts pc 121: arctan: 122: mov $p4p,r0 123: mov $4,-(sp) 124: movf fr0,fr3 125: mulf fr3,fr3 126: movf *(r0)+,fr1 127: 1: 128: mulf fr3,fr1 129: addf *(r0)+,fr1 130: dec (sp) 131: bne 1b 132: mov $4,(sp) 133: movf fr3,fr2 134: br 2f 135: 1: 136: mulf fr3,fr2 137: 2: 138: addf *(r0)+,fr2 139: dec (sp) 140: bne 1b 141: tst (sp)+ 142: divf fr2,fr1 143: mulf fr1,fr0 144: rts pc 145: 146: .data 147: 148: p4p: 149: p4;p3;p2;p1;p0 150: q3;q2;q1;p0 151: 152: one: 40200;0;0;0 153: pi2: 40311;7732;121041;64302 154: pi4: 40111;7732;121041;64302 155: 156: sq2p1: 40432 157: 101171 158: 114774 159: 167461 160: 161: sq2m1: 37724 162: 11714 163: 147747 164: 74621 165: 166: p4: 37442 167: 145026 168: 75504 169: 15621 170: p3: 40725 171: 21566 172: 115517 173: 50305 174: p2: 41443 175: 160206 176: 172714 177: 25441 178: p1: 41632 179: 172223 180: 76027 181: 56645 182: p0: 41462 183: 25125 184: 6152 185: 126064 186: q3: 41170 187: 10112 188: 141724 189: 64324 190: q2: 41573 191: 53776 192: 25372 193: 71522 194: q1: 41670 195: 123114 196: 51576 197: 75020 198: 199: / one = 1.00000 00000 00000 00000 d0 200: / sq2p1=2.41421 35623 73095 04880 d0 201: / sq2m1= .41421 35623 73095 04880 d0 202: / pi2 = 1.57079 63267 94896 61923 d0 203: / p4 = .15897 40288 48230 7048 d0 204: / p3 = .66605 79017 00926 2658 d1 205: / p2 = .40969 26483 21022 5637 d2 206: / p1 = .77477 68771 92042 0862 d2 207: / p0 = .44541 34005 92906 8032 d2 208: / q4 = .10000 00000 00000 0000 d1 209: / q3 = .15503 97755 14219 8753 d2 210: / q2 = .62835 93051 10323 7683 d2 211: / q1 = .92324 80107 23009 7484 d2 212: / q0 = .44541 34005 92906 8044 d2