Implement interrupt status register

Upon an interrupt, you can read from the interrupt status register to
see what caused the interrupt.
This commit is contained in:
Byron Lathi
2022-03-14 13:30:01 -05:00
parent e012eb7d4d
commit a5474b5ae5
5 changed files with 46 additions and 1 deletions

13
sw/interrupt.h Normal file
View File

@@ -0,0 +1,13 @@
#ifndef _INTERRUPT_H
#define _INTERRUPT_H
#include <stdint.h>
#define BUTTON (1 << 0)
void irq_int();
void nmi_int();
uint8_t irq_get_status();
#endif

View File

@@ -9,6 +9,9 @@
.import _handle_irq .import _handle_irq
.export _irq_int, _nmi_int .export _irq_int, _nmi_int
.export _irq_get_status
.include "io.inc65"
.segment "CODE" .segment "CODE"
@@ -44,3 +47,8 @@ irq: PLA ; Restore accumulator contents
break: JMP break ; If BRK is detected, something very bad break: JMP break ; If BRK is detected, something very bad
; has happened, so stop running ; has happened, so stop running
_irq_get_status:
lda IRQ_STATUS
ldx #$00
rts

View File

@@ -4,3 +4,5 @@ UART = $7ff4
UART_TXB = UART UART_TXB = UART
UART_RXB = UART UART_RXB = UART
UART_STATUS = UART + 1 UART_STATUS = UART + 1
IRQ_STATUS = $7fff

View File

@@ -1,7 +1,19 @@
#include <stdint.h>
#include "interrupt.h"
// This is defined in main.c // This is defined in main.c
void puts(const char* s); void puts(const char* s);
void handle_irq() { void handle_irq() {
uint8_t status;
puts("Interrupt Detected!\n"); puts("Interrupt Detected!\n");
status = irq_get_status();
if (status & BUTTON) {
puts("Button Interrupt!\n");
}
} }

View File

@@ -2,6 +2,7 @@
#include "sevenseg.h" #include "sevenseg.h"
#include "uart.h" #include "uart.h"
#include "interrupt.h"
int main(void) int main(void)
{ {
@@ -75,5 +76,14 @@ int main(void)
printf("Done!\n\n"); printf("Done!\n\n");
printf("Testing irq_get_status...\n");
*(uint8_t*)0x7fff = 0xa5;
if (irq_get_status() != 0xa5) {
printf("Incorrect value!\n", i);
retval++;
}
printf("Done!\n\n");
return retval != 0; return retval != 0;
} }