/* * ASAP.ppas - ActionScript 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 */ package { import flash.utils.ByteArray; public class ASAP { #define ACTIONSCRIPT #define ASAP_State ASAP #define ASAP_SampleFormat int #include "acpu.c" #include "apokeysnd.c" #include "asap.c" private var cycle : int; private var cpu_pc : int; private var cpu_a : int; private var cpu_x : int; private var cpu_y : int; private var cpu_s : int; private var cpu_nz : int; private var cpu_c : int; private var cpu_vdi : int; private var scanline_number : int; private var nearest_event_cycle : int; private var next_scanline_cycle : int; private var timer1_cycle : int; private var timer2_cycle : int; private var timer4_cycle : int; private var irqst : int; private var extra_pokey_mask : int; private var consol : int; private var covox : Array = new Array(4); private const base_pokey : PokeyState = new PokeyState(); private const extra_pokey : PokeyState = new PokeyState(); private var sample_offset : int; private var sample_index : int; private var samples : int; private var iir_acc_left : int; private var iir_acc_right : int; private const module_info : ASAP_ModuleInfo = new ASAP_ModuleInfo(); private var tmc_per_frame : int; private var tmc_per_frame_counter : int; private var current_song : int; private var current_duration : int; private var blocks_played : int; private var silence_cycles : int; private var silence_cycles_counter : int; private const poly9_lookup : ByteArray = new ByteArray(); private const poly17_lookup : ByteArray = new ByteArray(); private const memory : ByteArray = new ByteArray(); public static const VERSION : String = "2.0.0"; public static function parseDuration(s : String) : int { if (s == null || s.length == 0) return -1; var i : int = s.indexOf(":"); var r : int = 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; } public function load(filename : String, module : ByteArray) : void { if (!ASAP_Load(this, filename, module, module.length)) throw "ASAP load error"; } public function get moduleInfo() : ASAP_ModuleInfo { return this.module_info; } public function playSong(song : int, duration : int) : void { ASAP_PlaySong(this, song, duration); } public function mutePokeyChannels(mask : int) : void { ASAP_MutePokeyChannels(this, mask); } public function generate(buffer : ByteArray, buffer_len : int) : int { return ASAP_Generate(this, buffer, buffer_len, 0); } } }