Subversion Repositories svn.mios

Rev

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

Rev Author Line No. Line
44 tk 1
; $Id: cs_menu_ms.inc 44 2008-01-30 21:39:30Z tk $
1 tk 2
;
3
; SID Control Surface Master/Slave SID Functions
4
;
5
; ==========================================================================
6
;
7
;  Copyright 1998-2007 Thorsten Klose (tk@midibox.org)
8
;  Licensed for personal non-commercial use only.
9
;  All other rights reserved.
10
;
11
; ==========================================================================
12
 
13
;; --------------------------------------------------------------------------
14
;;  Determines the current SID number depending on the selected SIDs
15
;;  Result in WREG and CS_MENU_SID
16
;; --------------------------------------------------------------------------
17
CS_MENU_MS_GetSIDNumber
18
	;; set CS_MENU_SID depending on first selected SID
19
	movlw	0x03
20
	btfsc	CS_MENU_SELECTED_SID_FLAGS, 2
21
	movlw	0x02
22
	btfsc	CS_MENU_SELECTED_SID_FLAGS, 1
23
	movlw	0x01
24
	btfsc	CS_MENU_SELECTED_SID_FLAGS, 0
25
	movlw	0x00
26
	movwf	CS_MENU_SID
27
	andlw	0xff		; (fix ZERO flag)
28
	return
29
 
30
 
31
;; --------------------------------------------------------------------------
32
;;  This function updates the SID_EDIT_BUFFER if it is owned by the master
33
;;  (used after SysEx patch writes)
34
;; --------------------------------------------------------------------------
35
CS_MENU_MS_UpdateEditBufferMS
36
	movf	CS_MENU_EDIT_BUFFER_SID, W
37
	bz	CS_MENU_MS_UpdateEditBufferNow
38
	return
39
 
40
;; --------------------------------------------------------------------------
41
;;  This function updates the SID_EDIT_BUFFER if the selected SID has
42
;;  changed - it is called whenever SID1/SID2/SID3/SID4 button is pressed
43
;; --------------------------------------------------------------------------
44
CS_MENU_MS_UpdateEditBuffer
45
	call	CS_MENU_MS_GetSIDNumber
46
	xorwf	CS_MENU_EDIT_BUFFER_SID, W
47
	skpnz
48
	return
49
 
50
	;; store new SID number
51
	movff	CS_MENU_SID, CS_MENU_EDIT_BUFFER_SID
52
 
53
CS_MENU_MS_UpdateEditBufferNow
54
	;; transfer patch into buffer
55
	;; master: copy SID_PATCH_BUFFER to SID_EDIT_BUFFER
56
	;; slave: request and transfer patch content via CAN
57
	movf	CS_MENU_SID, W
58
	bnz	CS_MENU_MS_UpdateEditBuffer_S
59
CS_MENU_MS_UpdateEditBuffer_M
60
	;; get base address of edit and patch buffer
61
	lfsr	FSR0, SID_EDIT_BUFFER
62
	lfsr	FSR1, SID_PATCH_BUFFER
63
	;; copy 0x200 bytes (prepared for MBSID V2)
64
	clrf	PRODL
65
	clrf	PRODH
66
CS_MENU_MS_UpdateEditBuffer_ML
67
	movff	POSTINC1, POSTINC0
68
	incf	PRODL, F
69
	skpnz
70
	incf	PRODH, F
71
	BRA_IFCLR PRODH, 1, ACCESS, CS_MENU_MS_UpdateEditBuffer_ML
72
 
73
	;; transfer local ensemble setup into buffer
74
	call	SID_ENS_LocalSetupIntoBuffer
75
 
76
	rgoto	CS_MENU_MS_UpdateEditBufferEnd
77
 
78
CS_MENU_MS_UpdateEditBuffer_S
79
  	call	CS_MENU_MBNET_Tx_GetPatch
80
 	call	CS_MENU_MBNET_Tx_GetEns
81
 
82
CS_MENU_MS_UpdateEditBufferEnd
83
	;; request display update
84
	bsf	CS_STAT, CS_STAT_DISPLAY_UPDATE_REQ
85
 
86
	;; if in main page: force complete re-initialization
87
	btfsc	CS_MENU, 7
88
	bsf	CS_STAT, CS_STAT_DISPLAY_INIT_REQ
89
	return
90
 
91
 
