diff --git a/sw/interrupt.h b/sw/interrupt.h new file mode 100644 index 0000000..ce29bc5 --- /dev/null +++ b/sw/interrupt.h @@ -0,0 +1,13 @@ +#ifndef _INTERRUPT_H +#define _INTERRUPT_H + +#include + +#define BUTTON (1 << 0) + +void irq_int(); +void nmi_int(); + +uint8_t irq_get_status(); + +#endif \ No newline at end of file diff --git a/sw/interrupt.s b/sw/interrupt.s index c269e33..aad0d6b 100644 --- a/sw/interrupt.s +++ b/sw/interrupt.s @@ -9,6 +9,9 @@ .import _handle_irq .export _irq_int, _nmi_int +.export _irq_get_status + +.include "io.inc65" .segment "CODE" @@ -43,4 +46,9 @@ irq: PLA ; Restore accumulator contents ; BRK detected, stop break: JMP break ; If BRK is detected, something very bad - ; has happened, so stop running \ No newline at end of file + ; has happened, so stop running + +_irq_get_status: + lda IRQ_STATUS + ldx #$00 + rts \ No newline at end of file diff --git a/sw/io.inc65 b/sw/io.inc65 index 9192cff..f7f3155 100644 --- a/sw/io.inc65 +++ b/sw/io.inc65 @@ -4,3 +4,5 @@ UART = $7ff4 UART_TXB = UART UART_RXB = UART UART_STATUS = UART + 1 + +IRQ_STATUS = $7fff diff --git a/sw/irq.c b/sw/irq.c index 0d51cc0..64f6d74 100644 --- a/sw/irq.c +++ b/sw/irq.c @@ -1,7 +1,19 @@ +#include + +#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"); + } } \ No newline at end of file diff --git a/sw/tests/test_main.c b/sw/tests/test_main.c index 50e3d85..564fea6 100644 --- a/sw/tests/test_main.c +++ b/sw/tests/test_main.c @@ -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; } \ No newline at end of file