From 7b9ad33be265afc6cc729e309d6b076a2f069147 Mon Sep 17 00:00:00 2001 From: Nabile Rahmani Date: Tue, 11 Dec 2018 20:36:16 +0100 Subject: [PATCH] Fixed SI interrupts and moved memory maps. --- DotN64/PIF/PeripheralInterface.cs | 21 +---------- DotN64/RCP/RealityCoprocessor.cs | 4 +-- .../SI/RealityCoprocessor.SerialInterface.cs | 36 +++++++++++++++++-- 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/DotN64/PIF/PeripheralInterface.cs b/DotN64/PIF/PeripheralInterface.cs index eaa3111..0aaa80f 100644 --- a/DotN64/PIF/PeripheralInterface.cs +++ b/DotN64/PIF/PeripheralInterface.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; namespace DotN64 { @@ -16,8 +15,6 @@ namespace DotN64 #endregion #region Properties - public IReadOnlyList MemoryMaps { get; } - public byte[] BootROM { get; set; } public byte[] RAM { get; } = new byte[64]; @@ -33,22 +30,6 @@ namespace DotN64 public PeripheralInterface(Nintendo64 nintendo64) { this.nintendo64 = nintendo64; - MemoryMaps = new[] - { - new MappingEntry(0x1FC00000, 0x1FC007BF) // PIF Boot ROM. - { - Read = o => BitHelper.FromBigEndian(BitConverter.ToUInt32(BootROM, (int)o)) - }, - new MappingEntry(0x1FC007C0, 0x1FC007FF) // PIF (JoyChannel) RAM. - { - Read = o => BitConverter.ToUInt32(RAM, (int)o), - Write = (o, d) => - { - BitHelper.Write(RAM, (int)o, d); - OnRAMWritten((int)o); - } - } - }; } #endregion @@ -57,7 +38,7 @@ namespace DotN64 /// Called when a word is written at a specified index in the RAM. /// Handles actions sent through memory writes. /// - private void OnRAMWritten(int index) + internal void OnRAMWritten(int index) { switch (index) { diff --git a/DotN64/RCP/RealityCoprocessor.cs b/DotN64/RCP/RealityCoprocessor.cs index 3938a0b..f40cb7d 100644 --- a/DotN64/RCP/RealityCoprocessor.cs +++ b/DotN64/RCP/RealityCoprocessor.cs @@ -95,8 +95,8 @@ namespace DotN64.RCP }, new MappingEntry(0x1FC00000, 0x1FC007FF, false) { - Read = nintendo64.PIF.MemoryMaps.ReadWord, - Write = nintendo64.PIF.MemoryMaps.WriteWord + Read = SI.MemoryMaps.ReadWord, + Write = SI.MemoryMaps.WriteWord } }; } diff --git a/DotN64/RCP/SI/RealityCoprocessor.SerialInterface.cs b/DotN64/RCP/SI/RealityCoprocessor.SerialInterface.cs index 0e88916..7602cca 100644 --- a/DotN64/RCP/SI/RealityCoprocessor.SerialInterface.cs +++ b/DotN64/RCP/SI/RealityCoprocessor.SerialInterface.cs @@ -1,10 +1,16 @@ -namespace DotN64.RCP +using System; + +namespace DotN64.RCP { + using Helpers; + public partial class RealityCoprocessor { public partial class SerialInterface : Interface { #region Properties + private PeripheralInterface PIF => rcp.nintendo64.PIF; + public Statuses Status { get; set; } #endregion @@ -17,11 +23,37 @@ new MappingEntry(0x04800018, 0x0480001B) // SI status. { Read = o => (uint)Status, - Write = (o, d) => Status &= ~Statuses.Interrupt + Write = (o, d) => + { + Status &= ~Statuses.Interrupt; + rcp.MI.Interrupt &= ~MIPSInterface.Interrupts.SI; + } + }, + new MappingEntry(0x1FC00000, 0x1FC007BF) // PIF Boot ROM. + { + Read = o => BitHelper.FromBigEndian(BitConverter.ToUInt32(PIF.BootROM, (int)o)) + }, + new MappingEntry(0x1FC007C0, 0x1FC007FF) // PIF (JoyChannel) RAM. + { + Read = o => BitConverter.ToUInt32(PIF.RAM, (int)o), + Write = (o, d) => + { + BitHelper.Write(PIF.RAM, (int)o, d); + PIF.OnRAMWritten((int)o); + Interrupt(); + } } }; } #endregion + + #region Methods + private void Interrupt() + { + Status |= Statuses.Interrupt; + rcp.MI.Interrupt |= MIPSInterface.Interrupts.SI; + } + #endregion } } }