home *** CD-ROM | disk | FTP | other *** search
/ PC-SIG Library 8 / PC-SIG Library CD-ROM (8th Edition) (1990-04).iso / 001_100 / disk0051 / ramdisk.asm < prev    next >
Encoding:
Assembly Source File  |  1983-02-02  |  10.1 KB  |  456 lines

  1. ;Version 2.1   1982    Mark S Zachmann
  2. ;
  3. ;    This program lets you totally remap the
  4. ; disks on MS-DOS. You can map each side of a logical 
  5. ; drive to any other side or to memory.
  6. ;
  7. ;    For example, a usual configuration would be
  8. ; map drive 0, sides 0,1 to drive 0 sides 0,1 (no change)
  9. ;     drive 1, sides 0,1 to drive 1 sides 0,1    "
  10. ;     drive 2, side 0 to   segment  4000h
  11. ;     drive 2, side 1 to   segment  6800h
  12. ;
  13. ;  this will let you use 256K for the MS-DOS system, and another
  14. ; 320K of memory for a double-sided RAM disk, if you have a 512K 
  15. ; board installed. ( for 576K total )
  16.  
  17. ;**********************************************
  18. ; to alter this for your system:
  19. ;   change the equates at locations 'DISKPTR'
  20. ;    they come in order (0/0, 1/0, 0/1, 1/1, 0/2, 1/2, 0/3, ...
  21. ;    and each entry says which to map to:
  22. ;
  23. ;    0h = side 0/disk 0
  24. ;     100h = side 1/disk 0
  25. ;       1h = side 0/disk 1
  26. ;     101h = side 1/disk 1
  27. ;       ...etc
  28. ;     anything bigger than f00h is treated as a location in RAM,
  29. ;    thus
  30. ;     4000h = segment beginning at 4000:0000h
  31. ;     6800h = segment beginning at 6800:0000h
  32. ;    etc
  33. ;*********************************************
  34. ; also, 0FFFFh = return an error if this side is selected.
  35.  
  36. ; for my default setup: (disk A,B normal, C RAMdisk, ...)
  37. ;    Note that the dip switches inside must then be set to
  38. ; indicate 3 disk drives and 256K of memory. All disk operations
  39. ; are transparent to the user.
  40. ;    this is for two reasons:
  41. ;(1) MS-DOS must feel that any RAMdisk memory does not exist
  42. ;(2) MS-DOS needs to know how many drives (real or otherwise)
  43. ;    there are
  44. ; Note that the RAM disks must be FORMATted before use, unless
  45. ; you use DISKCOPY to send data to them.
  46. ;
  47. ;
  48. ;  SYNTAX:
  49.  
  50. ;    A>ramdisk        creates a ramdisk and writes F6 to each byte
  51. ;                to eliminate possible parity errors on read
  52. ;
  53. ;    A>ramdisk old        creates a ramdisk, but does not overwrite
  54. ;                old data. used if you had to reset
  55. ;                (ctrl-alt-del) for some reason
  56.  
  57.  
  58. TITLE Double-Sided Diskette Support
  59. SUBTTL
  60.  
  61.  
  62. BASE    equ    0h    ;Base of memory
  63. DiskInt    equ    4Ch    ;Offset of int
  64. DISKETTE_STATUS equ    0441h
  65. DISK_POINTER    equ    078h
  66. bufr    equ    80h    ; command line parm address
  67.  
  68.  
  69. ;first the macro library must be in here
  70.  
  71.     IF1
  72. Include Interupt.MAC
  73.     ENDIF
  74.  
  75. ;first macro ----
  76.  
  77.     Prolog    DOUBLE
  78.  
  79.   ASSUME DS:DOUBLE,CS:DOUBLE
  80. ;----------------------------------------
  81. ;----------------------------------------
  82. ;----------------------------------------
  83.  
  84. SUBTTL    Diskette I/O Call Entry Point
  85.  
  86. COMMENT *   Actual Entry point 
  87.    On entry:
  88.     DL = logical disk number (0-n)
  89.     DH = 0 (side-1)
  90.    On call to disk I/O:
  91.     DL = physical disk number
  92.     DH = side number (0 or 1)
  93.          DH=0 or 1 (1 if DL was odd)
  94.  
  95.    For other registers...
  96.     See Reference Manual p.A-32
  97.  
  98. IF reference is to memory_disk
  99.   {  Case:
  100.     RESET - pass to usual disk reset
  101.     STATUS - "    "    "
  102.     READ   - transfer buffer to memory
  103.     WRITE  - transfer memory to buffer
  104.     VERIFY  - do nothing (just like BIOS)
  105.     FORMAT  - fill sectors(s) with [DISK_BASE+8]
  106.  
  107.    Always return successful completion code.
  108.     unless signaled otherwise by 0xFFFF assegment
  109.   }
  110.  
  111.  Upon return, all registers except AX unchanged.
  112.     Memory references also set
  113.     DISKETTE_STATUS to 0.
  114.  
  115.     *
  116.  
  117. ;---------------------------------------------
  118. ;
  119. ;    Actual diskette I/O filter routine
  120. ;
  121. ;---------------------------------------------
  122. Main    proc    far
  123.  
  124. ENTRY:    STI    ;Allow interrupts
  125.     push    DX    ;So we can reset it later
  126.     cmp    AH,1    ;Is it disk independent?
  127.     jle    USUAL    ;Yes, do what is usual.
  128.  
  129. ; Now figure out which disk is involved.
  130. ;    by table lookup. No validity check here.
  131. ; The table will return a DX (DH - side, DL - drive)
  132. ;    value for use or > 3FFh which implies a memory
  133. ;    reference, in which case the two bytes
  134. ;    are a starting segment number.
  135. ; ** Special Case:
  136. ;    if address is FFFF hex (impossible, ROM is there)
  137. ;    we return an error code, so you can use 160K ramdisk
  138. ;    effectively as single sided disk
  139. ;    .Most DOS routines try to read side 2, hence this kludge
  140. ;    for a 160K ramdisk
  141.  
  142.     XCHG    BX,DX    ;Need BX for indexing
  143.     SHL    BL,1    ;*2 for word offset
  144.     add    BL,BH    ;side parameter
  145.     shl    BL,1
  146.     xor    BH,BH
  147.     MOV    BX,CS:[BX+offset DISKPTR]    ;address/map
  148.     xchg    BX,DX    ;back again
  149.     cmp    DX,0FFFFh    ;kludge ?
  150.     je    Doerror        ;generate error, for opposite side
  151.                 ;of 160K ramdisk
  152.     cmp    DX,03FFh    ;is memory ?
  153.     ja    short MEMdisk    ;yes
  154.  
  155. ;----------------------------------------------
  156. ;
  157. ;Now call the operating system
  158. ;    because call requires disk activity
  159. ;
  160. ;-----------------------------------------------
  161.  
  162. USUAL:    pushf        ; because OS does IRET
  163.             ;which wastes a stack item.
  164.     call    cs:disket    ;call BIOS
  165.  
  166. ;Return to calling routine
  167.  
  168. ToDOS:    pop    dx    ;old DX value, must be intact
  169.     ret    2    ;keep flags intact
  170. Main    endp
  171.  
  172. ;----------------------------------------------
  173. ;
  174. ;    Use memory for disk
  175. ; On entry:    DX -  starting SEGMENT
  176. ;        other registers as in BIOS call
  177. ;        old DX on top of stack
  178. ;
  179. ; On exit:
  180. ;        All registers returned 
  181. ;    to normal. AX set to status, and
  182. ;    DISKETTE_STATUS set to 0.
  183. ;    Also CY = 0, unless segment was FFFFh
  184. ;
  185. ;
  186. ;-----------------------------------------------
  187.  
  188. Doerror    proc    near        
  189.     clc
  190.     cmp    AH,5        ;format operation?
  191.     mov    AH,0
  192.     je    ToDos        ;if format, then say OK
  193.                 ;error routine for single
  194.     mov    AX,400h        ;sided operation of ramdisk
  195.     stc
  196.     jmp    short ToDOS    ;no need to do the push/pop stuff
  197. Doerror    endp
  198.  
  199.  
  200. MEMdisk    proc    near        ;usual memory disk, can't return error
  201. ; First calculate the starting address
  202. ;    DX+CH*100h+CL*20h
  203.     push    DI
  204.     push    SI
  205.     push    DS
  206.     push    ES
  207.     push    CX
  208.     push    BX
  209.     push    AX
  210.     CLD        ;always increment string moves
  211.  
  212. ; if parms change then leave reg's alone
  213.     xor    AX,AX
  214.     mov    AL,CL    ;sector
  215.     dec    AX    ;relative to 0
  216.     mov    CL,5
  217.     SHL    AX,CL    ;*20h
  218.     add    AH,CH    ;+track*100h
  219.     add    AX,DX    ;+segment
  220.     mov    DS,AX    ;now DS contains buffer addr
  221.  
  222.     pop    AX    ;get AX back, AL has count
  223.     push    AX
  224.     xor    CX,CX    ;how many sectors
  225.     mov    CH,AL    ;*256 for words to move
  226.  
  227. ; set up the parameters for DS:SI -> ES:DI
  228. ;    i.e. a read operation
  229.     xor    SI,SI    ; ->0
  230.     mov    DI,BX    ; was ES:BX
  231.  
  232. ; now do the operation
  233.  
  234.     cmp    AH,3
  235.     jb    short READ
  236.     je    short WRITE
  237.     cmp    AH,5
  238.     jb    short VERIF
  239.     je    short FORMAT
  240.     STC        ;unknown, set error flag
  241.  
  242. ;----------------------------------
  243. ;
  244. ; Return to DOS by setting status
  245. ;    to 0 (all OK) and then pop'ing
  246. ;    registers (leave flags alone)
  247. ;
  248. ;-------------------------------------
  249.  
  250. Memret    label    near
  251.     mov    AX,Base
  252.     mov    DS,AX
  253.     mov    BX,DISKETTE_STATUS
  254.     mov    BYTE PTR [BX],0
  255.     pop    AX
  256.     pop    BX
  257.     pop    CX
  258.     pop    ES
  259.     pop    DS
  260.     pop    SI
  261.     pop    DI
  262.     mov    AH,0    ;Status NEC no problems!
  263.     CLC        ;impossible to get error
  264.     jmp    short ToDOS
  265. MEMdisk    endp
  266.  
  267.  
  268. ;--------------------------------------
  269. ;
  270. ;   Memory I/O routines.
  271. ; On Entry:
  272. ;    ES:DI = DMA address for transfer
  273. ;    DS:SI - buffer address
  274. ;     CX   = number of words to transfer
  275. ;
  276. ;  On Exit:
  277. ;    CY = 0
  278. ;
  279. ;------------------------------------------
  280.  
  281. ;----------------------------------
  282. ;
  283. ; Memory read
  284. ;
  285. ;----------------------------------
  286.  
  287. READ    proc    near
  288.     rep movsw
  289.     jmp    short MEMret
  290. READ    endp
  291.  
  292. ;-----------------------------------------
  293. ;
  294. ; Memory write
  295. ;
  296. ;  On entry as in read
  297. ;
  298. ;------------------------------------------
  299.  
  300. WRITE    proc    near
  301.     call    REVERS    ;backwards move
  302.     rep movsw
  303.     jmp    short MEMret
  304. WRITE    endp
  305.  
  306. ;-----------------------------------------
  307. ;
  308. ; Memory Verify
  309. ;    note that verify does nothing
  310. ;    if you look at reference manual
  311. ;    p.A-34 it is clear that
  312. ;    verify only tries to read a track!
  313. ;    which must work here
  314. ;
  315. ;-----------------------------------------
  316.  
  317. VERIF    proc    near
  318.     jmp    short MEMret
  319. VERIF    endp
  320.  
  321. ;---------------------------------------
  322. ;
  323. ; Memory Format
  324. ;
  325. ;-----------------------------------------
  326.  
  327. FORMAT    proc    near
  328.     call    REVERS    ;source backwards
  329.     mov    AX,BASE
  330.     mov    DS,AX
  331.     mov    BX,DISK_POINTER
  332.     lds    BX,dword ptr [BX]
  333.     mov    AL,BYTE PTR [BX+8]    ; Format char
  334.     mov    AH,AL    ;Dup
  335.     rep    stosw
  336.     jmp    short MEMret
  337. FORMAT    endp
  338.  
  339.  
  340. ;-----------------------------------
  341. ;
  342. ;    REVERS
  343. ; Change Direction, i.e.
  344. ;    XCHG    DS:SI,ES:DI
  345. ;
  346. ;------------------------------------
  347.  
  348. REVERS    proc    near
  349.     mov    AX,DS
  350.     mov    BX,ES
  351.     mov    ES,AX
  352.     mov    DS,BX
  353.     xchg    DI,SI
  354.     ret
  355. REVERS    endp
  356.  
  357. ;--------------------------------------
  358. ;
  359. ; Permanent storage area
  360. ;
  361. ;--------------------------------------
  362.  
  363.  
  364. disket    LABEL    DWORD
  365.     DW    ?
  366.     DW    ?
  367. ;you can patch this (before or after assembly)
  368. ;or use the 7E and 7F system calls to set this
  369. ;on the fly
  370. DISKPTR    label    WORD
  371.     dw    0,100h,1,101h    ;my usual setup
  372.     dw    4000h,6800h    ;C disk is all memory
  373.     dw    0FFFFh, 0FFFFh        ;D disk is error
  374.     dw    12 dup(0)    ;extra
  375.  
  376. ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  377. ;!!
  378. ;!! everything after this is temporary
  379. ;!!
  380. ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  381.  
  382.  
  383. ;---------------------------------------------
  384. ;   This 'subroutine' sets up the operating
  385. ;    system so that the ENTRY routine
  386. ;    can map logical disks into physical
  387. ;    disks and memory.
  388. ;
  389. ;   Store the old interrupt vector 13h
  390. ;    at an indirect call location 'disket'.
  391. ;    Then replace the vector
  392. ;    with the user entry point (ENTRY).
  393. ;   This has the effect of leaving the
  394. ;    full user routine in memory until
  395. ;    there is a warm start.
  396. ;
  397. ;   On entry:
  398. ;    DS = origin of program segment
  399. ;  Effect on registers is irrelevant.
  400. ;
  401. ;------------------------------------------
  402.  
  403.  
  404. ; macro ---
  405.  
  406.     Epilog    013h,Disket,DOUBLE
  407.  
  408. ;---------------------------------
  409. ;
  410. ; Fill Memory Disk areas with zero's
  411. ;    for parity
  412. ;
  413. ;-----------------------------------
  414.  
  415. ;             if Old then do not fill
  416.     mov    AX,CS:zzarg    ; first word at 80h
  417.     cmp    AL,'O'
  418.     je    Nofl
  419.     cmp    AL,'o'        ;u/l case
  420.     je    Nofl
  421. ;
  422. ; must not have been an O
  423. ;
  424.     int    12h    ;memory size(K) -> AX
  425.     mov    CL,6    ;*64
  426.     shl    AX,CL    ;gives segment #
  427.     CLD        ;upwards
  428.     mov    BX,AX    ;for loop convenience
  429.     mov    DX,0800H    ;32K increment
  430. FILLUP:    mov    ES,BX
  431.     mov    AX,0F6F6h
  432.     xor    DI,DI    ;from 0 base
  433.     mov    CX,4000h ;words/32k
  434.     rep stosw
  435.     mov    BX,ES
  436.     add    BX,DX
  437.     cmp    BH,0B0h    ;video yet ?
  438.     jb    FILLUP
  439.  
  440. ;------------------------------------
  441. ;
  442. ; Configure the disks
  443. ;
  444. ;---------------------------------------
  445.  
  446. Nofl:    jmp    CONFIG
  447. HIMSG:    db    'Disk reconfiguration program',13,10
  448.     db    ' 1982, MSZachmann',13,10,'$'
  449.  
  450. ; macro ---
  451.  
  452.     Finish    DOUBLE,250
  453.  
  454.     end
  455. 
  456.     STC        ;unknown