*******************************************
*     Copyright William Lunney Nov 89     *
*******************************************
;Boot-writer V1.0

*****************************************************************************
*   OPEN THE DOS LIBRARY, SETUP THE TRACKDISK.DEVICE AND OPEN THE WINDOW    *
*****************************************************************************
		movea.l	execbase,a6			;Open the DOS library
		lea	dosname,a1
		jsr	openlib(a6)
		move.l	d0,dosbase
		tst.l	d0
		bne.s	opened
		rts			;cant open DOS library

opened		movea.l	execbase,a6		;reserve mem for rootblock buffer
		moveq.l	#chip_ram_only,d1	;I want chip ram ONLY
		move.l	#512,d0		;reserve a size equal to file
		jsr	allocmem(a6)
		move.l	d0,rootblock_buffer
		movea.l	execbase,a6		;reserve mem for bitmap buffer
		move.l	#chip_ram_only,d1	;I want chip ram ONLY
		move.l	#512,d0		;reserve a size equal to file
		jsr	allocmem(a6)
		move.l	d0,bitmap_buffer

		movea.l	execbase,a6	    ;reserve mem for fastmem allocation table
		move.l	#$10000,d1		;fastmem preferebly
		move.l	#4*1000,d0	       ;should be enough in all cases
		jsr	allocmem(a6)		;Space for 500 allocations
		move.l	d0,fastmem_alloc_tab	;(Memsize.l plus address.l)

		movea.l	execbase,a6		;reserve mem for bitmap buffer
		moveq.l	#chip_ram_only,d1	;chip ram ONLY (for TDISK access)
		move.l	#1024,d0	;reserve bootblock size
		jsr	allocmem(a6)
		tst.l	d0
		bne.s	allocation_ok
		bra	finish		;couldnt allocate chip ram so end
allocation_ok	move.l	d0,bootblock_buffer

		movea.l	execbase,a6		;Setup the trackdisk.device etc
		sub.l	a1,a1
		jsr	findtask(a6)
		move.l	d0,readreply+$10
		lea	readreply,a1
		jsr	addport(a6)
		lea	disk_IO_req,a1
		moveq.l	#0,d0			;drive 0
		clr.l	d1
		lea	track_disk,a0
		jsr	opendevice(a6)
		tst.l	d0
		beq.s	device_opened

		movea.l	execbase,a6			;close DOS library ONLY
		movea.l	dosbase,a1
		jsr	closelib(a6)
		rts

device_opened	movea.l	dosbase,a6
		move.l	#window_name,d1		;Open the new window
		move.l	#mode_old,d2
		jsr	open(a6)
		move.l	d0,conhandle
		tst.l	d0
		bne.s	try_again

		movea.l	execbase,a6			;close DOS library
		movea.l	dosbase,a1
		jsr	closelib(a6)
		lea	readreply,a1		;and remove the port
		jsr	remport(a6)
		lea	disk_IO_req,a1		;and the trackdisk device
		jsr	closedevice(a6)
		rts
*****************************************************************************
*      PRINT UP THE FILENAME PROMPT AND GET READY TO ACCEPT THEIR INPUT     *
*****************************************************************************
try_again	move.l	#name_prompt,d2		;Print the filename prompt
		move.l	#name_prompt2-name_prompt,d3
		bsr	print_message
		move.l	conhandle,d1 		;Read in the user input.
		move.l	#filename_buffer,d2
		move.l	#30,d3    		;Filenames max of 30 chars
		jsr	read(a6)
		move.b	d0,string_length
*****************************************************************************
* DO SOME ERROR CHECKS ON THEIR INPUT AND PRINT UP THE APPROPRIATE MESSAGES *
*****************************************************************************
		lea	filename_buffer,a0
		cmpi.l	#'QUIT',(a0)		;Check for user termination
		beq	finish
		cmpi.l	#'quit',(a0)
		beq	finish
		cmpi.l	#'HELP',(a0)
		beq	display_help_page
		cmpi.l	#'help',(a0)
		beq	display_help_page
