home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / AHDI / TESTSPAR / SCSI.FTH < prev    next >
Encoding:
Text File  |  2001-02-09  |  2.4 KB  |  74 lines

  1. ( Sparrow SCSI Words )
  2. ( 91.10.31  atari!jtittsler )
  3.  
  4. hex 
  5.  
  6. : wr  ( val reg -- )         ( write 'val' to 5380 register )
  7.    88 + wdl wdc ;
  8.  
  9. : rr  ( reg -- val )         ( read from 5380 register )
  10.    88 + wdl rdc ;
  11.  
  12. : sreset ( -- )              ( reset the SCSI bus )
  13.    80 1 wr  30 delay         ( assert reset )
  14.    0 1 wr   30 delay         ( deassert reset )
  15.    begin 7 rr drop 5 rr 10 and 0= until ;   ( clear interrupts that result )
  16.  
  17. : select ( devid -- )        ( select the specified SCSI device, no arb )
  18.    0 3 wr
  19.    0 4 wr   c 1 wr   0 wr
  20.    5 1 wr   2 rr fe and 2 wr
  21.             1 rr f7 and 1 wr
  22.    begin 4 rr 40 and until 
  23.             1 rr fa and 1 wr ;
  24.  
  25. : doack  ( -- )              ( assert ACK, wait for REQ to go away, clear ACK)
  26.    1 rr 11 or 1 wr
  27.    begin 4 rr 20 and 0= until
  28.    1 rr ef and 1 wr ;
  29.  
  30. ( send command to drive, except for final control byte )
  31. : cmd  ( #blocks lsb xsb msb cmd -- #blocks )
  32.    0 wr  2 3 wr  1 1 wr  doack
  33.    swap rot 3 0 do   0 wr doack  loop
  34.    dup 0 wr doack ;
  35.  
  36. : w4irq  ( -- )         ( wait for 5380 to assert HDIRQ )
  37.    begin gpip c@io 20 and 0= until ;
  38.  
  39. : sread   ( #blocks lsb xsb msb -- status )
  40.    7 rr drop            ( clear potential interrupt )
  41.    1 select             ( select unit 0 )
  42.    8 cmd                ( issue READ command )
  43.    190 wdl 90 wdl wdc   ( set the number of blocks to DMA )
  44.    0 0 wr doack         ( write final command byte to drive )
  45.    1 3 wr 2 2 wr        ( data out phase )
  46.    0 7 wr 0 wdl
  47.    w4irq 7 rr drop      ( wait for interrupt, and clear it )
  48.    0 3 wr  0 rr ff and doack  ( get status byte )
  49.    w4irq doack ;        ( wait for, ack, and ignore the message byte )
  50.  
  51. : swrite  ( #blocks lsb xsb msb -- status )
  52.    7 rr drop            ( clear potential pending interrupt )
  53.    cr
  54.    1 select             ( select the drive )
  55.    ."  selected"
  56.    0a cmd               ( issue the command )
  57.    ."  commanded"
  58.    190 wdl
  59.    ."  190"
  60.    wdc                  ( set number of blocks to DMA )
  61.    ."  nonzero cnt"
  62.    100 wdl
  63.    100 0 wr doack       ( write final command byte to drive )
  64.    101 1 wr  100 3 wr  102 2 wr  100 5 wr
  65.    ."  wait4irq"
  66.    w4irq
  67.    ."  status"
  68.    88 wdl 0 3 wr
  69.    7 rr drop 0 3 wr
  70.    0 rr ff and doack    ( get status byte )
  71.    ."  message"
  72.    w4irq doack
  73.    ."  complete" ;      ( wait for, ack, and ignore the message byte )
  74.