Subversion Repositories svn.mios

Rev

Rev 1064 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
102 tk 1
; $Id: seq_trk.inc 1176 2014-07-20 18:50:23Z tk $
97 tk 2
;
3
; MIDIboxSEQ
4
; Functions related to Tracks (Track Names, trigger pin assignments, etc..)
5
;
6
; ==========================================================================
7
;
8
;  Copyright 1998-2006 Thorsten Klose (tk@midibox.org)
9
;  Licensed for personal non-commercial use only.
10
;  All other rights reserved.
11
;
12
; ==========================================================================
13
 
14
	;; the track information table has been defined in form of a macro,
15
	;; which will be included here. It's located in the setup_*.asm file
16
	;; it consists of 16 entries for 16 tracks
17
SEQ_TRK_INFO_TABLE
18
	DEFAULT_TRKINFO
19
 
20
	;; I'm not happy to define the table width at a different place (here):
21
SEQ_TRK_INFO_TABLE_WIDTH EQU 10
22
	;; but the user shouldn't change it in his setup_*.asm file to avoid inconsistencies
23
 
24
SEQ_TRK_INFO_TABLE_OFFSET_NAME	EQU	0
25
SEQ_TRK_INFO_TABLE_OFFSET_SR	EQU	6
26
SEQ_TRK_INFO_TABLE_OFFSET_PIN	EQU	7
27
SEQ_TRK_INFO_TABLE_OFFSET_MPORT	EQU	8
28
SEQ_TRK_INFO_TABLE_OFFSET_ACHN	EQU	9
29
 
30
;; --------------------------------------------------------------------------
31
;;  This function prints the track name
32
;;  IN: track number (0-15) in WREG
33
;;  OUT: 6 characters
34
;; --------------------------------------------------------------------------
35
SEQ_TRK_PrnName
36
	TABLE_ADDR_MUL_W SEQ_TRK_INFO_TABLE, SEQ_TRK_INFO_TABLE_WIDTH
37
	movlw	6
38
	goto	MIOS_LCD_PrintPreconfString
39
 
40
 
41
 
42
;; --------------------------------------------------------------------------
43
;;  This function requests a trigger in SEQ_DRUM_TRIGGERS[01]
44
;;  IN: trigger number (correlates to track number) in WREG
45
;;      velocity (for forwardning to AOUT) in MIOS_PARAMETER1
46
;; --------------------------------------------------------------------------
47
SEQ_TRK_ReqTrigger
145 tk 48
	;; temporary store trigger number in MIOS_PARAMETER2
49
	movwf	MIOS_PARAMETER2
50
 
51
	;; request trigger
97 tk 52
	lfsr	FSR1, SEQ_DRUM_TRIGGERS0	; select register
53
	btfsc	WREG, 3
54
	lfsr	FSR1, SEQ_DRUM_TRIGGERS1
55
	call	MIOS_HLP_GetBitORMask		; get pin mask
56
	iorwf	INDF1, F			; set request flag
145 tk 57
 
58
	;; check for AOUT assignment
59
	movf	MIOS_PARAMETER2, W	; pin number was temporary stored in MIOS_PARAMETER2
60
	TABLE_ADDR_MUL_W SEQ_TRK_INFO_TABLE, SEQ_TRK_INFO_TABLE_WIDTH
61
	movlw	SEQ_TRK_INFO_TABLE_OFFSET_ACHN
62
	addwf	TBLPTRL, F
63
	movlw	0
64
	addwfc	TBLPTRH, F
65
 
66
	tblrd*+
67
	movf	TABLAT, W
68
	bz	SEQ_TRK_ReqTrigger_NoAOUT
69
SEQ_TRK_ReqTrigger_AOUT
1064 tk 70
	decf	TABLAT, W		; check for CV DOUT channel number in range 0..15
71
	andlw	0xf0
72
	bnz	SEQ_TRK_ReqTrigger_CV_Invalid
73
SEQ_TRK_ReqTrigger_CV
74
	lfsr	FSR1, SEQ_CV_DOUT_VALUE1
75
	decf	TABLAT, W		; assigned CV channel number
76
	andlw	0x0f
77
	addwf	FSR1L, F
