* * * << EDIT SCANNER >> * * * * ERRET DW -1 the way error return flag used to be set CIFILE DB 0 command input file COFILE DB 1 command output file * * Source file: * SALS8 DB NO ALS8-type file? Default is no. STYPE DB '.'+80H type SBLKSZ DW 4C0H blocksize SATTR DB 0 attributes (or lack thereof) SFILE DS 12 name of source (input) file SFNUM DS 1 its number when opened * * Output file: * OALS8 DB NO Should it be written in ALS8 format? OTYPE DB '.'+80H OBLKSZ DW 4C0H OATTR DB 0 OFILE DS 12 name of output file OFNUM DS 1 its number when opened * * Initialize values, read in file names, etc. * Code from GPRAM on is overwritten when the file * is read in, since it is no longer needed. * GPRAM LHLD SYSGLO HL->system global area. PUSH H LXI D,GLCIF offset to CI's input file DAD D MOV A,M STA CIFILE Save input file's number. POP H SYSGLO again. PUSH H LXI D,GLCOF offset to CI's output file DAD D MOV A,M STA COFILE Save output file's number. POP H SYSGLO PUSH H LXI D,GLERM offset for medium (level 1) error handling DAD D MOV E,M MVI M,-1 Make level 1's return. INX H MOV D,M MVI M,-1 XCHG SHLD ERRET Remember how error trapping used to be set. POP H SYSGLO LXI D,GLLOW offset to lowest address used by system DAD D MOV E,M INX H MOV D,M Set DE = Lowest address used by system. DCX D Low address - 1 XCHG SHLD EOSP Set End Of SPace = highest addr editor can use LXI H,GPRAM SHLD BFP beginning of file pointer SHLD EFP end of file pointer * * Now read in the arguments to EDIT. (at least one and * possible tw file names) * CALL RDARG Z set => no name, C set => ALS8 specified JNZ LABX0 Name was found. NONAM CALL SKIP erro: name expected. Ignore junk. MVI A,ERNAX JMP ERROR LABX0 JNC LABX1 not ALS8 MVI A,YES STA SALS8 Remember that source file is ALS8 type. LABX1 LXI H,PSBUF source for NAMECOPY LXI D,SFILE destination CALL NMCOPY Copy file name from HL to DE. LDA DELIM last char read by PSCAN in RDARG CPI ',' JZ NXTARG Outfile specification is coming. CALL LINEND CR or semicolon? JZ DEFALT Yes. Use same outfile as infile. BADSYN CALL SKIP Bad syntax -- ignore leftovers. MVI A,ERSYN JMP ERROR * SYSMEM MVI A,ERSMP MEMORY PROTECT error. JMP ERROR * TOOSML MVI A,ERIVA Illegal value error. JMP ERROR * NXTARG CALL RDARG Read in the output file specification. JZ CHKTOM No file name -- might be a Top-Of-Memory spec. JNC LABX2 not ALS8 MVI A,YES STA OALS8 Remember that outfile is to be written ALS8. LABX2 LXI H,PSBUF LXI D,OFILE Copy outfile name from PSBUF. CALL NMCOPY LDA DELIM CALL LINEND Was that the last thing on line? JZ CHECK Check files and memory, then begin. * * At this point we have something following the outfile * argument -- it must be a Top-Of-Memory (TOM) spec. * If the Z flag is set, we had an empty outfile spec, * so we must remember to fall through DEFALT to set * outfile=infile. The TOM number cannot be larger * than the number which is in EOSP (=GLLOW-1) or we * issue a MEMORY PROTECT error. * CHKTOM PUSH PSW Remember whether to default outfile. LDA DELIM Should be a comma here. CPI ',' JNZ BADSYN Nope--garbage. LXI D,PSBUF Prepare to read in the TOM spec. MVI A,PSV Value scan. CALL PSCAN STA DELIM Remember last char. JC BADSYN Rotten number. JZ BADSYN No number. CALL LINEND Better have been last thing on the line ... JNZ BADSYN ... o else. XCHG . TOM spec is now in HL. PUSH H Save it. LXI D,EOSP DE-> highest address which won't touch PTDOS. CALL DCMP Compare HL and what DE points to. POP H (Get TOM spec back.) JC SYSMEM TOM spec was too big -- complain. PUSH H TOM can't be less than 8K-1 either. LXI D,1FFFH = 8K - 1 CALL CP16 Compare HL and DE. Carry set => HL>=DE POP H JNC TOOSML TOM was too small. SHLD EOSP Change the highest available space. POP PSW Was outfile supposed to be default? JNZ CHECK Nope. * DEFALT LXI H,SFILE Copy infile name to outfile. LXI D,OFILE CALL NMCOPY LDA SALS8 If infile is ALS8, so it should be when STA OALS8 written back out. * * Check various things before beginning: * 1) Does infile exist, and if not does user wish * to have it created? * 2) If outfile already exists, is it open or protected? * 3) Is memory okay, and if so how much can we use? * CHECK LXI D,SFILE Look up the input file. LDAX D CPI '#' Don't look it up if it was #n instead of name. JZ CHK2 LXI H,PSBUF Use PSBUF for FINFO buffer too. CALL SYS DB INFOP information to HL JMP NONEXI File wasn't there. LXI H,PSBUF+11 file's type MOV A,M ANI 80H Image-type file? (image if left bit off) JNZ CHK2 LXI H,SFILE Yes. CALL PRINT Print SFILE's name. CALL OUST ASC / is an image file./ DB 0 JMP EXIT * NONEXI CPI ERNEX right error? JNZ ERROR No. Might be MEMORY PROTECT. CALL CRLF Output CRLF. LXI H,SFILE HL->file name. CALL PRINT Print it. CALL OUST ASC / is non-existent. Create? / DB 0 CALL CONIN PUSH PSW CALL CONOUT Echo. POP PSW CPI 'Y' JZ MAKEIT CPI 'y' JNZ EXIT User doesn't want file created. MAKEIT LXI D,STYPE DE->block for source file. CALL SYS DB CREOP JMP ERROR * * First file exists, and is not an image file. * Now check second file. * CHK2 LXI D,OFILE output file's name LDAX D CPI '#' Should we look it up? JZ GFWD No. Go check memory. LXI H,PSBUF CALL SYS DB INFOP Info about outfile to HL. JMP GFWD It doesn't exist. That's OK. LXI H,PSBUF+9 location of "open" flag MOV A,M CPI 0 Is file open already? JZ CHK3 No. CALL CRLF Output CRLF. LXI H,OFILE CALL PRINT Print outfile's name. CALL OUST ASC / is open./ (This means we can't write on it.) DB 0 JMP EXIT * CHK3 LXI H,PSBUF+14 location of attributes MOV A,M ANI PWRI Is file protected against writing? JZ GFWD Nope. Everything is okay with the files. CALL CRLF LXI H,OFILE CALL PRINT CALL OUST ASC / is protected./ DB 0 JMP EXIT * * Figure out how much memory we can use, and check * if any of it is bad. * GFWD LHLD EOSP MEMLP MOV A,H CPI 1FH JZ EDIT MOV A,M CMA MOV M,A CMP M JNZ MERR2 CMA MOV M,A DCX H JMP MEMLP * MERR1 PUSH H CALL OUST DW 0A0DH DW 0A0DH ASC "MEMORY ERROR IN FILE AREA" DW 0A0DH ASC "ADDRESS: " DB 0 POP H CALL OUT16 JMP SYSRT * MERR2 MOV A,M INR A TEST IF FF JNZ MERR1 DCX H SHLD EOSP JMP MEMLP * * Read in one argument from CIFILE. * RDARG LXI D,PSBUF MVI A,PSN name scan CALL PSCAN STA DELIM Record last char read. JC PSERR Probably more than 20 chars. RZ . No name found. CPI '<' ALS8 specification coming? JNZ RDRG1 No. CALL CKALS8 Make sure that "A>" follows. JNZ BADSYN Bad syntax. XRA A Clear A. DCR A Reset Z flag. STC . Set carry - indicates ALS8. RET RDRG1 XRA A Reset carry and clear A. DCR A Reset zero flag. RET * * Check if was typed correctly. * CKALS8 CALL IGBLNK Get next non-blank. CPI 'A' Is the "A" there? JZ CKAL1 Yes. How about the ">"? CPI 'a' RNZ Bad. CKAL1 CALL IGBLNK CPI '>' RNZ . Bad. CALL IGBLNK Get delimiter. XRA A Set zero flag - means OK. RET * * Return next non-blank char in CIFILE in A. * IGBLNK LDA CIFILE CALL RB JMP ERROR CPI SPACE JZ IGBLNK STA DELIM Remember last char read. RET * * Copy string pointed to by HL to location pointed to * by DE. Stop after transferring a zero byte or * eleven characters (since no filename can be longer). * NMCOPY MVI C,11 Count chars transferred. NMC1 MOV A,M STAX D INX H We leave HL and DE pointing one past the INX D last byte moved. CPI 0 RZ . DCR C If C hits zero then the 11th char wasn't a 0 JNZ NMC1 MVI A,ERNTL name too long JMP ERROR * LINEND CPI CR Check for end of command. RZ CPI ';' RET * * Error handling for the scanner. If error came from * PSCAN it is in E, otherwise it is in A. The error * printing utility is used to print it out, then we * leave the editor. * PSERR MOV A,E PSCAN error ORA A Set flags to see if we have a field error. JNZ ERROR MVI A,'X' Field error -- give SKIP a fake DELIM. STA DELIM CALL SKIP MVI A,ERNTL Error was "name too long". ERROR STA ERRNUM Put the err wher UXOP can find it. CALL SKIP Get rid of garbage. MVI A,10000000B Indicates that utility should return. LXI H,-1 No extra message. CALL UTIL DB UXOP JMP EXIT an error??? DB -1 not a command ERRNUM DB 0 the error number JMP EXIT * * Skip any leftover characters in CIFILE after an * error has occurred. * SKIP LDA DELIM SK0 CALL LINEND End of line? RZ . Yes. LDA CIFILE CALL RB JMP SK1 eof. STA DELIM JMP SK0 Keep going. SK1 RET * DELIM DB -1 Last char read. PSBUF DS 25 For PSCAN and FINFO.