home *** CD-ROM | disk | FTP | other *** search
/ Large Pack of OldSkool DOS MOD Trackers / trjoy094.zip / TECH.DOC < prev    next >
Text File  |  1995-01-09  |  32KB  |  801 lines

  1. ┌───────────────────────────────────────────────────────────────────────────┐
  2. │ TRACKJOY - Gravis Ultrasound Tracker by RSC                               │
  3. │ (c) Copyright 1993, 1994, 1995 Tomi Joy                                   │
  4. │ All rights reserved                                                       │
  5. │ Programming & documentation: Tomi Joy                                     │
  6. │                                                                           │
  7. │ TECHNICAL DOCUMENTATION for programmers                                   │
  8. │                                                                           │
  9. │ *** NOTE: This is not supposed to be a particularly pretty                │
  10. │           document, but is does supply some useful and                    │
  11. │           possibly interesting information.                               │
  12. │                                                                           │
  13. │ Specs are theoretically for Trackjoy version 1.00,                        │
  14. │ which is technically equivalent to all the                                │
  15. │ less than or equal to 1.00 beta versions.                                 │
  16. │ The file format specifications currently cover                            │
  17. │ *file* versions 1.0 and 1.1, the only difference being                    │
  18. │ in the way four bytes in then sample controllers are used.                │
  19. │                                                                           │
  20. └───────────────────────────────────────────────────────────────────────────┘
  21.  
  22.  ■ Note: You might see some references to a program called Instrument 
  23.    Maker in this document. IM is the sample editor which will be 
  24.    included in future versions of Trackjoy. At the moment it doesn't 
  25.    support 16-bit samples and has some severe bugs, so I didn't want to 
  26.    release it yet.
  27.  
  28.  ■ I don't promise that the information in this document is correct 
  29.    and/or up-to-date.
  30.  
  31.  ─────────────────────────────────────────────────────────────────────────────
  32.   Table of contents
  33.  ─────────────────────────────────────────────────────────────────────────────
  34.  
  35.  
  36.  1. Overview
  37.  2. The Gravis Ultrasoud
  38.  3. Trackjoy system requirements + other information
  39.  4. Trackjoy music storage & playing definitions
  40.  5. File formats (.TJS, .JOY, .BLK, samples)
  41.  6. Compression schemes
  42.  7. The interrupt interface
  43.  8. The sound effect interface
  44.  
  45.  
  46.  ─────────────────────────────────────────────────────────────────────────────
  47.   1.  Overview
  48.  ─────────────────────────────────────────────────────────────────────────────
  49.  
  50.  The heart of Trackjoy is the playing engine. It's a relatively simple
  51.  group of functions, one of which is hooked to the timer interrupt vector
  52.  08h. This function increments counters and checks for the next notes to
  53.  play. It also checks when to damp voices down with the Ultrasound's
  54.  volume ramping register. This is done to avoid clicking when samples
  55.  are abruptly cut off. The damping timing can be adjusted to some extent.
  56.  
  57.  The other functions associated with the playing engine simply fetch
  58.  the note, volume and instrument (and special command) data from the
  59.  storage array. One of the functions does the opposite of damping the
  60.  voices, ie. it lights them if the time is ripe.
  61.  
  62.  Normally when an 80x86 is booted up, the timer interrupt vector points
  63.  to a routine which increments the time and date counters in the PC's
  64.  memory. The frequency at which this is done is approximately 18.2 Hz.
  65.  Unfortunately this gives rise to a problem: Trackjoy needs a 100 Hz
  66.  timer for the player engine, so the timer has to be re-programmed.
  67.  Obviously if we still keep on chaining back to the old service
  68.  routine after the player has done with an interrupt, time is going to
  69.  go too fast. If, on the other hand, we don't chain to the previous
  70.  vector at all, time is going to *stop*. Now we don't want that either.
  71.  The solution (although not a very pleasing one) is to call the old
  72.  routine only every now and then.
  73.  
  74.  Trackjoy uses a 500 Hz hardware timer, but uses only every fifth tick 
  75.  (100 Hz) to do anything to the music score.
  76.  
  77.  Data bytes recognized by Trackjoy are the note, volume, instrument
  78.  bytes. On so-called FULL channels 3 more bytes are used: the command 
  79.  and its two parameters. Notes are very straight forward: the value 0 is 
  80.  C-0, 1 is C#0 and so on. When *any* of the data bytes has the falue 255 
  81.  or FFh, it's an *empty* byte and is represented by dots on the Trackjoy
  82.  editing screen.
  83.  
  84.  Semitones are supposed to be about 2^(1/12) * the previos note. ("The 
  85.  twelth root of two" equals "two to the power of one twelth".) In 
  86.  decimal this is about 1.05946. In other words, the frequency of any 
  87.  note in an octave is basic_frequency * 1.05947 ^ (number_of_note). To 
  88.  raise a note to an octave multiply it by 2 ^ (number_of_octave).
  89.  
  90.  Actually, that is *not* exacty what Trackjoy does. It looks up notes
  91.  from a table, since it's much quicker *and* it avoids using floating
  92.  point math that way.
  93.  
  94.  
  95. ────────────────────────────────────────────────────────────────────────────
  96.  2. The Gravis Ultrasound
  97. ────────────────────────────────────────────────────────────────────────────
  98.  
  99.  Let's be blunt: the Gravis Ultrasound card is a bugger to program.
  100.  Consider these "features" of the card from the programmer's point
  101.  of view.
  102.  
  103.    1. 16-bit samples can't be played across 256k boundaries
  104.       (Memory is segmented as 1 to 4 256k banks)
  105.  
  106.    2. With 32 voices in use, the maximum output frequency is only
  107.       19293 Hz, and 44.1 kHz is achieved only with 14 voices.
  108.  
  109.    3. The frequency the card produces with a certain frequency 
  110.       controller register value (and the speed at which volume ramping 
  111.       is done) depends on the number of active voices in use.
  112.  
  113.    4. Without significant programming effort, clicking is a real 
  114.       problem. The click is caused by suddenly changing the DAC value by 
  115.       a large degree. To remove it, you have to do a lot of careful 
  116.       volume ramping register programming.
  117.  
  118.    5. It only has 16 stereo pan positions. This isn't enough, because
  119.       the say in the official GUS documentation that it causes clicking.
  120.  
  121.    6. Certain registers (the self-modifying ones) have to be updated 
  122.       twice before you can be sure the card got the message.
  123.  
  124.  ─────────────────────────────────────────────────────────────────────────────
  125.   3. Trackjoy system requirements + other information
  126.  ─────────────────────────────────────────────────────────────────────────────
  127.  
  128.   Trackjoy was programmed in C and assembler
  129.  
  130.   System requirements:
  131.         - 80286+
  132.         - EGA, although VGA is supported
  133.         - Ultrasound card (256k will do)
  134.         - about 300k free low memory
  135.         - hard disk stronly recommeneded
  136.  
  137.    
  138.  ────────────────────────────────────────────────────────────────────────────
  139.   4. Trackjoy music storage & playing definitions
  140.  ────────────────────────────────────────────────────────────────────────────
  141.  
  142.  4.1 Music score is divided into patterns.
  143.  
  144.  4.2 Pattern length (1-255 rows) and structure (ie. width and type
  145.      for each channel) can vary
  146.  
  147.  4.3 Patterns consist of channels (max. 17 channels) Actual voice
  148.      channels are limited to sixteen in order to retain acceptable sound 
  149.      quality with the GUS. In practice this will be quite enough for 
  150.      almost any purpose. The 17th channel is an optional global channel 
  151.      that controls all channels.
  152.  
  153.  4.4 Three channel types are supported. They are:
  154.  
  155.      Stripped: Only note, instrument & volume information
  156.      Full:     Note, instrument, volume & special effect info
  157.      Global:   Global volume & special effect information (max one per pattern)
  158.  
  159.      (The CHORD type was omitted due to programming difficulties, not 
  160.      actually needing it and most important of all ─ laziness.)
  161.  
  162.  4.5 Notes: C-0 to B-9 (could in theory go to D-21, but that wouldn't be
  163.      practical)
  164.  
  165.  4.6 Instruments: Normal 8- and  16-bit samples will be supported in version
  166.      1.0. Version 1.1 might add ADSR support to these samples. Sorry, no
  167.      GF1 patch support.
  168.  
  169.  4.7 Channel sample volume: 0 - 254. This will be from a table, since 
  170.      the US's volume 0-4095 is logarithmic instead of linearic.
  171.  
  172.  4.8 Special effects (Full channels)
  173.  
  174.      (Look for these in the next version)
  175.  
  176. 4.10 Data requirements (in bytes per row per channel):
  177.  
  178.      Stripped channels.... 3 bytes
  179.      Full channels........ 6 bytes
  180.      Global channels...... 4 bytes
  181.  
  182.      If simple silence packing is implemented, this will be a lot less 
  183.      in most instances. It probably won't, though, so no need to get 
  184.      excited.
  185.  
  186. ──────────────────────────────────────────────────────────────────────────────
  187. 5. File format (Trackjoy saves and loads both songs and modules)
  188. ──────────────────────────────────────────────────────────────────────────────
  189.  
  190. Trackjoy music file format version 2.0 (It *should* be impossible
  191. to come across a version 1.X file, since this ─ the very first ─
  192. release of Trackjoy writes file version 2.0)
  193.  
  194. Format of song (.TJS) and module (.JOY)
  195.  
  196. ────────────────────────────────────────────────────────────────────
  197. OFFSET:       PURPOSE:
  198. ───────       ──────────────────────────────────────────────────────
  199. 0-7           8 bytes: "TRACKJOY"
  200. 8             1 byte: 0=song, 1=module
  201. 9             1 byte: file version, 20 decimal (20 means 2.0)
  202. 10            2 bytes (reserved, but Trackjoy writes 0x99 and 0x52)
  203. 12            1 word: default tempo
  204. 14            1 word: tempo modifier (not used)
  205. 16            1 word: master volume (max. 256)
  206. 18            1 word: volume modifier (not used)
  207. 20            1 byte: transpose
  208. 21            1 byte (reserved)
  209. 22            1 word: number of directory entries
  210.               Trackjoy can't write more than 196 (128 patterns,
  211.               64 samples + 4), and even this is more than anybody is 
  212.               usually going to use.
  213.  
  214. 24            Directory
  215.               [1 DWORD:PTR][1 BYTE:TAG][1 BYTE:UNUSED]
  216.  
  217.               <number of dir entries> of these
  218.  
  219.               The DWORD is a real byte-precision pointer to the object. 
  220.               Objects will start at even byte offsets.
  221.  
  222.               The first byte (tag) in a directory entry defines the 
  223.               object pointed to.
  224.  
  225.               Tags
  226.  
  227.               0 ─ Writer information (text)
  228.               1 ─ Song name
  229.               2 ─ Song composer
  230.               3 ─ Song comment
  231.               4 ─ Pan positions
  232.               5 ─ Song order list
  233.               6 ─ Pattern
  234.               7 ─ Sample parameter block (no sample data)
  235.               8 ─ Sample parameter block + sample data
  236.  
  237.               All objects in the directory are sorted in ascending
  238.               order by tag, ie., if song name exists, it will always
  239.               be before song composer etc.
  240.  
  241.               The patterns come in the order in which they will be
  242.               in memory. The order of sample depends on the sample
  243.               slot (sample number) they go into, but Trackjoy writes 
  244.               them in ascending order (by sample number).
  245.  
  246.               Trackjoy will always write the order first, then all the 
  247.               actual patterns and finally sample parameter blocks (with 
  248.               or without samples). Files written by Trackjoy can be read 
  249.               according to the directory almost sequentially to minimise 
  250.               the necessity for random access. However, it is legal for 
  251.               any of the objects to reside anywhere in the file.
  252.  
  253.               Please remember that all objects start at even byte
  254.               addresses, so there will be some padding bytes around
  255.               in the file.
  256.  
  257.               Note that each song and module has at least one pattern 
  258.               and the order array. There may not be any instruments, and 
  259.               the song information text strings are optional.
  260.  
  261.               The only difference between a song and a module is
  262.               the byte at offset 8 from the file's beginning and
  263.               that in modules, the samples have tag 8 instead of 7.
  264.               Of course, the *format* allows both types of sample in 
  265.               either song or module, but Trackjoy doesn't support this 
  266.               at least at the moment.
  267.  
  268.               Anything with a tag greater than 8 will promptly be
  269.               ignored by Trackjoy.
  270.  
  271. From here on, offsets will be relative to the beginning of the object in 
  272. question.
  273.  
  274. Format of writer information, song name, song composer and song comment:
  275.  
  276. 0             1 word: length of string
  277. 2             data
  278.  
  279.               Trackjoy will ignore parts of strings exceeding 80 bytes.
  280.               Trackjoy currently does not write "writer information"
  281.               at all.
  282.  
  283. Format of pan positions
  284.  
  285. 0             1 word: length of string, Trackjoy currently writes 18
  286. 2             Byte array. The value 0 means left, 100 means right.
  287.  
  288. Format of sample parameter block
  289.  
  290. 0             1 byte: sample number (the instrument number in patterns)
  291. 1             name: 30            (ASCIIZ)
  292.               filename: 13        (ASCIIZ)
  293.               type: 1             (0,1,2)
  294.               playmode: 1
  295.               allocated-flag: 1   (used internally by Trackjoy)
  296.               loop_beg: 4 (dw)
  297.               loop_end: 4 (dw)
  298.               length: 4 (dw)
  299.               gus_off: 4 (dw)     (used internally by Trackjoy)
  300.               freq: 2             (default 4000)
  301.               sampvolume: 2       (max. 256)
  302.               padding: 2  *** Not currently used ***
  303.               
  304.               Some sample (slot) numbers may not appear at all, so just 
  305.               leave the left-over slots empty.
  306.  
  307.  
  308. The format of a "sample parameter block + sample data" is exactly
  309. the same as "sample parameter block" except that is is followed
  310. by exactly <length> bytes of sample data, whether 8- or 16-bit.
  311. <Length> is found within the parameter block.
  312.  
  313.  
  314.  
  315. Format of pattern:
  316.  
  317. 0             1 word: rows (Trackjoy's maximum is 256, and
  318.               the absolute maximum is 512)
  319. 2             1 byte: width in channels (for first pattern)
  320. 3             1 byte (reserved)
  321. 4             1 byte: compression scheme (0=None, 1=Silence)
  322. 5             33 bytes = format array (SEE NOTE BELOW)
  323. 38            1 word = actual length of written pattern data
  324.               (length of uncompressed final pattern is computed
  325.               from the format array, the width and the number
  326.               of rows)
  327.  
  328. 40            value at [38] bytes of pattern data, compressed
  329.               or uncompressed
  330.  
  331.  
  332. Format of order array:
  333.  
  334. 0             1 word: length (always 128)
  335. 2             128 bytes: pattern play order array, FFh = empty
  336.  
  337.  
  338. *** NOTE: Each byte of the format array indicates what type of channel is at
  339.           that index. The value 0 is for FULL channels, 1 for STRIPPED 
  340.           and 2 for GLOBAL channels. There are 33 bytes because TRACKJOY 
  341.           is built so that it can (by modifying a #define directive) be 
  342.           made to operate on max. 33 channels.
  343.  
  344.  
  345.  
  346. Pattern compression:
  347.  
  348. Three byte values are reserved for special purposes. They are,
  349. in decimal, 233, 231 and 237. These values were chosen because
  350. they are bigger than valid note, instrument or special command
  351. values and are fairly unlikely to be entered as volumes by the
  352. user.
  353.  
  354. Byte/byte pair  Interpretation
  355.  
  356. 231             Repeat FFh twice
  357. 233             Repeat FFh three times
  358. 237,0           231
  359. 237,1           233
  360. 237,2           237
  361. 237,n when n>2  Repeat FFh n+1 times
  362.  
  363. In other words, 231 and 233 are always alone. 237 is always
  364. followed by another byte. The actual values 231 and 233 are
  365. encoded through 237. This ensures that the worst compression
  366. ratio when compressing strips of FFh longer than 1 byte will
  367. be 1:2. The best is 1:128. FFh is by far the most common
  368. byte in Trackjoy patterns. It is not worth bothering about
  369. other values, as the extra_compression / annoyance_of_
  370. extra_programming factor is very low indeed, not to mention
  371. that happiness_of_Tomi = 1 / Time_spent_in_extra_programming.
  372.  
  373. Note that pattern data is compressed COLUMN BY COLUMN,
  374. not row by row. This yields significantly better compression ratios
  375. than row-by-row compression, since the way data is entered into
  376. a pattern is more uniform vertically than horizontally.
  377.  
  378. Example pattern:
  379.  
  380.        Let X be the width (in 1-byte parameter columns like <note>, 
  381.        <ins> or <special command>) of the current pattern, and
  382.        let there be 3 rows in our pattern.
  383.  
  384.        ┌─┬─┬─┬─┬─┬─┬─┬─┬─── ─ ─
  385.     0+ │0│1│2│3│4│5│6│7│...
  386.        ├─┼─┼─┼─┼─┼─┼─┼─┼─── ─ ─
  387.     X+ │A│B│C│D│E│F│G│H│...
  388.        ├─┼─┼─┼─┼─┼─┼─┼─┼─── ─ ─
  389.    2X+ │L│M│N│O│P│Q│R│S│...
  390.        └─┴─┴─┴─┴─┴─┴─┴─┴─── ─ ─
  391.  
  392. In this pattern, you would compress or uncompress in order 
  393. 0,A,L,1,B,M,2,C,N,3... What type of field you are compressing doesn't 
  394. matter, but knowing the pattern width is important. Note that 
  395. compression from column to column (for instance, from P to 5) is 
  396. allowed. This compression scheme will of course only allow compression 
  397. of strips max. 256 times FFh in length, at a time.
  398.  
  399. Uncompression example:
  400.  
  401. The string
  402. <16><12><255><12><255><12><233><13><237><3><237><1>
  403.  
  404. uncompresses to
  405.  
  406. <16><12><255><12><255><12><255><255><255><13>
  407. <255><255><255><255><233>.
  408.  
  409. For obvious reasons, things like
  410.  
  411. <231><231>
  412. <231><233>
  413. <231><237><64>
  414. <233><255>
  415.  
  416. should never appear in the middle of a column. However, they are
  417. perfectly correct and readable, and may occur at the very last column
  418. of a pattern. Within a column, there are of course more logical ways of 
  419. compressing these oddities. However, <237><255> followed by <255>, 
  420. <231>, <233> or another <237><n> may appear anywhere if 257, 258 or more 
  421. FFh's are compressed.
  422.  
  423. For technical reasons, Trackjoy actually rotates and flips a pattern's
  424. data before compression, ie. a pattern is treated as a rectangular
  425. byte block with a width of <columns> and height of <rows>.
  426. Ie.,
  427.  
  428. abcd              aei
  429. efgh    becomes   bfj   which is like a 90° degree rotate clockwise
  430. ijkl              cgk   and a flip horizontal.
  431.                   dhl
  432.  
  433. After the 90 degree rotate (and flip) a normal run-length crunching 
  434. algorithm is used, and the output is saved to disk with the correct 
  435. parameters. This is the easiest way to do it :)
  436.  
  437.  
  438. 5.2 Trackjoy block file format
  439.  
  440.  
  441. Format of block file (.BLK)
  442. ────────────────────────────────────────────────────────────────────
  443. OFFSET:       PURPOSE:
  444. ───────       ──────────────────────────────────────────────────────
  445. 0             11 bytes: "ÖRÖRÖRÖRÖR!"
  446.               To understand why these first eleven bytes are 
  447.               "ÖRÖRÖRÖRÖR!", you really have to be an insider. Sorry 
  448.               about that. (According to some not-very-reliable sources, 
  449.               "ÖRÖRÖRÖRÖR!", derived from the verb "öristä", is the 
  450.               closest ASCII equivalent of the the sound emitted from a 
  451.               Class A Finnish "puliukko" on discovering that he has ─ in 
  452.               one way or an other ─ lost contact with his best friend ─ 
  453.               the bottle of "Kossu". The puliukko is a species of 
  454.               red-nosed scraggy-looking being completely pickled in 
  455.               alcohol and found in abundance in the parks of Helsinki. 
  456.               Örörörörörörör!)
  457.  
  458. 11            word: left
  459. 13            word: top
  460. 15            word: right
  461. 17            word: bottom
  462. 19            word: length
  463. 21            block data in linear uncompressed full channel format 
  464.               (ie., channel 1 row 0 is right after channel 0 row 0)
  465.               channel 0 row 0) END
  466.  
  467. 5.3 Sample formats
  468.  
  469. 5.3.1 Raw 8-bit PC8
  470.  
  471. This is the unsigned typical PC sample type with no header.
  472. Each sample is simply a value from 0 to 255, and +128 represents
  473. an output voltage of zero. It needs to be converted to signed
  474. format for most purposes including volume scaling and playing
  475. with the Ultrasound.
  476.  
  477. 5.3.2 Signed raw 8-bit A8
  478.  
  479. This is the same as PC8 except that it is in signed two's
  480. complement format. The values are signed integers from
  481. -128 to +127, zero naturally represents an output volume
  482. of zero.
  483.  
  484. 5.3.3 Unsigned raw 16-bit S16
  485.  
  486. This is the 16-bit format Trackjoy currently reads. Samples are unsigned 
  487. 16-bit integers (words) with 32768 representing the output voltage of 
  488. zero. Also this format is converted to signed 16-bit (by flipping bit 
  489. 15) before loading into the Ultrasound's memory. The byte order is 
  490. low-high, ie. the least significant 8 bits of the value occupy the lower 
  491. address. This is the Intel back-words integer storage format.
  492.  
  493.  
  494. 5.3.4 Trackjoy headered sample format
  495.  
  496. Format of TJINSX headered sample, version 1.1
  497. ────────────────────────────────────────────────────────────────────
  498. OFFSET:       PURPOSE:
  499. ───────       ──────────────────────────────────────────────────────
  500. 0             5 bytes: "TJINS"
  501. 5             1 byte: version number, 0Bh (11 decimal = 1.1)
  502.               *** Ignore any files with this byte less than 0Bh.
  503. 6             16 bytes: "XXXXXXXXXXXXXXXX", reserved for future
  504.               use, of course
  505. 22            sample information, precisely same format
  506.               as in songs and modules (See song & module formats,
  507.               offset x+1 or definition of "sampleinfo" structure)
  508. 90            sample data in signed format, low-high byte order
  509.               for 16-bit samples, can be dumped directly into
  510.               the Ultrasound and then played
  511. END
  512.  
  513.  
  514.  
  515. 5.3.5 Scream Tracker III / Digiplayer sample format
  516.  
  517. Trackjoy will read the basic Scream Tracker III sample format (8-bit 
  518. mono), and Instrument maker will, in addition to reading these files, 
  519. also write them. For a definition of the Scream Tracker III / Digiplayer 
  520. sample format, consult the TECH.DOC file included in the public release 
  521. package of Scream Tracker III.
  522.  
  523.  
  524. ─────────────────────────────────────────────────────────────────────────────
  525.  7. The interrupt interface
  526. ─────────────────────────────────────────────────────────────────────────────
  527.  
  528.  Trackjoy supports an interrupt interface for other programs to control 
  529.  music (or sound effect) output. The interface can also be used for 
  530.  synchronising other programs with the player engine. TRACKJOY can
  531.  hook itself to one of the interrupts between 60H ─ 66H, namely int 61h.
  532.  
  533.  When the interface (int 61h) is called, AL contains the function 
  534.  number. AL doesn't return a value. (W) means AH and BX contain 
  535.  information to pass to TRACKJOY (functions 0h - Fh). (R) means another 
  536.  program reads information from TRACKJOY, which returns it in the other 
  537.  registers (AH, BX, CX and in a few cases, DX). Pointers and long ints 
  538.  are dwords and are returned in the register pair BX:CX.
  539.  
  540.  The interrupt can be called either from an assembly language program by 
  541.  simply setting the registers to the desired values or through one of 
  542.  the interrupt interfaces supplied with your high-level compiler. 
  543.  (Syntax for popular C-compilers for MS-DOS offer the following 
  544.  interface:
  545.  
  546.  #include <dos.h>
  547.  ...
  548.  
  549.  call_trackjoy(void)
  550.  {
  551.         union REGS inregs, outregs;
  552.         unsigned interrupt_number = 0x61;
  553.  
  554.         inregs.h.al = 0x10; /* call "READ MUSIC CONTROL" */
  555.         int86(interrupt_number, &inregs, &outregs);
  556.  
  557.         /* Data returned is in outregs.h.ah, outregs.h.bl,
  558.            outregs.h.cl and outregs.h.ch, in this case. */
  559.         ...
  560.  }
  561.  ...)
  562.  
  563.  
  564.  These are the functions that are supported:
  565.  
  566.  ==============================================================================
  567.  WRITE COMMANDS 00h - 09h, 20h - 2Fh
  568.  ==============================================================================
  569.  
  570.  AL==00h  (W)  MUSIC CONTROL
  571.  
  572.         AH = Select function: 0 = none, 1 = play/stop, 2=pause/play
  573.  
  574.         1: play/stop - If BL == 0 TRACKJOY will stop
  575.         2: play/pause - If BL == 0 TRACKJOY will deep-freeze.
  576.            Ie., the timer interrupt is un-hooked from TRACKJOY,
  577.            the timer is set to 18.2 Hz and all the GUS accumulators
  578.            are frozen. This is equivalent to a pause state.
  579.            BL == 1 melts TRACKJOY...
  580.  ------------------------------------------------------------------------------
  581.  
  582.  AL==01h  (W)  MASTER VOLUME
  583.  
  584.         AH = new master volume (0-255)
  585.  ------------------------------------------------------------------------------
  586.  
  587.  AL==02h  (W)  CHANNEL CONTROL
  588.  
  589.         AH = number of channel
  590.         if CL == 1 TRACKJOY will mute channel <AH>
  591.  ------------------------------------------------------------------------------
  592.  
  593.  AL==03h  (W)  TRANSPOSE
  594.  
  595.        AH = notes to transpose (if bit 7 set, transpose down)
  596.  ------------------------------------------------------------------------------
  597.  
  598.  AL==04h  (W)  PITCH BEND
  599.  
  600.        new_global_pitch = global_pitch * BX / 1000;
  601.  ------------------------------------------------------------------------------
  602.  
  603.  AL==05h  (W) SET PITCH
  604.  
  605.        BX = global pitch
  606.  ------------------------------------------------------------------------------
  607.  
  608.  AL==06h  (W) SET GLOBAL TEMPO
  609.  
  610.        BX = new global tempo
  611.  ------------------------------------------------------------------------------
  612.  
  613.  
  614.  AL==07h  (W) FORCE TRACKJOY TO PLAY A PATTERN
  615.  
  616.       AH = pattern to play (0 = first)
  617.  ------------------------------------------------------------------------------
  618.  
  619.  
  620.  AL==08h  (W) JUMP ROW
  621.  
  622.       AH = row to jump to in current pattern (0 = first)
  623.  ------------------------------------------------------------------------------
  624.  
  625.  AL==09h  (W) END "P" COMMAND POLLING
  626.       If TRACKJOY is polling for keyboard input (invoked by the
  627.       "P" pattern command), issuing this command will make TRACKJOY
  628.       continue to play the current pattern.
  629.  
  630.       *** NOTE: This command is read from AL==1Eh, *NOT* AL==19h!
  631.  
  632.  ------------------------------------------------------------------------------
  633.  
  634.  AL==20h  (W) PLAY NOTE
  635.  
  636.       AH = number of sample
  637.       BL = note
  638.       BH = GUS channel to play through
  639.  
  640.  ==============================================================================
  641.  READ COMMANDS 10h - 1Fh, 30h
  642.  ==============================================================================
  643.  
  644.  
  645.  AL==10h  (R)  MUSIC CONTROL
  646.  
  647.         If AH bit 0 is OFF, music is stopped
  648.         If TRACKJOY is running, BL == 'T' (54h) and  BH == 'J' (4Ah)
  649.         CL = minor version number
  650.         CH = major version number
  651.                 If DL bit 0 is ON, Trackjoy is paused
  652.  ------------------------------------------------------------------------------
  653.  
  654.  AL==11h  (R)  MASTER VOLUME
  655.  
  656.         AH = master volume
  657.  ------------------------------------------------------------------------------
  658.  
  659.  AL==12h  (R)  CHANNEL CONTROL
  660.  
  661.     (w) AH = number of channel
  662.         BL = 1 for a short period, if a note was turned on
  663.         BH = state of voice (1 = GUS is playing voice, 0 = stopped)
  664.         CL = state of channel (1 means muted)
  665.  
  666.  ------------------------------------------------------------------------------
  667.  
  668.  AL==13h  (R)  TRANSPOSE
  669.  
  670.        AH = semitones transposed (if bit 7 set, transposed down)
  671.  ------------------------------------------------------------------------------
  672.  
  673.  AL==14h  (RESERVED, Pitch Bend can't be read. Use AL==15h instead)
  674.  ------------------------------------------------------------------------------
  675.  
  676.  
  677.  AL==15h  (R) READ PITCH
  678.  
  679.        BX = global pitch
  680.  ------------------------------------------------------------------------------
  681.  
  682.  AL==16h  (R) READ GLOBAL TEMPO
  683.  
  684.        BX = global tempo
  685.  ------------------------------------------------------------------------------
  686.  
  687.  
  688.  AL==17h  (R) READ CURRENT PATTERN AND ORDER
  689.  
  690.       AH = current pattern (0 = first)
  691.       BX:CX points to order string (128 bytes)
  692.       DL = current order
  693.  ------------------------------------------------------------------------------
  694.  
  695.  AL==18h  (R) READ CURRENT ROW
  696.  
  697.       AH = current row in pattern (0 = first)
  698.       BL = rows in current pattern
  699.  
  700.  ------------------------------------------------------------------------------
  701.  
  702.  AL==19h  (R) GET "sampleinfo" STRUCTURE ARRAY ADDRESS
  703.  
  704.       struct sampleinfo sample[SAMPLES];
  705.       BX:CX equals &sample[0]
  706.  ------------------------------------------------------------------------------
  707.  
  708.  AL==1Ah  (R) GET "gdram" STRUCTURE ADDRESS
  709.  
  710.       struct gus_dram gdram;
  711.       BX:CX equals &gdram
  712.  ------------------------------------------------------------------------------
  713.  
  714.  AL==1Bh  (R) GET NAME ASCIIZ ADDRESS
  715.  
  716.       char name[80];
  717.       BX:CX equals &name
  718.  ------------------------------------------------------------------------------
  719.  
  720.  
  721.  AL==1Ch  (R) GET COMPOSER ASCIIZ ADDRESS
  722.  
  723.       char composer[80];
  724.       BX:CX equals &composer
  725.  ------------------------------------------------------------------------------
  726.  
  727.  AL==1Dh  (R) GET COMMENT ASCIIZ ADDRESS
  728.  
  729.       char comment[80];
  730.       BX:CX equals &comment
  731.  ------------------------------------------------------------------------------
  732.  
  733.  AL==1Eh  (R) CHECK PATTERN POLLING STATE
  734.       If AH==1, TRACKJOY is waiting for a interrupt with AL==09h
  735.       to continue with the current pattern. This state is invoked
  736.       with the "P" pattern command.
  737.  
  738.       *** NOTE: This command is written to AL==09h, *NOT* AL=0Eh!
  739.  ------------------------------------------------------------------------------
  740.  
  741.  AL==1Fh   (R) READ ERROR LOG
  742.  
  743.       If AH != 0, TRACKJOY has an error to report
  744.       BX:CX points to the error message string
  745.  ------------------------------------------------------------------------------
  746.  
  747.  AL==30h   (R) READ TIMER
  748.       BX:CX = (unsigned long) timer ticks from start of play
  749.       DX = (unsigned int) timer frequency
  750.  
  751.  ------------------------------------------------------------------------------
  752.  
  753. This is the format of the SAMPLEINFO structure. It controls the audio 
  754. samples TRACKJOY uses as instruments.
  755.  
  756. *** NOTE: The constant SAMPLES = 64.
  757.  
  758. struct sampleinfo {      /* sample information */
  759.         char name[30];   /* sample description */
  760.         char file[13];   /* sample filename */
  761.         char type;       /* file type (16/PC8/A8) flag */
  762.         char playmode;   /* this is what's actually squirted into the GUS */
  763.         char acd;        /* allocated flag */
  764.         long loopbeg;    /* loop beginning */
  765.         long loopend;    /* loop end */
  766.         long length;     /* sample length (bytes) */
  767.         long gusoff;     /* offset in GUS memory */
  768.         int freq;        /* sample frequency */
  769.         unsigned vol;    /* sample volume */
  770.         unsigned pad;    /* padding */
  771. };
  772.  
  773. Storage definition in TRACKJOY.C:
  774. struct sampleinfo sample[SAMPLES];
  775.  
  776.  
  777. This is the format of the GUS_DRAM structure:
  778.  
  779. struct gus_dram {                       /* memory control block */
  780.         unsigned long used;             /* how much memory is allocated */
  781.         unsigned long beg[SAMPLES];     /* beginning of a block */
  782.         unsigned long length[SAMPLES];  /* length of a block */
  783.         char stat[SAMPLES];             /* status. 0 = empty, 1 = allocated,
  784.                                                    2 = free */
  785.         int c;                          /* number of blocks */
  786. };
  787.  
  788. *** NOTE:  Status 0 (empty) always means the free hunk of memory from
  789.            the end of the last allocated block to the end of memory.
  790.            Status 1 means the block in use, and status 2 means the
  791.            block has been freed, and can be re-used. Status 2 blocks
  792.            only exist before allocated blocks of memory. (A Status 2
  793.            block at the end of allocated memory is always converted to
  794.            status 0 when the block is freed.)
  795.         
  796. Storage definition in TRACKJOY.C:
  797. struct gus_dram gdram[4];
  798.  
  799. Each gdram in the above array is for a 256k Ultrasound memory bank.
  800.  
  801.