Subversion Repositories svn.mios

Rev

Rev 877 | 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->MBHP_OPL3 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
 
324 tk 44
; define the pins to which the MBHP_OPL3 module is connected
45
;
46
MBFM_LAT_D  EQU LATB        ; Port B
47
MBFM_LAT_A1 EQU LATD        ; Pin D.6
48
MBFM_PIN_A1 EQU 6
49
MBFM_LAT_A0 EQU LATD        ; Pin D.5
50
MBFM_PIN_A0 EQU 5
51
MBFM_LAT_CS EQU LATC        ; Pin C.5
52
MBFM_PIN_CS EQU 5
53
MBFM_LAT_IC EQU LATC        ; Pin C.4
54
MBFM_PIN_IC EQU 4
55
 
56
;; ==========================================================================
57
;;  All MIOS hooks in one file
58
;; ==========================================================================
59
 
60
;; --------------------------------------------------------------------------
61
;;  This function is called by MIOS after startup to initialize the 
62
;;  application
63
;; --------------------------------------------------------------------------
64
USER_Init
65
    clrf    OPL3_PIN_NUMBER
66
    call    OPL3_SetPin
67
    return
68
 
69
 
70
;; --------------------------------------------------------------------------
71
;;  This function is called by MIOS in the mainloop when nothing else is to do
72
;; --------------------------------------------------------------------------
73
USER_Tick
74
    return
75
 
76
 
77
;; --------------------------------------------------------------------------
78
;;  This function is periodically called by MIOS. The frequency has to be
79
;;  initialized with MIOS_Timer_Set
80
;;  Note that this is an interrupt service routine! Use FSR2 instead of FSR0
81
;;  and IRQ_TMPx instead of TMPx -- and make the routine as fast as possible!
82
;; --------------------------------------------------------------------------
83
USER_Timer
84
    return
85
 
86
 
87
;; --------------------------------------------------------------------------
88
;;  This function is called by MIOS when a debug command has been received
89
;;  via SysEx
90
;;  Input:
91
;;     o WREG, MIOS_PARAMETER1, MIOS_PARAMETER2, MIOS_PARAMETER3 like
92
;;       specified in the debug command
93
;;  Output:
94
;;     o return values WREG, MIOS_PARAMETER1, MIOS_PARAMETER2, MIOS_PARAMETER3
95
;; --------------------------------------------------------------------------
96
USER_MPROC_DebugTrigger
97
    return
98
 
99
 
100
;; --------------------------------------------------------------------------
101
;;  This function is called by MIOS when the display content should be 
102
;;  initialized. Thats the case during startup and after a temporary message
103
;;  has been printed on the screen
104
;; --------------------------------------------------------------------------
105
USER_DISPLAY_Init
106
    call    MIOS_LCD_Clear
107
 
108
    TABLE_ADDR TEXT_WELCOME_0
109
    call    MIOS_LCD_PrintString
110
    call    MIOS_LCD_PrintString
111
 
878 tk 112
    call    DEBUG_MSG_SendHeader
113
    movlw   '\n'
114
    call    DEBUG_MSG_SendChar
115
    call    DEBUG_MSG_SendFooter
116
 
117
    call    DEBUG_MSG_SendHeader
118
    call    DEBUG_MSG_SendASMString
119
    db  "MBFM Interconnection Test\n", 0
120
    call    DEBUG_MSG_SendFooter
121
 
122
    call    DEBUG_MSG_SendHeader
123
    call    DEBUG_MSG_SendASMString
124
    db  "=========================\n", 0
125
    call    DEBUG_MSG_SendFooter
126
 
127
    call    DEBUG_MSG_SendHeader
128
    call    DEBUG_MSG_SendASMString
129
    db  "Please play a note on any MIDI channel.\n", 0
130
    call    DEBUG_MSG_SendFooter
131
 
324 tk 132
    bsf DISPLAY_UPDATE_REQ, 0
133
 
134
    return
135
 
136
TEXT_WELCOME_0  STRING 16, 0x00, "Test OPL3 Module"
137
TEXT_WELCOME_1  STRING  4, 0x40, "Pin:"
138
 
139
;; --------------------------------------------------------------------------
140
;;  This function is called in the mainloop when no temporary message is shown
141
;;  on screen. Print the realtime messages here
142
;; --------------------------------------------------------------------------
143
USER_DISPLAY_Tick
144
    ;; display update requested from USER_SR_Service_Prepare on every LED change
