[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Activate an SYS program with a document attached
- Subject: Re: Activate an SYS program with a document attached
- From: dempson@atlantis.actrix.gen.nz (David Empson)
- Date: Sat, 7 Jan 1995 09:48:30 GMT
- Newsgroups: comp.sys.apple2
- Organization: Actrix - New Zealand Internet Service Providers
- References: <D20wzt.38D@eng_ser1.erg.cuhk.hk>
- Sender: news@actrix.gen.nz (News Administrator)
In article <D20wzt.38D@eng_ser1.erg.cuhk.hk>,
Ngai Chi Ho <chngai@cs.cuhk.hk> wrote:
> In BASIC, we can only use "-" to run SYS programs, and thus can't call
> it to open one of its document. But I heard from someone that there is
> a method to run an SYS program with a filename to be opened as its
> argument.
Yes, there is a way to do this, but it only works with SYS programs
that support this feature. BASIC.SYSTEM is one of them. Others that
come to mind are Talk Is Cheap (specifying a script to run
automatically) and AEPC.SYSTEM (the PC Transporter control program -
you can give it an MS-DOS command to be executed, which is picked up
by the LAUNCHER program, which should be in the AUTOEXEC.BAT file).
AppleWorks does not support this feature.
To check if a program does support it, look at the first few bytes of
the SYS file. It must start with a JMP instruction (three bytes, $4C
xx xx) followed by two $EE bytes. Following this is a byte indicating
the size of the pathname buffer which follows, and the buffer itself,
which is supposed to hold a string with length byte.
You can load a SYS file in BASIC using the command:
BLOAD filename,TSYS,A$2000
For example, BASIC.SYSTEM starts as follows:
2000- 4C xx xx EE EE 41 07 S T A R T U P (followed by 57 zero bytes)
^^^^^^^^ ^^^^^ ^^ ^^ ^^^^^^^^^^^^^
| | | | Default pathname
| | | Length of default pathname
| | Size of pathname buffer
| Signature bytes
Jump instruction
In the case of BASIC.SYSTEM, you can get it to launch another BASIC
program at startup time, by replacing the length byte and pathname
with the pathname of the desired program.
This cannot be done directly from BASIC. The "-" command will load a
SYS file and jump to it, but doesn't provide you with any way to check
for and/or change the default pathname.
You might be able to do it with a BASIC program, but it won't be easy,
because LOMEM will have to be set high enough to protect your
variables from the loaded SYS file. The steps would be:
1. BLOAD the SYS file, using the command above.
2. Use PEEK to check that location 8192 contains 76 ($4C) and locations
8195 and 8196 both contain 238 ($EE). The pathname buffer size can
then be PEEKed from 8197, and the replacement pathname POKEd starting
at 8198 with the length byte.
3. Start the SYS file using CALL 8192.
The same principle applies when launching a SYS file from a machine
code program. (In fact, this is exactly how a machine code program
must launch all SYS files, except that step 2 can be skipped if the
pathname does not need to be set.)
ProDOS calls may be used to load the SYS file (OPEN, READ and CLOSE)
at $2000, after adjusting the bitmap to allow all of main memory to be
used. Assuming you don't want to return to the BASIC program, it
would be a simple task to write a small machine language routine that
ran at $0300, which was passed the pathname of the SYS file and the
startup pathname, removed BASIC.SYSTEM from memory, loaded the SYS
file, patched the locations as above, then did a JMP $2000 to start
the program.
It could even be an & routine, if you wanted to go to a little
trouble.
Locations $1C00-$1FFF could be used as the file buffer for the ProDOS
OPEN command.
--
David Empson
dempson@actrix.gen.nz
Snail mail: P.O. Box 27-103, Wellington, New Zealand