home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / usoftpd.zip / MIXED.INC < prev    next >
Text File  |  1987-07-31  |  6KB  |  362 lines

  1. ; High-Level-Language Interface Macros - Version 1.0
  2. ;   for Microsoft Macro Assembler 5.0
  3. ; (C) Copyright Microsoft Corporation, 1987.
  4.  
  5. ;   Syntax             Purpose
  6. ;   ------             -------
  7. ;
  8. ;   setModel             Sets model from text equate
  9. ;
  10. ;   hProc  <name [NEAR|FAR]> [,<USES reglist>] [,arg[:type] [,arg[:type]]]...
  11. ;                 Starts a procedure with optional stack arguments
  12. ;
  13. ;   hLocal var[:type] [,var[:type]]...
  14. ;                 Defines local stack variables
  15. ;
  16. ;   hRet             Returns from the current procedure
  17. ;
  18. ;   hEndp             Ends the current procedure
  19. ;
  20. ;   ifFP  statement         Assembles statement if far data
  21. ;
  22. ;   FPoperand             Conditionally provides ES override for data
  23. ;
  24. ;   pLes  register,address   Conditionally loads data through ES
  25. ;
  26. ;   pLds  register,address   Conditionally loads data through DS
  27.  
  28. if1
  29.  
  30. ; Set model passed from command line
  31.  
  32. setModel macro
  33.     setModelDoit %model
  34. endm
  35.  
  36. setModelDoit macro option
  37.  
  38.     .model option
  39. endm
  40.  
  41. ; Declare high level routine and parameters
  42.  
  43. hProc macro funName, a,b,c,d,e,f,g,h,i,j
  44.  
  45. ; FP - supply far pointer ES overide as needed
  46.  
  47.     if @Datasize
  48.       FP equ <es:>
  49.     else
  50.       FP equ < >
  51.     endif
  52.  
  53.     cParm=0
  54.     cbLocals=0
  55.     argBase = 2 + @CodeSize*2
  56.     cbReturn = 0
  57.     localBase = 2
  58.  
  59.     tokenize funName
  60.     adjustType %token1
  61.     conCat procName, %token0
  62.     conCat nearFar, %token1
  63.  
  64.     tokenize a
  65.     hScanParms %token0, <a>, b,c,d,e,f,g,h,i,j
  66.  
  67.     hProcFinish %procName, %nearFar, %regPushed
  68.     endm
  69.  
  70. ; Preprocess arg list to save registers
  71.  
  72. hScanParms macro use, regList, b,c,d,e,f,g,h,i,j
  73.  
  74.     ifidni <use>,<uses>
  75.     regPushed equ <regList>
  76.     hScanArgs b,c,d,e,f,g,h,i,j
  77.     else
  78.     regPushed equ <>
  79.     hScanArgs regList,b,c,d,e,f,g,h,i,j
  80.     endif
  81. endm
  82.  
  83. ; Scan parameter list to process args
  84.  
  85. hScanArgs macro a,b,c,d,e,f,g,h,i,j
  86.  
  87.     irp arg,<a,b,c,d,e,f,g,h,i,j>
  88.  
  89.     ifb <arg>
  90.         exitm
  91.     endif
  92.  
  93.     fetType arg
  94.  
  95.     ifdef cLang
  96.         createArg %argNameCur, %typeNameCur, %argBase+cParm+2
  97.     else
  98.         createArg %argNameCur, %typeNameCur, %argBase-cbType-cParm,+cParm
  99.     endif
  100.  
  101.     cParm = cParm + cbType + 2
  102.     endm
  103. endm
  104.  
  105. ; Generate procedure and stack frame
  106.  
  107. hProcFinish macro funName, nearFar, regList
  108.  
  109.     ifdef cLang
  110.     funNameCur equ <_&funName>
  111.     else
  112.     funNameCur equ <funName>
  113.     cbReturn = cParm
  114.  
  115.     endif
  116.  
  117.     funNameCur proc nearFar
  118.     public funNameCur
  119.     if cParm
  120.         push    Bp
  121.         mov     Bp,Sp
  122.     endif
  123.     pushReg regList
  124. endm
  125.  
  126. ; Save registers
  127.  
  128. pushReg macro use,b,c,d,e,f,g
  129.  
  130.     regPushed equ <>
  131.     irp reg, <b,c,d,e,f,g>
  132.  
  133.         ifb <reg>
  134.         exitm
  135.         endif
  136.  
  137.         conCat regPushed, <,> %regPushed
  138.         conCat regPushed, reg, %regPushed
  139.         push   reg
  140.         localBase = localBase + 2
  141.     endm
  142. endm
  143.  
  144. ; Declare local stack variables
  145.  
  146. hLocal macro a,b,c,d,e,f,g,h,i,j
  147.  
  148.     irp arg,<a,b,c,d,e,f,g,h,i,j>
  149.  
  150.     ifb <arg>
  151.         exitm
  152.     endif
  153.  
  154.     fetType arg
  155.     createArg %argNameCur, %typeNameCur, %-cbLocals-localBase
  156.  
  157.     cbLocals = cbLocals + cbType + 2
  158.     endm
  159.  
  160.     ife cParm                ; Create empty frame if no params
  161.     push    Bp
  162.     mov    Bp,Sp
  163.     endif
  164.  
  165.     sub Sp,cbLocals
  166. endm
  167.  
  168. ; Split argment into argNameCur and typeNameCur
  169.  
  170. fetType macro arg
  171.     cbType=0
  172.     fColon=0
  173.     argNameCur equ < >
  174.     typeNameCur equ < >
  175.     .xcref fColon, argNameCur
  176.  
  177.     irpc aChar,arg
  178.     if fColon
  179.         conCat typeNameCur, %typeNameCur, aChar
  180.     else
  181.         ifidni <aChar>,<:>
  182.         fColon=1
  183.         else
  184.         conCat argNameCur,%argNameCur,aChar
  185.         endif
  186.     endif
  187.     endm
  188.     adjustType %typeNameCur
  189. endm
  190.  
  191. ; Tokenize arg into text macro name tokenN
  192. tokenize macro a,b,c,d,e,f,g,h,i,j
  193.  
  194.     cPart = 0
  195.     doTokenSet 1
  196.  
  197.     irp aWord,<a,b,c,d,e,f,g,h,i,j>
  198.     ifb <aWord>
  199.         exitm
  200.     endif
  201.  
  202.     doTokenSet %cPart, aWord
  203.     cPart = cPart+1
  204.     endm
  205. endm
  206.  
  207. ; Set tokenN to a value
  208.  
  209. doTokenSet macro tokenNum, aWord
  210.     token&tokenNum equ <aWord>
  211.     endm
  212.  
  213. ; Map typeName to byte count and ptr size
  214.  
  215. adjustType macro typeName
  216.  
  217.     ifb <typeName>
  218.     cbType = 0
  219.     typeNameCur equ <word>
  220.     exitm
  221.     endif
  222.  
  223.     ifidni <typeName>,<byte>
  224.     cbType = 0
  225.     exitm
  226.     endif
  227.  
  228.     ifidni <typeName>,<word>
  229.     cbType = 0
  230.     exitm
  231.     endif
  232.  
  233.     ifidni <typeName>,<dword>
  234.     cbType = 2
  235.     exitm
  236.     endif
  237.  
  238.     ifidni <typeName>,<ptr>
  239.     cbType = (1 + @DataSize) AND 2
  240.     if (cbType EQ 2)
  241.         typeNameCur equ <dword>
  242.     else
  243.         typeNameCur equ <word>
  244.     endif
  245.     exitm
  246.     endif
  247.  
  248.     ifidni <typeName>,<fword>
  249.     cbType = 4
  250.     exitm
  251.     endif
  252.  
  253.     ifidni <typeName>,<qword>
  254.     cbType = 6
  255.     exitm
  256.     endif
  257.  
  258.     ifidni <typeName>,<tword>
  259.     cbType = 8
  260.     exitm
  261.     endif
  262.  
  263.     ifidni <typeName>,<near>
  264.     argBase = 2
  265.     exitm
  266.     endif
  267.  
  268.     ifidni <typeName>,<far>
  269.     argBase = 4
  270.     endif
  271. endm
  272.  
  273. ; Concatenate a character to a text macro
  274.  
  275. conCat macro symbol,text,char
  276.     symbol equ <text&char>
  277. endm
  278.  
  279. ; Create text macro for an arg
  280.  
  281. createArg macro argName, typeName, offsetParm, argFactor
  282.     argName equ <typeName ptr [Bp]+offsetParm&argFactor>
  283. endm
  284.  
  285. ; Generate high level return
  286.  
  287. hRet macro
  288.  
  289.     popRegs %regPushed
  290.  
  291.     if cParm or cbLocals
  292.     pop    Bp
  293.     endif
  294.     ret    cbReturn
  295. endm
  296.  
  297. ; Restore saved registers
  298.  
  299. popRegs macro regList
  300.  
  301.     if cbLocals
  302.       ifnb <regList>
  303.         add     Sp,cbLocals
  304.     else
  305.         mov     Sp,Bp
  306.       endif
  307.     endif
  308.  
  309.     irp reg, <regList>
  310.     ifnb <reg>
  311.         pop reg
  312.     endif
  313.     endm
  314. endm
  315.  
  316. ; End a high level procedure
  317.  
  318. hEndp macro
  319. funNameCur  endp
  320. endm
  321.  
  322. ; Execute instruction if far data
  323.  
  324. ifFP    macro a,b,c,d,e,f,g,h,i,j
  325.  
  326. if @datasize
  327.        a b c d e f g h i j
  328. endif
  329. endm
  330.  
  331. ; Load 16/32 bit pointers into [ES:] reg
  332.  
  333. pLes macro reg, address
  334.  
  335.     if @datasize
  336.  
  337.     les reg,address
  338.     else
  339.     mov reg,address
  340.  
  341.     endif
  342. endm
  343.  
  344. ;Load 16/32 bit pointers into [DS:] reg
  345.  
  346. pLds macro reg, address
  347.  
  348.     if @datasize
  349.  
  350.     lds reg,address
  351.     else
  352.     mov reg,address
  353.  
  354.     endif
  355. endm
  356.  
  357. .xcref createArg, conCat, fetType, cbType, argBase, pushReg, hScanArgs, hScanParms
  358. .xcref adjustType, typeNameCur, setModelDoit, tokenize, dotokenSet
  359. .xcref token0, token1, regPushed, hProcFinish, procName, localBase, popRegs
  360.  
  361. endif ; Define on pass1 only
  362.