home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d07xx / d0787.lha / Spartan / generic_version / rdwt.asm < prev    next >
Assembly Source File  |  1992-12-24  |  6KB  |  249 lines

  1. ;
  2. ; BUSY check on SELECT
  3. ; improved handshake on MSGIN, CMDOUT 
  4. ;
  5. ; 26 May 1992 TM
  6. ; 17 Jun 1992 TM    SCSI BUSY FLAG ADDED for simaltaneous copy bug
  7. ; 15 Sep 1992 TM        GENERIC version
  8. ; 04 Oct 1992 HL    Selection timeout return status added
  9. ;             Normal return status zero added
  10. ;            Removal of "15(a1)" accesses
  11. ;
  12.     include        "exec/types.i"
  13.     include        "exec/io.i"
  14.     include        "exec/devices.i"
  15.     include        "exec/tasks.i"
  16.     include        "exec/interrupts.i
  17.     include        "devices/scsidisk.i"
  18.     include        "mydev.i"
  19.     include        "scsi.i"
  20.  
  21.     Public        SCSIRdWt
  22.  
  23. SCSIRdWt:
  24.     bset.b    #3,NCR+4    ;TM!!! EOP INTERRUPT bit is used for
  25.     bne.s    SCSIRdWt    ;TM!!! SCSI BUSY FLAG
  26.     move.b    #$08,NCR+4    ;TM!!!
  27.     movem.l    d4-d7/a1-a5,-(sp)    ;save regs
  28.     move.l    #CMDBUF,a1        ;get CMDBUF add
  29.     move.l    d2,d5        ;copy unit#
  30.     moveq    #$0,d2        ;LU=0
  31.     lsr.l    #1,d5        ;create Target address
  32.     bcc.s    Drive
  33.     moveq    #$20,d2        ;LU=1
  34. STILLbsy1:
  35.     btst.b    #6,NCR+8    ; TM BUSY check
  36.     bne.s    STILLbsy1    ; TM wait if still busy
  37. Drive:
  38.     moveq    #$1,d4
  39.     lsl.l    d5,d4        ;shift to address bit
  40.     or.b    #$80,d4        ;add addresses
  41.     move.b    d4,NCR        ;load addresses
  42.     move.b    #$5,NCR+2    ;assert BUS with address
  43.  
  44. ;build the scsi cmd packet
  45.     move.l    d1,d4        ;get the start sect #
  46.     move.l    d0,d5        ;get the #bytes to transfere
  47.     asr.l    #8,d5        ;shift 9 palces to get sectors
  48.     asr.l    #1,d5
  49.     and.l    #$FF,d5        ;must be less than 1 byte
  50. ;    asl.l    #8,d5        ;move to upper byte in word; TM to enable NEC cache
  51. ;    move.w    d5,4(a1)    ;place in packet           ; TM
  52.     move.b    d5,4(a1)    ;place in packet           ; TM don't mask last byte
  53.     asr.l    #8,d4        ;convert to sectors
  54.     asr.l    #1,d4
  55.     and.l    #$000FFFFF,d4    ;mask out L U #
  56.     move.l    d4,(a1)        ;place in packet
  57. ;add the logical unit #
  58.     or.b    d2,1(a1)    ;put LU# in the packet
  59.     cmp.w    #CMD_READ,IO_COMMAND(a2)    ;read ?
  60.     bne    WriteSCSI
  61.     move.b    #$08,(a1)    ;set cmd to read
  62.  
  63. Selection:
  64.     bsr    SELph        ;select the target
  65.  
  66. End:
  67.     bclr.b    #3,NCR+4    ;TM!!! clear SCSI BUSY FLAG
  68.     movem.l    (sp)+,d4-d7/a1-a5    ;restore regs
  69.     rts            ;return to caller
  70.  
  71. WriteSCSI:    ;send data to the SCSI
  72.     move.b   #$0a,(a1)
  73.     bra.s   Selection
  74.  
  75.  
  76. SELph:        ;select the target
  77.     move.l   #M250,d5    ;load timer
  78.  
  79. loop1:    btst.b   #6,NCR+8    ;test BSY
  80.     bne.s    SLECT        ;if busy , selected
  81.     subq    #1,d5        ;dec timer
  82.     bne.s    loop1        ;loop
  83. ;    move.b    #$01,15(a1)    ;set drive not ready error ; HL
  84.     move.b  #HFERR_SelTimeout,d0 ; HL
  85.     rts
  86.  
  87. SLECT:
  88.     and.b    #$FB,NCR+2    ;clr SEL
  89.       
  90. NextPhase:    ;Check the SCSI bus phase
  91.     move.b    #$0,NCR
  92.     move.b    #$0,NCR+6    ;clear TCR
  93.     btst.b    #5,NCR+8    ;test REQ
  94.     bne.s    GotREQ        ;if REQ it must be busy...
  95.     btst.b    #6,NCR+8    ;check BUSY
  96.     beq    Done        ;bus free
  97.     bra    NextPhase    ; still waiting for REQ
  98. GotREQ:
  99.     btst.b    #3,NCR+8    ;check C/D
  100.     beq.s    Dat        ;data in/out phase
  101.     btst.b    #4,NCR+8    ;check MSG
  102.     bne.s    Message        ;Message in/out phase
  103.     btst.b    #2,NCR+8    ;check I/O
  104.     bne.s    STATph        ;stat phase
  105.     bra.s    CMDph        ;command phase
  106. Message:    ;check to see if it is message in or out
  107.     btst.b    #2,NCR+8    ;check I/O
  108. ;    bne.s    MSGINph      
  109.     bne    MSGINph        ;TM
  110. ;    bra.s    MSGOUTph    ;TM
  111.     bra    MSGOUTph    ;TM        
  112. Dat:        ;check to see if it is data in or out
  113.     btst.b    #2,NCR+8    ;check I/O
  114. ;    bne.s    RDATph
  115.     bne    RDATph        ;TM
  116. ;    bra.s    SDATph        ;TM
  117.     bra    SDATph        ;TM
  118. CMDph:        ;send command
  119.     move.l    #CMDBUF,a4    ;set the cmd buffer add
  120.     move.b    #$02,NCR+6    ;set TCR to command phase
  121. Send:        ;send x characters to the target
  122.     btst.b    #6,NCR+8    ;TM busy check
  123.     beq    Done        ;TM busy check
  124.     btst.b    #5,NCR+8    ;test for REQ
  125.     beq.s    Send        ;wait for REQ
  126.     btst.b    #3,NCR+10    ;test phase match
  127. ;    beq.s    NextPhase
  128.     beq    NextPhase    ;TM
  129.     move.b    (a4)+,NCR    ;set the byte
  130.     ori.b    #$10,NCR+2    ;set ACK
  131. CMDReq:
  132.     btst.b    #6,NCR+8    ;TM busy check
  133.     beq    Done        ;TM busy check
  134.     btst.b    #5,NCR+8    ; TM test for REQ
  135.     bne.s    CMDReq        ; TM wait for REQ deasserted
  136.     andi.b    #$EF,NCR+2    ;clr ACK
  137.     bra    Send   
  138.  
  139. STATph:        ;get status byte
  140.     ori.b    #$10,NCR+2    ;set ACK
  141. STATReq:
  142.     btst.b    #6,NCR+8    ;TM busy check
  143.     beq    Done        ;TM busy check
  144.     btst.b    #5,NCR+8    ; TM test for REQ
  145.     bne.s    STATReq        ; TM wait for REQ deasserted
  146.     andi.b    #$ef,NCR+2    ;clr ACK
  147.     bra    NextPhase
  148.  
  149. MSGINph:    ;only msg supported is COMPLETE..so we just ack it
  150.     ori.b    #$10,NCR+2    ;set ACK   
  151. MSGINReq:
  152.     btst.b    #6,NCR+8    ;TM busy check
  153.     beq    Done        ;TM busy check
  154.     btst.b    #5,NCR+8    ; TM test for REQ
  155.     bne.s    MSGINReq    ; TM wait for REQ deasserted
  156.     and.b    #$EF,NCR+2    ;clr ACK
  157. STILLbsy:
  158.     btst.b    #6,NCR+8    ; TM BUSY check
  159.     bne.s    STILLbsy    ; TM wait if still busy
  160. Done:        ;did we end normally ?
  161.     clr.l    d0        ; HL 
  162.     rts    ;do a clean end
  163.  
  164. MSGOUTph:    ;send message to target
  165.     bra    NextPhase    ;error try again
  166.  
  167. SDATph:        ;send data to target
  168.     move.l    a0,a4        ;set the data buffer add
  169.     move.b    #$00,NCR+6    ;set TCR to send data
  170. SendData:    ;send x characters to the target
  171.     btst.b    #6,NCR+8    ;TM busy check
  172.     beq    Done        ;TM busy check
  173.     btst.b    #5,NCR+8    ;test for REQ
  174.     beq.s    SendData    ;wait for REQ
  175.     btst.b    #3,NCR+10    ;test phase match
  176. ;    beq.s    NextPhase
  177.     beq    NextPhase    ;TM
  178. ;    move.b    #$02,NCR+4    ;Set DMAMODE
  179.     bset.b    #1,NCR+4    ;TM!!!
  180.     move.b    #$00,NCR+12    ;start DMA recieve
  181.     moveq    #64,d4        ;load counter..we do 512 byte blocks
  182. LoopTop:
  183.     move.b    (a4)+,DMA    ;set byte 0
  184.     move.b    (a4)+,DMA    ;set byte 1
  185.     move.b    (a4)+,DMA    ;set byte 2
  186.     move.b    (a4)+,DMA    ;set byte 3
  187.     move.b    (a4)+,DMA    ;set byte 4
  188.     move.b    (a4)+,DMA    ;set byte 5
  189.     move.b    (a4)+,DMA    ;set byte 6
  190.     move.b    (a4)+,DMA    ;set byte 7
  191.     subq    #1,d4
  192.     bne.s    LoopTop
  193. ;    move.b    #$0,NCR+4    ;clear DMAMODE
  194.     bclr.b    #1,NCR+4    ;TM!!!
  195.     bra    SendData
  196.    
  197.  
  198.  
  199. RDATph:        ;receive data fron target
  200.     move.l    a0,a4        ;set the data buffer add
  201.     lea    DMA+12,a5    ;set DMA recieve Base
  202.     move.b    #$01,NCR+6    ;set TCR to receive data
  203. RecData:
  204. ;    move.b    #$02,NCR+4    ;Set DMAMODE
  205.     bset.b    #1,NCR+4    ;TM!!!
  206.     move.b    #$00,NCR+14    ;start DMA recieve
  207.     moveq    #63,d4        ;load counter..we do 512 byte blocks
  208. RecLoop:
  209.     move.b    (a5),(a4)+
  210.     move.b    (a5),(a4)+
  211.     move.b    (a5),(a4)+
  212.     move.b    (a5),(a4)+
  213.     move.b    (a5),(a4)+
  214.     move.b    (a5),(a4)+
  215.     move.b    (a5),(a4)+
  216.     move.b    (a5),(a4)+
  217.     subq    #1,d4        ;decrement counter
  218.     bne.s    RecLoop        ;done with block?
  219.     move.b    (a5),(a4)+
  220.     move.b    (a5),(a4)+
  221.     move.b    (a5),(a4)+
  222.     move.b    (a5),(a4)+
  223.     move.b    (a5),(a4)+
  224.     move.b    (a5),(a4)+
  225.     move.b    (a5),(a4)+
  226. ;    move.b    #$0,NCR+4    ;disable ack/req
  227.     bclr.b    #1,NCR+4    ;TM!!!
  228.     move.b    (a5),(a4)+    ;read last byte of block
  229.  WRec:
  230.     btst.b    #5,NCR+8    ;test REQ
  231.     bne.s    RReq        ;Got it
  232.     btst.b    #6,NCR+8    ;check BUSY
  233.     beq    Done        ;Not Busy? must be Done.
  234.     bra.s    WRec        ;wait for REQ
  235. RReq:
  236.     btst.b    #3,NCR+10    ;test for phase match
  237.     beq    NextPhase
  238.     bra.s    RecData
  239.  
  240. CMDBUF    dc.b    $0A,$00,$00,$00,$01,$00,$00,$00,$00,$00 ; TM GENERIC
  241. ;CMDBUF    dc.b    $0A,$00,$00,$00,$01,$0c,$00,$00,$00,$00  ; TM for NEC cache
  242. STAT    ds.b    $01        ;status word
  243. MSGINBUF    ds.b    $04    ;message buffer
  244. ERROR    ds.b    $01        ;error flag
  245. ;
  246. ;
  247.     END
  248.