⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dpmi16.asm

📁 汇编源代码大全
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;
; DPMI16.ASM (c) Rainer Schnitker 91,92,93
;

;
; 16bit library for DPMI 0.9 calls
;
; define 'HAVE386' to use 32bit DPMI mode
;

	.286
	.model SMALL, C

; macro to call dpmi in ax
;
DPMI MACRO function
	mov ax,function
	int 31h
	ENDM

; error check for dpmi-functions
; return -1 for dpmi 0.9
; for dpmi 1.0 replace with "jc @@end" , error code = ax
;
CHECKERR MACRO
	jnc	short @@ok
	mov	ax, -1
	jmp	short @@end
	ENDM

getdword MACRO high,low,address
	mov low,word ptr address
	mov high,word ptr address.2
	ENDM

setdword MACRO address,high,low
	mov word ptr address,low
	mov word ptr address.2,high
	ENDM


	.data

	.code


   ;
   ;	int AllocLDT(WORD anzahl,WORD *sel)
   ;
	public	C AllocLDT
AllocLDT PROC C \
	anzahl	:WORD, \
	sel	:PTR

	mov	cx, anzahl
	DPMI 0000h
	CHECKERR
@@ok:
	mov	bx, sel
	mov	word ptr [bx], ax
	xor	ax, ax
@@end:
	ret
AllocLDT	endp

   ;
   ;	int FreeLDT(WORD sel)
   ;
	public	C FreeLDT
FreeLDT PROC C \
	sel	:WORD

	mov	bx, sel
	DPMI 0001h
	CHECKERR
@@ok:
	xor	ax, ax
@@end:
	ret
FreeLDT 	endp

   ;
   ;	int SegToSel(WORD seg,WORD *sel)
   ;
	public	C SegToSel
SegToSel PROC C \
	paragr	: WORD , \
	sel	: PTR

	mov	bx,paragr
	DPMI 0002h
	CHECKERR
@@ok:
	mov	bx, sel
	mov	word ptr [bx], ax
	xor	ax, ax
@@end:
	ret
SegToSel       endp

   ;
   ;	WORD SelInc(void)
   ;
	public	C SelInc
SelInc PROC C
	DPMI 0003h
	ret
SelInc		endp

   ;
   ;	int LockSel(WORD sel)  undocumented in dpmi 0.9/1.0
   ;
	public	C LockSel
LockSel PROC C \
	sel	:WORD

	mov	bx, sel
	DPMI 0004h
	CHECKERR
@@ok:
	xor	ax, ax
@@end:
	ret
LockSel        endp

   ;
   ;	int UnlockSel(WORD sel)  undocumented in dpmi 0.9/1.0
   ;
	public	C UnlockSel
UnlockSel PROC C \
	sel	:WORD

	mov	bx,sel
	DPMI 0005h
	CHECKERR
@@ok:
	xor	ax, ax
@@end:
	ret
UnlockSel      endp

   ;
   ;	int GetBaseAddress(WORD sel,DWORD *address)
   ;
	public	C GetBaseAddress
GetBaseAddress PROC C \
	sel	:WORD , \
	address :PTR

	mov	bx, sel
	DPMI 0006h
	CHECKERR
@@ok:
	mov	bx, address
	setdword [bx],cx,dx
	xor	ax, ax
@@end:
	ret
GetBaseAddress endp

   ;
   ;	int SetBaseAddress(WORD sel,DWORD address)
   ;
	public	C SetBaseAddress
SetBaseAddress PROC C \
	sel	:WORD , \
	base	:DWORD

	getdword cx,dx,base
	mov	bx, sel
	DPMI 0007h
	CHECKERR
@@ok:
	xor	ax, ax
@@end:
	ret
SetBaseAddress endp

   ;
   ;	int SetLimit(WORD sel,DWORD limit)
   ;
	public	C SetLimit
SetLimit PROC C \
	sel	:WORD , \
	limit	:DWORD

	mov	bx,sel
	getdword cx,dx,limit
	DPMI 0008h
	CHECKERR
@@ok:
	xor	ax, ax
@@end:
	ret
SetLimit       endp

   ;
   ;	int SetAccess(WORD sel,BYTE access,BYTE extaccess)
   ;
	public	C SetAccess
SetAccess PROC C \
	sel	:WORD, \
	access	:BYTE, \
	extaccess :BYTE

	mov	bx,sel
	mov	cl,access
	mov	ch,extaccess
	DPMI 0009h
	CHECKERR
