home *** CD-ROM | disk | FTP | other *** search
/ Shareware Supreme Volume 6 #1 / swsii.zip / swsii / 165 / ST0102.ZIP / IOCTL.ASM < prev    next >
Assembly Source File  |  1991-11-18  |  6KB  |  261 lines

  1. ;
  2. ; Process an ioctl request for the current unit
  3. ;
  4. ; return 'C' on error
  5. ;
  6. scsi_ioctl    proc
  7.         mov    al,es:[bx].rh19_minor        ;Get the minor number
  8.         cmp    al,40h                ;Set Device Params?
  9.         jnz    scsi_i_42h
  10.         clc
  11.         jmp    scsi_i_exit
  12.  
  13. scsi_i_42h:    cmp    al,42h                ;Format and Verify?
  14.         jnz    scsi_i_60h
  15.         mov    di,es:[bx].rh19_buf_ofs        ;Get the Param Buffer
  16.         mov    ax,es:[bx].rh19_buf_seg
  17.         mov    es,ax
  18.         mov    ax,es:[di].ioctl_fmt_cyl    ;Cylinder
  19.         mov    bx,SECT_TRACK
  20.         mul    bx                ;Convert to Sector
  21.         mov    cx,es:[di].ioctl_fmt_head    ;Head
  22.         or    cx,cx
  23.         jz    head0_42h
  24. head_loop_42h:    add    ax,SECT_TRACK            ;Add Head Tracks
  25.         adc    dx,0
  26.         loop    head_loop_42h
  27. head0_42h:    mov    bx,0
  28.         mov    cx,es:[di].ioctl_fmt_len    ;How Many Tracks
  29. len_loop_42h:    add    bx,SECT_TRACK            ;Convert to Sectors
  30.         loop    len_loop_42h
  31.         mov    cx,bx
  32.  
  33.         ife large_drives
  34.         mov    di,cur_bpb            ;Add Drive Offset
  35.         mov    dx,[di].bpb_hs_msw
  36.         endif
  37.  
  38.         call    scsi_verify
  39.         jmp    scsi_i_exit
  40.  
  41. scsi_i_60h:    cmp    al,60h                ;Get Device Params?
  42.         jnz    scsi_i_61h
  43. build_bpb:    mov    si,cur_bpb            ;Get the Current BPB
  44.         mov    di,es:[bx].rh19_buf_ofs        ;Get the Param Buffer
  45.         mov    ax,es:[bx].rh19_buf_seg
  46.         mov    es,ax
  47.         mov    es:[di].dpb_special,05h        ;Sect Same/Use Cur BPB
  48.         mov    es:[di].dpb_type,05h        ;Fixed Disk
  49.         mov    es:[di].dpb_attr,0001h        ;Not Removable
  50.         if large_drives
  51.         mov    dx,[si].bpb_ts_msw
  52.         mov    ax,[si].bpb_ts_lsw
  53.         else
  54.         mov    dx,0
  55.         mov    ax,[si].bpb_ts
  56.         endif
  57.         add    ax,1                ;Sectors (1-n)
  58.         adc    dx,0
  59.         mov    bx,SECT_TRACK
  60.         div    bx
  61.         mov    es:[di].dpb_cyl,ax
  62.         mov    es:[di].dpb_media,0        ;????
  63.         mov    es:[di].dpb_sectors,SECT_TRACK    ;Sectors per Track
  64.  
  65.         push    di
  66.         lea    di,es:[di].dpb_bpb        ;Copy the bpb into
  67.         mov    cx,size bpb            ;the requestors buffer
  68.         cld
  69.     rep    movsb
  70.         pop    di
  71.  
  72.         lea    di,es:[di].dpb_track        ;Build the Track List
  73.         mov    cx,SECT_TRACK
  74.         mov    ax,0                ;Start with Sector 0
  75. scsi_i_t_loop:    mov    es:[di],ax            ;Sector Number
  76.         inc    ax
  77.         inc    di
  78.         inc    di
  79.         mov    word ptr es:[di],P_SECT        ;Sector Size
  80.         inc    di
  81.         inc    di
  82.         loop    scsi_i_t_loop
  83.         clc
  84.         jmp    short scsi_i_exit
  85.  
  86. scsi_i_61h:    cmp    al,61h                ;Read Track?
  87.         jnz    scsi_i_62h
  88.         mov    di,es:[bx].rh19_buf_ofs        ;Get the Param Buffer
  89.         mov    ax,es:[bx].rh19_buf_seg
  90.         mov    es,ax
  91.         mov    ax,es:[di].ioctl_read_cyl    ;Cylinder
  92.         mov    bx,SECT_TRACK
  93.         mul    bx                ;Convert to Sector
  94.         mov    cx,es:[di].ioctl_read_head    ;Head
  95.         or    cx,cx
  96.         jz    head0_61h
  97. head_loop_61h:    add    ax,SECT_TRACK            ;Add Head Tracks
  98.         adc    dx,0
  99.         loop    head_loop_61h
  100. head0_61h:    add    ax,es:[di].ioctl_read_sect    ;Offset into the Track
  101.         adc    dx,0
  102.         mov    cx,es:[di].ioctl_read_len    ;How Many Sectors
  103.  
  104.         ife large_drives
  105.         mov    di,cur_bpb            ;Add Drive Offset
  106.         mov    dx,[di].bpb_hs_msw
  107.         endif
  108.  
  109.         call    scsi_verify
  110.         jc    scsi_i_error
  111.         mov    es,rh_seg
  112.         mov    bx,rh_off
  113.         jmp    build_bpb
  114.  
  115. scsi_i_62h:    cmp    al,62h                ;Verify?
  116.         jnz    scsi_i_error
  117.         mov    di,es:[bx].rh19_buf_ofs        ;Get the Param Buffer
  118.         mov    ax,es:[bx].rh19_buf_seg
  119.         mov    es,ax
  120.         mov    ax,es:[di].ioctl_fmt_cyl    ;Cylinder
  121.         mov    bx,SECT_TRACK
  122.         mul    bx                ;Convert to Sector
  123.         mov    cx,es:[di].ioctl_fmt_head    ;Head
  124.         or    cx,cx
  125.         jz    head0_62h
  126. head_loop_62h:    add    ax,SECT_TRACK            ;Add Head Tracks
  127.         adc    dx,0
  128.         loop    head_loop_62h
  129. head0_62h:    mov    bx,0
  130.         mov    cx,es:[di].ioctl_fmt_len    ;How Many Tracks
  131. len_loop_62h:    add    bx,SECT_TRACK            ;Convert to Sectors
  132.         loop    len_loop_62h
  133.         mov    cx,bx
  134.  
  135.         ife large_drives
  136.         mov    di,cur_bpb            ;Add Drive Offset
  137.         mov    dx,[di].bpb_hs_msw
  138.         endif
  139.  
  140.         call    scsi_verify
  141.         jmp    short scsi_i_exit
  142.  
  143. scsi_i_error:    stc
  144. scsi_i_exit:    ret
  145. scsi_ioctl    endp
  146.  
  147. ;
  148. ; Process an ioctl_write request
  149. ;
  150. scsi_ioctl_write proc
  151.         mov    di,es:[bx].rh12_buf_ofs        ;Get The Command
  152.         mov    ax,es:[bx].rh12_buf_seg        ;Buffer
  153.         mov    es,ax
  154.         mov    ax,es:[di].ioc_command        ;What Command
  155.  
  156. ;
  157. ; Format Disk Unit
  158. ;
  159.         cmp    al,'F'                ;Format?
  160.         jnz    try_erase
  161.         mov    ax,es:[di].ioc_param1        ;Get Interleave
  162.         mov    bx,es:[di].ioc_buf_ofs        ;Get Buffer Offset
  163.         mov    cx,es:[di].ioc_buf_len        ;Get Buffer Length
  164.         mov    dx,es:[di].ioc_param2        ;Get Format Type
  165.         mov    es,es:[di].ioc_buf_seg        ;Get Buffer Seg
  166.         lea    di,cmd_format            ;Insert into Command
  167.         mov    [di].fmt_cmd_il_b1,ah
  168.         mov    [di].fmt_cmd_il_b0,al
  169.         mov    [di].fmt_cmd_type,dl
  170.         call    docmd
  171.         jnc    format_exit
  172.         call    scsi_sense
  173. format_exit:    jmp    scsi_i_w_exit
  174.  
  175. ;
  176. ; Erase Tape Unit
  177. ;
  178. try_erase:    cmp    al,'E'                ;Erase?
  179.         jnz    try_rewind
  180.         lea    di,cmd_erase            ;Now Erase Tape
  181.         call    docmd
  182.         jnc    erase_exit
  183.         call    scsi_sense
  184. erase_exit:    jmp    scsi_i_w_exit
  185.  
  186. ;
  187. ; Rewind Tape Unit
  188. ;
  189. try_rewind:    cmp    al,'R'                ;Rewind?
  190.         jnz    try_load
  191.         lea    di,cmd_rewind            ;Now Rewind Tape
  192.         call    docmd
  193.         jnc    rewind_exit
  194.         call    scsi_sense
  195. rewind_exit:    jmp    scsi_i_w_exit
  196.  
  197. ;
  198. ; Load Tape on Open
  199. ;
  200. try_load:    cmp    al,'L'                ;Load?
  201.         jnz    try_noload
  202.         mov    load_flag,TRUE
  203.         jmp    scsi_i_w_exit
  204.  
  205. ;
  206. ; No Load Tape on Open
  207. ;
  208. try_noload:    cmp    al,'N'                ;No Load?
  209.         jnz    try_space
  210.         mov    load_flag,FALSE
  211.         jmp    scsi_i_w_exit
  212.  
  213. ;
  214. ; Space Tape
  215. ;
  216. try_space:    cmp    al,'S'                ;Space?
  217.         jnz    try_filemark
  218.         mov    ax,es:[di].ioc_param1        ;Get Count
  219.         mov    bx,es:[di].ioc_param2        ;Get Type
  220.         lea    di,cmd_space            ;Insert into Command
  221.         mov    [di].space_cmd_code,bl
  222.         mov    [di].space_cmd_cnt2,ah        ;Dup of ah
  223.         mov    [di].space_cmd_cnt1,ah
  224.         mov    [di].space_cmd_cnt0,al
  225.         call    docmd
  226.         jnc    scsi_i_w_exit
  227.         call    scsi_sense
  228.         jmp    scsi_i_w_exit
  229.  
  230. ;
  231. ; Write Filemarks
  232. ;
  233. try_filemark:    cmp    al,'M'                ;Mark?
  234.         jnz    try_remap
  235.         mov    ax,es:[di].ioc_param1        ;Get Count
  236.         lea    di,cmd_twritefm            ;Insert into Command
  237.         mov    [di].fm_cmd_cnt_b1,ah
  238.         mov    [di].fm_cmd_cnt_b0,al
  239.         call    docmd
  240.         jnc    scsi_i_w_exit
  241.         call    scsi_sense
  242.         jmp    scsi_i_w_exit
  243.  
  244. ;
  245. ; Reassign Block
  246. ;
  247. try_remap:    cmp    al,'A'                ;ReAssign?
  248.         jnz    scsi_i_w_error
  249.         mov    bx,es:[di].ioc_buf_ofs        ;Get Buffer Offset
  250.         mov    cx,es:[di].ioc_buf_len        ;Get Buffer Length
  251.         mov    es,es:[di].ioc_buf_seg        ;Get Buffer Seg
  252.         lea    di,cmd_remap            ;Command
  253.         call    docmd
  254.         jnc    scsi_i_w_exit
  255.         call    scsi_sense
  256.         jmp    scsi_i_w_exit
  257.  
  258. scsi_i_w_error:    stc
  259. scsi_i_w_exit:    ret
  260. scsi_ioctl_write endp
  261.