head     56.3;
access   paws bayes jws quist brad dew jwh;
symbols  ;
locks    ; strict;
comment  @# @;


56.3
date     93.01.27.13.22.30;  author jwh;  state Exp;
branches ;
next     56.2;

56.2
date     93.01.27.12.02.37;  author jwh;  state Exp;
branches ;
next     56.1;

56.1
date     91.11.05.09.58.04;  author jwh;  state Exp;
branches ;
next     55.1;

55.1
date     91.08.25.10.33.15;  author jwh;  state Exp;
branches ;
next     54.3;

54.3
date     91.08.21.12.39.51;  author jwh;  state Exp;
branches ;
next     54.2;

54.2
date     91.08.21.09.52.02;  author jwh;  state Exp;
branches ;
next     54.1;

54.1
date     91.03.18.15.33.55;  author jwh;  state Exp;
branches ;
next     53.1;

53.1
date     91.03.11.19.33.46;  author jwh;  state Exp;
branches ;
next     52.1;

52.1
date     91.02.19.09.19.54;  author jwh;  state Exp;
branches ;
next     51.1;

51.1
date     91.01.30.16.18.20;  author jwh;  state Exp;
branches ;
next     50.1;

50.1
date     90.10.29.16.32.17;  author jwh;  state Exp;
branches ;
next     49.1;

49.1
date     90.08.14.14.16.03;  author jwh;  state Exp;
branches ;
next     48.1;

48.1
date     90.07.26.11.22.34;  author jwh;  state Exp;
branches ;
next     47.1;

47.1
date     90.05.14.11.08.17;  author dew;  state Exp;
branches ;
next     46.1;

46.1
date     90.05.07.08.55.05;  author jwh;  state Exp;
branches ;
next     45.1;

45.1
date     90.04.19.16.03.18;  author jwh;  state Exp;
branches ;
next     44.1;

44.1
date     90.04.01.22.20.22;  author jwh;  state Exp;
branches ;
next     43.1;

43.1
date     90.03.20.14.13.13;  author jwh;  state Exp;
branches ;
next     42.1;

42.1
date     90.01.23.17.57.13;  author jwh;  state Exp;
branches ;
next     41.1;

41.1
date     89.12.22.11.39.14;  author jwh;  state Exp;
branches ;
next     40.1;

40.1
date     89.09.29.12.00.17;  author jwh;  state Exp;
branches ;
next     39.1;

39.1
date     89.09.26.16.45.08;  author dew;  state Exp;
branches ;
next     38.1;

38.1
date     89.08.29.11.37.29;  author jwh;  state Exp;
branches ;
next     37.1;

37.1
date     89.05.12.11.51.03;  author dew;  state Exp;
branches ;
next     36.1;

36.1
date     89.02.06.10.28.28;  author dew;  state Exp;
branches ;
next     35.1;

35.1
date     89.02.02.13.45.13;  author dew;  state Exp;
branches ;
next     34.1;

34.1
date     89.01.23.16.19.43;  author jwh;  state Exp;
branches ;
next     33.1;

33.1
date     89.01.16.11.50.43;  author dew;  state Exp;
branches ;
next     32.1;

32.1
date     89.01.10.12.00.39;  author bayes;  state Exp;
branches ;
next     31.1;

31.1
date     88.12.14.18.21.31;  author bayes;  state Exp;
branches ;
next     30.1;

30.1
date     88.12.09.13.58.14;  author dew;  state Exp;
branches ;
next     29.1;

29.1
date     88.10.31.15.42.54;  author bayes;  state Exp;
branches ;
next     28.1;

28.1
date     88.10.06.11.08.44;  author dew;  state Exp;
branches ;
next     27.1;

27.1
date     88.09.29.11.52.12;  author bayes;  state Exp;
branches ;
next     26.1;

26.1
date     88.09.28.14.03.13;  author bayes;  state Exp;
branches ;
next     25.1;

25.1
date     88.03.02.09.47.34;  author bayes;  state Exp;
branches ;
next     24.1;

24.1
date     87.08.31.10.20.37;  author jws;  state Exp;
branches ;
next     23.1;

23.1
date     87.08.26.11.07.20;  author bayes;  state Exp;
branches ;
next     22.1;

22.1
date     87.08.17.11.46.36;  author bayes;  state Exp;
branches ;
next     21.1;

21.1
date     87.08.12.14.31.20;  author bayes;  state Exp;
branches ;
next     20.1;

20.1
date     87.07.30.11.42.36;  author bayes;  state Exp;
branches ;
next     19.1;

19.1
date     87.06.01.08.56.46;  author jws;  state Exp;
branches ;
next     18.1;

18.1
date     87.05.20.16.01.17;  author bayes;  state Exp;
branches ;
next     17.1;

17.1
date     87.04.30.11.04.57;  author jws;  state Exp;
branches ;
next     16.1;

16.1
date     87.04.26.16.15.00;  author jws;  state Exp;
branches ;
next     15.1;

15.1
date     87.04.13.09.56.51;  author jws;  state Exp;
branches ;
next     14.1;

14.1
date     87.04.01.16.08.00;  author jws;  state Exp;
branches ;
next     13.1;

13.1
date     87.02.28.18.57.47;  author jws;  state Exp;
branches ;
next     12.1;

12.1
date     87.02.02.13.51.54;  author jws;  state Exp;
branches ;
next     11.1;

11.1
date     87.01.19.10.18.26;  author jws;  state Exp;
branches ;
next     10.1;

10.1
date     86.12.24.11.33.48;  author jws;  state Exp;
branches ;
next     9.1;

9.1
date     86.12.12.15.18.34;  author bayes;  state Exp;
branches ;
next     8.1;

8.1
date     86.11.27.12.26.46;  author jws;  state Exp;
branches ;
next     7.1;

7.1
date     86.11.20.14.42.21;  author hal;  state Exp;
branches ;
next     6.1;

6.1
date     86.11.04.18.32.12;  author paws;  state Exp;
branches ;
next     5.1;

5.1
date     86.10.28.17.22.00;  author hal;  state Exp;
branches ;
next     4.1;

4.1
date     86.09.30.20.15.57;  author hal;  state Exp;
branches ;
next     3.1;

3.1
date     86.09.01.12.38.12;  author hal;  state Exp;
branches ;
next     2.1;

2.1
date     86.07.30.15.16.08;  author hal;  state Exp;
branches ;
next     1.1;

1.1
date     86.06.30.17.04.45;  author danm;  state tmp;
branches ;
next     ;


desc
@Base file for PWS 3.2 release.

@


56.3
log
@
pws2rcs automatic delta on Wed Jan 27 13:14:25 MST 1993
@
text
@ ttl Fminit - 9885 initialization routine


	rorg    0
	nosyms


*************************************************
*            PASCAL module interface            *
*************************************************

 src    module Fminit;
 src
 src    import
 src      sysglobals,
 src      midecs;
 src
 src    export
 src      function Fintdata: interleave_data;
 src      function Fphydata: physical_data;
 src      procedure Fminitialize(port: charptr; un: byte; intlve: shortint);
 src
 src    end;

*
* def's
*
	def     Fminit_Fminit       module intialization routine
	def     Fminit_Fintdata     interleave factor data function
	def     Fminit_Fphydata     physical attributes data function
	def     Fminit_Fminitialize 9885 formatting routine

*
* ref's
*
	refa    sysglobals

*
* module intialization routine
*
Fminit_Fminit   rts

	page

*************************************************
*                  functions                    *
*************************************************

*
* interleave factor data function
*
intdata dc      1       minimum interleave factor
	dc      29      maximum interleave factor
	dc      1       default interleave factor

Fminit_Fintdata equ *
	movea.l (sp)+,a0                return address
	movea.l (sp)+,a1                return variable address
	movem   intdata,d0-d2           interleave_data record constant
	movem   d0-d2,(a1)              assign the return variable
	jmp     (a0)                    return



*
* physical attributes data function
*
phydata dc.l    67-4    number of tracks per surface
	dc.l    1       number of surfaces per media
	dc.l    30      number of sectors per track

Fminit_Fphydata equ *
	movea.l (sp)+,a0                return address
	movea.l (sp)+,a1                return variable address
	movem.l phydata,d0-d2           interleave_data record constant
	movem.l d0-d2,(a1)              assign the return variable
	jmp     (a0)                    return

	page

*************************************************
*      passed parameters & local variables      *
*************************************************

*
* local variables
*
locals  equ     -342                    total local area size

v85buf  equ     -342        (256 bytes) read/write buffer

v85ibuf equ     -86         (62 bytes)  interleave buffer

v85lrp  equ     -24         (long)      logical record pointer
v85lrso equ     -20         (long)      logical record spiral offset

v85r29o equ     -16         (word)      logical record 29 offset
v85frec equ     -14         (word)      first record
v85lr0  equ     -12         (word)      this track's logical record 0
v85scmd equ     -10         (word)      skeleton command
v85stat equ     -8          (word)      status word

v85rc   equ     -6          (byte)      record count
v85rwf  equ     -5          (byte)      read/write flag
v85gtc  equ     -4          (byte)      good track count
v85btc  equ     -3          (byte)      bad track count
v85patc equ     -2          (byte)      test pattern count
v85gdcb equ     -1          (byte)      gpio dma control byte

*
* passed parameters
*
olda6   equ     0           (long)      dynamic link
retaddr equ     4           (long)      return address
intlve  equ     8           (word)      interleave factor
un      equ     10          (word)      unit number
port    equ     12          (long)      card port address

	page

*************************************************
*                 escape sequences              *
*************************************************

*
* assignment of ioresult values
*
ior_notGPIO     equ     16      (znodevice)             card is not GPIO
ior_not9885     equ     16      (znodevice)             peripheral is not 9885
ior_mediachange equ     46      (zmediumchanged)        media has been changed
ior_initfailed  equ     17      (zinitfail)             initialization failed
ior_catchall    equ     21      (zcatchall)             error undetermined

*
* 9885 error code mapping to ioresult values
*
f85ecm  dc.b    21  (zcatchall)         (0)     no error
	dc.b    16  (znodevice)         (1)     not all drives powered
	dc.b    34  (znomedium)         (2)     door open
	dc.b    34  (znomedium)         (3)     no disc in drive
	dc.b    18  (zprotected)        (4)     badcommand (write protected)
	dc.b    32  (znoblock)          (5)     record header error
	dc.b    32  (znoblock)          (6)     track not found
	dc.b     1  (zbadblock)         (7)     data checkword error
	dc.b    20  (zbadhardware)      (8)     data overrun
	dc.b     1  (zbadblock)         (9)     verify failed

*
* subroutine ioresult escape: enter with ioresult in d0.l
*
ioresc  move.l  d0,sysglobals-22(a5)    store the ioresult
	move    #-10,sysglobals-2(a5)   store the escapecode
	trap    #10                     escape a'la' Pascal

