main           proc    near 
               jmp     memo1 
buffer:        dw      300    dup    (?) 
memo1:         mov     b[0009h],60h     ;multiplier
               mov     b[0002h],00h     ;panel counter
               call    vid              ;mono,CGA,EGA?
               call    clrs             ;clear screen
               call    init             ;initial check
               call    rdfn             ;read filename
               call    openit           ;open it
               call    ptbuf            ;check password
               call    doit             ;main routine
               call    closeit          ;close file
               int     20h              ;exit
               endp
doit           proc    near
sub2:          inc     b[0002h]         ;step counter
               call    fillbuf          ;fill buffer
               call    clrs             ;clear screen
               mov     bx,107h          ;buffer address
               mov     w[0006h],bx      ;store it
               mov     ax,000bh         ;top row
               mov     w[0004h],ax      ;store it 
               mov     cx,000Ah         ;number of rows
sub3:          push    cx               ;save it
               call    sub1             ;display row
               add     w[0006h],+19h    ;row length
               inc     w[0004h]         ;step row counter
               pop     cx               ;get it back
               loop    sub3             ;complete block
               call    td               ;time delay
               mov     ah, b[0008h]     ;check for
               cmp     b[0002h], ah     ;out condition
               jz      sub4             ;yes, out
               jmp     sub2             ;no, do again
sub4:          call    clrs             ;clear screen
               ret
               endp
sub1           proc    near
               mov     si,[0006h]
               mov     cx,0019h         ;chars. per row
               mov     ax,w[0004h]      ;row counter
               mov     bx,0040h         ;base port
               mov     es,bx
               mul     es:w[004ah]
               mov     di,001ah
               add     di,ax
               shl     di,1
               mov     es:dx,[0063h]
               mov     ax,w[0215h]      ;mono video port
               mov     es,ax
               mov     bl,b[0212h]      ;attribute byte
               mov     dx,w[0213h]      ;mono retrace port
               cld
sub5:          in      al,dx            ;anti snow
               test    al,01            ;anti snow
               jnz     sub5             ;anti snow
               cli                      ;no interupts
sub6:          in      al,dx            ;anti snow
               test    al,01            ;anti snow
               jz      sub6             ;anti snow
               movsb
               mov     al,bl            ;moves row to
               stosb                    ;video buffer
               sti                      ;set interupt flag
               loop    sub5             ;loop back for row
               ret
               endp
vid            proc    near             ;get video state 
               mov     ah,0fh           ; 
               int     10h 
               sub     ah,019h          ;sub. 25 from line count 
               shl     ah,1h            ;mult. by 2, lose high bit 
               mov     b[0211h],ah      ;store count 
               mov     b[0212h],al      ;store mode 
               cmp     al,7h            ;is it hga text? 
               Jz      m7 
               cmp     al,3h            ;is it cga? 
               Jz      m3 
               cmp     al,2h            ;is it cga? 
               Jz      m2 
m7:            mov     w[213h],03bah    ;hga retrace port 
               mov     w[215h],0b000h   ;hga video segment 
               jmp     mm 
m3:            nop 
m2:            mov     w[213h],03dah    ;cga retrace port 
               mov     w[215h],0b800h   ;cga video segment 
mm:            ret 
clrs           proc    near
               mov     ax,0719h         ;clear screen
               mov     bh,07h           ;white on black
               mov     cx,0000h         ;upper left
               mov     dx,194fh         ;lower right
               int     10h
               ret
               endp
td             proc    near
               push    ax
               mov     ax,12h
               mul     b[0009h]
               mov     cx,ax
               pop     ax
d1:            push    cx
               mov     ah,00h
               int     1ah
d2:            push    dx
               mov     ah,0
               int     1ah
               mov     ax,0b00h
               int     21h
               cmp     al,0ffh
               je      outt
               pop     bx
               cmp     bx,dx
               je      d2
               pop     cx
               loop    d1
               ret
outt:          pop     cx
               mov     ax,0c00h
               mov     dx,0109h
               int     21h
               pop     ax
               ret
               endp
init           proc    near            ;initialization routine   
               mov     ah, 30h         ;what dos are we under?   
               int     21H   
               cmp     al,2            ;dos 2.0 or over?   
               jae     a1              ;yes, skip   
               mov     ah, 09h         ;no, bitch   
               mov     dx, offset baddos  
               int     21H   
               int     20h             ;and exit   
a1:            call    curpos          ;blank and position
               ret
