Interrupt handler

From MSX Game Library

Revision as of 13:59, 17 October 2025 by Aoineko (talk | contribs)

The MSX interrupt mechanism is essential for gameplay synchronization, but also for using certain peripheral features (such as the graphics processor).

What is an interrupt?

As its name suggests, an interrupt is a mechanism that temporarily interrupts the execution of the current main program to execute another piece of code, before returning control back to the main code.

On an MSX, it is the Z80, the central processor, that manages this mechanism. It has a specific input connected to the internal BUS that allows it to communicate with all internal (such as the VDP) and external (via the cartridge port) peripherals.

When the Z80 receives an interrupt signal from a peripheral device, it calls a routine located at a fixed address in memory page 0 (address 0x0038). #1

The code that is called during an interrupt is called an ISR (interrupt service routine).

Those with knowledge of assembly language should be concerned that the code executed during the interrupt may modify the CPU registers and that when the Z80 returns control to the main program, it will no longer function correctly. Well, you are right to be concerned because there is no automatic mechanism to prevent this!

As a result, before modifying the value of a register, ISRs save its value in the stack so that it can be restored before returning control to the main program.

BIOS

As by default, the main-ROM slot is selected on page 0, it is a piece of code provided by the BIOS that is executed at address 0x0038 each time an interrupt occurs.

The video processor sends an interrupt signal at constant intervals after displaying each frame (at 50 or 60 Hz depending on the region) and the BIOS’s ISR uses this interrupt to update some of its variables (frame counter, joystick or keyboard input state…).

Custom ISR

Notes

  • #1 In the default interrupt mode (IM 1)