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: sid_parin.inc 44 2008-01-30 21:39:30Z tk $
1 tk 2
;
3
; MIDIbox SID
4
; Parameter Input Handling
5
;
6
; ==========================================================================
7
;
8
;  Copyright 1998-2007 Thorsten Klose (tk@midibox.org)
9
;  Licensed for personal non-commercial use only.
10
;  All other rights reserved.
11
;
12
; ==========================================================================
13
 
14
;; --------------------------------------------------------------------------
15
;; Sets a Parameter Value
16
;;  IN: index of parameter in WREG
17
;;      16bit value in MIOS_PARAMETER[12]
18
;;      SID channels which should be modified in MIOS_PARAMETER3[1:0]
19
;;      Multi Patch: Instrument number in MIOS_PARAMETER3[6:4]
20
;;      Drum Patch: Instrument number in MIOS_PARAMETER3[7:4]
21
;; --------------------------------------------------------------------------
22
SID_PARIN_Set
23
	BRA_IFCLR INTCON, GIE, ACCESS, SID_PARIN_Set_FromIRQ	; (for the case that IRQ already disabled)
24
	IRQ_DISABLE				; interrupts must be disabled on 16x16 multiplication!
25
	rcall	SID_PARIN_Set_FromIRQ
26
	IRQ_ENABLE				; enable interrupts again
27
	return
28
 
29
SID_PARIN_Set_FromIRQ				; direct entry for SID_PARIN_Mod and SID_PARIN_SetWT
30
	;; store parameter index in SID_PAR_IX
31
	SET_BSR	SID_BASE
32
	movwf	SID_PAR_IX, BANKED
33
 
34
	;; get table entries
35
	movff	SID_PATCH_BUFFER_SHADOW + SID_Ix_ENGINE, TABLAT
36
	call	SID_PAR_TABLE_GetPtr	; expecting engine in TABLAT[1:0]
37
	tblrd*+			; skip left string
38
	tblrd*+			; skip right string
39
	tblrd*+
40
	movff	TABLAT, PRODL	; mod ID -> PRODL
41
	tblrd*+
42
	movff	TABLAT, FSR1L	; low byte of target registers -> FSR1L
43
 
44
	;; preselect FSR1H
45
	movlw	HIGH(SID_PATCH_BUFFER_SHADOW)
46
	movwf	FSR1H
47
 
48
	;; jump depending on mod ID
49
	movf	PRODL, W
50
	JUMPTABLE_2BYTES 0x39+1 ; entries
51
	rgoto	SID_PARIN_Set_NOP
52
	rgoto	SID_PARIN_Set_7
53
	rgoto	SID_PARIN_Set_8
54
	rgoto	SID_PARIN_Set_PM8
55
	rgoto	SID_PARIN_Set_4L
56
	rgoto	SID_PARIN_Set_4U
57
	rgoto	SID_PARIN_Set_PAR12
58
	rgoto	SID_PARIN_Set_CUSTOM_SW
59
	rgoto	SID_PARIN_Set_FIL4L
60
	rgoto	SID_PARIN_Set_FIL4U
61
	rgoto	SID_PARIN_Set_FIL12
62
	rgoto	SID_PARIN_Set_FIL8
63
	rgoto	SID_PARIN_Set_OSC123_PM7
64
	rgoto	SID_PARIN_Set_OSC123_PM8
65
	rgoto	SID_PARIN_Set_OSC123_7
66
	rgoto	SID_PARIN_Set_OSC123_8
67
	rgoto	SID_PARIN_Set_OSC123_12
68
	rgoto	SID_PARIN_Set_OSC123_4L
69
	rgoto	SID_PARIN_Set_OSC123_6L
70
	rgoto	SID_PARIN_Set_OSC123_4U
71
	rgoto	SID_PARIN_Set_OSC123_PB
72
	rgoto	SID_PARIN_Set_MOD_PM8
73
	rgoto	SID_PARIN_Set_MOD_B76
74
	rgoto	SID_PARIN_Set_LFO_4U
75
	rgoto	SID_PARIN_Set_LFO_PM8
76
	rgoto	SID_PARIN_Set_LFO_8
77
	rgoto	SID_PARIN_Set_ENV_PM8
78
	rgoto	SID_PARIN_Set_ENV_8
79
	rgoto	SID_PARIN_Set_WT_6
80
	rgoto	SID_PARIN_Set_WT_7
81
	rgoto	SID_PARIN_Set_WT_POS
82
	rgoto	SID_PARIN_Set_NOTE
83
	rgoto	SID_PARIN_Set_OSC_INS_PM7
84
	rgoto	SID_PARIN_Set_OSC_INS_PM8
85
	rgoto	SID_PARIN_Set_OSC_INS_7
86
	rgoto	SID_PARIN_Set_OSC_INS_8
87
	rgoto	SID_PARIN_Set_OSC_INS_12
88
	rgoto	SID_PARIN_Set_OSC_INS_4L
89
	rgoto	SID_PARIN_Set_OSC_INS_6L
90
	rgoto	SID_PARIN_Set_OSC_INS_4U
91
	rgoto	SID_PARIN_Set_OSC_INS_PB
92
	rgoto	SID_PARIN_Set_OSC_BL_PM7
93
	rgoto	SID_PARIN_Set_OSC_BL_PM8
94
	rgoto	SID_PARIN_Set_OSC_BL_P8
95
	rgoto	SID_PARIN_Set_OSC_BL_7
96
	rgoto	SID_PARIN_Set_OSC_BL_8
97
	rgoto	SID_PARIN_Set_OSC_BL_12
98
	rgoto	SID_PARIN_Set_OSC_BL_4L
99
	rgoto	SID_PARIN_Set_OSC_BL_6L
100
	rgoto	SID_PARIN_Set_OSC_BL_4U
101
	rgoto	SID_PARIN_Set_OSC_BL_PB
102
	rgoto	SID_PARIN_Set_OSC_BL_FIL12
103
	rgoto	SID_PARIN_Set_OSC_BL_FIL8
104
	rgoto	SID_PARIN_Set_DRM_8
105
	rgoto	SID_PARIN_Set_DRM_PM8
106
	rgoto	SID_PARIN_Set_DRM_4U
107
	rgoto	SID_PARIN_Set_DRM_4L
108
	rgoto	SID_PARIN_Set_NOTE_INS
109
 
110
 
111
;; ----------------------------------------------------------
112
SID_PARIN_SID_FIL_MACRO MACRO
113
	LOCAL	SID_PARIN_SID_FIL_Sub
114
 
115
	RCALL_IFSET MIOS_PARAMETER3, 0, ACCESS, SID_PARIN_SID_FIL_Sub
116
	btfss	MIOS_PARAMETER3, 1
117
	return
118
	movlw	(SID_Ix_L_S2F_BASE-SID_Ix_L_S1F_BASE)
119
	addwf	FSR1L, F
120
SID_PARIN_SID_FIL_Sub
121
	ENDM
122
 
123
SID_PARIN_SID_OSC_MACRO MACRO
124
	LOCAL	SID_PARIN_SID_OSC_Sub
125
	LOCAL	SID_PARIN_SID_OSC_Single
126
 
127
	RCALL_IFSET MIOS_PARAMETER3, 0, ACCESS, SID_PARIN_SID_OSC_Sub
128
	btfss	MIOS_PARAMETER3, 1
129
	return
130
	movlw	(SID_Ix_L_S2V1_BASE-SID_Ix_L_S1V1_BASE)
131
	addwf	FSR1L, F
132
SID_PARIN_SID_OSC_Sub
133
	movf	SID_PAR_IX, W, BANKED
134
	andlw	0x03
135
	bnz	SID_PARIN_SID_OSC_Single
136
	rcall	SID_PARIN_SID_OSC_Single
137
	movlw	(SID_Ix_L_S1V2_BASE-SID_Ix_L_S1V1_BASE)
138
	addwf	FSR1L, F
139
	rcall	SID_PARIN_SID_OSC_Single
140
	movlw	(SID_Ix_L_S1V2_BASE-SID_Ix_L_S1V1_BASE)
141
	addwf	FSR1L, F
142
	rcall	SID_PARIN_SID_OSC_Single
143
	movlw	(SID_Ix_L_S1V1_BASE-SID_Ix_L_S1V3_BASE)
144
	addwf	FSR1L, F
145
	return
146
SID_PARIN_SID_OSC_Single
147
	ENDM
148
 
