add interrupt init code (and increase rtc tick rate)

This commit is contained in:
Byron Lathi
2023-11-20 22:23:18 -08:00
parent 5e36d0824a
commit 7089b663ca
7 changed files with 244 additions and 230 deletions

View File

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

View File

@@ -1,51 +0,0 @@
; ---------------------------------------------------------------------------
; interrupt.s
; ---------------------------------------------------------------------------
;
; Interrupt handler.
;
; Checks for a BRK instruction and returns from all valid interrupts.
.import _handle_irq
.import _cputc, _clrscr
.export _irq_int, _nmi_int
.include "io.inc65"
.segment "CODE"
.PC02 ; Force 65C02 assembly mode
; ---------------------------------------------------------------------------
; Non-maskable interrupt (NMI) service routine
_nmi_int: RTI ; Return from all NMI interrupts
; ---------------------------------------------------------------------------
; Maskable interrupt (IRQ) service routine
_irq_int: PHX ; Save X register contents to stack
TSX ; Transfer stack pointer to X
PHA ; Save accumulator contents to stack
INX ; Increment X so it points to the status
INX ; register value saved on the stack
LDA $100,X ; Load status register contents
AND #$10 ; Isolate B status bit
BNE break ; If B = 1, BRK detected
; ---------------------------------------------------------------------------
; IRQ detected, return
irq: PLA ; Restore accumulator contents
PLX ; Restore X register contents
jsr _handle_irq ; Handle the IRQ
RTI ; Return from all IRQ interrupts
; ---------------------------------------------------------------------------
; BRK detected, stop
break:
pla
plx
rti

View File

@@ -14,6 +14,18 @@ RTC_IRQ_THRESHOLD = $20
RTC_OUTPUT = $30
RTC_CONTROL = $30
THRESHOLD_0 = $a0
; THRESHOLD_1 = $0f
THRESHOLD_1 = $00
THRESHOLD_2 = $00
THRESHOLD_3 = $00
; IRQ_THRESHOLD_0 = $32
IRQ_THRESHOLD_0 = $10
IRQ_THRESHOLD_1 = $00
IRQ_THRESHOLD_2 = $00
IRQ_THRESHOLD_3 = $00
; void init_rtc(void);
; Initialize rtc and generate 50ms interrupts
.proc _init_rtc
@@ -36,36 +48,36 @@ RTC_CONTROL = $30
lda #RTC_THRESHOLD+0 ; Set threshold to 4000 ($fa0)
sta RTC_CMD
lda #$a0
lda #THRESHOLD_0
sta RTC_DAT
lda #RTC_THRESHOLD+1
sta RTC_CMD
lda #$0f
lda #THRESHOLD_1
sta RTC_DAT
lda #RTC_THRESHOLD+2
sta RTC_CMD
lda #$00
lda #THRESHOLD_2
sta RTC_DAT
lda #RTC_THRESHOLD+3
sta RTC_CMD
lda #$00
lda #THRESHOLD_3
sta RTC_DAT
lda #RTC_IRQ_THRESHOLD+0 ; Set irq threshold to 50 ($32)
sta RTC_CMD
lda #$32
lda #IRQ_THRESHOLD_0
sta RTC_DAT
lda #RTC_IRQ_THRESHOLD+1
sta RTC_CMD
lda #$00
lda #IRQ_THRESHOLD_1
sta RTC_DAT
lda #RTC_IRQ_THRESHOLD+2
sta RTC_CMD
lda #$00
lda #IRQ_THRESHOLD_2
sta RTC_DAT
lda #RTC_IRQ_THRESHOLD+3
sta RTC_CMD
lda #$00
lda #IRQ_THRESHOLD_3
sta RTC_DAT
lda #$30