; Cherryside program to count software interrupts on 68hc11e9 with BUFFALO ; ie: a proof-of-concept for writing and installing ISRs ; ; Program Commands: ; r = report value of counter (in hex) ; t = trigger software interrupt (indirectly increment counter and toggle LED2) ; 1 = directly toggle LED1 ; 2 = directly toggle LED2 ; q = restart BUFFALO ; Mike Spooner, April 2017 ; Pass this file through cpp preprocessor, then the as11 assembler #include "board.def" /* target-board specific constants */ #include "hc11e.def" /* on-chip RAM size, etc */ #include "buffalo.def" /* monitor restart addr, remapped vectors, mem areas */ #include "mancon.def" /* manifest constants */ #include "lib.sym" /* Cherryside EEPROM-resident library entry-points */ ; pin-masks for PORTB LED1 EQU $01 LED2 EQU $02 EVNT EQU $04 ; a program-drivable output-logic event pin ; can be used to simulate PS/2 kbd clock-interrupts ; if PB2 wired directly to IC3 ORG HIRAM bra init ; jump to program code, skip over variables counter FCB 0 ; 16-bit counter variable FCB 0 prompt FCC "Ready [r,t,1,2,q] " FCB 0 crlf FCB $0D ; CR+LF string FCB $0A FCB 0 ; initialise the time-protected control registers and ; then initialise the rest of the system init ldx #CSREGS ; use X index-reg as ptr to base of control regs ldab TMSK2,X orab #$01 ; timer prescaler = /16 stab TMSK2,X ; initialise the SCI: ; 9600 baud, 8n1 ; transmitter enabled, transmitter-interrupts disabled, ; reciever enabled, single-drop, receiver-interrupts disabled ldab #$0C stab SCCR2,X ;ldab #$30 ; uncomment these to get 1200 baud ;stab BAUD,X ; ... ; initialise PORTB ; PORTB pins 0-1 used to drive a pair of debug LEDs ; PORTB pin 2 used to programatically generate low-going edge ldab #$00 stab PORTB,X ldd #0 ; (re-)initialise counter to zero std counter ; install ISR for software-interrupt ldaa #$7E ; opcode of jump-to-extended-address staa PVSWI ldd #swi_isr ; address of ISR std PVSWI+1 ; report the address of ISR, as a sanity-check jsr sci_puthex tba jsr sci_puthex ldy #crlf jsr sci_putstr ; main program loop more ldy #crlf ; emit the prompt to the SCI jsr sci_putstr ldy #prompt jsr sci_putstr wait jsr sci_getbyte ; wait for a command byte from the SCI cmpa #CR ; if got CR beq more ; skip, get next command jsr sci_putbyte ; else echo received character back cmd cmpa #'1' ; toggle LED1? bne try2 ldab #LED1 bsr bptog bra more try2 cmpa #'2' bne tryq ldab #LED2 bsr bptog bra more tryq cmpa #'q' ; quit? beq done cmpa #'r' ; report? beq report cmpa #'t' ; trigger interrupt? bne more swi ; trigger! bra more ; go get next command done ldy #crlf jsr sci_putstr jmp #BUFFALO ; restart the BUFFALO monitor ; report the hex value of the counter via the SCI ; clobbers: A report ldaa #LED2 bsr bptog ldy #crlf jsr sci_putstr ldaa counter jsr sci_puthex ldaa counter+1 jsr sci_puthex bra more ; clear specified PORTB pins (drive to logic-low) ; argument: B = pin bitmask ; clobbers: B bpclr comb ; invert mask andb PORTB,X bbstor stab PORTB,X rts ; set specified PORTB pins (drive to logic-high) ; argument: B = pin bitmask ; clobbers: B bpset orb PORTB,X bra bbstor ; set PORTB and return to caller ; toggle specified PORTB pins ; argument: B = pin bitmask ; clobbers: B bptog eorb PORTB,X bra bbstor ; set PORTB and return to caller ; SWI service routine swi_isr ; note: no need to explicitly "acknowledge" this interrupt, ; there is no flag to clear ; ldab #LED2 ; toggle LED2 bsr bptog ldd counter ; increment counter addd #1 std counter rti