no_all_is_well	cmpi.b	#1,d0			;Did they just hit return ?
		bne.s	no_its_cool
		move.l	#only_return,d2
		move.l	#only_return2-only_return,d3
		bsr	print_message
		bra	try_again
no_its_cool	cmpi.b	#34,d0			;More than 30 chars entered ?
		blt.s	input_ok
		move.l	#too_many_chars,d2
		move.l	#too_many_chars2-too_many_chars,d3
		bsr	print_message
		bra	try_again
*****************************************************************************
*LOAD THE FILE INTO THE FILE BUFFER (IF IT DOSENT EXIST REPLY WITH AN ERROR)*
*****************************************************************************
input_ok:	lea	filename_buffer,a0
		moveq.l	#0,d0
		move.b	string_length,d0
		subq.b	#1,d0
		clr.b	(a0,d0.w)	;add 0 terminator to user's filename
*****************************************************************************
*			   GET SIZE OF FILE				    *
*****************************************************************************
		movea.l	dosbase,a6	;get file length etc.
		move.w	#-2,d2		;mode=let other tasks read from file
		move.l	#filename_buffer,d1
		jsr	lock(a6)	;get file structure...
		tst.l	d0		;does it exist?
		bne.s	structure_found
		move.l	#file_not_found,d2	;file not found
		move.l	#file_not_found2-file_not_found,d3
		bsr	print_message
		bra	try_again
structure_found	move.l	d0,lockstatus	;save structure key
		movea.l	dosbase,a6
		move.l	lockstatus,d1		;old lock key
		move.l	#fileinfo_block,d2	;blank buffer
		jsr	examine(a6)		;get filesize into buffer etc
		tst.l	d0
		bne.s	exam_ok
		move.l	#unknown_error,d2	;file not found
		move.l	#unknown_error2-unknown_error,d3
		bsr	print_message
		bra	try_again
exam_ok		lea	fileinfo_block,a0
		move.l	124(a0),file_size	;store size of file
		move.l	file_size,d0
		move.l	d0,d3			;FIX DOS 'examine' BUG!!!!!
		andi.l	#%11111111111110000000000000000000,d3
		tst.l	d3
		beq.s	normal_op
		swap	d0
normal_op	move.l	d0,file_size
*****************************************************************************
*			ALLOCATE ALL FASTMEM				    *
*****************************************************************************
allocate_fstmem	movea.l	fastmem_alloc_tab,a5	;kill ALL fastmem
		movea.l	execbase,a6
allocate_all	move.l	#$20004,d1		;biggest chunk of fasmem
		jsr	availmem(a6)
		tst.l	d0			;if no fastmem continue
		beq	got_no_fastmem
		move.l	d0,(a5)+		;size of biggest chunk in D0
		jsr	allocmem(a6)
		tst.l	d0
		beq	got_no_fastmem
		move.l	d0,(a5)+		;address of chunk im D0
		bra.s	allocate_all
*****************************************************************************
*		  LOAD PROGRAM AS A SEGMENT INTO CHIPMEM		    *
*****************************************************************************
got_no_fastmem	move.l	#filename_buffer,d1	;load prog into chipram only
		movea.l	dosbase,a6
		jsr	loadseg(a6)
		tst.l	d0
		bne.s	segment_loaded
errorfound	move.l	#file_not_found,d2	;print an error then ...
		move.l	#file_not_found2-file_not_found,d3
		bsr	print_message
		bra	try_again		;try again.
segment_loaded	move.l	d0,segment_pointer	;preserve for 'unloadseg'
		lsl.l	#2,d0			;are you psycic Baz?
		addq.l	#4,d0
		move.l	d0,segment_address	;store location of program
*****************************************************************************
*		FREE ALL ALLOCATED FASTMEM (IF THERE WAS ANY)		    *
*****************************************************************************
		movea.l	fastmem_alloc_tab,a5	
		movea.l	execbase,a6
