/* * asap.ppjs - JavaScript version of ASAP * * Copyright (C) 2009 Piotr Fusik * * This file is part of ASAP (Another Slight Atari Player), * see http://asap.sourceforge.net * * ASAP is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published * by the Free Software Foundation; either version 2 of the License, * or (at your option) any later version. * * ASAP is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ASAP; if not, write to the Free Software Foundation, Inc., * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #define JAVASCRIPT var ASAP_VERSION = "2.0.0"; var ASAP_WAV_HEADER_BYTES = 44; var ASAP_SampleFormat = { U8 : 8, S16LE : 16, S16BE : -16 }; function ASAP_ParseDuration(s) { if (s == null || s.length == 0) return -1; var i = s.indexOf(":"); var r = 0; if (i >= 0) { r = parseInt(s.substring(0, i)) * 60000; s = s.substring(i + 1, s.length); } i = s.indexOf(" "); if (i >= 0) s = s.substring(0, i); r += Math.floor(parseFloat(s) * 1000); return r; } #include "acpu.c" #include "apokeysnd.c" #include "asap.c" function ASAP() { this.covox = new Array(4); this.base_pokey = { delta_buffer : new Array(888) }; this.extra_pokey = { delta_buffer : new Array(888) }; this.module_info = { durations : new Array(ASAP_SONGS_MAX), loops : new Array(ASAP_SONGS_MAX), song_pos : new Array(128) }; this.poly9_lookup = new Array(511); this.poly17_lookup = new Array(16385); this.memory = new Array(65536); this.load = function(filename, module) { if (!ASAP_Load(this, filename, module, module.length)) throw "ASAP load error"; } this.getModuleInfo = function() { return this.module_info; } this.playSong = function(song, duration) { ASAP_PlaySong(this, song, duration); } this.mutePokeyChannels = function(mask) { ASAP_MutePokeyChannels(this, mask); } this.getWavHeader = function(buffer, format) { ASAP_GetWavHeader(this, buffer, format); } this.generate = function(buffer, buffer_offset, buffer_len, format) { return ASAP_Generate(this, buffer, buffer_offset, buffer_len, format); } }