Example #1
0
        public Player()
        {
            // Set default settings for system
            m_tune        = null;
            m_errorString = ERR_NA;
            m_isPlaying   = state_t.STOPPED;
            //# ifdef PC64_TESTSUITE
            m_c64.setTestEnv(this);
            //#endif

            m_c64.setRoms(null, null, null);
            config(ref m_cfg);

            // Get component credits
            m_info.m_credits.Add(m_c64.cpuCredits());
            m_info.m_credits.Add(m_c64.ciaCredits());
            m_info.m_credits.Add(m_c64.vicCredits());
        }
Example #2
0
        public void rxbyte(byte b)
        {
            if (escaped)
            {
                escaped = false;
                switch (b)
                {
                case type_sync:
                    if (streamsyncrx != null)
                    {
                        streamsyncrx(this);
                    }
                    return;

                case type_msg:
                    rxstate   = state_t.message;
                    byteidx   = 0;
                    msglength = 0;
                    return;

                default: break;
                }
                if (1 <= b && b <= 4)
                {
                    layer2(escaped_codes[b - 1]);
                    return;
                }
                System.Console.WriteLine("Ooops got escaped 0x{0:X2}", b);
            }
            else
            {
                if (b == escape)
                {
                    escaped = true;
                }
                else
                {
                    layer2(b);
                }
            }
        }
Example #3
0
        private void initialise()
        {
            m_isPlaying = state_t.STOPPED;

            m_c64.reset();

            sidplayfp.SidTuneInfo tuneInfo = m_tune.getInfo();

            UInt32 size = (UInt32)(tuneInfo.loadAddr()) + tuneInfo.c64dataLen() - 1;

            if (size > 0xffff)
            {
                throw new configError(ERR_UNSUPPORTED_SIZE);
            }

            psiddrv driver = new psiddrv(m_tune.getInfo());

            if (!driver.drvReloc())
            {
                throw new configError(driver.errorString());
            }

            m_info.m_driverAddr   = driver.driverAddr();
            m_info.m_driverLength = driver.driverLength();

            sidmemory sm = m_c64.getMemInterface();

            driver.install(ref sm, videoSwitch);

            sm = m_c64.getMemInterface();
            if (!m_tune.placeSidTuneInC64mem(ref sm))
            {
                throw new configError(m_tune.statusString());
            }

            m_c64.resetCpu();
            //Console.WriteLine("{0:x}", sm.readMemByte(0x17e3));
        }
Example #4
0
        private void layer2(byte b)
        {
            if (rxstate == state_t.stream)
            {
                if (streambyterx != null)
                {
                    streambyterx(b, this);
                }
            }

            if (rxstate == state_t.message)
            {
                switch (byteidx)
                {
                case 0: msglength = (uint)b * 256;
                    break;

                case 1: msglength += b;
                    msgbuffer      = new byte[msglength];
                    break;

                default:
                    msgbuffer[byteidx - 2] = b;
                    break;
                }
                byteidx++;
                if (msglength + 2 == byteidx)
                {
                    /* recieved last byte of message */
                    if (messagerx != null)
                    {
                        messagerx(msgbuffer, this);
                    }
                    rxstate = state_t.stream;
                }
            }
        }
