{ dodaje na pocz¥tku DB " i na koäcu eol" }
PROGRAM ASM_TAS;
USES CRT;
CONST
 TITLE1:ARRAY[1..5] of Char=' DB "';
 TITLE2:ARRAY[1..4] of Char='eol"';
 SPACES:ARRAY[1..70] of Char='                                                                      ';
 EOL:WORD=$0A0D;
VAR
 FASM:FILE;
 FTAS:FILE;
 Color,BYTE1,BYTE2:BYTE;
 CounterCHAR,i,How:integer;

PROCEDURE ADD_SPACES;
 label pomin1;
BEGIN
  IF CounterCHAR>69 THEN goto pomin1;
  i:=70-CounterCHAR;
  BlockWrite(FTAS,SPACES,i);
pomin1:
END;

LABEL skip,start,cont;
BEGIN
  Color:=TextAttr;
  IF PARAMCOUNT<>2 THEN BEGIN
    TextColor(LIGHTRED);
    Writeln('ASM_TAS v1.0');
    Writeln('Convert *.ASM file into *.TAS file');
    Writeln;
    TextColor(YELLOW);
    Writeln('Use:  ASM_TAS  file.asm file.tas');
    Writeln;
    TextColor(Color);Writeln;
    HALT;
  END;
  ASSIGN(FASM,PARAMSTR(1));
  {$I-}
  RESET(FASM,1);
  {$I+}
  IF IORESULT<>0 THEN BEGIN
     TextColor(LIGHTRED);
     Writeln('Error by opening file : ',PARAMSTR(1));
     TextColor(Color);Writeln;
     Halt;
  END;
  ASSIGN(FTAS,PARAMSTR(2));
  {$I-}
  REWRITE(FTAS,1);
  {$I+}
  IF IORESULT<>0 THEN BEGIN
     TextColor(LIGHTRED);
     Writeln('Error by creating file : ',PARAMSTR(2));
     TextColor(Color);Writeln;
     Halt;
  END;

  BlockWrite(FTAS,TITLE1,5);

  REPEAT
start:
  {$I-} BlockRead(FASM,BYTE1,1);
    IF IOResult<>0 Then Begin
      ADD_SPACES;
      BlockWrite(FTAS,TITLE2,6);
      goto skip;
    End;

  BlockRead(FASM,BYTE2,1);{$I+}
    IF IOResult<>0 Then Begin
      BlockWrite(FTAS,BYTE1,1);
      INC(CounterCHAR);
      ADD_SPACES;
      goto skip;
    End;

  IF ((BYTE1=10) AND (BYTE2=13)) OR ((BYTE1=13) AND (BYTE2=10)) THEN Begin
cont:
    ADD_SPACES;
    BlockWrite(FTAS,TITLE2,4);
    BlockWrite(FTAS,EOL,2);
    BlockWrite(FTAS,TITLE1,5);
    CounterCHAR:=0;
    goto start;
  End;

    BlockWrite(FTAS,BYTE1,1);
  IF (BYTE2=13) OR (BYTE2=10) THEN Begin
  {$I-} BlockRead(FASM,BYTE1,1); {$I+}

    IF IOResult<>0 Then Begin
      BlockWrite(FTAS,BYTE2,1);
      CounterCHAR:=CounterCHAR+2;
      ADD_SPACES;
      goto skip;
    End;
    IF BYTE1=BYTE2 THEN Begin
      BlockWrite(FTAS,BYTE2,1);
      BlockWrite(FTAS,BYTE1,1);
      CounterCHAR:=CounterCHAR+3;
    End;
    IF (BYTE2=13) OR (BYTE2=10) THEN Begin
      CounterCHAR:=CounterCHAR+1;
      goto cont;
    End;

  End;

    BlockWrite(FTAS,BYTE2,1);
    CounterCHAR:=CounterCHAR+2;
  UNTIL 0=1;

Skip:
  TextColor(GREEN);
  Writeln('Convert: O.K.');
  TextColor(Color);Writeln;
  Close(FASM);
  Close(FTAS);
END.
