Subversion Repositories svn.mios

Rev

Rev 324 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
324 tk 1
; $Id: main.asm 878 2010-01-02 15:40:58Z tk $
2
;
3
; A CORE->SID Module Interconnection Test
4
;
5
; ==========================================================================
6
;
7
;  Copyright 2005 Thorsten Klose (tk@midibox.org)
8
;  Licensed for personal non-commercial use only.
9
;  All other rights reserved.
10
; 
11
; ==========================================================================
12
 
13
;; ---[ MIOS header file ]---
14
#include <mios.h>
15
 
16
;; ---[ useful macros ]---
17
#include <macros.h>
18
 
19
;; ---[ vectors to MIOS functions (never change!) ]---
20
#include <mios_vectors.inc>
21
 
22
;; ---[ user hooks (never change!) ]---
23
#include <user_vectors.inc>
24
 
25
;; ==========================================================================
26
;;  General Application Settings
27
;; ==========================================================================
28
 
29
;; ---[ variables used by application ]---
30
#include "app_defines.h"
31
 
32
; ==========================================================================
33
 
34
;; ---[ configuration table for MIDI processor and rotary encoders ]---
35
#include <mios_mt_table.inc>
36
#include <mios_enc_table.inc>
37
 
38
;; ---[ Custom LCD driver ]---
39
#include <app_lcd.inc>
40
 
878 tk 41
;; ---[ Debug Message Module ]---
42
#include <debug_msg.inc>
43
 
44
 
324 tk 45
;; ==========================================================================
46
;;  Include the SID SR Code
47
;; ==========================================================================
48
#include "sid_sr.inc"
49
 
50
 
51
;; ==========================================================================
52
;;  All MIOS hooks in one file
53
;; ==========================================================================
54
 
55
;; --------------------------------------------------------------------------
56
;;  This function is called by MIOS after startup to initialize the 
57
;;  application
58
;; --------------------------------------------------------------------------
59
USER_Init
60
    call    SID_SR_Init
61
    clrf    SID_PIN_NUMBER
62
    call    SID_SetPin
63
    return
64
 
65
 
66
;; --------------------------------------------------------------------------
67
;;  This function is called by MIOS in the mainloop when nothing else is to do
68
;; --------------------------------------------------------------------------
69
USER_Tick
70
    return
71
 
72
 
73
;; --------------------------------------------------------------------------
74
;;  This function is periodically called by MIOS. The frequency has to be
75
;;  initialized with MIOS_Timer_Set
76
;;  Note that this is an interrupt service routine! Use FSR2 instead of FSR0
77
;;  and IRQ_TMPx instead of TMPx -- and make the routine as fast as possible!
78
;; --------------------------------------------------------------------------
79
USER_Timer
80
    return
81
 
82
 
83
;; --------------------------------------------------------------------------
84
;;  This function is called by MIOS when a debug command has been received
85
;;  via SysEx
86
;;  Input:
87
;;     o WREG, MIOS_PARAMETER1, MIOS_PARAMETER2, MIOS_PARAMETER3 like
88
;;       specified in the debug command
89
;;  Output:
90
;;     o return values WREG, MIOS_PARAMETER1, MIOS_PARAMETER2, MIOS_PARAMETER3
91
;; --------------------------------------------------------------------------
92
USER_MPROC_DebugTrigger
93
    return
94
 
95
 
96
;; --------------------------------------------------------------------------
97
;;  This function is called by MIOS when the display content should be 
98
;;  initialized. Thats the case during startup and after a temporary message
99
;;  has been printed on the screen
100
;; --------------------------------------------------------------------------
101
USER_DISPLAY_Init
102
    call    MIOS_LCD_Clear
103
 
104
    TABLE_ADDR TEXT_WELCOME_0
105
    call    MIOS_LCD_PrintString
106
    call    MIOS_LCD_PrintString
107
 
878 tk 108
    call    DEBUG_MSG_SendHeader
109
    movlw   '\n'
