/---------------------wps004.ma-----------------------------
.NOLIST
.INCLUDE SMAC4.MA
.LIST
VSIZE,	1			/SIZE OF THE WPS004 VOLUME IN BLOCKS
DEVNUM,	0			/DEVICE NUMBER FOR RX50
SECPTR,	0			/POINTER INTO ILVTAB

.ZERO

*200

	HLT


/ The purpose of this program is dump block 0 of file file WPSYSTEM into
/ an os278 file called wps004.dt.


	.STSTK STACK+177 STACK+77


	.STPNT


	.CAN (QUIT

NEWPAG

/ FIRST, OPEN THE MENU FILE

	.RD 0 (VDAT
	JMS CHKRD

/ FETCH THE RX50 HANDLER.

	CLA
	CIF 10
	JMS 7700
	1
FTC1,	DEVICE RX51
FTC3,	RXHND+1
	JMP	FTCERR		/ERROR RETURN

	CLA
	TAD FTC1+1
	DCA DEVNUM

NEWPAG


/ NOW, OPEN A TENTATIVE FILE OF THE APPROPRIATE SIZE ON THE RX50.

	CLA CLL
	TAD VSIZE
	CLL RAL
	CLL RAL
	CLL RAL
	CLL RAL
	TAD DEVNUM
	CIF 10
	JMS 7700
	3				/"ENTER" FUNCTION
SBLK,	FNAME				/GETS REPLACED WITH STARTING BLOCK
FLEN,	0				/REPLACED WITH -LEN
	JMP ERROR

/ NOW, CONVERT SBLK TO TRACK, SECTOR!!!
/ FIGURE THERE ARE 10 SECTORS PER TRACK
/ SUBTRACT 10 TIL TRACK <= 10.

	CLA
	TAD SBLK
	DCA R0
	DCA R1

	LOOP
	  UNTIL <LT R0 (10.>
	  CLA
	  TAD R0
	  SUB (10.
	  DCA R0
	  ISZ R1			/R1=TRACK
	REPEAT
NEWPAG

	TAD R1
	IAC				/BLOCK ZERO IS ON TRACK 1
	DCA RXLOC+1
	TAD R0				/DETERMINE SECTOR FROM INTERLEAVE
	TAD (ILVTAB			/TABLE
	DCA SECPTR


/ NOW, COPY 1 BLOCK FROM THE HARD DISK TO THE RX50 FILE.

	CLA
	DCA VBLK+1
	DCA VBLK+2


	  / FIRST, READ A BLOCK FROM THE HARD DISK VOLUME (8BIT)
	  .RD 1 (VBLK		/SET BLOCK
	  .RD 4			/READ	  	
	  .RD 125 (BUFFER	/EMPTY BUFFER 8-BIT

	  / NOW, WRITE A BLOCK TO THE FLOPPY (8BIT).
	  .RX50 FILL8 (BUFFER

	  CLA
	  TAD I SECPTR
	  DCA RXLOC+2

	  .RX50 WRITE (RXLOC
	  IF <RX ERROR>
	    JMP WRTERR
	  ENDIF

/ NOW, CLOSE THE TENTATIVE FILE, MAKING IT A PERMAMENT FILE.


	CLA
	TAD VSIZE
	DCA TOTBLK

	TAD DEVNUM			/PUT DEVICE# IN ACC
	CIF 10
	JMS 7700
	4			/CLOSE FUNCTION
	FNAME
TOTBLK,	0			/#OF BLOCKS
	JMP CLSERR		/ERROR RETURN

QUIT,
	MONITR			/ALL DONE

PAGE

/--------------------------------------------------------------------
RXHND,	ZBLOCK 400
STACK,	ZBLOCK 200



ERROR,	HLT

PAGE
VDAT,	0306				/OPEN ON VOLUME 6
	ATEXT <"WPSYSTEM">
VDATA,	ZBLOCK 24.
VBLK,	6; 0 ; 0
RXLOC,	1 ; 0 ; 0			/DRIVE, TRACK, SECTOR
ILVTAB,	1 ; 3 ; 5 ; 7 ; 9. ; 2 ; 4 ; 6 ; 8. ; 10.
FNAME,	FILENAME WPS004.DT

ENTERR,	ATYPE <"ERROR! Couldn't allocate WPS004.DT file.!">
	MONITR
PAGE
CLSERR,	ATYPE <"ERROR! Couldn't close WPS004.DT file.!">
	MONITR
PAGE
WRTERR,	ATYPE <"ERROR! Couldn't write to WPS004.DT file.!">
	MONITR
PAGE
FTCERR,	ATYPE <"ERROR! Couldn't fetch the system handler.!">
	MONITR
PAGE
CHKRD,	0
	IF <RD ERROR>
	  .RD 27 (ERRNO
	  PUTOCT (ERRNO
	ENDIF
	JMP I CHKRD
ERRNO, 0
PAGE
BUFFER, ZBLOCK 512.

