prgsize:	equ	3000
*	blitter stuff	*
halftone:	equ	0
src_xinc:	equ	32
src_yinc:	equ	34
src_addr:	equ	36
endmask1:	equ	40
endmask2:	equ	42
endmask3:	equ	44
dst_xinc:	equ	46
dst_yinc:	equ	48
dst_addr:	equ	50
x_count:	equ	54
y_count:	equ	56
hop:		equ	58
op:		equ	59
line_num:	equ	60
skew:		equ	61
fhop_source:	equ	1
fhop_halftone:	equ	0
fskewfxsr:	equ	7
fskewnfsr:	equ	6
flinebusy:	equ	7
flinehog:	equ	6
flinesmudge:	equ	5
mhop_source:	equ	$02
mhop_halftone:	equ	$01
mskewfxsr:	equ	$80
mskewnfsr:	equ	$40
mlinebusy:	equ	$80
mlinehog:	equ	$40
mlinesmudge:	equ	$20
modulo=80
vbl_list=$4ce
	bra	start
start:
	MOVE.L	4(A7),A0
	moveq	#0,d6
	ADD.L	$C(A0),D6
	ADD.L	$14(A0),D6
	ADD.L	$1C(A0),D6
	MOVE.L	D6,-(A7)
loadinfo:
	move    #0,-(SP)        ;Open file
	move.l  #info,-(SP) ;Address of filename
	move    #$3D,-(SP)
	trap    #1              ;Get handle number in D0
	addq.l  #8,SP
	tst.w	d0
	bmi	noinfo
	move.w	d0,-(sp)
	move.w	(sp),d0
	move.l  #defs,-(SP)	;load it straight onto screen
	move.l  #6,-(SP)	;length to read in
	move    D0,-(SP)	;Handle
	move    #$3F,-(SP)	;bios number
	trap    #1		;Read file in
	addi.l   #12,SP
	move    #$3E,-(SP)      ;Handle already on stack
	trap    #1              ;Close file
	addq.l  #4,SP
noinfo:
	MOVE.W	#4,-(A7)	;get res
	TRAP	#14
	ADDQ.L	#2,A7
	CMP.W	#2,D0
	BNE	NOTHIGH
	MOVE.L	(A7)+,D6	;already mono
	MOVE.W	#0,-(A7)
	TRAP	#1
NOTHIGH:
	CLR.L	-(A7)		;go supervisor
	MOVE.W	#$20,-(A7)
	TRAP	#1
	ADDQ.L	#6,A7
	MOVE.L	D0,SAVESTACK	;save it

	MOVE.L	#MESSAGE,-(A7)	;print my message
	MOVE.W	#9,-(A7)
	TRAP	#1
	ADDQ.L	#6,A7
INLOOP:				;first determine speed
	MOVE.L	#speedmsg,-(A7)	;print my message
	MOVE.W	#9,-(A7)
	TRAP	#1
	ADDQ.L	#6,A7
	move.w	#1,-(sp)
	trap	#1
	addq.l	#2,sp
	move.l	d0,d1
	swap	d1
	cmpi.b	#13,d0
	beq	defaults
	cmpi.b	#48,d0
	blt	inloop
	cmpi.b	#57,d0
	bgt	inloop
	sub.w	#48,d0
	move.w	d0,userdelay
inloop2:			;then determine type of emulation
	MOVE.L	#emumsg,-(A7)	;print my message
	MOVE.W	#9,-(A7)
	TRAP	#1
	ADDQ.L	#6,A7
	move.w	#1,-(sp)
	trap	#1
	addq.l	#2,sp
	move.l	d0,d1
	swap	d1
	cmpi.b	#49,d0
	blt	inloop2
	cmpi.b	#51,d0
	bgt	inloop2
	sub.w	#48,d0
	move.w	d0,emu

inloop3:			;then determine type of emulation
	MOVE.L	#hrtzmsg,-(A7)	;print my message
	MOVE.W	#9,-(A7)
	TRAP	#1
	ADDQ.L	#6,A7
	move.w	#1,-(sp)
	trap	#1
	addq.l	#2,sp
	cmpi.b	#49,d0
	blt	inloop3
	cmpi.b	#50,d0
	bgt	inloop3
	cmpi.b	#49,d0
	bne.s	h1
	move.b	#2,$ff820a
	move.w	#2,hrz
	bra.s	h2
h1:
	move.b	#0,$ff820a
	move.w	#0,hrz
h2:
	MOVE.L	#savemsg,-(A7)	;print my message
	MOVE.W	#9,-(A7)
	TRAP	#1
	ADDQ.L	#6,A7
	move.w	#1,-(sp)
	trap	#1
	addq.l	#2,sp
	swap	d0
	cmpi.b	#$15,d0
	beq.s	saveinfo
	cmpi.b	#$31,d0
	beq.s	bydefault
