home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d6xx / d698 / scram500.lha / SCRAM500 / SCRAM500.lzh / software / example.asm next >
Assembly Source File  |  1992-06-20  |  11KB  |  227 lines

  1. *===================================================================*
  2. *                                                                   *
  3. * Example program demonstrating the various methods of talking to   *
  4. * the SCRAM 500 device driver.                                      *
  5. *                                                                   *
  6. * Both standard and SCSI-Direct methods are demonstrated.           *
  7. *                                                                   *
  8. * The code is verbosely commented to make it simple to understand   *
  9. * but some knowledge of 68000 assembler programming on the part of  *
  10. * the reader is assumed.                                            *
  11. *                                                                   *
  12. * All code by Will McGovern.  (yes, I wrote the driver as well !!)  *
  13. *                                                                   *
  14. * BLATENT AD ==> For a custom written driver for your hardware,     *
  15. *                send inquiries to :                                *
  16. *                                                                   *
  17. *                         Will McGovern                             *
  18. *                         PO Box 247,                               *
  19. *                         NEW LABTON,                               *
  20. *                         NSW 2289                                  *
  21. *                         AUSTRALIA                                 *
  22. *                                                                   *
  23. * The code is written to be assembled with Macro68 from DigiSoft    *
  24. * but can be converted to other formats with ease.  Any Macro68     *
  25. * specific directives are explained.                                *
  26. *                                                                   *
  27. * The 2.0 include files are used for all symbols and equates.       *
  28. *                                                                   *
  29. * THIS CODE IS COMPLETELY PUBLIC DOMAIN. USE IT HOWEVER YOU WANT !! *
  30. *===================================================================*
  31.  
  32.  Macro68 assembler directives
  33.  
  34.                 mc68000                     ;68000 mode
  35.                 strict                      ;strict syntax mode
  36.                 exeobj                      ;executable object file
  37.                 objfile    'example'        ;object filename
  38.  
  39.  SYS : Call system vector macro
  40.  
  41. sys             macro
  42.                 jsr(_LVO\1,a6)
  43.                 endm
  44.  
  45. *------------------------------------------------------------------
  46.  
  47. EXAMPLE_UNIT     equ      0                 ;scsi unit to talk to
  48. BLOCK_SIZE       equ      $200              ;size of 512 byte block
  49. MAXAUTO_SIZE     equ      $fe               ;maximum autosense size
  50. MAXINQUIRY_SIZE  equ      $fe               ;maximum # of inquiry bytes
  51.  
  52. *------------------------------------------------------------------
  53.  
  54.             section  excode,code
  55.  
  56.  Find this task and see if we started from workbench or from a CLI
  57.  
  58. start       movea.l  (4).w,a6            ;exec library base
  59.             suba.l   a1,a1               ;this task
  60.             sys      FindTask            ;find this task
  61.             movea.l  d0,a4               ;save task pointer
  62.             tst.l    (pr_CLI,a4)         ;did we come from a CLI ?
  63.             bne.s    clistartup          ;branch if CLI entry
  64.  
  65.  Discard the workbench startup msg
  66.  
  67.             lea     (pr_MsgPort,a4),a0  ;this task's message port
  68.             sys     WaitPort            ;wait for WB startup message
  69.             lea     (pr_MsgPort,a4),a0  ;this task's message port
  70.             sys     GetMsg              ;fetch the startup message
  71.  
  72.  Initialise a message port (MP) for use with my IORequest structure
  73.  
  74. clistartup   movea.l  #mymp,a2              ;my message port
  75.              move.l   a4,(MP_SIGTASK,a2)    ;save pointer to this task
  76.              moveq    #-1,d0                ;any signal will do
  77.              sys      AllocSignal           ;allocate a signal for MP
  78.              move.b   d0,(MP_SIGBIT,a2)     ;save signal # in MP
  79.              bmi      nosignal              ;branch if error
  80.              movea.l  a2,a1                 ;copy MP pointer
  81.              sys      AddPort               ;add my MP to the system
  82.  Open scram.device for EXAMPLEUNIT
  83.  
  84.              movea.l  #scramname,a0         ;scram.device name
  85.              movea.l  #myior,a1             ;my IORequest structure
  86.              move.l   a2,(MN_REPLYPORT,a1)  ;init MP pointer in IOR
  87.              moveq    #EXAMPLE_UNIT,d0      ;scsi unit to talk to
  88.              moveq    #0,d1                 ;no flags
  89.              sys      OpenDevice            ;open scram.device
  90.              tst.l    d0                    ;any errors ?
  91.              bne.b    noscramdevice         ;branch if error
  92.  
  93. * Now we can talk to the scram.device through the standard 
  94. * device commands such as CMD_READ or use the HD_SCSICMD command 
  95. * for SCSI-Direct mode.
  96.  
  97.  Here are some examples of normal and SCSI-Direct mode access.
  98.  
  99.  
  100.  Read block 0 from the unit into blockbuffer using CMD_READ command
  101.  
  102.              movea.l #myior,a1                    ;IORequest pointer
  103.              move.w  #CMD_READ,(IO_COMMAND,a1)    ;CMD_READ command
  104.              move.l  #blockbuffer,(IO_DATA,a1)    ;buffer for data
  105.              clr.l   (IO_OFFSET,a1)               ;block 0
  106.              move.l  #BLOCK_SIZE,(IO_LENGTH,a1)   ;one block to read
  107.              sys     DoIO                         ;read the block
  108.              tst.b   d0                           ;any error ?
  109.              bne.b   cmdreaderror                 ;error if d0 not zero
  110.  
  111.  Now do the same as above in SCSI-Direct mode
  112.  
  113.              movea.l #myior,a1                    ;IORequest pointer
  114.              move.w  #HD_SCSICMD,(IO_COMMAND,a1)  ;CMD_READ command
  115.              move.l  #scsireadcmd,(IO_DATA,a1)    ;pointer to SCSICmd
  116.              sys     DoIO                         ;read the block
  117.              tst.b   d0                           ;any error ?
  118.              bne.b   scsireaderror                ;error if d0 not zero
  119.  
  120.  Perform a SCSI INQUIRY command on the EXAMPLE_UNIT
  121.  
  122.              movea.l #myior,a1                    ;IORequest pointer
  123.              move.w  #HD_SCSICMD,(IO_COMMAND,a1)  ;HD_SCSICMD command
  124.              move.l  #scsiinquirycmd,(IO_DATA,a1) ;pointer to SCSICmd
  125.              sys     DoIO                         ;perform inquiry
  126.              tst.b   d0                           ;any error ?
  127.              beq.b   exitexample                  ;error if d0 not zero
  128.  
  129.  This is where an error handler would be placed if this was serious code
  130.  
  131. cmdreaderror:
  132. scsireaderror  nop
  133.  
  134.  Clean up our mess and return to DOS
  135.  
  136. exitexample    movea.l  #myior,a1           ;pointer to my IORequest
  137.                sys      CloseDevice         ;close scram.device
  138. noscramdevice  movea.l  #mymp,a1            ;pointer to my MP
  139.                sys      RemPort             ;remove my message port
  140.                moveq    #0,d0               ;prepare D0 for byte load
  141.                move.b   (mymp+MP_SIGBIT),d0 ;get signal # we allocated
  142.                sys      FreeSignal          ;free the allocated signal
  143. nosignal       moveq    #0,d0               ;clear return code
  144.                rts                          ;return to DOS
  145.  
  146. *--------------------------------------------------------------------
  147.  
  148.     section    exdata,data
  149.  
  150.  
  151. Note: The SCSICmd structure used in this example did not appear in the
  152.       early 1.3 include files in its entirety.  C= omitted the autosense
  153.       information.  See the 2.0 include file "devices/scsidisk.i" for a
  154.       full description of the SCSI-Direct protocol.
  155.  
  156.       Also note that the SCSIF_AUTOSENSE (4 byte sense length) has 
  157.       become SCSIF_OLDAUTOSENSE in the 2.0 implementation.
  158.  
  159.       The new SCSIF_AUTOSENSE supports sense data lengths of 4 to 255
  160.       bytes.  The sense length is specified in scsi_SenseLength field.
  161.  
  162. The SCSIF_READ/SCSIF_WRITE flags are NOT required by the scram.device as
  163. the data direction is determined automatically by the driver.
  164.  
  165.  
  166.  SCSICmd structure for reading block 0
  167.  
  168. scsireadcmd    dc.l     blockbuffer           ;data buffer address
  169.                dc.l     BLOCK_SIZE            ;number of bytes to read
  170.                dc.l     0                     ;actual bytes read
  171.                dc.l     readcmd               ;pointer to scsi CDB
  172.                dc.w     10                    ;# of command bytes
  173.                dc.w     0                     ;actual cmd bytes sent
  174.                dc.b     SCSIF_AUTOSENSE       ;automatic sense
  175.                dc.b     0                     ;status byte
  176.                dc.l     sensebuffer           ;buffer for sense data
  177.                dc.w     MAXAUTO_SIZE          ;size of my sense buffer
  178.                dc.w     0                     ;actual sense bytes read
  179.  
  180.  SCSICmd structure for an INQUIRY command
  181.  
  182. scsiinquirycmd dc.l     inquirybuffer         ;data buffer address
  183.                dc.l     MAXINQUIRY_SIZE       ;number of bytes to read
  184.                dc.l     0                     ;actual bytes read
  185.                dc.l     inquirycmd            ;pointer to scsi CDB
  186.                dc.w     6                     ;# of command bytes
  187.                dc.w     0                     ;actual cmd bytes sent
  188.                dc.b     SCSIF_AUTOSENSE       ;automatic sense
  189.                dc.b     0                     ;status byte
  190.                dc.l     sensebuffer           ;buffer for sense data
  191.                dc.w     MAXAUTO_SIZE          ;size of my sense buffer
  192.                dc.w     0                     ;actual sense bytes read
  193.  
  194. * Here are the actual command desciptor blocks (CDB's) sent to the 
  195. * selected scsi unit.
  196. *
  197. * For more information on these consult the SCSI specifications or the 
  198. * manual for your scsi device.
  199.  
  200. readcmd        dc.w   $2800,$0000,$0000,$0000,$0100  ;extended read
  201. inquirycmd     dc.w   $1200,$0000,MAXINQUIRY_SIZE<<8
  202.  
  203.  Text and byte data
  204.  
  205. scramname      cstr     'scram.device'        ;null terminated name
  206.                even
  207.  
  208. *--------------------------------------------------------------------
  209.  
  210. section        exbss,data
  211.  
  212. mymp           ds.b     MP_SIZE               ;my message port structure
  213.                even
  214. myior          ds.b     IOSTD_SIZE            ;my IORequest structure
  215.                even
  216. inquirybuffer  ds.b     MAXINQUIRY_SIZE       ;inquiry data buffer
  217.                even
  218. sensebuffer    ds.b     MAXAUTO_SIZE          ;autosense data buffer
  219.                even
  220. blockbuffer    ds.b     BLOCK_SIZE            ;block data buffer
  221.                even
  222.  
  223. *--------------------------------------------------------------------
  224.  
  225.                end
  226.  
  227.