;----------------------------------------------------------------------------
;File name:	CHK_OFLS.S			Revision date:	1994.11.19
;Disassembler:	Ulf Ronald Andersson		Disassembled:	1994.11.19
;----------------------------------------------------------------------------
;
	include	URAn_DOS.S
	include	URAn_XB.S
;
;----------------------------------------------------------------------------
;
	section	text
;
;----------------------------------------------------------------------------
;
begin:
	bra	init_1
;
;
l0000:
	dc.b	'OFLS',$01,$03
l0001:
	dcb.w	64,0
l0002:
	dc.l	0
l0003:
	dc.l	0
nu_currbp_p_p:
	dc.l	0
l0005:
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$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$ff,$ff
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
	dc.b	$ff,$ff
l0006:
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
	dc.b	$ff,$ff,$ff,$ff,$ff,$ff
;
;
l0007:
	dc.b	$39,$3A,$3C,$3d		;Dcreate,Ddelete,Fcreate,Fopen
	dc.b	$41,$43,$4E,$56		;Fwrite,Fattrib,Fsfirst,Frename
	dc.b	-1,-1
;
;----------------------------------------------------------------------------
;	XBRA_linked bios routine
;----------------------------------------------------------------------------
;
	XB_define	nu_bios,'OFLS'
	Pass_Frame	a0
	cmpi.w	#9,(a0)
	bne.s	l0010
	move.l	4(a0),-(sp)
	move.l	(a0),-(sp)
	tst.w	(_longframe).w
	beq.s	l000a
	move.w	14(sp),-(sp)
l000a:
	move.l	#l000b,-(sp)
	move	sr,-(sp)
	bra.s	l0010
;
l000b:
	addq.l	#2,sp
	move.w	(sp)+,d1
	addq.l	#4,sp
	cmp.w	#2,d0
	bne.s	l000f
	lea	l0001,a0
	move.w	d1,-(sp)
	add.w	d1,d1
	tst.w	0(a0,d1.w)
	ble.s	l000c
	move.w	0(a0,d1.w),d0
	neg.w	d0
	lsr.w	#1,d1
	move.w	d1,-(sp)
	move.w	d0,-(sp)
	bsr	l002a
	addq.w	#4,sp
	add.w	d1,d1
	move.w	#0,0(a0,d1.w)
l000c:
	move.w	(sp)+,d1
	move.w	#$4a,d0
	lea	l0005,a0
l000d:
	cmp.w	(a0),d1
	bne.s	l000e
	move.w	#-1,(a0)
	move.l	#-1,2(a0)
l000e:
	lea	6(a0),a0
	dbra	d0,l000d
	move.w	#2,d0
l000f:
	rte
;
;
l0010:
	move.l	nu_bios+8,-(sp)
	rts
;
;----------------------------------------------------------------------------
;Ends:	XBRA_linked bios routine
;----------------------------------------------------------------------------
;	XBRA_linked gemdos routine
;----------------------------------------------------------------------------
;
	XB_define	nu_gemdos,'OFLS'
	Pass_Frame	a0		;new:\ / This is to allow
	cmp	#Ptermres&$ff,(a0)	;new: X  maximum speed for
	blt	go_old_gemdos		;new:/ \ gemdos Super function
;
	movem.l	d1-d2/a1-a2,-(sp)	;new: Atari-required protection
;Bug: Original omitted the mandatory protection above (only protected a1-a2)
;
	bsr	l0016
	tst	d0
	bmi.s	l0014
	lea	l0001,a1
	move	d0,d1
	add	d1,d1
	lea	(a1,d1),a1
	cmp	#-1,(a1)
	beq.s	l0015
	tst	(a1)
	bge.s	l0013
	move	#0,(a1)
l0013:
	cmp	#Fcreate&$ff,(a0)
	beq.s	l001c
	cmp	#Fopen&$ff,(a0)
	beq.s	l001c
l0014:
	tst.w	(a0)			;Pterm0 ?
	beq	l001f
	cmp	#Pterm&$ff,(a0)		;Pterm ?
	beq	l001f
	cmp	#Ptermres&$ff,(a0)	;Ptermres ?
	beq	l001f
	cmp	#Fclose&$ff,(a0)	;Fclose ?
	beq	l0022
	movem.l	(sp)+,d1-d2/a1-a2	;new: Atari-required protection
;Bug: Original omitted the mandatory protection above (only protected a1-a2)
	bra	go_old_gemdos
;
l0015:
	movem.l	(sp)+,d1-d2/a1-a2	;new: Atari-required protection
;Bug: Original omitted the mandatory protection above (only protected a1-a2)
	moveq	#E_ACCDN,d0
	rte
