; *** BBSave written by Gerson Kurz ***
;
; Size : 632 Bytes !!
;
; Dieser Befehl liest den Bootblock von df0: ein und speichert ihn in einem
; beliebigen File ab. Wenn spaeter mal ein Virus den Bootblock zerstoert,
; kann man den Bootblock mit BBLoad wieder abspeichern...
; -----------------------------------------------------------------
; Zuerst suchen wir uns einen Task fuer unser Trackdiskdevice
; -----------------------------------------------------------------
o:	cmp.b	#1,d0		; Keine Parameter ?
	bls.l	nofile		; Ja, Error !
	movem.l	d0-d3/a0-a4,-(sp); Register sichern
	move.l	4,a6		; Execbase als Basisadr.
	suba.l	a1,a1		; eigener Task
	jsr	-294(a6)	; ExecCall FINDTASK
	move.l	d0,readreply+$10; Zeiger auf eigenen Task
	lea	readreply,a1	; Task herholen
	jsr	-354(a6)	; ExecCall ADDPORT
	movem.l	(sp)+,d0-d3/a0-a4; Register zurueckholen
; -----------------------------------------------------------------
; Filenamen suchen
; -----------------------------------------------------------------
	lea	$60000,a1	; String fuer Filename nach a1
search:	move.b	(a0)+,d1	; Char kopieren
	cmp.b	#$0a,d1		; Return erreicht ?
	beq.s	found		; Ja > Gefunden !
	move.b	d1,(a1)+	; Sonst Char in String kopieren
	bra.s	search		; Weiter nach Return suchen
found:	move.b	#$0,(a1)+	; Nullbyte ans Stringende
; -----------------------------------------------------------------
; Trackdisk oeffnen und Bootblock reinlesen
; -----------------------------------------------------------------
	lea	diskio,a1	; IO-Struktur
	moveq	#0,d0		; df0:
	moveq	#0,d1		; keine Flags
	lea	trackdev,a0	; Trackdisk-Device
	jsr	-444(a6)	; ExecCall OPENDEVICE
	tst.l	d0		; Error ?
	bne.L	error		; Ja, also nichts wie raus hier !
	lea	diskio,a1	; IO-Struktur
	move.l	#readreply,14(A1); Zeiger auf unseren Task
	move	#14,28(a1)	; TDComm. CHangestate (Diskette eingelegt?)
	move.l	4,a6		; Execbase in a6
	jsr	-456(a6)	; ExecCall DOIO
	lea	diskio,a1	; IO-Struktur
	move.l	#readreply,14(A1); Zeiger auf unseren Task
	move	#2,28(a1)	; TDCommand READ
	move.l	#$60080,40(a1)	; Zeiger auf unseren Buffer
	move.l	#1024,36(a1)	; 2 Sektoren einlesen
	move.l	#0,44(a1)	; von Sektor 0 Spur 0
	move.l	4,a6		; Execbase in a6
	jsr	-456(a6)	; ExecCall DOIO
; -----------------------------------------------------------------
; Device und Tasks schliessen
; -----------------------------------------------------------------
	lea	diskio,a1	; IO-Struktur
	move.l	#readreply,14(A1); Zeiger auf unseren Task
	move	#9,28(a1)	; TDCommand TD-MOTOR
	move.l	#0,36(a1)	; Motor ausschalten
	jsr	-456(a6)	; ExecCall DOIO
	lea	readreply,a1	; Task-Struktur
	jsr	-360(a6)	; ExecCall REMOVEPORT
	lea	diskio,a1	; IO-Struktur
	jsr	-450(a6)	; ExecCall CLOSEDEVICE
; -----------------------------------------------------------------
; Mittels AmigaDOS ein File oeffnen und Bootblock abspeichern
; -----------------------------------------------------------------
	bsr.s	init		; Doslibrary oeffnen
	move.l	#$60000,d1	; Zeiger auf den Filenamen
	move.l	#1006,d2	; Modus : NEU
	jsr	-30(a5)		; DosCall OPEN
	move.l	d0,a3		; filehd sichern
	moveq	#10,d3		; 10 Zeichen
	move.l	#filemsg,d2	; 'Saving.'-Message
	jsr	-60(a5)		; DosCall OUTPUT
	jsr	-48(a5)		; DosCall WRITE
	move.l	a3,d1		; Zeiger aufs File
	move.l	#$60080,d2	; Zeiger auf den Bootblock
	move.l	#1024,d3	; 1024 Zeichen ( = 2 Blocks )
	jsr	-48(a5)		; DosCall WRITE
; -----------------------------------------------------------------
; Alles schliessen und Zurueck ins CLI
; -----------------------------------------------------------------
	move.l	a3,d1		; Filehd nach d1
	jsr	-36(a5)		; DosCall CLOSE
close:	move.l 	a5,a1		; Dosbase zurueckholen
	jsr 	-414(a6)	; Und Schliesen..
error:	rts			; Zurueck ins CLI
; -----------------------------------------------------------------
; Subroutine, die die DOS.library oeffnet
; -----------------------------------------------------------------
init:	move.l	4,a6		; Execbase nach a6
	lea	dosname,a1	; dos.library
	jsr	-408(a6)	; ExecCall OPENLIBRARY
	move.l	d0,a5		; Dosbase retten
	rts			; Zurueck
; -----------------------------------------------------------------
; Subroutine, die aufgerufen wird, wenn kein File eingegeben wurde.
; -----------------------------------------------------------------
nofile:	bsr.s	init		; Dos.lib oeffnen
	moveq	#10,d3		; 10 Zeichen
	move.l	#nofilemsg,d2	; 'Bad Args.'-Message
	jsr	-60(a5)		; DosCall OUTPUT
	jsr	-48(a5)		; DosCall WRITE
	bra.s	close		; Zurueck ins CLI
; -----------------------------------------------------------------
; Labels...
; -----------------------------------------------------------------
dosname: dc.b 'dos.library',0
trackdev: dc.b 'trackdisk.device',0
nofilemsg: dc.b "Bad Args",$a,0
filemsg: dc.b "Saving..",$a,0
even
diskio: blk.l 20,0
readreply: blk.l 8,0
