AppleIIAsm-Collection/disks/disk3_math/T.MATH.MAC
nathanriggs 16c1731e54 Strings 0.2.0 update
- bugfixes
- implemented required library
- commenting updates
- .min of every routine
2018-12-22 20:35:05 -05:00

317 lines
8.3 KiB
Plaintext

*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*
* *
* MATH.MAC *
* *
* AUTHOR: NATHAN RIGGS *
* CONTACT: NATHAN.RIGGS@ *
* OUTLOOK.COM *
* *
* VERSION: 0.2.0 *
* DATE: 12-DEC-2018 *
* ASSEMBLER: MERLIN 8 PRO *
* LICENSE: APACHE 2.0 *
* OS: DOS 3.3 *
* *
*------------------------------*
* *
* THIS IS A MACRO LIBRARY FOR *
* MATH8.LIB AND MATH16.LIB *
* *
*------------------------------*
* *
* LIST OF MACROS *
* *
* ADD16 : 16BIT ADD *
* SUB16 : 16BIT SUBTRACT *
* MUL16 : 16BIT MULTIPLY *
* DIV16 : 16BIT DIVIDE *
* REM16 : 16BIT REMAINDER *
* RND8 : RANDOM # 0..255 *
* RNDB : RANDOM # LOW..HIGH *
* CMP16 : 16BIT COMPARE *
* RND16 : 16BIT RANDOM # *
* RNDW : RANDOM WORD LOW..HI *
* MUL8 : 8BIT MULTIPLY *
* DIV8 : 8BIT DIVIDE, REMAIND *
* *
*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*
*
*``````````````````````````````*
* ADD16 :: 16-BIT ADDITION *
*- -*
* ADD TWO 16BIT VALUES, STORE *
* RESULT IN Y, X (LOW, HIGH) *
*- -*
* PARAMETERS: *
* *
* ]1 = ADDEND 1 *
* ]2 = ADDEND 2 *
* ]3 = INDIRECT MEM FLAG *
*- -*
* SAMPLE USAGE: *
* *
* ADD16 #3000;#4000 *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
ADD16 MAC
_ISLIT ]1
_ISLIT ]2
JSR ADDIT16
<<<
*
*``````````````````````````````*
* SUB16 :: 16-BIT SUBTRACTION *
*- -*
* SUBTRACTS ONE 16BIT INTEGER *
* FROM ANOTHER, STORING THE *
* RESULT IN Y,X (LOW, HIGH) *
*- -*
* PARAMETERS: *
* *
* ]1 = MINUEND *
* ]2 = SUBTRAHEND *
*- -*
* SAMPLE USAGE: *
* *
* SUB16 #2000;#1500 *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
SUB16 MAC
_ISLIT ]1
_ISLIT ]2
JSR SUBT16
<<<
*
*``````````````````````````````*
* MUL16 :: 16-BIT MULTIPLY *
*- -*
* MULTIPLIES TWO 16BIT NUMBERS *
* AND RETURNS THE PRODUCT IN *
* Y,X (LOW, HIGH). *
*- -*
* PARAMETERS: *
* *
* ]1 = MULTIPLICAND *
* ]2 = MULTIPLIER *
*- -*
* SAMPLE USAGE: *
* *
* MUL16 #400;#500 *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
MUL16 MAC
_ISLIT ]1
_ISLIT ]2
JSR MULT16
<<<
*
*``````````````````````````````*
* DIV16 :: 16-BIT DIVISION *
*- -*
* DIVIDES ONE 16BIT NUMBER BY *
* ANOTHER AND RETURNS THE *
* RESULT IN Y,X (LOW,HIGH). *
* *
* IF THE THIRD PARAMETER IS *
* PASSED WITH A S, VALUES WILL *
* BE TREATED AS SIGNED; IF *
* NOT, VALUES WILL BE TREATED *
* AS UNSIGNED. *
*- -*
* PARAMETERS: *
* *
* ]1 = DIVIDEND *
* ]2 = DIVISOR *
*- -*
* SAMPLE USAGE: *
* *
* DIV16 #3000;#300 *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
DIV16 MAC
_ISLIT ]1
_ISLIT ]2
IF S,]3 ; SIGNED
JSR SDIVD16
ELSE
JSR UDIVD16 ; UNSIGNED
FIN
<<<
*
*``````````````````````````````*
* REM16 :: 16-BIT DIV REMAINR *
*- -*
* DIVIDES ONE INTEGER BY *
* ANOTHER AND RETURNS THE *
* REMAINDER IN Y,X (LOW, HIGH) *
* *
* IF THE THIRD PARAMETER IS *
* PASSED WITH A S, VALUES WILL *
* BE TREATED AS SIGNED; IF *
* NOT, VALUES WILL BE TREATED *
* AS UNSIGNED. *
*- -*
* PARAMETERS: *
* *
* ]1 = DIVIDEND *
* ]2 = DIVISOR *
*- -*
* SAMPLE USAGE: *
* *
* REM16 #1000;#333 *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
REM16 MAC
_ISLIT ]1
_ISLIT ]2
IF S,]3 ; SIGNED
JSR SREMD16
ELSE
JSR UREMD16 ; UNSIGNED
FIN
<<<
*
*``````````````````````````````*
* RNDB :: 8BIT RANDOM LOW,HI *
*- -*
* RETURNS A RANDOM NUMBER IN *
* REGISTER A THAT IS BETWEEN *
* THE LOW AND HIGH BOUNDARIES *
* PASSED IN THE PARAMETERS. *
* *
* NOTE THAT THIS RETURNS A *
* BYTE, AND THUS ONLY DEALS *
* WITH VALUES BETWEEN 0..255. *
*- -*
* PARAMETERS: *
* *
* ]1 = LOW BOUNDARY *
* ]2 = HIGH BOUNDARY *
*- -*
* SAMPLE USAGE: *
* *
* RNDB #50;#100 *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
RNDB MAC
LDA ]1 ; LOW
PHA
LDA ]2 ; HIGH
PHA
JSR RANDB
<<<
*
*``````````````````````````````*
* CMP16 : 16BIT COMPARISON *
*- -*
* COMPARES TWO 16BIT VALUES *
* AND ALTERS THE P-REGISTER *
* ACCORDINGLY (FLAGS). *
*- -*
* PARAMETERS: *
* *
* ]1 = WORD 1 TO COMPARE *
* ]2 = WORD 2 TO COMPARE *
*- -*
* SAMPLE USAGE: *
* *
* CMP16 #1023;#3021 *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
CMP16 MAC
_ISLIT ]1
_ISLIT ]2
JSR COMP16
<<<
*
*``````````````````````````````*
* MUL8 :: 8BIT MULTIPLICATION *
*- -*
* MULTIPLIES TWO 8BIT VALUES *
* AND RETURNS A 16BIT RESULT *
* IN Y,X (LOW, HIGH). *
*- -*
* PARAMETERS: *
* *
* ]1 = MULTIPLICAND *
* ]2 = MULTIPLIER *
*- -*
* SAMPLE USAGE: *
* *
* MUL8 #10;#20 *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
MUL8 MAC
LDA ]1
PHA
LDA ]2
PHA
JSR MULT8
<<<
*
*``````````````````````````````*
* DIV8 :: 8BIT MULTIPLICATION *
*- -*
* DIVIDES ONE 8BIT NUMBER BY *
* ANOTHER AND STORES THE *
* QUOTIENT IN A WITH THE *
* REMAINDER IN X. *
*- -*
* PARAMETERS: *
* *
* ]1 = DIVIDEND *
* ]2 = DIVISOR *
*- -*
* SAMPLE USAGE: *
* *
* DIV8 #100;#10 *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
DIV8 MAC
LDA ]1
PHA
LDA ]2
PHA
JSR DIVD8
<<<
*
*``````````````````````````````*
* RND16 :: RANDOM 16-BIT NUM *
*- -*
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
RND16 MAC
JSR RAND16
<<<
*
*``````````````````````````````*
* FPADD :: FLOATING POINT ADD *
*- -*
* ADD TWO FLOATING-POINT NUMS *
* STORED IN GIVEN ADDRESSES *
* AND STORE RESULT IN [RETURN] *
*- -*
* USAGE: FPADD $300;$310 *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
FPADD MAC
LDX #]1
LDY #>]1
JSR MOVFM
*
LDA #]2
LDY #>]2
JSR CONUPK
JSR NORM
LDA $9D
JSR FADDT
*
LDX #RETURN
LDY #>RETURN
JSR MOVMF
*
LDA #6
STA RETLEN
*
<<<