' DEMO-program to convert STAD-pictures
'
DIM buffer_stad|(32507)
DIM buffer_32k|(32000)
INLINE fromstad%,204
INLINE tostad%,380
'
CLS
PRINT "If you select a compressed STAD-picture *.PAC the file will be loaded,"
PRINT "uncompressed an saved as an unpacked 32k-picture *.PIC (screenformat)..."
PRINT "(and vice versa)"
'
FILESELECT "C:\*.P?C","",file$
IF file$=""
  QUIT (0)
ENDIF
IF NOT EXIST(file$)
  PRINT "File ";file$;" doen't exists..."
  QUIT (-33)
ENDIF
'
IF RIGHT$(file$,4)=".PAC"
  BLOAD file$,V:buffer_stad|(0)
  IF C:fromstad%(L:V:buffer_stad|(0),L:V:buffer_32k|(0))=1
    PRINT "Error: this is not a packed STAD-picture"
    QUIT (1)
  ENDIF
  BMOVE V:buffer_32k|(0),XBIOS(2),32000
  file$=LEFT$(file$,LEN(file$)-4)+".PIC"
  IF EXIST(file$)
    ALERT 2," Output-file | already exists.... ",2," Write | Cancel ",button%
    IF button%=2
      QUIT (2)
    ENDIF
  ENDIF
  BSAVE file$,V:buffer_32k|(0),32000
ELSE IF RIGHT$(file$,4)=".PIC"
  BLOAD file$,V:buffer_32k|(0)
  BMOVE V:buffer_32k|(0),XBIOS(2),32000
  length%=C:tostad%(L:V:buffer_32k|(0),L:V:buffer_stad|(0))
  file$=LEFT$(file$,LEN(file$)-4)+".PAC"
  IF EXIST(file$)
    ALERT 2," Output-file | already exists.... ",2," Write | Cancel ",button%
    IF button%=2
      QUIT (2)
    ENDIF
  ENDIF
  BSAVE file$,V:buffer_stad|(0),length%
ENDIF
END
