home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
drdobbs
/
c_spec
/
sources
/
mydos.asm
< prev
next >
Wrap
Assembly Source File
|
1986-02-20
|
4KB
|
167 lines
TITLE DOS INTERFACE FUNCTION
SUBTTL Copyright 1985 by Allen I. Holub
NAME DOS
PAGE 58,132
;----------------------------------------------------------------------
;
; Data types: The REGS structure is defined as type allregs in mydos.h
;
REGS STRUC ; Structure used to transfer register
AX_REG DW 0 ; contents. Note that this structure is
BX_REG DW 0 ; a supperset of that defined in the
CX_REG DW 0 ; dos.h supplied by Lattice. This particular
DX_REG DW 0 ; structure is defined in \include\mydos.h
SI_REG DW 0
DI_REG DW 0
ES_REG DW 0
CS_REG DW 0
SS_REG DW 0
DS_REG DW 0
REGS ENDS
OFF EQU 4 ; Offset to arguments
;----------------------------------------------------------------------
; Header for Microsoft C compiler
;
_TEXT SEGMENT BYTE PUBLIC 'CODE'
_TEXT ENDS
CONST SEGMENT WORD PUBLIC 'CONST'
CONST ENDS
_BSS SEGMENT WORD PUBLIC 'BSS'
_BSS ENDS
_DATA SEGMENT WORD PUBLIC 'DATA'
_DATA ENDS
DGROUP GROUP CONST, _BSS, _DATA
ASSUME CS: _TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP
;----------------------------------------------------------------------
;
; name: mydos -- Do a DOS function call
;
; synopsis: #include <mydos.h>
;
; status = mydos( regsp );
; int status ; /* returned status register */
; REGS *regp ; /* pointer to register struct */
;
; description: This function is a more useful version of the bdos()
; function provided with the lattice C compiler. It
; saves the existing machine state, replaces the
; contents of all registers except CS & SS from the
; structure pointed to by regp, does an int 21, loads
; the registers back into the structure, restores the
; machine state and returns.
;
; notes: This function will only work with the SMALL model, since
; it assumes a 16 bit pointer. The stack frame is
; non-standard too (ie the BP holds the structure pointer
; arg rather than the frame pointer).
;
PUBLIC _mydos
_TEXT SEGMENT
_mydos PROC NEAR
PUSH BP ; Save the old stack frame.
MOV BP,SP ;
MOV BP,[BP+OFF] ; BP = pointer to register structure.
PUSH BX ; Save the current machine state. No
PUSH CX ; point in saving AX because it's
PUSH DX ; going to be used for the return
PUSH SI ; value.
PUSH DI
PUSH ES
PUSH DS
MOV AX,[BP].AX_REG ; Set up a new machine state
MOV BX,[BP].BX_REG ; using the contents of the
MOV CX,[BP].CX_REG ; REGS structure. Don't modify
MOV DX,[BP].DX_REG ; the SS or CS registers.
MOV SI,[BP].SI_REG
MOV DI,[BP].DI_REG
MOV ES,[BP].ES_REG
MOV DS,[BP].DS_REG
PUSH BP ; Make the DOS call. Save the BP
INT 21H ; out of irrational paranoia.
POP BP
MOV [BP].AX_REG,AX ; Now update the original structure
MOV [BP].BX_REG,BX ; to reflect the return values from
MOV [BP].CX_REG,CX ; the DOS call.
MOV [BP].DX_REG,DX
MOV [BP].SI_REG,SI
MOV [BP].DI_REG,DI
MOV [BP].ES_REG,ES
MOV [BP].CS_REG,CS
MOV [BP].DS_REG,DS
MOV [BP].SS_REG,SS
POP DS
POP ES
POP DI ; Restore the previous machine state
POP SI
POP DX
POP CX
POP BX
LAHF ; Return the flags:
MOV AL,AH ; Move flags to LSB
XOR AH,AH ; Clear high bytes
POP BP ; Restore the previous stack frame's
RET ; frame pointer and return.
_mydos ENDP
_TEXT ENDS
;----------------------------------------------------------------------
;
; name: gregs -- Initialize a REGS structure to the current
; register contents.
;
; synopsis: #include <mydos.h>
;
; gregs( regp )
; REGS *regp ; /* pointer to register struct */
;
; description: This function is used before before calling mydos().
;
; notes: This function will only work with the SMALL model.
;
;
PUBLIC _gregs
;
_TEXT SEGMENT
;
_gregs PROC NEAR
PUSH BP ; Save the old stack frame.
MOV BP,SP ;
MOV BP,[BP+OFF] ; BP = pointer to register structure.
MOV [BP].AX_REG,AX ; Initialize the structure pointed
MOV [BP].BX_REG,BX ; to by bp.
MOV [BP].CX_REG,CX
MOV [BP].DX_REG,DX
MOV [BP].SI_REG,SI
MOV [BP].DI_REG,DI
MOV [BP].ES_REG,ES
MOV [BP].CS_REG,CS
MOV [BP].DS_REG,DS
MOV [BP].SS_REG,SS
POP BP ; Restore the previous stack
RET ; frame and return.
_gregs ENDP
_TEXT ENDS
END