149
SID_PARIN_SID_OSC_INS_MACRO MACRO
150
	LOCAL	SID_PARIN_SID_OSC_INS_All
151
	LOCAL	SID_PARIN_SID_OSC_INS_Single
152
 
153
	rcall	SID_PARIN_Hlp_GetVoices		; affected voices in PRODH
154
	RCALL_IFSET PRODH, 0, ACCESS, SID_PARIN_SID_OSC_INS_Single
155
	rcall	SID_PARIN_Hlp_FSR1_NextVoice	; switches to next voice
156
	RCALL_IFSET PRODH, 1, ACCESS, SID_PARIN_SID_OSC_INS_Single
157
	rcall	SID_PARIN_Hlp_FSR1_NextVoice	; switches to next voice
158
	RCALL_IFSET PRODH, 2, ACCESS, SID_PARIN_SID_OSC_INS_Single
159
	rcall	SID_PARIN_Hlp_FSR1_NextVoice	; switches to next voice
160
	RCALL_IFSET PRODH, 3, ACCESS, SID_PARIN_SID_OSC_INS_Single
161
	rcall	SID_PARIN_Hlp_FSR1_NextVoice	; switches to next voice
162
	RCALL_IFSET PRODH, 4, ACCESS, SID_PARIN_SID_OSC_INS_Single
163
	rcall	SID_PARIN_Hlp_FSR1_NextVoice	; switches to next voice
164
	RCALL_IFSET PRODH, 5, ACCESS, SID_PARIN_SID_OSC_INS_Single
165
	return
166
SID_PARIN_SID_OSC_INS_Single
167
	ENDM
168
 
169
SID_PARIN_SID_OSC_BL_MACRO MACRO
170
	LOCAL	SID_PARIN_SID_OSC_BL_Single
171
 
172
	rcall	SID_PARIN_Hlp_GetBL		; affected basslines in PRODH
173
	RCALL_IFSET PRODH, 0, ACCESS, SID_PARIN_SID_OSC_BL_Single
174
	movlw	(SID_Ix_B_S2V1_BASE-SID_Ix_B_S1V1_BASE)
175
	addwf	FSR1L, F
176
	RCALL_IFSET PRODH, 1, ACCESS, SID_PARIN_SID_OSC_BL_Single
177
	return
178
SID_PARIN_SID_OSC_BL_Single
179
	ENDM
180
 
181
SID_PARIN_SID_OSC_BL_FIL_MACRO MACRO
182
	LOCAL	SID_PARIN_SID_OSC_BL_FIL_Single
183
 
184
	rcall	SID_PARIN_Hlp_GetBL		; affected basslines in PRODH
185
	RCALL_IFSET PRODH, 0, ACCESS, SID_PARIN_SID_OSC_BL_FIL_Single
186
	movlw	(SID_Ix_L_S2F_BASE-SID_Ix_L_S1F_BASE)
187
	addwf	FSR1L, F
188
	RCALL_IFSET PRODH, 1, ACCESS, SID_PARIN_SID_OSC_BL_FIL_Single
189
	return
190
SID_PARIN_SID_OSC_BL_FIL_Single
191
	ENDM
192
 
193
SID_PARIN_SID_DRM_MACRO MACRO
194
	swapf	MIOS_PARAMETER3, W
195
	andlw	0x0f
196
	mullw	(SID_Ix_D_I2_BASE-SID_Ix_D_I1_BASE)
197
	movf	PRODL, W
198
	addwf	FSR1L, F
199
	ENDM
200
 
201
SID_PARIN_SID_NOTE_MACRO MACRO
202
	LOCAL	SID_PARIN_SID_NOTE_Single
203
 
204
	movf	SID_PAR_IX, W, BANKED
205
	andlw	0x03
206
	bnz	SID_PARIN_SID_NOTE_Single
207
	rcall	SID_PARIN_SID_NOTE_Single
208
	movlw	(SIDL_V2_BASE-SIDL_V1_BASE)
209
	addwf	FSR1L, F
210
	rcall	SID_PARIN_SID_NOTE_Single
211
	movlw	(SIDL_V3_BASE-SIDL_V2_BASE)
212
	addwf	FSR1L, F
213
	rcall	SID_PARIN_SID_NOTE_Single
214
	movlw	(SIDL_V1_BASE-SIDL_V3_BASE)
215
	addwf	FSR1L, F
216
	return
217
SID_PARIN_SID_NOTE_Single
218
	ENDM
219
 
220
;; ----------------------------------------------------------
221
 
222
 
223
SID_PARIN_Set_NOP
224
	return
225
 
226
SID_PARIN_Set_7
227
	movf	MIOS_PARAMETER1, W
228
	andlw	0x7f
229
	movwf	INDF1
230
	return
231
 
232
SID_PARIN_Set_8
233
	movff	MIOS_PARAMETER1, INDF1
234
	return
235
 
236
SID_PARIN_Set_PAR12
237
	swapf	MIOS_PARAMETER1, W
238
	andlw	0xf0
239
	movwf	POSTINC1
240
	swapf	MIOS_PARAMETER1, W
241
	andlw	0x0f
242
	movwf	INDF1
243
	swapf	MIOS_PARAMETER2, W
244
	andlw	0xf0
245
	iorwf	POSTDEC1, F
246
	return
247
 
248
SID_PARIN_Set_CUSTOM_SW
249
	movf	SID_PAR_IX, W, BANKED
250
	BRA_IFSET MIOS_PARAMETER1, 0, ACCESS, SID_PARIN_Set_CUSTOM_SW_1
251
SID_PARIN_Set_CUSTOM_SW_0
252
	call	MIOS_HLP_GetBitANDMask
253
	andwf	INDF1, F
254
	return
255
SID_PARIN_Set_CUSTOM_SW_1
256
	call	MIOS_HLP_GetBitORMask
257
	iorwf	INDF1, F
258
	return
259
 
260
SID_PARIN_Set_FIL4L
261
	SID_PARIN_SID_FIL_MACRO		; select SIDL/SIDR filter
262
	movlw	0xf0
263
	andwf	INDF1, F
264
	movf	MIOS_PARAMETER1, W
265
	andlw	0x0f
266
	iorwf	INDF1, F
267
	return
268
 
269
SID_PARIN_Set_FIL4U
270
	SID_PARIN_SID_FIL_MACRO		; select SIDL/SIDR filter
271
	movlw	0x0f
272
	andwf	INDF1, F
273
	swapf	MIOS_PARAMETER1, W
274
	andlw	0xf0
275
	iorwf	INDF1, F
276
	return
277
 
278
SID_PARIN_Set_FIL12
279
	SID_PARIN_SID_FIL_MACRO		; select SIDL/SIDR filter
280
	movff	MIOS_PARAMETER1, POSTINC1
281
	movf	MIOS_PARAMETER2, W
282
	andlw	0x0f
283
	movwf	POSTDEC1
284
	return
285
 
286
SID_PARIN_Set_FIL8
287
	SID_PARIN_SID_FIL_MACRO		; select SIDL/SIDR filter
288
	movff	MIOS_PARAMETER1, INDF1
289
	return
290
 
291
SID_PARIN_Set_OSC123_PM7
292
SID_PARIN_Set_OSC123_PM8
293
SID_PARIN_Set_OSC123_7
294
SID_PARIN_Set_OSC123_8
295
	SID_PARIN_SID_OSC_MACRO		; select SIDL/SIDR OSC1/2/3
296
SID_PARIN_Set_PM8
297
	movff	MIOS_PARAMETER1, INDF1
298
	return
299
 
300
SID_PARIN_Set_OSC123_12
301
	SID_PARIN_SID_OSC_MACRO		; select SIDL/SIDR OSC1/2/3
302
	movff	MIOS_PARAMETER1, POSTINC1
303
	movf	MIOS_PARAMETER2, W
304
	andlw	0x0f
305
	movwf	POSTDEC1
306
	return
307
 
308
SID_PARIN_Set_OSC123_4L
309
	SID_PARIN_SID_OSC_MACRO		; select SIDL/SIDR OSC1/2/3
310
SID_PARIN_Set_4L
311
	movlw	0xf0
312
	andwf	INDF1, F
313
	movf	MIOS_PARAMETER1, W
314
	andlw	0x0f
315
	iorwf	INDF1, F
316
	return
317
 
318
SID_PARIN_Set_OSC123_6L
319
	SID_PARIN_SID_OSC_MACRO		; select SIDL/SIDR OSC1/2/3
320
	movlw	0xc0
321
	andwf	INDF1, F
