SUBTTL MACRO DEFINITIONS -- ND, XP, EXT, GLOB
;MACRO TO DEFINE A SYMBOL IF NOT ALREADY DEFINED
; ND SYMBOL,VALUE
DEFINE ND(SYMBOL,VALUE),<
IFNDEF SYMBOL,<SYMBOL==VALUE>
>
;MACRO TO SHOW THE VALUE OF AN ABSOLUTE SYMBOL
; SHOW SYMBOL
;WARNING-- DO NOT USE AS LAST LOCATION IN A SEGMENT
DEFINE SHOW.(ARG$),< .XCREF
EXP <ARG$>
.ORG .-1
.CREF>
;MACRO TO DEFINE A SYMBOL IF NOT ALREADY DEFINED AND SHOW ITS VALUE
;WARNING-- DO NOT USE AS LAST LOCATION IN A SEGMENT
DEFINE NDS.(SYMBOL,VALUE),<
IFNDEF SYMBOL,<SYMBOL==VALUE>
SHOW. (SYMBOL)
>

SUBTTL MACRO DEFINITIONS -- LISTING CONTROL
;THIS MACRO IS USED TO FORCE A PAGE OVERFLOW WITH COMMENT
;TO HAVE LISTINGS MATCH THE PROPOSED CODING STANDARD.
;
;IT IS INVOKED WHENEVER A PAGE OVERFLOW WOULD HAVE HAPPENED.
;
;
;ACCORDING TO THE PROPOSED STANDARD, ALL SOURCE FOR A ROUTINE
;MUST OCCUR ON ONE PAGE. HOWEVER, IT IS IMPORTANT FOR THE
;USER TO FIND "SENTENCE" BREAKS TO FORM THE OVERFLOW (EJECT)
;POINTS. WHENEVER OVERFLOW OCCURS, A COMMENT
;TO THAT EFFECT SHOULD APPEAR IN THE LISTING. ALL THIS IS
;ACCOMPLISHED BY THE USER INCLUDING THE MACRO "CONT." IN HIS
;SOURCE AT THE POINT OF THE OVERFLOW. NO BLANKS SHOULD PRECEED
;OR FOLLOW THE MACRO.
DEFINE CONT.<LALL
PAGE ;(CONTINUED ON NEXT PAGE)
SALL ;(CONTINUED FROM PREVIOUS PAGE)
>
;MACROS TO TURN ON AND OFF LISTINGS WHEN NESTING
; LSTOF. TURNS OFF LISTING AND CREF
; LSTOF. X TURNS OFF LISTING
; LSTON. RESTORES LISTING AND CREF IF TOP LEVEL
;IF LSTIN. IS DEFINED AS .MINFI, THEN ALL LISTINGS ON
DEFINE LSTOF.(CREF$),<
IFNDEF LSTIN., LSTIN.==0
IFE LSTIN.,<
IFB <CREF$>, .XCREF
XLIST>
LSTIN.==LSTIN.+1
>
DEFINE LSTON.,<
IFG LSTIN., LSTIN.==LSTIN.-1
IFLE LSTIN.,< .CREF
LIST>
>

