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