
 MIDI 5.00
 =========

 The MIDI500 module was developed from the documentation of the MIDI
 module API. It doesn't support the entire API and some things (most
 notably the interface to drivers) have been done in different ways,
 due to lack of documentation.


 SWI MIDI_SoundEnable                   &404c0
 ---------------------------------------------
 Enable/disable sound interpreter

 On entry
          R0  =     reason code
                    0 disable sound interpreter
                    1 connect to port 0 input
                    2 connect to port 0 output
                    3 connect to port 1 input
                    4 connect to port 1 output
                    etc.
          R1  =     sound interpreter touch sensitivity
                    1 enable
                    2 disable

 On exit
          R0        undefined

 MIDI500 does not include a sound interpreter.
 This SWI doesn't do anything.


 SWI MIDI_SetMode                       &404c1
 ---------------------------------------------
 Sound interpreter mode

 On entry
          R0  =     mode number (1-4) or 0 for unchanged
          R1  =     midi channel number in bits 0..7
                    no. of channels in bits 8..16 for OmniOff/Mono
                    0 for unchanged

 On exit
          R0,R1     new or current values

 MIDI500 does not include a sound interpreter.
 This SWI doesn't do anything.


 SWI MIDI_SetTxChannel                  &404c2
 ---------------------------------------------
 Set/read channel/port number for MIDI_Tx... SWIs

 On entry
          R0  =     channel/port number or 0 for unchanged
                     1..16  channel on port 0
                    17..32  channel on port 1
                    33..48  channel on port 2
                    49..64  channel on port 3

 On exit
          R0  =     new or current channel/port


 SWI MIDI_SetTxActiveSensing            &404c3
 ---------------------------------------------
 Enable/disable tx of active sensing messages

 On entry
          R0        bit 0     = 0 disable
                                1 enable
                    bits 1..2 = port number

 On exit
          R0        bit N (0..3) set if enabled for port N
                    bit N+4 set if port N is receiving
                            active sensing

 This SWI is not fully supported.


 SWI MIDI_InqSongPositionPointer        &404c4
 ---------------------------------------------
 Read song position pointer

 On exit
          R0  =     song position pointer (beat counter/6)
          R1        bit 0 set if in external timing mode
                    bit 1 set if in internal timing mode
                    bit 2 set if in FastClock mode
                    bit 3 set if MIDI_FastClock has been called
                    bit 4 set if in special mode ?
                    bit 5 set if in special mode ?

 This SWI is not fully supported.


 SWI MIDI_InqBufferSize                 &404c5
 ---------------------------------------------
 Read buffer sizes

 On entry
          R0        bit 0     = 0 to read rx buffer size
                                1 to read tx buffer size
                    bits 1..2 = port number

 On exit
          R0  =     free bytes in buffer

 As the module doesn't support tx buffers, it just returns a dummy
 value when the num of free bytes in the tx buffer is read.


 SWI MIDI_InqError                      &404c6
 ---------------------------------------------
 Read error

 On exit
          R0        bits  0..7   error for port 0
                    bits  8..15  error for port 1
                    bits 16..23  error for port 2
                    bits 24..31  error for port 3

 This SWI is not fully supported - it always returns 0.


 SWI MIDI_RxByte                        &404c7
 ---------------------------------------------
 Read byte

 On entry
          R0  =     port number or -1 to scan all ports

 On exit
          R0  =     bits  0..7   status
                    bits 24..25  no. of bytes read (1 or 0)
                    bits 28..31  port number
          R1  =     receive time

 This SWI is not fully support - it always returns 0.


 SWI MIDI_RxCommand                     &404c8
 ---------------------------------------------
 Read command

 On entry
          R0  =     port number or -1 to scan all ports

 On exit
          R0        bits  0..7   status
                    bits  8..15  data byte 1 (or 0)
                    bits 16..23  data byte 2 (or 0)
                    bits 24..25  no. of bytes (0..3)
                    bits 28..31  port no.
          R1  =     receive time

 This SWI is not fully support - it always returns 0.


 SWI MIDI_TxByte                        &404c9
 ---------------------------------------------
 Transmit byte

 On entry
          R0        bits  0..7   byte
                    bits 28..31  port no.

 On exit
          R0        preserved


 SWI MIDI_TxCommand                     &404ca
 ---------------------------------------------
 Transmit command

 On entry
          R0        bits  0..7   status
                    bits  8..15  data byte 1
                    bits 16..23  data byte 2
                    bits 24..25  no. of bytes
                    bits 28..31  port no.
          R1  =     schedule time or 0 for immediate
 On exit
          R0  =     no. of schedule slots free or
                    -1 if scheduler is full or
                    -2 if schedule time is earlier than previous command
       if R1=0 on entry, R0 is preserved


 SWI MIDI_TxNoteOff                     &404cb
 ---------------------------------------------
 Transmit a 'note off' on the previously selected port and channel.

 On entry
          R0  =     note
          R1  =     velocity


 SWI MIDI_TxNoteOn                      &404cc
 ---------------------------------------------
 Transmit a 'note on' on the previously selected port and channel.

 On entry
          R0  =     note
          R1  =     velocity


 SWI MIDI_TxPolyKeyPressure             &404cd
 ---------------------------------------------
 Transmit am 'aftertouch' on the previously selected port and channel.

 On entry
          R0  =     note
          R1  =     velocity


 SWI MIDI_TxControlChange               &404ce
 ---------------------------------------------
 Transmit a 'control change' on the previously selected port and channel.

 On entry
          R0  =     controller
          R1  =     value


 SWI MIDI_TxLocalControl                &404cf
 ---------------------------------------------
 Transmit a 'control change' for controller 122 on the previously selected
 port and channel.

 On entry
          R0  =     0 off
                    1 on


 SWI MIDI_TxAllNotesOff                 &404d0
 ---------------------------------------------
 Transmit a 'control change' for controller 123 on the previously selected
 port and channel.


 SWI MIDI_TxOmniModeOff                 &404d1
 ---------------------------------------------
 Transmit a 'control change' for controller 124 on the previously selected
 port and channel.


 SWI MIDI_TxOmniModeOn                  &404d2
 ---------------------------------------------
 Transmit a 'control change' for controller 125 on the previously selected
 port and channel.


 SWI MIDI_TxMonoModeOn                  &404d3
 ---------------------------------------------
 Transmit a 'control change' for controller 126 on the previously selected
 port and channel.


 SWI MIDI_TxPolyModeOn                  &404d4
 ---------------------------------------------
 Transmit a 'control change' for controller 127 on the previously selected
 port and channel.


 SWI MIDI_TxProgramChange               &404d5
 ---------------------------------------------
 Transmit a 'program change' on the previously selected port and channel.

 On entry
          R0  =     program


 SWI MIDI_TxChannelPressure             &404d6
 ---------------------------------------------
 Transmit a 'channel pressure' on the previously selected port and
 channel.

 On entry
          R0  =     pressure


 SWI MIDI_TxPitchwheel                  &404d7
 ---------------------------------------------
 Transmit a 'pitch wheel' on the previously selected port and channel.

 On entry
          R0  =     pitchwheel value (0..&3fff)


 SWI MIDI_TxSongPositionPointer         &404d8
 ---------------------------------------------
 Transmit a 'song position pointer' on the previously selected port
 and channel.

 On entry
          R0  =     song position pointer (0..&3fff)

 This SWI is not fully supported.


 SWI MIDI_TxSongSelect                  &404d9
 ---------------------------------------------
 Transmit a 'song select' on the previously selected port and channel.

 On entry
          R0  =     song number


 SWI MIDI_TxTuneRequest                 &404da
 ---------------------------------------------
 Transmit a 'tune request' on the previously selected port and channel.


 SWI MIDI_TxStart                       &404db
 ---------------------------------------------
 Transmit a 'start' on the previously selected port and channel.


 SWI MIDI_TxContinue                    &404dc
 ---------------------------------------------
 Transmit a 'continue' on the previously selected port and channel.


 SWI MIDI_TxStop                        &404dd
 ---------------------------------------------
 Transmit a 'stop' on the previously selected port and channel.


 SWI MIDI_TxSystemReset                 &404de
 ---------------------------------------------
 Transmit a 'system reset' on the previously selected port and channel.


 SWI MIDI_IgnoreTiming                  &404df
 ---------------------------------------------
 On entry
          R0  =     0 receive messages normally
                    1 ignore received timing messages

 This SWI is not fully supported.


 SWI MIDI_SynchSoundScheduler           &404e0
 ---------------------------------------------
 This SWI is not fully supported.


 SWI MIDI_FastClock                     &404e1
 ---------------------------------------------
 Read/set/control the fast clock.

 On entry
          R0        < 0  read fast clock
                    = 0  stop fast clock
                    = t  reset fastclock to r1 and transmit
                         timing clock message every t ms
          R1  =     time to reset fast clock to

 On exit
          R1  =     previous value of fast clock

 See also SWI MIDI_Interface.


 SWI MIDI_Init                          &404e2
 ---------------------------------------------
 Reset the MIDI module.

 On entry
          R0  =     0  reset to power-on state
                 or bit 0  set  clear tx running status
                    bit 1  set  clear receive buffers
                    bit 2  set  clear transmit buffers
                    bit 3  set  clear scheduler
                    bit 4  set  clear error
                    bit 30 set  special mode (ignored)
                    bit 31 set  special mode (ignored)
 On exit
          R1  =     no. of ports available


 SWI MIDI_SetBufferSize                 &404e3
 ---------------------------------------------
 Read/set the rx buffer sizes.

 On entry
          R0  =     0
          R1  =     new rx buffer size in bytes or 0 to read size

 On exit
          R0  =     buffer size in bytes
          R1  =     total amount of memory claimed

 This SWI is not fully supported.


 SWI MIDI_Interface                     &404e4
 ---------------------------------------------
 Allow access to the MIDI_ SWIs without the SWI calling overhead.

 On exit
          R0  =     module r12 value
          R1  =     address of SWI handler

 The SWI handler should be called in SVC mode with
          R0 .. R4  parameters (as described for each SWI)
          R11  =    SWI to call - &404c0 (eg. &01 for SWI MIDI_SetMode)
          R12  =    module r12 value
          R13       pointer to stack
          R14       return address


 The following feature is not supported by the 'official' MIDI module:

 This SWI also gives access to the fast_clock_increment routine, which
 may be used to drive the fast clock if you do not want the MIDI module
 to use timer1. If the SWI handler is at address X, the
 fast_clock_increment routine is at address X-4 - it should be called
 in IRQ mode, with interrupts disabled, and with the registers set up
 like this:
          R0   =    no. of ms to increment by
                    if R0 < 0, the fast clock will be set to -R0
          R12  =    module r12 value
          R13       pointer to stack
          R14       return address


 SWI MIDI_Driver                        &404ff
 ---------------------------------------------
 Install a driver using our own interface

 On entry
          R0        bits 0..7  =  0   (install rx driver)
                                  1   (remove rx driver)
                                  2   (read name of rx driver)
                                  4   (install tx driver)
                                  5   (remove tx driver)
                                  6   (read name of tx driver)
                    port number in bits 28..31
                    all other bits are reserved and must be 0
          R1 ->     rx/tx driver block (in RMA) (if R0=0,1,4,5)
          R2 =      r12 value (if R0=0,1,4,5)

 On exit
    if R0 = 0,1,4,5 on entry:
          R0  =     1 (OK)
                 or 0 (driver not installed/removed)

    if R0 = 2,6 on entry:
          R0  =     pointer to driver name
                 or 0 if no driver is installed


 ---------------------------------------------------------------------
 RX driver block

 The rx driver block and code must be stored in RMA. The format of
 the driver block is:

          +0     flags, must be 0
          +4     pointer to service code
          +8     pointer to rx code
          +12    pointer driver name (0-terminated)

 The service code is called with:
          R0  =  reason code
                 0  driver has been installed
                 1  driver is being removed
          R12 =  value passed in R2 when the driver was installed

 The rx code is called with:
          R0  =  byte or command
                 status/data byte 0 in bits 0..7
                 status/data byte 1 in bits 8..15
                 status/data byte 2 in bits 16..23
                 no. of status/data bytes in bits 24..25
                 port number in bits 28..31
          R1  = time (if fast clock is running) or 0
          R12 = value passed in R2 when the driver was installed

  mode=IRQ, IRQ off, FIQ on
  On exit, R0-R5 and R12 may be corrupt


 TX driver block

 A TX driver block is similar to a RX driver block:

          +0     flags, must be 0
          +4     pointer to service code
          +8     pointer to tx code (not used)
          +12    pointer driver name (0-terminated)
