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:
13
sw/interrupt.h
Normal file
13
sw/interrupt.h
Normal 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
|
||||
@@ -9,6 +9,9 @@
|
||||
.import _handle_irq
|
||||
|
||||
.export _irq_int, _nmi_int
|
||||
.export _irq_get_status
|
||||
|
||||
.include "io.inc65"
|
||||
|
||||
.segment "CODE"
|
||||
|
||||
@@ -44,3 +47,8 @@ irq: PLA ; Restore accumulator contents
|
||||
|
||||
break: JMP break ; If BRK is detected, something very bad
|
||||
; has happened, so stop running
|
||||
|
||||
_irq_get_status:
|
||||
lda IRQ_STATUS
|
||||
ldx #$00
|
||||
rts
|
||||
@@ -4,3 +4,5 @@ UART = $7ff4
|
||||
UART_TXB = UART
|
||||
UART_RXB = UART
|
||||
UART_STATUS = UART + 1
|
||||
|
||||
IRQ_STATUS = $7fff
|
||||
|
||||
12
sw/irq.c
12
sw/irq.c
@@ -1,7 +1,19 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "interrupt.h"
|
||||
|
||||
// This is defined in main.c
|
||||
void puts(const char* s);
|
||||
|
||||
void handle_irq() {
|
||||
uint8_t status;
|
||||
|
||||
puts("Interrupt Detected!\n");
|
||||
|
||||
status = irq_get_status();
|
||||
|
||||
if (status & BUTTON) {
|
||||
puts("Button Interrupt!\n");
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "sevenseg.h"
|
||||
#include "uart.h"
|
||||
#include "interrupt.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
@@ -75,5 +76,14 @@ int main(void)
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user