*
* subroutine decode and issue the error code
*
f85die  moveq   #0,d1                   clear upper byte for word indexing
	move.b  v85stat(a6),d1          9885 error code

	moveq   #ior_catchall,d0        ioresult in case error code is out of range
	cmp     #9,d1                   is the error code within the expected range?
	bhi     ioresc                  branch if not

	move.b  f85ecm(d1),d0           load the appropriate ioresult value
	bra     ioresc                  escape with the bad ioresult

	page

**********************************************************************
*                gpio interface card switch settings                 *
**********************************************************************

*            option switches

*    1) invert pclt             open
*    2) invert pflg             open
*    3) invert psts             open
*    4) full/pulse handshake    open
*    5) invert data in          open
*    6) invert data out         open


*          data clock switches

*    1) read                    open             \
*    2) ready to busy                 closed       lower data register
*    3) busy to ready           open             /
*    4) read                    open             \
*    5) ready to busy                 closed       upper data register
*    6) busy to ready           open             /


*    select code switches: 0-31; default 1


*    interrupt priority switches: don't cares; default 0

	page

**********************************************************************
*                                                                    *
* basic program flow is as follows:                                  *
*                                                                    *
*  Generate the interleave buffer containing the logical record      *
*  number sequences.                                                 *
*                                                                    *
*  Reset dumbo to force a "seek" to physical track 0.                *
*                                                                    *
*  Format & test the current track. If the track is good, increment  *
*  the good track count. If not, increment the bad track count and   *
*  make the bad track invisible. Step the heads in one track. Repeat *
*  until all 67 tracks have been processed.                          *
*                                                                    *
*  Reset dumbo again.                                                *
*                                                                    *
*  If more than 4 tracks were bad, issue an error.                   *
*                                                                    *
**********************************************************************



**********************************************************************
*                                                                    *
* procedure for formatting and testing one track                     *
*                                                                    *
*   1. Format the track with the sequence of logical record numbers  *
*      appropriate for the specified interleave factor.              *
*                                                                    *
*   2. With tight margins read back the data written by the format.  *
*      Write & read back under tight margins 3 other test patterns.  *
*      Write 0's to all records.                                     *
*                                                                    *
*   3. If the track had no errors, increment the good track count.   *
*      Else increment the bad track count and make the (bad) track   *
*      invisible.                                                    *
*                                                                    *
**********************************************************************

	page

**********************************************************************
*                          format the media                          *
**********************************************************************

*
* preliminary setup & checks
*
Fminit_Fminitialize equ     *

	link    a6,#locals              build our stack frame

	movea.l port(a6),a4             a4 dedicated as the gpio card pointer
*
* test for gpio card; status clear; sti0 & sti1 clear
*
	moveq   #ior_notGPIO,d0         ioresult in case card is not GPIO
	moveq   #31,d1                  mask for card id bits
	and.b   1(a4),d1                iosolate the card id bits
	subq.b  #3,d1                   is the card GPIO?
	bne     ioresc                  escape if not

	moveq   #ior_not9885,d0         ioresult in case peripheral is not a 9885
	moveq   #$0B,d1                 mask for peripheral status bits
	and.b   7(a4),d1                isolate the appropriate status bits
	bne     ioresc                  branch if inappropriate status for 9885
*
* test for media change
*
	move.b  #0,3(a4)                clear enab, word, dmac1, dmac0
	move.b  #0,7(a4)                clear ctl0 & ctl1

	bsr     f85lgin                 give the password

	moveq   #-4,d0                  build the
	or      un(a6),d0                 request status
	ror     #4,d0                       command
	bsr     f85wo                   issue it

	bsr     f85wi                   fetch the status word
	move    d0,v85stat(a6)          save the status word for now

	moveq   #0,d0
	bsr     f85wo                   complete the handshake with the '85

	moveq   #ior_mediachange,d0     ioresult in case media was changed

	moveq   #$04,d1                 disc changed bit
	and     v85stat(a6),d1          is it set?
	bne     ioresc                  escape if so

	page

*
* generate the interleave buffer (in ibuf)
*
	lea     v85ibuf(a6),a0          buffer's first byte address
	lea     30(a0),a1               buffer's last byte address plus one
	moveq   #-1,d0                  buffer's initial contents
	moveq   #8-1,d1                 loop counter
	move.l  d0,(a0)+                store four bytes
	dbra    d1,*-2                  loop until done

	lea     v85ibuf(a6),a0          buffer's first byte address
	clr.b   (a0)                    logical record 0 goes here
	moveq   #1,d0                   logical record number counter

f85gbl  adda    intlve(a6),a0           bump by the interleave factor

f85tpr  cmpa.l  a1,a0                   are we still in range?
	blt.s   *+6                     branch if so
	suba    #30,a0                  otherwise, circle around

	tst.b   (a0)+                   is this slot empty?
	bpl     f85tpr                  branch if not

	move.b  d0,-(a0)                this slot's empty: claim it
	addq    #1,d0                   bump the logical record number
	cmp     #30,d0                  all 30 lrn's (0-29) placed?
	blt     f85gbl                  loop until done

	lea     v85ibuf(a6),a1          buffer's FBA (lrn 0's position)
	suba.l  a1,a0                   offset from lrn 0 to lrn 29
	move    a0,v85r29o(a6)          save it
*
* make another copy of the buffer
*
	movem.l v85ibuf(a6),d0-d7       load 32 bytes
	movem.l d0-d7,v85ibuf+30(a6)    store 32 bytes
*
* some initializations for the main loop
*
	move.b  d0,1(a4)                clear the gpio card & reset dumbo

	lea     v85ibuf(a6),a0          interleave buffer's FBA
	move.l  a0,v85lrso(a6)          init the logical record spiral offset
	clr.b   v85gtc(a6)              clear the good track count
	clr.b   v85btc(a6)              clear the bad track count

	moveq   #$0C,d0
	or      un(a6),d0               unit number
	ror     #4,d0                   skeleton for various commands
	move    d0,v85scmd(a6)          save it

	page

*
* main loop section
*
f85ml   bsr.s   f85fmt                  format and test one track

	move.b  v85gtc(a6),d0           good track count
	add.b   v85btc(a6),d0           bad track count
	cmp.b   #77,d0                  all done?
	bge.s   f85fc                   branch if so

	bsr     f85lgin                 give the password
	move    v85scmd(a6),d0          basic command skeleton
	or      #$0F9F,d0               form a step in command
	bsr     f85wo                   issue it

	bsr     f85fst                  fetch status
	and     #$FFFC,d0               strip off the drive bits
	cmp     #$0020,d0               seek complete, no errors?
	beq     f85ml                   if so, continue with the main loop
	bra     f85die                  otherwise, decode and issue error



*
* formatting complete: wrap it up
*
f85fc   move.b  d0,1(a4)                clear the gpio card & reset dumbo

	moveq   #40,d0           wait a bit for card to reset     JS 8/19/83
	dbra    d0,*                                              JS 8/19/83

	moveq   #ior_initfailed,d0      ioresult in case of excessive rejected tracks
	cmpi.b  #63,v85gtc(a6)          did we get enough good tracks?
	blt     ioresc                  escape if not

	unlk    a6                      remove our stack frame
	movea.l (sp)+,a0                pop off the return address
	addq.l  #8,sp                   pop off the parameters
	jmp     (a0)                    return


*
* test patterns (the first is written by the format command!)
*                       1               2
*       dc      $C6C6   11000110110001101100011011000110
f85ptrn dc      $6363   01100011011000110110001101100011
	dc      $DB6D   11011011011011011101101101101101
	dc      $8888   10001000100010001000100010001000
	dc      $0000   (final sector contents)

	page