saveinfo:
	lea	defs,a0
	move.w	userdelay,(a0)+
	move.w	emu,(a0)+
	move.w	hrz,(a0)+

	move    #1,-(SP)        ;Open file for write
	move.l  #info,-(SP) ;Address of filename
	move    #$3d,-(SP)
	trap    #1              ;Get handle number in D0
	addq.l  #8,SP
	cmpi.w	#-33,d0		;doesn't exist
	beq	create
	tst.w	d0		;other error
	bmi	docn2
	move.w	d0,-(sp)
cb:
	move.w	(sp),d0
	move.l  #defs,-(SP)
	move.l  #6,-(SP)	;length to write in
	move    D0,-(SP)	;Handle
	move    #$40,-(SP)	;bios number
	trap    #1		;write file
	addi.l   #12,SP
	move    #$3E,-(SP)      ;Handle already on stack
	trap    #1              ;Close file
	addq.l  #4,SP
	bra.s	bydefault
defaults:
	lea	defs,a0
	move.w	(a0)+,userdelay
	move.w	(a0)+,emu
	move.w	(a0)+,d0
	move.b	d0,$ff820a
bydefault:
	MOVE.L	$44E,d0		;get video address
	move.l	d0,mono1
	add.l	#modulo,d0
	move.l	d0,mono2

	MOVE.L	$B8,XBIOSPOKE+2	;trap	#14
	MOVE.L	$70,vblankpoke1+2	;vb
	MOVE.L	$70,vblankpoke2+2	;vb
	MOVE.L	$70,vblankpoke3+2	;vb
	MOVE.W	#2,-(A7)	;set to mono
	MOVE.L	#$FFFFFFFF,-(A7)
	MOVE.L	#$FFFFFFFF,-(A7)
	MOVE.W	#5,-(A7)
	TRAP	#14
	ADDA.L	#$C,A7

	MOVE.L	$70,A0
	MOVE.L	#SIMPLE_VBLANK,$70
	MOVE.W	#1,RASTER_FLAG
WAIT_RASTER:
	TST.W	RASTER_FLAG
	BNE	WAIT_RASTER	;wait for vblank

	MOVE.B	#1,$FF8260	;move mono into shifter
	MOVE.L	A0,$70		;restore normal vblank

emu1:
	cmpi.w	#1,emu
	bne.s	emu2
	move.w	#16000-1,d1
	bsr	doclear
	move.l	#screena,screen1
	move.l	screen1,screen2
	add.l	#160,screen2
	move.l	screen1,screen3
	move.l	screen2,screen4
	MOVE.L	#VBLANK1,$70	;and new vbl
	move.l	(sp)+,d6
	add.l	#32000*2+prgsize,d6
	move.l	d6,-(sp)
	bra.L	alldone
emu2:
	cmpi.w	#2,emu
	bne.s	emu3
	move.w	#8000-1,d1
	bsr	doclear
	move.l	#screena,screen1
	move.l	screen1,screen2
	add.l	#2,screen2
	move.l	screen1,screen3
	move.l	screen2,screen4
	MOVE.L	#VBLANK2,$70	;and new vbl
	move.l	(sp)+,d6
	add.l	#32000+prgsize,d6
	move.l	d6,-(sp)
	bra.s	alldone
emu3:
	move.w	#8000-1,d1
	bsr	doclear
	dc.w	$a000
	sub.l	#$258,a0
	move.l	a0,myad
	move.l	#screena,screen1
	move.l	screen1,screen2
	MOVE.L	#VBLANK3,$70	;and new vbl
	move.l	(sp)+,d6
	add.l	#32000+prgsize,d6
	move.l	d6,-(sp)
*	bra.s	alldone

alldone:
	MOVE.L	#XBIOS,$B8	;put my trap catch
	MOVE.L	SAVESTACK,-(A7)
	MOVE.W	#$20,-(A7)
	TRAP	#1
	ADDQ.L	#6,A7		;back to user
*illegal
	MOVE.L	(A7)+,D0	;that d6 thing
	CLR.W	-(A7)		;no error code
	MOVE.L	D0,-(A7)	;protect this much
	MOVE.W	#$31,-(A7)	;keep process
	TRAP	#1

doclear:
	lea	screena,a0
	addq.l	#2,a0
	moveq	#-1,d0
*	move.w	#15999,d1
monloop:
	move.w	d0,(a0)+
	addq.l	#2,a0
	dbf	d1,monloop
	rts

create:
	move.w	#$0,-(sp)
	move.l	#info,-(sp)
	move.w	#$3c,-(sp)
	trap	#1
	addq.l	#8,sp
	tst.w	d0
	bmi.s	docn
	move.w	d0,-(sp)	;put the handle on the stack
	bra	cb