SUBTTL MACRO DEFINITIONS -- BYTE MANIPULATION
;MACRO TO COMPUTE THE WIDTH OF A MASK
; "WID" RETURNS THE LENGTH OF THE LEFTMOST STRING OF
; CONSECUTIVE ONES IN THE WORD.
DEFINE WID(MASK),<<^L<-<<MASK>_<^L<MASK>>>-1>>>
;MACRO TO COMPUTE THE POSITION OF A MASK
DEFINE POS(MASK),<<^L<MASK>+^L<-<<MASK>_<^L<MASK>>>-1>-1>>
;MACRO TO BUILD A POINTER TO A MASKED QUANTITY
; POINTR LOCATION,MASK
DEFINE POINTR(LOC,MASK),<<POINT WID(MASK),LOC,POS(MASK)>>
;MACRO TO BUILD A MASK "WID" BITS WIDE, WITH ITS RIGHTMOST BIT
; IN THE BIT POSITION "POS". (I.E. A MASK FOR THE BYTE
; POINTED TO BY THE BYTE POINTER "POINT WID,LOC,POS")
DEFINE MASK.(WID,POS),<<<<1_<WID>>-1>B<POS>>>
;MACRO TO DEFINE A SYMBOL WITH ONLY ONE BIT ON, IN THE SAME POSITION AS
; THE RIGHTMOST BIT IN "MASK" (OR 0, IF "MASK" = 0)
DEFINE RGHBT.(MASK),<<<MASK>&-<MASK>>>
;MACRO TO DEFINE A SYMBOL WITH ONLY ONE BIT ON, IN THE SAME POSITION AS
; THE LEFTMOST BIT IN "MASK" (OR 0, IF "MASK" = 0)
DEFINE LFTBT.(MASK),<<1B<^L<MASK>>>>
; "FILIN." RETURNS A WORD WITH A CONSECUTIVE STRING OF ONES FROM THE
; BIT POSITION OF THE LEFTMOST ONE IN "MASK" THROUGH THE BIT POSITION
; OF THE RIGHTMOST ONE IN "MASK" INCLUSIVE.
DEFINE FILIN.(MASK),<<<MASK>!<<LFTBT.(MASK)>-<RGHBT.(MASK)>>>>
; "ALIGN." RETURNS THE NUMBER OF TRAILING ZEROS IN "MASK"
; (I.E. A VALUE WHICH IS THE RIGHT COUNTERPART OF THE VALUE
; RETURNED BY THE MACRO-10 OPERATOR "^L")
DEFINE ALIGN.(MASK),<<^D35-<^L<RGHBT.(MASK)>>+<^D37*<<^L<RGHBT.(MASK)>>/^D36>>>>
; BTSWP.(AC,BIT-1,BIT-2) SWAPS BITS 1 AND 2 IN AC.
; BIT-1 AND BIT-2 ARE DECIMALS 0-35
DEFINE BTSWP.(AC,BIT1,BIT2),<
REPEAT 3,<
TXCE AC,1B<BIT1>!1B<BIT2>
>>
; "INSVL." POSITIONS VALUE IN MASK
DEFINE INSVL.(VALUE,MASK),<<<<VALUE>B<POS(<MASK>)>>&<MASK>>>

SUBTTL MACRO DEFINITIONS -- INFO/REDEF
;THE FOLLOWING MACROS FACILITATE THE ACCUMULATION OF TEXT BY PERMITTING
;THE USER TO APPEND A LINE OF TEXT TO THE BODY OF TEXT ALREADY
;ACCUMULATED. THE MACROS ARE USED IN THE FOLLOWING WAY:
;1. TO CLEAR THE MECHANISM:
; CINFO.
;2. TO APPEND THE LINE "SAMPLE LINE" (FOLLOWED BY CR-LF) TO THE
;END OF THE TEXT ACCUMULATED SO FAR:
; INFO. REDEF.,"SAMPLE LINE"
;3. TO DEFINE A MACRO "NAME" SO THAT ITS EXPANSION WILL BE THE TEXT
;ACCUMULATED SO FAR, (NOTE-IT ADDS A NULL LINE TO THE END):
; INFO. DEFINE "NAME"
DEFINE CINFO. <
DEFINE INFO.(OPCODE,NEWARG)<
OPCODE NEWARG>>
DEFINE REDEF.(OLDARG)<
DEFINE INFO.(OPCODE,NEWARG)<
OPCODE <OLDARG
NEWARG>>>

SUBTTL FLAG DEFINITIONS
;MACRO FLAG. DEFINES A LIST OF FLAGS AS BEING IN
;A PARTICULAR REGISTER IN SUCH A FASHION THAT
;THE BITS ARE ASSIGNED AT ASSEMBLY TIME AND THE REGISTER AND
;BITS ARE "REMEMBERED" FOR FUTURE USE IN THE TX?? MACROS.
;;THIS WILL BE DEFINED AT SOME FUTURE TIME AND VERSION.

