* keyint.asm - Test circuit for setting IRQ based on keypad #include "registers.asm" ; Declares control registers. #include "buffalo.asm" ; Declares utility subroutine jumptable and ISR jumptable org $2000 main: jmp start #include "delay.asm" ; Delay loop; needed by keypad.asm. #include "keypad.asm" ; Keypad-related routines. str1: fcc "PORTD=" fcb $04 str2: fcc "PORTE=" fcb $04 start: jsr init_keypad ; Initialize port D for keypad output clr PORTD ; Clear all port D output pins jsr setup_irq ; Set up our interrupt service routine for IRQ. mainloop: ldx #str1 jsr outstrg0 ldx #PORTD jsr out1bsp ldx #str2 jsr outstrg0 ldx #PORTE jsr out1bsp jsr outcrlf ldx #$ffff jsr dloop wai ; Wait for interrupt jmp mainloop * jsr really_stop ; Stop the CPU till we get an IRQ. rts ; Return to caller. * Set up our ISR to be triggered on an IRQ interrupt. setup_irq: sei ; Set I interrupt mask (disable IRQ interrupts) ldx #myisr ; Get the address of our ISR stx jirq+1 ; Store it at the IRQ jumptable address cli ; Clear I interrupt mask (enable IRQ interrupts) rts ; Return from IRQ setup. * Our interrupt service routine. * Echoes the keypad key that was pressed to the SCI. str3: fcc "Interrupted by key: " fcb $04 key: rmb 1 str4: fcc "Oops, no key pressed." fcb $04 myisr: ldx #str3 jsr outstrg0 jsr key_scan ; Scan to see what key was pressed. tsta ; Was any key pressed? beq nokey ; No; false alarm. jsr outa jsr outcrlf rti nokey: ldx #str4 jsr outstrg jsr outcrlf rti ; Return from interrupt. * Enable the STOP instruction to actually halt the CPU clocks. enable_stop: psha ; Preserve the caller's A register. tpa ; Get the CCR bits. anda #SFLAG^ALL1S ; Clear the S flag to enable the STOP instruction. tap ; Set the CCR bits. pula ; Restore the caller's A register. rts ; Return from enable_stop subroutine. * Really stop the CPU, until interrupts. * Must enable the STOP instruction first. really_stop: jsr enable_stop ; Enable the STOP instruction nop ; Use this before STOP, to be safe. (See ref.man. p.581) stop ; Stop the CPU (until interrupt) rts ; If we get here, return to caller.