Example #1
0
        /**
         * Copy in power on settings. These were created by running
         * the kernel reset routine and storing the useful values
         * from $0000-$03ff. Format is:
         * - offset byte (bit 7 indicates presence rle byte)
         * - rle count byte (bit 7 indicates compression used)
         * - data (single byte) or quantity represented by uncompressed count
         * all counts and offsets are 1 less than they should be
         */
        private void copyPoweronPattern(ref sidmemory mem)
        {
            UInt16 addr = 0;

            for (UInt32 i = 0; i < POWERON.Length;)
            {
                byte off        = POWERON[i++];
                byte count      = 0;
                bool compressed = false;

                // Determine data count/compression
                if ((off & 0x80) != 0)
                {
                    // fixup offset
                    off  &= 0x7f;
                    count = POWERON[i++];
                    if ((count & 0x80) != 0)
                    {
                        // fixup count
                        count     &= 0x7f;
                        compressed = true;
                    }
                }

                // Fix count off by ones (see format details)
                count++;
                addr += off;

                if (compressed)
                {
                    // Extract compressed data
                    byte data = POWERON[i++];
                    while (count-- > 0)
                    {
                        mem.writeMemByte(addr++, data);
                    }
                }
                else
                {
                    // Extract uncompressed data
                    while (count-- > 0)
                    {
                        mem.writeMemByte(addr++, POWERON[i++]);
                    }
                }
            }
        }
Example #2
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 #3
0
        public void install(ref sidmemory mem, byte video)
        {
            mem.fillRam(0, (byte)(0), 0x3ff);

            if (m_tuneInfo.compatibility() >= sidplayfp.SidTuneInfo.compatibility_t.COMPATIBILITY_R64)
            {
                copyPoweronPattern(ref mem);
            }

            // Set PAL/NTSC switch
            mem.writeMemByte(0x02a6, video);

            mem.installResetHook(sidendian.endian_little16(reloc_driver));

            // If not a basic tune then the psiddrv must install
            // interrupt hooks and trap programs trying to restart basic
            if (m_tuneInfo.compatibility() == sidplayfp.SidTuneInfo.compatibility_t.COMPATIBILITY_BASIC)
            {
                // Install hook to set subtune number for basic
                mem.setBasicSubtune((byte)(m_tuneInfo.currentSong() - 1));
                mem.installBasicTrap(0xbf53);
            }
            else
            {
                // Only install irq handle for RSID tunes
                mem.fillRam(0x0314, new Ptr <byte>(reloc_driver, 2), (UInt32)(m_tuneInfo.compatibility() == sidplayfp.SidTuneInfo.compatibility_t.COMPATIBILITY_R64 ? 2 : 6));

                // Experimental restart basic trap
                UInt16 addr = sidendian.endian_little16(new Ptr <byte>(reloc_driver, 8));
                mem.installBasicTrap(0xffe1);
                mem.writeMemWord(0x0328, addr);
            }

            Int32 pos = m_driverAddr;

            // Install driver to ram
            mem.fillRam((UInt16)pos, new Ptr <byte>(reloc_driver, 10), (UInt32)reloc_size);

            // Set song number
            mem.writeMemByte((UInt16)pos, (byte)(m_tuneInfo.currentSong() - 1));
            pos++;

            // Set tunes speed (VIC/CIA)
            mem.writeMemByte((UInt16)pos, (byte)(m_tuneInfo.songSpeed() == sidplayfp.SidTuneInfo.SPEED_VBI ? 0 : 1));
            pos++;

            // Set init address
            mem.writeMemWord((UInt16)pos, (UInt16)(m_tuneInfo.compatibility() == sidplayfp.SidTuneInfo.compatibility_t.COMPATIBILITY_BASIC ?
                                                   0xbf55 : m_tuneInfo.initAddr()));
            pos += 2;

            // Set play address
            mem.writeMemWord((UInt16)pos, m_tuneInfo.playAddr());
            pos += 2;

            // Set init address io bank value
            mem.writeMemByte((UInt16)pos, iomap(m_tuneInfo.initAddr()));
            pos++;

            // Set play address io bank value
            mem.writeMemByte((UInt16)pos, iomap(m_tuneInfo.playAddr()));
            pos++;

            // Set PAL/NTSC flag
            mem.writeMemByte((UInt16)pos, video);
            pos++;

            // Set the required tune clock speed
            byte clockSpeed;

            switch (m_tuneInfo.clockSpeed())
            {
            case sidplayfp.SidTuneInfo.clock_t.CLOCK_PAL:
                clockSpeed = 1;
                break;

            case sidplayfp.SidTuneInfo.clock_t.CLOCK_NTSC:
                clockSpeed = 0;
                break;

            default:     // UNKNOWN or ANY
                clockSpeed = video;
                break;
            }
            mem.writeMemByte((UInt16)pos, clockSpeed);
            pos++;

            // Set default processor register flags on calling init
            mem.writeMemByte((UInt16)pos, (byte)(m_tuneInfo.compatibility() >= sidplayfp.SidTuneInfo.compatibility_t.COMPATIBILITY_R64 ? 0 : 1 << c64.CPU.MOS6510.SR_INTERRUPT));

            //Console.WriteLine("{0}",mem.readMemByte(0x17e3));
        }