|
BB2 C port
API reference: Blitz libraries in C and the shared code
|
#include "blitzlib.h"#include "blitzexec.h"#include <exec/interrupts.h>#include <hardware/custom.h>#include <hardware/cia.h>#include <graphics/gfxbase.h>#include <dos/dos.h>#include <proto/dos.h>Data Structures | |
| struct | modent |
| struct | chan |
Macros | |
| #define | __NOLIBBASE__ |
| #define | DOS_BASE_NAME dos |
| #define | CUSTOM ((volatile struct Custom *)0xdff000) |
| #define | CIAAPRA (*(volatile UBYTE *)0xbfe001) |
| #define | VPOSR_LO (*(volatile UBYTE *)0xdff006) /* the vertical position, bits 0-7 */ |
| #define | ID(a, b, c, d) |
| #define | WORDAT(p) |
| #define | LONGAT(p) |
| #define | CMDW(ch) |
| #define | LAUNDER(ptr) |
Typedefs | |
| typedef volatile struct AudChannel | aud_t |
Functions | |
| void | _loadtrkmodule (void) |
| void | _StartTrkModule (void) |
| void | _StopTracker (void) |
| void | _decodemod (void) |
| void | _gettrklen (void) |
| void | _gettrkloc (void) |
| void | _freetrackermodule (void) |
| void | _gettrackerevent (void) |
| void | _checktrackerevent (void) |
| void | _waittrackerevent (void) |
| void | _checkid (void) |
| void | _modtochip2 (void) |
| void | _getmodulename (void) |
| void | _modulepositionjump (void) |
| void | _getmoduleposition (void) |
| void | _pausemodule (void) |
| void | _change_playtype (void) |
| void | _Play_Tracker (void) |
| void | _Volume_Control (void) |
| void | _ChangeTrackerMask (void) |
| void | _maxpatterns (void) |
| void | _inittrackerlib (void) |
| void | _finittrackerlib (void) |
| void | ciatrklib_mt_music (void) |
| void | _loadcheck (void) |
| void | _checkused (void) |
| void | _decodecheck (void) |
| void | _freecheck (void) |
| static struct modent * | slot (ULONG num) |
| static const UWORD * | periods (UBYTE ft) |
| static aud_t * | voice (int ch) |
| static ULONG | globalloc (ULONG size, ULONG flags) |
| static void | globfree (ULONG mem, ULONG size) |
| static void | mt_end (void) |
| static void | resetciaint (void) |
| static void | setciaint (void) |
| static void | settempo (UWORD bpm) |
| static UWORD | set_volume (UWORD v) |
| static UWORD | set_real_mask (UWORD bits) |
| static ULONG | maxpattern (const UBYTE *mod) |
| static ULONG | patternsize (const UBYTE *mod) |
| static void | clearsamplenums (UBYTE *mod, ULONG modlen) |
| static void | maskfinetunes (UBYTE *mod) |
| static void | mt_init (ULONG modlen) |
| static void | waitline (void) |
| static void | playsamples (UWORD chans) |
| static void | pernop (struct chan *ch, aud_t *aud) |
| static void | updatefunk (struct chan *ch) |
| static void | arpeggio (struct chan *ch, aud_t *aud) |
| static void | portaup (struct chan *ch, aud_t *aud) |
| static void | portadown (struct chan *ch, aud_t *aud) |
| static void | fineportaup (struct chan *ch, aud_t *aud) |
| static void | fineportadown (struct chan *ch, aud_t *aud) |
| static UWORD | findperiod (const UWORD *table, UWORD per) |
| static void | settoneporta (struct chan *ch) |
| static void | toneportnochange (struct chan *ch, aud_t *aud) |
| static void | toneportamento (struct chan *ch, aud_t *aud) |
| static UBYTE | wave (UBYTE pos, UBYTE form) |
| static void | vibrato2 (struct chan *ch, aud_t *aud) |
| static UBYTE | newcmd (UBYTE old, UBYTE cmdlo) |
| static void | vibrato (struct chan *ch, aud_t *aud) |
| static void | volumeslide (struct chan *ch, aud_t *aud) |
| static void | toneplusvolslide (struct chan *ch, aud_t *aud) |
| static void | vibratoplusvolslide (struct chan *ch, aud_t *aud) |
| static void | tremolo (struct chan *ch, aud_t *aud) |
| static void | sampleoffset (struct chan *ch) |
| static void | volslideup (struct chan *ch, aud_t *aud, UBYTE delta) |
| static void | volslidedown2 (struct chan *ch, aud_t *aud, UBYTE delta) |
| static void | positionjump (struct chan *ch) |
| static void | volumechange (struct chan *ch, aud_t *aud) |
| static void | patternbreak (struct chan *ch) |
| static void | setspeed (struct chan *ch) |
| static void | filteronoff (struct chan *ch) |
| static void | jumploop (struct chan *ch) |
| static void | karplusstrong (struct chan *ch) |
| static void | doretrig (struct chan *ch, aud_t *aud) |
| static void | retrignote (struct chan *ch, aud_t *aud) |
| static void | volumefineup (struct chan *ch, aud_t *aud) |
| static void | volumefinedown (struct chan *ch, aud_t *aud) |
| static void | notecut (struct chan *ch, aud_t *aud) |
| static void | notedelay (struct chan *ch, aud_t *aud) |
| static void | patterndelay (struct chan *ch) |
| static void | funkit (struct chan *ch) |
| static void | e_commands (struct chan *ch, aud_t *aud) |
| static void | checkefx (struct chan *ch, aud_t *aud) |
| static void | checkmoreefx (struct chan *ch, aud_t *aud) |
| static void | setperiod_regs (struct chan *ch, aud_t *aud) |
| static void | setperiod (struct chan *ch, aud_t *aud) |
| static void | playvoice (struct chan *ch, aud_t *aud, const UBYTE *samples, const UBYTE *note) |
| static void | nextposition (void) |
| static void | dskip (void) |
| static void | nonewallchannels (void) |
| static void | getnewnote (void) |
| static void | mt_music_c (void) |
| PlayTracker: one tick of the play routine (mt_music). | |
| static void | change_volume_levels (void) |
| static void | freetrackermodule_c (ULONG num) |
| static ULONG | loadtrkmodule_c (ULONG num, ULONG name, struct DosLibrary *dos) |
| LoadTrackerModule(TrackerModule#,Name): load a module file into chip memory. | |
| static BB_BOOL | modtochip (ULONG num) |
| static void | decodemod_c (ULONG num, ULONG addr) |
| DecodeModule TrackerModule#,ModuleAddress: use a module in memory. | |
| static ULONG | gettrklen_c (ULONG num) |
| GetTrackerSize(TrackerModule#): the length of a slot's module. | |
| static ULONG | gettrkloc_c (ULONG num) |
| GetTrackerLocation(TrackerModule#): the address of a slot's module. | |
| static void | freetrk_c (ULONG num) |
| FreeTrackerModule TrackerModule#: free a slot's module. | |
| static ULONG | checkid_c (ULONG num) |
| CheckTrackerID(TrackerModule#): is the slot's module a Protracker module? | |
| static ULONG | modtochip2_c (ULONG arg) |
| ModuleToChip(TrackerModule#): does nothing (RTS). | |
| static ULONG | getmodulename_c (ULONG num) |
| GetModuleName$(TrackerModule#): the name of a slot's module. | |
| static ULONG | starttrkmodule_c (ULONG num) |
| StartTracker(TrackerModule#): play a slot's module. | |
| static void | stoptracker_c (void) |
| StopTracker: stop playing (mt_end: volumes 0, audio DMA off). | |
| static ULONG | maxpatterns_c (ULONG num) |
| ModulePatterns(Module #): the number of patterns of the module. | |
| static ULONG | gettrackerevent_c (ULONG old) |
| GetTrackerEvent: the value of the last tracker event (effect 8). | |
| static ULONG | checktrackerevent_c (ULONG old) |
| CheckTrackerEvent: has a new tracker event come? | |
| static void | waittrackerevent_c (const void *caller_a6) |
| WaitTrackerEvent: wait for the next tracker event. | |
| static void | modulepositionjump_c (ULONG pos) |
| ModulePositionJump (Position#): jump to a song position. | |
| static ULONG | getmoduleposition_c (ULONG old) |
| GetModulePosition: the current song position. | |
| static void | pausemodule_c (void) |
| PauseModule: pause or continue the playing module. | |
| static void | change_playtype_c (void) |
| ChangeTrackerVBlank: play without the CIA interrupt. | |
| static void | volume_control_c (ULONG vol) |
| TrackerVolume (Volume Range: 0-64): the master volume. | |
| static void | changetrackermask_c (ULONG mask) |
| ChangeTrackerMask Channel_Mask: the voices to play. | |
| static void | inittrackerlib_c (void) |
| init: install the CIA interrupt and clear the module slots. | |
| static void | finittrackerlib_c (void) |
| finit: stop playing and remove the CIA interrupt. | |
| static void | slotcheck_c (ULONG num) |
| static void | loadcheck_c (ULONG num) |
| static void | checkused_c (ULONG num) |
| static void | decodecheck_c (ULONG num) |
| static void | freecheck_c (ULONG num) |
Variables | |
| struct { | |
| UBYTE pause_status | |
| UBYTE play_type | |
| UWORD old_volume | |
| UWORD master_volume | |
| UWORD volume_flag | |
| UBYTE master_mask | |
| UBYTE master_mask_lo | |
| struct modent modtable [10] | |
| } | libvars |
| struct { | |
| UWORD RealTempo | |
| volatile struct CIA * CIAAaddr | |
| char CIAAname [14] | |
| char CIABname [14] | |
| struct Library * CIAAbase | |
| ULONG TimerFlag | |
| ULONG TimerValue | |
| UBYTE * mt_data | |
| char GfxName [18] | |
| struct Interrupt MusicIntServer | |
| char musintname [20] | |
| volatile struct Custom *volatile endcustom | |
| } | ciapart |
| struct { | |
| UBYTE FunkTable [16] | |
| UBYTE VibratoTable [32] | |
| UWORD PeriodTable [16 *36] | |
| struct chan chan [4] | |
| struct AudChannel fake_channel | |
| UBYTE fake_rest [60 - sizeof(struct AudChannel)] | |
| UBYTE * SampleStarts [32] | |
| UBYTE * SongDataPtr | |
| UBYTE speed | |
| UBYTE counter | |
| UBYTE SongPos | |
| UBYTE PBreakPos | |
| UBYTE PosJumpFlag | |
| UBYTE PBreakFlag | |
| UBYTE LowMask | |
| UBYTE PattDelTime | |
| UBYTE PattDelTime2 | |
| UBYTE Enable | |
| UWORD PatternPos | |
| UWORD DMACONtemp | |
| UBYTE TrkEvt | |
| UBYTE LstEvt | |
| } | playdata |
| static BPTR | hand |
| static BPTR | lock |
| static ULONG | fname |
| static ULONG | fib |
| static ULONG | readerr |
| static ULONG | thismod |
| static const char | mess [] = "Tracker: File error! (Not found?)" |
| static const char | mess2 [] = "Tracker Library Error" |
| static const UBYTE * | patdata |
| #define __NOLIBBASE__ |
| #define CIAAPRA (*(volatile UBYTE *)0xbfe001) |
| #define CMDW | ( | ch | ) |
| #define CUSTOM ((volatile struct Custom *)0xdff000) |
| #define DOS_BASE_NAME dos |
| #define LAUNDER | ( | ptr | ) |
| #define LONGAT | ( | p | ) |
| #define VPOSR_LO (*(volatile UBYTE *)0xdff006) /* the vertical position, bits 0-7 */ |
| #define WORDAT | ( | p | ) |
| typedef volatile struct AudChannel aud_t |
| void _change_playtype | ( | void | ) |
| void _ChangeTrackerMask | ( | void | ) |
| void _checkid | ( | void | ) |
| void _checktrackerevent | ( | void | ) |
| void _checkused | ( | void | ) |
| void _decodecheck | ( | void | ) |
| void _decodemod | ( | void | ) |
| void _finittrackerlib | ( | void | ) |
| void _freecheck | ( | void | ) |
| void _freetrackermodule | ( | void | ) |
| void _getmodulename | ( | void | ) |
| void _getmoduleposition | ( | void | ) |
| void _gettrackerevent | ( | void | ) |
| void _gettrklen | ( | void | ) |
| void _gettrkloc | ( | void | ) |
| void _inittrackerlib | ( | void | ) |
| void _loadcheck | ( | void | ) |
| void _loadtrkmodule | ( | void | ) |
| void _maxpatterns | ( | void | ) |
| void _modtochip2 | ( | void | ) |
| void _modulepositionjump | ( | void | ) |
| void _pausemodule | ( | void | ) |
| void _Play_Tracker | ( | void | ) |
| void _StartTrkModule | ( | void | ) |
| void _StopTracker | ( | void | ) |
| void _Volume_Control | ( | void | ) |
| void _waittrackerevent | ( | void | ) |
|
static |
ChangeTrackerVBlank: play without the CIA interrupt.
Stops playing (mt_end) and removes the CIA interrupt (ResetCIAInt); from then on the program calls PlayTracker itself and StartTracker installs no interrupt. Ends a pause of PauseModule (fixed, #1076).
|
static |
|
static |
ChangeTrackerMask Channel_Mask: the voices to play.
Bit 0 = voice 1 ... bit 3 = voice 4. A masked voice writes its registers into fake_channel; its volume is set to 0 at once.
| mask | d0.w: the voice bits |
|
static |
CheckTrackerID(TrackerModule#): is the slot's module a Protracker module?
Tests the id at $438 for "M.K." or "M!K!". "Not a module" and an empty slot (length 0) are False (fixed, #430: the original returned the long at ADDRESS 0, MOVE.l 0,d0). Error check (_checkused): slots 0-8, a module in the slot.
| num | d0: the slot |
|
static |
CheckTrackerEvent: has a new tracker event come?
A new event (one that differs from the last seen) is marked seen. No new event is False (fixed, #431: the original loaded only the low byte of d0 with the last event's value).
| old | d0: the caller's d0 |
|
static |
| void ciatrklib_mt_music | ( | void | ) |
|
static |
|
static |
|
static |
DecodeModule TrackerModule#,ModuleAddress: use a module in memory.
The slot gets the address, length 1 (so CheckTrackerID works) and flag 0. A module in chip memory (an address below $200000, compared unsigned: fixed, #432, the original's BLT took every address from $80000000 up for chip memory) stays where it is; one from other memory is copied to chip memory, with the size + 3 (fixed, #434: the original added the 3 as a word), flag 2; when that memory is missing the slot keeps the old address with flag 2 and the new length (#433; memlib's globalloc ends the program instead). The size comes from mt_init's scan of the song positions (all 128, Fixed (#477)). Error check (_decodecheck): slots 0-8, no loaded or copied module in the slot.
| num | d0: the slot |
| addr | d1: the module |
|
static |
|
static |
|
static |
|
static |
finit: stop playing and remove the CIA interrupt.
ResetCIAInt (unless ChangeTrackerVBlank removed it) removes the vector with its timer's bit (fixed, #448: the original always used bit 0); it leaves the filter as it is (fixed, #449). The module slots are not freed here.
|
static |
|
static |
|
static |
FreeTrackerModule TrackerModule#: free a slot's module.
The memory of a loaded or copied module is freed; a module that plays from the slot is not stopped. Error check (_freecheck): slots 0-8, and not the loaded or copied module that plays (fixed, #436: the original's _slotcheck let it be freed while the play routine went on reading it).
| num | d0: the slot |
|
static |
|
static |
GetModuleName$(TrackerModule#): the name of a slot's module.
Up to 20 characters of the module's name, at a3, and a 0. An empty slot is the empty string (fixed, #437: the original wrote nothing, not even the 0, and returned slot*10 as the length). Error check (_checkused): slots 0-8, a module in the slot.
| num | d0: the slot |
|
static |
GetModulePosition: the current song position.
| old | d0: the caller's d0 |
|
static |
|
static |
GetTrackerEvent: the value of the last tracker event (effect 8).
Effect 8 is seen on the row's tick (fixed, #435: the original saw it only on the ticks between the rows). Only the low byte of d0 changes (declared byte, not a defect).
| old | d0: the caller's d0 |
|
static |
GetTrackerSize(TrackerModule#): the length of a slot's module.
Error check (_checkused): slots 0-8, a module in the slot.
| num | d0.w: the slot |
|
static |
GetTrackerLocation(TrackerModule#): the address of a slot's module.
Error check (_checkused): slots 0-8, a module in the slot.
| num | d0: the slot |
|
static |
|
static |
|
static |
init: install the CIA interrupt and clear the module slots.
SetCIAInt (mt_music every 1/50 s on timer A of ciaa, else timer B of ciab; the ICR bits 0 and 1, fixed, #450: the original read them from the addresses 1 and 2), slots 0-7 cleared (DBNE from 7), master volume 64, all four voices on. The play type is cleared first (fixed, #1165: the original kept it, so after a run with ChangeTrackerVBlank the next run of the program from the editor installed no CIA interrupt, here nor in StartTracker, and played nothing without PlayTracker).
|
static |
|
static |
|
static |
|
static |
LoadTrackerModule(TrackerModule#,Name): load a module file into chip memory.
The slot is freed first; Lock, Examine (FileInfoBlock of memlib), memory of the file size + 3 (fixed, #442: the original added as a byte and lost the carry) from memlib's globalloc (not checked, #440: memlib ends the program when it fails), Open by name while the lock is held, Read, Close, UnLock; flag 1 (fixed, #1146: the original called OpenFromLock, dos V36, and crashed on Kickstart 1.x). The compiler loads DOSBase into a6 (fixed, #443: the original's !libs was empty, the dos calls went through whatever a6 held). A failing Lock, FileInfoBlock or Examine is a runtime error ("Tracker: File error! (Not found?)", "Tracker Library Error"), the last two leave the lock allocated (#441). A failed open frees the slot and unlocks the lock (#1146: the original passed the handle to Read untested). A Read error frees the slot (fixed, #444: the original also unlocked the lock that OpenFromLock had taken over, a second time after Close). Error check (_loadcheck): slots 0-8, the slot must be empty.
|
static |
|
static |
|
static |
ModulePatterns(Module #): the number of patterns of the module.
The highest pattern number of the song positions + 1, from mt_init's scan (fixed, #445: the original returned the song length, byte 950 of the module). Error check (_checkused): slots 0-8, a module in the slot.
| num | d0: the slot |
|
static |
|
static |
ModuleToChip(TrackerModule#): does nothing (RTS).
By design (#446): the module is not copied, DecodeModule does that; the documentation: "the command has no function".
| arg | d0: the slot |
|
static |
ModulePositionJump (Position#): jump to a song position.
Stores n - 1, as effect Bxx does: at the next tick mt_NextPosition increments it and the song continues at position n (fixed, #447: the original stored n, the song went on at n + 1).
| pos | d0.b: the position |
|
static |
|
static |
|
static |
PlayTracker: one tick of the play routine (mt_music).
Also the code of the CIA interrupt (MusicIntServer); after ChangeTrackerVBlank the program calls PlayTracker itself, once per tick. Nothing happens unless a module plays (mt_Enable). The bugs of the Protracker 2.3A routine are listed in the head of the file.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
PauseModule: pause or continue the playing module.
Toggles: a module that plays (mt_Enable) is stopped (mt_end), the module this call paused plays on at the next call. Fixed (#1076): StartTracker, StopTracker, ChangeTrackerVBlank and freeing the paused module's slot end the pause, and without a module that plays the call does nothing; the original toggled its state whatever happened in between, so after a pause the next PauseModule only enabled playing (a module started again was not paused, a stopped one or the module of a freed slot played again), and two calls played a stopped module again (tests ciatrklib-pause-state-kept, ciatrklib-pause-after-stop). Accepted: a module that stopped itself (F00) is not continued by two PauseModule any more.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
StartTracker(TrackerModule#): play a slot's module.
Resets the CIA tempo (removes the interrupt), installs it again unless ChangeTrackerVBlank was used, mt_init (its scan: Fixed (#477); the first long of every sample inside the module cleared, fixed, #438) and enables playing. Error check (_checkused): slots 0-8, a module in the slot.
| num | d0: the slot |
|
static |
StopTracker: stop playing (mt_end: volumes 0, audio DMA off).
Ends a pause of PauseModule (fixed, #1076: the original left it, the next PauseModule played the stopped module again).
|
static |
|
static |
|
static |
TrackerVolume (Volume Range: 0-64): the master volume.
Values above 64 are ignored. Every volume 0-64 also changes the volumes of the notes that play now (Change_Volume_Levels; fixed, #452: the original did that only for 0 < volume < 64, so TrackerVolume 0 and 64 did not reach them); new notes get note volume * master / 64.
| vol | d0.w: the volume |
|
static |
|
static |
WaitTrackerEvent: wait for the next tracker event.
Marks the current event seen, then WaitTOF (-270) until the event changes. The compiler loads GfxBase into a6 (fixed, #453: the original's !libs was empty, WaitTOF went through whatever a6 held).
| caller_a6 | a6: graphics.library (!libs {graphicslib,la6}) |
|
static |
| struct chan chan[4] |
| volatile struct CIA* CIAAaddr |
| struct Library* CIAAbase |
| char CIAAname[14] |
| char CIABname[14] |
| struct { ... } ciapart |
| UBYTE counter |
| UWORD DMACONtemp |
| UBYTE Enable |
| volatile struct Custom* volatile endcustom |
| struct AudChannel fake_channel |
| UBYTE fake_rest[60 - sizeof(struct AudChannel)] |
|
static |
|
static |
| UBYTE FunkTable[16] |
| char GfxName[18] |
|
static |
| struct { ... } libvars |
|
static |
| UBYTE LowMask |
| UBYTE LstEvt |
| UBYTE master_mask |
| UBYTE master_mask_lo |
| UWORD master_volume |
|
static |
|
static |
| struct modent modtable[10] |
| UBYTE* mt_data |
| struct Interrupt MusicIntServer |
| char musintname[20] |
| UWORD old_volume |
|
static |
| UBYTE PattDelTime |
| UBYTE PattDelTime2 |
| UWORD PatternPos |
| UBYTE pause_status |
| UBYTE PBreakFlag |
| UBYTE PBreakPos |
| UWORD PeriodTable[16 *36] |
| UBYTE play_type |
| struct { ... } playdata |
| UBYTE PosJumpFlag |
|
static |
| UWORD RealTempo |
| UBYTE* SampleStarts[32] |
| UBYTE* SongDataPtr |
| UBYTE SongPos |
| UBYTE speed |
|
static |
| ULONG TimerFlag |
| ULONG TimerValue |
| UBYTE TrkEvt |
| UBYTE VibratoTable[32] |
| UWORD volume_flag |