home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / basic / library / qb_pds / dos / bdisk / asmsrc / newvec.asm < prev    next >
Encoding:
Assembly Source File  |  1987-12-04  |  3.6 KB  |  142 lines

  1.         DOSSEG
  2.         .MODEL medium
  3.  
  4.         PUBLIC _SetBase, _ResBase, _SctrSz
  5.  
  6. ;========================================================
  7. ; Copy the diskette parameters and set the sector and
  8. ; track size.  The usage is:
  9. ;
  10. ;   push <sectors>      ;number of sectors per track
  11. ;   push <bytes>        ;number of bytes per sector
  12. ;   call _SetBase       ;set new parameters
  13. ;
  14. ; To restore the diskette parameters:
  15. ;
  16. ;   call _ResBase       ;restore parameters
  17. ;
  18. ; DOS might not be able to read diskettes while the new
  19. ; parameters are in effect, thus the parameters should
  20. ; be reset before any DOS disk routines are called. The
  21. ; stack is cleared on exit and all registers are
  22. ; preserved.
  23.  
  24. BASE_SIZE       EQU 11          ;size of disk parameters
  25.  
  26.         .DATA?
  27.  
  28. Old_DBase       dd ?                    ;old disk base
  29. Disk_Parms      db BASE_SIZE DUP (?)    ;new disk base data
  30.  
  31.         .CODE
  32.  
  33. SetBasStk       STRUC
  34. registers       dw 9 DUP (?)
  35. retaddr         dw 2 DUP (?)
  36. bytes           dw ?
  37. sectors         dw ?
  38. SetBasStk       ENDS
  39.  
  40. ;routine to set diskette parameters
  41.  
  42.         ASSUME ds:NOTHING, es:@DATA, ss:NOTHING
  43.  
  44. _SetBase PROC
  45.         push ax
  46.         push bx
  47.         push cx
  48.         push dx
  49.         push di
  50.         push si
  51.         push bp
  52.         push ds
  53.         push es
  54.         mov bp, sp
  55.  
  56.         mov ax, 351eH   ;get interrupt and disk pointer
  57.         int 21h         ;execute
  58.  
  59.         mov ax, es
  60.         mov ds, ax      ;segement of disk parameters
  61.         mov si, bx      ;offset
  62.         mov ax, @DATA
  63.         mov es, ax      ;data segment
  64.  
  65.         mov word ptr Old_DBase[0], si   ;save original offset
  66.         mov word ptr Old_DBase[2], ds   ;              segment
  67.  
  68.         lea di, Disk_Parms      ;parameter location
  69.         mov cx, BASE_SIZE       ;size of parameter data
  70.         rep movsb               ;copy data
  71.  
  72.         ASSUME ds:@DATA
  73.         mov ax, es
  74.         mov ds, ax              ;set main data segment
  75.         lea bx, Disk_Parms      ;location of local parameters
  76.  
  77.         mov ax, [bp].bytes      ;get the bytes per sector
  78.         call far ptr _SctrSz    ;get the sector size
  79.         mov [bx][3], al         ;save it
  80.  
  81.         mov al, byte ptr [bp].sectors   ;get the sectors per track
  82.         mov [bx][4], al                 ;save it
  83.  
  84.         mov ax, 251eH           ;set interrupt and disk pointer
  85.         mov dx, bx              ;load offset, segment (DS) already loaded
  86.         int 21h                 ;execute
  87.  
  88.         pop es
  89.         pop ds
  90.         pop bp
  91.         pop si
  92.         pop di
  93.         pop dx
  94.         pop cx
  95.         pop bx
  96.         pop ax
  97.         ret 4
  98. _SetBase ENDP
  99.  
  100. ;routine to restore diskette parameters
  101.  
  102.         ASSUME ds:@DATA
  103.  
  104. _ResBase PROC
  105.         push ax
  106.         push dx
  107.         push ds
  108.         mov ax, @DATA
  109.         mov ds, ax              ;set data segment
  110.         lds dx, Old_DBase       ;load old parameter base
  111.         mov ax, 251eH           ;set interrupt and disk pointer
  112.         int 21h                 ;execute
  113.         pop ds
  114.         pop dx
  115.         pop ax
  116.         ret
  117. _ResBase ENDP
  118.  
  119. ; routine to solve X for (AX = 128*2^X), AL returns result
  120.  
  121. _SctrSz PROC
  122.         push dx
  123.         mov dl, 128             ;divisor
  124.         div dl                  ;divide
  125.  
  126.         sub ah, ah      ;default minimum
  127.         or al, al       ;check if zero
  128.         jz Scsz2
  129.  
  130.         mov ah, 8       ;starting number
  131. Scsz1:  dec ah          ;decrement power
  132.         shl al, 1       ;check if high bit set
  133.         jnc Scsz1       ;jump if not
  134.  
  135. Scsz2:  mov al, ah
  136.         sub ah, ah
  137.         pop dx
  138.         ret
  139. _SctrSz ENDP
  140.  
  141.         END
  142.