home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpmug / cpmug047.ark / BMAP7_11.ASM < prev    next >
Encoding:
Assembly Source File  |  1984-04-29  |  9.5 KB  |  245 lines

  1. ;
  2. ;       BITMAP for CP/M 2.0+            as of 7/11/80
  3. ;
  4. ;
  5. ;       Lauren Guimont
  6. ;       14211 8th Avenue South
  7. ;       Seattle, Washington  98168
  8. ;
  9. ;
  10. ;
  11. ;The bitmap idea is based upon Ward Christensen's original
  12. ;  bitmap program, which refused to run on 2.0+ systems.
  13. ;  After giving his program a quick going over with SID, I
  14. ;  decided it would be easier to rewrite it than to try and
  15. ;  patch it for 2.0, 2.1, 2.2.
  16. ;
  17. ;
  18. ;               ***** EQUATES *****
  19. ;
  20. base    equ     0               ; 'normal' CP/M
  21. bdos    equ     base+5          ; jump to bdos
  22. ochar   equ     2               ; bdos console output
  23. sdsk    equ     14              ; select disk
  24. curdsk  equ     25              ; current disk
  25. gtaloc  equ     27              ; get allocation address
  26. dskpar  equ     31              ; get disk parameters
  27. fcb     equ     base+5ch        ; file control block
  28. ;
  29. ;
  30. ;
  31.         org     base+100h       ; start of TPA
  32. ;
  33.         lxi     h,0             ; clear HL
  34.         dad     sp              ; load HL with CCP sp
  35.         shld    oldsp           ; save it for later
  36.         lxi     sp,stack        ; initialize our own sp
  37.         jmp     start           ; bypass some subroutines
  38.         ds      48              ; stack space
  39. stack   equ     $               ; our own stack
  40. oldsp   ds      2               ; old stack from ccp
  41. ;
  42. inlprt:                         ; in line print
  43.         xthl                    ; HL to stack...pointer to HL
  44. inlprt1 mov     a,m             ; get a character
  45.         inx     h               ; increment the pointer
  46.         cpi     '$'             ; endmark?
  47.         jz      inlprt2         ; if so, prepare to exit
  48.         call    conout          ; output to console
  49.         jmp     inlprt1         ; go get another
  50. inlprt2 xthl                    ; orig HL...sp at end of msg
  51.         ret                     ; return to end of msg
  52. ;
  53. conout  push    h               ; single character console
  54.         push    d               ; ...output; 1st save all
  55.         push    b               ; ...the registers
  56.         push    psw
  57.         mvi     c,ochar         ; tell bdos
  58.         mov     e,a             ; bdos wants it in E
  59.         call    bdos            ; let bdos do it
  60.         pop     psw             ; reinstate all registers
  61.         pop     b
  62.         pop     d
  63.         pop     h
  64.         ret                     ; return to caller
  65. ;
  66. crlf    call    inlprt          ; use in line print
  67.         db      0dh,0ah,'$'     ; ...for cr & lf
  68.         ret                     ; return to caller
  69. ;
  70. one     push    psw             ; save Acc
  71.         mvi     a,'1'           ; print a '1' to console
  72.         call    conout          ; do it
  73.         pop     psw             ; restore Acc
  74.         ret                     ; return to caller
  75. ;
  76. zero    push    psw             ; save Acc
  77.         mvi     a,'0'           ; print a '0' to console
  78.         call    conout          ; do it
  79.         push    h               ; save <hl>
  80.         lhld    free            ; get nb of free blocks
  81.         inx     h               ; add one free
  82.         shld    free            ; store total free count
  83.         pop     h
  84.         pop     psw             ; restore Acc
  85.         ret                     ; return to caller
  86. ;
  87. ;Binary to decimal output routine. Enter with 8 bit binary
  88. ;number in <A>. Second entry at BNDEC2 assumes 16 bit nb. in <HL>
  89. ;
  90. bndec1  mvi     h,0
  91.         mov     l,a             ;<HL> now has number
  92. ;
  93. bndec2  push    b
  94.         push    d
  95.         push    h
  96.         lxi     b,-10
  97.         lxi     d,-1
  98. bndc    dad     b
  99.         inx     d
  100.         jc      bndc
  101.         lxi     b,10
  102.         dad     b
  103.         xchg
  104.         mov     a,h
  105.         ora     l
  106.         cnz     bndec2
  107.         mov     a,e
  108.         adi     '0'
  109.         call    conout
  110.         pop     h
  111.         pop     d
  112.         pop     b
  113.         ret
  114. ;
  115. err1    call    inlprt          ; in line print
  116.         db      0dh,0ah,'Nonstandard disk '
  117.         db      'parameter block error'
  118.         db      0dh,0ah,'$'
  119. ;
  120. finis   lhld    oldsp           ; get CCP sp
  121.         sphl                    ; retore it
  122.         ret                     ; direct return to CCP
  123. ;
  124. ;We need a little internal storage
  125. ;
  126. drive   ds      1               ; current drive
  127. aldrv   ds      1               ; alternate specified drv
  128. dpb     ds      2               ; disk parameter block add
  129. tbtr    ds      2               ; total bits to read
  130. alloc   ds      2               ; allocation address
  131. blksiz  ds      1               ; block size code
  132. free    dw      0               ; count of free blocks
  133. ;
  134. ;The actual start of it all
  135. ;
  136. start   lda     fcb             ; get any alternate drv
  137.         sta     aldrv           ; save it for later
  138.         call    inlprt          ; in line print
  139.         db      'BITMAP 2.2    AS OF '
  140.         db      '7/11/80',0dh,0ah,0dh,0ah,'$'
  141.         mvi     c,curdsk        ; get current disk in
  142.         call    bdos            ; ...use from bdos
  143.         sta     drive           ; save it
  144.         lda     aldrv           ; get any alternate drv
  145.         ora     a               ; any specified?
  146.         jz      dpblk           ; if not, skip next
  147.         dcr     a               ; less one
  148.         sta     drive           ; save as drive to use
  149. ;
  150. dpblk   lda     drive           ; get drive to bitmap
  151.         mvi     c,sdsk          ; set call for disk select
  152.         mov     e,a             ; bdos wants it in E
  153.         call    bdos            ; let bdos do it
  154.         mvi     c,dskpar        ; we want dsk parameter blk
  155.         call    bdos            ; get it, and.....
  156.         shld    dpb             ; ...save it
  157.         lxi     d,5             ; offset for total blks used
  158.         dad     d               ; add it to HL
  159.         mov     e,m             ; lsb into E
  160.         inx     h               ; point to msb
  161.         mov     d,m             ; get it
  162.         xchg                    ; put it in HL...
  163.         inx     h               ; alloc size = (dsm/8)+1
  164.         shld    tbtr            ; ...and save it
  165.         lhld    dpb             ; get dsk parameter blk add
  166.         inx     h               ; ...and increment HL to
  167.         inx     h               ; ...the 3rd byte
  168.         mov     a,m             ; it has the block size
  169.         sui     2               ; it will be 3-7 (make it 1-5)
  170.         cpi     5+1             ; check for over 5
  171.         jnc     err1            ; nonstandard size
  172.         cpi     1               ; check for less than 1
  173.         jc      err1            ; nonstandard size
  174.         push    psw             ; save it
  175.         call    inlprt          ; in line print
  176.         db      'Allocated disk block size is $'
  177.         pop     psw             ; get block size back
  178.         sta     blksiz          ; save it for end
  179.         lxi     h,512           ; set 1/2k counter
  180. lp      dad     h               ; multiply * 2=1024
  181.         dcr     a               ; less block size code count
  182.         jnz     lp              ; loop till <A>= 0
  183.         call    bndec2          ; print size in K
  184. ;
  185. dpbend  call    inlprt          ; finish message
  186.         db      ' bytes per block',0dh,0ah,'$'
  187.         lhld    tbtr            ; total bits to read
  188.         push    h               ; save it in the stack
  189.         lda     drive           ; again to be safe
  190.         mov     e,a             ; into E for bdos
  191.         mvi     c,sdsk          ; reselect disk
  192.         call    bdos            ; let bdos do it
  193.         mvi     c,gtaloc        ; get the allocation address
  194.         call    bdos            ; ...from bdos
  195.         pop     d               ; tbtr from stack
  196.         dcx     h               ; back allocation up one
  197. ;
  198. ;
  199. ;We now have the total number of bits to read in DE, and
  200. ;  the address to start reading them at in HL for the
  201. ;  proper drive. So now let's print the bitmap.
  202. ;
  203. ;
  204. bmap    mvi     c,48            ; 1's and 0's per line
  205.         call    crlf            ; followed by a cr,lf
  206. bmap1   inx     h               ; kick the pointer
  207.         mov     a,m             ; get the byte
  208.         mvi     b,8             ; it has 8 bits
  209. bmap2   rlc                     ; runn'em through carry
  210.         cc      one             ; carry set = print '1'
  211.         cnc     zero            ; carry not set = print '0'
  212.         dcx     d               ; decrement bit count
  213.         push    psw             ; save the bit pattern
  214.         mov     a,d             ; check to see if...
  215.         ora     e               ; ...DE = 0
  216.         jz      bmapend         ; if so, we're finished
  217.         pop     psw             ; restore bit pattern
  218.         dcr     c               ; decrement line count
  219.         jz      bmap            ; new line if zero
  220.         dcr     b               ; decrment bit count
  221.         jz      bmap1           ; new byte if zero
  222.         jmp     bmap2           ; finish this byte
  223. ;
  224. bmapend pop     psw             ; not neccessary, but keeps the
  225.         call    crlf            ; ...stack straight..send cr,lf
  226.         call    crlf
  227.         lda     drive           ;get drive used
  228.         adi     'A'
  229.         call    conout
  230.         call    inlprt
  231.         db      ': R/W, Space: $'
  232.         lda     blksiz          ; get block size code
  233.         lhld    free            ; get nb of free blocks
  234. lp1     dcr     a
  235.         jz      don             ; multiplied by size of block
  236.         dad     h               ; times 2
  237.         jmp     lp1
  238. ;
  239. don     call    bndec2          ; print size of free space
  240.         call    inlprt
  241.         db      'k',0dh,0ah,'$'
  242.         jmp     finis           ; restore things and GET OUT
  243. ;
  244.         end
  245.