Source file: /~heha/hs/finger.zip/SRC/FWD.ASM

	ideal
	model	small
	P386
ATTSIZE	EQU	256
UDATASEG
AttH	dd	ATTSIZE dup (?)
AttP	dd	ATTSIZE dup (?)
CODESEG
proc AttInit pascal
	push	ds
	pop	es
	lea	di,[AttH]
	xor	eax,eax
	mov	ecx,ATTSIZE*2
	cld
	rep	stosd
	ret
endp

proc CalcDI
;PE: EAX=Such-DWORD
;    L(DI)=Hash-Index
;PA: Z=1: gefunden, DI=Index
	and	di,0FFh
	shl	di,2		;bessere Trefferwahrscheinlichkeit
	add	di,offset AttH
	cmp	[di],eax
	jz	@@fnd		;Vorzugsposition ist frei!
	push	ds
	pop	es
	lea	di,[AttH]
	mov	ecx,ATTSIZE
	cld
	repne	scasd		;DWORD EAX suchen
	pushf
	 sub	di,4
	popf
@@fnd:	ret
endp

AttPutWW:
proc AttPut pascal
arg @@H:DWord,@@P:DWord
	xor	eax,eax
	mov	di,[word LOW @@H]	;Index-Hash
	call	CalcDI
	mov	ax,-1
	jnz	@@e		;Return mit Fehler
@@fnd:	mov	eax,[@@H]
	mov	[di],eax
	mov	eax,[@@P]
	mov	[AttP-AttH+di],eax
	mov	ax,di
	sub	ax,offset AttH	;Adresse minus Anfang
	shr	ax,2		;nun: Index 0..255
@@e:	ret
endp

AttGetWW:
proc AttGet pascal
arg @@H:DWord
	mov	eax,[@@H]
	mov	di,ax		;Index-Hash
	call	CalcDI
	jz	@@fnd		;an Vorzugsposition entdeckt!
	xor	eax,eax		;NIL
	stc			;Return mit Fehler und NIL
	jmp	@@e
@@fnd:	mov	eax,[AttP-AttH+di]
	clc			;Return: OK
@@e:	push	eax
	pop	ax dx		;EAX->DX:AX
	ret
endp

proc AttIdxGet pascal
arg @@I:Word
	xor	eax,eax
	mov	bx,[@@I]
	or	bh,bh
	jnz	@@e
	shl	bx,2
	mov	eax,[AttP+bx]
@@e:	push	eax
	pop	ax dx
	ret
endp

proc AttGetRev pascal
arg @@P:DWord
	mov	eax,[@@P]
	push	ds
	pop	es
	lea	di,[AttP]
	mov	ecx,ATTSIZE
	cld
	repne	scasd		;DWORD EAX suchen
	jz	@@fnd1		;gefunden: DI korrigieren!
	xor	eax,eax		;NIL
	stc			;Return mit Fehler und NIL
	jmp	@@e
@@fnd1:	mov	eax,[AttH-AttP+di-4]
	clc			;Return: OK
@@e:	push	eax
	pop	ax dx		;EAX->DX:AX
	ret
endp


AttDelWW:
proc AttDel pascal
arg @@H:DWord
	push	[@@H]
	call	AttGet
	jc	@@e
	xor	ebx,ebx		;CY bleibt 0
	mov	[dword di],ebx
	mov	[AttP-AttH+di],ebx
@@e:	ret
endp

proc AttIdxDel pascal
arg @@I:Word
	xor	eax,eax
	mov	bx,[@@I]
	or	bh,bh
	jnz	@@e
	shl	bx,2
	cmp	[AttP+bx],eax
	jz	@@e
	xchg	[AttH+bx],eax	;Return!
@@e:	push	eax
	pop	ax dx
	ret
endp

AttIdxWW:
proc AttIdx pascal
arg @@H:DWord
	push	[@@H]
	call	AttGet
	mov	ax,-1		;wenn nicht gefunden
	jc	@@e
	mov	ax,di
	sub	ax,offset AttH	;Adresse minus Anfang
	shr	ax,2		;nun: Index 0..255
@@e:	ret
endp

public AttInit,AttPut,AttPutWW,AttGet,AttGetWW,AttGetRev,AttDel,AttDelWW
public AttIdxWW,AttIdx,AttIdxGet,AttIdxDel
	END
Detected encoding: ASCII (7 bit)2