	.TITLE	WDROM

	.DSABL	GBL
	.ENABL	LC

	.mcall	.exit .print .readw .writw .lookup .enter .purge .close
;µµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµ
	.Psect	Code
	.Psect	Proc
	.psect	Data
	.psect	Text
	.Psect	Rom
	.Psect	IObuf

	rsk2   = 176674
	rdk2   = 176676

.macro	eprint	str,?local
	bcc	local
	jsr	r0,e$prnt
	.word	str
local:
.endm
	jmpadr	= 1000
;;;;;	DBG	= 1
;µµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµ
start:

;	.Psect	Code

	.lookup	#area,#0,#infil
	eprint	lerr
	.readw	#area,#0,#I.buff,#2000,#0
	eprint	ierr
	.purge	#0
	cmp	I.buff+40,#1000
	bne	inv0
	cmp	I.buff+42,#1000		; stack
	bne	inv0
	mov	I.buff+50,r3
	sub	#1000-2,r3
;;;	asr	r3
	mov	r3,sizmnu

	mov	#O.buff,r5
	mov	#robase,r4

10$:

.If	Df,Dbg
	movb	(r4)+,(r5)+
	inc	r4
.Iff
	movb	(r4)+,(r5)
	comb	(r5)+
	inc	r4
.Endc
	cmp	r4,#ro.beg
	blo	10$

20$:	movb	(r4)+,(r5)	; ëÏÐÉÒÕÅÍ ÚÁÇÒÕÚÞÉË ÍÅÎÀ 2
.Iif	df,dbg	inc	r5
.Iif	ndf,dbg	comb	(r5)+
	cmp	r4,#ro.end
	blo	20$

	mov	#I.buff+1000,r4
	mov	offset,r5
	asr	r5
	add	#O.buff,r5

30$:	movb	(r4)+,(r5)	; ëÏÐÉÒÕÅÍ ÍÅÎÀ 2
.Iif	df,dbg	tstb	(r5)+
.Iif	ndf,dbg	comb	(r5)+
	sob	r3,30$

	mov	#m.s.g,r4
	
40$:	movb	(r4)+,(r5)	; ëÏÐÉÒÕÅÍ ÓÔÒÏËÕ
.Iif	df,dbg	inc	r5
.Iif	ndf,dbg	comb	(r5)+
	tstb	(r4)
	bne	40$

	cmp	#O.buff+4000,r5
	eprint	over


50$:	movb	#-1,(r5)+
	cmp	r5,#O.buff+4000
	blo	50$

.If	ndf,dbg
				; ðÅÒÅ×ÅÒÎÅÍ ðúõ
	Mov	#O.buff,r4
60$:
	movb	-(r5),r0
	movb	(r4),(r5)
	movb	r0,(r4)+
	cmp	r4,r5
	blo	60$
.Endc

	.enter	#area,#0,#outfil,#4
	Eprint	eerr
	.writw	#area,#0,#O.buff,#2000,#0
	Eprint	oerr
	.close	#0
	jsr	r0,e$prnt
	.word	Succes


inv0:	jsr	r0,e$prnt
	.word	inv$0
e$prnt:
	.print	(r0)
	.exit

;µµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµ
	.Psect	Rom
robase::
	nop				; 0
	mtps	#200
	mov	#100000,sp
	mov	#Lo.mnu-ro.beg,r3
	mov	#ro.beg-robase,r2
	mov	r2,r1
1$:	movb	(r1)+,(r2)+
	inc	r1			; âÕÄÅÔ ÕËÁÚÙ×ÁÔØ ÎÁ Lo.mnu
	sob	r3,1$
ro.beg:
	movb	r0,cas.N

wait:	tstb	@#rsk2
	bpl	wait
	tstb	(r1)
	bmi	10$
	mov	(r1)+,@#rdk2
	br	wait

10$:	mov	sizmnu,r3
	mov	#1000,r2
	mov	r2,r1

13$:	movb	(r1)+,(r2)+
	inc	r1
	sob	r3,13$
	br	resMnu

.iif	gt <.-<robase + 100>>	.error	Timer too big !!!
	.= robase + 100
	.word	102,2			; ôÁÊÍÅÒ

resMnu:
;	inc	r1
;10$:	tstb	@#177564
;	bpl	10$
;	mov	(r1)+,@#177566
;	dec	#e.hello-hello
;	bne	10$
	
	jmp	@#1000

Lo$mnu:	.byte	0,10,21
cas.N:	.byte	222
offset:	.word	< << <ro.end-ro.beg> + <<ro.beg-robase>/2> >+1>&^c1> * 2
	.word	1000
sizmnu:	.blkw	1

Lo.mnu:	.word	Lo$mnu-RoBase
	.byte	111,111,-1
;hello:	.ascii	/WDROM V01.00 by Oleg H./<15><12>
;e.hello:
ro.end:
;µµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµ
	.psect	Data	
infil:	.rad50	/dk wdbootsav/
outfil:	.rad50	/dk wdbootrom/
	.psect	Text	
ierr:	.asciz	/Input error/
oerr:	.asciz	/Output error/
lerr:	.asciz	/.Lookup error/
eerr:	.asciz	/.Enter error/
inv$0:	.asciz	/Invalid 0 block/
over:	.asciz	/ROM overflow/
Succes:	.asciz	/Full success; file written: DK:WDBOOT.ROM/
m.s.g:	.Asciz	/ Written by Oleg H. (c) Aug, 1996; olegh@nemo.ankey.ru /
	.even

	.PSECT	IOBUF
area:	.blkw	10.
O.buff:
I.buff = O.buff + 6000

	.end	start
	                                                                                                                                                                                                                                                    