home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / PCACHSRC.ZIP / DSK2SCRN.ASM < prev    next >
Assembly Source File  |  1989-05-04  |  5KB  |  102 lines

  1. ;DSK2SCRN.COM           B.Kauler 1989.
  2. ;reads a text file from disk and displays it on the screen.
  3. ;DOS command line:  DSK2SCRN [filename]
  4. ;................................................................
  5. comseg  segment
  6.         assume  cs:comseg,ds:comseg,ss:comseg
  7.         org     100h
  8. main    proc    far
  9.         jmp     code_starts
  10. ;................................................................
  11. ;disk access data here.....
  12. fcb     db      36 dup(0)       ;file control block.
  13. dta     db      0               ;disk transfer area(1byte only).
  14. err_msg db      "file access error!"
  15. ;
  16. ;program data here.....
  17. char_pos   db   0               ;character position on the line.
  18. ;................................................................
  19. code_starts:
  20. ;read the DOS-command-line tail from the PSP, to a File Control
  21. ;Block (FCB) that we are creating for the file to be opened.....
  22.         mov     si,5Ch          ;get addr of tail in PSP.
  23.         mov     di,offset fcb   ;get addr of FCB.
  24.         mov     cx,12           ;string length to move.
  25.         cld
  26.         rep movsb               ;mov string PSP -->FCB.
  27. ;We need to specify a Disk Transfer Address, through which chars
  28. ;are sent to and received from disk....
  29.         mov     dx,offset dta   ;DOS function SET_DTA.
  30.         mov     ah,1Ah          ;       /(DS:DX-->)
  31.         int     21h             ;       /
  32. ;the filename must be at DS:DX to open the file.  We have the name
  33. ;in the FCB, so....
  34.         mov     dx,offset fcb   ;DOS function OPEN_FILE.
  35.         mov     ah,0Fh          ;       /(DS:DX-->)
  36.         int     21h             ;       /
  37.         cmp     al,0            ;test file open error.
  38.         jnz     error
  39. ;If function 0Fh succeeds in opening the file, various relevant
  40. ;information is automatically transfered from disk into the FCB.
  41. ;the first byte of the FCB will hold the disk number from which
  42. ;the file was read, and offset 0Eh specifies the record-size
  43. ;and is set to 128, which is arbitrary, and we can change it and
  44. ;other parameters....
  45.         mov     word ptr fcb+0Ch,0      ;current block=0.
  46.         mov     word ptr fcb+0Eh,1      ;record size=1
  47.         mov     fcb+20h,0               ;current record=0
  48. ;read a char from file & display it....
  49. ;note that we test here for CTRL-Z to determine the end of the
  50. ;file, as CTRL-Z occurs at the end of text files, however
  51. ;function 14h returns an error-code in AL that can be used to
  52. ;signal the end of file.
  53. again:  mov     dx,offset fcb   ;DOS function SEQUENTIAL_READ.
  54.         mov     ah,14h          ;       /
  55.         int     21h             ;       /
  56.         cmp     al,0            ;test if read error.
  57.         jnz     error
  58.         mov     al,dta          ;get the char just read.
  59.         cmp     al,1Ah          ;is it CTRL-Z?
  60.         je      eof
  61.         cmp     al,09h          ;is it TAB?
  62.         je      tab
  63.         call    disp_char       ;display the char.
  64.         inc     char_pos        ;update current char position.
  65.         cmp     dta,0Ah         ;test if end of line.
  66.         jne     again           ;not end of line--get next char.
  67.         mov     char_pos,0      ;clear char count.
  68.         jmp     again           ;get next char.
  69. ;..................................................................
  70. tab:    mov     al," "
  71.         call    disp_char       ;display a blank.
  72.         inc     char_pos        ;update current char position.
  73.         test    char_pos,7      ;are we at a TAB stop?
  74.         jz      again           ;yes.
  75.         jmp     tab
  76. ;.................................................................
  77. eof:    mov     dx,offset fcb   ;DOS function CLOSE_FILE.
  78.         mov     ah,10h          ;       /
  79.         int     21h             ;       /
  80.         mov     al,0            ;return to DOS.
  81.         mov     ah,4Ch          ;       /
  82.         int     21h             ;       /
  83. ;.................................................................
  84. error:  mov     dx,offset err_msg       ;display error message.
  85.         mov     ah,9                    ;       /
  86.         int     21h                     ;       /
  87.         mov     al,0            ;return to DOS.
  88.         mov     ah,4Ch          ;       /
  89.         int     21h             ;       /
  90. ;.................................................................
  91. disp_char       proc    near
  92.         push    bx
  93.         mov     bx,0            ;display a char.
  94.         mov     ah,14           ;       /
  95.         int     10h             ;       /
  96.         pop     bx
  97.         ret
  98. ;................................................................
  99. main    endp
  100. comseg  ends
  101. end     main
  102.