ciatrklib
This library plays Protracker modules: files in the “M.K.” format with
31 samples and four voices. Its play routine is the Protracker 2.3A CIA
routine by Peter “Crayon” Hanning of Mushroom Studios, released as
public domain. The library extends it with a master volume
(TrackerVolume), a channel mask that keeps voices free for sound
effects (ChangeTrackerMask) and tracker events. A tracker event is
the effect 8xx, which Protracker does not use: it passes its value
to the program, which can wait for it or check for it to time
graphics to the music.
Modules live in the library’s own numbered slots, 0 to 8; they are
not Blitz objects. LoadTrackerModule loads a module file into chip
memory, DecodeModule takes a module that is already in memory and
copies it into chip memory if it is elsewhere. StartTracker plays
the module of a slot from the beginning.
The library can play in two ways. By default, in CIA mode, it sets up a
CIA timer interrupt when the program starts, which plays the module by
itself at the right tempo; StartTracker is all a program needs.
After ChangeTrackerVBlank the program plays the module itself
instead: it calls PlayTracker 50 times a second, for example from a
vertical blank interrupt handler. In that mode tempo commands of a
module have no effect.
ChangeTrackerVBlank
If LoadTrackerModule(0,"mod.tune")<>-1 Then End
x=StartTracker(0)
SetInt 5
PlayTracker
End SetInt
MouseWait
StopTrackerLoadTrackerModule reads the file with AmigaDOS. The known faults of
the play routine, for example with some effect commands, are fixed
(Fixes in the Protracker play routine).
Based on the CIA Protracker Library documentation by Crossbones/Binary Assault.
Library number 56.
Commands
ChangeTrackerMask
Chooses the voices the module plays on, bit 0 for voice 1 up to bit 3 for voice 4; the default is all four. A voice left out is silenced at once and stays free for sound effects.
Statement. Help text: Channel_Mask
Arguments: .w
ChangeTrackerMask %1001 plays voices 1 and 4 and leaves voices 2
and 3 to the program.
ChangeTrackerVBlank
Switches to playing without the CIA interrupt. It stops the module and removes the interrupt; from then on the program calls PlayTracker 50 times a second itself.
Statement. No help text.
No arguments.
Call it before StartTracker. Tempo commands of a module have no
effect in this mode. The mode lasts until the program ends: the next
run, also from the editor, starts in CIA mode again.
CheckTrackerEvent
Returns -1 if a new tracker event came since the last check, and 0 otherwise; GetTrackerEvent gives its value.
Function, result .w. No help text.
No arguments.
CheckTrackerID
Returns -1 if the slot’s module has the Protracker mark “M.K.” or “M!K!”, and 0 otherwise, also for an empty slot.
Function, result .l. Help text: (TrackerModule#)
Arguments: .l
DecodeModule
Puts the module at ModuleAddress into slot TrackerModule# (0 to 8). A module in chip memory is used where it is; one in other memory is copied into chip memory.
Statement. Help text: TrackerModule#,ModuleAddress
Arguments: .l, .l
The module is not checked; CheckTrackerID tells whether it looks
like one. With the debugger’s checks, the slot must not hold a module
that was loaded or copied.
FreeTrackerModule
Frees the module of slot TrackerModule#. The memory of a loaded or copied module is freed; a module that DecodeModule left in place is only forgotten.
Statement. Help text: TrackerModule#
Arguments: .l
Call StopTracker first: a module that is playing is not stopped.
With the debugger’s checks, freeing it is a runtime error; without
them, it keeps playing from the freed memory.
GetModuleName$
The name of a slot’s module, up to 20 characters.
Function, result $. Help text: (TrackerModule#)
Arguments: .l
With the debugger’s checks, an empty slot is a runtime error; without them, it gives the empty string.
GetModulePosition
The song position the module is playing.
Function, result .b. No help text.
No arguments.
GetTrackerEvent
The value of the most recent tracker event, the effect 8xx of the module. The event comes on the first tick of its row.
Function, result .b. No help text.
No arguments.
GetTrackerLocation
The address of a slot’s module in memory.
Function, result .l. Help text: (TrackerModule#)
Arguments: .l
GetTrackerSize
The number of bytes a slot’s module takes in memory, the file size plus 3 for a loaded module. A module that DecodeModule left where it was gives 1.
Function, result .l. Help text: (TrackerModule#)
Arguments: .w
LoadTrackerModule
Loads the module file Name into chip memory, into slot TrackerModule# (0 to 8). Returns -1 when the file was read, and the AmigaDOS error code when it cannot be opened, such as a directory, or after a read error; the slot then stays empty.
Function, result .l. Help text: (TrackerModule#,Name)
Arguments: .l, $
A file that cannot be found or examined is a runtime error. With the debugger’s checks, the slot must be empty; without them, a module in the slot is freed first. Do not load into the slot of the module that is playing.
ModulePatterns
The number of patterns of a slot’s module, the highest pattern number in its 128 song positions plus 1.
Function, result .b. Help text: (Module #)
Arguments: .l
ModulePositionJump
Makes the module continue at another song position at the next tick. The position is not checked.
Statement. Help text: (Position#)
Arguments: .b
ModuleToChip
Does nothing; DecodeModule copies a module into chip memory itself.
Function, result .l. Help text: (TrackerModule#)
Arguments: .l
It returns its argument. That it has no function is by design: the library’s documentation says so, and the command is kept only so that older programs still compile (#446).
PauseModule
Pauses the module and silences the voices; the next call continues it.
Statement. No help text.
No arguments.
Only a module that plays is paused; without one, the command does
nothing. A pause ends with a StartTracker that starts a module,
with StopTracker and ChangeTrackerVBlank, and when the paused
module is freed, by FreeTrackerModule or by loading or decoding
another module into its slot. After that, PauseModule works as if
there had been no pause. So a module that StopTracker or the effect
F00 stopped is not continued by PauseModule.
PlayTracker
Plays one tick of the module. After ChangeTrackerVBlank, call it 50 times a second, for example from a vertical blank interrupt handler (SetInt 5).
Statement. No help text.
No arguments.
Nothing happens unless a module was started and is not stopped or paused.
StartTracker
Plays the module of slot TrackerModule# from the beginning, in place of the module that played before. Returns -1.
Function, result .l. Help text: (TrackerModule#)
Arguments: .l
Unless ChangeTrackerVBlank was used, the CIA interrupt is set up
again. With the debugger’s checks, an empty slot is a runtime error;
without them, an empty slot plays nothing and returns 0.
Before it plays, StartTracker corrects two kinds of invalid data in
the module in memory: sample numbers above 31 in the patterns become 0,
and a sample’s finetune above 15 keeps only its low four bits.
StopTracker
Stops the module and silences the four voices.
Statement. No help text.
No arguments.
TrackerVolume
Sets the master volume of the module, 0 to 64; the default is 64. Values above 64 are ignored. The volume also changes the notes that are playing.
Statement. Help text: (Volume Range: 0-64)
Arguments: .w
WaitTrackerEvent
Waits until the next tracker event comes, checking once per frame.
Statement. No help text.
No arguments.