;
;
;Here Fcreate and Fopen are served
l001c:
	move	d0,-(sp)
	move.l	4(a0),-(sp)
	move.l	(a0),-(sp)
	move	#10+4*4,d0		;stack distance to return frame
	bsr	l0024
	lea	8(sp),sp
	move	(sp)+,d2
	cmp	#6,d0
	blt.s	.l001e
	cmp	#$4b,d0
	bge.s	.l001e
	lea	l0001,a1
	lea	l0005,a0
	move.w	d0,d1
	add	d0,d1
	add	d0,d1
	add	d1,d1
	lea	(a0,d1),a0
	tst	(a0)
	bmi.s	.l001d
	move	(a0),d1
	add	d1,d1
	tst	(a1,d1)
	ble.s	.l001d
	subq	#1,(a1,d1)
	move	(a0),-(sp)
	move	#-1,-(sp)
	bsr	l002a
	addq	#4,sp
.l001d:
	move	d2,(a0)
	movea.l	nu_currbp_p_p,a2
	move.l	(a2),2(a0)
	add	d2,d2
	addq	#1,(a1,d2)
	move	(a0),-(sp)
	move	#1,-(sp)
	bsr	l002a
	addq	#4,sp
.l001e:
	movem.l	(sp)+,d1-d2/a1-a2	;new: Atari-required protection
;Bug: Original omitted the mandatory protection above (only protected a1-a2)
	rte
;
;
;Here Pterm0, Pterm, and Ptermres are served
l001f:
	move	#$4a,d0
	lea	l0005,a0
	lea	l0001,a1
	movea.l	nu_currbp_p_p,a2
.l0020:
	move.l	2(a0),d1
	cmp.l	(a2),d1
	bne.s	.l0021
	move	(a0),d1
	move	#-1,(a0)
	move.l	#-1,2(a0)
	add	d1,d1
	tst	(a1,d1)
	ble.s	.l0021
	subq	#1,(a1,d1)
	lsr	#1,d1
	move	d1,-(sp)
	move	#-1,-(sp)
	bsr	l002a
	addq	#4,sp
.l0021:
	lea	6(a0),a0
	dbra	d0,.l0020
	movem.l	(sp)+,d1-d2/a1-a2	;new: Atari-required protection
;Bug: Original omitted the mandatory protection above (only protected a1-a2)
	bra.s	go_old_gemdos
;
;
;Here Fclose is served
l0022:
	move.l	(a0),-(sp)
	move	#4+4*4,d0			;stack distance to return frame
	bsr.s	l0024
	addq	#2,sp
	move	(sp)+,d1
	move	d1,d2
	lea	l0001,a1
	lea	l0005,a0
	cmp	#6,d1
	blt.s	.l0023
	cmp	#$4b,d1
	bge.s	.l0023
	add	d1,d1
	add	d2,d1
	add	d1,d1
	lea	(a0,d1),a0
	tst	(a0)
	bmi.s	.l0023
	move	(a0),d1
	move	#-1,(a0)
	move.l	#-1,2(a0)
	add	d1,d1
	tst	(a1,d1)
	bmi.s	.l0023
	beq.s	.l0023
	subq	#1,(a1,d1)
	lsr	#1,d1
	move	d1,-(sp)
	move	#-1,-(sp)
	bsr.s	l002a
	addq	#4,sp
.l0023:
	movem.l	(sp)+,d1-d2/a1-a2	;new: Atari-required protection
;Bug: Original omitted the mandatory protection above (only protected a1-a2)
	rte
;
;-------------------------------------
;Here d0 = pre_call stack distance to exception return frame
;	   used only if (_longframe) is nonzero
;
l0024:
	tst	(_longframe).w
	beq.s	.l0025
	movea.l	(sp)+,a0	;a0 -> popped return address
	addq	#6,d0		;(sp+d0) -> original frame extension word
	move	(sp,d0),-(sp)	;repush original frame extension word
	move.l	a0,-(sp)	;repush return address (simulate frame dest)
.l0025:
	move	sr,-(sp)	;push status register (simulate frame status)
go_old_gemdos:
	move.l	nu_gemdos+8,-(sp)
	rts
;
;-------------------------------------
;
l0016:
	move.l	a1,-(sp)
	lea	l0007,a1
.l0017:				;loop here to test tabled opcodes
	move.b	(a1)+,d0
	ext.w	d0
	bmi.s	.l001b		;if not found, exit via .l001b
	cmp.w	(a0),d0
	bne.s	.l0017		;loop back to test tabled opcodes
	movea.l	nu_currbp_p_p,a1	;a1 -> currbp_p
	movea.l	(a1),a1			;a1 -> current basepage
	move.b	55(a1),d0
	ext.w	d0
	cmp	#Frename&$ff,(a0)
	bne.s	.l0019
	movea.l	4(a0),a1
	bra.s	.l001a
;
.l0019:
	movea.l	2(a0),a1