docn:
	MOVE.L	#errormsg1,-(A7)	;print my message
	MOVE.W	#9,-(A7)
	TRAP	#1
	ADDQ.L	#6,A7
	move.l	#520000,d0
dl:
	sub.l	#1,d0
	bpl	dl
	bra	bydefault

docn2:
	MOVE.L	#errormsg2,-(A7)	;print my message
	MOVE.W	#9,-(A7)
	TRAP	#1
	ADDQ.L	#6,A7
	move.l	#530000,d0
dl2:
	sub.l	#1,d0
	bpl	dl2
	bra	bydefault

*********************************************************
*	programe says goodbye with a fond farewell	*
*********************************************************
XBIOS:
	MOVEM.L	A1-a2,-(A7)
	MOVE.L	A7,A2
	ADDA.L	#8,A2
	BTST	#5,(A2)
	BNE	NOTUSER
	MOVE.L	USP,A2
	SUBA.L	#6,A2
NOTUSER:
	MOVE.W	6(A2),D0
	CMP.W	#2,D0
	BEQ	PHYSBASE
	CMP.W	#4,D0
	BEQ	GETREZ
	CMP.W	#5,D0
	BNE	NORM_XBIOS
	MOVE.W	#$FFFF,$10(A2)
	MOVE.L	$C(A2),D0
	CMP.L	#$FFFFFFFF,D0
	BEQ	NORM_XBIOS
	MOVE.L	D0,mono1			;get the new address
	move.l	mono1,mono2
	add.l	#modulo,mono2
	MOVE.L	#$FFFFFFFF,$C(A2)
	BRA	NORM_XBIOS
PHYSBASE:
	MOVE.L	MONO1,D0			;return 
	MOVEM.L	(A7)+,A1-a2
	RTE
GETREZ:
	MOVE.W	#2,D0			;tell em its mono
	MOVEM.L	(A7)+,A1-a2
	RTE
NORM_XBIOS:
	MOVEM.L	(A7)+,A1-a2
XBIOSPOKE:
	JMP	$0

VBLANK1:
	MOVEM.L	D0-d7/A0-a6,-(A7)
	move.w	#0,$2bc6	;tell everybody theres no blitter
	subq.w	#1,vdelay
	bpl	noblit
	move.w	userdelay,vdelay
	moveq	#7,d0
	lea	$ff8a00,a3
	lea	$ff8a3c,a2
waitblitset:
	btst	d0,(a2)
	bne.L	noblit
	move.w	#2,src_xinc(a3)
	move.w	#82,src_yinc(a3)
	move.w	#4,dst_xinc(a3)
	move.w	#164,dst_yinc(a3)
	move.w	#40,x_count(a3)
	move.w	#-1,endmask1(a3)
	move.w	#-1,endmask2(a3)
	move.w	#-1,endmask3(a3)
	move.b	#$3,op(a3)
	move.b	#2,hop(a3)
	move.b	#0,skew(a3)
	move.l	screen3,dst_addr(a3)	;set dest address
	move.l	mono1,src_addr(a3)	;*
	move.w	#200,y_count(a3)
	move.b	#%10000000,(a2)
	move.l	mono1,a0
	move.l	mono2,mono1
	move.l	a0,mono2
	move.l	screen3,a0
	move.l	screen4,screen3
	move.l	a0,screen4
noblit:
	move.w	#80,$ff820e
	move.b	screen1+1,$ff8205
	move.b	screen1+2,$ff8207
	move.b	screen1+3,$ff8209
	move.l	screen1,a0
	move.l	screen2,screen1
	move.l	a0,screen2

	MOVE.W	#$0fff,$FF8244
	MOVE.W	#$0,$FF8240
	MOVE.W	#0,$FF8246
	MOVEM.L	(A7)+,D0-d7/A0-a6
VBLANKPOKE1:
	JMP	$0


VBLANK2:
	MOVEM.L	D0-d7/A0-a6,-(A7)
	move.w	#0,$2bc6	;tell everybody theres no blitter
	subq.w	#1,vdelay
	bpl	noblit2
	move.w	userdelay,vdelay
	moveq	#7,d0
	lea	$ff8a00,a3
	lea	$ff8a3c,a2
	btst	d0,(a2)
	bne.L	noblit2
	move.w	#2,src_xinc(a3)
	move.w	#82,src_yinc(a3)
	move.w	#4,dst_xinc(a3)
	move.w	#4,dst_yinc(a3)
	move.w	#40,x_count(a3)
	move.w	#-1,endmask1(a3)
	move.w	#-1,endmask2(a3)
	move.w	#-1,endmask3(a3)
	move.b	#$3,op(a3)
	move.b	#2,hop(a3)
	move.b	#0,skew(a3)
	move.l	screen3,dst_addr(a3)	;set dest address
	move.l	mono1,src_addr(a3)	;*
	move.w	#200,y_count(a3)
	move.b	#%10000000,(a2)
	move.l	mono1,a0
	move.l	mono2,mono1
	move.l	a0,mono2
	move.l	screen3,a0
	move.l	screen4,screen3
	move.l	a0,screen4