*
* routine to format and test one track
*
f85fmt  move.b  v85gtc(a6),d0           good track count
	cmp.b   #63,d0                  already have enough good tracks?
	bge     f85mtd                  branch if so (don't leave "extra" tracks)

	add.b   v85btc(a6),d0           compute current physical track number
	cmp.b   #66,d0                  out past the 9885's "supported" range?
	bgt     f85mtd                  branch if so (don't leave "extra" tracks)

	bsr     f85lgin                 give the password
	move    v85scmd(a6),d0          basic command skeleton
	ror     #5,d0
	or.b    v85gtc(a6),d0           current logical track number
	rol     #5,d0
	or      #30,d0                  format command for this track

	bsr     f85wf                   wait for the flag
	move    d0,4(a4)                place the command in the output buffer
	trap    #11                                                     scs
* scs   move    sr,-(sp)                prepare to disable interrupts
	ori     #$2700,sr               disable interrupts
************************ interrupts disabled *************************
	move.b  d0,(a4)                 set the peripheral control flag

	moveq   #30-1,d1                initialize the loop counter
	movea.l v85lrso(a6),a0          logical record spiral offset
	moveq   #0,d0                   need upper byte cleared

f85flb  move.b  (a0)+,d0                next logical record number to send

	bsr     f85cswf                 check status and wait for the flag
	  bra.s f85fle                  ret 1; terminate & check status

	move    d0,4(a4)                place the lrn in the output buffer
	move.b  d0,(a4)                 set the peripheral control flag

	dbra    d1,f85flb               loop until all 30 lrn's sent

f85fle  move    (sp)+,sr                re-enable interrupts
*********************** interrupts re-enabled ************************
	bsr     f85fst                  fetch status
	and     #$FFF8,d0               strip the drive & disc change bits
	cmp     #$0040,d0               format complete, no errors?
	bne     f85die                  if not, decode and issue error
*
* prepare for reading and writing under i/o control
*
	lea     f85ptrn,a3              first test pattern address

	move.b  #4,v85patc(a6)          init the pattern count

	page

*
* loop to read verify the previous pattern and write the next pattern
*   note: the first test pattern was written by the format command!
*         the last pattern written is 0, and will not be read verified
*

*
* verify under i/o control
*
f85vwl  movea.l v85lrso(a6),a0          logical record spiral offset
	move.l  a0,v85lrp(a6)           init the logical record pointer

	move.b  #30,v85rc(a6)           init the record counter

	moveq   #0,d0                   clear the upper byte
	move.b  v85gtc(a6),d0           this track's logical track#
	mulu    #30,d0                  this track's logical record 0
	move    d0,v85lr0(a6)           save it

f85vl   movea.l v85lrp(a6),a0           logical record pointer
	moveq   #0,d0                   clear upper byte and word
	move.b  (a0)+,d0                logical record to verify next
	add     v85lr0(a6),d0           this track's logical record 0
	move.l  a0,v85lrp(a6)           updated logical record pointer
	move    d0,v85frec(a6)          record to verify

	sf      v85rwf(a6)              set read/write flag to read
	bsr     f85xfr                  do the transfer
	  bra.s f85ferr                 ret 1; some error occurred

	subq.b  #1,v85rc(a6)            decrement the record counter
	bgt     f85vl                   loop til all 30 records are verified

*
* write under i/o control
*
	move    (a3),d0                 test pattern
	swap    d0
	move    (a3)+,d0                need it in upper & lower words
	lea     v85buf(a6),a0           first word address
	moveq   #64-1,d1                initialize the loop counter
	move.l  d0,(a0)+                write four bytes
	dbra    d1,*-2                  loop until done

	movea.l v85lrso(a6),a0          logical record spiral offset
	move.l  a0,v85lrp(a6)           logical record pointer

	move.b  #30,v85rc(a6)           init the record count

	page

f85wl   movea.l v85lrp(a6),a0           logical record pointer
	moveq   #0,d0                   clear upper byte and word
	move.b  (a0)+,d0                next record to be written
	add     v85lr0(a6),d0           this track's logical record 0
	move.l  a0,v85lrp(a6)           updated logical record pointer
	move    d0,v85frec(a6)          record number to write

	st      v85rwf(a6)              set the read/write flag to write
	bsr     f85xfr                  do the transfer
f85ferr   bra.s f85err                  ret 1; some error occurred

	subq.b  #1,v85rc(a6)            decrement the record count
	bgt     f85wl                   loop till all 30 records are written



	subq.b  #1,v85patc(a6)          decrement the pattern count
	bgt     f85vwl                  loop until done

	addq.b  #1,v85gtc(a6)           increment the good track count

	moveq   #26,d0
	sub     intlve(a6),d0
	sub     v85r29o(a6),d0          (offset=offset-inter-r29o+26)
	ext.l   d0                      need the offset long
	bra.s   f85bof                  bump the logical record offset



*
* an error occurred in verifying or writing: is it "ok"?
*
f85err  move.b  v85stat(a6),d0          the upper byte of the error code word

	subq.b  #5,d0                   id error?
	beq.s   f85mtd                  branch if so
	subq.b  #6-5,d0                 track error?
	beq.s   f85mtd                  branch if so
	subq.b  #7-6,d0                 crc error?
	beq.s   f85mtd                  branch if so
	subq.b  #9-7,d0                 verify error?
	beq.s   f85mtd                  branch if so

	bra     f85die                  take the error exit

	page

*
* mark the (bad) track defective (invisible)
*
f85mtd  bsr     f85lgin                 give the password

	move    v85scmd(a6),d0          basic command skeleton
	or      #$0FBF,d0               form a mark track defective cmd
	bsr     f85wo                   issue it

	bsr.s   f85fst                  fetch status
	and     #$FFFC,d0               strip off the drive bits
	bne     f85die                  branch if any errors

	addq.b  #1,v85btc(a6)           increment the bad track count

	moveq   #-4,d0                  logical record offset to be bumped by 4
*       bra.s   f85bof                  bump the offset


*
* subroutine to bump the logical record spiral offset
*
f85bof  add.l   v85lrso(a6),d0          bump it
	move.l  d0,v85lrso(a6)          save it
	lea     v85ibuf(a6),a0          interleave buffer's FBA
	cmp.l   a0,d0                   offset still in range?
	bge.s   *+6                     branch if so
	moveq   #30,d0                  else put it in range
	bra.s   f85bof
	rts

*
* subroutine to fetch status
*
f85fst  bsr     f85cswf                 check status and wait for the flag
	  nop                           ret 1; error occurred

	bsr     f85winw                 word in; don't wait on the flag
	move    d0,v85stat(a6)          save the status word for now

	moveq   #0,d0
	bsr     f85wo                   complete the handshake with the '85

	move    v85stat(a6),d0          load the status word
	rts

	page

**********************************************************************
*                   routine to transfer one sector                   *
**********************************************************************

*
* gain access to the dma channel
*
f85xfr  movea.l #$500000,a2             DMA channel 0 address
	moveq   #$05,d0                 gpio dma control byte: chan 0
*
* set up the gpio card
*
	move.b  d0,v85gdcb(a6)          save the gpio dma control byte
	move.b  #0,3(a4)                clear enab, word, dmac1, dmac0
	move.b  #0,7(a4)                clear ctl1 & ctl0
*
* build and issue the seek command
*
	bsr     f85lgin                 give the password

	move    v85frec(a6),d0          first record number
	ext.l   d0                      make it long for division
	divs    #30,d0                  split into track & sector #'s
	swap    d0                      track in upper; sector in lower
	ror     #5,d0                   sector in upper bits of lower
	ror.l   #7,d0                   track&sector in upper bits of lower
	or      un(a6),d0               track&sector&00&unit in lower
	ror     #2,d0                   unit&track&sector&00
	or      #3,d0                   unit&track&sector&11
	ror     #2,d0                   11&unit&track&sector (finally!)
	bsr     f85wo                   issue the seek command

*
* partially build the appropriate transfer command
*
	bsr     f85lgin                 give the password

	move    un(a6),d0               unit number
	ror     #4,d0                   position for read/write/verify
	addq    #1,d0                   specify a record count of one

	lea     v85buf(a6),a0           read/write buffer's FWA
	move.l  a0,(a2)                 write in the DMA channel's address register

	moveq   #127,d1                 #words-1 in a sector
	move    d1,4(a2)                write in the DMA channel's count register

	bsr     f85cswf                 check status and wait for the flag
	  bra.s f85_grs                 ret 1 - error; go read status

	tst.b   v85rwf(a6)              read/write flag
	bmi.s   f85_wrt                 branch if a write

	page

*
* section for verify (read)
*
	bset    #14,d0                  make a verify command
	move    d0,4(a4)                place cmnd in the output buffer

	trap    #11                                                      scs
* scs   move    sr,-(sp)                prepare to disable interrupts
	ori     #$2700,sr               disable interrupts (except nmi)
************************ interrupts disabled *************************
	move.b  d0,(a4)                 set the peripheral control line

	bsr     f85cswf                 check status and wait for the flag
	  bra.s f85_rby                 ret 1; bypass because of error

	move    #0,4(a4)                clear the output buffers
	tst     4(a4)                   set direction in w/ dummy read
	move.b  d0,(a4)                 set the peripheral control flag

f85_rby move.b  v85gdcb(a6),3(a4)       set the gpio dma control bits
	subq    #1,4(a2)                don't dma the last word in
	blt.s   f85_rei                 don't arm if no words to dma in
	move    #$0002,6(a2)            arm the dma channel
f85_rei move    (sp)+,sr                re-enable interrupts
*********************** interrupts re-enabled ************************
	lea     v85buf+254(a6),a0       transfer's last word address

f85_rwt btst    #3,7(a4)                peripheral status set?
	bne.s   f85_tdx                 if so, terminate dma xfer now!
	btst    #0,7(a2)                dma channel still armed?
	bne     f85_rwt                 if so, loop

	bsr     f85cswf                 check status and wait for the flag
	  bra.s f85_tdx                 ret 1 - error; bypass else hang
	move    4(a4),(a0)              transfer the last word
f85_grs bra.s   f85_tdx                 go read the status word

	page

*
* section for write
*
f85_wrt bset    #15,d0                  make it a write command
	move    d0,4(a4)                place the command in the output buffer

	trap    #11                                                     scs
* scs   move    sr,-(sp)                prepare to disable interrupts
	ori     #$2700,sr               disable interrupts (except nmi)
************************ interrupts disabled *************************
	move.b  d0,(a4)                 set the peripheral control line

	move.b  v85gdcb(a6),3(a4)       set gpio card dma control bits
	move    #$0006,6(a2)            arm the dma channel

	move    (sp)+,sr                re-enable interrupts
*********************** interrupts re-enabled ************************
f85_wwt btst    #3,7(a4)                peripheral status set?
	bne.s   f85_tdx                 if so, terminate dma xfer now!
	btst    #0,7(a2)                dma channel still armed?
	bne.s   f85_wwt                 if so, loop

	bsr     f85cswf                 check status and wait for the flag
	  nop                           ret 1; some error occurred

*
* terminate the dma transfer and read the status word
*
f85_tdx move    (a2),d0                 disarm the dma channel
	clr.b   3(a4)                   clr the gpio card dma control bits

	move.b  #1,7(a4)                set the transfer complete bit
	bsr     f85winw                 word in; don't wait for the flag
	move    d0,v85stat(a6)          save the status word for now
	move.b  #0,7(a4)                clear the transfer complete bit

	moveq   #0,d0
	bsr     f85wo                   complete the handshake with the '85
*
* check for errors
*
	move    v85stat(a6),d0          drive ready, seek complete,
	and     #$FFF0,d0                 transfer complete, &
	cmp     #$0060,d0                   no error in error code?
	bne.s   *+4                     branch if any errors
	addq.l  #2,(sp)                 setup a normal (ret 2) exit
	rts                             exit

	page

**********************************************************************
*                      9885 shared driver routines                   *
**********************************************************************

*
* routine to check status while waiting on the flag
*
f85cswf addq.l  #2,(sp)                 anticipate a normal (ret 2) exit

f85tfb  btst    #0,(a4)                 flag bit
	bne.s   f85ret                  branch if set

	btst    #3,7(a4)                peripheral status bit
	beq.s   f85tfb                  keep looping unless it's set

	subq.l  #2,(sp)                 change the ret 2 back to a ret 1
f85ret  rts                             exit



*
* routine to wait for the flag
*
f85wf   btst    #0,(a4)                 flag bit
	beq     *-4                     loop until set
	rts



*
* routine to send the 9885 password
*
f85lgin move    #44679,d0               9885's "secret" password



*
* routine to send one word out on the gpio card
*
f85wo   bsr     f85wf                   wait for the flag
	move    d0,4(a4)                place word in the output buffer
	move.b  d0,(a4)                 set the peripheral control line
	rts

	page

*
* routine to receive one word in on the gpio card
*
f85wi   bsr     f85wf                   wait for the flag

f85winw move    #0,4(a4)                clear the output buffer

	tst     4(a4)                   set direction in w/ dummy read
	move.b  d0,(a4)                 set the peripheral control line
	bsr     f85wf                   wait for the flag
	move    4(a4),d0                load in the word
	rts


	end
@


56.2
log
@
pws2rcs automatic delta on Wed Jan 27 11:57:27 MST 1993
@
text
@d1 804
@


56.1
log
@Automatic bump of revision number for PWS version 3.25
@
text
@a0 804
 ttl Fminit - 9885 initialization routine


	rorg    0
	nosyms


*************************************************
*            PASCAL module interface            *
*************************************************

 src    module Fminit;
 src
 src    import
 src      sysglobals,
 src      midecs;
 src
 src    export
 src      function Fintdata: interleave_data;
 src      function Fphydata: physical_data;
 src      procedure Fminitialize(port: charptr; un: byte; intlve: shortint);
 src
 src    end;

*
* def's
*
	def     Fminit_Fminit       module intialization routine
	def     Fminit_Fintdata     interleave factor data function
	def     Fminit_Fphydata     physical attributes data function
	def     Fminit_Fminitialize 9885 formatting routine

*
* ref's
*
	refa    sysglobals

*
* module intialization routine
*
Fminit_Fminit   rts

	page

*************************************************
*                  functions                    *
*************************************************

*
* interleave factor data function
*
intdata dc      1       minimum interleave factor
	dc      29      maximum interleave factor
	dc      1       default interleave factor

Fminit_Fintdata equ *
	movea.l (sp)+,a0                return address
	movea.l (sp)+,a1                return variable address
	movem   intdata,d0-d2           interleave_data record constant
	movem   d0-d2,(a1)              assign the return variable
	jmp     (a0)                    return



*
* physical attributes data function
*
phydata dc.l    67-4    number of tracks per surface
	dc.l    1       number of surfaces per media
	dc.l    30      number of sectors per track

Fminit_Fphydata equ *
	movea.l (sp)+,a0                return address
	movea.l (sp)+,a1                return variable address
	movem.l phydata,d0-d2           interleave_data record constant
	movem.l d0-d2,(a1)              assign the return variable
	jmp     (a0)                    return

	page

*************************************************
*      passed parameters & local variables      *
*************************************************

*
* local variables
*
locals  equ     -342                    total local area size

v85buf  equ     -342        (256 bytes) read/write buffer

v85ibuf equ     -86         (62 bytes)  interleave buffer

v85lrp  equ     -24         (long)      logical record pointer
v85lrso equ     -20         (long)      logical record spiral offset

v85r29o equ     -16         (word)      logical record 29 offset
v85frec equ     -14         (word)      first record
v85lr0  equ     -12         (word)      this track's logical record 0
v85scmd equ     -10         (word)      skeleton command
v85stat equ     -8          (word)      status word

v85rc   equ     -6          (byte)      record count
v85rwf  equ     -5          (byte)      read/write flag
v85gtc  equ     -4          (byte)      good track count
v85btc  equ     -3          (byte)      bad track count
v85patc equ     -2          (byte)      test pattern count
v85gdcb equ     -1          (byte)      gpio dma control byte

*
* passed parameters
*
olda6   equ     0           (long)      dynamic link
retaddr equ     4           (long)      return address
intlve  equ     8           (word)      interleave factor
un      equ     10          (word)      unit number
port    equ     12          (long)      card port address

	page

*************************************************
*                 escape sequences              *
*************************************************

*
* assignment of ioresult values
*
ior_notGPIO     equ     16      (znodevice)             card is not GPIO
ior_not9885     equ     16      (znodevice)             peripheral is not 9885
ior_mediachange equ     46      (zmediumchanged)        media has been changed
ior_initfailed  equ     17      (zinitfail)             initialization failed
ior_catchall    equ     21      (zcatchall)             error undetermined

*
* 9885 error code mapping to ioresult values
*
f85ecm  dc.b    21  (zcatchall)         (0)     no error
	dc.b    16  (znodevice)         (1)     not all drives powered
	dc.b    34  (znomedium)         (2)     door open
	dc.b    34  (znomedium)         (3)     no disc in drive
	dc.b    18  (zprotected)        (4)     badcommand (write protected)
	dc.b    32  (znoblock)          (5)     record header error
	dc.b    32  (znoblock)          (6)     track not found
	dc.b     1  (zbadblock)         (7)     data checkword error
	dc.b    20  (zbadhardware)      (8)     data overrun
	dc.b     1  (zbadblock)         (9)     verify failed

*
* subroutine ioresult escape: enter with ioresult in d0.l
*
ioresc  move.l  d0,sysglobals-22(a5)    store the ioresult
	move    #-10,sysglobals-2(a5)   store the escapecode
	trap    #10                     escape a'la' Pascal

*
* subroutine decode and issue the error code
*
f85die  moveq   #0,d1                   clear upper byte for word indexing
	move.b  v85stat(a6),d1          9885 error code

	moveq   #ior_catchall,d0        ioresult in case error code is out of range
	cmp     #9,d1                   is the error code within the expected range?
	bhi     ioresc                  branch if not

	move.b  f85ecm(d1),d0           load the appropriate ioresult value
	bra     ioresc                  escape with the bad ioresult

	page

**********************************************************************
*                gpio interface card switch settings                 *
**********************************************************************

*            option switches

*    1) invert pclt             open
*    2) invert pflg             open
*    3) invert psts             open
*    4) full/pulse handshake    open
*    5) invert data in          open
*    6) invert data out         open


