Skip to content
This repository has been archived by the owner on May 24, 2019. It is now read-only.

Commit

Permalink
UI Enhancement (#14)
Browse files Browse the repository at this point in the history
* Some User Interface Enhancement

* Fix a dumb mistake

* Remove PIF loading

* Change paths directory to application data
  • Loading branch information
Dudejoe870 committed Dec 2, 2018
1 parent 3e0fa71 commit 8a06fb5
Show file tree
Hide file tree
Showing 13 changed files with 183 additions and 180 deletions.
37 changes: 6 additions & 31 deletions Ryu64.Common/Settings.cs
Expand Up @@ -7,46 +7,21 @@ namespace Ryu64.Common
{
public class Settings
{
public static bool DEBUG;
public static bool SUPPORT_CPUTEST_SYSCALL;
public static bool LOAD_PIF;
public static bool MEASURE_SPEED;
public static bool LOG_MEM_USAGE;
public static bool DUMP_MEMORY;
public static uint DUMP_MEMORY_START;
public static uint DUMP_MEMORY_END;
public static bool STEP_MODE;
public static bool LLE;
public static string PIF_ROM = "";
public static bool STEP_MODE;
public static bool GRAPHICS_LLE;

public static void Parse(string SettingsFile)
{
try
{
IniParser Parse = new IniParser(SettingsFile);
DEBUG = bool.Parse(Parse.Value("DEBUG", "false"));
SUPPORT_CPUTEST_SYSCALL = bool.Parse(Parse.Value("SUPPORT_CPUTEST_SYSCALL", "false"));
LOAD_PIF = bool.Parse(Parse.Value("LOAD_PIF", "false"));
MEASURE_SPEED = bool.Parse(Parse.Value("MEASURE_SPEED", "false"));
LOG_MEM_USAGE = bool.Parse(Parse.Value("LOG_MEM_USAGE", "false"));
DUMP_MEMORY = bool.Parse(Parse.Value("DUMP_MEMORY", "false"));
DUMP_MEMORY_START = Convert.ToUInt32(Parse.Value("DUMP_MEMORY_START", "0x0"), 16);
DUMP_MEMORY_END = Convert.ToUInt32(Parse.Value("DUMP_MEMORY_END", "0x0"), 16);
LLE = bool.Parse(Parse.Value("LLE", "false"));
STEP_MODE = bool.Parse(Parse.Value("STEP_MODE", "false"));
GRAPHICS_LLE = bool.Parse(Parse.Value("GRAPHICS_LLE", "false"));
STEP_MODE = bool.Parse(Parse.Value("STEP_MODE", "false"));
}
catch
{
DEBUG = false;
SUPPORT_CPUTEST_SYSCALL = false;
LOAD_PIF = false;
MEASURE_SPEED = false;
LOG_MEM_USAGE = false;
DUMP_MEMORY = false;
LLE = false;
STEP_MODE = false;
DUMP_MEMORY_START = 0x0;
DUMP_MEMORY_END = 0x0;
GRAPHICS_LLE = false;
STEP_MODE = false;
}
}

Expand Down
10 changes: 3 additions & 7 deletions Ryu64.Common/Util.cs
Expand Up @@ -6,13 +6,9 @@ public class Util
{
public static void Cleanup(uint PC)
{
if (Settings.MEASURE_SPEED)
{
Measure.MeasureTime.Stop();
Logger.PrintSuccessLine($"Took {Measure.MeasureTime.Elapsed:c}, Instructions Executed: {Measure.InstructionCount}, Cycles Counted: {Measure.CycleCounter}, stopped at 0x{PC:x8}.");
}

if (Settings.LOG_MEM_USAGE) Logger.PrintSuccessLine($"Allocated: {GC.GetTotalMemory(false) / 1024:#,#} kb");
Measure.MeasureTime.Stop();
Logger.PrintSuccessLine($"Took {Measure.MeasureTime.Elapsed:c}, Instructions Executed: {Measure.InstructionCount}, Cycles Counted: {Measure.CycleCounter}, stopped at 0x{PC:x8}.");
Logger.PrintSuccessLine($"Allocated: {GC.GetTotalMemory(false) / 1024:#,#} kb");
}

public static unsafe ulong DoubleToUInt64(double value)
Expand Down
10 changes: 8 additions & 2 deletions Ryu64.Common/Variables.cs
@@ -1,7 +1,13 @@
namespace Ryu64.Common
using System;

namespace Ryu64.Common
{
public class Variables
{
public static bool Step = false;
public static bool Step = false;
public static bool UTEsyscall = false;
public static bool Debug = false;

public static string AppdataFolder = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}/Ryu64";
}
}
1 change: 1 addition & 0 deletions Ryu64.Formats/CartFormat.cs
Expand Up @@ -10,6 +10,7 @@ public CartFormat(string Path)
}

public byte[] AllData;
public string Name;

public bool HasBeenParsed = false;

Expand Down
5 changes: 5 additions & 0 deletions Ryu64.Formats/Z64.cs
Expand Up @@ -19,6 +19,11 @@ public override void Parse()
if (!IsCorrectEndian)
return;

Name = "";

for (int i = 0; i < 27; ++i)
Name += (char)AllData[i + 0x20];

HasBeenParsed = true;
}
}
Expand Down
13 changes: 8 additions & 5 deletions Ryu64.Graphics/MainWindow.cs
Expand Up @@ -10,16 +10,18 @@ namespace Ryu64.Graphics
{
public class MainWindow : GameWindow
{
private const string BaseTitle = "Ryu64";
private static string BaseTitle = "Ryu64";
private static uint CurrentScanline = 0;
private static int FramebufferTexture;

public MainWindow() : base(960, 720, GraphicsMode.Default, BaseTitle,
public MainWindow(string GameName) : base(960, 720, GraphicsMode.Default, BaseTitle,
GameWindowFlags.FixedWindow,
DisplayDevice.Default,
3, 1,
GraphicsContextFlags.ForwardCompatible)
{
BaseTitle += $" | {GameName}";

Thread ScanlineThread = new Thread(() =>
{
while (MIPS.R4300.R4300_ON)
Expand All @@ -30,6 +32,7 @@ public class MainWindow : GameWindow
CurrentScanline = 0;
}
});
ScanlineThread.Name = "VIScanlineThread";
ScanlineThread.Start();
}

Expand All @@ -50,7 +53,7 @@ protected override void OnLoad(EventArgs e)

GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);

if (Common.Settings.LLE)
if (Common.Settings.GRAPHICS_LLE)
{
GL.Disable(EnableCap.DepthTest);

Expand Down Expand Up @@ -81,7 +84,7 @@ protected override void OnRenderFrame(FrameEventArgs e)
base.OnRenderFrame(e);

GL.ClearColor(0, 0, 0, 1);
if (Common.Settings.LLE)
if (Common.Settings.GRAPHICS_LLE)
{
GL.Clear(ClearBufferMask.ColorBufferBit);
RenderFramebufferDirect();
Expand All @@ -98,7 +101,7 @@ protected override void OnClosing(CancelEventArgs e)
{
base.OnClosing(e);

if (Common.Settings.LLE)
if (Common.Settings.GRAPHICS_LLE)
GL.DeleteTexture(FramebufferTexture);

Common.Util.Cleanup(MIPS.Registers.R4300.PC);
Expand Down
12 changes: 2 additions & 10 deletions Ryu64.MIPS/Interpreter/COP0.cs
Expand Up @@ -10,16 +10,8 @@ public static void PowerOnCOP0()
Registers.COP0.Reg[i] = 0; // Clear Registers.

Registers.COP0.Reg[Registers.COP0.COMPARE_REG] = 0xFFFFFFFF;

if (!Common.Settings.LOAD_PIF)
{
Registers.COP0.Reg[Registers.COP0.STATUS_REG] = 0x34000000;
Registers.COP0.Reg[Registers.COP0.CONFIG_REG] = 0x0006E463;
}
else
{
Registers.COP0.Reg[Registers.COP0.STATUS_REG] = 0x00400004;
}
Registers.COP0.Reg[Registers.COP0.STATUS_REG] = 0x34000000;
Registers.COP0.Reg[Registers.COP0.CONFIG_REG] = 0x0006E463;

COP0_ON = true;
}
Expand Down
2 changes: 1 addition & 1 deletion Ryu64.MIPS/Interpreter/InstInterpSpecial.cs
Expand Up @@ -6,7 +6,7 @@ public partial class InstInterp
{
public static void SYSCALL(OpcodeTable.OpcodeDesc Desc)
{
if (Desc.op4 > 0 && Common.Settings.SUPPORT_CPUTEST_SYSCALL)
if (Desc.op4 > 0 && Common.Variables.UTEsyscall)
{
// Special type of SYSCALL used for the Fraser CPU Tests
char TestChar = (char)(Desc.op2 + 64);
Expand Down
138 changes: 38 additions & 100 deletions Ryu64.MIPS/Interpreter/R4300.cs
Expand Up @@ -114,7 +114,7 @@ public static void InterpretOpcode(uint Opcode)
OpcodeTable.OpcodeDesc Desc = new OpcodeTable.OpcodeDesc(Opcode);
OpcodeTable.InstInfo Info = OpcodeTable.GetOpcodeInfo(Opcode);

if (Common.Settings.DEBUG)
if (Common.Variables.Debug)
{
string ASM = string.Format(
Info.FormattedASM,
Expand All @@ -131,61 +131,47 @@ public static void InterpretOpcode(uint Opcode)
if (Registers.COP0.Reg[Registers.COP0.RANDOM_REG] < Registers.COP0.Reg[Registers.COP0.WIRED_REG])
Registers.COP0.Reg[Registers.COP0.RANDOM_REG] = 0x1F; // TODO: Reset the Random Register to 0x1F after writing to the Wired Register.

if (Common.Settings.MEASURE_SPEED)
{
Common.Measure.InstructionCount += 1;
Common.Measure.CycleCounter = CycleCounter;
}
Common.Measure.InstructionCount += 1;
Common.Measure.CycleCounter = CycleCounter;
}

public static void PowerOnR4300()
{
for (int i = 0; i < Registers.R4300.Reg.Length; ++i)
Registers.R4300.Reg[i] = 0; // Clear Registers.

if (Common.Settings.LOAD_PIF)
{
byte[] PIF = File.ReadAllBytes(Common.Settings.PIF_ROM);

memory.FastMemoryWrite(0x1FC00000, PIF); // Load the PIF rom into memory.

Registers.R4300.PC = 0xBFC00000;
}
else
{
uint RomType = 0; // 0 = Cart, 1 = DD
uint ResetType = 0; // 0 = Cold Reset, 1 = NMI, 2 = Reset to boot disk
uint osVersion = 0; // 00 = 1.0, 15 = 2.5, etc.
uint TVType = 1; // 0 = PAL, 1 = NTSC, 2 = MPAL

Registers.R4300.Reg[1] = 0x0000000000000001;
Registers.R4300.Reg[2] = 0x000000000EBDA536;
Registers.R4300.Reg[3] = 0x000000000EBDA536;
Registers.R4300.Reg[4] = 0x000000000000A536;
Registers.R4300.Reg[5] = 0xFFFFFFFFC0F1D859;
Registers.R4300.Reg[6] = 0xFFFFFFFFA4001F0C;
Registers.R4300.Reg[7] = 0xFFFFFFFFA4001F08;
Registers.R4300.Reg[8] = 0x00000000000000C0;
Registers.R4300.Reg[10] = 0x0000000000000040;
Registers.R4300.Reg[11] = 0xFFFFFFFFA4000040;
Registers.R4300.Reg[12] = 0xFFFFFFFFED10D0B3;
Registers.R4300.Reg[13] = 0x000000001402A4CC;
Registers.R4300.Reg[14] = 0x000000002DE108EA;
Registers.R4300.Reg[15] = 0x000000003103E121;
Registers.R4300.Reg[19] = RomType;
Registers.R4300.Reg[20] = TVType;
Registers.R4300.Reg[21] = ResetType;
Registers.R4300.Reg[22] = (GetCICSeed() >> 8) & 0xFF;
Registers.R4300.Reg[23] = osVersion;
Registers.R4300.Reg[25] = 0xFFFFFFFF9DEBB54F;
Registers.R4300.Reg[29] = 0xFFFFFFFFA4001FF0;
Registers.R4300.Reg[31] = 0xFFFFFFFFA4001550;
Registers.R4300.HI = 0x000000003FC18657;
Registers.R4300.LO = 0x000000003103E121;
Registers.R4300.PC = 0xA4000040;

memory.FastMemoryCopy(0xA4000000, 0xB0000000, 0xFFF); // Load the Boot Code into the correct memory address.
}
uint RomType = 0; // 0 = Cart, 1 = DD
uint ResetType = 0; // 0 = Cold Reset, 1 = NMI, 2 = Reset to boot disk
uint osVersion = 0; // 00 = 1.0, 15 = 2.5, etc.
uint TVType = 1; // 0 = PAL, 1 = NTSC, 2 = MPAL

Registers.R4300.Reg[1] = 0x0000000000000001;
Registers.R4300.Reg[2] = 0x000000000EBDA536;
Registers.R4300.Reg[3] = 0x000000000EBDA536;
Registers.R4300.Reg[4] = 0x000000000000A536;
Registers.R4300.Reg[5] = 0xFFFFFFFFC0F1D859;
Registers.R4300.Reg[6] = 0xFFFFFFFFA4001F0C;
Registers.R4300.Reg[7] = 0xFFFFFFFFA4001F08;
Registers.R4300.Reg[8] = 0x00000000000000C0;
Registers.R4300.Reg[10] = 0x0000000000000040;
Registers.R4300.Reg[11] = 0xFFFFFFFFA4000040;
Registers.R4300.Reg[12] = 0xFFFFFFFFED10D0B3;
Registers.R4300.Reg[13] = 0x000000001402A4CC;
Registers.R4300.Reg[14] = 0x000000002DE108EA;
Registers.R4300.Reg[15] = 0x000000003103E121;
Registers.R4300.Reg[19] = RomType;
Registers.R4300.Reg[20] = TVType;
Registers.R4300.Reg[21] = ResetType;
Registers.R4300.Reg[22] = (GetCICSeed() >> 8) & 0xFF;
Registers.R4300.Reg[23] = osVersion;
Registers.R4300.Reg[25] = 0xFFFFFFFF9DEBB54F;
Registers.R4300.Reg[29] = 0xFFFFFFFFA4001FF0;
Registers.R4300.Reg[31] = 0xFFFFFFFFA4001550;
Registers.R4300.HI = 0x000000003FC18657;
Registers.R4300.LO = 0x000000003103E121;
Registers.R4300.PC = 0xA4000040;

memory.FastMemoryCopy(0xA4000000, 0xB0000000, 0xFFF); // Load the Boot Code into the correct memory address.

COP0.PowerOnCOP0();
COP1.PowerOnCOP1();
Expand All @@ -194,58 +180,10 @@ public static void PowerOnR4300()

OpcodeTable.Init();

if (Common.Settings.DUMP_MEMORY)
{
string Output = "";
for (uint i = Common.Settings.DUMP_MEMORY_START; i <= Common.Settings.DUMP_MEMORY_END; i += 4)
{
uint Current = 0;

string Line;

try
{
Current = memory.ReadUInt32(i);
}
catch
{
Line = "NONE\n";
Output += Line;
Common.Logger.PrintInfo(Line);
continue;
}

OpcodeTable.OpcodeDesc Desc = new OpcodeTable.OpcodeDesc(Current);
OpcodeTable.InstInfo Info = new OpcodeTable.InstInfo();

try
{
Info = OpcodeTable.GetOpcodeInfo(Current);
}
catch
{
Line = $"0x{i:x8}: 0x{Current:x8}: UNK\n";
Output += Line;
Common.Logger.PrintInfo(Line);
continue;
}

string ASM = string.Format(
Info.FormattedASM,
Desc.op1, Desc.op2, Desc.op3, Desc.op4,
Desc.Imm, Desc.Target);
Line = $"0x{i:x8}: 0x{Current:x8}: {ASM}\n";
Output += Line;
Common.Logger.PrintInfo(Line);
}

File.WriteAllText("./DMP_MEM", Output);
}

Thread CPUThread =
new Thread(() =>
{
if (Common.Settings.MEASURE_SPEED) Common.Measure.MeasureTime.Start();
Common.Measure.MeasureTime.Start();
while (R4300_ON)
{
uint Opcode = memory.ReadUInt32(Registers.R4300.PC);
Expand All @@ -261,9 +199,9 @@ public static void PowerOnR4300()
Common.Variables.Step = false;
}
}
if (Common.Settings.MEASURE_SPEED) Common.Measure.MeasureTime.Stop();
Common.Measure.MeasureTime.Stop();
});

CPUThread.Name = "R4300";
CPUThread.Start();
}
}
Expand Down
3 changes: 1 addition & 2 deletions Ryu64.MIPS/Memory.cs
Expand Up @@ -170,8 +170,7 @@ public Memory(byte[] Rom)
WriteUInt32(0x0470000C, 0b1110); // RI_SELECT_REG

// Copy the Boot Code to SP_DMEM
if (!Common.Settings.LOAD_PIF)
FastMemoryCopy(0x04000040, 0x10000040, 0xFC0);
FastMemoryCopy(0x04000040, 0x10000040, 0xFC0);

// Required by CIC x105
WriteUInt32(0x40001000, 0x3C0DBFC0);
Expand Down

0 comments on commit 8a06fb5

Please sign in to comment.