Subversion Repositories svn.mios

Rev

Rev 301 | Rev 552 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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