*          data clock switches

*    1) read                    open             \
*    2) ready to busy                 closed       lower data register
*    3) busy to ready           open             /
*    4) read                    open             \
*    5) ready to busy                 closed       upper data register
*    6) busy to ready           open             /


*    select code switches: 0-31; default 1


*    interrupt priority switches: don't cares; default 0

	page

**********************************************************************
*                                                                    *
* basic program flow is as follows:                                  *
*                                                                    *
*  Generate the interleave buffer containing the logical record      *
*  number sequences.                                                 *
*                                                                    *
*  Reset dumbo to force a "seek" to physical track 0.                *
*                                                                    *
*  Format & test the current track. If the track is good, increment  *
*  the good track count. If not, increment the bad track count and   *
*  make the bad track invisible. Step the heads in one track. Repeat *
*  until all 67 tracks have been processed.                          *
*                                                                    *
*  Reset dumbo again.                                                *
*                                                                    *
*  If more than 4 tracks were bad, issue an error.                   *
*                                                                    *
**********************************************************************



**********************************************************************
*                                                                    *
* procedure for formatting and testing one track                     *
*                                                                    *
*   1. Format the track with the sequence of logical record numbers  *
*      appropriate for the specified interleave factor.              *
*                                                                    *
*   2. With tight margins read back the data written by the format.  *
*      Write & read back under tight margins 3 other test patterns.  *
*      Write 0's to all records.                                     *
*                                                                    *
*   3. If the track had no errors, increment the good track count.   *
*      Else increment the bad track count and make the (bad) track   *
*      invisible.                                                    *
*                                                                    *
**********************************************************************

	page

**********************************************************************
*                          format the media                          *
**********************************************************************

*
* preliminary setup & checks
*
Fminit_Fminitialize equ     *

	link    a6,#locals              build our stack frame

	movea.l port(a6),a4             a4 dedicated as the gpio card pointer
*
* test for gpio card; status clear; sti0 & sti1 clear
*
	moveq   #ior_notGPIO,d0         ioresult in case card is not GPIO
	moveq   #31,d1                  mask for card id bits
	and.b   1(a4),d1                iosolate the card id bits
	subq.b  #3,d1                   is the card GPIO?
	bne     ioresc                  escape if not

	moveq   #ior_not9885,d0         ioresult in case peripheral is not a 9885
	moveq   #$0B,d1                 mask for peripheral status bits
	and.b   7(a4),d1                isolate the appropriate status bits
	bne     ioresc                  branch if inappropriate status for 9885
*
* test for media change
*
	move.b  #0,3(a4)                clear enab, word, dmac1, dmac0
	move.b  #0,7(a4)                clear ctl0 & ctl1

	bsr     f85lgin                 give the password

	moveq   #-4,d0                  build the
	or      un(a6),d0                 request status
	ror     #4,d0                       command
	bsr     f85wo                   issue it

	bsr     f85wi                   fetch the status word
	move    d0,v85stat(a6)          save the status word for now

	moveq   #0,d0
	bsr     f85wo                   complete the handshake with the '85

	moveq   #ior_mediachange,d0     ioresult in case media was changed

	moveq   #$04,d1                 disc changed bit
	and     v85stat(a6),d1          is it set?
	bne     ioresc                  escape if so

	page

*
* generate the interleave buffer (in ibuf)
*
	lea     v85ibuf(a6),a0          buffer's first byte address
	lea     30(a0),a1               buffer's last byte address plus one
	moveq   #-1,d0                  buffer's initial contents
	moveq   #8-1,d1                 loop counter
	move.l  d0,(a0)+                store four bytes
	dbra    d1,*-2                  loop until done

	lea     v85ibuf(a6),a0          buffer's first byte address
	clr.b   (a0)                    logical record 0 goes here
	moveq   #1,d0                   logical record number counter

f85gbl  adda    intlve(a6),a0           bump by the interleave factor

f85tpr  cmpa.l  a1,a0                   are we still in range?
	blt.s   *+6                     branch if so
	suba    #30,a0                  otherwise, circle around

	tst.b   (a0)+                   is this slot empty?
	bpl     f85tpr                  branch if not

	move.b  d0,-(a0)                this slot's empty: claim it
	addq    #1,d0                   bump the logical record number
	cmp     #30,d0                  all 30 lrn's (0-29) placed?
	blt     f85gbl                  loop until done

	lea     v85ibuf(a6),a1          buffer's FBA (lrn 0's position)
	suba.l  a1,a0                   offset from lrn 0 to lrn 29
	move    a0,v85r29o(a6)          save it
*
* make another copy of the buffer
*
	movem.l v85ibuf(a6),d0-d7       load 32 bytes
	movem.l d0-d7,v85ibuf+30(a6)    store 32 bytes
*
* some initializations for the main loop
*
	move.b  d0,1(a4)                clear the gpio card & reset dumbo

	lea     v85ibuf(a6),a0          interleave buffer's FBA
	move.l  a0,v85lrso(a6)          init the logical record spiral offset
	clr.b   v85gtc(a6)              clear the good track count
	clr.b   v85btc(a6)              clear the bad track count

	moveq   #$0C,d0
	or      un(a6),d0               unit number
	ror     #4,d0                   skeleton for various commands
	move    d0,v85scmd(a6)          save it

	page

*
* main loop section
*
f85ml   bsr.s   f85fmt                  format and test one track

	move.b  v85gtc(a6),d0           good track count
	add.b   v85btc(a6),d0           bad track count
	cmp.b   #77,d0                  all done?
	bge.s   f85fc                   branch if so

	bsr     f85lgin                 give the password
	move    v85scmd(a6),d0          basic command skeleton
	or      #$0F9F,d0               form a step in command
	bsr     f85wo                   issue it

	bsr     f85fst                  fetch status
	and     #$FFFC,d0               strip off the drive bits
	cmp     #$0020,d0               seek complete, no errors?
	beq     f85ml                   if so, continue with the main loop
	bra     f85die                  otherwise, decode and issue error



*
* formatting complete: wrap it up
*
f85fc   move.b  d0,1(a4)                clear the gpio card & reset dumbo

	moveq   #40,d0           wait a bit for card to reset     JS 8/19/83
	dbra    d0,*                                              JS 8/19/83

	moveq   #ior_initfailed,d0      ioresult in case of excessive rejected tracks
	cmpi.b  #63,v85gtc(a6)          did we get enough good tracks?
	blt     ioresc                  escape if not

	unlk    a6                      remove our stack frame
	movea.l (sp)+,a0                pop off the return address
	addq.l  #8,sp                   pop off the parameters
	jmp     (a0)                    return