92
;; --------------------------------------------------------------------------
93
;;  This function updates the SID_ENS_BUFFER depending on CS_MENU_EDIT_BUFFER_SID
94
;; --------------------------------------------------------------------------
95
CS_MENU_MS_UpdateEnsBuffer
96
	movf	CS_MENU_EDIT_BUFFER_SID, W
97
	movwf	CS_MENU_SID
98
	bnz	CS_MENU_MS_UpdateEnsBuffer_S
99
 
100
CS_MENU_MS_UpdateEnsBuffer_M
101
	;; transfer local ensemble setup into buffer
102
	goto	SID_ENS_LocalSetupIntoBuffer
103
 
104
CS_MENU_MS_UpdateEnsBuffer_S
105
	goto	CS_MENU_MBNET_Tx_GetEns
106
 
107
 
108
;; --------------------------------------------------------------------------
109
;;  A parameter should be sent
110
;;  value in INDF0, pointer to parameter is FSR0-SID_EDIT_BUFFER
111
;; --------------------------------------------------------------------------
112
CS_MENU_MS_SendParameter
113
	;; branch depending on selected SID
114
	movf	CS_MENU_SID, W
115
	bnz	CS_MENU_MS_SendParameter_Slave
116
 
117
CS_MENU_MS_SendParameter_Master
118
 
119
	;; calc pointer to patch buffer
120
	movff	FSR0L, FSR1L
121
	movf	FSR0H, W
122
	addlw	HIGH(SID_PATCH_BUFFER)-HIGH(SID_EDIT_BUFFER)
123
	movwf	FSR1H
124
 
125
	;; copy value to patch buffer
126
	movff	INDF0, INDF1
127
 
128
	;; copy to shadowed patch buffer
129
	movlw	HIGH(SID_PATCH_BUFFER_SHADOW)-HIGH(SID_PATCH_BUFFER)
130
	addwf	FSR1H, F
131
	movff	INDF0, INDF1
132
CS_MENU_MS_SendParameter_MasterE
133
	return
134
 
135
 
136
CS_MENU_MS_SendParameter_Slave
137
	;; send parameter to slave via CAN
138
	movff	FSR0L, MIOS_PARAMETER1	; low byte
139
	movf	FSR0H, W		; high byte
140
	addlw	0-HIGH(SID_EDIT_BUFFER)
141
	movwf	MIOS_PARAMETER2
142
	movf	INDF0, W		; value in WREG
143
	call	CS_MENU_MBNET_Tx_SendPar	; send parameter to slave
144
	return
145
 
146
 
147
;; --------------------------------------------------------------------------
148
;;  An ensemble parameter should be sent
149
;;  IN: value in INDF0
150
;;      pointer to edit parameter (SID_ENS_BUFFER + SID_ENSx_*) in FSR0
151
;; --------------------------------------------------------------------------
152
CS_MENU_MS_SendEnsParameter
153
	;; branch depending on selected SID
154
	movf	CS_MENU_SID, W
155
	bnz	CS_MENU_MS_SendEnsParameter_S
156
 
