FIX.ASM 20 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336
  1. ;THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  2. ;SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
  3. ;END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  4. ;ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  5. ;IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  6. ;SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  7. ;FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  8. ;CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
  9. ;AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
  10. ;COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
  11. ;
  12. ; $Source: f:/miner/source/fix/rcs/fix.asm $
  13. ; $Revision: 1.16 $
  14. ; $Author: mike $
  15. ; $Date: 1994/11/30 00:59:40 $
  16. ;
  17. ; Fixed-point rotines
  18. ;
  19. ; $Log: fix.asm $
  20. ; Revision 1.16 1994/11/30 00:59:40 mike
  21. ; optimizations.
  22. ;
  23. ; Revision 1.15 1994/11/16 18:05:01 matt
  24. ; Added error checking to atan2
  25. ;
  26. ; Revision 1.14 1994/10/21 12:14:26 matt
  27. ; For acos & asin, saturate at 1 instead of generate error
  28. ;
  29. ; Revision 1.13 1994/05/18 17:15:56 matt
  30. ; Allow sin & cos ptrs in C sincos func to be null
  31. ;
  32. ; Revision 1.12 1994/02/10 21:23:08 matt
  33. ; Changed 'if DEBUG_ON' to 'ifndef NDEBUG'
  34. ;
  35. ; Revision 1.11 1994/01/19 23:11:26 matt
  36. ; Made fix_atan2() left-handed, like our coordinate system
  37. ;
  38. ; Revision 1.10 1993/10/26 18:51:49 matt
  39. ; Fixed register trash in fix_atan2()
  40. ;
  41. ; Revision 1.9 1993/10/20 01:09:01 matt
  42. ; Add fix_asin(), improved fix_atan2()
  43. ;
  44. ; Revision 1.8 1993/10/19 23:53:48 matt
  45. ; Added fix_atan2()
  46. ;
  47. ; Revision 1.7 1993/10/19 22:22:34 matt
  48. ; Added fix_acos()
  49. ;
  50. ; Revision 1.6 1993/09/10 19:13:44 matt
  51. ; Fixed problem with quad_sqrt() when edx==0 and high bit of eax set
  52. ;
  53. ; Revision 1.5 1993/08/24 13:00:17 matt
  54. ; Adopted new standard, and made assembly-callable routines not trash any regs
  55. ;
  56. ; Revision 1.4 1993/08/12 14:43:34 matt
  57. ; Added rcsid
  58. ;
  59. ; Revision 1.3 1993/08/06 15:59:49 matt
  60. ; Added check for high bit of low longword set in quad_sqrt
  61. ; Changed long_sqrt to do longword moves and save the override
  62. ;
  63. ; Revision 1.2 1993/08/04 19:56:03 matt
  64. ; Fixed mistake in quad_sqrt first quess code
  65. ;
  66. ; Revision 1.1 1993/08/03 17:45:26 matt
  67. ; Initial revision
  68. ;
  69. ;
  70. ;
  71. .386
  72. option oldstructs
  73. .nolist
  74. include types.inc
  75. include psmacros.inc
  76. include fix.inc
  77. .list
  78. assume cs:_TEXT,ds:_DATA
  79. _DATA segment dword public USE32 'DATA'
  80. rcsid db "$Id: fix.asm 1.16 1994/11/30 00:59:40 mike Exp $"
  81. sin_table dw 0
  82. dw 402
  83. dw 804
  84. dw 1205
  85. dw 1606
  86. dw 2006
  87. dw 2404
  88. dw 2801
  89. dw 3196
  90. dw 3590
  91. dw 3981
  92. dw 4370
  93. dw 4756
  94. dw 5139
  95. dw 5520
  96. dw 5897
  97. dw 6270
  98. dw 6639
  99. dw 7005
  100. dw 7366
  101. dw 7723
  102. dw 8076
  103. dw 8423
  104. dw 8765
  105. dw 9102
  106. dw 9434
  107. dw 9760
  108. dw 10080
  109. dw 10394
  110. dw 10702
  111. dw 11003
  112. dw 11297
  113. dw 11585
  114. dw 11866
  115. dw 12140
  116. dw 12406
  117. dw 12665
  118. dw 12916
  119. dw 13160
  120. dw 13395
  121. dw 13623
  122. dw 13842
  123. dw 14053
  124. dw 14256
  125. dw 14449
  126. dw 14635
  127. dw 14811
  128. dw 14978
  129. dw 15137
  130. dw 15286
  131. dw 15426
  132. dw 15557
  133. dw 15679
  134. dw 15791
  135. dw 15893
  136. dw 15986
  137. dw 16069
  138. dw 16143
  139. dw 16207
  140. dw 16261
  141. dw 16305
  142. dw 16340
  143. dw 16364
  144. dw 16379
  145. cos_table dw 16384
  146. dw 16379
  147. dw 16364
  148. dw 16340
  149. dw 16305
  150. dw 16261
  151. dw 16207
  152. dw 16143
  153. dw 16069
  154. dw 15986
  155. dw 15893
  156. dw 15791
  157. dw 15679
  158. dw 15557
  159. dw 15426
  160. dw 15286
  161. dw 15137
  162. dw 14978
  163. dw 14811
  164. dw 14635
  165. dw 14449
  166. dw 14256
  167. dw 14053
  168. dw 13842
  169. dw 13623
  170. dw 13395
  171. dw 13160
  172. dw 12916
  173. dw 12665
  174. dw 12406
  175. dw 12140
  176. dw 11866
  177. dw 11585
  178. dw 11297
  179. dw 11003
  180. dw 10702
  181. dw 10394
  182. dw 10080
  183. dw 9760
  184. dw 9434
  185. dw 9102
  186. dw 8765
  187. dw 8423
  188. dw 8076
  189. dw 7723
  190. dw 7366
  191. dw 7005
  192. dw 6639
  193. dw 6270
  194. dw 5897
  195. dw 5520
  196. dw 5139
  197. dw 4756
  198. dw 4370
  199. dw 3981
  200. dw 3590
  201. dw 3196
  202. dw 2801
  203. dw 2404
  204. dw 2006
  205. dw 1606
  206. dw 1205
  207. dw 804
  208. dw 402
  209. dw 0
  210. dw -402
  211. dw -804
  212. dw -1205
  213. dw -1606
  214. dw -2006
  215. dw -2404
  216. dw -2801
  217. dw -3196
  218. dw -3590
  219. dw -3981
  220. dw -4370
  221. dw -4756
  222. dw -5139
  223. dw -5520
  224. dw -5897
  225. dw -6270
  226. dw -6639
  227. dw -7005
  228. dw -7366
  229. dw -7723
  230. dw -8076
  231. dw -8423
  232. dw -8765
  233. dw -9102
  234. dw -9434
  235. dw -9760
  236. dw -10080
  237. dw -10394
  238. dw -10702
  239. dw -11003
  240. dw -11297
  241. dw -11585
  242. dw -11866
  243. dw -12140
  244. dw -12406
  245. dw -12665
  246. dw -12916
  247. dw -13160
  248. dw -13395
  249. dw -13623
  250. dw -13842
  251. dw -14053
  252. dw -14256
  253. dw -14449
  254. dw -14635
  255. dw -14811
  256. dw -14978
  257. dw -15137
  258. dw -15286
  259. dw -15426
  260. dw -15557
  261. dw -15679
  262. dw -15791
  263. dw -15893
  264. dw -15986
  265. dw -16069
  266. dw -16143
  267. dw -16207
  268. dw -16261
  269. dw -16305
  270. dw -16340
  271. dw -16364
  272. dw -16379
  273. dw -16384
  274. dw -16379
  275. dw -16364
  276. dw -16340
  277. dw -16305
  278. dw -16261
  279. dw -16207
  280. dw -16143
  281. dw -16069
  282. dw -15986
  283. dw -15893
  284. dw -15791
  285. dw -15679
  286. dw -15557
  287. dw -15426
  288. dw -15286
  289. dw -15137
  290. dw -14978
  291. dw -14811
  292. dw -14635
  293. dw -14449
  294. dw -14256
  295. dw -14053
  296. dw -13842
  297. dw -13623
  298. dw -13395
  299. dw -13160
  300. dw -12916
  301. dw -12665
  302. dw -12406
  303. dw -12140
  304. dw -11866
  305. dw -11585
  306. dw -11297
  307. dw -11003
  308. dw -10702
  309. dw -10394
  310. dw -10080
  311. dw -9760
  312. dw -9434
  313. dw -9102
  314. dw -8765
  315. dw -8423
  316. dw -8076
  317. dw -7723
  318. dw -7366
  319. dw -7005
  320. dw -6639
  321. dw -6270
  322. dw -5897
  323. dw -5520
  324. dw -5139
  325. dw -4756
  326. dw -4370
  327. dw -3981
  328. dw -3590
  329. dw -3196
  330. dw -2801
  331. dw -2404
  332. dw -2006
  333. dw -1606
  334. dw -1205
  335. dw -804
  336. dw -402
  337. dw 0
  338. dw 402
  339. dw 804
  340. dw 1205
  341. dw 1606
  342. dw 2006
  343. dw 2404
  344. dw 2801
  345. dw 3196
  346. dw 3590
  347. dw 3981
  348. dw 4370
  349. dw 4756
  350. dw 5139
  351. dw 5520
  352. dw 5897
  353. dw 6270
  354. dw 6639
  355. dw 7005
  356. dw 7366
  357. dw 7723
  358. dw 8076
  359. dw 8423
  360. dw 8765
  361. dw 9102
  362. dw 9434
  363. dw 9760
  364. dw 10080
  365. dw 10394
  366. dw 10702
  367. dw 11003
  368. dw 11297
  369. dw 11585
  370. dw 11866
  371. dw 12140
  372. dw 12406
  373. dw 12665
  374. dw 12916
  375. dw 13160
  376. dw 13395
  377. dw 13623
  378. dw 13842
  379. dw 14053
  380. dw 14256
  381. dw 14449
  382. dw 14635
  383. dw 14811
  384. dw 14978
  385. dw 15137
  386. dw 15286
  387. dw 15426
  388. dw 15557
  389. dw 15679
  390. dw 15791
  391. dw 15893
  392. dw 15986
  393. dw 16069
  394. dw 16143
  395. dw 16207
  396. dw 16261
  397. dw 16305
  398. dw 16340
  399. dw 16364
  400. dw 16379
  401. dw 16384
  402. asin_table dw 0
  403. dw 41
  404. dw 81
  405. dw 122
  406. dw 163
  407. dw 204
  408. dw 244
  409. dw 285
  410. dw 326
  411. dw 367
  412. dw 408
  413. dw 448
  414. dw 489
  415. dw 530
  416. dw 571
  417. dw 612
  418. dw 652
  419. dw 693
  420. dw 734
  421. dw 775
  422. dw 816
  423. dw 857
  424. dw 897
  425. dw 938
  426. dw 979
  427. dw 1020
  428. dw 1061
  429. dw 1102
  430. dw 1143
  431. dw 1184
  432. dw 1225
  433. dw 1266
  434. dw 1307
  435. dw 1348
  436. dw 1389
  437. dw 1431
  438. dw 1472
  439. dw 1513
  440. dw 1554
  441. dw 1595
  442. dw 1636
  443. dw 1678
  444. dw 1719
  445. dw 1760
  446. dw 1802
  447. dw 1843
  448. dw 1884
  449. dw 1926
  450. dw 1967
  451. dw 2009
  452. dw 2050
  453. dw 2092
  454. dw 2134
  455. dw 2175
  456. dw 2217
  457. dw 2259
  458. dw 2300
  459. dw 2342
  460. dw 2384
  461. dw 2426
  462. dw 2468
  463. dw 2510
  464. dw 2551
  465. dw 2593
  466. dw 2636
  467. dw 2678
  468. dw 2720
  469. dw 2762
  470. dw 2804
  471. dw 2847
  472. dw 2889
  473. dw 2931
  474. dw 2974
  475. dw 3016
  476. dw 3059
  477. dw 3101
  478. dw 3144
  479. dw 3187
  480. dw 3229
  481. dw 3272
  482. dw 3315
  483. dw 3358
  484. dw 3401
  485. dw 3444
  486. dw 3487
  487. dw 3530
  488. dw 3573
  489. dw 3617
  490. dw 3660
  491. dw 3704
  492. dw 3747
  493. dw 3791
  494. dw 3834
  495. dw 3878
  496. dw 3922
  497. dw 3965
  498. dw 4009
  499. dw 4053
  500. dw 4097
  501. dw 4142
  502. dw 4186
  503. dw 4230
  504. dw 4275
  505. dw 4319
  506. dw 4364
  507. dw 4408
  508. dw 4453
  509. dw 4498
  510. dw 4543
  511. dw 4588
  512. dw 4633
  513. dw 4678
  514. dw 4723
  515. dw 4768
  516. dw 4814
  517. dw 4859
  518. dw 4905
  519. dw 4951
  520. dw 4997
  521. dw 5043
  522. dw 5089
  523. dw 5135
  524. dw 5181
  525. dw 5228
  526. dw 5274
  527. dw 5321
  528. dw 5367
  529. dw 5414
  530. dw 5461
  531. dw 5508
  532. dw 5556
  533. dw 5603
  534. dw 5651
  535. dw 5698
  536. dw 5746
  537. dw 5794
  538. dw 5842
  539. dw 5890
  540. dw 5938
  541. dw 5987
  542. dw 6035
  543. dw 6084
  544. dw 6133
  545. dw 6182
  546. dw 6231
  547. dw 6281
  548. dw 6330
  549. dw 6380
  550. dw 6430
  551. dw 6480
  552. dw 6530
  553. dw 6580
  554. dw 6631
  555. dw 6681
  556. dw 6732
  557. dw 6783
  558. dw 6835
  559. dw 6886
  560. dw 6938
  561. dw 6990
  562. dw 7042
  563. dw 7094
  564. dw 7147
  565. dw 7199
  566. dw 7252
  567. dw 7306
  568. dw 7359
  569. dw 7413
  570. dw 7466
  571. dw 7521
  572. dw 7575
  573. dw 7630
  574. dw 7684
  575. dw 7740
  576. dw 7795
  577. dw 7851
  578. dw 7907
  579. dw 7963
  580. dw 8019
  581. dw 8076
  582. dw 8133
  583. dw 8191
  584. dw 8249
  585. dw 8307
  586. dw 8365
  587. dw 8424
  588. dw 8483
  589. dw 8543
  590. dw 8602
  591. dw 8663
  592. dw 8723
  593. dw 8784
  594. dw 8846
  595. dw 8907
  596. dw 8970
  597. dw 9032
  598. dw 9095
  599. dw 9159
  600. dw 9223
  601. dw 9288
  602. dw 9353
  603. dw 9418
  604. dw 9484
  605. dw 9551
  606. dw 9618
  607. dw 9686
  608. dw 9754
  609. dw 9823
  610. dw 9892
  611. dw 9963
  612. dw 10034
  613. dw 10105
  614. dw 10177
  615. dw 10251
  616. dw 10324
  617. dw 10399
  618. dw 10475
  619. dw 10551
  620. dw 10628
  621. dw 10706
  622. dw 10785
  623. dw 10866
  624. dw 10947
  625. dw 11029
  626. dw 11113
  627. dw 11198
  628. dw 11284
  629. dw 11371
  630. dw 11460
  631. dw 11550
  632. dw 11642
  633. dw 11736
  634. dw 11831
  635. dw 11929
  636. dw 12028
  637. dw 12130
  638. dw 12234
  639. dw 12340
  640. dw 12449
  641. dw 12561
  642. dw 12677
  643. dw 12796
  644. dw 12919
  645. dw 13046
  646. dw 13178
  647. dw 13315
  648. dw 13459
  649. dw 13610
  650. dw 13770
  651. dw 13939
  652. dw 14121
  653. dw 14319
  654. dw 14538
  655. dw 14786
  656. dw 15079
  657. dw 15462
  658. dw 16384
  659. dw 16384 ;extra for when exacty 1
  660. acos_table dw 16384
  661. dw 16343
  662. dw 16303
  663. dw 16262
  664. dw 16221
  665. dw 16180
  666. dw 16140
  667. dw 16099
  668. dw 16058
  669. dw 16017
  670. dw 15976
  671. dw 15936
  672. dw 15895
  673. dw 15854
  674. dw 15813
  675. dw 15772
  676. dw 15732
  677. dw 15691
  678. dw 15650
  679. dw 15609
  680. dw 15568
  681. dw 15527
  682. dw 15487
  683. dw 15446
  684. dw 15405
  685. dw 15364
  686. dw 15323
  687. dw 15282
  688. dw 15241
  689. dw 15200
  690. dw 15159
  691. dw 15118
  692. dw 15077
  693. dw 15036
  694. dw 14995
  695. dw 14953
  696. dw 14912
  697. dw 14871
  698. dw 14830
  699. dw 14789
  700. dw 14748
  701. dw 14706
  702. dw 14665
  703. dw 14624
  704. dw 14582
  705. dw 14541
  706. dw 14500
  707. dw 14458
  708. dw 14417
  709. dw 14375
  710. dw 14334
  711. dw 14292
  712. dw 14250
  713. dw 14209
  714. dw 14167
  715. dw 14125
  716. dw 14084
  717. dw 14042
  718. dw 14000
  719. dw 13958
  720. dw 13916
  721. dw 13874
  722. dw 13833
  723. dw 13791
  724. dw 13748
  725. dw 13706
  726. dw 13664
  727. dw 13622
  728. dw 13580
  729. dw 13537
  730. dw 13495
  731. dw 13453
  732. dw 13410
  733. dw 13368
  734. dw 13325
  735. dw 13283
  736. dw 13240
  737. dw 13197
  738. dw 13155
  739. dw 13112
  740. dw 13069
  741. dw 13026
  742. dw 12983
  743. dw 12940
  744. dw 12897
  745. dw 12854
  746. dw 12811
  747. dw 12767
  748. dw 12724
  749. dw 12680
  750. dw 12637
  751. dw 12593
  752. dw 12550
  753. dw 12506
  754. dw 12462
  755. dw 12419
  756. dw 12375
  757. dw 12331
  758. dw 12287
  759. dw 12242
  760. dw 12198
  761. dw 12154
  762. dw 12109
  763. dw 12065
  764. dw 12020
  765. dw 11976
  766. dw 11931
  767. dw 11886
  768. dw 11841
  769. dw 11796
  770. dw 11751
  771. dw 11706
  772. dw 11661
  773. dw 11616
  774. dw 11570
  775. dw 11525
  776. dw 11479
  777. dw 11433
  778. dw 11387
  779. dw 11341
  780. dw 11295
  781. dw 11249
  782. dw 11203
  783. dw 11156
  784. dw 11110
  785. dw 11063
  786. dw 11017
  787. dw 10970
  788. dw 10923
  789. dw 10876
  790. dw 10828
  791. dw 10781
  792. dw 10733
  793. dw 10686
  794. dw 10638
  795. dw 10590
  796. dw 10542
  797. dw 10494
  798. dw 10446
  799. dw 10397
  800. dw 10349
  801. dw 10300
  802. dw 10251
  803. dw 10202
  804. dw 10153
  805. dw 10103
  806. dw 10054
  807. dw 10004
  808. dw 9954
  809. dw 9904
  810. dw 9854
  811. dw 9804
  812. dw 9753
  813. dw 9703
  814. dw 9652
  815. dw 9601
  816. dw 9549
  817. dw 9498
  818. dw 9446
  819. dw 9394
  820. dw 9342
  821. dw 9290
  822. dw 9237
  823. dw 9185
  824. dw 9132
  825. dw 9078
  826. dw 9025
  827. dw 8971
  828. dw 8918
  829. dw 8863
  830. dw 8809
  831. dw 8754
  832. dw 8700
  833. dw 8644
  834. dw 8589
  835. dw 8533
  836. dw 8477
  837. dw 8421
  838. dw 8365
  839. dw 8308
  840. dw 8251
  841. dw 8193
  842. dw 8135
  843. dw 8077
  844. dw 8019
  845. dw 7960
  846. dw 7901
  847. dw 7841
  848. dw 7782
  849. dw 7721
  850. dw 7661
  851. dw 7600
  852. dw 7538
  853. dw 7477
  854. dw 7414
  855. dw 7352
  856. dw 7289
  857. dw 7225
  858. dw 7161
  859. dw 7096
  860. dw 7031
  861. dw 6966
  862. dw 6900
  863. dw 6833
  864. dw 6766
  865. dw 6698
  866. dw 6630
  867. dw 6561
  868. dw 6492
  869. dw 6421
  870. dw 6350
  871. dw 6279
  872. dw 6207
  873. dw 6133
  874. dw 6060
  875. dw 5985
  876. dw 5909
  877. dw 5833
  878. dw 5756
  879. dw 5678
  880. dw 5599
  881. dw 5518
  882. dw 5437
  883. dw 5355
  884. dw 5271
  885. dw 5186
  886. dw 5100
  887. dw 5013
  888. dw 4924
  889. dw 4834
  890. dw 4742
  891. dw 4648
  892. dw 4553
  893. dw 4455
  894. dw 4356
  895. dw 4254
  896. dw 4150
  897. dw 4044
  898. dw 3935
  899. dw 3823
  900. dw 3707
  901. dw 3588
  902. dw 3465
  903. dw 3338
  904. dw 3206
  905. dw 3069
  906. dw 2925
  907. dw 2774
  908. dw 2614
  909. dw 2445
  910. dw 2263
  911. dw 2065
  912. dw 1846
  913. dw 1598
  914. dw 1305
  915. dw 922
  916. dw 0
  917. dw 0 ;extra for when exacty 1
  918. ;values for first guess in square root routines. Note that the first entry
  919. ;is useful in quad_sqrt when edx=0 and high bit of eax is set.
  920. guess_table db 1 dup (1) ;0
  921. db 3 dup (1) ;1..3
  922. db 5 dup (2) ;4..8
  923. db 7 dup (3) ;9..15
  924. db 9 dup (4) ;16..24
  925. db 11 dup (5) ;25..35
  926. db 13 dup (6) ;36..48
  927. db 15 dup (7) ;49..63
  928. db 17 dup (8) ;64..80
  929. db 19 dup (9) ;81..99
  930. db 21 dup (10) ;100..120
  931. db 23 dup (11) ;121..143
  932. db 25 dup (12) ;144..168
  933. db 27 dup (13) ;169..195
  934. db 29 dup (14) ;196..224
  935. db 31 dup (15) ;225..255
  936. _DATA ends
  937. _TEXT segment para public USE32 'CODE'
  938. ;the sincos functions have two varients: the C version is passed pointer
  939. ;to variables for sin & cos, and the assembly version returns the values
  940. ;in two registers
  941. ;takes ax=angle, returns eax=sin, ebx=cos.
  942. fix_fastsincos:
  943. movzx eax,ah ;get high byte
  944. movsx ebx,cos_table[eax*2]
  945. sal ebx,2 ;make a fix
  946. movsx eax,sin_table[eax*2]
  947. sal eax,2 ;make a fix
  948. ret
  949. ;takes ax=angle, returns eax=sin, ebx=cos.
  950. fix_sincos:
  951. pushm ecx,edx
  952. xor edx, edx
  953. xor ecx, ecx
  954. mov dl, ah ;get high byte
  955. mov cl, al ;save low byte
  956. shl edx, 1
  957. movsx eax,sin_table[edx]
  958. movsx ebx,sin_table+2[edx]
  959. sub ebx,eax
  960. imul ebx,ecx ;mul by fraction
  961. sar ebx,8
  962. add eax,ebx ;add in frac part
  963. sal eax,2 ;make a fix
  964. movsx ebx,cos_table[edx]
  965. movsx edx,cos_table+2[edx]
  966. sub edx,ebx
  967. imul edx,ecx ;mul by fraction
  968. sar edx,8
  969. add ebx,edx ;add in frac part
  970. sal ebx,2 ;make a fix
  971. popm ecx,edx
  972. ret
  973. align 16
  974. ;takes eax=cos angle, returns ax=angle
  975. fix_acos: pushm ebx,ecx,edx
  976. abs_eax ;get abs value
  977. push edx ;save sign
  978. cmp eax,10000h
  979. jle no_acos_oflow
  980. mov eax,10000h
  981. no_acos_oflow:
  982. movzx ecx,al ;save low byte (fraction)
  983. mov edx,eax
  984. sar edx,8 ;get high byte (+1 bit)
  985. movsx eax,acos_table[edx*2]
  986. movsx ebx,acos_table+2[edx*2]
  987. sub ebx,eax
  988. imul ebx,ecx ;mul by fraction
  989. sar ebx,8
  990. add eax,ebx ;add in frac part
  991. pop edx ;get sign back
  992. xor eax,edx
  993. sub eax,edx ;make correct sign
  994. and edx,8000h ;zero or 1/2
  995. add eax,edx
  996. popm ebx,ecx,edx
  997. ret
  998. ;takes eax=sin angle, returns ax=angle
  999. fix_asin: pushm ebx,ecx,edx
  1000. abs_eax ;get abs value
  1001. push edx ;save sign
  1002. cmp eax,10000h
  1003. jle no_asin_oflow
  1004. mov eax,10000h
  1005. no_asin_oflow:
  1006. movzx ecx,al ;save low byte (fraction)
  1007. mov edx,eax
  1008. sar edx,8 ;get high byte (+1 bit)
  1009. movsx eax,asin_table[edx*2]
  1010. movsx ebx,asin_table+2[edx*2]
  1011. sub ebx,eax
  1012. imul ebx,ecx ;mul by fraction
  1013. sar ebx,8
  1014. add eax,ebx ;add in frac part
  1015. pop edx ;get sign back
  1016. xor eax,edx ;make sign correct
  1017. sub eax,edx
  1018. popm ebx,ecx,edx
  1019. ret
  1020. ;given cos & sin of an angle, return that angle. takes eax=cos,ebx=sin.
  1021. ;returns ax. parms need not be normalized, that is, the ratio eax/ebx must
  1022. ;equal the ratio cos/sin, but the parms need not be the actual cos & sin.
  1023. ;NOTE: this is different from the standard C atan2, since it is left-handed.
  1024. ;trashes ebx
  1025. ;uses either asin or acos, to get better precision
  1026. fix_atan2: pushm ecx,edx
  1027. ifndef NDEBUG
  1028. mov edx,eax
  1029. or edx,ebx
  1030. break_if z,'Both parms to atan2 are zero!'
  1031. endif
  1032. push ebx
  1033. push eax
  1034. ;find smaller of two
  1035. pushm eax,ebx ;save
  1036. abs_eax
  1037. xchg eax,ebx
  1038. abs_eax
  1039. cmp ebx,eax ;compare x to y
  1040. popm eax,ebx
  1041. jl use_cos
  1042. ;sin is smaller, use arcsin
  1043. imul eax
  1044. xchg eax,ebx
  1045. mov ecx,edx
  1046. imul eax
  1047. add eax,ebx
  1048. adc edx,ecx
  1049. call quad_sqrt
  1050. mov ecx,eax ;ecx = mag
  1051. pop ebx ;get cos, save in ebx
  1052. pop eax ;get sin
  1053. jecxz sign_ok ;abort!
  1054. fixdiv ecx ;normalize it
  1055. call fix_asin ;get angle
  1056. or ebx,ebx ;check sign of cos
  1057. jns sign_ok
  1058. sub eax,8000h ;adjust
  1059. neg eax
  1060. sign_ok:
  1061. popm ecx,edx
  1062. ret
  1063. ;cos is smaller, use arccos
  1064. use_cos: imul eax
  1065. xchg eax,ebx
  1066. mov ecx,edx
  1067. imul eax
  1068. add eax,ebx
  1069. adc edx,ecx
  1070. call quad_sqrt
  1071. mov ecx,eax
  1072. pop eax ;get cos
  1073. fixdiv ecx ;normalize it
  1074. call fix_acos ;get angle
  1075. mov ebx,eax ;save in ebx
  1076. pop eax ;get sin
  1077. cdq ;get sign of sin
  1078. mov eax,ebx ;get cos back
  1079. xor eax,edx
  1080. sub eax,edx ;make sign correct
  1081. popm ecx,edx
  1082. ret
  1083. public fix_fastsincos_,fix_sincos_
  1084. ;C version - takes ax=angle, esi,edi=*sin,*cos. fills in sin&cos.
  1085. ;either (or both) pointers can be null
  1086. ;trashes eax,ebx
  1087. fix_fastsincos_: call fix_fastsincos
  1088. or esi,esi
  1089. jz no_sin
  1090. mov [esi],eax
  1091. no_sin: or edi,edi
  1092. jz no_cos
  1093. mov [edi],ebx
  1094. no_cos: ret
  1095. ;C version - takes ax=angle, esi,edi=*sin,*cos. fills in sin&cos.
  1096. ;trashes eax,ebx
  1097. ;either (or both) pointers can be null
  1098. fix_sincos_: call fix_sincos
  1099. or esi,esi
  1100. jz no_sin
  1101. mov [esi],eax
  1102. or edi,edi
  1103. jz no_cos
  1104. mov [edi],ebx
  1105. ret
  1106. ;standard Newtonian-iteration square root routine. takes eax, returns ax
  1107. ;trashes eax,ebx,ecx,edx,esi,edi
  1108. long_sqrt: or eax,eax ;check sign
  1109. jle error ;zero or negative
  1110. pushm ebx,ecx,edx,esi,edi
  1111. mov edx,eax
  1112. shr edx,16 ;split eax -> dx:ax
  1113. ;get a good first quess by checking which byte most significant bit is in
  1114. xor ebx,ebx ;clear high bytes for index
  1115. or dh,dh ;highest byte
  1116. jz not_dh
  1117. mov bl,dh ;get value for lookup
  1118. mov cl,12
  1119. jmp got_guess
  1120. not_dh: or dl,dl
  1121. jz not_dl
  1122. mov bl,dl ;get value for lookup
  1123. mov cl,8
  1124. jmp got_guess
  1125. not_dl: or ah,ah
  1126. jz not_ah
  1127. mov bl,ah ;get value for lookup
  1128. mov cl,4
  1129. jmp got_guess
  1130. not_ah: mov bl,al ;get value for lookup
  1131. mov cl,0
  1132. got_guess:
  1133. movzx ebx,guess_table[ebx] ;get byte guess
  1134. sal ebx,cl ;get in right place
  1135. mov ecx,eax
  1136. mov esi,edx ;save dx:ax
  1137. ;the loop nearly always executes 3 times, so we'll unroll it 2 times and
  1138. ;not do any checking until after the third time. By my calcutations, the
  1139. ;loop is executed 2 times in 99.97% of cases, 3 times in 93.65% of cases,
  1140. ;four times in 16.18% of cases, and five times in 0.44% of cases. It never
  1141. ;executes more than five times. By timing, I determined that is is faster
  1142. ;to always execute three times and not check for termination the first two
  1143. ;times through. This means that in 93.65% of cases, we save 6 cmp/jcc pairs,
  1144. ;and in 6.35% of cases we do an extra divide. In real life, these numbers
  1145. ;might not be the same.
  1146. ;newt_loop:
  1147. rept 2
  1148. mov eax,ecx
  1149. mov edx,esi ;restore dx:ax
  1150. div bx ;dx:ax / bx
  1151. mov edi,ebx ;save for compare
  1152. add bx,ax
  1153. rcr bx,1 ;next guess = (d + q)/2
  1154. endm
  1155. newt_loop: mov ax,cx
  1156. mov dx,si ;restore dx:ax
  1157. div bx ;dx:ax / bx
  1158. cmp ax,bx ;correct?
  1159. je got_it ;..yep
  1160. mov di,bx ;save for compare
  1161. add bx,ax
  1162. rcr bx,1 ;next guess = (d + q)/2
  1163. cmp bx,ax
  1164. je almost_got_it
  1165. cmp bx,di
  1166. jne newt_loop
  1167. almost_got_it: mov ax,bx
  1168. or dx,dx ;check remainder
  1169. jz got_it
  1170. inc ax
  1171. got_it: popm ebx,ecx,edx,esi,edi
  1172. ret
  1173. ;sqrt called with zero or negative input. return zero
  1174. error: xor eax,eax
  1175. ret
  1176. ;call the longword square root for quad with high longword equal zero
  1177. call_long: call long_sqrt
  1178. movzx eax,ax ;return longword result
  1179. ret
  1180. ;standard Newtonian-iteration square root routine. takes edx:eax, returns eax
  1181. quad_sqrt: or edx,edx ;check sign
  1182. js error ;can't do negative number!
  1183. jnz must_do_quad ;we really must do 64/32 div
  1184. or eax,eax ;check high bit of low longword
  1185. jns call_long ;we can use longword version
  1186. must_do_quad:
  1187. pushm ebx,ecx,edx,esi,edi
  1188. ;get a good first quess by checking which byte most significant bit is in
  1189. xor ebx,ebx ;clear high bytes for index
  1190. ror edx,16 ;get high 2 bytes
  1191. or dh,dh
  1192. jz q_not_dh
  1193. mov bl,dh ;get value for lookup
  1194. mov cl,12+16
  1195. ror edx,16 ;restore edx
  1196. jmp q_got_guess
  1197. q_not_dh: or dl,dl
  1198. jz q_not_dl
  1199. mov bl,dl ;get value for lookup
  1200. mov cl,8+16
  1201. ror edx,16 ;restore edx
  1202. jmp q_got_guess
  1203. q_not_dl: ror edx,16 ;restore edx
  1204. or dh,dh
  1205. jz q_not_ah
  1206. mov bl,dh ;get value for lookup
  1207. mov cl,4+16
  1208. jmp q_got_guess
  1209. q_not_ah: mov bl,dl ;get value for lookup
  1210. mov cl,0+16
  1211. q_got_guess:
  1212. movzx ebx,guess_table[ebx] ;get byte guess
  1213. sal ebx,cl ;get in right place
  1214. q_really_got_guess:
  1215. mov ecx,eax
  1216. mov esi,edx ;save edx:eax
  1217. ;quad loop usually executes 4 times
  1218. ;q_newt_loop:
  1219. rept 3
  1220. mov eax,ecx
  1221. mov edx,esi ;restore dx:ax
  1222. div ebx ;dx:ax / bx
  1223. mov edi,ebx ;save for compare
  1224. add ebx,eax
  1225. rcr ebx,1 ;next guess = (d + q)/2
  1226. endm
  1227. q_newt_loop: mov eax,ecx
  1228. mov edx,esi ;restore dx:ax
  1229. div ebx ;dx:ax / bx
  1230. cmp eax,ebx ;correct?
  1231. je q_got_it ;..yep
  1232. mov edi,ebx ;save for compare
  1233. add ebx,eax
  1234. rcr ebx,1 ;next guess = (d + q)/2
  1235. cmp ebx,eax
  1236. je q_almost_got_it
  1237. cmp ebx,edi
  1238. jne q_newt_loop
  1239. q_almost_got_it: mov eax,ebx
  1240. or edx,edx ;check remainder
  1241. jz q_got_it
  1242. inc eax
  1243. q_got_it: popm ebx,ecx,edx,esi,edi
  1244. ret
  1245. ;fixed-point square root
  1246. fix_sqrt: call long_sqrt
  1247. movzx eax,ax
  1248. sal eax,8
  1249. ret
  1250. _TEXT ends
  1251. end