deallocate_all	tst.l	(a5)			;end of allocation table?
		beq.s	deallocated_mem
		move.l	(a5)+,d0		;memchunk size in D0
		move.l	(a5)+,a1		;address of chunk in A1
		jsr	freemem(a6)
		bra.s	deallocate_all


*****************************************************************************
** hexadecimal to ASCII convertor.
** will convert one byte to its ASCII equivalent
** d3	the value to convert
** a3	the place to put the result
*****************************************************************************
convex
	move.l d3,d2
	lsr #4,d2
	bsr nibble
	move.b d2,(a3)+
	move d3,d2
	bsr nibble
 	move.b d2,(a3)+
	rts
nibble
	and #$0f,d2
	add #$0030,d2
	cmp #$3a,d2
	bcs ok
	add #7,d2
ok	rts


*****************************************************************************
*   TELL THE USER HIS FILE HAS LOADED, AND TO INSERT THE DESTINATION DISK   *
*****************************************************************************
deallocated_mem	move.l	#load_succesful,d2	;Tell the user his files in!
		move.l	#load_succesful2-load_succesful,d3
		bsr	print_message
		move.l	#display_filesize,d2	;print filesize for user
		move.l	#display_filesize2-display_filesize,d3
		bsr	print_message

		lea	file_size,a0
		lea	ascii_filesize,a3
		moveq.l	#4-1,d7
size_in_buffer	clr.l	d3
		move.b	(a0),d3
		bsr	convex
		add.l	#1,a0
		dbf	d7,size_in_buffer
		move.l	#ascii_filesize,d2
		move.l	#10,d3
		bsr	print_message
		move.l	#bytes,d2	;print filesize for user
		move.l	#bytes2-bytes,d3
		bsr	print_message

		move.l	#stick_in_disk,d2	;and insert the dest. disk
		move.l	#stick_in_disk2-stick_in_disk,d3
		bsr	print_message
		move.l	conhandle,d1 		;wait for return key
		move.l	#dummy_buffer,d2
		move.l	#1,d3    		;1 character only
		jsr	read(a6)
*****************************************************************************
* 		WRITE THEIR FILE OUT TO BLOCK 2 ONWARDS			    *
*****************************************************************************
		move.l	file_size,d0		;WRITE OUT THE PROGRAM
		divu	#512,d0	;get number of sectors
		andi.l	#%00000000000000001111111111111111,d0
		addq.l	#1,d0	;and add 1 for safety
		mulu.w	#512,d0
		move.l	d0,sectors_written
		lea	disk_IO_req,a1	;write out program onto disk
		move.l	#readreply,14(a1)
		move.w	#3,28(a1)	;WRITE command
		movea.l	segment_address,a0
		move.l	a0,40(a1)	;buffer address
		move.l	d0,36(a1)	;length in blocks
		move.l	#2*512,44(a1)	;start block on disk
		movea.l	execbase,a6
		jsr	do_IO_function(a6)
		move.l	disk_IO_req+32,d6
		lea	disk_IO_req,a1
		move.w	#9,28(a1)	;turn off drive motor
		clr.l	36(a1)
		jsr	do_IO_function(a6)
		lea	readreply,a1
		jsr	remport(a6)
*****************************************************************************
*	  READ IN THE ROOT BLOCK (TO GET THE LOCATION OF THE BITMAP)	    *
*****************************************************************************
alright		lea	disk_IO_req,a1		;READ IN THE ROOT BLOCK
		move.l	#readreply,14(a1)
		move.w	#2,28(a1)	;READ command
		move.l	rootblock_buffer,40(a1)	;root block buffer address
		move.l	#1*512,36(a1)	;length in sectors
		move.l	#880*512,44(a1)	;root block at sector 880
		movea.l	execbase,a6
		jsr	do_IO_function(a6)
		move.l	disk_IO_req+32,d6
		lea	disk_IO_req,a1
		move.w	#9,28(a1)	;turn off drive motor
		clr.l	36(a1)
		jsr	do_IO_function(a6)
		lea	readreply,a1
		jsr	remport(a6)
