Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ClusterM committed Jan 16, 2017
1 parent 10de3c4 commit 2e07a79
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 163 deletions.
53 changes: 37 additions & 16 deletions FelLib/Fel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace com.clusterrr.FelLib
public class Fel
{
public byte[] Fes1Bin;
public byte[] UBootBin;
byte[] uBootBin;

public enum CurrentAction { RunningCommand, ReadingMemory, WritingMemory }
public delegate void OnFelProgress(CurrentAction action, string command);
Expand All @@ -25,20 +25,40 @@ public enum CurrentAction { RunningCommand, ReadingMemory, WritingMemory }
UInt16 vid, pid;
bool DramInitDone = false;

const UInt32 cmdOffset = 0x604FF;
const UInt32 fes1_base_m = 0x2000;
const UInt32 dram_base = 0x40000000;
const UInt32 flash_mem_base = 0x43800000;
const UInt32 flash_mem_size = 0x20;
const UInt32 uboot_base_m = 0x47000000u;
const UInt32 sector_size = 0x20000;
const UInt32 uboot_base_f = 0x100000;
const UInt32 kernel_base_f = (sector_size * 0x30);
const UInt32 kernel_base_m = flash_mem_base;
const UInt32 kernel_max_size = (uboot_base_m - flash_mem_base);
const UInt32 kernel_max_flash_size = (sector_size * 0x20);
int cmdOffset = -1;
public const UInt32 fes1_base_m = 0x2000;
public const UInt32 dram_base = 0x40000000;
public const UInt32 flash_mem_base = 0x43800000;
public const UInt32 flash_mem_size = 0x20;
public const UInt32 uboot_base_m = 0x47000000u;
public const UInt32 sector_size = 0x20000;
public const UInt32 uboot_base_f = 0x100000;
public const UInt32 kernel_base_f = (sector_size * 0x30);
public const UInt32 kernel_base_m = flash_mem_base;
public const UInt32 kernel_max_size = (uboot_base_m - flash_mem_base);
public const UInt32 kernel_max_flash_size = (sector_size * 0x20);
const string fastboot = "fastboot_test";

public byte[] UBootBin
{
get
{
return uBootBin;
}

set
{
uBootBin = value;
var prefix = "bootcmd=";
for (int i = 0; i < uBootBin.Length - prefix.Length; i++)
if (Encoding.ASCII.GetString(uBootBin, i, prefix.Length) == prefix)
{
cmdOffset = i + prefix.Length;
break;
}
}
}

public static bool DeviceExists(UInt16 vid, UInt16 pid)
{
var fel = new Fel();
Expand Down Expand Up @@ -82,14 +102,14 @@ public void Open(UInt16 vid, UInt16 pid)
{
inEndp = pipe.Address;
#if DEBUG
DebugLog("IN endpoint found: "+ inEndp);
DebugLog("IN endpoint found: " + inEndp);
#endif
}
else
{
outEndp = pipe.Address;
#if DEBUG
DebugLog("Out endpoint found: "+outEndp);
DebugLog("Out endpoint found: " + outEndp);
#endif
}
}
Expand Down Expand Up @@ -329,7 +349,8 @@ public void Exec(UInt32 address)

public void RunUbootCmd(string command, bool noreturn = false, OnFelProgress callback = null)
{
if (callback != null) callback(CurrentAction.RunningCommand, command);
callback?.Invoke(CurrentAction.RunningCommand, command);
if (cmdOffset < 0) throw new Exception("Invalid Unoot binary, command variable not found");
const UInt32 testSize = 0x20;
if (UBootBin == null || UBootBin.Length < testSize)
throw new FelException("Can't init Uboot, incorrect Uboot binary");
Expand Down
2 changes: 0 additions & 2 deletions GameGenie.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace com.clusterrr.Famicom
{
Expand Down
2 changes: 0 additions & 2 deletions NesFile.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace com.clusterrr.Famicom
Expand Down
1 change: 0 additions & 1 deletion NesGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Xml.XPath;
Expand Down
92 changes: 45 additions & 47 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,47 +1,45 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;

namespace com.clusterrr.hakchi_gui
{
static class Program
{
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
bool createdNew = true;
using (Mutex mutex = new Mutex(true, "hakchi2", out createdNew))
{
if (createdNew)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
else
{
Process current = Process.GetCurrentProcess();
foreach (Process process in Process.GetProcessesByName(current.ProcessName))
{
if (process.Id != current.Id)
{
SetForegroundWindow(process.MainWindowHandle);
break;
}
}
}
}
}
}
}
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;

namespace com.clusterrr.hakchi_gui
{
static class Program
{
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
bool createdNew = true;
using (Mutex mutex = new Mutex(true, "hakchi2", out createdNew))
{
if (createdNew)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
else
{
Process current = Process.GetCurrentProcess();
foreach (Process process in Process.GetProcessesByName(current.ProcessName))
{
if (process.Id != current.Id)
{
SetForegroundWindow(process.MainWindowHandle);
break;
}
}
}
}
}
}
}
6 changes: 0 additions & 6 deletions SearchForm.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace com.clusterrr.hakchi_gui
Expand Down
28 changes: 0 additions & 28 deletions Settings.cs

This file was deleted.

3 changes: 0 additions & 3 deletions UnsupportedFourScreenException.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using com.clusterrr.Famicom;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace com.clusterrr.hakchi_gui
{
Expand Down
31 changes: 14 additions & 17 deletions UnsupportedMapperException.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
using com.clusterrr.Famicom;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace com.clusterrr.hakchi_gui
{
public class UnsupportedMapperException : Exception
{
public readonly NesFile ROM;
public UnsupportedMapperException(NesFile nesFile)
{
ROM = nesFile;
}
}
}
using com.clusterrr.Famicom;
using System;

namespace com.clusterrr.hakchi_gui
{
public class UnsupportedMapperException : Exception
{
public readonly NesFile ROM;
public UnsupportedMapperException(NesFile nesFile)
{
ROM = nesFile;
}
}
}
8 changes: 1 addition & 7 deletions WaitingForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@
using com.clusterrr.hakchi_gui.Properties;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Management;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace com.clusterrr.hakchi_gui
Expand All @@ -29,7 +23,7 @@ public WaitingForm(UInt16 vid, UInt16 pid)

public static bool WaitForDevice(UInt16 vid, UInt16 pid)
{
if (/*DeviceExists(vid, pid) &&*/ Fel.DeviceExists(vid, pid)) return true;
if (Fel.DeviceExists(vid, pid)) return true;
var form = new WaitingForm(vid, pid);
form.ShowDialog();
return form.DialogResult == DialogResult.OK;
Expand Down
Loading

0 comments on commit 2e07a79

Please sign in to comment.