home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / ASM / VDISK.ZIP / VDISK.ASM next >
Encoding:
Assembly Source File  |  1987-01-14  |  8.7 KB  |  383 lines

  1. ; This is the DOS 2.0 ELECTRONIC DISK from the example in the DOS 2.0
  2. ; manual. It is now set for 180K of space. Look for the ======> 2 locations
  3. ; to change the size.
  4. ;
  5. ; To include the drive into your system, edit a file called CONFIG.SYS. It
  6. ; does not exist on the system supplied by IBM. Create a new file, and type
  7. ; in   DEVICE=VDISK.COM
  8. ;  and save the file  (must be standard ASCII fornat!).
  9. ; make sure you copy VDISK.COM to your boot disk.
  10. ; When you boot, the number of disk drives will be determined from the
  11. ; switch setting and the ELECTRONIC DISK will be made the next drive letter.
  12. ;
  13. ; For example, if you have two floppies, the RAM DISK will be Drive C.
  14. ;
  15. ;
  16. ; Assemble this will MASM and link with LINK pgm.
  17. ; You must then use the EXE2BIN command,  type   EXE2BIN VDISK VDISK
  18. ; after that, you must rename the new file  RENAME VDISK.BIN VDISK.COM
  19. ;
  20. cseg    segment para public 'code'
  21. status  macro   state,err,rc
  22.         ifidn   <state>,<done>
  23.         or      es:word ptr srh_sta_fld[bx],0100h
  24.         endif
  25.         ifidn   <state>,<busy>
  26.         or      es:word ptr srh_sta_fld[bx],0200h
  27.         endif
  28.         ifidn   <err>,<error>
  29.         or      es:word ptr srh_sta_fld[bx],1000h
  30.         endif
  31.         ifnb    <rc>
  32.         or      es:word ptr srh_sta_fld[bx],rc
  33.         endif
  34.         endm
  35. ;
  36. ;
  37. ;
  38. srh     equ     0
  39. srh_len equ     13
  40. srh_len_fld     equ     srh
  41. srh_ucd_fld     equ     srh+1
  42. srh_ccd_fld     equ     srh+2
  43. srh_sta_fld     equ     srh+3
  44. srh_res_fld     equ     srh+5
  45. ;
  46. md      equ     srh+srh_len
  47. md_len  equ     1
  48. dta     equ     md+md_len
  49. dta_len equ     4
  50. count   equ     dta+dta_len
  51. count_len       equ     2
  52. ssn     equ     count+count_len
  53. ssn_len equ     2
  54. ;
  55. ret_byte        equ     md+md_len
  56. ;
  57. bpba_ptr        equ     dta+dta_len
  58. bpda_ptr_len    equ     4
  59. ;
  60. units   equ     srh+srh_len
  61. units_len       equ     1
  62. br_addr_0       equ     units+units_len
  63. br_addr_1       equ     br_addr_0+2
  64. br_addr_len     equ     4
  65. bpb_ptr_off     equ     br_addr_0+br_addr_len
  66. bpb_ptr_seg     equ     bpb_ptr_off+2
  67. ;
  68. vdsk    proc    far
  69.         assume  cs:cseg,es:cseg,ds:cseg
  70. begin:
  71. start   equ     $
  72. ;
  73. next_dev        dd      -1
  74. attribute       dw      2000h
  75. strategy        dw      dev_strategy
  76. interrupt       dw      dev_int
  77. dev_name        db      1
  78.         db      7 dup(?)
  79. ;
  80. rh_off  dw      ?
  81. rh_seg  dw      ?;
  82. bpb     equ     $
  83.         dw      512
  84.         db      1
  85.         dw      1
  86.         db      2
  87.         dw      64
  88.         dw      360
  89.         db      0fch
  90.         dw      2
  91. ;
  92. bpb_ptr dw      bpb
  93. ;
  94. ; current virtual disk information
  95. ;
  96. total   dw      ?
  97. verify  db      0
  98. start_sec       dw      0
  99. vdisk_ptr       dw      0
  100. user_dta        dd      ?
  101. boot_rec        equ     $
  102.         db      3 dup(0)
  103.         db      'IBM  2.0'
  104.         dw      512
  105.         db      1
  106.         dw      1
  107.         db      2
  108.         dw      64
  109.         dw      360
  110.         db      0fch
  111.         dw      2
  112. ;
  113. ;
  114. funtab  label   byte
  115.         dw      init
  116.         dw      media_check
  117.         dw      build_bpb
  118.         dw      ioctl_in
  119.         dw      input
  120.         dw      nd_input
  121.         dw      in_stat
  122.         dw      in_flush
  123.         dw      output
  124.         dw      out_verify
  125.         dw      out_stat
  126.         dw      out_flush
  127.         dw      ioctl_out
  128. ;
  129. ;
  130. in_save proc    near
  131.         mov     ax,es:word ptr dta[bx]
  132.         mov     cs:user_dta,ax
  133.         mov     ax,es:word ptr dta+2[bx]
  134.         mov     cs:user_dta+2,ax
  135.         mov     ax,es:word ptr count[bx]
  136.         xor     ah,ah
  137.         mov     cs:total,ax
  138.         ret
  139. in_save endp
  140. ;
  141. calc_addr       proc    near
  142.         mov     ax,cs:start_sec
  143.         mov     cx,20h
  144.         mul     cx
  145.         mov     dx,cs:vdisk_ptr
  146.         add     dx,ax
  147.         mov     ds,dx
  148.         xor     si,si
  149.         mov     ax,cs:total
  150.         mov     cx,512
  151.         mul     cx
  152.         or      ax,ax
  153.         jnz     move_it
  154.         mov     ax,0ffffh
  155. move_it:
  156.         xchg    cx,ax
  157.         ret
  158. calc_addr       endp
  159. ;
  160. sector_read proc near
  161.         call    calc_addr
  162.         mov     es,cs:user_dta+2
  163.         mov     di,cs:user_dta
  164. ;
  165.         mov     ax,di
  166.         add     ax,cx
  167.         jnc     read_copy
  168.         mov     ax,0ffffh
  169.         sub     ax,di
  170.         mov     cx,ax
  171. read_copy:
  172. rep     movsb
  173.         ret
  174. sector_read endp
  175. ;
  176. sector_write proc near
  177.         call    calc_addr
  178.         push    ds
  179.         pop     es
  180.         mov     di,si
  181.         mov     ds,cs:user_dta+2
  182.         mov     si,cs:user_dta
  183. ;
  184. ;
  185.         mov     ax,si
  186.         add     ax,cx
  187.         jnc     write_copy
  188.         mov     ax,0ffffh
  189.         sub     ax,si
  190.         mov     cx,ax
  191. write_copy:
  192. rep     movsb
  193.         ret
  194. sector_write endp
  195. ;
  196. dev_strategy:
  197.         mov     cs:rh_seg,es
  198.         mov     cs:rh_off,bx
  199.         ret
  200. ;
  201. ;
  202. ;
  203. dev_int:
  204.         cld
  205.         push    ds
  206.         push    es
  207.         push    ax
  208.         push    bx
  209.         push    cx
  210.         push    dx
  211.         push    di
  212.         push    si
  213. ;
  214. ;
  215.         mov     al,es:[bx]+2
  216.         rol     al,1
  217.         lea     di,funtab
  218.         xor     ah,ah
  219.         add     di,ax
  220.         jmp     word ptr[di]
  221. ;
  222. ;
  223. init:
  224.         push    cs
  225.         pop     dx
  226.         lea     ax,cs:vdisk
  227.         mov     cl,4
  228.         ror     ax,cl
  229.         add     dx,ax
  230.         mov     cs:vdisk_ptr,dx
  231.         mov     ax,2d00h
  232.         add     dx,ax
  233.         mov     es:word ptr br_addr_0[bx],0
  234.         mov     es:br_addr_1[bx],dx
  235.         mov     es:byte ptr units[bx],1
  236.         lea     dx,bpb_ptr
  237.         mov     es:bpb_ptr_off[bx],dx
  238.         mov     es:bpb_ptr_seg[bx],cs
  239.         mov     es,cs:vdisk_ptr
  240.         xor     di,di
  241.         lea     si,boot_rec
  242.         mov     cx,24
  243. rep     movsb
  244.         mov     cs:word ptr start_sec,1
  245.         mov     cs:word ptr total,2
  246.         call    calc_addr
  247.         push    ds
  248.         pop     es
  249.         mov     di,si
  250.         xor     al,al
  251. rep     stosb
  252.         mov     ds:byte ptr [si],0fch
  253.         mov     ds:byte ptr 1[si],0ffh
  254.         mov     ds:byte ptr 2[si],0ffh
  255.         push    ds
  256.         push    si
  257.         mov     cs:word ptr start_sec,3
  258.         mov     cs:word ptr total,2
  259.         call    calc_addr
  260.         push    ds
  261.         pop     es
  262.         mov     di,si
  263.         pop     si
  264.         pop     ds
  265. rep     movsb
  266.         mov     cs:word ptr start_sec,5
  267.         mov     cs:word ptr total,4
  268.         call    calc_addr
  269.         xor     al,al
  270.         push    ds
  271.         pop     es
  272.         xor     di,di
  273. rep     stosb
  274.         mov     es,cs:rh_seg
  275.         mov     bx,cs:rh_off
  276.         status  done,moerror,0
  277.         jmp     exit
  278. ;
  279. ;
  280. media_check:
  281.         mov     es:byte ptr ret_byte[bx],1
  282.         status  done,moerror,0
  283.         jmp     exit
  284. ;
  285. ;
  286. ;
  287. build_bpb:
  288.         push    es
  289.         push    bx
  290.         mov     cs:word ptr start_sec,0
  291.         mov     cs:word ptr total,1
  292.         call    calc_addr
  293.         push    cs
  294.         pop     es
  295.         lea     di,bpb
  296.         add     si,11
  297.         mov     cx,13
  298. rep     movsb
  299.         pop     bx
  300.         pop     es
  301.         lea     dx,bpb
  302.         mov     es:bpba_ptr[bx],dx
  303.         mov     es:bpba_ptr+2[bx],cs
  304.         mov     es:dta[bx],dx
  305.         mov     es:dta+2[bx],cs
  306.         status  done,moerror,0
  307.         jmp     exit
  308. ;
  309. ;
  310. ioctl_in:
  311. ioctl_out:
  312. nd_input:
  313. in_stat:
  314. in_flush:
  315. out_stat:
  316. out_flush:
  317. ;
  318. input:
  319.         call    in_save
  320.         mov     ax,es:word ptr ssn[bx]
  321.         mov     cs:start_sec,ax
  322.         mov     ax,es:word ptr count[bx]
  323.         mov     cs:total,ax
  324.         call    sector_read
  325.         mov     bx,cs:rh_off
  326.         mov     es,cs:rh_seg
  327.         status  done,moerror,0
  328.         jmp     exit
  329. ;
  330. ;
  331. output:
  332.         call    in_save
  333.         mov     ax,es:word ptr ssn[bx]
  334.         mov     cs:start_sec,ax
  335.         mov     ax,es:word ptr count[bx]
  336.         mov     cs:total,ax
  337.         call    sector_write
  338.         mov     bx,cs:rh_off
  339.         mov     es,cs:rh_seg
  340.         cmp     cs:byte ptr verify,0
  341.         jz      no_verify
  342.         mov     cs:byte ptr verify,0
  343.         jmp     input
  344. no_verify:
  345.         status  done,moerror,0
  346.         jmp     exit
  347. out_verify:
  348.         mov     cs:byte ptr verify,1
  349.         jmp     output
  350. ;
  351. ;
  352. exit:
  353.         pop     si
  354.         pop     di
  355.         pop     dx
  356.         pop     cx
  357.         pop     bx
  358.         pop     ax
  359.         pop     es
  360.         pop     ds
  361.         ret
  362. e_q_p:
  363.  if ($-start) mod 16
  364.  org ($-start)+16-(($-start) mod 16)
  365.  endif
  366. vdisk   equ     $
  367. vdsk    endp
  368. cseg    ends
  369.         end     begin
  370. t) mod 16
  371.  org ($-start)+16-(($-start) mod 16)
  372.  endif
  373. vdisk   equ     $
  374. vdsk    endp
  375. cseg    ends
  376.     yectbx],1
  377.         status  done,moerror,0
  378.         jmp     exit
  379. ;
  380. ;
  381. ;
  382. build_bpb:
  383.         p