Browse Source

added MATHPACK

pull/5/head
Michael Steil 4 years ago
parent
commit
acd921ae3d
  1. 223
      MATHPACK/ddiv
  2. 391
      MATHPACK/mathpack
  3. 5
      README.md
  4. 1
      build.sh

223
MATHPACK/ddiv

@ -0,0 +1,223 @@
;DDIV **DECIMAL DIVIDE FAC=ARG/FAC
; 12-20-79
;DIVISION BY ZERO ERROR IF FAC ZERO
;
DDIV LDA FACMSD
BNE *+5
JMP DVOERR
;
;DONE IF ARG IS ZERO
;
LDA ARGMSD
BNE DDIV5
JMP DZEROF
;
;2'S COMPLEMENT ON DIVISOR
;AND SAVE EXPONENTS
;
DDIV5 LDA FACEXP
EOR #$FE
CLC
ADC #2
PHA
LDA ARGEXP
PHA
;
LDA #0
STA ARGEXP
STA FACEXP
LDX #RESMSD-RESLSD
DDIV10 STA RESLSD,X
DEX
BPL DDIV10
STA RESEXP
;
;IS DIVISOR GREATER THAN DIVIDEND
;
LDY #FACMSD-FACLSD
LDX #0
SEC
SED
DDIV20 LDA ARGLSD,X
SBC FACLSD,X
STA ARGLSD,X
INX
DEY
BPL DDIV20
LDA ARGEXP
SBC FACEXP
STA ARGEXP
CLD
PHP ;DECREMENT FLAG
BCS DDIV80
;
;RESTORE ARG
;
DDIV30 LDY #FACMSD-FACLSD
LDX #0
CLC
SED
DDIV40 LDA ARGLSD,X
ADC FACLSD,X
STA ARGLSD,X
INX
DEY
BPL DDIV40
LDA ARGEXP
ADC FACEXP
STA ARGEXP
CLD
;
;IS RESMSD ZERO?
;
LDA RESMSD
AND #$0F
BEQ DDIV45
PLP
PLA
;
;ADJUST EXPONENT
;
BCS DDIV43
SEC
SBC #2
PHA
LSR A
CMP #$3F
BNE DDIV41
PLA
PLA
JMP DZEROF
DDIV41 PLA
DDIV43 STA ARGEXP
PLA
STA FACEXP
JMP DMULDN
;
;SHIFT ARG MANTISSA LEFT ONE DIGIT
;
DDIV45 LDY #3
DDIV50 LDX #0
CLC
PHP
DDIV52 PLP
ROL ARGLSD,X
PHP
INX
CPX #1+ARGMSD-ARGLSD
BCC DDIV52
PLP
ROL ARGEXP
;
;SHIFT RES MANTISSA LEFT ONE DIGIT
;
LDX #0
CLC
PHP
DDIV62 PLP
ROL RESLSD,X
PHP
INX
CPX #1+RESMSD-RESLSD
BCC DDIV62
PLP
ROL RESEXP
DEY
BPL DDIV50
;
;IS DIVISOR GREATER THAN DIVIDEND
;
DDIV70 LDY #FACMSD-FACLSD
LDX #0
SEC
SED
DDIV72 LDA ARGLSD,X
SBC FACLSD,X
STA ARGLSD,X
INX
DEY
BPL DDIV72
LDA ARGEXP
SBC FACEXP
STA ARGEXP
CLD
BCC DDIV30
;
;INCREMENT RESLSD
;
DDIV80 INC RESLSD
BNE DDIV70
.END
.LIB DCOMP
;DECIMAL COMPARE ARG:FAC
;DECEMBER 31, 1979
;
;.A= 1,C=0 IF ARG .LT. FAC
;.A= 0,C=1 IF ARG .EQ. FAC
;.A=-1,C=1 IF ARG .GT. FAC
;
DCOMP LDA FACEXP
EOR ARGEXP
;
;ARE MANTISSA SIGNS SAME?
;
LSR A
BCS DCOM10 ;NO...
;
;ARE EXOPONENT SIGNS SAME?
;
ROL A
BMI DCOM20 ;NO...
;
;ARE EXPONENT MAGNITUDES SAME?
;
BNE DCOM30 ;NO...
;
;COMPARE MANATISSA MAGNITUDES
;
LDX #FACMSD-FACLSD-1
SED
DCOM5 LDA ARGLSD+1, X
CMP FACLSD+1,X
BCC DCOM7
BNE DCOM7
DEX
BNE DCOM5
DCOM7 CLD
BNE DCOM40
TXA
BEQ DCOM45
;
;CASE DIFFERENT MANTISSA SIGNS
;
DCOM10 LDA FACEXP
ROR A
JMP DCOM42
;
;CASE DIFFERENT EXPONENT SIGNS
;
DCOM20 LDA FACEXP
ROL A
JMP DCOM40
;
;CASE DIFFERENT EXPONENT MAGNITUDES
;
DCOM30 SEC
LDA ARGEXP
SBC FACEXP
;
;HANDLE NEGATIVE MANTISSA
;
DCOM40 ROL A
EOR ARGEXP
LSR A
;
;COMMON EXIT CODE
;
DCOM42 LDA #$FF
BCS DCOM45
LDA #$01
;
DCOM45 RTS
.END
.END