.l001a:
	cmpi.b	#':',1(a1)	;drive character infix ?
	bne.s	.l001b
	move.b	(a1),d0		;d0 = drive character
	and.b	#~$20,d0
	sub.b	#'A',d0
	ext.w	d0		;d0 = drive number
	cmpi.w	#$20,d0
	blt.s	.l001b
	tst.w	d0
	bpl.s	.l001b
	move.w	#-1,d0
.l001b:
	movea.l	(sp)+,a1
	rts
;
;----------------------------------------------------------------------------
;Ends:	XBRA_linked gemdos routine
;----------------------------------------------------------------------------
;
l002a:
	move.l	d0,-(sp)
	move.l	#'XHDI',d0
	bsr	l0032
	tst.l	d0
	beq.s	.l002c
	movem.l	a0-a1/d1-d3,-(sp)
	movea.l	d0,a0
	movea.l	4(a0),a0
	cmpi.l	#$27011992,-4(a0)
	bne.s	.l002b
	movea.l	a0,a1
	move.w	30(sp),d2
	move.w	28(sp),d3
	move.l	#0,-(sp)
	movea.l	sp,a0
	move.l	#0,-(sp)
	move.l	#0,-(sp)
	pea	(a0)
	pea	2(a0)
	move.w	d2,-(sp)
	move.w	#7,-(sp)
	jsr	(a1)
	adda.w	#$14,sp
	move.w	(sp)+,d2
	move.w	(sp)+,d1
	tst.l	d0
	bne.s	.l002b
	bsr.s	l002d
	cmpa.w	#0,a0
	beq.s	.l002b
	add.w	d3,4(a0)
	tst.w	4(a0)
	bgt.s	.l002b
	clr.w	-(sp)
	move.w	#0,-(sp)
	move.w	2(a0),-(sp)
	move.w	(a0),-(sp)
	move.l	#-1,(a0)
	move.w	#3,-(sp)
	jsr	(a1)
	adda.w	#$a,sp
.l002b:
	movem.l	(sp)+,a0-a1/d1-d3
.l002c:
	move.l	(sp)+,d0
	rts
;
;
l002d:
	move.w	d1,d0
	swap	d0
	move.w	d2,d0
	bsr.s	l002f
	cmpa.w	#0,a0
	bne.s	.l002e
	move.l	d0,-(sp)
	moveq	#-1,d0
	bsr.s	l002f
	move.l	(sp)+,d0
	cmpa.w	#0,a0
	beq.s	.l002e
	move.l	d0,(a0)
	move.w	#0,4(a0)
	clr.w	-(sp)
	move.w	#1,-(sp)
	move.w	d2,-(sp)
	move.w	d1,-(sp)
	move.w	#3,-(sp)
	jsr	(a1)
	adda.w	#$a,sp
.l002e:
	rts
;
;
l002f:
	move.l	d3,-(sp)
	lea	l0006,a0
	move.w	#4,d3
.l0030:
	cmp.l	(a0),d0
	beq.s	.l0031
	lea	6(a0),a0
	dbra	d3,.l0030
	suba.l	a0,a0
.l0031:
	move.l	(sp)+,d3
	rts
;
;
l0032:
	movem.l	a0/d2,-(sp)
	move.l	d0,d2
	move.l	(_cookies).w,d0
	beq.s	.l0035
	movea.l	d0,a0
	clr.l	d0
.l0033:
	tst.l	(a0)
	beq.s	.l0035
	cmp.l	(a0),d2
	beq.s	.l0034
	addq.l	#8,a0
	bra.s	.l0033
;
.l0034:
	move.l	a0,d0
.l0035:
	movem.l	(sp)+,a0/d2
	rts
;
;
l0036:
	move.l	(resvalid).w,l0003
	move.l	#$31415926,(resvalid).w
	move.l	(resvector).w,nu_resvector+8
	move.l	#nu_resvector+12,(resvector).w
	rts
;
;----------------------------------------------------------------------------
;	XBRA_linked reset routine
;----------------------------------------------------------------------------
;
	XB_define	nu_resvector,'OFLS'
	dc.b	'XBRAOFLS'
	clr.l	(_cookies).w
	move.l	nu_resvector+8,(resvector).w
	move.l	l0003,(resvalid).w
	jmp	(a6)
;
;----------------------------------------------------------------------------
;Ends:	XBRA_linked reset routine
;----------------------------------------------------------------------------
;
l0039:
	move.l	a2,-(sp)
	tst.w	d2
	bne.s	l003a
	bsr	l0036
l003a:
	add.w	#$14,d2
	lsl.w	#3,d2
	move.w	d2,l0002
	lsr.w	#3,d2
	lea	l0044,a0
	movea.l	a0,a2
	tst.l	(_cookies).w
	beq.s	l003c
	movea.l	(_cookies).w,a1