noblit2:
	move.w	#0,$ff820e
	move.b	screen1+1,$ff8205
	move.b	screen1+2,$ff8207
	move.b	screen1+3,$ff8209

	MOVE.W	#$0ccc,$FF8244
	MOVE.W	#$0fff,$FF8240
	move.w	#$0ccc,$ff8242
	MOVE.W	#$0000,$FF8246
	MOVEM.L	(A7)+,D0-d7/A0-a6
VBLANKPOKE2:
	JMP	$0

VBLANK3:
	MOVEM.L	D0-d7/A0-a6,-(A7)
	move.w	#0,$2bc6	;tell everybody theres no blitter
	subq.w	#1,vdelay
	bpl	noblit3
	move.w	userdelay,vdelay
	moveq	#7,d0
	lea	$ff8a00,a3
	lea	$ff8a3c,a2
waitblitset3:
	btst	d0,(a2)
	bne.L	noblit3
	move.w	#2,src_xinc(a3)
	move.w	#2,src_yinc(a3)
	move.w	#4,dst_xinc(a3)
	move.w	#4,dst_yinc(a3)
	move.w	#40,x_count(a3)
	move.w	#-1,endmask1(a3)
	move.w	#-1,endmask2(a3)
	move.w	#-1,endmask3(a3)
	move.b	#$3,op(a3)
	move.b	#2,hop(a3)
	move.b	#0,skew(a3)
	move.l	screen1,dst_addr(a3)	;set dest address
	move.l	myad,a0
	move.w	(a0),d0		;get y
	cmpi.w	#100,d0
	bgt.s	wb1
	move.l	mono1,mono2
	bra.s	wb
wb1:
	cmpi.w	#300,d0
	blt.s	wb2
	move.l	mono1,mono2
	add.l	#16000,mono2
	bra.s	wb
wb2:
	move.l	mono1,d1
	sub.w	#100,d0
	mulu	#80,d0
	add.w	d0,d1
	move.l	d1,mono2
wb:
	move.l	mono2,src_addr(a3)	;*
	move.w	#200,y_count(a3)
	move.b	#%10000000,(a2)
noblit3:
	move.w	#0,$ff820e
	move.b	screen1+1,$ff8205
	move.b	screen1+2,$ff8207
	move.b	screen1+3,$ff8209

	MOVE.W	#$0fff,$FF8244
	MOVE.W	#$0,$FF8240
	MOVE.W	#0,$FF8246
	MOVEM.L	(A7)+,D0-d7/A0-a6
VBLANKPOKE3:
	JMP	$0

SIMPLE_VBLANK:
	CLR.W	RASTER_FLAG
	RTE

vdelay:	dc.w	-1
SAVESTACK:
	dc.l	0
MONO1:
	dc.l	0
mono2:
	dc.l	0
screen1:	dc.l	0
screen2:	dc.l	0
screen3:	dc.l	0
screen4:	dc.l	0
RASTER_FLAG:
	dc.w	1
MESSAGE:
	dc.b	$0d,$0a,'STE MONO EMULATOR,(c) T.Barker.',$0d,$0a
	dc.b	'Return for defaults.',$0d,$0a,0
speedmsg:
	dc.b	'What speed would you like (0-9)?',$0d,$0a,0
emumsg:
	dc.b	$0d,$0a,'What type of emulation ?',$0d,$0a
	dc.b	'Interlace (64k+)	1',$0d,$0a
	dc.b	'Aliasing  (32k+)	2',$0d,$0a
	dc.b	'Scrolling (32k+)	3',$0d,$0a,0
hrtzmsg:
	dc.b	$0d,$0a,'What Sync ?',$0d,$0a
	dc.b	'50 Hz		-	1',$0d,$0a
	dc.b	'60 Hz		-	2',$0d,$0a,0
info:
	dc.b	'\auto\mono.inf',0
savemsg:
	dc.b	$0d,$0a,'Do you wish to save these settings ?',$0d,$0a
	dc.b	'(Y/N)',$0d,$0a,0
errormsg1:
	dc.b	$0d,$0a,'ERROR! Could not create info file.',0
errormsg2:
	dc.b	$0d,$0a,'ERROR! Could not save defaults.',0
even
defs:
userdelay:	dc.w	4
emu:		dc.w	1
hrz:		dc.w	2
myad:		dc.l	0
screena:
