[comp.sys.cbm] Changing sequential files to program files

msf@rayssd.UUCP (01/26/87)

Does anyone out there know how I can convert a sequential file (which is how
my terminal program downloads) into a program file (so I can load and run it)
I've tried to look at Track 18/Block 1 etc, but can't seem to get the hang
of it.  Thanks in advance!
-- 
Michael Frank     { allegra, brunix, cci632, gatech ihnp4, } 
                  { linus, uriecl, mirror, purbos, raybed2 }  ...!rayssd!msf
These opinions are mine, Mine MINE! And do not reflect anybody else's opionions.
                              So There.

grwalter@watmath.UUCP (01/27/87)

In article <592@rayssd.RAY.COM> msf@rayssd.RAY.COM (Michael S. Frank) writes:
>Does anyone out there know how I can convert a sequential file (which is how
>my terminal program downloads) into a program file (so I can load and run it)
>I've tried to look at Track 18/Block 1 etc, but can't seem to get the hang
>of it.  Thanks in advance!

Rather than re-invent the wheel, i will re-post something that came over
the net last summer, because other people might find it of interest.

>From: fred@cbmvax.cbm.UUCP (Fred Bowen)
Newsgroups: net.micro.cbm
Subject: Re: Tokenize text files.
Date: 20 Aug 86 19:38:39 GMT

The lastest issue of Transactor (Nov 86) contains a letter describing how
to do this (as well as execute command files!) via a one liner.  This little
ditty thanks to Frank DiGioia, Stone Mountain, GA:

	OPEN 2,8,2,"file,S,R": POKE 812,73: POKE 781,2: SYS 65478

Just hit RESTORE when it finishes, or end file data with the following (note
NO line number):

	CLOSE 2: POKE 812,47: SYS 65484

This will also work on a 128, if you do the following:

	OPEN 2,8,2,"file,S,R": POKE DEC("32C"),DEC("3C"): SYS DEC("FFC6"),,2
	...
	CLOSE 2: POKE DEC("32C"),DEC("22")

mwilson@crash.UUCP (01/27/87)

In article <592@rayssd.RAY.COM> msf@rayssd.RAY.COM (Michael S. Frank) writes:

>Does anyone out there know how I can convert a sequential file (which is how
>my terminal program downloads) into a program file (so I can load and run it)
>I've tried to look at Track 18/Block 1 etc, but can't seem to get the hang
>of it.  Thanks in advance!

     If the file actually contains a program in *tokenized* form, it
is fairly easy to change the filetype to PRG.  It's not 18,1 that you have
to change, though.  What you have to do is change the first byte in the
directory entry for the file.  A SEQ file will have $81 here.  Change this
to $82, and you have a PRG file.

     If the SEQ file does *not* contain a tokenized program, then you have
to use a different approach.  It involves re-directing BASIC's input
vector to the open disk file.  Sorry, but I can't tell you how it's done...
I no longer have the equipment.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Marc Wilson

     ARPA: ...!crash!mwilson@nosc                  ( preferred )
           ...!crash!pnet01!pro-sol!mwilson@nosc

     UUCP: [ akgua | hp-sdd!hplabs | sdcsvax | nosc ]!crash!mwilson
	   mwilson@crash.CTS.COM
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

adam@utcs.UUCP (01/28/87)

In article <592@rayssd.RAY.COM> msf@rayssd.UUCP writes:
>Does anyone out there know how I can convert a sequential file (which is how
>my terminal program downloads) into a program file (so I can load and run it)
>I've tried to look at Track 18/Block 1 etc, but can't seem to get the hang
>of it.  Thanks in advance!

     If you want to avoid using a disk editor (such as the one that comes with
the FASTLOAD cartrige) you can simply copy the seq file into a prg file on the
same disk.  A basic program that will let you do this follows in this article,
but it's being typed from the top of my head (so it'll probably have bugz :-)

     If you do want the faster way (using a disk editor) there are a few things
about the directory blocks that will be helpfull.
	- The starting block is Track 18 Sector 1 (1541, 4040, 2031, ...)
	- The records that represent the files are 32 bytes long
	- the break down is as follows...
	     BYTE   		DESCRIPTION
	      0-1 	pointer to the next track/sector (1st file only)
	      2 	File type (0 - Scratched files)
				  (1 - SEQ files)    Note: these values
				  (2 - PRG files)	are OR'ed with
				  (3 - USR files)	$80 when properly
				  (4 - REL files)	closed.
	      3-4	start of file Track/Sector
	      5-20	File name (padded with chr$(160))
				.
				.
				.

Therefor if you want to change the second file to a program file you will
want to change byte 34 to $82 from $81.

0 rem "Adam R. Iles 870127 -- Bare bones seq to prg
10 open 1,8,8,"seq file,s,r": open 2,8,9,"prg file,p,w"
20 for s=0 to 1: get#1,a$: s=st: if a$="" then a$=z$ : rem when st>0 last byte
30 print#2,a$;:next
40 close 1: close 2


-- 
    
        Any opinions stated above may, or may not, refect those
        of any sane person living, dead, or just sleeping.

       Adam R. Iles:
                ...{decvax,ihnp4,utcsri,{allegra,linus}!utzoo}!utcs!adam

adam@utcs.UUCP (01/28/87)

      Sorry about the second posting, but sure enough I found a bug in the
little basic program in the preceding article (see I was right 8-).  The
second line should read:

10 open 1,8,8,"seq file,s,r": open 2,8,9,"prg file,p,w": z$=chr$(0)

-- 
    
        Any opinions stated above may, or may not, refect those
        of any sane person living, dead, or just sleeping.

       Adam R. Iles:
                ...{decvax,ihnp4,utcsri,{allegra,linus}!utzoo}!utcs!adam

hedley@cbmvax.UUCP (01/28/87)

In article <592@rayssd.RAY.COM> msf@rayssd.RAY.COM (Michael S. Frank) writes:
>Does anyone out there know how I can convert a sequential file (which is how
>my terminal program downloads) into a program file (so I can load and run it)
>I've tried to look at Track 18/Block 1 etc, but can't seem to get the hang
>of it.

A program file is similar to a sequential type file. The difference is
that the first two bytes in a program file contain the 16 bit load
address of the file. This determines where in memory the file will be
loaded if the ,1 option is used in the LOAD command,        

	LOAD "FILENAME",8,1

Of course, there is also a byte in the directory entry for the file
which indicates the filetype. See the 15xx users manual for details on
directory structure.

The point is that you cannot easily patch the disk because you need to
insert two bytes at the start of the file which will cause the rest of
bytes to shift back. Therefore you might consider using a short basic 
program that goes sort of like this:

	10 OPEN 8,8,8,"NEWPROGFILE,P,W" 
	20 OPEN 9,8,9,"OLDSEQFILE,S,R" 
	30 PRINT#8,CHR$(LOADADDRESSLOW)+CHR$(LOADADDRESSHIGH);
	40 GET#9,A$ : S=ST : PRINT#8,A$; : IF S=0 THEN 40
	50 CLOSE 8 : CLOSE 9

This is untested, and needs some interpretaion to fit your needs.
Just becareful not to forget the semicolons at the end of your print#
statements. You also should add error channel checking after the opens
and closes to verify that the program runs properly.

Hedley