*** SpeedRamsey.asm - A fifteen minutes hack - © 1993 Holger Lubitz
***
***                   Started  Thursday 12-Aug-93 20:24:02 CES
*** Version 1.0       Finished Thursday 12-Aug-93 20:36:21 CES
*** Version 1.1	      Finished Friday   13-Aug-93 10:16:53 CES
*** Version 1.2       Finished Monday   16-Aug-93 23:14:10 CES
***
*** Sets the skip mode bit in the Rev G Ramsey
***
*** Done due to popular demand on comp.sys.amiga.hardware
*** Use with care! This may crash your Amiga if your RAM is too slow.
*** (60 ns or faster required)
***
*** Messages were now put in, even though I didn't really have time for this
*** There goes another valuable half of an hour :)
***
*** Contact me at hal@caty.north.de if you have got comments on this
*** or if you have improved it
***
*** Free for non-commercial distribution, not for sale

	XREF	_LVOClose
	XREF	_LVOCloseLibrary
	XREF	_LVODelay
	XREF	_LVOForbid
	XREF	_LVOGetMsg
	XREF	_LVOOldOpenLibrary
	XREF	_LVOOpen
	XREF	_LVOOutput
	XREF	_LVOReplyMsg
	XREF	_LVOSupervisor
	XREF	_LVOWaitPort
	XREF	_LVOWrite

_AbsExecBase	= 4
ThisTask	= 276
pr_CLI		= $ac
pr_MsgPort	= $5c
MODE_OLDFILE	= 1005

   SECTION "",CODE

	move.l	_AbsExecBase,a6 ; get Exec
	move.l	ThisTask(a6),a5 ; FindTask(0)

*** Since we now have error messages, we need the DOS-Base, too

        lea	dosname(pc),a1	; Pointer to 'dos.library'
        jsr	_LVOOldOpenLibrary(a6) ; Version doesn't matter
	move.l	d0,a4		; store in a4

*** Have we been started from Workbench or Shell ?

	tst.l	pr_CLI(a5)	; Shell ?
	beq.s	WB		; if not, go to WB startup

*** CLI-Startup
	
	exg	a4,a6		; get DOS-Base
	jsr	_LVOOutput(a6)  ; get Filehandle of Window
	bra.s	main		; to main program

*** WB-Startup

WB:	lea.l	pr_MsgPort(a5),a0 ; wait for
	jsr	_LVOWaitPort(a6) ; WB-Message
	jsr	_LVOGetMsg(a6)	; there it is, get it
	move.l	d0,-(a7)	; save pointer to msg
	lea	fenster(pc),a0  ; window title
	move.l	a0,d1		; to d1
	move.l	#MODE_OLDFILE,d2 ; CON: should exist
	exg	a4,a6		; we need dos now
	jsr	_LVOOpen(a6)	; open window
	tst.l	d0		; check if it worked
	beq.s	wbexit		; we can't proceed if not

main:	
	move.l	d0,d6		; save handle in d6
	lea	text0(pc),a0	; init text
	move.l	a0,d2
	moveq	#text0e-text0,d3
	bsr.s	write

	lea	$de0003,a0	; ramsey configuration register
	move.l	a5,-(a7)	; save a5
	lea	ramsey(pc),a5   ; start of our ramsey routine
	exg	a4,a6		; exec again
	jsr	_LVOSupervisor(a6) ; to be done in Supervisor mode
	exg	a4,a6		; dos again
	cmp.b	#5,d5		; return code 5 ? 
	blt.s	settext		; load settext
	beq.s	resettext	; load resettext
errtxt:	lea	text3(pc),a0    ; load errtext
	move.l	a0,d2
	moveq	#text3e-text3,d3
wrtext:	bsr.s	write

cleanup
	move.l	(a7)+,a5	; restore a5
	tst.l	pr_CLI(a5)	; was it the CLI
	bne.s	closedos1	; quit

	moveq	#127,d1		; 127/50 seconds
	jsr	_LVODelay(a6)	; wait
	move.l	d6,d1		; window
	jsr	_LVOClose(a6) 	; close
wbexit:
	bsr.s	closedos2	; close dos-lib
	jsr	_LVOForbid(a6)	; don't let WB kick us out early
	move.l	(a7)+,a1	; saved msg to a1
	jmp	_LVOReplyMsg(a6) ; and finally answer

closedos1
	move.l	d5,d0		; copy returncode (from CLI only)
closedos2
	move.l	a6,a1                   ; Dos-Base to A1
	move.l  a4,a6			; Exec-Base to A6
	jmp	_LVOCloseLibrary(a6)    ; close it

write
	move.l	d6,d1
	jmp	_LVOWrite(a6)   

settext
	lea	text1(pc),a0
	move.l	a0,d2
	moveq	#text1e-text1,d3
	bra.s	wrtext

resettext
	lea	text2(pc),a0
	move.l	a0,d2
	moveq	#text2e-text2,d3
	bra.s	wrtext

ramsey:	moveq	#$0F,d5		; Version G of Ramsey
	cmp.b   $40(a0),d5	; check for it (version reg @ $DE0043)
	bne.s	exit		; because this is only possible with Rev G
	moveq	#0,d5		; clear error code
	btst	#4,(a0) 	; test the fast mode bit
	beq.s	chg		; if it's 0, then just set it
	moveq	#5,d5		; else set warn code and
chg:	bchg	#4,(a0)		; change it
exit:	rte			; return from Supervisor mode

*** This is the text section

dosname
   dc.b     "dos.library",0
fenster
   dc.b     "CON:0/0/320/80/SpeedRamsey",0

	dc.b	"$VER: "
text0
	dc.b	"SpeedRamsey 1.2a",10,"by Holger Lubitz <hal@caty.north.de>",10,"Rev G Ramsey "
text0e

text1
	dc.b	"set to skip mode.",10
text1e
	
text2
	dc.b	"set to normal mode.",10
text2e

text3
	dc.b	"not found.",10
text3e

	END
