home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / enterprs / cpm / utils / a / assy1-1.arc / CPMMAC.LIB < prev    next >
Encoding:
Text File  |  1993-03-31  |  9.0 KB  |  531 lines

  1. ;; Macro library for CP/M system routines
  2. ;;filename: "CPMMAC.LIB"
  3. ;;August 1, 1992
  4. ;;
  5. ;;Macros in this library:
  6. ;;(List each macro name at this point)
  7. ;;NAME                        Flags
  8. ;;
  9. ;;AMBIG        MACRO    OLD, NEW        (none)
  10. ;;COMPAR    MACRO    FIRST, SECOND, BYTES    CMFLAG
  11. ;;COMPRA    MACRO    FIRST, SECOND, BYTES    CMFLAG
  12. ;;CRLF        MACRO
  13. ;;ENTER        MACRO                (none)
  14. ;;EXIT        MACRO    WHERE?,SPACE?        (none)
  15. ;;FILL        MACRO    ADDR, BYTES, CHAR    FLFLAG
  16. ;;MOVE          MACRO    FROM,TO,BYTES        MVFLAG
  17. ;;PCHAR        MOVE    PAR
  18. ;;PRINT        MACRO    TEXT
  19. ;;READCH    MACRO    REG
  20. ;;SBC        MACRO                (none)
  21. ;;SYSF        MACRO    FUNC,AE
  22. ;;UCASE        MACRO    REG            (none)
  23. ;;UPPER        MACRO    REG            (none)
  24. ;;VERSN        MACRO    NUM            (none)
  25. ;
  26. EOF    EQU    1AH        ;end of file
  27. ESC    EQU    1BH        ;escape
  28. CR    EQU    13        ;carriage return
  29. LF    EQU    10         ;line feed
  30. TAB    EQU    9        ;control-I
  31. BLANK    EQU    32        ;space
  32. PERIOD    EQU    46        ;decimal point
  33. COMMA    EQU    44
  34. ;;(place macros here)
  35. ;
  36. AMBIG    MACRO    OLD, NEW
  37. ;;August 16, 1992
  38. ;;inline macro to change ambiguous file name
  39. ;;at FCB NEW to match FCB OLD
  40. ;;
  41. ;;USAGE:AMBIG    FCB1, FCB2
  42. ;;
  43.     PUSH    H
  44.     PUSH    D
  45.     PUSH    B
  46.     LXI    H,NEW+1
  47.     LXI    D,OLD+1
  48.     MVI    C,11        ;number of char
  49. AMB2?:
  50.     MVI    A,'?'
  51.     CMP    M        ;question mark?
  52.     JNZ    AMB3?        ;no
  53. ;
  54. ;copy one char from original to new
  55. ;
  56.     LDAX    D        ;get old char
  57.     MOV    M,A        ;put into new
  58. AMB3?:
  59.     INX    H        ;new
  60.     INX    D        ;orig
  61.     DCR    C        ;count
  62.     JNZ    AMB2?
  63.     POP    B
  64.     POP    D
  65.     POP    H
  66.                 ;;AMBIG
  67.     ENDM
  68. ;
  69. COMPAR    MACRO    FIRST, SECOND, BYTES
  70. ;;August 16, 1992
  71. ;;inline macro to compare 2 memory areas.
  72. ;;Zero flag is set if both are the same,
  73. ;;first and second may be addresses,
  74. ;;third parameter is number of bytes.
  75. ;;First parameter may be a quoted string,
  76. ;;in which case there is no third parameter.
  77. ;;Any of the parameters may be omitted.
  78. ;;Register A is altered.
  79. ;;USAGE:COMPAR    FCB1, FCB2, 12
  80. ;;    COMPAR    '???',FCB1+9
  81. ;;    COMPAR    ,,5
  82. ;;
  83.     LOCAL    MESG, AROUND
  84.     PUSH    H
  85.     PUSH    D
  86.     PUSH    B
  87.     IF    NUL BYTES
  88.     LXI    H,MESG        ;quoted text
  89.     MVI    C,AROUND-MESG    ;length
  90.     ELSE
  91.     IF    NOT NUL FIRST
  92.     LXI    H,FIRST
  93.     ENDIF
  94.     IF    NOT NUL BYTES
  95.     MVI    C,BYTES
  96.     ENDIF
  97.     ENDIF            ;nul bytes
  98.     IF    NOT NUL SECOND
  99.     LXI    D,SECOND
  100.     ENDIF
  101.     CALL    COMP2?
  102.     POP    B
  103.     POP    D
  104.     POP    H
  105.     IF    NOT CMFLAG OR NUL BYTES
  106.     JMP    AROUND
  107.     ENDIF
  108.     IF    NOT CMFLAG    ;one copy
  109. COMP2?:                ;compare routine
  110.     LDAX    D        ;get char
  111.     CMP    M        ;same?
  112.     RNZ            ;no
  113.     INX    H
  114.     INX    D        ;pointers
  115.     DCR    C        ;and count
  116.     JNZ    COMP2?        ;keep going
  117.     RET
  118. CMFLAG    SET    TRUE        ;only one
  119.     ENDIF
  120.     IF    NUL BYTES
  121. MESG:    DB    FIRST        ;;text
  122.     ENDIF
  123. AROUND:                ;;COMPAR
  124.     ENDM
  125. ;
  126. CRLF    MACRO
  127. ;;August 16, 1992
  128. ;;Inline macro to send a
  129. ;;carriage return, line feed to console.
  130. ;;All registers saved including A.
  131. ;; Macro needed: PCHAR
  132. ;;
  133.     LOCAL     AROUND
  134.     CALL    CRLF2?
  135.     IF    NOT CRLF2    ;just one
  136.     JMP    AROUND
  137. CRLF2?:
  138.     PUSH    PSW
  139.     PCHAR    CR
  140.     PCHAR     LF
  141.     POP    PSW
  142.     RET
  143. CRFLA    SET    TRUE        ;only one copy
  144.     ENDIF
  145. AROUND:                ;;CRLF
  146.     ENDM
  147. ;
  148. ENTER        MACRO
  149. ;;August 2, 1992
  150. ;;inline macro to save incoming stack
  151. ;;
  152.     LXI    H,0        ;clear
  153.     DAD    SP        ;add pointer
  154.     SHLD    OLDSTK        ;save
  155.     LXI    SP,STACK
  156.                 ;;ENTER
  157.     ENDM
  158. ;
  159. EXIT        MACRO    WHERE?,SPACE?
  160. ;;
  161. ;;Inline macro to restore the incoming stack
  162. ;;and branch to location WHERE?
  163. ;;If WHERE? is omitted, execute a return instruction.
  164. ;;SPACE? sets the stack space; default is 34.
  165. ;;
  166.     LHLD    OLDSTK
  167.     SPHL
  168.     IF    NUL WHERE?
  169.     RET
  170.     ELSE
  171.     JMP    WHERE?
  172.     ENDIF
  173. ;
  174. OLDSTK:    DS    2        ;incoming stack
  175.     IF    NUL SPACE?
  176.     DS    34
  177.     ELSE
  178.     DS    SPACE?
  179.     ENDIF
  180. STACK:    EQU    $        ;omit EQU $ for Microsoft
  181.                 ;;EXIT
  182.     ENDM
  183. ;
  184. COMPRA    MACRO    FIRST, SECOND, BYTES
  185. ;;August 16, 1992
  186. ;;ASCII version (high bit is zeroed).
  187. ;;inline macro to compare 2 memory areas.
  188. ;;ZERO flag is set if both are same
  189. ;;first and second may be addresses,
  190. ;;third parameter is number of bytes.
  191. ;;First parameter may be a quoted string,
  192. ;;in which case there is no third parameter.
  193. ;;Any of the parameters may be omitted.
  194. ;;Register A is altered.
  195. ;;UASGE:COMPRA    FCB1, FCB2, 11
  196. ;;    COMPRA    'COM',FCB1+9
  197. ;;    COMPRA    ,FCB1+1, 11
  198. ;;
  199.     LOCAL    MESG, AROUND
  200.     PUSH    H
  201.     PUSH    D
  202.     PUSH    B
  203.     IF    NUL BYTES
  204.     LXI    H,MESG        ;quoted text
  205.     MVI    C,AROUND-MESG    ;length
  206.     ELSE
  207.     IF    NOT NUL FIRST
  208.     LXI    H,FIRST
  209.     ENDIF
  210.     IF    NOT NUL C
  211.     MVI    C,BYTES
  212.     ENDIF
  213.     ENDIF            ;nul bytes
  214.     IF    NOT NUL SECOND
  215.     LXI    D,SECOND
  216.     ENDIF
  217.     CALL    COMP2?
  218.     POP    B
  219.     POP    D
  220.     POP    H
  221.     IF    NOT CMFLAG OR NUL BYTES
  222.     JMP    AROUND
  223.     ENDIF
  224.     IF    NOT CMFLAG    ;one copy
  225. COMP2?:                ;compare routine
  226.     LDAX    D        ;get char
  227.     ANI    7FH        ;mask bit 7
  228.     PUSH    B
  229.     MOV    C,A
  230.     MOV    A,M
  231.     ANI    7FH
  232.     CMP    C        ;same?
  233.     POP    B
  234.     RNZ            ;no
  235.     INX    H
  236.     INX    D        ;pointers
  237.     DCR    C        ;and count
  238.     JNZ    COMP2?        ;keep going
  239.     RET
  240. CMFLAG    SET    TRUE        ;only one
  241.     ENDIF
  242.     IF    NUL BYTES
  243. MESG:    DB    FIRST        ;;text
  244.     ENDIF
  245. AROUND:                ;;COMPRA
  246.     ENDM
  247. ;
  248. FILL    MACRO    ADDR, BYTES, CHAR
  249. ;;August 16, 1992
  250. ;;inline macro to fill byte memory
  251. ;;locations with CHAR starting at ADDR
  252. ;;Usage:FILL    FCB+1, BLANK, 8
  253. ;;    FILL    FCB+9, '?', 3
  254. ;;
  255.     LOCAL    AROUND
  256.     PUSH    H
  257.     PUSH    B
  258.     IF    NOT NULL ADDR
  259.     LXI    H,ADDR
  260.     ENDIF
  261.     MVI    C,BYTES
  262.     MVI    A,CHAR
  263.     CALL    FILL2?
  264.     POP    B
  265.     POP    H
  266.     IF    NOT FLFLAG
  267.     JMP    AROUND
  268. FILL2?:
  269.     MOV    M,A        ;put into memory
  270.     INX    H        ;pointer
  271.     DCR    C        ;count
  272.     JNZ    FILL2?        ;keep going
  273.     RET
  274. FLFLAG    SET    TRUE
  275.     ENDIF
  276. AROUND:                ;;FILL
  277.     ENDM
  278. ;
  279. MOVE    MACRO    FROM,TO,BYTES
  280. ;;August 16, 1992 Version 3
  281. ;;inline macro to move text
  282. ;;
  283.     LOCAL    AROUND,MESG
  284.     PUSH    H
  285.     PUSH    D
  286.     PUSH    B
  287.     IF    NOT NULL TO
  288.     LXI    D,TO
  289.     ENDIF
  290.     LXI    NUL BYTES    ;;string move
  291.     LXI    H,MESG        ;;test
  292.     LXI    B,AROUND-MESG
  293.     ELSE
  294.     IF    NOT NULL FROM
  295.     LXI    H, FROM
  296.     ENDIF
  297.     LXI    B, BYTES
  298.     ENDIF            ;;string/not string
  299.     CALL    MOVE2?
  300.     POP    B
  301.     POP    D
  302.     POP    H
  303.     IF    NOT MVFLAG OR NUL BYTES
  304.     JMP    AROUND
  305.     ENDIF
  306. ;
  307.     IF    NOT MVFLAG
  308. MOVE2?:
  309.     MOV    A,M        ;get byte
  310.     STAX    D        ;new place
  311.     INX    H        ;from
  312.     INX    D        ;to
  313.     DCX    B        ;byte count
  314.     MOV    A,C
  315.     ORA    B
  316.     JNZ    MOVE2?        ;not done
  317.     RET
  318. ;
  319. MVFLAG    SET    TRUE        ;;one copy
  320.     ENDIF            ;;not MVFLAG
  321.     IF    NUL BYTES
  322. MESG:
  323.     DB    FROM        ;;text
  324.     ENDIF
  325. AROUND:                ;;MOVE
  326.     ENDM
  327. ;
  328. PCHAR    MACRO    PAR
  329. ;;August 16, 1992
  330. ;;Inline macro to print one console char.
  331. ;;Parameter, if present, is loaded into A.
  332. ;;Macro needed: SYSF
  333. ;;
  334. ;;Usage:PCHAR
  335. ;;    PCHAR    '*'
  336. ;;
  337.     LOCAL    AROUND
  338.     IF     NOT NUL PAR
  339.     MVI    A,PAR
  340.     ENDIF
  341.     CALL    PCH2?
  342.     IF    NOT COFLAG
  343.     JMP    AROUND
  344. PCH2?    SYSF        ,AE
  345. COFLAG    SET    TRUE        ;only one copy
  346.     ENDIF
  347. AROUND:                ;;PCHAR
  348.     ENDM
  349. ;
  350. ;PRINT    MACRO    TEXT
  351. ;;August 23, 1992
  352. ;;inline macro to print string on console.
  353. ;;TEXT is address of string, BYTES in length.
  354. ;;TEXT may be in quotes if BYTES is omitted.
  355. ;;Macro needed:  PCHAR
  356. ;;
  357. ;;Usage:PRINT    FCB1+1,11
  358. ;;    PRINT    'end of file'
  359. ;;    PRINT    <CR,LF,'message'>
  360. ;;    PRINT    ,12
  361. ;;
  362.     LOCAL    AROUND,MESG
  363.     PUSH    H
  364.     PUSH    B
  365.     IF    NUL BYTES
  366.     LXI    H,MESG
  367.     MVI    B,AROUND-MESG
  368.     ELSE
  369.     IF    NOT NUL TEXT
  370.     LXI    H,TEXT
  371.     ENDIF
  372.     MVI    B,BYTES
  373.     ENDIF
  374.     CALL    PBUF?
  375.     POP    B
  376.     POP    H
  377.     IF    NOT PRFLAG OR NUL BYTES
  378.     JMP    AROUND
  379.     ENDIF
  380.     IF    NOT PRFLAG
  381. PBUF?    MOV    A,M
  382.     PCHAR
  383.     INX    H
  384.     DCR    B
  385.     JNZ    PBUF?
  386.     RET
  387. PRFLAG    SET    TRUE
  388.     ENDIF
  389.     IF    NUL BYTES
  390. MESG:    DB    TEXT
  391.     ENDIF            ;;PRINT
  392. AROUND:
  393.     ENDM
  394. ;
  395. SBC    MACRO
  396. ;;August 16, 1992
  397. ;;Inline macro to subtract DE from HL
  398. ;;The result is in HL.  This is almost
  399. ;;the Z80 SBC HL,DE opcode.
  400. ;;
  401. ;;Usage:SBC
  402.     SBC    HL,DE
  403. ;;
  404.     MOV    A,L
  405.     SUB    E
  406.     MOV    L,A
  407.     MOV    A,H
  408.     SBB    D
  409.     MOV    H,A
  410.                 ;;SBC
  411.     ENDM
  412. ;
  413. SYSF    MACRO    FUNC,AE
  414. ;;August 16, 1992
  415. ;;Macro to generate BDOS calls.
  416. ;;FUNC is BDOS function number for C.
  417. ;;THIS IS NOT AN INLINE MACRO.
  418. ;;Move A to E if there is a second parameter.
  419. ;;
  420. ;;Usage:OPEN:    SYSF    15
  421. ;;    PUCHAR:    SYSF    2,AE
  422. ;;
  423.     PUSH    H
  424.     PUSH    D
  425.     PUSH    B
  426.     MVI    C,FUNC
  427.     IF    NOT NUL AE
  428.     MOV    A,E        ;console and list
  429.     PUSH    PSW        ;save A
  430.     CALL    BDOS
  431.     POP    PSW
  432.     ELSE
  433.     CALL BDOS
  434.     ENDIF
  435.     POP    B
  436.     POP    D
  437.     POP    H
  438.     RET
  439.                 ;;SYSF
  440.     ENDM
  441. ;
  442.  
  443. READCH    MSCRO    REG
  444. ;;August 16, 1992
  445. ;;Inline macro to read one character from
  446. ;;the console; character is returned in register
  447. ;;A unless a second parameter is given
  448. ;;Macro needed: SYSF
  449. ;;
  450. ;;Usage:READCH
  451. ;;    READCH    C
  452. ;;
  453.     LOCAL AROUND
  454.     CALL    RDCH?
  455.     IF    NOT NUL REG
  456.     MOV    REG,A
  457.     ENDIF
  458.     IF    NOT CIFLAG
  459.     JMP    AROUND
  460. RDCH?:    SYSF    1
  461. CIFLAG    SET    TRUE        ;only one copy
  462.     ENDIF
  463. AROUND:                ;;READCH
  464.     ENDM
  465. ;
  466. ;UCASE        MACRO    REG
  467. ;;August 16, 1992
  468. ;;inline macro to convert a character in any
  469. register to uppercase.
  470. ;;Omit parameter for register A.
  471. ;;
  472. ;;USAGE:UCASE
  473. ;;    UCASE    C
  474. ;;
  475.     LOCAL    NOTUP?
  476.     IF    NOT NUL REG
  477.     PUSH    PSW        ;save
  478.     MOV    A,REG        ;get value
  479.     ENDIF
  480.     CPI    'Z'+7        ;uppercase?
  481.     JC    NOTUP?        ;no
  482.     ANI    5FH        ;make uppercase
  483. NOTUP?:
  484.     IF    NOT NUL REG
  485.     MOV    REG,A        ;put back
  486.     POP    PSW        ;restore
  487.     ENDIF
  488.                 ;;UCASE
  489.     ENDM
  490. ;
  491. UPPER    MACRO    REG
  492. ;;August 16, 1992
  493. ;;Macro to move the upper 4 bits of the
  494. ;;accumulator to the lower 4 bits. The
  495. ;;new upper 4 bits are zeroed.
  496. ;;Use this macro to isolate the left
  497. ;;character of packed BCD numbers.
  498. ;;
  499. ;;Usage:UPPER            ;rotate down
  500. ;;    OUTHEX            ;print
  501. ;;
  502.     IF    NOT NUL REG
  503.     PUSH     PSW        ;save A
  504. MOV    A,REG            ;move to A
  505.     ENDIF
  506.     RAR            ;move to
  507.     RAR            ;lower half
  508.     RAR
  509.     RAR
  510.     ANI    0FH        ;mask upper
  511.     IF    NOT NUL REG
  512.     MOV    REG,A        ;put back
  513.     POP    PSW        ;restore A
  514.     ENDIF
  515.                 ;;UPPER
  516.     ENDM
  517. ;
  518. VERSN        MACRO    NUM
  519. ;;August 1, 1992
  520. ;;inline macro to embed verson number.
  521. ;;NUM is enclosed in quotes.
  522. ;;
  523. ;;Usage:    VERSN    'XX.XX.XX.NAME'
  524. ;;
  525.     LOCAL    AROUND
  526.     JMP    AROUND
  527.     DB    'Ver',NUM
  528. AROUND:                ;;VERSN
  529.     ENDM
  530. ;
  531.