*
* test patterns (the first is written by the format command!)
*                       1               2
*       dc      $C6C6   11000110110001101100011011000110
f85ptrn dc      $6363   01100011011000110110001101100011
	dc      $DB6D   11011011011011011101101101101101
	dc      $8888   10001000100010001000100010001000
	dc      $0000   (final sector contents)

	page

*
* routine to format and test one track
*
f85fmt  move.b  v85gtc(a6),d0           good track count
	cmp.b   #63,d0                  already have enough good tracks?
	bge     f85mtd                  branch if so (don't leave "extra" tracks)

	add.b   v85btc(a6),d0           compute current physical track number
	cmp.b   #66,d0                  out past the 9885's "supported" range?
	bgt     f85mtd                  branch if so (don't leave "extra" tracks)

	bsr     f85lgin                 give the password
	move    v85scmd(a6),d0          basic command skeleton
	ror     #5,d0
	or.b    v85gtc(a6),d0           current logical track number
	rol     #5,d0
	or      #30,d0                  format command for this track

	bsr     f85wf                   wait for the flag
	move    d0,4(a4)                place the command in the output buffer
	trap    #11                                                     scs
* scs   move    sr,-(sp)                prepare to disable interrupts
	ori     #$2700,sr               disable interrupts
************************ interrupts disabled *************************
	move.b  d0,(a4)                 set the peripheral control flag

	moveq   #30-1,d1                initialize the loop counter
	movea.l v85lrso(a6),a0          logical record spiral offset
	moveq   #0,d0                   need upper byte cleared

f85flb  move.b  (a0)+,d0                next logical record number to send

	bsr     f85cswf                 check status and wait for the flag
	  bra.s f85fle                  ret 1; terminate & check status

	move    d0,4(a4)                place the lrn in the output buffer
	move.b  d0,(a4)                 set the peripheral control flag

	dbra    d1,f85flb               loop until all 30 lrn's sent

f85fle  move    (sp)+,sr                re-enable interrupts
*********************** interrupts re-enabled ************************
	bsr     f85fst                  fetch status
	and     #$FFF8,d0               strip the drive & disc change bits
	cmp     #$0040,d0               format complete, no errors?
	bne     f85die                  if not, decode and issue error
*
* prepare for reading and writing under i/o control
*
	lea     f85ptrn,a3              first test pattern address

	move.b  #4,v85patc(a6)          init the pattern count

	page

*
* loop to read verify the previous pattern and write the next pattern
*   note: the first test pattern was written by the format command!
*         the last pattern written is 0, and will not be read verified
*

*
* verify under i/o control
*
f85vwl  movea.l v85lrso(a6),a0          logical record spiral offset
	move.l  a0,v85lrp(a6)           init the logical record pointer

	move.b  #30,v85rc(a6)           init the record counter

	moveq   #0,d0                   clear the upper byte
	move.b  v85gtc(a6),d0           this track's logical track#
	mulu    #30,d0                  this track's logical record 0
	move    d0,v85lr0(a6)           save it

f85vl   movea.l v85lrp(a6),a0           logical record pointer
	moveq   #0,d0                   clear upper byte and word
	move.b  (a0)+,d0                logical record to verify next
	add     v85lr0(a6),d0           this track's logical record 0
	move.l  a0,v85lrp(a6)           updated logical record pointer
	move    d0,v85frec(a6)          record to verify

	sf      v85rwf(a6)              set read/write flag to read
	bsr     f85xfr                  do the transfer
	  bra.s f85ferr                 ret 1; some error occurred

	subq.b  #1,v85rc(a6)            decrement the record counter
	bgt     f85vl                   loop til all 30 records are verified

*
* write under i/o control
*
	move    (a3),d0                 test pattern
	swap    d0
	move    (a3)+,d0                need it in upper & lower words
	lea     v85buf(a6),a0           first word address
	moveq   #64-1,d1                initialize the loop counter
	move.l  d0,(a0)+                write four bytes
	dbra    d1,*-2                  loop until done

	movea.l v85lrso(a6),a0          logical record spiral offset
	move.l  a0,v85lrp(a6)           logical record pointer

	move.b  #30,v85rc(a6)           init the record count

	page

f85wl   movea.l v85lrp(a6),a0           logical record pointer
	moveq   #0,d0                   clear upper byte and word
	move.b  (a0)+,d0                next record to be written
	add     v85lr0(a6),d0           this track's logical record 0
	move.l  a0,v85lrp(a6)           updated logical record pointer
	move    d0,v85frec(a6)          record number to write

	st      v85rwf(a6)              set the read/write flag to write
	bsr     f85xfr                  do the transfer
f85ferr   bra.s f85err                  ret 1; some error occurred

	subq.b  #1,v85rc(a6)            decrement the record count
	bgt     f85wl                   loop till all 30 records are written



	subq.b  #1,v85patc(a6)          decrement the pattern count
	bgt     f85vwl                  loop until done

	addq.b  #1,v85gtc(a6)           increment the good track count

	moveq   #26,d0
	sub     intlve(a6),d0
	sub     v85r29o(a6),d0          (offset=offset-inter-r29o+26)
	ext.l   d0                      need the offset long
	bra.s   f85bof                  bump the logical record offset



*
* an error occurred in verifying or writing: is it "ok"?
*
f85err  move.b  v85stat(a6),d0          the upper byte of the error code word

	subq.b  #5,d0                   id error?
	beq.s   f85mtd                  branch if so
	subq.b  #6-5,d0                 track error?
	beq.s   f85mtd                  branch if so
	subq.b  #7-6,d0                 crc error?
	beq.s   f85mtd                  branch if so
	subq.b  #9-7,d0                 verify error?
	beq.s   f85mtd                  branch if so

	bra     f85die                  take the error exit

	page

*
* mark the (bad) track defective (invisible)
*
f85mtd  bsr     f85lgin                 give the password

	move    v85scmd(a6),d0          basic command skeleton
	or      #$0FBF,d0               form a mark track defective cmd
	bsr     f85wo                   issue it

	bsr.s   f85fst                  fetch status
	and     #$FFFC,d0               strip off the drive bits
	bne     f85die                  branch if any errors

	addq.b  #1,v85btc(a6)           increment the bad track count

	moveq   #-4,d0                  logical record offset to be bumped by 4
*       bra.s   f85bof                  bump the offset


*
* subroutine to bump the logical record spiral offset
*
f85bof  add.l   v85lrso(a6),d0          bump it
	move.l  d0,v85lrso(a6)          save it
	lea     v85ibuf(a6),a0          interleave buffer's FBA
	cmp.l   a0,d0                   offset still in range?
	bge.s   *+6                     branch if so
	moveq   #30,d0                  else put it in range
	bra.s   f85bof
	rts

*
* subroutine to fetch status
*
f85fst  bsr     f85cswf                 check status and wait for the flag
	  nop                           ret 1; error occurred

	bsr     f85winw                 word in; don't wait on the flag
	move    d0,v85stat(a6)          save the status word for now

	moveq   #0,d0
	bsr     f85wo                   complete the handshake with the '85

	move    v85stat(a6),d0          load the status word
	rts

	page

**********************************************************************
*                   routine to transfer one sector                   *
**********************************************************************

*
* gain access to the dma channel
*
f85xfr  movea.l #$500000,a2             DMA channel 0 address
	moveq   #$05,d0                 gpio dma control byte: chan 0
*
* set up the gpio card
*
	move.b  d0,v85gdcb(a6)          save the gpio dma control byte
	move.b  #0,3(a4)                clear enab, word, dmac1, dmac0
	move.b  #0,7(a4)                clear ctl1 & ctl0
*
* build and issue the seek command
*
	bsr     f85lgin                 give the password

	move    v85frec(a6),d0          first record number
	ext.l   d0                      make it long for division
	divs    #30,d0                  split into track & sector #'s
	swap    d0                      track in upper; sector in lower
	ror     #5,d0                   sector in upper bits of lower
	ror.l   #7,d0                   track&sector in upper bits of lower
	or      un(a6),d0               track&sector&00&unit in lower
	ror     #2,d0                   unit&track&sector&00
	or      #3,d0                   unit&track&sector&11
	ror     #2,d0                   11&unit&track&sector (finally!)
	bsr     f85wo                   issue the seek command

*
* partially build the appropriate transfer command
*
	bsr     f85lgin                 give the password

	move    un(a6),d0               unit number
	ror     #4,d0                   position for read/write/verify
	addq    #1,d0                   specify a record count of one

	lea     v85buf(a6),a0           read/write buffer's FWA
	move.l  a0,(a2)                 write in the DMA channel's address register

	moveq   #127,d1                 #words-1 in a sector
	move    d1,4(a2)                write in the DMA channel's count register

	bsr     f85cswf                 check status and wait for the flag
	  bra.s f85_grs                 ret 1 - error; go read status

	tst.b   v85rwf(a6)              read/write flag
	bmi.s   f85_wrt                 branch if a write

	page

*
* section for verify (read)
*
	bset    #14,d0                  make a verify command
	move    d0,4(a4)                place cmnd in the output buffer

	trap    #11                                                      scs
* scs   move    sr,-(sp)                prepare to disable interrupts
	ori     #$2700,sr               disable interrupts (except nmi)
************************ interrupts disabled *************************
	move.b  d0,(a4)                 set the peripheral control line

	bsr     f85cswf                 check status and wait for the flag
	  bra.s f85_rby                 ret 1; bypass because of error

	move    #0,4(a4)                clear the output buffers
	tst     4(a4)                   set direction in w/ dummy read
	move.b  d0,(a4)                 set the peripheral control flag

f85_rby move.b  v85gdcb(a6),3(a4)       set the gpio dma control bits
	subq    #1,4(a2)                don't dma the last word in
	blt.s   f85_rei                 don't arm if no words to dma in
	move    #$0002,6(a2)            arm the dma channel
f85_rei move    (sp)+,sr                re-enable interrupts
*********************** interrupts re-enabled ************************
	lea     v85buf+254(a6),a0       transfer's last word address

f85_rwt btst    #3,7(a4)                peripheral status set?
	bne.s   f85_tdx                 if so, terminate dma xfer now!
	btst    #0,7(a2)                dma channel still armed?
	bne     f85_rwt                 if so, loop

	bsr     f85cswf                 check status and wait for the flag
	  bra.s f85_tdx                 ret 1 - error; bypass else hang
	move    4(a4),(a0)              transfer the last word
f85_grs bra.s   f85_tdx                 go read the status word

	page

*
* section for write
*
f85_wrt bset    #15,d0                  make it a write command
	move    d0,4(a4)                place the command in the output buffer

	trap    #11                                                     scs
* scs   move    sr,-(sp)                prepare to disable interrupts
	ori     #$2700,sr               disable interrupts (except nmi)
************************ interrupts disabled *************************
	move.b  d0,(a4)                 set the peripheral control line

	move.b  v85gdcb(a6),3(a4)       set gpio card dma control bits
	move    #$0006,6(a2)            arm the dma channel

	move    (sp)+,sr                re-enable interrupts
*********************** interrupts re-enabled ************************
f85_wwt btst    #3,7(a4)                peripheral status set?
	bne.s   f85_tdx                 if so, terminate dma xfer now!
	btst    #0,7(a2)                dma channel still armed?
	bne.s   f85_wwt                 if so, loop

	bsr     f85cswf                 check status and wait for the flag
	  nop                           ret 1; some error occurred

*
* terminate the dma transfer and read the status word
*
f85_tdx move    (a2),d0                 disarm the dma channel
	clr.b   3(a4)                   clr the gpio card dma control bits

	move.b  #1,7(a4)                set the transfer complete bit
	bsr     f85winw                 word in; don't wait for the flag
	move    d0,v85stat(a6)          save the status word for now
	move.b  #0,7(a4)                clear the transfer complete bit

	moveq   #0,d0
	bsr     f85wo                   complete the handshake with the '85
*
* check for errors
*
	move    v85stat(a6),d0          drive ready, seek complete,
	and     #$FFF0,d0                 transfer complete, &
	cmp     #$0060,d0                   no error in error code?
	bne.s   *+4                     branch if any errors
	addq.l  #2,(sp)                 setup a normal (ret 2) exit
	rts                             exit

	page

**********************************************************************
*                      9885 shared driver routines                   *
**********************************************************************

*
* routine to check status while waiting on the flag
*
f85cswf addq.l  #2,(sp)                 anticipate a normal (ret 2) exit

f85tfb  btst    #0,(a4)                 flag bit
	bne.s   f85ret                  branch if set

	btst    #3,7(a4)                peripheral status bit
	beq.s   f85tfb                  keep looping unless it's set

	subq.l  #2,(sp)                 change the ret 2 back to a ret 1
f85ret  rts                             exit



*
* routine to wait for the flag
*
f85wf   btst    #0,(a4)                 flag bit
	beq     *-4                     loop until set
	rts



*
* routine to send the 9885 password
*
f85lgin move    #44679,d0               9885's "secret" password



*
* routine to send one word out on the gpio card
*
f85wo   bsr     f85wf                   wait for the flag
	move    d0,4(a4)                place word in the output buffer
	move.b  d0,(a4)                 set the peripheral control line
	rts

	page

*
* routine to receive one word in on the gpio card
*
f85wi   bsr     f85wf                   wait for the flag

f85winw move    #0,4(a4)                clear the output buffer

	tst     4(a4)                   set direction in w/ dummy read
	move.b  d0,(a4)                 set the peripheral control line
	bsr     f85wf                   wait for the flag
	move    4(a4),d0                load in the word
	rts


	end
@


55.1
log
@Automatic bump of revision number for PWS version 3.25A
@
text
@@


54.3
log
@
pws2rcs automatic delta on Wed Aug 21 12:27:56 MDT 1991
@
text
@@


54.2
log
@
pws2rcs automatic delta on Wed Aug 21 09:35:48 MDT 1991
@
text
@d1 804
@


54.1
log
@Automatic bump of revision number for PWS version 3.24
@
text
@a0 804
 ttl Fminit - 9885 initialization routine


	rorg    0
	nosyms


*************************************************
*            PASCAL module interface            *
*************************************************

 src    module Fminit;
 src
 src    import
 src      sysglobals,
 src      midecs;
 src
 src    export
 src      function Fintdata: interleave_data;
 src      function Fphydata: physical_data;
 src      procedure Fminitialize(port: charptr; un: byte; intlve: shortint);
 src
 src    end;

*
* def's
*
	def     Fminit_Fminit       module intialization routine
	def     Fminit_Fintdata     interleave factor data function
	def     Fminit_Fphydata     physical attributes data function
	def     Fminit_Fminitialize 9885 formatting routine

*
* ref's
*
	refa    sysglobals

*
* module intialization routine
*
Fminit_Fminit   rts

	page

*************************************************
*                  functions                    *
*************************************************

*
* interleave factor data function
*
intdata dc      1       minimum interleave factor
	dc      29      maximum interleave factor
	dc      1       default interleave factor

Fminit_Fintdata equ *
	movea.l (sp)+,a0                return address
	movea.l (sp)+,a1                return variable address
	movem   intdata,d0-d2           interleave_data record constant
	movem   d0-d2,(a1)              assign the return variable
	jmp     (a0)                    return



*
* physical attributes data function
*
phydata dc.l    67-4    number of tracks per surface
	dc.l    1       number of surfaces per media
	dc.l    30      number of sectors per track

Fminit_Fphydata equ *
	movea.l (sp)+,a0                return address
	movea.l (sp)+,a1                return variable address
	movem.l phydata,d0-d2           interleave_data record constant
	movem.l d0-d2,(a1)              assign the return variable
	jmp     (a0)                    return

	page

*************************************************
*      passed parameters & local variables      *
*************************************************

*
* local variables
*
locals  equ     -342                    total local area size

v85buf  equ     -342        (256 bytes) read/write buffer

v85ibuf equ     -86         (62 bytes)  interleave buffer

v85lrp  equ     -24         (long)      logical record pointer
v85lrso equ     -20         (long)      logical record spiral offset

v85r29o equ     -16         (word)      logical record 29 offset
v85frec equ     -14         (word)      first record
v85lr0  equ     -12         (word)      this track's logical record 0
v85scmd equ     -10         (word)      skeleton command
v85stat equ     -8          (word)      status word

v85rc   equ     -6          (byte)      record count
v85rwf  equ     -5          (byte)      read/write flag
v85gtc  equ     -4          (byte)      good track count
v85btc  equ     -3          (byte)      bad track count
v85patc equ     -2          (byte)      test pattern count
v85gdcb equ     -1          (byte)      gpio dma control byte

*
* passed parameters
*
olda6   equ     0           (long)      dynamic link
retaddr equ     4           (long)      return address
intlve  equ     8           (word)      interleave factor
un      equ     10          (word)      unit number
port    equ     12          (long)      card port address

	page

*************************************************
*                 escape sequences              *
*************************************************

*
* assignment of ioresult values
*
ior_notGPIO     equ     16      (znodevice)             card is not GPIO
ior_not9885     equ     16      (znodevice)             peripheral is not 9885
ior_mediachange equ     46      (zmediumchanged)        media has been changed
ior_initfailed  equ     17      (zinitfail)             initialization failed
ior_catchall    equ     21      (zcatchall)             error undetermined

*
* 9885 error code mapping to ioresult values
*
f85ecm  dc.b    21  (zcatchall)         (0)     no error
	dc.b    16  (znodevice)         (1)     not all drives powered
	dc.b    34  (znomedium)         (2)     door open
	dc.b    34  (znomedium)         (3)     no disc in drive
	dc.b    18  (zprotected)        (4)     badcommand (write protected)
	dc.b    32  (znoblock)          (5)     record header error
	dc.b    32  (znoblock)          (6)     track not found
	dc.b     1  (zbadblock)         (7)     data checkword error
	dc.b    20  (zbadhardware)      (8)     data overrun
	dc.b     1  (zbadblock)         (9)     verify failed

*
* subroutine ioresult escape: enter with ioresult in d0.l
*
ioresc  move.l  d0,sysglobals-22(a5)    store the ioresult
	move    #-10,sysglobals-2(a5)   store the escapecode
	trap    #10                     escape a'la' Pascal

*
* subroutine decode and issue the error code
*
f85die  moveq   #0,d1                   clear upper byte for word indexing
	move.b  v85stat(a6),d1          9885 error code

	moveq   #ior_catchall,d0        ioresult in case error code is out of range
	cmp     #9,d1                   is the error code within the expected range?
	bhi     ioresc                  branch if not

	move.b  f85ecm(d1),d0           load the appropriate ioresult value
	bra     ioresc                  escape with the bad ioresult

	page

**********************************************************************
*                gpio interface card switch settings                 *
**********************************************************************

*            option switches

*    1) invert pclt             open
*    2) invert pflg             open
*    3) invert psts             open
*    4) full/pulse handshake    open
*    5) invert data in          open
*    6) invert data out         open