322
	movf	MIOS_PARAMETER1, W
323
	andlw	0x3f
324
	iorwf	INDF1, F
325
	return
326
 
327
SID_PARIN_Set_OSC123_4U
328
	SID_PARIN_SID_OSC_MACRO		; select SIDL/SIDR OSC1/2/3
329
SID_PARIN_Set_4U
330
	movlw	0x0f
331
	andwf	INDF1, F
332
	swapf	MIOS_PARAMETER1, W
333
	andlw	0xf0
334
	iorwf	INDF1, F
335
	return
336
 
337
SID_PARIN_Set_OSC123_PB
338
	movlw	HIGH(SIDL_V1_BASE)	; select right address range
339
	movwf	FSR1H
340
 
341
	SID_PARIN_SID_NOTE_MACRO	; select OSC1/2/3
342
 
343
	;; transfer to register
344
	movf	MIOS_PARAMETER1, W
345
	xorlw	0x80
346
	movwf	PRODL
347
 
348
	movlw	SID_Vx_PITCHBENDER
349
	btfsc	MIOS_PARAMETER3, 0
350
	movff	PRODL, PLUSW1
351
 
352
	movlw	SID_Vx_PITCHBENDER + (SIDR_V1_BASE-SIDL_V1_BASE)
353
	btfsc	MIOS_PARAMETER3, 1
354
	movff	PRODL, PLUSW1
355
 
356
	return
357
 
358
SID_PARIN_Set_MOD_PM8
359
	incf	FSR1H, F	; (select upper address range)
360
	movff	MIOS_PARAMETER1, INDF1
361
	return
362
 
363
SID_PARIN_Set_MOD_B76
364
	incf	FSR1H, F	; (select upper address range)
365
	movlw	0x3f
366
	andwf	INDF1, F
367
	swapf	MIOS_PARAMETER1, W
368
	rlf	WREG, W
369
	rlf	WREG, W
370
	andlw	0xc0
371
	iorwf	INDF1, F
372
	return
373
 
374
SID_PARIN_Set_LFO_4U
375
	movlw	0x0f
376
	andwf	INDF1, F
377
	swapf	MIOS_PARAMETER1, W
378
	andlw	0xf0
379
	iorwf	INDF1, F
380
	return
381
 
382
SID_PARIN_Set_LFO_PM8
383
SID_PARIN_Set_LFO_8
384
	movff	MIOS_PARAMETER1, INDF1
385
	return
386
 
387
SID_PARIN_Set_ENV_PM8
388
SID_PARIN_Set_ENV_8
389
	movff	MIOS_PARAMETER1, INDF1
390
	return
391
 
392
SID_PARIN_Set_WT_6
393
	incf	FSR1H, F	; (select upper address range)
394
	movlw	0xc0
395
	andwf	INDF1, F
396
	movf	MIOS_PARAMETER1, W
397
	andlw	0x3f
398
	iorwf	INDF1, F
399
	return
400
 
401
SID_PARIN_Set_WT_7
402
	incf	FSR1H, F	; (select upper address range)
403
	movlw	0x80
404
	andwf	INDF1, F
405
	movf	MIOS_PARAMETER1, W
406
	andlw	0x7f
407
	iorwf	INDF1, F
408
	return
409
 
410
SID_PARIN_Set_WT_POS
411
	movlw	HIGH(SID_WT1_BASE)	; select right address range
412
	movwf	FSR1H
413
	movff	MIOS_PARAMETER1, INDF1
414
	return
415
 
416
SID_PARIN_Set_OSC_INS_PM7
417
SID_PARIN_Set_OSC_INS_PM8
418
SID_PARIN_Set_OSC_INS_7
419
SID_PARIN_Set_OSC_INS_8
420
	SID_PARIN_SID_OSC_INS_MACRO	; select instrument
421
	movff	MIOS_PARAMETER1, INDF1
422
	return
423
 
424
SID_PARIN_Set_OSC_INS_12
425
	SID_PARIN_SID_OSC_INS_MACRO	; select instrument
426
	movff	MIOS_PARAMETER1, POSTINC1
427
	movf	MIOS_PARAMETER2, W
428
	andlw	0x0f
429
	movwf	POSTDEC1
430
	return
431
 
432
SID_PARIN_Set_OSC_INS_4L
433
	SID_PARIN_SID_OSC_INS_MACRO	; select instrument
434
	movlw	0xf0
435
	andwf	INDF1, F
436
	movf	MIOS_PARAMETER1, W
437
	andlw	0x0f
438
	iorwf	INDF1, F
439
	return
440
 
441
SID_PARIN_Set_OSC_INS_6L
442
	SID_PARIN_SID_OSC_INS_MACRO	; select instrument
443
	movlw	0xc0
444
	andwf	INDF1, F
445
	movf	MIOS_PARAMETER1, W
446
	andlw	0x3f
447
	iorwf	INDF1, F
448
	return
449
 
450
SID_PARIN_Set_OSC_INS_4U
451
	SID_PARIN_SID_OSC_INS_MACRO	; select instrument
452
	movlw	0x0f
453
	andwf	INDF1, F
454
	swapf	MIOS_PARAMETER1, W
455
	andlw	0xf0
456
	iorwf	INDF1, F
457
	return
458
 
459
SID_PARIN_Set_OSC_INS_PB
460
	;; determine affected instruments
461
	movf	SID_PAR_IX, W, BANKED
462
	andlw	0x07
463
	bz	SID_PARIN_Set_OSC_INS_PB_All
464
	addlw	-1
465
	bz	SID_PARIN_Set_OSC_INS_PB_Cur
466
	addlw	-1
467
SID_PARIN_Set_OSC_INS_PB_CurCont
468
	call	MIOS_HLP_GetBitORMask
469
	rgoto	SID_PARIN_Set_OSC_INS_PB_Cont
470
 
471
SID_PARIN_Set_OSC_INS_PB_All
472
	movlw	0x3f
473
	rgoto	SID_PARIN_Set_OSC_INS_PB_Cont
474
 
475
SID_PARIN_Set_OSC_INS_PB_Cur
476
	swapf	MIOS_PARAMETER3, W
477
	andlw	0x07
478
	rgoto	SID_PARIN_Set_OSC_INS_PB_CurCont
479
 
480
SID_PARIN_Set_OSC_INS_PB_Cont
481
	;; store it in PRODH
482
	movwf	PRODH
483
 
484
	;; store pitchbender value in MIDI voice record
485
	movf	MIOS_PARAMETER1, W
486
	xorlw	0x80
487
	movwf	PRODL
488
 
489
	btfsc	PRODH, 0
490
	movff	PRODL, SID_MV1_BASE + SID_MVx_PITCHBENDER
491
	btfsc	PRODH, 1
492
	movff	PRODL, SID_MV2_BASE + SID_MVx_PITCHBENDER
493
	btfsc	PRODH, 2
494
	movff	PRODL, SID_MV3_BASE + SID_MVx_PITCHBENDER
495
	btfsc	PRODH, 3
496
	movff	PRODL, SID_MV4_BASE + SID_MVx_PITCHBENDER
497
	btfsc	PRODH, 4
498
	movff	PRODL, SID_MV5_BASE + SID_MVx_PITCHBENDER
499
	btfsc	PRODH, 5
500
	movff	PRODL, SID_MV6_BASE + SID_MVx_PITCHBENDER
501
 
502
	return
503
 
504
 
505
SID_PARIN_Set_OSC_BL_PM7
506
SID_PARIN_Set_OSC_BL_PM8
507
SID_PARIN_Set_OSC_BL_7
508
SID_PARIN_Set_OSC_BL_8
509
	SID_PARIN_SID_OSC_BL_MACRO	; select BL
510
	movff	MIOS_PARAMETER1, INDF1
511
	return
512
 
513
SID_PARIN_Set_OSC_BL_12
514
	SID_PARIN_SID_OSC_BL_MACRO	; select BL
515
	movff	MIOS_PARAMETER1, POSTINC1
516
	movf	MIOS_PARAMETER2, W
517
	andlw	0x0f
518
	movwf	POSTDEC1
519
	return
520
 
521
SID_PARIN_Set_OSC_BL_4L
522
	SID_PARIN_SID_OSC_BL_MACRO	; select BL
523
	movlw	0xf0
524
	andwf	INDF1, F
525
	movf	MIOS_PARAMETER1, W
526
	andlw	0x0f
527
	iorwf	INDF1, F
528
	return
529
 