391
MATHPACK/mathpack

@ -0,0 +1,391 @@
;
;
;
; BCD MATH PACKAGE
;
; THE FOLLOWING ROUTINES ARE PRO-
; VIDED: (+,-,*,/,:) DADD, DSUB, DMULT
; DDIV, AND DCOMP. THE ROUTINES ARE
; SET FOR FIXED 22 DIGIT PRECISION WITH
; AN EXPONENT RANGE +63 TO -64. THE
; MANTISSA IS STORED IN ELEVEN BYTES
; WITH THE LSD IN THE LOWEST MEMORY BYTE
; AND LEAST SIGNIFICANT NYBBLE. THE
; EXPONENT BYTE CONTAINS THE EXPONENT
; TWO'S COMPLEMENT AND SHIFTED LEFT ONE
; BIT. THE LEAST SIGNIFICANT BIT OF THE
; EXPONENT BYTE CONTAINS THE SIGN OF THE
; MANTISSA.
;
; COPYRIGHT 1979 BY JOHN FEAGANS
;
;RESULT REGISTER
;
RESEXP *=*+1
RESLSD *=*+10
RESMSD *=*+1
;
;FLOATING ACCUMULATOR
;
FACEXP *=*+1
FACLSD *=*+10
FACMSD *=*+1
;
;ARGUMENT REGISTER
;
ARGEXP *=*+1
ARGLSD *=*+10
ARGMSD *=*+1
;
;LOCAL VARIABLE FOR MATH ROUTINES
;
COUNT *=*+1
;
;USER SUPPLIED ROUTINES FOR ERROR
;
* =$400
OVERR BRK ;OVERFLOW ERROR
DVOERR BRK ;DIVIDE BY ZERO ERROR
;.LIB DADD
;**DECIMAL SUBTRACT FAC=ARG=FAC**
; 1-02-80
;COMPLEMENT SIGN OF FAC MANTISSA
;
DSUB LDA FACEXP
EOR #$01
STA FACEXP
;
;**DECIMAL ADD FAC=FAC+ARG**
;
;EXCHANGE ARG AND FAC
;
DADD0 LDX #FACMSD-FACEXP
;
;NO EXCHANGE IF ARG 0
;
LDA ARGMSD
BNE DADD2
LDA FACEXP
STA ARGEXP
JMP DADD
;
DADD2 LDY ARGEXP,X
LDA FACEXP,X
STA ARGEXP,X
STY FACEXP,X
DEX
BPL DADD2
;
;CHECK IF BOTH EXPONENTS SAME
;
DADD LDA FACMSD
BNE DADD5
LDA ARGEXP
STA FACEXP
DADD5 LDA FACEXP
ORA #1
PHA
SEC ;FOR LATER SUBTRACTS
EOR ARGEXP
BPL DADD10
;
;COMPUTE # OF TIMES ARG TO BE SHIFTED
;RIGHT, MAKING SURE FACEXP>=ARGEXP FOR
;CASE WHEN EXP SIGNS --DIFFERENT--
;
PLA
BMI DADD0 ;FACEXP<ARGEXP
SBC ARGEXP
JMP DADD20
;
;COMPUTE # OF TIMES ARG TO BE SHIFTED
;RIGHT, MAKING SURE FACEXP>=ARGEXP FOR
;CASE WHEN EXP SIGNS --SAME--
;
DADD10 PLA
SBC ARGEXP
BCC DADD0
AND #$FE
BNE DADD20
;
;IF FACEXP=ARGEXP, THEN MAKE SURE THAT
;ABS(FAC-MANTISSA)>=ABS(ARG-MANTISSA)
;
PHA
LDX #0
;CARRY SET HERE
SED
LDY #FACMSD-FACLSD
DADD12 LDA FACLSD,X
SBC ARGLSD,X
INX
DEY
BPL DADD12
CLD
PLA
BCC DADD0
;
;CONVERT DIFFERENCE OF EXPONENTS TO SHIFT COUNT
;
DADD20 LSR A
STA COUNT
;
;SHIFT ARG MANTISSA RIGHT THE NUMBER OF
;TIMES SPECIFIED IN COUNT.
;
DADD30 DEC COUNT
BMI DADD40
LDY #3
DADD32 LDX #ARGMSD-ARGLSD
CLC
DADD34 ROR ARGLSD,X
DEX
BPL DADD34
DEY
BPL DADD32
BMI DADD30
;
;IF BOTH MANTISSA HAVE SAME SIGN THEN
;PERFORM AN ADD :FAC=FAC+ARG
;
DADD40 LDA ARGEXP
EOR FACEXP
ROR A
LDX #0
LDY #FACMSD-FACLSD
SED
BCS DADD50
;
DADD42 LDA FACLSD,X
ADC ARGLSD,X
STA FACLSD,X
INX
DEY
BPL DADD42
BMI DNORM
;
DADD50 LDA FACLSD,X
SBC ARGLSD,X
STA FACLSD,X
INX
DEY
BPL DADD50
;
;**DECIMAL NORMALIZE FAC WITH NO LSR**
;
DNORMZ CLC
;
;**DECIMAL NORMALIZE FAC WITH POTENTIAL LSR**
;
DNORM CLD
BCS DNOR20
;
;BAIL OUT IF MANTISSA ZERO
;
LDA #0
LDX #FACMSD-FACLSD
DNORM2 ORA FACLSD,X
DEX
BPL DNORM2
TAX
BEQ DZEROF
;
;IS MSD SIGNIFICANT YET?
;
DNOR10 LDA FACMSD
AND #$F0
BNE DNOR40 ;YES...DONE
;
;SHIFT FAC LEFT ONE DIGIT
;
LDY #3
DNOR12 LDX #0
CLC
PHP
DNOR14 PLP
ROL FACLSD,X
PHP
INX
CPX #1+FACMSD-FACLSD
BCC DNOR14
PLP
DEY
BPL DNOR12
;
;DECREMENT FACEXP WITH UNDERFLOW PROTECTION
;
LDA FACEXP
LSR A
PHP
SEC
SBC #1
CMP #$3F
BNE DNOR15
PLP
JMP DZEROF ;UNDERFLOW
DNOR15 PLP
ROL A
STA FACEXP
JMP DNOR10
;
;SHIFT FAC RIGHT ONE DIGIT
;
DNOR20 LDY #3
DNOR22 LDX #FACMSD-FACLSD
CLC
DNOR24 ROR FACLSD,X
DEX
BPL DNOR24
DEY
BPL DNOR22
;
;MAKE MSD A 1 FROM CARRY
;
LDA FACMSD
ORA #$10
STA FACMSD
;
;INCREMENT FACEXP QUARD OVERFLOW
;
LDA FACEXP
LSR A
PHP
CLC
ADC #1
CMP #$40
BEQ DOVERR ;CASE $7F+$01->$80
PLP
ROL A
STA FACEXP
;
DNOR40 RTS
;
DOVERR JMP OVERR
;
;**PUT DECIMAL ZERO IN FAC**
;
DZEROF LDA #0
LDX #FACMSD-FACLSD
DZERO2 STA FACLSD,X
DEX
BPL DZERO2
STA FACEXP
RTS
;.END
;.LIB DMULT
;**DECIMAL MULTIPLY FAC=FAC*ARG**
; 12-20-79
DMULT LDX #RESMSD-RESLSD
LDA #0
DMUL10 STA RESEXP,X
DEX
BPL DMUL10
STA RESEXP
;
;EXTRACT LSD OF FAC INTO COUNT
;
DMUL20 LDA FACLSD
AND #$F
STA COUNT
;
;ADD ARG TO RES COUNT TIMES
;
DMUL30 DEC COUNT
BMI DMUL50
;
LDX #0
LDY #ARGMSD-ARGLSD
SED
CLC
DMUL40 LDA RESLSD,X
ADC ARGLSD,X
STA RESLSD,X
INX
DEY
BPL DMUL40
;
LDA #0
ADC RESEXP
STA RESEXP ;OVERFLOW TO RESEXP
CLD
BCC DMUL30
;
;SHIFT RES RIGHT 1 DIGIT
;
DMUL50 LDY #3
DMUL52 LDX #RESMSD-RESLSD
LSR RESEXP
DMUL54 ROR RESLSD,X
DEX
BPL DMUL54
;
;SHIFT FAC RIGHT 1 DIGIT
;
LDX #FACMSD-FACLSD
CLC
LDA #0
DMUL58 ROR FACLSD,X
ORA FACLSD,X
DEX
BPL DMUL58
DEY
BPL DMUL52
;
;CONTINUE UNTIL FAC IS ZERO
;
TAX
BNE DMUL20
;
;COMPUTE SIGN OF PRODUCT
;
DMULDN LDA ARGEXP
AND #$01
EOR FACEXP
STA FACEXP
;
;MOV PRODUCT FROM RES TO FAC
;
LDX #FACMSD-FACLSD
DMUL70 LDA RESLSD,X
STA FACLSD,X
DEX
BPL DMUL70
;
;COMPUTE EXPONENT OF PRODUCT
;
SEC
LDA ARGEXP
AND #$FE
PHA
EOR FACEXP
BPL DMUL90
;
;DIFFERENT SIGNS--DO ADD
;
PLA
ADC FACEXP
CLC
ADC #1
JMP DMUL97
;
;BOTH NEGATIVE--WATCH UNDERFLOW
;
DMUL90 PLA
BPL DMUL95
ADC FACEXP
CLC
ADC #1
BMI DMUL97
JMP DZEROF
;
;BOTH POSITIVE--POSSIBLE OVERFLOW
;
DMUL95 ADC FACEXP
CLC
ADC #1
BPL DMUL97
JMP OVERR
DMUL97 STA FACEXP
JMP DNORMZ
;.END
.FILE DDIV

