900	!This program simply copies a floppy to/from
	!a VAX file. The copy is done a physical sector
	!at a time.
	!Logical I/O privileges are required.
	print "FLOPPY  V1.1"

1000	declare long sys_status, phy_address, msglen
	declare word floppy_chan
	external long function sys$assign, sys$qiow, sys$dassgn, sys$getmsg
	external long constant io$_readpblk, io$_writepblk, ss$_normal
	phase%=1%
	map (dmpmap) buffer$( 3% ) = 128%
	sys_status=sys$assign("_CSA1:" by desc,floppy_chan by ref,,)
	goto 4000 unless sys_status=ss$_normal
	linput "Copy 'TO' or 'FROM' the floppy (_CSA1:) ";cmd$
	cmd$=edit$(cmd$,-1%)
	if cmd$="TO" then
	    linput "Name of data file to copy onto floppy ";file$
	    open file$ for input as file 3%, &
		access read, organization virtual, &
		map dmpmap, recordtype none, filesize 501
	    buffer%=3%
	 else
	  if cmd$="FROM" then
	    linput "Name of new file for dump of floppy ";file$
	    open file$ for output as file 3%, &
		access write, organization virtual, &
		map dmpmap, recordtype none, filesize 501
	    buffer%=0%
	  else
	    print "Unknown command....aborting"
	    goto 32767

1500	phase%=2%
	  for cyl%=0% to 76%
	    for sect%=1% to 26%
	    phy_address = cyl%*65536% + sect%
	    if cmd$="FROM" then
		gosub 5000
	     else
		gosub 6000

3000	    next sect%
	  next cyl%
	phase%=3%
	put #3%  if buffer%<4% and cmd$="FROM"
	close 3%
	sys_status=sys$dassgn(floppy_chan by value)
	goto 32767 if sys_status=ss$_normal

4000	print "System error: ";sys_status;" at phase ";phase%
	message$ = space$( 256% )
	sys_status=sys$getmsg(sys_status by value, &
		msglen by ref, message$ by desc, &
		15% by value, )
	print left(message$,msglen)
	print "aborting..."
	goto 32767

5000	!read floppy routine.
	sys_status = sys$qiow(, floppy_chan by value, &
		io$_readpblk by value, , , , buffer$(buffer%) by ref, &
		128% by value, phy_address by value, , , )
	goto 4000 unless sys_status=ss$_normal
	buffer% = buffer% + 1%
	if buffer%>3% then
		put #3%
		buffer%=0%

5100	return

6000	buffer% = buffer% + 1%	!write floppy routine.
	if buffer%>3% then
		get #3%
		buffer%=0%

6100	sys_status = sys$qiow(, floppy_chan by value, &
		io$_writepblk by value, , , , buffer$(buffer%) by ref, &
		128% by value, phy_address by value, , , )
	goto 4000 unless sys_status=ss$_normal
	return

32767	end