78
	rrf	MIOS_PARAMETER1, W	; use 6bit resolution
79
	andlw	0x3f
80
	movwf	INDF1
81
SEQ_TRK_ReqTrigger_CV_Invalid
82
 
83
	decf	TABLAT, W		; check for AOUT channel number in range 0..7
84
	andlw	0xf8
85
	bnz	SEQ_TRK_ReqTrigger_AOUT_Invalid
86
	decf	TABLAT, W		; assigned AOUT channel number
145 tk 87
	call	AOUT_Pin7bitSet		; velocity passed in MIOS_PARAMETER1
1064 tk 88
SEQ_TRK_ReqTrigger_AOUT_Invalid
145 tk 89
SEQ_TRK_ReqTrigger_NoAOUT
90
 
97 tk 91
	return
92
 
93
 
94
;; --------------------------------------------------------------------------
95
;;  This function is called from SEQ_CORE_Clk and SEQ_MIDI_NoteOn to update all triggers
120 tk 96
;;  that have been requested at the same moment
97 tk 97
;;  IN: trigger states in SEQ_DRUM_TRIGGERS[01]
98
;;  OUT: SEQ_DRUM_TRIGGERS[01] will be cleared during update
99
;; --------------------------------------------------------------------------
100
SEQ_TRK_SetTriggers
101
	SET_BSR	SEQ_BASE
102
 
120 tk 103
	;; interrupts must be disabled during DOUT update to ensure, that all triggers
104
	;; are set during the same SRIO update cycle
105
	movff	INTCON, PRODH		; store current interrupt status in PRODH
106
	IRQ_DISABLE			; disable IRQs
1176 tk 107
 
108
#if DEFAULT_909LIKE_HH_CONTROL_ENABLED
109
	;; special HH selection logic for 909 like control
110
	movlw	DEFAULT_909LIKE_HH_TRACK_CH - 1
111
	lfsr	FSR1, SEQ_DRUM_TRIGGERS0
112
	btfsc	WREG, 3
113
	incf	FSR1L, F
114
	call	MIOS_HLP_GetBitORMask
115
	andwf	INDF1, W
116
	bz	SEQ_TRK_SetTriggers_909CH_Cont
117
SEQ_TRK_SetTriggers_909CH_1
118
#if DEFAULT_909LIKE_HH_SWITCH_SR
119
	movlw	((DEFAULT_909LIKE_HH_SWITCH_SR-1) << 3) | ((7 - DEFAULT_909LIKE_HH_SWITCH_PIN) & 0x7)
120
	call	MIOS_DOUT_PinSet1
121
#endif
122
SEQ_TRK_SetTriggers_909CH_Cont
123
 
124
	movlw	DEFAULT_909LIKE_HH_TRACK_OH - 1
125
	lfsr	FSR1, SEQ_DRUM_TRIGGERS0
126
	btfsc	WREG, 3
127
	incf	FSR1L, F
128
	call	MIOS_HLP_GetBitORMask
129
	andwf	INDF1, W
130
	bz	SEQ_TRK_SetTriggers_909OH_Cont
131
SEQ_TRK_SetTriggers_909OH_1
132
#if DEFAULT_909LIKE_HH_SWITCH_SR
133
	movlw	((DEFAULT_909LIKE_HH_SWITCH_SR-1) << 3) | ((7 - DEFAULT_909LIKE_HH_SWITCH_PIN) & 0x7)
134
	call	MIOS_DOUT_PinSet0
135
#endif
136
SEQ_TRK_SetTriggers_909OH_Cont
137
 
138
#endif
139
 
120 tk 140
 
97 tk 141
	;; get offset to table
142
	movlw	LOW(SEQ_TRK_INFO_TABLE)
143
	addlw	SEQ_TRK_INFO_TABLE_OFFSET_SR
144
	movwf	TBLPTRL
145
	clrf	TBLPTRH
146
	movlw	HIGH(SEQ_TRK_INFO_TABLE)
147
	addwfc	TBLPTRH, F
148
 
149
	;; go through table and set all requested triggers
150
	clrf	PRODL			; used as loop counter