110
    call    DEBUG_MSG_SendChar
111
    call    DEBUG_MSG_SendFooter
112
 
113
    call    DEBUG_MSG_SendHeader
114
    call    DEBUG_MSG_SendASMString
115
    db  "MBSID Interconnection Test\n", 0
116
    call    DEBUG_MSG_SendFooter
117
 
118
    call    DEBUG_MSG_SendHeader
119
    call    DEBUG_MSG_SendASMString
120
    db  "==========================\n", 0
121
    call    DEBUG_MSG_SendFooter
122
 
123
    call    DEBUG_MSG_SendHeader
124
    call    DEBUG_MSG_SendASMString
125
    db  "Please play a note on any MIDI channel.\n", 0
126
    call    DEBUG_MSG_SendFooter
127
 
324 tk 128
    bsf DISPLAY_UPDATE_REQ, 0
129
 
130
    return
131
 
132
TEXT_WELCOME_0  STRING 15, 0x00, "Test SID Module"
133
TEXT_WELCOME_1  STRING  4, 0x40, "Pin:"
134
 
135
;; --------------------------------------------------------------------------
136
;;  This function is called in the mainloop when no temporary message is shown
137
;;  on screen. Print the realtime messages here
138
;; --------------------------------------------------------------------------
139
USER_DISPLAY_Tick
140
    ;; display update requested from USER_SR_Service_Prepare on every LED change
141
    btfss   DISPLAY_UPDATE_REQ, 0
142
    return
143
    bcf DISPLAY_UPDATE_REQ, 0
144
 
145
    ;; print pin name
146
    movlw   0x45
147
    call    MIOS_LCD_CursorSet
148
    TABLE_ADDR SID_PIN_NAMES_TABLE
149
    movf    SID_PIN_NUMBER, W
150
    mullw   SID_PIN_NAMES_LEN
151
    movf    PRODL, W
152
    addwf   TBLPTRL, F
153
    movf    PRODH, W
154
    addwfc  TBLPTRH, F
155
    movlw   SID_PIN_NAMES_LEN
878 tk 156
    call    MIOS_LCD_PrintPreconfString
157
 
324 tk 158
 
878 tk 159
    ;; send message to MIOS Terminal
160
    call    DEBUG_MSG_SendHeader
324 tk 161
 
878 tk 162
    ;; special message for CS# pin (since it's inverted)
163
    movf    SID_PIN_NUMBER, W
164
    xorlw   14
165
    bnz USER_DISPLAY_Tick_Normal
166
USER_DISPLAY_Tick_CS
167
    call    DEBUG_MSG_SendASMString
168
    db  "Pin 'CS#' of SID chip set to 5V, remaining digital pins set to 0V as well.", 0
169
    call    DEBUG_MSG_SendFooter
170
    return
171
 
172
 
173
USER_DISPLAY_Tick_Normal
174
    call    DEBUG_MSG_SendASMString
175
    db  "Pin '", 0
176
 
177
    TABLE_ADDR SID_PIN_NAMES_TABLE
178
    movf    SID_PIN_NUMBER, W
179
    mullw   SID_PIN_NAMES_LEN
180
    movf    PRODL, W
181
    addwf   TBLPTRL, F
182
    movf    PRODH, W
183
    addwfc  TBLPTRH, F
184
 
185
    ;; always four chars
186
    tblrd*+
187
    movf    TABLAT, W
188
    call    DEBUG_MSG_SendChar
189
    tblrd*+
190
    movf    TABLAT, W
191
    call    DEBUG_MSG_SendChar
192
    tblrd*+
193
    movf    TABLAT, W
194
    call    DEBUG_MSG_SendChar
195
    tblrd*+
196
    movf    TABLAT, W
197
    call    DEBUG_MSG_SendChar
198
 
199
    call    DEBUG_MSG_SendASMString
200
    db  "' of SID chip set to 5V, remaining digital pins set to 0V (exception: CS# set to 5V)", 0
