Subversion Repositories svn.mios

Rev

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

Rev Author Line No. Line
44 tk 1
; $Id: sid_bank.inc 44 2008-01-30 21:39:30Z tk $
1 tk 2
;
3
; MIDIbox SID
4
; BankStick Handler
5
;
6
; (Bank Load/Store routines located in sid_pbank.inc and sid_ebank.inc)
7
;
8
; ==========================================================================
9
;
10
;  Copyright 1998-2007 Thorsten Klose (tk@midibox.org)
11
;  Licensed for personal non-commercial use only.
12
;  All other rights reserved.
13
;
14
; ==========================================================================
15
 
16
 
17
;; --------------------------------------------------------------------------
18
;;  Check Stick: try to read from BankStick, clear the appr. flag in
19
;;  SID_BANKSTICK_STATUS if BankStick not available
20
;; --------------------------------------------------------------------------
21
SID_BANK_CheckStick
22
	;; increment check counter, wrap at 8
23
	incf	SID_BANKSTICK_CHK_CTR, W
24
	andlw	0x07
25
	movwf	SID_BANKSTICK_CHK_CTR
26
 
27
	;; select "magic number" and try to read from BankStick
28
	rcall	SID_BANK_CheckStick_SelectMagic
29
	call	MIOS_BANKSTICK_Read
30
	;; this sets the MIOS_BOX_STAT_BS_AVAILABLE flag
31
 
32
	;; save old BankStick status in TMP1
33
	movff	SID_BANKSTICK_STATUS, TMP1
34
 
35
	;; modify the available flag of current bankstick
36
	BRA_IFSET MIOS_BOX_STAT, MIOS_BOX_STAT_BS_AVAILABLE, ACCESS, SID_BANK_CheckStick_AccPassed
37
SID_BANK_CheckStick_AccFailed
38
	movf	SID_BANKSTICK_CHK_CTR, W
39
	call	MIOS_HLP_GetBitANDMask
40
	andwf	SID_BANKSTICK_STATUS, F
41
	rgoto	SID_BANK_CheckStick_AccCont
42
SID_BANK_CheckStick_AccPassed
43
	movf	SID_BANKSTICK_CHK_CTR, W
44
	call	MIOS_HLP_GetBitORMask
45
	iorwf	SID_BANKSTICK_STATUS, F
46
SID_BANK_CheckStick_AccCont
47
 
48
	;; check if flag has been changed
49
	movf	SID_BANKSTICK_STATUS, W
50
	xorwf	TMP1, W
51
	bz	SID_BANK_CheckStick_End		; no change
52
 
53
	;; flag changed - branch depending on available status
54
	movf	SID_BANKSTICK_CHK_CTR, W
55
	call	MIOS_HLP_GetBitORMask
56
	andwf	SID_BANKSTICK_STATUS, W
57
	bnz	SID_BANK_CheckStick_Ext
58
 
59
 
60
	;; ------------------------------------------------------------------
61
	;; --> Internal Patch
62
SID_BANK_CheckStick_Int
63
SID_BANK_CheckStick_IntReload
64
	;; 	TABLE_ADDR TEXT_INTBANK_0		; print message
65
	;; 	call	MIOS_LCD_PrintMessage
66
	;; 	call	MIOS_LCD_PrintMessage
67
 
68
	;; play tune
69
	movf	SID_BANKSTICK_CHK_CTR, W
70
	call	SID_TUNE_Play2
71
 
72
	;; branch depending on patch/ensemble BankStick
73
#if DEFAULT_ENS_BS_CS >= 0 && DEFAULT_ENS_BS_CS <= 7
74
	movlw	DEFAULT_ENS_BS_CS
75
	xorwf	SID_BANKSTICK_CHK_CTR, W
76
	bnz	SID_BANK_CheckStick_Int_P
77
SID_BANK_CheckStick_Int_E
78
	;; change to ensemble 0
79
	clrf	SID_ENSEMBLE
80
	;; set reinit counter - CS configuration will be restored after 1 second
81
	movlw	10
82
	movwf	CS_MENU_REINIT_CFG_CTR
83
	rgoto	SID_BANK_CheckStick_End
84
#endif
85
 
86
SID_BANK_CheckStick_Int_P
87
	;; change to patch 0
88
	movff	SID_MV1_BASE + SID_MVx_MIDI_CHANNEL, WREG
89
	andlw	0x0f
90
	iorlw	0xc0
91
	movwf	MIOS_PARAMETER1
92
	clrf	MIOS_PARAMETER2
