;************************************************************************** ; FILE: drummer.asm * ; CONTENTS: 'Funky Drummer' drum machine * ; COPYRIGHT: MadLab Ltd. 1998 * ; AUTHOR: James Hutchby * ; UPDATED: 15/01/99 * ;************************************************************************** list p=16C54 ifdef __16C54 include "p16c5x.inc" endif ifdef __16C84 include "p16c84.inc" endif ifdef __16C54 __config _HS_OSC & _WDT_ON & _CP_ON endif ifdef __16C84 __config _HS_OSC & _WDT_ON & _PWRTE_ON & _CP_ON endif __idlocs h'BB10' ;************************************************************************** ; * ; Specification * ; * ;************************************************************************** ; PIC16C54,84 - Osc: HS, WDT: On, PuT: On ; mode button + drum/rhythm/record button changes mode ; drum mode: ; touch switches play drum samples in banks of 4 ; bank button cycles through drum banks ; tempo buttons ignored ; rhythm mode: ; touch switches play rhythms in banks of 4 ; bank button cycles through rhythm banks ; tempo buttons increase or decrease tempo ; LED flashes at start of loop ; record mode: ; metronome click on 4 beats ; touch switches record drum samples in banks of 4 (first 15 only) ; bank button cycles through drum banks ; tempo buttons increase or decrease tempo ; record button stops metronome but user rhythm continues ; records a maximum of 11 user events ;************************************************************************** ; * ; Port assignments * ; * ;************************************************************************** PORTA_IO equ b'0100' ; port A I/O status PORTB_IN equ b'11111111' ; port B IN status PORTB_OUT equ b'00000000' ; port B OUT status ADDR_PORT equ PORTB ; ISD address port #define PLAYL PORTA,0 ; play level #define PLAYE PORTA,3 ; play edge #define RECLED PORTA,2 ; record LED #define LED PORTA,1 ; LED BUTTONS_PORT equ PORTB ; buttons port TOUCH1 equ 3 ; touch switch #1 TOUCH2 equ 2 ; touch switch #2 TOUCH3 equ 1 ; touch switch #3 TOUCH4 equ 0 ; touch switch #4 MODE equ 4 ; mode select DRUM equ 5 ; drum mode RHYTHM equ 6 ; rhythm mode RECORD equ 7 ; record mode SELECT equ 5 ; drum/rhythm bank FAST equ 6 ; faster tempo SLOW equ 7 ; slower tempo ;************************************************************************** ; * ; Constants and timings * ; * ;************************************************************************** CLOCK equ d'4000000' ; processor clock frequency in Hz DEBOUNCE equ d'50' ; ISD debounce period in ms DRUM_BANKS equ d'10' ; number of drum banks RHYTHM_BANKS equ d'3' ; number of rhythm banks TIMER_MASK equ h'1f' ; timer mask TEMPO_MIN equ d'50' ; minimum tempo TEMPO_MAX equ d'3' ; maximum tempo TEMPO_INIT equ d'20' ; initial tempo ;-------------------------------------------------------------------------- ; drum indexes ;-------------------------------------------------------------------------- cblock 0 BEEP ; beep CL_HIHAT ; closed hihat LO_TOM1 ; low tom #1 SNARE1 ; snare #1 BASS1 ; bass #1 OP_HIHAT ; open hihat LO_TOM2 ; low tom #2 SNARE2 ; snare #2 BASS2 ; bass #2 CRASH ; crash cymbal TAIKO ; taiko SNARE3 ; snare #3 BASS3 ; bass #3 HI_TOM3 ; high tom #3 HI_TOM2 ; high tom #2 HI_TOM1 ; high tom #1 SNARE4 ; snare #4 HI_CONGA ; high conga LO_CONGA ; low conga HI_BONGO ; high bongo LO_BONGO ; low bongo TIMPANI ; timpani TIMBALE ; timbale HI_AGOGO ; high agogo LO_AGOGO ; low agogo CHINA ; china cymbal CABASA ; cabasa BRUSH2 ; brush #2 BRUSH1 ; brush #1 SNAP ; snap CLAP ; clap COWBELL ; cowbell TRIANGLE ; triangle GUNSHOT ; gunshot SCRATCH ; scratch WHISTLE ; whistle KALIMBA ; kalimba RIMSHOT ; rimshot CHICKEN ; chicken BUBBLE ; bubble QUIJADA ; quijada endc CLICK equ RIMSHOT ; metronome click ;************************************************************************** ; * ; File register usage * ; * ;************************************************************************** ifdef __16C54 RAM set h'07' endif ifdef __16C84 RAM set h'0c' endif cblock RAM flags ; various flags buttons ; buttons pressed, 0 if none buttons_ ; previous buttons pressed banks ; banks (bits 7-4 = rhythm, bits 3-0 = drum) timer ; tempo timer tempo ; rhythm tempo sustain ; drum sustain rhythm_pnt ; rhythm pointer count ; scratch counter work ; work register buffer ; user rhythm buffer endc cblock buffer rhythm_start ; rhythm start endc buffer_end equ h'1f' ; end of user buffer ; flags MODE_DRUM equ 0 ; drum mode MODE_RHYTHM equ 1 ; rhythm mode MODE_RECORD equ 2 ; record mode SHIFT equ 3 ; set if mode button pressed SHORT equ 4 ; set if minimum sustain event TMR equ 5 ; timer flag ;************************************************************************** ; * ; Macros * ; * ;************************************************************************** routine macro label ; routine label endm table macro label ; define lookup table label addwf PCL endm entry macro value ; define table entry retlw value endm index macro label ; index lookup table call label endm jump macro label ; jump through table goto label endm tstw macro ; test w register iorlw 0 endm movff macro f1,f2 ; move file to file movfw f1 movwf f2 endm movlf macro n,f ; move literal to file movlw n movwf f endm tris_A macro ; tristate port A ifdef __16C54 tris PORTA endif ifdef __16C84 bsf STATUS,RP0 movwf TRISA&h'7f' bcf STATUS,RP0 endif endm tris_B macro ; tristate port B ifdef __16C54 tris PORTB endif ifdef __16C84 bsf STATUS,RP0 movwf TRISB&h'7f' bcf STATUS,RP0 endif endm option_ macro ; set options ifdef __16C54 option endif ifdef __16C84 bsf STATUS,RP0 movwf OPTION_REG&h'7f' bcf STATUS,RP0 endif endm org 0 ;-------------------------------------------------------------------------- ; reset vector ;-------------------------------------------------------------------------- ifdef __16C84 goto main_entry endif ;************************************************************************** ; * ; Lookup tables * ; * ;************************************************************************** ;-------------------------------------------------------------------------- ; message addresses ;-------------------------------------------------------------------------- table address_table msg_ macro addr,mask,bit if addr&mask addr_ |= 1<