145
    btfss   DISPLAY_UPDATE_REQ, 0
146
    return
147
    bcf DISPLAY_UPDATE_REQ, 0
148
 
149
    ;; print pin name
150
    movlw   0x45
151
    call    MIOS_LCD_CursorSet
152
    TABLE_ADDR OPL3_PIN_NAMES_TABLE
153
    movf    OPL3_PIN_NUMBER, W
154
    mullw   OPL3_PIN_NAMES_LEN
155
    movf    PRODL, W
156
    addwf   TBLPTRL, F
157
    movf    PRODH, W
158
    addwfc  TBLPTRH, F
159
    movlw   OPL3_PIN_NAMES_LEN
160
    call    MIOS_LCD_PrintPreconfString
161
 
878 tk 162
 
163
    ;; send message to MIOS Terminal
164
    call    DEBUG_MSG_SendHeader
165
    call    DEBUG_MSG_SendASMString
166
    db  "Pin '", 0
167
 
168
    TABLE_ADDR OPL3_PIN_NAMES_TABLE
169
    movf    OPL3_PIN_NUMBER, W
170
    mullw   OPL3_PIN_NAMES_LEN
171
    movf    PRODL, W
172
    addwf   TBLPTRL, F
173
    movf    PRODH, W
174
    addwfc  TBLPTRH, F
175
 
176
    ;; always two chars
177
    tblrd*+
178
    movf    TABLAT, W
179
    call    DEBUG_MSG_SendChar
180
    tblrd*+
181
    movf    TABLAT, W
182
    call    DEBUG_MSG_SendChar
183
 
184
    call    DEBUG_MSG_SendASMString
185
    db  "' of MBHP_OPL3 module set to 5V, all other pins set to 0V", 0
186
    call    DEBUG_MSG_SendFooter
187
 
324 tk 188
    ;; IMPORTANT!!!
189
    ;; Since a LCD message could overwrite the data/address/control
190
    ;; line value, we update the pins again
191
    goto    OPL3_SetPin
192
 
193
 
194
OPL3_PIN_NAMES_LEN  EQU 4
195
OPL3_PIN_NAMES_NUM  EQU 12
196
OPL3_PIN_NAMES_TABLE
197
    db  "RS  "
198
    db  "A0  "
199
    db  "A1  "
200
    db  "WR  "
201
    db  "D0  "
202
    db  "D1  "
203
    db  "D2  "
204
    db  "D3  "
205
    db  "D4  "
206
    db  "D5  "
207
    db  "D6  "
208
    db  "D7  "
209
 
210
 
211
;; --------------------------------------------------------------------------
212
;;  This function is called by MIOS when a complete MIDI event has been received
213
;;  Input:
214
;;     o first  MIDI event byte in MIOS_PARAMETER1
215
;;     o second MIDI event byte in MIOS_PARAMETER2
216
;;     o third  MIDI event byte in MIOS_PARAMETER3
217
;; --------------------------------------------------------------------------
218
USER_MPROC_NotifyReceivedEvent
219
    ;; if modulation wheel received: set new pin
220
    movf    MIOS_PARAMETER1, W
221
    andlw   0xf0
222
    xorlw   0xb0
876 tk 223
    bnz USER_NotifyReceivedEvent_ChkNote
324 tk 224
    movf    MIOS_PARAMETER2, W
225
    xorlw   0x01
876 tk 226
    bnz USER_NotifyReceivedEvent_ChkNote
324 tk 227
 
228
    movf    MIOS_PARAMETER3, W
229
    movwf   OPL3_PIN_NUMBER
230
    movlw   OPL3_PIN_NAMES_NUM
231
    cpfslt  OPL3_PIN_NUMBER, ACCESS
232
    clrf OPL3_PIN_NUMBER
233
    bsf DISPLAY_UPDATE_REQ, 0
234
 
235
    ;; set the pin depending on selected OPL3 number
236
    call    OPL3_SetPin
876 tk 237
    rgoto   USER_NotifyReceivedEvent_End
238
 
239
 
240
USER_NotifyReceivedEvent_ChkNote
241
    ;; alternative control via MIDI keyboard (Note On Events with velocity > 0)
242
    movf    MIOS_PARAMETER1, W
243
    andlw   0xf0
244
    xorlw   0x90
