home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / asm / PROC.ZIP / PROC.MAC < prev   
Encoding:
Text File  |  1988-10-31  |  4.6 KB  |  219 lines

  1.     .XLIST
  2.  
  3.     PAGE    ,132
  4.  
  5. FALSE    EQU    0
  6. TRUE    EQU    NOT FALSE
  7. NUL    EQU    0
  8. BS    EQU    8
  9. HT    EQU    9
  10. TAB    EQU    HT
  11. LF    EQU    10
  12. FF    EQU    12
  13. CR    EQU    13
  14. EOF    EQU    26
  15. ESC    EQU    27
  16. DEL    EQU    127
  17.  
  18. @WRD@@    STRUC
  19. LB    DB    ?;        x.LB = BYTE PTR x
  20. HB    DB    ?;        x.HB = BYTE PTR x + 1
  21. @WRD@@    ENDS
  22. B    EQU    LB;        x.B = BYTE PTR x
  23.  
  24. @DWD@@    STRUC
  25. LW    DW    ?;        x.LW = WORD PTR x
  26. HW    DW    ?;        x.HW = WORD PTR x + 2
  27. @DWD@@    ENDS
  28. W    EQU    LW;        x.W = WORD PTR x
  29.  
  30. @DDW@@    STRUC
  31. D    DD    ?;        x.D = DWORD PTR x
  32. @DDW@@    ENDS
  33.  
  34.  
  35. @RST@@    MACRO;;        initialize procedure & parameter controls
  36. @PAR@@    =    0;;        where next parameter is    in frame
  37. @FPA@@    =    0;;        where first parameter is in frame
  38. @LAS@@    =    0;;        controls partial parameter cleanup
  39. @VAR@@    =    0;;        where latest variable is in frame
  40. @INT@@    =    FALSE;;        define interrupt procedure flag
  41. @SAV@@    =    FALSE;;        define existence of local frame
  42.     ENDM
  43.  
  44.  
  45. $PASCAL    MACRO;;        discard parameters upon $RET
  46. @PAS@@    =    TRUE
  47.     ENDM
  48.  
  49.  
  50. $C    MACRO;;        leave parameters upon $RET
  51. @PAS@@    =    FALSE
  52.     ENDM
  53.  
  54.  
  55. ;  begin procedure, define parameter addresses
  56. $PROC    MACRO    P1, P2,    P3, P4,    P5, P6,    P7, P8,    P9, P10
  57. PUBLIC P1
  58. IFIDN <P2>, <FAR>
  59.     @FPA@@ = 6;;    first parameter after saved caller's frame
  60. ELSE;;               and far return address
  61.     @FPA@@ = 4;;    first parameter after saved caller's frame
  62. ENDIF;;               and near return address
  63. @PAR@@ = @FPA@@;;    next parm address = first parm address
  64. P1    PROC    P2;;    begin procedure
  65. IFNB <P3>;;        if parms in proc def then execute $PARM
  66.     $PARM P3 P4 P5 P6 P7 P8 P9 P10
  67. ENDIF
  68.     ENDM
  69.  
  70.  
  71. ;  begin interrupt procedure, define flags option
  72. $IPROC    MACRO    P1, FLAGS
  73. @INT@@ = TRUE;;        flag interrupt procedure
  74. @FPA@@ = 6
  75. P1    PROC    FAR
  76. IFNB <FLAGS>;;        if flags parm not blank then define it
  77.     @PAR@@ = 6
  78.     $PARM FLAGS 2
  79. ELSE;;            else set @PAR@@ as if defined
  80.     @PAR@@ = 8
  81. ENDIF
  82.     ENDM
  83.  
  84.  
  85. $PARM    MACRO    P1, P2,    P3, P4,    P5, P6,    P7, P8,    P9, P10
  86.     LOCAL    PARM
  87. IFIDN <P1>, <$LAST>;;        if keyword $LAST then
  88.     IF @PAS@@;;            if pascal call then
  89.     @LAS@@ = @PAR@@;;       define partial stack cleanup
  90.     ENDIF
  91.     IFNB <P2>;;            if more then execute $PARM
  92.     $PARM P2 P3 P4 P5 P6 P7 P8 P9
  93.     ENDIF
  94. ELSE;;                else define parameter address
  95.     PARM = @PAR@@
  96.     P1 EQU [BP + PARM]
  97.     .XCREF PARM, P1
  98.     @PAR@@ = @PAR@@ + P2;;    address of next parameter
  99.     IFNB <P3>;;            if more then execute $PARM
  100.     $PARM P3 P4 P5 P6 P7 P8 P9 P10
  101.     ENDIF
  102. ENDIF
  103.     ENDM
  104.  
  105.  
  106. $VAR    MACRO    V1, V2,    V3, V4,    V5, V6,    V7, V8,    V9, V10
  107.     LOCAL    VAR
  108. @VAR@@ = @VAR@@ - V2;;        subtract length of current variable
  109. VAR = @VAR@@;;            create new symbol = to current @VAR@@
  110. V1 EQU [BP + VAR];;        frame offset for variable
  111.     .XCREF    VAR, V1
  112. IFNB <V3>;;            then another variable exists
  113.     $VAR V3 V4 V5 V6 V7 V8 V9 V10;;  recursive call
  114. ENDIF
  115.     ENDM
  116.  
  117.  
  118. @SUB@@    MACRO    P1;;        cosmetic macro lists value
  119.     SUB    SP, P1;;       of P1 in .LST file
  120.     ENDM
  121.  
  122.  
  123. $SAVE    MACRO
  124.     @SAV@@ = TRUE
  125.     PUSH    BP;;        save caller's frame pointer
  126.     MOV    BP, SP;;    set up new frame pointer
  127.   IF @VAR@@;;        if local variable(s) exist
  128.     IF @VAR@@ EQ -1 OR @VAR@@ EQ -2;; if 1 or 2 bytes
  129.     DEC    SP
  130.       IF @VAR@@ EQ -2;; if 2 bytes
  131.     DEC    SP
  132.       ENDIF
  133.     ELSE
  134.     @SUB@@ %-@VAR@@;;    make room on stack for
  135.     ENDIF;;               local variable(s)
  136.   ENDIF
  137.     ENDM
  138.  
  139.  
  140. @RET@@    MACRO    P1;;        cosmetic macro lists value
  141.     RET    P1;;           of P1 in .LST file
  142.     ENDM
  143.  
  144.  
  145. @RFR@@    MACRO;;        restore frame if necessary
  146. IF @SAV@@;;        if local frame exists
  147.     IF @VAR@@;;        if local variable(s) exist then
  148.     MOV    SP, BP;;   restore stack pointer
  149.     ENDIF
  150.     POP    BP;;    restore caller's frame pointer
  151. ENDIF
  152.     ENDM
  153.  
  154.  
  155. $RET    MACRO    R1;;    return selected by @INT@@
  156. IF @INT@@
  157.     $IRET R1
  158. ELSE
  159.     $PRET R1
  160. ENDIF
  161.     ENDM
  162.  
  163.  
  164. $PRET    MACRO    R1;;    return from procedure call
  165.     @RFR@@
  166.     IF @LAS@@
  167.     @PAR@@ = @LAS@@;;  set @PAR@@ for partial cleanup
  168.     ENDIF
  169.     IF @PAS@@ AND @PAR@@ NE @FPA@@
  170.     @RET@@ %@PAR@@ - @FPA@@;;  RET  n
  171.     ELSE
  172.     RET
  173.     ENDIF
  174.     IFNB <R1>;;        if R1 not empty then end procedure
  175.     $TERM R1
  176.     ENDIF
  177.     ENDM
  178.  
  179.  
  180. $IRET    MACRO    R1;;    return from interrupt
  181.     @RFR@@
  182.     IRET
  183.     IFNB <R1>;;    if R1 not empty then end procedure
  184.         $TERM R1
  185.     ENDIF
  186.     ENDM
  187.  
  188.  
  189. $RETURN    MACRO    R1;;    same as $RET
  190.     $RET    R1
  191.     ENDM
  192.  
  193.  
  194. $TERM    MACRO    R1;;    end procedure
  195. R1    ENDP
  196.     @RST@@;;    reset macro variables
  197.     ENDM
  198.  
  199.  
  200. $LIST    MACRO;;        does not print .LIST
  201.     .LIST
  202.     ENDM
  203.  
  204.  
  205.     @PAS@@ = TRUE;        define pascal calling flag
  206.  
  207.     .XCREF    FALSE, TRUE, BS, HT, TAB, LF, FF, CR
  208.     .XCREF    EOF, ESC, @WRD@@, LB, HB, B, @DWD@@
  209.     .XCREF    LW, HW, W, @DDW@@, D, @RST@@, @PAR@@
  210.     .XCREF    @FPA@@, @LAS@@, @VAR@@, @INT@@
  211.     .XCREF    $PASCAL, @PAS@@, $C, $PROC
  212.     .XCREF    $IPROC, $PARM, $VAR, @SUB@@, $SAVE
  213.     .XCREF    @RET@@, @RFR@@, $RET, $PRET, $IRET
  214.     .XCREF    $RETURN, $TERM, $LIST, NUL, DEL
  215.  
  216.     @RST@@;        set up defaults for first procedure
  217.  
  218.     $LIST
  219.