Refacotor MemoryDomain.Size to be long instead of int, still some small todos, but it compiles and seems to work

This commit is contained in:
adelikat 2015-01-18 15:25:47 +00:00
parent 54605ad12f
commit 91ffc17aae
28 changed files with 137 additions and 92 deletions

View File

@ -50,9 +50,9 @@ namespace BizHawk.Client.Common
"getcurrentmemorydomainsize",
"Returns the number of bytes of the domain defined as main memory"
)]
public int GetSize()
public uint GetSize() // int to long TODO: test this and think about it more
{
return Domain.Size;
return (uint)Domain.Size;
}
#endregion

View File

@ -84,9 +84,9 @@ namespace BizHawk.Client.Common
"getcurrentmemorydomainsize",
"Returns the number of bytes of the current memory domain selected by Lua. The default is Main memory"
)]
public int GetCurrentMemoryDomainSize()
public uint GetCurrentMemoryDomainSize() // int to long TODO: test this and think about it more
{
return Domain.Size;
return (uint)Domain.Size;
}
[LuaMethodAttributes(

View File

@ -68,7 +68,7 @@ namespace BizHawk.Client.Common
listSize /= (int)_settings.Size;
}
_watchList = new List<IMiniWatch>(listSize);
_watchList = new List<IMiniWatch>((int)listSize);
switch (_settings.Size)
{

View File

@ -18,7 +18,7 @@ namespace BizHawk.Client.EmuHawk
public class HexTextBox : TextBox, INumberBox
{
private string _addressFormatStr = string.Empty;
private int? _maxSize;
private long? _maxSize;
private bool _nullable = true;
public HexTextBox()
@ -28,7 +28,7 @@ namespace BizHawk.Client.EmuHawk
public bool Nullable { get { return _nullable; } set { _nullable = value; } }
public void SetHexProperties(int domainSize)
public void SetHexProperties(long domainSize)
{
_maxSize = domainSize - 1;
MaxLength = _maxSize.Value.NumHexDigits();

View File

@ -46,11 +46,11 @@ namespace BizHawk.Client.EmuHawk
get { return (uint)AddressBox.ToRawInt().Value; }
}
public int MaxAddressSize
public long MaxAddressSize
{
get
{
return AddressBox.MaxLength;
return AddressBox.MaxLength; // int to long TODO: I think this logic was wrong (even before the int to long refactor)
}
set

View File

@ -25,7 +25,7 @@ namespace BizHawk.Client.EmuHawk
public string Mnemonic { get; private set; }
}
private int BusMaxValue
private long BusMaxValue
{
get
{

View File

@ -49,7 +49,7 @@ namespace BizHawk.Client.EmuHawk
private long _domainSize;
private MemoryDomain _domain = new MemoryDomain(
"NULL", 1024, MemoryDomain.Endian.Little, addr => 0, delegate(int a, byte v) { v = 0; });
"NULL", 1024, MemoryDomain.Endian.Little, addr => 0, delegate(long a, byte v) { v = 0; });
private int _row;
private int _addr;

View File

@ -63,7 +63,7 @@ namespace BizHawk.Common.NumberExtensions
/// Receives a number and returns the number of hexadecimal digits it is
/// Note: currently only returns 2, 4, 6, or 8
/// </summary>
public static int NumHexDigits(this int i)
public static int NumHexDigits(this long i)
{
//now this is a bit of a trick. if it was less than 0, it mustve been >= 0x80000000 and so takes all 8 digits
if (i < 0)
@ -86,7 +86,12 @@ namespace BizHawk.Common.NumberExtensions
return 6;
}
return 8;
if (i < 0x100000000)
{
return 8;
}
return 16;
}
}
}

View File

@ -9,7 +9,7 @@ namespace BizHawk.Emulation.Common
{
public enum Endian { Big, Little, Unknown }
public MemoryDomain(string name, int size, Endian endian, Func<int, byte> peekByte, Action<int, byte> pokeByte)
public MemoryDomain(string name, long size, Endian endian, Func<long, byte> peekByte, Action<long, byte> pokeByte)
{
Name = name;
Size = size;
@ -24,13 +24,13 @@ namespace BizHawk.Emulation.Common
/// Special note: if this is 0, the memorydomain is 0x100000000 (full 32bits) in size.
/// This was judged to be less of a mess than using a bunch of longs everywhere.
/// </summary>
public int Size { get; private set; }
public long Size { get; private set; }
public Endian EndianType { get; private set; }
public Func<int, byte> PeekByte { get; private set; }
public Func<long, byte> PeekByte { get; private set; }
public Action<int, byte> PokeByte { get; private set; }
public Action<long, byte> PokeByte { get; private set; }
/// <summary>
/// create a memorydomain that references an unmanaged memory block
@ -50,13 +50,13 @@ namespace BizHawk.Emulation.Common
name,
size,
endian,
delegate(int addr)
delegate(long addr)
{
if ((uint)addr >= size)
throw new ArgumentOutOfRangeException();
return p[addr];
},
delegate(int addr, byte val)
delegate(long addr, byte val)
{
if (writable)
{
@ -86,13 +86,13 @@ namespace BizHawk.Emulation.Common
name,
size,
endian,
delegate(int addr)
delegate(long addr)
{
if (addr < 0 || addr >= size)
throw new ArgumentOutOfRangeException();
return p[addr ^ 1];
},
delegate(int addr, byte val)
delegate(long addr, byte val)
{
if (writable)
{
@ -109,7 +109,7 @@ namespace BizHawk.Emulation.Common
return Name;
}
public ushort PeekWord(int addr, bool bigEndian)
public ushort PeekWord(long addr, bool bigEndian)
{
Endian endian = bigEndian ? Endian.Big : Endian.Little;
switch (endian)
@ -122,7 +122,7 @@ namespace BizHawk.Emulation.Common
}
}
public uint PeekDWord(int addr, bool bigEndian)
public uint PeekDWord(long addr, bool bigEndian)
{
Endian endian = bigEndian ? Endian.Big : Endian.Little;
switch (endian)
@ -141,7 +141,7 @@ namespace BizHawk.Emulation.Common
}
}
public void PokeWord(int addr, ushort val, bool bigEndian)
public void PokeWord(long addr, ushort val, bool bigEndian)
{
Endian endian = bigEndian ? Endian.Big : Endian.Little;
switch (endian)
@ -158,7 +158,7 @@ namespace BizHawk.Emulation.Common
}
}
public void PokeDWord(int addr, uint val, bool bigEndian)
public void PokeDWord(long addr, uint val, bool bigEndian)
{
Endian endian = bigEndian ? Endian.Big : Endian.Little;
switch (endian)

View File

@ -30,6 +30,16 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
ram[i] = ((i & 0x40) != 0) ? (byte)0xFF : (byte)0x00;
}
public byte Peek(long addr)
{
return ram[addr];
}
public void Poke(long addr, byte val)
{
ram[addr] = val;
}
public byte Peek(int addr)
{
return ram[addr];

View File

@ -146,24 +146,24 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
public bool FlagN { get { return cpu.FlagN; } }
public bool FlagT { get { return cpu.FlagT; } }
public byte Peek(int addr)
public byte Peek(long addr)
{
if (addr == 0x0000)
return port.Direction;
else if (addr == 0x0001)
return PortData;
else
return PeekMemory(addr);
return PeekMemory((int)addr);
}
public void Poke(int addr, byte val)
public void Poke(long addr, byte val)
{
if (addr == 0x0000)
port.Direction = val;
else if (addr == 0x0001)
port.Latch = val;
else
PokeMemory(addr, val);
PokeMemory((int)addr, val);
}
public byte PortData

View File

@ -372,14 +372,24 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
// ------------------------------------
public byte Peek(long addr)
{
return ReadRegister((int)addr & 0xF);
}
public void Poke(long addr, byte val)
{
WriteRegister((int)(addr & 0xF), val);
}
public byte Peek(int addr)
{
return ReadRegister(addr & 0xF);
return ReadRegister((int)addr & 0xF);
}
public void Poke(int addr, byte val)
{
WriteRegister((addr & 0xF), val);
WriteRegister((int)(addr & 0xF), val);
}
public byte Read(int addr)

View File

@ -7,14 +7,24 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{
sealed public partial class Sid
{
public byte Peek(long addr)
{
return ReadRegister((int)(addr & 0x1F));
}
public void Poke(long addr, byte val)
{
WriteRegister((int)(addr & 0x1F), val);
}
public byte Peek(int addr)
{
return ReadRegister((addr & 0x1F));
return ReadRegister((int)(addr & 0x1F));
}
public void Poke(int addr, byte val)
{
WriteRegister((addr & 0x1F), val);
WriteRegister((int)(addr & 0x1F), val);
}
public byte Read(int addr)

View File

@ -7,14 +7,24 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{
sealed public partial class Vic
{
public byte Peek(long addr)
{
return ReadRegister((int)(addr & 0x3F));
}
public void Poke(long addr, byte val)
{
WriteRegister((int)(addr & 0x3F), val);
}
public byte Peek(int addr)
{
return ReadRegister((addr & 0x3F));
return ReadRegister((int)(addr & 0x3F));
}
public void Poke(int addr, byte val)
{
WriteRegister((addr & 0x3F), val);
WriteRegister((int)(addr & 0x3F), val);
}
public byte Read(int addr)

View File

@ -53,8 +53,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
"Cart Ram",
_mapper.CartRam.Len,
MemoryDomain.Endian.Little,
addr => _mapper.CartRam[addr],
(addr, value) => _mapper.CartRam[addr] = value));
addr => _mapper.CartRam[(int)addr],
(addr, value) => _mapper.CartRam[(int)addr] = value));
}
MemoryDomains = new MemoryDomainList(domains);

View File

@ -22,13 +22,13 @@ namespace BizHawk.Emulation.Cores.Atari.Atari7800
{
_MemoryDomains.Add(new MemoryDomain(
"RAM1", 0x800, MemoryDomain.Endian.Unknown,
delegate(int addr)
delegate(long addr)
{
if (addr < 0 || addr >= 0x800)
throw new ArgumentOutOfRangeException();
return ((Machine7800)theMachine).RAM1[(ushort)addr];
},
delegate(int addr, byte val)
delegate(long addr, byte val)
{
if (addr < 0 || addr >= 0x800)
throw new ArgumentOutOfRangeException();
@ -36,13 +36,13 @@ namespace BizHawk.Emulation.Cores.Atari.Atari7800
}));
_MemoryDomains.Add(new MemoryDomain(
"RAM2", 0x800, MemoryDomain.Endian.Unknown,
delegate(int addr)
delegate(long addr)
{
if (addr < 0 || addr >= 0x800)
throw new ArgumentOutOfRangeException();
return ((Machine7800)theMachine).RAM2[(ushort)addr];
},
delegate(int addr, byte val)
delegate(long addr, byte val)
{
if (addr < 0 || addr >= 0x800)
throw new ArgumentOutOfRangeException();
@ -50,44 +50,44 @@ namespace BizHawk.Emulation.Cores.Atari.Atari7800
}));
_MemoryDomains.Add(new MemoryDomain(
"BIOS ROM", bios.Length, MemoryDomain.Endian.Unknown,
delegate(int addr)
delegate(long addr)
{
return bios[addr];
},
delegate(int addr, byte val)
delegate(long addr, byte val)
{
}));
if (hsc7800 != null)
{
_MemoryDomains.Add(new MemoryDomain(
"HSC ROM", hsbios.Length, MemoryDomain.Endian.Unknown,
delegate(int addr)
delegate(long addr)
{
return hsbios[addr];
},
delegate(int addr, byte val)
delegate(long addr, byte val)
{
}));
_MemoryDomains.Add(new MemoryDomain(
"HSC RAM", hsram.Length, MemoryDomain.Endian.Unknown,
delegate(int addr)
delegate(long addr)
{
return hsram[addr];
},
delegate(int addr, byte val)
delegate(long addr, byte val)
{
hsram[addr] = val;
}));
}
_MemoryDomains.Add(new MemoryDomain(
"System Bus", 65536, MemoryDomain.Endian.Unknown,
delegate(int addr)
delegate(long addr)
{
if (addr < 0 || addr >= 0x10000)
throw new ArgumentOutOfRangeException();
return theMachine.Mem[(ushort)addr];
},
delegate(int addr, byte val)
delegate(long addr, byte val)
{
if (addr < 0 || addr >= 0x10000)
throw new ArgumentOutOfRangeException();

View File

@ -37,13 +37,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
// special domain for system bus
{
MemoryDomain sb = new MemoryDomain("System Bus", 1 << 28, MemoryDomain.Endian.Little,
delegate(int addr)
delegate(long addr)
{
if (addr < 0 || addr >= 0x10000000)
throw new IndexOutOfRangeException();
return LibMeteor.libmeteor_peekbus((uint)addr);
},
delegate(int addr, byte val)
delegate(long addr, byte val)
{
if (addr < 0 || addr >= 0x10000000)
throw new IndexOutOfRangeException();
@ -56,7 +56,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
var ew = _domainList[1];
var iw = _domainList[0];
MemoryDomain cr = new MemoryDomain("Combined WRAM", (256 + 32) * 1024, MemoryDomain.Endian.Little,
delegate(int addr)
delegate(long addr)
{
if (addr < 0 || addr >= (256 + 32) * 1024)
throw new IndexOutOfRangeException();
@ -65,7 +65,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
else
return ew.PeekByte(addr);
},
delegate(int addr, byte val)
delegate(long addr, byte val)
{
if (addr < 0 || addr >= (256 + 32) * 1024)
throw new IndexOutOfRangeException();

View File

@ -25,24 +25,24 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
mm.Add(MemoryDomain.FromIntPtr("ROM", 32 * 1024 * 1024, l, s.rom));
mm.Add(new MemoryDomain("System Bus", 0x10000000, l,
delegate(int addr)
delegate(long addr)
{
if (addr < 0 || addr >= 0x10000000)
throw new ArgumentOutOfRangeException();
return LibVBANext.SystemBusRead(Core, addr);
return LibVBANext.SystemBusRead(Core, (int)addr);
},
delegate(int addr, byte val)
delegate(long addr, byte val)
{
if (addr < 0 || addr >= 0x10000000)
throw new ArgumentOutOfRangeException();
LibVBANext.SystemBusWrite(Core, addr, val);
LibVBANext.SystemBusWrite(Core, (int)addr, val);
}));
// special combined ram memory domain
{
var ew = mm[1];
var iw = mm[0];
MemoryDomain cr = new MemoryDomain("Combined WRAM", (256 + 32) * 1024, MemoryDomain.Endian.Little,
delegate(int addr)
delegate(long addr)
{
if (addr < 0 || addr >= (256 + 32) * 1024)
throw new IndexOutOfRangeException();
@ -51,7 +51,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
else
return ew.PeekByte(addr);
},
delegate(int addr, byte val)
delegate(long addr, byte val)
{
if (addr < 0 || addr >= (256 + 32) * 1024)
throw new IndexOutOfRangeException();

View File

@ -36,13 +36,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
// also add a special memory domain for the system bus, where calls get sent directly to the core each time
_memoryDomains.Add(new MemoryDomain("System Bus", 65536, MemoryDomain.Endian.Little,
delegate(int addr)
delegate(long addr)
{
if (addr < 0 || addr >= 65536)
throw new ArgumentOutOfRangeException();
return LibGambatte.gambatte_cpuread(GambatteState, (ushort)addr);
},
delegate(int addr, byte val)
delegate(long addr, byte val)
{
if (addr < 0 || addr >= 65536)
throw new ArgumentOutOfRangeException();

View File

@ -25,49 +25,49 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
IntPtr memPtr = api.get_memory_ptr(id);
Func<int, byte> peekByte;
Action<int, byte> pokeByte;
Func<long, byte> peekByte;
Action<long, byte> pokeByte;
if (swizzled)
{
peekByte = delegate(int addr)
peekByte = delegate(long addr)
{
if (addr < 0 || addr >= size)
{
throw new ArgumentOutOfRangeException();
}
return Marshal.ReadByte(memPtr, (addr ^ 3));
return Marshal.ReadByte(memPtr, (int)(addr ^ 3));
};
pokeByte = delegate(int addr, byte val)
pokeByte = delegate(long addr, byte val)
{
if (addr < 0 || addr >= size)
{
throw new ArgumentOutOfRangeException();
}
Marshal.WriteByte(memPtr, (addr ^ 3), val);
Marshal.WriteByte(memPtr, (int)(addr ^ 3), val);
};
}
else
{
peekByte = delegate(int addr)
peekByte = delegate(long addr)
{
if (addr < 0 || addr >= size)
{
throw new ArgumentOutOfRangeException();
}
return Marshal.ReadByte(memPtr, (addr));
return Marshal.ReadByte(memPtr, (int)(addr));
};
pokeByte = delegate(int addr, byte val)
pokeByte = delegate(long addr, byte val)
{
if (addr < 0 || addr >= size)
{
throw new ArgumentOutOfRangeException();
}
Marshal.WriteByte(memPtr, (addr), val);
Marshal.WriteByte(memPtr, (int)(addr), val);
};
}
@ -116,15 +116,15 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
}
Func<int, byte> peekByte;
Action<int, byte> pokeByte;
Func<long, byte> peekByte;
Action<long, byte> pokeByte;
peekByte = delegate(int addr)
peekByte = delegate(long addr)
{
return api.m64p_read_memory_8((uint)addr);
};
pokeByte = delegate(int addr, byte val)
pokeByte = delegate(long addr, byte val)
{
api.m64p_write_memory_8((uint)addr, val);
};
@ -132,7 +132,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
_memoryDomains.Add(new MemoryDomain
(
name: "System Bus",
size: 0, // special case for full 32bit memorydomain
size: 0, // special case for full 32bit memorydomain // int to long TODO: remove this special case!
endian: MemoryDomain.Endian.Big,
peekByte: peekByte,
pokeByte: pokeByte

View File

@ -228,7 +228,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
public MemoryDomain GetDiskPeeker()
{
return new MemoryDomain("FDS SIDE", diskdrive.NumBytes, MemoryDomain.Endian.Little, diskdrive.PeekData, null);
return new MemoryDomain("FDS SIDE", diskdrive.NumBytes, MemoryDomain.Endian.Little, diskdrive.PeekData, null); // silent poke fail TODO: don't pass null! Throw a not implemented exception, handle this exception in ram tools
}
void SetIRQ()

View File

@ -290,7 +290,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
/// </summary>
/// <param name="addr"></param>
/// <returns></returns>
public byte PeekData(int addr)
public byte PeekData(long addr)
{
if (disk != null && disk.Length > addr)
return disk[addr];

View File

@ -16,9 +16,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
var RAM = new MemoryDomain("RAM", 0x800, MemoryDomain.Endian.Little,
addr => ram[addr], (addr, value) => ram[addr] = value);
var SystemBus = new MemoryDomain("System Bus", 0x10000, MemoryDomain.Endian.Little,
addr => PeekMemory((ushort)addr), (addr, value) => ApplySystemBusPoke(addr, value));
addr => PeekMemory((ushort)addr), (addr, value) => ApplySystemBusPoke((int)addr, value));
var PPUBus = new MemoryDomain("PPU Bus", 0x4000, MemoryDomain.Endian.Little,
addr => ppu.ppubus_peek(addr), (addr, value) => ppu.ppubus_write(addr, value));
addr => ppu.ppubus_peek((int)addr), (addr, value) => ppu.ppubus_write((int)addr, value));
var CIRAMdomain = new MemoryDomain("CIRAM (nametables)", 0x800, MemoryDomain.Endian.Little,
addr => CIRAM[addr], (addr, value) => CIRAM[addr] = value);
var OAMdoman = new MemoryDomain("OAM", 64 * 4, MemoryDomain.Endian.Unknown,

View File

@ -32,23 +32,23 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES
"System Bus",
0x10000,
MemoryDomain.Endian.Unknown,
delegate(int addr)
delegate(long addr)
{
if (addr < 0 || addr >= 0x10000)
{
throw new ArgumentOutOfRangeException();
}
return LibQuickNES.qn_peek_prgbus(Context, addr);
return LibQuickNES.qn_peek_prgbus(Context, (int)addr);
},
delegate(int addr, byte val)
delegate(long addr, byte val)
{
if (addr < 0 || addr >= 0x10000)
{
throw new ArgumentOutOfRangeException();
}
LibQuickNES.qn_poke_prgbus(Context, addr, val);
LibQuickNES.qn_poke_prgbus(Context, (int)addr, val);
}
));

View File

@ -1026,7 +1026,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
var md = new MemoryDomain("System Bus", 0x1000000, MemoryDomain.Endian.Little,
(addr) =>
{
var a = FakeBusMap(addr);
var a = FakeBusMap((int)addr);
if (a.HasValue)
return blockptr[a.Value];
else
@ -1034,7 +1034,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
},
(addr, val) =>
{
var a = FakeBusMap(addr);
var a = FakeBusMap((int)addr);
if (a.HasValue)
blockptr[a.Value] = val;
});

View File

@ -479,13 +479,13 @@ namespace BizHawk.Emulation.Cores.PCEngine
{
if (addr < 0 || addr >= 0x200000)
throw new ArgumentOutOfRangeException();
return Cpu.ReadMemory21(addr);
return Cpu.ReadMemory21((int)addr);
},
(addr, value) =>
{
if (addr < 0 || addr >= 0x200000)
throw new ArgumentOutOfRangeException();
Cpu.WriteMemory21(addr, value);
Cpu.WriteMemory21((int)addr, value);
});
domains.Add(SystemBusDomain);

View File

@ -474,7 +474,7 @@ namespace BizHawk.Emulation.Cores.Sega.Genesis
(addr, value) => RomData[addr & (RomData.Length - 1)] = value);
var SystemBusDomain = new MemoryDomain("System Bus", 0x1000000, MemoryDomain.Endian.Big,
addr => (byte)ReadByte(addr),
addr => (byte)ReadByte((int)addr),
(addr, value) => Write8((uint)addr, (uint)value));
domains.Add(MainMemoryDomain);

View File

@ -600,17 +600,17 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
{
byte* p = (byte*)area;
mm.Add(new MemoryDomain(name, size, MemoryDomain.Endian.Unknown,
delegate(int addr)
delegate(long addr)
{
if (addr < 0 || addr >= 65536)
throw new ArgumentOutOfRangeException();
return p[addr ^ 1];
},
delegate(int addr, byte val)
delegate(long addr, byte val)
{
if (addr < 0 || addr >= 65536)
throw new ArgumentOutOfRangeException();
LibGPGX.gpgx_poke_vram(addr ^ 1, val);
LibGPGX.gpgx_poke_vram(((int)addr) ^ 1, val);
}));
}
else