530
SID_PARIN_Set_OSC_BL_6L
531
	SID_PARIN_SID_OSC_BL_MACRO	; select BL
532
	movlw	0xc0
533
	andwf	INDF1, F
534
	movf	MIOS_PARAMETER1, W
535
	andlw	0x3f
536
	iorwf	INDF1, F
537
	return
538
 
539
SID_PARIN_Set_OSC_BL_4U
540
	SID_PARIN_SID_OSC_BL_MACRO	; select BL
541
	movlw	0x0f
542
	andwf	INDF1, F
543
	swapf	MIOS_PARAMETER1, W
544
	andlw	0xf0
545
	iorwf	INDF1, F
546
	return
547
 
548
SID_PARIN_Set_OSC_BL_P8
549
	SID_PARIN_SID_OSC_BL_MACRO	; select BL
550
	movf	MIOS_PARAMETER1, W
551
	addlw	0x80
552
	btfss	WREG, 7
553
	movlw 0xff
554
	movwf	INDF1
555
	return
556
 
557
SID_PARIN_Set_OSC_BL_PB
558
	rcall	SID_PARIN_Hlp_GetBL		; affected basslines in PRODH
559
 
560
	;; store pitchbender value in MIDI voice record
561
	movf	MIOS_PARAMETER1, W
562
	xorlw	0x80
563
	movwf	PRODL
564
 
565
	btfsc	PRODH, 0
566
	movff	PRODL, SID_MV1_BASE + SID_MVx_PITCHBENDER
567
	btfsc	PRODH, 1
568
	movff	PRODL, SID_MV2_BASE + SID_MVx_PITCHBENDER
569
 
570
	return
571
 
572
 
573
SID_PARIN_Set_OSC_BL_FIL12
574
	SID_PARIN_SID_OSC_BL_MACRO	; select BL
575
	movff	MIOS_PARAMETER1, POSTINC1
576
	movf	MIOS_PARAMETER2, W
577
	andlw	0x0f
578
	movwf	POSTDEC1
579
	return
580
 
581
SID_PARIN_Set_OSC_BL_FIL8
582
	SID_PARIN_SID_OSC_BL_MACRO	; select BL
583
	movff	MIOS_PARAMETER1, POSTINC1
584
	movf	MIOS_PARAMETER2, W
585
	andlw	0x0f
586
	movwf	POSTDEC1
587
	return
588
 
589
SID_PARIN_Set_DRM_8
590
	SID_PARIN_SID_DRM_MACRO		; select drum
591
	rgoto	SID_PARIN_Set_8
592
 
593
SID_PARIN_Set_DRM_PM8
594
	SID_PARIN_SID_DRM_MACRO		; select drum
595
	rgoto	SID_PARIN_Set_PM8
596
 
597
SID_PARIN_Set_DRM_4U
598
	SID_PARIN_SID_DRM_MACRO		; select drum
599
	rgoto	SID_PARIN_Set_4U
600
 
601
SID_PARIN_Set_DRM_4L
602
	SID_PARIN_SID_DRM_MACRO		; select drum
603
	rgoto	SID_PARIN_Set_4L
604
 
605
;; Note handler for multi engine
606
SID_PARIN_Set_NOTE_INS
607
	;; ensure that only one voice modified
608
	bcf	MIOS_PARAMETER3, 1
609
 
610
	rcall	SID_PARIN_Hlp_GetVoices		; affected voices in PRODH
611
	movff	PRODH, MUL_A_L			; copy to MUL_A_L (interrupts are disabled)
612
	lfsr	FSR1, SIDL_V1_BASE
613
	RCALL_IFSET MUL_A_L, 0, BANKED, SID_PARIN_Set_NOTE_Sub
614
	lfsr	FSR1, SIDL_V2_BASE
615
	RCALL_IFSET MUL_A_L, 1, BANKED, SID_PARIN_Set_NOTE_Sub
616
	lfsr	FSR1, SIDL_V3_BASE
617
	RCALL_IFSET MUL_A_L, 2, BANKED, SID_PARIN_Set_NOTE_Sub
618
	lfsr	FSR1, SIDR_V1_BASE
619
	RCALL_IFSET MUL_A_L, 3, BANKED, SID_PARIN_Set_NOTE_Sub
620
	lfsr	FSR1, SIDR_V2_BASE
621
	RCALL_IFSET MUL_A_L, 4, BANKED, SID_PARIN_Set_NOTE_Sub
622
	lfsr	FSR1, SIDR_V3_BASE
623
	RCALL_IFSET MUL_A_L, 5, BANKED, SID_PARIN_Set_NOTE_Sub
624
	return
625
 
626
 
627
;; Note handler for lead engine
628
SID_PARIN_Set_NOTE
629
	movlw	HIGH(SIDL_V1_BASE)	; select right address range
630
	movwf	FSR1H
631
 
632
	SID_PARIN_SID_NOTE_MACRO	; select OSC1/2/3
633
 
634
SID_PARIN_Set_NOTE_Sub
635
	;; do nothing if 0x01 (hold note) is played
636
	decf	MIOS_PARAMETER1, W
637
	bz	SID_PARIN_Set_NOTE_End
638
 
639
	;; clear gate bit if note value is 0
640
	movf	MIOS_PARAMETER1, W
641
	bnz	SID_PARIN_Set_NOTE_On
642
SID_PARIN_Set_NOTE_Off
643
	BRA_IFCLR MIOS_PARAMETER3, 0, ACCESS, SID_PARIN_Set_NOTE_Off_NoL
644
SID_PARIN_Set_NOTE_Off_L
645
	movlw	SID_Vx_STATE
646
	bcf	PLUSW1, SID_V_STATE_GATE_SET_REQ
647
	bsf	PLUSW1, SID_V_STATE_GATE_CLR_REQ
648
SID_PARIN_Set_NOTE_Off_NoL
649
	BRA_IFCLR MIOS_PARAMETER3, 1, ACCESS, SID_PARIN_Set_NOTE_Off_NoR
650
SID_PARIN_Set_NOTE_Off_R
651
	movlw	SID_Vx_STATE + (SIDR_V1_BASE-SIDL_V1_BASE)
652
	bcf	PLUSW1, SID_V_STATE_GATE_SET_REQ
653
	bsf	PLUSW1, SID_V_STATE_GATE_CLR_REQ
654
SID_PARIN_Set_NOTE_Off_NoR
655
 
656
	;; propagate to trigger matrix
657
	movff	SID_PATCH_BUFFER_SHADOW + SID_Ix_ENGINE, WREG
658
	BRA_IFSET WREG, 1, ACCESS, SID_PARIN_Set_NOTE_Off_Trg_DM
659
SID_PARIN_Set_NOTE_Off_Trg_LB
660
	BRA_IFSET WREG, 0, ACCESS, SID_PARIN_Set_NOTE_Off_Trg_B
661
SID_PARIN_Set_NOTE_Off_Trg_L
662
	movff	SID_PATCH_BUFFER_SHADOW + SID_Ix_L_TRG_NOf_BASE + 0, WREG
663
	andlw	0xc0		; (Gates handled seperately)
664
	iorwf	SID_SE_TRG_EVNT_L, F, BANKED
665
	movff	SID_PATCH_BUFFER_SHADOW + SID_Ix_L_TRG_NOf_BASE + 1, WREG
666
	iorwf	SID_SE_TRG_EVNT_H, F, BANKED
667
	;; don't trigger SID_SE_TRG_EVNT_U (the wavetable events) - wouldn't make sense here!
668
	rgoto	SID_PARIN_Set_NOTE_End
669
 
670
SID_PARIN_Set_NOTE_Off_Trg_B
671
	rgoto	SID_PARIN_Set_NOTE_End	; not implemented yet
672
 
673
SID_PARIN_Set_NOTE_Off_Trg_DM
674
	BRA_IFSET WREG, 0, ACCESS, SID_PARIN_Set_NOTE_Off_Trg_M
675
SID_PARIN_Set_NOTE_Off_Trg_D
676
	rgoto	SID_PARIN_Set_NOTE_End	; not implemented yet
677
SID_PARIN_Set_NOTE_Off_Trg_M
678
	movlw	0x03		; static assignment: ENV release
679
	iorwf	SID_SE_TRG_EVNT_H, F, BANKED
680
	rgoto	SID_PARIN_Set_NOTE_End	; not implemented yet
681
 
682
 
683
 
684
SID_PARIN_Set_NOTE_On
685
	;; TODO: hold mode (via trigger matrix?)