*          data clock switches

*    1) read                    open             \
*    2) ready to busy                 closed       lower data register
*    3) busy to ready           open             /
*    4) read                    open             \
*    5) ready to busy                 closed       upper data register
*    6) busy to ready           open             /


*    select code switches: 0-31; default 1


*    interrupt priority switches: don't cares; default 0

	page

**********************************************************************
*                                                                    *
* basic program flow is as follows:                                  *
*                                                                    *
*  Generate the interleave buffer containing the logical record      *
*  number sequences.                                                 *
*                                                                    *
*  Reset dumbo to force a "seek" to physical track 0.                *
*                                                                    *
*  Format & test the current track. If the track is good, increment  *
*  the good track count. If not, increment the bad track count and   *
*  make the bad track invisible. Step the heads in one track. Repeat *
*  until all 67 tracks have been processed.                          *
*                                                                    *
*  Reset dumbo again.                                                *
*                                                                    *
*  If more than 4 tracks were bad, issue an error.                   *
*                                                                    *
**********************************************************************



**********************************************************************
*                                                                    *
* procedure for formatting and testing one track                     *
*                                                                    *
*   1. Format the track with the sequence of logical record numbers  *
*      appropriate for the specified interleave factor.              *
*                                                                    *
*   2. With tight margins read back the data written by the format.  *
*      Write & read back under tight margins 3 other test patterns.  *
*      Write 0's to all records.                                     *
*                                                                    *
*   3. If the track had no errors, increment the good track count.   *
*      Else increment the bad track count and make the (bad) track   *
*      invisible.                                                    *
*                                                                    *
**********************************************************************

	page

**********************************************************************
*                          format the media                          *
**********************************************************************

*
* preliminary setup & checks
*
Fminit_Fminitialize equ     *

	link    a6,#locals              build our stack frame

	movea.l port(a6),a4             a4 dedicated as the gpio card pointer
*
* test for gpio card; status clear; sti0 & sti1 clear
*
	moveq   #ior_notGPIO,d0         ioresult in case card is not GPIO
	moveq   #31,d1                  mask for card id bits
	and.b   1(a4),d1                iosolate the card id bits
	subq.b  #3,d1                   is the card GPIO?
	bne     ioresc                  escape if not

	moveq   #ior_not9885,d0         ioresult in case peripheral is not a 9885
	moveq   #$0B,d1                 mask for peripheral status bits
	and.b   7(a4),d1                isolate the appropriate status bits
	bne     ioresc                  branch if inappropriate status for 9885
*
* test for media change
*
	move.b  #0,3(a4)                clear enab, word, dmac1, dmac0
	move.b  #0,7(a4)                clear ctl0 & ctl1

	bsr     f85lgin                 give the password

	moveq   #-4,d0                  build the
	or      un(a6),d0                 request status
	ror     #4,d0                       command
	bsr     f85wo                   issue it

	bsr     f85wi                   fetch the status word
	move    d0,v85stat(a6)          save the status word for now

	moveq   #0,d0
	bsr     f85wo                   complete the handshake with the '85

	moveq   #ior_mediachange,d0     ioresult in case media was changed

	moveq   #$04,d1                 disc changed bit
	and     v85stat(a6),d1          is it set?
	bne     ioresc                  escape if so

	page

