home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol116 / bishow11.asm < prev    next >
Encoding:
Assembly Source File  |  1985-02-10  |  9.4 KB  |  300 lines

  1. title    'BISHOW.ASM'
  2. ;A buffered, bidirectional version of SHOW.ASM.
  3. ;Ver 1.0, 23 Aug 82
  4. ;Phil Cary, 748 Kenilworth Parkway, Baton Rouge, LA  70808
  5. ;Ver 1.1, 30 Mar 83 added BDOS function 6 W.F.McGee
  6. ;
  7. ;BISHOW is a buffered, bidirectional version of SHOW.ASM which first
  8. ;appeared in Interface Age, November, 1981.  That program could
  9. ;only scroll forward in a file, and read sectors from disk one at a
  10. ;time as they were sent to the console.  I used SHOW frequently to take
  11. ;a quick look at a file without loading a big text editor, and to examine
  12. ;another file with the RUN command while in Wordstar.  TYPE does not work
  13. ;since it is not a file that Wordstar can load and run.
  14. ;
  15. ;It was annoying when I went past the point I was looking for in a file 
  16. ;with SHOW, and could not go backwards.  Thus, this bidirectional version 
  17. ;which uses random access reads. In addition, buffering was added so that
  18. ;the number of disk reads would be reduced, and moving back and forth
  19. ;in a moderate sized file would be speeded up.  There is a trade off
  20. ;between the size of the buffer and the length of time it takes to refill
  21. ;the buffer which should be set to the user's preference.
  22. ;
  23. ;There are three customizing items in this program.  One is the equate
  24. ;"maxsec" which sets the buffer size.  The other is the string in the
  25. ;subroutinσ "clrscr" just after the org statement.  Thi≤ shoulΣ bσ changeΣ 
  26. ;t∩ thσ erase screen and home cursor sequence for the user's terminal. The 
  27. ;program is presently set up for a H/Z-19.  The program, as written, does
  28. ;require a 24 X 80 screen with an erase screen and home cursor function.
  29. ;Finally, direct I/O to the console is used to avoid echoing the commands
  30. ;to the console as the CP/M write console function does.  Three equates
  31. ;under "Console equates" must be changed to match the user's system.
  32. ;
  33. ;Just a small contribution to the public domain software as partial
  34. ;payment for the many fine and educational programs the system has
  35. ;given me.  Phil Cary.
  36.  
  37. ; Begin code
  38.  
  39. false    equ    0
  40. true    equ    not false
  41. APPLE    EQU    TRUE
  42.  
  43. ; BDOS equates
  44.  
  45. boot    equ    0    ;warm boot
  46. wrcon    equ    2    ;console write
  47. bdos    equ    5    ;bdos entry
  48. open    equ    15    ;open file
  49. readr    equ    33    ;read file random access
  50. stdma    equ    26    ;set dma address
  51.  
  52. ; FCB equates
  53.  
  54. fcb    equ    05ch    ;default fcb drive number
  55. fcbfn    equ    fcb+1    ;start of filename
  56. fcbft    equ    fcb+9    ;start of filetype
  57. fcbex    equ    fcb+12    ;current extent number
  58. fcbcrr    equ    fcb+33    ;current record number, random access
  59.  
  60. ; ASCII equates
  61.  
  62. cr    equ    0dh    ;carriage return
  63. lf    equ    0ah    ;line feed
  64. eof    equ    01ah    ;end of file
  65. esc    equ    01bh    ;escape
  66. bell    equ    07h    ;bell
  67.  
  68.  
  69. ; Operational equates
  70.  
  71. maxsec    equ    64    ;number of sectors in buffer
  72.  
  73.     org    100h
  74.  
  75. fulbuf:    set    dskbuf+(maxsec*128)    ;need to know end of buffer
  76.     jmp    start            ;skip over next subroutine
  77.  
  78. clrscr:    call    ilprt        ;code to erase screen and home cursor
  79.  
  80.     IF NOT APPLE
  81.     db    esc,'E',0    ;..for H/Z-19 terminal. change as required
  82.     ENDIF
  83.     IF APPLE
  84.     db    esc,'*',0    ;..for terminal screen function table
  85.     ENDIF
  86.     ret
  87.  
  88. start:    lxi    sp,stack    ;set up local stack
  89.     call    clrscr        ;clear the screen
  90.     call    opnfil        ;open file in default fcb
  91.     xra    a        ;get a 0
  92.     sta    lincnt        ;store in line count
  93.     sta    fcbex        ;zero current extent
  94.     sta    fcbcrr        ;zero current record
  95.     sta    fcbcrr+1    ;..both bytes
  96.     sta    fcbcrr+2    ;..and the overflow
  97.     call    filbuf        ;fill the disk buffer
  98.  
  99. wrtfwd:    lxi    h,dskbuf    ;point to beginning of buffer
  100. wrtfwd1    mov    a,m        ;get a character
  101.     cpi    eof        ;if it is EOF
  102.     jz    getcmd        ;..loop for another command
  103.     push    psw        ;save character from BDOS clobber
  104.     call    ctype        ;put it on console
  105.     pop    psw        ;get character
  106.     cpi    cr        ;see if end of line
  107.     jz    fwdcnt        ;yes, count line
  108. wrtfwd2    inx    h        ;no, bump buffer
  109.     lxi    d,fulbuf    ;get end of buffer address
  110.     mov    a,d        ;compare high
  111.     cmp    h        ;..order bytes
  112.     jnz    wrtfwd1        ;if not equal, continue
  113.     mov    a,e        ;else compare low
  114.     cmp    l        ;..order bytes
  115.     cz    filbuf        ;if end of buffer, go refill
  116.     jz    wrtfwd        ;..and start at beginning of buffer
  117.     jmp    wrtfwd1        ;else, continue with next character
  118.  
  119. fwdcnt:    lda    lincnt        ;get number of lines displayed
  120.     inr    a        ;bump it
  121.     sta    lincnt        ;..and store it
  122.     xchg            ;save the buffer pointer
  123.     lxi    h,linmax    ;point to max number of line for this pass
  124.     cmp    m        ;compare with line count
  125.     xchg            ;restore pointer
  126.     jnz    wrtfwd2        ;if not there, continue, else get command
  127.     xra    a        ;zero the
  128.     sta    lincnt        ;..line count
  129.  
  130. getcmd:
  131.     push    h
  132.     push    d
  133.     push    b
  134. getcmd1:
  135.     mvi     c,06
  136.     mvi    e,0FFH
  137.     call    bdos
  138.     cmp    00h
  139.     jz    getcmd1
  140.     ani    5fH        ;make it upper case
  141.     cpi    'F'        ;scroll forward?
  142.     push    psw        ;save flags
  143.     mvi    a,22        ;set up for only 22 lines on forward
  144.     sta    linmax        ;..scrolls
  145.     pop    psw        ;get flags
  146.     pop    b
  147.     pop    d
  148.     pop    h
  149.     jz    wrtfwd1        ;scroll forward
  150.     push    psw        ;else save character and flags again
  151.     mvi    a,24        ;set up for full screen on scroll
  152.     sta    linmax        ;..backward
  153.     pop    psw        ;get character and flags
  154.     cpi    'B'        ;scroll backward?
  155.     jz    wrtbak        ;yes
  156.     cpi    'X'        ;must be exit
  157.     jz    exit        ;yes, or
  158.     call    ilprt        ;..a wrong choice so give message
  159.     db    cr,lf,'Enter F to scroll forward, B to scroll backward, '
  160.     db    'or X to exit.',cr,lf,bell,0
  161.     jmp    getcmd        ;try again for command
  162.  
  163. wrtbak    mvi    a,44
  164.     sta    lincnt
  165.     call    clrscr        ;clear the screen
  166. wrtbak1    lxi    d,dskbuf    ;get address of buffer start
  167.     mov    a,d        ;compare high
  168.     cmp    h        ;..order bytes
  169.     jnz    wrtbak2        ;continue if not equal
  170.     mov    a,e        ;else, compare low
  171.     cmp    l        ;..order bytes
  172.     jnz    wrtbak2        ;continue if not equal
  173.     jmp    filbak        ;..and go write it
  174. wrtbak2    mov    a,m        ;get a character
  175.     cpi    cr        ;see if end of line
  176.     dcx    h        ;decrement buffer
  177.     jnz    wrtbak1        ;..and loop if not
  178.  
  179. bakcnt:    lda    lincnt        ;else, get number of lines to move back
  180.     dcr    a        ;..and decrement it
  181.     sta    lincnt        ;..store it
  182.     jnz    wrtbak1        ;..and loop if not there
  183.     inx    h        ;else bump pointer to account for lf with cr
  184.     jmp    wrtfwd1        ;..and go write a screen
  185.  
  186. filbak:    lxi    d,maxsec    ;get the buffer size
  187.     lhld    seccnt        ;..anΣ numbe≥ oµ sector≤ las⌠ read
  188.     dad    d        ;add them
  189.     xchg            ;..and put them in DE
  190.     lda    fcbcrr        ;subtract low order byte 
  191.     sub    e        ;..from current record count
  192.     sta    fcbcrr        ;..and store in current record count
  193.     lda    fcbcrr+1    ;same with high order byte
  194.     sbb    d        ;..but with borrow
  195.     jm    filbeg        ;if beyond beginning of file, go zero count
  196.     sta    fcbcrr+1    ;else, store high order byte
  197.     call    filbuf        ;fill the buffer
  198.     lxi    h,fulbuf    ;..and point to end of buffer
  199.     call    clrscr        ;clear the screen
  200.     jmp    wrtbak2        ;continue moving back in file
  201.                     
  202. filbeg:    xra    a        ;if beyond beginning of file
  203.     sta    fcbcrr        ;..zero the current record field
  204.     sta    fcbcrr+1
  205.     sta    lincnt        ;..and the line count
  206.     call     filbuf        ;fill the buffer again
  207.     jmp    wrtfwd        ;..and go write it
  208.  
  209. filbuf:    lxi    d,dskbuf    ;load start of disk buffer
  210.     mvi    b,maxsec    ;number of sectors to resd
  211.     lxi    h,0        ;zero out the
  212.     shld    seccnt        ;..number of sectors in buffer
  213. filbuf1    push    h        ;save all
  214.     push    d        ;..registers from
  215.     push    b        ;..BDOS clobber
  216.     mvi     c,stdma        ;set dma to
  217.     call    bdos        ;..disk buffer
  218.     lxi    d,fcb        ;set up to read
  219.     mvi    c,readr        ;..a record
  220.     call    bdos        ;do it
  221.     cpi    0        ;read OK?
  222.     lhld    fcbcrr        ;get current record number
  223.     inx    h        ;..bump it
  224.     shld    fcbcrr        ;..and save it
  225.     lhld    seccnt        ;get sectors in buffer
  226.     inx    h        ;bump it
  227.     shld    seccnt        ;store it
  228.     jnz    rderr        ;no, last sector read
  229.     pop    b        ;yes, get sector count
  230.     dcr    b        ;decrement it
  231.     pop    d        ;get de off stack to expose return address
  232.     pop    h        ;
  233.     rz            ;if done return
  234.     lxi    h,128        ;else, add 128 to
  235.     dad    d        ;..dma address
  236.     xchg            ;put it in de
  237.     jmp    filbuf1        ;read another sector
  238.  
  239. rderr:    pop    b        ;restore
  240.     pop    d        ;..registers
  241.     pop    h        ;..and
  242.     xra    a        ;..get a zero to direct to start of buffer
  243.     ret            ;..on ret
  244.  
  245. opnfil:    lda    fcbfn        ;point to first letter of filename
  246.     cpi    ' '        ;anything there?
  247.     jz    help        ;no, give help message
  248.     lxi    d,fcb        ;file name in default fcb
  249.     mvi    c,open        ;set up to open
  250.     call    bdos        ;do it
  251.     cpi    0ffh        ;open OK?
  252.     rnz            ;yes
  253.     call    ilprt        ;else, give error msg and quit
  254.     db    cr,lf,lf,'Requested file is not on this disk.',cr,lf,bell
  255.     db    'Please check your spelling or use DIR.',cr,lf,lf,bell,0
  256.     jmp    exit1        ;leave msg on screen on exit
  257.  
  258. help:    call    ilprt
  259.     db    'Correct usage of BISHOW is --',cr,lf,lf
  260.     db    '    A>bishow filename  ',cr,lf,lf
  261.     db    'After first page is displayed, press F to scroll forward, '
  262.     db     cr,lf
  263.     db    'B to scroll backward, or X to exit.',bell,cr,lf,lf,0       
  264.     jmp    exit1
  265.  
  266. ilprt:    xthl            ;exchange top of stack and HL
  267. ilprt1    mov    a,m        ;HL now pointing to db message
  268.     ora    a        ;see if 0 at end of message
  269.     jz    ilprt2        ;yes, restore stack and return
  270.     call    ctype        ;no, print the character
  271.     inx    h        ;bump the pointer
  272.     jmp    ilprt1        ;..and loop
  273. ilprt2    xthl            ;get return address on top of stack
  274.     ret            ;..and return
  275.  
  276. ctype:    push    b        ;Save the registers
  277.     push    d        ;..from bdos
  278.     push    h        ;..clobber
  279.     mov    e,a        ;set up character
  280.     mvi    c,wrcon        ;..to send to console
  281.     call    bdos        ;do it
  282.     pop    h        ;restore
  283.     pop    d        ;..the registers
  284.     pop    b
  285.     ret
  286.  
  287. exit:    call     clrscr        ;clear the screen
  288. exit1    jmp    0        ;warm boot
  289.  
  290. ; Memory allocation
  291.  
  292. seccnt:    dw    0    ;number of sectors read into buffer
  293. linmax:    db    24    ;number of to write lines on console
  294. lincnt:    db    0    ;line number on write or move back in buffer
  295.     ds    60    ;stack area
  296. stack:    ds    2
  297. dskbuf:    equ    $    ;disk buffer area above the program
  298.  
  299.     end    100h
  300.