[comp.os.msdos.programmer] Need help finding bug in TSR code

maniac@howlin.cs.unlv.edu (Eric J. Schwertfeger) (02/28/91)

	I`m working on code to write-protect a hard disk, and after giving up on intercepting int26H (even when I set int26 to an IRET, it still wrote to the disk), I came up with this code fragment.  This is only the new interupt handler.

;
old_han	label	dword
old_off dw	?
old_seg	dw	?
dx_save	dw	0
bx_save dw	0

New_han	proc	far
	cmp	dl,80h
	jne	DoIt
	cmp	AH,03
	je	block
	cmp	AH,0Bh
	jne	DoIt
block:
	cmp	cl,3Fh
	ja	DoIt
	cmp 	ch,CCh
	ja	DoIt
	mov	cs:dx_save,dx
	mov	cs:bx_save,bx
	pop	dx
	pop	bx
	popf
	stc
	pushf
	push	bx
	push	dx
	mov	dx,cs:dx_save
	mov	bx,cs:bx_save
	mov	AX,0300
	iret
DoIt:
	mov	cs:dx_save,dx
	mov	dx,cs:old_seg
	push	dx
	mov	dx,cs:old_off
	push	dx
	mov	dx,cs:dx_save
	ret

	block is supposed to determine the cylinder of the write, and block any write to a cylinder of 204 or below.  With the comparisons commented out, the entire hard disk becomes write protected.  However, once I try to protect just a single partition, the code doesn't block anything.
	I've even inverted each comparison, and both, to no avail.  according to the documentation I`ve read on int13h, functions 03h and 0Bh, the cylinder is kept in CH, with the upper 2 bits in the upper 2 bits of CL, giving a high number of 1023 (So that's where that limit comes from :-).
Is my source wrong, or am I missinterpreting something somewhere?
	Also, I know there's got to be a better way to do what I'm doing in DoIt, that is jumping to the proper interupt handler, but I can't figure it out.  any suggestions?
-- 
Eric J. Schwertfeger, maniac@jimi.cs.unlv.edu