201
    call    DEBUG_MSG_SendFooter
202
 
203
    return
204
 
205
 
324 tk 206
SID_PIN_NAMES_LEN   EQU 4
207
SID_PIN_NAMES_NUM   EQU 15
208
SID_PIN_NAMES_TABLE
209
    db  "A0  "
210
    db  "A1  "
211
    db  "A2  "
212
    db  "A3  "
213
    db  "A4  "
214
    db  "RES#"
215
    db  "D0  "
216
    db  "D1  "
217
    db  "D2  "
218
    db  "D3  "
219
    db  "D4  "
220
    db  "D5  "
221
    db  "D6  "
222
    db  "D7  "
223
    db  "CS# "
224
 
225
 
226
;; --------------------------------------------------------------------------
227
;;  This function is called by MIOS when a complete MIDI event has been received
228
;;  Input:
229
;;     o first  MIDI event byte in MIOS_PARAMETER1
230
;;     o second MIDI event byte in MIOS_PARAMETER2
231
;;     o third  MIDI event byte in MIOS_PARAMETER3
232
;; --------------------------------------------------------------------------
233
USER_MPROC_NotifyReceivedEvent
234
    ;; if modulation wheel received: set new pin
235
    movf    MIOS_PARAMETER1, W
236
    andlw   0xf0
237
    xorlw   0xb0
878 tk 238
    bnz USER_NotifyReceivedEvent_ChkNote
324 tk 239
    movf    MIOS_PARAMETER2, W
240
    xorlw   0x01
878 tk 241
    bnz USER_NotifyReceivedEvent_ChkNote
324 tk 242
 
243
    movf    MIOS_PARAMETER3, W
244
    movwf   SID_PIN_NUMBER
245
    movlw   SID_PIN_NAMES_NUM
246
    cpfslt  SID_PIN_NUMBER, ACCESS
247
    clrf SID_PIN_NUMBER
248
    bsf DISPLAY_UPDATE_REQ, 0
249
 
250
    ;; set the pin depending on selected SID number
251
    call    SID_SetPin
878 tk 252
    rgoto   USER_NotifyReceivedEvent_End
253
 
254
 
255
USER_NotifyReceivedEvent_ChkNote
256
    ;; alternative control via MIDI keyboard (Note On Events with velocity > 0)
257
    movf    MIOS_PARAMETER1, W
258
    andlw   0xf0
259
    xorlw   0x90
260
    bnz USER_NotifyReceivedEvent_End
261
    movf    MIOS_PARAMETER3, W
262
    bz  USER_NotifyReceivedEvent_End
263
    ;; normalize note to 0..23 range
264
    movf    MIOS_PARAMETER2, W
265
USER_NotifyReceivedEvent_NoteNor
266
    addlw   -24
267
    BRA_IFCLR WREG, 7, ACCESS, USER_NotifyReceivedEvent_NoteNor
268
    addlw   24      ; now in range 0..23
269
    movwf   SID_PIN_NUMBER
270
 
271
    movlw   SID_PIN_NAMES_NUM
272
    cpfslt  SID_PIN_NUMBER, ACCESS
273
    clrf SID_PIN_NUMBER
274
    bsf DISPLAY_UPDATE_REQ, 0
275
 
276
    ;; set the pin depending on selected SID number
277
    call    SID_SetPin
278
    ;;  rgoto   USER_NotifyReceivedEvent_End
279
 
324 tk 280
USER_NotifyReceivedEvent_End
281
    return
282
 
283
 
284
;; --------------------------------------------------------------------------
285
;;  This function is called by MIOS when a MIDI event has been received
286
;;  which has been specified in the CONFIG_MIDI_IN table
287
;;  Input:
288
;;     o number of entry in WREG
289
;;     o first  MIDI event byte in MIOS_PARAMETER1
290
;;     o second MIDI event byte in MIOS_PARAMETER2
291
;;     o third  MIDI event byte in MIOS_PARAMETER3
292
;; --------------------------------------------------------------------------
293
USER_MPROC_NotifyFoundEvent
294
    return
