private byte ReadPort(ushort port) { port &= 0xFF; if (port >= 0xA0 && port < 0xC0) { if ((port & 1) == 0) { return(_vdp.ReadData()); } return(_vdp.ReadVdpStatus()); } if (port >= 0xE0) { if ((port & 1) == 0) { return(ReadController1()); } return(ReadController2()); } if (use_SGM) { if (port == 0x50) { return(SGM_sound.port_sel); } if (port == 0x52) { return(SGM_sound.ReadReg()); } if (port == 0x53) { return(port_0x53); } if (port == 0x7F) { return(port_0x7F); } } return(0xFF); }
private void SyncState(Serializer ser) { byte[] core = null; if (ser.IsWriter) { var ms = new MemoryStream(); ms.Close(); core = ms.ToArray(); } _cpu.SyncState(ser); ser.BeginSection("Coleco"); _vdp.SyncState(ser); ControllerDeck.SyncState(ser); PSG.SyncState(ser); SGM_sound.SyncState(ser); ser.Sync("UseSGM", ref use_SGM); ser.Sync("is_MC", ref is_MC); ser.Sync("MC_bank", ref MC_bank); ser.Sync("EnableSGMhigh", ref enable_SGM_high); ser.Sync("EnableSGMlow", ref enable_SGM_low); ser.Sync("Port_0x53", ref port_0x53); ser.Sync("Port_0x7F", ref port_0x7F); ser.Sync("RAM", ref _ram, false); ser.Sync("SGM_high_RAM", ref SGM_high_RAM, false); ser.Sync("SGM_low_RAM", ref SGM_low_RAM, false); ser.Sync("Frame", ref _frame); ser.Sync("LagCount", ref _lagCount); ser.Sync("IsLag", ref _isLag); ser.EndSection(); if (ser.IsReader) { SyncAllByteArrayDomains(); } }
public bool FrameAdvance(IController controller, bool render, bool renderSound) { _controller = controller; // NOTE: Need to research differences between reset and power cycle if (_controller.IsPressed("Power")) { HardReset(); } if (_controller.IsPressed("Reset")) { SoftReset(); } _frame++; _isLag = true; if (_tracer.Enabled) { _cpu.TraceCallback = s => _tracer.Put(s); } else { _cpu.TraceCallback = null; } byte tempRet1 = ControllerDeck.ReadPort1(controller, true, false); byte tempRet2 = ControllerDeck.ReadPort2(controller, true, false); bool intPending = false; // the return values represent the controller's current state, but the sampling rate is not high enough // to catch all changes in wheel orientation // so we use the wheel variable and interpolate between frames // first determine how many degrees the wheels changed, and how many regions have been traversed float change1 = (float)(((ControllerDeck.wheel1 - ControllerDeck.temp_wheel1) % 180) / 1.25); float change2 = (float)(((ControllerDeck.wheel2 - ControllerDeck.temp_wheel2) % 180) / 1.25); // special cases if ((ControllerDeck.temp_wheel1 > 270) && (ControllerDeck.wheel1 < 90)) { change1 = (float)((ControllerDeck.wheel1 + (360 - ControllerDeck.temp_wheel1)) / 1.25); } if ((ControllerDeck.wheel1 > 270) && (ControllerDeck.temp_wheel1 < 90)) { change1 = -(float)((ControllerDeck.temp_wheel1 + (360 - ControllerDeck.wheel1)) / 1.25); } if ((ControllerDeck.temp_wheel2 > 270) && (ControllerDeck.wheel2 < 90)) { change2 = (float)((ControllerDeck.wheel2 + (360 - ControllerDeck.temp_wheel2)) / 1.25); } if ((ControllerDeck.wheel2 > 270) && (ControllerDeck.temp_wheel2 < 90)) { change2 = -(float)((ControllerDeck.temp_wheel2 + (360 - ControllerDeck.wheel2)) / 1.25); } int changes1 = change1 > 0 ? (int)Math.Floor(change1) : (int)Math.Ceiling(change1); int changes2 = change2 > 0 ? (int)Math.Floor(change2) : (int)Math.Ceiling(change2); for (int scanLine = 0; scanLine < 262; scanLine++) { _vdp.RenderScanline(scanLine); if (scanLine == 192) { _vdp.InterruptPending = true; if (_vdp.EnableInterrupts) { _cpu.NonMaskableInterrupt = true; } } for (int i = 0; i < 228; i++) { PSG.generate_sound(1); if (use_SGM) { SGM_sound.generate_sound(1); } _cpu.ExecuteOne(); // pick out sound samples from the sound devices twice per scanline int v = PSG.Sample(); if (use_SGM) { v += SGM_sound.Sample(); } if (v != _latchedSample) { _blip.AddDelta((uint)_sampleClock, v - _latchedSample); _latchedSample = v; } _sampleClock++; } // starting from scanline 20, changes to the wheel are added once per scanline (up to 144) if (scanLine > 20) { if (changes1 != 0) { if (changes1 > 0) { ControllerDeck.temp_wheel1 = (float)((ControllerDeck.temp_wheel1 + 1.25) % 360); changes1--; } else { ControllerDeck.temp_wheel1 = (float)((ControllerDeck.temp_wheel1 - 1.25) % 360); changes1++; } } if (changes2 != 0) { if (changes2 > 0) { ControllerDeck.temp_wheel2 = (float)((ControllerDeck.temp_wheel2 + 1.25) % 360); changes2--; } else { ControllerDeck.temp_wheel2 = (float)((ControllerDeck.temp_wheel2 - 1.25) % 360); changes2++; } } } tempRet1 = ControllerDeck.ReadPort1(controller, true, true); tempRet2 = ControllerDeck.ReadPort2(controller, true, true); intPending = (!tempRet1.Bit(4) && temp_1_prev) | (!tempRet2.Bit(4) && temp_2_prev); _cpu.FlagI = false; if (intPending) { _cpu.FlagI = true; intPending = false; } temp_1_prev = tempRet1.Bit(4); temp_2_prev = tempRet2.Bit(4); } ControllerDeck.temp_wheel1 = ControllerDeck.wheel1; ControllerDeck.temp_wheel2 = ControllerDeck.wheel2; if (_isLag) { _lagCount++; } return(true); }
private void WritePort(ushort port, byte value) { port &= 0xFF; if (port >= 0xA0 && port <= 0xBF) { if ((port & 1) == 0) { _vdp.WriteVdpData(value); } else { _vdp.WriteVdpControl(value); } return; } if (port >= 0x80 && port <= 0x9F) { _inputPortSelection = InputPortMode.Right; return; } if (port >= 0xC0 && port <= 0xDF) { _inputPortSelection = InputPortMode.Left; return; } if (port >= 0xE0) { PSG.WriteReg(value); } if (use_SGM) { if (port == 0x50) { SGM_sound.port_sel = (byte)(value & 0xF); } if (port == 0x51) { SGM_sound.WriteReg(value); } if (port == 0x53) { if ((value & 1) > 0) { enable_SGM_high = true; } else { // NOTE: the documentation states that you shouldn't turn RAM back off once enabling it // so we won't do anything here } port_0x53 = value; } if (port == 0x7F) { if (value == 0xF) { enable_SGM_low = false; } else if (value == 0xD) { enable_SGM_low = true; } port_0x7F = value; } } }