151
SEQ_TRK_SetTriggersLoop
152
	BRA_IFSET SEQ_DRUM_TRIGGERS0, 0, BANKED, SEQ_TRK_SetTriggersLoop_Req
153
	tblrd*+				; dummy read for SR definition
154
	tblrd*+				; dummy read for pin definition
155
	rgoto	SEQ_TRK_SetTriggersLoop_Next
156
SEQ_TRK_SetTriggersLoop_Req
157
	tblrd*+				; read shift register number
158
	movf	TABLAT, W		; skip if zero
159
	bnz	SEQ_TRK_SetTriggersLoop_Cont
160
	tblrd*+				; dummy read for pin definition
161
	rgoto	SEQ_TRK_SetTriggersLoop_Next
162
SEQ_TRK_SetTriggersLoop_Cont
163
	addlw	-1			; get value of SR
164
	call	MIOS_DOUT_SRGet		; result in MIOS_PARAMETER1 and WREG, pointer to SR in FSR1
165
 
166
	tblrd*+				; read pin number
167
	movf	TABLAT, W
1064 tk 168
	xorlw	0x07			; DOUT pins are mirrored!
97 tk 169
	call	MIOS_HLP_GetBitORMask	; get OR mask
170
	iorwf	INDF1, F		; set bit
171
SEQ_TRK_SetTriggersLoop_Next
172
	clrc				; shift-right request flags
173
	rrf	SEQ_DRUM_TRIGGERS1, F, BANKED
174
	rrf	SEQ_DRUM_TRIGGERS0, F, BANKED
175
	incf	PRODL, F		; next entry?
176
	BRA_IFSET PRODL, 4, ACCESS, SEQ_TRK_SetTriggersLoop_Break
177
	movlw	SEQ_TRK_INFO_TABLE_WIDTH-2
178
	addwf	TBLPTRL, F
179
	movlw	0
180
	addwfc	TBLPTRH, F
181
	rgoto	SEQ_TRK_SetTriggersLoop
182
 
183
SEQ_TRK_SetTriggersLoop_Break
120 tk 184
 
185
	movff	PRODH, INTCON		; restore interrupt status from PRODH
186
 
97 tk 187
	return
188
 
189
 
190
;; --------------------------------------------------------------------------
191
;;  This function is called from USER_SR_ServiceFinish to clear the trigger
192
;;  pins - this simple method allows to generate 1mS pulses, since all pins,
193
;;  which have been set before (e.g. from the main program), will turn low
194
;;  with the next SR update cycle (which is performed 1 mS later)
195
;;
196
;;  Note that this routine is called from an interrupt service routine!
197
;; --------------------------------------------------------------------------
198
SEQ_TRK_ClearTriggers
199
	;; get offset to table
200
	movlw	LOW(SEQ_TRK_INFO_TABLE)
201
	addlw	SEQ_TRK_INFO_TABLE_OFFSET_SR
202
	movwf	TBLPTRL
203
	clrf	TBLPTRH
204
	movlw	HIGH(SEQ_TRK_INFO_TABLE)
205
	addwfc	TBLPTRH, F
206
 
207
	;; go through table and clear all triggers
208
	clrf	IRQ_TMP1		; used as loop counter
209
SEQ_TRK_ClearTriggersLoop
210
	tblrd*+				; read shift register number
211
	movf	TABLAT, W		; skip if zero
212
	bnz	SEQ_TRK_ClearTriggersLoop_Cont
213
	tblrd*+				; dummy read for pin definition
214
	rgoto	SEQ_TRK_ClearTriggersLoop_Next
215
SEQ_TRK_ClearTriggersLoop_Cont
216
	addlw	-1			; get value of SR
217
	call	MIOS_DOUT_SRGet		; result in MIOS_PARAMETER1 and WREG, pointer to SR in FSR1
218
 
219
	tblrd*+				; read pin number
220
	movf	TABLAT, W
1064 tk 221
	xorlw	0x07			; DOUT pins are mirrored!
97 tk 222
	call	MIOS_HLP_GetBitANDMask	; get AND mask
223
	andwf	INDF1, F		; clear bit
224
SEQ_TRK_ClearTriggersLoop_Next
225
 
226
	incf	IRQ_TMP1, F		; next entry?