@@ok:
	xor	ax, ax
@@end:
	ret
SetAccess      endp

   ;
   ;	int CreatAlias(WORD segsel,WORD *alias)
   ;
	public	C CreatAlias
CreatAlias  PROC C \
	segsel	:WORD , \
	alias	:PTR

	mov	bx,sel
	DPMI 000Ah
	CHECKERR
@@ok:
	mov	bx,alias
	mov	word ptr [bx],ax
	xor	ax, ax
@@end:
	ret
CreatAlias     endp

   ;
   ;	int GetDescriptor(WORD sel,NPDESCRIPTOR desc)
   ;
	public	C GetDescriptor
GetDescriptor PROC C USES DI, \
	sel	:WORD , \
	desc	:PTR

	push	ds
	pop	es
	mov	bx,sel
ifdef HAVE386
	.386
	movzx	edi, desc
	.286
else
	mov	di,desc
endif
	DPMI 000Bh
	CHECKERR
@@ok:
	xor	ax, ax
@@end:
	ret
GetDescriptor  endp

   ;
   ;	int SetDescriptor(WORD sel,NPDESCRIPTOR desc)
   ;
	public	C SetDescriptor
SetDescriptor PROC C USES DI, \
	sel	:WORD, \
	desc	:PTR

	push	ds
	pop	es
ifdef HAVE386
	.386
	movzx	edi, sel
	.286
else
	mov	di,desc
endif
	mov	bx,sel
	DPMI 000Ch
	CHECKERR
@@ok:
	xor	ax, ax
@@end:
	ret
SetDescriptor  endp

   ;
   ;	int AllocSpecialLDT(WORD sel)
   ;
	public	C AllocSpecialLDT
AllocSpecialLDT PROC C \
	sel	:WORD

	mov	bx,sel
	DPMI 000Dh
	CHECKERR
@@ok:
	xor	ax, ax
@@end:
	ret
AllocSpecialLDT        endp

   ;
   ;	int AllocDosMem(WORD paragraphs,WORD *segment,WORD *selector)
   ;
	public	C AllocDosMem
AllocDosMem  PROC C \
	request :WORD , \
	result	:PTR , \
	sel	:PTR

	mov	bx,request
	DPMI 0100h
	jnc	short @@ok
	mov	dx,bx
	mov	bx,result
	mov	word ptr [bx],dx
	jmp	short @@end
@@ok:
	mov	bx,result
	mov	word ptr [bx],ax
	mov	bx,sel
	mov	word ptr [bx],dx
	xor	ax, ax
@@end:
	ret
AllocDosMem    endp

   ;
   ;	int FreeDosMem(WORD selector)
   ;
	public	C FreeDosMem
FreeDosMem PROC C \
	sel	:WORD

	mov	dx,sel
	DPMI 0101h
	CHECKERR
@@ok:
	xor	ax, ax
@@end:
	ret
FreeDosMem     endp

   ;
   ;	int ResizeDosMem(WORD paragraphs,WORD oldsel,WORD *maxpara)
   ;
	public	C ResizeDosMem
ResizeDosMem PROC C \
	paragr	:WORD , \
	oldsel	:WORD , \
	maxpara :PTR

	mov	bx,paragr
	mov	dx,oldsel
	DPMI 0102h
	jnc	short @@ok
	mov	dx,bx
	mov	bx,maxpara
	mov	word ptr [bx],dx
	jmp	short @@end
@@ok:
	xor	ax, ax
@@end:
	ret
ResizeDosMem   endp

   ;
   ;	int GetRealModeVector(BYTE b,WORD *seg,WORD *off)
   ;
	public	C GetRealModeVector
GetRealModeVector PROC C \
	no	:BYTE , \
	segm	:PTR , \
	offs	:PTR

	mov	bl,no
	DPMI 0200h
	CHECKERR
@@ok:
	mov	bx,segm
	mov	word ptr [bx],cx
	mov	bx,offs
	mov	word ptr [bx],dx
	xor	ax, ax
@@end:
	ret
GetRealModeVector      endp

   ;
   ;	int SetRealModeVector(BYTE b,WORD seg,WORD off)
   ;
	public	C SetRealModeVector
SetRealModeVector PROC C \
	b	:BYTE , \
	segm	:WORD , \
	offs	:WORD

	mov	bl,b
	mov	cx,segm
	mov	dx,offs
	DPMI 0201h
	CHECKERR
@@ok:
	xor	ax, ax