295
 
296
 
297
;; --------------------------------------------------------------------------
298
;;  This function is called by MIOS when a MIDI event has not been completly
299
;;  received within 2 seconds
300
;; --------------------------------------------------------------------------
301
USER_MPROC_NotifyTimeout
302
    return
303
 
304
 
305
;; --------------------------------------------------------------------------
306
;;  This function is called by MIOS when a MIDI byte has been received
307
;;  Input:
308
;;     o received MIDI byte in WREG and MIOS_PARAMETER1
309
;; --------------------------------------------------------------------------
310
USER_MPROC_NotifyReceivedByte
311
    return
312
 
313
;; --------------------------------------------------------------------------
314
;;  This function is called by MIOS before the transfer of a MIDI byte. 
315
;;  It can be used to monitor the Tx activity or to do any other actions
316
;;  (e.g. to switch a pin for multiplexed MIDI Outs) before the byte will 
317
;;  be sent.
318
;;  Note that this is an interrupt service routine! Use FSR2 instead of FSR0
319
;;  and IRQ_TMPx instead of TMPx -- and make the routine as fast as possible!
320
;;  Input:
321
;;     o transmitted byte in WREG
322
;; --------------------------------------------------------------------------
323
USER_MIDI_NotifyTx
324
    return
325
 
326
;; --------------------------------------------------------------------------
327
;;  This function is called by MIOS when a MIDI byte has been received.
328
;;  It can be used to monitor the Rx activity or to do any action - e.g.
329
;;  to react on realtime events like MIDI clock (0xf8) with a minimum latency
330
;;  Note that this is an interrupt service routine! Use FSR2 instead of FSR0
331
;;  and IRQ_TMPx instead of TMPx -- and make the routine as fast as possible!
332
;;  Input:
333
;;     o received byte in WREG
334
;; --------------------------------------------------------------------------
335
USER_MIDI_NotifyRx
336
    return
337
 
338
;; --------------------------------------------------------------------------
339
;;  This function is called by MIOS when an button has been toggled
340
;;  Input:
341
;;     o Button number in WREG and MIOS_PARAMETER1
342
;;     o Button value MIOS_PARAMETER2:
343
;;       - 1 if button has been released (=5V)
344
;;       - 0 if button has been pressed (=0V)
345
;; --------------------------------------------------------------------------
346
USER_DIN_NotifyToggle
347
    return
348
 
349
 
350
;; --------------------------------------------------------------------------
351
;;  This function is called by MIOS when an encoder has been moved
352
;;  Input:
353
;;     o Encoder number in WREG and MIOS_PARAMETER1
354
;;     o signed incrementer value in MIOS_PARAMETER2:
355
;;       - is positive when encoder has been turned clockwise
356
;;       - is negative when encoder has been turned counter clockwise
357
;; --------------------------------------------------------------------------
358
USER_ENC_NotifyChange
359
    return
360
 
361
 
362
;; --------------------------------------------------------------------------
363
;;  This function is called by MIOS before the shift register are loaded
364
;;  Note that this is an interrupt service routine! Use FSR2 instead of FSR0
365
;;  and IRQ_TMPx instead of TMPx -- and make the routine as fast as possible
366
;; --------------------------------------------------------------------------
367
USER_SR_Service_Prepare
368
    return
369
 
370
 
371
;; --------------------------------------------------------------------------
372
;;  This function is called by MIOS after the shift register have been loaded
373
;;  Note that this is an interrupt service routine! Use FSR2 instead of FSR0
374
;;  and IRQ_TMPx instead of TMPx -- and make the routine as fast as possible
375
;; --------------------------------------------------------------------------
376
USER_SR_Service_Finish
377
    return
378
 