686
	;; TODO: SIDL/R check?
687
 
688
	;; set gate bit if voice is active and gate not already set
689
	movlw	SID_Vx_STATE
690
	BRA_IFCLR PLUSW1, SID_V_STATE_VOICE_ACTIVE, ACCESS, SID_PARIN_Set_NOTE_On_NoGate
691
	BRA_IFSET PLUSW1, SID_V_STATE_GATE_ACTIVE, ACCESS, SID_PARIN_Set_NOTE_On_NoGate
692
SID_PARIN_Set_NOTE_On_Gate
693
	;; set gate bit
694
	BRA_IFCLR MIOS_PARAMETER3, 0, ACCESS, SID_PARIN_Set_NOTE_On_NoL
695
SID_PARIN_Set_NOTE_On_L
696
	movlw	SID_Vx_STATE
697
	bsf	PLUSW1, SID_V_STATE_GATE_SET_REQ
698
SID_PARIN_Set_NOTE_On_NoL
699
	BRA_IFCLR MIOS_PARAMETER3, 1, ACCESS, SID_PARIN_Set_NOTE_On_NoR
700
SID_PARIN_Set_NOTE_On_R
701
	movlw	SID_Vx_STATE + (SIDR_V1_BASE-SIDL_V1_BASE)
702
	bsf	PLUSW1, SID_V_STATE_GATE_SET_REQ
703
SID_PARIN_Set_NOTE_On_NoR
704
 
705
	;; propagate to trigger matrix
706
	movff	SID_PATCH_BUFFER_SHADOW + SID_Ix_ENGINE, WREG
707
	BRA_IFSET WREG, 1, ACCESS, SID_PARIN_Set_NOTE_On_Trg_DM
708
SID_PARIN_Set_NOTE_On_Trg_LB
709
	BRA_IFSET WREG, 0, ACCESS, SID_PARIN_Set_NOTE_On_Trg_B
710
SID_PARIN_Set_NOTE_On_Trg_L
711
	movff	SID_PATCH_BUFFER_SHADOW + SID_Ix_L_TRG_NOn_BASE + 0, WREG
712
	andlw	0xc0		; (Gates handled seperately)
713
	iorwf	SID_SE_TRG_EVNT_L, F, BANKED
714
	movff	SID_PATCH_BUFFER_SHADOW + SID_Ix_L_TRG_NOn_BASE + 1, WREG
715
	iorwf	SID_SE_TRG_EVNT_H, F, BANKED
716
	;; don't trigger SID_SE_TRG_EVNT_U (the wavetable events) - wouldn't make sense here!
717
	rgoto	SID_PARIN_Set_NOTE_On_Trg_Cont
718
 
719
SID_PARIN_Set_NOTE_On_Trg_B
720
	rgoto	SID_PARIN_Set_NOTE_On_Trg_Cont	; not implemented yet
721
 
722
SID_PARIN_Set_NOTE_On_Trg_DM
723
	BRA_IFSET WREG, 0, ACCESS, SID_PARIN_Set_NOTE_On_Trg_M
724
SID_PARIN_Set_NOTE_On_Trg_D
725
	rgoto	SID_PARIN_Set_NOTE_On_Trg_Cont	; not implemented yet
726
SID_PARIN_Set_NOTE_On_Trg_M
727
	movlw	0xc0		; static assignment: ENV attack
728
	iorwf	SID_SE_TRG_EVNT_H, F, BANKED
729
	;; 	rgoto	SID_PARIN_Set_NOTE_On_Trg_Cont	; not implemented yet
730
SID_PARIN_Set_NOTE_On_Trg_Cont
731
 
732
 
733
SID_PARIN_Set_NOTE_On_NoGate
734
	;; set new note
735
	;; (temporary stored in TABLAT)
736
	movff	MIOS_PARAMETER1, TABLAT
737
 
738
	;; if > 0x7c, play arpeggiator note
739
	movlw	0x7c-1
740
	cpfsgt	TABLAT, ACCESS
741
	rgoto SID_PARIN_Set_NOTE_On_NoArp
742
SID_PARIN_Set_NOTE_On_Arp
743
	movff	FSR1L, PRODL		; temporary store FSR1 in PROD[LH]
744
	movff	FSR1H, PRODH
745
	lfsr	FSR1, SID_MV1_BASE + SID_MVx_WT_STACK_0		; (sorted stack)
746
								;; TODO: alternatively take HOLD stack (global option?)
747
	movf	TABLAT, W
748
	addlw	-0x7c
749
	movf	PLUSW1, W	; (note 1-4)
750
	skpnz
751
	movf	PLUSW1, W	; (first note)
752
	movwf	TABLAT
753
 
754
	movff	PRODL, FSR1L		; restore FSR1 from PROD[LH]
755
	movff	PRODH, FSR1H
756
 
757
	movf	TABLAT, W
758
	bz	SID_PARIN_Set_NOTE_Off
759
SID_PARIN_Set_NOTE_On_NoArp
760
 
761
	;; transfer new note to SID_Vx_NOTE register
762
	;; (SID_Vx_NOTE cannot be used due to special handling in SID_MIDI_Hlp_GateOff!)
763
	movlw	SID_Vx_NOTE
764
	btfsc	MIOS_PARAMETER3, 0	; SIDL?
765
	movff	TABLAT, PLUSW1
766
	movlw	SID_Vx_STATE
767
	btfsc	MIOS_PARAMETER3, 0
768
	bsf	PLUSW1, SID_V_STATE_PORTA_ACTIVE	; will be cleared automatically if no portamento enabled
769
 
770
	BRA_IFCLR MIOS_PARAMETER3, 1, ACCESS, SID_PARIN_Set_NOTE_End ; SIDR?
771
	movlw	SID_Vx_NOTE + (SIDR_V1_BASE-SIDL_V1_BASE)
772
	movff	TABLAT, PLUSW1
773
	movlw	SID_Vx_STATE + (SIDR_V1_BASE-SIDL_V1_BASE)
774
	bsf	PLUSW1, SID_V_STATE_PORTA_ACTIVE	; will be cleared automatically if no portamento enabled
775
SID_PARIN_Set_NOTE_End
776
	return
777
 
778
 
779
;; --------------------------------------------------------------------------
780
;; Scales a 16bit value to target range or a source value to 16bit
781
;;  IN: index of parameter in WREG
782
;;      16bit value in MIOS_PARAMETER[12]
783
;;      MIOS_PARAMETER3[3] = 0: scale down (from 16bit), else scale up (to 16bit)
784
;;  OUT: scaled value in MIOS_PARAMETER[12]
785
;; --------------------------------------------------------------------------
786
SID_PARIN_Scale
787
	;; determine number of bits from tables
788
	movff	SID_PATCH_BUFFER_SHADOW + SID_Ix_ENGINE, TABLAT
789
	call	SID_PAR_TABLE_GetPtr	; expecting engine in TABLAT[1:0]
790
	tblrd*+			; skip left string
791
	tblrd*+			; skip right string
792
	tblrd*+			; now TABLAT contains mod ID
793
 
794
	;; store MAX value in SID_PAR_MAX_[LH]
795
	movf	TABLAT, W	; (mod ID)
796
	JUMPTABLE_2BYTES 0x39+1 ; entries
797
	rgoto	SID_PARIN_Scale_0	;NOP
798
	rgoto	SID_PARIN_Scale_7	;7
799
	rgoto	SID_PARIN_Scale_8	;8
800
	rgoto	SID_PARIN_Scale_8	;PM8
801
	rgoto	SID_PARIN_Scale_4	;4L
802
	rgoto	SID_PARIN_Scale_4	;4U
803
	rgoto	SID_PARIN_Scale_12	;PAR12
804
	rgoto	SID_PARIN_Scale_1	;CUSTOM_SW
805
	rgoto	SID_PARIN_Scale_4	;FIL4L
806
	rgoto	SID_PARIN_Scale_4	;FIL4U
807
	rgoto	SID_PARIN_Scale_12	;FIL12
808
	rgoto	SID_PARIN_Scale_8	;FIL8
809
	rgoto	SID_PARIN_Scale_7	;OSC123_PM7
810
	rgoto	SID_PARIN_Scale_8	;OSC123_PM8
811
	rgoto	SID_PARIN_Scale_7	;OSC123_7
812
	rgoto	SID_PARIN_Scale_8	;OSC123_8
813
	rgoto	SID_PARIN_Scale_12	;OSC123_12
814
	rgoto	SID_PARIN_Scale_4	;OSC123_4L