baddos:        db      0dh,0ah,'This program requires DOS 2.0!'
               db      0dh,0ah,0dh,0ah,'$'
               endp
pcrm           proc    near
               mov     ah, 09h         ;send title message   
               mov     dx, offset tmsg  
               int     21H   
               ret
tmsg:  db   0dh,0ah,'MEMO  version 2.0  Copyright (c) 1992 ',0dh,0ah
    db  'If you find this program useful or interesting, please',0dh,0ah
    db  'send a minimum contribution of Fifteen Dollars to:',0dh,0ah,0dh,0ah
    db  'Robert Wallingford, 2338 N. McVicker Ave., Chicago, IL 60639'
    db  0dh,0ah,0dh,0ah,'$'
               endp  
rdfn           proc    near            ;read file name
               cld                     ;positive increment
               mov     si, 081h        ;initial offset F.N.
rdl1:          lodsb                   ;get character
               cmp     al, 0dh         ;is it CR ?
               je      rdlo            ;if yes print msg.
               mov     di, 0162h
               mov     cx, 05h
               repne   scasb
               cmp     al, 020h        ;count blank spaces
               je      rdl1
               mov     dx,si           ;true offset F.N.
               dec     dx
rdl2:          lodsb                   ;get cÿ!racter
               cmp     al, 0dh         ;is it CR ?
               je      rdl3            ;done if yes
               jne     rdl2            ;get another if no
rdl3:          mov     b[si-1], 00h
               jmp     rdl4
rdlo:          mov     ah, 09h         ;print msg
               mov     dx, offset rdlmsg
               int     21h
               call    pcrm
               int     20h
rdl4:          ret
               endp
rdlmsg:        db      'Syntax:    SHOWMEMO [file_path]FILE_NAME ',0dh,0ah,'$'
curpos         proc    near
               push    dx              ;
               mov     ax, 0200h       ;position cursor
               mov     bx, 0000h       ;
               mov     dx, 0000h       ;
               int     10h             ;
               xor     cx, cx          ;blank screen
               mov     dx, 194fh       ;
               mov     bh, 07h         ;
               mov     ax, 0619h       ;
               int     10h             ;
               pop     dx              ;
               ret
               endp
openit         proc    near            ;Open file  
               mov     ax, 3d00h  
               int     21h   
               jc      fail_end  
               mov     w[102h], ax     ;save fhandle
               jmp     open_end  
fail_end:      mov     ah, 09h         ;fail exit
               mov     dx, offset fnfmsg
               int     21h
               int     20h
open_end:      ret   
fnfmsg:        db      0dh,0ah,'File not found.   ',0dh,0ah,'$'
               endp   
closeit        proc    near            ;close file  
               mov     ax, 3e00h  
               mov     bx, w[102h]
               int     21h   
               jc      ffail_end  
               jmp     close_end 
ffail_end:     int     20h             ;fail exit
close_end:     ret 
               endp   
ptbuf          proc    near            ;move file pointer
               mov     ah, 3fh
               mov     bx, w[0102h]
               mov     cx, 0005h
               mov     dx, 107h
               int     21h             ;get number of panels
               mov     bh, b[0107h]
               mov     b[0008h], bh
               mov     bp, 107h
               mov     bh, 00h
               mov     bl, [bp]
               mov     dx, [bp+1]
               mov     cx, [bp+3]
               cmp     dl, 'M'
               jne     stop            ;is this file
               cmp     dh, 'E'         ;a 'MEMO' file?
               jne     stop            ;if not, exit
               cmp     cl, 'M'
               jne     stop
               cmp     ch, 'O'
               je      ok
stop:          mov     ah, 09h         ;print password msg
               mov     dx, offset pswd
               int     21h
               int     20h             ;and exit
ok:            ret
pswd:          db      'This is not a MEMO file.',0dh,0ah,'$'
               endp
fillbuf        proc    near
               mov     ah, 3fh         ;get time byte
               mov     bx, w[102h]     ;file handle
               mov     cx, 01h         ;one byte
               mov     dx, 0009h       ;storeage address
               int     21h
               mov     ah, 3fh         ;get attribute byte
               mov     bx, w[102h]     ;file handle
               mov     cx, 01h         ;one byte
               mov     dx, 0212h       ;storeage address
               int     21h
               mov     ah, 3fh
               mov     cx, 0FAh         ;pointer buffer length
               mov     dx, 0107h       ;and location
               int     21h             ;fill index buffer   
               ret
               endp
