changeset 12:981a5ed51a4d

Enable interrupts during startup and add handler to process keyboard
author William Astle <lost@l-w.ca>
date Sun, 06 Nov 2022 12:05:33 -0700
parents b2212c9de7b7
children 6b3609304712
files src/lwbasic.s
diffstat 1 files changed, 23 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/lwbasic.s	Sun Nov 06 00:27:04 2022 -0600
+++ b/src/lwbasic.s	Sun Nov 06 12:05:33 2022 -0700
@@ -403,9 +403,13 @@
                 stx RSTVEC
                 lda #0x55                       ; activate warm start handler
                 sta RSTFLG
+                ldx #irqhandler                 ; enable IRQ handler with a JMP at the vector
+                lda #0x7e
+                sta IRQVEC                      ; set JMP instruction
+                stx IRQVEC+1                    ; set address
                 ldx #greeting                   ; display greeting
                 jsr console_outstr
-                bra *
+                bra warmstartb                  ; finish up initialization
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ; Warm start handling
                 ifdef COCO3
@@ -414,7 +418,10 @@
 warmstart       nop                             ; flag warm start routine as valid
                 endc
                 jsr console_clear               ; clear screen
-                jsr keyb_reset                  ; reset the keyboard
+warmstartb      jsr keyb_reset                  ; reset the keyboard
+                lda #0x35                       ; enable VSYNC interrupt in PIA
+                sta PIA0.CB
+                andcc #0xaf                     ; enable interrupts at the cpu
                 bra *
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ; System startup message
@@ -424,6 +431,20 @@
                 fcc 'WIZARD ENTERPRISES INC.\r\n'
                 fcn '\n'
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+; IRQ handler
+;
+; Note that the interrupt flag in the PIA is cleared at the start of the interrupt handler. That means that if it takes
+; a long time to process this interrupt, or processing this interrupt was delayed somewhat, it is far less likely that
+; an interrupt gets missed. In that case, we may end up re-interrupting immediately on RTI, but it should reduce the
+; number of missed interrupts.
+irqhandler      lda PIA0.CB                     ; was it VSYNC?
+                bmi irqhandler0                 ; brif so
+                lda PIA0.DA                     ; clear HSYNC flag so we don't get stuck if it gets enabled
+                rti
+irqhandler0     lda PIA0.DB                     ; clear VSYNC flag
+                bsr keyb_read                   ; go handle the keyboard
+                rti
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ; Console keyboard input driver
 ;
 ; Reset the keyboard state, which means clearing the buffer and state flags