Amiga Computing - Commodore Is Awesome
Amiga Computing - Commodore Is Awesome
Amiga Computing - Commodore Is Awesome
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Paul Overac delves<br />
beneath the surface<br />
of the <strong>Amiga</strong>'s<br />
program scatter<br />
coding routines<br />
Ai<br />
taking a look at the routines that ore used<br />
0 ver to lood the next and few run issues <strong>Amiga</strong> I am programs. going to The be<br />
illOrce•<br />
to - files used to store an executable program on disk,<br />
• in other words the sacaled Ain igaDOS 'Load Files'.<br />
A load file consists of a number of units known as<br />
sta<br />
'hunks' which, amongst other things, contain program<br />
code, rtin static data such as graphics and text, and<br />
details g of any uninitialised space needed by the pro-<br />
ppm. oWhen<br />
a user runs such a program, either from<br />
ithe Workbench n or by typing its name at a Shel win-<br />
t<br />
dow, on <strong>Amiga</strong>DOS loading routine is brought into<br />
reion.<br />
f<br />
The first thing that happens is that a header block<br />
ois<br />
read and the space for a hunk table, used during<br />
r the loading operations, is alocated Immediately after<br />
tesis,<br />
appropriate amounts of memory for the various<br />
hcode,<br />
data and bss luninihalised spacer hunks present<br />
in the load file ore alocated, with the hunk con<br />
e<br />
tnts being read into the ac<br />
s<br />
qBecause<br />
separate memory alocations for the various<br />
e<br />
uired hunks are made, the hunk information basicaly just<br />
dgels loaded i into any suitable memory area Mot is<br />
m e m o r y<br />
scm:viable<br />
(with the loading routine performing any<br />
b l o c k s .<br />
ccenchee<br />
address relocation calculations and creating<br />
My segment code links that may be required(<br />
u<br />
Pogrom segments produced in this way are linked<br />
skigeohor<br />
using on arrangement known as a 'seglist'<br />
scmd the i original DOS routine for scatter loading o<br />
oprogram<br />
into memory_ loadSegl), for example will<br />
ncreate<br />
just such a list, and return a pointer to it, if the<br />
s load is successful, At some stage, of course, any pro.<br />
gram loaded by this routine will need to be removed<br />
a<br />
horn memory and the routine used to perform this<br />
roperation<br />
is caled UnLoadSegg.<br />
e<br />
'liters: dO d i<br />
l<br />
steins<br />
.<br />
:<br />
O P<br />
TS<br />
L o<br />
o d<br />
i S e<br />
t g<br />
e 1<br />
i t<br />
't<br />
t<br />
ts<br />
i<br />
4<br />
t e<br />
i r<br />
:lout hive:<br />
o<br />
n<br />
Worn Weiss:<br />
:<br />
s<br />
eu<br />
gc<br />
lt<br />
i e<br />
s<br />
turn Woe seetist_p<br />
uteri: d l<br />
It<br />
Prototype: POOL UnLoadOes(OPTS)<br />
Function 2 : The <strong>Amiga</strong> D OS se gme nt unloa ding routine<br />
ler<br />
Function 1 : The<br />
<strong>Amiga</strong> D OS sca tte r<br />
loa ding sa glia l<br />
cre a tion routine<br />
pot Oslo: fi lenase_p . p o i n t e r to s null terminated<br />
string<br />
pointer too tog List or NIAL<br />
if error errors<br />
seglist.p p o i n t e r to s 'seise<br />
StgettS B o o l e a n succesettoitore<br />
qtrli:ator<br />
f<br />
,<br />
i<br />
,<br />
t<br />
g<br />
e<br />
s<br />
.<br />
5<br />
4<br />
1<br />
1<br />
1<br />
6<br />
1<br />
1<br />
1<br />
1<br />
1<br />
1<br />
1<br />
d<br />
e<br />
l<br />
e<br />
t<br />
t<br />
e<br />
l<br />
l<br />
a<br />
l<br />
b<br />
3<br />
-<br />
s<br />
U<br />
r<br />
Scatteri<br />
brain<br />
PLACING A LOAD FILE<br />
INTO MEMORY<br />
The use of the LoaciSegji routine itself is easy. Load a pointer to the filename into<br />
•<br />
register di and then make a conventional DOS library call it. t<br />
i<br />
prive.t<br />
c f a s h i oMASTS n :<br />
itt teeese,ell Lead hi./ nose<br />
lostiStg<br />
o<br />
The result which comes bock in dO should, _DOSB of course, be checked for elf Vt and often<br />
a convenient way of doing this will be e to sstore e the pointer in memory and test the<br />
zero flag after the move has been completed like this:<br />
erne. L eD,steitst_p<br />
beq.s .error<br />
preserve EN. pointer for unfolding<br />
Having got the seglist equivalent of a load file safely into memory, the DOS library<br />
provides routines, including one coiled CreateProc(), which allows the code to be<br />
brought to life as a separate process. There are, however, other uses for the loading<br />
routines - you can, for example, pass files containing just image data structures<br />
through the conventional assemble/link stages, producing graphics data that can be<br />
scatter loaded. When it comes to using functions like intuition's Drcrwimage() and so<br />
on you do, however, need to be able to locate the start of the real data within each<br />
segment.<br />
Individual segments which make up a seglist are tied together by means of pointers<br />
(lICPE pointers) with a NULL value signifying the end of the seglist chain. If we<br />
then take the starting BPTR seglist pointer provided by a routine such as LoaciSegt),<br />
left shift it by two bit positions and add 4, we end with on address that is the start of<br />
the real segment information. Here's a typical piece of example code for scatter<br />
loading a load file into memory and locating the entry point of the first segment:<br />
move.1<br />
CALLSTS<br />
sove.1<br />
berr.s<br />
'ALL<br />
•tfOrkt<br />
sone.l<br />
If i lenese,d1<br />
LoodSeg,_DO10e se<br />
dO,s es ti st_s<br />
.error<br />
02,dO<br />
04,d0<br />
d0,11<br />
As far as file loading<br />
<strong>Amiga</strong>DOS routines take<br />
look at how seglists can<br />
next month.<br />
111•11111•111111111111•1<br />
preserve BCPL pointer for unloading<br />
el points to tntry point<br />
and segfist creation is concerned that's basically it - the<br />
care of all the difficult stuff. The next thing to do is take a<br />
be used and, needless to say, this part of the story comes<br />
SEGLIST POINTERS<br />
<strong>Amiga</strong>DOS has its roots in cm operahr<br />
system called Tripos, much of which wo'<br />
written in a language called BCPI<br />
Amigo coders in general do not have to<br />
worry about BCPL except for the fact<br />
that it uses a form of long word addressing<br />
based on the normal 680x0-style<br />
memory addresses divided by four. lf,<br />
therefore, an <strong>Amiga</strong> DOS function is specified<br />
as returning a BPTR, i.e. a BCPLtype<br />
pointer, you have to multiply that<br />
AMIGA COMPUTING<br />
FEBRUARY 1996<br />
sove.I<br />
Leki<br />
Weiss<br />
111•111111111'<br />
uret<br />
...lciress by four before using or.<br />
If an <strong>Amiga</strong>DOS function returns a<br />
EIPTR, then any equivalent der:notation<br />
function will also expect a BPTR as well.<br />
This being so, it's usually best to store<br />
these pointers in BCPL form and then<br />
convert them just before use like this:<br />
Sep1_00 UPI. fors<br />
02,d0 r o o t slobine<br />
A.