Re: LZ: Interrupts


[Prev][Next][Index][Thread]

Re: LZ: Interrupts



Ed Plese, Jr. wrote:
> 
> I have been trying to get some code to run under int 2, but without
> success.  I found out that I have to use IM 2, and I am trying to get
> the interrupts to jump to a spot in my program instead of having the
> interrupt jump to some spot in GRAPH_MEM.  I don't know why it
> doesn't work because my program is right after ZShell in mem, and I
> have loaded $92 to the IV and that's where my $88's start.  I wasn't
> sure if the problem was with the $88's so I changed them to 00's but
> it still didn't work.  I have not changed the interrupt routine at
> all, so it should work.  I think that the problem may be with the
> $88's or the $00's.  How does the CPU know what address to jump to in
> IM 2?  Does it take the IV as the MSB and then use the value on the
> data bus as the LSB (in my case it'd be $92xx, and I have 256 bytes
> of $88's or $00's there) or does it take the IV as the MSB and then
> take the value pointed to by the value on the data bus (in my case
> it's be $9288 or $9200).  I haven't tried the second case yet, but I
> figured that someone on the list should know.
> 


You're almost right...


When an interrupt is called in IM 2, the CPU jumps to an address where
the I reg is the MSB and the data bus is the LSB which means that the
LSB is a random number that you don't know. That means that you must
make a table of 257 byte (yeah, not 256) beginning at $xx00 to $x(x+1)00
(example, $8700-$8800). In the table you store a lot of $88 for example,
and then a jump to $8888 will occor, where you store the interrupt handler
which should end with a jp $38.


In the grayscale routine, the table is stored at $8700-$8800 and the
handler is stored from $8888-$88??. If you want to store it after
ZShell, you should also increase the string since else the program will
move around in the memory.


I put the 257 byte long table at $9100-$9200 and the handler at $9292.
Then there are some space for the interrupt variables at $90A4-$90FF
and $9201-$9291 which should be enough.


The problem with putting it after ZShell is that you only can run one
IM 2 program at a time. One thing I would definately see in ZShell 4.5
is support for more than one IM 2. ZShell could have a list over all
calls it would make when an IM 2 occurs. For example, you could have a
call to ZShell that installed a new IM 2 like this:


 ld hl,InterruptHandler
 CALL_(InstallIM2)   ; hl points to RELATIVE address in your program
 .
 .
 .
 ret


InterruptHandler:
 .
 .
 .
 ret


Another good point with this is that ZShell could look up the program and
call it. That way you wouldn't need to put the program with the handler
at a specific spot in the memory.


The problem with this is that ZShell will increase a lot... First 257 byte
for the table that and then probably at least 100 more bytes to get it all
to work. But then you could run all IM 2 programs at the same time...
(grayscale, game wizard, intzs and my fakemem program that uses im 2)


<pre>
-- 
Real name: Jimmy Mårdell
Email....: mailto:mja@algonet.se
IRC-name.: Yarin
WWW......: http://www.algonet.se/~mja


"Strap me down with disillusion 
  Tie me up in lifelines
   Nothing stops my thoughts from breeding
    Nothing's stopping my mind" - Leather Strip
</pre>


References: