On the Subject or Intereupts

Although I have learned a lot by designing my own z80 computer, I have yet to learn much about interrupts. It’s just not something that I initially saw a strong need for.

However, since I have been looking at porting other people’s code over to my system I have come to realize just how important other people see interrupts to be. In fact, from what I can tell,  more often than not this is the case. At least with the code I have examined.

This means, that if I am to port some of the code I would like to use, I need to learn about interrupts.

The first thing of note is the hardware situation. On my first run of boards, what I’m calling the Beta Boards, the IEI line on the DART was left disconnected/floating. As it turns out, this is a no-no. This pin is the Interrupt Enable Input. Meaning it’s the enable on the SIO for interrupts. Without a High signal on this pin, there are no interrupts. So, I’ve fixed this issue on my new design by adding a resistor between IEI and VCC, and I’ve used a bodge resistor as a solution on my Beta Board.

The second thing to note is the different types of interrupt modes on the z80. There are three: Mode 0, Mode 1, and Mode 2. From what I can tell, Mode 1 is the most straight forward. In this Mode a low on INT will call the z80 to perform a RST 38H instruction. Which is essentially the same thing as a CALL 0038H. However, in order to return from this instruction the system requires a RETI instruction. So keep that in mind.

Mode 2 is interesting because it allows you to jump to a specific routine pointed to by a reset vector. In this Mode the upper 8-bits of the address is held in a register. And the lower 8-bits is placed onto the data bus by the peripheral. Trying to understand this Mode almost caused my head to explode. A little complex for our needs.

Mode 0, as I understand it, is a reset mode that is designed to be compatible with the 8080. Where in the peripherals place data on the data bus. I’m not going to presume to understand anything about this Mode.

So therefore we’ll be using IM 1 where polling is not usable. But wait, what if we need multiple devices? Well, luckily there is a way around this. Although I suppose it could be a little slow. When the z80 receives an interrupt the routine checks all the peripherals before deciding how to react. Good thing our system clock is at 6mhz. We may even need a little more speed. But in the end, if we have to, we can always use IM 2.

Here is an example of working code of Interrupt Mode 0.  I found interrupts a little difficult to understand at first.  But hopefully a very simple example of an interrupt routine will be enough to help the beginner.

IM 1 Example

Leave a Reply

Your email address will not be published. Required fields are marked *