;Program: TXTALIAS ;Author: Bruce Morgen ;Version: 1.0 ;Date: May 10, 1991 ; ;Derivation: ALIAS1.Z80 (Second module of ALIAS17.COM) by Joe ; Wright (1/21/91) for a great deal of the code and ; ACREATE2.C by Howard Cripe (5/6/85) for the basic ; idea. Ernest Stiltner (Skunk Creek Computing ; Services) wrote a similar program called BA24, but ; it was distributed sans source and did not figure ; in the development of TXTALIAS. ; ;Purpose: The purpose of TXTALIAS is to create aliases using ; the ALIAS0 module from an ordinary ASCII text file. ; TXTALIAS supports assembler-style comments in the ; "source" text file. Full line comments must begin ; with a ";" and inline comments must be preceded by ; at least one horizontal tab (09h) and a ";". ; Multiple consecutive newlines compile to a single ; ";" in the alias. ; ;Comments: "Source" files are limited to what will fit in memory ; with TXTALIAS and the CCP (plus any RSXs present), ; minus a page. I trust this will not be a problem. ; What passes for command line parsing can be easily ; "fooled" with alias names like "/R" and "R" -- ; this can be remedied by preceding the alias name ; with ":" (current Z-Systems) or a drive/directory ; form that includes the current default drive (older ; Z3-compatible systems). In these cases, just use ; the "opposite" form of the recursion option if that's ; what you want. ; ;Production: Follows the latest ALIAS/SALIAS sequence: ; 1. Assemble using ZMAC, ZAS, M80, or an SLR Zilog- ; convention assembler to TXTALIAS.REL. ; 2. Link with ALIAS0, Z3LIB, and SYSLIB or SYSLIB0. ; e.g. ZML TXTALIAS=ALIAS0,TXTALIAS,Z3LIB/,SYSLIB/ version equ 10 ; Basic Equates ; tbuff equ 80h fcb equ 5ch fcb2 equ 6ch cr equ 0dh lf equ 0ah tab equ 09h eof equ 1ah ; ; External References ; ext z3init,z3log,zfname,puter2,getwhl ext getcl1,prtnam,gzmtop,z33chk,z33fname ext sksp,bbline,capine,pfn2,pafdc ext setdma,initfcb,sfa,cout,eprint,epstr,crlf ext f$open,f$read,f$close,f$make,f$write,f$exist ext codend,putud,getud,retud ; ; Things we want to know about ALIAS0 ; ext alias0,start,z3eadr,recur,aclbuf ; Addresses in ALIAS0 ; ; ALIAS0 needs this from us ; public alias1 ; ; This is the start of ALIAS1. ; alias1: ld c,9 ld de,notz3 ld hl,(z3eadr) ; Pt to ZCPR3 environment ld a,l or h jp z,5 call z3init ; Initialize the ZCPR3 Env call getwhl jr nz,gotwhl call eprint db 'Wheel privileges required',0 ret gotwhl: call putud ; Save default User/Drive ; ; Print Banner ; call eprint db 'TXTALIAS, Version ' db version/10+'0','.',version mod 10+'0' db cr,lf,0 ; ; Check for File ; over: ld hl,tbuff ; Find TBUFF's last token ld e,(hl) dec e ; Char. count of one is blank jr z,help inc e ; As is char. count of zero jr z,help ld d,h ; Zero out D from H add hl,de ; Point to last char. ld d,(hl) ; Into D dec hl ; Preceding char. ld e,(hl) ; Into E dec hl ; Yet another char. ld c,(hl) ; Into C ld hl,'R/' ; First form of recursive request xor a sbc hl,de ; Is last token /R? jr nz,over0 ; One more test and we accede ld a,c sub ' ' jr z,over1 over0: ld hl,'R ' ; Second form of request xor a sbc hl,de ; Just plain R? ld c,d ; Swap D & E for FCB test later ld d,e ld e,c jr nz,over2 ; Request accepted if Z (A = 0) over1: cpl ; 0FFh becomes 0 & vice-versa over2: ld (recflg),a inc a ; Z if recursive jr nz,over3 ; Skip some stuff if not ld hl,(fcb2+1) ; See if option is second token or a sbc hl,de over3: ld hl,fcb2 ; Save possible dest. file FCB ld de,fcbbuf jr nz,over5 ; Must be 3rd one if NZ ld a,(hl) or a ld a,h jr nz,over2 call retud ld a,(fcb2+13) cp c ld a,h jr nz,over2 ld b,11 ; Otherwise blank out FCB2 name push hl over4: inc hl ld (hl),20h djnz over4 pop hl over5: ld bc,fcblen ; Move FCB2 to our buffer ldir over6: ld de,fcb+1 ; Pt to input file name ld a,(de) ; Get first char dec de ; Point to FCB cp '/' ; Help? jp nz,start0 ; We have a file name ; ; Help Message ; help: call eprint db 'Creates an Alias Command from an ASCII text file',cr,lf db 'Syntax:',cr,lf,' ',0 call prtnam call eprint db ' [dir:]filename[.typ] [dir:][alias] [[/]R]',cr,lf db ' Without an output alias specification, produces',cr,lf db ' the alias "filename.COM" in the current directory.',cr,lf db ' "R" option is for a VALIAS-style recursive alias.',0 ret nofile: call eprint db 'No source file',0 ret ; ; Find and Open Text File ; start0: call z3log ; Log into specified directory call initfcb ; Initialize the FCB call f$open ; Open text file for input call puter2 ; Result to Program Error Flag jr nz,nofile ; Can't find it, complain ; Else fall through to LOAD it ; ; Load Text File ; call gzmtop ; Get CPR or RSX start dec h ; Minus a page ld b,h ; BC is available ld c,l call codend ; Point to load buffer ld (hl),l ; Null to flag empty source file load1: call setdma ; Set DMAADR call f$read ; Read next record jr nz,load2 ; End of File ; call add128 ; Advance DMAADR or a sbc hl,bc jr nc,loaderr add hl,bc jr load1 ; ; TPA overflow ; loaderr: call eprint db 'Not enough memory for ',0 call pdufn ld a,'?' jp puter2 ; Load Complete ; load2: call f$close ; Close input file ld a,(hl) or a jp z,werr ; Leading null is an error! ld (hl),eof ; Just in case... ex de,hl call codend ex de,hl or a sbc hl,de ld (maxlen),hl ; ; Prep to Copy New Command Into ALIAS0 ; ld hl,start ; START address in ALIAS0 ld (alias0+1),hl ; Point ALIAS0 to itself ld a,(recflg) ld (recur),a call getcl1 ld b,a ; Current MCL length in B ld c,255 ; Absolute ALIAS0 limit in C ex de,hl ; Beginning of inp. file (codend) ld de,aclbuf ; Alias0 command line buffer ld a,(hl) ; Takes care of leading ";"s & cp cr ; newlines (thanks Howard!) jr z,prelp cp ';' jr nz,copylp prelp: push bc ld bc,(maxlen) prelp1: inc hl ld a,lf cpir jp po,nocrlf ld a,(hl) cp cr jr z,prelp1 cp ';' jr z,prelp1 pop bc ; FALL THROUGH ; ; Copy New Command into ALIAS0 File ; with "comment killer" -- ; Full line comments must begin with a ";" ; Inline comments require at least one tab before the ";" ; Multiple consecutive newlines become one command sep. ; copylp: ld a,(hl) ; Get character cp eof ; Are we done? jp z,copydn cp tab jr nz,nottab push hl tablp: inc hl cp (hl) jr z,tablp ld a,(hl) cp ';' jr z,tabcom pop hl ; Get back ptr. & jr notlf ; process normal char. tabcom: pop af ; Benign way to balance stack jr cmntlp ; Now process comment nottab: cp cr ; Probable newline jr nz,notcr ; No? Then just copy it to alias crloop: inc hl ; Otherwise bump pointer ld a,(hl) ; Get next character cp lf ; A linefeed? ld a,';' jr z,gotlf ; Nope, treat as text dec hl jr notlf gotlf: inc hl cp (hl) ; Semicolon at line start? jr z,cmntlp ; Then process as comment dec hl ; Adjust source ptr. dec de ; DE points to last char. moved inc b ; Pre-adjust counters inc c ex de,hl ; Swap ptrs. cp (hl) ; Was it a semicolon? ex de,hl ; Swap back jr z,notcr ; If semicolon, don't double it inc de ; Otherwise normal move dec b ; Fix pointers again dec c jr notcr ; isn't doubled or a comment cmntlp: inc hl ld a,(hl) ; Otherwise scan for next CR cp cr jr nz,cmntlp jr crloop notlf: ld a,(hl) notcr: ld (de),a inc hl inc de dec c jr z,ovfl djnz copylp toobig: call eprint db 'Too much text for ZCPR3 Command Line, continue (y/N)? ',0 call capine cp 'Y' jp z,copylp ld a,89 jppter: jp puter2 ovfl: call eprint db cr,lf db 'ALIAS overflow' abtstr: db ', aborting',0 ld a,99 jr jppter nocrlf: pop af call eprint db cr,lf db 'Source file error, no final newline found',0 ld hl,abtstr call epstr ld a,100 jr jppter ask: call new ; Get new alias name ret z ; No name specified call crlf call z3log ; Log into destination directory call initfcb ; Clear the FCB jr write0 copydn: xor a ld (de),a dec de ld a,(de) cp ';' jr z,copydn ; ; Write File whose Name is in FCB ; write: call getud ; Home directory for login ld de,fcbbuf+1 ; Get 1st character of 2nd token ld a,(de) dec de call z3log ; Login ex de,hl ; 2nd token FCB pointer to HL ld de,fcb ; Working FCB in DE cp ' ' ; 2nd token blank? jr z,write0 ; Nope, use the whole thing ld bc,fcblen push de ldir pop de write0: call setcom ; Set file type to COM call f$exist ; Check for existence jr z,write1 ; No file, go for it call eprint db ' File ',0 call pdufn call eprint db ' Exists - Overwrite (y/N)? ',0 call capine sub 'Y' jr nz,ask ; If not 'Y', prompt for new name call crlf ld de,fcb ; Clear file attributes call sfa ; Set file attributes to R/W DIR ; ; Create New File ; write1: call initfcb call f$make ; Create file ld hl,alias1-100h ; Length of ALIAS0 in bytes (mod 128) add hl,hl ; Records to H ld b,h ; Now to B ld hl,alias0 ; Beginning of ALIAS0 write2: call setdma ; Set DMAADR for BDOS call f$write jr nz,werr call add128 ; Advance DMAADR djnz write2 ; Count down ; ; Write is finished, sign off. ; call f$close ; Close file call eprint db ' Alias ',0 call pdufn call eprint db ' Created',0 ret werr: call eprint db ' DOS File Error',0 inc a ; Adjust so all are unique inc a jp puter2 ; Poke Program Error Flag, return ; newfile: call new ; Ask for new name ret z ; None, Quit jp over6 ; Start over new: call eprint db cr,lf,' Name of ALIAS Command (RETURN to Quit)? ',0 ld a,0ffh ; Capitalize call bbline ; Get dir:filename from user call sksp ; Skip to non-blank ld a,(hl) or a ret z ; Quit call getud ; Start with default User/Drive ld de,fcb call zparse ; Parse it into FCB or 255 ; NZ for success ret ; ; Use best available ZCPR3 parser ; zparse: call z33chk jp z,z33fname xor a ; DIR first jp zfname ; ; Set File Type of File in FCB to COM ; setcom: push hl push de ld hl,comtyp ; Set COM type ld de,fcb+9 ; Copy into file type call movit pop de pop hl ret ; ; Move (hl) to (de) until and including Null terminator ; movit: ld a,(hl) ; Get the byte we are about to move ldi ; (hl) to (de), inc HL and DE or a ; Test byte for Null jr nz,movit ; Move another if not ret ; ; Print DU:NAME.TYP ; pdufn: call pdu ; Print DU: ld de,fcb+1 ; Point to filespec jp pfn2 ; Print it ; ; Print DU: ; pdu: call retud ; Drive (Rel 0) in B, User in C ld a,b ; Get Drive add a,'A' ; Add Ascii call cout ; Print it ld a,c ; Get User call pafdc ; Print it ld a,':' jp cout ; ; Add 128 to HL ; add128: ld a,128 ; ; Add A to HL ; addah: add a,l ; Add A to L ld l,a ; Put it back ret nc ; If LT 256 inc h ; Overflow ret ; ; Buffers ; comtyp: db 'COM',0 ; COM File Type notz3: db 7,'Needs ZCPR3!$' dseg recflg: ds 1 maxlen: ds 2 fcbbuf: ds 36 fcblen equ $-fcbbuf end ; ; End of TXTALIAS.Z80