Example #5
0
    public bool zread_buff()
    {
        switch (this.zs_state)
        {
        case state_t.S_START:
            this.zs_state = state_t.S_EOB;
            break;

        case state_t.S_MIDDLE:
            goto middleing;
            break;

        case state_t.S_STREAMING:
            goto streaming;
            break;

        case state_t.S_EOB:
            goto streamstart;
            break;
        }

        this.zs_n_bits  = BITS;
        this.zs_maxcode = ((1 << (this.zs_n_bits)) - 1);
        for (this.s_read.zs_code = 255; this.s_read.zs_code >= 0; this.s_read.zs_code--)
        {
            this.zs_codetab[this.s_read.zs_code] = 0;
            this.zs_htab[this.s_read.zs_code]    = (char)this.s_read.zs_code;
        }

        this.zs_free_ent      = (this.zs_block_compress != 0) ? 258 : 256;
        this.s_read.zs_stackp = 1 << BITS;

streamstart:
        this.s_read.zs_oldcode = this.getcode();
        if (this.s_read.zs_oldcode == -1) /* EOF already? */
        {
            return(false);                /* Get out of here */
        }

        if (this.s_read.zs_oldcode == EOB || this.s_read.zs_oldcode == CLEAR)
        {
            // 出错了
            return(false);
        }

        this.zs_state = state_t.S_STREAMING;
        if (this.s_read.zs_oldcode < 256)
        {
            this.s_read.zs_finchar = this.s_read.zs_oldcode;
            this.s_read.reader.zreader_output((byte)this.s_read.zs_finchar);
        }
        else
        {
            int code_ = this.s_read.zs_oldcode;
            while (code_ >= 256)
            {
                this.zs_htab[this.s_read.zs_stackp++] = this.zs_htab[code_];
                code_ = (int)this.zs_codetab[code_];
            }
            this.s_read.zs_finchar = this.zs_htab[code_];
            this.zs_htab[this.s_read.zs_stackp++] = this.s_read.zs_finchar;

            do
            {
                this.s_read.reader.zreader_output((byte)(this.zs_htab[--this.s_read.zs_stackp]));
            }while(this.s_read.zs_stackp > (1 << BITS));
        }

streaming:
        while ((this.s_read.zs_code = this.getcode()) > -1)
        {
            if (this.s_read.zs_code == EOB)
            {
                this.zs_state = state_t.S_EOB;
                return(true);
            }

            if ((this.s_read.zs_code == CLEAR) && this.zs_block_compress > 0)
            {
                for (this.s_read.zs_code = 255; this.s_read.zs_code >= 0; this.s_read.zs_code--)
                {
                    this.zs_codetab[this.s_read.zs_code] = 0;
                }
                this.zs_clear_flg = 1;
                this.zs_free_ent  = FIRST - 1;
                if ((this.s_read.zs_code = this.getcode()) == -1)
                {
                    break;
                }
            }
            this.s_read.zs_incode = this.s_read.zs_code;
            if (this.s_read.zs_code >= this.zs_free_ent)
            {
                this.zs_htab[this.s_read.zs_stackp++] = this.s_read.zs_finchar;
                this.s_read.zs_code = this.s_read.zs_oldcode;
            }

            while (this.s_read.zs_code >= 256)
            {
                this.zs_htab[this.s_read.zs_stackp++] = this.zs_htab[this.s_read.zs_code];
                this.s_read.zs_code = (int)this.zs_codetab[this.s_read.zs_code];
            }
            this.s_read.zs_finchar = this.zs_htab[this.s_read.zs_code];
            this.zs_htab[this.s_read.zs_stackp++] = this.s_read.zs_finchar;
            goto middleing;
        }

        goto end;

middleing:
        {
            do
            {
                this.s_read.reader.zreader_output((byte)(this.zs_htab[--this.s_read.zs_stackp]));
            }while(this.s_read.zs_stackp > (1 << BITS));

            //bool is_goto_end = (this.s_read.zs_code > -1)?false:true;
            bool is_goto_end = false;
            if ((this.s_read.zs_code = this.zs_free_ent) < this.zs_maxmaxcode)
            {
                this.zs_codetab[this.s_read.zs_code] = (uint)this.s_read.zs_oldcode;
                this.zs_htab[this.s_read.zs_code]    = this.s_read.zs_finchar;
                this.zs_free_ent = this.s_read.zs_code + 1;
            }
            this.s_read.zs_oldcode = this.s_read.zs_incode;
            if (!is_goto_end)
            {
                goto streaming;
            }
            else
            {
                goto end;
            }
        }

end:
        return(false);
    }