;MACROS TO TEST AND SET/CLEAR/COMPLEMENT FLAGS WHICH ARE NOT
;IN ACCUMULATORS. BE VERY CAREFUL THAT THESE GENERATE TWO
;INSTRUCTIONS, SO CAN NOT BE SKIPPED OVER.
;THEY EACH HAVE TWO ARGUMENTS, THE FIRST IS A SCRATCH AC
; AND THE SECOND IS THE FLAG WHICH WAS DEFINED IN A FLAG. MACRO.
DEFINE TYNE. (AC,FLAG),<
MOVX AC,1B<FLAG_-^D30>
.XCREF
<TDNE AC,>!<37777777&FLAG>
.CREF
>
DEFINE TYNN. (AC,FLAG),<
MOVX AC,1B<FLAG_-^D30>
.XCREF
<TDNN AC,>!<37777777&FLAG>
.CREF
>
DEFINE TYO. (AC,FLAG),<
MOVX AC,1B<FLAG_-^D30>
.XCREF
<IORM AC,>!<37777777&FLAG>
.CREF
>
DEFINE TYZ. (AC,FLAG),<
MOVX AC,1B<FLAG_-^D30>
.XCREF
<ANDCAM AC,>!<37777777&FLAG>
.CREF
>
DEFINE TYC. (AC,FLAG),<
MOVX AC,1B<FLAG_-^D30>
.XCREF
<XORM AC,>!<37777777&FLAG>
.CREF
>

;NOTE - "TXNI.", "TXND.", "JUMPI." & "JUMPD." MAY ASSEMBLE AS ONE OR MORE
; INSTRUCTIONS, DEPENDING ON THE ACTUAL VALUES OF THEIR ARGUMENTS.
; IN ALL CASES WHERE THE MACRO EXPANSION IS MORE THAN ONE INSTRUCTION
; IT WILL BE TRUE THAT IF CONTROL ARRIVES AT THE SECOND INSTRUCTION
; OF THE MACRO EXPANSION, CONTROL WILL UNCONDITIONALLY BE PASSED TO
; THE INSTRUCTION IMMEDIATELY FOLLOWING THE LAST INSTRUCTION OF THE
; MACRO EXPANSION (WITHOUT HAVING ALTERED ANY PART OF THE MACHINE
; STATE OTHER THAN THE PC). THUS A SKIP TYPE INSTRUCTION IMMEDIATELY
; PRECEEDING A "TXNI.", "TXND.", "JUMPI.", OR "JUMPD." MACRO WILL HAVE
; THE EFFECT OF SKIPPING OVER THE ENTIRE MACRO EXPANSION.
;
;
;TEST (BUT DON'T MODIFY) THE FIELD
; (IN "AC") SPECIFIED BY "MASK" AND SKIP IF IT IS IDENTICAL TO "PATERN"
DEFINE TXNI.(AC,MASK,PATERN),<
IFE <<MASK>_<1+^L<MASK>>>,<
IFE <<MASK>&<PATERN>>,<
TXNE AC,<MASK>
>
IFN <<MASK>&<PATERN>>,<
TXNN AC,<MASK>
>>
IFN <<MASK>_<1+^L<MASK>>>,<
TXCA AC,<<PATERN>&<MASK>>
JRST .+4
TXCE AC,<<PATERN>&<MASK>>
JRST .+2
TXNE AC,<<-<PATERN>-1>&<MASK>>
>>
;TEST (BUT DON'T MODIFY) THE FIELD
; (IN "AC") SPECIFIED BY "MASK" AND SKIP IF IT IS DIFFERENT THAN "PATERN"
DEFINE TXND.(AC,MASK,PATERN),<
IFE <<MASK>_<1+^L<MASK>>>,<
IFE <<MASK>&<PATERN>>,<
TXNN AC,<MASK>
>
IFN <<MASK>&<PATERN>>,<
TXNE AC,<MASK>
>>
IFN <<MASK>_<1+^L<MASK>>>,<
TXCA AC,<<PATERN>&<MASK>>
JRST .+4
TXCE AC,<<PATERN>&<MASK>>
JRST .+3
TXNN AC,<<-<PATERN>-1>&<MASK>>
>>