245
    bnz USER_NotifyReceivedEvent_End
246
    movf    MIOS_PARAMETER3, W
877 tk 247
    bz  USER_NotifyReceivedEvent_End
876 tk 248
    ;; normalize note to 0..11 range
249
    movf    MIOS_PARAMETER2, W
250
USER_NotifyReceivedEvent_NoteNor
251
    addlw   -12
252
    BRA_IFCLR WREG, 7, ACCESS, USER_NotifyReceivedEvent_NoteNor
253
    addlw   12      ; now in range 0..11
254
    movwf   OPL3_PIN_NUMBER
255
 
878 tk 256
    movlw   OPL3_PIN_NAMES_NUM
876 tk 257
    cpfslt  OPL3_PIN_NUMBER, ACCESS
258
    clrf OPL3_PIN_NUMBER
259
    bsf DISPLAY_UPDATE_REQ, 0
260
 
261
    ;; set the pin depending on selected OPL3 number
262
    call    OPL3_SetPin
263
    ;;  rgoto   USER_NotifyReceivedEvent_End
264
 
324 tk 265
USER_NotifyReceivedEvent_End
266
    return
267
 
268
 
269
;; --------------------------------------------------------------------------
270
;;  This function is called by MIOS when a MIDI event has been received
271
;;  which has been specified in the CONFIG_MIDI_IN table
272
;;  Input:
273
;;     o number of entry in WREG
274
;;     o first  MIDI event byte in MIOS_PARAMETER1
275
;;     o second MIDI event byte in MIOS_PARAMETER2
276
;;     o third  MIDI event byte in MIOS_PARAMETER3
277
;; --------------------------------------------------------------------------
278
USER_MPROC_NotifyFoundEvent
279
    return
280
 
281
 
282
;; --------------------------------------------------------------------------
283
;;  This function is called by MIOS when a MIDI event has not been completly
284
;;  received within 2 seconds
285
;; --------------------------------------------------------------------------
286
USER_MPROC_NotifyTimeout
287
    return
288
 
289
 
290
;; --------------------------------------------------------------------------
291
;;  This function is called by MIOS when a MIDI byte has been received
292
;;  Input:
293
;;     o received MIDI byte in WREG and MIOS_PARAMETER1
294
;; --------------------------------------------------------------------------
295
USER_MPROC_NotifyReceivedByte
296
    return
297
 
298
;; --------------------------------------------------------------------------
299
;;  This function is called by MIOS before the transfer of a MIDI byte. 
300
;;  It can be used to monitor the Tx activity or to do any other actions
301
;;  (e.g. to switch a pin for multiplexed MIDI Outs) before the byte will 
302
;;  be sent.
303
;;  Note that this is an interrupt service routine! Use FSR2 instead of FSR0
304
;;  and IRQ_TMPx instead of TMPx -- and make the routine as fast as possible!
305
;;  Input:
306
;;     o transmitted byte in WREG
307
;; --------------------------------------------------------------------------
308
USER_MIDI_NotifyTx
309
    return
310
 
311
;; --------------------------------------------------------------------------
312
;;  This function is called by MIOS when a MIDI byte has been received.
313
;;  It can be used to monitor the Rx activity or to do any action - e.g.
314
;;  to react on realtime events like MIDI clock (0xf8) with a minimum latency
315
;;  Note that this is an interrupt service routine! Use FSR2 instead of FSR0
316
;;  and IRQ_TMPx instead of TMPx -- and make the routine as fast as possible!
317
;;  Input:
318
;;     o received byte in WREG
319
;; --------------------------------------------------------------------------
320
USER_MIDI_NotifyRx
321
    return
322
 
323
;; --------------------------------------------------------------------------
324
;;  This function is called by MIOS when an button has been toggled
325
;;  Input:
326
;;     o Button number in WREG and MIOS_PARAMETER1
327
;;     o Button value MIOS_PARAMETER2:
328
;;       - 1 if button has been released (=5V)
329
;;       - 0 if button has been pressed (=0V)
330
;; --------------------------------------------------------------------------
331
USER_DIN_NotifyToggle
332
    return
333
 
334
 