815
	rgoto	SID_PARIN_Scale_6	;OSC123_6L
816
	rgoto	SID_PARIN_Scale_4	;OSC123_4U
817
	rgoto	SID_PARIN_Scale_8	;OSC123_PB
818
	rgoto	SID_PARIN_Scale_8	;MOD_PM8
819
	rgoto	SID_PARIN_Scale_2	;MOD_B76
820
	rgoto	SID_PARIN_Scale_4	;LFO_4U
821
	rgoto	SID_PARIN_Scale_8	;LFO_PM8
822
	rgoto	SID_PARIN_Scale_8	;LFO_8
823
	rgoto	SID_PARIN_Scale_8	;ENV_PM8
824
	rgoto	SID_PARIN_Scale_8	;ENV_8
825
	rgoto	SID_PARIN_Scale_6	;WT_6
826
	rgoto	SID_PARIN_Scale_7	;WT_7
827
	rgoto	SID_PARIN_Scale_7	;WT_POS
828
	rgoto	SID_PARIN_Scale_7	;NOTE
829
	rgoto	SID_PARIN_Scale_7	;OSC_INS_PM7
830
	rgoto	SID_PARIN_Scale_8	;OSC_INS_PM8
831
	rgoto	SID_PARIN_Scale_7	;OSC_INS_7
832
	rgoto	SID_PARIN_Scale_8	;OSC_INS_8
833
	rgoto	SID_PARIN_Scale_12	;OSC_INS_12
834
	rgoto	SID_PARIN_Scale_4	;OSC_INS_4L
835
	rgoto	SID_PARIN_Scale_6	;OSC_INS_6L
836
	rgoto	SID_PARIN_Scale_4	;OSC_INS_4U
837
	rgoto	SID_PARIN_Scale_8	;OSC_INS_PB
838
	rgoto	SID_PARIN_Scale_7	;OSC_BL_PM7
839
	rgoto	SID_PARIN_Scale_8	;OSC_BL_PM8
840
	rgoto	SID_PARIN_Scale_7	;OSC_BL_P8
841
	rgoto	SID_PARIN_Scale_7	;OSC_BL_7
842
	rgoto	SID_PARIN_Scale_8	;OSC_BL_8
843
	rgoto	SID_PARIN_Scale_12	;OSC_BL_12
844
	rgoto	SID_PARIN_Scale_4	;OSC_BL_4L
845
	rgoto	SID_PARIN_Scale_6	;OSC_BL_6L
846
	rgoto	SID_PARIN_Scale_4	;OSC_BL_4U
847
	rgoto	SID_PARIN_Scale_8	;OSC_BL_PB
848
	rgoto	SID_PARIN_Scale_12	;OSC_BL_FIL12
849
	rgoto	SID_PARIN_Scale_8	;OSC_BL_FIL8
850
	rgoto	SID_PARIN_Scale_8	;DRM_8
851
	rgoto	SID_PARIN_Scale_8	;DRM_PM8
852
	rgoto	SID_PARIN_Scale_4	;DRM_4U
853
	rgoto	SID_PARIN_Scale_4	;DRM_4L
854
	rgoto	SID_PARIN_Scale_7	;NOTE_INS
855
 
856
SID_PARIN_Scale_0
857
	clrf	MIOS_PARAMETER1
858
	clrf	MIOS_PARAMETER2
859
	return
860
 
861
SID_PARIN_Scale_1
862
	BRA_IFSET MIOS_PARAMETER3, 3, ACCESS, SID_PARIN_Scale_1_Up
863
SID_PARIN_Scale_1_Down
864
	movlw	0x00
865
	btfsc	MIOS_PARAMETER2, 7
866
	movlw 0x01
867
	movwf	MIOS_PARAMETER1
868
	clrf	MIOS_PARAMETER2
869
	return
870
SID_PARIN_Scale_1_Up
871
	movlw	0x00
872
	btfsc	MIOS_PARAMETER1, 0
873
	movlw 0x80
874
	movwf	MIOS_PARAMETER2
875
	clrf	MIOS_PARAMETER1
876
	return
877
 
878
;; ---
879
SID_PARIN_Scale_2
880
	BRA_IFSET MIOS_PARAMETER3, 3, ACCESS, SID_PARIN_Scale_2_Up
881
SID_PARIN_Scale_2_Down
882
	swapf	MIOS_PARAMETER2, W
883
	rrf	WREG, W
884
	rrf	WREG, W
885
	andlw	0x03
886
	movwf	MIOS_PARAMETER1
887
	clrf	MIOS_PARAMETER2
888
	return
889
SID_PARIN_Scale_2_Up
890
	swapf	MIOS_PARAMETER1, W
891
	rlf	WREG, W
892
	rlf	WREG, W
893
	andlw	0xc0
894
	movwf	MIOS_PARAMETER2
895
	clrf	MIOS_PARAMETER1
896
	return
897
 
898
;; ---
899
SID_PARIN_Scale_4
900
	BRA_IFSET MIOS_PARAMETER3, 3, ACCESS, SID_PARIN_Scale_4_Up
901
SID_PARIN_Scale_4_Down
902
	swapf	MIOS_PARAMETER2, W
903
	andlw	0x0f
904
	movwf	MIOS_PARAMETER1
905
	clrf	MIOS_PARAMETER2
906
	return
907
SID_PARIN_Scale_4_Up
908
	swapf	MIOS_PARAMETER1, W
909
	andlw	0xf0
910
	movwf	MIOS_PARAMETER2
911
	clrf	MIOS_PARAMETER1
912
	return
913
 
914
;; ---
915
SID_PARIN_Scale_6
916
	BRA_IFSET MIOS_PARAMETER3, 3, ACCESS, SID_PARIN_Scale_6_Up
917
SID_PARIN_Scale_6_Down
918
	rrf	MIOS_PARAMETER2, W
919
	rrf	WREG, W
920
	andlw	0x3f
921
	movwf	MIOS_PARAMETER1
922
	clrf	MIOS_PARAMETER2
923
	return
924
SID_PARIN_Scale_6_Up
925
	rlf	MIOS_PARAMETER1, W
926
	rlf	WREG, W
927
	andlw	0xfc
928
	movwf	MIOS_PARAMETER2
929
	clrf	MIOS_PARAMETER1
930
	return
931
 
932
;; ---
933
SID_PARIN_Scale_7
934
	BRA_IFSET MIOS_PARAMETER3, 3, ACCESS, SID_PARIN_Scale_7_Up
935
SID_PARIN_Scale_7_Down
936
	rrf	MIOS_PARAMETER2, W
937
	andlw	0x7f
938
	movwf	MIOS_PARAMETER1
939
	clrf	MIOS_PARAMETER2
940
	return
941
SID_PARIN_Scale_7_Up
942
	rlf	MIOS_PARAMETER1, W
943
	andlw	0xfe
944
	movwf	MIOS_PARAMETER2
945
	clrf	MIOS_PARAMETER1
946
	return
947
 
948
;; ---
949
SID_PARIN_Scale_8
950
	BRA_IFSET MIOS_PARAMETER3, 3, ACCESS, SID_PARIN_Scale_8_Up
951
SID_PARIN_Scale_8_Down
952
	movff	MIOS_PARAMETER2, MIOS_PARAMETER1
953
	clrf	MIOS_PARAMETER2
954
	return
955
SID_PARIN_Scale_8_Up
956
	movff	MIOS_PARAMETER1, MIOS_PARAMETER2
957
	clrf	MIOS_PARAMETER1
958
	return
959
 
960
;; ---
961
SID_PARIN_Scale_12
962
	BRA_IFSET MIOS_PARAMETER3, 3, ACCESS, SID_PARIN_Scale_12_Up
963
SID_PARIN_Scale_12_Down
964
	swapf	MIOS_PARAMETER2, W
965
	movwf	PRODL
966
	andlw	0x0f
967
	movwf	MIOS_PARAMETER2
968
	swapf	MIOS_PARAMETER1, W
969
	andlw	0x0f
970
	movwf	MIOS_PARAMETER1
971
	movf	PRODL, W
972
	andlw	0xf0
973
	iorwf	MIOS_PARAMETER1, F
974
	return
975
SID_PARIN_Scale_12_Up
976
	swapf	MIOS_PARAMETER1, W
977
	movwf	PRODL
978
	andlw	0xf0
979
	movwf	MIOS_PARAMETER1
980
	swapf	MIOS_PARAMETER2, W
