Subversion Repositories svn.mios

Rev

Rev 327 | Rev 362 | 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.inc 360 2008-06-21 20:03:46Z tk $
1 tk 2
;
3
; SID Control Surface Menu 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
;;  This function is called by SID_Init during startup to reset the
15
;;  control surface
16
;; --------------------------------------------------------------------------
17
CS_MENU_Reset
18
	;; control surface: begin with main page
19
	movlw	CS_MENU_MAIN
20
	movwf	CS_MENU
21
 
22
	;; set reinit counter - CS configuration will be restored after one second
327 tk 23
	movlw	0x18
1 tk 24
	movwf	CS_MENU_REINIT_CFG_CTR
25
 
26
	;; start with master SID, SID button 1-4 depressed
27
	movlw	0xf1
28
	movwf	CS_MENU_SELECTED_SID_FLAGS
29
 
30
	;; select left and right channel
31
	movlw	0x03
32
	movwf	CS_MENU_SELECTED_SID_LR
33
 
34
	;; set mode of modulation matrix
35
#if DEFAULT_LEDMATRIX_MODE == 0
36
	bcf	CS_MENU_MODE, CS_MENU_MODE_MATRIX_METER
37
#else
38
	bsf	CS_MENU_MODE, CS_MENU_MODE_MATRIX_METER
39
#endif
40
 
41
	;; initialize button matrix handler
42
	call	CS_MENU_MATRIX_Init
43
 
360 tk 44
#if DEFAULT_LCD_LINES >= 4
45
	;; meter bar: print spaces after power-on
46
	movlw	0xff
47
	call	CS_MENU_UpdateMeterBar
48
#endif
49
 
1 tk 50
	return
51
 
52
;; --------------------------------------------------------------------------
53
;;  entry function for a menu page update
54
;; --------------------------------------------------------------------------
55
CS_MENU_Handler
56
	;; check if configuration has to be restored from BankStick
57
	call	CS_MENU_BANK_RestoreCfg_Tst
58
	;; so long as re-init ctr is != zero, exit
59
	movf	CS_MENU_REINIT_CFG_CTR, W
60
	skpz
61
	return
62
 
63
	;; get SID number
64
	call	CS_MENU_MS_GetSIDNumber
65
 
66
	;; check if edit buffer is filled - exit so long buffer not complete
67
	call	CS_MENU_MBNET_Tx_GetPatchChk
68
	skpz
69
	return
70
 
71
	;; check if edit buffer update has been requested
72
	BRA_IFCLR CS_STAT2, CS_STAT2_EDIT_UPDATE_REQ, ACCESS, CS_MENU_Handler_NoEditUpdate
73
CS_MENU_Handler_EditUpdate
74
	bcf	CS_STAT2, CS_STAT2_EDIT_UPDATE_REQ
75
	;; update edit buffer and exit
76
	goto	CS_MENU_MS_UpdateEditBuffer
77
CS_MENU_Handler_NoEditUpdate
78
 
79
	;; check if tx transfer to slave has been requested and can be granted
80
 	call	CS_MENU_MS_Send_SysExDump_TxTst
81
 
82
	;; check if meters should be displayed (will also be checked in cs_menu_matrix.inc)
83
	IRQ_DISABLE
84
	bcf	CS_MENU_MODE, CS_MENU_MODE_MATRIX_METER_DISP
85
	btfsc	CS_MENU_MODE, CS_MENU_MODE_MATRIX_METER
86
	bsf	CS_MENU_MODE, CS_MENU_MODE_MATRIX_METER_DISP
87
	movf	CS_MENU_MATRIX_SELECTED_COL, W		; don't display if one of the column buttons is pressed
88
	skpz
89
	bcf	CS_MENU_MODE, CS_MENU_MODE_MATRIX_METER_DISP
90
	IRQ_ENABLE
91
 
92
	;; check if display initialization has been requested (CS_STAT.CS_STAT_DISPLAY_INIT_REQ set)
93
	BRA_IFCLR CS_STAT, CS_STAT_DISPLAY_INIT_REQ, ACCESS, CS_MENU_Handler_NoInit
94
 
95
CS_MENU_Handler_Init
96
	;; clear request flag
97
	bcf	CS_STAT, CS_STAT_DISPLAY_INIT_REQ
98
	;; force an display update
99
	bsf	CS_STAT, CS_STAT_DISPLAY_UPDATE_REQ
100
	;; clear counter so that cs_menu_timer.inc counts from zero and the menu entry is marked for a short time
101
	clrf	CS_CURSOR_CTR
102
	;; clear "CS_STAT_CURSOR_FLASH" bit (see cs_menu.inc for the handling)
103
	bcf	CS_STAT, CS_STAT_CURSOR_FLASH
104
	;; disable page and "big" message
105
	bcf	CS_STAT, CS_STAT_PAGE_MSG
106
	bcf	CS_STAT, CS_STAT_BIG_MSG
107
	;; update OSC flags
360 tk 108
	call	CS_MENU_Hlp_UpdateOSCFlags
1 tk 109
 
296 tk 110
	;; if not in SHIFT page
111
	BRA_IFSET CS_STAT3, CS_STAT3_SHIFT_PAGE, ACCESS, CS_MENU_Handler_Init_CFGSkip
1 tk 112
CS_MENU_Handler_Init_NotCFGSkip
113
	;; init menu table
114
	rcall	CS_MENU_Page_Init
115
	;; get SID number
116
	call	CS_MENU_MS_GetSIDNumber
117
	;; set encoder speed of menu encoder
118
	movlw	0
119
	rcall	CS_MENU_EncSpeedSet
120
	;; set parameter
121
	rcall	CS_MENU_EncParameterSet
122
	;; set max position of cursor (or patch)
123
	rcall	CS_MENU_EncMaxSet
360 tk 124
 
125
CS_MENU_Handler_Init_CFGSkip
126
 
1 tk 127
	;; clear item counter - used for optimized refresh handling
128
	clrf	CS_MENU_REFRESH_ITEM_CTR
129
 
130
	;; SID are not available if no connection to MBNET node
131
	bsf	CS_STAT, CS_STAT_SID_AVAILABLE
132
	call	CS_MENU_MBNET_Check
133
	btfss	CS_STAT, CS_STAT_SID_AVAILABLE
134
	return
360 tk 135
 
1 tk 136
	;; in main page: print static display elements
296 tk 137
	BRA_IFSET CS_STAT3, CS_STAT3_SHIFT_PAGE, ACCESS, CS_MENU_Handler_Init_NotMainPage
1 tk 138
	BRA_IFCLR CS_MENU, 7, ACCESS, CS_MENU_Handler_Init_NotMainPage
139
CS_MENU_Handler_Init_MainPage
140
#if CS_MENU_DISPLAYED_ITEMS > 5
141
	;; only relevant for 2x40 LCD: clear left half
142
	movlw	0x00 + 20
143
	call	MIOS_LCD_CursorSet
144
	movlw	20
145
	call	SID_LCD_PrintSpaces
146
 
147
	movlw	0x40 + 20
148
	call	MIOS_LCD_CursorSet
149
	movlw	20
150
	call	SID_LCD_PrintSpaces
151
#endif
152
 
153
	;; print patch name at lower line
154
	movlw	0x40 + 5
155
	call	MIOS_LCD_CursorSet
156
	call	SID_LCD_PrintPatch
157
 
158
CS_MENU_Handler_Init_NotMainPage
159
 
160
CS_MENU_Handler_Init_End
161
 
162
CS_MENU_Handler_NoInit
163
	;; exit if SID not available (only update LEDs)
164
	GOTO_IFCLR CS_STAT, CS_STAT_SID_AVAILABLE, ACCESS, CS_MENU_LED_Update
165
 
166
	;; don't continue if CS_SELECT_CTR > 0 (used by "CS messages")
167
	movf	CS_SELECT_CTR, W
168
	skpz
169
	return
170
 
360 tk 171
	;; should menu label be print?
172
	movf	CS_MENU_LABEL_CTR, W
173
	skpz
174
	rgoto	CS_MENU_Handler_MenuLabel
175
 
1 tk 176
	;; for the optimized display handling: refresh items step by step
177
	movf	CS_MENU_REFRESH_ITEM_CTR, W
178
	bnz	CS_MENU_Handler_CheckMain
179
 
360 tk 180
	;; for meter bar (will be printed piecewise as well)
181
	;; it has low priority: skip if counter == 20 (new value) and delayed update *not* active (best "realtime" feeling: menu items will be printed first)
182
	movf	CS_MENU_METER_BAR_CTR, W
183
	bz	CS_MENU_Handler_NoMeterBar
184
	xorlw	20
185
	bnz	CS_MENU_Handler_MeterBar
186
	movf	CS_MENU_DELAYED_UPDATE_CTR, W
187
	bz	CS_MENU_Handler_NoMeterBar
188
CS_MENU_Handler_MeterBar
189
	rgoto	CS_MENU_Handler_ParamBar
190
CS_MENU_Handler_NoMeterBar
191
 
192
	;; skip update check if DELAYED_UPDATE_CTR != 0
193
	movf	CS_MENU_DELAYED_UPDATE_CTR, W
194
	skpz
195
	return
196
 
197
	;; check if update has been requested
1 tk 198
	btfss	CS_STAT, CS_STAT_DISPLAY_UPDATE_REQ
199
	return
360 tk 200
 
1 tk 201
	;; clear request flag
202
	bcf	CS_STAT, CS_STAT_DISPLAY_UPDATE_REQ
203
 
360 tk 204
	;; set new update counter (-> we update each 50 mS)
205
	movlw	50
206
	movwf	CS_MENU_DELAYED_UPDATE_CTR
207
 
1 tk 208
	;; update LEDs
209
	call	CS_MENU_LED_Update
210
 
211
CS_MENU_Handler_CheckMain
296 tk 212
	;; branch if SHIFT page is displayed
213
	BRA_IFSET CS_STAT3, CS_STAT3_SHIFT_PAGE, ACCESS, CS_MENU_Page_Cfg
1 tk 214
 
215
	;; branch if menu page is displayed
216
	BRA_IFCLR CS_MENU, 7, ACCESS, CS_MENU_Handler_MenuPage
217
 
218
	;; ------------------------------------------------------------------
219
	;; else handle mainpage
220
CS_MENU_Handler_MainPage
221
	;; skip upper line if page message is print
222
	BRA_IFSET CS_STAT, CS_STAT_PAGE_MSG, ACCESS, CS_MENU_Handler_MainPage_End
223
 
224
	;; get current CS_MENU_SID
225
	call	CS_MENU_MS_GetSIDNumber
226
 
227
	;; branch depending on item counter
228
	movf	CS_MENU_REFRESH_ITEM_CTR, W
229
	bz	CS_MENU_Handler_MainPage_0
230
	addlw	-1
231
	bz	CS_MENU_Handler_MainPage_1
232
	addlw	-1
233
	bz	CS_MENU_Handler_MainPage_2
234
	addlw	-1
235
	bz	CS_MENU_Handler_MainPage_3
236
	rgoto	CS_MENU_Handler_MainPage_4
237
 
238
 
239
 
240
	;; print current bank and patch number
241
	;; NOTE: it's intended that patch number is print before ensemble number, although the
242
	;; ensemble is the leftmost value!
243
	;; Printing the patch value first ensures, that value will be displayed immediately
244
	;; on fast encoder turns
245
CS_MENU_Handler_MainPage_0
246
	movlw	0x00 + 5
247
	call	MIOS_LCD_CursorSet
248
	call	CS_MENU_MS_GetSIDBank
249
	movwf	SID_BANK
250
	call	CS_MENU_MS_GetSIDPatch
251
	movwf	SID_PATCH
252
	call	SID_LCD_PrintPatchNumber
253
 
254
	;; print '*' if patch not valid
255
	call	SID_PBANK_CheckPatchValid
256
	movlw	' '
257
	skpz
258
	movlw	'*'
259
	call	MIOS_LCD_PrintChar
260
 
261
	;; increment item counter, so that on next call we continue at MainPage_1
262
	incf	CS_MENU_REFRESH_ITEM_CTR, F
263
	rgoto	CS_MENU_Handler_MainPage_End
264
 
265
 
266
	;; print ensemble number
267
CS_MENU_Handler_MainPage_1
268
	movlw	0x00 + 0
269
	call	MIOS_LCD_CursorSet
270
	call	SID_LCD_PrintEnsembleNumber
271
 
272
	;; print divider
273
	movlw	'|'
274
	call	MIOS_LCD_PrintChar
275
 
276
	;; increment item counter, so that on next call we continue at MainPage_3
277
	incf	CS_MENU_REFRESH_ITEM_CTR, F
278
	rgoto	CS_MENU_Handler_MainPage_End
279
 
280
 
281
	;; print engine name
282
CS_MENU_Handler_MainPage_2
283
	movlw	0x00 + 10
284
	call	MIOS_LCD_CursorSet
285
	movff	SID_EDIT_BUFFER + SID_Ix_ENGINE, WREG
286
	call	SID_LCD_PrintEngine
287
	movlw	2
288
	call	SID_LCD_PrintSpaces
289
 
290
	;; increment item counter, so that on next call we continue at MainPage_2
291
	incf	CS_MENU_REFRESH_ITEM_CTR, F
292
	rgoto	CS_MENU_Handler_MainPage_End
293
 
294
 
295
	;; print MIDI channel
296
CS_MENU_Handler_MainPage_3
297
	;; Chn for Channel
298
	movlw	0x00 + 14
299
	call	MIOS_LCD_CursorSet
300
	movlw	'C'
301
	call	MIOS_LCD_PrintChar
302
	movlw	'h'
303
	call	MIOS_LCD_PrintChar
304
	movlw	'n'
305
	call	MIOS_LCD_PrintChar
306
	movlw	'.'
307
	call	MIOS_LCD_PrintChar
308
 
309
	lfsr	FSR1, CS_MENU_SID_M_CHN
310
	movf	CS_MENU_SID, W
311
	andlw	0x03
312
	addwf	FSR1L, F
313
	incf	INDF1, W
314
	andlw	0x7f		; mask out "sent" flag
315
	call	MIOS_LCD_PrintBCD2
316
 
317
	;; increment item counter, so that on next call we continue at MainPage_2
318
	incf	CS_MENU_REFRESH_ITEM_CTR, F
319
	rgoto	CS_MENU_Handler_MainPage_End
320
 
321
 
322
	;; print selected SIDs
323
CS_MENU_Handler_MainPage_4
324
	movlw	0x40 + 0
325
	call	MIOS_LCD_CursorSet
326
	movff	MBNET_NODE_AVAIL, PRODL
327
 
328
	movlw	'-'
329
	btfsc	CS_STAT2, CS_STAT2_PLAY_SID1
330
	movlw 'P'
331
	BRA_IFCLR CS_MENU_SELECTED_SID_FLAGS, 0, ACCESS, CS_MENU_Handler_MainPage_SID1
332
	movlw	'1'
333
	btfsc	CS_STAT2, CS_STAT2_PLAY_SID1; inverted 1
334
	movlw 0x02
335
CS_MENU_Handler_MainPage_SID1
336
	btfss	PRODL, 0
337
	movlw '*'
338
	call	MIOS_LCD_PrintChar
339
	movlw	'-'
340
	btfsc	CS_STAT2, CS_STAT2_PLAY_SID2
341
	movlw 'P'
342
	BRA_IFCLR CS_MENU_SELECTED_SID_FLAGS, 1, ACCESS, CS_MENU_Handler_MainPage_SID2
343
	movlw	'2'
344
	btfsc	CS_STAT2, CS_STAT2_PLAY_SID2; inverted 2
345
	movlw 0x03
346
CS_MENU_Handler_MainPage_SID2
347
	btfss	PRODL, 1
348
	movlw '*'
349
	call	MIOS_LCD_PrintChar
350
	movlw	'-'
351
	btfsc	CS_STAT2, CS_STAT2_PLAY_SID3
352
	movlw 'P'
353
	BRA_IFCLR CS_MENU_SELECTED_SID_FLAGS, 2, ACCESS, CS_MENU_Handler_MainPage_SID3
354
	movlw	'3'
355
	btfsc	CS_STAT2, CS_STAT2_PLAY_SID3; inverted 3
356
	movlw 0x04
357
CS_MENU_Handler_MainPage_SID3
358
	btfss	PRODL, 2
359
	movlw '*'
360
	call	MIOS_LCD_PrintChar
361
	movlw	'-'
362
	btfsc	CS_STAT2, CS_STAT2_PLAY_SID4
363
	movlw 'P'
364
	BRA_IFCLR CS_MENU_SELECTED_SID_FLAGS, 3, ACCESS, CS_MENU_Handler_MainPage_SID4
365
	movlw	'4'
366
	btfsc	CS_STAT2, CS_STAT2_PLAY_SID4; inverted 4
367
	movlw 0x05
368
CS_MENU_Handler_MainPage_SID4
369
	btfss	PRODL, 3
370
	movlw '*'
371
	call	MIOS_LCD_PrintChar
372
 
373
	;; print divider
374
	movlw	'|'
375
	call	MIOS_LCD_PrintChar
376
 
377
	;; last item reached - clear item counter
378
	clrf	CS_MENU_REFRESH_ITEM_CTR
379
	;; rgoto	CS_MENU_Handler_MainPage_End
380
 
381
 
382
	;; ...and exit
383
CS_MENU_Handler_MainPage_End
384
	return
385
 
386
	;; ------------------------------------------------------------------
387
	;; handle menu page
388
CS_MENU_Handler_MenuPage
360 tk 389
#if DEFAULT_LCD_PRINT_CURSOR
1 tk 390
	;; if CLCD: disable blinking CLCD cursor
391
	movlw	0x0c
392
	CALL_IFCLR MIOS_BOX_CFG0, MIOS_BOX_CFG0_USE_GLCD, ACCESS, MIOS_LCD_Cmd
360 tk 393
#endif
1 tk 394
 
395
	;; feed the watchdog
396
	clrwdt
397
 
398
	;; branch depending on CS_MENU
399
	;; execute handler function
400
	;; calc pointer to function: CS_MENU_TABLES_x + (CS_MENU*CS_MENU_T_ENTRY_LEN) + CS_MENU_ENTRY_HANDLER_OFFSET
401
	movlw	CS_MENU_T_ENTRY_HANDLER_OFFSET
402
	call	CS_MENU_GetMenuTablesPtr
403
	goto	MIOS_HLP_IndirectJump
404
 
360 tk 405
 
406
	;; ------------------------------------------------------------------
407
	;; handle meter bar at lower line
408
CS_MENU_Handler_ParamBar
409
	;; select next character
410
	decf	CS_MENU_METER_BAR_CTR, F
411
 
412
	;; set cursor
413
	movf	CS_MENU_METER_BAR_CTR, W
414
	iorlw	0xc0		; (line 4)
415
	call	MIOS_LCD_CursorSet
416
 
417
	;; print spaces if value is 0xff (used inside menu pages)
418
	incf	CS_MENU_METER_BAR_VALUE, W
419
	bz	CS_MENU_Handler_ParamBar_Spc
420
 
421
	;; print character:
422
	;; " [#############>  ] "
423
	;; "0123456789ABCDEF0123"
424
	movf	CS_MENU_METER_BAR_CTR, W
425
	bz	CS_MENU_Handler_ParamBar_0
426
	addlw	-1
427
	bz	CS_MENU_Handler_ParamBar_1
428
	addlw	-1-16
429
	bz	CS_MENU_Handler_ParamBar_18
430
	addlw	-1
431
	bz	CS_MENU_Handler_ParamBar_19
432
 
433
CS_MENU_Handler_ParamBar_Meter
434
	movf	CS_MENU_METER_BAR_VALUE, W
435
	xorlw	0x20
436
	bz	CS_MENU_Handler_ParamBar_Max
437
 
438
	movf	CS_MENU_METER_BAR_CTR, W
439
	addlw	-2		; meter position: 0..15
440
	movwf	PRODL
441
	rrf	CS_MENU_METER_BAR_VALUE, W	; compare with meter value
442
	andlw	0x0f
443
	subwf	PRODL, W
444
	bz	CS_MENU_Handler_ParamBar_Last	; if rightmost character: differ between '=' and '-'
445
	bnc	CS_MENU_Handler_ParamBar_Full
446
	rgoto	CS_MENU_Handler_ParamBar_Spc
447
 
448
CS_MENU_Handler_ParamBar_Last
449
	BRA_IFSET CS_MENU_METER_BAR_VALUE, 0, ACCESS, CS_MENU_Handler_ParamBar_Full
450
 
451
CS_MENU_Handler_ParamBar_Half
452
	movlw	'-'
453
	rgoto	CS_MENU_Handler_ParamBar_End
454
CS_MENU_Handler_ParamBar_Full
455
CS_MENU_Handler_ParamBar_Max
456
	movlw	'='
457
	rgoto	CS_MENU_Handler_ParamBar_End
458
 
459
CS_MENU_Handler_ParamBar_0
460
CS_MENU_Handler_ParamBar_19
461
CS_MENU_Handler_ParamBar_Spc
462
	movlw	' '
463
	rgoto	CS_MENU_Handler_ParamBar_End
464
 
465
CS_MENU_Handler_ParamBar_1
466
	movlw	'['
467
	rgoto	CS_MENU_Handler_ParamBar_End
468
 
469
CS_MENU_Handler_ParamBar_18
470
	movlw	']'
471
	rgoto	CS_MENU_Handler_ParamBar_End
472
 
473
CS_MENU_Handler_ParamBar_End
474
	goto	MIOS_LCD_PrintChar
475
 
476
 
477
	;; ------------------------------------------------------------------
478
	;; handle meter bar at upper line
479
CS_MENU_Handler_MenuLabel
480
	;; decrement counter
481
	decf	CS_MENU_LABEL_CTR, F
482
 
483
	;; cursor pos = 4 * (4-LABEL_CTR)
484
	movf	CS_MENU_LABEL_CTR, W
485
	sublw	4
486
	mullw	4
487
	movf	PRODL, W
488
	iorlw	0x80		; select upper line
489
	call	MIOS_LCD_CursorSet
490
 
491
	;; branch depending on display piece
492
	movf	CS_MENU_LABEL_CTR, W
493
	bz	CS_MENU_Handler_MenuLabel_4
494
	addlw	-1
495
	bz	CS_MENU_Handler_MenuLabel_3
496
CS_MENU_Handler_MenuLabel_012
497
	;; get pointer to label
498
	movf	CS_MENU_LABEL, W
499
	TABLE_ADDR_MUL_W CS_MENU_LABEL_TABLE, CS_MENU_LABEL_TABLE_ENTRY_SIZE
500
	;; add offset
501
	movf	CS_MENU_LABEL_CTR, W
502
	sublw	4
503
	mullw	4
504
	movf	PRODL, W
505
	TABLE_ADD_W
506
 
507
	;; print 4 characters and exit
508
	movlw	4
509
	goto	MIOS_LCD_PrintPreconfString
510
 
511
 
512
CS_MENU_Handler_MenuLabel_3
513
	;; print 4 spaces if EMPTY message selected
514
	movf	CS_MENU_LABEL, W
515
	bz	CS_MENU_Handler_MenuLabel_Empty
516
	rgoto	CS_MENU_Handler_MenuLabel_Empty
517
 
518
	;; TODO: add element value
519
 
520
CS_MENU_Handler_MenuLabel_4
521
	;; print 4 spaces if EMPTY message selected
522
	movf	CS_MENU_LABEL, W
523
	bz	CS_MENU_Handler_MenuLabel_Empty
524
	;; TODO: add element value
525
	rgoto	CS_MENU_Handler_MenuLabel_Empty
526
	return
527
 
528
 
529
CS_MENU_Handler_MenuLabel_Empty
530
	movlw	4		; empty piece
531
	goto	SID_LCD_PrintSpaces
532
 
1 tk 533
;; --------------------------------------------------------------------------
534
;;  initialize the page
535
;; --------------------------------------------------------------------------
536
CS_MENU_Page_Init
360 tk 537
#if DEFAULT_LCD_LINES >= 3
538
	;; select empty label by default (for menu page)
539
	clrf	CS_MENU_LABEL
540
	;; request printing label
541
	call	CS_MENU_UpdateLabel
542
#endif
543
 
1 tk 544
	;; exit if in main page
545
	btfsc	CS_MENU, 7
546
	return
547
 
548
	;; get pointer to menu table depending on CS_MENU (CS_MENU_TABLES + CS_MENU*4)
549
	movlw	0		; offset
550
	call	CS_MENU_GetMenuTablesPtr
551
 
552
	;; get address from table, store it in TBLPTR[LH]
553
	call	MIOS_HLP_AddressFromTable
554
	clrf	TBLPTRU		; TBLPTRU must be 0 (lower 64k page)
555
 
556
	;; read number of menu entries and save it in CS_MENU_ENTRIES
557
	tblrd*+
558
	movff	TABLAT, CS_MENU_ENTRIES
559
 
360 tk 560
	;; read label ID and save it in CS_MENU_LABEL
561
	tblrd*+
562
	movff	TABLAT, CS_MENU_LABEL
563
 
1 tk 564
	;; store pointer in CS_MENU_TABLE_0_[LH], so that other functions can reference
565
	;; to the entries
566
	movff	TBLPTRL, CS_MENU_TABLE_0_L
567
	movff	TBLPTRH, CS_MENU_TABLE_0_H
568
 
569
	;; done in CS_MENU_EXEC_GoToRoot now, so that the cursor doesn't change when we are within a menu page and LCD initialisation is requested
570
#if 0
571
	;; clear cursor and page offset
572
	clrf	CS_MENU_CURSOR_POS
573
	clrf	CS_MENU_PAGE_OFFSET
574
#endif
575
	;; update max value and exit
576
	rgoto	CS_MENU_EncMaxSet
577
 
578
 
579
;; --------------------------------------------------------------------------
580
;;  print the CFG page
581
;; --------------------------------------------------------------------------
582
CS_MENU_Page_Cfg
583
	;; print lower/upper line
584
	movf	CS_MENU_REFRESH_ITEM_CTR, W
585
	bnz	CS_MENU_Page_Cfg_Step1
586
CS_MENU_Page_Cfg_Step0
296 tk 587
	call	CS_MENU_SHIFT_PrintUL
1 tk 588
	rgoto	CS_MENU_Page_Cfg_End
589
CS_MENU_Page_Cfg_Step1
296 tk 590
	call	CS_MENU_SHIFT_PrintLL
1 tk 591
	;; 	rgoto	CS_MENU_Page_Cfg_End
592
 
593
CS_MENU_Page_Cfg_End
594
	;; increment counter until last step reached
595
	incf	CS_MENU_REFRESH_ITEM_CTR, F
596
	movlw	2-1
597
	cpfsgt	CS_MENU_REFRESH_ITEM_CTR, ACCESS
598
	return
599
	clrf	CS_MENU_REFRESH_ITEM_CTR
600
	return
601
 
602
;; --------------------------------------------------------------------------
603
;;  print the root page
604
;; --------------------------------------------------------------------------
605
CS_MENU_PAGE_ROOT_ENS_STR STRING 10, 0x00, "Ensemble: "
606
 
607
CS_MENU_Page_Root
608
	;; print upper line on first step
609
	movf	CS_MENU_REFRESH_ITEM_CTR, W
610
	bnz	CS_MENU_Page_Root_Refresh_NoUL
611
 
612
CS_MENU_Page_Root_Refresh_UL
613
	;; skip upper line if page message is print
614
	BRA_IFSET CS_STAT, CS_STAT_PAGE_MSG, ACCESS, CS_MENU_Page_Root_Refresh_NoUL
615
 
616
	;; in ensemble menu: print ensemble number, otherwise patch name
617
	BRA_IFCLR CS_MENU, 6, ACCESS, CS_MENU_Page_Root_Refresh_UL_P
618
CS_MENU_Page_Root_Refresh_UL_E
619
	TABLE_ADDR CS_MENU_PAGE_ROOT_ENS_STR
620
	call	MIOS_LCD_PrintString
621
 
622
	;; print ensemble number
623
	call	SID_LCD_PrintEnsembleNumber
624
 
625
	;; print '*' if ensemble not valid (no BankStick)
626
	call	SID_EBANK_CheckValid
627
	movlw	' '
628
	skpz
629
	movlw	'*'
630
	call	MIOS_LCD_PrintChar
631
 
632
	;; fill rest with spaces
633
	movlw	5
634
	call	SID_LCD_PrintSpaces
635
 
636
	rgoto	CS_MENU_Page_Root_Refresh_UL_C
637
 
638
CS_MENU_Page_Root_Refresh_UL_P
639
	;; set cursor to first line, first column
640
	movlw	0x00
641
	call	MIOS_LCD_CursorSet
642
 
643
	;; get current CS_MENU_SID
644
	call	CS_MENU_MS_GetSIDNumber
645
 
646
	;; print patch name
647
	call	SID_LCD_PrintPatch
648
 
649
	;; print bank number and patch
650
	call	CS_MENU_MS_GetSIDBank
651
	movwf	SID_BANK
652
	call	CS_MENU_MS_GetSIDPatch
653
	movwf	SID_PATCH
654
	call	SID_LCD_PrintPatchNumber
655
 
656
CS_MENU_Page_Root_Refresh_UL_C
657
CS_MENU_Page_Root_Refresh_NoUL
658
	;; print menu item name
659
	movlw	0x40
660
	call	CS_MENU_PrintILine
661
 
662
CS_MENU_Page_Root_Refresh_End
663
	;; increment counter until last step reached
664
	incf	CS_MENU_REFRESH_ITEM_CTR, F
665
	movf	CS_MENU_REFRESH_ITEM_CTR, W
666
	xorlw	CS_MENU_DISPLAYED_ITEMS
667
	skpz
668
	return
669
 
670
	;; last step: print also the arrows and clear item counter
671
	movlw	0x40
672
	rcall	CS_MENU_PrintILine_Arw
673
	clrf	CS_MENU_REFRESH_ITEM_CTR
674
	return
675
 
676
 
677
;; --------------------------------------------------------------------------
678
;;  print a parameters page
679
;; --------------------------------------------------------------------------
680
CS_MENU_Page_Parameters
681
	;; if in MODIFY_NAME mode, print name editing screen
682
	BRA_IFSET CS_STAT, CS_STAT_MODIFY_NAME, ACCESS, CS_MENU_Page_EditName
683
 
684
	;; if in MODIFY_SEQ mode, print drum editing screen
685
	BRA_IFSET CS_STAT3, CS_STAT3_MODIFY_SEQ, ACCESS, CS_MENU_Page_EditSeq
686
 
687
	;; print menu item name
688
	;; skip if page or "big" message is print
689
	BRA_IFSET CS_STAT, CS_STAT_PAGE_MSG, ACCESS, CS_MENU_Page_Parameters_SkipUL
690
	BRA_IFSET CS_STAT, CS_STAT_BIG_MSG, ACCESS, CS_MENU_Page_Parameters_SkipUL
691
CS_MENU_Page_Parameters_UL
692
	movlw	0x00
693
	call	CS_MENU_PrintILine
694
CS_MENU_Page_Parameters_SkipUL
695
 
696
	;; print parameter value
697
	;; skip if "big" big message is print
698
	BRA_IFSET CS_STAT, CS_STAT_BIG_MSG, ACCESS, CS_MENU_Page_Parameters_SkipLL
699
CS_MENU_Page_Parameters_LL
700
	movlw	0x40
701
	call	CS_MENU_PrintPLine
702
CS_MENU_Page_Parameters_SkipLL
703
 
704
	;; increment counter until last step reached
705
	incf	CS_MENU_REFRESH_ITEM_CTR, F
706
	movf	CS_MENU_REFRESH_ITEM_CTR, W
707
	xorlw	CS_MENU_DISPLAYED_ITEMS
708
	skpz
709
	return
710
 
711
	;; last step: print arrow, clear item counter and enable the cursor
712
	movlw	0x00
713
	rcall	CS_MENU_PrintILine_Arw
714
	clrf	CS_MENU_REFRESH_ITEM_CTR
715
 
716
	;; if not GLCD and in "modify parameter" mode, set cursor
717
	btfsc	MIOS_BOX_CFG0, MIOS_BOX_CFG0_USE_GLCD
718
	return
719
	btfss	CS_STAT, CS_STAT_MODIFY_PARAMETER
720
	return
721
 
722
	;; don't set cursor if no menu item
723
	movf	CS_MENU_ENTRIES, W
724
	cpfslt	CS_MENU_CURSOR_POS, ACCESS
725
	return
726
 
727
	;; don't set cursor if "big message" is visible
728
	btfsc	CS_STAT, CS_STAT_BIG_MSG
729
	return
730
 
731
	;; set cursor to: 0x40 + 4*(CS_MENU_CURSOR_POS-CS_MENU_PAGE_OFFSET) + 2
732
	movf	CS_MENU_PAGE_OFFSET, W
733
	subwf	CS_MENU_CURSOR_POS, W
734
	mullw	4
735
	movf	PRODL, W
736
	addlw	0x40 + 2
737
	call	MIOS_LCD_CursorSet
738
 
360 tk 739
#if DEFAULT_LCD_PRINT_CURSOR
1 tk 740
	;; enable blinking CLCD cursor and exit
741
	movlw	0x0e
742
	CALL_IFCLR MIOS_BOX_CFG0, MIOS_BOX_CFG0_USE_GLCD, ACCESS, MIOS_LCD_Cmd
360 tk 743
#endif
1 tk 744
	return
745
 
296 tk 746
 
1 tk 747
;; --------------------------------------------------------------------------
296 tk 748
;;  print parameter name on whole screen
749
;;  called when a parameter assignment is edited
750
;; --------------------------------------------------------------------------
751
				     ;;  <------------------>
752
TEXT_CS_MENU_PARAMETER STRING 20, 0x00, "Parameter Assign.:  "
753
				     ;;  12341234123412341234
754
CS_MENU_Page_BigMsg_ParName
755
	;; notify that "big" message will be print (until item is deselected)
756
	bsf	CS_STAT, CS_STAT_BIG_MSG
757
 
758
	;; print uppper line
759
	TABLE_ADDR TEXT_CS_MENU_PARAMETER
760
	call	MIOS_LCD_PrintString
761
 
762
	;; print lower line
763
	movlw	0x40
764
	call	MIOS_LCD_CursorSet
765
 
766
	movf	CS_MENU_PARAMETER_L, W
767
	goto	SID_LCD_LongParName
768
 
769
 
770
;; --------------------------------------------------------------------------
771
;;  print patch and bank
772
;;  called when a parameter assignment is edited
773
;; --------------------------------------------------------------------------
774
				     ;;  <------------------>
775
TEXT_CS_MENU_PATCH     STRING  7, 0x00, "Patch: "
776
TEXT_CS_MENU_BANK      STRING  7, 0x00, "Bank:  "
777
				     ;;  12341234123412341234
778
 
779
CS_MENU_Page_BigMsg_Bank
780
	TABLE_ADDR TEXT_CS_MENU_BANK
781
	rgoto	CS_MENU_Page_BigMsg_Bank_Cont
782
 
783
CS_MENU_Page_BigMsg_Patch
784
	TABLE_ADDR TEXT_CS_MENU_PATCH
785
	rgoto	CS_MENU_Page_BigMsg_Bank_Cont
786
 
787
CS_MENU_Page_BigMsg_Bank_Cont
788
	;; notify that "big" message will be print (until item is deselected)
789
	bsf	CS_STAT, CS_STAT_BIG_MSG
790
 
791
	;; print uppper line
792
	call	MIOS_LCD_PrintString
793
 
794
	call	CS_MENU_MS_GetSIDNumber
795
	call	CS_MENU_MS_GetSIDBank
796
	movwf	SID_BANK
797
	call	CS_MENU_MS_GetSIDPatch
798
	movwf	SID_PATCH
799
	call	SID_LCD_PrintPatchNumber
800
 
801
	movlw	9
802
	call	SID_LCD_PrintSpaces
803
 
804
 
805
	;; print lower line
806
	movlw	0x40
807
	call	MIOS_LCD_CursorSet
808
 
809
	call	SID_LCD_PrintPatchEE	; (new name not loaded into edit buffer yet!)
810
 
811
	movlw	4
812
	goto	SID_LCD_PrintSpaces
813
 
814
 
815
;; --------------------------------------------------------------------------
1 tk 816
;;  name editing screen
817
;; --------------------------------------------------------------------------
818
CS_MENU_Page_EditName
819
	;; skip upper line if page message is print
820
	BRA_IFSET CS_STAT, CS_STAT_PAGE_MSG, ACCESS, CS_MENU_Page_EditName_SkipUL
821
CS_MENU_Page_EditName_UL
822
	;; set cursor to first line, first column
823
	movlw	0x00
824
	call	MIOS_LCD_CursorSet
825
 
826
	;; print steps
827
	call	SID_LCD_PrintPatch
828
 
829
	;; fill rest with spaces
830
	movlw	40-16
831
	rcall	CS_MENU_Hlp_PrintSpaces
832
 
833
CS_MENU_Page_EditName_SkipUL
834
	;; flashing cursor: set space
835
	BRA_IFSET CS_STAT, CS_STAT_CURSOR_FLASH, ACCESS, CS_MENU_Page_EditName_NoSpc
836
	movf	CS_MENU_NAME_POS, W
837
	call	MIOS_LCD_CursorSet
838
	movlw	' '
839
	call	MIOS_LCD_PrintChar
840
CS_MENU_Page_EditName_NoSpc
841
 
842
	;; print button options @ position 0x40 (second line)
843
	TABLE_ADDR TEXT_CS_MENU_EDIT_NAME_OPTIONS
844
	call	MIOS_LCD_PrintString
845
	;; print 20 spaces (for 2x40 displays)
846
#if CS_MENU_DISPLAYED_ITEMS > 5
847
	movlw	20
848
	rcall	CS_MENU_Hlp_PrintSpaces
849
#endif
850
 
851
	;; if not GLCD, set cursor
852
	btfsc	MIOS_BOX_CFG0, MIOS_BOX_CFG0_USE_GLCD
853
	return
854
 
855
	;; set cursor to: 0x00 + CS_MENU_NAME_POS
856
	movf	CS_MENU_NAME_POS, W
857
	call	MIOS_LCD_CursorSet
858
 
360 tk 859
#if DEFAULT_LCD_PRINT_CURSOR
1 tk 860
	;; enable blinking CLCD cursor and exit
861
	movlw	0x0e
862
	CALL_IFCLR MIOS_BOX_CFG0, MIOS_BOX_CFG0_USE_GLCD, ACCESS, MIOS_LCD_Cmd
360 tk 863
#endif
1 tk 864
	return
865
 
866
				  	     ;;  <------------------>
867
TEXT_CS_MENU_EDIT_NAME_OPTIONS STRING 20, 0x40, "SAVE  <   >  Del Clr"
868
					     ;;  12341234123412341234
869
 
870
;; --------------------------------------------------------------------------
871
;;  drum sequence editing screen
872
;; --------------------------------------------------------------------------
873
CS_MENU_Page_EditSeq
874
	;; skip upper line if page message is print
875
	BRA_IFSET CS_STAT, CS_STAT_PAGE_MSG, ACCESS, CS_MENU_Page_EditSeq_SkipUL
876
CS_MENU_Page_EditSeq_UL
877
	;; set cursor to first line, first column
878
	movlw	0x00
879
	call	MIOS_LCD_CursorSet
880
 
881
	;; print track steps (16 characters)
882
	call	CS_MENU_PRINT_SeqSteps
883
 
884
	;; one space
885
	movlw	' '
886
	call	MIOS_LCD_PrintChar
887
 
888
	;; if rotate button pressed, print "Rot", otherwise sequencer and track number
889
	BRA_IFSET CS_STAT3, CS_STAT3_MODIFY_SEQ_ROTATE, ACCESS, CS_MENU_Page_EditSeq_UL_Rot
890
CS_MENU_Page_EditSeq_UL_Norm
891
	;; print track
892
	incf	CS_MENU_WT_SEQ, W
893
	call	MIOS_LCD_PrintBCD1
894
	movlw	'_'
895
	call	MIOS_LCD_PrintChar
896
	movf	CS_MENU_SELECTED_TRK, W
897
	andlw	0x07
898
	addlw	1
899
	call	MIOS_LCD_PrintBCD1
900
	rgoto	CS_MENU_Page_EditSeq_UL_Cont
901
 
902
CS_MENU_Page_EditSeq_UL_Rot
903
	movlw	'R'
904
	call	MIOS_LCD_PrintChar
905
	movlw	'o'
906
	call	MIOS_LCD_PrintChar
907
	movlw	't'
908
	call	MIOS_LCD_PrintChar
909
	;; 	rgoto	CS_MENU_Page_EditSeq_UL_Cont
910
 
911
CS_MENU_Page_EditSeq_UL_Cont
912
	;; fill rest with spaces
913
	movlw	40-20
914
	rcall	CS_MENU_Hlp_PrintSpaces
915
 
916
CS_MENU_Page_EditSeq_SkipUL
917
	;; not if rotate function active
918
	BRA_IFSET CS_STAT3, CS_STAT3_MODIFY_SEQ_ROTATE, ACCESS, CS_MENU_Page_EditSeq_NoSpc
919
 
920
	;; flashing cursor: set space
921
	BRA_IFSET CS_STAT, CS_STAT_CURSOR_FLASH, ACCESS, CS_MENU_Page_EditSeq_NoSpc
922
	movf	CS_MENU_NAME_POS, W
923
	call	MIOS_LCD_CursorSet
924
	movlw	' '
925
	call	MIOS_LCD_PrintChar
926
CS_MENU_Page_EditSeq_NoSpc
927
 
928
	;; print button options @ position 0x40 (second line)
929
	TABLE_ADDR TEXT_CS_MENU_EDIT_SEQ_OPTIONS
930
	call	MIOS_LCD_PrintString
931
 
932
	;; print 20 spaces (for 2x40 displays)
933
#if CS_MENU_DISPLAYED_ITEMS > 5
934
	movlw	20
935
	rcall	CS_MENU_Hlp_PrintSpaces
936
#endif
937
 
938
	;; if not GLCD, set cursor
939
	btfsc	MIOS_BOX_CFG0, MIOS_BOX_CFG0_USE_GLCD
940
	return
941
 
942
	;; not if rotate function active
943
	btfsc	CS_STAT3, CS_STAT3_MODIFY_SEQ_ROTATE
944
	return
945
 
946
	;; set cursor to: 0x00 + CS_MENU_NAME_POS
947
	movf	CS_MENU_NAME_POS, W
948
	call	MIOS_LCD_CursorSet
949
 
360 tk 950
#if DEFAULT_LCD_PRINT_CURSOR
1 tk 951
	;; enable blinking CLCD cursor and exit
952
	movlw	0x0e
953
	CALL_IFCLR MIOS_BOX_CFG0, MIOS_BOX_CFG0_USE_GLCD, ACCESS, MIOS_LCD_Cmd
360 tk 954
#endif
1 tk 955
	return
956
 
957
 
958
TEXT_CS_MENU_EDIT_SEQ_OPTIONS STRING 20, 0x40, "GAS Rot Rnd Clr DRM "
959
					    ;;  12341234123412341234
960
 
961
;; --------------------------------------------------------------------------
962
;;  print the menu items line
963
;;  IN: pointer to menu entries in TBLPTR[LH]
964
;;      offset to first entry in CS_MENU_PAGE_OFFSET
965
;;      cursor offset (normaly 0x40 or 0x00) in WREG
966
;; --------------------------------------------------------------------------
967
CS_MENU_PrintILine
968
	;; determine cursor position and set cursor
969
	movwf	TMP1
970
 
971
	movf	CS_MENU_REFRESH_ITEM_CTR, W
972
	mullw	CS_MENU_ENTRY_SLABEL_LEN+1
973
	movf	PRODL, W
974
	iorwf	TMP1, W
975
	call	MIOS_LCD_CursorSet
976
 
977
	;; move pointer to first visible entry to CS_MENU_ENTRY_TBLPTR[LH]
978
	rcall	CS_MENU_Hlp_GetFirstVisibleEntry
979
 
980
	;; add offset to selected item
981
	movf	CS_MENU_REFRESH_ITEM_CTR, W
982
	mullw	CS_MENU_ENTRY_LEN
983
	movf	PRODL, W
984
	addwf	CS_MENU_ENTRY_TBLPTRL, F
985
	movf	PRODH, W
986
	addwfc	CS_MENU_ENTRY_TBLPTRH, F
987
 
988
 
989
	;; if  CS_MENU_PAGE_OFFSET + CS_MENU_LOOP_CTR - 1 >= CS_MENU_ENTRIES
990
	;;    -> print spaces
991
	movf	CS_MENU_PAGE_OFFSET, W
992
	addwf	CS_MENU_REFRESH_ITEM_CTR, W
993
	addlw	1
994
	cpfslt	CS_MENU_ENTRIES, ACCESS
995
	rgoto CS_MENU_PrintILine_Ok
996
	;; print 4 spaces
997
	movlw	4
998
	rcall	CS_MENU_Hlp_PrintSpaces
999
	rgoto	CS_MENU_PrintILine_End
1000
CS_MENU_PrintILine_Ok
1001
	;; if CS_MENU_CURSOR_POS == CS_MENU_PAGE_OFFSET + CS_MENU_LOOP_CTR,
1002
	;;    AND CS_STAT.CS_STAT_MODIFY_PARAMETER cleared
1003
	;;    -> print spaces of cursor flash flag cleared,
1004
	;;    -> else short label
1005
	;; print short label (function switches to next table entry)
1006
	rcall	CS_MENU_PrintSEntry
1007
	;; print space
1008
	movlw	' '
1009
	call	MIOS_LCD_PrintChar
1010
 
1011
CS_MENU_PrintILine_End
1012
	return
1013
 
1014
;; --------------------------------------------------------------------------
1015
;;  print the arrows at the end of an ILine
1016
;;  IN: pointer to menu entries in TBLPTR[LH]
1017
;;      offset to first entry in CS_MENU_PAGE_OFFSET
1018
;; --------------------------------------------------------------------------
1019
CS_MENU_PrintILine_Arw
1020
	;; set cursor
1021
	addlw	CS_MENU_DISPLAYED_ITEMS*4 - 1
1022
	call	MIOS_LCD_CursorSet
1023
 
1024
	;; don't print arrow if in "modify parameter" mode
1025
	BRA_IFSET CS_STAT, CS_STAT_MODIFY_PARAMETER, ACCESS, CS_MENU_PrintILine_Arw_NL
1026
CS_MENU_PrintILine_Arw_L
1027
	;; print space, left or right arrow, depending on cursor position
1028
	;; if CS_MENU_ENTRIES < CS_MENU_DISPLAYED_ITEMS, print space
1029
	movlw	CS_MENU_DISPLAYED_ITEMS+1
1030
	cpfslt	CS_MENU_ENTRIES, ACCESS
1031
	rgoto CS_MENU_PrintILine_Arw_LNS
1032
CS_MENU_PrintILine_Arw_LSp
1033
	movlw	' '
1034
	rgoto	CS_MENU_PrintILine_Arw_C
1035
CS_MENU_PrintILine_Arw_LNS
1036
	;; if CS_MENU_PAGE_OFFSET == 0, print '>'
1037
	movf	CS_MENU_PAGE_OFFSET, W
1038
	bz	CS_MENU_PrintILine_Arw_LR
1039
	;; if CS_MENU_PAGE_OFFSET != CS_MENU_ENTRIES-CS_MENU_DISPLAY_ITEMS, print '<>'
1040
	movf	CS_MENU_ENTRIES, W
1041
	addlw	-CS_MENU_DISPLAYED_ITEMS
1042
	cpfseq	CS_MENU_PAGE_OFFSET, ACCESS
1043
	rgoto CS_MENU_PrintILine_Arw_LLR
1044
CS_MENU_PrintILine_Arw_LL
1045
	btfss	MIOS_BOX_CFG0, MIOS_BOX_CFG0_USE_GLCD; special char #0: '<'
1046
	movlw 0x00
1047
	btfsc	MIOS_BOX_CFG0, MIOS_BOX_CFG0_USE_GLCD; undocumented feature: GLCD special char #8: '<'
1048
	movlw 0x08
1049
	rgoto	CS_MENU_PrintILine_Arw_C
1050
CS_MENU_PrintILine_Arw_LR
1051
	btfss	MIOS_BOX_CFG0, MIOS_BOX_CFG0_USE_GLCD; special char #1: '>'
1052
	movlw 0x01
1053
	btfsc	MIOS_BOX_CFG0, MIOS_BOX_CFG0_USE_GLCD; undocumented feature: GLCD special char #9: '>'
1054
	movlw 0x09
1055
	rgoto	CS_MENU_PrintILine_Arw_C
1056
CS_MENU_PrintILine_Arw_LLR
1057
	btfss	MIOS_BOX_CFG0, MIOS_BOX_CFG0_USE_GLCD; special char #7: '<>'
1058
	movlw 0x07
1059
	btfsc	MIOS_BOX_CFG0, MIOS_BOX_CFG0_USE_GLCD; undocumented feature: GLCD special char #9: '>'
1060
	movlw 0x09
1061
	rgoto	CS_MENU_PrintILine_Arw_C
1062
 
1063
CS_MENU_PrintILine_Arw_NL
1064
	;; no: print space
1065
	movlw	' '
1066
	;; 	rgoto	CS_MENU_PrintILine_Arw_C
1067
CS_MENU_PrintILine_Arw_C
1068
	goto	MIOS_LCD_PrintChar
1069
 
1070
;; --------------------------------------------------------------------------
1071
;;  print the menu parameters line
1072
;;  IN: pointer to menu entries in TBLPTR[LH]
1073
;;      offset to first entry in CS_MENU_PAGE_OFFSET
1074
;; --------------------------------------------------------------------------
1075
CS_MENU_PrintPLine
1076
	;; determine cursor position and set cursor
1077
	movwf	TMP1
1078
 
1079
	movf	CS_MENU_REFRESH_ITEM_CTR, W
1080
	mullw	CS_MENU_ENTRY_SLABEL_LEN+1
1081
	movf	PRODL, W
1082
	iorwf	TMP1, W
1083
	call	MIOS_LCD_CursorSet
1084
 
1085
	;; move pointer to first visible entry to CS_MENU_ENTRY_TBLPTR[LH]
1086
	rcall	CS_MENU_Hlp_GetFirstVisibleEntry
1087
 
1088
	;; add offset to selected item
1089
	movf	CS_MENU_REFRESH_ITEM_CTR, W
1090
	mullw	CS_MENU_ENTRY_LEN
1091
	movf	PRODL, W
1092
	addwf	CS_MENU_ENTRY_TBLPTRL, F
1093
	movf	PRODH, W
1094
	addwfc	CS_MENU_ENTRY_TBLPTRH, F
1095
 
1096
	;; if  CS_MENU_PAGE_OFFSET + CS_MENU_REFRESH_ITEM_CTR - 1 >= CS_MENU_ENTRIES
1097
	;;    -> print spaces
1098
	movf	CS_MENU_PAGE_OFFSET, W
1099
	addwf	CS_MENU_REFRESH_ITEM_CTR, W
1100
	addlw	1
1101
	cpfslt	CS_MENU_ENTRIES, ACCESS
1102
	rgoto CS_MENU_PrintPLine_Ok
1103
	;; EXTRA: not in "save" menu due to the long parameter name
1104
	call	CS_MENU_GetMenuID_SAV
1105
	xorwf	CS_MENU, W
1106
	bz	CS_MENU_PrintPLine_End
1107
	;; print 4 spaces
1108
	movlw	4
1109
	rcall	CS_MENU_Hlp_PrintSpaces
1110
	rgoto	CS_MENU_PrintPLine_End
1111
CS_MENU_PrintPLine_Ok
1112
	;; if CS_MENU_CURSOR_POS == CS_MENU_PAGE_OFFSET + CS_MENU_LOOP_CTR
1113
	;;    AND CS_STAT.CS_STAT_MODIFY_PARAMETER set
1114
	;;    -> print spaces of cursor flash flag cleared,
1115
	;;    -> else parameter
1116
	movf	CS_MENU_PAGE_OFFSET, W
1117
	addwf	CS_MENU_REFRESH_ITEM_CTR, W
1118
	cpfseq	CS_MENU_CURSOR_POS, ACCESS
1119
	rgoto CS_MENU_PrintPLine_COn
1120
	BRA_IFSET CS_STAT, CS_STAT_CURSOR_FLASH, ACCESS, CS_MENU_PrintPLine_COn
1121
	BRA_IFCLR CS_STAT, CS_STAT_MODIFY_PARAMETER, ACCESS, CS_MENU_PrintPLine_COn
1122
	;; print 4 spaces
1123
	movlw	4
1124
	rcall	CS_MENU_Hlp_PrintSpaces
1125
	rgoto	CS_MENU_PrintPLine_End
1126
CS_MENU_PrintPLine_COn
1127
	rcall	CS_MENU_PrintPEntry
1128
	movlw	' '
1129
	call	MIOS_LCD_PrintChar
1130
 
1131
CS_MENU_PrintPLine_End
1132
 
1133
	return
1134
 
1135
;; --------------------------------------------------------------------------
1136
;;  print the short label of a menu item
1137
;;  IN: pointer to menu entry in CS_MENU_ENTRY_TBLPTR[LH]
1138
;;  USES: TMP1
1139
;;  OUT: pointer to next entry
1140
;; --------------------------------------------------------------------------
1141
CS_MENU_PrintSEntry
1142
	;; calc offset to short entry and copy result to tablepointer
1143
	movlw	CS_MENU_ENTRY_SLABEL_OFFSET
1144
	rcall	CS_MENU_Hlp_GetPointer
1145
 
1146
	;; quick hack: if first character is "$", print WTPos offset
1147
	;; used in WT Editor
1148
	tblrd*
1149
	movlw	'$'
1150
	cpfseq	TABLAT, ACCESS
1151
	rgoto CS_MENU_PrintSEntry_Norm
1152
CS_MENU_PrintSEntry_WT
1153
	movlw	'$'
1154
	CALL_IFCLR CS_STAT2, CS_STAT2_WT_DEC_VIEW, ACCESS, MIOS_LCD_PrintChar
1155
 
1156
	;; hack: CS_MENU_FSR0_WTPos expects WT number (L:0-3/M:0-5) in CS_MENU_PARAMETER_IX, and returns WT address in FSR0L
1157
	;; it sets ZERO flag if address outside begin/end range
1158
	decf	CS_MENU_PAGE_OFFSET, W
1159
	addwf	CS_MENU_REFRESH_ITEM_CTR, W
1160
	movwf	CS_MENU_PARAMETER_IX
1161
	call	CS_MENU_FSR0_WTPos
1162
	bnz	CS_MENU_PrintSEntry_WT_Ok
1163
CS_MENU_PrintSEntry_WT_Inv
1164
	movlw	'<'
1165
	call	MIOS_LCD_PrintChar
1166
	movlw	'-'
1167
	CALL_IFSET CS_STAT2, CS_STAT2_WT_DEC_VIEW, ACCESS, MIOS_LCD_PrintChar
1168
	movlw	'>'
1169
	goto	MIOS_LCD_PrintChar
1170
 
1171
CS_MENU_PrintSEntry_WT_Ok
1172
	movf	FSR0L, W
1173
	addlw	0-LOW(SID_Ix_WAVETABLE)
1174
	GOTO_IFSET CS_STAT2, CS_STAT2_WT_DEC_VIEW, ACCESS, MIOS_LCD_PrintBCD3
1175
	goto	MIOS_LCD_PrintHex2
1176
 
1177
CS_MENU_PrintSEntry_Norm
1178
	;; print short label
1179
	movlw	CS_MENU_ENTRY_SLABEL_LEN
1180
	movwf	TMP1
1181
CS_MENU_PrintSEntry_Loop
1182
	tblrd*+
1183
	movf	TABLAT, W
1184
	call	MIOS_LCD_PrintChar
1185
	decfsz	TMP1, F
1186
	rgoto	CS_MENU_PrintSEntry_Loop
1187
	return
1188
 
1189
 
1190
;; --------------------------------------------------------------------------
1191
;;  print the parameter of a menu entry
1192
;;  IN: pointer to menu entry in CS_MENU_ENTRY_TBLPTR[LH]
1193
;; --------------------------------------------------------------------------
1194
CS_MENU_PrintPEntry
1195
	;; get handler IDs
1196
	rcall	CS_MENU_GetHandlerIDs
1197
	;; PRINT ID in MIOS_PARAMETER1
1198
	movf	MIOS_PARAMETER1, W
1199
	goto	CS_MENU_PRINT_Handler
1200
 
1201
 
1202
;; --------------------------------------------------------------------------
1203
;;  Update the encoder speed setting
1204
;;  Encoder number in WREG
1205
;;  If >0, function has to be called after CS_MENU_PARAMETER_MAX_[LH] has been updated!
1206
;; --------------------------------------------------------------------------
1207
CS_MENU_EncSpeedSet
1208
	;; if encoder number > 0, always use ModVal speed
1209
	movwf	PRODL		; store number in PRODL
1210
	andlw	0xff		; fix ZERO flag
1211
	bnz	CS_MENU_EncSpeedSet_ModVal
1212
 
1213
	;; following branch only used with menu encoder
1214
	BRA_IFSET CS_MENU, 7, ACCESS, CS_MENU_EncSpeedSet_Main
1215
	BRA_IFSET CS_STAT, CS_STAT_MODIFY_PARAMETER, ACCESS, CS_MENU_EncSpeedSet_ModVal
1216
 
1217
CS_MENU_EncSpeedSet_SelItem
1218
	;; "select menu item" mode: set encoder speed to "normal"
1219
	movlw	MIOS_ENC_SPEED_NORMAL
1220
	movwf	MIOS_PARAMETER1
1221
	movf	PRODL, W	; encoder number
1222
	goto	MIOS_ENC_SpeedSet
1223
 
1224
	;; in main page (where the patch number is selected with the encoder)
1225
	;; - set to "fast mode" if SHIFT button is *not* pressed (fast selection)
1226
	;; - set to "normal mode" if SHIFT button is pressed (slow selection)
1227
CS_MENU_EncSpeedSet_Main
1228
	movlw	2			; this speed value is taken when ENC_SPEED_FAST is selected
1229
	movwf	MIOS_PARAMETER2
1230
	movlw	MIOS_ENC_SPEED_FAST	; FAST or NORMAL mode depending on state of shift button
1231
	btfsc	CS_MENU_MODE, CS_MENU_MODE_SHIFT_PRESSED
1232
	movlw	MIOS_ENC_SPEED_NORMAL
1233
	movwf	MIOS_PARAMETER1
1234
	movf	PRODL, W		; encoder number
1235
	goto	MIOS_ENC_SpeedSet
1236
 
1237
CS_MENU_EncSpeedSet_ModVal
1238
	;; "modify parameter" mode: set encoder speed to "fast"
1239
	;; divider value depends directly on max value
1240
 
1241
	movf	CS_MENU_PARAMETER_MAX_L, W
1242
	movwf	TMP1
1243
	andlw	0xe0
1244
	iorwf	CS_MENU_PARAMETER_MAX_H, W
1245
	bnz	CS_MENU_EncSpeedSet_ModVal_GT1F
1246
	;; max value <= 0x1f: set slow/normal speed
1247
CS_MENU_EncSpeedSet_ModVal_LE1F
1248
	;; "select menu item" mode: set encoder speed to "normal"
1249
	movlw	0x00
1250
	movwf	MIOS_PARAMETER3
1251
	movlw	MIOS_ENC_SPEED_NORMAL
1252
	movwf	MIOS_PARAMETER1
1253
	movf	PRODL, W	; encoder number
1254
	goto	MIOS_ENC_SpeedSet
1255
 
1256
CS_MENU_EncSpeedSet_ModVal_GT1F
1257
	;; max value > 0x1f: set fast speed
1258
	movf	CS_MENU_PARAMETER_MAX_H, W
1259
	movwf	TMP2
1260
	rlf	TMP1, F
1261
	rlf	TMP2, F
1262
	movlw	0x05		; saturate if value >= 5
1263
	cpfsgt  TMP2, ACCESS	; (IFLEQ)
1264
	movf	TMP2, W
1265
 
1266
	;; increase speed if shift button NOT pressed
1267
	btfss	CS_MENU_MODE, CS_MENU_MODE_SHIFT_PRESSED
1268
	addlw 2
1269
 
1270
	movwf	MIOS_PARAMETER2
1271
 
1272
	movlw	MIOS_ENC_SPEED_FAST
1273
	movwf	MIOS_PARAMETER1
1274
	movf	PRODL, W	; encoder number
1275
	goto	MIOS_ENC_SpeedSet
1276
 
1277
 
1278
;; --------------------------------------------------------------------------
1279
;;  Set max value of currently selected parameter (or menu pos or SID patch)
1280
;; --------------------------------------------------------------------------
1281
CS_MENU_EncMaxSet
1282
	;; if in parameter selection mode, max value has been set by CS_MENU_EXEC_SelPar
1283
	btfsc	CS_STAT, CS_STAT_MODIFY_PARAMETER
1284
	return
1285
 
1286
	;; set CS_MENU_PARAMETER depending on CS_MENU[7] (main or menu page)
1287
	BRA_IFSET CS_MENU, 7, ACCESS, CS_MENU_ParameterMaxSet_Main
1288
CS_MENU_ParameterMaxSet_Root
1289
	decf	CS_MENU_ENTRIES, W
1290
	movf	CS_MENU_ENTRIES, W
1291
	addlw	-CS_MENU_DISPLAYED_ITEMS
1292
	skpc
1293
	movlw	0x00
1294
	movwf	CS_MENU_PARAMETER_MAX_L	; low-byte of max value
1295
	clrf	CS_MENU_PARAMETER_MAX_H	; high-byte of max value
1296
	return
1297
 
1298
CS_MENU_ParameterMaxSet_Ens
1299
CS_MENU_ParameterMaxSet_Main
1300
	movlw	0x7f
1301
	movwf	CS_MENU_PARAMETER_MAX_L
1302
	clrf	CS_MENU_PARAMETER_MAX_H
1303
	return
1304
 
1305
;; --------------------------------------------------------------------------
1306
;;  Update parameter value of currently selected parameter (or menu pos or SID patch)
1307
;; --------------------------------------------------------------------------
1308
CS_MENU_EncParameterSet
1309
	BRA_IFCLR CS_STAT, CS_STAT_MODIFY_PARAMETER, ACCESS, CS_MENU_EncParameterSet_NoItem
1310
CS_MENU_EncParameterSet_Item
1311
	;; menu item: execute R2P function and exit
1312
 
1313
	;; get pointer to entry which has been selected
1314
	rcall	CS_MENU_Hlp_GetCursorPosEntry
1315
	;; get handler IDs
1316
	rcall	CS_MENU_GetHandlerIDs
1317
	;; R2PP2R ID in MIOS_PARAMETER3
1318
	movf	MIOS_PARAMETER3, W
1319
	goto	CS_MENU_R2P_Handler
1320
 
1321
CS_MENU_EncParameterSet_NoItem
1322
 
1323
	;; set CS_MENU_PARAMETER depending on CS_MENU[7] (main or menu page)
1324
	BRA_IFSET CS_MENU, 7, ACCESS, CS_MENU_ParameterSet_Main
1325
CS_MENU_ParameterSet_Root
1326
	movf	CS_MENU_PAGE_OFFSET, W
1327
	movwf	CS_MENU_PARAMETER_L
1328
	clrf	CS_MENU_PARAMETER_H
1329
	return
1330
 
1331
CS_MENU_ParameterSet_Main
1332
	;; also called from CS_MENU_ENC_Handler, so that CS_MENU_PARAMETER_[LH] contain the value
1333
	;; depending on menu button state
1334
	BRA_IFCLR CS_MENU_MODE, CS_MENU_MODE_MENU_PRESSED, ACCESS, CS_MENU_ParameterSet_Main_Patch
1335
CS_MENU_ParameterSet_Main_Ens
1336
	movf	SID_ENSEMBLE, W
1337
	rgoto	CS_MENU_ParameterSet_Main_End
1338
 
1339
CS_MENU_ParameterSet_Main_Patch
1340
	;; get SID number
1341
	call	CS_MENU_MS_GetSIDNumber
1342
	;; copy selected patch * 4 to CS_MENU_PARAMETER_[LH]
1343
	call	CS_MENU_MS_GetSIDPatch
1344
	;; 	rgoto	CS_MENU_ParameterSet_Main_End
1345
 
1346
CS_MENU_ParameterSet_Main_End
1347
	movwf	CS_MENU_PARAMETER_L
1348
	clrf	CS_MENU_PARAMETER_H
1349
	return
1350
 
1351
 
1352
;; --------------------------------------------------------------------------
1353
;;  called by cs_menu_buttons.inc when a parameter has been selected
1354
;;  IN: new cursor position in WREG
1355
;; --------------------------------------------------------------------------
1356
CS_MENU_Select
1357
	;; exit if SID not available
1358
	btfss	CS_STAT, CS_STAT_SID_AVAILABLE
1359
	return
1360
 
1361
	;; ignore if "big" message is print
1362
	btfsc	CS_STAT, CS_STAT_BIG_MSG
1363
	return
1364
 
1365
	;; if in name editing mode, branch to CS_MENU_Select_NameFunc
1366
	BRA_IFSET CS_STAT, CS_STAT_MODIFY_NAME, ACCESS, CS_MENU_Select_NameFunc
1367
 
1368
	;; if in drum sequence editing mode, branch to CS_MENU_Select_SeqFunc
1369
	BRA_IFSET CS_STAT3, CS_STAT3_MODIFY_SEQ, ACCESS, CS_MENU_Select_SeqFunc
1370
 
1371
	;; if in main page (CS_MENU[7] set), branch to root menu
1372
	BRA_IFCLR CS_MENU, 7, ACCESS, CS_MENU_Select_Menu
1373
CS_MENU_Select_Main
1374
	;; branch depending on button number
1375
	;; first button branches to ENS menu, all others to normal root page
1376
	andlw	0xff		; fix zero flag
1377
	skpnz
1378
	goto	CS_MENU_EXEC_GoToEnsRoot
1379
	goto	CS_MENU_EXEC_GoToRoot
1380
 
1381
CS_MENU_Select_Menu
1382
	;; store new position in CS_MENU_CURSOR_POS
1383
	movwf	CS_MENU_CURSOR_POS
1384
 
1385
	;; store cursor pos in CS_MENU_PARAMETER_L
1386
	movwf	CS_MENU_PARAMETER_L
1387
 
1388
	;; clear CS_SELECT_CTR (so that new message appears immediately)
1389
	clrf	CS_SELECT_CTR
1390
 
1391
	;; now request a display update so that we see the new parameter on screen
1392
	bsf	CS_STAT, CS_STAT_DISPLAY_UPDATE_REQ	; (see cs_menu.inc)
1393
	;; clear counter so that cs_menu_timer.inc counts from zero and the menu entry is marked for a short time
1394
	clrf	CS_CURSOR_CTR
1395
	;; clear "CS_STAT_CURSOR_FLASH" bit (see cs_menu.inc for the handling)
1396
	bcf	CS_STAT, CS_STAT_CURSOR_FLASH
1397
 
1398
	;; leave function if cursor pos >= max entries
1399
	movf	CS_MENU_ENTRIES, W
1400
	cpfslt	CS_MENU_CURSOR_POS, ACCESS
1401
	return
1402
 
1403
	;; branch to EXEC handler
1404
 
1405
	;; get pointer to entry which has been selected
1406
	rcall	CS_MENU_Hlp_GetCursorPosEntry
1407
 
1408
	;; get handler IDs
1409
	rcall	CS_MENU_GetHandlerIDs
1410
 
1411
	;; EXEC ID in MIOS_PARAMETER2
1412
	movf	MIOS_PARAMETER2, W
1413
	goto	CS_MENU_EXEC_Handler
1414
 
1415
;; --------------------------------------------------------------------------
1416
;;  called by cs_menu_buttons.inc when the exec button has been pressed
1417
;; --------------------------------------------------------------------------
1418
CS_MENU_Exec
1419
	;; exit if SID not available
1420
	btfss	CS_STAT, CS_STAT_SID_AVAILABLE
1421
	return
1422
 
1423
	;; clear CS_SELECT_CTR (so that new message appears immediately)
1424
	clrf	CS_SELECT_CTR
1425
 
1426
	;; clear refresh item counter --- ensures that the whole display will be refreshed
1427
	clrf	CS_MENU_REFRESH_ITEM_CTR
1428
 
360 tk 1429
#if DEFAULT_LCD_LINES >= 4
1430
	;; clear meter bar
1431
	movlw	0xff
1432
	call	CS_MENU_UpdateMeterBar
1433
#endif
1434
 
1 tk 1435
	;; exit if we are in main menu
1436
	btfsc	CS_MENU, 7
1437
	return
1438
 
1439
	;; execute function
1440
	;; calc pointer to function: CS_MENU_TABLES + (CS_MENU*CS_MENU_T_ENTRY_LEN) + CS_MENU_ENTRY_EXEC_OFFSET
1441
	movlw	CS_MENU_T_ENTRY_EXEC_OFFSET
1442
	call	CS_MENU_GetMenuTablesPtr
1443
	goto	MIOS_HLP_IndirectJump
1444
 
1445
 
1446
;; --------------------------------------------------------------------------
1447
;;  called by cs_menu_enc.inc and CS_MENU_PageUpDown when the ensemble number should be updated
1448
;;  ensemble number in SID_ENSEMBLE
1449
;; --------------------------------------------------------------------------
1450
CS_MENU_EnsUpdate
1451
	;; init ensemble and exit
1452
	goto	SID_ENS_Init
1453
 
1454
 
1455
;; --------------------------------------------------------------------------
1456
;;  called by cs_menu_enc.inc and CS_MENU_PageUpDown when the patch number should be updated
1457
;;  patch number in CS_MENU_PARAMETER_[LH]
1458
;; --------------------------------------------------------------------------
1459
CS_MENU_PatchUpdate
1460
	;; save current patch if it has been changed
1461
	rcall	CS_MENU_PatchUpdate_SaveOld
1462
 
1463
	;; determine bank of currently selected SID -> SID_BANK
1464
	call	CS_MENU_MS_GetSIDNumber
1465
	call	CS_MENU_MS_GetSIDBank
1466
	movwf	SID_BANK
1467
 
1468
	;; new patch -> SID_PATCH
1469
	movf	CS_MENU_PARAMETER_L, W
1470
	andlw	0x7f
1471
	movwf	SID_PATCH
1472
 
1473
	;; copy patch (and bank) number to all selected SIDs
1474
	clrf	CS_MENU_SID		; using CS_MENU_SID as counter
1475
CS_MENU_PatchUpdate_Loop
1476
	movf	CS_MENU_SID, W
1477
	call	MIOS_HLP_GetBitORMask
1478
	andwf	CS_MENU_SELECTED_SID_FLAGS, W
1479
	bz	CS_MENU_PatchUpdate_Next
1480
	;; copy changed CS_MENU_PARAMETER_L to saved patch number and init sound
1481
	call	CS_MENU_MS_GetSIDPatch; sets FSR1 to patch register
1482
	movff	SID_PATCH, INDF1
1483
	;; copy bank
1484
	call	CS_MENU_MS_GetSIDBank; set FSR1 to bank register
1485
	movff	SID_BANK, INDF1
1486
	;; request update of CS parameters
1487
	call	CS_MENU_MS_Send_SysExDump_TxReq
1488
	;; store new patch and bank number in ensemble
1489
	lfsr	FSR0, SID_ENS_BUFFER + SID_ENSx_PATCH
1490
	movff	SID_PATCH, INDF0
1491
	call	CS_MENU_MS_SendEnsParameter
1492
	lfsr	FSR0, SID_ENS_BUFFER + SID_ENSx_BANK
1493
	movff	SID_BANK, INDF0
1494
	call	CS_MENU_MS_SendEnsParameter
1495
CS_MENU_PatchUpdate_Next
1496
	incf	CS_MENU_SID, F
1497
	BRA_IFCLR CS_MENU_SID, 2, ACCESS, CS_MENU_PatchUpdate_Loop
1498
 
1499
	;; restore CS_MENU_SID
1500
	call	CS_MENU_MS_GetSIDNumber
1501
 
1502
	return
1503
 
1504
;; --------------------------------------------------------------------------
1505
;;  called by cs_menu_enc.inc when a single patch should be updated
1506
;;  patch number in CS_MENU_PARAMETER_[LH]
1507
;;  SID number in CS_MENU_SID
1508
;; --------------------------------------------------------------------------
1509
CS_MENU_PatchUpdateSingle
1510
	;; save current patch if it has been changed
1511
	rcall	CS_MENU_PatchUpdate_SaveOld
1512
 
1513
	;; copy changed CS_MENU_PARAMETER_L to saved patch number and init sound
1514
	call	CS_MENU_MS_GetSIDPatch; sets FSR1 to patch register
1515
	movf	CS_MENU_PARAMETER_L, W
1516
	andlw	0x7f
1517
	movwf	INDF1
1518
	;; request update of CS parameters and exit
1519
	goto	CS_MENU_MS_Send_SysExDump_TxReq
1520
 
1521
 
1522
;; --------------------------------------------------------------------------
1523
;;  this function saves the current patch if it has been changed
1524
;; --------------------------------------------------------------------------
1525
CS_MENU_PatchUpdate_SaveOld
1526
	;; in edit mode: save current patch if it has been changed
1527
	btfss	CS_MENU_MODE, CS_MENU_MODE_EDIT
1528
	return
1529
	;; don't save if nothing has been changed
1530
	btfss	CS_MENU_MODE, CS_MENU_MODE_EDIT_NOTIFIER
1531
	return
1532
	;; clear edit notifier
1533
	bcf	CS_MENU_MODE, CS_MENU_MODE_EDIT_NOTIFIER
1534
	;; save patch to CS_MENU_SAVE_PATCH
1535
	call	CS_MENU_MS_GetSIDNumber
1536
	call	CS_MENU_MS_GetSIDPatch; sets FSR1 to patch register
1537
	movf	INDF1, W
1538
	andlw	0x7f
1539
	movwf	CS_MENU_SAVE_PATCH
1540
	call	CS_MENU_MS_GetSIDBank; sets FSR1 to bank register
1541
	movf	INDF1, W
1542
	movwf	CS_MENU_SAVE_BANK
1543
	rgoto	CS_MENU_SavePatch
1544
 
1545
 
1546
;; --------------------------------------------------------------------------
1547
;;  called by cs_menu_enc.inc when the menu pos should be updated
1548
;;  item in CS_MENU_PARAMETER_L
1549
;; --------------------------------------------------------------------------
1550
CS_MENU_MenuPosUpdate
1551
	;; copy result to cursor pos and request display update
1552
	movf	CS_MENU_PARAMETER_L, W
1553
	andlw	0x3f
1554
	movwf	CS_MENU_CURSOR_POS
1555
 
1556
	;; set page offset directly
1557
	movwf	CS_MENU_PAGE_OFFSET
1558
 
1559
	;; now request a display update so that we see the new parameter on screen
1560
	bsf	CS_STAT, CS_STAT_DISPLAY_UPDATE_REQ
1561
	;; clear counter so that cs_menu_timer.inc counts from zero and the menu item is marked for a short time
1562
	clrf	CS_CURSOR_CTR
1563
	;; clear "CS_STAT_CURSOR_FLASH" bit (see cs_menu.inc for the handling)
1564
	bcf	CS_STAT, CS_STAT_CURSOR_FLASH
1565
	;; thats all
1566
	return
1567
 
1568
;; --------------------------------------------------------------------------
1569
;;  called by cs_menu_enc.inc and cs_menu_exec.inc when a parameter
1570
;;  should be updated
1571
;; --------------------------------------------------------------------------
1572
CS_MENU_ParameterUpdate
1573
	;; prepare pointers to currently selected entry
1574
	rcall	CS_MENU_Hlp_GetCursorPosEntry
1575
 
1576
	;; notify that a value has been changed
1577
	bsf	CS_MENU_MODE, CS_MENU_MODE_EDIT_NOTIFIER
1578
 
1579
	;; call P2R function for all selected SIDs
1580
	clrf	CS_MENU_SID		; using CS_MENU_SID as counter
1581
CS_MENU_ParameterUpdate_Loop
1582
	movf	CS_MENU_SID, W
1583
	call	MIOS_HLP_GetBitORMask
1584
	andwf	CS_MENU_SELECTED_SID_FLAGS, W
1585
	bz	CS_MENU_ParameterUpdate_Next
1586
	;; get handler IDs
1587
	rcall	CS_MENU_GetHandlerIDs_SIDPreSel
1588
	;; R2PP2R ID in MIOS_PARAMETER3
1589
	movf	MIOS_PARAMETER3, W
1590
	call	CS_MENU_P2R_Handler
1591
CS_MENU_ParameterUpdate_Next
1592
	incf	CS_MENU_SID, F
1593
	BRA_IFCLR CS_MENU_SID, 2, ACCESS, CS_MENU_ParameterUpdate_Loop
1594
 
1595
	;; temporary print long label on special menu items which are listed below
1596
	;; get handler IDs
1597
	rcall	CS_MENU_GetHandlerIDs
1598
	;; PRINT ID in MIOS_PARAMETER1
1599
	movf	MIOS_PARAMETER1, W
1600
	xorlw	PRINT_KNB_PAR			; Knob Assignment
1601
	bz	CS_MENU_ParameterUpdateParName
1602
	xorlw	PRINT_WTx_PAR ^ PRINT_KNB_PAR	; WT Assignment
1603
	bz	CS_MENU_ParameterUpdateParName
1604
	xorlw	PRINT_M_D_Vx_ASG ^ PRINT_WTx_PAR; Velocity/Pitchbender Assignment
1605
	bz	CS_MENU_ParameterUpdateParName
1606
	xorlw	PRINT_PAT ^ PRINT_M_D_Vx_ASG	; Patch Name
1607
	bz	CS_MENU_ParameterUpdatePatName
1608
	xorlw	PRINT_BNK ^ PRINT_PAT		; Bank Name
1609
	bz	CS_MENU_ParameterUpdatePatBank
1610
	rgoto	CS_MENU_ParameterUpdateNoBigMsg
1611
 
1612
CS_MENU_ParameterUpdateParName
296 tk 1613
	rcall	CS_MENU_Page_BigMsg_ParName
1 tk 1614
	rgoto	CS_MENU_ParameterUpdateParName_C
1615
CS_MENU_ParameterUpdatePatBank
296 tk 1616
	rcall	CS_MENU_Page_BigMsg_Bank
1617
	rgoto	CS_MENU_ParameterUpdateParName_C
1 tk 1618
CS_MENU_ParameterUpdatePatName
296 tk 1619
	rcall	CS_MENU_Page_BigMsg_Patch
1620
	;; 	rgoto	CS_MENU_ParameterUpdateParName_C
1 tk 1621
CS_MENU_ParameterUpdateParName_C
1622
CS_MENU_ParameterUpdateNoBigMsg
1623
 
360 tk 1624
 
1625
#if DEFAULT_LCD_LINES >= 4
1626
	;; for meter bar at lower line: get scaled value and preload display counter
1627
	call	CS_MENU_GetScaledParam
1628
	call	CS_MENU_UpdateMeterBar
1629
#endif
1630
 
1 tk 1631
	;; now request a display update so that we see the new parameter on screen
1632
	bsf	CS_STAT, CS_STAT_DISPLAY_UPDATE_REQ	; (see tc_display.inc)
1633
	;; set counter to 5*2 so that the cs_menu_timer.inc function prints the value
1634
	movlw	5*2
1635
	movwf	CS_CURSOR_CTR
1636
	;; set the "CS_STAT_CURSOR_FLASH" bit (see cs_menu.inc for the handling)
1637
	bsf	CS_STAT, CS_STAT_CURSOR_FLASH
360 tk 1638
 
1 tk 1639
	;; thats all
1640
	return
1641
 
1642
 
1643
;; --------------------------------------------------------------------------
1644
;;  This help function adds WREG to CS_MENU_ENTRY_TBLPTR[LH] and copies
1645
;;  the result to TBLPTR[LH]
1646
;; --------------------------------------------------------------------------
1647
CS_MENU_Hlp_GetPointer
1648
	addwf	CS_MENU_ENTRY_TBLPTRL, W
1649
	movwf	TBLPTRL
1650
	movlw	0x00
1651
	addwfc	CS_MENU_ENTRY_TBLPTRH, W
1652
	movwf	TBLPTRH
1653
	clrf	TBLPTRU		; TBLPTRU must be 0 (lower 64k page)
1654
	return
1655
 
1656
;; --------------------------------------------------------------------------
1657
;;  This function returns the handler IDs of the selected parameter in the menu
1658
;;  Prepares also MBFM_SELECTED_INS and CS_MENU_PARAMETER_IX depending on
1659
;;  the menu table entry
1660
;;  OUT: ID for CS_MENU_PRINT in MIOS_PARAMETER1
1661
;;       ID for CS_MENU_EXEC in MIOS_PARAMETER2
1662
;;       ID for CS_MENU_R2PP2R in MIOS_PARAMETER3
1663
;; --------------------------------------------------------------------------
1664
CS_MENU_GetHandlerIDs
1665
	;; select instrument
1666
	call	CS_MENU_MS_GetSIDNumber
1667
 
1668
CS_MENU_GetHandlerIDs_SIDPreSel	; used by CS_MENU_ParameterUpdate which can call the function for all selected SIDs
1669
	;; base address of edit buffer -> FSR0
1670
	lfsr	FSR0, SID_EDIT_BUFFER
1671
 
1672
	;; copy offset to register entry (must be the first entry!) to tablepointer
1673
	movff	CS_MENU_ENTRY_TBLPTRL, TBLPTRL
1674
	movff	CS_MENU_ENTRY_TBLPTRH, TBLPTRH
1675
 
1676
	;; get register address, add it to FSR0L and store it also in CS_MENU_PARAMETER_IX
1677
	tblrd*+
1678
	movf	TABLAT, W
1679
	movwf	CS_MENU_PARAMETER_IX
1680
	addwf	FSR0L, F
1681
 
1682
	;; get pointer to PRINT_IX offset
1683
	movlw	CS_MENU_ENTRY_PRINT_IX_OFFSET
1684
	rcall	CS_MENU_Hlp_GetPointer
1685
 
1686
	;; PRINT ID in MIOS_PARAMETER1
1687
	tblrd*+
1688
	movff	TABLAT, MIOS_PARAMETER1
1689
 
1690
	;; EXEC ID in MIOS_PARAMETER2
1691
	tblrd*+
1692
	movff	TABLAT, MIOS_PARAMETER2
1693
 
1694
	;; R2PP2R ID in MIOS_PARAMETER3
1695
	tblrd*+
1696
	movff	TABLAT, MIOS_PARAMETER3
1697
 
1698
	return
1699
 
1700
;; --------------------------------------------------------------------------
1701
;;  returns first visible entry
1702
;; --------------------------------------------------------------------------
1703
CS_MENU_Hlp_GetFirstVisibleEntry
1704
	;; copy pointer to first entry to CS_MENU_ENTRY_TBLPTR[LH]
1705
	movff	CS_MENU_TABLE_0_L, CS_MENU_ENTRY_TBLPTRL
1706
	movff	CS_MENU_TABLE_0_H, CS_MENU_ENTRY_TBLPTRH
1707
 
1708
	;; calc offset to first visible entry:
1709
	movf	CS_MENU_PAGE_OFFSET, W
1710
	mullw	CS_MENU_ENTRY_LEN
1711
	movf	PRODL, W
1712
	addwf	CS_MENU_ENTRY_TBLPTRL, F
1713
	movlw	0x00
1714
	addwfc	CS_MENU_ENTRY_TBLPTRH, F
1715
	return
1716
 
1717
;; --------------------------------------------------------------------------
1718
;;  returns entry, indexed by cursor_pos
1719
;; --------------------------------------------------------------------------
1720
CS_MENU_Hlp_GetCursorPosEntry
1721
	;; copy pointer to first entry to CS_MENU_ENTRY_TBLPTR[LH]
1722
	movff	CS_MENU_TABLE_0_L, CS_MENU_ENTRY_TBLPTRL
1723
	movff	CS_MENU_TABLE_0_H, CS_MENU_ENTRY_TBLPTRH
1724
 
1725
	;; calc offset to cursor pos entry:
1726
	movf	CS_MENU_CURSOR_POS, W
1727
	mullw	CS_MENU_ENTRY_LEN
1728
	movf	PRODL, W
1729
	addwf	CS_MENU_ENTRY_TBLPTRL, F
1730
	movlw	0x00
1731
	addwfc	CS_MENU_ENTRY_TBLPTRH, F
1732
	return
1733
 
1734
;; --------------------------------------------------------------------------
1735
;;  This help function prints n spaces
1736
;;  IN: number of spaces in WREG
1737
;; --------------------------------------------------------------------------
1738
CS_MENU_Hlp_PrintSpaces
1739
	movwf	TMP1		; using TMP1 as loop counter
1740
CS_MENU_Hlp_PrintSpaces_Loop
1741
	movlw	' '
1742
	call	MIOS_LCD_PrintChar
1743
	decfsz	TMP1, F		; decrement TMP1, skip if zero
1744
	rgoto	CS_MENU_Hlp_PrintSpaces_Loop
1745
 
1746
	return
1747
 
1748
;; --------------------------------------------------------------------------
1749
;;  This help function updates the OSC select flags
1750
;; --------------------------------------------------------------------------
1751
CS_MENU_Hlp_UpdateOSCFlags
1752
	movf	CS_MENU_SELECTED_OSC, W
1753
	rcall	CS_MENU_Hlp_UpdateOSCFlags_Val
1754
	movwf	CS_MENU_SELECTED_OSC_FLAGS
1755
	return
1756
CS_MENU_Hlp_UpdateOSCFlags_Val
1757
	JUMPTABLE_2BYTES 7	; 7 entries
1758
	retlw	b'00000001'	; OSC1
1759
	retlw	b'00000010'	; OSC2
1760
	retlw	b'00000100'	; OSC3
1761
	retlw	b'00000011'	; OSC1+OSC2
1762
	retlw	b'00000101'	; OSC1+OSC3
1763
	retlw	b'00000110'	; OSC2+OSC3
1764
	retlw	b'00000111'	; OSC1+OSC2+OSC3
1765
 
1766
 