*****************************************************************************
*		   READ THE DISK BITMAP INTO THE BUFFER			    *
*****************************************************************************
		movea.l	rootblock_buffer,a0	;READ IN THE DISK BITMAP
		adda.l	#316,a0			;+316=bitmap location
		move.l	(a0),d0			;shuv it in D0 for tdisk
		mulu.w	#512,d0
		lea	disk_IO_req,a1
		move.l	#readreply,14(a1)
		move.w	#2,28(a1)	;READ command
		move.l	bitmap_buffer,40(a1)	;root block buffer address
		move.l	#1*512,36(a1)	;length in sectors
		move.l	d0,44(a1)	;root block at sector 880
		movea.l	execbase,a6
		jsr	do_IO_function(a6)
		move.l	disk_IO_req+32,d6
		lea	disk_IO_req,a1
		move.w	#9,28(a1)	;turn off drive motor
		clr.l	36(a1)
		jsr	do_IO_function(a6)
		lea	readreply,a1
		jsr	remport(a6)
*****************************************************************************
*		      CALCULATE THE NEW DISK BITMAP			    *
*****************************************************************************
		move.l	file_size,d7   ;work out the number of sectors needed
		divu	#512,d7	       ;to store the program.
		andi.l	#%00000000000000001111111111111111,d7
		addq.l	#1,d7		;D7=no. of bits to set in the bitmap
		movea.l	bitmap_buffer,a0
		adda.l	#4,a0		;skip past checksum
		move.l	(a0),d1		;1 long word of bitmap in D1
		moveq.l	#0,d0		;start at bit 0 (first block)
allocate_bitmap	bclr.l	d0,d1		;allocate a 512 byte chunk
		addq.w	#1,d0		;go to next bit
		cmpi.w	#32,d0
		beq.s	restart_at_0
		dbf	d7,allocate_bitmap	;do the rest of the bits
		move.l	d1,(a0)
		bra.s	next_bit
restart_at_0	moveq.l	#0,d0		;restart at bit 0
		move.l	d1,(a0)		;put modified longword into bitmap
		adda.l	#4,a0		;point to next word in bitmap
		move.l	(a0),d1
		dbf	d7,allocate_bitmap
next_bit	movea.l	bitmap_buffer,a0	;do checksum
		movea.l	a0,a1
		move.w	#$7f,d1
		clr.l	d0
		move.l	d0,(a1)
bitmap_checksum	sub.l	(a0)+,d0
		dbf	d1,bitmap_checksum
		move.l	d0,(a1)			;put in new checksum
*****************************************************************************
*			WRITE OUT THE NEW BITMAP			    *
*****************************************************************************
		movea.l	rootblock_buffer,a0
		adda.l	#316,a0
		move.l	(a0),d0
		mulu.w	#512,d0
		lea	disk_IO_req,a1
		move.l	#readreply,14(a1)
		move.w	#3,28(a1)	;WRITE command
		move.l	bitmap_buffer,40(a1)	;root block buffer address
		move.l	#1*512,36(a1)	;length in sectors
		move.l	d0,44(a1)	;bitmap at block D0
		movea.l	execbase,a6
		jsr	do_IO_function(a6)
		move.l	rootblock_buffer,a0	;recalculate bitmap location
		adda.l	#316,a0			;LAME!!!
		move.l	(a0),d0
		mulu.w	#512,d0
		lea	disk_IO_req,a1
		move.w	#4,28(a1)		;UPDATE command
		move.l	#1*512,36(a1)
		move.l	bitmap_buffer,40(a1)
		move.l	d0,44(a1)
		jsr	do_IO_function(a6)
		move.l	disk_IO_req+32,d6
		lea	disk_IO_req,a1
		move.w	#9,28(a1)	;turn off drive motor
		move.l	#0,36(a1)
		jsr	do_IO_function(a6)
		lea	readreply,a1
		jsr	remport(a6)
