File:  [OS/2 SDKs] / os2sdk / startup / dos / nmsghdr.asm
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Thu Aug 9 12:25:13 2018 UTC (7 years, 9 months ago) by root
Branches: msft, MAIN
CVS tags: os2sdk-1987, HEAD
Microsoft OS/2 SDK 12-15-1987

	page	,132
	TITLE	nmsghdr - near message handler and finder
;***
;nmsghdr.asm - near message handler and finder
;
;	Copyright (c) 1986-1987, Microsoft Corporation.  All rights reserved.
;
;Purpose:
;	Near message handler and finder.
;
;*******************************************************************************


?DF=	1			; this is special for c startup
include	version.inc
?PLM=	1			; pascal calling conventions
.xlist
ifdef	_QC			;[2] Move these includes out of version.inc
include	\sl\qc\src\include\kernel.inc	;[2]
include \sl\qc\src\include\kmac.inc	;[2]
endif	;_QC			;[2]

include	cmacros.inc
include	msdos.inc
.list

createSeg _TEXT, code,	word,	public, CODE,	<>

createSeg _DATA, data,	word,	public, DATA,	DGROUP

createSeg HDR,	nhdr,	byte,	public, MSG,	DGROUP
createSeg MSG,	nmsg,	byte,	public, MSG,	DGROUP
createSeg PAD,	npad,	byte,	common, MSG,	DGROUP
createSeg EPAD,	nepad,	byte,	common, MSG,	DGROUP

defGrp	DGROUP			; define DGROUP

codeOFFSET equ	offset _TEXT:
dataOFFSET equ	offset DGROUP:


sBegin	nhdr
assumes	ds,data

	db	'<<NMSG>>'
stnmsg	label	byte

sEnd

sBegin	npad
assumes	ds,data

	dw	-1		; message padding marker

sEnd

sBegin	nepad
assumes	ds,data

	db	-1

sEnd

ifdef	_QC
sBegin	data
externW	__psp			; psp:0 (paragraph #)
sEnd	data
endif	;_QC


sBegin	code
assumes	cs,code
assumes	ds,data

page
;***
;__NMSG_TEXT(messagenumber) - find message for given message number
;
;Purpose:
;	This routine returns a near pointer to the message associated with
;	messagenumber.	If the message does not exist, then a 0 is returned.
;
ifdef	IBMC20
;	This routine reestablishes DS = ES = SS (DGROUP)
else
;	This routine assumes DS = DGROUP
endif ; IBMC20
;
;Entry:
;	==PASCAL CALLING CONVENTIONS==
;	messagenumber = WORD message number of desired message
;
;Exit:
;	AX	= pointer to message text or 0 if no message exists.
;
;Uses:
;
;Exceptions:
;
;*******************************************************************************

cProc	__NMSG_TEXT,<PUBLIC>,<si,di>  ; pascal calling

	parmW	msgt

cBegin
ifdef	_QC				;[X]
	push	ds			; assume that ds = DGROUP
	pop	es			; es = ds = DGROUP
	mov	dx,msgt			; dx = message number
	mov	si,dataOFFSET stnmsg	; start of messages in core
	call	tloop			; search for message
	or	ax,ax			; found one?
	jnz	done			; yes - exit

;
;  try finding message in user library
;
	push	ds			; save DGROUP
	mov	ds,[__psp]		;
	lds	si,dword ptr ds:[PSP_UL_TERM_OFF] ; [X]
	mov	cx,ds			; is there a user lib?
	or	cx,si			;
	jz	nmsg2			; no - skip to .exe

	lds	si,ds:[si+28h]		;
	push	ds
	pop	es
	call	tloop			; search for message
	or	ax,ax			; found one?
	jnz	nmsg3			; yes - clean it up correctly

;
;  try finding message in program-list.exe
;
nmsg2:
	pop	ds			; restore DGROUP
	push	ds			; save DGROUP
	mov	ds,[__psp]		;
	lds	si,dword ptr ds:[PSP_EXE_TRM_OFF] ; [X]
	mov	cx,ds			; is there a user lib?
	or	cx,si			;
	jz	fail			; no - fail

	lds	si,ds:[si+28h]		;
	push	ds
	pop	es
	call	tloop			; search for message
	or	ax,ax			; found one?
	jz	fail			; no - fail

nmsg3:
	pop	ds			;
	push	ax			;
	mov	ax,es			;
	mov	dx,ds			;
	sub	ax,dx			;
	mov	cl,4			;
	shl	ax,cl			;
	pop	bx			;
	add	ax,bx			;
	push	ds			;
	pop	es			;
	jmp	done			;

fail:
	pop	ds			;
done:
			
	
else	;_QC				;[X]
ifdef	IBMC20
	mov	ax,DGROUP
	mov	ds,ax		; ds = DGROUP (force it always)
endif ; IBMC20
	push	ds
	pop	es
	mov	dx,msgt		; dx = message number
	mov	si,dataOFFSET stnmsg ; start of near messages

tloop:
	lodsw			; ax = current message number
	cmp	ax,dx
	je	found		;   found it - return address
	inc	ax
	xchg	ax,si
	jz	found		;   at end and not found - return 0
	xchg	di,ax
	xor	ax,ax
	mov	cx,-1
	repne	scasb		; skip until 00
	mov	si,di
	jmp	tloop		; try next entry

found:
	xchg	ax,si
endif	;_QC				;[X]
cEnd

ifdef	_QC
tloop:
	lodsw			; ax = current message number
	cmp	ax,dx
	je	found		;   found it - return address
	inc	ax
	xchg	ax,si
	jz	found		;   at end and not found - return 0
	xchg	di,ax
	xor	ax,ax
	mov	cx,-1
	repne	scasb		; skip until 00
	mov	si,di
	jmp	tloop		; try next entry
found:
	xchg	ax,si
	ret
endif	;_QC

page
;***
;__NMSGWRITE(messagenumber) - writes message on stderr
;
;Purpose:
;	This routine writes the message associated with messagenumber
;	to stderr.
;
;Entry:
;	==PASCAL CALLING CONVENTIONS==
;	messagenumber = WORD number of desired message
;
;Exit:
;
;Uses:
;
;Exceptions:
;
;*******************************************************************************

cProc	__NMSG_WRITE,<PUBLIC>,<di>  ; pascal calling

	parmW	msgw

cBegin
	push	msgw
	call	__NMSG_TEXT	; find near text pointer
	or	ax,ax
	jz	nowrite		; don't write anything if not there

	xchg	dx,ax		; ds:dx = string address
	mov	di,dx
	xor	ax,ax
	mov	cx,-1
	repne	scasb		; es = ds from __NMSG_TEXT
	not	cx
	dec	cx		; cx = string length
	mov	bx,2
ifdef	_QC			;[1]
	int	0f3h		;[1] Force Screen for QC
endif	;_QC
	callos	write

nowrite:
cEnd

sEnd

	end

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.