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: main.inc 44 2008-01-30 21:39:30Z tk $
1 tk 2
;
3
; MIOS Application
4
; MIDIbox SID
5
;
6
; -> see doc/README.txt for details
7
;
8
;
9
; ==========================================================================
10
;
11
; Hardware related setup is located in setup_mbseq_*.asm
12
; Please make your customisations there
13
;
14
; ==========================================================================
15
;
16
; ==========================================================================
17
;
18
;  Copyright 1998-2007 Thorsten Klose (tk@midibox.org)
19
;  Licensed for personal non-commercial use only.
20
;  All other rights reserved.
21
;
22
; ==========================================================================
23
;
24
; Version:                <-------------------->
25
#define MBSID_VERSION_STR "MIDIboxSID V2.0RC17 "
26
; (fixed string length - 20 characters!)
27
 
28
;; MBNET specific definitions (ping reply information - don't touch this!)
29
#define MBNET_CONST_PROTOCOL_V		1
30
#define MBNET_CONST_TYPE_C0		'S'
31
#define MBNET_CONST_TYPE_C1		'I'
32
#define MBNET_CONST_TYPE_C2		'D'
33
#define MBNET_CONST_TYPE_C3		' '
34
#define MBNET_CONST_TYPE_VERSION	2
35
#define MBNET_CONST_TYPE_SUBVERSION	0
36
;
37
;
38
;; temporary flag which allows automatic patch modifications on structural changes
39
;; BankStick content will be modified!
40
#define ENABLE_PATCH_FIXING 0
41
;
42
;
43
;
44
        ERRORLEVEL      -311    ; suppress "Operand of HIGH operator was larger than H'FFFF'"
45
;
46
;; ---[ MIOS header file ]---
47
#include <mios.h>
48
 
49
;; ---[ useful macros ]---
50
#include <macros.h>
51
 
52
;; ---[ vectors to MIOS functions (never change!) ]---
53
#include <mios_vectors.inc>
54
 
55
;; ---[ user hooks (never change!) ]---
56
#include <user_vectors.inc>
57
 
58
;; ---[ variables used by application ]---
59
#include "app_defines.h"
60
 
61
; ==========================================================================
62
 
63
;; ---[ configuration table for MIDI processor and rotary encoders ]---
64
#include "mios_tables.inc"
65
 
66
;; ---[ MBNet Clone Code -- must be located at the begin of the user flash range ]---
67
;; ---[ reserved region: 0x3300-0x3500 ]---
68
#include "mbnet_clone.inc"
69
 
70
;; ---[ Custom LCD driver ]---
71
#include "app_lcd.inc"
72
#include "special_characters.inc"
73
 
74
;; ==========================================================================
75
;;  All MIOS hooks in one file
76
;; ==========================================================================
77
 
78
;; --------------------------------------------------------------------------
79
;;  This function is called by MIOS after startup to initialize the
80
;;  application
81
;; --------------------------------------------------------------------------
82
USER_Init
83
	;; avoid that program will be started on a PIC which doesn't meet the memory requirements
84
	;; this is to gracefully stop the application from exeution of non-available code memory
85
 
86
	;; in MBSID, we only consider the usage of PIC18F4685, PIC18F4682 and partly PIC18F4620 (master only)
87
	;; execution on PIC18F452 is prevented
88
	;; due to these variations, the DEVID1 won't be checked, only DEVID2
89
	clrf	SID_STAT		; clear whole SID status register
90
	IRQ_DISABLE			; interrupts must be disabled, as TBLPTRU is changed
91
	TABLE_ADDR_FULL 0x3ffffe
92
	tblrd*+
93
	movf	TABLAT, W		; read DEVID1
94
	movwf	TMP1			; store for MIDI message
95
	tblrd*+
96
	movf	TABLAT, W		; read DEVID2
97
	movwf	TMP2			; store for MIDI message
98
	xorlw	0x27			; for PIC18F2682/2685/4682/4685
99
	bz	USER_Init_PIC_Ok
100
#if 0
101
	;; PIC18F4620 not supported anymore - 64k border reached
102
	xorlw	0x0c ^ 0x27		; for PIC18F2525/2620/4525/4620
103
	bz	USER_Init_PIC_Ok
104
#endif
105
USER_Init_PIC_NotOk
106
	clrf	TBLPTRU			; clear TBLPTRU
107
	IRQ_ENABLE			; temporary enable interrupts again
108
	movlw	0xee			; send MIDI event to notify that the app won't be started (for the case that no LCD is connected to core)
109
	call	MIOS_MIDI_TxBufferPut
110
	swapf	TMP1, W			; send DEV[2:0]
111
	andlw	0x07
112
	call	MIOS_MIDI_TxBufferPut	; send DEV[9:3]
113
	movf	TMP2, W
114
	andlw	0x7f
115
	call	MIOS_MIDI_TxBufferPut	; send DEV[9:3]
116
	call	MIOS_MIDI_TxBufferFlush	; wait until message sent
117
	IRQ_DISABLE			; disable interrupts
118
USER_Init_PIC_NotOk_Kill		; and loop endless (WDT will reset the chip)
119
	rgoto	USER_Init_PIC_NotOk_Kill
120
USER_Init_PIC_Ok
121
	clrf	TBLPTRU			; clear TBLPTRU
122
	IRQ_ENABLE			; enable interrupts again
123
 
124
 
125
	;; initialize application specific variables
126
	clrf	SID_SYSEX_STATE
127
	clrf	SID_SYSEX_ACTION
128
	setf	SID_BANKSTICK_CHK_CTR	; (we have to start with BS0 in SID_BANK_CheckStick)
129
 
130
        ;; Initialize Clock Generator (the PWM unit is used to generate a 1MHz clock with 1:1 duty cycle)
131
        movlw   0x09
132
        movwf   PR2
133
	movlw	0x24
134
	movwf	T2CON
135
        movlw   0x0f
136
        movwf   CCP1CON
137
	movlw	0x04
138
        movwf   CCPR1L
139
 
140
	;; initialize the MBHP_SID module
141
	call	SID_SR_Init
142
 
143
	;; get and store the device ID
144
	call	MIOS_MIDI_DeviceIDGet
145
	movwf	SID_MIDI_DEVICE
146
 
147
	;; initial random seed
148
	SET_BSR	SID_BASE
149
	;; restart pseudo random generator
150
	movlw	0x42
151
	movwf	SID_RANDOM_SEED_L, BANKED
152
	movwf	SID_RANDOM_SEED_H, BANKED
153
 
154
	;; ensure that volume is already maximum when starting MBSID
155
	;; this might look incorrect, but the reason is, that there is some increased
156
	;; background noise when VOL registers are zero!
157
	movlw	0x0f
158
	movff	WREG, SIDL_BASE + SIDx_MODE_VOL
159
	movff	WREG, SIDR_BASE + SIDx_MODE_VOL
160
 
161
	;; load patch buffer and init patch
162
	clrf	SID_PATCH
163
	clrf	SID_BANK
164
	call	SID_PATCH_LoadPatchBuffer
165
 
166
	;; init ensemble
167
	;; (will be done again from the CS once CAN slaves are available)
168
	call	SID_ENS_LoadDefaultNum
169
	call	SID_ENS_Init
170
 
171
	;; initialize the shift registers (master only)
172
	movf	SID_MIDI_DEVICE, W	; skip if device ID != 0x00
173
	bnz	USER_Init_NoCS
174
USER_Init_CS
175
	movlw	DEFAULT_SRIO_NUMBER	; number of used shift registers in a chain
176
	call	MIOS_SRIO_NumberSet
177
	movlw	0x01			; set update frequncy
178
	call	MIOS_SRIO_UpdateFrqSet
179
	movlw	0x00			; disable touch sensor
180
	call	MIOS_SRIO_TS_SensitivitySet
181
USER_Init_NoCS
182
 
183
#if DEFAULT_J5_FUNCTION == 1
184
	;; initialize J5 for analog inputs if enabled
185
 	call	AIN_Init
186
#endif
187
#if (DEFAULT_J5_FUNCTION == 2) || (DEFAULT_J5_FUNCTION == 3)
188
	;; initialize J5 for driving LEDs if enabled
189
	call	J5_DOUT_Init
190
#endif
191
 
192
	;; initialize the AOUT module if enabled
193
#if ENABLE_AOUT == 1
194
	call	SID_AOUT_Init
195
#endif
196
#if ENABLE_AOUT == 2
197
	call	SID_AOUT_LC_Init
198
#endif
199
#if ENABLE_AOUT == 3
200
	call	SID_AOUT_NG_Init
201
#endif
202
 
203
	;; initialize the integrated MIDI merger
204
	movlw	MIOS_MIDI_MERGER_DISABLED	; should be disabled for a synthesizer
205
	call	MIOS_MIDI_MergerSet
206
 
207
	;; initialize the ECAN interface
208
	call	MBNET_Init
209
 
210
	;; initialize SID player
211
	call	SIDPLAY_Init
212
 
213
	;; disable engine so long no note is played
214
	;; this is to overcome a WDT issue when no display is connected (LCD timeout loop takes too long on high IRQ load)
215
	bsf	SID_STAT, SID_STAT_ENGINE_DISABLE_LEVEL0
216
 
217
	;; initialize the timer for the SIDSW handler
218
	movlw	LOW(10000)		; every 1 mS (update cycle splitted into 2 halfs!)
219
	movwf	MIOS_PARAMETER1
220
	movlw	HIGH(10000)
221
	movwf	MIOS_PARAMETER2
222
	movlw	0x00			; prescaler 1:1
223
	call	MIOS_TIMER_Init
224
 
225
	;; reset the control surface
226
	call	CS_MENU_Reset
227
 
228
	return
229
 
230
;; --------------------------------------------------------------------------
231
;;  This function is called by MIOS in the mainloop when nothing else is to do
232
;; --------------------------------------------------------------------------
233
USER_Tick
234
	;; enable engine (only required after startup or after a SysEx/MBNet patch upload)
235
	bcf	SID_STAT, SID_STAT_ENGINE_DISABLE_LEVEL0
236
 
237
	;; ---[ update AOUTs (if enabled) ]---
238
#if ENABLE_AOUT == 1
239
	call	SID_AOUT_Update
240
#endif
241
#if ENABLE_AOUT == 2
242
	call	SID_AOUT_LC_Update
243
#endif
244
#if ENABLE_AOUT == 3
245
	call	SID_AOUT_NG_Update
246
#endif
247
 
248
	;; if not in SIDPLAY mode:
249
	BRA_IFSET SID_STAT, SID_STAT_SIDPLAYER, ACCESS, USER_Tick_SIDPlayEnabled
250
USER_Tick_SIDPlayDisabled
251
	;; ---[ check BankStick status ]---
252
 	call	SID_BANK_CheckStick
253
 
254
	;; ---[ call SID shift register handler ]---
255
	call	SID_SR_Handler
256
	rgoto	USER_Tick_SIDPlayDisabled_Cont
257
 
258
USER_Tick_SIDPlayEnabled
259
	;; disable CS if SID player enabled and SID#1 selected
260
	;; (tmp. disable interrupts, so that LED matrix doesn't start to decrement bar counters)
261
	IRQ_DISABLE
262
	bcf	SID_STAT, SID_STAT_SIDPLAYER_CS_DISABLE
263
	btfsc	CS_MENU_SELECTED_SID_FLAGS, 0
264
	bsf	SID_STAT, SID_STAT_SIDPLAYER_CS_DISABLE
265
	IRQ_ENABLE
266
USER_Tick_SIDPlayDisabled_Cont
267
 
268
	;; ---[ call the MBNET handler ]---
269
	call	MBNET_Handler
270
 
271
#if DEFAULT_SRM_BUTTONS_DIN
272
	;; ---[ button matrix ]---
273
	call	CS_MENU_MATRIX_BHandler
274
#endif
275
 
276
#if DEFAULT_J5_FUNCTION == 1
277
	;; ---[ AD handler ]---
278
	call	AIN_Handler
279
#endif
280
	return
281
 
282
 
283
;; --------------------------------------------------------------------------
284
;;  This function is periodically called by MIOS. The frequency has to be
285
;;  initialized with MIOS_Timer_Set
286
;;  Note that this is an interrupt service routine! Use FSR2 instead of FSR0
287
;;  and IRQ_TMPx instead of TMPx -- and make the routine as fast as possible!
288
;; --------------------------------------------------------------------------
289
USER_Timer
290
 
291
#if DEFAULT_J5_FUNCTION == 1
292
	;; ---[ AD conversion ]---
293
	call	AIN_Tick
294
#endif
295
 
296
	;; ---[ call Software SID Handler ]---
297
	;; (if not in SIDPLAY mode)
298
	CALL_IFCLR SID_STAT, SID_STAT_SIDPLAYER, ACCESS, SIDSE_Handler
299
 
300
	movf	SID_MIDI_DEVICE, W	; skip if device ID != 0x00
301
	bnz	USER_TimerNoCS
302
 
303
	;; ---[ handle with control surface variables (flashing cursor, etc) ]---
304
	call	CS_MENU_TIMER
305
USER_TimerNoCS
306
 
307
	return
308
 
309
;; --------------------------------------------------------------------------
310
;;  This function is called by MIOS when a debug command has been received
311
;;  via SysEx
312
;;  Input:
313
;;     o WREG, MIOS_PARAMETER1, MIOS_PARAMETER2, MIOS_PARAMETER3 like
314
;;       specified in the debug command
315
;;  Output:
316
;;     o return values WREG, MIOS_PARAMETER1, MIOS_PARAMETER2, MIOS_PARAMETER3
317
;; --------------------------------------------------------------------------
318
USER_MPROC_DebugTrigger
319
	return
320
 
321
 
322
;; --------------------------------------------------------------------------
323
;;  This function is called by MIOS when the display content should be
324
;;  initialized. Thats the case during startup and after a temporary message
325
;;  has been printed on the screen
326
;; --------------------------------------------------------------------------
327
TEXT_WELCOME_0	STRING 20, 0x00, MBSID_VERSION_STR
328
TEXT_WELCOME_10	STRING 16, 0x40, "Launching CS    "
329
TEXT_WELCOME_11	STRING 16, 0x40, "CS not enabled! "
330
 
331
USER_DISPLAY_Init
332
	;; clear screen
333
	call	MIOS_LCD_Clear
334
 
335
	TABLE_ADDR TEXT_WELCOME_0		; print welcome message
336
 
337
	;; print welcome message only during startup phase
338
	movf	CS_MENU_REINIT_CFG_CTR, W
339
	bz	USER_DISPLAY_Init_NoStartup
340
 
341
	call	MIOS_LCD_PrintString		; first line
342
 
343
	TABLE_ADDR TEXT_WELCOME_10
344
	movf	SID_MIDI_DEVICE, W
345
	bz	USER_DISPLAY_Init_NotDis
346
USER_DISPLAY_Init_Dis
347
	TABLE_ADDR TEXT_WELCOME_11
348
USER_DISPLAY_Init_NotDis
349
	call	MIOS_LCD_PrintString		; second line
350
 
351
	;; only if character LCD connected: init special characters
352
	BRA_IFSET MIOS_BOX_CFG0, MIOS_BOX_CFG0_USE_GLCD, ACCESS, USER_DISPLAY_Init_NoSC
353
	TABLE_ADDR CS_MENU_SPECIAL_CHARS	; (defined in special_characters.inc)
354
	call	MIOS_CLCD_SpecialCharsInit
355
USER_DISPLAY_Init_NoSC
356
 
357
USER_DISPLAY_Init_NoStartup
358
 
359
	;; request an initialization
360
	bsf	CS_STAT, CS_STAT_DISPLAY_INIT_REQ
361
 
362
	;; exception: if in SID player mode, and first SID selected: call special LCD init routine
363
	BRA_IFCLR SID_STAT, SID_STAT_SIDPLAYER, ACCESS, USER_DISPLAY_Init_NoPlayer
364
	BRA_IFCLR CS_MENU_SELECTED_SID_FLAGS, 0, ACCESS, USER_DISPLAY_Init_NoPlayer
365
USER_DISPLAY_Init_Player
366
	;; init LCD
367
	call	SIDPLAY_InitLCD
368
USER_DISPLAY_Init_NoPlayer
369
 
370
	;; in the next cycle USER_DISPLAY_Tick will be called which
371
	;; does the job
372
	return
373
 
374
 
375
;; --------------------------------------------------------------------------
376
;;  This function is called in the mainloop when no temporary message is shown
377
;;  on screen. Print the realtime messages here
378
;; --------------------------------------------------------------------------
379
USER_DISPLAY_Tick
380
	movf	SID_MIDI_DEVICE, W	; exit if device ID != 0x00
381
	skpz
382
	return
383
 
384
	;; exception: if in SID player mode, and first SID selected: don't do anything
385
	btfsc	SID_STAT, SID_STAT_SIDPLAYER_CS_DISABLE
386
	return
387
 
388
	;; continue at the control surface menu handler
389
	call	CS_MENU_Handler
390
 
391
#if 0
392
	movlw	0x00
393
	call	MIOS_LCD_CursorSet
394
	movff	0x3dc, WREG
395
	call	MIOS_LCD_PrintHex2
396
	movff	0x3dd, WREG
397
	call	MIOS_LCD_PrintHex2
398
	movff	0x3de, WREG
399
	call	MIOS_LCD_PrintHex2
400
	movff	0x3df, WREG
401
	call	MIOS_LCD_PrintHex2
402
#endif
403
 
404
	return
405
 
406
;; --------------------------------------------------------------------------
407
;;  This function is called by MIOS when a complete MIDI event has been received
408
;;  Input:
409
;;     o first  MIDI event byte in MIOS_PARAMETER1
410
;;     o second MIDI event byte in MIOS_PARAMETER2
411
;;     o third  MIDI event byte in MIOS_PARAMETER3
412
;; --------------------------------------------------------------------------
413
USER_MPROC_NotifyReceivedEvent
414
	;; branch to ReceiveEvent function of SID synth
415
	goto	SID_MIDI_NotifyReceivedEvent
416
 
417
 
418
;; --------------------------------------------------------------------------
419
;;  This function is called by MIOS when a MIDI event has been received
420
;;  which has been specified in the CONFIG_MIDI_IN table
421
;;  Input:
422
;;     o number of entry in WREG
423
;;     o first  MIDI event byte in MIOS_PARAMETER1
424
;;     o second MIDI event byte in MIOS_PARAMETER2
425
;;     o third  MIDI event byte in MIOS_PARAMETER3
426
;; --------------------------------------------------------------------------
427
USER_MPROC_NotifyFoundEvent
428
	return
429
 
430
 
431
;; --------------------------------------------------------------------------
432
;;  This function is called by MIOS when a MIDI event has not been completly
433
;;  received within 2 seconds
434
;; --------------------------------------------------------------------------
435
USER_MPROC_NotifyTimeout
436
	;; -> jump to "ActionInvalid" for a proper reset of the sysex parser
437
	goto	SID_SYSEX_ActionInvalid
438
 
439
;; --------------------------------------------------------------------------
440
;;  This function is called by MIOS when a MIDI byte has been received
441
;;  Input:
442
;;     o received MIDI byte in WREG and MIOS_PARAMETER1
443
;; --------------------------------------------------------------------------
444
USER_MPROC_NotifyReceivedByte
445
	;; -> check for SIDplay stream
446
	;; (only done for master)
447
	movf	SID_MIDI_DEVICE, F ; don't modify WREG
448
	bnz	USER_MPROC_NotifyReceivedByteNSP
449
USER_MPROC_NotifyReceivedByteSP
450
	movff	WREG, SID_MIDI_PARAMETER1	; store byte in WREG
451
	call	SIDPLAY_Handler
452
	btfsc	SID_STAT, SID_STAT_SIDPLAYER; exit here if SID player enabled
453
	return
454
	movff	SID_MIDI_PARAMETER1, WREG	; restore byte
455
USER_MPROC_NotifyReceivedByteNSP
456
 
457
	;; -> continue at SID_MPROC_Parser
458
	goto	SID_SYSEX_Parser
459
 
460
;; --------------------------------------------------------------------------
461
;;  This function is called by MIOS before the transfer of a MIDI byte.
462
;;  It can be used to monitor the Tx activity or to do any other actions
463
;;  (e.g. to switch a pin for multiplexed MIDI Outs) before the byte will
464
;;  be sent.
465
;;  Note that this is an interrupt service routine! Use FSR2 instead of FSR0
466
;;  and IRQ_TMPx instead of TMPx -- and make the routine as fast as possible!
467
;;  Input:
468
;;     o transmitted byte in WREG
469
;; --------------------------------------------------------------------------
470
USER_MIDI_NotifyTx
471
	return
472
 
473
;; --------------------------------------------------------------------------
474
;;  This function is called by MIOS when a MIDI byte has been received.
475
;;  It can be used to monitor the Rx activity or to do any action - e.g.
476
;;  to react on realtime events like MIDI clock (0xf8) with a minimum latency
477
;;  Note that this is an interrupt service routine! Use FSR2 instead of FSR0
478
;;  and IRQ_TMPx instead of TMPx -- and make the routine as fast as possible!
479
;;  Input:
480
;;     o received byte in WREG
481
;; --------------------------------------------------------------------------
482
USER_MIDI_NotifyRx
483
	;; temporary save received byte in IRQ_TMP1
484
	movwf	IRQ_TMP1
485
 
486
	SET_BSR	SID_BASE
487
 
488
	;; notify clock event if received
489
	movlw	0xf8
490
	cpfseq	IRQ_TMP1, ACCESS
491
	rgoto USER_MIDI_NotifyRx_NoClk
492
USER_MIDI_NotifyRx_Clk
493
	;; we've measured a new delay between two F8 events
494
	movf	SID_INCOMING_CLK_CTR, W, BANKED
495
	movwf	SID_INCOMING_CLK_DELAY, BANKED
496
	clrf	SID_INCOMING_CLK_CTR, BANKED
497
 
498
	;; increment clock counter by 4
499
	movf	SID_SENT_CLK_CTR, W, BANKED
500
	sublw	4
501
	addwf	SID_CLK_REQ_CTR, F, BANKED
502
 
503
	;; clear interpolation clock counter and get new SENT_CLK delay
504
	clrf	SID_SENT_CLK_CTR, BANKED
505
	rrf	SID_INCOMING_CLK_DELAY, W, BANKED
506
	rrf	WREG, W
507
	andlw	0x3f
508
	movwf	SID_SENT_CLK_DELAY, BANKED
509
USER_MIDI_NotifyRx_NoClk
510
 
511
	;; if MIDI start: notify start
512
	movlw	0xfa
513
	cpfseq	IRQ_TMP1, ACCESS
514
	rgoto USER_MIDI_NotifyRx_NoStart
515
USER_MIDI_NotifyRx_Start
516
	bsf	SID_SE_STATE, SID_SE_STATE_MIDI_CLK_FA_REQ, BANKED
517
 
518
	;; Auto Mode: immediately switch to slave mode
519
	movff	SID_LOCAL_ENS + SID_ENSx_CTRL1, WREG
520
	btfsc	WREG, SID_ENS_CTRL1_CLK_AUTO
521
	bsf	SID_STAT, SID_STAT_CLK_SLAVE
522
 
523
	;; ensure that incoming clock counter != 0xff (means: no clock received for long time)
524
	incf	SID_INCOMING_CLK_CTR, W, BANKED
525
	movlw	0x80		; should be enough until first MIDI clock
526
	skpnz
527
	clrf	SID_INCOMING_CLK_CTR, BANKED
528
 
529
	;; cancel all requested clocks
530
	clrf	SID_CLK_REQ_CTR, BANKED
531
	movlw	3
532
	movwf	SID_SENT_CLK_CTR, BANKED
533
USER_MIDI_NotifyRx_NoStart
534
 
535
	;; if MIDI continue: notify continue
536
	movlw	0xfb
537
	cpfseq	IRQ_TMP1, ACCESS
538
	rgoto USER_MIDI_NotifyRx_NoCont
539
USER_MIDI_NotifyRx_Cont
540
	bsf	SID_SE_STATE, SID_SE_STATE_MIDI_CLK_FB_REQ, BANKED
541
USER_MIDI_NotifyRx_NoCont
542
 
543
	;; if MIDI stop: notify stop
544
	movlw	0xfc
545
	cpfseq	IRQ_TMP1, ACCESS
546
	rgoto USER_MIDI_NotifyRx_NoStop
547
USER_MIDI_NotifyRx_Stop
548
	bsf	SID_SE_STATE, SID_SE_STATE_MIDI_CLK_FC_REQ, BANKED
549
USER_MIDI_NotifyRx_NoStop
550
 
551
	return
552
 
553
;; --------------------------------------------------------------------------
554
;;  This function is called by MIOS when an button has been toggled
555
;;  Input:
556
;;     o Button number in WREG and MIOS_PARAMETER1
557
;;     o Button value MIOS_PARAMETER2:
558
;;       - 1 if button has been released (=5V)
559
;;       - 0 if button has been pressed (=0V)
560
;; --------------------------------------------------------------------------
561
USER_DIN_NotifyToggle
562
	movf	SID_MIDI_DEVICE, W	; skip if device ID != 0x00
563
	bnz	USER_DIN_NotifyToggleNoCS
564
 
565
	;; continue in cs_menu_button.inc
566
	goto	CS_MENU_BUTTON_Handler
567
 
568
USER_DIN_NotifyToggleNoCS
569
	return
570
 
571
 
572
;; --------------------------------------------------------------------------
573
;;  This function is called by MIOS when an encoder has been moved
574
;;  Input:
575
;;     o Encoder number in WREG and MIOS_PARAMETER1
576
;;     o signed incrementer value in MIOS_PARAMETER2:
577
;;       - is positive when encoder has been turned clockwise
578
;;       - is negative when encoder has been turned counter clockwise
579
;; --------------------------------------------------------------------------
580
USER_ENC_NotifyChange
581
	movf	SID_MIDI_DEVICE, W	; exit if device ID != 0x00
582
	skpz
583
	return
584
 
585
	;; store encoder number in CS_MENU_USED_ENCODER - will be used by CS_MENU_ENC_CSInc later to set a new speed!
586
	movff	MIOS_PARAMETER1, CS_MENU_USED_ENCODER
587
 
588
#if CS_MENU_USE_INCDEC_BUTTONS == 0
589
	;; if encoder #0 has been moved, jump to Control Surface Menu Encoder Handler
590
	movlw	0x00		; encoder #0
591
	cpfseq	MIOS_PARAMETER1, ACCESS
592
	rgoto USER_ENC_Handler_NoMenu
593
 
594
	;; get incrementer and jump to control surface menu encoder handler
595
	movf	MIOS_PARAMETER2, W
596
	goto	CS_MENU_ENC_Handler
597
 
598
USER_ENC_Handler_NoMenu
599
	decf	MIOS_PARAMETER1, F; decrement encoder number (the CS encoders begin at 0)
600
#endif
601
	;; jump to CS handler
602
	goto	CS_MENU_ENC_CS_Handler
603
 
604
 
605
;; --------------------------------------------------------------------------
606
;;  This function is called by MIOS before the shift register are loaded
607
;;  Note that this is an interrupt service routine! Use FSR2 instead of FSR0
608
;;  and IRQ_TMPx instead of TMPx -- and make the routine as fast as possible
609
;; --------------------------------------------------------------------------
610
USER_SR_Service_Prepare
611
	;; handle with Modulation matrix on every update cycle if enabled
612
	movf	SID_MIDI_DEVICE, W		; skip if device ID != 0x00
613
	bnz	USER_SR_Service_PrepareNoCS
614
 	call	CS_MENU_MATRIX_Handler
615
USER_SR_Service_PrepareNoCS
616
	return
617
 
618
;; --------------------------------------------------------------------------
619
;;  This function is called by MIOS after the shift register have been loaded
620
;;  Note that this is an interrupt service routine! Use FSR2 instead of FSR0
621
;;  and IRQ_TMPx instead of TMPx -- and make the routine as fast as possible
622
;; --------------------------------------------------------------------------
623
USER_SR_Service_Finish
624
#if DEFAULT_SRM_BUTTONS_DIN
625
	;; ---[ button matrix ]---
626
	call	CS_MENU_MATRIX_GetRowIRQ
627
#endif
628
	return
629
 
630
;; --------------------------------------------------------------------------
631
;;  This function is called by MIOS when a pot has been moved
632
;;  Input:
633
;;     o Pot number in WREG and MIOS_PARAMETER1
634
;;     o LSB value in MIOS_PARAMETER2
635
;;     o MSB value in MIOS_PARAMETER3
636
;; --------------------------------------------------------------------------
637
USER_AIN_NotifyChange
638
 
639
	;; NOTE: WE HAVE OUR OWN AIN HANDLER IN ain.inc
640
	;; THE MIOS DRIVER IS NOT USED, THEREFORE THIS FUNCTION WILL NEVER BE CALLED !!!
641
 
642
	return
643
 
644
 
645
;; --------------------------------------------------------------------------
646
;;  This function is called by the ain.inc driver when a pot has been moved
647
;;  Input:
648
;;     o Pot number in WREG and MIOS_PARAMETER1
649
;;     o 8bit value in MIOS_PARAMETER2
650
;; --------------------------------------------------------------------------
651
AIN_NotifyChange
652
	;; exit if pin number >= 5 (only forward Knob #1..4)
653
	movlw	5
654
	cpfslt	MIOS_PARAMETER1, ACCESS
655
	return
656
 
657
	;; branch depending on master/slave
658
	movf	SID_MIDI_DEVICE, W
659
	bz	AIN_NotifyChange_Master
660
AIN_NotifyChange_Slave
661
	;; Slave: only forward to knob handler
662
	;; forward to knob handler
663
	movf	MIOS_PARAMETER1, W
664
	movff	MIOS_PARAMETER2, MIOS_PARAMETER1
665
	goto	SID_KNOB_SetValue
666
 
667
 
668
AIN_NotifyChange_Master
669
	;; Master: forward via CS for all selected SIDs
670
	clrf	CS_MENU_SID
671
AIN_NotifyChange_Loop
672
	movf	CS_MENU_SID, W
673
	call	MIOS_HLP_GetBitORMask
674
	andwf	CS_MENU_SELECTED_SID_FLAGS, W
675
	bz	AIN_NotifyChange_Loop_Next
676
 
677
	movf	MIOS_PARAMETER1, W
678
	call	SID_KNOB_GetPtr
679
	movf	FSR1L, W
680
	addlw	SID_Ix_Px_VALUE
681
	movwf	FSR0L
682
	movf	FSR1H, W
683
	addlw	HIGH(SID_EDIT_BUFFER)-HIGH(SID_PATCH_BUFFER)
684
	movwf	FSR0H
685
	movff	MIOS_PARAMETER2, INDF0
686
 
687
	;; special sending routine knob values
688
	movff	MIOS_PARAMETER1, CS_MENU_PARAMETER_IX
689
	call	CS_MENU_MS_SendKnob
690
 
691
AIN_NotifyChange_Loop_Next
692
	incf	CS_MENU_SID, F
693
	BRA_IFCLR CS_MENU_SID, 2, ACCESS, AIN_NotifyChange_Loop
694
 
695
	return
696
 
697
 
698
;; ==========================================================================
699
;;  Application code (see comments in files)
700
;; ==========================================================================
701
 
702
;; ---[ reusable functions ]---
703
#include "math_mul16_16.inc"
704
#include "math_div24_16.inc"
705
#include "j5_dout.inc"
706
#include "ain.inc"
707
#include "mbnet.inc"
708
 
709
;; ---[ Control surface functions ]---
710
#include "cs_menu_enc_table.inc"
711
#include "cs_menu_buttons.inc"
712
#include "cs_menu_leds.inc"
713
#include "cs_menu_matrix.inc"
714
#include "cs_menu_enc.inc"
715
#include "cs_menu_timer.inc"
716
#include "cs_menu_exec.inc"
717
#include "cs_menu.inc"
718
#include "cs_menu_fsr0.inc"
719
#include "cs_menu_p2r_r2p.inc"
720
#include "cs_menu_print.inc"
721
#include "cs_menu_ms.inc"
722
#include "cs_menu_cfg.inc"
723
#include "cs_menu_bank.inc"
724
#include "cs_menu_mbnet.inc"
725
#include "cs_menu_tables.inc"
726
 
727
;; ---[ SID kernel ]---
728
#include "sid_lcd.inc"
729
#include "sid_ens.inc"
730
#include "sid_patch.inc"
731
#include "sid_voice.inc"
732
#include "sid_rnd.inc"
733
#include "sid_bank.inc"
734
#include "sid_pbank.inc"
735
#include "sid_ebank.inc"
736
#include "sid_tune.inc"
737
#include "sid_sr.inc"
738
#include "sid_se.inc"
739
#include "sid_se_l.inc"
740
#include "sid_se_b.inc"
741
#include "sid_se_d.inc"
742
#include "sid_se_m.inc"
743
#include "sid_midi.inc"
744
#include "sid_midi_l.inc"
745
#include "sid_midi_b.inc"
746
#include "sid_midi_d.inc"
747
#include "sid_midi_m.inc"
748
#include "sid_sysex.inc"
749
#include "sid_mbnet.inc"
750
#if ENABLE_AOUT == 2
751
#include "sid_aout_lc.inc"
752
#else
753
#if ENABLE_AOUT == 3
754
#include "sid_aout_ng.inc"
755
#else
756
#include "sid_aout.inc"
757
#endif
758
#endif
759
#include "sid_knob.inc"
760
#include "sid_parin.inc"
761
#include "sid_parout.inc"
762
#include "sid_par_table.inc"
763
#include "sid_env_table.inc"
764
#include "sid_lfo_table.inc"
765
#include "sid_note_table.inc"
766
#include "sid_frq_table.inc"
767
#include "sid_sin_table.inc"
768
#include "sid_depth_table.inc"
769
#include "sid_dmodel.inc"	; (must be located in upper 64k area)
770
 
771
;; ---[ SIDplay module ]---
772
#include "sidplay.inc"
773
 
774
;; ---[ SID EEPROM content ]---
775
#include "sid_presets.inc"
776
 
777
	END