l003b:
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	tst.l	(a1)
	bne.s	l003b
l003c:
	clr.l	(a0)+
	move.l	d2,(a0)
	move.l	a2,(_cookies).w
	movea.l	(sp)+,a2
	rts
;
;----------------------------------------------------------------------------
;
init_1:
	lea	prog_title_s(pc),a0
	bsr	cconws_ia0
	pea	l003f(pc)
	move.w	#$26,-(sp)	;supexec
	trap	#$e
	addq.l	#6,sp
	clr.w	-(sp)
	tst.w	d0
	beq.s	l003e
	lea	$8b6.l,a0
	adda.w	l0002,a0
	move.l	a0,-(sp)
	move.w	#$31,-(sp)	;ptermres
l003e:
	trap	#1
;
;----------------------------------------------------------------------------
;
l003f:
	move.l	#'OFLS',d0
	bsr	l0032
	tst.l	d0
	bne	l0044
	move.l	#'MiNT',d0
	bsr	l0032
	tst.l	d0
	bne.s	l0045
	bsr	get_currbp_p_p
	move.l	a0,nu_currbp_p_p
	pea	nu_gemdos+12(pc)
	move.w	#evn_gemdos,-(sp)
	move.w	#5,-(sp)	;setexc
	trap	#$d
	addq.l	#8,sp
	move.l	d0,nu_gemdos+8
	pea	nu_bios+12(pc)
	move.w	#evn_bios,-(sp)
	move.w	#5,-(sp)	;setexc
	trap	#$d
	addq.l	#8,sp
	move.l	d0,nu_bios+8
	bsr.s	l0040
	moveq	#1,d0
	rts
;
;
l0043:
	bsr	l0039
l0040:
	move.l	#'OFLS',d0
	moveq	#0,d2
	tst.l	(_cookies).w
	beq.s	l0043
	movea.l	(_cookies).w,a0
	moveq	#1,d2
l0041:
	tst.l	(a0)
	beq.s	l0042
	lea	8(a0),a0
	addq.l	#1,d2
	bra.s	l0041
;
l0042:
	cmp.l	4(a0),d2
	beq.s	l0043
	move.l	4(a0),12(a0)
	clr.l	8(a0)
	move.l	d0,(a0)
	move.l	#l0000,4(a0)
	rts
;
;
l0045:
	lea	not_with_MiNT_s(pc),a0
	bsr.s	cconws_ia0
	rts
;
;
l0044:
	lea	already_in_s(pc),a0
	bsr.s	cconws_ia0
l0046:
	bsr.s	cconin_sub
	clr.l	d0
	rts
;
;
cconws_ia0:
	move.l	a0,-(sp)
	move.w	#9,-(sp)	;cconws
	trap	#1
	addq.l	#6,sp
	rts
;
;
cconin_sub:
	move.w	#1,-(sp)	;cconin
	trap	#1
	addq.l	#2,sp
	rts
;
;
;----------------------------------------------------------------------------
;sup	get_currbp_p_p	=> a0 -> os_currbp_p for new or old TOS
;----------------------------------------------------------------------------
;
get_currbp_p_p:
	movea.l	(_sysbase).w,a0
	movea.l	os_selfbeg_p(a0),a0
	cmpi.w	#$102,os_version(a0)
	bcs.s	.l004d			;if version < 1.02 goto .l004d
	movea.l	os_currbp_p_p(a0),a0
	rts
;
.l004d:
	move.w	os_config(a0),d0
	asr.w	#1,d0
	subq.w	#4,d0
	bne.s	.l004e
	movea.l	#$873c,a0
	rts
;
.l004e:
	movea.l	#$602c,a0
	rts
;
;----------------------------------------------------------------------------
;
	section	data
;
;----------------------------------------------------------------------------
;
prog_title_s:
	dc.b	CR,LF
	dc.b	ESC,'p'
	dc.b	'        GEMDOS-Safety  V 1.03        ',ESC,'q',' ',CR,LF
	dc.b	'     A Product of KOBOLD Research     ',CR,LF
	dc.b	' 1992 by H.-J. Richstein * Kaktus GbR ',CR,LF,NUL,NUL
;
already_in_s:
	dc.b	BEL,ESC,'p'
	dc.b	'   CHK_OFLS is already installed!    '
	dc.b	ESC,'q'
	dc.b	' ',CR,LF,NUL
;
not_with_MiNT_s:
	dc.b	BEL,ESC,'p'
	dc.b	'      Does not work with MiNT!       ',ESC,'q',' ',LF,CR,NUL
	even
;
;----------------------------------------------------------------------------
;
	section	bss
;
;----------------------------------------------------------------------------
;
;----------------------------------------------------------------------------
zuend:	end
;----------------------------------------------------------------------------
;End of file:	CHK_OFLS.S
;----------------------------------------------------------------------------
