2018-11-07 17:44:04 +00:00
|
|
|
*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*
|
|
|
|
* *
|
|
|
|
* MATH.MAC *
|
|
|
|
* *
|
|
|
|
* AUTHOR: NATHAN RIGGS *
|
|
|
|
* CONTACT: NATHAN.RIGGS@ *
|
|
|
|
* OUTLOOK.COM *
|
|
|
|
* *
|
2018-12-21 21:47:01 +00:00
|
|
|
* VERSION: 0.2.0 *
|
|
|
|
* DATE: 12-DEC-2018 *
|
2018-11-07 17:44:04 +00:00
|
|
|
* ASSEMBLER: MERLIN 8 PRO *
|
2018-12-21 21:47:01 +00:00
|
|
|
* LICENSE: APACHE 2.0 *
|
|
|
|
* OS: DOS 3.3 *
|
2018-11-07 17:44:04 +00:00
|
|
|
* *
|
|
|
|
*------------------------------*
|
|
|
|
* *
|
|
|
|
* THIS IS A MACRO LIBRARY FOR *
|
2018-12-21 21:47:01 +00:00
|
|
|
* MATH8.LIB AND MATH16.LIB *
|
2018-11-07 17:44:04 +00:00
|
|
|
* *
|
|
|
|
*------------------------------*
|
|
|
|
* *
|
|
|
|
* LIST OF MACROS *
|
|
|
|
* *
|
2018-12-21 21:47:01 +00:00
|
|
|
* 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 *
|
2018-11-07 17:44:04 +00:00
|
|
|
* *
|
|
|
|
*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*
|
|
|
|
*
|
|
|
|
*``````````````````````````````*
|
2018-12-21 21:47:01 +00:00
|
|
|
* ADD16 :: 16-BIT ADDITION *
|
2018-11-07 17:44:04 +00:00
|
|
|
*- -*
|
|
|
|
* ADD TWO 16BIT VALUES, STORE *
|
|
|
|
* RESULT IN Y, X (LOW, HIGH) *
|
|
|
|
*- -*
|
|
|
|
* PARAMETERS: *
|
|
|
|
* *
|
2018-12-21 21:47:01 +00:00
|
|
|
* ]1 = ADDEND 1 *
|
|
|
|
* ]2 = ADDEND 2 *
|
|
|
|
* ]3 = INDIRECT MEM FLAG *
|
2018-11-07 17:44:04 +00:00
|
|
|
*- -*
|
|
|
|
* SAMPLE USAGE: *
|
|
|
|
* *
|
2018-12-21 21:47:01 +00:00
|
|
|
* ADD16 #3000;#4000 *
|
2018-11-07 17:44:04 +00:00
|
|
|
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
|
|
|
|
*
|
2018-12-21 21:47:01 +00:00
|
|
|
ADD16 MAC
|
|
|
|
_ISLIT ]1
|
|
|
|
_ISLIT ]2
|
|
|
|
JSR ADDIT16
|
2018-11-07 17:44:04 +00:00
|
|
|
<<<
|
|
|
|
*
|
|
|
|
*``````````````````````````````*
|
2018-12-21 21:47:01 +00:00
|
|
|
* SUB16 :: 16-BIT SUBTRACTION *
|
2018-11-07 17:44:04 +00:00
|
|
|
*- -*
|
|
|
|
* SUBTRACTS ONE 16BIT INTEGER *
|
|
|
|
* FROM ANOTHER, STORING THE *
|
|
|
|
* RESULT IN Y,X (LOW, HIGH) *
|
|
|
|
*- -*
|
|
|
|
* PARAMETERS: *
|
|
|
|
* *
|
2018-12-21 21:47:01 +00:00
|
|
|
* ]1 = MINUEND *
|
|
|
|
* ]2 = SUBTRAHEND *
|
2018-11-07 17:44:04 +00:00
|
|
|
*- -*
|
|
|
|
* SAMPLE USAGE: *
|
|
|
|
* *
|
2018-12-21 21:47:01 +00:00
|
|
|
* SUB16 #2000;#1500 *
|
2018-11-07 17:44:04 +00:00
|
|
|
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
|
|
|
|
*
|
2018-12-21 21:47:01 +00:00
|
|
|
SUB16 MAC
|
|
|
|
_ISLIT ]1
|
|
|
|
_ISLIT ]2
|
|
|
|
JSR SUBT16
|
2018-11-07 17:44:04 +00:00
|
|
|
<<<
|
|
|
|
*
|
|
|
|
*``````````````````````````````*
|
2018-12-21 21:47:01 +00:00
|
|
|
* MUL16 :: 16-BIT MULTIPLY *
|
2018-11-07 17:44:04 +00:00
|
|
|
*- -*
|
|
|
|
* MULTIPLIES TWO 16BIT NUMBERS *
|
|
|
|
* AND RETURNS THE PRODUCT IN *
|
|
|
|
* Y,X (LOW, HIGH). *
|
|
|
|
*- -*
|
|
|
|
* PARAMETERS: *
|
|
|
|
* *
|
2018-12-21 21:47:01 +00:00
|
|
|
* ]1 = MULTIPLICAND *
|
|
|
|
* ]2 = MULTIPLIER *
|
2018-11-07 17:44:04 +00:00
|
|
|
*- -*
|
|
|
|
* SAMPLE USAGE: *
|
|
|
|
* *
|
2018-12-21 21:47:01 +00:00
|
|
|
* MUL16 #400;#500 *
|
2018-11-07 17:44:04 +00:00
|
|
|
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
|
|
|
|
*
|
2018-12-21 21:47:01 +00:00
|
|
|
MUL16 MAC
|
|
|
|
_ISLIT ]1
|
|
|
|
_ISLIT ]2
|
|
|
|
JSR MULT16
|
2018-11-07 17:44:04 +00:00
|
|
|
<<<
|
|
|
|
*
|
|
|
|
*``````````````````````````````*
|
2018-12-21 21:47:01 +00:00
|
|
|
* DIV16 :: 16-BIT DIVISION *
|
2018-11-07 17:44:04 +00:00
|
|
|
*- -*
|
|
|
|
* DIVIDES ONE 16BIT NUMBER BY *
|
|
|
|
* ANOTHER AND RETURNS THE *
|
|
|
|
* RESULT IN Y,X (LOW,HIGH). *
|
|
|
|
* *
|
|
|
|
* IF THE THIRD PARAMETER IS *
|
2018-12-21 21:47:01 +00:00
|
|
|
* PASSED WITH A S, VALUES WILL *
|
|
|
|
* BE TREATED AS SIGNED; IF *
|
2018-11-07 17:44:04 +00:00
|
|
|
* NOT, VALUES WILL BE TREATED *
|
2018-12-21 21:47:01 +00:00
|
|
|
* AS UNSIGNED. *
|
2018-11-07 17:44:04 +00:00
|
|
|
*- -*
|
|
|
|
* PARAMETERS: *
|
|
|
|
* *
|
2018-12-21 21:47:01 +00:00
|
|
|
* ]1 = DIVIDEND *
|
|
|
|
* ]2 = DIVISOR *
|
2018-11-07 17:44:04 +00:00
|
|
|
*- -*
|
|
|
|
* SAMPLE USAGE: *
|
|
|
|
* *
|
2018-12-21 21:47:01 +00:00
|
|
|
* DIV16 #3000;#300 *
|
2018-11-07 17:44:04 +00:00
|
|
|
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
|
|
|
|
*
|
2018-12-21 21:47:01 +00:00
|
|
|
DIV16 MAC
|
|
|
|
_ISLIT ]1
|
|
|
|
_ISLIT ]2
|
|
|
|
IF S,]3 ; SIGNED
|
|
|
|
JSR SDIVD16
|
2018-11-07 17:44:04 +00:00
|
|
|
ELSE
|
2018-12-21 21:47:01 +00:00
|
|
|
JSR UDIVD16 ; UNSIGNED
|
2018-11-07 17:44:04 +00:00
|
|
|
FIN
|
|
|
|
<<<
|
|
|
|
*
|
|
|
|
*``````````````````````````````*
|
2018-12-21 21:47:01 +00:00
|
|
|
* REM16 :: 16-BIT DIV REMAINR *
|
2018-11-07 17:44:04 +00:00
|
|
|
*- -*
|
|
|
|
* DIVIDES ONE INTEGER BY *
|
|
|
|
* ANOTHER AND RETURNS THE *
|
|
|
|
* REMAINDER IN Y,X (LOW, HIGH) *
|
|
|
|
* *
|
|
|
|
* IF THE THIRD PARAMETER IS *
|
2018-12-21 21:47:01 +00:00
|
|
|
* PASSED WITH A S, VALUES WILL *
|
|
|
|
* BE TREATED AS SIGNED; IF *
|
2018-11-07 17:44:04 +00:00
|
|
|
* NOT, VALUES WILL BE TREATED *
|
2018-12-21 21:47:01 +00:00
|
|
|
* AS UNSIGNED. *
|
2018-11-07 17:44:04 +00:00
|
|
|
*- -*
|
|
|
|
* PARAMETERS: *
|
|
|
|
* *
|
2018-12-21 21:47:01 +00:00
|
|
|
* ]1 = DIVIDEND *
|
|
|
|
* ]2 = DIVISOR *
|
2018-11-07 17:44:04 +00:00
|
|
|
*- -*
|
|
|
|
* SAMPLE USAGE: *
|
|
|
|
* *
|
2018-12-21 21:47:01 +00:00
|
|
|
* REM16 #1000;#333 *
|
2018-11-07 17:44:04 +00:00
|
|
|
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
|
|
|
|
*
|
2018-12-21 21:47:01 +00:00
|
|
|
REM16 MAC
|
|
|
|
_ISLIT ]1
|
|
|
|
_ISLIT ]2
|
|
|
|
IF S,]3 ; SIGNED
|
|
|
|
JSR SREMD16
|
2018-11-07 17:44:04 +00:00
|
|
|
ELSE
|
2018-12-21 21:47:01 +00:00
|
|
|
JSR UREMD16 ; UNSIGNED
|
2018-11-07 17:44:04 +00:00
|
|
|
FIN
|
|
|
|
<<<
|
|
|
|
*
|
|
|
|
*``````````````````````````````*
|
2018-12-21 21:47:01 +00:00
|
|
|
* RNDB :: 8BIT RANDOM LOW,HI *
|
2018-11-07 17:44:04 +00:00
|
|
|
*- -*
|
|
|
|
* 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: *
|
|
|
|
* *
|
2018-12-21 21:47:01 +00:00
|
|
|
* ]1 = LOW BOUNDARY *
|
|
|
|
* ]2 = HIGH BOUNDARY *
|
2018-11-07 17:44:04 +00:00
|
|
|
*- -*
|
|
|
|
* SAMPLE USAGE: *
|
|
|
|
* *
|
2018-12-21 21:47:01 +00:00
|
|
|
* RNDB #50;#100 *
|
2018-11-07 17:44:04 +00:00
|
|
|
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
|
|
|
|
*
|
2018-12-21 21:47:01 +00:00
|
|
|
RNDB MAC
|
2018-11-07 17:44:04 +00:00
|
|
|
LDA ]1 ; LOW
|
|
|
|
PHA
|
|
|
|
LDA ]2 ; HIGH
|
|
|
|
PHA
|
|
|
|
JSR RANDB
|
|
|
|
<<<
|
|
|
|
*
|
|
|
|
*``````````````````````````````*
|
2018-12-21 21:47:01 +00:00
|
|
|
* CMP16 : 16BIT COMPARISON *
|
2018-11-07 17:44:04 +00:00
|
|
|
*- -*
|
|
|
|
* COMPARES TWO 16BIT VALUES *
|
|
|
|
* AND ALTERS THE P-REGISTER *
|
|
|
|
* ACCORDINGLY (FLAGS). *
|
|
|
|
*- -*
|
|
|
|
* PARAMETERS: *
|
|
|
|
* *
|
2018-12-21 21:47:01 +00:00
|
|
|
* ]1 = WORD 1 TO COMPARE *
|
|
|
|
* ]2 = WORD 2 TO COMPARE *
|
2018-11-07 17:44:04 +00:00
|
|
|
*- -*
|
|
|
|
* SAMPLE USAGE: *
|
|
|
|
* *
|
2018-12-21 21:47:01 +00:00
|
|
|
* CMP16 #1023;#3021 *
|
2018-11-07 17:44:04 +00:00
|
|
|
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
|
|
|
|
*
|
2018-12-21 21:47:01 +00:00
|
|
|
CMP16 MAC
|
|
|
|
_ISLIT ]1
|
|
|
|
_ISLIT ]2
|
|
|
|
JSR COMP16
|
2018-11-07 17:44:04 +00:00
|
|
|
<<<
|
|
|
|
*
|
|
|
|
*``````````````````````````````*
|
2018-12-21 21:47:01 +00:00
|
|
|
* MUL8 :: 8BIT MULTIPLICATION *
|
2018-11-07 17:44:04 +00:00
|
|
|
*- -*
|
|
|
|
* MULTIPLIES TWO 8BIT VALUES *
|
|
|
|
* AND RETURNS A 16BIT RESULT *
|
|
|
|
* IN Y,X (LOW, HIGH). *
|
|
|
|
*- -*
|
|
|
|
* PARAMETERS: *
|
|
|
|
* *
|
2018-12-21 21:47:01 +00:00
|
|
|
* ]1 = MULTIPLICAND *
|
|
|
|
* ]2 = MULTIPLIER *
|
2018-11-07 17:44:04 +00:00
|
|
|
*- -*
|
|
|
|
* SAMPLE USAGE: *
|
|
|
|
* *
|
2018-12-21 21:47:01 +00:00
|
|
|
* MUL8 #10;#20 *
|
2018-11-07 17:44:04 +00:00
|
|
|
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
|
|
|
|
*
|
2018-12-21 21:47:01 +00:00
|
|
|
MUL8 MAC
|
2018-11-07 17:44:04 +00:00
|
|
|
LDA ]1
|
|
|
|
PHA
|
|
|
|
LDA ]2
|
|
|
|
PHA
|
2018-12-21 21:47:01 +00:00
|
|
|
JSR MULT8
|
2018-11-07 17:44:04 +00:00
|
|
|
<<<
|
|
|
|
*
|
|
|
|
*``````````````````````````````*
|
2018-12-21 21:47:01 +00:00
|
|
|
* DIV8 :: 8BIT MULTIPLICATION *
|
2018-11-07 17:44:04 +00:00
|
|
|
*- -*
|
|
|
|
* DIVIDES ONE 8BIT NUMBER BY *
|
|
|
|
* ANOTHER AND STORES THE *
|
|
|
|
* QUOTIENT IN A WITH THE *
|
|
|
|
* REMAINDER IN X. *
|
|
|
|
*- -*
|
|
|
|
* PARAMETERS: *
|
|
|
|
* *
|
2018-12-21 21:47:01 +00:00
|
|
|
* ]1 = DIVIDEND *
|
|
|
|
* ]2 = DIVISOR *
|
2018-11-07 17:44:04 +00:00
|
|
|
*- -*
|
|
|
|
* SAMPLE USAGE: *
|
|
|
|
* *
|
2018-12-21 21:47:01 +00:00
|
|
|
* DIV8 #100;#10 *
|
2018-11-07 17:44:04 +00:00
|
|
|
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
|
|
|
|
*
|
2018-12-21 21:47:01 +00:00
|
|
|
DIV8 MAC
|
2018-11-07 17:44:04 +00:00
|
|
|
LDA ]1
|
|
|
|
PHA
|
|
|
|
LDA ]2
|
|
|
|
PHA
|
2018-12-21 21:47:01 +00:00
|
|
|
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
|
|
|
|
*
|
2018-11-07 17:44:04 +00:00
|
|
|
<<<
|