Making Your Own MOD Files By Tony Morales INTRODUCTION One of the most exciting events in the history of IIgs music was the introduction of utilities to play Amiga-compatible MOD files. These utilities, with one exception, lacked one important feature--the ability to edit, and create, MOD files. The one exception, if you could call it that, was Noise Tracker GS' ability to import MODs and save them under it's own file format. The disadvantages of doing this were that you could not load the saved files back into any MOD player, and almost all of the special effects which MODs support would be lost during the conversion. The great thing about MOD files is that many other computers have utilities to play them. For example, you could download an Amiga MOD, play it on your IIgs, and take it to work and play it on your Mac or PC. No other music format on the IIgs is as universal as MOD files are, and there are thousands of them out there. Unless you happened to have an Amiga or PC sitting beside your IIgs, with the appropriate software, you had no way to create MODs, and become a part of the MOD-mania which is sweeping the various online services around the world. However, all things must come to an end at some point. Obviously, if you are reading this, you are familiar with GS MOD Monthly, the first IIgs MOD magazine. This magazine has featured new MODs, not previously available on any other computer. The great part is that they were created entirely on an IIgs. The first thing you are saying is, "How is this possible? Is there a MOD editor I don't know about?" Unfortunately, there is not an IIgs MOD editor at present, although this may change in the future. It turns out that with a small amount of effort, MOD files can be assembled by hand. That's right--by hand. The rest of this article will present theoretical perspectives on what exactly needs to be done to create a MOD file. WHAT YOU'LL NEED Before a carpenter builds a house, he must be equipped with the proper tools. The same thing is true for designing MODs. The first thing you'll need to have around is your copy of the MOD Tools disk, which you should already have if you are reading this. This disk will allow you to control the overall sound of your MOD when it is finished. The second thing you'll need to have is a copy of AudioZap, (not included on the MOD Tools disk). You can get it from any online service or your local user group. AudioZap is important because it's the only IIgs sound utility that can convert IIgs sound samples to the format used on the Amiga. The third, and final, thing you should have is a utility which can take several small binary files and combine them together, (in any order), into one large binary file. I currently know of only one program which can do this, Davex. Davex is a ProDOS 8 shell utility which sports a user interface similar to the MS-DOS shell. Davex's most powerful feature is it's support for external commands. Several commands come with the program, including, (you guessed it), a command to combine small files into large ones. Davex is available from any online service. It is, without a doubt, the best 8-bit shell for the Apple //e and IIgs. ABOUT MOD FILES Assuming you have the above utilities, or some means of performing the required file operations, we'll start with an overview of the MOD file format. Note that a much more expanded version of this format is found in another file on this disk. MOD files have 3 basic parts; a header, blocks of notes, and sound samples. The header consists of the title of the MOD, the instrument definitions, and the order in which to play the blocks of notes the MOD contains. PREPARING THE SAMPLES MODs can have up to 31 instruments. Naturally, you won't need to use all of them at once unless you choose to--any number of instruments will work. The first thing you should do is decide on which samples to use for your particular MOD. Next, you must save the samples as raw binary files, so there is no extraneous information in the file, (such as AIFF chunks). Important! All of the samples should have an even number of bytes in them. For example, a sample that uses 32000 bytes is fine, while a sample that uses 21847 bytes is not fine. Also, it is generally a good idea to round the sample lengths to a multiple of 100. While this last step is not absolutely required, many MOD-designers do this. When you have prepared your samples, you need to write down the individual lengths of each of them. You need this information when defining the instruments. Next, you must combine all the samples into one large file, which we will refer to as a wavebank. When this is done, you must load the wavebank into AudioZap. If you were to play this file, you would hear all your samples, one right after the other. Audiozap has an option to convert a sample into one usable on the Amiga. You need to select this option, and resave the converted wavebank over the original. For those who are curious, the method of encoding the bytes used on the Amiga is to exclusively OR each byte with $80. For you non-technical folks, 8-bit sound samples consist of volume intensities in the range $00 to $FF, (0 to 255 decimal). If you are unfamiliar with hexadecimal notation, you can think of the exclusive OR with $80 operation as the following. If the volume intensity is greater than or equal to 128, subtract 128. If the intensity is less than 128, add 128. For example, $7D would become $FD, (125 would become 253). As explained before, each byte in an 8-bit sample is a number from 0 to 255 that represents the volume level at that moment in the sample. After you have saved your wavebank samples in the Amiga format, it's time to define the instruments which correspond to the samples. For the following examples, you need to be in BASIC.System and in the Monitor. To get to the Monitor from BASIC, type: CALL -151 All of the following examples will use memory locations starting with $1000. It might help to have a printed copy of the MOD file format note to guide you through the examples. First, you need to prepare your MOD header. Each header is 1084 bytes long, so start by zeroing 1084 bytes of memory. Type: 00<1000.143BZ The first 20 bytes of every MOD contain the MOD's title. If you can't think of a title for your MOD right off hand, you can skip this step. To title your song, first clear bit 7 of the ASCII filter mask, (all MOD ASCII strings must have their high-order bit off). Do this by typing: 7F=F In the next example, "My first MOD," is an example title for the MOD. Type: 1000:"My first MOD" DEFINING AN INSTRUMENT Each instrument definition takes 30 bytes. All 31 definitions come directly after the MOD's title. The first definition starts at offset 20, the next at 50, and so on. Convert each base into hex, and add $1000, and you will have the address where the corresponding instrument definition begins. The following would calculate the address for instrument #1: (((1*30)+20)+$1000) = $1032 You could also look at the offsets in the file format note, convert these to hex, and add $1000 to get the instrument address. The first 22 bytes of an instrument definition is the instrument title. Some MODiots like to make a message, using all 31 instrument titles as a few words of the message. Some simply title the instrument with a description of the instrument. Of course, you can also skip titling your instruments if you wish. If you choose to title any or all of the 31 instruments, repeat the processes discussed above for titling the MOD. Be sure to use the correct addresses. This example would title instrument #1: 1032:"Instrument 1" After the title comes the length of the instrument/2. Here is a very important point which you need to be familiar with. Almost every other microprocessor, other than the 65xxx, stores byte pairs, (words), in memory with the high-order byte first, followed by the low-order byte. The 65xxx stores the low-order byte first, followed by the high-order byte. Suppose your first instrument was 32000 bytes long. Divide this in half to get 16000. Convert this to hex to get $3E80. Flip the bytes around to get $803E. The following shows how to enter this in memory: 1048:3E 80 The next byte is the semitone for that instrument. Values here range from $00 to $0F. I've never seen a MOD that uses anything other than $00, so you might wish to stick with this value. The next byte is the volume level for the instrument. Range is $00 to $40. Most instruments use $40, but you can use lower values if you want to. The next word is the loop offset for the instrument/2. For our 32000-byte instrument, if we wanted to loop at offset 12000, we would use a value of $7017, ($1770*2 = 12000). If you don't want to loop, set this field to 0. The last word in an instrument definition is the loop length/2. This value is the number of bytes to repeat, following the loop offset. To loop 100 bytes over and over from offset 12000, you would enter $3200, ($0032*2 = 100). If you don't have the instrument looping, you need to set this field to $0100, ($0001). To define the first instrument with all of the above information, you could enter the following: 1032:"Instrument 1" 1048:3E 80 00 40 17 70 00 32 COMPLETING THE HEADER Before we move on, two more fields must be added to the MOD header. The first of these is at offset 951, ($3B7). This byte should be set to $7F. This is for some old MOD players, which use this byte as the number of patterns to scan when loading. Setting this byte to $7F tells the players, (who care), to scan all patterns. This will enter the correct value: 13B7:7F The last thing that needs to be added is the Protracker signature. This signature tells MOD players that they are dealing with a Protracker-compatible MOD file. The Protracker signature is made up of 4 letters. The following will enter the signature, which begins at offset 1080, ($438): 1438:"M.K." That is all there is to it. Note that we haven't defined any music patterns yet. These will come later. You must save the header for future reference. This example will do it: BSAVE HDR,A$1000,L1084 While we are at it, it might be a good idea to rename the file that contains your wavebank samples to, "INST." This is because we will be using this name later, when we put the MOD together. CREATING A PATTERN A pattern is a 1024-byte chunk of the MOD, which is made up of 64 positions. Each position consists of 16 bytes, and up to 4 notes can be playing at each position. A note takes 4 bytes, so this effectively allows for 4 tracks. The first 4 bytes in a position correspond to track 1, the second 4 correspond to track 2, and so on. Each note has information for the note value to be played, the instrument corresponding to the note, and the effects/parameters, if any. See the file format note for a pictorial representation of the 4 bytes that make up a note. As shown in the figure, the note value takes 12 bits, the instrument number takes 8, the effect takes 4, and the parameter takes 8 bits. The first byte of the 4-byte note consists of the upper 4 bits of the instrument, (in the high-order nibble), and the upper 4 bits of the note value, (in the low-order nibble). The high nibble will always be $0 or $1, as instrument numbers range from $00 to $1F. The low-order nibble of the instrument number is stored in the high-order nibble of byte 3 of the 4-byte note. The low-order nibble of byte 1, and all of byte 2, combine to be the note value. See the file format note for allowable note values. There are 3 octaves possible, with 12 notes in each octave. The low-order nibble of byte 3 contains the effect number, ($0 to $F). The last byte contains the parameter for the effect. If no effect is desired, both the parameter byte and the effect nibble should be set to 0. A more descriptive list of the allowable effects, with their required parameters, is located in another file on this disk. The following example demonstrates the 4 bytes needed to play a note C in the 3rd octave, with instrument #1, and a fine slide up value of 2: 00 D6 1E 12 It is rather difficult to tell you which notes and effects to enter in your MOD. Experiment with different values for a while. To begin creating a pattern, zero 1024-bytes of memory: 00<1000.13FFZ Then begin entering your notes. When the pattern is done, save it to disk: BSAVE P1,A$1000,L1024 Go ahead and make 2 more patterns, repeating the above steps, each time saving the new pattern with a higher number, (P2, P3). When this is done, we need to reload the MOD header and define the pattern play list. Type the following to reload the header: BLOAD HDR,A$1000 Then, you must decide how many patterns you would like to play. You can repeat any pattern as many times as you wish. Suppose you wanted to play patterns 1, 2, 3, 3, 2, and 1. There would be 6 total patterns. At offset 950, ($3B6), you must store the total number of patterns: 13B6:06 Then, at offset 952, you must enter the patterns to play-1: 13B8:00 01 02 02 01 00 Now resave the header as follows: BSAVE HDR,A$1000,L1084 Now, we have constructed a very primitive MOD file. Combine the files together in the following order: HDR, P1, P2, P3, INST Now load this file into one of the IIgs MOD players, and test the results. It may take some time to understand all of the concepts presented in this note. If you are serious about creating your own MODs, don't give up--it can be done. Probably the best thing to do if you are confused, is to look at other MOD files, and see the way the various effects are utilized. If you do manage to produce a very good MOD, and aren't too afraid to show it to the IIgs community, I would appreciate it if you sent it to me, to feature in GS MOD Monthly. Happy MODing!