unit asap_lib;
{$mode objfpc}{$H+}
interface
uses
windows;
const
ASAPLIB = 'asap.dll';
type
TPoly9LookupArray = array[0..510] of Byte;
TPoly17LookupArray = array[0..16384] of Byte;
TSincLookupArray = array[0..1023, 0..31] of SmallInt;
PASAPWriter = ^ASAPWriter;
ASAPWriter = record
output :PInt16;
outputOffset : Integer;
outputEnd: Integer;
end;
ASAPModuleType = (amtUnknown, amtType1, amtType2,ASAPModuleType_SAP_B,
ASAPModuleType_SAP_C,
ASAPModuleType_SAP_D,
ASAPModuleType_SAP_S,
ASAPModuleType_CMC,
ASAPModuleType_CM3,
ASAPModuleType_CMR,
ASAPModuleType_CMS,
ASAPModuleType_DLT,
ASAPModuleType_MPT,
ASAPModuleType_RMT,
ASAPModuleType_TMC,
ASAPModuleType_TM2,
ASAPModuleType_FC);
NmiStatus = (NmiStatus_RESET, NmiStatus_ON_V_BLANK,NmiStatus_WAS_V_BLANK);
// sample formats
ASAPSampleFormat = (
ASAPSampleFormat_U8, // Unsigned 8-bit
ASAPSampleFormat_S16_L_E, // Signed 16-bit little-endian
ASAPSampleFormat_S16_B_E // Signed 16-bit big-endian
);
TPokeyChannel = record
Audf: Integer;
Audc: Integer;
PeriodCycles: Integer;
TickCycle: Integer;
TimerCycle: Integer;
Mute: Integer;
Out: Integer;
Delta: Integer;
end;
TPokeyChannelArray = array[0..3] of TPokeyChannel;
TPokey = record
Channels: TPokeyChannelArray;
Audctl: Integer;
Skctl: Integer;
Irqst: Integer;
Init: Boolean;
DivCycles: Integer;
ReloadCycles1: Integer;
ReloadCycles3: Integer;
PolyIndex: Integer;
DeltaBufferLength: Integer;
DeltaBuffer: PInteger; // Correspond Ă un pointeur sur int en C c'est sure !!
SumDACInputs: Integer;
SumDACOutputs: Integer;
IIRRate: Integer;
IIRAcc: Integer;
Trailing: Integer;
end;
PokeyPair = record
Poly9Lookup: TPoly9LookupArray;
Poly17Lookup: TPoly17LookupArray;
ExtraPokeyMask: Integer;
BasePokey: TPokey;
ExtraPokey: TPokey;
SampleRate: Integer;
SincLookup: TSincLookupArray;
SampleFactor: Integer;
SampleOffset: Integer;
ReadySamplesStart: Integer;
ReadySamplesEnd: Integer;
end;
PASAPInfo = ^ASAPInfo;
ASAPInfo = record
filename: PChar;
author: PChar;
title: PChar;
date: PChar;
channels: Integer;
songs: Integer;
defaultSong: Integer;
durations: array[0..31] of Integer;
loops: array[0..31] of Boolean;
ntsc: Boolean;
mtype_: ASAPModuleType;
fastplay: Integer;
music: Integer;
init: Integer;
player: Integer;
covoxAddr: Integer;
headerLen: Integer;
songPos: array[0..31] of Byte;
end;
TCpu6502 = ^Cpu6502;
PASAP = ^ASAP;
Cpu6502 = record
asap: PASAP;
memory: array[0..65535] of Byte;
cycle: Integer;
pc: Integer;
a: Integer;
x: Integer;
y: Integer;
s: Integer;
nz: Integer;
c: Integer;
vdi: Integer;
end;
ASAP = record
nextEventCycle: Integer;
cpu: TCpu6502;
nextScanlineCycle: Integer;
nmist: NmiStatus;
consol: Integer;
covox: array[0..3] of Byte;
pokeys: PokeyPair;
moduleInfo: ASAPInfo;
nextPlayerCycle: Integer;
tmcPerFrameCounter: Integer;
currentSong: Integer;
currentDuration: Integer;
blocksPlayed: Integer;
silenceCycles: Integer;
silenceCyclesCounter: Integer;
gtiaOrCovoxPlayedThisFrame: Boolean;
currentSampleRate: Integer;
end;
function ASAP_New: PASAP; cdecl; external ASAPLIB;
procedure ASAP_Delete(var self: ASAP); cdecl; external ASAPLIB;
procedure ASAP_DetectSilence( self: ASAP; seconds: Integer); cdecl; external ASAPLIB;
function ASAP_Load( self: PASAP; filename: PChar; const module: PByte; moduleLen: Integer): Boolean; cdecl; external ASAPLIB;
function ASAP_GetInfo(self: PASAP): PASAPInfo; cdecl; external ASAPLIB;
procedure ASAP_MutePokeyChannels( self: ASAP; mask: Integer); cdecl; external ASAPLIB;
procedure ASAPInfo_SetNtsc(self :PASAP ; ntsc : Boolean); cdecl; external ASAPLIB;
function ASAP_PlaySong( self: PASAP; song, duration: Integer): Boolean; cdecl; external ASAPLIB;
function ASAP_GetBlocksPlayed(const self: ASAP): Integer; cdecl; external ASAPLIB;
function ASAP_GetPosition( self: PASAP): Integer; cdecl; external ASAPLIB;
function ASAP_SeekSample( self: ASAP; block: Integer): Boolean; cdecl; external ASAPLIB;
function ASAP_Seek( self: ASAP; position: Integer): Boolean; cdecl; external ASAPLIB;
function ASAP_GetWavHeader( self: PASAP; buffer: PByte; format: ASAPSampleFormat; metadata: Boolean): Integer; cdecl; external ASAPLIB;
function ASAP_Generate(self: PASAP; buffer: PByte; bufferLen: Integer; format: ASAPSampleFormat): Integer; cdecl; external ASAPLIB;
function ASAP_GetPokeyChannelVolume(const self: ASAP; channel: Integer): Integer; cdecl; external ASAPLIB;
procedure ASAPInfo_Delete( self: PASAPInfo); cdecl; external ASAPLIB;
function ASAPInfo_GetAuthor(const self: ASAPInfo): PChar; cdecl; external ASAPLIB;
function ASAPInfo_SetAuthor( self: PASAPInfo; value: PChar): Boolean; cdecl; external ASAPLIB;
function ASAPInfo_GetTitle(const self: PASAPInfo): PChar; cdecl; external ASAPLIB;
function ASAPInfo_SetTitle( self: PASAPInfo; value: PChar): Boolean; cdecl; external ASAPLIB;
function ASAPInfo_GetTitleOrFilename(const self: ASAPInfo): PChar; cdecl; external ASAPLIB;
function ASAPInfo_GetDate(const self: PASAPInfo): PChar; cdecl; external ASAPLIB;
function ASAPInfo_SetDate( self: PASAPInfo; value: PChar): Boolean; cdecl; external ASAPLIB;
function ASAPInfo_GetYear(const self: PASAPInfo): Integer; cdecl; external ASAPLIB;
function ASAPInfo_GetMonth(const self: PASAPInfo): Integer; cdecl; external ASAPLIB;
function ASAPInfo_GetDayOfMonth(const self: PASAPInfo): Integer; cdecl; external ASAPLIB;
function ASAPInfo_GetChannels(const self: PASAPInfo): Integer; cdecl; external ASAPLIB;
function ASAPInfo_GetSongs(const self: PASAPInfo): Integer; cdecl; external ASAPLIB;
function ASAPInfo_GetDefaultSong(const self: PASAPInfo): Integer; cdecl; external ASAPLIB;
function ASAPInfo_SetDefaultSong( self: PASAPInfo; song: Integer): Boolean; cdecl; external ASAPLIB;
function ASAPInfo_GetDuration(const self: pASAPInfo; song: Integer): Integer; cdecl; external ASAPLIB;
function ASAPInfo_SetDuration( self: PASAPInfo; song, duration: Integer): Boolean; cdecl; external ASAPLIB;
function ASAPInfo_GetLoop(const self: PASAPInfo; song: Integer): Boolean; cdecl; external ASAPLIB;
function ASAPInfo_SetLoop( self: PASAPInfo; song: Integer; loop: Boolean): Boolean; cdecl; external ASAPLIB;
function ASAPInfo_IsNtsc(const self: PASAPInfo): Boolean; cdecl; external ASAPLIB;
function ASAPInfo_GetTypeLetter(const self: PASAPInfo): Integer; cdecl; external ASAPLIB;
function ASAPInfo_GetPlayerRateScanlines(const self: PASAPInfo): Integer; cdecl; external ASAPLIB;
function ASAPInfo_GetPlayerRateHz(const self: PASAPInfo): Integer; cdecl; external ASAPLIB;
function ASAPInfo_GetMusicAddress(const self: PASAPInfo): Integer; cdecl; external ASAPLIB;
function ASAPInfo_SetMusicAddress( self: PASAPInfo; address: Integer): Boolean; cdecl; external ASAPLIB;
function ASAPInfo_GetInitAddress(const self: PASAPInfo): Integer; cdecl; external ASAPLIB;
function ASAPInfo_GetPlayerAddress(const self: PASAPInfo): Integer; cdecl; external ASAPLIB;
function ASAPInfo_GetCovoxAddress(const self: PASAPInfo): Integer; cdecl; external ASAPLIB;
function ASAPInfo_GetSapHeaderLength(const self: PASAPInfo): Integer; cdecl; external ASAPLIB;
function ASAPInfo_GetInstrumentNamesOffset(const self: PASAPInfo; const module: PByte; moduleLen: Integer): Integer; cdecl; external ASAPLIB;
function ASAPInfo_ParseDuration(s: PChar): Integer; cdecl; external ASAPLIB;
function ASAPInfo_IsOurFile(filename: PChar): Boolean; cdecl; external ASAPLIB;
function ASAPInfo_IsOurExt(ext: PChar): Boolean; cdecl; external ASAPLIB;
function ASAPInfo_Load( self: PASAPInfo; filename: PChar; const module: PByte; moduleLen: Integer): Boolean; cdecl; external ASAPLIB;
function ASAPInfo_GetExtDescription(ext: PChar): PChar; cdecl; external ASAPLIB;
function ASAPInfo_GetOriginalModuleExt(const self: PASAPInfo; const module: PByte; moduleLen: Integer): PChar; cdecl; external ASAPLIB;
function ASAPWriter_New:PASAPWriter;cdecl; external ASAPLIB;
procedure ASAPWriter_Delete( self: ASAPWriter); cdecl; external ASAPLIB;
function ASAPWriter_GetSaveExts(exts: PPointer; const info: PASAPInfo; const module: PByte; moduleLen: Integer): Integer; cdecl; external ASAPLIB;
function ASAPWriter_DurationToString(result: PByte; value: Integer): Integer; cdecl; external ASAPLIB;
procedure ASAPWriter_SetOutput( self: PASAPWriter; output: PByte; startIndex, endIndex: Integer); cdecl; external ASAPLIB;
function ASAPWriter_Write( self: PASAPWriter; targetFilename: PChar; const info: PASAPInfo; const module: PByte; moduleLen: Integer; tag: Boolean): Integer; cdecl; external ASAPLIB;
implementation
end.