*
* generate the interleave buffer (in ibuf)
*
	lea     v85ibuf(a6),a0          buffer's first byte address
	lea     30(a0),a1               buffer's last byte address plus one
	moveq   #-1,d0                  buffer's initial contents
	moveq   #8-1,d1                 loop counter
	move.l  d0,(a0)+                store four bytes
	dbra    d1,*-2                  loop until done

	lea     v85ibuf(a6),a0          buffer's first byte address
	clr.b   (a0)                    logical record 0 goes here
	moveq   #1,d0                   logical record number counter

f85gbl  adda    intlve(a6),a0           bump by the interleave factor

f85tpr  cmpa.l  a1,a0                   are we still in range?
	blt.s   *+6                     branch if so
	suba    #30,a0                  otherwise, circle around

	tst.b   (a0)+                   is this slot empty?
	bpl     f85tpr                  branch if not

	move.b  d0,-(a0)                this slot's empty: claim it
	addq    #1,d0                   bump the logical record number
	cmp     #30,d0                  all 30 lrn's (0-29) placed?
	blt     f85gbl                  loop until done

	lea     v85ibuf(a6),a1          buffer's FBA (lrn 0's position)
	suba.l  a1,a0                   offset from lrn 0 to lrn 29
	move    a0,v85r29o(a6)          save it
*
* make another copy of the buffer
*
	movem.l v85ibuf(a6),d0-d7       load 32 bytes
	movem.l d0-d7,v85ibuf+30(a6)    store 32 bytes
*
* some initializations for the main loop
*
	move.b  d0,1(a4)                clear the gpio card & reset dumbo

	lea     v85ibuf(a6),a0          interleave buffer's FBA
	move.l  a0,v85lrso(a6)          init the logical record spiral offset
	clr.b   v85gtc(a6)              clear the good track count
	clr.b   v85btc(a6)              clear the bad track count

	moveq   #$0C,d0
	or      un(a6),d0               unit number
	ror     #4,d0                   skeleton for various commands
	move    d0,v85scmd(a6)          save it

	page

*
* main loop section
*
f85ml   bsr.s   f85fmt                  format and test one track

	move.b  v85gtc(a6),d0           good track count
	add.b   v85btc(a6),d0           bad track count
	cmp.b   #77,d0                  all done?
	bge.s   f85fc                   branch if so

	bsr     f85lgin                 give the password
	move    v85scmd(a6),d0          basic command skeleton
	or      #$0F9F,d0               form a step in command
	bsr     f85wo                   issue it

	bsr     f85fst                  fetch status
	and     #$FFFC,d0               strip off the drive bits
	cmp     #$0020,d0               seek complete, no errors?
	beq     f85ml                   if so, continue with the main loop
	bra     f85die                  otherwise, decode and issue error



*
* formatting complete: wrap it up
*
f85fc   move.b  d0,1(a4)                clear the gpio card & reset dumbo

	moveq   #40,d0           wait a bit for card to reset     JS 8/19/83
	dbra    d0,*                                              JS 8/19/83

	moveq   #ior_initfailed,d0      ioresult in case of excessive rejected tracks
	cmpi.b  #63,v85gtc(a6)          did we get enough good tracks?
	blt     ioresc                  escape if not

	unlk    a6                      remove our stack frame
	movea.l (sp)+,a0                pop off the return address
	addq.l  #8,sp                   pop off the parameters
	jmp     (a0)                    return


*
* test patterns (the first is written by the format command!)
*                       1               2
*       dc      $C6C6   11000110110001101100011011000110
f85ptrn dc      $6363   01100011011000110110001101100011
	dc      $DB6D   11011011011011011101101101101101
	dc      $8888   10001000100010001000100010001000
	dc      $0000   (final sector contents)

	page

