; JAB_PartyLights ; For the Crackhouse party November 18th, 2006 XDEF main ; export 'Entry' symbol ABSENTRY main ; for absolute assembly: mark this as application entry point RAMStart equ $3800 ; absolute address to place my variables ROMConst equ $4000 ; absolute address to place constants in EEPROM (ie the linked list control) ROMProg equ $C000 ; absolute address to ROM in which to place the program DDRT equ $0242 ; Port T Data Direction Register DDRM equ $0252 ; Port M Data Direction Register PTM equ $0250 ; Port M I/O Register PTT equ $0240 ; Port T I/O Register ;Interrupt Stuff CRGFLG equ $0037 ; CRG Flags Register CRGINT equ $0038 ; CRG Interrupt Enable Register RTICTL equ $003B ; CRG RTI Control Register ;Timer Stuff TSCR1 equ $0046 TSCR2 equ $004D ;Serial Stuff SCIBD equ $00C8 ; SCI Baud Rate Register SCIBDL equ $00C9 ; SCI Baud Rate Register Low SCICR1 equ $00CA ; SCI Control Register 1 SCICR2 equ $00CB ; SCI Control Register 2 SCIDRH equ $00CE ; SCI Data Register High SCIDRL equ $00CF ; SCI Data Register Low SCISR1 equ $00CC ; SCI Status Register 1 SCISR2 equ $00CD ; SCI Status Register 2 PTS equ $0248 ; Port S I/O Register RDRF equ $20 TDRE equ $80 TCNT equ $0044 ; Character Codes CR equ 13 EOT equ 4 BS equ 8 SPACE equ 32 NP equ 12 LF equ 10 org RAMStart Beat1 rmb 2 Beat2 rmb 2 Beat3 rmb 2 Beat4 rmb 2 Interval1 rmb 2 Interval2 rmb 2 Interval3 rmb 2 Wait rmb 2 Next_State_SW rmb 2 State rmb 2 org ROMConst Welcome fcb NP,"Welcome to JAB_BlinkyLights",CR,LF,"Press A to activate and B to deactivate",LF,CR,EOT StartWait fdb 20000 Start fdb S1 S1 fcb $01 fdb S2 S2 fcb $02 fdb S4 S4 fcb $04 fdb S8 S8 fcb $08 fdb S1 org ROMProg main lds #$4000 movb #$0F,DDRT ;Data Direction jsr SCI_Init ;We're running at 19200 jsr Timer_Init ldx #Welcome jsr SCI_OutString ldx Start movw StartWait,Wait cli loop movb 0,X,PTT ;Set Output ldd TCNT addd Wait std Next_State_SW ;We store this here so that the interrupt can change it ldx 1,X wloop ldd Next_State_SW cpd TCNT bpl wloop ;Is this right? bra loop SCI_InterruptHandler ldaa SCISR1 ; Read RDRF so we can clear it ldaa SCIDRL ; Bug: if TRDE is set, we are screwed jsr SCI_OutChar cmpa #'1' bne SIHnot1 jsr SetNewTempo rti SIHnot1 cmpa #'A' bne SIHnotA jsr OnOff rti SIHnotA cmpa #'B' bne done jsr OnOff done rti ; SetNewTempo ; Catch a tempo from 4 keypresses from the serial port SetNewTempo movw TCNT,Beat1 ldx Start ; First State movb 0,X,PTT ldx 1,X b2 brclr SCISR1,#RDRF,b2 movw TCNT,Beat2 ldaa SCIDRL ; Echo Char, Clear RDRF jsr SCI_OutChar movb 0,X,PTT ; State Change ldx 1,X b3 brclr SCISR1,#RDRF,b3 movw TCNT,Beat3 ldaa SCIDRL ; Echo Char, Clear RDRF jsr SCI_OutChar movb 0,X,PTT ; State Change ldx 1,X b4 brclr SCISR1,#RDRF,b4 movw TCNT,Beat4 ldaa SCIDRL ; Echo Char, Clear RDRF jsr SCI_OutChar movb 0,X,PTT ; State Change ldx 1,X ;now it's time to average the Interval! ldd Beat2 subd Beat1 std Interval1 ldd Beat3 subd Beat2 std Interval2 ldd Beat4 subd Beat3 ;std Interval3 ; D contains Avg3, no need to store it addd Interval1 addd Interval2 ldx #3 idiv ; RegD / RegX = RegX stx Wait tfr X,D ; Because we cannot add to x addd Beat4 ; Calculate Beat4+Timer_wait std Next_State_SW rts ; OnOff ; Function to immediately control all lights ; input: Initially RegA has the first key press OnOff cmpa #'A' ; A turns lights on bne notOn movb #$07,PTT notOn cmpa #'B' ; B turns lights off bne notOff movb #$00,PTT notOff cmpa #'C' ; C returns to the previous tempo bne notRet ; (ie it returns from the interrupt) rts notRet cmpa #'1' ; 1 kicks us into the tempo finder bne notTempo jsr SetNewTempo rts notTempo jsr SCI_InCharEcho ; Wait for next key press bra OnOff ;****Timer_Init********** ;* Initialize Timer: cycle period = 1us ;* Input: none ;* Outputs: none ;* error: none Timer_Init movb #$80,TSCR1 ;enable TCNT movb #$07,TSCR2 ;32us cycles rts ;****Timer_500ms********** ;* Waits 500ms ;* Input: none ;* Outputs: none ;* error: none Timer_500ms pshd ldd #15625 addd TCNT ;TCNT at end of delay Wloop cpd TCNT ;is EndT