Subversion Repositories svn.mios

Rev

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