*****************************************************************************
*	MODIFY BOOTBUFFER SO AS CORRECT NUMBER OF BLOCKS ARE LOADED	    *
*****************************************************************************
		move.l	sectors_written,d0	;block size*512
		move.l	d0,baz_length1+2	;shuv into bootblock buffer
		move.l	segment_address,baz_start1+2
		move.l	segment_address,baz_execute1+2
*****************************************************************************
*   COPY BOOTBUFFER INTO ALLOCATED CHIPMEM (TO ALLOW FOR TRACKDISK ACCESS)  *
*****************************************************************************
		movea.l	bootblock_buffer,a0
		lea	bootblock1,a1
		move.w	#$ff,d7
transfer_mem	move.l	(a1)+,(a0)+
		dbf	d7,transfer_mem
*****************************************************************************
*	    CALCULATE THE NEW BOOTBLOCK CHECKSUM AND STICK IT IN	    *
*****************************************************************************
		movea.l	bootblock_buffer,a0
		lea	4(a0),a1		;pointer to checksum
		clr.l	(a1)			;zero it
		move.w	#$ff,d7			;256 long words to tally
		clr.l	d0			;tally=0
calculate_loop	add.l	(a0)+,d0		;tally+X
		bcc.s	jump
		addq.l	#1,d0
jump		dbf	d7,calculate_loop
		not.l	d0
		move.l	d0,(a1)			;store new checksum in buffer
*****************************************************************************
*		       WRITE OUT THE NEW BOOTBLOCK			    *
*****************************************************************************
		lea	disk_IO_req,a1
		move.l	#readreply,14(a1)
		move.w	#3,28(a1)		;WRITE command
		move.l	bootblock_buffer,40(a1)	;bootblock buffer address
		move.l	#2*512,36(a1)		;2 sectors in length
		clr.l	44(a1)			;bootblock at block 0
		movea.l	execbase,a6
		jsr	do_IO_function(a6)
		lea	disk_IO_req,a1
		move.w	#4,28(a1)		;UPDATE command
		move.l	#2*512,36(a1)
		move.l	bootblock_buffer,40(a1)
		clr.l	44(a1)
		jsr	do_IO_function(a6)
		move.l	disk_IO_req+32,d6
		lea	disk_IO_req,a1
		move.w	#9,28(a1)	;turn off drive motor
		clr.l	36(a1)
		jsr	do_IO_function(a6)
		lea	readreply,a1
		jsr	remport(a6)
*****************************************************************************
*  END THE PROGRAM BY CLOSING THE TDISK DEVICE, WINDOW AND THE DOS LIBRARY  *
*****************************************************************************
finish		movea.l	execbase,a6		;close the trackdisk.device
		lea	disk_IO_req,a1
		jsr	closedevice(a6)
finish2		movea.l	dosbase,a6	;close the custom window
		move.l	conhandle,d1
		jsr	close(a6)
		movea.l	dosbase,a6
		move.l	segment_pointer,d1
		jsr	unloadseg(a6)
		movea.l	execbase,a6
		movea.l	file_buffer_addr,a1
		move.l	allocated_mem,d0
		jsr	freemem(a6)
		movea.l	execbase,a6
		movea.l	rootblock_buffer,a1
		move.l	#512,d0
		jsr	freemem(a6)
		movea.l	execbase,a6
		movea.l	bitmap_buffer,a1
		move.l	#512,d0
		jsr	freemem(a6)
		movea.l	execbase,a6
		movea.l	bootblock_buffer,a1
		move.l	#1024,d0
		jsr	freemem(a6)
		bra.s	ende

		move.l	#-1,d0
ende		clr.l	d1
		movea.l	dosbase,a6
		jsr	exit(a6)
		movea.l	execbase,a6
		movea.l	dosbase,a1
		jsr	closelib(a6)