227
	BRA_IFSET IRQ_TMP1, 4, ACCESS, SEQ_TRK_ClearTriggersLoop_Break
228
	movlw	SEQ_TRK_INFO_TABLE_WIDTH-2
229
	addwf	TBLPTRL, F
230
	movlw	0
231
	addwfc	TBLPTRH, F
232
	rgoto	SEQ_TRK_ClearTriggersLoop
233
 
234
SEQ_TRK_ClearTriggersLoop_Break
235
	return
236
 
237
 
238
;; --------------------------------------------------------------------------
239
;;  This function returns the MIDI port of a given track
240
;;  IN: track number in WREG
241
;;  OUT: port number + 1 in WREG (if 0: port disabled by user)
242
;; --------------------------------------------------------------------------
243
SEQ_TRK_GetMIDIPort
244
	TABLE_ADDR_MUL_W SEQ_TRK_INFO_TABLE, SEQ_TRK_INFO_TABLE_WIDTH
245
	movlw	SEQ_TRK_INFO_TABLE_OFFSET_MPORT
246
	addwf	TBLPTRL, F
247
	movlw	0
248
	addwfc	TBLPTRH, F
249
 
250
	tblrd*+
251
	movf	TABLAT, W
252
	andlw	0xff		; (fix ZERO flag)
253
	return
254
 
255
 
1064 tk 256
;; --------------------------------------------------------------------------
257
;;  This function is called periodically by USER_SR_ServicePrepare to
258
;;  transfer CV channel values to DOUT registers
259
;; --------------------------------------------------------------------------
260
SEQ_TRK_CV_DOUT_Update
261
 
262
	;; help macro
263
SEQ_TRK_CV_DOUT_Update_SR MACRO cv, DOUT_SR
264
  IF DOUT_SR && DOUT_SR <= 16
265
	movlw	DOUT_SR-1
266
	call	MIOS_DOUT_SRGet
267
	andlw	0xc0
268
	SET_BSR	SEQ_BASE
269
	iorwf	SEQ_CV_DOUT_VALUE1+cv, W, BANKED
270
	movwf	MIOS_PARAMETER1
271
	movlw	DOUT_SR-1
272
	call	MIOS_DOUT_SRSet
273
  ENDIF
274
	ENDM
275
 
276
 
277
	SEQ_TRK_CV_DOUT_Update_SR 0, DEFAULT_CV_DOUT_SR1
278
	SEQ_TRK_CV_DOUT_Update_SR 1, DEFAULT_CV_DOUT_SR2
279
	SEQ_TRK_CV_DOUT_Update_SR 2, DEFAULT_CV_DOUT_SR3
280
	SEQ_TRK_CV_DOUT_Update_SR 3, DEFAULT_CV_DOUT_SR4
281
	SEQ_TRK_CV_DOUT_Update_SR 4, DEFAULT_CV_DOUT_SR5
282
	SEQ_TRK_CV_DOUT_Update_SR 5, DEFAULT_CV_DOUT_SR6
283
	SEQ_TRK_CV_DOUT_Update_SR 6, DEFAULT_CV_DOUT_SR7
284
	SEQ_TRK_CV_DOUT_Update_SR 7, DEFAULT_CV_DOUT_SR8
285
	SEQ_TRK_CV_DOUT_Update_SR 8, DEFAULT_CV_DOUT_SR9
286
	SEQ_TRK_CV_DOUT_Update_SR 9, DEFAULT_CV_DOUT_SR10
287
	SEQ_TRK_CV_DOUT_Update_SR 10, DEFAULT_CV_DOUT_SR11
288
	SEQ_TRK_CV_DOUT_Update_SR 11, DEFAULT_CV_DOUT_SR12
289
	SEQ_TRK_CV_DOUT_Update_SR 12, DEFAULT_CV_DOUT_SR13
290
	SEQ_TRK_CV_DOUT_Update_SR 13, DEFAULT_CV_DOUT_SR14
291
	SEQ_TRK_CV_DOUT_Update_SR 14, DEFAULT_CV_DOUT_SR15
292
	SEQ_TRK_CV_DOUT_Update_SR 15, DEFAULT_CV_DOUT_SR16
293
 
294
	return