> Hello ppl...
>
> Today my eyes fell on a Z80 instruction set again... My attention this
time
> went to the IM 0, IM 1 and IM 2 instructions... I never used them, and I
> think I can say no one ever used 'em,

I used IM 2 for an own interrupt routine in Basic. All editions of Track
used it.


> but I just wanted to know how they
> work... Normally the MSX uses IM (Interrupt Mode) 1.. This means that a
> restart is made to address $38 (RST 38h). Interrupt mode 0 is like the
> 8080A, but my attention fell on the IM 2 instruction... This uses register
I
> and a random number to jump to a location...

Not random: it uses the number which is on the Z80 databus. But since this
interrupt mode is not specified in the MSX standard, yes, it's kinda random
(although on my computer it is always 255).


> I started coding a routine that
> uses IM 2, and I did it to jump to the location I wanted, only the strange
> thing is, is that if I enable the IM 2 and then end my ASM program the
> interrupt works perfectly, though when returned to BASIC, it ONLY executed
> the interrupt, and for the rest noting, but when I don't end the ASM code,
> the IM doesn't work... What I did was I enabled the IM 2 then I read a
key,
> and then returned to BASIC. But after the IM 2 was enabled, it executed it
> once, then did nothing, and after I pressed a key (and returned to BASIC)
it
> continued...
>
> How come??

Pfff... Well you are really very clear here.

I can tell you how to code it in a way it will work, maybe that's of some
use to you.

========================================

First, you will have to put your interrupt-routine on an adress of which the
MSB is the same as the LSB, so for example #C0C0

Then, fill an area starting at an adress of which the LSB is #00 (e.g.
#C200) with 257 times the MSB (or the LSB) of your interrupt-routine's
adress.

Then set I to the MSB of the jump-table.

Q&A:
====
Q: Why must the MSB equal the LSB?
A: Because on computers which use IM2 (PC uses something like it), the
number on the databus MUST be a multiple of 2. On MSX however, this is
undefined, so the adress in the jump-table can also be an odd number.

Q: Why 257 times the value?
A: Because if 255 is on the databus, it will get the jump-adress from #C2FF
and #C300.


Example routine:

org #C000

Start: ld a,IntJumpTable / 256
    ld i,a
    IM 2
    ret

FILLAREA: DS Interrupt - FILLAREA

org #C0C0

Interrupt: push af
    in a,(#99)
    pop af
    ei
    ret

FILLAREA2: DS IntJumpTable - FILLAREA2

org #C200

IntJumpTable: DS 257, Interrupt / 256


~Grauw


--
>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<
 email me: [EMAIL PROTECTED] or ICQ: 10196372
   visit the Datax homepage at http://datax.cjb.net/
>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<


****
MSX Mailinglist. To unsubscribe, send an email to [EMAIL PROTECTED]
and put "unsubscribe msx [EMAIL PROTECTED]" (without the quotes) in
the body (not the subject) of the message.
Problems? contact [EMAIL PROTECTED]
More information on MSX can be found in the following places:
 The MSX faq: http://www.faq.msxnet.org/
 The MSX newsgroup: comp.sys.msx
 The MSX IRC channel: #MSX on Undernet
****

Reply via email to