981
	andlw	0xf0
982
	movwf	MIOS_PARAMETER2
983
	movf	PRODL, W
984
	andlw	0x0f
985
	iorwf	MIOS_PARAMETER2, F
986
	return
987
 
988
 
989
;; --------------------------------------------------------------------------
990
;; Sets a parameter value from 16bit value
991
;;  IN: index of parameter in WREG
992
;;      16bit value in MIOS_PARAMETER[12]
993
;;      SID channels which should be modified in MIOS_PARAMETER3[1:0]
994
;;      Multi Patch: Instrument number in MIOS_PARAMETER3[6:4]
995
;;      Drum Patch: Instrument number in MIOS_PARAMETER3[7:4]
996
;; --------------------------------------------------------------------------
997
SID_PARIN_Set16
998
	BRA_IFCLR INTCON, GIE, ACCESS, SID_PARIN_Set16_FromIRQ	; (for the case that IRQ already disabled)
999
	IRQ_DISABLE				; interrupts must be disabled on 16x16 multiplication!
1000
	rcall	SID_PARIN_Set16_FromIRQ
1001
	IRQ_ENABLE				; enable interrupts again
1002
	return
1003
 
1004
SID_PARIN_Set16_FromIRQ				; direct entry for SID_PARIN_SetWT
1005
	;; store parameter index in SID_PAR_IX
1006
	SET_BSR	SID_BASE
1007
	andlw	0xff			; fix zero flag
1008
	bz	SID_PARIN_Set16_End	; skip if parameter is zero
1009
	movwf	SID_PAR_IX, BANKED
1010
 
1011
	;; scale 16bit value in MIOS_PARAMETER[12] to target range
1012
	;; (SID_PAR_IX already in WREG)
1013
	bcf	MIOS_PARAMETER3, 3	; scale down
1014
	rcall	SID_PARIN_Scale
1015
 
1016
	;; set new value
1017
	movf	SID_PAR_IX, W, BANKED
1018
	rcall	SID_PARIN_Set_FromIRQ	; (IRQ already disabled)
1019
 
1020
SID_PARIN_Set16_End
1021
	return
1022
 
1023
 
1024
;; --------------------------------------------------------------------------
1025
;; Sets a NRPN parameter value (called from CC handler in sid_midi_*.inc)
1026
;;  IN: MIDI channel in SID_CURRENT_CHANNEL
1027
;;      NRPN data MSB in SID_MIDI_PARAMETER2
1028
;;      NRPN data LSB in NRPN_DATA_LSB[SID_CURRENT_CHANNEL]
1029
;;      NRPN address LSB in NRPN_ADDRESS_LSB[SID_CURRENT_CHANNEL]
1030
;;      NRPN address MSB in NRPN_ADDRESS_MSB[SID_CURRENT_CHANNEL]
1031
;;      Multi Patch: Instrument number in MIOS_PARAMETER3[6:4]
1032
;;      Drum Patch: Instrument number in MIOS_PARAMETER3[7:4]
1033
;; --------------------------------------------------------------------------
1034
SID_PARIN_SetNRPN
1035
	SET_BSR	SID_BASE
1036
 
1037
	;; LSB -> PRODL (temporary)
1038
	lfsr	FSR1, NRPN_ADDRESS_LSB
1039
	movf	SID_CURRENT_CHANNEL, W, BANKED
1040
	movff	PLUSW1, PRODL
1041
 
1042
	;; MSB mask: ensure that following values are accepted:
1043
	;; 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 - scaled values
1044
	;; 0x40, 0x41, 0x42, 0x43, 0x44, 0x45 - absolute values
1045
	lfsr	FSR1, NRPN_ADDRESS_MSB
1046
	movf	SID_CURRENT_CHANNEL, W, BANKED
1047
	movf	PLUSW1, W
1048
	movwf	PRODH		; temporary store in PRODH
