home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / ASMUTL / CHEAPASM.ZIP / RAMDISK.ASM < prev    next >
Encoding:
Assembly Source File  |  1987-01-11  |  9.0 KB  |  377 lines

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