ùúùú  k                                    * Includes, info finder....
* Coded by Si\k in idle moments... '94
* $VER: 1.0

WriteLn	MACRO			; Writes \1 to screen and newlines it
	move.l	#\1,a1
	bsr	WLAscii
	ENDM

Write	MACRO			; Write text
	move.l	#\1,a1
	bsr	WAscii
	ENDM

	incdir	include:
	include	exec/exec.i
	include lvo3.0/exec_lib.i
	include	dos/dos.i
	include	lvo3.0/dos_lib.i
	incdir	standard:
	include	macros.s
	include	equates.s

	section	main,code	; Where all the action happens...

	bra	lard
	text
	Ho hum, Digital present another silly little patch for another demo 
	this time - Anarchy's 3D Demo II - Well I guess old Hannibal didn't
	want us to see what happens to vector space on faster machines...
	blitter timings ARE fun...  Enough...  come to the Digital Symposium '95
	 in the UK - more details from silk@dcs.warwick.ac.uk - or call:
	+44 (0)1462 491553 and ask for Rob - it's on the 21st of October, be there
	or... don't.   Digital, The Dog's Bollox
	etext
	even
lard

	bsr	Initialise	; opens dos etc...
	bne.w	Fatal_error	; couldn't even open dos so die...

	bsr	exists		; does the file exist ?
	cmp.w	#0,d0
	bne.w	.endit

	bsr	dochange
	cmp.w	#0,d0
	bne.s	.dead
	writeln	Success
	bra	.dead

.endit	writeln	Usage_Text
.dead	move.l	#0,Returncode
	bra	Close_Down	; End of program


Initialise			; Opens dos, return <>0 if error occured
	move.l	#doslib,a1	; open dos
	move.l	#0,d0		; version number
	callexec OpenLibrary	; .
	cmp.l	#0,d0		; open okay ?
	beq.s	.couldnt_open_dos
	move.l	d0,_Dosbase	; yes so store dosbase
	moveq	#0,d0		; no error
	rts

.couldnt_open_dos		; Handle error opening library
	moveq	#1,d0		; error val
	rts			


Close_Down			; Closes down dos
	move.l	_Dosbase,a1	; close dos
	callexec CloseLibrary	; .
	move.l	Returncode,d0	; terminated ok...
	rts

Fatal_Error			; Comes here if dos could not be opened
	moveq	#-1,d0		; HELP
	rts			; end... maybe.....

WLAscii	; This routine will write and asciiz string to default output and cr 
	; a0 already points to string

	bsr	WAscii		; Normal write...

	move.l	d4,d1		; restore standard output..
	move.l	#newline,d2	; newline buffer
	moveq	#1,d3		; length one
	calldos write		; do a newline

	rts

WAscii	; Write out an asciiz string, pointed to by a1

	calldos	output		; get default output

	move.l	d0,d1		; file...
	move.l	d0,d4		; store it
	move.l	a1,d2		; output data....

.loop	cmp.b	#0,(a1)+	; find end of string
	bne.s	.loop		; .

	move.l	a1,d3		; get final point
	sub.l	d2,d3		; subtract initial point
	sub.l	d3,a1		; restore initial a0
	sub.l	#1,d3		; coz we still have 0 invlolved
	calldos	write		; and write it
	rts


exists				; see if file exists
	move.l	#DemoName,d1	; File to lock
	move.l	#Access_Read,d2	; 
	calldos	Lock	

	cmp.l	#0,d0		; failed
	beq.s	.Doesnt_Exist	; so file does not exist

	move.l	d0,d1		; get lock
	calldos	UnLock		; and remove it

	move.l	#DemoName,d1
	move.l	#MODE_OLDFILE,d2
	calldos	Open		; open file
	move.l	d0,Demofile
	move.l	#0,d0
	rts

.Doesnt_Exist			; Oops, file not found
	Write	DemoName
	WriteLn	File_Not_Found
	move.l	Demofile,d1	; get handle
	calldos	Close		; so we can close the input file
	move.l	#1,d0
	rts			; end of program


dochange
	move.l	Demofile,d1
	move.l	#44842,d2
	move.l	#OFFSET_BEGINNING,d3
	calldos	Seek		; move to appropriate position

	move.l	Demofile,d1
	move.l	#inputbuffer,d2
	move.l	#8,d3
	calldos	Read	
	move.l	#inputbuffer,a0
	move.l	originalcode,d0
	cmp.l	(a0)+,d0
	bne.s	.comparefailed
	move.l	originalcode+4,d0
	cmp.l	(a0),d0
	bne.s	.comparefailed

	move.l	Demofile,d1
	move.l	#44842,d2
	move.l	#OFFSET_BEGINNING,d3
	calldos	Seek		; move to appropriate position

	move.b	#$60,inputbuffer	; jmp, not jle....

	move.l	Demofile,d1
	move.l	#inputbuffer,d2
	move.l	#1,d3
	calldos	Write		; update file
	move.l	#0,ReturnCode
	move.l	Demofile,d1	; get handle
	calldos	Close		; so we can close the input file

	rts	

.comparefailed
	writeln	comparefailed
	move.l	Demofile,d1	; get handle
	calldos	Close		; so we can close the input file
	move.l	#-1,d0
	rts
	
	
	section	main_data,data

_Dosbase		dc.l	0
Doslib			DOSNAME		; from Dos.I
Returncode		dc.l	0

Demofile		dc.l	0
InputBuffer		dcb.b	10,0	; For each line from the input file

	section	Text_Data,data

originalcode	dc.b	$6a,$00,$02,$3c,$2d,$7c,$00,$00
Demoname	dc.b	'har vi røget hash?',0
File_Not_Found	dc.b	' Was not found.',$a,$a,0
Usage_Text	dc.b	'3D Demo II - Anarchy',$a,$a
		dc.b	'Accelerator check removal - Silk / Digital',$a,$a
		dc.b	'Make sure the file:',$a
		dc.b	'har vi røget hash?',$a
		dc.b	'is in the current directory',$a,$a
		dc.b	'Please keep a backup copy of this file just for safety',$a,0
Success		dc.b	'3D Demo 2 by Anarchy has been succesfully patched',$a
		dc.b	'--- Cpu speed check removed ---',$a
		dc.b	'Silk/Digital',$a,$a
		dc.b	'silk@dcs.warwick.ac.uk',$a
		dc.b	'Version 0.5',$a,0
comparefailed	dc.b	'Screwup - your Har vi røget hash? file is different to mine!',$a
		dc.b	$a,'This program will patch version 2.01 - no others!',$a
		dc.b	0
newline		dc.b	$a

	printt	"Don't forget about the debug Command line.."
