
;BSET.ASM
;BZERO.ASM
;
;   Uses longword operations if data is aligned on a longword boundry
;   and the size is a mulitple of 4.  Otherwise, uses byte operations.

	xdef  _bset
	xdef  _bzero

_bzero
	clr.l	D1
	bra	begin
_bset
	move.b	15(A7),D1	;12(A7)-> msb . . lsb	(D1 = data)
begin
	move.l	4(A7),A0	;A0 = address
	move.l	8(A7),D0	;D0 = byte count
	andi.b	#3,11(A7)	;byte count on long word boundry?
	bne	drop
	andi.b	#3,7(A7)	;address on longword boundry?
	bne	drop
	bra	lwb
loop	move.b	D1,(A0)+	;BYTE SET LOOP
drop	dbf.w	D0,loop 	;remember, only effects lower word
	sub.l	#$10000,D0	;for buffers >65535
	bpl	loop		;branch to loop because D0.W now is FFFF
	rts

lwb	lsr.l	#2,D0		;byte count / 4 (longword chunks)
	tst.l	D1		;BZERO
	beq	dropl
	move.b	D1,14(A7)	;15(A7) already contains the byte
	move.w	14(A7),D1	;D1 0..15 set
	swap	D1
	move.w	14(A7),D1	;D1 16..31 set
	bra	dropl

loopl	move.l	D1,(A0)+	;BYTE SET LOOP
dropl	dbf.w	D0,loopl	;remember, only effects lower word
	sub.l	#$10000,D0	;for buffers >65535
	bpl	loopl		;branch to loop because D0.W now is FFFF
	rts



;/*
; *  The assembly tag for the DOS process:  CNOP causes alignment problems
; *  with the Aztec assembler for some reason.  I assume then, that the
; *  alignment is unknown.  Since the BCPL conversion basically zero's the
; *  lower two bits of the address the actual code may start anywhere around
; *  the label....  Sigh....  (see CreatProc() above).
; */

	xref	_debugmain
	xdef	_debugproc

	cnop	0,2
	nop
	nop
	nop
_debugproc:
	nop
	nop
	movem.l D2-D7/A2-A6,-(sp)
	jsr	_debugmain
	movem.l (sp)+,D2-D7/A2-A6
	rts




	xdef	_FindHandler		; Find Handler of (A1) Name
	xref	_DOSBase


_FindHandler
	move.l	4(a7),a1		; a1 = handler name to find
	move.l	8(a7),a0		; a0 = dosbase
	movem.l	d2-d7/a2-a6,-(a7)
	move.l	44+12(a7),a4		; a4 = ptr to copy of vir_volumeID stuff
	bsr	Find100
	movem.l	(a7)+,d2-d7/a2-a6
	rts
Find100
					; A0 = DosBase
					; A1 = Named Handler to Find
					; Capitalize
	move.l	a1,a3			; (stash a1, next trashes a1)

;
; don't capitalize because
; we're looking for the exact same
; instance of device as
; what we had before
;
; later on we can make it less specific when we support keys
;
					; A1 = Capitalize
;2$	move.b	(a1)+,d0		; Parse User Input Chars
;	beq.s	3$
;	bmi.s	3$			; (some error, try contain error)
;	cmp.b	#':',d0			; Allow ':' (or 0)
;	beq.s	3$
;	cmp.b	#' ',d0			; (some error, try contain error)
;	bcs.s	3$
;	cmp.b	#'a',d0			; Ignore if <a
;	bcs.s	2$
;	cmp.b	#'z',d0			; Ignore if >z
;	bcc.s	2$
;	sub.b	#32,-1(a1)		; Change to UpperCase
;	bra.s	2$
;3$	;clr.b	-1(a0)			; terminate

Find200
	move.l	34(a0),a0		; dl_root->struct RootNode
	move.l	24(a0),a0		; rn_info->struct DosInfo
	add.l	a0,a0			; BPTR -> APTR
	add.l	a0,a0
	move.l	4(a0),d0		; dl_DevInfo->struct DevicList
					; Goto Next Device/Handler if Any
0$	add.l	d0,d0			; BPTR -> APTR
	beq.s	3$			; End Device/Handler List?
	add.l	d0,d0
	move.l	d0,a0
	move.l	(a0),d0			; (Stash Next Device/Handler)
	cmp.l	#2,4(a0)
	bne.s	0$			; dl_Type == 2 != Handler?


; (this being an extra picky robust check might be overkill, for example does
;  a revalidation change the datestamp (and thus volume ID)?)
; there should be a "be-stupid" option for cases like this, or intentional cases.

					; this little section deviates from a
					;   normal "findhandler"
	;------------------		; Check if diskkeys match:

	;move.l	16(a0),vir_VolID(a4)	; Volume->VolDays
	;move.l	20(a0),vir_VolID+4(a4)
	;move.l	24(a0),vir_VolID+8(a4)
	;move.l	4(a0),vir_VolType(a4)	; Volume->Type (must == 2!)
	;move.l	64(a0),vir_VolDiskType(a4)	; Volume->DiskType
	;
	;STRUCT	vir_VolID,ds_SIZEOF	; Volume DateStamp Positive ID
	;LONG	vir_VolType		; Volume Type
	;LONG	vir_VolDiskType		; Volume Disk Type 'NDOS'...

	move.l	(a4),d1			; read vir_VolID
	cmp.l	16(a0),d1		; compare to device VolID
	bne.s	0$
	move.l	4(a4),d1
	cmp.l	20(a0),d1
	bne.s	0$
	move.l	8(a4),d1
	cmp.l	24(a0),d1
	bne.s	0$

	move.l	12(a4),d1		; read vir_VolType
	cmp.l	4(a0),d1		; compare to device VolType
	bne.s	0$

	move.l	16(a4),d1		; read vir_VolType
	cmp.l	64(a0),d1		; compare to device VolType
	bne.s	0$

	;-------------------
					; now check if names match (they should)
					; (as per a normal findhandler search)
	move.l	40(a0),d1
	beq.s	0$			; dl_Name?
	add.l	d1,d1
	add.l	d1,d1
	move.l	d1,a2			; (don't trash a0)
	moveq	#0,d1
	move.b	(a2)+,d1		; BSTR STRLEN > 0?
	beq.s	0$
	move.l	a3,a1			; Compare Handler Names
	bra.s	2$
1$	cmp.b	(a1)+,(a2)+
	bne.s	0$
2$	dbf	d1,1$
	cmp.b	#':',(a1)		; Both Terminated?
	beq.s	4$
	tst.b	(a1)			; Permit ':' or 0 on Search String
	bne.s	0$
4$	move.l	a0,d0			; D0/A0 = Handler Node (C wants d0)
	moveq	#1,d1			; Success (C doesn't need this but)
	rts
3$	moveq	#0,d0			; Failure (C wants D0=0 - just in case)
	rts
