Subversion Repositories svn.mios

Rev

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

Rev Author Line No. Line
111 tk 1
; $Id: main.inc 1168 2014-06-23 22:13:36Z tk $
2
;
3
; MIOS Application
4
; MIDIbox FM
5
;
6
; Version:                <-------------->
1168 tk 7
#define MBFM_VERSION_STR "MIDIbox FM V1.4j"
111 tk 8
; (fixed string length - 16 characters!)
9
;
10
; ==========================================================================
11
;
12
;  Copyright 1998-2006 Thorsten Klose (tk@midibox.org)
13
;  Licensed for personal non-commercial use only.
14
;  All other rights reserved.
15
;
16
; ==========================================================================
17
 
18
;; ---[ MIOS header file ]---
19
#include <mios.h>
20
 
21
;; ---[ useful macros ]---
22
#include <macros.h>
23
 
24
;; ---[ vectors to MIOS functions (never change!) ]---
25
#include <mios_vectors.inc>
26
 
27
;; ---[ user hooks (never change!) ]---
28
#include <user_vectors.inc>
29
 
30
;; ==========================================================================
31
;;  General Application Settings
32
;; ==========================================================================
33
 
34
;; ==========================================================================
35
;;  General Settings
36
;; ==========================================================================
37
 
379 tk 38
#ifndef separate_SETUP_FILE
111 tk 39
#endif
40
 
41
;; ---[ variables used by application ]---
42
#include "app_defines.h"
43
 
44
; ==========================================================================
45
 
46
;; ---[ configuration table for MIDI processor and rotary encoders ]---
47
#include "mios_tables.inc"
48
 
49
;; ---[ Custom LCD driver ]---
1168 tk 50
#if USE_8BIT_LCD_DRIVER
51
#include "app_lcd_8bitdriver.inc"
52
#else
111 tk 53
#include <app_lcd.inc>
1168 tk 54
#endif
111 tk 55
 
56
;; ==========================================================================
57
;;  All MIOS hooks in one file
58
;; ==========================================================================
59
 
60
;; --------------------------------------------------------------------------
61
;;  This function is called by MIOS after startup to initialize the
62
;;  application
63
;; --------------------------------------------------------------------------
64
USER_Init
65
	;; initialize OPL3 module
66
	call	MBFM_REG_Init
67
 
1168 tk 68
#if USE_8BIT_LCD_DRIVER
69
	;; optional 8bit LCD driver (located in app_lcd_8bitdriver.inc)
70
	;; select LCD type #7 (custom LCD driver, hooks in app_lcd module will be used)
71
	clrf	MIOS_PARAMETER1	; variable enable pin not provided
72
	clrf	MIOS_PARAMETER2	; variable enable pin not provided
73
	movlw	0x07
74
	call	MIOS_LCD_TypeSet
75
#endif
76
 
111 tk 77
	;; ------------------------------------------------------------------
78
 
79
	;; initialize the shift registers
80
	movlw	0x04			; use up to 4 shift registers (maximum would be 16!)
81
	call	MIOS_SRIO_NumberSet
82
	movlw	0x01			; set update frequncy
83
	call	MIOS_SRIO_UpdateFrqSet
84
	movlw	0x00			; disable touch sensor
85
	call	MIOS_SRIO_TS_SensitivitySet
86
 
139 tk 87
	;; initialize the AOUT module
88
	call	AOUT_Init
111 tk 89
 
90
	;; initialize the integrated MIDI merger
91
	movlw	MIOS_MIDI_MERGER_DISABLED	; should be disabled for a synthesizer
92
	call	MIOS_MIDI_MergerSet
93
 
94
	;; ------------------------------------------------------------------
95
 
