******************************************************************
* *
* 68000 ASSEMBLY COURSE ON ATARI ST *
* *
* by The Ferocious Rabbit (from 44E) *
* *
* Second series *
* *
* Lesson number 10 *
******************************************************************
Before providing you with the much-awaited bibliography, I will
very briefly talk about interruptions. The principle is nor-
mally known (if not, refer to lesson number 5 of the first
series!). However, there is a topic that deserves a bit more
attention: the MFP68901. It is a circuit recognized by the
68000 as having an interruption level of 6 (see the sheet
provided with lesson 1 titled "68000 AND 68901 INTERRUPTION
VECTORS TABLE"). Internally, this circuit can manage
16 levels of interruption, with each level having an
associated address ($100-$13C for the ST). Here is a small bit of
listing intended to show you how to place your own routine
in Timer A. First, you must block interruptions by
setting the SR to $2700, save the MFP registers, place your
routine, and then lower the interruption level to its usual
level on the ST, which is $2300. This is done, of course,
in Supervisor mode, a mode you can access with Gemdos
$20.
* To set up....
MOVE.W #$2700,SR interrupts forbidden
MOVE.B $FFFFFA07,ANC_IERA save
MOVE.B $FFFFFA09,ANC_IERB MFP 68901
MOVE.B $FFFFFA13,ANC_IMRA values
MOVE.B $FFFFFA15,ANC_IMRB
MOVE.B $FFFFFA17,ANC_VR
MOVE.L $134,ANC_TIMEA save Timer A
MOVE.L #MY_TIMEA,$134 place new routine
CLR.B $FFFFFA09 prevents interrupt 0-7
CLR.B $FFFFFA15 masks interrupt 0-7
MOVE.B #%00100000,$FFFA07 OK interrupt 13 (timer A)
MOVE.B #%00100000,$FFFA13 OK also for its mask
MOVE.B #7,$FFFFFA19 set TACR
MOVE.B #12,$FFFFFA1F and TADR (1kHz)
BCLR #3,$FFFFFA17 automatic end of interrupt
MOVE.W #$2300,SR allow interruptions
* And now, when we leave the program...
MOVE.W #$2700,SR interrupts forbidden
MOVE.B ANC_IERA,$FFFFFA07 restoring
MOVE.B ANC_IERB,$FFFFFA09
MOVE.B ANC_IMRA,$FFFFFA13
MOVE.B ANC_IMRB,$FFFFFA15
MOVE.B ANC_VR,$FFFFFA17
MOVE.L ANC_TIMEA,$134
MOVE.W #$2300,SR allow interruptions
* My Timer A routine
* Do not forget to save the registers that are used
* and to finish with an RTE.
MY_TIMEA: movem.l d0-a6,-(sp)
'
'
'
BCLR #5,ISRA depending on VR!!!
MOVEM.L sp)+,d0-a6
RTE
*----------------------------------------------------------*
SECTION BSS
ANC_TIMEA DS.L 1
ANC_IERA DS.B 1 backup for the MFP
ANC_IERB DS.B 1 "
ANC_IMRA DS.B 1 "
ANC_IMRB DS.B 1 "
ANC_VR DS.B 1 "
I will simply describe to you the IERA, IMRA, IPRA
etc... registers of the MFP. For more details, consult the ST
Bible, the Developer's Book, or the official ATARI documentation
(the ideal!), the goal of these lessons is not to be a copy of the
information you can find elsewhere.
First of all, the 16 levels of the MFP are divided into 2 groups.
Group A covers levels 15 to 8 and group B covers levels 7 to 0.
Be careful, here A and B have nothing to do with Timers A and B!!!
For each group (A or B), there is a series of registers. In each of
these registers, the interruptions are represented by a bit.
Let's see these registers:
IERA ($FFFFFA07) and IERB ($FFFFFA09)
Interrupt Enable Register A (or B)
By setting the corresponding bit for an interruption to 0, you
forbid it. It will not be taken into account by the MFP at all.
IPRA ($FFFFFA0B) and IPRB ($FFFFFA0D)
Interrupt Pending Register A (or B)
When an interruption occurs, the MFP sets the corresponding bit to 1
in the IPRA (or IPRB). This signals that an interruption is pending.
Because of the priority system, it is possible for a high-level
interruption to be in process and a lower level interruption to
occur during that time. It is therefore necessary to note this
intention to trigger, so that once the treatment of the priority
interruption is finished, the treatment of the weaker one can take
place.
It is, of course, possible to read IPRA and IPRB to determine if
an interruption is pending. It is also possible to set the bit
of a pending interruption to 0, so that it does not trigger. However,
setting a bit to 1 in this register has no effect. We realize here that
the possibilities are already quite numerous. An interruption may
thus scrutinize another one to obtain an irregular interruption cycle.
It is also possible to let an interruption trigger just 'for fun'.
This can be done by leaving it valid through IERA but masking it with
IMRA.
IMRA ($FFFFFA13) and IMRB ($FFFFFA15)
Interrupt Mask Register A (and B)
Masking prevents an interruption from triggering although it is
authorized by IERA or IERB. This can allow, for example, a
level 4 interruption to not be bothered by a level 6 interruption. For
this, it simply has to mask the latter during its execution.
VR ($FFFFFA17)
Vector Register
This byte is a bit special. In our case, only bit 3 interests us,
the others being used by the MFP to encode the vector number that
corresponds to the source of interruption. Bit 3 is used to indicate
to the MFP if it is in Software End of Interrupt mode or in Automatic
End of Interrupt mode (default mode). Let's see the explanations with
the following registers:
ISRA ($FFFFFA0F) and ISRB ($FFFFFA11)
Interrupt in Service Register A (or B)
A bit at 1 indicates that the interruption is being processed. If we
are in Software End of Interrupt mode, it is at the end of our routine
in interruption that we must indicate ourselves that our routine is
finished. For this, we must set to 0 the corresponding bit of our
interruption, in ISRA (or ISRB). As long as this bit is at 1, less
priority interruptions cannot disturb us. However, as soon as the treatment
of our interruption begins, its bit in IPRA is automatically set to 0, and
another interruption of the same level can very well occur during the
treatment of this one. The IPRA bit will therefore be set to 1 again, but
this new interruption will only be treated when the first one has set
the ISRA bit back to 0.
On the other hand, if we are in Automatic End of Interrupt mode, as
soon as our routine executes, the MFP, of course, sets its IPRA bit to 0
(since the interrupt is no longer pending), but also sets its ISRA bit
to 0! It is then possible for other weaker interruptions to interrupt the
first one, even if it is not yet finished.
You see that with all this, it is possible to skillfully juggle by
considering the most twisted cases!!! Concerning the timers
A, B, C, and D, here are just the addresses to address them, the
information provided in the bible or the developer's book being
largely sufficient. If by chance you are eager for information on
this circuit, rush to a bookstore specialized in electronic
"literature" and ask for a book on the MK68901. Also pass by the
pharmacy to pick up some aspirin....
To conclude these assembly lessons, here is a small bibliography
so that you can direct your research toward the subjects that
interest you.
Machine Language on ST (Ed. Micro App). Quite an unnecessary book!
Very very little information, really, it is not a good purchase.
The ST Bible (Ed. Micro-App). Became quite hard to find, too bad!
Quite a lot of good info, sufficient in most cases. It has been
replaced by the Developer's Book.
Tips and Traps (Ed. Micro-App). To be avoided at all costs! The
programs made following these tips will surely be incompatible as
soon as there is a change in TOS.
The Developer's Book (Volume 1 and 2) (Ed. Micro App) If you
do not have access to the documentation for developers with the
Atari endorsement, this is the book you need. We can regret the doz-
ens of pages containing the BIOS listing of the STF and the other
dozens of pages containing the BIOS of the Mega ST. It feels a bit
like padding: either you have the level in assembly to understand
something and then you have the level to follow the BIOS with
MONST, or anyway, you do not understand anything and it is not
because you have the listing in front of your eyes that it will change
anything. Anyway, this is my opinion, and as, in addition, the
listing is only valid for the mentioned models, if you rely on it to
"discover" new addresses you might be surprised with newer
machines...
The book on GEM on Atari ST (Ed. Micro App). If you think you
are going to learn how to program GEM with that, you are heading for
disaster. The problem with GEM is that it is usable in assembly
provided you use macros, otherwise it is far too
heavy. However, in a commercial book, it is impossible to limit
oneself to a single assembler. This means that the authors have
dissected everything with direct calls to TRAP #2, and it becomes
totally incomprehensible for beginners. However, the functions are
relatively well detailed, and if you already know what you are
looking for, this book will be a good tool. We can just regret
some absences such as the Escape functions of GEM and
some AES functions. Note that this book is 99% taken from the
Developer's Book.
GFA 3.00 Documentation. There, it's the right thing! Indeed in the last
pages of the documentation of this BASIC, you will find the list of all
the GEMDOS, BIOS, and XBIOS functions (the GEMDOS $20
function that allows you to switch to Supervisor mode is missing,
since it is inaccessible in GFA), ASCII codes, keyboard codes and a
few pages earlier, a good list of AES functions. I have to
admit that I photocopied these few pages and they often serve
me: the information is sufficient in most cases, and especially very
easy to find, which is not the case for example with the GEM Book which does
not even include an index of functions!!!
Note that some GEM functions exist in the internal library of GFA but are not
available in the DEV-PACK library. This is the case with Form_Button and
Form_Keybd. And it's annoying!
Indeed, at the beginning Form_do did not exist. The people of Digital
Research thus decided to create this function from scratch using
Form_Keybd and Form_button, and released the C source code. After a while,
programmers no longer used anything but Form_Do and we fell into the current
routine of form management that we know.
If you want to make your own Form_do, more advanced, it "simply"
necessitates taking Form_Keybd and Form_button to recreate Form_do. Unfor-
tunately these two functions have fallen into oblivion and to get them,
well, pffuuuuuttt!!!
You want to know their opcode and parameters? Easy as pie!
If you have followed these lessons well, you know a lot of things
about GEM (where the function opcode is placed, where the
number of parameters is written etc... and well, you launch AMonst, and
then you run a small piece of GFA that calls Form_keybd while displaying on
the screen the AES table address beforehand, and that waits for a key
press thereafter. All of this happens under the GFA
interpreter, of course! As soon as you are waiting for a key
press, you trigger AMONST (shift+alternate+help) and hop, the
great search begins. You do the same with Form_button,
and the job is done. Courage, it's not very hard, and it makes
a great exercise!
Implementation of the 68000 (Ed. Sybex) Excellent book, dealing with the
68000 in general. Do not expect to find system addresses
for your ST. Here, we talk about clock cycles, addressing modes, etc...
Implementation of Common Functions in 68000 (Ed. Masson, by
François BRET). How to do sine, cosine, Fourier transforms, etc...
Not sold with aspirin or coffee, but essential if you tackle
trigonometry problems in ASM. Only 191 Francs, a bargain! (Thanks to
Shizuka for providing the reference for this book!!!!!)
STATION INFORMATIQUE 2 rue Piémontési 75018 PARIS
tel:(1)42.55.14.26
Excellent Dom-Pubs catalog. Before trying to pirate various
software without the documentation, take a look at their
catalog. Many little things are to be discovered (various
ASM sources, debugging utilities, etc...) If you are a fan of Mac
emulation, the Cyclan pack, a Mac assembler with its editor, etc. can be
found among the dom-pubs for this machine...
Quite nice to discover this other machine, equipped with a 68000 too.
ST Mags was also teeming with various tricks, at least
especially in the old issues in my opinion...
Here is a small non-exhaustive list...
Integration of a resource in GFA (46)
Form Exdo (46)
Samples on ST (27,28,29,30,31,35) (In GFA with assembler, but the GFA is
barely noticeable...)
Scrolling in GFA (31 to 45 except issue 37 and 44) Same remark as
for the digits!!!
Managing disks in GFA (13,14,15,16)
Programming GEM (6 to about 30) Great! All in C, but the calls
are the same and the syntax identical to the DEV-PACK library! Quickly
search your old ST Mag issues because to learn GEM, it's excellent!!!
3D Animation (45,46,49) For the moment the last article has
not been released... We hope it will not end up like the listing that
allows booting from a cartridge... Very clear, nice, ideal
for starting in 3D.
For coprocessors, 2 articles in issues 31 and 32.
In the extinct First (1ST), there were some nice tricks on
MIDI, decompressing DEGAS images, creating a RAM disk
and a printer spooler.
Atari Mag is coming back strong at the moment.
Very good articles on graphic programming of the STE. This allows
to get an idea of the BLITTER, the 4096 colors, etc...
It's in BASIC, but the translation is easy. (21,22).
Being in the know, I can also inform you that in the
upcoming issues of Atari Mag, you will find articles on
different subjects with sources in ASM and GFA, and that this type
of article should last quite some time.
Well, in a summary, buy ST Mag and Atari Mag every month. If
necessary, buy them in groups, but make a big pile of all
those magazines because it's an important mine of information. Often
the questions that are asked on RTEL for example find
their answer in reading the old issues! Some good
binders, dividers, and you'll have a huge documentation
for not very expensive.
I will end these courses by renewing the warning about
the hunt for listings! It is preferable to have some books
and notes on paper rather than 10 megabytes of sources to
which one does not understand much, and which, in any case, are
quite inconvenient to consult compared to written information!
As for fairly large programs, prepare a few
sheets next to you, to jot down the names of routines,
labels, variables, etc... you will quickly realize that the
main difficulty of assembly lies in the fact that listings are very
very long and it is difficult to navigate them
to look for something. Program cleanly, be clear and avoid
inelegant solutions if possible. Comment profusely
your sources because in 6 months when it comes to making a slight modi-
fication, you will see the difference between clear sources and
the others!
Well, I leave you hoping that these courses will have interests-
ed you and that they will have given you a taste for assembly! Don't forget
that you can always contact me on 3614 RTEL1 (or
RTEL2) in FEROCE LAPIN's inbox, and that there is a section on this server
for