-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathmath2
869 lines (869 loc) · 13 KB
/
math2
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
.PAG 'MATH2'
FMAPTR LDA COUNT
ASL A
ADC #5 ;-> ENTRIES, C CLR'D BY ASL
ADC LOWTR
LDY LOWTR+1
BCC JSRGM
INY
JSRGM STA ARYPNT
STY ARYPNT+1
RTS
.SKI 4
; READ A FORMULA FROM THE CURRENT POS AND TURNS
; IT INTO A POSITIVE INTEGER.
; LEAVING THE RESULT IN FACMO & LO. NEGATIVE
; ARGUMENTS ARE NOT ALLOWED.
;
;
;
INTIDX JSR CHRGET
JSR FRMEVL
POSINT JSR CHKNUM
LDA FACSGN
BMI NONONO
AYINT LDA FACEXP
CMP #$90
BCC QINTGO
LDA #<N32768
LDY #>N32768
JSR FCOMP
NONONO BNE FCERR8
QINTGO JMP QINT
FCERR8 JMP FCERR
.SKI 4
ISARY ;FORMAT OF ARRAYS IN RAM.
; DESCRIPTOR
; LB = 1ST CHAR
; HB = 2ND CHAR (200 BIT = STR FLAG)
; LENGTH OF ARRAY IN RAM IN BYTES
; NUMBER OF DIMS
; FOR EACH DIM STARTING WITH THE 1ST LIST
; (2 BYTES EACH) OF THE MAX INDICE+1 THE
; VALUES.
;
LDA DIMFLG
ORA INTFLG
PHA
LDA VALTYP
PHA
LDA #0
PHA
INDLOP LDA VARNAM+1
PHA
LDA VARNAM
PHA
JSR INTIDX
PLA
STA VARNAM
PLA
STA VARNAM+1
PLA
TAY
TSX
LDA 258,X
PHA
LDA 257,X
PHA
LDA INDICE
STA 258,X
LDA INDICE+1
STA 257,X
INY
TYA
PHA
JSR CHRGOT
CMP #44
BEQ INDLOP
PLA
STA COUNT
JSR CHKCLS
PLA
STA VALTYP
PLA
STA INTFLG
AND #127
STA DIMFLG
LDX ARYTAB
LDA ARYTAB+1
LOPFDA STX LOWTR
STA LOWTR+1
.IFN CC1+CC2 <
CMP STREND+1 ;64K,128K
>
.IFN CC3+CC4 <
CMP ARYEND+1 ;192K,256K
>
BNE LOPFDV
.IFN CC1+CC2 <
CPX STREND ;64K,128K
>
.IFN CC3+CC4 <
CPX ARYEND ;192K,256K
>
BEQ NOTFDD
LOPFDV JSR MAPARY
LDY #0
LDA (LOWTR)Y
INY
CMP VARNAM
BNE NMARY1
LDA (LOWTR)Y
CMP VARNAM+1
BEQ GOTARY
NMARY1 INY
LDA (LOWTR)Y
CLC
ADC LOWTR
TAX
INY
LDA (LOWTR)Y
JSR MAPTXT
ADC LOWTR+1
BCC LOPFDA
BSERR LDX #ERRBS
.BYT $2C
FCERR LDX #ERRFC
ERRGO3 JMP ERROR
;
GOTARY JSR MAPTXT
LDX #ERRDD
LDA DIMFLG
BNE ERRGO3
JSR FMAPTR
JSR MAPARY
LDY #4
LDA (LOWTR)Y
CMP COUNT
BNE BSERR
JMP GETDEF ;GETDEF EXPECTS I6509 SET TO ARYBNK
SAV44 BPL SAV45; FLOAT: SIZE=5
DEX
LDA VARNAM
BPL SAV45 ; STRING:SIZE=4
DEX
DEX ; INT : SIZE=2
SAV45 RTS
.PAG
; HERE WHEN VAR IS NOT FOUND IN THE ARRAY TABLE
;
; BUILDING AN ENTRY
; PUT DOWN THE DESCRIPTOR
; SETUP # OF DIMS
; MAKE SURE THERE IS ROOM FOR THE NEW ENTRY
; REMEMBER 'VARPNT'
; TALLY =4
; SKIP 2 LOCS FOR LATER FILL IN OF SIZE
; LOOP GET AN INDICE
; PUT DOWN #+1 AND INC VARPTR
; TALLY= TALLY*#+1
; DECREMENT #-DIMS
; BNE LOOP
; CALL 'REASON' WITH Y,A REFLECTING LAST LOC OF VAR
; UPDATE STREND
; ZERO ALL
; MAKE TALLY INCLUDE MAXDIMS AND DESCRIPTOR
; PUT DOWN TALLY
; IF CALLED BY DIM, RETURN
; OTHERWISE
; INDEX INTO THE VAR AS IF IT WERE FOUND ON THE
; INITIAL SEARCH
NOTFDD JSR FMAPTR
.IFN CC1+CC2 <
JSR REASON
>
.IFN CC3+CC4 <
JSR REASNA
>
JSR MAPARY
LDY #0
STY CURTOL+1
LDA VARNAM ;STOR NAME, CALC ELT SIZE
STA (LOWTR)Y
INY
LDX #5
LDA VARNAM+1
STA (LOWTR)Y
JSR SAV44
STX CURTOL
LDA COUNT
INY
INY
INY
STA (LOWTR)Y ;STORE #DIMENSIONS
LOPPTA
LDX #11 ;DEFAULT UPPER BOUND FOR SUBSCR
LDA #0
BIT DIMFLG
BVC NOTDIM
PLA ;NOT USING DEFAULT, GET SIZE FROM STACK...
CLC
ADC #1 ;...AND ADD 1 TO IT FOR LIMIT
TAX
PLA
ADC #0
NOTDIM INY
STA (LOWTR)Y ;STORE UPPER BOUND (REVERSE ORDER)
INY
TXA
STA (LOWTR)Y
JSR UMULT ;INCREASE CURRENT SIZE
STX CURTOL
STA CURTOL+1
LDY INDEX ;RESTORE INDEX SAVED BY UMULT
DEC COUNT
BNE LOPPTA ;ANY MORE DIMS TO DO?
ADC ARYPNT+1 ;NO, ADD TOTAL SIZE OF ARRAY TO PTR
BCS OMERR1
STA ARYPNT+1
TAY
TXA
ADC ARYPNT
BCC GREASE
INY
BEQ OMERR1
GREASE
JSR MAPTXT
.IFN CC1+CC2 <
JSR REASON ;64K OR 128K VERSIONS
STA STREND
STY STREND+1
>
.IFN CC3+CC4 <
JSR REASNA ;192K OR 256K VERSIONS
STA ARYEND
STY ARYEND+1
>
JSR MAPARY
LDA #0
INC CURTOL+1
LDY CURTOL
BEQ DECCUR
ZERITA DEY
STA (ARYPNT)Y
BNE ZERITA
DECCUR
DEC ARYPNT+1
DEC CURTOL+1
BNE ZERITA
INC ARYPNT+1
SEC
.IFN CC1+CC2 <
LDA STREND ;64K OR 128K VERSIONS
>
.IFN CC3+CC4 <
LDA ARYEND ;192K OR 256K VERSIONS
>
SBC LOWTR
LDY #2
STA (LOWTR)Y
.IFN CC1+CC2 <
LDA STREND+1 ;64K OR 128K VERSIONS
>
.IFN CC3+CC4 <
LDA ARYEND+1 ;192K OR 256K VERSIONS
>
INY
SBC LOWTR+1
STA (LOWTR)Y
LDA DIMFLG
BNE DIMRTS
INY
GETDEF
LDA (LOWTR)Y ;I6509 SET TO ARRAY BANK ALREADY
STA COUNT
LDA #0
STA CURTOL
INLPNM STA CURTOL+1
INY
PLA
TAX
STA INDICE
PLA
STA INDICE+1
LDA (LOWTR)Y
INY
CMP INDICE+1
BEQ INLPN0
BCS INLPN1
BSERR7 JMP BSERR
.IFN CC1+CC2 <
OMERR1 JMP OMERR
>
.IFN CC3+CC4 <
OMERR1 JMP OMERRA
>
;
INLPN0 LDA (LOWTR)Y
CMP INDICE
BEQ BSERR7
BCC BSERR7
;
INLPN1 LDA CURTOL+1
ORA CURTOL
CLC
BEQ ADDIND
JSR UMULT
TXA
ADC INDICE
TAX
TYA
LDY INDEX1
ADDIND ADC INDICE+1
STX CURTOL
DEC COUNT
BNE INLPNM
STA CURTOL+1
LDX #5 ;MAXIMUM ELT SIZE IS:
LDA VARNAM+1
JSR SAV44
STX ADDEND
LDA #0
JSR UMULTD
TXA
ADC ARYPNT
STA VARPNT
TYA
ADC ARYPNT+1
STA VARPNT+1
TAY
LDA VARPNT
LDX #ARYBNK
STX VARPNT+2
DIMRTS JMP MAPTXT
.PAG
; TWO BYTE UNSIGNED INTEGER MULTIPLY.
; FOR MULTIPLY DIMENSIONED ARRAYS.
; X,Y= X,A= CURTOL*LOWTR,Y,Y+1
UMULT STY INDEX
LDA (LOWTR)Y ;ASSUMES I6509 SET BY CALLER
STA ADDEND
DEY
LDA (LOWTR)Y
UMULTD STA ADDEND+1
LDA #16
STA DECCNT
LDX #0
LDY #0
UMULTC TXA
ASL A
TAX
TYA
ROL A
TAY
BCS OMERR1
ASL CURTOL
ROL CURTOL+1
BCC UMLCNT
CLC
TXA
ADC ADDEND
TAX
TYA
ADC ADDEND+1
TAY
BCS OMERR1
UMLCNT DEC DECCNT
BNE UMULTC
RTS
.PAG
;FRE
;
; FRE(EXPR) RETURNS THE NUMBER OF AVAILABLE BYTES IN THE
; SPECIFIED BANK. IF 'EXPR' IS STRING, THEN THE BANK IS
; ASSUMED TO BE THE STRING BANK. IF 'EXPR' IS NUMERIC, IT
; MUST BE A POSITIVE, BYTE VALUE TO BE USED AS THE BANK#.
; IF THE SELECTED BANK CANNOT BE USED FOR BASIC PROGRAMS,
; A ZERO IS RETURNED. GARBAGE COLLECTION IS ALWAYS DONE
; WHENEVER THE STRING BANK IS SELECTED.
;
; FRE IS COMPUTED AS FOLLOWS:
;
; FRETOP-STREND : 64 (0), 128(1), 192(1), 256(3)
; BUFFPT-TXTEND : 128(0), 192(0), 256(0)
; HIGHST-ARYEND : 192(2), 256(2)
; HIGHST-VAREND : 256(1)
;
FRE
LDA VALTYP ;NUMERIC OR STRING PARAM?
BEQ FREF10 ;NUMERIC
JSR FREFAC ;STRING... FREE TEMPORARY
LDX #STRBNK
JMP FREFST
FREF10
JSR CONINT ;.X := BANK#
CPX #TXTBNK
BNE FREF80
.IFN CC1 <
FREFST
JSR GARBA2 ;COMPRESS OUT GARBAGE STRINGS
SEC
LDA FRETOP
SBC STREND
TAY
LDA FRETOP+1
SBC STREND+1
>
.IFN CC2+CC3+CC4 <
SEC
LDA BUFFPT
SBC TXTEND
TAY
LDA BUFFPT+1
SBC TXTEND+1
>
JMP NOSFLT
FREF80
.IFN CC2+CC3+CC4 <
CPX #VARBNK
BNE FREF70
>
.IFN CC2+CC3 <
FREFST
JSR GARBA2 ;COMPRESS OUT GARBAGE STRINGS
SEC
LDA FRETOP
SBC STREND
TAY
LDA FRETOP+1
SBC STREND+1
JMP NOSFLT
>
.IFN CC4 <
SEC
LDA HIGHST
SBC VAREND
TAY
LDA HIGHST+1
SBC VAREND+1
JMP NOSFLT
>
FREF70
.IFN CC3+CC4 <
CPX #ARYBNK
BNE FREF60
SEC
LDA HIGHST
SBC ARYEND
TAY
LDA HIGHST+1
SBC ARYEND+1
JMP NOSFLT
>
FREF60
.IFN CC4 <
FREFST
CPX #STRBNK
BNE FREF50
JSR GARBA2 ;COMPRESS OUT STRINGS
SEC
LDA FRETOP
SBC STREND
TAY
LDA FRETOP+1
SBC STREND+1
JMP NOSFLT
>
FREF50 LDA #0
TAY
.SKI 4
;UNSIGNED DOUBLE BYTE INTEGER TO FLOAT
;
NOSFLT JSR STOINT
SEC ;SIGN IS POSITIVE
JMP FLOATC
.SKI 4
;FUNCTION POS(X)
;
POS SEC
JSR PLOT ;GET CURRENT POSITION
.SKI 4
;SIGNED SINGLE BYTE INTEGER TO FLOAT
;
SNGFLT LDA #0 ;MSD IS 0, LSD IN .Y
.SKI 4
;SIGNED DOUBLE BYTE INTEGER TO FLOAT
;
GIVAYF JSR STOINT
JMP FLOATS
.SKI 4
;MOV INT TO FAC AND COMPUTE
;PROPER EXPONENTS
;
STOINT LDX #0
STX VALTYP ;TYPE IS INTEGER
STA FACHO ;MSD
STY FACHO+1 ;LSD
LDX #$90 ;EXPONENT
STORTS RTS
.PAG
; NOTE
; ONLY SINGLE ARGUMENTS ARE ALLOWED TO FUNCTIONS AND
; FUNCTIONS MUST BE OF THE SINGLE LINE FORM
; DEF FNA(X)= X^2+X-2
; NO STRINGS CAN BE INVOLVED WITH THESE FUNCTIONS
;
; IDEA
; CREAT A SIMPLE VARIABLE ENTRY WHOSE 1ST CHAR HAS THE
; 200 BIT SET.
; THE VALUE WILL BE
; A TEXT PTR TO THE FORMULA
; A PTR TO THE ARGUMENT VARIABLE
;
; FUNCTION NAMES CAN BE LIKE 'FNA4'.
.SKI 4
;SEE IF WE ARE IN DIRECT MODE.
; AND COMPLAIN IF SO.
ERRDIR JSR TSTDIR ;IN DIRECT MODE?
BNE STORTS ;NO...
LDX #ERRID ;YES...'ILLEGAL DIRECT'
.BYT $2C
ERRGUF LDX #ERRUF ;UDF NEVER DEFINED
JMP ERROR
.SKI 4
;TSTDIR
;
;TEST IF EXECUTION IS IN DIRECT MODE
;
;RETURN Z=1 IF DIRECT, Z=0 OTHERWISE
;
TSTDIR LDA CURLIN+1
CMP #$FF
RTS
;
TDM =TSTDIR
.SKI 4
GETFNM ; GET A PTR TO A FUNCTION NAME
LDA #TKFN ; MUST START WITH FN
JSR SYNCHR
ORA #$80 ; .A<-1ST CHAR OF FN NAME+$80
STA SUBFLG ; INDICATES PARSING FN
JSR PTRGT2
STA DEFPNT ; DEFPNT<-PTR TO FTN
STY DEFPNT+1
STX DEFPNT+2
JMP CHKNUM
.SKIP 3
FNDOER JSR GETFNM
LDA DEFPNT+2 ;STACK <- PTR TO FTN (DEFPNT)
PHA
LDA DEFPNT+1
PHA
LDA DEFPNT
PHA
JSR PARCHK ;COMPUTE ACTUAL PARAM, CHECK FOR PARENS
JSR CHKNUM
PLA ; DEFPNT <- STACK
STA DEFPNT
PLA
STA DEFPNT+1
PLA
STA DEFPNT+2
STA I6509
LDY #2 ; VARPNT <- PTR FOR FORMAL PARAM
LDA (DEFPNT)Y
STA VARPNT
TAX
INY
LDA (DEFPNT)Y
STA VARPNT+1
ORA VARPNT ;NULL PTR => UNDEF'D
BEQ ERRGUF
INY
LDA (DEFPNT)Y
STA VARPNT+2
STA I6509
FNDO50 LDA (VARPNT)Y ; PUSH OLD VALUE OF FORMAL PARAM
PHA
DEY
BPL FNDO50
LDY VARPNT+1 ;INIT FORMAL PARAM WITH FAC
LDA VARPNT+2
JSR MOVUMF
LDA TXTPTR+1 ; STACK <- TEXT PTR
PHA
LDA TXTPTR
PHA
LDA DEFPNT+2
STA I6509
LDA (DEFPNT)Y ;TEXT PTR <- PTR TO FTN BODY TEXT
STA TXTPTR
INY
LDA (DEFPNT)Y
STA TXTPTR+1
JSR MAPTXT
LDA VARPNT+2 ; STACK <- PTR TO FORMAL PARAM
PHA
LDA VARPNT+1
PHA
LDA VARPNT
PHA
JSR FRMNUM ; COMPUTE THE FTN BODY
PLA ; DEFPNT <- PTR TO FORMAL
STA DEFPNT
PLA
STA DEFPNT+1
PLA
STA DEFPNT+2
JSR CHRGOT
BEQ *+5 ; NO MULTI-STMT FTN BODIES
JMP SNERR
PLA ; RESTORE TEXT PTR
STA TXTPTR
PLA
STA TXTPTR+1
;
; WHEN ENTERED FROM DEFSTF, DEFFIN IS USED TO
; RESTORE THE PRE-FUNCTION CALL VALUE OF THE
; FORMAL PARAMETER (5 BYTES).
;
; WHEN ENTERED FROM DEFN, DEFFIN IS USED TO INI-
; TIALIZE THE FTN'S SYMBOL TABLE ENTRY WITH A PTR
; TO THE TEXT FOR THE FTN BODY (2 BYTES) AND A PTR
; TO THE DATA AREA OF THE FORMAL PARAMETER (3 BYTES)
;
DEFFIN LDA DEFPNT+2
STA I6509
LDY #0
PLA
STA (DEFPNT)Y
PLA
INY
STA (DEFPNT)Y
PLA
INY
STA (DEFPNT)Y
PLA
INY
STA (DEFPNT)Y
PLA
INY
STA (DEFPNT)Y
JMP MAPTXT
.SKI 3
PEEK LDA POKER+1
PHA
LDA POKER
PHA
JSR GETADR
LDX I6509
LDA DFBANK
STA I6509
LDY #0
LDA (POKER)Y
TAY
PLA
STA POKER
PLA
STA POKER+1
STX I6509
JMP SNGFLT
.PAGE
FADDH LDA #<FHALF
LDY #>FHALF
BNE FADD
.SKI 4
FSUB JSR CONUPK
FSUBT JSR SAV41
EOR ARGSGN
STA ARISGN
LDA FACEXP
JMP FADDT
;
SAV75
LDY BUFFPT+1
LDX BUFFPT
BNE SAV76
DEY
SAV76
DEX
ZERRTS RTS
;
FADD5 JSR SHIFTR
BCC FADD4 ;ALWAYS
FADD JSR CONUPK
FADDT BNE *+5
JMP MOVFA
;
LDX FACOV
STX OLDOV
LDX #ARGEXP
LDA ARGEXP
FADDC TAY
BEQ ZERRTS
SEC
SBC FACEXP
BEQ FADD4
BCC FADDA
STY FACEXP
LDY ARGSGN
STY FACSGN
EOR #$FF
ADC #0
LDY #0
STY OLDOV
LDX #FAC
BNE FADD1
FADDA LDY #0
STY FACOV
FADD1 CMP #$F9
BMI FADD5
TAY
LDA FACOV
LSR 1,X
JSR ROLSHF
FADD4 BIT ARISGN
BPL FADD2
LDY #FACEXP
CPX #ARGEXP
BEQ SUBIT
LDY #ARGEXP
SUBIT SEC
EOR #$FF
ADC OLDOV
STA FACOV
LDA 3+ADDPRC,Y
SBC 3+ADDPRC,X
STA FACLO
LDA ADDPRC+2,Y
SBC 2+ADDPRC,X
STA FACMO
LDA 2,Y
SBC 2,X
STA FACMOH
LDA 1,Y
SBC 1,X
STA FACHO
FADFLT BCS NORMAL
JSR NEGFAC
NORMAL LDY #0
TYA
CLC
NORM3 LDX FACHO
BNE NORM1
LDX FACHO+1
STX FACHO
LDX FACMOH+1
STX FACMOH
LDX FACMO+1
STX FACMO
LDX FACOV
STX FACLO
STY FACOV
ADC #$08
CMP #$18+ADDPR8
BNE NORM3
ZEROFC LDA #0
ZEROF1 STA FACEXP
ZEROML STA FACSGN
RTS
FADD2 ADC OLDOV
STA FACOV
LDA FACLO
ADC ARGLO
STA FACLO
LDA FACMO
ADC ARGMO
STA FACMO
LDA FACMOH
ADC ARGMOH
STA FACMOH
LDA FACHO
ADC ARGHO
STA FACHO
JMP SQUEEZ
;
NORM2 ADC #1
ASL FACOV
ROL FACLO
ROL FACMO
ROL FACMOH
ROL FACHO
NORM1 BPL NORM2
SEC
SBC FACEXP
BCS ZEROFC
EOR #$FF
ADC #1
STA FACEXP
SQUEEZ BCC RNDRTS
RNDSHF INC FACEXP
BEQ OVERR
ROR FACHO
ROR FACMOH
ROR FACMO
ROR FACLO
ROR FACOV
RNDRTS RTS
NEGFAC JSR SAV41
NEGFCH LDA FACHO
EOR #$FF
STA FACHO
LDA FACMOH
EOR #$FF
STA FACMOH
LDA FACMO
EOR #$FF
STA FACMO
LDA FACLO
EOR #$FF
STA FACLO
LDA FACOV
EOR #$FF
STA FACOV
INC FACOV
BNE INCFRT
INCFAC INC FACLO
BNE INCFRT
INC FACMO
BNE INCFRT
INC FACMOH
BNE INCFRT
INC FACHO
INCFRT RTS
OVERR LDX #ERROV
JMP ERROR
;
MULSHF LDX #RESHO-1
SHFTR2 LDY 3+ADDPRC,X
STY FACOV
LDY 3,X
STY 4,X
LDY 2,X
STY 3,X
LDY 1,X
STY 2,X
LDY BITS
STY 1,X
SHIFTR ADC #$08
BMI SHFTR2
BEQ SHFTR2
SBC #$08
TAY
LDA FACOV
BCS SHFTRT
SHFTR3 ASL 1,X
BCC SHFTR4
INC 1,X
SHFTR4 ROR 1,X
ROR 1,X
ROLSHF ROR 2,X
ROR 3,X
ROR 4,X
ROR A
INY
BNE SHFTR3
SHFTRT CLC
RTS
.SKI 4
FONE .BYT $81,0,0,0,0
LOGCN2 .BYT $03,$7F,$5E,$56
.BYT $CB,$79,$80,$13
.BYT $9B,$0B,$64,$80
.BYT $76,$38,$93,$16
.BYT $82,$38,$AA,$3B,$20
SQR05 .BYT $80,$35,$04,$F3,$34
SQR20 .BYT $81,$35,$04,$F3,$34
NEGHLF .BYT $80,$80,0,0,0
LOG2 .BYT $80,$31,$72,$17,$F8
.END