Date : Thu, 04 Jan 2001 11:41:48 +0000
From : jgh@... (Jonathan Graham Harston)
Subject: Determing file type
Thomas Harte <t.harte@...> wrote:
> 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?
Osfile 5 returns load address, exec address, length and attributes.
> 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
Are, you mean you want to examine the contents of a file to see what is
likely to have saved it, and so what should load it. After all, you can
save a Basic program and give it whatever load and execution addresses you
want as Basic LOADs files to the address it supplies itself (PAGE).
What I tend to use as a quick way of seeing if a file is *not* a Basic
program is to look at the first byte. A valid Basic program will always
start with a <CR> (&0D) byte, so if it is not there you can confidently
reject it as not being Basic. Note that this does not guarantee that it
*is* Basic. See previous comments and cats and dogs and legs. Any old
data file could happen to start with a <CR>, but not be a Basic program.
> I suppose a related question is - how does BASIC decide if a program is
> a 'Bad Program'?
It goes through memory, starting at PAGE doing the following:
.FindTOP
TOP=PAGE
.~loop
IF ?ptr<>13 THEN Bad_Program
IF ptr?1=&FF THEN TOP=ptr+2; Exit
ptr=ptr+ptr?3
GOTO ~loop
Essentially, it goes through the program checking that the line length
pointers point to a <CR>, ending when no <CR> is pointed to, or an &FF
endmarker is found. Note that BBCBasic(65) actually checks for any byte
>&7F as an endmarker, which limits the maximum line number to 32767, but
BBCBasic32,80,86,ARM and others check for &FF, so allowing line numbers up
to 65279.
--
J.G.Harston (JGH BBC PD Library) 70 Camm Street, Walkley, SHEFFIELD S6 3TR
jgh@... - Running on BBCs & Masters with SJ MDFS FileServer
Z80+6502/CoPro+Tubes/Econet+SJ - - - - - - - http://www.mdfs.net/User/JGH/
Et In Arcadia Ego