Repository navigation
Expand file tree
/
Copy pathfp.asm
More file actions
2915 lines (2731 loc) · 71.5 KB
/
Copy pathfp.asm
File metadata and controls
2915 lines (2731 loc) · 71.5 KB
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
keep obj/fp
mcopy fp.macros
****************************************************************
*
* SANE Floating Point Libraries
*
* These libraries are common routines used by the 65816 ORCA
* native code compilers for accessing SANE.
*
* Copyright 1987, 1990, 1992
* Byte Works, Inc.
* All rights reserved.
*
* By Mike Westerfield
*
* Notes: Some subroutines in this library do not contain SANE
* calls, but they are called by other subroutines that do.
* Many are also called from ORCALib or PasLib, so do not change
* the call protocall or global variables.
*
****************************************************************
*
Dummy start
end
****************************************************************
*
* SetFPESlot - Set the FPE slot number
*
* Inputs:
* slot - slot number
*
****************************************************************
*
SetFPESlot start
phb
phk
plb
plx
ply
pla
phy
phx
plb
rtl
end
****************************************************************
*
* ~InitFloat - Initialize floating-point libraries (no-op)
*
****************************************************************
*
~InitFloat start
rtl
end
****************************************************************
*
* ~AddE - Add two SANE extended numbers
*
* Inputs:
* n1,n2: numbers
*
****************************************************************
*
~AddE start
longa on
longi on
tsc push the addresses
pea 0
clc
adc #4
pha
pea 0
adc #10
pha
faddx add the two numbers
lda 0,S remove the left over from the stack
sta 10,S
lda 2,S
sta 12,S
tsc
clc
adc #10
tcs
rtl
end
****************************************************************
*
* ~ArcCosE - ArcCos function
*
* Inputs:
* 1,S - return address
* 4,S - number
*
****************************************************************
*
~ArcCosE start
longa on
longi on
using ~RealCom
lda 12,S t1 := arcsin(x)
pha
lda 12,S
pha
lda 12,S
pha
lda 12,S
pha
lda 12,S
pha
jsl ~ArcSinE
pla
sta >t1
pla
sta >t1+2
pla
sta >t1+4
pla
sta >t1+6
pla
sta >t1+8
lda >piover2 x := pi/2
sta 4,S
lda >piover2+2
sta 6,S
lda >piover2+4
sta 8,S
lda >piover2+6
sta 10,S
lda >piover2+8
sta 12,S
ph4 #t1 x := x-t1
pea 0
clc
tsc
adc #10
pha
fsubx
rtl
end
****************************************************************
*
* ~ArcSinE - ArcSin function
*
* Inputs:
* 1,S - return address
* 4,S - number
*
****************************************************************
*
~ArcSinE start
longa on
longi on
using ~RealCom
x equ 6 location of number
phd set up local DP
tsc
tcd
phb set up local data addressing
phk
plb
ldx #8 t1 := one
lb1 lda one,X t2 := x
sta t1,X
lda x,X
sta t2,X
dex
dex
bpl lb1
pea 0 push addresses onto the stack
clc push(x)
tdc
adc #x
pha
ldy #^t1 push(t1)
ldx #t1
phy
phx
pea 0 push(x)
pha
phy push(t1);
phx
lda #t2 push(t2)
phy
pha
phy push(t1)
phx
phy push(t2)
pha
phy push(t2)
pha
fmulx t2 := t2*t2
fsubx t1 := t1-t2
fsqrtx t1 := sqrt(t1)
fdivx x := x/t1
fatanx x := arctan(x)
plb reset data bank
pld restore DP
rtl
end
****************************************************************
*
* ~ArcTan2E - Take the two argument arc tangent of two SANE extended numbers
*
* Inputs:
* n1,n2: numbers
*
****************************************************************
*
~ArcTan2E start
longa on
longi on
using ~RealCom
lda 12,S y := arctan(y/x);
pha (save signs)
lda 24,S
pha
clc
tsc
adc #8
tay
adc #10
pea 0
pha
pea 0
phy
pea 0
pha
fdivx
fatanx
ply if x < 0 then
plx if y >= 0 then
bpl lb2 y := y+pi
pea pi|-16 else
pea pi y := y-pi
pea 0
clc
tsc
adc #20
pha
tya
bmi lb1
faddx
bra lb2
lb1 fsubx
lb2 lda 0,S remove the left over from the stack
sta 10,S
lda 2,S
sta 12,S
tsc
clc
adc #10
tcs
rtl
end
****************************************************************
*
* ~AtnE - ArcTan function
*
* Inputs:
* 1,S - return address
* 4,S - number
*
****************************************************************
*
~AtnE start
longa on
longi on
tsc push the addresse twice
pea 0
clc
adc #4
pha
fatanx compute function
rtl
end
****************************************************************
*
* ~CCompRet - Save a comp function return value in ~RealVal
*
* Inputs:
* rval - comp value to save
*
* Outputs:
* X-Y - address of ~RealVal
*
****************************************************************
*
~CCompRet start
lcAfterMarkStack equ 1 location of function return value
pea 0 push address of double value
tdc
clc
adc #lcAfterMarkStack
pha
ph4 #~RealVal push address of extended value
fc2x convert to extended
ldx #^~RealVal load address of result
ldy #~RealVal
rtl return
end
****************************************************************
*
* ~CDoubleRet - Save a double function return value in ~RealVal
*
* Inputs:
* rval - double value to save
*
* Outputs:
* X-Y - address of ~RealVal
*
****************************************************************
*
~CDoubleRet start
lcAfterMarkStack equ 1 location of function return value
pea 0 push address of double value
tdc
clc
adc #lcAfterMarkStack
pha
ph4 #~RealVal push address of extended value
fd2x convert to extended
ldx #^~RealVal load address of result
ldy #~RealVal
rtl return
end
****************************************************************
*
* ~CExtendedRet - Save an extended function return value in ~RealVal
*
* Inputs:
* rval - extended value to save
*
* Outputs:
* X-Y - address of ~RealVal
*
****************************************************************
*
~CExtendedRet start
lcAfterMarkStack equ 1 location of function return value
ldx #8 move the value
lb1 lda lcAfterMarkStack,X
sta >~RealVal,X
dex
dex
bpl lb1
ldx #^~RealVal load address of result
ldy #~RealVal
rtl return
end
****************************************************************
*
* ~CnvES - convert extended sane to string
*
* Inputs:
* 1,S - return address
* 4,S - fixed precision digit count
* 6,S - field width
* 8,S - extended format real number
*
* Outputs:
* stack - length of result string
* stack-1 - pointer to result string
*
****************************************************************
*
~CnvES start
using ~RealCom
longa on
longi on
sLen equ 0
sAddr equ 2 string pointer
return equ 0
decDig equ 3
fw equ 5
ext equ 7
rLen equ 11 return string length
rAddr equ 13 return string address
tdc set up stack and direct page
tax
tsc
sec
sbc #$FFFF
tcd
dec a
tcs
phx
phb set data bank reg
phk
plb
ldx #12 format the number
cv1 lda decDig,X
pha
dex
dex
bpl cv1
jsl ~FormatReal
lda pasString
and #$00FF
sta rLen
beq rts
ldx #0
jsr ~GetSBuffer
sta rAddr
stx rAddr+2
bcs err
ldy rLen
dey
short M
cv2 lda pasString+1,y
sta [rAddr],y
dey
bpl cv2
long M
rts plb
lda return+1
sta rLen-2
lda return
sta rLen-3
clc
tdc
adc #rLen-4
pld
tcs
rtl
err error #5 out of memory
stz sLen return 0
bra rts
end
****************************************************************
*
* ~CnvIntReal - convert an integer into an extended SANE real
*
* Inputs:
* A - integer
*
* Outputs:
* extended real on stack
*
****************************************************************
*
~CnvIntReal start
longa on
longi on
phb recover return addr
plx
ply
pha make room for extended value
pha
pha
pha
pha
phy fix return address
phx
plb
pha save integer on stack
tsc push address of integer
ina
pea 0
pha
pea 0 push address of extended real
clc
adc #5
pha
fi2x convert
pla remove integer
rtl return
end
****************************************************************
*
* ~CnvLE - convert a longint into an extended SANE real
*
* Inputs:
* longint on stack
*
* Outputs:
* extended real on stack
*
****************************************************************
*
~CnvLE start
using ~RealCom
longa on
longi on
phb recover return addr & set up bank addr
phk
plb
pl4 t1+4
pl4 t1 fetch number to convert
ph4 #t1 push addr of integer
ph4 #t2 push addr to place result
fl2x convert
lda t2+8 push real result
pha
lda t2+6
pha
lda t2+4
pha
lda t2+2
pha
lda t2
pha
ph4 t1+4 fix stack
plb
rtl return
end
****************************************************************
*
* ~CnvLongReal - convert a long integer into an extended SANE real
*
* Inputs:
* A - integer
*
* Outputs:
* extended real on stack
*
****************************************************************
*
~CnvLongReal start
phb save the long value
phk
plb
sta lval
stx lval+2
plx recover return addr
ply
pha make room for extended value
pha
pha
pha
pha
phy fix return address
phx
plb
ph4 #lval push address of integer
pea 0 push address of extended real
clc
tsc
adc #10
pha
fl2x convert
rtl return
lval ds 4 long value
end
****************************************************************
*
* ~CnvRealInt - trunc and convert a real to an integer
*
* Inputs:
* extended real on stack
*
* Outputs:
* A - integer
*
****************************************************************
*
~CnvRealInt start
longa on
longi on
tsc push address of real 2 times
clc
adc #4
pea 0
pha
pea 0
pha
pea 0 push address of integer
pha
ftintx round
fx2i convert
phb move return address
pla
sta 9,S
pla
sta 9,S
pla remove integer
plx fix stack
plx
plb
tax set condition codes
rtl return
end
****************************************************************
*
* ~CnvRealLong - trunc and convert a real to a long
*
* Inputs:
* extended real on stack
*
* Outputs:
* X-A - integer
*
****************************************************************
*
~CnvRealLong start
tsc push address of real 2 times
clc
adc #4
pea 0
pha
pea 0
pha
pea 0 push address of integer
pha
ftintx round
fx2c convert
phb move return address
pla
sta 9,S
pla
sta 9,S
pla remove integer
plx
ply fix stack
plb
tay set condition codes
bne lb1
txy
lb1 rtl return
end
****************************************************************
*
* ~CnvRealUInt - trunc and convert a real to an integer
*
* Inputs:
* extended real on stack
*
* Outputs:
* A - integer
*
****************************************************************
*
~CnvRealUInt start
longa on
longi on
tsc push address of real 2 times
clc
adc #4
pea 0
pha
pea 0
pha
pea 0 push address of integer
pha
ftintx round
fx2l convert
phb move return address
pla
sta 9,S
pla
sta 9,S
pla remove integer
plx fix stack
plx
plb
tax set condition codes
rtl return
end
****************************************************************
*
* ~CnvSE - convert string to extended sane
*
* Inputs:
* 1,S - return address
* 4,S - string len
* 6,S - string
*
* Outputs:
* stack - length of result string
* stack-1 - pointer to result string
*
****************************************************************
*
~CnvSE start
longa on
longi on
using ~FileCom
using ~RealCom
dpage equ 1 caller's direct page
return equ 3 return address
ext equ 6
slen equ 10 string length
sAddr equ 12 string address
lda 3,S move and save return address
pha
lda 3,S
pha
phd save direct page
tsc set up direct page
tcd
phb save data bank
phk set up local data bank
plb
ph4 <sAddr convert string to standard form
ph2 <sLen
jsr ~StringToStandard
pl2 sLen
pl4 sAddr
lda sLen
tax
short M move over the string
sta pasString
lda #0
sta pasString+1,X
txy
beq cv3
bra cv2
cv1 lda [sAddr],Y
sta pasString+1,Y
cv2 dey
bpl cv1
;
; Convert the string into a number
;
cv3 long M
ldy #0 skip leading blanks
lda #' '
short M
cv4 cmp pasString+1,Y
bne cv5
iny
bra cv4
cv5 long M
sty index
ph4 #pasString+1 lvp^.rval := cnvsr(digit);
ph4 #index {convert from ascii to decform}
ph4 #decrec
ph4 #valid
stz index
fcstr2dec
lda valid {flag an error if SANE said to}
beq err1
lda pasString
and #$00FF
cmp index
bne err1
ph4 #decrec {convert decform to real}
pea 0
clc
tdc
adc #ext
pha
fdec2x
bcc rts
err1 error #10 real math error
rts plb
pld
rtl
end
****************************************************************
*
* ~CnvULongReal - convert an unsigned long integer into an
* extended SANE real
*
* Inputs:
* A - integer
*
* Outputs:
* extended real on stack
*
****************************************************************
*
~CnvULongReal start
phb save the long value
phk
plb
sta lval
stx lval+2
plx recover return addr
ply
pha make room for extended value
pha
pha
pha
pha
phy fix return address
phx
plb
ph4 #lval push address of integer
pea 0 push address of extended real
clc
tsc
adc #10
pha
fc2x convert
rtl return
lval ds 4 long value
dc i4'0' least significant bits of comp value
end
****************************************************************
*
* ~CompFix - Convert a parameter from extended to comp
*
* Inputs:
* rval - disp in stack frame of real value
*
****************************************************************
*
~CompFix start
longa on
longi on
rval equ 4
tdc push address of real value
clc
adc rval,S
pea 0
pha
pea 0
pha
fx2c convert from extended
lda 2,S fix return addr
sta 4,S
pla
sta 1,S
rtl
end
****************************************************************
*
* ~CompRet2 - Save a comp function return value in ~RealVal
*
* Inputs:
* rval - real value to save
*
* Outputs:
* X-Y - address of ~RealVal
*
* Notes: Pascal 2.0 version
*
****************************************************************
*
~CompRet2 start
lda 1,S swap address of value
tax and return address
lda 2,S
tay
lda 4,S
sta 1,S
lda 6,S
sta 3,S
tya
sta 6,S
txa
sta 5,S
ph4 #~RealVal push address of extended value
fc2x convert to extended
ldx #^~RealVal load address of result
ldy #~RealVal
rtl return
end
****************************************************************
*
* ~CopyComp - Save a comp value
*
* Inputs:
* 1,S - return address
* 4,S - address to save to
* 8,S - extended real value
*
****************************************************************
*
~CopyComp start
csubroutine (4:addr),0
ext equ addr+4
ph2 #0 push addr of extended #
clc
tdc
adc #ext
pha
ph4 <addr push addr of real value
fx2c convert and move
creturn
end
****************************************************************
*
* ~CopyDouble - Copy a double value
*
* Inputs:
* 1,S - return address
* 4,S - address to save to
* 8,S - extended real value
*
****************************************************************
*
~CopyDouble start
csubroutine (4:addr),0
ext equ addr+4
ph2 #0 push addr of extended #
clc
tdc
adc #ext
pha
ph4 <addr push addr of real value
fx2d convert and move
creturn
end
****************************************************************
*
* ~CopyExtended - Save an extended value
*
* Inputs:
* 1,S - return address
* 4,S - address to save to
* 8,S - extended real value
*
****************************************************************
*
~CopyExtended start
csubroutine (4:addr),0
ext equ addr+4
ldx #8
lb1 txy
lda ext,X
sta [addr],Y
dex
dex
bpl lb1
creturn
end
****************************************************************
*
* ~CopyReal - Save a real value
*
* Inputs:
* 1,S - return address
* 4,S - address to save to
* 8,S - extended real value
*
****************************************************************
*
~CopyReal start
csubroutine (4:addr),0
ext equ addr+4
ph2 #0 push addr of extended #
clc
tdc
adc #ext
pha