This repository has been archived on 2026-04-18. You can view files and clone it, but cannot push or open issues or pull requests.
Virtual-Memory-Demo/Assets/Scripts/UI/SimulationTablesView.cs

49 lines
1.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using TMPro;
using UnityEngine;
using VMdemo.Simulation;
namespace VMdemo.UI
{
public class SimulationTablesView : MonoBehaviour
{
[SerializeField] private TMP_Text tlbText;
[SerializeField] private TMP_Text pageTableText;
[SerializeField] private TMP_Text fifoText;
public void ShowNotInitialized()
{
SetText(tlbText, "TLBN/A");
SetText(pageTableText, "页表N/A");
SetText(fifoText, "FIFON/A");
}
public void Render(TranslatorEngine engine)
{
if (engine == null)
{
ShowNotInitialized();
return;
}
var vpnBits = engine.VaBits - engine.OffsetBits;
var pfnBits = SimulationUIFormatter.ComputeBitsForCount(engine.PhysicalMemoryManager.FrameCount);
SetText(
tlbText,
SimulationUIFormatter.FormatTlbTable(
engine.TlbCache.GetEntriesMostRecentFirst(),
vpnBits,
pfnBits));
SetText(pageTableText, SimulationUIFormatter.FormatCurrentPageTableEntry(engine.State, engine.PageTable, engine.LastEviction));
SetText(fifoText, SimulationUIFormatter.FormatFifoQueue(engine.PhysicalMemoryManager.GetFifoVpnOrder()));
}
private static void SetText(TMP_Text target, string value)
{
if (target != null)
{
target.text = value;
}
}
}
}