;*************************** AMUS Program Label ******************************
; Filename: UUENCO.M68                                      Date: 9/25/90
; Category: UTIL         Hash Code: 051-640-161-456      Version: 1.0(100)
; Initials: ROBB/AM      Name: Erik Petrich
; Company: Microlink Computing Systems, Inc.       Telephone #: 4053218333
; Related Files: UUDECO.M68
; Min. Op. Sys.:                               Expertise Level: ADV
; Special: Requires the 2.0 assembler to reassemble.
; Description: This is uuencode ported to AMOS/L. It encodes binary files to
; an ascii file that uudecode and UUDECO can decode.
;*****************************************************************************
;
; UUENCO - Copyright 1990 Microlink Computing Systems, Inc.
;
; Usage:
;   UUENCO {DestinationFile=}SourceFile {DecodedFilename}
;
; Notes:
;   The DecodedFilename is the default destination file that uudecode or
;     UUDECO will use when decoding the file.
;   If not specified, the DecodedFilename will default to the SourceFile's
;     filename.
;
;Edit History:
;[100] 07 September 1990 23:15  Edited by Erik Petrich
;
;

       SEARCH  SYS
       SEARCH  SYSSYM

       VMAJOR = 1.
       VMINOR = 0.
       VEDIT  = 100.

       .OFINI
       .OFDEF  infil,D.DDB
       .OFDEF  inbuf,512.
       .OFDEF  outfil,D.DDB
       .OFDEF  outbuf,512.
       .OFDEF  linbuf,46.
       .OFDEF  linsiz,2
       .OFDEF  CheckSum,2
       .OFDEF  FileSize,4
       .OFSIZ  impsiz

       PHDR    -1,0,PH$REE!PH$REU

       GETIMP  impsiz,a5

       BYP
       LIN
       jeq     Usage
       mov     a2,a1
       orb     #D$ERC,D.FLG+outfil(a5)
       clr     d6
       FSPEC   outfil(a5)
       jne     Abort
       byp
       movb    (a2)+,d1
       cmpb    d1,#'=
       bne     20$
       lea     a6,outbuf(a5)
       mov     a6,D.BUF+outfil(a5)
       orb     #D$INI,D.FLG+outfil(a5)
       clr     D.DVR+outfil(a5)
       LOOKUP  outfil(a5)
       bne     10$
       DSKDEL  outfil(a5)
       jne     Abort
10$:    OPENO   outfil(a5)
       jne     Abort
       br      30$
20$:    mov     a1,a2
30$:

StartFile:
       BYP
       LIN
       jeq     Usage
       clr     d6
       orb     #D$ERC,D.FLG+infil(a5)
       FSPEC   infil(a5)
       jne     Abort
       lea     a6,inbuf(a5)
       mov     a6,D.BUF+infil(a5)
       orb     #D$INI,D.FLG+infil(a5)
       OPENI   infil(a5)
       jne     Abort

       lea     a0,BeginTxt
       call    StringOut
       byp
       lin
       beq     10$

       mov     a2,a0
       br      20$
10$:    lea     a2,linbuf(a5)
       ofile   infil(a5),ot$mem
       clrb    @a2
       lea     a0,linbuf(a5)
20$:    call    StringOut
       call    CRLFout

ReadLine:
       CTRLC   Abort
       lea     a0,linbuf(a5)
       clrw    linsiz(a5)
10$:    FILINB  infil(a5)
       jne     Abort
       tst     D.SIZ+infil(a5)
       beq     20$
       movb    d1,(a0)+
       inc     FileSize(a5)
       rorw    CheckSum(a5)
       addw    d1,CheckSum(a5)
       incw    linsiz(a5)
       cmpw    linsiz(a5),#45.
       blo     10$
20$:
       tstw    linsiz(a5)
       jeq     WriteEOF

WriteLine:
       movw    linsiz(a5),d1
       call    ByteOutBumped
       lea     a0,linbuf(a5)

10$:    CTRLC   Abort

       movb    @a0,d1
       lsrb    d1,#2
       call    ByteOutBumped

       movb    @a0,d7
       lslb    d7,#4
       movb    1(a0),d1
       lsrb    d1,#4
       orb     d7,d1
       call    ByteOutBumped

       movb    1(a0),d7
       lslb    d7,#2
       movb    2(a0),d1
       lsrb    d1,#6
       orb     d7,d1
       call    ByteOutBumped

       movb    2(a0),d1
       call    ByteOutBumped

       add     #3,a0
       subw    #3,linsiz(a5)
       bhi     10$

20$:    call    CRLFout

       tst     D.SIZ+infil(a5)
       jne     ReadLine

WriteEOF:
       clrb    d1
       call    ByteOutBumped
       call    CRLFout
       lea     a0,EndTxt
       call    StringOut
       call    CRLFout

       CLOSE   infil(a5)
       jne     Abort
       type    <File size : >
       mov     FileSize(a5),d1
       dcvt    0,ot$trm
       crlf
       type    <      Sum : >
       clr     d1
       movw    CheckSum(a5),d1
       dcvt    0,ot$trm
       crlf
       jmp     Done

StringOut:
10$:    movb    (a0)+,d1
       cmpb    d1,#32.
       blo     20$
       lcs
       call    ByteOut
       br      10$
20$:    rtn

CRLFout:
       movb    #13.,d1
       call    ByteOut
       movb    #10.,d1
       call    ByteOut
       rtn

ByteOutBumped:
       andb    #^H03f,d1
       bne     10$
       movb    #64.,d1
10$:    addb    #32.,d1

ByteOut:
       tstb    D.OPN+outfil(a5)
       bne     10$
       TTY
       rtn
10$:    FILOTB  outfil(a5)
       jne     Abort
       rtn

Abort:  CRLF
Done:   tstb    D.OPN+outfil(a5)
       beq     10$
       CLOSE   outfil(a5)
10$:    tstb    D.OPN+infil(a5)
       beq     20$
       CLOSE   outfil(a5)
20$:
       EXIT

BeginTxt:
       asciz   /begin 600 /
EndTxt:
       asciz   /end/
       even

Usage:  TYPECR  <UUENCO - Copyright 1990 Microlink Computing Systems, Inc.>
       CRLF
       TYPECR  <Usage:>
       TYPECR  <  UUENCO {DestinationFile=}SourceFile {DecodedFilename}>
       CRLF
       EXIT

       end