157
CS_MENU_MS_SendEnsParameter_M
158
	;; just update all parameters (it's fast enough)
159
	goto	SID_ENS_Init_Local
160
 
161
CS_MENU_MS_SendEnsParameter_S
162
	;; send parameter to slave via CAN
163
	movlw	0-LOW(SID_ENS_BUFFER)
164
	addwf	FSR0L, W
165
	movwf	MIOS_PARAMETER1		; address
166
	movf	INDF0, W		; value in WREG
167
	goto	CS_MENU_MBNET_Tx_SendEPar ; send parameter to slave
168
 
169
 
170
;; --------------------------------------------------------------------------
171
;;  A knob value should be sent
172
;;  IN: value in INDF0
173
;;      knob number in CS_MENU_PARAMETER_IX
174
;; --------------------------------------------------------------------------
175
CS_MENU_MS_SendKnob
176
	;; branch depending on selected SID
177
	movf	CS_MENU_SID, W
178
	bnz	CS_MENU_MS_SendKnob_Slave
179
 
180
CS_MENU_MS_SendKnob_Master
181
	;; forward to knob handler
182
	movff	INDF0, MIOS_PARAMETER1
183
	movf	CS_MENU_PARAMETER_IX, W
184
	call	SID_KNOB_SetValue
185
	;; continue with CC sending routine
186
	rgoto	CS_MENU_MS_SendKnob_CC
187
 
188
CS_MENU_MS_SendKnob_Slave
189
	;; send knob value to slave via CAN
190
	movff	CS_MENU_PARAMETER_IX, MIOS_PARAMETER1	; knob number
191
	movf	INDF0, W	; value in WREG
192
	call	CS_MENU_MBNET_Tx_SendKnob
193
	;; 	rgoto	CS_MENU_MS_SendKnob_CC
194
 
195
 
196
CS_MENU_MS_SendKnob_CC
197
	;; skip if CC mode not activated
198
	btfss	CS_MENU_MODE, CS_MENU_MODE_CC
199
	return
200
 
201
	;; select MIDI channel -> FSR1
202
	lfsr	FSR1, CS_MENU_SID_M_CHN
203
	movf	CS_MENU_SID, W
204
	addwf	FSR1L, F
205
 
206
	;; branch depending on knob number
207
	movf	CS_MENU_PARAMETER_IX, W
208
	andlw	0x07
209
	JUMPTABLE_2BYTES_UNSECURE
210
	rgoto	CS_MENU_MS_SendKnob_CC_1
211
	rgoto	CS_MENU_MS_SendKnob_CC_2
212
	rgoto	CS_MENU_MS_SendKnob_CC_3
213
	rgoto	CS_MENU_MS_SendKnob_CC_4
214
	rgoto	CS_MENU_MS_SendKnob_CC_5
215
	rgoto	CS_MENU_MS_SendKnob_CC_V
216
	rgoto	CS_MENU_MS_SendKnob_CC_P
217
	rgoto	CS_MENU_MS_SendKnob_CC_A
218
 
219
CS_MENU_MS_SendKnob_CC_1
220
	movlw	0x01		; send ModWheel
221
CS_MENU_MS_SendKnob_CC_Cont
222
	movwf	PRODL		; store CC number in PRODL
223
 
224
	movf	INDF1, W	; status byte (pointer to channel in FSR1)
225
	andlw	0x0f
226
	iorlw	0xb0
227
	call	MIOS_MIDI_TxBufferPut
228
 
229
	movf	PRODL, W	; CC number
230
	call	MIOS_MIDI_TxBufferPut
231
 
232
	rrf	INDF0, W	; 7bit value
233
	andlw	0x7f
234
	goto	MIOS_MIDI_TxBufferPut
235
 
236
 
237
CS_MENU_MS_SendKnob_CC_2
238
	movlw	0x10		; send CC#16
239
	rgoto	CS_MENU_MS_SendKnob_CC_Cont
240
CS_MENU_MS_SendKnob_CC_3
241
	movlw	0x11		; send CC#17
242
	rgoto	CS_MENU_MS_SendKnob_CC_Cont
243
CS_MENU_MS_SendKnob_CC_4
244
	movlw	0x12		; send CC#18
245
	rgoto	CS_MENU_MS_SendKnob_CC_Cont
246
CS_MENU_MS_SendKnob_CC_5
247
	movlw	0x13		; send CC#19
248
	rgoto	CS_MENU_MS_SendKnob_CC_Cont
249
CS_MENU_MS_SendKnob_CC_V
250
	return			; ignore velocity
251
CS_MENU_MS_SendKnob_CC_P
252
	movf	INDF1, W	; status byte (pointer to channel in FSR1)
253
	andlw	0x0f
254
	iorlw	0xe0
255
	call	MIOS_MIDI_TxBufferPut
256
 
257
	movlw	0x00		; LSB
258
	btfsc	INDF0, 0
259
	movlw 0x40
260
	call	MIOS_MIDI_TxBufferPut
261
 
262
	rrf	INDF0, W	; MSBs
263
	andlw	0x7f
264
	goto	MIOS_MIDI_TxBufferPut
265
 
266
CS_MENU_MS_SendKnob_CC_A
267
	return			; ignore aftertouch
268
 
269
 
270
;; --------------------------------------------------------------------------
271
;;  A knob value should be updated (e.g. based on new Min/Max boundary)
272
;;  IN: knob number in WREG
273
;; --------------------------------------------------------------------------
274
CS_MENU_MS_UpdateKnob
275
	;; store knob number in MIOS_PARAMETER1
276
	movwf	MIOS_PARAMETER1
277
 
278
	;; branch depending on selected SID
279
	movf	CS_MENU_SID, W
280
	bnz	CS_MENU_MS_UpdateKnob_Slave
281
 
282
CS_MENU_MS_UpdateKnob_Master
283
	;; just get&set value, this will calculate the new modulation result
284
	movf	CS_MENU_SELECTED_KNOB, W
285
	goto	SID_KNOB_UpdateValue
286
 
287
CS_MENU_MS_UpdateKnob_Slave
288
	;; request update via CAN
289
	;; (expects knob number in MIOS_PARAMETER1)
290
	goto	CS_MENU_MBNET_Tx_UpdateKnob
291
 
292
 
293
;; --------------------------------------------------------------------------
294
;;  Updates the shadow buffer - should be used when WT/Knob assignments are
295
;;  changed
296
;; --------------------------------------------------------------------------
297
CS_MENU_MS_UpdateShadow
298
	;; branch depending on selected SID
299
	movf	CS_MENU_SID, W
300
	bnz	CS_MENU_MS_UpdateShadow_Slave
301
 
302
CS_MENU_MS_UpdateShadow_Master
303
	;; use local update routine
304
	goto	SID_PATCH_UpdateShadowBuffer
305
 
306
CS_MENU_MS_UpdateShadow_Slave
307
	;; request update via CAN
308
	goto	CS_MENU_MBNET_Tx_UpdateShadow
309
 
310
 
311
;; --------------------------------------------------------------------------
312
;;  If update of all parameters has been requested
313
;;  expecting SID number in CS_MENU_SID
314
;; --------------------------------------------------------------------------
315
CS_MENU_MS_UpdateAllParameters
316
	;; send dump
317
	rcall	CS_MENU_MS_Send_SysExDump
318
 
319
	;; force a display update
320
	bsf	CS_STAT, CS_STAT_DISPLAY_UPDATE_REQ
321
 
322
	;; if in main page: force complete re-initialization
323
	btfsc	CS_MENU, 7
324
	bsf	CS_STAT, CS_STAT_DISPLAY_INIT_REQ
325
 
326
	return
327
 
328
 
329
;; --------------------------------------------------------------------------
330
;;  some util routines for the SID_PATCH and SID_BANK handling
331
;; --------------------------------------------------------------------------
332
	;; set SID_PATCH/BANK to patch/bank number of current selected SID
333
	;; doesn't overwrite WREG!
334
CS_MENU_MS_SetSIDPatch_C
335
	;; branch depending on selected SID
336
	BRA_IFSET CS_MENU_SID, 1, ACCESS, CS_MENU_MS_SetSIDPatch_C_23
337
 
338
CS_MENU_MS_SetSIDPatch_C_01
339
	BRA_IFSET CS_MENU_SID, 0, ACCESS, CS_MENU_MS_SetSIDPatch_C_1
340
CS_MENU_MS_SetSIDPatch_C_0
341
	movff	CS_MENU_SID_M_PATCH, SID_PATCH
342
	movff	CS_MENU_SID_M_BANK, SID_BANK
343
	rgoto	CS_MENU_MS_SetSIDPatch_C_End
344
CS_MENU_MS_SetSIDPatch_C_1
345
	movff	CS_MENU_SID_S1_PATCH, SID_PATCH
346
	movff	CS_MENU_SID_S1_BANK, SID_BANK
347
	rgoto	CS_MENU_MS_SetSIDPatch_C_End
348
 
349
CS_MENU_MS_SetSIDPatch_C_23
350
	BRA_IFSET CS_MENU_SID, 0, ACCESS, CS_MENU_MS_SetSIDPatch_C_3
351
CS_MENU_MS_SetSIDPatch_C_2
352
	movff	CS_MENU_SID_S2_PATCH, SID_PATCH
353
	movff	CS_MENU_SID_S2_BANK, SID_BANK
354
	rgoto	CS_MENU_MS_SetSIDPatch_C_End
355
CS_MENU_MS_SetSIDPatch_C_3
356
	movff	CS_MENU_SID_S3_PATCH, SID_PATCH
357
	movff	CS_MENU_SID_S3_BANK, SID_BANK
358
	rgoto	CS_MENU_MS_SetSIDPatch_C_End
359
 
360
CS_MENU_MS_SetSIDPatch_C_End
361
	;; mask out 'sent' flag
362
	bcf	SID_PATCH, 7
363
	return
364
 
365
 
366
	;; set SID_BANK to patch number of master SID
367
	;; doesn't overwrite WREG!
368
CS_MENU_MS_SetSIDPatch_M
369
	movff	CS_MENU_SID_M_PATCH, SID_PATCH
370
	movff	CS_MENU_SID_M_BANK, SID_BANK
371
	;; mask out 'sent' flag
372
	bcf	SID_PATCH, 7
373
	return
374
 
375
	;; get patch number of current selected SID
376
	;; uses FSR1!
377
CS_MENU_MS_GetSIDPatch
378
	lfsr	FSR1, CS_MENU_SID_M_PATCH
379
	movf	CS_MENU_SID, W
380
	addwf	FSR1L, F
381
	movf	INDF1, W
382
	andlw	0x7f
383
	return
384
 
385
	;; get bank number of current selected SID
386
	;; uses FSR1!
387
CS_MENU_MS_GetSIDBank
388
	lfsr	FSR1, CS_MENU_SID_M_BANK
389
	movf	CS_MENU_SID, W
390
	addwf	FSR1L, F
391
	movf	INDF1, W
392
	andlw	0x07
393
	return
394
 
395
;; --------------------------------------------------------------------------
396
;;  This function is called to forward a Program Change event to the control surface
397
;;  Input:
398
;;     o midi channel in SID_CURRENT_CHANNEL
399
;;     o patch number in SID_MIDI_PARAMETER1
400
;; --------------------------------------------------------------------------
401
CS_MENU_MS_NotifyProgramChange
402
	;; request patch send to SIDs with matching channel number
403
	SET_BSR	SID_BASE
404
	clrf	PRODL			; PRODL used as counter
405
CS_MENU_MS_NotifyProgramChangeL
406
	;; calc pointer to channel entry
407
	lfsr	FSR0, CS_MENU_SID_M_CHN
408
	movf	PRODL, W
409
	addwf	FSR0L, F
410
 
411
	;; check if channel number matches
412
	movf	INDF0, W
413
	xorwf	SID_CURRENT_CHANNEL, W, BANKED
414
	andlw	0x0f
415
	bnz	CS_MENU_MS_NotifyProgramChangeLN
416
	;; check if patch number matches (in this case don't change the patch)
417
	movlw	(CS_MENU_SID_M_PATCH-CS_MENU_SID_M_CHN) & 0xff
418
	addwf	FSR0L, F
419
	movf	SID_MIDI_PARAMETER1, W
420
	xorwf	INDF0, W
421
	andlw	0x7f
422
	bz	CS_MENU_MS_NotifyProgramChangeLN
423
	;; store patch number
424
	movff	SID_MIDI_PARAMETER1, INDF0
425
	;; skip if patch change already requested
426
	movlw	(CS_MENU_TX_M_CTR-CS_MENU_SID_M_PATCH) & 0xff
427
	addwf	FSR0L, F
428
	BRA_IFSET INDF0, 7, ACCESS, CS_MENU_MS_NotifyProgramChangeLN
429
	;; request patch change
430
	movlw	0x81
431
	movwf	INDF0
432
CS_MENU_MS_NotifyProgramChangeLN
433
	incf	PRODL, F
434
	BRA_IFCLR PRODL, 2, ACCESS, CS_MENU_MS_NotifyProgramChangeL
435
 
436
	return
437
 
438
 
439
;; --------------------------------------------------------------------------
440
;;  This function is called to forward a Bank Change event to the control surface
441
;;  Input:
442
;;     o midi channel in SID_CURRENT_CHANNEL
443
;;     o bank number in SID_MIDI_PARAMETER2
444
;; --------------------------------------------------------------------------
445
CS_MENU_MS_NotifyBankChange
446
	;; request patch send to SIDs with matching channel number
447
	SET_BSR	SID_BASE
448
	clrf	PRODL			; PRODL used as counter
449
CS_MENU_MS_NotifyBankChangeL
450
	;; calc pointer to channel entry
451
	lfsr	FSR0, CS_MENU_SID_M_CHN
452
	movf	PRODL, W
453
	addwf	FSR0L, F
454
 
455
	;; check if channel number matches
456
	movf	INDF0, W
457
	xorwf	SID_CURRENT_CHANNEL, W, BANKED
458
	andlw	0x0f
459
	bnz	CS_MENU_MS_NotifyBankChangeLN
460
	;; check if bank number matches (in this case don't change the patch)
461
	movlw	(CS_MENU_SID_M_BANK-CS_MENU_SID_M_CHN) & 0xff
462
	addwf	FSR0L, F
463
	movf	SID_MIDI_PARAMETER2, W
464
	xorwf	INDF0, W
465
	andlw	0x07
466
	bz	CS_MENU_MS_NotifyBankChangeLN
467
	;; store bank number
468
	movf	SID_MIDI_PARAMETER2, W
469
	andlw	0x07
470
	movwf	INDF0
471
 
472
	movlw	(CS_MENU_SID_M_PATCH-CS_MENU_SID_M_BANK) & 0xff
473
	addwf	FSR0L, F	; clear 'sent' flag of patch
474
	bcf	INDF0, 7
475
	;; skip if patch change already requested
476
	movlw	(CS_MENU_TX_M_CTR-CS_MENU_SID_M_PATCH) & 0xff
477
	addwf	FSR0L, F
478
	BRA_IFSET INDF0, 7, ACCESS, CS_MENU_MS_NotifyBankChangeLN
479
	;; request bank/patch change
480
	movlw	0x81
481
	movwf	INDF0
482
CS_MENU_MS_NotifyBankChangeLN
483
	incf	PRODL, F
484
	BRA_IFCLR PRODL, 2, ACCESS, CS_MENU_MS_NotifyBankChangeL
485
 
486
	return
487
 
488
 
489
;; --------------------------------------------------------------------------
490
;;  this function sends the edit buffer to the SID selected by CS_MENU_SID
491
;; --------------------------------------------------------------------------
492
CS_MENU_MS_Send_EditBuffer
493
	;; branch depending on master/slave SID
494
	movf	CS_MENU_SID, W
495
	bnz	CS_MENU_MS_Send_EditBuffer_S
496
 
497
CS_MENU_MS_Send_EditBuffer_M
498
	;; local SID: copy edit buffer into SID_PATCH_BUFFER and shadow buffer
499
	lfsr	FSR0, SID_EDIT_BUFFER
500
	lfsr	FSR1, SID_PATCH_BUFFER
501
	lfsr	FSR2, SID_PATCH_BUFFER_SHADOW
502
	movlw	2
503
	movwf	PRODL
504
CS_MENU_MS_Send_EditBuffer_MLoop
505
	movff	INDF0, POSTINC1
506
	movff	POSTINC0, POSTINC2
507
	movf	FSR0L, W
508
	bnz	CS_MENU_MS_Send_EditBuffer_MLoop
509
	decfsz	PRODL, F
510
	rgoto	CS_MENU_MS_Send_EditBuffer_MLoop
511
 
512
	;; init patch and exit
513
	goto	SID_PATCH_Init
514
 
515
 
516
CS_MENU_MS_Send_EditBuffer_S
517
	goto	CS_MENU_MBNET_Tx_SendEdit	; sends the edit buffer
518
 
519
 
520
;; --------------------------------------------------------------------------
521
;;  this function sends the edit buffer to all selected SIDs
522
;; --------------------------------------------------------------------------
523
CS_MENU_MS_Send_EditBufferAll
524
	clrf	CS_MENU_SID
525
CS_MENU_MS_Send_EditBufferAllLp
526
	movf	CS_MENU_SID, W
527
	call	MIOS_HLP_GetBitORMask
528
	andwf	CS_MENU_SELECTED_SID_FLAGS, W
529
	bz	CS_MENU_MS_Send_EditBufferAllLpN
530
	rcall	CS_MENU_MS_Send_EditBuffer
531
CS_MENU_MS_Send_EditBufferAllLpN
532
	incf	CS_MENU_SID, F
533
	BRA_IFCLR CS_MENU_SID, 2, ACCESS, CS_MENU_MS_Send_EditBufferAllLp
534
 
535
	;; get back old CS_MENU_SID and exit
536
	rgoto	CS_MENU_MS_GetSIDNumber
537
 
538
 
539
;; --------------------------------------------------------------------------
540
;;  this function sends the whole patch to the SID which is
541
;;  selected by CS_MENU_SID
542
;; --------------------------------------------------------------------------
543
CS_MENU_MS_Send_SysExDump
544
	;; TODO: needs to be overworked
545
	;; should use CS_MENU_MS_Send_EditBuffer!!!
546
 
547
	;; check TX counter, if > 6, delay the sending
548
	;; this register is decremented by cs_menu_timer.inc every 100 ms
549
	lfsr	FSR1, CS_MENU_TX_M_CTR
550
	movf	CS_MENU_SID, W
551
	addwf	FSR1L, F
552
 
553
	;; if counter != 0, request delayed TX of dump and exit
554
	movf	INDF1, W
555
	skpz
556
	rgoto	CS_MENU_MS_Send_SysExDump_TxReq
557
 
558
	;; branch depending on master/slave SID
559
	movf	CS_MENU_SID, W
560
	bnz	CS_MENU_MS_Send_SysExDump_S
561
 
562
CS_MENU_MS_Send_SysExDump_M
563
	;; reload TX counter
564
	movlw	0x01
565
	movwf	INDF1
566
 
567
	;; skip if 'sent' flag set
568
	BRA_IFSET CS_MENU_SID_M_PATCH, 7, ACCESS, CS_MENU_MS_Send_SysExDump_End
569
 
570
	;; store patch/bank number of master in SID_PATCH/SID_BANK
571
	movff	CS_MENU_SID_M_PATCH, SID_PATCH
572
	movff	CS_MENU_SID_M_BANK, SID_BANK
573
 
574
	bsf	CS_MENU_SID_M_PATCH, 7	; set 'sent' flag
575
 
576
	;; transfer EEPROM content into SID patch buffer and init patch
577
	call	SID_PATCH_LoadPatchBuffer
578
 
579
	;; restore CS_MENU_SID
580
	rgoto	CS_MENU_MS_Send_SysExDump_End
581
 
582
CS_MENU_MS_Send_SysExDump_S
583
	;; else send dump of current patch to slave SID
584
 
585
	;; reload TX counter
586
	movlw	0x06
587
	movwf	INDF1
588
 
589
	;; skip send patch if 'sent' flag set
590
	lfsr	FSR1, CS_MENU_SID_M_PATCH
591
	movf	CS_MENU_SID, W
592
	BRA_IFSET PLUSW1, 7, ACCESS, CS_MENU_MS_Send_SysExDump_End
593
	bsf	PLUSW1, 7	; set 'sent' flag
594
 
595
	;; disable SID engine of slave
596
	call	CS_MENU_MBNET_Tx_DisableEngine
597
 
598
	;; send patch to slave
599
	call	CS_MENU_MS_SetSIDPatch_C	; prepares SID_PATCH and SID_BANK
600
	call	CS_MENU_MBNET_Tx_SendPatch	; sends the patch
601
 
602
CS_MENU_MS_Send_SysExDump_End
603
	return
604
 
605
 
606
;; --------------------------------------------------------------------------
607
	;; request delayed TX of dump and exit
608
CS_MENU_MS_Send_SysExDump_TxReq
609
	lfsr	FSR1, CS_MENU_TX_M_CTR
610
	movf	CS_MENU_SID, W
611
	addwf	FSR1L, F	; no delay
612
	movlw	0x80
613
	movwf	INDF1
614
	return
615
 
616
	;; check if transfer can be granted
617
CS_MENU_MS_Send_SysExDump_TxTst
618
	clrf	CS_MENU_SID		; handle all 4 SIDs
619
CS_MENU_MS_Send_SysExDump_TxTstL
620
	lfsr	FSR1, CS_MENU_TX_M_CTR
621
	movf	CS_MENU_SID, W
622
	addwf	FSR1L, F
623
 
624
	;; skip if CTR[7] not set (no sync requested)
625
	BRA_IFCLR INDF1, 7, ACCESS, CS_MENU_MS_Send_SysExDump_TxTstN
626
 
627
	;; skip if CTR[6..0] is != 0
628
	movf	INDF1, W
629
	andlw	0x7f
630
	bnz	CS_MENU_MS_Send_SysExDump_TxTstN
631
 
632
	;; else clear request
633
	bcf	INDF1, 7
634
 
635
	;; and update parameters
636
	rcall	CS_MENU_MS_UpdateAllParameters
637
 
638
CS_MENU_MS_Send_SysExDump_TxTstN
639
	incf	CS_MENU_SID, F		; loop 4 times
640
	BRA_IFCLR CS_MENU_SID, 2, ACCESS, CS_MENU_MS_Send_SysExDump_TxTstL
641
 
642
	return
643
 
644
;; --------------------------------------------------------------------------
645
;;  this routine is used when a note should be played on a given SID
646
;;  It's only used by CS_MENU_BUTTON_Exec when a SIDx button is hold
647
;;  and the menu button is pressed
648
;;  Note On/Off status will be toggled each time this function is executed
649
;;  IN: SID number in WREG (will be stored in CS_MENU_SID)
650
;; --------------------------------------------------------------------------
651
CS_MENU_MS_PlayNote
652
	movwf	CS_MENU_SID
653
 
654
	;; toggle play state which is stored in CS_STAT2
655
	call	MIOS_HLP_GetBitORMask
656
	swapf	WREG, W
657
	andlw	0xf0
658
	movwf	TMP2
659
 
660
	IRQ_DISABLE		; must be atomic since the IRQ handler modifies this register
661
	movf	CS_STAT2, W
662
	xorwf	TMP2, W
663
	movwf	CS_STAT2
664
	IRQ_ENABLE
665
 
666
	;; branch to Note On/Off function
667
	movf	CS_MENU_SID, W
668
	call	MIOS_HLP_GetBitORMask
669
	swapf	WREG, W
670
	andwf	CS_STAT2, W
671
	bz	CS_MENU_MS_PlayNoteOff
672
CS_MENU_MS_PlayNoteOn
673
	rgoto	CS_MENU_MS_NotesOn
674
CS_MENU_MS_PlayNoteOff
675
	rgoto	CS_MENU_MS_NotesOff
676
 
677
 
678
;; --------------------------------------------------------------------------
679
;;  All Notes On command
680
;; --------------------------------------------------------------------------
681
CS_MENU_MS_NotesOn
682
	;; branch depending on selected SID
683
	movf	CS_MENU_SID, W
684
	bnz	CS_MENU_MS_NotesOn_Slave
685
 
686
CS_MENU_MS_NotesOn_Master
687
	;; use local routine
688
	goto	SID_PATCH_NotesOn
689
 
690
CS_MENU_MS_NotesOn_Slave
691
	;; request notes off via CAN
692
	goto	CS_MENU_MBNET_Tx_NotesOn
693
 
694
 
695
;; --------------------------------------------------------------------------
696
;;  All Notes Off command
697
;; --------------------------------------------------------------------------
698
CS_MENU_MS_NotesOff
699
	;; branch depending on selected SID
700
	movf	CS_MENU_SID, W
701
	bnz	CS_MENU_MS_NotesOff_Slave
702
 
703
CS_MENU_MS_NotesOff_Master
704
	;; use local routine
705
	goto	SID_PATCH_NotesOff
706
 
707
CS_MENU_MS_NotesOff_Slave
708
	;; request notes off via CAN
709
	goto	CS_MENU_MBNET_Tx_NotesOff
710
 
711
 
712
;; --------------------------------------------------------------------------
713
;;  Voice Reinit command
714
;; --------------------------------------------------------------------------
715
CS_MENU_MS_VoiceReInit
716
	;; branch depending on selected SID
717
	movf	CS_MENU_SID, W
718
	bnz	CS_MENU_MS_VoiceReInit_Slave
719
 
720
CS_MENU_MS_VoiceReInit_Master
721
	;; use local routine
722
	goto	SID_VOICE_ReInit
723
 
724
CS_MENU_MS_VoiceReInit_Slave
725
	;; request notes off via CAN
726
	goto	CS_MENU_MBNET_Tx_VoiceReInit
727
 
728
;; --------------------------------------------------------------------------
729
;;  Superpoly Reinit command
730
;; --------------------------------------------------------------------------
731
CS_MENU_MS_SP_ReInit
732
	;; branch depending on selected SID
733
	movf	CS_MENU_SID, W
734
	bnz	CS_MENU_MS_SP_ReInit_Slave
735
 
736
CS_MENU_MS_SP_ReInit_Master
737
	;; use local routine
738
	goto	SID_VOICE_SP_ReInit
739
 
740
CS_MENU_MS_SP_ReInit_Slave
741
	;; request notes off via CAN
742
	goto	CS_MENU_MBNET_Tx_SP_ReInit