Subversion Repositories svn.mios

Rev

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