@@end:
	ret
SetRealModeVector      endp

   ;
   ;	int GetExceptionVector(BYTE b,WORD *sel,WORD *off)
   ;
	public	C GetExceptionVector
GetExceptionVector PROC C \
	no	:BYTE , \
	segm	:PTR , \
	offs	:PTR

	mov	bl,no
	DPMI 0202h
	CHECKERR
@@ok:
	mov	bx,segm
	mov	word ptr [bx],cx
	mov	bx,offs
	mov	word ptr [bx],dx
	xor	ax, ax
@@end:
	ret
GetExceptionVector     endp

ifdef HAVE386
   ;
   ;	int GetExceptionVector32(BYTE b,WORD *sel,DWORD *off)
   ;
	public	C GetExceptionVector32
GetExceptionVector32 PROC C \
	no	:BYTE , \
	segm	:PTR , \
	offs	:PTR

	mov	bl,no
	DPMI 0202h
	CHECKERR
@@ok:
	mov	bx,segm
	mov	word ptr [bx],cx
	mov	bx,offs
	mov	word ptr [bx],dx
	.386
	shr	edx,16
	.286
	mov	word ptr [bx].2,dx
	xor	ax,ax
@@end:
	ret
GetExceptionVector32   endp
endif

   ;
   ;	int SetExceptionVector(BYTE b,WORD sel,WORD off)
   ;
	public	C SetExceptionVector
SetExceptionVector PROC C \
	b	:BYTE , \
	segm	:WORD , \
	offs	:WORD

	mov	bl,b
	mov	cx,segm
	mov	dx,offs
	DPMI 0203h
	CHECKERR
@@ok:
	xor	ax, ax
@@end:
	ret
SetExceptionVector     endp

ifdef HAVE386
   ;
   ;	int SetExceptionVector32(BYTE b,WORD sel,DWORD off)
   ;
	public	C SetExceptionVector32
SetExceptionVector32 PROC C \
	b	:BYTE , \
	segm	:WORD , \
	offs	:DWORD

	mov	bl,b
	mov	cx,segm
	.386
	mov	edx,offs
	.286
	DPMI 0203h
	CHECKERR
@@ok:
	xor	ax,ax
@@end:
	.386
	xor	edx,edx
	.286
	ret
SetExceptionVector32   endp
endif

   ;
   ;	int GetProtModeVector(BYTE b,WORD *sel,WORD *off)
   ;
	public	C GetProtModeVector
GetProtModeVector PROC C \
	no	:BYTE , \
	segm	:PTR , \
	offs	:PTR

	mov	bl,no
	DPMI 0204h
	CHECKERR
@@ok:
	mov	bx,segm
	mov	word ptr [bx],cx
	mov	bx,offs
	mov	word ptr [bx],dx
	xor	ax, ax
@@end:
	ret
GetProtModeVector   endp

ifdef HAVE386
   ;
   ;	int GetProtModeVector32(BYTE b,WORD *sel,DWORD *off)
   ;
	public	C GetProtModeVector32
GetProtModeVector32 PROC C \
	no	:BYTE , \
	segm	:PTR , \
	offs	:PTR

	mov	bl,no
	DPMI 0204h
	CHECKERR
@@ok:
	mov	bx,segm
	mov	word ptr [bx],cx
	mov	bx,offs
	mov	word ptr [bx],dx
	.386
	shr	edx,16
	.286
	mov	word ptr [bx].2,dx
	xor	ax,ax
@@end:
	ret
GetProtModeVector32 endp
endif

   ;
   ;	int SetProtModeVector(BYTE b,WORD sel,WORD off)
   ;
	public	C SetProtModeVector
SetProtModeVector PROC C \
	b	:BYTE , \
	segm	:WORD , \
	offs	:WORD

	mov	bl,b
	mov	cx,segm
	mov	dx,offs
	DPMI 0205h
	CHECKERR
@@ok:
	xor	ax, ax
@@end:
	ret
SetProtModeVector   endp

ifdef HAVE386
   ;
   ;	int SetProtModeVector32(BYTE b,WORD sel,DWORD off)
   ;
	public	C SetProtModeVector32
SetProtModeVector32 PROC C \
	b	:BYTE , \
	segm	:WORD , \
	offs	:DWORD

	mov	bl,b
	mov	cx,segm
	.386
	mov	edx,offs
	.286
	DPMI 0205h
	CHECKERR
@@ok:
	xor	ax, ax
@@end:
	ret