93
	call	SID_MIDI_ProgramChange
94
	rgoto	SID_BANK_CheckStick_End
95
 
96
 
97
	;; ------------------------------------------------------------------
98
	;; --> External Patch
99
SID_BANK_CheckStick_Ext
100
	;; 	TABLE_ADDR TEXT_EXTBANK_0		; print message
101
	;; 	call	MIOS_LCD_PrintMessage
102
	;; 	call	MIOS_LCD_PrintMessage
103
	;; play tune
104
	movf	SID_BANKSTICK_CHK_CTR, W
105
	call	SID_TUNE_Play1
106
 
107
	;; new setup will be reloaded automatically
108
	;; set reinit counter - CS configuration will be restored after one second
109
	movlw	10
110
	movwf	CS_MENU_REINIT_CFG_CTR
111
 
112
	;; now check if the magic numbers exist in bankstick bank - if not, format bank automatically
113
	movlw	50				; wait some ms to get a stable status
114
	call	MIOS_Delay
115
 
116
	;; magic numbers are different between Ensemble/Patch bankstick
117
#if DEFAULT_ENS_BS_CS >= 0 && DEFAULT_ENS_BS_CS <= 7
118
	movlw	DEFAULT_ENS_BS_CS
119
	xorwf	SID_BANKSTICK_CHK_CTR, W
120
	bnz	SID_BANK_CheckStick_Ext_P
121
SID_BANK_CheckStick_Ext_E
122
	rcall	SID_BANK_CheckStick_SelectMagic
123
	call	MIOS_BANKSTICK_Read
124
	xorlw	BANKSTICK_E_MAGIC0		; branch to unformatted message if number not equal
125
	bnz	SID_BANK_CheckStick_Unformatted
126
	call	MIOS_BANKSTICK_Read		; read second byte from BankStick
127
	xorlw	BANKSTICK_E_MAGIC1		; branch to unformatted message if number not equal
128
	bnz	SID_BANK_CheckStick_Unformatted
129
 
130
	rgoto	SID_BANK_CheckStick_Ext_E_Cont
131
#endif
132
 
133
SID_BANK_CheckStick_Ext_P
134
	rcall	SID_BANK_CheckStick_SelectMagic
135
	call	MIOS_BANKSTICK_Read
136
	xorlw	BANKSTICK_MAGIC0		; branch to unformatted message if number not equal
137
	bnz	SID_BANK_CheckStick_Unformatted
138
	call	MIOS_BANKSTICK_Read		; read second byte from BankStick
139
	xorlw	BANKSTICK_MAGIC1		; branch to unformatted message if number not equal
140
	bnz	SID_BANK_CheckStick_Unformatted
141
 
142
SID_BANK_CheckStick_Ext_E_Cont
143
	;; set bankstick size depending on third byte (32=32k, 64=64k)
144
	movf	SID_BANKSTICK_CHK_CTR, W
145
	call	MIOS_HLP_GetBitANDMask
146
	andwf	SID_BANKSTICK_SIZE, F
147
	call	MIOS_BANKSTICK_Read
148
	xorlw	64
149
	bnz	SID_BANK_CheckStrick_Ext_Not64k
150
SID_BANK_CheckStrick_Ext_64k
151
	movf	SID_BANKSTICK_CHK_CTR, W
152
	call	MIOS_HLP_GetBitORMask
153
	iorwf	SID_BANKSTICK_SIZE, F
154
SID_BANK_CheckStrick_Ext_Not64k
155
 
156
	;; fix patches if required (and enabled via ENABLE_PATCH_FIXING)
157
	movff	SID_BANKSTICK_CHK_CTR, SID_BANK
158
	rcall	SID_BANK_FixPatches
159
	;; ok
160
	rgoto	SID_BANK_CheckStick_End
161
 
162
SID_BANK_CheckStick_Unformatted
163
 
164
	movff	SID_BANKSTICK_CHK_CTR, SID_BANK
165
	rcall	SID_BANK_FormatStick		; --> format bankstick
166
 
167
SID_BANK_CheckStick_End
168
	return
169
 
170
 
171
;; --------------------------------------------------------------------------
172
;; selects address of magic number depending on SID_BANKSTICK_CHK_CTR (0x0000)
173
;; 0x0000
174
;; --------------------------------------------------------------------------
175
SID_BANK_CheckStick_SelectMagic
176
	;; select BankStick
177
	movf	SID_BANKSTICK_CHK_CTR, W
178
	call	MIOS_BANKSTICK_CtrlSet
