// SIDFX // Copyright (C) 2004 Ian Cowburn // // This program 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. // // This program 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 this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // // $Id$ // using System; using HardsidInterface; namespace SIDFX { /// /// Description of SID. /// public class SID { [Flags] public enum ControlFlag { NOISE=128, PULSE=64, SAW=32, TRIANGLE=16, TEST=8, RING=4, SYNC=2, GATE=1, NONE=0 }; [Flags] public enum FilterFlag { OFF3=128, HP=64, BP=32, LP=16, EXT=8, V3=4, V2=2, V1=1, NONE=0 }; public static void Volume(byte volume) { byte v=(byte)(Hardsid.Read(24)&0xf0u); v|=volume; Hardsid.Write(24,v); } public static void Frequency(byte voice, uint val) { byte r=(byte)(voice*7); byte h=(byte)(val>>8); byte l=(byte)(val&0xff); Hardsid.Write(r,l); Hardsid.Write(r+1u,h); } public static void PulseWidth(byte voice, uint val) { byte r=(byte)(voice*7); byte h=(byte)(val>>8); byte l=(byte)(val&0xff); Hardsid.Write(r+2u,l); Hardsid.Write(r+3u,h); } public static void ADSR(byte voice, byte attack, byte decay, byte sustain, byte release) { byte r=(byte)(voice*7); byte ad=(byte)(((attack&0x0fu)<<4)|(decay&0x0fu)); byte sr=(byte)(((sustain&0x0fu)<<4)|(release&0x0fu)); Hardsid.Write(r+5u,ad); Hardsid.Write(r+6u,sr); } public static void Control(byte voice, ControlFlag control) { byte r=(byte)(voice*7); Hardsid.Write(r+4u,(uint)control); } public static void Cutoff(uint val) { byte h=(byte)(val>>3); byte l=(byte)(val&0x7); Hardsid.Write(21,l); Hardsid.Write(22+1u,h); } public static void Resonance(byte val) { byte v=(byte)(Hardsid.Read(23)&0x0fu); v|=(byte)((val&0x0fu)<<4); Hardsid.Write(23,v); } public static void Filter(FilterFlag flags) { byte h=(byte)((uint)flags&0xf0u); byte l=(byte)((uint)flags&0x0fu); byte v=(byte)(Hardsid.Read(23)&0xf0u); v|=l; Hardsid.Write(23,v); v=(byte)(Hardsid.Read(24)&0x0fu); v|=h; Hardsid.Write(24,v); } private SID() {} } }