*
* routine to format and test one track
*
f85fmt  move.b  v85gtc(a6),d0           good track count
	cmp.b   #63,d0                  already have enough good tracks?
	bge     f85mtd                  branch if so (don't leave "extra" tracks)

	add.b   v85btc(a6),d0           compute current physical track number
	cmp.b   #66,d0                  out past the 9885's "supported" range?
	bgt     f85mtd                  branch if so (don't leave "extra" tracks)

	bsr     f85lgin                 give the password
	move    v85scmd(a6),d0          basic command skeleton
	ror     #5,d0
	or.b    v85gtc(a6),d0           current logical track number
	rol     #5,d0
	or      #30,d0                  format command for this track

	bsr     f85wf                   wait for the flag
	move    d0,4(a4)                place the command in the output buffer
	trap    #11                                                     scs
* scs   move    sr,-(sp)                prepare to disable interrupts
	ori     #$2700,sr               disable interrupts
************************ interrupts disabled *************************
	move.b  d0,(a4)                 set the peripheral control flag

	moveq   #30-1,d1                initialize the loop counter
	movea.l v85lrso(a6),a0          logical record spiral offset
	moveq   #0,d0                   need upper byte cleared

f85flb  move.b  (a0)+,d0                next logical record number to send

	bsr     f85cswf                 check status and wait for the flag
	  bra.s f85fle                  ret 1; terminate & check status

	move    d0,4(a4)                place the lrn in the output buffer
	move.b  d0,(a4)                 set the peripheral control flag

	dbra    d1,f85flb               loop until all 30 lrn's sent

f85fle  move    (sp)+,sr                re-enable interrupts
*********************** interrupts re-enabled ************************
	bsr     f85fst                  fetch status
	and     #$FFF8,d0               strip the drive & disc change bits
	cmp     #$0040,d0               format complete, no errors?
	bne     f85die                  if not, decode and issue error
*
* prepare for reading and writing under i/o control
*
	lea     f85ptrn,a3              first test pattern address

	move.b  #4,v85patc(a6)          init the pattern count

	page

*
* loop to read verify the previous pattern and write the next pattern
*   note: the first test pattern was written by the format command!
*         the last pattern written is 0, and will not be read verified
*

*
* verify under i/o control
*
f85vwl  movea.l v85lrso(a6),a0          logical record spiral offset
	move.l  a0,v85lrp(a6)           init the logical record pointer

	move.b  #30,v85rc(a6)           init the record counter

	moveq   #0,d0                   clear the upper byte
	move.b  v85gtc(a6),d0           this track's logical track#
	mulu    #30,d0                  this track's logical record 0
	move    d0,v85lr0(a6)           save it

f85vl   movea.l v85lrp(a6),a0           logical record pointer
	moveq   #0,d0                   clear upper byte and word
	move.b  (a0)+,d0                logical record to verify next
	add     v85lr0(a6),d0           this track's logical record 0
	move.l  a0,v85lrp(a6)           updated logical record pointer
	move    d0,v85frec(a6)          record to verify

	sf      v85rwf(a6)              set read/write flag to read
	bsr     f85xfr                  do the transfer
	  bra.s f85ferr                 ret 1; some error occurred

	subq.b  #1,v85rc(a6)            decrement the record counter
	bgt     f85vl                   loop til all 30 records are verified

*
* write under i/o control
*
	move    (a3),d0                 test pattern
	swap    d0
	move    (a3)+,d0                need it in upper & lower words
	lea     v85buf(a6),a0           first word address
	moveq   #64-1,d1                initialize the loop counter
	move.l  d0,(a0)+                write four bytes
	dbra    d1,*-2                  loop until done

	movea.l v85lrso(a6),a0          logical record spiral offset
	move.l  a0,v85lrp(a6)           logical record pointer

	move.b  #30,v85rc(a6)           init the record count

	page

f85wl   movea.l v85lrp(a6),a0           logical record pointer
	moveq   #0,d0                   clear upper byte and word
	move.b  (a0)+,d0                next record to be written
	add     v85lr0(a6),d0           this track's logical record 0
	move.l  a0,v85lrp(a6)           updated logical record pointer
	move    d0,v85frec(a6)          record number to write

	st      v85rwf(a6)              set the read/write flag to write
	bsr     f85xfr                  do the transfer
f85ferr   bra.s f85err                  ret 1; some error occurred

	subq.b  #1,v85rc(a6)            decrement the record count
	bgt     f85wl                   loop till all 30 records are written



	subq.b  #1,v85patc(a6)          decrement the pattern count
	bgt     f85vwl                  loop until done

	addq.b  #1,v85gtc(a6)           increment the good track count

	moveq   #26,d0
	sub     intlve(a6),d0
	sub     v85r29o(a6),d0          (offset=offset-inter-r29o+26)
	ext.l   d0                      need the offset long
	bra.s   f85bof                  bump the logical record offset



*
* an error occurred in verifying or writing: is it "ok"?
*
f85err  move.b  v85stat(a6),d0          the upper byte of the error code word

	subq.b  #5,d0                   id error?
	beq.s   f85mtd                  branch if so
	subq.b  #6-5,d0                 track error?
	beq.s   f85mtd                  branch if so
	subq.b  #7-6,d0                 crc error?
	beq.s   f85mtd                  branch if so
	subq.b  #9-7,d0                 verify error?
	beq.s   f85mtd                  branch if so

	bra     f85die                  take the error exit

	page

*
* mark the (bad) track defective (invisible)
*
f85mtd  bsr     f85lgin                 give the password

	move    v85scmd(a6),d0          basic command skeleton
	or      #$0FBF,d0               form a mark track defective cmd
	bsr     f85wo                   issue it

	bsr.s   f85fst                  fetch status
	and     #$FFFC,d0               strip off the drive bits
	bne     f85die                  branch if any errors

	addq.b  #1,v85btc(a6)           increment the bad track count

	moveq   #-4,d0                  logical record offset to be bumped by 4
*       bra.s   f85bof                  bump the offset


*
* subroutine to bump the logical record spiral offset
*
f85bof  add.l   v85lrso(a6),d0          bump it
	move.l  d0,v85lrso(a6)          save it
	lea     v85ibuf(a6),a0          interleave buffer's FBA
	cmp.l   a0,d0                   offset still in range?
	bge.s   *+6                     branch if so
	moveq   #30,d0                  else put it in range
	bra.s   f85bof
	rts

*
* subroutine to fetch status
*
f85fst  bsr     f85cswf                 check status and wait for the flag
	  nop                           ret 1; error occurred

	bsr     f85winw                 word in; don't wait on the flag
	move    d0,v85stat(a6)          save the status word for now

	moveq   #0,d0
	bsr     f85wo                   complete the handshake with the '85

	move    v85stat(a6),d0          load the status word
	rts

	page

**********************************************************************
*                   routine to transfer one sector                   *
**********************************************************************

*
* gain access to the dma channel
*
f85xfr  movea.l #$500000,a2             DMA channel 0 address
	moveq   #$05,d0                 gpio dma control byte: chan 0
*
* set up the gpio card
*
	move.b  d0,v85gdcb(a6)          save the gpio dma control byte
	move.b  #0,3(a4)                clear enab, word, dmac1, dmac0
	move.b  #0,7(a4)                clear ctl1 & ctl0
*
* build and issue the seek command
*
	bsr     f85lgin                 give the password

	move    v85frec(a6),d0          first record number
	ext.l   d0                      make it long for division
	divs    #30,d0                  split into track & sector #'s
	swap    d0                      track in upper; sector in lower
	ror     #5,d0                   sector in upper bits of lower
	ror.l   #7,d0                   track&sector in upper bits of lower
	or      un(a6),d0               track&sector&00&unit in lower
	ror     #2,d0                   unit&track&sector&00
	or      #3,d0                   unit&track&sector&11
	ror     #2,d0                   11&unit&track&sector (finally!)
	bsr     f85wo                   issue the seek command

*
* partially build the appropriate transfer command
*
	bsr     f85lgin                 give the password

	move    un(a6),d0               unit number
	ror     #4,d0                   position for read/write/verify
	addq    #1,d0                   specify a record count of one

	lea     v85buf(a6),a0           read/write buffer's FWA
	move.l  a0,(a2)                 write in the DMA channel's address register

	moveq   #127,d1                 #words-1 in a sector
	move    d1,4(a2)                write in the DMA channel's count register

	bsr     f85cswf                 check status and wait for the flag
	  bra.s f85_grs                 ret 1 - error; go read status

	tst.b   v85rwf(a6)              read/write flag
	bmi.s   f85_wrt                 branch if a write

	page

*
* section for verify (read)
*
	bset    #14,d0                  make a verify command
	move    d0,4(a4)                place cmnd in the output buffer

	trap    #11                                                      scs
* scs   move    sr,-(sp)                prepare to disable interrupts
	ori     #$2700,sr               disable interrupts (except nmi)
************************ interrupts disabled *************************
	move.b  d0,(a4)                 set the peripheral control line

	bsr     f85cswf                 check status and wait for the flag
	  bra.s f85_rby                 ret 1; bypass because of error

	move    #0,4(a4)                clear the output buffers
	tst     4(a4)                   set direction in w/ dummy read
	move.b  d0,(a4)                 set the peripheral control flag

f85_rby move.b  v85gdcb(a6),3(a4)       set the gpio dma control bits
	subq    #1,4(a2)                don't dma the last word in
	blt.s   f85_rei                 don't arm if no words to dma in
	move    #$0002,6(a2)            arm the dma channel
f85_rei move    (sp)+,sr                re-enable interrupts
*********************** interrupts re-enabled ************************
	lea     v85buf+254(a6),a0       transfer's last word address

f85_rwt btst    #3,7(a4)                peripheral status set?
	bne.s   f85_tdx                 if so, terminate dma xfer now!
	btst    #0,7(a2)                dma channel still armed?
	bne     f85_rwt                 if so, loop

	bsr     f85cswf                 check status and wait for the flag
	  bra.s f85_tdx                 ret 1 - error; bypass else hang
	move    4(a4),(a0)              transfer the last word
f85_grs bra.s   f85_tdx                 go read the status word

	page

*
* section for write
*
f85_wrt bset    #15,d0                  make it a write command
	move    d0,4(a4)                place the command in the output buffer

	trap    #11                                                     scs
* scs   move    sr,-(sp)                prepare to disable interrupts
	ori     #$2700,sr               disable interrupts (except nmi)
************************ interrupts disabled *************************
	move.b  d0,(a4)                 set the peripheral control line

	move.b  v85gdcb(a6),3(a4)       set gpio card dma control bits
	move    #$0006,6(a2)            arm the dma channel

	move    (sp)+,sr                re-enable interrupts
*********************** interrupts re-enabled ************************
f85_wwt btst    #3,7(a4)                peripheral status set?
	bne.s   f85_tdx                 if so, terminate dma xfer now!
	btst    #0,7(a2)                dma channel still armed?
	bne.s   f85_wwt                 if so, loop

	bsr     f85cswf                 check status and wait for the flag
	  nop                           ret 1; some error occurred

*
* terminate the dma transfer and read the status word
*
f85_tdx move    (a2),d0                 disarm the dma channel
	clr.b   3(a4)                   clr the gpio card dma control bits

	move.b  #1,7(a4)                set the transfer complete bit
	bsr     f85winw                 word in; don't wait for the flag
	move    d0,v85stat(a6)          save the status word for now
	move.b  #0,7(a4)                clear the transfer complete bit

	moveq   #0,d0
	bsr     f85wo                   complete the handshake with the '85
*
* check for errors
*
	move    v85stat(a6),d0          drive ready, seek complete,
	and     #$FFF0,d0                 transfer complete, &
	cmp     #$0060,d0                   no error in error code?
	bne.s   *+4                     branch if any errors
	addq.l  #2,(sp)                 setup a normal (ret 2) exit
	rts                             exit

	page

**********************************************************************
*                      9885 shared driver routines                   *
**********************************************************************

*
* routine to check status while waiting on the flag
*
f85cswf addq.l  #2,(sp)                 anticipate a normal (ret 2) exit

f85tfb  btst    #0,(a4)                 flag bit
	bne.s   f85ret                  branch if set

	btst    #3,7(a4)                peripheral status bit
	beq.s   f85tfb                  keep looping unless it's set

	subq.l  #2,(sp)                 change the ret 2 back to a ret 1
f85ret  rts                             exit



*
* routine to wait for the flag
*
f85wf   btst    #0,(a4)                 flag bit
	beq     *-4                     loop until set
	rts



*
* routine to send the 9885 password
*
f85lgin move    #44679,d0               9885's "secret" password



*
* routine to send one word out on the gpio card
*
f85wo   bsr     f85wf                   wait for the flag
	move    d0,4(a4)                place word in the output buffer
	move.b  d0,(a4)                 set the peripheral control line
	rts

	page

*
* routine to receive one word in on the gpio card
*
f85wi   bsr     f85wf                   wait for the flag

f85winw move    #0,4(a4)                clear the output buffer

	tst     4(a4)                   set direction in w/ dummy read
	move.b  d0,(a4)                 set the peripheral control line
	bsr     f85wf                   wait for the flag
	move    4(a4),d0                load in the word
	rts


	end
@


53.1
log
@Automatic bump of revision number for PWS version 3.24B
@
text
@@


52.1
log
@Automatic bump of revision number for PWS version 3.24A
@
text
@@


51.1
log
@Automatic bump of revision number for PWS version 3.24d
@
text
@@


50.1
log
@Automatic bump of revision number for PWS version 3.23c
@
text
@@


49.1
log
@Automatic bump of revision number for PWS version 3.24b
@
text
@@


48.1
log
@Automatic bump of revision number for PWS version 3.24a
@
text
@@


47.1
log
@Automatic bump of revision number for PWS version 3.23
@
text
@@


46.1
log
@Automatic bump of revision number for PWS version 3.23
@
text
@@


45.1
log
@Automatic bump of revision number for PWS version 3.23C
@
text
@@


44.1
log
@Automatic bump of revision number for PWS version 3.23B
@
text
@@


43.1
log
@Automatic bump of revision number for PWS version 3.23aA
@
text
@@


42.1
log
@Automatic bump of revision number for PWS version 3.23e
@
text
@@


41.1
log
@Automatic bump of revision number for PWS version 3.23d
@
text
@@


40.1
log
@Automatic bump of revision number for PWS version 3.23c
@
text
@@


39.1
log
@Automatic bump of revision number for PWS version 3.23b
@
text
@@


38.1
log
@Automatic bump of revision number for PWS version 3.23a
@
text
@@


37.1
log
@Automatic bump of revision number for PWS version 3.3a
@
text
@@


36.1
log
@Automatic bump of revision number for PWS version 3.22
@
text
@@


35.1
log
@Automatic bump of revision number for PWS version 3.22
@
text
@@


34.1
log
@Automatic bump of revision number for PWS version 3.22
@
text
@@


33.1
log
@Automatic bump of revision number for PWS version 3.22D
@
text
@@


32.1
log
@Automatic bump of revision number for PWS version 3.22C
@
text
@@


31.1
log
@Automatic bump of revision number for PWS version 3.22B
@
text
@@


30.1
log
@Automatic bump of revision number for PWS version 3.22A
@
text
@@


29.1
log
@Automatic bump of revision number for PWS version 3.22b
@
text
@@


28.1
log
@Automatic bump of revision number for PWS version 3.3b
@
text
@@


27.1
log
@Automatic bump of revision number for PWS version 3.3a
@
text
@@


26.1
log
@Automatic bump of revision number for PWS version 3.3 Synch
@
text
@@


25.1
log
@Automatic bump of revision number for PWS version 3.2Y
@
text
@@


24.1
log
@Automatic bump of revision number for PWS version 3.2
@
text
@@


23.1
log
@Automatic bump of revision number for PWS version 3.2P
@
text
@@


22.1
log
@Automatic bump of revision number for PWS version 3.2N
@
text
@@


21.1
log
@Automatic bump of revision number for PWS version 3.2M
@
text
@@


20.1
log
@Automatic bump of revision number for PWS version 3.2L
@
text
@@


19.1
log
@Automatic bump of revision number for PWS version 3.2K
@
text
@@


18.1
log
@Automatic bump of revision number for PWS version 3.2J
@
text
@@


17.1
log
@Automatic bump of revision number for PWS version 3.2I+
@
text
@@


16.1
log
@Automatic bump of revision number for PWS version 3.2I
@
text
@@


15.1
log
@Automatic bump of revision number for PWS version 3.2H
@
text
@@


14.1
log
@Automatic bump of revision number for PWS version 3.2G
@
text
@@


13.1
log
@Automatic bump of revision number for PWS version 3.2F
@
text
@@


12.1
log
@Automatic bump of revision number for PWS version 3.2E
@
text
@@


11.1
log
@Automatic bump of revision number for PWS version 3.2D
@
text
@@


10.1
log
@Automatic bump of revision number for PWS version 3.2C
@
text
@@


9.1
log
@Automatic bump of revision number for PWS version 3.2B
@
text
@@


8.1
log
@Automatic bump of revision number for PWS version 3.2A
@
text
@@


7.1
log
@Automatic bump of revision number for PWS version 3.2l
@
text
@@


6.1
log
@Automatic bump of revision number for PWS version 3.2k
@
text
@@


5.1
log
@Automatic bump of revision number for PWS version 3.2j
@
text
@@


4.1
log
@Automatic bump of revision number for PWS version 3.2i
@
text
@@


3.1
log
@Auto bump revision for PAWS 3.2h
@
text
@@


2.1
log
@Auto bump rev number to 2.1 for sys 3.2e.
@
text
@@


1.1
log
@Initial revision
@
text
@@
