-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
92 changed files
with
4,611 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Addinational File | ||
LICENSE.meta | ||
README.md.meta | ||
README_CN.md.meta | ||
|
||
/[Ll]ibrary/ | ||
/[Tt]emp/ | ||
/[Oo]bj/ | ||
/[Bb]uild/ | ||
/[Bb]uilds/ | ||
/[Pp]rojectSettings/ProjectVersion.txt | ||
/Assets/AssetStoreTools* | ||
|
||
# Autogenerated VS/MD solution and project files | ||
ExportedObj/ | ||
*.csproj | ||
*.unityproj | ||
*.sln | ||
*.suo | ||
*.tmp | ||
*.user | ||
*.userprefs | ||
*.pidb | ||
*.booproj | ||
*.svd | ||
|
||
# Unity3D generated meta files | ||
*.pidb.meta | ||
|
||
# Unity3D Generated File On Crash Reports | ||
sysinfo.txt | ||
|
||
# Builds | ||
*.apk | ||
*.unitypackage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "Aya.UNes", | ||
"references": [], | ||
"includePlatforms": [], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": true, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": true, | ||
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# UNes | ||
|
||
本项目修改自 https://github.com/Xyene/Emulator.NES |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace Aya.UNes | ||
{ | ||
public abstract class Addressable | ||
{ | ||
public delegate uint ReadDelegate(uint address); | ||
|
||
public delegate void WriteDelegate(uint address, byte val); | ||
|
||
protected readonly Emulator _emulator; | ||
protected readonly ReadDelegate[] _readMap; | ||
protected readonly WriteDelegate[] _writeMap; | ||
protected readonly uint _addressSize; | ||
|
||
protected Addressable(Emulator emulator, uint addressSpace) | ||
{ | ||
_emulator = emulator; | ||
_addressSize = addressSpace; | ||
_readMap = new ReadDelegate[addressSpace + 1]; | ||
_writeMap = new WriteDelegate[addressSpace + 1]; | ||
} | ||
|
||
protected virtual void InitializeMemoryMap() | ||
{ | ||
_readMap.Fill(address => 0); | ||
|
||
// Some games write to addresses not mapped and expect to continue afterwards | ||
_writeMap.Fill((address, val) => { }); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public uint ReadByte(uint address) | ||
{ | ||
address &= _addressSize; | ||
return _readMap[address](address); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public void WriteByte(uint address, uint val) | ||
{ | ||
address &= _addressSize; | ||
_writeMap[address](address, (byte)val); | ||
} | ||
|
||
public void MapReadHandler(uint start, uint end, CPU.ReadDelegate func) | ||
{ | ||
for (uint i = start; i <= end; i++) | ||
{ | ||
_readMap[i] = func; | ||
} | ||
} | ||
|
||
public void MapWriteHandler(uint start, uint end, CPU.WriteDelegate func) | ||
{ | ||
for (uint i = start; i <= end; i++) | ||
{ | ||
_writeMap[i] = func; | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using System; | ||
|
||
namespace Aya.UNes | ||
{ | ||
sealed partial class CPU | ||
{ | ||
public enum InterruptType | ||
{ | ||
NMI, | ||
IRQ, | ||
RESET | ||
} | ||
|
||
private readonly uint[] _interruptHandlerOffsets = { 0xFFFA, 0xFFFE, 0xFFFC }; | ||
private readonly bool[] _interrupts = new bool[2]; | ||
|
||
public void Initialize() | ||
{ | ||
A = 0; | ||
X = 0; | ||
Y = 0; | ||
SP = 0xFD; | ||
P = 0x24; | ||
|
||
PC = ReadWord(_interruptHandlerOffsets[(int) InterruptType.RESET]); | ||
} | ||
|
||
public void Reset() | ||
{ | ||
SP -= 3; | ||
F.InterruptsDisabled = true; | ||
} | ||
|
||
public void TickFromPPU() | ||
{ | ||
if (Cycle-- > 0) return; | ||
ExecuteSingleInstruction(); | ||
} | ||
|
||
public void ExecuteSingleInstruction() | ||
{ | ||
for (var i = 0; i < _interrupts.Length; i++) | ||
{ | ||
if (_interrupts[i]) | ||
{ | ||
PushWord(PC); | ||
Push(P); | ||
PC = ReadWord(_interruptHandlerOffsets[i]); | ||
F.InterruptsDisabled = true; | ||
_interrupts[i] = false; | ||
return; | ||
} | ||
} | ||
|
||
_currentInstruction = NextByte(); | ||
|
||
Cycle += _opCodeDefs[_currentInstruction].Cycles; | ||
|
||
ResetInstructionAddressingMode(); | ||
// if (_numExecuted > 10000 && PC - 1 == 0xFF61) | ||
// if(_emulator.Controller.debug || 0x6E00 <= PC && PC <= 0x6EEF) | ||
// Console.WriteLine($"{(PC - 1).ToString("X4")} {_currentInstruction.ToString("X2")} {opcodeNames[_currentInstruction]}\t\t\tA:{A.ToString("X2")} X:{X.ToString("X2")} Y:{Y.ToString("X2")} P:{P.ToString("X2")} SP:{SP.ToString("X2")}"); | ||
|
||
var op = _opCodes[_currentInstruction]; | ||
if (op == null) | ||
{ | ||
throw new ArgumentException(_currentInstruction.ToString("X2")); | ||
} | ||
|
||
op(); | ||
} | ||
|
||
public void TriggerInterrupt(InterruptType type) | ||
{ | ||
if (!F.InterruptsDisabled || type == InterruptType.NMI) | ||
{ | ||
_interrupts[(int)type] = true; | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.CompilerServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Aya.UNes | ||
{ | ||
sealed partial class CPU | ||
{ | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public void WriteIoRegister(uint reg, byte val) | ||
{ | ||
switch (reg) | ||
{ | ||
case 0x4014: // OAM DMA | ||
_emulator.PPU.PerformDMA(val); | ||
break; | ||
case 0x4016: | ||
_emulator.Controller.Strobe(val == 1); | ||
break; | ||
} | ||
|
||
if (reg <= 0x401F) | ||
{ | ||
return; // APU write | ||
} | ||
|
||
throw new NotImplementedException($"{reg:X4} = {val:X2}"); | ||
} | ||
|
||
public uint ReadIORegister(uint reg) | ||
{ | ||
switch (reg) | ||
{ | ||
case 0x4016: | ||
return (uint) _emulator.Controller.ReadState() & 0x1; | ||
} | ||
return 0x00; | ||
//throw new NotImplementedException(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.