<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Wed, 03 Jan 2001 19:39:44 -0000
From   : "Tom Seddon" <T.W.Seddon@...>
Subject: Re: Determing file type

There isn't really a good way to determine this, at least not 100% reliably.
BASIC detects whether a program is bad or not by scanning through it
linearly, it seems; from memory, each BASIC line starts with 0D, then the
length, then the line. The last 'line' (which is just a marker) is 0D FF.
For exact values just *DUMP a BASIC file and examine by eye. There is an
advanced BASIC user guide with this sort of info in, including entry points
for BASIC [12] -- this might be at the BBC documentatino project, though
I've not checked.

[As a sidenote BASIC seems to set TOP based on this scan. It seems it starts
TOP at PAGE and bumps it as it finds each valid line. If it never finds the
0DFF the program ends up as a Bad one. If a program is a Bad Program, you
can sometimes save some of it by !TOP=&FF0D. But, if the corruption is just
a few bytes, this will lose everything after the corrupted area; sometimes
it is better to *SAVE from PAGE to HIMEM and look at that.]

On the BBC BASICs I've seen, SAVEing a file gives it a load address of PAGE
(whatever that was on the system it was saved on) and an execution address
of FFFF801F (BASIC 1) or FFFF8023 (BASIC 2). As with the exec address the
laod addrses has its high bits set so it is laoded into the host processor.
But, you can manually *SAVE a BASIC program so that its exec & load
addresses are different, although I don't suppose many people did/do this.

Either of the two would work, I suppose, though clearly there's always giong
to be cases where the above won't work. I guess scanning assuming the file
is BASIC and deciding it's a binary if the scan doesn't work would be the
best bet.

--
--Tom
this space filled with | this space not filled with this space filled
this intentionally     | with this intentionally unintentionally


> -----Original Message-----
> From: owner-bbc-micro@...         
> [mailto:owner-bbc-micro@...         ]On Behalf Of Thomas Harte
> Sent: 31 December 2000 17:10
> To: List, BBC
> Subject: [BBC-Micro] Determing file type
>
>
> Is there any way, given the full information about a file (including the
> file itself) to determine whether, for example, it is a valid BASIC save?
>
> Specifically, I want to implement 'automatic loading' in my Electron
> emulator, but when it comes to tapes they are split between those that
> function correctly on a 'CHAIN""' and those (the minority) that
> function on
> a '*RUN""'. Locked files can instantly be put into the second
> category, but
> for the rest I can't seem to find a rule. It seems to me the difference is
> simply which games have BASIC loaders and which have machine code loaders
> though, so can anyone help?
>
> I suppose a related question is - how does BASIC decide if a program is a
> 'Bad Program'?
>
> -Thomas
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>