error		rts
*****************************************************************************
*			   DISPLAY HELP PAGE				    *
*****************************************************************************
display_help_page:
		move.l	#help_page,d2	;Tell the user his files in!
		move.l	#help_page2-help_page,d3
		bsr	print_message
		move.l	conhandle,d1 		;wait for return key
		move.l	#dummy_buffer,d2
		move.l	#1,d3    		;1 character only
		jsr	read(a6)
		move.l	#clear_screen,d2	;Tell the user his files in!
		move.l	#clear_screen2-clear_screen,d3
		bsr	print_message
		bra	try_again
*****************************************************************************
*									    *
*****************************************************************************
dosname		dc.b	"dos.library",0
		even
filename_buffer	dcb.b	34,0
		even
file_size	dc.l	0
lockstatus	dc.l	0
string_length	dc.w	0
dosbase		dc.l	0
conhandle	dc.l	0
allocated_mem	dc.l	0
file_buffer_addr	dc.l	0
rootblock_buffer	dc.l	0
bitmap_buffer	dc.l	0
bootblock_buffer	dc.l	0
sectors_written	dc.l	0
segment_address	dc.l	0
segment_pointer	dc.l	0
fastmem_alloc_tab	dc.l	0
ascii_filesize	dcb.b	16,0
dummy_buffer	dcb.b	8,0
*****************************************************************************
*			TEXT PRINTING SUBROUTINE			    *
*****************************************************************************
print_message	movea.l	dosbase,a6
		move.l	conhandle,d1	;ENTRY: d2=text start
		jsr	write(a6)		d3=text length
		rts
*****************************************************************************
*			 PROMPT AND WINDOW TEXT				    *
*****************************************************************************
window_name	dc.b	"CON:0/0/640/256/Boot-writer V1.0 by William Lunney.                       -  Access!  -  ",0
		even
name_prompt	dc.b	$9b,"1;32;40m","Filename:  ",$9b,"0;31;40m",0
name_prompt2:
		even
load_succesful	dc.b	$0c,$9b,"1;33;40m","Ok your file has loaded."
		dc.b	$9b,"0;31;40m",$a
load_succesful2:
		even
display_filesize dc.b	$a,$9b,"1;33;40m","Its size is $"
display_filesize2:
		even
bytes		dc.b	" bytes."
		dc.b	$9b,"0;31;40m",$a,$a,$a,$a
bytes2:
		even
stick_in_disk	dc.b	$9b,"1;32;40m","Insert a newly formatted disk in drive 0, then hit return."
		dc.b	$9b,"0;31;40m",$a,$9b,$30,$20,$70,$9b,"0;30;40m"
stick_in_disk2:
*****************************************************************************
*			     HELP PAGE TEXT				    *
*****************************************************************************
help_page:
 dc.b $0c,$9b,"1;33;40m"	;clear screen, set text mode
 dc.b 'When asked for the filename simply enter the drive name follwed by',$a
 dc.b 'the path and the actual filename.  Here are few examples:',$a,$a
 dc.b 'To load a file in the C directory from drive 1 you would enter...',$a
 dc.b $9b,"1;32;40m",'DF1:C/filename',$9b,"1;33;40m",$a
 dc.b 'To load a file from the C directory on the hard disk you would enter...',$a
 dc.b $9b,"1;32;40m",'DH0:C/filename',$9b,"1;33;40m",$a
 dc.b 'To load a file from the root directory of drive 0 just enter...',$a
 dc.b $9b,"1;32;40m",'DF0:filename',$9b,"1;33;40m",$a
 dc.b $a,$a
 dc.b 'Simple eh?, oh and capital letters dont need to be used.',$a
 dc.b $9b,"1;33;40m"
 dc.b 'Press return to leave this page.',$a,$9b,$30,$20,$70,$9b,"0;30;40m"
help_page2:
		even
clear_screen:	dc.b	$0c,$9b,$20,$70
clear_screen2:
		even