179
 
180
	;; select address of magic number
181
	clrf	MIOS_PARAMETER1
182
	clrf	MIOS_PARAMETER2
183
	return
184
 
185
;; --------------------------------------------------------------------------
186
;;  Format Stick: copy the lead default patch into the currently selected BankStick Bank
187
;;  IN: bank number in SID_BANK
188
;; --------------------------------------------------------------------------
189
TEXT_FORMATBANK_0 STRING 20, 0x00, "* Formatting xxk *  "
190
TEXT_FORMATBANK_1 STRING 20, 0x40, "* Patch x  0     *  "
191
TEXT_FORMATBANK_E STRING 20, 0x40, "* Ensemble 000   *  "
192
 
193
SID_BANK_FormatStick
194
	;; select BankStick depending on SID_BANK
195
	movf	SID_BANK, W
196
	call	MIOS_BANKSTICK_CtrlSet
197
 
198
	;; determine if this is a 64k BankStick:
199
	;; read from address 0x8000, store value in PRODL
200
	clrf	MIOS_PARAMETER1
201
	movlw	0x80
202
	movwf	MIOS_PARAMETER2
203
	call	MIOS_BANKSTICK_Read
204
	movwf	PRODL
205
 
206
	;; add 0x42 and write number to 0x0000
207
	addlw	0x42
208
	clrf	MIOS_PARAMETER1
209
	clrf	MIOS_PARAMETER2
210
	call	MIOS_BANKSTICK_Write
211
 
212
	;; read again number from 0x8000, check if we still see the old value
213
	clrf	MIOS_PARAMETER1
214
	movlw	0x80
215
	movwf	MIOS_PARAMETER2
216
	call	MIOS_BANKSTICK_Read
217
	xorwf	PRODL, W
218
	bz	SID_BANK_FormatStick_64k
219
SID_BANK_FormatStick_32k
220
	;; clear flag in SIZE register
221
	movf	SID_BANKSTICK_CHK_CTR, W
222
	call	MIOS_HLP_GetBitANDMask
223
	andwf	SID_BANKSTICK_SIZE, F
224
	;; write 32 to address 0x0002
225
	movlw	32
226
	rgoto	SID_BANK_FormatStick_SizeIDCont
227
SID_BANK_FormatStick_64k
228
	;; set flag in SIZE register
229
	movf	SID_BANKSTICK_CHK_CTR, W
230
	call	MIOS_HLP_GetBitORMask
231
	iorwf	SID_BANKSTICK_SIZE, F
232
	;; write 64 to address 0x0002
233
	movlw	64
234
	;; 	rgoto	SID_BANK_FormatStick_SizeIDCont
235
SID_BANK_FormatStick_SizeIDCont
236
	movwf	PRODL
237
	movlw	0x02
238
	movwf	MIOS_PARAMETER1
239
	clrf	MIOS_PARAMETER2
240
	movf	PRODL, W
241
	call	MIOS_BANKSTICK_Write
242
 
243
	;; print format message
244
	TABLE_ADDR TEXT_FORMATBANK_0
245
	call	MIOS_LCD_PrintMessage
246
	call	MIOS_LCD_PrintMessage
247
 
248
	;; print bankstick size
249
	movlw	0x00 + 13
250
	call	MIOS_LCD_CursorSet
251
	movf	PRODL, W
252
	call	MIOS_LCD_PrintBCD2
253
 
254
 
255
 
256
	;; now branch depending on Ensemble/Patch
257
#if DEFAULT_ENS_BS_CS >= 0 && DEFAULT_ENS_BS_CS <= 7
258
	movlw	DEFAULT_ENS_BS_CS
259
	xorwf	SID_BANKSTICK_CHK_CTR, W
260
	bnz	SID_BANK_FormatStick_P
261
SID_BANK_FormatStick_E
262
	;; print ensemble message (TBLPTR[LHU] already correctly initialised from previous PrintMessage)
263
	call	MIOS_LCD_PrintMessage
264
 
265
	;; using SID_ENSEMBLE as loop counter, start with E1
266
	movlw	1
267
	movwf	SID_ENSEMBLE
268
SID_BANK_FormatStick_E_OuterLoop
269
	;; print ensemble number
270
	movlw	0x40 + 11
271
	call	MIOS_LCD_CursorSet
272
	incf	SID_ENSEMBLE, W
273
	call	MIOS_LCD_PrintBCD3
274
 
275
	;; copy 256 bytes from EEPROM to BankStick
276
	clrf	EEADR