96
	;; set MIDI channel of drum section (won't be saved in EEPROM/BankStick)
97
	movlw	0x0f
98
	movff	WREG, MBFM_DRUM_MIDI_CHANNEL
99
 
100
	;; init ensemble and drumset
101
	call	MBFM_ENS_Init
102
 
103
	;; init voices
104
	call	MBFM_VOICE_Init
105
 
986 tk 106
	;; initialize the timer for the sound engine handler
107
	movlw	LOW(10000)		; every 1 mS (update cycle splitted into 2 halfs!)
108
	movwf	MIOS_PARAMETER1
109
	movlw	HIGH(10000)
110
	movwf	MIOS_PARAMETER2
111
	movlw	0x00			; prescaler 1:1
112
	call	MIOS_TIMER_Init
113
 
111 tk 114
	;; ------------------------------------------------------------------
115
 
116
#if CS_ENABLED
117
	;; reset the control surface
118
	goto	CS_MENU_Reset
119
#else
120
	return
121
#endif
122
 
123
 
124
;; --------------------------------------------------------------------------
125
;;  This function is called by MIOS in the mainloop when nothing else is to do
126
;; --------------------------------------------------------------------------
127
USER_Tick
128
 
129
	;; ---[ check BankStick status ]---
130
	call	MBFM_BANK_CheckStick
131
 
132
	;; ---[ update the FM registers ]---
133
	call	MBFM_REG_Update
134
 
135
	;; ---[ call the wavetable handler ]---
136
	call	MBFM_WT_Handler
137
 
139 tk 138
	;; ---[ update AOUTs channels (if enabled) ]---
111 tk 139
	call	MBFM_AOUT_Update
140
 
946 tk 141
#if DISPLAY_PERFORMANCE == 1
111 tk 142
	;; ---[ for performance measuring ]---
143
	call	MBFM_LOAD_IncLoadCtr
946 tk 144
#endif
111 tk 145
 
146
	return
147
 
148
 
149
;; --------------------------------------------------------------------------
150
;;  This function is periodically called by MIOS. The frequency has to be
151
;;  initialized with MIOS_Timer_Set
152
;;  Note that this is an interrupt service routine! Use FSR2 instead of FSR0
153
;;  and IRQ_TMPx instead of TMPx -- and make the routine as fast as possible!
154
;; --------------------------------------------------------------------------
155
USER_Timer
986 tk 156
	;; ---[ call Synth Engine Handler ]---
157
	goto	MBFM_SE_Handler
111 tk 158
 
159
 
160
;; --------------------------------------------------------------------------
161
;;  This function is called by MIOS when a debug command has been received
162
;;  via SysEx
163
;;  Input:
164
;;     o WREG, MIOS_PARAMETER1, MIOS_PARAMETER2, MIOS_PARAMETER3 like
165
;;       specified in the debug command
166
;;  Output:
167
;;     o return values WREG, MIOS_PARAMETER1, MIOS_PARAMETER2, MIOS_PARAMETER3
168
;; --------------------------------------------------------------------------
169
USER_MPROC_DebugTrigger
170
	return
171
 
172
 
173
;; --------------------------------------------------------------------------
174
;;  This function is called by MIOS when the display content should be
175
;;  initialized. Thats the case during startup and after a temporary message
176
;;  has been printed on the screen
177
;; --------------------------------------------------------------------------
178
 
179
TEXT_WELCOME_0	STRING 16, 0x00, MBFM_VERSION_STR
180
TEXT_WELCOME_11	STRING 16, 0x40, "CS not enabled! "
181
 
182
USER_DISPLAY_Init
183
	TABLE_ADDR TEXT_WELCOME_0		; print welcome message
184
 
185
#if CS_ENABLED
186
	;; print welcome message only during startup phase
187
	BRA_IFSET CS_STAT, CS_STAT_STARTUP_DONE, ACCESS, USER_DISPLAY_Init_NoStartup
188
USER_DISPLAY_Init_Startup
189
	bsf	CS_STAT, CS_STAT_STARTUP_DONE
190
	call	MIOS_LCD_PrintMessage		; first line
191
 
960 tk 192
#if USE_CUSTOM_CHAR_HANDLER
938 wilba 193
	movlw	255
194
	movwf	LAST_CHARSET
195
	movlw	2
196
	call	MIOS_CUSTOM_CHAR_HANDLER_LoadCharset
197
#else
198
	TABLE_ADDR CS_MENU_SPECIAL_CHARS	; (defined in special_characters.inc)
199
	call	MIOS_CLCD_SpecialCharsInit
200
#endif
111 tk 201
USER_DISPLAY_Init_NoStartup
202
 
203
	;; request an initialization
204
	bsf	CS_STAT, CS_STAT_DISPLAY_INIT_REQ
205
 
206
	;; in the next cycle USER_DISPLAY_Tick will be called which
207
	;; does the job
208
	return
209
 
210
#else
211
	call	MIOS_LCD_PrintString		; first line
212
	TABLE_ADDR TEXT_WELCOME_11
213
	call	MIOS_LCD_PrintString		; second line
214
	return
215
#endif
216
 
217
;; --------------------------------------------------------------------------
218
;;  This function is called in the mainloop when no temporary message is shown
219
;;  on screen. Print the realtime messages here
220
;; --------------------------------------------------------------------------
221
USER_DISPLAY_Tick
222
#if CS_ENABLED == 1
223
	;; continue at the control surface menu handler
224
	call	CS_MENU_Handler
225
#endif
226
 
227
#if DISPLAY_PERFORMANCE == 1
228
	movlw	40-1-6
229
	call	MIOS_LCD_CursorSet
230
	call	MBFM_LOAD_Print
231
#endif
232
	return
233
 
234
 
235
;; --------------------------------------------------------------------------
236
;;  This function is called by MIOS when a complete MIDI event has been received
237
;;  Input:
238
;;     o first  MIDI event byte in MIOS_PARAMETER1
239
;;     o second MIDI event byte in MIOS_PARAMETER2
240
;;     o third  MIDI event byte in MIOS_PARAMETER3
241
;; --------------------------------------------------------------------------
242
USER_MPROC_NotifyReceivedEvent
243
	;; process MIDI event
244
	goto	MBFM_MIDI_NotifyReceivedEvent
245
 
246
 
247
;; --------------------------------------------------------------------------
248
;;  This function is called by MIOS when a MIDI event has been received
249
;;  which has been specified in the CONFIG_MIDI_IN table
250
;;  Input:
251
;;     o number of entry in WREG
252
;;     o first  MIDI event byte in MIOS_PARAMETER1
253
;;     o second MIDI event byte in MIOS_PARAMETER2
254
;;     o third  MIDI event byte in MIOS_PARAMETER3
255
;; --------------------------------------------------------------------------
256
USER_MPROC_NotifyFoundEvent
257
	return
258
 
259
 
260
;; --------------------------------------------------------------------------
261
;;  This function is called by MIOS when a MIDI event has not been completly
262
;;  received within 2 seconds
263
;; --------------------------------------------------------------------------
264
USER_MPROC_NotifyTimeout
265
	goto	MBFM_SYSEX_ActionInvalid
266
 
267
 
268
;; --------------------------------------------------------------------------
269
;;  This function is called by MIOS when a MIDI byte has been received
270
;;  Input:
271
;;     o received MIDI byte in WREG and MIOS_PARAMETER1
272
;; --------------------------------------------------------------------------
273
USER_MPROC_NotifyReceivedByte
274
	goto	MBFM_SYSEX_Parser
275
 
276
;; --------------------------------------------------------------------------
277
;;  This function is called by MIOS before the transfer of a MIDI byte.
278
;;  It can be used to monitor the Tx activity or to do any other actions
279
;;  (e.g. to switch a pin for multiplexed MIDI Outs) before the byte will
280
;;  be sent.
281
;;  Note that this is an interrupt service routine! Use FSR2 instead of FSR0
282
;;  and IRQ_TMPx instead of TMPx -- and make the routine as fast as possible!
283
;;  Input:
284
;;     o transmitted byte in WREG
285
;; --------------------------------------------------------------------------
286
USER_MIDI_NotifyTx
287
	return
288
 
289
;; --------------------------------------------------------------------------
290
;;  This function is called by MIOS when a MIDI byte has been received.
291
;;  It can be used to monitor the Rx activity or to do any action - e.g.
292
;;  to react on realtime events like MIDI clock (0xf8) with a minimum latency
293
;;  Note that this is an interrupt service routine! Use FSR2 instead of FSR0
294
;;  and IRQ_TMPx instead of TMPx -- and make the routine as fast as possible!
295
;;  Input:
296
;;     o received byte in WREG
297
;; --------------------------------------------------------------------------
298
USER_MIDI_NotifyRx
299
	;; temporary save received byte in IRQ_TMP1
300
	movwf	IRQ_TMP1
301
 
302
	;; if MIDI clock: notify clock
303
	lfsr	FSR2, MBFM_MIDI_SYNC
304
	xorlw	0xf8
305
	skpnz
306
	bsf	INDF2, MBFM_MIDI_SYNC_F8
307
 
308
	;; if MIDI start: notify start
309
	movf	IRQ_TMP1, W
310
	xorlw	0xfa
311
	skpnz
312
	bsf	INDF2, MBFM_MIDI_SYNC_FA
313
 
1025 tk 314
	;; quick&dirty: reset divider on song position change as well
315
	;; normaly we should parse the new position as well, but for
316
	;; most common cases (interaction with DAW) this is sufficient
317
	xorlw	0xf2 ^ 0xfa
318
	skpnz
319
	bsf	INDF2, MBFM_MIDI_SYNC_FA
320
 
111 tk 321
	return
322
 
323
;; --------------------------------------------------------------------------
324
;;  This function is called by MIOS when an button has been toggled
325
;;  Input:
326
;;     o Button number in WREG and MIOS_PARAMETER1
327
;;     o Button value MIOS_PARAMETER2:
328
;;       - 1 if button has been released (=5V)
329
;;       - 0 if button has been pressed (=0V)
330
;; --------------------------------------------------------------------------
331
USER_DIN_NotifyToggle
332
#if CS_ENABLED
333
	;; continue in cs_menu_button.inc
334
	goto	CS_MENU_BUTTON_Handler
335
#else
336
	return
337
#endif
338
 
339
 
340
;; --------------------------------------------------------------------------
341
;;  This function is called by MIOS when an encoder has been moved
342
;;  Input:
343
;;     o Encoder number in WREG and MIOS_PARAMETER1
344
;;     o signed incrementer value in MIOS_PARAMETER2:
345
;;       - is positive when encoder has been turned clockwise
346
;;       - is negative when encoder has been turned counter clockwise
347
;; --------------------------------------------------------------------------
348
USER_ENC_NotifyChange
349
#if CS_ENABLED == 0
350
	return
351
#else
352
 
353
#if CS_MENU_USE_INCDEC_BUTTONS == 0
354
	;; if encoder #0 has been moved, jump to Control Surface Menu Encoder Handler
355
	movlw	0x00		; encoder #0
356
	cpfseq	MIOS_PARAMETER1, ACCESS
357
	rgoto USER_ENC_NotifyChange_NoMenu
358
 
359
	;; get incrementer and jump to control surface menu encoder handler
360
	movf	MIOS_PARAMETER2, W
361
	goto	CS_MENU_ENC_Handler
362
 
363
USER_ENC_NotifyChange_NoMenu
364
	decf	MIOS_PARAMETER1, F; decrement encoder number (the CS encoders begin at 0)
365
#endif
366
	;; jump to CS handler
367
	goto	CS_MENU_ENC_CS_Handler
368
#endif
369
 
370
;; --------------------------------------------------------------------------
371
;;  This function is called by MIOS before the shift register are loaded
372
;;  Note that this is an interrupt service routine! Use FSR2 instead of FSR0
373
;;  and IRQ_TMPx instead of TMPx -- and make the routine as fast as possible
374
;; --------------------------------------------------------------------------
375
USER_SR_Service_Prepare
376
#if CS_ENABLED
377
	;; ---[ handle with control surface variables (flashing cursor, etc) ]---
378
	goto	CS_MENU_TIMER
379
USER_SR_Service_Prepare_NoCS
380
#else
381
	return
382
#endif
383
 
384
 
385
;; --------------------------------------------------------------------------
386
;;  This function is called by MIOS after the shift register have been loaded
387
;;  Note that this is an interrupt service routine! Use FSR2 instead of FSR0
388
;;  and IRQ_TMPx instead of TMPx -- and make the routine as fast as possible
389
;; --------------------------------------------------------------------------
390
USER_SR_Service_Finish
946 tk 391
#if DISPLAY_PERFORMANCE == 1
111 tk 392
	;; ---[ for performance measuring ]---
393
	call	MBFM_LOAD_IncRefCtr
946 tk 394
#endif
111 tk 395
 
396
	;; ---[ handler for selection matrix buttons/LEDs ]---
397
	goto	CS_MENU_MATRIX_Handler
398
 
399
 
400
;; --------------------------------------------------------------------------
401
;;  This function is called by MIOS when a pot has been moved
402
;;  Input:
403
;;     o Pot number in WREG and MIOS_PARAMETER1
404
;;     o LSB value in MIOS_PARAMETER2
405
;;     o MSB value in MIOS_PARAMETER3
406
;; --------------------------------------------------------------------------
407
USER_AIN_NotifyChange
408
	return
409
 
410
#if CS_ENABLED == 1
411
;; ---[ Control surface functions ]---
412
#include "cs_menu_io_tables.inc"
413
#include "cs_menu_matrix_table.inc"
414
#include "cs_menu_buttons.inc"
415
#include "cs_menu_matrix.inc"
416
#include "cs_menu_leds.inc"
417
#include "cs_menu_enc.inc"
418
#include "cs_menu_timer.inc"
419
#include "cs_menu_exec.inc"
420
#include "cs_menu.inc"
421
#include "cs_menu_p2r_r2p.inc"
422
#include "cs_menu_print.inc"
423
#include "cs_menu_ms.inc"
424
#include "cs_menu_cfg.inc"
425
#include "cs_menu_tables.inc"
938 wilba 426
 
960 tk 427
#if USE_CUSTOM_CHAR_HANDLER
938 wilba 428
#include "mios_custom_char_handler.inc"
111 tk 429
#endif
430
 
938 wilba 431
#endif
432
 
139 tk 433
;; ---[ modules from code library ]---
434
; override default pin definitions of AOUT driver
435
#define AOUT_LAT_CS	LATC	; The chip select pin CS#
436
#define AOUT_TRIS_CS	TRISC	; is connected to Port C.3
437
#define AOUT_PIN_CS	3	; (CANNOT be shared with other outputs!)
438
;
439
#define AOUT_LAT_DIN	LATC	; The data input pin DIN
440
#define AOUT_TRIS_DIN	TRISC	; is connected to Port C.1
441
#define AOUT_PIN_DIN	1	; (can be shared with other outputs)
442
;
443
#define AOUT_LAT_SCLK	LATC	; The shift clock input pin SCLK
444
#define AOUT_TRIS_SCLK	TRISC	; is connected to Port C.0
445
#define AOUT_PIN_SCLK	0	; (can be shared with other outputs)
446
; include AOUT driver (located in $MIOS_PATH/modules/aout/)
447
#include <aout.inc>
448
 
111 tk 449
;; ---[ reusable functions ]---
450
#include "math_mul16_16.inc"
451
#include "special_characters.inc"
452
 
453
;; ---[ MIDIbox FM kernel ]---
454
 
455
#include "mbfm_reg.inc"
456
#include "mbfm_sysex.inc"
457
#include "mbfm_midi.inc"
139 tk 458
#include "mbfm_aout.inc"
111 tk 459
#include "mbfm_se.inc"
460
#include "mbfm_wt.inc"
461
#include "mbfm_bank.inc"
462
#include "mbfm_instr.inc"
463
#include "mbfm_drum.inc"
464
#include "mbfm_ens.inc"
465
#include "mbfm_voice.inc"
466
#include "mbfm_frq.inc"
467
#include "mbfm_eg_table.inc"
468
#include "mbfm_lfo_table.inc"
469
#include "mbfm_sin_table.inc"
470
#include "mbfm_lcd.inc"
962 tk 471
#include "mbfm_rnd.inc"
946 tk 472
 
473
#if DISPLAY_PERFORMANCE == 1
474
# include "mbfm_load.inc"
475
#endif
476
 
111 tk 477
#include "mbfm_note_table.inc"
478
#include "mbfm_vol_table.inc"
479
#include "mbfm_par_table.inc"
480
#include "mbfm_parin.inc"
481
#include "mbfm_parout.inc"
482
#include "mbfm_curve_table.inc"
483
 
484
;; ---[ MIDIbox FM EEPROM content ]---
485
#include "mbfm_presets.inc"
486
 
487
	END