5
README.md

@ -243,6 +243,10 @@ The source contains a 90 degree rotated 6x8 pixel variant of the PETSCII charact
"DISK MONITOR 2040 V1.0", an extension to the PET monitor for disk commands (see mon.cmd). Extracted from UNKN008.D80 from [Ruud Baltissen's ICPUG disks](http://www.pagetable.com/docs/CBM2_Sources.zip) and converted to LF line breaks and LST-style indenting.
## MATHPACK
A variant of the "BCD Math Package" printed in the [Commodore 700 Reference Manual](http://www.zimmers.net/anonftp/pub/cbm/programming/b/Commodore_700_Reference_Manual.pdf). Extracted from UNKN008.D80 from [Ruud Baltissen's ICPUG disks](http://www.pagetable.com/docs/CBM2_Sources.zip) and converted to LF line breaks and LST-style indenting.
## ASSEMBLER_TED
A version of the Commodore Resident Assembler for the TED series (Plus/4, C16 and C116). Extracted from [ted_kernal_basic_src.tar.gz](http://www.zimmers.net/anonftp/pub/cbm/src/plus4/ted_kernal_basic_src.tar.gz).
@ -254,6 +258,7 @@ The KIM-1 "monitor" ROM (1975) from the [zimmers.net archive](http://www.zimmers
## KIMATH
The KIM-1 "KIMATH" math package (1976). Generated from the [original LST printout](http://retro.hansotten.nl/uploads/files/kimath.ZIP), and the .asm reconstruction by C. Bond from the same package.
# Credits
This repository is maintained by Michael Steil, mist64@mac.com

1
build.sh

@ -142,3 +142,4 @@ build1 PRINTER_8023P us.ptr.src
build2 ASSEMBLER_TED assembler
build1 DISK_MONITOR mon.lib
build1 MATHPACK mathpack

Loading…
Cancel
Save