277
	movlw	HIGH(EEPROM_ENSEMBLE)
278
	movwf	EEADRH		; (only relevant for internal EEPROM)
279
SID_BANK_FormatStick_E_InnerLoop
280
	clrwdt			; feed watchdog
281
 
282
	;; select ENS buffer (64 bytes)
283
	lfsr	FSR1, SID_ENS_BUFFER
284
 
285
	;; load page of internal EEPROM into this buffer
286
	call	MIOS_EEPROM_ReadPage
287
 
288
	;; switch back to old address
289
	movlw	-0x40
290
	addwf	EEADR, F
291
 
292
	;; write a 64byte page into EEPROM
293
	call	SID_EBANK_WritePage
294
	;; (will increment EEADR by 0x40)
295
 
296
	movf	EEADR, W	; until address 0x100 is reached
297
	bnz	SID_BANK_FormatStick_E_InnerLoop
298
 
299
	;; increment ensemble until last one (128) reached
300
	incf	SID_ENSEMBLE, F
301
	BRA_IFCLR SID_ENSEMBLE, 7, ACCESS, SID_BANK_FormatStick_E_OuterLoop
302
 
303
 
304
	;; write magic bytes to confirm valid content
305
	movff	SID_BANK, SID_BANKSTICK_CHK_CTR
306
	rcall	SID_BANK_CheckStick_SelectMagic
307
	movlw	BANKSTICK_E_MAGIC0
308
	call	MIOS_BANKSTICK_Write
309
	movlw	BANKSTICK_E_MAGIC1
310
	call	MIOS_BANKSTICK_Write
311
 
312
	;; select first external ensemble
313
	movlw	1
314
	movwf	SID_ENSEMBLE
315
 
316
	;; store number in EEPROM
317
	call	SID_ENS_StoreDefaultNum
318
 
319
	;; and branch to end
320
	rgoto	SID_BANK_FormatStickEnd
321
 
322
#endif
323
SID_BANK_FormatStick_P
324
 
325
	;; print bank number
326
	movlw	0x40 + 8
327
	call	MIOS_LCD_CursorSet
328
	movf	SID_BANK, W
329
	addlw	'A'
330
	call	MIOS_LCD_PrintChar
331
 
332
	;; load preset patch into edit buffer
333
	call	SID_PATCH_LoadPresetIntoEdit
334
 
335
	;; clear name
336
	lfsr	FSR0, SID_EDIT_BUFFER
337
SID_BANK_FormatStick_P_ClearLoop
338
	clrf	POSTINC0
339
	BRA_IFCLR FSR0L, 4, ACCESS, SID_BANK_FormatStick_P_ClearLoop
340
 
341
	;; now format patch 1 to 127 (64k) or 63 (32k)
342
	movlw	0x01
343
	movwf	SID_PATCH	; starting patch
344
SID_BANK_FormatStick_P_OuterLoop
345
	movlw	0x49
346
	call	MIOS_LCD_CursorSet
347
	incf	SID_PATCH, W
348
	call	MIOS_LCD_PrintBCD3
349
 
350
	movf	SID_PATCH, W
351
	call	SID_TUNE_Play3_Note
352
 
353
	;; copy 0x200 words
354
	lfsr	FSR1, SID_EDIT_BUFFER
355
	clrf	EEADR
356
	clrf	EEADRH
357
SID_BANK_FormatStick_P_InnerLoop
358
	clrwdt			; feed watchdog
359
 
360
	;; write a 64byte page into EEPROM
361
	call	SID_PBANK_WritePage
362
 
363
	;; increment FSR1 by 0x40
364
	movlw	0x40
365
	addwf	FSR1L, F
366
	movlw	0x00
367
	addwfc	FSR1H, F
368
 
369
	movf	EEADR, W	; until address 0x200 is reached
370
	bnz	SID_BANK_FormatStick_P_InnerLoop
371
	movlw	0x02-1
372
	cpfsgt	EEADRH, ACCESS
373
	rgoto SID_BANK_FormatStick_P_InnerLoop
374
 
375
	;; continue until last patch is reached
376
	incf	SID_PATCH, F
377
 
378
	movf	SID_BANK, W
379
	call	MIOS_HLP_GetBitORMask
380
	andwf	SID_BANKSTICK_SIZE, W
381
	movlw	128-1
382
	skpnz
383
	movlw	64-1
384
	cpfsgt	SID_PATCH, W
385
	rgoto SID_BANK_FormatStick_P_OuterLoop
386
 
387
	;; clear address 0x0003-0x01ff
