components/prboom/mmus2mid.c
//
// TWriteVarLen()
//
// write the ULONG value to tracknum-th track, in midi format, which is
// big endian, 7 bits per byte, with all bytes but the last flagged by
// bit 8 being set, allowing the length to vary.
//
// Passed the Allegro MIDI structure, the track number to write,
// and the ULONG value to encode in midi format there
//
// Returns 0 if sucessful, MEMALLOC if a memory allocation error occurs
//
TWriteVarLen()
write the ULONG value to tracknum-th track, in midi format, which is
big endian, 7 bits per byte, with all bytes but the last flagged by
bit 8 being set, allowing the length to vary.

Passed the Allegro MIDI structure, the track number to write,
and the ULONG value to encode in midi format there

Returns 0 if sucessful, MEMALLOC if a memory allocation error occurs
TWriteVarLen () write the ULONG value to tracknum - th track in midi format which is big endian 7 bits per byte with all bytes but the last flagged by bit 8 being set allowing the length to vary . Passed the Allegro MIDI structure the track number to write and the ULONG value to encode in midi format there Returns 0 if sucessful MEMALLOC if a memory allocation error occurs
static int TWriteVarLen(MIDI *mididata, int tracknum, register ULONG value)
{
  register ULONG buffer;
  buffer = value & 0x7f;
  while ((value >>= 7))         
  {
    buffer <<= 8;               
    buffer |= 0x80;             
    buffer += (value & 0x7f);
  }
  while (1)                     
  {
    if (TWriteByte(mididata, tracknum, (UBYTE)(buffer&0xff))) 
      return MEMALLOC;
    if (buffer & 0x80)
      buffer >>= 8;
    else                        
      break;
  }
  return 0;
}
static int TWriteVarLen ( MIDI * mididata , int tracknum , register ULONG value ) { register ULONG buffer ; buffer = value & 0x7f ; while ( ( value >>= 7 ) ) { buffer <<= 8 ; buffer |= 0x80 ; buffer += ( value & 0x7f ) ; } while ( 1 ) { if ( TWriteByte ( mididata , tracknum , ( UBYTE ) ( buffer & 0xff ) ) ) return MEMALLOC ; if ( buffer & 0x80 ) buffer >>= 8 ; else break ; } return 0 ; }
TWriteVarLen()
write the ULONG value to tracknum-th track, in midi format, which is
big endian, 7 bits per byte, with all bytes but the last flagged by
bit 8 being set, allowing the length to vary.
TWriteVarLen () write the ULONG value to tracknum - th track in midi format which is big endian 7 bits per byte with all bytes but the last flagged by bit 8 being set allowing the length to vary .
// terminates because value unsigned // note first value shifted in has bit 8 clear // all succeeding values do not // write bytes out in opposite order // insure buffer masked // terminate on the byte with bit 8 clear