/* ASMCV ASMZ file converter utility to allow files generated by ASMZ to be converted to standard ASCII files with tabs. This program also strips off the line number field of the ASMZ file. Input files should be *.SRC, but need not be. Output file will be named INPUTFILE.Z80 in order to be compatible with ASMB. SYNTAX: A>ASMZCV INFILE.SRC This will accept ASMZ source file 'INFILE.SRC' as input and create 'INFILE.Z80' on same drive. ************************************************************** Revisions: x.0 Pre-release ************************************************************** */ #define version "x.0" /************************************************************* */ #define false 0 #define true 1 #define null 0 #define namesiz 14 #define nbufsiz 19 #define ibufsiz 1024 #define obufsiz 1024 #define defltbufr 0x80 #define noerrors false #define error (-1) #define asmeof 1 #define ctrlz 0x1a #define cr 0x0d #define lf 0x0a #define tab 0x09 #define label 1 #define opcode 2 #define operand 3 #define comment 4 #define spaces 0x80 /************************************************************ variable declarations *************************************************************/ int ibufcnt; /* input buffer byte count */ char *ibufptr, /* input file bufer ptr */ ibuf[ibufsiz]; /* input file buffer */ int obufcnt; /* output buffer byte count */ char *obufptr, /* output file buffer ptr */ obuf[obufsiz]; /* output file bufer */ char infile[nbufsiz]; /* input filename buffer */ int inkey; /* input file key */ char outfile[nbufsiz]; /* output filename buffer */ int outkey; /* output file key */ int temp; int ch; /************************************************************* program start *************************************************************/ main(){ initialize(); run(); exit(); } /* initialize & fetch user comand */ initialize(){ char *cptr; temp = ( *defltbufr) & 0xff; /* save char count */ cptr = defltbufr + 1;/* remove leading spaces */ while ((*cptr == ' ') & (temp > 0)){ temp = temp - 1; cptr++; } if (temp == 0){ nl(); puts("Input file needed."); nl(); exit(); } movmem( cptr, infile, namesiz ); if ( temp > namesiz) temp = namesiz ; infile[ temp ] = null; movmem( infile, outfile, namesiz); /* outfile = infile */ cptr = outfile; /* make outfile 'infile.Z80' */ while ((*cptr != null) & (*cptr != '.') & (*cptr != ' ')){ cptr++ ; } *cptr++ = '.'; *cptr++ = 'Z'; *cptr++ = '8'; *cptr = '0'; if ((inkey = fopen( infile, "r")) == false){ nl(); puts("Input file not found!"); nl(); exit(); } if ((outkey = fopen( outfile, "w")) == false){ nl(); puts("Disk full?"); nl(); exit(); } ibufcnt = 0; /* init buffer vars */ obufcnt = 0; obufptr = obuf; } /* main converter */ run(){ char field, flag; flag = false; field = 0; ch = (fetch() & 0xff); while ((ch > 0) & (ch != asmeof)){ if (field == comment){ if (ch > spaces){ ch = ch - spaces;/* convert to # spaces */ while (ch > 0){ output(' '); ch = ch - 1; } } else output( ch ); } else if ( field == operand ){ if (ch > spaces){ field = comment; output( tab ); output( ';'); } else output( ch ); } else if (field == opcode){ if (ch > (spaces + 4)){ field = comment; output( tab ); output( tab ); output( ';'); } else if (ch > spaces){ field = operand; output( tab ); } else output( ch ); } else if (field == label){ if ((ch == '*') & (flag == false)){ output( ';' ); field = comment; } else if (ch > spaces){ field = opcode; output( ':' ); output( tab ); } else{ output( ch ); flag = true; } } else if (field == 0){ if (ch > spaces){ if (ch > (spaces + 1)){ field = opcode; output( tab ); } else field = label; } } if (ch == cr){ output( lf ); flag = false; field = 0; } ch = (fetch() & 0xff); } output( ctrlz); finishup(); } /* functions */ nl(){ putchar(13); } fetch(){ int status; if (ibufcnt == 0){ ibufptr = ibuf; status = noerrors; while ((ibufcnt < ibufsiz) & (status >= noerrors)){ status = cget( inkey); if ( status >= 0){ *ibufptr++ = status; ibufcnt++; } else{ *ibufptr++ = 0;/* set eof flag */ ibufcnt++; } } ibufptr = ibuf; } ibufcnt--; return *ibufptr++; } output(chr) char chr;{ int status; if (obufcnt >= obufsiz){ obufcnt = obufsiz; obufptr = obuf; while (obufcnt > 0){ status = cput(*obufptr++, outkey); if (status < 0){ nl(); puts("Disk full!"); nl(); exit; } obufcnt--; } obufcnt = 0; obufptr = obuf; } *obufptr++ = chr; obufcnt++; } finishup(){ int status; obufptr = obuf; while (obufcnt > 0){ status = cput( *obufptr++, outkey); if (status < 0){ nl(); puts("Disk full on last write!"); nl(); break; } obufcnt--; } status = fclose( inkey); if (status < 0){ nl(); puts("Cannot close input file!"); nl(); } status = fclose( outkey ); if (status < 0){ nl(); puts("Cannot close output file!"); nl(); exit(); } } #include cz80.lib #include cutil.lib