388
	movlw	0x03
389
	movwf	MIOS_PARAMETER1
390
	clrf	MIOS_PARAMETER2
391
SID_BANK_FormatStick_P_CfgLoop
392
	clrwdt			; feed watchdog
393
	movlw	0x00
394
	call	MIOS_BANKSTICK_Write
395
	movf	MIOS_PARAMETER1, W
396
	bnz	SID_BANK_FormatStick_P_CfgLoop
397
	movlw	0x02-1
398
	cpfsgt	MIOS_PARAMETER2, ACCESS
399
	rgoto SID_BANK_FormatStick_P_CfgLoop
400
 
401
	;; write magic bytes to confirm valid content
402
	movff	SID_BANK, SID_BANKSTICK_CHK_CTR
403
	rcall	SID_BANK_CheckStick_SelectMagic
404
	movlw	BANKSTICK_MAGIC0
405
	call	MIOS_BANKSTICK_Write
406
	movlw	BANKSTICK_MAGIC1
407
	call	MIOS_BANKSTICK_Write
408
 
409
	;; switch to internal patch
410
	clrf	SID_PATCH
411
 
412
	;; play tune, new setup will be reloaded automatically
413
	movf	SID_BANK, W
414
	call	SID_TUNE_Play1
415
 
416
SID_BANK_FormatStickEnd
417
	;; set reinit counter - CS configuration will be restored after 1 second
418
	movlw	10
419
	movwf	CS_MENU_REINIT_CFG_CTR
420
	return
421
 
422
;; --------------------------------------------------------------------------
423
 
424
 
425
;; --------------------------------------------------------------------------
426
;;  Fix Patches - temporary routine to modify all patches stored in BankStick
427
;;  IN: bank number in SID_BANK
428
;; --------------------------------------------------------------------------
429
TEXT_FIXBANK_0 STRING 20, 0x00, "* Fixing         *  "
430
TEXT_FIXBANK_1 STRING 20, 0x40, "* Patch x  0     *  "
431
 
432
SID_BANK_FixPatches
433
#if ENABLE_PATCH_FIXING
434
	;; select BankStick depending on SID_BANK
435
	movf	SID_BANK, W
436
	call	MIOS_BANKSTICK_CtrlSet
437
 
438
	;; print message
439
	TABLE_ADDR TEXT_FIXBANK_0
440
	call	MIOS_LCD_PrintMessage
441
	call	MIOS_LCD_PrintMessage
442
 
443
	;; print bank number
444
	movlw	0x40 + 8
445
	call	MIOS_LCD_CursorSet
446
	movf	SID_BANK, W
447
	addlw	'A'
448
	call	MIOS_LCD_PrintChar
449
 
450
	;; now fixing patch 1 to 127 (64k) or 63 (32k)
451
	movlw	0x01
452
	movwf	SID_PATCH	; starting patch
453
SID_BANK_FixPatches_OuterLoop
454
	movlw	0x49
455
	call	MIOS_LCD_CursorSet
456
	incf	SID_PATCH, W
457
	call	MIOS_LCD_PrintBCD3
458
 
459
	;; fix pitchbender assignment if K#P not already assigned to other parameter
460
	movlw	SID_Ix_P_KP_BASE+SID_Ix_Px_ASSIGN1
461
	movwf	EEADR
462
	clrf	EEADRH
463
	call	SID_BANK_SetBankStickAddress
464
	call	MIOS_BANKSTICK_Read
465
	bnz	SID_BANK_FixPatches_NoPbFix
466
SID_BANK_FixPatches_PbFix
467
	decf	MIOS_PARAMETER1, F
468
	movlw	0x50
469
	call	MIOS_BANKSTICK_Write
470
SID_BANK_FixPatches_NoPbFix
471
 
472
#if 0
473
	movf	SID_PATCH, W
474
	call	SID_TUNE_Play3_Note
475
#endif
476
 
477
	;; continue until last patch is reached
478
	incf	SID_PATCH, F
479
 
480
	movf	SID_BANK, W
481
	call	MIOS_HLP_GetBitORMask
482
	andwf	SID_BANKSTICK_SIZE, W
483
	movlw	128-1
484
	skpnz
485
	movlw	64-1
486
	cpfsgt	SID_PATCH, W
487
	rgoto SID_BANK_FixPatches_OuterLoop
488
 
489
	;; switch to internal patch
490
	clrf	SID_PATCH
491
 
492
SID_BANK_FixPatchesEnd
493
#endif
494
	return
495