-
Notifications
You must be signed in to change notification settings - Fork 14
/
fpp.asm
2233 lines (2233 loc) · 31.1 KB
/
fpp.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; TITLE '(C) COPYRIGHT R.T.RUSSELL 1986'
;
;Z80 FLOATING POINT PACKAGE
;(C) COPYRIGHT R.T.RUSSELL 1986
;VERSION 0.0, 26-10-1986
;VERSION 0.1, 14-12-1988 (BUG FIX)
;
;BINARY FLOATING POINT REPRESENTATION:
; 32 BIT SIGN-MAGNITUDE NORMALIZED MANTISSA
; 8 BIT EXCESS-128 SIGNED EXPONENT
; SIGN BIT REPLACES MANTISSA MSB (IMPLIED "1")
; MANTISSA=0 & EXPONENT=0 IMPLIES VALUE IS ZERO.
;
;BINARY INTEGER REPRESENTATION:
; 32 BIT 2'S-COMPLEMENT SIGNED INTEGER
; "EXPONENT" BYTE = 0 (WHEN PRESENT)
;
;NORMAL REGISTER ALLOCATION: MANTISSA - HLH'L'
; EXPONENT - C
;ALTERNATE REGISTER ALLOCATION: MANTISSA - DED'E'
; EXPONENT - B
;
;Error codes:
;
BADOP EQU 1 ;Bad operation code
DIVBY0 EQU 18 ;Division by zero
TOOBIG EQU 20 ;Too big
NGROOT EQU 21 ;Negative root
LOGRNG EQU 22 ;Log range
ACLOST EQU 23 ;Accuracy lost
EXPRNG EQU 24 ;Exp range
;
PUBLIC FPP
;
;Call entry and despatch code:
;
FPP: PUSH IY ;Save IY
LD IY,0
ADD IY,SP ;Save SP in IY
CALL OP ;Perform operation
CP A ;Good return (Z, NC)
EXIT: POP IY ;Restore IY
RET ;Return to caller
;
;Error exit:
;
BAD: LD A,BADOP ;"Bad operation code"
ERROR: LD SP,IY ;Restore SP from IY
OR A ;Set NZ
SCF ;Set C
JR EXIT
;
;Perform operation or function:
;
OP: CP (RTABLE-DTABLE)/2
JR NC,BAD
CP (FTABLE-DTABLE)/2
JR NC,DISPAT
EX AF,AF'
LD A,B
OR C ;Both integer?
CALL NZ,FLOATA ;No, so float both
EX AF,AF'
DISPAT: PUSH HL
LD HL,DTABLE
PUSH BC
ADD A,A ;A = op-code * 2
LD C,A
LD B,0 ;BC = op-code * 2
ADD HL,BC
LD A,(HL) ;Get low byte
INC HL
LD H,(HL) ;Get high byte
LD L,A
POP BC
EX (SP),HL
RET ;Off to routine
;
;Despatch table:
;
DTABLE: DEFW IAND ;AND (INTEGER)
DEFW IBDIV ;DIV
DEFW IEOR ;EOR
DEFW IMOD ;MOD
DEFW IOR ;OR
DEFW ILE ;<=
DEFW INE ;<>
DEFW IGE ;>=
DEFW ILT ;<
DEFW IEQ ;=
DEFW IMUL ;*
DEFW IADD ;+
DEFW IGT ;>
DEFW ISUB ;-
DEFW IPOW ;^
DEFW IDIV ;/
;
FTABLE: DEFW ABS ;ABS
DEFW ACS ;ACS
DEFW ASN ;ASN
DEFW ATN ;ATN
DEFW COS ;COS
DEFW DEG ;DEG
DEFW EXP ;EXP
DEFW INT ;INT
DEFW LN ;LN
DEFW LOG ;LOG
DEFW NOT ;NOT
DEFW RAD ;RAD
DEFW SGN ;SGN
DEFW SIN ;SIN
DEFW SQR ;SQR
DEFW TAN ;TAN
;
DEFW ZERO ;ZERO
DEFW FONE ;FONE
DEFW TRUE ;TRUE
DEFW PI ;PI
;
DEFW VAL ;VAL
DEFW STR ;STR$
;
DEFW SFIX ;FIX
DEFW SFLOAT ;FLOAT
;
DEFW FTEST ;TEST
DEFW FCOMP ;COMPARE
;
RTABLE: DEFW FAND ;AND (FLOATING-POINT)
DEFW FBDIV ;DIV
DEFW FEOR ;EOR
DEFW FMOD ;MOD
DEFW FOR ;OR
DEFW FLE ;<=
DEFW FNE ;<>
DEFW FGE ;>=
DEFW FLT ;<
DEFW FEQ ;=
DEFW FMUL ;*
DEFW FADD ;+
DEFW FGT ;>
DEFW FSUB ;-
DEFW FPOW ;^
DEFW FDIV ;/
;
;ARITHMETIC AND LOGICAL OPERATORS:
;All take two arguments, in HLH'L'C & DED'E'B.
;Output in HLH'L'C
;All registers except IX, IY destroyed.
; (N.B. FPOW destroys IX).
;
;FAND - Floating-point AND.
;IAND - Integer AND.
;
FAND: CALL FIX2
IAND: LD A,H
AND D
LD H,A
LD A,L
AND E
LD L,A
EXX
LD A,H
AND D
LD H,A
LD A,L
AND E
LD L,A
EXX
RET
;
;FEOR - Floating-point exclusive-OR.
;IEOR - Integer exclusive-OR.
;
FEOR: CALL FIX2
IEOR: LD A,H
XOR D
LD H,A
LD A,L
XOR E
LD L,A
EXX
LD A,H
XOR D
LD H,A
LD A,L
XOR E
LD L,A
EXX
RET
;
;FOR - Floating-point OR.
;IOR - Integer OR.
;
FOR: CALL FIX2
IOR: LD A,H
OR D
LD H,A
LD A,L
OR E
LD L,A
EXX
LD A,H
OR D
LD H,A
LD A,L
OR E
LD L,A
EXX
RET
;
;FMOD - Floating-point remainder.
;IMOD - Integer remainder.
;
FMOD: CALL FIX2
IMOD: LD A,H
XOR D ;DIV RESULT SIGN
BIT 7,H
EX AF,AF'
BIT 7,H
CALL NZ,NEGATE ;MAKE ARGUMENTS +VE
CALL SWAP
BIT 7,H
CALL NZ,NEGATE
LD B,H
LD C,L
LD HL,0
EXX
LD B,H
LD C,L
LD HL,0
LD A,-33
CALL DIVA ;DIVIDE
EXX
LD C,0 ;INTEGER MARKER
EX AF,AF'
RET Z
JP NEGATE
;
;BDIV - Integer division.
;
FBDIV: CALL FIX2
IBDIV: CALL IMOD
OR A
CALL SWAP
LD C,0
RET P
JP NEGATE
;
;ISUB - Integer subtraction.
;FSUB - Floating point subtraction with rounding.
;
ISUB: CALL SUB
RET PO
CALL ADD
CALL FLOAT2
FSUB: LD A,D
XOR 80H ;CHANGE SIGN THEN ADD
LD D,A
JR FADD
;
;Reverse subtract.
;
RSUB: LD A,H
XOR 80H
LD H,A
JR FADD
;
;IADD - Integer addition.
;FADD - Floating point addition with rounding.
;
IADD: CALL ADD
RET PO
CALL SUB
CALL FLOAT2
FADD: DEC B
INC B
RET Z ;ARG 2 ZERO
DEC C
INC C
JP Z,SWAP ;ARG 1 ZERO
EXX
LD BC,0 ;INITIALISE
EXX
LD A,H
XOR D ;XOR SIGNS
PUSH AF
LD A,B
CP C ;COMPARE EXPONENTS
CALL C,SWAP ;MAKE DED'E'B LARGEST
LD A,B
SET 7,H ;IMPLIED 1
CALL NZ,FIX ;ALIGN
POP AF
LD A,D ;SIGN OF LARGER
SET 7,D ;IMPLIED 1
JP M,FADD3 ;SIGNS DIFFERENT
CALL ADD ;HLH'L'=HLH'L'+DED'E'
CALL C,DIV2 ;NORMALISE
SET 7,H
JR FADD4
;
FADD3: CALL SUB ;HLH'L'=HLH'L'-DED'E'
CALL C,NEG ;NEGATE HLH'L'B'C'
CALL FLO48
CPL ;CHANGE RESULT SIGN
FADD4: EXX
EX DE,HL
LD HL,8000H
OR A ;CLEAR CARRY
SBC HL,BC
EX DE,HL
EXX
CALL Z,ODD ;ROUND UNBIASSED
CALL C,ADD1 ;ROUND UP
CALL C,INCC
RES 7,H
DEC C
INC C
JP Z,ZERO
OR A ;RESULT SIGNQ
RET P ;POSITIVE
SET 7,H ;NEGATIVE
RET
;
;IDIV - Integer division.
;FDIV - Floating point division with rounding.
;
IDIV: CALL FLOAT2
FDIV: DEC B ;TEST FOR ZERO
INC B
LD A,DIVBY0
JP Z,ERROR ;"Division by zero"
DEC C ;TEST FOR ZERO
INC C
RET Z
LD A,H
XOR D ;CALC. RESULT SIGN
EX AF,AF' ;SAVE SIGN
SET 7,D ;REPLACE IMPLIED 1's
SET 7,H
PUSH BC ;SAVE EXPONENTS
LD B,D ;LOAD REGISTERS
LD C,E
LD DE,0
EXX
LD B,D
LD C,E
LD DE,0
LD A,-32 ;LOOP COUNTER
CALL DIVA ;DIVIDE
EXX
BIT 7,D
EXX
CALL Z,DIVB ;NORMALISE & INC A
EX DE,HL
EXX
SRL B ;DIVISOR/2
RR C
OR A ;CLEAR CARRY
SBC HL,BC ;REMAINDER-DIVISOR/2
CCF
EX DE,HL ;RESULT IN HLH'L'
CALL Z,ODD ;ROUND UNBIASSED
CALL C,ADD1 ;ROUND UP
POP BC ;RESTORE EXPONENTS
CALL C,INCC
RRA ;LSB OF A TO CARRY
LD A,C ;COMPUTE NEW EXPONENT
SBC A,B
CCF
JP CHKOVF
;
;IMUL - Integer multiplication.
;
IMUL: LD A,H
XOR D
EX AF,AF' ;SAVE RESULT SIGN
BIT 7,H
CALL NZ,NEGATE
CALL SWAP
BIT 7,H
CALL NZ,NEGATE
LD B,H
LD C,L
LD HL,0
EXX
LD B,H
LD C,L
LD HL,0
LD A,-33
CALL MULA ;MULTIPLY
EXX
LD C,191 ;PRESET EXPONENT
CALL TEST ;TEST RANGE
JR NZ,IMUL1 ;TOO BIG
BIT 7,D
JR NZ,IMUL1
CALL SWAP
LD C,D ;INTEGER MARKER
EX AF,AF'
RET P
JP NEGATE
;
IMUL1: DEC C
EXX
SLA E
RL D
EXX
RL E
RL D
EXX
ADC HL,HL
EXX
ADC HL,HL
JP P,IMUL1 ;NORMALISE
EX AF,AF'
RET M
RES 7,H ;POSITIVE
RET
;
;FMUL - Floating point multiplication with rounding.
;
FMUL: DEC B ;TEST FOR ZERO
INC B
JP Z,ZERO
DEC C ;TEST FOR ZERO
INC C
RET Z
LD A,H
XOR D ;CALC. RESULT SIGN
EX AF,AF'
SET 7,D ;REPLACE IMPLIED 1's
SET 7,H
PUSH BC ;SAVE EXPONENTS
LD B,H ;LOAD REGISTERS
LD C,L
LD HL,0
EXX
LD B,H
LD C,L
LD HL,0
LD A,-32 ;LOOP COUNTER
CALL MULA ;MULTIPLY
CALL C,MULB ;NORMALISE & INC A
EXX
PUSH HL
LD HL,8000H
OR A ;CLEAR CARRY
SBC HL,DE
POP HL
CALL Z,ODD ;ROUND UNBIASSED
CALL C,ADD1 ;ROUND UP
POP BC ;RESTORE EXPONENTS
CALL C,INCC
RRA ;LSB OF A TO CARRY
LD A,C ;COMPUTE NEW EXPONENT
ADC A,B
CHKOVF: JR C,CHKO1
JP P,ZERO ;UNDERFLOW
JR CHKO2
CHKO1: JP M,OFLOW ;OVERFLOW
CHKO2: ADD A,80H
LD C,A
JP Z,ZERO
EX AF,AF' ;RESTORE SIGN BIT
RES 7,H
RET P
SET 7,H
RET
;
;IPOW - Integer involution.
;
IPOW: CALL SWAP
BIT 7,H
PUSH AF ;SAVE SIGN
CALL NZ,NEGATE
IPOW0: LD C,B
LD B,32 ;LOOP COUNTER
IPOW1: CALL X2
JR C,IPOW2
DJNZ IPOW1
POP AF
EXX
INC L ;RESULT=1
EXX
LD C,H
RET
;
IPOW2: POP AF
PUSH BC
EX DE,HL
PUSH HL
EXX
EX DE,HL
PUSH HL
EXX
LD IX,0
ADD IX,SP
JR Z,IPOW4
PUSH BC
EXX
PUSH DE
EXX
PUSH DE
CALL SFLOAT
CALL RECIP
LD (IX+4),C
EXX
LD (IX+0),L
LD (IX+1),H
EXX
LD (IX+2),L
LD (IX+3),H
JR IPOW5
;
IPOW3: PUSH BC
EXX
SLA E
RL D
PUSH DE
EXX
RL E
RL D
PUSH DE
LD A,'*' & 0FH
PUSH AF
CALL COPY
CALL OP ;SQUARE
POP AF
CALL DLOAD5
CALL C,OP ;MULTIPLY BY X
IPOW5: POP DE
EXX
POP DE
EXX
LD A,C
POP BC
LD C,A
IPOW4: DJNZ IPOW3
POP AF
POP AF
POP AF
RET
;
FPOW0: POP AF
POP AF
POP AF
JR IPOW0
;
;FPOW - Floating-point involution.
;
FPOW: BIT 7,D
PUSH AF
CALL SWAP
CALL PUSH5
DEC C
INC C
JR Z,FPOW0
LD A,158
CP C
JR C,FPOW1
INC A
CALL FIX
EX AF,AF'
JP P,FPOW0
FPOW1: CALL SWAP
CALL LN0
CALL POP5
POP AF
CALL FMUL
JP EXP0
;
;Integer and floating-point compare.
;Result is TRUE (-1) or FALSE (0).
;
FLT: CALL FCP
JR ILT1
ILT: CALL ICP
ILT1: RET NC
JR TRUE
;
FGT: CALL FCP
JR IGT1
IGT: CALL ICP
IGT1: RET Z
RET C
JR TRUE
;
FGE: CALL FCP
JR IGE1
IGE: CALL ICP
IGE1: RET C
JR TRUE
;
FLE: CALL FCP
JR ILE1
ILE: CALL ICP
ILE1: JR Z,TRUE
RET NC
JR TRUE
;
FNE: CALL FCP
JR INE1
INE: CALL ICP
INE1: RET Z
JR TRUE
;
FEQ: CALL FCP
JR IEQ1
IEQ: CALL ICP
IEQ1: RET NZ
TRUE: LD HL,-1
EXX
LD HL,-1
EXX
XOR A
LD C,A
RET
;
;FUNCTIONS:
;
;Result returned in HLH'L'C (floating point)
;Result returned in HLH'L' (C=0) (integer)
;All registers except IY destroyed.
;
;ABS - Absolute value
;Result is numeric, variable type.
;
ABS: BIT 7,H
RET Z ;POSITIVE/ZERO
DEC C
INC C
JP Z,NEGATE ;INTEGER
RES 7,H
RET
;
;NOT - Complement integer.
;Result is integer numeric.
;
NOT: CALL SFIX
LD A,H
CPL
LD H,A
LD A,L
CPL
LD L,A
EXX
LD A,H
CPL
LD H,A
LD A,L
CPL
LD L,A
EXX
XOR A ;NUMERIC MARKER
RET
;
;PI - Return PI (3.141592654)
;Result is floating-point numeric.
;
PI: LD HL,490FH
EXX
LD HL,0DAA2H
EXX
LD C,81H
XOR A ;NUMERIC MARKER
RET
;
;DEG - Convert radians to degrees
;Result is floating-point numeric.
;
DEG: CALL FPI180
CALL FMUL
XOR A
RET
;
;RAD - Convert degrees to radians
;Result is floating-point numeric.
;
RAD: CALL FPI180
CALL FDIV
XOR A
RET
;
;180/PI
;
FPI180: CALL SFLOAT
LD DE,652EH
EXX
LD DE,0E0D3H
EXX
LD B,85H
RET
;
;SGN - Return -1, 0 or +1
;Result is integer numeric.
;
SGN: CALL TEST
OR C
RET Z ;ZERO
BIT 7,H
JP NZ,TRUE ;-1
CALL ZERO
JP ADD1 ;1
;
;VAL - Return numeric value of string.
;Input: ASCII string at IX
;Result is variable type numeric.
;
VAL: CALL SIGNQ
PUSH AF
CALL CON
POP AF
CP '-'
LD A,0 ;NUMERIC MARKER
RET NZ
DEC C
INC C
JP Z,NEGATE ;ZERO/INTEGER
LD A,H
XOR 80H ;CHANGE SIGN (FP)
LD H,A
XOR A
RET
;
;INT - Floor function
;Result is integer numeric.
;
INT: DEC C
INC C
RET Z ;ZERO/INTEGER
LD A,159
LD B,H ;B7=SIGN BIT
CALL FIX
EX AF,AF'
AND B
CALL M,ADD1 ;NEGATIVE NON-INTEGER
LD A,B
OR A
CALL M,NEGATE
XOR A
LD C,A
RET
;
;SQR - square root
;Result is floating-point numeric.
;
SQR: CALL SFLOAT
SQR0: BIT 7,H
LD A,NGROOT
JP NZ,ERROR ;"-ve root"
DEC C
INC C
RET Z ;ZERO
SET 7,H ;IMPLIED 1
BIT 0,C
CALL Z,DIV2 ;MAKE EXPONENT ODD
LD A,C
SUB 80H
SRA A ;HALVE EXPONENT
ADD A,80H
LD C,A
PUSH BC ;SAVE EXPONENT
EX DE,HL
LD HL,0
LD B,H
LD C,L
EXX
EX DE,HL
LD HL,0
LD B,H
LD C,L
LD A,-31
CALL SQRA ;ROOT
EXX
BIT 7,B
EXX
CALL Z,SQRA ;NORMALISE & INC A
CALL SQRB
OR A ;CLEAR CARRY
CALL DIVB
RR E ;LSB TO CARRY
LD H,B
LD L,C
EXX
LD H,B
LD L,C
CALL C,ADD1 ;ROUND UP
POP BC ;RESTORE EXPONENT
CALL C,INCC
RRA
SBC A,A
ADD A,C
LD C,A
RES 7,H ;POSITIVE
XOR A
RET
;
;TAN - Tangent function
;Result is floating-point numeric.
;
TAN: CALL SFLOAT
CALL PUSH5
CALL COS0
CALL POP5
CALL PUSH5
CALL SWAP
CALL SIN0
CALL POP5
CALL FDIV
XOR A ;NUMERIC MARKER
RET
;
;COS - Cosine function
;Result is floating-point numeric.
;
COS: CALL SFLOAT
COS0: CALL SCALE
INC E
INC E
LD A,E
JR SIN1
;
;SIN - Sine function
;Result is floating-point numeric.
;
SIN: CALL SFLOAT
SIN0: PUSH HL ;H7=SIGN
CALL SCALE
POP AF
RLCA
RLCA
RLCA
AND 4
XOR E
SIN1: PUSH AF ;OCTANT
RES 7,H
RRA
CALL PIBY4
CALL C,RSUB ;X=(PI/4)-X
POP AF
PUSH AF
AND 3
JP PO,SIN2 ;USE COSINE APPROX.
CALL PUSH5 ;SAVE X
CALL SQUARE ;PUSH X*X
CALL POLY
DEFW 0A8B7H ;a(8)
DEFW 3611H
DEFB 6DH
DEFW 0DE26H ;a(6)
DEFW 0D005H
DEFB 73H
DEFW 80C0H ;a(4)
DEFW 888H
DEFB 79H
DEFW 0AA9DH ;a(2)
DEFW 0AAAAH
DEFB 7DH
DEFW 0 ;a(0)
DEFW 0
DEFB 80H
CALL POP5
CALL POP5
CALL FMUL
JP SIN3
;
SIN2: CALL SQUARE ;PUSH X*X
CALL POLY
DEFW 0D571H ;b(8)
DEFW 4C78H
DEFB 70H
DEFW 94AFH ;b(6)
DEFW 0B603H
DEFB 76H
DEFW 9CC8H ;b(4)
DEFW 2AAAH
DEFB 7BH
DEFW 0FFDDH ;b(2)
DEFW 0FFFFH
DEFB 7EH
DEFW 0 ;b(0)
DEFW 0
DEFB 80H
CALL POP5
SIN3: POP AF
AND 4
RET Z
DEC C
INC C
RET Z ;ZERO
SET 7,H ;MAKE NEGATIVE
RET
;
;Floating-point one:
;
FONE: LD HL,0
EXX
LD HL,0
EXX
LD C,80H
RET
;
DONE: LD DE,0
EXX
LD DE,0
EXX
LD B,80H
RET
;
PIBY4: LD DE,490FH
EXX
LD DE,0DAA2H
EXX
LD B,7FH
RET
;
;EXP - Exponential function
;Result is floating-point numeric.
;
EXP: CALL SFLOAT
EXP0: CALL LN2 ;LN(2)
EXX
DEC E
LD BC,0D1CFH ;0.6931471805599453
EXX
PUSH HL ;H7=SIGN
CALL MOD48 ;"MODULUS"
POP AF
BIT 7,E
JR Z,EXP1
RLA
JP C,ZERO
LD A,EXPRNG
JP ERROR ;"Exp range"
;
EXP1: AND 80H
OR E
PUSH AF ;INTEGER PART
RES 7,H
CALL PUSH5 ;PUSH X*LN(2)
CALL POLY
DEFW 4072H ;a(7)
DEFW 942EH
DEFB 73H
DEFW 6F65H ;a(6)
DEFW 2E4FH
DEFB 76H
DEFW 6D37H ;a(5)
DEFW 8802H
DEFB 79H
DEFW 0E512H ;a(4)
DEFW 2AA0H
DEFB 7BH
DEFW 4F14H ;a(3)
DEFW 0AAAAH
DEFB 7DH
DEFW 0FD56H ;a(2)
DEFW 7FFFH
DEFB 7EH
DEFW 0FFFEH ;a(1)
DEFW 0FFFFH
DEFB 7FH
DEFW 0 ;a(0)
DEFW 0
DEFB 80H
CALL POP5
POP AF
PUSH AF
CALL P,RECIP ;X=1/X
POP AF
JP P,EXP4
AND 7FH
NEG
EXP4: ADD A,80H
ADD A,C
JR C,EXP2
JP P,ZERO ;UNDERFLOW
JR EXP3
EXP2: JP M,OFLOW ;OVERFLOW
EXP3: ADD A,80H
JP Z,ZERO
LD C,A
XOR A ;NUMERIC MARKER
RET
;
RECIP: CALL DONE
RDIV: CALL SWAP
JP FDIV ;RECIPROCAL
;
LN2: LD DE,3172H ;LN(2)
EXX
LD DE,17F8H
EXX
LD B,7FH
RET
;
;LN - Natural log.
;Result is floating-point numeric.