1049
	andlw	0xb8		; (mask out bit [2:0] and bit #6)
1050
	bnz	SID_PARIN_SetNRPN_End
1051
 
1052
	;; invalid if PRODH[2:1] == 3
1053
	movf	PRODH, W
1054
	andlw	0x06
1055
	xorlw	0x06
1056
	bz	SID_PARIN_SetNRPN_End
1057
 
1058
	;; if PRODH[2:1] == 0 -> turn it to 3 (L/R channel selected)
1059
	movf	PRODH, W
1060
	andlw	0x06
1061
	movlw	0x06
1062
	skpnz
1063
	iorwf	PRODH, F
1064
 
1065
	;; now select L/R channel
1066
	rrf	PRODH, W
1067
	andlw	0x03
1068
	iorwf	MIOS_PARAMETER3, F
1069
 
1070
	;; set 8th bit in parameter number-> PRODL
1071
	btfsc	PRODH, 0
1072
	bsf	PRODL, 7
1073
 
1074
	;; prepare data LSB -> MIOS_PARAMETER1
1075
	lfsr	FSR1, NRPN_DATA_LSB
1076
	movf	SID_CURRENT_CHANNEL, W, BANKED
1077
	movf	PLUSW1, W
1078
	movwf	MIOS_PARAMETER1
1079
 
1080
	;; branch depending on scaled/absolute selection
1081
	BRA_IFSET PRODH, 6, ACCESS, SID_PARIN_SetNRPN_Abs
1082
SID_PARIN_SetNRPN_Scaled
1083
	;; expecting left-aligned 16bit data word in MIOS_PARAMETER[12]
1084
	movff	SID_MIDI_PARAMETER2, MIOS_PARAMETER2
1085
	clrc
1086
	rlf	MIOS_PARAMETER1, F
1087
	clrc
1088
	rlf	MIOS_PARAMETER1, F
1089
	rlf	MIOS_PARAMETER2, F
1090
 
1091
	;; call parameter function
1092
	movf	PRODL, W
1093
	rcall	SID_PARIN_Set16
1094
 
1095
	rgoto	SID_PARIN_SetNRPN_End
1096
 
1097
SID_PARIN_SetNRPN_Abs
1098
	;; expecting right-aligned 16bit data word in MIOS_PARAMETER[12]
1099
	movff	SID_MIDI_PARAMETER2, MIOS_PARAMETER2
1100
	rrf	MIOS_PARAMETER2, F
1101
	skpc
1102
	bsf	MIOS_PARAMETER1, 7
1103
 
1104
	;; call parameter function
1105
	movf	PRODL, W
1106
	call	SID_PARIN_Set
1107
 
1108
	;; 	rgoto	SID_PARIN_SetNRPN_End
1109
 
1110
SID_PARIN_SetNRPN_End
1111
	return
1112
 
1113
 
1114
;; --------------------------------------------------------------------------
1115
;; Sets a Parameter Value from WT handler
1116
;;  IN: index of parameter in WREG
1117
;;      8bit WT value (from WT table) in MIOS_PARAMETER1
1118
;;      SID channels which should be modified in MIOS_PARAMETER3[1:0]
1119
;;      Multi Patch: Instrument number in MIOS_PARAMETER3[6:4]
1120
;;      Drum Patch: Instrument number in MIOS_PARAMETER3[7:4]
1121
;; --------------------------------------------------------------------------
1122
	;; SHOULD ONLY BE CALLED FROM IRQ (sid_se.inc)
1123
SID_PARIN_SetWT
1124
	;; store parameter index in SID_PAR_IX
1125
	SET_BSR	SID_BASE
1126
	andlw	0xff			; fix zero flag
1127
	bz	SID_PARIN_SetWT_End	; skip if parameter is zero
1128
	movwf	SID_PAR_IX, BANKED
1129
 
1130
	;; branch depending on relative (bit 7 cleared) or absolute value (bit 7 set)
1131
	BRA_IFSET MIOS_PARAMETER1, 7, ACCESS, SID_PARIN_SetWT_Abs
1132
SID_PARIN_SetWT_Rel
1133
	;; convert signed 7bit to signed 15bit, result in MUL_R_[23]
1134
	clrf	MUL_R_2, BANKED
1135
	clrc
1136
	rlf	MIOS_PARAMETER1, W
1137
	addlw	-0x80
1138
	movwf	MUL_R_3, BANKED
1139
	;; skip modification if offset is 0
1140
	bz	SID_PARIN_SetWT_End
1141
 
1142
	;; get current value -> MIOS_PARAMETER[12]
1143
	;; take value from shadow buffer!
1144
	bsf	MIOS_PARAMETER3, 2
1145
	movf	SID_PAR_IX, W, BANKED
1146
	call	SID_PAROUT_Get
1147
 
1148
	;; scale value in MIOS_PARAMETER[12] to 16bit
1149
	movf	SID_PAR_IX, W, BANKED
1150
	bsf	MIOS_PARAMETER3, 3	; scale up
1151
	rcall	SID_PARIN_Scale
1152
 
1153
	;; add MUL_R_[23] to MIOS_PARAMETER[12] and saturate
1154
	movf	MUL_R_2, W, BANKED
1155
	addwf	MIOS_PARAMETER1, F
1156
	movf	MUL_R_3, W, BANKED
1157
	addwfc	MIOS_PARAMETER2, F
1158
	BRA_IFSET MUL_R_3, 7, BANKED, SID_PARIN_SetWT_SatNeg
1159
SID_PARIN_SetWT_SatPos
1160
	bnc	SID_PARIN_SetWT_NoSat
1161
	setf	MIOS_PARAMETER1
1162
	setf	MIOS_PARAMETER2
1163
	rgoto	SID_PARIN_SetWT_Sat_Cont
1164
SID_PARIN_SetWT_SatNeg
1165
	bc	SID_PARIN_SetWT_NoSat
1166
	clrf	MIOS_PARAMETER1
1167
	clrf	MIOS_PARAMETER2
1168
	;; 	rgoto	SID_PARIN_SetWT_Sat_Cont
1169
SID_PARIN_SetWT_Sat_Cont
1170
SID_PARIN_SetWT_NoSat
1171
 
1172
	;; scale 16bit value in MIOS_PARAMETER[12] to target range
1173
	movf	SID_PAR_IX, W, BANKED
1174
	bcf	MIOS_PARAMETER3, 3	; scale down
1175
	rcall	SID_PARIN_Scale
1176
 
1177
	;; store new value
1178
	movf	SID_PAR_IX, W, BANKED
1179
	goto	SID_PARIN_Set
1180
 
1181
 
1182
SID_PARIN_SetWT_Abs
1183
	;; 7bit -> 16bit value
1184
	clrc
1185
	rlf	MIOS_PARAMETER1, W
1186
	movwf	MIOS_PARAMETER2
1187
	clrf	MIOS_PARAMETER1
1188
 
1189
	;; set new value
1190
	movf	SID_PAR_IX, W, BANKED
1191
	rcall	SID_PARIN_Set16_FromIRQ
1192
 
1193
SID_PARIN_SetWT_End
1194
	return
1195
 
1196
 
1197
 
1198
;; --------------------------------------------------------------------------
1199
;; Help routine which determines the instrument->voice assignments depending
1200
;; on the instrument selection in SID_PAR_IX
1201
;; only used by the SID_PARIN_SID_OSC_INS_MACRO to save code
1202
;; IN: instrument selection in SID_PAR_IX[2:0]
1203
;;     current instrument in MIOS_PARAMETER3[6:4]
1204
;; OUT: affected voices in PRODH[5:0]
1205
;; --------------------------------------------------------------------------
1206
SID_PARIN_Hlp_GetVoices
1207
	movf	SID_PAR_IX, W, BANKED
1208
	andlw	0x07
1209
	bz	SID_PARIN_Hlp_GetVoices_All
1210
	addlw	-1
1211
	bz	SID_PARIN_Hlp_GetVoices_Cur
1212
SID_PARIN_Hlp_GetVoices_Single
1213
	addlw	-1
1214
SID_PARIN_Hlp_GetVoices_Cur_Cont
1215
	;; final voice selection in PRODH
1216
	clrf	PRODH
1217
	SET_BSR	SIDL_V1_BASE
1218
	cpfseq	SIDL_V1_BASE + SID_Vx_ASSIGNED_MV, BANKED
1219
	rgoto	SID_PARIN_Hlp_GetVoices_Not0
1220
SID_PARIN_Hlp_GetVoices_0
1221
	bsf	PRODH, 0
1222
SID_PARIN_Hlp_GetVoices_Not0
1223
	cpfseq	SIDL_V2_BASE + SID_Vx_ASSIGNED_MV, BANKED
1224
	rgoto	SID_PARIN_Hlp_GetVoices_Not1
1225
SID_PARIN_Hlp_GetVoices_1
1226
	bsf	PRODH, 1
1227
SID_PARIN_Hlp_GetVoices_Not1
1228
	cpfseq	SIDL_V3_BASE + SID_Vx_ASSIGNED_MV, BANKED
1229
	rgoto	SID_PARIN_Hlp_GetVoices_Not2
1230
SID_PARIN_Hlp_GetVoices_2
1231
	bsf	PRODH, 2
1232
SID_PARIN_Hlp_GetVoices_Not2
1233
	cpfseq	SIDR_V1_BASE + SID_Vx_ASSIGNED_MV, BANKED
1234
	rgoto	SID_PARIN_Hlp_GetVoices_Not3
1235
SID_PARIN_Hlp_GetVoices_3
1236
	bsf	PRODH, 3
1237
SID_PARIN_Hlp_GetVoices_Not3
1238
	cpfseq	SIDR_V2_BASE + SID_Vx_ASSIGNED_MV, BANKED
1239
	rgoto	SID_PARIN_Hlp_GetVoices_Not4
1240
SID_PARIN_Hlp_GetVoices_4
1241
	bsf	PRODH, 4
1242
SID_PARIN_Hlp_GetVoices_Not4
1243
	cpfseq	SIDR_V3_BASE + SID_Vx_ASSIGNED_MV, BANKED
1244
	rgoto	SID_PARIN_Hlp_GetVoices_Not5
1245
SID_PARIN_Hlp_GetVoices_5
1246
	bsf	PRODH, 5
1247
SID_PARIN_Hlp_GetVoices_Not5
1248
	SET_BSR	SID_BASE
1249
	return
1250
 
1251
SID_PARIN_Hlp_GetVoices_All
1252
	movlw	0x3f
1253
	movwf	PRODH
1254
	return
1255
 
1256
SID_PARIN_Hlp_GetVoices_Cur
1257
	swapf	MIOS_PARAMETER3, W
1258
	andlw	0x07
1259
	rgoto	SID_PARIN_Hlp_GetVoices_Cur_Cont
1260
 
1261
 
1262
;; --------------------------------------------------------------------------
1263
;; Help routine which increments FSR1 to the next voice
1264
;; only used by the SID_PARIN_SID_OSC_INS_MACRO to save code
1265
;; --------------------------------------------------------------------------
1266
SID_PARIN_Hlp_FSR1_NextVoice
1267
	movlw	(SID_Ix_M_I2_BASE-SID_Ix_M_I1_BASE)
1268
	addwf	FSR1L, F
1269
	movlw	0
1270
	addwfc	FSR1H, F
1271
	return
1272
 
1273
;; --------------------------------------------------------------------------
1274
;; Help routine which determines the BL->voice assignments depending
1275
;; on the instrument selection in SID_PAR_IX
1276
;; only used by the SID_PARIN_SID_OSC_BL_MACRO to save code
1277
;; IN: instrument selection in SID_PAR_IX[1:0]
1278
;;     current instrument in MIOS_PARAMETER3[6:4]
1279
;; OUT: affected voices in PRODH[1:0]
1280
;; --------------------------------------------------------------------------
1281
SID_PARIN_Hlp_GetBL
1282
	movf	SID_PAR_IX, W, BANKED
1283
	andlw	0x03
1284
	bz	SID_PARIN_Hlp_GetBL_All
1285
	addlw	-1
1286
	bz	SID_PARIN_Hlp_GetBL_Cur
1287
	addlw	-1
1288
	bz	SID_PARIN_Hlp_GetBL_L
1289
SID_PARIN_Hlp_GetBL_R
1290
	movlw	0x02
1291
	rgoto	SID_PARIN_Hlp_GetBL_End
1292
SID_PARIN_Hlp_GetBL_L
1293
	movlw	0x01
1294
	rgoto	SID_PARIN_Hlp_GetBL_End
1295
SID_PARIN_Hlp_GetBL_Cur
1296
	swapf	MIOS_PARAMETER3, W
1297
	andlw	0x03
1298
	rgoto	SID_PARIN_Hlp_GetBL_End
1299
SID_PARIN_Hlp_GetBL_All
1300
	movlw	0x03
1301
	;; 	rgoto	SID_PARIN_Hlp_GetBL_End
1302
SID_PARIN_Hlp_GetBL_End
1303
	movwf	PRODH
1304
	return
1305
 
1306