SetProtModeVector32 endp
endif

   ;
   ;	int SimulateRMint(BYTE int,BYTE flag,WORD args,NPTRANSLATION call,..)
   ;
	public	C SimulateRMint
SimulateRMint PROC C USES SI DI, \
	intnr	:BYTE, \
	flags	:BYTE, \
	stwords :WORD, \
	trans	:PTR, \
	argv	:BYTE

	push	ds		; small model! ds=ss=es
	pop	es
	mov	cx,stwords
	jcxz	@@simulate
; copy
	sub	sp, cx		;
	sub	sp, cx		; space for cx words
	mov	di, sp
	lea	si, argv
	cld
	rep movsw

	mov	cx, stwords	; reload after movs
@@simulate:
	mov	bh, flags
	mov	bl, intnr
ifdef HAVE386
	.386
	movzx	edi, trans
	.286
else
	mov	di,trans
endif
	DPMI 0300h
	CHECKERR
@@ok:
	xor	ax, ax
@@end:
	mov	cx, stwords
	add	sp,stwords
	add	sp,stwords
	ret
SimulateRMint  endp

   ;
   ;	int CallRMprocFar(BYTE flag,WORD args,NPTRANSLATION call,...)
   ;
	public	C CallRMprocFar
CallRMprocFar PROC C USES SI DI , \
	flags	:BYTE, \
	stwords :WORD, \
	trans	:PTR, \
	argv	:BYTE

	push	ds		; small model! ds=ss=es
	pop	es
	mov	cx,stwords
	jcxz	@@simulate
; copy
	sub	sp, cx
	sub	sp, cx		; space for cx words
	mov	di, sp
	lea	si, argv
	cld
	rep movsw

	mov	cx, stwords
@@simulate:
	xor	bx,bx	; don't use flags
ifdef HAVE386
	.386
	movzx	edi, trans
	.286
else
	mov	di,trans
endif
	DPMI 0301h
	CHECKERR
@@ok:
	xor	ax, ax
@@end:
	mov	cx, stwords
	add	sp,cx
	add	sp,cx
	ret
CallRMprocFar  endp

   ;
   ;	int CallRMprocIret(BYTE flag,WORD args,NPTRANSLATION call,...)
   ;
	public	C CallRMprocIret
CallRMprocIret PROC C USES SI DI, \
	flags	:BYTE, \
	stwords :WORD, \
	trans	:PTR, \
	argv	:BYTE

	push	ds		; small model! ds=ss=es
	pop	es
	mov	cx,stwords
	mov	cx,stwords
	jcxz	@@simulate
; copy
	sub	sp, cx
	mov	di, sp
	lea	si, argv
	cld
	rep movsw

	mov	cx, stwords
@@simulate:
	mov	bh, flags
ifdef HAVE386
	.386
	movzx	edi, trans
	.286
else
	mov	di,trans
endif
	DPMI 0302h
	CHECKERR
@@ok:
	xor	ax, ax
@@end:
	mov	cx, stwords
	add	sp,stwords
	add	sp,stwords
	ret
CallRMprocIret endp

   ;
   ;	int AllocRMcallAddress(WORD pmsel,WORD pmoff,NPTRANSLATION call,
   ;				WORD *rmseg,WORD *rmoff)
   ;
	public	C AllocRMcallAddress
AllocRMcallAddress PROC C USES SI DI, \
	pmsel	:WORD , \
	pmoff	:WORD , \
	trans	:PTR ,	\
	rmseg	:PTR ,	\
	rmoff	:PTR

	push	ds
	pop	es
	push	ds
	mov	ds,pmsel
ifdef HAVE386
	.386
	movzx	esi, pmoff
	movzx	edi, trans
	.286
else
	mov	si, pmoff
	mov	di, trans
endif
	DPMI 0303h
	pop	ds
	CHECKERR
@@ok:
	mov	bx,rmseg
	mov	word ptr [bx],cx
	mov	bx,rmoff
	mov	word ptr [bx],dx
	xor	ax, ax
@@end:
	ret
AllocRMcallAddress     endp

   ;
   ;	int FreeRMcallAddress(WORD rmseg,WORD rmoff)
   ;
	public	C FreeRMcallAddress
FreeRMcallAddress PROC C \
	rmseg	:WORD , \
	rmoff	:WORD

	mov	cx,rmseg
	mov	dx,rmoff
	DPMI 0304h
	CHECKERR
@@ok:
	xor	ax, ax
@@end:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -