;
;       Turbo BASIC interface support MACROs
;
;       Capital Equipment Corporation, 1987


;       NOTE: the PC-488 memory segment has been added as an extra
;       argument to these routines
;
;       These macros handle ONLY the string subroutines (XMIT, RECV, SEND, 
;       ENTER).
;---------------------------------------------------------------------------

ENTRY MACRO     strarg          ; strarg is the argument number of the string
                                ;  (counting R->L)
        push    bp
        mov     bp,sp
        mov     di,0            ; set DI to point to area in string segment
                                ; to be used as temporary storage
        les     bx,[bp+6+strarg*4]
        test    word ptr es:[bx+2],8000H
        jnz     a
        cmp     word ptr es:[bx+2],30
        jge     a
        mov     di,es:[bx+2]
        mov     ax,es:[bx]
        and     ax,7FFFH
        add     di,ax
a:   
        push    ds              ; set DS to point to string segment
        mov     ax,ds:[0]
        mov     ds,ax
nrestore =      0
        SAVE    -4
        SAVE    -2
        SAVE    strarg*4
        SAVE    strarg*4+2
        mov     ax,es:[bx]              ; build string descriptor in temp. area
        and     ax,7FFFH
        mov     [di+4+strarg*4],ax
        mov     ax,es:[bx+2]
        mov     [di+4+strarg*4+2],ax
nargs   =       1
 ENDM
;---------------------------------------------------------------------------
SAVE MACRO      ofs             ; save a word of the string segment at
                                ; the given offset
        mov     ax,di
        add     ax,ofs+4
        push    ax
        mov     ax,ds:[di+ofs+4]
        push    ax
nrestore =      nrestore+1
 ENDM
RESTORE MACRO
        pop     ax              ; restore one word of string segment
        pop     bx
        mov     [bx],ax
 ENDM
;---------------------------------------------------------------------------
INTARG MACRO    argnum          ; handle integer argument number argnum
                                ; (counting R->L)
        SAVE    argnum*4
        les     bx,[bp+6+argnum*4]
        mov     ax,es:[bx]
        mov     [di+4+argnum*4],ax
nargs   =       nargs+1
 ENDM
UNDO MACRO      argnum          ; undo integer args (copy value back)
        les     bx,[bp+6+argnum*4]
        mov     ax,[di+4+argnum*4]
        mov     es:[bx],ax
 ENDM
;---------------------------------------------------------------------------
EXECUTE MACRO   ofs             ; CALL routine at offset given
        push    di
        mov     ax,di
        add     ax,nargs*4+4
    REPT nargs
        push    ax
        sub     ax,4
    ENDM
        mov     word ptr ds:[di+0],ofs
        les     bx,[bp+6]
        mov     ax,es:[bx]
        mov     word ptr ds:[di+2],ax
        push    ds
        pop     es
        call    dword ptr ds:[di+0]
        pop     di
 ENDM
;---------------------------------------------------------------------------
EXIT MACRO
   REPT nrestore
        RESTORE
   ENDM
        pop     ds              ; restore DS
        pop     bp
 ENDM

