comment |
File: READER.ASM
Author: Craig Allsop (Daemon) of White Lightning @ 3:640/225

Create with this:

TASM READER.ASM
TLINK /t READER

Produces: READER.COM (137 bytes)

This code I Craig Allsop alias Daemon, declare public domain, and was designed
to be the smallest not the fastest.

It accepts ONE argument, a filename, no checking for dumb users. It is also
assumed to exist in .COM format, ie. the read buffer is not declared. Please
add to the 80XXX snippits (insert this text above)
       |


ideal
model   tiny

codeseg
        org     100h

proc    reader

        mov     di,80h
        mov     bl,[byte ptr di]
        xor     bh,bh
        mov     [byte ptr di+bx+1],0    ; make filename into ASCIIZ format.

        mov     dx,82h
        mov     ax,3d00h
        int     21h                     ; Open file
        jc short @@exit                 ; If an error opening file, exit.
        mov     bx,ax                   ; bx = file handle
        mov     di,24                   ; di = line counter
@@loop1:
        mov     dx,offset block
        mov     ah,3fh
        mov     cx,16384
        int     21h                     ; Read big chunk (16384 bytes)
        jc short @@exit
        or      ax,ax                   ; Read nothing? At end of file, exit.
        jz short @@ending
        mov     cx,ax                   ; cx = real bytes read
        mov     si,dx
        mov     ah,2                    ; Dos function 2 (write char)
        push    cx
@@loop2:
        lodsb
        cmp     al,10
        jnz short @@loop3               ; char not linefeed so display it
        dec     di
        jnz short @@loop3               ; if not end of screen continue
        mov     ah,9
        mov     dx,offset more
        int     21h                     ; display more prompt
        xor     ax,ax
        int     16h                     ; get keyboard entry
        cmp     al,'n'
        jz short @@ending               ; if 'n' then exit
        mov     di,24                   ; reset line counter
        mov     ax,020dh
@@loop3:
        mov     dl,al
        int     21h                     ; display char
        loop    @@loop2
        pop     cx
        cmp     cx,16384                ; was full block read, if so loop
        jz short @@loop1
@@ending:
        mov     ah,3eh
        int     21h                     ; close file
@@exit:
        mov     dx,offset credit
        mov     ah,9
        int     21h                     ; display credits
        mov     ax,4c00h
        int     21h                     ; exit to dos
endp

credit  db      13,'Code by Deamon!$'
more    db      10,'More(Y/n)?$'
block   db      0

end     reader

