You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/Interrupts.md
+30-32Lines changed: 30 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,14 +16,14 @@ the following instructions/events only:
16
16
EI ; Enables interrupts (that is, IME=1)
17
17
DI ; Disables interrupts (that is, IME=0)
18
18
RETI ; Enables interrupts and returns (same as the instruction sequence EI, RET)
19
-
<INT> ; Disables interrupts and calls interrupt vector
19
+
<ISR> ; Disables interrupts and calls the interrupt handler
20
20
```
21
21
22
-
Where \<INT\>means the operation which is automatically executed by the
23
-
CPU when it executes an interrupt.
22
+
Where \<ISR\>is the Interrupt Service Routine that is automatically executed
23
+
by the CPU when it services an interrupt request.
24
24
25
25
The effect of `ei` is delayed by one instruction. This means that `ei`
26
-
followed immediately by DI does not allow any interrupts between them.
26
+
followed immediately by `di` does not allow any interrupts between them.
27
27
This interacts with the [`halt` bug](<#halt bug>) in an interesting way.
28
28
29
29
## FFFF - IE - Interrupt Enable (R/W)
@@ -46,61 +46,59 @@ Bit 3: Serial Interrupt Request (INT $58) (1=Request)
46
46
Bit 4: Joypad Interrupt Request (INT $60) (1=Request)
47
47
```
48
48
49
-
When an interrupt signal changes from low to high, the
50
-
corresponding bit in the IF register becomes set. For example, Bit 0
49
+
When an interrupt request signal changes from low to high, the
50
+
corresponding bit in the IF register is set. For example, Bit 0
51
51
becomes set when the LCD controller enters the VBlank period.
52
52
53
-
Any set bits in the IF register are only **requesting** an interrupt to be
54
-
executed. The actual **execution** happens only if both the IME flag and
55
-
the corresponding bit in the IE register are set, otherwise the
56
-
interrupt "waits" until both IME and IE allow its execution.
53
+
Any set bits in the IF register are only **requesting** an interrupt.
54
+
The actual **execution** of the interrupt handler happens only if both the IME flag and
55
+
the corresponding bit in the IE register are set; otherwise the
56
+
interrupt "waits" until both IME and IE allow it to be serviced.
57
57
58
58
Since the CPU automatically sets and clears the bits in the IF register, it
59
-
is usually not required to write to the IF register. However, the user
59
+
is usually not necessary to write to the IF register. However, the user
60
60
may still do that in order to manually request (or discard) interrupts.
61
-
Like with real interrupts, a manually requested interrupt isn't executed
62
-
unless/until IME and IE allow its execution.
61
+
Just like real interrupts, a manually requested interrupt isn't serviced
62
+
unless/until IME and IE allow it.
63
63
64
64
## Interrupt Handling
65
65
66
66
1. The IF bit corresponding to this interrupt and the IME flag are reset by the CPU.
67
67
The former "acknowledges" the interrupt, while the latter prevents any further interrupts
68
68
from being handled until the program re-enables them, typically by using the `reti` instruction.
69
69
2. The corresponding interrupt handler (see the IE and IF register descriptions [above](<#FFFF - IE - Interrupt Enable (R/W)>)) is
70
-
called by the CPU. This is a regular call, exactly like what would be performed by a `call <vector>` instruction (the current PC is pushed on the stack
71
-
and then set to the address of the interrupt vector).
70
+
called by the CPU. This is a regular call, exactly like what would be performed by a `call <address>` instruction (the current PC is pushed onto the stack
71
+
and then set to the address of the interrupt handler).
72
72
73
-
The following occurs when control is being transferred to an interrupt handler:
73
+
The following interrupt service routine is executed when control is being transferred to an interrupt handler:
74
74
75
-
1. Two wait states are executed (2 M-cycles pass while nothing
76
-
occurs, presumably the CPU is executing `nop`s during this time).
77
-
2. The current PC is pushed to the stack, consuming 2 more M-cycles.
78
-
3. The PC register is set to the address of the handler ($40, $48, $50, $58, $60).
75
+
1. Two wait states are executed (2 M-cycles pass while nothing happens; presumably the CPU is executing `nop`s during this time).
76
+
2. The current value of the PC register is pushed onto the stack, consuming 2 more M-cycles.
77
+
3. The PC register is set to the address of the handler (one of: $40, $48, $50, $58, $60).
79
78
This consumes one last M-cycle.
80
79
81
-
The entire ISR**should** last a total of 5 M-cycles.
80
+
The entire routine**should** last a total of 5 M-cycles.
82
81
This has yet to be tested, but is what the Z80 datasheet implies.
83
82
84
83
## Interrupt Priorities
85
84
86
-
In the following three situations it might happen that more than one bit in the IF register is set, requesting more than one interrupt at once:
85
+
In the following circumstances it is possible that more than one bit in the IF register is set, requesting more than one interrupt at once:
87
86
88
-
1. More than one interrupt signal changed from Low to High at the same time.
89
-
2. Several interrupts have been requested while IME/IE didn't allow them to be handled directly.
87
+
1. More than one interrupt request signal changed from low to high at the same time.
88
+
2. Several interrupts have been requested while IME/IE didn't allow them to be serviced.
90
89
3. The user has written a value with several bits set (for example binary 00011111) to the IF register.
91
90
92
-
If IME and IE allow the execution of more than one of the
91
+
If IME and IE allow the servicing of more than one of the
93
92
requested interrupts, the interrupt with the highest priority
94
-
is executed first. The priorities follow the same order as the bits in the IE
93
+
is serviced first. The priorities follow the order of the bits in the IE
95
94
and IF registers: Bit 0 (VBlank) has the highest priority, and Bit 4
96
95
(Joypad) has the lowest priority.
97
96
98
97
## Nested Interrupts
99
98
100
99
The CPU automatically disables all the other interrupts by setting IME=0
101
-
when it executes an interrupt. Usually IME remains zero until the
102
-
interrupt handler returns (and sets IME=1 by means of the RETI instruction).
103
-
However, if you want any other interrupts (of any priority)
104
-
to be allowed to be executed from inside the interrupt
105
-
handler, then you can use the EI instruction in the interrupt
106
-
handler.
100
+
when it services an interrupt. Usually IME remains zero until the
101
+
interrupt handler returns (and sets IME=1 by means of the `reti` instruction).
102
+
However, if you want to allow the servicing of other interrupts (of any priority)
103
+
during the execution of an interrupt handler, you may do so by using the
0 commit comments