; High-Level-Language Interface Macros - Version 1.0 ; for Microsoft Macro Assembler 5.0 ; (C) Copyright Microsoft Corporation, 1987. ; Syntax Purpose ; ------ ------- ; ; setModel Sets model from text equate ; ; hProc [,] [,arg[:type] [,arg[:type]]]... ; Starts a procedure with optional stack arguments ; ; hLocal var[:type] [,var[:type]]... ; Defines local stack variables ; ; hRet Returns from the current procedure ; ; hEndp Ends the current procedure ; ; ifFP statement Assembles statement if far data ; ; FPoperand Conditionally provides ES override for data ; ; pLes register,address Conditionally loads data through ES ; ; pLds register,address Conditionally loads data through DS if1 ; Set model passed from command line setModel macro setModelDoit %model endm setModelDoit macro option .model option endm ; Declare high level routine and parameters hProc macro funName, a,b,c,d,e,f,g,h,i,j ; FP - supply far pointer ES overide as needed if @Datasize FP equ else FP equ < > endif cParm=0 cbLocals=0 argBase = 2 + @CodeSize*2 cbReturn = 0 localBase = 2 tokenize funName adjustType %token1 conCat procName, %token0 conCat nearFar, %token1 tokenize a hScanParms %token0, , b,c,d,e,f,g,h,i,j hProcFinish %procName, %nearFar, %regPushed endm ; Preprocess arg list to save registers hScanParms macro use, regList, b,c,d,e,f,g,h,i,j ifidni , regPushed equ hScanArgs b,c,d,e,f,g,h,i,j else regPushed equ <> hScanArgs regList,b,c,d,e,f,g,h,i,j endif endm ; Scan parameter list to process args hScanArgs macro a,b,c,d,e,f,g,h,i,j irp arg, ifb exitm endif fetType arg ifdef cLang createArg %argNameCur, %typeNameCur, %argBase+cParm+2 else createArg %argNameCur, %typeNameCur, %argBase-cbType-cParm,+cParm endif cParm = cParm + cbType + 2 endm endm ; Generate procedure and stack frame hProcFinish macro funName, nearFar, regList ifdef cLang funNameCur equ <_&funName> else funNameCur equ cbReturn = cParm endif funNameCur proc nearFar public funNameCur if cParm push Bp mov Bp,Sp endif pushReg regList endm ; Save registers pushReg macro use,b,c,d,e,f,g regPushed equ <> irp reg, ifb exitm endif conCat regPushed, <,> %regPushed conCat regPushed, reg, %regPushed push reg localBase = localBase + 2 endm endm ; Declare local stack variables hLocal macro a,b,c,d,e,f,g,h,i,j irp arg, ifb exitm endif fetType arg createArg %argNameCur, %typeNameCur, %-cbLocals-localBase cbLocals = cbLocals + cbType + 2 endm ife cParm ; Create empty frame if no params push Bp mov Bp,Sp endif sub Sp,cbLocals endm ; Split argment into argNameCur and typeNameCur fetType macro arg cbType=0 fColon=0 argNameCur equ < > typeNameCur equ < > .xcref fColon, argNameCur irpc aChar,arg if fColon conCat typeNameCur, %typeNameCur, aChar else ifidni ,<:> fColon=1 else conCat argNameCur,%argNameCur,aChar endif endif endm adjustType %typeNameCur endm ; Tokenize arg into text macro name tokenN tokenize macro a,b,c,d,e,f,g,h,i,j cPart = 0 doTokenSet 1 irp aWord, ifb exitm endif doTokenSet %cPart, aWord cPart = cPart+1 endm endm ; Set tokenN to a value doTokenSet macro tokenNum, aWord token&tokenNum equ endm ; Map typeName to byte count and ptr size adjustType macro typeName ifb cbType = 0 typeNameCur equ exitm endif ifidni , cbType = 0 exitm endif ifidni , cbType = 0 exitm endif ifidni , cbType = 2 exitm endif ifidni , cbType = (1 + @DataSize) AND 2 if (cbType EQ 2) typeNameCur equ else typeNameCur equ endif exitm endif ifidni , cbType = 4 exitm endif ifidni , cbType = 6 exitm endif ifidni , cbType = 8 exitm endif ifidni , argBase = 2 exitm endif ifidni , argBase = 4 endif endm ; Concatenate a character to a text macro conCat macro symbol,text,char symbol equ endm ; Create text macro for an arg createArg macro argName, typeName, offsetParm, argFactor argName equ endm ; Generate high level return hRet macro popRegs %regPushed if cParm or cbLocals pop Bp endif ret cbReturn endm ; Restore saved registers popRegs macro regList if cbLocals ifnb add Sp,cbLocals else mov Sp,Bp endif endif irp reg, ifnb pop reg endif endm endm ; End a high level procedure hEndp macro funNameCur endp endm ; Execute instruction if far data ifFP macro a,b,c,d,e,f,g,h,i,j if @datasize a b c d e f g h i j endif endm ; Load 16/32 bit pointers into [ES:] reg pLes macro reg, address if @datasize les reg,address else mov reg,address endif endm ;Load 16/32 bit pointers into [DS:] reg pLds macro reg, address if @datasize lds reg,address else mov reg,address endif endm .xcref createArg, conCat, fetType, cbType, argBase, pushReg, hScanArgs, hScanParms .xcref adjustType, typeNameCur, setModelDoit, tokenize, dotokenSet .xcref token0, token1, regPushed, hProcFinish, procName, localBase, popRegs endif ; Define on pass1 only