Example #6
0
    public int zwrite_buff(byte[] wbp, int num)
    {
        int bp_index = 0;
        int i;
        int c, disp;

        byte[] bp;
        int    count;

        if (num == 0)
        {
            return(0);
        }

        count = num;
        bp    = (byte[])wbp;

        if (this.zs_state == state_t.S_MIDDLE)
        {
            goto middle;
        }

        this.zs_state          = state_t.S_MIDDLE;
        this.zs_maxmaxcode     = (int)(1L << this.zs_maxbits);
        this.zs_offset         = 0;
        this.zs_bytes_out      = 3;
        this.zs_out_count      = 0;
        this.zs_clear_flg      = 0;
        this.zs_ratio          = 0;
        this.zs_in_count       = 1;
        this.zs_checkpoint     = 10000;
        this.zs_free_ent       = ((this.zs_block_compress != 0)? FIRST : 256);
        this.zs_n_bits         = BITS;
        this.zs_maxcode        = ((1 << (this.zs_n_bits)) - 1);
        this.s_write.zs_hshift = 0;
        for (this.s_write.zs_fcode = (long)this.zs_hsize; this.s_write.zs_fcode < 65536L; this.s_write.zs_fcode *= 2L)
        {
            this.s_write.zs_hshift++;
        }

        this.s_write.zs_hshift    = 8 - this.s_write.zs_hshift;
        this.s_write.zs_hsize_reg = this.zs_hsize;
        this.cl_hash(this.s_write.zs_hsize_reg);

        middle : this.s_write.zs_ent = bp[bp_index++];
        --count;
        for (i = 0; count > 0; count--)
        {
            c = bp[bp_index++];
            this.zs_in_count++;
            this.s_write.zs_fcode = (long)(((long)c << this.zs_maxbits) + this.s_write.zs_ent);
            i = ((c << this.s_write.zs_hshift) ^ this.s_write.zs_ent);
            if (this.zs_htab[i] == this.s_write.zs_fcode)
            {
                this.s_write.zs_ent = (int)this.zs_codetab[i];
                continue;
            }
            else if ((long)this.zs_htab[i] < 0)
            {
                goto nomatch;
            }

            disp = this.s_write.zs_hsize_reg - i;
            if (i == 0)
            {
                disp = 1;
            }

            probe :          if ((i -= disp) < 0)
            {
                i += this.s_write.zs_hsize_reg;
            }

            if (this.zs_htab[i] == this.s_write.zs_fcode)
            {
                this.s_write.zs_ent = (int)this.zs_codetab[i];
                continue;
            }

            if ((long)this.zs_htab[i] >= 0)
            {
                goto probe;
            }

            nomatch :        if (this.output((int)this.s_write.zs_ent) == -1)
            {
                return(-1);
            }
            this.zs_out_count++;
            this.s_write.zs_ent = c;
            if (this.zs_free_ent < this.zs_maxmaxcode)
            {
                this.zs_codetab[i] = (UInt16)(this.zs_free_ent++);
                this.zs_htab[i]    = (int)this.s_write.zs_fcode;
            }
            else if ((int)this.zs_in_count >= this.zs_checkpoint && this.zs_block_compress != 0)
            {
                if (this.cl_block() == -1)
                {
                    return(-1);
                }
            }
        }

        if (output((int)this.s_write.zs_ent) == -1)
        {
            return(-1);
        }
        this.zs_out_count++;

        if (output((int)EOB) == -1)
        {
            return(-1);
        }

        if (output((int)-1) == -1)
        {
            return(-1);
        }

        return(num);
    }
Example #7
0
 public lop()
 {
     escaped = false;
     rxstate = state_t.stream;
 }
Example #8
0
        public UInt32 play(Int16[] buffer, UInt32 count)
        {
            // Make sure a tune is loaded
            if (m_tune == null)
            {
                return(0);
            }

            // Start the player loop
            if (m_isPlaying == state_t.STOPPED)
            {
                m_isPlaying = state_t.PLAYING;
            }

            if (m_isPlaying == state_t.PLAYING)
            {
                m_mixer.begin(buffer, count);
                //MDPlayer.log.Write(string.Format("{0}", count));
                try
                {
                    if (m_mixer.getSid(0) != null)
                    {
                        if (count != 0 && buffer != null)
                        {
                            // Clock chips and mix into output buffer
                            while (m_isPlaying != state_t.STOPPED && m_mixer.notFinished())
                            {
                                run((UInt32)sidemu.output.OUTPUTBUFFERSIZE);

                                m_mixer.clockChips();
                                m_mixer.doMix();
                            }
                            count = m_mixer.samplesGenerated();
                        }
                        else
                        {
                            // Clock chips and discard buffers
                            int size = (Int32)(m_c64.getMainCpuSpeed() / m_cfg.frequency);
                            while (m_isPlaying != state_t.STOPPED && (--size) != 0)
                            {
                                run((UInt32)sidemu.output.OUTPUTBUFFERSIZE);

                                m_mixer.clockChips();
                                m_mixer.resetBufs();
                            }
                        }
                    }
                    else
                    {
                        // Clock the machine
                        int size = (Int32)(m_c64.getMainCpuSpeed() / m_cfg.frequency);
                        while (m_isPlaying != state_t.STOPPED && (--size) != 0)
                        {
                            run((UInt32)sidemu.output.OUTPUTBUFFERSIZE);
                        }
                    }
                }
                catch //(MOS6510.haltInstruction const &)
                {
                    m_errorString = "Illegal instruction executed";
                    m_isPlaying   = state_t.STOPPING;
                }
            }

            if (m_isPlaying == state_t.STOPPING)
            {
                try
                {
                    initialise();
                }
                catch
                { //(configError const &) { }
                    m_isPlaying = state_t.STOPPED;
                }
            }

            return(count);
        }