1767
;; --------------------------------------------------------------------------
1768
;;  if ensemble should be saved
1769
;;  (target ensemble in CS_MENU_SAVE_ENS
1770
;; --------------------------------------------------------------------------
1771
CS_MENU_SaveEns
1772
	call	SID_EBANK_CheckValid
1773
	bnz	CS_MENU_SaveEns_End
1774
 
1775
	;; switch to new ensemble
1776
	movff	CS_MENU_SAVE_ENS, SID_ENSEMBLE
1777
 
1778
	;; loop through all SIDs
1779
	clrf	CS_MENU_SID
1780
CS_MENU_SaveEns_Loop
1781
	;; load setup into ENS buffer
1782
	movf	CS_MENU_SID, W
1783
	bnz	CS_MENU_SaveEns_Loop_S
1784
CS_MENU_SaveEns_Loop_M
1785
	call	SID_ENS_LocalSetupIntoBuffer
1786
	rgoto	CS_MENU_SaveEns_Loop_Cont
1787
CS_MENU_SaveEns_Loop_S
1788
	call	CS_MENU_MBNET_Tx_GetEns
1789
	;; skip if slave not available
1790
	movff	MBNET_NODE_AVAIL, PRODL
1791
	movf	CS_MENU_SID, W
1792
	call	MIOS_HLP_GetBitORMask
1793
	andwf	PRODL, W
1794
	bz	CS_MENU_SaveEns_Loop_Next
1795
CS_MENU_SaveEns_Loop_Cont
1796
	;; store into BankStick
1797
	movf	CS_MENU_SID, W
1798
	call	SID_ENS_StoreSIDSetup
1799
 
1800
CS_MENU_SaveEns_Loop_Next
1801
	incf	CS_MENU_SID, F
1802
	BRA_IFCLR CS_MENU_SID, 2, ACCESS, CS_MENU_SaveEns_Loop
1803
 
1804
	;; store new ensemble number as default ensemble, so that it will be selected again after power-on
1805
	call	SID_ENS_StoreDefaultNum
1806
 
1807
	;; restore SID_ENS_BUFFER
1808
	call	CS_MENU_MS_UpdateEnsBuffer
1809
 
1810
CS_MENU_SaveEns_End
1811
	return
1812
 
1813
 
1814
;; --------------------------------------------------------------------------
1815
;;  if patch should be saved
1816
;;  (target patch in CS_MENU_SAVE_PATCH/CS_MENU_SAVE_BANK)
1817
;; --------------------------------------------------------------------------
1818
CS_MENU_SavePatch
1819
	;; get current CS_MENU_SID
1820
	call	CS_MENU_MS_GetSIDNumber
1821
 
1822
	;; switch patch/bank to CS_MENU_SAVE_PATCH/BANK
1823
	movff	CS_MENU_SAVE_PATCH, SID_PATCH
1824
	movff	CS_MENU_SAVE_BANK, SID_BANK
1825
 
1826
	;; check if target location available
1827
	call	SID_PBANK_CheckPatchValid
1828
	bnz	CS_MENU_SavePatch_End
1829
 
1830
	;; store edit buffer into BankStick (8 * 64byte pages)
1831
	clrf	EEADR
1832
	clrf	EEADRH
1833
CS_MENU_SavePatch_Loop
1834
	clrwdt	; feed watchdog
1835
	lfsr	FSR1, SID_EDIT_BUFFER
1836
	movf	EEADR, W
1837
	addwf	FSR1L, F
1838
	movf	EEADRH, W
1839
	addwfc	FSR1H, F
1840
	call	SID_PBANK_WritePage
1841
	movf	EEADR, W
1842
	bnz	CS_MENU_SavePatch_Loop
1843
	movlw	2-1
1844
	cpfsgt	EEADRH, ACCESS
1845
	rgoto CS_MENU_SavePatch_Loop
1846
 
1847
	;; switch to new patch/bank
1848
	call	CS_MENU_MS_GetSIDPatch	; get pointer to patch number
1849
	movff	SID_PATCH, INDF1
1850
	call	CS_MENU_MS_GetSIDBank	; get pointer to bank number
1851
	movff	SID_BANK, INDF1
1852
 
1853
	;; store new patch also in ensemble
1854
	lfsr	FSR0, SID_ENS_BUFFER + SID_ENSx_PATCH
1855
	movff	SID_PATCH, INDF0
1856
	call	CS_MENU_MS_SendEnsParameter
1857
 
1858
	lfsr	FSR0, SID_ENS_BUFFER + SID_ENSx_BANK
1859
	movff	SID_BANK, INDF0
1860
	call	CS_MENU_MS_SendEnsParameter
1861
 
1862
CS_MENU_SavePatch_End
1863
	return
1864
 
1865
;; --------------------------------------------------------------------------
1866
;;  Updates a CS register on SysEx changes in EDIT mode
1867
;;  IN: Syx number in WREG
1868
;;      value in MIOS_PARAMETER1
1869
;; --------------------------------------------------------------------------
1870
CS_MENU_UpdateSyxPara
1871
#if 0
1872
	btfsc	WREG, 7; exit if value stored in EEPROM
1873
	return
1874
	movwf	TABLAT
1875
 
1876
	;; get SID base
1877
	clrf	CS_MENU_SID
1878
	lfsr	FSR0, SID_EDIT_BUFFER
1879
 
1880
	;; transfer to CS_SID register
1881
	movf	TABLAT, W
1882
	movff	MIOS_PARAMETER1, PLUSW0
1883
#endif
1884
	;; TODO
1885
 
1886
	;; notify that a value has been changed
1887
	bsf	CS_MENU_MODE, CS_MENU_MODE_EDIT_NOTIFIER
1888
 
1889
	;; force an display update
1890
	bsf	CS_STAT, CS_STAT_DISPLAY_UPDATE_REQ
1891
 
1892
	return
1893
 
1894
;; --------------------------------------------------------------------------
1895
;;  This function increments a given parameter which is indexed like shown
1896
;;  here:
1897
;;     ID of CS_MENU in WREG (example: CS_MENU_OSC)
1898
;;     table (cursor) position in MIOS_PARAMETER1 (example: 0x01 for waveform)
1899
;;     page offset in MIOS_PARAMETER2 (example: 0x00 begins at first line)
1900
;;  used by cs_menu_buttons.inc
1901
;; --------------------------------------------------------------------------
1902
CS_MENU_ButtonInc
1903
	;; exit if SID not available
1904
	btfss	CS_STAT, CS_STAT_SID_AVAILABLE
1905
	return
1906
 
1907
	;; save WREG
1908
	movwf	TMP5
1909
	;; save menu settings so that we can jump back to the current menu later
1910
	movff	CS_MENU, SAVED_CS_MENU
1911
	movff	CS_MENU_CURSOR_POS, SAVED_CS_MENU_CURSOR_POS
1912
	movff	CS_MENU_PAGE_OFFSET, SAVED_CS_MENU_PAGE_OFFSET
1913
	;; change to menu
1914
	movwf	CS_MENU
1915
	rcall	CS_MENU_Page_Init
1916
	;; set new page offset and cursor pos
1917
	movff	MIOS_PARAMETER1, CS_MENU_CURSOR_POS
1918
	movff	MIOS_PARAMETER2, CS_MENU_PAGE_OFFSET
1919
	;; select parameter
1920
	call	CS_MENU_EXEC_SelPar
1921
	;; increment the parameter value, if max value reached, reset value
1922
	movf	CS_MENU_PARAMETER_L, W
1923
	cpfsgt	CS_MENU_PARAMETER_MAX_L, ACCESS
1924
	movlw 0xff
1925
	addlw	1
1926
	movwf	CS_MENU_PARAMETER_L
1927
	rcall	CS_MENU_ParameterUpdate		; update parameter
1928
	call	CS_MENU_EXEC_Hlp_ChangeMenu	; deselect parameter
1929
	;; change back to old parameter if we were already in the menu before
1930
	movf	SAVED_CS_MENU, W
1931
	xorwf	TMP5, W
1932
	bnz	CS_MENU_ButtonInc_End
1933
	movff	SAVED_CS_MENU, CS_MENU
1934
	rcall	CS_MENU_Page_Init
1935
	movff	SAVED_CS_MENU_PAGE_OFFSET, CS_MENU_PAGE_OFFSET
1936
	movff	SAVED_CS_MENU_CURSOR_POS, CS_MENU_CURSOR_POS
1937
CS_MENU_ButtonInc_End
1938
	;; force a display update and exit
1939
	bsf	CS_STAT, CS_STAT_DISPLAY_UPDATE_REQ
1940
 
1941
	return
1942
 
1943
;; --------------------------------------------------------------------------
1944
;;  This function toggles a given parameter which is indexed like shown
1945
;;  here:
1946
;;     ID of CS_MENU in WREG (example: CS_MENU_OSC)
1947
;;     table (cursor) position in MIOS_PARAMETER1 (example: 0x01 for waveform)
1948
;;     page offset in MIOS_PARAMETER2 (example: 0x00 begins at first line)
1949
;;  used by cs_menu_buttons.inc
1950
;; --------------------------------------------------------------------------
1951
CS_MENU_ButtonToggle
1952
	;; exit if SID not available
1953
	btfss	CS_STAT, CS_STAT_SID_AVAILABLE
1954
	return
1955
 
1956
	;; save WREG
1957
	movwf	TMP5
1958
	;; save menu settings so that we can jump back to the current menu later
1959
	movff	CS_MENU, SAVED_CS_MENU
1960
	movff	CS_MENU_CURSOR_POS, SAVED_CS_MENU_CURSOR_POS
1961
	movff	CS_MENU_PAGE_OFFSET, SAVED_CS_MENU_PAGE_OFFSET
1962
	;; change to menu
1963
	movwf	CS_MENU
1964
	rcall	CS_MENU_Page_Init
1965
	;; set new page offset and cursor pos
1966
	movff	MIOS_PARAMETER1, CS_MENU_CURSOR_POS
1967
	movff	MIOS_PARAMETER2, CS_MENU_PAGE_OFFSET
1968
	;; select parameter
1969
	call	CS_MENU_EXEC_SelPar
1970
	;; toggle the parameter value
1971
	btg	CS_MENU_PARAMETER_L, 0
1972
	rcall	CS_MENU_ParameterUpdate		; update parameter
1973
	call	CS_MENU_EXEC_Hlp_ChangeMenu	; deselect parameter
1974
 
1975
	;; change back to old menu and cursor pos
1976
	movff	SAVED_CS_MENU, CS_MENU
1977
	rcall	CS_MENU_Page_Init
1978
	movff	SAVED_CS_MENU_PAGE_OFFSET, CS_MENU_PAGE_OFFSET
1979
	movff	SAVED_CS_MENU_CURSOR_POS, CS_MENU_CURSOR_POS
1980
 
1981
	;; force a display update and exit
1982
	bsf	CS_STAT, CS_STAT_DISPLAY_UPDATE_REQ
1983
 
1984
	return
1985
 
1986
 
1987
;; --------------------------------------------------------------------------
1988
;;  This function increments a given parameter which is indexed like shown
1989
;;  here:
1990
;;     ID of CS_MENU in WREG (example: CS_MENU_OSC)
1991
;;     table (cursor) position in MIOS_PARAMETER1 (example: 0x01 for waveform)
1992
;;     page offset in MIOS_PARAMETER2 (example: 0x00 begins at first line)
1993
;;     increment value in MIOS_PARAMETER3
1994
;;     used encoder in CS_MENU_USED_ENCODER (for new speed setting)
1995
;;  used by cs_menu_enc.inc
1996
;; --------------------------------------------------------------------------
1997
CS_MENU_ENC_CSInc
1998
	;; exit if SID not available
1999
	btfss	CS_STAT, CS_STAT_SID_AVAILABLE
2000
	return
2001
 
2002
	;; save incrementer in TMP5
2003
	movff	MIOS_PARAMETER3, TMP5
2004
 
2005
	;; change to menu
2006
	movwf	CS_MENU
2007
	rcall	CS_MENU_Page_Init
2008
 
2009
	;; set new page offset and cursor pos
2010
	movff	MIOS_PARAMETER1, CS_MENU_CURSOR_POS
2011
	movff	MIOS_PARAMETER2, CS_MENU_PAGE_OFFSET
2012
 
2013
	;; select parameter
2014
	call	CS_MENU_EXEC_SelPar
2015
 
2016
	;; inc/dec value by using the 16 bit add w/ saturation routine
2017
	;; set pointer to CS_MENU_PARAMETER_L (is located to an even address, thats important when this function is used!)
2018
	lfsr	FSR1, CS_MENU_PARAMETER_L
2019
	;; set max value
2020
	movff	CS_MENU_PARAMETER_MAX_L, MIOS_PARAMETER1	; low-byte of max value
2021
	movff	CS_MENU_PARAMETER_MAX_H, MIOS_PARAMETER2	; high-byte of max value
2022
	;; get incrementer (which has been stored in TMP5)
2023
	movf	TMP5, W
2024
	;; call routine
2025
	call	MIOS_HLP_16bitAddSaturate
2026
	;; now [FSR1] = INDF1 = CS_MENU_PARAMETER_[LH] contains the result
2027
	;; MIOS_PARAMETER1[0] is set when value has been changed
2028
	RCALL_IFSET MIOS_PARAMETER1, 0, ACCESS, CS_MENU_ParameterUpdate		; update parameter
2029
 
2030
	;; update encoder speed according to new max setting
2031
	;; will overwrite MIOS_PARAMETER[123] !!!
2032
	movf	CS_MENU_USED_ENCODER, W
2033
	rcall	CS_MENU_EncSpeedSet
2034
 
2035
	;; deselect parameter
2036
	call	CS_MENU_EXEC_Hlp_Deselect
2037
 
2038
	;; force a display update and exit
2039
	bsf	CS_STAT, CS_STAT_DISPLAY_UPDATE_REQ
2040
 
2041
	return
2042
 
2043
 
2044
;; --------------------------------------------------------------------------
2045
;;  This function increments/decrements the OSC/LFO/ENV/MOD/TRG/KNB/Patch value
2046
;;  depending on the menu context
2047
;;  Note: if the _NoWrap variation is called, the number won't be wrapped
2048
;;  IN: incrementer (1 or -1) in WREG
2049
;; --------------------------------------------------------------------------
2050
CS_MENU_PageUpDown_NoWrap
2051
	bcf	MIOS_PARAMETER1, 0	; store wrap flag in MIOS_PARAMETER1.0
2052
	rgoto	CS_MENU_PageUpDown_NoWrap_Cont
2053
 
2054
CS_MENU_PageUpDown
2055
	bsf	MIOS_PARAMETER1, 0	; store wrap flag in MIOS_PARAMETER1.0
2056
 
2057
CS_MENU_PageUpDown_NoWrap_Cont
2058
	;; store incrementer in TMP1
2059
	;; ensure that it is either 1 or -1
2060
	clrf	TMP1
2061
	incf	TMP1, F
2062
	btfsc	WREG, 7
2063
	setf TMP1
2064
 
2065
	;; increment patch/ensemble if in main menu
2066
	BRA_IFCLR CS_MENU, 7, ACCESS, CS_MENU_PageUpDown_NotMain
2067
CS_MENU_PageUpDown_Main
2068
	movlw	SID_PATCH
2069
	btfsc	CS_MENU_MODE, CS_MENU_MODE_MENU_PRESSED
2070
	movlw SID_ENSEMBLE
2071
	rgoto	CS_MENU_PageUpDown_Main_Cont
2072
CS_MENU_PageUpDown_NotMain
2073
	;; get variable which should be modified - if 0, do nothing
2074
	movlw	CS_MENU_T_ENTRY_NUMVAR_OFFSET
2075
	call	CS_MENU_GetMenuTablesPtr
2076
	tblrd*+
2077
	movf	TABLAT, W
2078
	skpnz
2079
	rgoto	CS_MENU_PageUpDown_Inv
2080
CS_MENU_PageUpDown_Main_Cont
2081
	movwf	FSR0L		; store pointer to variable in FSR0
2082
	clrf	FSR0H
2083
 
2084
	;; if variable is SID_PATCH, get current patch number and store it into SID_PATCH
2085
	xorlw	SID_PATCH
2086
	bnz	CS_MENU_PageUpDown_DontGetPatch
2087
CS_MENU_PageUpDown_GetPatch
2088
	call	CS_MENU_MS_GetSIDPatch
2089
	movwf	SID_PATCH
2090
CS_MENU_PageUpDown_DontGetPatch
2091
 
2092
	;; get max value -> TMP2
2093
	tblrd*+
2094
	movf	TABLAT, W
2095
	btfsc	CS_MENU, 7; (patch/ensemble)
2096
	movlw 0x7f
2097
	movwf	TMP2
2098
 
2099
	;; wrap variable if allowed, otherwise saturate at boundaries
2100
	BRA_IFSET MIOS_PARAMETER1, 0, ACCESS, CS_MENU_PageUpDown_Wrap
2101
CS_MENU_PageUpDown_Sat
2102
	movf	TMP1, W
2103
	addwf	INDF0, F
2104
	BRA_IFSET TMP1, 7, ACCESS, CS_MENU_PageUpDown_SatDown
2105
CS_MENU_PageUpDown_SatUp
2106
	movf	TMP2, W
2107
	cpfslt	INDF0, ACCESS
2108
	movwf INDF0
2109
	rgoto	CS_MENU_PageUpDown_SatCont
2110
CS_MENU_PageUpDown_SatDown
2111
	movf	TMP2, W
2112
	btfsc	INDF0, 7
2113
	clrf INDF0
2114
	rgoto	CS_MENU_PageUpDown_SatCont
2115
 
2116
 
2117
CS_MENU_PageUpDown_Wrap
2118
	movf	TMP1, W
2119
	addwf	INDF0, F
2120
	BRA_IFSET TMP1, 7, ACCESS, CS_MENU_PageUpDown_WrapDown
2121
CS_MENU_PageUpDown_WrapUp
2122
	movf	TMP2, W
2123
	addlw	1
2124
	cpfslt	INDF0, ACCESS
2125
	clrf INDF0
2126
	rgoto CS_MENU_PageUpDown_WrapCont
2127
CS_MENU_PageUpDown_WrapDown
2128
	movf	TMP2, W
2129
	btfsc	INDF0, 7
2130
	movwf INDF0
2131
	;; 	rgoto CS_MENU_PageUpDown_WrapCont
2132
CS_MENU_PageUpDown_WrapCont
2133
CS_MENU_PageUpDown_SatCont
2134
 
2135
	;; if PRINT_VAR_123: call the OSC flags update function and set FSR0 to CS_MENU_SELECTED_OSC_FLAGS
2136
	;; if PRINT_LR: if zero, increment by one, so that only L, R or LR selectable
2137
	BRA_IFSET CS_MENU, 7, ACCESS, CS_MENU_PageUpDown_NoSpecialFunc
2138
	movlw	CS_MENU_T_ENTRY_PRINT_IX_OFFSET
2139
	call	CS_MENU_GetMenuTablesPtr
2140
	tblrd*+
2141
	movf	TABLAT, W
2142
	xorlw	PRINT_VAR_123
2143
	bz	CS_MENU_PageUpDown_OSC
2144
	xorlw	PRINT_VAR_LR ^ PRINT_VAR_123
2145
	bz	CS_MENU_PageUpDown_LR
2146
	rgoto	CS_MENU_PageUpDown_SF_Cont
2147
CS_MENU_PageUpDown_OSC
2148
	call	CS_MENU_Hlp_UpdateOSCFlags
2149
	lfsr	FSR0, CS_MENU_SELECTED_OSC_FLAGS	; (for correct PRINT_VAR_123)
2150
	rgoto	CS_MENU_PageUpDown_SF_Cont
2151
 
2152
CS_MENU_PageUpDown_LR
2153
	BRA_IFSET TMP1, 7, ACCESS, CS_MENU_PageUpDown_LR_Down
2154
CS_MENU_PageUpDown_LR_Up
2155
	movf	INDF0, W
2156
	skpnz
2157
	incf	INDF0, F
2158
 	rgoto	CS_MENU_PageUpDown_SF_Cont
2159
 
2160
CS_MENU_PageUpDown_LR_Down
2161
	movf	INDF0, W
2162
	skpnz
2163
	decf	INDF0, W
2164
	andlw	0x03
2165
	movwf	INDF0
2166
	;; 	rgoto	CS_MENU_PageUpDown_SF_Cont
2167
 
2168
CS_MENU_PageUpDown_SF_Cont
2169
CS_MENU_PageUpDown_NoSpecialFunc
2170
 
2171
#if CS_MENU_DISPLAYED_ITEMS >= 5
2172
	;; don't print message if in editor mode (track is displayed at right side)
2173
	;; will only work if LCD display size >= 20
2174
	BRA_IFSET CS_STAT3, CS_STAT3_MODIFY_SEQ, ACCESS, CS_MENU_PageUpDown_End_NoMsg
2175
#endif
2176
 
2177
	;; special handling for patch/ensemble (only used in menu page, no special display mode required)
2178
	movf	FSR0L, W
2179
	xorlw	SID_PATCH
2180
	bz	CS_MENU_PageUpDown_Patch
2181
	xorlw	SID_ENSEMBLE ^ SID_PATCH
2182
	bz	CS_MENU_PageUpDown_Ens
2183
	rgoto	CS_MENU_PageUpDown_NoPatchOrEns
2184
CS_MENU_PageUpDown_Patch
2185
	;; select new patch
2186
	movff	SID_PATCH, CS_MENU_PARAMETER_L
2187
	rcall	CS_MENU_PatchUpdate
2188
	rgoto	CS_MENU_PageUpDown_End_NoMsg
2189
CS_MENU_PageUpDown_Ens
2190
	;; select new ensemble (ensemble number already in SID_ENSEMBLE)
2191
	rcall	CS_MENU_EnsUpdate
2192
	rgoto	CS_MENU_PageUpDown_End_NoMsg
2193
CS_MENU_PageUpDown_NoPatchOrEns
2194
 
360 tk 2195
	;; printing the new element value is not required on displays with >= 3 lines, since it is print at the upper line anyhow
2196
;#if DEFAULT_LCD_LINES <= 2
2197
; TODO: will be disabled once CS_MENU_Handler_MenuLabel has been enhanced
2198
#if 1
1 tk 2199
	;; set cursor
2200
	movlw	0x00
2201
	call	MIOS_LCD_CursorSet
2202
 
2203
	;; print new variable content
2204
	movlw	'['
2205
	call	MIOS_LCD_PrintChar
2206
	movlw	CS_MENU_T_ENTRY_PGNAME_OFFSET
2207
	call	CS_MENU_GetMenuTablesPtr
2208
	movlw	3
2209
	call	MIOS_LCD_PrintPreconfString
2210
 
2211
	movlw	CS_MENU_T_ENTRY_PRINT_IX_OFFSET
2212
	call	CS_MENU_GetMenuTablesPtr
2213
	tblrd*+
2214
	movf	TABLAT, W
2215
	xorlw	PRINT_VAR_DECP1
2216
	bnz	CS_MENU_PageUpDown_NotDecP1
2217
CS_MENU_PageUpDown_DecP1
2218
	;; special measure for DECP1 - print number without spaces
2219
 
2220
	;; branch if value >= 10
2221
	movlw	8
2222
	cpfsgt	INDF0, ACCESS
2223
	rgoto CS_MENU_PageUpDown_DecP1_LT9
2224
CS_MENU_PageUpDown_DecP1_GE9
2225
	incf	INDF0, W
2226
	call	MIOS_LCD_PrintBCD2
2227
	rgoto	CS_MENU_PageUpDown_DecP1_Cont
2228
CS_MENU_PageUpDown_DecP1_LT9
2229
	incf	INDF0, W
2230
	call	MIOS_LCD_PrintBCD1
2231
	rgoto	CS_MENU_PageUpDown_DecP1_Cont
2232
CS_MENU_PageUpDown_NotDecP1
2233
	movlw	' '
2234
	call	MIOS_LCD_PrintChar
2235
	movf	TABLAT, W
2236
	call	CS_MENU_PRINT_Handler
2237
CS_MENU_PageUpDown_DecP1_Cont
2238
 
2239
	movlw	']'
2240
	call	MIOS_LCD_PrintChar
2241
	movlw	' '
2242
	call	MIOS_LCD_PrintChar
2243
 
360 tk 2244
#if DEFAULT_LCD_PRINT_CURSOR
1 tk 2245
	;; if CLCD: disable blinking CLCD cursor
2246
	movlw	0x0c
2247
	CALL_IFCLR MIOS_BOX_CFG0, MIOS_BOX_CFG0_USE_GLCD, ACCESS, MIOS_LCD_Cmd
360 tk 2248
#endif
1 tk 2249
	rgoto	CS_MENU_PageUpDown_End
360 tk 2250
#else
2251
	;; update the label at upper line
2252
	rcall	CS_MENU_UpdateLabel
2253
	rgoto	CS_MENU_PageUpDown_End_NoMsg
2254
#endif
1 tk 2255
 
2256
 
360 tk 2257
 
1 tk 2258
CS_MENU_PageUpDown_Inv_STR STRING 12, 0x00, "[Not here!] "
2259
CS_MENU_PageUpDown_Inv
2260
	TABLE_ADDR CS_MENU_PageUpDown_Inv_STR
2261
	call	MIOS_LCD_PrintString
2262
	;; 	rgoto	CS_MENU_PageUpDown_End
2263
 
2264
CS_MENU_PageUpDown_End
2265
	;; enable temporary page message (LCD won't be updated until next DISPLAY_INIT_REQ
2266
	bsf	CS_STAT, CS_STAT_PAGE_MSG
2267
 
2268
CS_MENU_PageUpDown_End_NoMsg
2269
	;; request display update (will only update LEDs, the rest is blocked by the CS_STAT_PAGE_MSG flag)
2270
	bsf	CS_STAT, CS_STAT_DISPLAY_UPDATE_REQ
2271
 
2272
	;; if parameter was selected before: select it again for proper CS_MENU_PARAMETER_* initialisation
2273
	btfss	CS_STAT, CS_STAT_MODIFY_PARAMETER
2274
	return
2275
	goto	CS_MENU_EXEC_SelPar
2276
 
2277
 
2278
;; --------------------------------------------------------------------------
2279
;;  This function returns the CS_MENU_x_xxx ID depending on selected engine
2280
;; --------------------------------------------------------------------------
2281
CS_MENU_GetMenuID_OSC
2282
	movlw	0*4
2283
	rgoto	CS_MENU_GetMenuID_Cont
2284
CS_MENU_GetMenuID_FIL
2285
	movlw	1*4
2286
	rgoto	CS_MENU_GetMenuID_Cont
2287
CS_MENU_GetMenuID_LFO
2288
	movlw	2*4
2289
	rgoto	CS_MENU_GetMenuID_Cont
2290
CS_MENU_GetMenuID_ENV
2291
	movlw	3*4
2292
	rgoto	CS_MENU_GetMenuID_Cont
2293
CS_MENU_GetMenuID_MOD
2294
	movlw	4*4
2295
	rgoto	CS_MENU_GetMenuID_Cont
2296
CS_MENU_GetMenuID_KNB
2297
	movlw	5*4
2298
	rgoto	CS_MENU_GetMenuID_Cont
2299
CS_MENU_GetMenuID_SAV
2300
	movlw	6*4
2301
	;; 	rgoto	CS_MENU_GetMenuID_Cont
2302
 
2303
CS_MENU_GetMenuID_Cont
2304
	movwf	PRODL
2305
	movff	SID_EDIT_BUFFER + SID_Ix_ENGINE, WREG
2306
	andlw	0x03
2307
	addwf	PRODL, W
2308
	addlw	LOW(CS_MENU_TABLES_IDS)
2309
	movwf	TBLPTRL
2310
	clrf	TBLPTRH
2311
	movlw	HIGH(CS_MENU_TABLES_IDS)
2312
	addwfc	TBLPTRH, F
2313
	clrf	TBLPTRU
2314
	movlw	UPPER(CS_MENU_TABLES_IDS)
2315
	addwfc	TBLPTRU, F
2316
	tblrd*+
2317
	movf	TABLAT, W
2318
	return
2319
 
2320
;; --------------------------------------------------------------------------
2321
;;  This function returns the pointer to a CS_MENU_TABLES_x entry
2322
;;  depending on selected engine
2323
;;  IN: table offset in WREG
2324
;;      menu page in CS_MENU
2325
;;  USES: PROD[LH] and FSR1L (!!!)
2326
;; --------------------------------------------------------------------------
2327
CS_MENU_GetMenuTablesPtr
2328
	movwf	FSR1L		; temporary store offset in FSR1L
2329
	;; FSR1L is a very bad choice (unexpected temporary register) --- try to find a better one!
2330
 
2331
	;; get pointer to CS_MENU_TABLES_x depending on selected engine
2332
	movff	SID_EDIT_BUFFER + SID_Ix_ENGINE, WREG
2333
	andlw	0x03
2334
	btfsc	CS_MENU, 6; extra: select ensemble menu structure if flag 6 is set)
2335
	movlw 0x04
2336
	TABLE_ADDR_MUL_W CS_MENU_TABLES_ENGINE, 2
2337
 
2338
	;; get address from table (we have a nice MIOS help function for this)
2339
	call	MIOS_HLP_AddressFromTable
2340
	clrf	TBLPTRU		; TBLPTRU must be 0 (lower 64k page)
2341
 
2342
	;; select page entry
2343
	movf	CS_MENU, W
2344
	andlw	0x3f
2345
	mullw	CS_MENU_T_ENTRY_LEN
2346
	movf	PRODL, W
2347
	addwf	FSR1L, W	; add offset
2348
	addwf	TBLPTRL, F
2349
	movf	PRODH, W
2350
	addwfc	TBLPTRH, F
2351
	return
2352
 
2353
 
2354
;; --------------------------------------------------------------------------
2355
;;  special functions of name editing mode
2356
;;  IN: function which should be executed in WREG (CS_MENU_PAGE_OFFSET has to be substracted!)
2357
;; --------------------------------------------------------------------------
2358
CS_MENU_Select_NameFunc
2359
	;; exit if SID not available
2360
	btfss	CS_STAT, CS_STAT_SID_AVAILABLE
2361
	return
2362
 
2363
	movwf	TMP1		; temporary save function in TMP1
2364
	movf	CS_MENU_PAGE_OFFSET, W
2365
	subwf	TMP1, F
2366
 
2367
	;; clear CS_SELECT_CTR (so that new message appears immediately)
2368
	clrf	CS_SELECT_CTR
2369
	;; now request a display update so that we see the new parameter on screen
2370
	bsf	CS_STAT, CS_STAT_DISPLAY_UPDATE_REQ	; (see cs_menu.inc)
2371
	;; clear counter so that cs_menu_timer.inc counts from zero and the menu entry is marked for a short time
2372
	clrf	CS_CURSOR_CTR
2373
	;; clear "CS_STAT_CURSOR_FLASH" bit (see cs_menu.inc for the handling)
2374
	bcf	CS_STAT, CS_STAT_CURSOR_FLASH
2375
	;; get SID number
2376
	call	CS_MENU_MS_GetSIDNumber
2377
 
2378
	;; branch depending on (new) cursor pos, set by the select button
2379
	movf	TMP1, W
2380
	JUMPTABLE_2BYTES 6	; 6 entries
2381
	rgoto	CS_MENU_Select_NameFunc_Save
2382
	rgoto	CS_MENU_Select_NameFunc_Dec
2383
	rgoto	CS_MENU_Select_NameFunc_Inc
2384
	rgoto	CS_MENU_Select_NameFunc_Del
2385
	rgoto	CS_MENU_Select_NameFunc_Clr
2386
 	rgoto	CS_MENU_Select_NameFunc_Ins	; (function if 6th button - if available)
2387
 
2388
CS_MENU_Select_NameFunc_Save
2389
	;; exit page and store patch
2390
	call	CS_MENU_EXEC_Hlp_Deselect
2391
	goto	CS_MENU_EXEC_SavePatch_Final
2392
 
2393
CS_MENU_Select_NameFunc_Dec	; decrement name pos
2394
	decf	CS_MENU_NAME_POS, W
2395
	andlw	0x0f
2396
	movwf	CS_MENU_NAME_POS
2397
 	rgoto	CS_MENU_Select_NameFunc_End
2398
 
2399
CS_MENU_Select_NameFunc_Inc	; increment name pos (16 positions max)
2400
	incf	CS_MENU_NAME_POS, W
2401
	andlw	0x0f
2402
	movwf	CS_MENU_NAME_POS
2403
 	rgoto	CS_MENU_Select_NameFunc_End
2404
 
2405
CS_MENU_Select_NameFunc_Del	; delete character
2406
	lfsr	FSR0, SID_EDIT_BUFFER
2407
	movlw	SID_Ix_NAME_x
2408
	addwf	FSR0L, F
2409
 
2410
	movf	CS_MENU_NAME_POS, W
2411
	movwf	TMP1
2412
	movlw	0x0f
2413
	cpfslt	TMP1, ACCESS
2414
	rgoto CS_MENU_Select_NameFunc_Del_End
2415
	;; shift left name from current cursor position
2416
CS_MENU_Select_NameFunc_Del_Loop
2417
	incf	TMP1, W
2418
	movff	PLUSW0, TMP2
2419
	movf	TMP1, W
2420
	movff	TMP2, PLUSW0
2421
	incf	TMP1, F
2422
	movlw	0x0e
2423
	cpfsgt	TMP1, ACCESS
2424
	rgoto CS_MENU_Select_NameFunc_Del_Loop
2425
 
2426
CS_MENU_Select_NameFunc_Del_End
2427
	movlw	0x0f		; set last character to 0x00
2428
	clrf	PLUSW0
2429
 	rgoto	CS_MENU_Select_NameFunc_End
2430
 
2431
CS_MENU_Select_NameFunc_Ins	; insert space
2432
	lfsr	FSR0, SID_EDIT_BUFFER
2433
	movlw	SID_Ix_NAME_x
2434
	addwf	FSR0L, F
2435
 
2436
	movlw	0x0e
2437
	movwf	TMP1
2438
	;; shift right name from current cursor position
2439
CS_MENU_Select_NameFunc_Ins_Loop
2440
	movf	TMP1, W
2441
	movff	PLUSW0, TMP2
2442
	incf	TMP1, W
2443
	movff	TMP2, PLUSW0
2444
	decf	TMP1, F
2445
	incf	TMP1, W
2446
	bz	CS_MENU_Select_NameFunc_Ins_End
2447
	movf	CS_MENU_NAME_POS, W
2448
	cpfslt	TMP1, ACCESS
2449
	rgoto CS_MENU_Select_NameFunc_Ins_Loop
2450
 
2451
CS_MENU_Select_NameFunc_Ins_End
2452
	movf	CS_MENU_NAME_POS, W; set current character to 0x20 (space)
2453
	clrf	PLUSW0
2454
	bsf	PLUSW0, 5
2455
 	rgoto	CS_MENU_Select_NameFunc_End
2456
 
2457
CS_MENU_Select_NameFunc_Clr	; clear name
2458
	;; print patch name
2459
	lfsr	FSR0, SID_EDIT_BUFFER
2460
	movlw	SID_Ix_NAME_x
2461
	addwf	FSR0L, F
2462
	clrf	TMP1			; TMP1 used as loop counter
2463
CS_MENU_Select_NameFunc_Clr_Loop
2464
	clrf	POSTINC0
2465
	incf	TMP1, F
2466
	BRA_IFCLR TMP1, 4, ACCESS, CS_MENU_Select_NameFunc_Clr_Loop; loop 16 times
2467
	;; 	rgoto	CS_MENU_Select_NameFunc_End
2468
 
2469
CS_MENU_Select_NameFunc_End
2470
	;; execute R2P function and exit
2471
	;; get handler IDs
2472
	rcall	CS_MENU_GetHandlerIDs
2473
	;; R2PP2R ID in MIOS_PARAMETER3
2474
	movf	MIOS_PARAMETER3, W
2475
	rgoto	CS_MENU_R2P_Handler
2476
 
2477
;; --------------------------------------------------------------------------
2478
;;  special functions of sequence editing mode
2479
;;  IN: function which should be executed in WREG (CS_MENU_PAGE_OFFSET has to be substracted!)
2480
;; --------------------------------------------------------------------------
2481
CS_MENU_Select_SeqFunc
2482
	movwf	TMP1		; temporary save function in TMP1
2483
	movf	CS_MENU_PAGE_OFFSET, W
2484
	subwf	TMP1, F
2485
 
2486
	;; clear CS_SELECT_CTR (so that new message appears immediately)
2487
	clrf	CS_SELECT_CTR
2488
	;; now request a display update so that we see the new parameter on screen
2489
	bsf	CS_STAT, CS_STAT_DISPLAY_UPDATE_REQ	; (see cs_menu.inc)
2490
	;; clear counter so that cs_menu_timer.inc counts from zero and the menu entry is marked for a short time
2491
	clrf	CS_CURSOR_CTR
2492
	;; clear "CS_STAT_CURSOR_FLASH" bit (see cs_menu.inc for the handling)
2493
	bcf	CS_STAT, CS_STAT_CURSOR_FLASH
2494
	;; get SID number
2495
	call	CS_MENU_MS_GetSIDNumber
2496
 
2497
	;; branch depending on (new) cursor pos, set by the select button
2498
	movf	TMP1, W
2499
	JUMPTABLE_2BYTES 5	; 5 entries
2500
	rgoto	CS_MENU_Select_SeqFunc_GAS
2501
	rgoto	CS_MENU_Select_SeqFunc_Rot
2502
	rgoto	CS_MENU_Select_SeqFunc_Rnd
2503
	rgoto	CS_MENU_Select_SeqFunc_Clr
2504
	rgoto	CS_MENU_Select_SeqFunc_DRM
2505
 
2506
CS_MENU_Select_SeqFunc_GAS
2507
	;; toggle between four states (No Note, Gate, Accent, Secondary)
2508
	call	CS_MENU_FSR0_WTPos
2509
	movlw	2
2510
	btfsc	CS_MENU_NAME_POS, 3
2511
	addwf	FSR0L, F
2512
 
2513
	movf	CS_MENU_NAME_POS, W
2514
	call	MIOS_HLP_GetBitORMask
2515
	movwf	TMP1		; bit mask for step
2516
 
2517
	;; coding:
2518
	;; Gate  Accent  Result
2519
	;;    0       0  Don't play note
2520
	;;    1       0  Play Note w/o accent
2521
	;;    0       1  Play Note w/ accent
2522
	;;    1       1  Play Secondary Note
2523
	clrf	TMP2		; using TMP2 as temporary accumulator
2524
	movf	POSTINC0, W	; extract G/A from track structure
2525
	andwf	TMP1, W
2526
	skpz
2527
	bsf	TMP2, 0
2528
	movf	POSTDEC0, W
2529
	andwf	TMP1, W
2530
	skpz
2531
	bsf	TMP2, 1
2532
 
2533
	incf	TMP2, W			; increment G/A
2534
	andlw	0x03
2535
	movwf	TMP2
2536
 
2537
 
2538
	comf	TMP1, W			; copy back to track structure
2539
	andwf	INDF0, F
2540
	BRA_IFCLR TMP2, 0, ACCESS, CS_MENU_Select_SeqFunc_GAS_NoG
2541
CS_MENU_Select_SeqFunc_GAS_G
2542
	movf	TMP1, W
2543
	iorwf	INDF0, F
2544
CS_MENU_Select_SeqFunc_GAS_NoG
2545
	movf	INDF0, W
2546
 	rcall	CS_MENU_Select_SeqFunc_Hlp_Send	; (increments FSR0)
2547
 
2548
	comf	TMP1, W
2549
	andwf	INDF0, F
2550
	BRA_IFCLR TMP2, 1, ACCESS, CS_MENU_Select_SeqFunc_GAS_NoA
2551
CS_MENU_Select_SeqFunc_GAS_A
2552
	movf	TMP1, W
2553
	iorwf	INDF0, F
2554
CS_MENU_Select_SeqFunc_GAS_NoA
2555
	movf	INDF0, W
2556
	rcall	CS_MENU_Select_SeqFunc_Hlp_Send	; (increments FSR0)
2557
 
2558
	rgoto	CS_MENU_Select_SeqFunc_End
2559
 
2560
 
2561
CS_MENU_Select_SeqFunc_Rot	; activate/deactivate rotate function
2562
	btg	CS_STAT3, CS_STAT3_MODIFY_SEQ_ROTATE
2563
	;; always reset cursor position for defined behaviour of rotary encoder
2564
	clrf	CS_MENU_NAME_POS
2565
	clrf	CS_MENU_PARAMETER_L
2566
 	rgoto	CS_MENU_Select_SeqFunc_End
2567
 
2568
CS_MENU_Select_SeqFunc_Rnd	; random sequence
2569
	call	CS_MENU_FSR0_WTPos
2570
 
2571
	;; gate flags
2572
	call	SID_RND_GenRandomNumber
2573
	movff	SID_RANDOM_SEED_L, WREG
2574
	rcall	CS_MENU_Select_SeqFunc_Hlp_Send	; (increments FSR0)
2575
	movff	SID_RANDOM_SEED_H, WREG
2576
	rcall	CS_MENU_Select_SeqFunc_Hlp_Send	; (increments FSR0)
2577
 
2578
	;; accent flags
2579
	call	SID_RND_GenRandomNumber
2580
	movff	SID_RANDOM_SEED_L, WREG
2581
	rcall	CS_MENU_Select_SeqFunc_Hlp_Send	; (increments FSR0)
2582
	movff	SID_RANDOM_SEED_H, WREG
2583
	rcall	CS_MENU_Select_SeqFunc_Hlp_Send	; (increments FSR0)
2584
 
2585
 	rgoto	CS_MENU_Select_SeqFunc_End
2586
 
2587
CS_MENU_Select_SeqFunc_Clr	; clear sequence
2588
	call	CS_MENU_FSR0_WTPos
2589
	movlw	0x00
2590
	rcall	CS_MENU_Select_SeqFunc_Hlp_Send	; (increments FSR0)
2591
	movlw	0x00
2592
	rcall	CS_MENU_Select_SeqFunc_Hlp_Send	; (increments FSR0)
2593
	movlw	0x00
2594
	rcall	CS_MENU_Select_SeqFunc_Hlp_Send	; (increments FSR0)
2595
	movlw	0x00
2596
	rcall	CS_MENU_Select_SeqFunc_Hlp_Send	; (increments FSR0)
2597
 	rgoto	CS_MENU_Select_SeqFunc_End
2598
 
2599
CS_MENU_Select_SeqFunc_DRM	; branch to drum page
2600
	;; disable track editor
2601
	bcf	CS_STAT3, CS_STAT3_MODIFY_SEQ
2602
	;; select drum instrument depending on current track
2603
	clrc
2604
	rlf	CS_MENU_SELECTED_TRK, W
2605
	movwf	CS_MENU_SELECTED_INS
2606
	;; go to DRM page
2607
	movlw	CS_MENU_D_DRM
2608
	goto	CS_MENU_BUTTON_Hlp_MenuChange
2609
 
2610
CS_MENU_Select_SeqFunc_End
2611
	return
2612
 
2613
 
2614
	;; help function to send a parameter, and to increment FSR0 pointer
2615
CS_MENU_Select_SeqFunc_Hlp_Send
2616
	movwf	INDF0
2617
	call	CS_MENU_MS_SendParameter
2618
	movf	POSTINC0, W
2619
	return
360 tk 2620
 
2621
 
2622
;; --------------------------------------------------------------------------
2623
;;  get parameter value scaled from 0..32 for meter bar display
2624
;;  IN: CS_MENU_PARAMETER_[LH] and CS_MENU_PARAMETER_MAX_[LH]
2625
;;  OUT: scaled value (0..32) in WREG
2626
;;  USES: PROD[LH] and TABLAT
2627
;; --------------------------------------------------------------------------
2628
CS_MENU_GetScaledParam
2629
	;; return 0x20 if max value has been reached
2630
	movf	CS_MENU_PARAMETER_L, W
2631
	xorwf	CS_MENU_PARAMETER_MAX_L, W
2632
	bnz	CS_MENU_GetScaledParam_NotMax
2633
	movf	CS_MENU_PARAMETER_H, W
2634
	xorwf	CS_MENU_PARAMETER_MAX_H, W
2635
	bnz	CS_MENU_GetScaledParam_NotMax
2636
CS_MENU_GetScaledParam_Max
2637
	retlw	0x20
2638
 
2639
CS_MENU_GetScaledParam_NotMax
2640
	movf	CS_MENU_PARAMETER_MAX_H, W
2641
	bnz	CS_MENU_GetScaledParam_Upper
2642
CS_MENU_GetScaledParam_Lower
2643
	movff	CS_MENU_PARAMETER_MAX_L, TABLAT
2644
	clrf	PRODL
2645
	movff	CS_MENU_PARAMETER_L, PRODH
2646
	rgoto	CS_MENU_GetScaledParam_Cont
2647
CS_MENU_GetScaledParam_Upper
2648
	movff	CS_MENU_PARAMETER_MAX_H, TABLAT
2649
	movff	CS_MENU_PARAMETER_L, PRODL
2650
	movff	CS_MENU_PARAMETER_H, PRODH
2651
	;; 	rgoto	CS_MENU_GetScaledParam_Cont
2652
CS_MENU_GetScaledParam_Cont
2653
 
2654
	movf	TABLAT, W	; (CS_MENU_PARAMETER_MAX_x)
2655
	andlw	0xf0
2656
	bnz	CS_MENU_GetScaledParam_U
2657
CS_MENU_GetScaledParam_L
2658
	BRA_IFSET TABLAT, 3, ACCESS, CS_MENU_GetScaledParam_3
2659
	BRA_IFSET TABLAT, 2, ACCESS, CS_MENU_GetScaledParam_2
2660
	BRA_IFSET TABLAT, 1, ACCESS, CS_MENU_GetScaledParam_1
2661
	rgoto	CS_MENU_GetScaledParam_0
2662
CS_MENU_GetScaledParam_U
2663
	BRA_IFSET TABLAT, 7, ACCESS, CS_MENU_GetScaledParam_7
2664
	BRA_IFSET TABLAT, 6, ACCESS, CS_MENU_GetScaledParam_6
2665
	BRA_IFSET TABLAT, 5, ACCESS, CS_MENU_GetScaledParam_5
2666
	rgoto	CS_MENU_GetScaledParam_4
2667
 
2668
CS_MENU_GetScaledParam_0
2669
	swapf	PRODH, F
2670
	swapf	PRODL, W
2671
	andlw	0x0f
2672
	iorwf	PRODH, W
2673
	rgoto	CS_MENU_GetScaledParam_End
2674
 
2675
CS_MENU_GetScaledParam_1
2676
	rlf	PRODL, F
2677
	rlf	PRODH, F
2678
	rlf	PRODL, F
2679
	rlf	PRODH, F
2680
	rlf	PRODL, F
2681
	rlf	PRODH, W
2682
	rgoto	CS_MENU_GetScaledParam_End
2683
 
2684
CS_MENU_GetScaledParam_2
2685
	rlf	PRODL, F
2686
	rlf	PRODH, F
2687
	rlf	PRODL, F
2688
	rlf	PRODH, W
2689
	rgoto	CS_MENU_GetScaledParam_End
2690
 
2691
CS_MENU_GetScaledParam_3
2692
	rlf	PRODL, F
2693
	rlf	PRODH, W
2694
	rgoto	CS_MENU_GetScaledParam_End
2695
 
2696
CS_MENU_GetScaledParam_4
2697
	movf	PRODH, W	; CS_MENU_PARAMETER_x
2698
	rgoto	CS_MENU_GetScaledParam_End
2699
 
2700
CS_MENU_GetScaledParam_5
2701
	rrf	PRODH, W	; CS_MENU_PARAMETER_x
2702
	rgoto	CS_MENU_GetScaledParam_End
2703
 
2704
CS_MENU_GetScaledParam_6
2705
	rrf	PRODH, W	; CS_MENU_PARAMETER_x
2706
	rrf	WREG, W
2707
	rgoto	CS_MENU_GetScaledParam_End
2708
 
2709
CS_MENU_GetScaledParam_7
2710
	rrf	PRODH, W	; CS_MENU_PARAMETER_x
2711
	rrf	WREG, W
2712
	rrf	WREG, W
2713
	;; 	rgoto	CS_MENU_GetScaledParam_End
2714
 
2715
CS_MENU_GetScaledParam_End
2716
	andlw	0x1f
2717
	return
2718
 
2719
 
2720
;; --------------------------------------------------------------------------
2721
;;  Updates the meter bar display
2722
;;  IN: scaled value (0..31) in WREG
2723
;;      if 0xff: spaces will be print (used inside menu pages)
2724
;; --------------------------------------------------------------------------
2725
CS_MENU_UpdateMeterBar
2726
	;; skip if value hasn't changed
2727
	xorwf	CS_MENU_METER_BAR_VALUE, W
2728
	bz	CS_MENU_UpdateMeterBar_End
2729
	xorwf	CS_MENU_METER_BAR_VALUE, W ; (get back original WREG value by a second XOR operation)
2730
	movwf	CS_MENU_METER_BAR_VALUE
2731
	movlw	20		; 20 characters should be displayed
2732
	movwf	CS_MENU_METER_BAR_CTR
2733
CS_MENU_UpdateMeterBar_End
2734
	return
2735
 
2736
 
2737
;; --------------------------------------------------------------------------
2738
;;  Updates the menu label at upper line
2739
;; --------------------------------------------------------------------------
2740
CS_MENU_UpdateLabel
2741
	movlw	5		; 5 pieces
2742
	movwf	CS_MENU_LABEL_CTR
2743
	return