***	Corrige un bug dans getrez (Xbios 4)

***	.PRG a mettre en AUTO


	include	gemdos.i
	include	bios.i
	include	xbios.i
	
	text
	
***	Startup code

Start
	move.l	4(a7),a3		Get Basepage
	move.l	12(a3),d0		Get Text size
	add.w	#256,d0			Plus Basepage
	lea.l	Stack,sp
	move.l	d0,d7			Save this value
	move.l	d0,-(sp)
	move.l	a3,-(sp)
	clr.w	-(sp)
	move.w	#m_shrink,-(sp)		Do Mshrink
	trap	#1
	lea.l	12(sp),sp
	
***	Exchanges trap #14 vector.

	pea.l	New_trp
	move.w	#46,-(sp)		Trap #14 vector number
	move.w	#setexc,-(sp)
	trap	#13			Bios setexec
	addq.l	#8,sp
	move.l	d0,Old_trp		Save old value

***	Display message and terminates.

	pea.l	message
	move.w	#c_conws,-(sp)
	trap	#1
	addq.l	#6,sp
	
	clr.w	-(sp)			Terminates
	move.l	d7,-(sp)		Keep all memory shrunk
	move.w	#p_termres,-(sp)
	trap	#1
	
***	Constants and stack

Old_trp	ds.l	1
Usr_stk	ds.l	1
	ds.l	31
Stack	ds.l	1

***	Permanent part

New_trp
	lea.l	8(sp),a0		a0 points to 1st parameter
	move.w	(sp),d0			Test S bit in frame
	btst.l	#13,d0			Was it set ?
	bne.s	.super			Yes, it's correct
	move.l	usp,a0			Else get user stack
.super
	move.w	(a0),d0			Examine call number
	cmpi.w	#getrez,d0
	beq.s	Vid_new			Getrez : modifies value
	movea.l	Old_trp,a0
	jmp	(a0)			Otherwise branch to old handler
	
Vid_new
	move.w	#$ffff,-(sp)		Get video mode
	move.w	#vsetmode,-(sp)
	trap	#14
	addq.l	#4,sp
	andi.b	#$8f,d0			Mask unused flags
	cmpi.b	#%10001000,d0		St high ?
	bne.s	.v1
	moveq.l	#2,d0
	rte
.v1
	cmpi.b	#%10001001,d0		St medium ?
	bne.s	.v2
	moveq.l	#1,d0
	rte
.v2
	cmpi.b	#%10000010,d0		St low ?
	bne.s	.v3
	moveq.l	#0,d0
	rte
.v3
	cmpi.b	#%00001010,d0		TT medium ?
	bne.s	.v4
	moveq.l	#4,d0
	rte
.v4
	cmpi.b	#%00000011,d0		TT low ?
	bne.s	.v5
	moveq.l	#7,d0
	rte
.v5
	moveq.l	#5,d0			Returns unknown.
	rte
	
	
***	Le message !

message	dc.b	'GETREZ patch V 0.0 installed',10,13,00

***	that's all !!!

	end