335
;; --------------------------------------------------------------------------
336
;;  This function is called by MIOS when an encoder has been moved
337
;;  Input:
338
;;     o Encoder number in WREG and MIOS_PARAMETER1
339
;;     o signed incrementer value in MIOS_PARAMETER2:
340
;;       - is positive when encoder has been turned clockwise
341
;;       - is negative when encoder has been turned counter clockwise
342
;; --------------------------------------------------------------------------
343
USER_ENC_NotifyChange
344
    return
345
 
346
 
347
;; --------------------------------------------------------------------------
348
;;  This function is called by MIOS before the shift register are loaded
349
;;  Note that this is an interrupt service routine! Use FSR2 instead of FSR0
350
;;  and IRQ_TMPx instead of TMPx -- and make the routine as fast as possible
351
;; --------------------------------------------------------------------------
352
USER_SR_Service_Prepare
353
    return
354
 
355
 
356
;; --------------------------------------------------------------------------
357
;;  This function is called by MIOS after the shift register have been loaded
358
;;  Note that this is an interrupt service routine! Use FSR2 instead of FSR0
359
;;  and IRQ_TMPx instead of TMPx -- and make the routine as fast as possible
360
;; --------------------------------------------------------------------------
361
USER_SR_Service_Finish
362
    return
363
 
364
;; --------------------------------------------------------------------------
365
;;  This function is called by MIOS when a pot has been moved
366
;;  Input:
367
;;     o Pot number in WREG and MIOS_PARAMETER1
368
;;     o LSB value in MIOS_PARAMETER2
369
;;     o MSB value in MIOS_PARAMETER3
370
;; --------------------------------------------------------------------------
371
USER_AIN_NotifyChange
372
    return
373
 
374
 
375
 
376
;; --------------------------------------------------------------------------
377
;;  This function sets a OPL3 pin depending on OPL3_PIN_NUMBER
378
;; --------------------------------------------------------------------------
379
OPL3_SetPin
380
    ;; clear all pins
381
    clrf    MBFM_LAT_D
382
    bcf MBFM_LAT_A0, MBFM_PIN_A0
383
    bcf MBFM_LAT_A1, MBFM_PIN_A1
384
    bcf MBFM_LAT_CS, MBFM_PIN_CS
385
    bcf MBFM_LAT_IC, MBFM_PIN_IC
386
 
387
    ;; set selected pin
388
    movf    OPL3_PIN_NUMBER, W
389
    JUMPTABLE_2BYTES 12 ; entries
390
    rgoto   OPL3_SetPin_RS
391
    rgoto   OPL3_SetPin_A0
392
    rgoto   OPL3_SetPin_A1
393
    rgoto   OPL3_SetPin_WR
394
    rgoto   OPL3_SetPin_D0
395
    rgoto   OPL3_SetPin_D1
396
    rgoto   OPL3_SetPin_D2
397
    rgoto   OPL3_SetPin_D3
398
    rgoto   OPL3_SetPin_D4
399
    rgoto   OPL3_SetPin_D5
400
    rgoto   OPL3_SetPin_D6
401
    rgoto   OPL3_SetPin_D7
402
 
403
OPL3_SetPin_RS
404
    bsf MBFM_LAT_IC, MBFM_PIN_IC
405
    return
406
 
407
OPL3_SetPin_A0
408
    bsf MBFM_LAT_A0, MBFM_PIN_A0
409
    return
410
 
411
OPL3_SetPin_A1
412
    bsf MBFM_LAT_A1, MBFM_PIN_A1
413
    return
414
 
415
OPL3_SetPin_WR
416
    bsf MBFM_LAT_CS, MBFM_PIN_CS
417
    return
418
 
419
OPL3_SetPin_D0
420
    bsf MBFM_LAT_D, 0
421
    return
422
 
423
OPL3_SetPin_D1
424
    bsf MBFM_LAT_D, 1
425
    return
426
 
427
OPL3_SetPin_D2
428
    bsf MBFM_LAT_D, 2
429
    return
430
 
431
OPL3_SetPin_D3
432
    bsf MBFM_LAT_D, 3
433
    return
434
 
435
OPL3_SetPin_D4
436
    bsf MBFM_LAT_D, 4
437
    return
438
 
439
OPL3_SetPin_D5
440
    bsf MBFM_LAT_D, 5
441
    return
442
 
443
OPL3_SetPin_D6
444
    bsf MBFM_LAT_D, 6
445
    return
446
 
447
OPL3_SetPin_D7
448
    bsf MBFM_LAT_D, 7
449
    return
450
 
451
 
452
    END