*****************************************************************************
*			    ERROR MESSAGES				    *
*****************************************************************************
		even
unknown_error	dc.b	$9b,"3;33;40m","Sorry there seems to be something wrong with this"
		dc.b	"file."
		dc.b	$9b,"0;31;40m",$a
unknown_error2:
		even
only_return	dc.b	$9b,"3;33;40m","How can I load your program if you dont tell me its name?."
		dc.b	$9b,"0;31;40m",$a
only_return2:
		even
too_many_chars	dc.b	$9b,"3;33;40m","DOS filenames can only be a maximum of 30"
		dc.b	" characters, so what are you doing?."
		dc.b	$9b,"0;31;40m",$a
too_many_chars2:
file_not_found	dc.b	$9b,"3;33;40m","File not found.",$a,$9b,"0;31;40m"
		dc.b	$9b,"1;33;40m","Type QUIT if you want to leave the program or...",$a
		dc.b	"HELP if you want some fileloading information."
		dc.b	$9b,"0;31;40m",$a
file_not_found2:
		even
no_memory	dc.b	$a,"Sorry I couldnt allocate that much chip RAM.",$a
		dc.b	$a,"Try doing a cold start.",$a
no_memory2:
		even
*****************************************************************************
*			ROM ROUTINE EQUATES				    *
*****************************************************************************
openlib		equ	-408
closelib	equ	-414
opendevice	equ	-444
closedevice	equ	-450
do_IO_function	equ	-456
findtask	equ	-294
addport		equ	-354
remport		equ	-360
allocmem	equ	-198
freemem		equ	-210
size		equ	124
findresident	equ	-$60
availmem	equ	-216
loadseg		equ	-150
unloadseg	equ	-156
dmacon		equ	$096
custom		equ	$dff000
execbase	equ	4
chip_ram_only	equ	2

open		equ	-30
close		equ	-36
read		equ	-42
write		equ	-48
exit		equ	-144
lock		equ	-84
unlock		equ	-90
examine		equ	-102

mode_old	equ	1005

track_disk	dc.b	"trackdisk.device",0
		even
disk_IO_req	dcb.l	20,0	;diskIO structure
readreply	dcb.l	8,0
		even
fileinfo_block	dcb.l	260,0
*****************************************************************************
*		DIFFERENT BOOTBLOCKS FOR EACH OF THE OPTIONS		    *
*****************************************************************************
bootblock1:
		dc.b 'DOS',0			;DOS marker etc.
		dc.l 0
		dc.l $370
		movem.l a0-a6/d0-d7,-(sp)	;preserve regs (IMPORTANT!)

		movea.l	execbase,a6
		move.w	#2,28(a1)	;read command
baz_length1	move.l	#1*512,36(a1)	;length in blocks (variable)
baz_start1	move.l	#0,40(a1)	;load to segment address (variable)
		move.l	#2*512,44(a1)	;prog always at block 2 onwards
		jsr	do_IO_function(a6)	;load it
		move.w	#%1000001111110000,dmacon+custom
		move.w	#9,28(a1)	;turn off drive motor
		clr.l	36(a1)
		jsr	do_IO_function(a6)
baz_execute1	jsr	$00000

		movem.l (sp)+,a0-a6/d0-d7	;get old values back
		lea 	doslib(pc),a1		;enter the CLI as normal
		jsr	findresident(a6)
		tst.l	d0
		beq.s	boot_error
		movea.l	d0,a0
		movea.l 22(a0),a0
		clr.l 	d0
		rts
boot_error	move.w	#$ff,d0		;Whoops, there seems to be a problem!
		rts			;Signal error and return

doslib		dc.b	"dos.library",0
		even
		dc.b	"Welcome stranger, to the deep dark world of bootblocks.  "
		dc.b	"Im just a plain old boot loader, "
		dc.b	"nothing more, nothing less.  So please dont kill "
		dc.b	"me.  Bootblocks have a right to life as well you "
		dc.b	"know!."
		dcb.b	800,0
