home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 1: Collection A / 17Bit_Collection_A.iso / files / 73.dms / 73.adf / include / common / asmmac.i < prev   
Text File  |  2008-06-02  |  4KB  |  220 lines

  1. ;    asm(1.0) macro package - Various macros that may be
  2. ;    found useful.
  3. ;
  4. ;    This macro package has been written and placed in the
  5. ;    public domain by Douglas J Leavitt, 1986.  Feel free
  6. ;    to use this package in anyway whatsoever, hopefully
  7. ;    making millions of dollars in the process.
  8. ;
  9. ;    Global Macro Variables start with ___
  10. ;    ___argchk is a local temp variable used by various macros
  11. ;    To pass extra params to the ARGCHK macro
  12. ;
  13.  
  14. ;    ARGCHK    min_args,max_args,nargs
  15. ;
  16. ;    Check a macro invocation for the proper number of arguments
  17.  
  18.     ifnd    ASM_COMMON
  19.     ASM_COMMON = 1
  20. ARGCHK    macro
  21.     ifne    narg-2
  22.         ___badarg=2    ; args to ARGCHK are bad
  23.         mexit
  24.     endc
  25.     ___badarg=0        ; Just the right amount
  26.     iflt    ___argchk-\\1
  27.         ___badarg=-1    ; Not enough args
  28.     endc
  29.     ifgt    ___argchk-\\2
  30.         ___badarg=1    ; Too many args
  31.     endc
  32.     endm
  33.  
  34.     endc            ; ASM_COMMON
  35.  
  36. ;    SETFP    fp
  37. ;
  38. ;    Change the Default frame pointer variable (___deffp)
  39. ;
  40. SETFP    macro
  41.     ___argchk=narg
  42.     ARGCHK    1,1
  43.     ___deffp=\1
  44.     endm
  45.  
  46. ;    Initial setting
  47.     SETFP    a6
  48.  
  49. ;    CSAVE    local_size,[fp]
  50. ;
  51. ;    Generate a legal C function prolog (Without saving registers)
  52. ;    The default frame Pointer is:    ___deffp   (normally a6)
  53. ;
  54. CSAVE    macro
  55.     ___argchk=narg
  56.     ARGCHK    1,2
  57.     ifne    ___badarg
  58.         fail        ; Generate a user warning
  59.         mexit        ; Incorrect arguments given
  60.     endc
  61.     iflt    \1
  62.         fail
  63.         mexit
  64.     endc
  65.     ifle    \1-32767
  66.         ifeq    narg-1    ; Use default fp (a6)
  67.             link    ___deffp,#\1
  68.         endc
  69.         ifeq    narg-2    ; Use chosen fp
  70.             link    \2,#\1
  71.         endc
  72.     endc
  73.     ifgt    \1-32767
  74.         ifeq    narg-1    ; Use default fp (a6)
  75.             link    ___deffp,#0
  76.             sub.l    #\1,sp
  77.         endc
  78.         ifeq    narg-2    ; Use chosen fp
  79.             link    \2,#0
  80.             sub.l    #\1,sp
  81.         endc
  82.     endc
  83.     endm
  84.  
  85. ;    CRET    [fp]
  86. ;
  87. ;    generate C subroutine epilog (no register saving)
  88. ;
  89. CRET    macro
  90.     ___argchk=narg
  91.     ARGCHK    0,1
  92.     ifeq    narg
  93.         unlk    ___deffp
  94.     endc
  95.     ifeq    narg-1
  96.         unlk    \1
  97.     endc
  98.     rts
  99.     endm
  100.  
  101. ;    REGDIR    field1,field2,dir
  102. ;
  103. ;    sets ___movmask to either field1 or field2 depending on dir
  104. ;
  105. REGDIR    macro
  106.     ___argchk=narg
  107.     ARGCHK    3,3
  108.     ifeq    \\3
  109.         ___movmask=\\1
  110.     endc
  111.     ifne    \\3
  112.         ___movmask=\\2
  113.     endc
  114.     endm
  115.  
  116. ;    REGSET    reg_name,dir
  117. ;
  118. ;    sets ___movmask to be the value of the given regname
  119. ;    depending on the given direction.
  120. ;
  121. REGSET    macro
  122.     ifne    narg-2
  123.         mexit
  124.     endc
  125.     ifc    \\1,"d0"
  126.         REGDIR    0x0001,0x8000,\\2
  127.     endc
  128.     ifc    \\1,"d1"
  129.         REGDIR    0x0002,0x4000,\\2
  130.     endc
  131.     ifc    \\1,"d2"
  132.         REGDIR    0x0004,0x2000,\\2
  133.     endc
  134.     ifc    \\1,"d3"
  135.         REGDIR    0x0008,0x1000,\\2
  136.     endc
  137.     ifc    \\1,"d4"
  138.         REGDIR    0x0010,0x0800,\\2
  139.     endc
  140.     ifc    \\1,"d5"
  141.         REGDIR    0x0020,0x0400,\\2
  142.     endc
  143.     ifc    \\1,"d6"
  144.         REGDIR    0x0040,0x0200,\\2
  145.     endc
  146.     ifc    \\1,"d7"
  147.         REGDIR    0x0080,0x0100,\\2
  148.     endc
  149.     ifc    \\1,"a0"
  150.         REGDIR    0x0100,0x0080,\\2
  151.     endc
  152.     ifc    \\1,"a1"
  153.         REGDIR    0x0200,0x0040,\\2
  154.     endc
  155.     ifc    \\1,"a2"
  156.         REGDIR    0x0400,0x0020,\\2
  157.     endc
  158.     ifc    \\1,"a3"
  159.         REGDIR    0x0800,0x0010,\\2
  160.     endc
  161.     ifc    \\1,"a4"
  162.         REGDIR    0x1000,0x0008,\\2
  163.     endc
  164.     ifc    \\1,"a5"
  165.         REGDIR    0x2000,0x0004,\\2
  166.     endc
  167.     ifc    \\1,"a6"
  168.         REGDIR    0x4000,0x0002,\\2
  169.     endc
  170.     ifc    \\1,"a7"
  171.         REGDIR    0x8000,0x0001,\\2
  172.     endc
  173.     endm
  174.  
  175. ;    GENMOVEM    pred,dir,addr,reg1,reg2,....
  176. ;
  177. ;    pred is set if predecrement mode is to be used
  178. ;    dir  is 0 for movem to mem, 1 for movem to registers
  179. ;    addr is the addressing mode to use
  180. ;    reg1,reg2,... are the registers to save
  181. ;
  182. GENMOVEM    macro
  183.     ___argchk=narg
  184.     ARGCHK    4,16
  185.     ___movval=0
  186.     REGSET    "\4",\1
  187.     ___movval=___movval!___movmask
  188.     REGSET    "\5",\1
  189.     ___movval=___movval!___movmask
  190.     REGSET    "\6",\1
  191.     ___movval=___movval!___movmask
  192.     REGSET    "\7",\1
  193.     ___movval=___movval!___movmask
  194.     REGSET    "\8",\1
  195.     ___movval=___movval!___movmask
  196.     REGSET    "\9",\1
  197.     ___movval=___movval!___movmask
  198.     REGSET    "\10",\1
  199.     ___movval=___movval!___movmask
  200.     REGSET    "\11",\1
  201.     ___movval=___movval!___movmask
  202.     REGSET    "\12",\1
  203.     ___movval=___movval!___movmask
  204.     REGSET    "\13",\1
  205.     ___movval=___movval!___movmask
  206.     REGSET    "\14",\1
  207.     ___movval=___movval!___movmask
  208.     REGSET    "\15",\1
  209.     ___movval=___movval!___movmask
  210.     REGSET    "\16",\1
  211.     ___movval=___movval!___movmask
  212.     ifeq    \2
  213.         movem.l    #___movval,\3
  214.     endc
  215.     ifne    \2
  216.         movem.l    \3,#___movval
  217.     endc
  218.     endm
  219.  
  220.