public ADSPlayer(Resource.ADS ads)
        {
            screen   = new Bitmap(640, 480);
            g        = Graphics.FromImage(screen);
            this.ads = ads;
            bwads.WorkerReportsProgress      = true;
            bwads.WorkerSupportsCancellation = true;
            bwads.DoWork             += play;
            bwads.RunWorkerCompleted += bw_RunWorkerCompleted;
            //Debug.WriteLine("Properties:");
            //Debug.WriteLine("id\tname:");
            foreach (Resource.ADS.ResourceProperty rp in ads.resourceproperties)
            {
                //Debug.WriteLine(rp.id.ToString("X4") + "\t" + rp.name);
                Resource.TTM ttm       = (Resource.TTM)ResourceManager.get(rp.name);
                TTMPlayer    ttmplayer = new TTMPlayer(ttm, screen);
                //ttmplayer.bw.RunWorkerCompleted += bw_RunWorkerCompleted;
                ttmplayer.bw.ProgressChanged += bw_ProgressChanged;
                ttms.Add(rp.id, ttmplayer);

                /*foreach (UInt16 key in ttm.tags.Keys)
                 * {
                 * Debug.WriteLine("\t" + key.ToString("X4") + "\t" + ttm.tags[key]);
                 * }*/
            }
        }
 public void playAndWait(TTMPlayer ttmplayer, UInt16 instructionno)
 {
     ttmplayer.bw.RunWorkerAsync(instructionno);
     System.Threading.Thread.Sleep(20);
     while (ttmplayer.Playing)
     {
         System.Threading.Thread.Sleep(20);
     }
 }
        public void playTTMInstruction(Instruction instruction)
        {
            TTMPlayer ttmplayer = ttms[instruction.data[0]];

            //System.Diagnostics.Debug.WriteLine("ttm: " + instruction.data[0].ToString("X2") + ", sequence: " + instruction.data[1].ToString("X2"));
            playAndWait(ttmplayer, instruction.data[1]);
            byte repeat = (byte)(instruction.data[2] & 0xff);

            if (repeat > 0)
            {
                //System.Diagnostics.Debug.WriteLine("repeating: " + repeat);
                for (int i = 1; i < repeat; i++)
                {
                    //System.Diagnostics.Debug.WriteLine("ttm: " + instruction.data[0].ToString("X2") + ", sequence: " + instruction.data[1].ToString("X2"));
                    playAndWait(ttmplayer, instruction.data[1]);
                    //                System.Threading.Thread.Sleep(100);
                }
            }
            lastplayed.Add(getTouple(instruction.data[0], instruction.data[1]));
        }