Creative SB0350 Hardware Programming Guide - Page 79

Creative SB0350 Manual

Page 79 highlights

5-4 MIDI Port I/O Programming Reading MIDI Data When MIDI data is available from an external MIDI device, it can be read in from the DSP data port. As mentioned before, there are two operational modes for detecting the availability of in-bound MIDI data: polling mode or interrupt mode. When in polling mode, in-bound MIDI data is available when bit 7 of the DSP Read-Buffer Status port is set. Conversely, when bit 7 is clear, no MIDI data is available. In interrupt mode, an interrupt occurs when MIDI data is available. An interrupt service routine has to be set up to retrieve the MIDI data. A read of the DSP Read-Buffer Status port will clear the interrupt signal. The sequence for reading MIDI data is identical in both polling and interrupt modes. Below is an assembly code fragment that can be used in either a polling routine or an interrupt service routine: mov add Busy: in or jns sub in al,dx al,al Busy dl,4 al,dx ; Read Read-Buffer Status port ; Data available? ; Bit 7 clear, try again ; Read Data port, 2xAh ; Read in-bound DSP data dx,wSBCBaseAddx dl,0Eh ; SBC base I/O address 2x0h ; Read-Buffer Status port, 2xEh The in-bound MIDI data is not tagged with timing information unless the MIDI time stamp mode is used. Therefore, it is up to the application to handle the timing for the MIDI data. Under MIDI time stamp mode, in-bound MIDI data is tagged with 3 bytes of timing information. Hence, 4 bytes of data are always available whenever there is any in-bound MIDI data. The procedure of retrieving the MIDI data together with the timing information is the same except you can now read 4 bytes at a time within the interrupt service routine. The MIDI time stamp is a 3-byte quality that measures time in units of milliseconds. The packing format of time stamped in-bound MIDI data is as follows: nTime.LowByte, nTime.MidByte, nTime.HighByte, bMidiData

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141

5-4
MIDI Port I/O Programming
Reading MIDI Data
When MIDI data is available from an external MIDI device, it can be read in from
the DSP data port.
As mentioned before, there are two operational modes for
detecting the availability of in-bound MIDI data: polling mode or interrupt mode.
When in polling mode, in-bound MIDI data is available when bit 7 of the DSP
Read-Buffer Status port is set.
Conversely, when bit 7 is clear, no MIDI data is
available.
In interrupt mode, an interrupt occurs when MIDI data is available.
An interrupt
service routine has to be set up to retrieve the MIDI data.
A read of the DSP
Read-Buffer Status port will clear the interrupt signal.
The sequence for reading MIDI data is identical in both polling and interrupt modes.
Below is an assembly code fragment that can be used in either a polling routine or an
interrupt service routine:
mov
dx,wSBCBaseAddx
; SBC base I/O address 2
x
0h
add
dl,0Eh
; Read-Buffer Status port, 2
x
Eh
Busy:
in
al,dx
; Read Read-Buffer Status port
or
al,al
; Data available?
jns
Busy
; Bit 7 clear, try again
sub
dl,4
; Read Data port, 2
x
Ah
in
al,dx
; Read in-bound DSP data
The in-bound MIDI data is not tagged with timing information unless the MIDI time
stamp mode is used.
Therefore, it is up to the application to handle the timing for the
MIDI data.
Under MIDI time stamp mode, in-bound MIDI data is tagged with 3 bytes of timing
information.
Hence, 4 bytes of data are always available whenever there is any
in-bound MIDI data.
The procedure of retrieving the MIDI data together with the
timing information is the same except you can now read 4 bytes at a time within the
interrupt service routine.
The MIDI time stamp is a 3-byte quality that measures time in units of milliseconds.
The packing format of time stamped in-bound MIDI data is as follows:
nTime.LowByte, nTime.MidByte, nTime.HighByte, bMidiData