COMMENT ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MACROS.INC created Apr 3, 1989
Copyright (C) 1989-1992, Datalight Inc.
All Rights Reserved
General macros for interfacing assembly with C Code.
Works equally well with Microsoft and Borland C (all
versions).
MACRO DESCRIPTIONS:
------------------
cBegCode ; open the code segment (CODE)
cEndCode ; close the code segment
cBegData ; open the data segment (DATA)
cEndData ; close the data segment
cBegUdata ; open the uninitialized data seg (BSS)
cEndUdata ; close udata segment
c_func ; declares a function callable from C
c_endp ; declare ending of a function
c_callm ; calls a C function
c_public ; declares a c public
c_extrn ; declares a "C" external
c_extrnP ; declares an external function
largeCODE ; TRUE if M, L or H model
largeDATA ; TRUE if C, L or H model
P ; offset of first parameter on stack
GOFFSET ; DGROUP:xxxx (offset of a variable within DGROUP)
COFFSET ; CS:xxxx (offset within the current CODE segment)
AN EXAMPLE:
-------------------
cBegCode
c_func name ; C function declaration name()
PUSH BP
MOV BP,SP
if largeDATA
MOV ES,P+4[BP] ; some code dependant on large data
endif
.
.
MOV AX,P[BP] ; get first argument (word)
MOV BX,P+2[BP] ; get next argument (word)
.
callm a_routine ; call a C routine from assembly
MOV BX,AX ; return value (if any) is in AX
.
POP BP
RET
c_endp name
CEndCode
END
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
; >
IFNDEF memS
IFNDEF memM
IFNDEF memL
IFNDEF memC
IFNDEF memH
memL = 1
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
; >
out1 MACRO msg
IFDEF ??version
%out msg
ELSE
IF1
%out msg
ENDIF
ENDIF
ENDM
; >
setsize MACRO name,codesize,datasize
IFDEF name
IF name
largeCODE = codesize
largeDATA = datasize
ENDIF
ENDIF
ENDM
; >
setsize memS, 0,0 ;
setsize memM, 1,0 ;
setsize memC, 0,1 ;
setsize memL, 1,1 ;
setsize memH, 1,1 ;
; >
outif MACRO name,msg
IFDEF name
IF name
out1
ENDIF
ENDIF
ENDM
; >
cBegCode MACRO
_TEXT SEGMENT WORD PUBLIC 'CODE'
ASSUME CS:_TEXT
ENDM
cEndCode MACRO
_TEXT ENDS
ENDM
; >
cBegData MACRO
DGROUP GROUP _DATA
_DATA SEGMENT WORD PUBLIC 'DATA'
_DATA ENDS
_DATA SEGMENT
ASSUME DS:DGROUP
ENDM
cEndData MACRO
_DATA ends
ENDM
cBegUdata MACRO
DGROUP GROUP _BSS
_BSS SEGMENT WORD PUBLIC 'BSS'
ASSUME DS:DGROUP
ENDM
cEndUdata MACRO
_BSS ENDS
ENDM
IF largeCODE
P equ 6
ELSE
P equ 4
ENDIF
c_func MACRO name
public _&name
IF largeCODE
_&name PROC FAR
ELSE
_&name PROC NEAR
ENDIF
name EQU _&name
ENDM
c_endp MACRO name
_&name ENDP
ENDM
c_callm MACRO name
IF largeCODE
CALL FAR PTR _&name
ELSE
CALL NEAR PTR _&name
ENDIF
name EQU _&name
ENDM
c_public MACRO a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
ifnb ; recursive check for blank argument
public _&a
a EQU _&a
ifnb
c_public b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
endif
endif
ENDM
c_extrn MACRO a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
ifnb ; recursive check for blank argument
extrn _&a:b
a EQU _&a
ifnb
c_extrn c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
endif
endif
ENDM
c_extrnP MACRO name
ifnb
IF largeCODE
extrn _&name:far
ELSE
extrn _&name:near
ENDIF
name EQU _&name
endif
ENDM
c_label MACRO name,xxx
ifnb
PUBLIC _&name
_&name LABEL xxx
name EQU _&name
endif
ENDM
c_labelP MACRO name
ifnb
PUBLIC _&name
IF largeCODE
_&name LABEL FAR
ELSE
_&name LABEL NEAR
ENDIF
name EQU _&name
endif
ENDM
; >
GOFFSET EQU
COFFSET EQU