home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
No Fragments Archive 10: Diskmags
/
nf_archive_10.iso
/
MAGS
/
ST_USER
/
1990
/
USERNV90.MSA
/
TEXT_CLINIC.DOC
< prev
next >
Wrap
Text File
|
1990-05-24
|
10KB
|
243 lines
Stuck with a stick ST problem? Mathew Lodge and his readers can sort it out -
from tough GEM and C troubles to files from BASIC. This month, C programmers
are put right, GEM is queried, and the new Atari file selector is explained.
Mind Your Handles
=================
David Mycroft from Cosham, Portsmouth, and Roland Givan of Brentwood in Essex
both reply to Simon May, who, in the first RunTime clinic, had problems with C
standard file handles.
"Simon's problem of not being able to send text to the printer with fprintf is
due to confusion over 'standard handles' on the ST.
All input / output under GEMDOS / TOS uses handles to refer to the files /
devices that are to be used. Handles are returned by Fopen call, but a number
of standard handles are considered to be open before your program runs. These
are called stdin, stdout, stderr, stdprn and stdaux. GEMDOS / TOS doesn't
really support a stderr device, but see later. Sozobon uses Dale Schumacer's
Dlibs 1.2 package for runtime support, and the stdxxx handles are defined in
that package. This table hopefully explains:
File/Device GEMDOS GULAM DLIBS
--------------------------------------------------
Console input (stdin) 0 0 0
Console output (stdout) 1 1 1
Error (stderr) - 2 -1
RS-232 port (stdaux) 2 4 3
Printer (stdprn) 3 3 2
We can see that some disagreement exists between the various elements that are
involved in output to a device. UNIX defines standard handle 2 to refer to the
standard error (stderr) device, and Gulam, being a UNIX lookalike, redirects
handle 2 to the console as part of its initialisation.
Hence, when Simon uses the Dlibs fprintf to output to stdprn (for which Dlibs
uses handle 2) and runs under Gulam, the output gets redirected to the screen.
However, when he runs his program direct from the Desktop, GEMDOS handle 2 is
used which unfortunately refers to the AUX: device (RS-232 port). Assuming that
Simon has no device attached here, and that the default handshake protocol for
the serial port (no handshake) is in effect, the ST will just pour his output
down a black hole. This is why he says his output just disappears."
Roland suggested inserting the following line just after you include stdio:
#include stdprn stdaux
Sozobon will issue a warning about redefining an already defined symbol, but
your program will now work.
Simon's other problem was auto-starting Gulam on a standard STFM. Lucky STE
owners don't have this problem, nor do those with new STFMs that have TOS 1.4
('Rainbow TOS') fitted. The solutions list, in decreasing order of cost and
desirability, is therefore
i) Buy an STE
ii) Fit TOS 1.4 ROMs, available from Atari UK Spares Dept. and Ladbroke
Computing at around £40 (fit them yourself - I did), or have them fitted
by Ladbroke for £50, or by Gasteiner Technologies at £99.
iii) Buy Headstart from Codehead software
Change Warning
==============
The next query comes from Michael Conrad of Bushey, Herts, who is writing a
desk accessory, but having trouble with resolution changes.
"My accessory re-directs some TOS vectors to my own code, in order to provide a
keyboard macro facility. When my own handlers have been called, they execute
the previous routine that was pointed to by the vector I've redirected. In this
way, my accessory is fully integrated with TOS.
However, when the user changes resolution, GEM is reloaded, and my accessory
along with it. The TOS vectors I use now point to garbage, since the accessory
code has, in effect, moved. When my accessory re-installs itself, the handlers
it installs attempt to execute this garbage after they have run, because this
is what is contained in the appropriate vectors. The result is that as soon as
the user presses a key, the machine crashes.
Is there any way to detect a resolution change before it happens? At the
moment, the user has to remember to deinstall my accessory before changing
resolution."
A difficult problem, but one that I'm sure someone has encountered and
surmounted before. Suggestions to the address given at the end of the column.
Gem Patching
============
Conrad Bessant of Carlton, Bedfordshire, has a query about replacement file
selectors and the like.
"There are many programs around in the public domain and elsewhere, which alter
the way GEM works. Replacement file selectors are a typical example. I would
like to alter the Desktop's Show/Print/Cancel dialogue box, displayed when the
user clicks on a non-executable file. There must obviously be some way that
things like calls to the file selector can be detected or patched over. My
question is: How is this done, and is it possible to get the GEM Desktop to
call a routine of mine written in C instead of the Show/Print/Cancel box?"
Mix 'n Match
============
Waikei Chung wanted to use assembler code in his C programs, but wondered about
how to do it. Jim Rolfe of the 13th Signal Regiment, BFPO 42 has come to the
rescue, as has Kevin Watson of West Drayton, Middlesex.
Kevin notes that Waikei will require a separate assembler package, and suggests
that he upgrade to Lattice 5, which includes an assembler in the package. Jim
explains how to call the assembler routine:
"The simplest way to access an assembly routine from a C program is to call it
as a normal function. For example:
#include <stdio.h>
main()
{
printf("Now is the time\n");
line_2(); /* Assembly language module */
printf("to come to the aid of their party");
}
line_2 is the name of our separately written machine code routine which prints
the second line of the famous quote.
In simple terms, the function call acts like a subroutine branch in assembler.
The address of the next instruction is placed on the stack, and the program
branches to the label line_2. Armed with this knowledge we can now go ahead and
write our assembly module.
line_2: move.l #text,-(sp) ;Put address of text onto stack
move.w #9,-(sp) ;GEMDOS function 9 (Cconws)
trap #1 ;Call GEMDOS
addq.l #6,sp ;Repair stack
rts ;Return to C program
text: dc.b "for all good men",13,10,0
end
This module is then assembled using the +L directive, producing linkable code.
You can now use either the Lattice or Devpak linker to link your modules into
an executable file.
Parameters are also passed on the stack. Consider the following C extract:
int a,b
a = 5; b = 8;
add (a,b); /* Assembly routine */
C will move the value of a and b onto the stack followed by the return address
before branching to the label add. The add module could be:
add: move.w 4(sp),d1 ; Value of b
move.w 6(sp),d2 ; Value of a
add d1,d2 ; Add them together
rts ; Return to calling program
end "
However, Kevin commented that in Lattice 3, all parameters are placed on the
stack as 32-bit values, regardless of their size in the C program, and that the
return value must be placed in register d0. This is also my experience, and it
means that the add routine above should actually read
add: move.l 4(sp),d1 ; Value of b (extended to 32 bits)
move.l 8(sp),d0 ; Value of a (ditto)
add.l d1,d0 ; Add, return result in d0
rts ; Return to C program
end
Name It In One
==============
Now that the latest revisions (versions 1.4, 1.6 1.62 and 3.0) of the ST's
operating system, TOS, are more widely available, I'm starting an occasional
series of articles within the clinic on how to use the new features added by
Atari. If you use GFA Basic, then you'll find much of these features present in
the latest version, but I hope everyone else will find these snippets useful.
This month I'll cover the new file selector, which while being exactly the same
size as its predecessors, has many more features. One of these is that the
programmer can change the title across the top from FILE SELECTOR to whatever
he likes, up to a maximum length of thirty characters.
This is supported by a new AES function called FSEL_EXINPUT, with the following
parameters:
control(0) = 91
control(1) = 0
control(2) = 2
control(3) = 3
control(4) = 0
int_out(0) = fs_ireturn -- 0 = an error occurred, otherwise OK
int_out(1) = fs_iexbutton -- 0 = Cancel clicked, 1 = OK clicked
addr_in(0) = fs_iinpath -- Pointer to string holding initial path
addr_in(1) = fs_innsel -- Pointer to string holding initial file name
addr_in(2) = fs_label -- Pointer to string that will be displayed
across the top of the File Selector box
The appropriate C binding would be:
fs_ireturn = fsel_exinput(fs_iinpath,fs_innsel,&fs_iexbutton,fs_label);
That's All Folks
================
Keep the letters coming - especially the solutions and comments on other
people's problems and ideas, but don't forget that the clinic depends on your
problems too! Remember to include your full name (or title, if preferred), and
give your phone number if possible.
If you have a listing longer than about 25 lines then please include it on a
disk - I don't have time to type long listings in. Putting the text of your
letter on disk is doubly helpful - First Word or First Word Plus format if
possible, but straight ASCII is fine. Whilst on the subject of file formats,
note that I can't decipher tokenised Fast Basic .BSC files - please send an
ASCII version.
If you are sending a complete program, then I also like to see it running
before putting it into the column, so please include a double-
clickable version of your program if at all possible. If you want the disk
and/or listing back, also include a stamped addressed envelope. No SAE, no
disk.
Mathew Lodge
"Programmer's Clinic"
"Maen Melin"
Holmes Chapel Road
Lach Dennis
Northwich
Cheshire
CW9 7SZ