home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
No Fragments Archive 10: Diskmags
/
nf_archive_10.iso
/
MAGS
/
ST_USER
/
1990
/
USERDC90.MSA
/
TEXT_CLINIC.TXT
< prev
next >
Wrap
Text File
|
1990-10-17
|
11KB
|
236 lines
In Mathew Lodge's Clinic this month the rather strange-sounding Atari Cookie
Jar is opened, dynamic C arrays are created and FATs are queried.
This month's clinic kicks off with a question from Richard Wheeldon of
Stoke-on-Trent:
"Can anybody explain how to read the File Allocation Table (FAT) entries of an
ST disk? I do know that each entry is 12-bits (on a floppy at least), but how
are the three 4-bit nibbles arranged? Once I've sorted out the order of the
nibbles, what does the number mean?
Finally, does all this apply unchanged to hard disks? - I've got a 20MB drive
running under TOS 1.4"
Cookie Monster
==============
In the Clinic on User disk 55 David Hoggan and I wanted to know what the Atari
"Cookie Jar" was. Kent Johansson from Sweden has written in with an excellent,
comprehensive guide to all things cookie.
"The 'cookie' is a nice try from Atari to make programs more compatible with
various machines. If you follow the 'rules' and start using the 'cookie' in
your own programs, it is more likely they will run on the TT (and future ST
computers) as well. The Cookie Jar features information about the system that
might be useful while writing programs, and you can also insert your own
'cookies' using TSR-programs.
The address $5A0 contains zero on all ST computers except for the STE/TT where
it contains the pointer to the Cookie Jar. Below is a system variable that you
can add to your Concise/Internals manual, on the system variables page. It is
an official system variable from Atari that you can trust!
_p_cookies $5A0 L Cookie Jar pointer
Always check $5A0 when using the Cookie Jar because its location varies on
different ST models. A program that allocates memory (such as a RAM disk) can
force the cookie to be moved to another location since it's installed in RAM
and not in ROM.
The 'Cookie' is consists of two pairs of longwords. Always remember to read
them two and two, like this (assuming address of the cookie jar was in a0):
MOVE.L (A0)+,D0
MOVE.L (A0)+,D1
First you have an ID number that identifies the cookie, this number is unique
for each cookie. When you are searching for a specific cookie you must stop
when you find an empty longword instead of the ID longword. The existing
"official" cookies are: _CPU,_VDO,_MCH,_SND and _SWI (all official Atari
cookies start with the underscore character)
This is what you can find in Atari's basic Cookie Jar:
The _CPU cookie features information about the CPU fitted in you machine. The
lowest byte contains any of these values: 00, 10, 20, 30 or even 40 (I want
one!) This value is written in decimal form. For instance, if you should find
the value 30 here it's most likely that you have a TT (or an '030 board) since
that would mean that you have a 68030 in your machine.
The _VDO cookie shows what kind of shifter you have. Look at this table (But
note that the value is found in the high word!):
Value Shifter type
----------------------
0 A plain normal ST shifter
1 The improved ST shifter that is found in the STE.
2 TT Graphic chip.
The _SND cookie describes what sound hardware you have. It only describes what
internal sound hardware you have. External hardware such as FM-Melody Maker or
ST-Replay/AVR should not be described here. If they want to use a cookie they
have to install one of their own. The value here is on bit level, and it's
found in the lowest byte.
Bit Sound hardware:
------------------------
0 Normal ST sound chip (Yamaha/GI)
1 STE/TT Hardware DMA stereo chip.
The _MCH cookie describes the system in general, information you can find at
other locations but it's easier to read this one. In this one (just as in the
_VDO cookie) the important information is found in the higher word, the lower
word is reserved for smaller "changes" such as special things that might pop-up
in the computers in the future.
Value Hardware:
------------------
0 Plain ST (520,1040)
1 Mega ST
2 STE
3 TT
Finally, there is a last cookie called _SWI where the value of the
configuration switches can be found. Only STE and TT computers have those
switches, and I don't know what those switches do. I found the value $FF in the
lower word on my STE.
On TT's you can also find a cookie called _FRB, this means Fast Ram Buffers and
it is used with the ACSI DMA controller. The longword points to a 64kb buffer
used by the ACSI DMA. If it is zero, no buffers are installed and if one
doesn't find it, there is no FRB at all (not to be found in ST/STE).
When you check the 'cookies' for some information it would be nice to find the
end somewhere. That's why this 'empty longword' exists. The longword after the
empty one (remember, always read pairs of longwords) holds the number of
'cookies' in the system. If you find an 8 here (like I did on my STE) it means
that 8 slots are reserved (allocated) for the jar. On a plain STE, five are
used by cookies and one is used by the 'empty longword'. That leaves two, which
come after the empty longword.
Let's say that I decided to make a external utility - a sound extension,
featuring a 6 channel stereo chip. After having written the software I want to
tell other programs that such an extension was connected to the ST. I use the
Cookie Jar! Of course I would also hope that the game making firms would read
off the Jar and check if my great thing was present and then use it. How would
I do this?
First I must check if a Cookie Jar exists by reading of $5A0. If it doesn't
exist ($5A0 is zero) then I need to install a Cookie Jar.
Let's assume that the Jar does exist and let's say I got the address $980 from
$5A0. As you would know by now the jar have some "locked" information and if no
one else has mucked around with it then I should have two slots free, but I'll
describe how to use the jar whether there is any free space or not.
As we scanned through the jar we (hopefully) came across the 'empty longword'
and as we did that we also found a value saying how many slots that have been
reserved. (The number of slots multiplied with eight gives us the size of the
jar in bytes. I.e. the normal jar is 64 bytes). And as I was only going to add
one more slot I might write code like this:
MOVE.W #32,-(SP) ; SET SUPERVISOR
TRAP #1
ADDQ #2,SP
MOVE.L $5A0.W,A0 ; GET START ADDRESS OF THE JAR
MOVEQ #0,D7 ; CLEAR "OUR" COUNTER
NO: MOVE.L (A0)+,D0 ; GET INFORMATION
MOVE.L (A0)+,D1 ; IN LONGWORD PAIRS!
ADDQ #1,D7 ; INCREASE OUR JAR COUNTER
TST D0 ; CHECK IF IT'S THE EMPTY LONGWORD
BNE NO ; IF NOT, CONTINUE
CMP.L D7,D1 ; CHECK IF THE JAR IS FULL
BEQ FULLJAR
MOVE.L #"_STU",-8(A0) ; IF THERE IS SPACE, INSERT OUR
MOVE.L #56,-4(A0) ; NEW JAR, OVER THE OLD "EMPTY" ONE
MOVE.L D1,4(A0) ; AND MAKE A NEW EMPTY ONE WITH
; DATA ABOUT THE SIZE OF THE JAR.
FULLJAR CLR.W -(SP) ; BYE!
TRAP #1
If the jar is full, then you must make a new bigger jar:
* Check how big the old one was.
* Allocate memory for the new one. Size = Old_size + 8_new_slots.
* Copy the old one to the new spot.
* Make my new cookie.
* Write a new "empty longword".
* Overwrite the old address in $5A0 with the new one.
I recommend that you reserve enough space for 8 cookies at a time. If you only
reserve space for one cookie at a time the next program (that uses the cookie)
would have to allocate more memory and your poor ST will end up with a nice
fragmented memory."
Dynamic Arrays
==============
The array is one of the basic building blocks of almost every computer
language, but in most cases the size of the array is fixed - you can't change
its size while the program is running. This month, John Merrill presents a
technique for dynamically changing the size of an array in your 'C' programs.
John's method takes advantage of the fact that there is no array bound checking
in C at run-time:
"For number crunching, or when a large number of huge arrays may be needed
fixed-sized arrays are not an ideal solution. It would be nice if there was a
way in which arrays could be created and destroyed at will.
The functions below - vector() and free_vector() rely on the fact that that an
array is simply a pointer. For example in the declaration 'int a[6]', a is
simply a pointer to the memory containing the array. Suppose that the pointer
'int *p_aray' is declared in the same function, then the statement 'p_aray=a'
is perfectly legal and the elements 'p_aray[0]' to 'p_aray[5]' all exist.
The trick is to declare just the pointer in the function requiring the array
and when the array is needed, vector() is called. vector() takes one parameter,
the size of the array, and returns a pointer to some allocated memory for the
array. The original version used 'malloc(nl*sizeof(int))' but in my book this
is identical to 'calloc(nl, sizeof(int)'. The array can then be used just like
any other (although remember its name is now a pointer variable) and exists
until it's name is passed to free_vector() which releases the allocated
memory.
The example below shows how to use vector() and free_vector(). Note that they
only work with integer type arrays. However it is a trivial matter to convert
them to types float, double or short. Further information can be found in
'Numerical Recipes in C' by William H. Press, Brian P. Flannery, Saul A.
Teukolsky and Wiliam T. Vetterling."
Winding down
============
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