379
;; --------------------------------------------------------------------------
380
;;  This function is called by MIOS when a pot has been moved
381
;;  Input:
382
;;     o Pot number in WREG and MIOS_PARAMETER1
383
;;     o LSB value in MIOS_PARAMETER2
384
;;     o MSB value in MIOS_PARAMETER3
385
;; --------------------------------------------------------------------------
386
USER_AIN_NotifyChange
387
    return
388
 
389
 
390
 
391
;; --------------------------------------------------------------------------
392
;;  This function sets a SID pin depending on SID_PIN_NUMBER
393
;; --------------------------------------------------------------------------
394
SID_SetPin
395
    bcf SID_SR_LAT_WR, SID_SR_PIN_WR
396
    clrf    MIOS_PARAMETER1
397
    clrf    MIOS_PARAMETER2
398
 
399
    movf    SID_PIN_NUMBER, W
400
    JUMPTABLE_2BYTES 15 ; entries
401
    rgoto   SID_SetPin0
402
    rgoto   SID_SetPin1
403
    rgoto   SID_SetPin2
404
    rgoto   SID_SetPin3
405
    rgoto   SID_SetPin4
406
    rgoto   SID_SetPin5
407
    rgoto   SID_SetPin6
408
    rgoto   SID_SetPin7
409
    rgoto   SID_SetPin8
410
    rgoto   SID_SetPin9
411
    rgoto   SID_SetPin10
412
    rgoto   SID_SetPin11
413
    rgoto   SID_SetPin12
414
    rgoto   SID_SetPin13
415
    rgoto   SID_SetPin14
416
 
417
SID_SetPin0
418
    movlw   0x01        ; A0
419
    movwf   MIOS_PARAMETER1
420
    goto    SID_SR_Write
421
 
422
SID_SetPin1
423
    movlw   0x02        ; A1
424
    movwf   MIOS_PARAMETER1
425
    goto    SID_SR_Write
426
 
427
SID_SetPin2
428
    movlw   0x04        ; A2
429
    movwf   MIOS_PARAMETER1
430
    goto    SID_SR_Write
431
 
432
SID_SetPin3
433
    movlw   0x08        ; A3
434
    movwf   MIOS_PARAMETER1
435
    goto    SID_SR_Write
436
 
437
SID_SetPin4
438
    movlw   0x10        ; A4
439
    movwf   MIOS_PARAMETER1
440
    goto    SID_SR_Write
441
 
442
SID_SetPin5
443
    movlw   0x20        ; RES#
444
    movwf   MIOS_PARAMETER1
445
    goto    SID_SR_Write
446
 
447
SID_SetPin6
448
    movlw   0x01        ; D0
449
    movwf   MIOS_PARAMETER2
450
    goto    SID_SR_Write
451
 
452
SID_SetPin7
453
    movlw   0x02        ; D1
454
    movwf   MIOS_PARAMETER2
455
    goto    SID_SR_Write
456
 
457
SID_SetPin8
458
    movlw   0x04        ; D2
459
    movwf   MIOS_PARAMETER2
460
    goto    SID_SR_Write
461
 
462
SID_SetPin9
463
    movlw   0x08        ; D3
464
    movwf   MIOS_PARAMETER2
465
    goto    SID_SR_Write
466
 
467
SID_SetPin10
468
    movlw   0x10        ; D4
469
    movwf   MIOS_PARAMETER2
470
    goto    SID_SR_Write
471
 
472
SID_SetPin11
473
    movlw   0x20        ; D5
474
    movwf   MIOS_PARAMETER2
475
    goto    SID_SR_Write
476
 
477
SID_SetPin12
478
    movlw   0x40        ; D6
479
    movwf   MIOS_PARAMETER2
480
    goto    SID_SR_Write
481
 
482
SID_SetPin13
483
    movlw   0x80        ; D7
484
    movwf   MIOS_PARAMETER2
485
    goto    SID_SR_Write
486
 
487
SID_SetPin14
488
    bcf SID_SR_LAT_WR, SID_SR_PIN_WR
489
    return
490
 
491
    END