home *** CD-ROM | disk | FTP | other *** search
- ;; Macro library for CP/M system routines
- ;;filename: "CPMMAC.LIB"
- ;;August 1, 1992
- ;;
- ;;Macros in this library:
- ;;(List each macro name at this point)
- ;;NAME Flags
- ;;
- ;;AMBIG MACRO OLD, NEW (none)
- ;;COMPAR MACRO FIRST, SECOND, BYTES CMFLAG
- ;;COMPRA MACRO FIRST, SECOND, BYTES CMFLAG
- ;;CRLF MACRO
- ;;ENTER MACRO (none)
- ;;EXIT MACRO WHERE?,SPACE? (none)
- ;;FILL MACRO ADDR, BYTES, CHAR FLFLAG
- ;;MOVE MACRO FROM,TO,BYTES MVFLAG
- ;;PCHAR MOVE PAR
- ;;PRINT MACRO TEXT
- ;;READCH MACRO REG
- ;;SBC MACRO (none)
- ;;SYSF MACRO FUNC,AE
- ;;UCASE MACRO REG (none)
- ;;UPPER MACRO REG (none)
- ;;VERSN MACRO NUM (none)
- ;
- EOF EQU 1AH ;end of file
- ESC EQU 1BH ;escape
- CR EQU 13 ;carriage return
- LF EQU 10 ;line feed
- TAB EQU 9 ;control-I
- BLANK EQU 32 ;space
- PERIOD EQU 46 ;decimal point
- COMMA EQU 44
- ;;(place macros here)
- ;
- AMBIG MACRO OLD, NEW
- ;;August 16, 1992
- ;;inline macro to change ambiguous file name
- ;;at FCB NEW to match FCB OLD
- ;;
- ;;USAGE:AMBIG FCB1, FCB2
- ;;
- PUSH H
- PUSH D
- PUSH B
- LXI H,NEW+1
- LXI D,OLD+1
- MVI C,11 ;number of char
- AMB2?:
- MVI A,'?'
- CMP M ;question mark?
- JNZ AMB3? ;no
- ;
- ;copy one char from original to new
- ;
- LDAX D ;get old char
- MOV M,A ;put into new
- AMB3?:
- INX H ;new
- INX D ;orig
- DCR C ;count
- JNZ AMB2?
- POP B
- POP D
- POP H
- ;;AMBIG
- ENDM
- ;
- COMPAR MACRO FIRST, SECOND, BYTES
- ;;August 16, 1992
- ;;inline macro to compare 2 memory areas.
- ;;Zero flag is set if both are the same,
- ;;first and second may be addresses,
- ;;third parameter is number of bytes.
- ;;First parameter may be a quoted string,
- ;;in which case there is no third parameter.
- ;;Any of the parameters may be omitted.
- ;;Register A is altered.
- ;;USAGE:COMPAR FCB1, FCB2, 12
- ;; COMPAR '???',FCB1+9
- ;; COMPAR ,,5
- ;;
- LOCAL MESG, AROUND
- PUSH H
- PUSH D
- PUSH B
- IF NUL BYTES
- LXI H,MESG ;quoted text
- MVI C,AROUND-MESG ;length
- ELSE
- IF NOT NUL FIRST
- LXI H,FIRST
- ENDIF
- IF NOT NUL BYTES
- MVI C,BYTES
- ENDIF
- ENDIF ;nul bytes
- IF NOT NUL SECOND
- LXI D,SECOND
- ENDIF
- CALL COMP2?
- POP B
- POP D
- POP H
- IF NOT CMFLAG OR NUL BYTES
- JMP AROUND
- ENDIF
- IF NOT CMFLAG ;one copy
- COMP2?: ;compare routine
- LDAX D ;get char
- CMP M ;same?
- RNZ ;no
- INX H
- INX D ;pointers
- DCR C ;and count
- JNZ COMP2? ;keep going
- RET
- CMFLAG SET TRUE ;only one
- ENDIF
- IF NUL BYTES
- MESG: DB FIRST ;;text
- ENDIF
- AROUND: ;;COMPAR
- ENDM
- ;
- CRLF MACRO
- ;;August 16, 1992
- ;;Inline macro to send a
- ;;carriage return, line feed to console.
- ;;All registers saved including A.
- ;; Macro needed: PCHAR
- ;;
- LOCAL AROUND
- CALL CRLF2?
- IF NOT CRLF2 ;just one
- JMP AROUND
- CRLF2?:
- PUSH PSW
- PCHAR CR
- PCHAR LF
- POP PSW
- RET
- CRFLA SET TRUE ;only one copy
- ENDIF
- AROUND: ;;CRLF
- ENDM
- ;
- ENTER MACRO
- ;;August 2, 1992
- ;;inline macro to save incoming stack
- ;;
- LXI H,0 ;clear
- DAD SP ;add pointer
- SHLD OLDSTK ;save
- LXI SP,STACK
- ;;ENTER
- ENDM
- ;
- EXIT MACRO WHERE?,SPACE?
- ;;
- ;;Inline macro to restore the incoming stack
- ;;and branch to location WHERE?
- ;;If WHERE? is omitted, execute a return instruction.
- ;;SPACE? sets the stack space; default is 34.
- ;;
- LHLD OLDSTK
- SPHL
- IF NUL WHERE?
- RET
- ELSE
- JMP WHERE?
- ENDIF
- ;
- OLDSTK: DS 2 ;incoming stack
- IF NUL SPACE?
- DS 34
- ELSE
- DS SPACE?
- ENDIF
- STACK: EQU $ ;omit EQU $ for Microsoft
- ;;EXIT
- ENDM
- ;
- COMPRA MACRO FIRST, SECOND, BYTES
- ;;August 16, 1992
- ;;ASCII version (high bit is zeroed).
- ;;inline macro to compare 2 memory areas.
- ;;ZERO flag is set if both are same
- ;;first and second may be addresses,
- ;;third parameter is number of bytes.
- ;;First parameter may be a quoted string,
- ;;in which case there is no third parameter.
- ;;Any of the parameters may be omitted.
- ;;Register A is altered.
- ;;UASGE:COMPRA FCB1, FCB2, 11
- ;; COMPRA 'COM',FCB1+9
- ;; COMPRA ,FCB1+1, 11
- ;;
- LOCAL MESG, AROUND
- PUSH H
- PUSH D
- PUSH B
- IF NUL BYTES
- LXI H,MESG ;quoted text
- MVI C,AROUND-MESG ;length
- ELSE
- IF NOT NUL FIRST
- LXI H,FIRST
- ENDIF
- IF NOT NUL C
- MVI C,BYTES
- ENDIF
- ENDIF ;nul bytes
- IF NOT NUL SECOND
- LXI D,SECOND
- ENDIF
- CALL COMP2?
- POP B
- POP D
- POP H
- IF NOT CMFLAG OR NUL BYTES
- JMP AROUND
- ENDIF
- IF NOT CMFLAG ;one copy
- COMP2?: ;compare routine
- LDAX D ;get char
- ANI 7FH ;mask bit 7
- PUSH B
- MOV C,A
- MOV A,M
- ANI 7FH
- CMP C ;same?
- POP B
- RNZ ;no
- INX H
- INX D ;pointers
- DCR C ;and count
- JNZ COMP2? ;keep going
- RET
- CMFLAG SET TRUE ;only one
- ENDIF
- IF NUL BYTES
- MESG: DB FIRST ;;text
- ENDIF
- AROUND: ;;COMPRA
- ENDM
- ;
- FILL MACRO ADDR, BYTES, CHAR
- ;;August 16, 1992
- ;;inline macro to fill byte memory
- ;;locations with CHAR starting at ADDR
- ;;Usage:FILL FCB+1, BLANK, 8
- ;; FILL FCB+9, '?', 3
- ;;
- LOCAL AROUND
- PUSH H
- PUSH B
- IF NOT NULL ADDR
- LXI H,ADDR
- ENDIF
- MVI C,BYTES
- MVI A,CHAR
- CALL FILL2?
- POP B
- POP H
- IF NOT FLFLAG
- JMP AROUND
- FILL2?:
- MOV M,A ;put into memory
- INX H ;pointer
- DCR C ;count
- JNZ FILL2? ;keep going
- RET
- FLFLAG SET TRUE
- ENDIF
- AROUND: ;;FILL
- ENDM
- ;
- MOVE MACRO FROM,TO,BYTES
- ;;August 16, 1992 Version 3
- ;;inline macro to move text
- ;;
- LOCAL AROUND,MESG
- PUSH H
- PUSH D
- PUSH B
- IF NOT NULL TO
- LXI D,TO
- ENDIF
- LXI NUL BYTES ;;string move
- LXI H,MESG ;;test
- LXI B,AROUND-MESG
- ELSE
- IF NOT NULL FROM
- LXI H, FROM
- ENDIF
- LXI B, BYTES
- ENDIF ;;string/not string
- CALL MOVE2?
- POP B
- POP D
- POP H
- IF NOT MVFLAG OR NUL BYTES
- JMP AROUND
- ENDIF
- ;
- IF NOT MVFLAG
- MOVE2?:
- MOV A,M ;get byte
- STAX D ;new place
- INX H ;from
- INX D ;to
- DCX B ;byte count
- MOV A,C
- ORA B
- JNZ MOVE2? ;not done
- RET
- ;
- MVFLAG SET TRUE ;;one copy
- ENDIF ;;not MVFLAG
- IF NUL BYTES
- MESG:
- DB FROM ;;text
- ENDIF
- AROUND: ;;MOVE
- ENDM
- ;
- PCHAR MACRO PAR
- ;;August 16, 1992
- ;;Inline macro to print one console char.
- ;;Parameter, if present, is loaded into A.
- ;;Macro needed: SYSF
- ;;
- ;;Usage:PCHAR
- ;; PCHAR '*'
- ;;
- LOCAL AROUND
- IF NOT NUL PAR
- MVI A,PAR
- ENDIF
- CALL PCH2?
- IF NOT COFLAG
- JMP AROUND
- PCH2? SYSF ,AE
- COFLAG SET TRUE ;only one copy
- ENDIF
- AROUND: ;;PCHAR
- ENDM
- ;
- ;PRINT MACRO TEXT
- ;;August 23, 1992
- ;;inline macro to print string on console.
- ;;TEXT is address of string, BYTES in length.
- ;;TEXT may be in quotes if BYTES is omitted.
- ;;Macro needed: PCHAR
- ;;
- ;;Usage:PRINT FCB1+1,11
- ;; PRINT 'end of file'
- ;; PRINT <CR,LF,'message'>
- ;; PRINT ,12
- ;;
- LOCAL AROUND,MESG
- PUSH H
- PUSH B
- IF NUL BYTES
- LXI H,MESG
- MVI B,AROUND-MESG
- ELSE
- IF NOT NUL TEXT
- LXI H,TEXT
- ENDIF
- MVI B,BYTES
- ENDIF
- CALL PBUF?
- POP B
- POP H
- IF NOT PRFLAG OR NUL BYTES
- JMP AROUND
- ENDIF
- IF NOT PRFLAG
- PBUF? MOV A,M
- PCHAR
- INX H
- DCR B
- JNZ PBUF?
- RET
- PRFLAG SET TRUE
- ENDIF
- IF NUL BYTES
- MESG: DB TEXT
- ENDIF ;;PRINT
- AROUND:
- ENDM
- ;
- SBC MACRO
- ;;August 16, 1992
- ;;Inline macro to subtract DE from HL
- ;;The result is in HL. This is almost
- ;;the Z80 SBC HL,DE opcode.
- ;;
- ;;Usage:SBC
- SBC HL,DE
- ;;
- MOV A,L
- SUB E
- MOV L,A
- MOV A,H
- SBB D
- MOV H,A
- ;;SBC
- ENDM
- ;
- SYSF MACRO FUNC,AE
- ;;August 16, 1992
- ;;Macro to generate BDOS calls.
- ;;FUNC is BDOS function number for C.
- ;;THIS IS NOT AN INLINE MACRO.
- ;;Move A to E if there is a second parameter.
- ;;
- ;;Usage:OPEN: SYSF 15
- ;; PUCHAR: SYSF 2,AE
- ;;
- PUSH H
- PUSH D
- PUSH B
- MVI C,FUNC
- IF NOT NUL AE
- MOV A,E ;console and list
- PUSH PSW ;save A
- CALL BDOS
- POP PSW
- ELSE
- CALL BDOS
- ENDIF
- POP B
- POP D
- POP H
- RET
- ;;SYSF
- ENDM
- ;
-
- READCH MSCRO REG
- ;;August 16, 1992
- ;;Inline macro to read one character from
- ;;the console; character is returned in register
- ;;A unless a second parameter is given
- ;;Macro needed: SYSF
- ;;
- ;;Usage:READCH
- ;; READCH C
- ;;
- LOCAL AROUND
- CALL RDCH?
- IF NOT NUL REG
- MOV REG,A
- ENDIF
- IF NOT CIFLAG
- JMP AROUND
- RDCH?: SYSF 1
- CIFLAG SET TRUE ;only one copy
- ENDIF
- AROUND: ;;READCH
- ENDM
- ;
- ;UCASE MACRO REG
- ;;August 16, 1992
- ;;inline macro to convert a character in any
- register to uppercase.
- ;;Omit parameter for register A.
- ;;
- ;;USAGE:UCASE
- ;; UCASE C
- ;;
- LOCAL NOTUP?
- IF NOT NUL REG
- PUSH PSW ;save
- MOV A,REG ;get value
- ENDIF
- CPI 'Z'+7 ;uppercase?
- JC NOTUP? ;no
- ANI 5FH ;make uppercase
- NOTUP?:
- IF NOT NUL REG
- MOV REG,A ;put back
- POP PSW ;restore
- ENDIF
- ;;UCASE
- ENDM
- ;
- UPPER MACRO REG
- ;;August 16, 1992
- ;;Macro to move the upper 4 bits of the
- ;;accumulator to the lower 4 bits. The
- ;;new upper 4 bits are zeroed.
- ;;Use this macro to isolate the left
- ;;character of packed BCD numbers.
- ;;
- ;;Usage:UPPER ;rotate down
- ;; OUTHEX ;print
- ;;
- IF NOT NUL REG
- PUSH PSW ;save A
- MOV A,REG ;move to A
- ENDIF
- RAR ;move to
- RAR ;lower half
- RAR
- RAR
- ANI 0FH ;mask upper
- IF NOT NUL REG
- MOV REG,A ;put back
- POP PSW ;restore A
- ENDIF
- ;;UPPER
- ENDM
- ;
- VERSN MACRO NUM
- ;;August 1, 1992
- ;;inline macro to embed verson number.
- ;;NUM is enclosed in quotes.
- ;;
- ;;Usage: VERSN 'XX.XX.XX.NAME'
- ;;
- LOCAL AROUND
- JMP AROUND
- DB 'Ver',NUM
- AROUND: ;;VERSN
- ENDM
- ;