use more advanced language features in Emulation.Cores (#1852)

* Use expression bodies in Emulation.Cores, and a few other misc cleanups

* remove unused usings in Emulation.Common

* cleanups in Tables_Direct.cs

* some cleanups in nes boards - redundant code

* remove some redundant array initializers in Emulation.Cores

* cleanup AmstradCPC.Controllers

* use object initializers in a lot of places

* nes mappers - remove disch's notes comments in favor of the nesdev wiki link

* cleanup CdtConverter.cs, mostly use of object initializers

* remove redundant .ToString() calls in Emulation.Cores

* using var in Emulation.Cores

* AmstradCPC/ZXSpectrum - simplify some linq, tabs instead of spaces, a few other misc cleanups

* Use null-propagation in Emulation.Cores
This commit is contained in:
adelikat 2020-02-17 16:54:51 -06:00 committed by GitHub
parent f7174eb398
commit 606c3bf1c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
459 changed files with 5214 additions and 7558 deletions

View File

@ -1,6 +1,4 @@
using System; namespace BizHawk.Emulation.Cores.Components.M68000
namespace BizHawk.Emulation.Cores.Components.M68000
{ {
partial class MC68000 partial class MC68000
{ {

View File

@ -1,6 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; using System.Text;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;

View File

@ -181,8 +181,7 @@ namespace BizHawk.Emulation.Cores.Components.CP1610
bool FlagD_prev = FlagD; bool FlagD_prev = FlagD;
opcode = ReadMemoryWrapper(RegisterPC++, false) & 0x3FF; opcode = ReadMemoryWrapper(RegisterPC++, false) & 0x3FF;
if (TraceCallback != null) TraceCallback?.Invoke(CP1610State());
TraceCallback(CP1610State());
if (MemoryCallbacks != null) if (MemoryCallbacks != null)
{ {

View File

@ -26,13 +26,7 @@ namespace BizHawk.Emulation.Cores.Components.CP1610
set => Register[7] = value; set => Register[7] = value;
} }
public string TraceHeader public string TraceHeader => "CP1610: PC, machine code, mnemonic, operands, flags (SCZOID)";
{
get
{
return "CP1610: PC, machine code, mnemonic, operands, flags (SCZOID)";
}
}
public Action<TraceInfo> TraceCallback; public Action<TraceInfo> TraceCallback;
public IMemoryCallbackSystem MemoryCallbacks { get; set; } public IMemoryCallbackSystem MemoryCallbacks { get; set; }

View File

@ -1,4 +1,4 @@
using System;
// Do not modify this file directly! This is GENERATED code. // Do not modify this file directly! This is GENERATED code.
// Please open the CpuCoreGenerator solution and make your modifications there. // Please open the CpuCoreGenerator solution and make your modifications there.

View File

@ -1,7 +1,4 @@
using System; using System;
using System.Globalization;
using System.IO;
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
@ -264,10 +261,7 @@ namespace BizHawk.Emulation.Cores.Components.H6280
return (ushort)(ReadMemory(address) | (ReadMemory(highAddress) << 8)); return (ushort)(ReadMemory(address) | (ReadMemory(highAddress) << 8));
} }
public string TraceHeader public string TraceHeader => "HuC6280: PC, machine code, mnemonic, operands, registers (A, X, Y, P, SP, Cy), flags (NVTBDIZC)";
{
get { return "HuC6280: PC, machine code, mnemonic, operands, registers (A, X, Y, P, SP, Cy), flags (NVTBDIZC)"; }
}
public TraceInfo State() public TraceInfo State()
{ {

View File

@ -1,7 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO; using System.IO;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
@ -73,7 +71,7 @@ namespace BizHawk.Emulation.Cores.Components.H6280
public string Name; public string Name;
public int Offs; public int Offs;
public int VOffs; // if non-zero, specifies a larger potential offset public int VOffs; // if non-zero, specifies a larger potential offset
public int MaxOffs { get { return Math.Max(Offs, VOffs); } } public int MaxOffs => Math.Max(Offs, VOffs);
} }
public MemMapping[] Mappings; // = new MemMapping[256]; public MemMapping[] Mappings; // = new MemMapping[256];

View File

@ -1,7 +1,4 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Components.H6280 namespace BizHawk.Emulation.Cores.Components.H6280
@ -14,10 +11,7 @@ namespace BizHawk.Emulation.Cores.Components.H6280
set { } set { }
} }
public string PCRegisterName public string PCRegisterName => "PC";
{
get { return "PC"; }
}
public IEnumerable<string> AvailableCpus public IEnumerable<string> AvailableCpus
{ {

View File

@ -1,5 +1,3 @@
using System;
namespace BizHawk.Emulation.Cores.Components.I8048 namespace BizHawk.Emulation.Cores.Components.I8048
{ {
public partial class I8048 public partial class I8048

View File

@ -160,10 +160,10 @@ namespace BizHawk.Emulation.Cores.Components.I8048
// do nothing // do nothing
break; break;
case OP: case OP:
// Read the opcode of the next instruction // Read the opcode of the next instruction
if (OnExecFetch != null) OnExecFetch(PC); OnExecFetch?.Invoke(PC);
if (TraceCallback != null) TraceCallback(State()); TraceCallback?.Invoke(State());
if (CDLCallback != null) CDLCallback(PC, eCDLogMemFlags.FetchFirst); CDLCallback?.Invoke(PC, eCDLogMemFlags.FetchFirst);
FetchInstruction(ReadMemory(Regs[PC])); FetchInstruction(ReadMemory(Regs[PC]));
Regs[ALU2] = (ushort)(Regs[PC] & 0x800); Regs[ALU2] = (ushort)(Regs[PC] & 0x800);
Regs[PC] = (ushort)(((Regs[PC] + 1) & 0x7FF) | Regs[ALU2]); Regs[PC] = (ushort)(((Regs[PC] + 1) & 0x7FF) | Regs[ALU2]);
@ -259,8 +259,8 @@ namespace BizHawk.Emulation.Cores.Components.I8048
else else
{ {
Regs[reg_d_ad] = (ushort)((reg_h_ad << 8) | Regs[reg_l_ad]); Regs[reg_d_ad] = (ushort)((reg_h_ad << 8) | Regs[reg_l_ad]);
} }
break; break;
case CLC: case CLC:
FlagC = false; FlagC = false;
break; break;
@ -437,12 +437,12 @@ namespace BizHawk.Emulation.Cores.Components.I8048
if (++irq_pntr == IRQS) if (++irq_pntr == IRQS)
{ {
// then regular IRQ // then regular IRQ
if (IRQPending && IntEn && INT_MSTR) if (IRQPending && IntEn && INT_MSTR)
{ {
IRQPending = false; IRQPending = false;
if (TraceCallback != null) { TraceCallback(new TraceInfo { Disassembly = "====IRQ====", RegisterInfo = "" }); } TraceCallback?.Invoke(new TraceInfo { Disassembly = "====IRQ====", RegisterInfo = "" });
IRQ_(0); IRQ_(0);
IRQCallback(); IRQCallback();
@ -452,7 +452,7 @@ namespace BizHawk.Emulation.Cores.Components.I8048
{ {
TIRQPending = false; TIRQPending = false;
if (TraceCallback != null) { TraceCallback(new TraceInfo { Disassembly = "====TIRQ====", RegisterInfo = "" }); } TraceCallback?.Invoke(new TraceInfo { Disassembly = "====TIRQ====", RegisterInfo = "" });
IRQ_(1); IRQ_(1);
IRQCallback(); IRQCallback();
@ -511,10 +511,7 @@ namespace BizHawk.Emulation.Cores.Components.I8048
public Action<TraceInfo> TraceCallback; public Action<TraceInfo> TraceCallback;
public string TraceHeader public string TraceHeader => "MC6809: PC, machine code, mnemonic, operands, registers (A, B, X, Y, US, SP, DP, CC), Cy, flags (CAFBIFTTR)";
{
get { return "MC6809: PC, machine code, mnemonic, operands, registers (A, B, X, Y, US, SP, DP, CC), Cy, flags (CAFBIFTTR)"; }
}
public TraceInfo State(bool disassemble = true) public TraceInfo State(bool disassemble = true)
{ {

View File

@ -1,5 +1,4 @@
using System; using BizHawk.Common.NumberExtensions;
using BizHawk.Common.NumberExtensions;
namespace BizHawk.Emulation.Cores.Components.I8048 namespace BizHawk.Emulation.Cores.Components.I8048
{ {
@ -17,7 +16,7 @@ namespace BizHawk.Emulation.Cores.Components.I8048
public void Write_Func(ushort dest, ushort src) public void Write_Func(ushort dest, ushort src)
{ {
if (CDLCallback != null) CDLCallback(Regs[dest], eCDLogMemFlags.Write | eCDLogMemFlags.Data); CDLCallback?.Invoke(Regs[dest], eCDLogMemFlags.Write | eCDLogMemFlags.Data);
WriteMemory(Regs[dest], (byte)Regs[src]); WriteMemory(Regs[dest], (byte)Regs[src]);
} }

View File

@ -1,5 +1,3 @@
using System;
namespace BizHawk.Emulation.Cores.Components.I8048 namespace BizHawk.Emulation.Cores.Components.I8048
{ {
public partial class I8048 public partial class I8048

View File

@ -1,5 +1,3 @@
using System;
namespace BizHawk.Emulation.Cores.Components.LR35902 namespace BizHawk.Emulation.Cores.Components.LR35902
{ {
public partial class LR35902 public partial class LR35902

View File

@ -1,5 +1,3 @@
using System;
namespace BizHawk.Emulation.Cores.Components.LR35902 namespace BizHawk.Emulation.Cores.Components.LR35902
{ {
public partial class LR35902 public partial class LR35902

View File

@ -1,7 +1,4 @@
using System; using System;
using System.Globalization;
using System.IO;
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
using BizHawk.Common.NumberExtensions; using BizHawk.Common.NumberExtensions;
@ -145,14 +142,11 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
{ {
interrupts_enabled = false; interrupts_enabled = false;
if (TraceCallback != null) TraceCallback?.Invoke(new TraceInfo
{ {
TraceCallback(new TraceInfo Disassembly = "====IRQ====",
{ RegisterInfo = ""
Disassembly = "====IRQ====", });
RegisterInfo = ""
});
}
// call interrupt processor // call interrupt processor
// lowest bit set is highest priority // lowest bit set is highest priority
@ -160,9 +154,9 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
} }
else else
{ {
if (OnExecFetch != null) OnExecFetch(RegPC); OnExecFetch?.Invoke(RegPC);
if (TraceCallback != null && !CB_prefix) TraceCallback(State()); if (TraceCallback != null && !CB_prefix) TraceCallback(State());
if (CDLCallback != null) CDLCallback(RegPC, eCDLogMemFlags.FetchFirst); CDLCallback?.Invoke(RegPC, eCDLogMemFlags.FetchFirst);
FetchInstruction(ReadMemory(RegPC++)); FetchInstruction(ReadMemory(RegPC++));
} }
instr_pntr = 0; instr_pntr = 0;
@ -296,14 +290,11 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
{ {
interrupts_enabled = false; interrupts_enabled = false;
if (TraceCallback != null) TraceCallback?.Invoke(new TraceInfo
{ {
TraceCallback(new TraceInfo Disassembly = "====IRQ====",
{ RegisterInfo = ""
Disassembly = "====IRQ====", });
RegisterInfo = ""
});
}
halted = false; halted = false;
if (is_GBC) if (is_GBC)
@ -321,23 +312,20 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
} }
} }
else else
{ {
// call interrupt processor // call interrupt processor
INTERRUPT_(); INTERRUPT_();
Halt_bug_3 = false; Halt_bug_3 = false;
} }
} }
else if (temp) else if (temp)
{ {
// even if interrupt servicing is disabled, any interrupt flag raised still resumes execution // even if interrupt servicing is disabled, any interrupt flag raised still resumes execution
if (TraceCallback != null) TraceCallback?.Invoke(new TraceInfo
{ {
TraceCallback(new TraceInfo Disassembly = "====un-halted====",
{ RegisterInfo = ""
Disassembly = "====un-halted====", });
RegisterInfo = ""
});
}
halted = false; halted = false;
if (is_GBC) if (is_GBC)
@ -345,9 +333,9 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
// extra 4 cycles for GBC // extra 4 cycles for GBC
if (Halt_bug_3) if (Halt_bug_3)
{ {
if (OnExecFetch != null) OnExecFetch(RegPC); OnExecFetch?.Invoke(RegPC);
if (TraceCallback != null && !CB_prefix) TraceCallback(State()); if (TraceCallback != null && !CB_prefix) TraceCallback(State());
if (CDLCallback != null) CDLCallback(RegPC, eCDLogMemFlags.FetchFirst); CDLCallback?.Invoke(RegPC, eCDLogMemFlags.FetchFirst);
RegPC++; RegPC++;
FetchInstruction(ReadMemory(RegPC)); FetchInstruction(ReadMemory(RegPC));
@ -356,18 +344,20 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
} }
else else
{ {
cur_instr = new ushort[] cur_instr = new[]
{IDLE, {
IDLE, IDLE,
IDLE, IDLE,
OP }; IDLE,
OP
};
} }
} }
else else
{ {
if (OnExecFetch != null) OnExecFetch(RegPC); OnExecFetch?.Invoke(RegPC);
if (TraceCallback != null && !CB_prefix) TraceCallback(State()); if (TraceCallback != null && !CB_prefix) TraceCallback(State());
if (CDLCallback != null) CDLCallback(RegPC, eCDLogMemFlags.FetchFirst); CDLCallback?.Invoke(RegPC, eCDLogMemFlags.FetchFirst);
if (Halt_bug_3) if (Halt_bug_3)
{ {
@ -379,8 +369,8 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
else else
{ {
FetchInstruction(ReadMemory(RegPC++)); FetchInstruction(ReadMemory(RegPC++));
} }
} }
} }
else else
{ {
@ -431,19 +421,16 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
stop_time--; stop_time--;
if (stop_time == 0) if (stop_time == 0)
{ {
if (TraceCallback != null) TraceCallback?.Invoke(new TraceInfo
{ {
TraceCallback(new TraceInfo Disassembly = "====un-stop====",
{ RegisterInfo = ""
Disassembly = "====un-stop====", });
RegisterInfo = ""
});
}
stopped = false; stopped = false;
if (OnExecFetch != null) OnExecFetch(RegPC); OnExecFetch?.Invoke(RegPC);
if (TraceCallback != null && !CB_prefix) TraceCallback(State()); if (TraceCallback != null && !CB_prefix) TraceCallback(State());
if (CDLCallback != null) CDLCallback(RegPC, eCDLogMemFlags.FetchFirst); CDLCallback?.Invoke(RegPC, eCDLogMemFlags.FetchFirst);
FetchInstruction(ReadMemory(RegPC++)); FetchInstruction(ReadMemory(RegPC++));
instr_pntr = 0; instr_pntr = 0;
@ -461,19 +448,16 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
} }
else if (interrupt_src.Bit(4)) // button pressed, not actually an interrupt though else if (interrupt_src.Bit(4)) // button pressed, not actually an interrupt though
{ {
if (TraceCallback != null) TraceCallback?.Invoke(new TraceInfo
{ {
TraceCallback(new TraceInfo Disassembly = "====un-stop====",
{ RegisterInfo = ""
Disassembly = "====un-stop====", });
RegisterInfo = ""
});
}
stopped = false; stopped = false;
if (OnExecFetch != null) OnExecFetch(RegPC); OnExecFetch?.Invoke(RegPC);
if (TraceCallback != null && !CB_prefix) TraceCallback(State()); if (TraceCallback != null && !CB_prefix) TraceCallback(State());
if (CDLCallback != null) CDLCallback(RegPC, eCDLogMemFlags.FetchFirst); CDLCallback?.Invoke(RegPC, eCDLogMemFlags.FetchFirst);
FetchInstruction(ReadMemory(RegPC++)); FetchInstruction(ReadMemory(RegPC++));
instr_pntr = 0; instr_pntr = 0;
@ -482,11 +466,13 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
else else
{ {
instr_pntr = 0; instr_pntr = 0;
cur_instr = new ushort[] cur_instr = new[]
{IDLE, {
IDLE, IDLE,
IDLE, IDLE,
STOP }; IDLE,
STOP
};
} }
break; break;
case PREFIX: case PREFIX:
@ -499,9 +485,9 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
ADDS_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++], cur_instr[instr_pntr++], cur_instr[instr_pntr++]); ADDS_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++], cur_instr[instr_pntr++], cur_instr[instr_pntr++]);
break; break;
case OP_G: case OP_G:
if (OnExecFetch != null) OnExecFetch(RegPC); OnExecFetch?.Invoke(RegPC);
if (TraceCallback != null) TraceCallback(State()); TraceCallback?.Invoke(State());
if (CDLCallback != null) CDLCallback(RegPC, eCDLogMemFlags.FetchFirst); CDLCallback?.Invoke(RegPC, eCDLogMemFlags.FetchFirst);
FetchInstruction(ReadMemory(RegPC)); // note no increment FetchInstruction(ReadMemory(RegPC)); // note no increment
@ -557,10 +543,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
public Action<TraceInfo> TraceCallback; public Action<TraceInfo> TraceCallback;
public string TraceHeader public string TraceHeader => "LR35902: PC, machine code, mnemonic, operands, registers (A, F, B, C, D, E, H, L, SP), Cy, flags (ZNHCI)";
{
get { return "LR35902: PC, machine code, mnemonic, operands, registers (A, F, B, C, D, E, H, L, SP), Cy, flags (ZNHCI)"; }
}
public TraceInfo State(bool disassemble = true) public TraceInfo State(bool disassemble = true)
{ {

View File

@ -526,8 +526,10 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
public static string Disassemble(ushort addr, Func<ushort, byte> reader, out ushort size) public static string Disassemble(ushort addr, Func<ushort, byte> reader, out ushort size)
{ {
ushort origaddr = addr; ushort origaddr = addr;
List<byte> bytes = new List<byte>(); var bytes = new List<byte>
bytes.Add(reader(addr++)); {
reader(addr++)
};
string result = table[bytes[0]]; string result = table[bytes[0]];
if (bytes[0] == 0xcb) if (bytes[0] == 0xcb)
@ -573,7 +575,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
offs -= 256; offs -= 256;
result = result.Replace("r8", $"{(ushort)(addr + offs):X4}h"); result = result.Replace("r8", $"{(ushort)(addr + offs):X4}h");
} }
StringBuilder ret = new StringBuilder(); var ret = new StringBuilder();
ret.Append($"{origaddr:X4}: "); ret.Append($"{origaddr:X4}: ");
foreach (var b in bytes) foreach (var b in bytes)
ret.Append($"{b:X2} "); ret.Append($"{b:X2} ");

View File

@ -1,5 +1,4 @@
using BizHawk.Common.NumberExtensions; using BizHawk.Common.NumberExtensions;
using System;
namespace BizHawk.Emulation.Cores.Components.LR35902 namespace BizHawk.Emulation.Cores.Components.LR35902
{ {
@ -16,7 +15,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
Regs[dest] = ReadMemory(addr); Regs[dest] = ReadMemory(addr);
} }
// speical read for POP AF that always clears the lower 4 bits of F // special read for POP AF that always clears the lower 4 bits of F
public void Read_Func_F(ushort dest, ushort src_l, ushort src_h) public void Read_Func_F(ushort dest, ushort src_l, ushort src_h)
{ {
Regs[dest] = (ushort)(ReadMemory((ushort)(Regs[src_l] | (Regs[src_h]) << 8)) & 0xF0); Regs[dest] = (ushort)(ReadMemory((ushort)(Regs[src_l] | (Regs[src_h]) << 8)) & 0xF0);
@ -25,7 +24,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
public void Write_Func(ushort dest_l, ushort dest_h, ushort src) public void Write_Func(ushort dest_l, ushort dest_h, ushort src)
{ {
ushort addr = (ushort)(Regs[dest_l] | (Regs[dest_h]) << 8); ushort addr = (ushort)(Regs[dest_l] | (Regs[dest_h]) << 8);
if (CDLCallback != null) CDLCallback(addr, eCDLogMemFlags.Write | eCDLogMemFlags.Data); CDLCallback?.Invoke(addr, eCDLogMemFlags.Write | eCDLogMemFlags.Data);
WriteMemory(addr, (byte)Regs[src]); WriteMemory(addr, (byte)Regs[src]);
} }
@ -141,7 +140,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
FlagZ = Regs[src] == 0; FlagZ = Regs[src] == 0;
FlagH = false; FlagH = false;
FlagN = false; FlagN = false;
} }
public void SRA_Func(ushort src) public void SRA_Func(ushort src)

View File

@ -1,6 +1,3 @@
using System.Runtime.InteropServices;
using System;
namespace BizHawk.Emulation.Cores.Components.LR35902 namespace BizHawk.Emulation.Cores.Components.LR35902
{ {
public partial class LR35902 public partial class LR35902

View File

@ -1,51 +1,58 @@
using System;
namespace BizHawk.Emulation.Cores.Components.LR35902 namespace BizHawk.Emulation.Cores.Components.LR35902
{ {
public partial class LR35902 public partial class LR35902
{ {
// this contains the vectors of instrcution operations // this contains the vectors of instruction operations
// NOTE: This list is NOT confirmed accurate for each individual cycle // NOTE: This list is NOT confirmed accurate for each individual cycle
private void NOP_() private void NOP_()
{ {
cur_instr = new ushort[] cur_instr = new[]
{IDLE, {
IDLE, IDLE,
HALT_CHK, IDLE,
OP }; HALT_CHK,
OP
};
} }
private void INC_16(ushort src_l, ushort src_h) private void INC_16(ushort srcL, ushort srcH)
{ {
cur_instr = new ushort[] cur_instr = new[]
{IDLE, {
IDLE, IDLE,
IDLE, IDLE,
INC16, src_l, src_h, IDLE,
IDLE, INC16,
IDLE, srcL,
HALT_CHK, srcH,
OP }; IDLE,
IDLE,
HALT_CHK,
OP
};
} }
private void DEC_16(ushort src_l, ushort src_h) private void DEC_16(ushort src_l, ushort src_h)
{ {
cur_instr = new ushort[] cur_instr = new[]
{IDLE, {
IDLE, IDLE,
IDLE, IDLE,
DEC16, src_l, src_h, IDLE,
IDLE, DEC16,
IDLE, src_l,
HALT_CHK, src_h,
OP }; IDLE,
IDLE,
HALT_CHK,
OP
};
} }
private void ADD_16(ushort dest_l, ushort dest_h, ushort src_l, ushort src_h) private void ADD_16(ushort dest_l, ushort dest_h, ushort src_l, ushort src_h)
{ {
cur_instr = new ushort[] cur_instr = new[]
{IDLE, {IDLE,
IDLE, IDLE,
IDLE, IDLE,
@ -58,7 +65,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
private void REG_OP(ushort operation, ushort dest, ushort src) private void REG_OP(ushort operation, ushort dest, ushort src)
{ {
cur_instr = new ushort[] cur_instr = new[]
{operation, dest, src, {operation, dest, src,
IDLE, IDLE,
HALT_CHK, HALT_CHK,
@ -67,7 +74,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
private void STOP_() private void STOP_()
{ {
cur_instr = new ushort[] cur_instr = new[]
{RD, Z, PCl, PCh, {RD, Z, PCl, PCh,
INC16, PCl, PCh, INC16, PCl, PCh,
IDLE, IDLE,
@ -82,7 +89,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
{ {
// in GBC mode, the HALT bug is worked around by simply adding a NOP // in GBC mode, the HALT bug is worked around by simply adding a NOP
// so it just takes 4 cycles longer to reach the next instruction // so it just takes 4 cycles longer to reach the next instruction
cur_instr = new ushort[] cur_instr = new[]
{IDLE, {IDLE,
IDLE, IDLE,
IDLE, IDLE,
@ -92,7 +99,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
{ // if interrupts are disabled, { // if interrupts are disabled,
// a glitchy decrement to the program counter happens // a glitchy decrement to the program counter happens
{ {
cur_instr = new ushort[] cur_instr = new[]
{IDLE, {IDLE,
IDLE, IDLE,
IDLE, IDLE,
@ -104,7 +111,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
{ {
cur_instr = new ushort[] cur_instr = new ushort[]
{ {
IDLE, IDLE,
HALT_CHK, HALT_CHK,
IDLE, IDLE,
HALT, 0 }; HALT, 0 };
@ -139,7 +146,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
} }
else else
{ {
cur_instr = new ushort[] cur_instr = new[]
{IDLE, {IDLE,
IDLE, IDLE,
IDLE, IDLE,
@ -155,7 +162,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
{ {
if (cond) if (cond)
{ {
cur_instr = new ushort[] cur_instr = new[]
{IDLE, {IDLE,
IDLE, IDLE,
IDLE, IDLE,
@ -175,7 +182,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
} }
else else
{ {
cur_instr = new ushort[] cur_instr = new[]
{IDLE, {IDLE,
IDLE, IDLE,
IDLE, IDLE,
@ -193,7 +200,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
private void RET_() private void RET_()
{ {
cur_instr = new ushort[] cur_instr = new[]
{IDLE, {IDLE,
IDLE, IDLE,
IDLE, IDLE,
@ -214,7 +221,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
private void RETI_() private void RETI_()
{ {
cur_instr = new ushort[] cur_instr = new[]
{IDLE, {IDLE,
IDLE, IDLE,
IDLE, IDLE,
@ -238,7 +245,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
{ {
if (cond) if (cond)
{ {
cur_instr = new ushort[] cur_instr = new[]
{IDLE, {IDLE,
IDLE, IDLE,
IDLE, IDLE,
@ -262,7 +269,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
} }
else else
{ {
cur_instr = new ushort[] cur_instr = new[]
{IDLE, {IDLE,
IDLE, IDLE,
IDLE, IDLE,
@ -278,7 +285,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
{ {
if (cond) if (cond)
{ {
cur_instr = new ushort[] cur_instr = new[]
{IDLE, {IDLE,
IDLE, IDLE,
IDLE, IDLE,
@ -306,7 +313,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
} }
else else
{ {
cur_instr = new ushort[] cur_instr = new[]
{IDLE, {IDLE,
IDLE, IDLE,
IDLE, IDLE,
@ -324,7 +331,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
private void INT_OP(ushort operation, ushort src) private void INT_OP(ushort operation, ushort src)
{ {
cur_instr = new ushort[] cur_instr = new[]
{operation, src, {operation, src,
IDLE, IDLE,
HALT_CHK, HALT_CHK,
@ -333,7 +340,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
private void BIT_OP(ushort operation, ushort bit, ushort src) private void BIT_OP(ushort operation, ushort bit, ushort src)
{ {
cur_instr = new ushort[] cur_instr = new[]
{operation, bit, src, {operation, bit, src,
IDLE, IDLE,
HALT_CHK, HALT_CHK,
@ -342,7 +349,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
private void PUSH_(ushort src_l, ushort src_h) private void PUSH_(ushort src_l, ushort src_h)
{ {
cur_instr = new ushort[] cur_instr = new[]
{IDLE, {IDLE,
IDLE, IDLE,
IDLE, IDLE,
@ -368,7 +375,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
{ {
if (src_l != F) if (src_l != F)
{ {
cur_instr = new ushort[] cur_instr = new[]
{IDLE, {IDLE,
IDLE, IDLE,
IDLE, IDLE,
@ -384,7 +391,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
} }
else else
{ {
cur_instr = new ushort[] cur_instr = new[]
{IDLE, {IDLE,
IDLE, IDLE,
IDLE, IDLE,
@ -423,7 +430,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
private void PREFIX_() private void PREFIX_()
{ {
cur_instr = new ushort[] cur_instr = new[]
{PREFIX, {PREFIX,
IDLE, IDLE,
IDLE, IDLE,
@ -432,7 +439,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
private void DI_() private void DI_()
{ {
cur_instr = new ushort[] cur_instr = new[]
{DI, {DI,
IDLE, IDLE,
HALT_CHK, HALT_CHK,
@ -441,7 +448,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
private void EI_() private void EI_()
{ {
cur_instr = new ushort[] cur_instr = new[]
{EI, {EI,
IDLE, IDLE,
HALT_CHK, HALT_CHK,
@ -450,7 +457,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
private void JP_HL() private void JP_HL()
{ {
cur_instr = new ushort[] cur_instr = new[]
{TR, PCl, L, {TR, PCl, L,
TR, PCh, H, TR, PCh, H,
HALT_CHK, HALT_CHK,
@ -480,7 +487,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
private void LD_SP_HL() private void LD_SP_HL()
{ {
cur_instr = new ushort[] cur_instr = new[]
{IDLE, {IDLE,
IDLE, IDLE,
IDLE, IDLE,
@ -510,7 +517,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
private void JAM_() private void JAM_()
{ {
cur_instr = new ushort[] cur_instr = new[]
{JAM, {JAM,
IDLE, IDLE,
IDLE, IDLE,

View File

@ -1,5 +1,3 @@
using System;
namespace BizHawk.Emulation.Cores.Components.MC6800 namespace BizHawk.Emulation.Cores.Components.MC6800
{ {
public partial class MC6800 public partial class MC6800

View File

@ -1,5 +1,3 @@
using System;
namespace BizHawk.Emulation.Cores.Components.MC6800 namespace BizHawk.Emulation.Cores.Components.MC6800
{ {
public partial class MC6800 public partial class MC6800

View File

@ -153,10 +153,10 @@ namespace BizHawk.Emulation.Cores.Components.MC6800
// do nothing // do nothing
break; break;
case OP: case OP:
// Read the opcode of the next instruction // Read the opcode of the next instruction
if (OnExecFetch != null) OnExecFetch(PC); OnExecFetch?.Invoke(PC);
if (TraceCallback != null) TraceCallback(State()); TraceCallback?.Invoke(State());
if (CDLCallback != null) CDLCallback(PC, eCDLogMemFlags.FetchFirst); CDLCallback?.Invoke(PC, eCDLogMemFlags.FetchFirst);
FetchInstruction(ReadMemory(Regs[PC]++)); FetchInstruction(ReadMemory(Regs[PC]++));
instr_pntr = 0; instr_pntr = 0;
irq_pntr = -1; irq_pntr = -1;
@ -433,7 +433,7 @@ namespace BizHawk.Emulation.Cores.Components.MC6800
irq_pntr = -1; irq_pntr = -1;
IRQS = 3; IRQS = 3;
if (TraceCallback != null) { TraceCallback(new TraceInfo { Disassembly = "====CWAI NMI====", RegisterInfo = "" }); } TraceCallback?.Invoke(new TraceInfo { Disassembly = "====CWAI NMI====", RegisterInfo = "" });
} }
else if (IRQPending && !FlagI) else if (IRQPending && !FlagI)
{ {
@ -446,7 +446,7 @@ namespace BizHawk.Emulation.Cores.Components.MC6800
irq_pntr = -1; irq_pntr = -1;
IRQS = 3; IRQS = 3;
if (TraceCallback != null) { TraceCallback(new TraceInfo { Disassembly = "====CWAI IRQ====", RegisterInfo = "" }); } TraceCallback?.Invoke(new TraceInfo { Disassembly = "====CWAI IRQ====", RegisterInfo = "" });
} }
else else
{ {
@ -465,23 +465,23 @@ namespace BizHawk.Emulation.Cores.Components.MC6800
{ {
NMIPending = false; NMIPending = false;
if (TraceCallback != null) { TraceCallback(new TraceInfo { Disassembly = "====NMI====", RegisterInfo = "" }); } TraceCallback?.Invoke(new TraceInfo { Disassembly = "====NMI====", RegisterInfo = "" });
NMI_(); NMI_();
NMICallback(); NMICallback();
instr_pntr = irq_pntr = 0; instr_pntr = irq_pntr = 0;
} }
// then regular IRQ // then regular IRQ
else if (IRQPending && !FlagI) else if (IRQPending && !FlagI)
{ {
IRQPending = false; IRQPending = false;
if (TraceCallback != null) { TraceCallback(new TraceInfo { Disassembly = "====IRQ====", RegisterInfo = "" }); } TraceCallback?.Invoke(new TraceInfo { Disassembly = "====IRQ====", RegisterInfo = "" });
IRQ_(); IRQ_();
IRQCallback(); IRQCallback();
instr_pntr = irq_pntr = 0; instr_pntr = irq_pntr = 0;
} }
// otherwise start the next instruction // otherwise start the next instruction
else else
{ {
@ -498,10 +498,7 @@ namespace BizHawk.Emulation.Cores.Components.MC6800
public Action<TraceInfo> TraceCallback; public Action<TraceInfo> TraceCallback;
public string TraceHeader public string TraceHeader => "MC6809: PC, machine code, mnemonic, operands, registers (A, B, X, SP, CC), Cy, flags (EHINZVC)";
{
get { return "MC6809: PC, machine code, mnemonic, operands, registers (A, B, X, SP, CC), Cy, flags (EHINZVC)"; }
}
public TraceInfo State(bool disassemble = true) public TraceInfo State(bool disassemble = true)
{ {
@ -523,7 +520,7 @@ namespace BizHawk.Emulation.Cores.Components.MC6800
FlagN ? "N" : "n", FlagN ? "N" : "n",
FlagZ ? "Z" : "z", FlagZ ? "Z" : "z",
FlagV ? "V" : "v", FlagV ? "V" : "v",
FlagC ? "C" : "c" FlagC ? "C" : "c"
) )
}; };
} }

View File

@ -1,6 +1,3 @@
using System;
using BizHawk.Common.NumberExtensions;
namespace BizHawk.Emulation.Cores.Components.MC6800 namespace BizHawk.Emulation.Cores.Components.MC6800
{ {
public partial class MC6800 public partial class MC6800

View File

@ -1,5 +1,4 @@
using System; using BizHawk.Common.NumberExtensions;
using BizHawk.Common.NumberExtensions;
namespace BizHawk.Emulation.Cores.Components.MC6800 namespace BizHawk.Emulation.Cores.Components.MC6800
{ {
@ -31,33 +30,33 @@ namespace BizHawk.Emulation.Cores.Components.MC6800
public void Write_Func(ushort dest, ushort src) public void Write_Func(ushort dest, ushort src)
{ {
if (CDLCallback != null) CDLCallback(Regs[dest], eCDLogMemFlags.Write | eCDLogMemFlags.Data); CDLCallback?.Invoke(Regs[dest], eCDLogMemFlags.Write | eCDLogMemFlags.Data);
WriteMemory(Regs[dest], (byte)Regs[src]); WriteMemory(Regs[dest], (byte)Regs[src]);
} }
public void Write_Dec_Lo_Func(ushort dest, ushort src) public void Write_Dec_Lo_Func(ushort dest, ushort src)
{ {
if (CDLCallback != null) CDLCallback(Regs[dest], eCDLogMemFlags.Write | eCDLogMemFlags.Data); CDLCallback?.Invoke(Regs[dest], eCDLogMemFlags.Write | eCDLogMemFlags.Data);
WriteMemory(Regs[dest], (byte)Regs[src]); WriteMemory(Regs[dest], (byte)Regs[src]);
Regs[dest] -= 1; Regs[dest] -= 1;
} }
public void Write_Dec_HI_Func(ushort dest, ushort src) public void Write_Dec_HI_Func(ushort dest, ushort src)
{ {
if (CDLCallback != null) CDLCallback(Regs[dest], eCDLogMemFlags.Write | eCDLogMemFlags.Data); CDLCallback?.Invoke(Regs[dest], eCDLogMemFlags.Write | eCDLogMemFlags.Data);
WriteMemory(Regs[dest], (byte)(Regs[src] >> 8)); WriteMemory(Regs[dest], (byte)(Regs[src] >> 8));
Regs[dest] -= 1; Regs[dest] -= 1;
} }
public void Write_Hi_Func(ushort dest, ushort src) public void Write_Hi_Func(ushort dest, ushort src)
{ {
if (CDLCallback != null) CDLCallback(Regs[dest], eCDLogMemFlags.Write | eCDLogMemFlags.Data); CDLCallback?.Invoke(Regs[dest], eCDLogMemFlags.Write | eCDLogMemFlags.Data);
WriteMemory(Regs[dest], (byte)(Regs[src] >> 8)); WriteMemory(Regs[dest], (byte)(Regs[src] >> 8));
} }
public void Write_Hi_Inc_Func(ushort dest, ushort src) public void Write_Hi_Inc_Func(ushort dest, ushort src)
{ {
if (CDLCallback != null) CDLCallback(Regs[dest], eCDLogMemFlags.Write | eCDLogMemFlags.Data); CDLCallback?.Invoke(Regs[dest], eCDLogMemFlags.Write | eCDLogMemFlags.Data);
WriteMemory(Regs[dest], (byte)(Regs[src] >> 8)); WriteMemory(Regs[dest], (byte)(Regs[src] >> 8));
Regs[dest]++; Regs[dest]++;
} }

View File

@ -1,5 +1,3 @@
using System;
namespace BizHawk.Emulation.Cores.Components.MC6800 namespace BizHawk.Emulation.Cores.Components.MC6800
{ {
public partial class MC6800 public partial class MC6800

View File

@ -1,5 +1,3 @@
using System;
namespace BizHawk.Emulation.Cores.Components.MC6809 namespace BizHawk.Emulation.Cores.Components.MC6809
{ {
public partial class MC6809 public partial class MC6809

View File

@ -1,5 +1,3 @@
using System;
namespace BizHawk.Emulation.Cores.Components.MC6809 namespace BizHawk.Emulation.Cores.Components.MC6809
{ {
public partial class MC6809 public partial class MC6809

View File

@ -162,10 +162,10 @@ namespace BizHawk.Emulation.Cores.Components.MC6809
// do nothing // do nothing
break; break;
case OP: case OP:
// Read the opcode of the next instruction // Read the opcode of the next instruction
if (OnExecFetch != null) OnExecFetch(PC); OnExecFetch?.Invoke(PC);
if (TraceCallback != null) TraceCallback(State()); TraceCallback?.Invoke(State());
if (CDLCallback != null) CDLCallback(PC, eCDLogMemFlags.FetchFirst); CDLCallback?.Invoke(PC, eCDLogMemFlags.FetchFirst);
FetchInstruction(ReadMemory(Regs[PC]++)); FetchInstruction(ReadMemory(Regs[PC]++));
instr_pntr = 0; instr_pntr = 0;
irq_pntr = -1; irq_pntr = -1;
@ -473,7 +473,7 @@ namespace BizHawk.Emulation.Cores.Components.MC6809
irq_pntr = -1; irq_pntr = -1;
IRQS = 3; IRQS = 3;
if (TraceCallback != null) { TraceCallback(new TraceInfo { Disassembly = "====CWAI NMI====", RegisterInfo = "" }); } TraceCallback?.Invoke(new TraceInfo { Disassembly = "====CWAI NMI====", RegisterInfo = "" });
} }
else if (FIRQPending && !FlagF) else if (FIRQPending && !FlagF)
{ {
@ -486,7 +486,7 @@ namespace BizHawk.Emulation.Cores.Components.MC6809
irq_pntr = -1; irq_pntr = -1;
IRQS = 3; IRQS = 3;
if (TraceCallback != null) { TraceCallback(new TraceInfo { Disassembly = "====CWAI FIRQ====", RegisterInfo = "" }); } TraceCallback?.Invoke(new TraceInfo { Disassembly = "====CWAI FIRQ====", RegisterInfo = "" });
} }
else if (IRQPending && !FlagI) else if (IRQPending && !FlagI)
{ {
@ -499,7 +499,7 @@ namespace BizHawk.Emulation.Cores.Components.MC6809
irq_pntr = -1; irq_pntr = -1;
IRQS = 3; IRQS = 3;
if (TraceCallback != null) { TraceCallback(new TraceInfo { Disassembly = "====CWAI IRQ====", RegisterInfo = "" }); } TraceCallback?.Invoke(new TraceInfo { Disassembly = "====CWAI IRQ====", RegisterInfo = "" });
} }
else else
{ {
@ -522,7 +522,7 @@ namespace BizHawk.Emulation.Cores.Components.MC6809
irq_pntr = -1; irq_pntr = -1;
IRQS = 3; IRQS = 3;
if (TraceCallback != null) { TraceCallback(new TraceInfo { Disassembly = "====SYNC NMI====", RegisterInfo = "" }); } TraceCallback?.Invoke(new TraceInfo { Disassembly = "====SYNC NMI====", RegisterInfo = "" });
} }
else if (FIRQPending) else if (FIRQPending)
{ {
@ -537,11 +537,11 @@ namespace BizHawk.Emulation.Cores.Components.MC6809
irq_pntr = -1; irq_pntr = -1;
IRQS = 3; IRQS = 3;
if (TraceCallback != null) { TraceCallback(new TraceInfo { Disassembly = "====SYNC FIRQ====", RegisterInfo = "" }); } TraceCallback?.Invoke(new TraceInfo { Disassembly = "====SYNC FIRQ====", RegisterInfo = "" });
} }
else else
{ {
FIRQPending = false; FIRQPending = false;
IN_SYNC = false; IN_SYNC = false;
IRQS = 2; IRQS = 2;
instr_pntr = irq_pntr = 0; instr_pntr = irq_pntr = 0;
@ -563,7 +563,7 @@ namespace BizHawk.Emulation.Cores.Components.MC6809
irq_pntr = -1; irq_pntr = -1;
IRQS = 3; IRQS = 3;
if (TraceCallback != null) { TraceCallback(new TraceInfo { Disassembly = "====SYNC IRQ====", RegisterInfo = "" }); } TraceCallback?.Invoke(new TraceInfo { Disassembly = "====SYNC IRQ====", RegisterInfo = "" });
} }
else else
{ {
@ -593,7 +593,7 @@ namespace BizHawk.Emulation.Cores.Components.MC6809
{ {
NMIPending = false; NMIPending = false;
if (TraceCallback != null) { TraceCallback(new TraceInfo { Disassembly = "====NMI====", RegisterInfo = "" }); } TraceCallback?.Invoke(new TraceInfo { Disassembly = "====NMI====", RegisterInfo = "" });
NMI_(); NMI_();
NMICallback(); NMICallback();
@ -604,23 +604,22 @@ namespace BizHawk.Emulation.Cores.Components.MC6809
{ {
FIRQPending = false; FIRQPending = false;
if (TraceCallback != null) { TraceCallback(new TraceInfo { Disassembly = "====FIRQ====", RegisterInfo = "" }); } TraceCallback?.Invoke(new TraceInfo { Disassembly = "====FIRQ====", RegisterInfo = "" });
FIRQ_(); FIRQ_();
FIRQCallback(); FIRQCallback();
instr_pntr = irq_pntr = 0; instr_pntr = irq_pntr = 0;
} }
// then regular IRQ // then regular IRQ
else if (IRQPending && !FlagI) else if (IRQPending && !FlagI)
{ {
IRQPending = false; IRQPending = false;
if (TraceCallback != null) { TraceCallback(new TraceInfo { Disassembly = "====IRQ====", RegisterInfo = "" }); } TraceCallback?.Invoke(new TraceInfo { Disassembly = "====IRQ====", RegisterInfo = "" });
IRQ_(); IRQ_();
IRQCallback(); IRQCallback();
instr_pntr = irq_pntr = 0; instr_pntr = irq_pntr = 0;
} }
// otherwise start the next instruction // otherwise start the next instruction
else else
{ {
@ -637,10 +636,7 @@ namespace BizHawk.Emulation.Cores.Components.MC6809
public Action<TraceInfo> TraceCallback; public Action<TraceInfo> TraceCallback;
public string TraceHeader public string TraceHeader => "MC6809: PC, machine code, mnemonic, operands, registers (A, B, X, Y, US, SP, DP, CC), Cy, flags (EFHINZVC)";
{
get { return "MC6809: PC, machine code, mnemonic, operands, registers (A, B, X, Y, US, SP, DP, CC), Cy, flags (EFHINZVC)"; }
}
public TraceInfo State(bool disassemble = true) public TraceInfo State(bool disassemble = true)
{ {
@ -667,7 +663,7 @@ namespace BizHawk.Emulation.Cores.Components.MC6809
FlagN ? "N" : "n", FlagN ? "N" : "n",
FlagZ ? "Z" : "z", FlagZ ? "Z" : "z",
FlagV ? "V" : "v", FlagV ? "V" : "v",
FlagC ? "C" : "c" FlagC ? "C" : "c"
) )
}; };
} }

View File

@ -1,4 +1,3 @@
using System;
using BizHawk.Common.NumberExtensions; using BizHawk.Common.NumberExtensions;
namespace BizHawk.Emulation.Cores.Components.MC6809 namespace BizHawk.Emulation.Cores.Components.MC6809

View File

@ -1,5 +1,4 @@
using System; using BizHawk.Common.NumberExtensions;
using BizHawk.Common.NumberExtensions;
namespace BizHawk.Emulation.Cores.Components.MC6809 namespace BizHawk.Emulation.Cores.Components.MC6809
{ {
@ -31,40 +30,40 @@ namespace BizHawk.Emulation.Cores.Components.MC6809
public void Write_Func(ushort dest, ushort src) public void Write_Func(ushort dest, ushort src)
{ {
if (CDLCallback != null) CDLCallback(Regs[dest], eCDLogMemFlags.Write | eCDLogMemFlags.Data); CDLCallback?.Invoke(Regs[dest], eCDLogMemFlags.Write | eCDLogMemFlags.Data);
WriteMemory(Regs[dest], (byte)Regs[src]); WriteMemory(Regs[dest], (byte)Regs[src]);
} }
public void Write_Dec_Lo_Func(ushort dest, ushort src) public void Write_Dec_Lo_Func(ushort dest, ushort src)
{ {
if (CDLCallback != null) CDLCallback(Regs[dest], eCDLogMemFlags.Write | eCDLogMemFlags.Data); CDLCallback?.Invoke(Regs[dest], eCDLogMemFlags.Write | eCDLogMemFlags.Data);
WriteMemory(Regs[dest], (byte)Regs[src]); WriteMemory(Regs[dest], (byte)Regs[src]);
Regs[dest] -= 1; Regs[dest] -= 1;
} }
public void Write_Dec_HI_Func(ushort dest, ushort src) public void Write_Dec_HI_Func(ushort dest, ushort src)
{ {
if (CDLCallback != null) CDLCallback(Regs[dest], eCDLogMemFlags.Write | eCDLogMemFlags.Data); CDLCallback?.Invoke(Regs[dest], eCDLogMemFlags.Write | eCDLogMemFlags.Data);
WriteMemory(Regs[dest], (byte)(Regs[src] >> 8)); WriteMemory(Regs[dest], (byte)(Regs[src] >> 8));
Regs[dest] -= 1; Regs[dest] -= 1;
} }
public void Write_Hi_Func(ushort dest, ushort src) public void Write_Hi_Func(ushort dest, ushort src)
{ {
if (CDLCallback != null) CDLCallback(Regs[dest], eCDLogMemFlags.Write | eCDLogMemFlags.Data); CDLCallback?.Invoke(Regs[dest], eCDLogMemFlags.Write | eCDLogMemFlags.Data);
WriteMemory(Regs[dest], (byte)(Regs[src] >> 8)); WriteMemory(Regs[dest], (byte)(Regs[src] >> 8));
} }
public void Write_Hi_Inc_Func(ushort dest, ushort src) public void Write_Hi_Inc_Func(ushort dest, ushort src)
{ {
if (CDLCallback != null) CDLCallback(Regs[dest], eCDLogMemFlags.Write | eCDLogMemFlags.Data); CDLCallback?.Invoke(Regs[dest], eCDLogMemFlags.Write | eCDLogMemFlags.Data);
WriteMemory(Regs[dest], (byte)(Regs[src] >> 8)); WriteMemory(Regs[dest], (byte)(Regs[src] >> 8));
Regs[dest]++; Regs[dest]++;
} }
public void Write_Lo_Inc_Func(ushort dest, ushort src) public void Write_Lo_Inc_Func(ushort dest, ushort src)
{ {
if (CDLCallback != null) CDLCallback(Regs[dest], eCDLogMemFlags.Write | eCDLogMemFlags.Data); CDLCallback?.Invoke(Regs[dest], eCDLogMemFlags.Write | eCDLogMemFlags.Data);
WriteMemory(Regs[dest], (byte)Regs[src]); WriteMemory(Regs[dest], (byte)Regs[src]);
Regs[dest]++; Regs[dest]++;
} }
@ -126,7 +125,7 @@ namespace BizHawk.Emulation.Cores.Components.MC6809
FlagZ = Regs[dest] == 0; FlagZ = Regs[dest] == 0;
FlagV = false; FlagV = false;
FlagN = Regs[dest] > 0x7FFF; FlagN = Regs[dest] > 0x7FFF;
} }
// for LEAX/Y, zero flag can be effected, but not for U/S // for LEAX/Y, zero flag can be effected, but not for U/S
@ -134,7 +133,7 @@ namespace BizHawk.Emulation.Cores.Components.MC6809
{ {
Regs[dest] = Regs[src]; Regs[dest] = Regs[src];
if ((dest == X) || (dest == Y)) if (dest == X || dest == Y)
{ {
FlagZ = Regs[dest] == 0; FlagZ = Regs[dest] == 0;
} }

View File

@ -1,5 +1,3 @@
using System;
namespace BizHawk.Emulation.Cores.Components.MC6809 namespace BizHawk.Emulation.Cores.Components.MC6809
{ {
public partial class MC6809 public partial class MC6809

View File

@ -20,19 +20,13 @@ namespace BizHawk.Emulation.Cores.Components.M6502
public string Cpu public string Cpu
{ {
get get => "6502";
{
return "6502";
}
set set
{ {
} }
} }
public string PCRegisterName public string PCRegisterName => "PC";
{
get { return "PC"; }
}
public IEnumerable<string> AvailableCpus public IEnumerable<string> AvailableCpus
{ {

View File

@ -1,7 +1,6 @@
//http://nesdev.parodius.com/6502_cpu.txt //http://nesdev.parodius.com/6502_cpu.txt
using System; using System;
using BizHawk.Common;
using BizHawk.Common.NumberExtensions; using BizHawk.Common.NumberExtensions;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
@ -561,14 +560,11 @@ namespace BizHawk.Emulation.Cores.Components.M6502
interrupt_pending = false; interrupt_pending = false;
if (NMI) if (NMI)
{ {
if (TraceCallback != null) TraceCallback?.Invoke(new TraceInfo
{ {
TraceCallback(new TraceInfo Disassembly = "====NMI====",
{ RegisterInfo = ""
Disassembly = "====NMI====", });
RegisterInfo = ""
});
}
ea = NMIVector; ea = NMIVector;
opcode = VOP_NMI; opcode = VOP_NMI;
@ -577,16 +573,14 @@ namespace BizHawk.Emulation.Cores.Components.M6502
ExecuteOneRetry(); ExecuteOneRetry();
return; return;
} }
else if (IRQ && !my_iflag)
if (IRQ && !my_iflag)
{ {
if (TraceCallback != null) TraceCallback?.Invoke(new TraceInfo
{ {
TraceCallback(new TraceInfo Disassembly = "====IRQ====",
{ RegisterInfo = ""
Disassembly = "====IRQ====", });
RegisterInfo = ""
});
}
ea = IRQVector; ea = IRQVector;
opcode = VOP_IRQ; opcode = VOP_IRQ;
mi = 0; mi = 0;
@ -606,8 +600,7 @@ namespace BizHawk.Emulation.Cores.Components.M6502
if (debug) Console.WriteLine(State()); if (debug) Console.WriteLine(State());
branch_irq_hack = false; branch_irq_hack = false;
_link.OnExecFetch(PC); _link.OnExecFetch(PC);
if (TraceCallback != null) TraceCallback?.Invoke(State());
TraceCallback(State());
opcode = _link.ReadMemory(PC++); opcode = _link.ReadMemory(PC++);
mi = -1; mi = -1;
} }

View File

@ -138,7 +138,7 @@ namespace BizHawk.Emulation.Cores.Components.M6502
}; };
} }
public bool AtStart { get { return opcode == VOP_Fetch1 || Microcode[opcode][mi] >= Uop.End; } } public bool AtStart => opcode == VOP_Fetch1 || Microcode[opcode][mi] >= Uop.End;
public TraceInfo TraceState() public TraceInfo TraceState()
{ {

View File

@ -28,18 +28,13 @@ namespace BizHawk.Emulation.Cores.Components.W65816
get { yield return "W65816"; } get { yield return "W65816"; }
} }
public string PCRegisterName => "PC";
public string PCRegisterName
{
get { return "PC"; }
}
public string Disassemble(MemoryDomain m, uint addr, out int length) public string Disassemble(MemoryDomain m, uint addr, out int length)
{ {
byte P = 0; //TODO - user preferences somehow... byte P = 0; //TODO - user preferences somehow...
return disassemblerCpu.Disassemble(addr, m.PeekByte, ref P, out length); return disassemblerCpu.Disassemble(addr, m.PeekByte, ref P, out length);
} }
} }
class W65816 class W65816

View File

@ -1,5 +1,3 @@
using System;
namespace BizHawk.Emulation.Cores.Components.Z80A namespace BizHawk.Emulation.Cores.Components.Z80A
{ {
public partial class Z80A public partial class Z80A
@ -8,7 +6,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A
private int EI_pending; private int EI_pending;
// ZXHawk needs to be able to read this for zx-state snapshot export // ZXHawk needs to be able to read this for zx-state snapshot export
public int EIPending { get { return EI_pending; } } public int EIPending => EI_pending;
public const ushort CBpre = 0; public const ushort CBpre = 0;
public const ushort EXTDpre = 1; public const ushort EXTDpre = 1;

View File

@ -26,7 +26,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A
return format; return format;
} }
static readonly string[] mnemonics = new string[] static readonly string[] mnemonics =
{ {
"NOP", "LD BC, nn", "LD (BC), A", "INC BC", //0x04 "NOP", "LD BC, nn", "LD (BC), A", "INC BC", //0x04
"INC B", "DEC B", "LD B, n", "RLCA", //0x08 "INC B", "DEC B", "LD B, n", "RLCA", //0x08
@ -94,7 +94,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A
"CALL M, nn", "[FD]", "CP n", "RST $38", //0x100 "CALL M, nn", "[FD]", "CP n", "RST $38", //0x100
}; };
static readonly string[] mnemonicsDD = new string[] static readonly string[] mnemonicsDD =
{ {
"NOP", "LD BC, nn", "LD (BC), A", "INC BC", //0x04 "NOP", "LD BC, nn", "LD (BC), A", "INC BC", //0x04
"INC B", "DEC B", "LD B, n", "RLCA", //0x08 "INC B", "DEC B", "LD B, n", "RLCA", //0x08
@ -162,7 +162,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A
"CALL M, nn", "[!!DD FD!!]", "CP n", "RST $38", //0x100 "CALL M, nn", "[!!DD FD!!]", "CP n", "RST $38", //0x100
}; };
static readonly string[] mnemonicsFD = new string[] static readonly string[] mnemonicsFD =
{ {
"NOP", "LD BC, nn", "LD (BC), A", "INC BC", //0x04 "NOP", "LD BC, nn", "LD (BC), A", "INC BC", //0x04
"INC B", "DEC B", "LD B, n", "RLCA", //0x08 "INC B", "DEC B", "LD B, n", "RLCA", //0x08
@ -230,7 +230,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A
"CALL M, nn", "[!FD FD!]", "CP n", "RST $38", //0x100 "CALL M, nn", "[!FD FD!]", "CP n", "RST $38", //0x100
}; };
static readonly string[] mnemonicsDDCB = new string[] static readonly string[] mnemonicsDDCB =
{ {
"RLC (IX+d)->B", "RLC (IX+d)->C", "RLC (IX+d)->D", "RLC (IX+d)->E", "RLC (IX+d)->H", "RLC (IX+d)->L", "RLC (IX+d)", "RLC (IX+d)->A", "RLC (IX+d)->B", "RLC (IX+d)->C", "RLC (IX+d)->D", "RLC (IX+d)->E", "RLC (IX+d)->H", "RLC (IX+d)->L", "RLC (IX+d)", "RLC (IX+d)->A",
"RRC (IX+d)->B", "RRC (IX+d)->C", "RRC (IX+d)->D", "RRC (IX+d)->E", "RRC (IX+d)->H", "RRC (IX+d)->L", "RRC (IX+d)", "RRC (IX+d)->A", "RRC (IX+d)->B", "RRC (IX+d)->C", "RRC (IX+d)->D", "RRC (IX+d)->E", "RRC (IX+d)->H", "RRC (IX+d)->L", "RRC (IX+d)", "RRC (IX+d)->A",
@ -266,7 +266,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A
"SET 7 (IX+d)->B", "SET 7 (IX+d)->C", "SET 7 (IX+d)->D", "SET 7 (IX+d)->E", "SET 7 (IX+d)->H", "SET 7 (IX+d)->L", "SET 7 (IX+d)", "SET 7 (IX+d)->A", "SET 7 (IX+d)->B", "SET 7 (IX+d)->C", "SET 7 (IX+d)->D", "SET 7 (IX+d)->E", "SET 7 (IX+d)->H", "SET 7 (IX+d)->L", "SET 7 (IX+d)", "SET 7 (IX+d)->A",
}; };
static readonly string[] mnemonicsFDCB = new string[] static readonly string[] mnemonicsFDCB =
{ {
"RLC (IY+d)->B", "RLC (IY+d)->C", "RLC (IY+d)->D", "RLC (IY+d)->E", "RLC (IY+d)->H", "RLC (IY+d)->L", "RLC (IY+d)", "RLC (IY+d)->A", "RLC (IY+d)->B", "RLC (IY+d)->C", "RLC (IY+d)->D", "RLC (IY+d)->E", "RLC (IY+d)->H", "RLC (IY+d)->L", "RLC (IY+d)", "RLC (IY+d)->A",
"RRC (IY+d)->B", "RRC (IY+d)->C", "RRC (IY+d)->D", "RRC (IY+d)->E", "RRC (IY+d)->H", "RRC (IY+d)->L", "RRC (IY+d)", "RRC (IY+d)->A", "RRC (IY+d)->B", "RRC (IY+d)->C", "RRC (IY+d)->D", "RRC (IY+d)->E", "RRC (IY+d)->H", "RRC (IY+d)->L", "RRC (IY+d)", "RRC (IY+d)->A",
@ -302,7 +302,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A
"SET 7 (IY+d)->B", "SET 7 (IY+d)->C", "SET 7 (IY+d)->D", "SET 7 (IY+d)->E", "SET 7 (IY+d)->H", "SET 7 (IY+d)->L", "SET 7 (IY+d)", "SET 7 (IY+d)->A", "SET 7 (IY+d)->B", "SET 7 (IY+d)->C", "SET 7 (IY+d)->D", "SET 7 (IY+d)->E", "SET 7 (IY+d)->H", "SET 7 (IY+d)->L", "SET 7 (IY+d)", "SET 7 (IY+d)->A",
}; };
static readonly string[] mnemonicsCB = new string[] static readonly string[] mnemonicsCB =
{ {
"RLC B", "RLC C", "RLC D", "RLC E", "RLC H", "RLC L", "RLC (HL)", "RLC A", "RLC B", "RLC C", "RLC D", "RLC E", "RLC H", "RLC L", "RLC (HL)", "RLC A",
"RRC B", "RRC C", "RRC D", "RRC E", "RRC H", "RRC L", "RRC (HL)", "RRC A", "RRC B", "RRC C", "RRC D", "RRC E", "RRC H", "RRC L", "RRC (HL)", "RRC A",
@ -338,7 +338,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A
"SET 7, B", "SET 7, C", "SET 7, D", "SET 7, E", "SET 7, H", "SET 7, L", "SET 7, (HL)", "SET 7, A", "SET 7, B", "SET 7, C", "SET 7, D", "SET 7, E", "SET 7, H", "SET 7, L", "SET 7, (HL)", "SET 7, A",
}; };
static readonly string[] mnemonicsED = new string[] static readonly string[] mnemonicsED =
{ {
"NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP",
"NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP", "NOP",
@ -439,10 +439,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A
set { } set { }
} }
public string PCRegisterName public string PCRegisterName => "PC";
{
get { return "PC"; }
}
public IEnumerable<string> AvailableCpus public IEnumerable<string> AvailableCpus
{ {

View File

@ -1,5 +1,4 @@
using BizHawk.Common.NumberExtensions; using BizHawk.Common.NumberExtensions;
using System;
namespace BizHawk.Emulation.Cores.Components.Z80A namespace BizHawk.Emulation.Cores.Components.Z80A
{ {

View File

@ -1,6 +1,3 @@
using System.Runtime.InteropServices;
using System;
namespace BizHawk.Emulation.Cores.Components.Z80A namespace BizHawk.Emulation.Cores.Components.Z80A
{ {
public partial class Z80A public partial class Z80A

View File

@ -1,5 +1,3 @@
using System;
namespace BizHawk.Emulation.Cores.Components.Z80A namespace BizHawk.Emulation.Cores.Components.Z80A
{ {
public partial class Z80A public partial class Z80A

View File

@ -1,8 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.IO;
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
using BizHawk.Common.NumberExtensions; using BizHawk.Common.NumberExtensions;
@ -306,8 +303,8 @@ namespace BizHawk.Emulation.Cores.Components.Z80A
break; break;
case OP_F: case OP_F:
// Read the opcode of the next instruction // Read the opcode of the next instruction
if (OnExecFetch != null) OnExecFetch(RegPC); OnExecFetch?.Invoke(RegPC);
if (TraceCallback != null) TraceCallback(State()); TraceCallback?.Invoke(State());
opcode = FetchMemory(RegPC++); opcode = FetchMemory(RegPC++);
FetchInstruction(); FetchInstruction();
@ -778,10 +775,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A
{ {
nonMaskableInterruptPending = false; nonMaskableInterruptPending = false;
if (TraceCallback != null) TraceCallback?.Invoke(new TraceInfo { Disassembly = "====NMI====", RegisterInfo = "" });
{
TraceCallback(new TraceInfo { Disassembly = "====NMI====", RegisterInfo = "" });
}
iff2 = iff1; iff2 = iff1;
iff1 = false; iff1 = false;
@ -802,10 +796,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A
iff1 = iff2 = false; iff1 = iff2 = false;
EI_pending = 0; EI_pending = 0;
if (TraceCallback != null) TraceCallback?.Invoke(new TraceInfo { Disassembly = "====IRQ====", RegisterInfo = "" });
{
TraceCallback(new TraceInfo { Disassembly = "====IRQ====", RegisterInfo = "" });
}
switch (interruptMode) switch (interruptMode)
{ {
@ -858,10 +849,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A
// tracer stuff // tracer stuff
public Action<TraceInfo> TraceCallback; public Action<TraceInfo> TraceCallback;
public string TraceHeader public string TraceHeader => "Z80A: PC, machine code, mnemonic, operands, registers (AF, BC, DE, HL, IX, IY, SP, Cy), flags (CNP3H5ZS)";
{
get { return "Z80A: PC, machine code, mnemonic, operands, registers (AF, BC, DE, HL, IX, IY, SP, Cy), flags (CNP3H5ZS)"; }
}
public TraceInfo State(bool disassemble = true) public TraceInfo State(bool disassemble = true)
{ {
@ -906,7 +894,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A
/// <summary> /// <summary>
/// Optimization method to set BUSRQ /// Optimization method to set BUSRQ
/// </summary> /// </summary>
private void PopulateBUSRQ(ushort d0 = 0, ushort d1 = 0, ushort d2 = 0, ushort d3 = 0, ushort d4 = 0, ushort d5 = 0, ushort d6 = 0, ushort d7 = 0, ushort d8 = 0, private void PopulateBUSRQ(ushort d0 = 0, ushort d1 = 0, ushort d2 = 0, ushort d3 = 0, ushort d4 = 0, ushort d5 = 0, ushort d6 = 0, ushort d7 = 0, ushort d8 = 0,
ushort d9 = 0, ushort d10 = 0, ushort d11 = 0, ushort d12 = 0, ushort d13 = 0, ushort d14 = 0, ushort d15 = 0, ushort d16 = 0, ushort d17 = 0, ushort d18 = 0) ushort d9 = 0, ushort d10 = 0, ushort d11 = 0, ushort d12 = 0, ushort d13 = 0, ushort d14 = 0, ushort d15 = 0, ushort d16 = 0, ushort d17 = 0, ushort d18 = 0)
{ {
@ -921,7 +909,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A
/// <summary> /// <summary>
/// Optimization method to set MEMRQ /// Optimization method to set MEMRQ
/// </summary> /// </summary>
private void PopulateMEMRQ(ushort d0 = 0, ushort d1 = 0, ushort d2 = 0, ushort d3 = 0, ushort d4 = 0, ushort d5 = 0, ushort d6 = 0, ushort d7 = 0, ushort d8 = 0, private void PopulateMEMRQ(ushort d0 = 0, ushort d1 = 0, ushort d2 = 0, ushort d3 = 0, ushort d4 = 0, ushort d5 = 0, ushort d6 = 0, ushort d7 = 0, ushort d8 = 0,
ushort d9 = 0, ushort d10 = 0, ushort d11 = 0, ushort d12 = 0, ushort d13 = 0, ushort d14 = 0, ushort d15 = 0, ushort d16 = 0, ushort d17 = 0, ushort d18 = 0) ushort d9 = 0, ushort d10 = 0, ushort d11 = 0, ushort d12 = 0, ushort d13 = 0, ushort d14 = 0, ushort d15 = 0, ushort d16 = 0, ushort d17 = 0, ushort d18 = 0)
{ {

View File

@ -16,14 +16,16 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{ {
get get
{ {
ControllerDefinition definition = new ControllerDefinition(); var definition = new ControllerDefinition
definition.Name = "AmstradCPC Controller"; {
Name = "AmstradCPC Controller"
};
// joysticks // joysticks
List<string> joys1 = new List<string> var joys1 = new List<string>
{ {
// P1 Joystick // P1 Joystick
"P1 Up", "P1 Down", "P1 Left", "P1 Right", "P1 Fire1", "P1 Fire2", "P1 Fire3" "P1 Up", "P1 Down", "P1 Left", "P1 Right", "P1 Fire1", "P1 Fire2", "P1 Fire3"
}; };
foreach (var s in joys1) foreach (var s in joys1)
@ -32,10 +34,10 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
definition.CategoryLabels[s] = "J1"; definition.CategoryLabels[s] = "J1";
} }
List<string> joys2 = new List<string> var joys2 = new List<string>
{ {
// P2 Joystick // P2 Joystick
"P2 Up", "P2 Down", "P2 Left", "P2 Right", "P2 Fire", "P2 Up", "P2 Down", "P2 Left", "P2 Right", "P2 Fire",
}; };
foreach (var s in joys2) foreach (var s in joys2)
@ -45,25 +47,25 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
} }
// keyboard // keyboard
List<string> keys = new List<string> var keys = new List<string>
{ {
// http://www.cpcwiki.eu/index.php/Programming:Keyboard_scanning // http://www.cpcwiki.eu/index.php/Programming:Keyboard_scanning
// http://www.cpcwiki.eu/index.php/File:Grimware_cpc464_version3_case_top.jpg // http://www.cpcwiki.eu/index.php/File:Grimware_cpc464_version3_case_top.jpg
// Keyboard - row 1 // Keyboard - row 1
"Key ESC", "Key 1", "Key 2", "Key 3", "Key 4", "Key 5", "Key 6", "Key 7", "Key 8", "Key 9", "Key 0", "Key Dash", "Key Hat", "Key CLR", "Key DEL", "Key ESC", "Key 1", "Key 2", "Key 3", "Key 4", "Key 5", "Key 6", "Key 7", "Key 8", "Key 9", "Key 0", "Key Dash", "Key Hat", "Key CLR", "Key DEL",
// Keyboard - row 2 // Keyboard - row 2
"Key TAB", "Key Q", "Key W", "Key E", "Key R", "Key T", "Key Y", "Key U", "Key I", "Key O", "Key P", "Key @", "Key LeftBracket", "Key RETURN", "Key TAB", "Key Q", "Key W", "Key E", "Key R", "Key T", "Key Y", "Key U", "Key I", "Key O", "Key P", "Key @", "Key LeftBracket", "Key RETURN",
// Keyboard - row 3 // Keyboard - row 3
"Key CAPSLOCK", "Key A", "Key S", "Key D", "Key F", "Key G", "Key H", "Key J", "Key K", "Key L", "Key Colon", "Key SemiColon", "Key RightBracket", "Key CAPSLOCK", "Key A", "Key S", "Key D", "Key F", "Key G", "Key H", "Key J", "Key K", "Key L", "Key Colon", "Key SemiColon", "Key RightBracket",
// Keyboard - row 4 // Keyboard - row 4
"Key SHIFT", "Key Z", "Key X", "Key C", "Key V", "Key B", "Key N", "Key M", "Key Comma", "Key Period", "Key ForwardSlash", "Key BackSlash", "Key SHIFT", "Key Z", "Key X", "Key C", "Key V", "Key B", "Key N", "Key M", "Key Comma", "Key Period", "Key ForwardSlash", "Key BackSlash",
// Keyboard - row 5 // Keyboard - row 5
"Key SPACE", "Key CONTROL", "Key SPACE", "Key CONTROL",
// Keyboard - Cursor // Keyboard - Cursor
"Key CURUP", "Key CURDOWN", "Key CURLEFT", "Key CURRIGHT", "Key COPY", "Key CURUP", "Key CURDOWN", "Key CURLEFT", "Key CURRIGHT", "Key COPY",
// Keyboard - Numpad // Keyboard - Numpad
"Key NUM0", "Key NUM1", "Key NUM2", "Key NUM3", "Key NUM4", "Key NUM5", "Key NUM6", "Key NUM7", "Key NUM8", "Key NUM9", "Key NUMPERIOD", "KEY ENTER" "Key NUM0", "Key NUM1", "Key NUM2", "Key NUM3", "Key NUM4", "Key NUM5", "Key NUM6", "Key NUM7", "Key NUM8", "Key NUM9", "Key NUMPERIOD", "KEY ENTER"
}; };
foreach (var s in keys) foreach (var s in keys)
@ -73,10 +75,10 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
} }
// Power functions // Power functions
List<string> power = new List<string> var power = new List<string>
{ {
// Power functions // Power functions
"Reset", "Power" "Reset", "Power"
}; };
foreach (var s in power) foreach (var s in power)
@ -86,10 +88,10 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
} }
// Datacorder (tape device) // Datacorder (tape device)
List<string> tape = new List<string> var tape = new List<string>
{ {
// Tape functions // Tape functions
"Play Tape", "Stop Tape", "RTZ Tape", "Record Tape", "Insert Next Tape", "Play Tape", "Stop Tape", "RTZ Tape", "Record Tape", "Insert Next Tape",
"Insert Previous Tape", "Next Tape Block", "Prev Tape Block", "Get Tape Status" "Insert Previous Tape", "Next Tape Block", "Prev Tape Block", "Get Tape Status"
}; };
@ -100,10 +102,10 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
} }
// Datacorder (tape device) // Datacorder (tape device)
List<string> disk = new List<string> var disk = new List<string>
{ {
// Tape functions // Tape functions
"Insert Next Disk", "Insert Previous Disk", /*"Eject Current Disk",*/ "Get Disk Status" "Insert Next Disk", "Insert Previous Disk", /*"Eject Current Disk",*/ "Get Disk Status"
}; };
foreach (var s in disk) foreach (var s in disk)

View File

@ -46,24 +46,11 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
return true; return true;
} }
public int Frame public int Frame => _machine?.FrameCount ?? 0;
{
get
{
if (_machine == null)
return 0;
else
return _machine.FrameCount;
}
}
public string SystemId => "AmstradCPC"; public string SystemId => "AmstradCPC";
private bool deterministicEmulation; public bool DeterministicEmulation { get; }
public bool DeterministicEmulation
{
get { return deterministicEmulation; }
}
public void ResetCounters() public void ResetCounters()
{ {

View File

@ -39,9 +39,9 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
if (tmpM != _machineType && _machineType.ToString() != "72") if (tmpM != _machineType && _machineType.ToString() != "72")
{ {
string msg = "SAVESTATE FAILED TO LOAD!!\n\n"; string msg = "SAVESTATE FAILED TO LOAD!!\n\n";
msg += "Current Configuration: " + tmpM.ToString(); msg += "Current Configuration: " + tmpM;
msg += "\n"; msg += "\n";
msg += "Saved Configuration: " + _machineType.ToString(); msg += "Saved Configuration: " + _machineType;
msg += "\n\n"; msg += "\n\n";
msg += "If you wish to load this SaveState ensure that you have the correct machine configuration selected, reboot the core, then try again."; msg += "If you wish to load this SaveState ensure that you have the correct machine configuration selected, reboot the core, then try again.";
CoreComm.ShowMessage(msg); CoreComm.ShowMessage(msg);

View File

@ -1,5 +1,4 @@
using System; using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Computers.AmstradCPC namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{ {

View File

@ -1,5 +1,4 @@
using System; using System.Linq;
using System.Linq;
using System.Text; using System.Text;
namespace BizHawk.Emulation.Cores.Computers.AmstradCPC namespace BizHawk.Emulation.Cores.Computers.AmstradCPC

View File

@ -39,18 +39,18 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
PutSyncSettings((AmstradCPCSyncSettings)syncSettings ?? new AmstradCPCSyncSettings()); PutSyncSettings((AmstradCPCSyncSettings)syncSettings ?? new AmstradCPCSyncSettings());
PutSettings((AmstradCPCSettings)settings ?? new AmstradCPCSettings()); PutSettings((AmstradCPCSettings)settings ?? new AmstradCPCSettings());
deterministicEmulation = ((AmstradCPCSyncSettings)syncSettings as AmstradCPCSyncSettings).DeterministicEmulation; DeterministicEmulation = ((AmstradCPCSyncSettings)syncSettings).DeterministicEmulation;
switch (SyncSettings.MachineType) switch (SyncSettings.MachineType)
{ {
case MachineType.CPC464: case MachineType.CPC464:
ControllerDefinition = AmstradCPCControllerDefinition; ControllerDefinition = AmstradCPCControllerDefinition;
Init(MachineType.CPC464, _files, ((AmstradCPCSyncSettings)syncSettings as AmstradCPCSyncSettings).AutoStartStopTape, Init(MachineType.CPC464, _files, ((AmstradCPCSyncSettings)syncSettings).AutoStartStopTape,
((AmstradCPCSyncSettings)syncSettings as AmstradCPCSyncSettings).BorderType); ((AmstradCPCSyncSettings)syncSettings).BorderType);
break; break;
case MachineType.CPC6128: case MachineType.CPC6128:
ControllerDefinition = AmstradCPCControllerDefinition; ControllerDefinition = AmstradCPCControllerDefinition;
Init(MachineType.CPC6128, _files, ((AmstradCPCSyncSettings)syncSettings as AmstradCPCSyncSettings).AutoStartStopTape, ((AmstradCPCSyncSettings)syncSettings as AmstradCPCSyncSettings).BorderType); Init(MachineType.CPC6128, _files, ((AmstradCPCSyncSettings)syncSettings).AutoStartStopTape, ((AmstradCPCSyncSettings)syncSettings).BorderType);
break; break;
default: default:
throw new InvalidOperationException("Machine not yet emulated"); throw new InvalidOperationException("Machine not yet emulated");
@ -194,13 +194,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
#region IDriveLight #region IDriveLight
public bool DriveLightEnabled public bool DriveLightEnabled => true;
{
get
{
return true;
}
}
public bool DriveLightOn public bool DriveLightOn
{ {

View File

@ -8,7 +8,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
public interface IBeeperDevice public interface IBeeperDevice
{ {
/// <summary> /// <summary>
/// Initialisation /// Initialization
/// </summary> /// </summary>
void Init(int sampleRate, int tStatesPerFrame); void Init(int sampleRate, int tStatesPerFrame);

View File

@ -7,7 +7,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
public interface IFDDHost public interface IFDDHost
{ {
/// <summary> /// <summary>
/// The currently inserted diskimage /// The currently inserted disk image
/// </summary> /// </summary>
FloppyDisk Disk { get; set; } FloppyDisk Disk { get; set; }
@ -23,7 +23,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
/// <summary> /// <summary>
/// Signs whether the current active drive has a disk inserted /// Signs whether the current active drive has a disk inserted
/// </summary> /// </summary>
bool FDD_IsDiskLoaded { get; } bool FDD_IsDiskLoaded { get; }
} }
} }

View File

@ -9,7 +9,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
public interface IPSG : ISoundProvider public interface IPSG : ISoundProvider
{ {
/// <summary> /// <summary>
/// Initlization routine /// Initialization routine
/// </summary> /// </summary>
void Init(int sampleRate, int tStatesPerFrame); void Init(int sampleRate, int tStatesPerFrame);

View File

@ -87,8 +87,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{ {
get get
{ {
if (_dataBlocks.Count() > 0) { return _currentDataBlockIndex; } if (_dataBlocks.Any())
else { return -1; } {
return _currentDataBlockIndex;
}
return -1;
} }
set set
{ {
@ -105,23 +109,13 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
/// The current position within the current data block /// The current position within the current data block
/// </summary> /// </summary>
private int _position = 0; private int _position = 0;
public int Position public int Position => _position >= _dataBlocks[_currentDataBlockIndex].DataPeriods.Count ? 0 : _position;
{
get
{
if (_position >= _dataBlocks[_currentDataBlockIndex].DataPeriods.Count) { return 0; }
else { return _position; }
}
}
/// <summary> /// <summary>
/// Signs whether the tape is currently playing or not /// Signs whether the tape is currently playing or not
/// </summary> /// </summary>
private bool _tapeIsPlaying = false; private bool _tapeIsPlaying = false;
public bool TapeIsPlaying public bool TapeIsPlaying => _tapeIsPlaying;
{
get { return _tapeIsPlaying; }
}
/// <summary> /// <summary>
/// A list of the currently loaded data blocks /// A list of the currently loaded data blocks
@ -811,7 +805,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
#region State Serialization #region State Serialization
/// <summary> /// <summary>
/// Bizhawk state serialization /// BizHawk state serialization
/// </summary> /// </summary>
public void SyncState(Serializer ser) public void SyncState(Serializer ser)
{ {

View File

@ -372,22 +372,13 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
switch (ActiveCommandParams.SectorSize) switch (ActiveCommandParams.SectorSize)
{ {
case 1: case 1:
if (CMD_FLAG_MF) maxTransferCap = CMD_FLAG_MF ? 6656 : 3840;
maxTransferCap = 6656;
else
maxTransferCap = 3840;
break; break;
case 2: case 2:
if (CMD_FLAG_MF) maxTransferCap = CMD_FLAG_MF ? 7680 : 4096;
maxTransferCap = 7680;
else
maxTransferCap = 4096;
break; break;
case 3: case 3:
if (CMD_FLAG_MF) maxTransferCap = CMD_FLAG_MF ? 8192 : 4096;
maxTransferCap = 8192;
else
maxTransferCap = 4096;
break; break;
} }
@ -397,7 +388,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
var mtc = maxTransferCap; var mtc = maxTransferCap;
// get the current track // get the current track
var track = ActiveDrive.Disk.DiskTracks.Where(a => a.TrackNumber == ActiveDrive.CurrentTrackID).FirstOrDefault(); var track = ActiveDrive.Disk.DiskTracks.FirstOrDefault(a => a.TrackNumber == ActiveDrive.CurrentTrackID);
if (track == null || track.NumberOfSectors <= 0) if (track == null || track.NumberOfSectors <= 0)
{ {
@ -704,7 +695,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
} }
// get the current track // get the current track
var track = ActiveDrive.Disk.DiskTracks.Where(a => a.TrackNumber == ActiveDrive.CurrentTrackID).FirstOrDefault(); var track = ActiveDrive.Disk.DiskTracks.FirstOrDefault(a => a.TrackNumber == ActiveDrive.CurrentTrackID);
if (track == null || track.NumberOfSectors <= 0) if (track == null || track.NumberOfSectors <= 0)
{ {
@ -754,7 +745,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
Status1 = sector.Status1; Status1 = sector.Status1;
Status2 = sector.Status2; Status2 = sector.Status2;
// we dont need EN // we don't need EN
UnSetBit(SR1_EN, ref Status1); UnSetBit(SR1_EN, ref Status1);
// invert CM for read deleted data command // invert CM for read deleted data command
@ -994,22 +985,13 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
switch (ActiveCommandParams.SectorSize) switch (ActiveCommandParams.SectorSize)
{ {
case 1: case 1:
if (CMD_FLAG_MF) maxTransferCap = CMD_FLAG_MF ? 6656 : 3840;
maxTransferCap = 6656;
else
maxTransferCap = 3840;
break; break;
case 2: case 2:
if (CMD_FLAG_MF) maxTransferCap = CMD_FLAG_MF ? 7680 : 4096;
maxTransferCap = 7680;
else
maxTransferCap = 4096;
break; break;
case 3: case 3:
if (CMD_FLAG_MF) maxTransferCap = CMD_FLAG_MF ? 8192 : 4096;
maxTransferCap = 8192;
else
maxTransferCap = 4096;
break; break;
} }
@ -1017,7 +999,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
} }
// get the current track // get the current track
var track = ActiveDrive.Disk.DiskTracks.Where(a => a.TrackNumber == ActiveDrive.CurrentTrackID).FirstOrDefault(); var track = ActiveDrive.Disk.DiskTracks.FirstOrDefault(a => a.TrackNumber == ActiveDrive.CurrentTrackID);
if (track == null || track.NumberOfSectors <= 0) if (track == null || track.NumberOfSectors <= 0)
{ {
@ -1209,7 +1191,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
break; break;
} }
var track = ActiveDrive.Disk.DiskTracks.Where(a => a.TrackNumber == ActiveDrive.CurrentTrackID).FirstOrDefault(); var track = ActiveDrive.Disk.DiskTracks.FirstOrDefault(a => a.TrackNumber == ActiveDrive.CurrentTrackID);
if (track != null && track.NumberOfSectors > 0 && track.TrackNumber != 0xff) if (track != null && track.NumberOfSectors > 0 && track.TrackNumber != 0xff)
{ {
@ -2539,7 +2521,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
cmdByte = cByte; cmdByte = cByte;
// lookup the command // lookup the command
var cmd = CommandList.Where(a => a.CommandCode == cmdByte).FirstOrDefault(); var cmd = CommandList.FirstOrDefault(a => a.CommandCode == cmdByte);
if (cmd == null) if (cmd == null)
{ {

View File

@ -171,18 +171,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
/// <summary> /// <summary>
/// Signs whether the current active drive has a disk inserted /// Signs whether the current active drive has a disk inserted
/// </summary> /// </summary>
public bool FDD_IsDiskLoaded public bool FDD_IsDiskLoaded => DriveStates[DiskDriveIndex].FDD_IsDiskLoaded;
{
get { return DriveStates[DiskDriveIndex].FDD_IsDiskLoaded; }
}
/// <summary> /// <summary>
/// Returns the disk object from drive 0 /// Returns the disk object from drive 0
/// </summary> /// </summary>
public FloppyDisk DiskPointer public FloppyDisk DiskPointer => DriveStates[0].Disk;
{
get { return DriveStates[0].Disk; }
}
public FloppyDisk Disk { get; set; } public FloppyDisk Disk { get; set; }

View File

@ -6,8 +6,6 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BizHawk.Emulation.Cores.Computers.AmstradCPC namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{ {
@ -986,10 +984,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
private int _bufferWidth; private int _bufferWidth;
private int _bufferHeight; private int _bufferHeight;
public int BackgroundColor public int BackgroundColor => CPCHardwarePalette[0];
{
get { return CPCHardwarePalette[0]; }
}
public int VirtualWidth public int VirtualWidth
{ {
@ -1024,10 +1019,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
set { } set { }
} }
public int VsyncDenominator public int VsyncDenominator => Z80ClockSpeed;
{
get { return Z80ClockSpeed; }
}
public int[] GetVideoBuffer() public int[] GetVideoBuffer()
{ {
@ -1313,10 +1305,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
Phases.Add(phase); Phases.Add(phase);
} }
public int PhaseCount public int PhaseCount => Phases.Count();
{
get { return Phases.Count(); }
}
public void Clear(int screenMode) public void Clear(int screenMode)
{ {

View File

@ -1,7 +1,5 @@
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Common.NumberExtensions; using BizHawk.Common.NumberExtensions;
using System;
using System.Collections;
namespace BizHawk.Emulation.Cores.Computers.AmstradCPC namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{ {
@ -98,123 +96,57 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
/// <summary> /// <summary>
/// The total frame width (in characters) /// The total frame width (in characters)
/// </summary> /// </summary>
public int FrameWidth public int FrameWidth => (int)Regs[HOR_TOTAL] + 1;
{
get
{
return (int)Regs[HOR_TOTAL] + 1;
}
}
/// <summary> /// <summary>
/// The total frame height (in scanlines) /// The total frame height (in scanlines)
/// </summary> /// </summary>
public int FrameHeight public int FrameHeight => ((int)Regs[VER_TOTAL] + 1) * ((int)Regs[MAX_RASTER_ADDR] + 1);
{
get
{
return ((int)Regs[VER_TOTAL] + 1) * ((int)Regs[MAX_RASTER_ADDR] + 1);
}
}
/// <summary> /// <summary>
/// The total frame height (in scanlines) /// The total frame height (in scanlines)
/// </summary> /// </summary>
public int FrameHeightInChars public int FrameHeightInChars => ((int)Regs[VER_TOTAL] + 1);
{
get
{
return ((int)Regs[VER_TOTAL] + 1);
}
}
/// <summary> /// <summary>
/// The width of the display area (in characters) /// The width of the display area (in characters)
/// </summary> /// </summary>
public int DisplayWidth public int DisplayWidth => (int)Regs[HOR_DISPLAYED];
{
get
{
return (int)Regs[HOR_DISPLAYED];
}
}
/// <summary> /// <summary>
/// The width of the display area (in scanlines) /// The width of the display area (in scanlines)
/// </summary> /// </summary>
public int DisplayHeight public int DisplayHeight => (int)Regs[VER_DISPLAYED] * ((int)Regs[MAX_RASTER_ADDR] + 1);
{
get
{
return (int)Regs[VER_DISPLAYED] * ((int)Regs[MAX_RASTER_ADDR] + 1);
}
}
/// <summary> /// <summary>
/// The width of the display area (in scanlines) /// The width of the display area (in scanlines)
/// </summary> /// </summary>
public int DisplayHeightInChars public int DisplayHeightInChars => (int)Regs[VER_DISPLAYED];
{
get
{
return (int)Regs[VER_DISPLAYED];
}
}
/// <summary> /// <summary>
/// The character at which to start HSYNC /// The character at which to start HSYNC
/// </summary> /// </summary>
public int HorizontalSyncPos public int HorizontalSyncPos => (int)Regs[HOR_SYNC_POS];
{
get
{
return (int)Regs[HOR_SYNC_POS];
}
}
/// <summary> /// <summary>
/// Width (in characters) of the HSYNC /// Width (in characters) of the HSYNC
/// </summary> /// </summary>
public int HorizontalSyncWidth public int HorizontalSyncWidth => HSYNCWidth;
{
get
{
return HSYNCWidth;
}
}
/// <summary> /// <summary>
/// The vertical scanline at which to start VSYNC /// The vertical scanline at which to start VSYNC
/// </summary> /// </summary>
public int VerticalSyncPos public int VerticalSyncPos => (int)Regs[VER_SYNC_POS] * ((int)Regs[MAX_RASTER_ADDR] + 1);
{
get
{
return (int)Regs[VER_SYNC_POS] * ((int)Regs[MAX_RASTER_ADDR] + 1);
}
}
/// <summary> /// <summary>
/// Height (in scanlines) of the VSYNC /// Height (in scanlines) of the VSYNC
/// </summary> /// </summary>
public int VerticalSyncHeight public int VerticalSyncHeight => VSYNCWidth; // * ((int)Regs[MAX_RASTER_ADDR] + 1);
{
get
{
return VSYNCWidth; // * ((int)Regs[MAX_RASTER_ADDR] + 1);
}
}
/// <summary> /// <summary>
/// The number of scanlines in one character (MAXRASTER) /// The number of scanlines in one character (MAXRASTER)
/// </summary> /// </summary>
public int ScanlinesPerCharacter public int ScanlinesPerCharacter => (int)Regs[MAX_RASTER_ADDR] + 1;
{
get
{
return (int)Regs[MAX_RASTER_ADDR] + 1;
}
}
/// <summary> /// <summary>
/// Returns the starting video page address as specified within R12 /// Returns the starting video page address as specified within R12
@ -236,11 +168,9 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
} }
} }
public int DStartHigh public int DStartHigh => Regs[DISP_START_ADDR_H];
{ get { return Regs[DISP_START_ADDR_H]; } }
public int DStartLow public int DStartLow => Regs[DISP_START_ADDR_L];
{ get { return Regs[DISP_START_ADDR_L]; } }
/// <summary> /// <summary>
/// Returns the video buffer size as specified within R12 /// Returns the video buffer size as specified within R12
@ -456,14 +386,14 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
/// http://www.cantrell.org.uk/david/tech/cpc/cpc-firmware/firmware.pdf /// http://www.cantrell.org.uk/david/tech/cpc/cpc-firmware/firmware.pdf
/// (The defaults values given here are those programmed by the firmware ROM after a cold/warm boot of the CPC/Plus) /// (The defaults values given here are those programmed by the firmware ROM after a cold/warm boot of the CPC/Plus)
/// </summary> /// </summary>
private byte[] RegDefaults = new byte[] { 63, 40, 46, 112, 38, 0, 25, 30, 0, 7, 0, 0, 48, 0, 192, 7, 0, 0 }; private byte[] RegDefaults = { 63, 40, 46, 112, 38, 0, 25, 30, 0, 7, 0, 0, 48, 0, 192, 7, 0, 0 };
/// <summary> /// <summary>
/// Register masks /// Register masks
/// 0 = WRITE /// 0 = WRITE
/// 1 = READ /// 1 = READ
/// </summary> /// </summary>
private byte[] CPCMask = new byte[] { 255, 255, 255, 255, 127, 31, 127, 126, 3, 31, 31, 31, 63, 255, 63, 255, 63, 255 }; private byte[] CPCMask = { 255, 255, 255, 255, 127, 31, 127, 126, 3, 31, 31, 31, 63, 255, 63, 255, 63, 255 };
/// <summary> /// <summary>
/// Horizontal Character Count /// Horizontal Character Count

View File

@ -1,7 +1,6 @@
using BizHawk.Common; using System.Collections;
using BizHawk.Common;
using BizHawk.Common.NumberExtensions; using BizHawk.Common.NumberExtensions;
using System;
using System.Collections;
namespace BizHawk.Emulation.Cores.Computers.AmstradCPC namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{ {
@ -62,7 +61,8 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
/// An external dot counter is used to derive this signal which is usually the character rate in an alphanumeric CRT. /// An external dot counter is used to derive this signal which is usually the character rate in an alphanumeric CRT.
/// The active transition is high-to-low /// The active transition is high-to-low
/// </summary> /// </summary>
public bool CLK { get { return _CLK; } } public bool CLK => _CLK;
private bool _CLK; private bool _CLK;
/// <summary> /// <summary>
/// The RES input is used to Reset the CRTC. An input low level on RES forces CRTC into following status: /// The RES input is used to Reset the CRTC. An input low level on RES forces CRTC into following status:
@ -74,13 +74,15 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
/// (At least 1 cycle CLK signal is necessary for reset.) /// (At least 1 cycle CLK signal is necessary for reset.)
/// (C) The CRTC starts the Display operation immediately after the release of RES signal. /// (C) The CRTC starts the Display operation immediately after the release of RES signal.
/// </summary> /// </summary>
public bool RESET { get { return _RESET; } } public bool RESET => _RESET;
private bool _RESET; private bool _RESET;
/// <summary> /// <summary>
/// Light Pen Strobe (LPSTR) - This high impedance TTLIMOS compatible input latches the cu rrent Refresh Addresses in the Register File. /// Light Pen Strobe (LPSTR) - This high impedance TTLIMOS compatible input latches the cu rrent Refresh Addresses in the Register File.
/// Latching is on the low to high edge and is synchronized internally to character clock. /// Latching is on the low to high edge and is synchronized internally to character clock.
/// </summary> /// </summary>
public bool LPSTB { get { return _LPSTB; } } public bool LPSTB => _LPSTB;
private bool _LPSTB; private bool _LPSTB;
#endregion #endregion
@ -92,23 +94,27 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
/// This TTL compatible output is an active high signal which drives the monitor directly or is fed to Video Processing Logic for composite generation. /// This TTL compatible output is an active high signal which drives the monitor directly or is fed to Video Processing Logic for composite generation.
/// This signal determines the vertical position of the displayed text. /// This signal determines the vertical position of the displayed text.
/// </summary> /// </summary>
public bool VSYNC { get { return _VSYNC; } } public bool VSYNC => _VSYNC;
private bool _VSYNC; private bool _VSYNC;
/// <summary> /// <summary>
/// This TTL compatible output is an active high signal which drives the monitor directly or is fed to Video Processing Logic for composite generation. /// This TTL compatible output is an active high signal which drives the monitor directly or is fed to Video Processing Logic for composite generation.
/// This signal determines the horizontal position of the displayed text. /// This signal determines the horizontal position of the displayed text.
/// </summary> /// </summary>
public bool HSYNC { get { return _HSYNC; } } public bool HSYNC => _HSYNC;
private bool _HSYNC; private bool _HSYNC;
/// <summary> /// <summary>
/// This TTL compatible output is an active high signal which indicates the CRTC is providing addressing in the active Display Area. /// This TTL compatible output is an active high signal which indicates the CRTC is providing addressing in the active Display Area.
/// </summary> /// </summary>
public bool DISPTMG { get { return _DISPTMG; } } public bool DISPTMG => _DISPTMG;
private bool _DISPTMG; private bool _DISPTMG;
/// <summary> /// <summary>
/// This TTL compatible output indicates Cursor Display to external Video Processing Logic.Active high signal. /// This TTL compatible output indicates Cursor Display to external Video Processing Logic.Active high signal.
/// </summary> /// </summary>
public bool CUDISP { get { return _CUDISP; } } public bool CUDISP => _CUDISP;
private bool _CUDISP; private bool _CUDISP;
// Refresh memory addresses // Refresh memory addresses
@ -117,31 +123,31 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
data located within a 16K block of refresh memory. These outputs drive a TTL load and 30pF. A high level on data located within a 16K block of refresh memory. These outputs drive a TTL load and 30pF. A high level on
MAO-MA 13 is a logical "1." MAO-MA 13 is a logical "1."
*/ */
public bool MA0 { get { return LinearAddress.Bit(0); } } public bool MA0 => LinearAddress.Bit(0);
public bool MA1 { get { return LinearAddress.Bit(1); } } public bool MA1 => LinearAddress.Bit(1);
public bool MA2 { get { return LinearAddress.Bit(2); } } public bool MA2 => LinearAddress.Bit(2);
public bool MA3 { get { return LinearAddress.Bit(3); } } public bool MA3 => LinearAddress.Bit(3);
public bool MA4 { get { return LinearAddress.Bit(4); } } public bool MA4 => LinearAddress.Bit(4);
public bool MA5 { get { return LinearAddress.Bit(5); } } public bool MA5 => LinearAddress.Bit(5);
public bool MA6 { get { return LinearAddress.Bit(6); } } public bool MA6 => LinearAddress.Bit(6);
public bool MA7 { get { return LinearAddress.Bit(7); } } public bool MA7 => LinearAddress.Bit(7);
public bool MA8 { get { return LinearAddress.Bit(8); } } public bool MA8 => LinearAddress.Bit(8);
public bool MA9 { get { return LinearAddress.Bit(9); } } public bool MA9 => LinearAddress.Bit(9);
public bool MA10 { get { return LinearAddress.Bit(10); } } // cpcwiki would suggest that this isnt connected in the CPC range public bool MA10 => LinearAddress.Bit(10); // cpcwiki would suggest that this isnt connected in the CPC range
public bool MA11 { get { return LinearAddress.Bit(11); } } // cpcwiki would suggest that this isnt connected in the CPC range public bool MA11 => LinearAddress.Bit(11); // cpcwiki would suggest that this isnt connected in the CPC range
public bool MA12 { get { return LinearAddress.Bit(12); } } // cpcwiki would suggest that this is connected in the CPC range but not used public bool MA12 => LinearAddress.Bit(12); // cpcwiki would suggest that this is connected in the CPC range but not used
public bool MA13 { get { return LinearAddress.Bit(13); } } // cpcwiki would suggest that this is connected in the CPC range but not used public bool MA13 => LinearAddress.Bit(13); // cpcwiki would suggest that this is connected in the CPC range but not used
// Row addresses for character generators // Row addresses for character generators
/* /*
Raster Addresses (RAO-RA4) - These 5 outputs from the internal Raster Counter address the Character ROM Raster Addresses (RAO-RA4) - These 5 outputs from the internal Raster Counter address the Character ROM
for the row of a character. These outputs drive a TTL load and 30pF. A high level (on RAO-RA4) is a logical "1." for the row of a character. These outputs drive a TTL load and 30pF. A high level (on RAO-RA4) is a logical "1."
*/ */
public bool RA0 { get { return RowSelects.Bit(0); } } public bool RA0 => RowSelects.Bit(0);
public bool RA1 { get { return RowSelects.Bit(1); } } public bool RA1 => RowSelects.Bit(1);
public bool RA2 { get { return RowSelects.Bit(2); } } public bool RA2 => RowSelects.Bit(2);
public bool RA3 { get { return RowSelects.Bit(3); } } // cpcwiki would suggest that this isnt connected in the CPC range public bool RA3 => RowSelects.Bit(3); // cpcwiki would suggest that this isnt connected in the CPC range
public bool RA4 { get { return RowSelects.Bit(4); } } // cpcwiki would suggest that this isnt connected in the CPC range public bool RA4 => RowSelects.Bit(4); // cpcwiki would suggest that this isnt connected in the CPC range
/// <summary> /// <summary>
/// This 16-bit property emulates how the Amstrad CPC Gate Array is connected up to the CRTC /// This 16-bit property emulates how the Amstrad CPC Gate Array is connected up to the CRTC
@ -682,15 +688,9 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
/// <summary> /// <summary>
/// Current programmed HSYNC width for Type 0 (HD6845S & UM6845) & Type 1 (UM6845R) /// Current programmed HSYNC width for Type 0 (HD6845S & UM6845) & Type 1 (UM6845R)
/// </summary> /// </summary>
private int HSYNCWidth_Type0_1 // Bits 3..0 define Horizontal Sync Width.
{ // If 0 is programmed no HSYNC is generated.
get private int HSYNCWidth_Type0_1 => (Register[SYNC_WIDTHS] >> 0) & 0x0F;
{
// Bits 3..0 define Horizontal Sync Width.
// If 0 is programmed no HSYNC is generated.
return (Register[SYNC_WIDTHS] >> 0) & 0x0F;
}
}
/// <summary> /// <summary>
/// Current programmed HSYNC width for Type 2 (MC6845), 3 (AMS40489) & 4 (pre-ASIC) /// Current programmed HSYNC width for Type 2 (MC6845), 3 (AMS40489) & 4 (pre-ASIC)
@ -727,15 +727,9 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
/// <summary> /// <summary>
/// Current programmed VSYNC width for Type 1 (UM6845R) & 2 (MC6845) /// Current programmed VSYNC width for Type 1 (UM6845R) & 2 (MC6845)
/// </summary> /// </summary>
private int VSYNCWidth_Type1_2 // Bits 7..4 are ignored.
{ // Vertical Sync is fixed at 16 lines.
get private int VSYNCWidth_Type1_2 => 16;
{
// Bits 7..4 are ignored.
// Vertical Sync is fixed at 16 lines.
return 16;
}
}
#endregion #endregion

View File

@ -2,10 +2,6 @@
using BizHawk.Common.NumberExtensions; using BizHawk.Common.NumberExtensions;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BizHawk.Emulation.Cores.Computers.AmstradCPC namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{ {
@ -188,10 +184,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
private int _bufferWidth; private int _bufferWidth;
private int _bufferHeight; private int _bufferHeight;
public int BackgroundColor public int BackgroundColor => CPCHardwarePalette[0];
{
get { return CPCHardwarePalette[0]; }
}
public int VirtualWidth public int VirtualWidth
{ {
@ -223,15 +216,9 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
set { } set { }
} }
public int VsyncDenominator public int VsyncDenominator => GateArray.Z80ClockSpeed;
{
get { return GateArray.Z80ClockSpeed; }
}
public int[] GetVideoBuffer() public int[] GetVideoBuffer() => ProcessVideoBuffer();
{
return ProcessVideoBuffer();
}
public void SetupScreenSize() public void SetupScreenSize()
{ {

View File

@ -1,7 +1,6 @@
using BizHawk.Common; using System.Collections;
using BizHawk.Common;
using BizHawk.Common.NumberExtensions; using BizHawk.Common.NumberExtensions;
using System;
using System.Collections;
namespace BizHawk.Emulation.Cores.Computers.AmstradCPC namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{ {
@ -38,18 +37,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
/// <summary> /// <summary>
/// BDIR Line connected to PSG /// BDIR Line connected to PSG
/// </summary> /// </summary>
public bool BDIR public bool BDIR => Regs[PORT_C].Bit(7);
{
get { return Regs[PORT_C].Bit(7); }
}
/// <summary> /// <summary>
/// BC1 Line connected to PSG /// BC1 Line connected to PSG
/// </summary> /// </summary>
public bool BC1 public bool BC1 => Regs[PORT_C].Bit(6);
{
get { return Regs[PORT_C].Bit(6); }
}
/* Port Constants */ /* Port Constants */
private const int PORT_A = 0; private const int PORT_A = 0;
@ -65,34 +58,22 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
/// <summary> /// <summary>
/// Returns the currently latched port direction for Port A /// Returns the currently latched port direction for Port A
/// </summary> /// </summary>
private PortDirection DirPortA private PortDirection DirPortA => Regs[PORT_CONTROL].Bit(4) ? PortDirection.Input : PortDirection.Output;
{
get { return Regs[PORT_CONTROL].Bit(4) ? PortDirection.Input : PortDirection.Output; }
}
/// <summary> /// <summary>
/// Returns the currently latched port direction for Port B /// Returns the currently latched port direction for Port B
/// </summary> /// </summary>
private PortDirection DirPortB private PortDirection DirPortB => Regs[PORT_CONTROL].Bit(1) ? PortDirection.Input : PortDirection.Output;
{
get { return Regs[PORT_CONTROL].Bit(1) ? PortDirection.Input : PortDirection.Output; }
}
/// <summary> /// <summary>
/// Returns the currently latched port direction for Port C (lower half) /// Returns the currently latched port direction for Port C (lower half)
/// </summary> /// </summary>
private PortDirection DirPortCL private PortDirection DirPortCL => Regs[PORT_CONTROL].Bit(0) ? PortDirection.Input : PortDirection.Output;
{
get { return Regs[PORT_CONTROL].Bit(0) ? PortDirection.Input : PortDirection.Output; }
}
/// <summary> /// <summary>
/// Returns the currently latched port direction for Port C (upper half) /// Returns the currently latched port direction for Port C (upper half)
/// </summary> /// </summary>
private PortDirection DirPortCU private PortDirection DirPortCU => Regs[PORT_CONTROL].Bit(3) ? PortDirection.Input : PortDirection.Output;
{
get { return Regs[PORT_CONTROL].Bit(3) ? PortDirection.Input : PortDirection.Output; }
}
#region OUT Methods #region OUT Methods

View File

@ -1,10 +1,4 @@
using System; namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{ {
/// <summary> /// <summary>
/// CPC464 /// CPC464

View File

@ -1,9 +1,5 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BizHawk.Emulation.Cores.Computers.AmstradCPC namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{ {

View File

@ -1,5 +1,4 @@
using BizHawk.Emulation.Cores.Components.Z80A; using BizHawk.Emulation.Cores.Components.Z80A;
using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace BizHawk.Emulation.Cores.Computers.AmstradCPC namespace BizHawk.Emulation.Cores.Computers.AmstradCPC

View File

@ -1,10 +1,4 @@
using System; namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{ {
/// <summary> /// <summary>
/// CPC6128 /// CPC6128

View File

@ -1,10 +1,6 @@
using BizHawk.Common.NumberExtensions; using BizHawk.Common.NumberExtensions;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BizHawk.Emulation.Cores.Computers.AmstradCPC namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{ {

View File

@ -1,5 +1,4 @@
using BizHawk.Emulation.Cores.Components.Z80A; using BizHawk.Emulation.Cores.Components.Z80A;
using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace BizHawk.Emulation.Cores.Computers.AmstradCPC namespace BizHawk.Emulation.Cores.Computers.AmstradCPC

View File

@ -1,7 +1,4 @@
using System.Collections.Generic; namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
using System.Linq;
namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{ {
/// <summary> /// <summary>
/// The abstract class that all emulated models will inherit from /// The abstract class that all emulated models will inherit from

View File

@ -1,7 +1,4 @@
using System; namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
using System.Collections.Generic;
namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{ {
/// <summary> /// <summary>
/// The abstract class that all emulated models will inherit from /// The abstract class that all emulated models will inherit from

View File

@ -1,6 +1,5 @@
 
using BizHawk.Common.NumberExtensions; using BizHawk.Common.NumberExtensions;
using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace BizHawk.Emulation.Cores.Computers.AmstradCPC namespace BizHawk.Emulation.Cores.Computers.AmstradCPC

View File

@ -172,8 +172,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
// we have reached the end of a frame // we have reached the end of a frame
LastFrameStartCPUTick = CPU.TotalExecutedCycles; // - OverFlow; LastFrameStartCPUTick = CPU.TotalExecutedCycles; // - OverFlow;
if (AYDevice != null) AYDevice?.EndFrame();
AYDevice.EndFrame();
FrameCount++; FrameCount++;
@ -185,7 +184,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
// is this a lag frame? // is this a lag frame?
CPC.IsLagFrame = !InputRead; CPC.IsLagFrame = !InputRead;
// FDC debug // FDC debug
if (UPDDiskDevice != null && UPDDiskDevice.writeDebug) if (UPDDiskDevice != null && UPDDiskDevice.writeDebug)
{ {
// only write UPD log every second // only write UPD log every second
@ -360,10 +359,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
if (ser.IsReader) if (ser.IsReader)
DiskMediaIndex = diskMediaIndex; DiskMediaIndex = diskMediaIndex;
if (UPDDiskDevice != null) UPDDiskDevice?.SyncState(ser);
{
UPDDiskDevice.SyncState(ser);
}
ser.EndSection(); ser.EndSection();
} }

View File

@ -3,10 +3,6 @@ using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Components.Z80A; using BizHawk.Emulation.Cores.Components.Z80A;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BizHawk.Emulation.Cores.Computers.AmstradCPC namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{ {
@ -452,10 +448,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
private int _bufferWidth; private int _bufferWidth;
private int _bufferHeight; private int _bufferHeight;
public int BackgroundColor public int BackgroundColor => CPCHardwarePalette[16];
{
get { return CPCHardwarePalette[16]; }
}
public int VirtualWidth public int VirtualWidth
{ {
@ -487,15 +480,9 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
set { } set { }
} }
public int VsyncDenominator public int VsyncDenominator => Z80ClockSpeed;
{
get { return Z80ClockSpeed; }
}
public int[] GetVideoBuffer() public int[] GetVideoBuffer() => ScreenBuffer;
{
return ScreenBuffer;
}
protected void SetupScreenSize() protected void SetupScreenSize()
{ {

View File

@ -68,8 +68,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
// check for unformatted track // check for unformatted track
if (DiskHeader.TrackSizes[i] == 0) if (DiskHeader.TrackSizes[i] == 0)
{ {
DiskTracks[i] = new Track(); DiskTracks[i] = new Track { Sectors = new Sector[0] };
DiskTracks[i].Sectors = new Sector[0];
continue; continue;
} }
@ -94,15 +93,16 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
DiskTracks[i].Sectors = new Sector[DiskTracks[i].NumberOfSectors]; DiskTracks[i].Sectors = new Sector[DiskTracks[i].NumberOfSectors];
for (int s = 0; s < DiskTracks[i].NumberOfSectors; s++) for (int s = 0; s < DiskTracks[i].NumberOfSectors; s++)
{ {
DiskTracks[i].Sectors[s] = new Sector(); DiskTracks[i].Sectors[s] = new Sector
{
DiskTracks[i].Sectors[s].TrackNumber = data[p++]; TrackNumber = data[p++],
DiskTracks[i].Sectors[s].SideNumber = data[p++]; SideNumber = data[p++],
DiskTracks[i].Sectors[s].SectorID = data[p++]; SectorID = data[p++],
DiskTracks[i].Sectors[s].SectorSize = data[p++]; SectorSize = data[p++],
DiskTracks[i].Sectors[s].Status1 = data[p++]; Status1 = data[p++],
DiskTracks[i].Sectors[s].Status2 = data[p++]; Status2 = data[p++],
DiskTracks[i].Sectors[s].ActualDataByteLength = MediaConverter.GetWordValue(data, p); ActualDataByteLength = MediaConverter.GetWordValue(data, p)
};
p += 2; p += 2;
// sector data - begins at 0x100 offset from the start of the track info block (in this case dpos) // sector data - begins at 0x100 offset from the start of the track info block (in this case dpos)

View File

@ -69,8 +69,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
// check for unformatted track // check for unformatted track
if (DiskHeader.TrackSizes[i] == 0) if (DiskHeader.TrackSizes[i] == 0)
{ {
DiskTracks[i] = new Track(); DiskTracks[i] = new Track { Sectors = new Sector[0] };
DiskTracks[i].Sectors = new Sector[0];
continue; continue;
} }
@ -94,15 +93,17 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
DiskTracks[i].Sectors = new Sector[DiskTracks[i].NumberOfSectors]; DiskTracks[i].Sectors = new Sector[DiskTracks[i].NumberOfSectors];
for (int s = 0; s < DiskTracks[i].NumberOfSectors; s++) for (int s = 0; s < DiskTracks[i].NumberOfSectors; s++)
{ {
DiskTracks[i].Sectors[s] = new Sector(); DiskTracks[i].Sectors[s] = new Sector
{
TrackNumber = data[p++],
SideNumber = data[p++],
SectorID = data[p++],
SectorSize = data[p++],
Status1 = data[p++],
Status2 = data[p++],
ActualDataByteLength = MediaConverter.GetWordValue(data, p)
};
DiskTracks[i].Sectors[s].TrackNumber = data[p++];
DiskTracks[i].Sectors[s].SideNumber = data[p++];
DiskTracks[i].Sectors[s].SectorID = data[p++];
DiskTracks[i].Sectors[s].SectorSize = data[p++];
DiskTracks[i].Sectors[s].Status1 = data[p++];
DiskTracks[i].Sectors[s].Status2 = data[p++];
DiskTracks[i].Sectors[s].ActualDataByteLength = MediaConverter.GetWordValue(data, p);
p += 2; p += 2;
// actualdatabytelength value is calculated now // actualdatabytelength value is calculated now

View File

@ -1,10 +1,4 @@
using System; namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{ {
/// <summary> /// <summary>
/// This is called first when importing disk images /// This is called first when importing disk images

View File

@ -700,21 +700,16 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
} }
} }
public CHRN SectorIDInfo public CHRN SectorIDInfo =>
{ new CHRN
get
{ {
return new CHRN C = TrackNumber,
{ H = SideNumber,
C = TrackNumber, R = SectorID,
H = SideNumber, N = SectorSize,
R = SectorID, Flag1 = Status1,
N = SectorSize, Flag2 = Status2,
Flag1 = Status1, };
Flag2 = Status2,
};
}
}
} }
} }

View File

@ -17,31 +17,19 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
/// <summary> /// <summary>
/// Signs whether this class can be used to read the data format /// Signs whether this class can be used to read the data format
/// </summary> /// </summary>
public virtual bool IsReader public virtual bool IsReader => false;
{
get
{
return false;
}
}
/// <summary> /// <summary>
/// Signs whether this class can be used to write the data format /// Signs whether this class can be used to write the data format
/// </summary> /// </summary>
public virtual bool IsWriter public virtual bool IsWriter => false;
{
get
{
return false;
}
}
/// <summary> /// <summary>
/// Serialization method /// Serialization method
/// </summary> /// </summary>
public virtual void Read(byte[] data) public virtual void Read(byte[] data)
{ {
throw new NotImplementedException(this.GetType().ToString() + throw new NotImplementedException(this.GetType() +
"Read operation is not implemented for this converter"); "Read operation is not implemented for this converter");
} }
@ -50,7 +38,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
/// </summary> /// </summary>
public virtual void Write(byte[] data) public virtual void Write(byte[] data)
{ {
throw new NotImplementedException(this.GetType().ToString() + throw new NotImplementedException(this.GetType() +
"Write operation is not implemented for this converter"); "Write operation is not implemented for this converter");
} }

View File

@ -6,7 +6,7 @@ using System.Text;
namespace BizHawk.Emulation.Cores.Computers.AmstradCPC namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{ {
/// <summary> /// <summary>
/// Reponsible for TZX format serializaton /// Responsible for TZX format serialization
/// </summary> /// </summary>
public class CdtConverter : MediaConverter public class CdtConverter : MediaConverter
{ {
@ -14,23 +14,17 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
/// The type of serializer /// The type of serializer
/// </summary> /// </summary>
private MediaConverterType _formatType = MediaConverterType.CDT; private MediaConverterType _formatType = MediaConverterType.CDT;
public override MediaConverterType FormatType public override MediaConverterType FormatType => _formatType;
{
get
{
return _formatType;
}
}
/// <summary> /// <summary>
/// Signs whether this class can be used to read the data format /// Signs whether this class can be used to read the data format
/// </summary> /// </summary>
public override bool IsReader { get { return true; } } public override bool IsReader => true;
/// <summary> /// <summary>
/// Signs whether this class can be used to write the data format /// Signs whether this class can be used to write the data format
/// </summary> /// </summary>
public override bool IsWriter { get { return false; } } public override bool IsWriter => false;
/// <summary> /// <summary>
/// Working list of generated tape data blocks /// Working list of generated tape data blocks
@ -65,14 +59,16 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
/// </summary> /// </summary>
private TapeDataBlock ConvertClock(TapeDataBlock db) private TapeDataBlock ConvertClock(TapeDataBlock db)
{ {
TapeDataBlock tb = new TapeDataBlock(); var tb = new TapeDataBlock
tb.BlockDescription = db.BlockDescription; {
tb.BlockID = db.BlockID; BlockDescription = db.BlockDescription,
tb.Command = db.Command; BlockID = db.BlockID,
tb.DataPeriods = new List<int>(); Command = db.Command,
tb.InitialPulseLevel = db.InitialPulseLevel; DataPeriods = new List<int>(),
tb.MetaData = db.MetaData; InitialPulseLevel = db.InitialPulseLevel,
tb.PauseInMS = db.PauseInMS; MetaData = db.MetaData,
PauseInMS = db.PauseInMS
};
double multiplier = 8.0 / 7.0; double multiplier = 8.0 / 7.0;
//double cycleScale = ((40 << 16) / 35); //double cycleScale = ((40 << 16) / 35);
@ -172,7 +168,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
if (ident != "ZXTape!" || eotm != 0x1A) if (ident != "ZXTape!" || eotm != 0x1A)
{ {
// this is not a valid TZX format file // this is not a valid TZX format file
throw new Exception(this.GetType().ToString() + throw new Exception(this.GetType() +
"This is not a valid TZX format file"); "This is not a valid TZX format file");
} }
@ -180,7 +176,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
_position = 10; _position = 10;
while (_position < data.Length) while (_position < data.Length)
{ {
// block ID is the first byte in a new block // block ID is the first byte in a new block
int ID = data[_position++]; int ID = data[_position++];
// process the data // process the data
@ -347,10 +343,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
for custom loading routines that use the same timings as ROM ones do. */ for custom loading routines that use the same timings as ROM ones do. */
private void ProcessBlockID10(byte[] data) private void ProcessBlockID10(byte[] data)
{ {
TapeDataBlock t = new TapeDataBlock(); var t = new TapeDataBlock
t.BlockID = 0x10; {
t.BlockDescription = BlockType.Standard_Speed_Data_Block; BlockID = 0x10,
t.DataPeriods = new List<int>(); BlockDescription = BlockType.Standard_Speed_Data_Block,
DataPeriods = new List<int>()
};
int pauseLen = GetWordValue(data, _position); int pauseLen = GetWordValue(data, _position);
if (pauseLen == 0) if (pauseLen == 0)
@ -399,10 +397,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
sync or pilot tones (i.e. all sorts of protection schemes) then use the next three blocks to describe it.*/ sync or pilot tones (i.e. all sorts of protection schemes) then use the next three blocks to describe it.*/
private void ProcessBlockID11(byte[] data) private void ProcessBlockID11(byte[] data)
{ {
TapeDataBlock t = new TapeDataBlock(); var t = new TapeDataBlock
t.BlockID = 0x11; {
t.BlockDescription = BlockType.Turbo_Speed_Data_Block; BlockID = 0x11,
t.DataPeriods = new List<int>(); BlockDescription = BlockType.Turbo_Speed_Data_Block,
DataPeriods = new List<int>()
};
int pilotPL = GetWordValue(data, _position); int pilotPL = GetWordValue(data, _position);
int sync1P = GetWordValue(data, _position + 2); int sync1P = GetWordValue(data, _position + 2);
@ -450,17 +450,18 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{ {
int blockLen = 4; int blockLen = 4;
TapeDataBlock t = new TapeDataBlock(); var t = new TapeDataBlock
t.BlockID = 0x12; {
t.BlockDescription = BlockType.Pure_Tone; BlockID = 0x12,
t.DataPeriods = new List<int>(); BlockDescription = BlockType.Pure_Tone,
t.PauseInMS = 0; DataPeriods = new List<int>(), PauseInMS = 0
};
// get values // get values
int pulseLength = GetWordValue(data, _position); int pulseLength = GetWordValue(data, _position);
int pulseCount = GetWordValue(data, _position + 2); int pulseCount = GetWordValue(data, _position + 2);
t.AddMetaData(BlockDescriptorTitle.Pulse_Length, pulseLength.ToString() + " T-States"); t.AddMetaData(BlockDescriptorTitle.Pulse_Length, pulseLength + " T-States");
t.AddMetaData(BlockDescriptorTitle.Pulse_Count, pulseCount.ToString()); t.AddMetaData(BlockDescriptorTitle.Pulse_Count, pulseCount.ToString());
// build period information // build period information
@ -487,14 +488,15 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
sync tones used by some protection schemes. */ sync tones used by some protection schemes. */
private void ProcessBlockID13(byte[] data) private void ProcessBlockID13(byte[] data)
{ {
TapeDataBlock t = new TapeDataBlock(); TapeDataBlock t = new TapeDataBlock
t.BlockID = 0x13; {
t.BlockDescription = BlockType.Pulse_Sequence; BlockID = 0x13,
t.DataPeriods = new List<int>(); BlockDescription = BlockType.Pulse_Sequence,
DataPeriods = new List<int>(),
PauseInMS = 0
};
t.PauseInMS = 0; // get pulse count
// get pulse count
int pulseCount = data[_position]; int pulseCount = data[_position];
t.AddMetaData(BlockDescriptorTitle.Pulse_Count, pulseCount.ToString()); t.AddMetaData(BlockDescriptorTitle.Pulse_Count, pulseCount.ToString());
_position++; _position++;
@ -504,7 +506,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{ {
// get pulse length // get pulse length
int pulseLength = GetWordValue(data, _position); int pulseLength = GetWordValue(data, _position);
t.AddMetaData(BlockDescriptorTitle.Needs_Parsing, "Pulse " + p + " Length\t" + pulseLength.ToString() + " T-States"); t.AddMetaData(BlockDescriptorTitle.Needs_Parsing, "Pulse " + p + " Length\t" + pulseLength + " T-States");
t.DataPeriods.Add(pulseLength); t.DataPeriods.Add(pulseLength);
} }
@ -528,10 +530,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
This is the same as in the turbo loading data block, except that it has no pilot or sync pulses. */ This is the same as in the turbo loading data block, except that it has no pilot or sync pulses. */
private void ProcessBlockID14(byte[] data) private void ProcessBlockID14(byte[] data)
{ {
TapeDataBlock t = new TapeDataBlock(); TapeDataBlock t = new TapeDataBlock
t.BlockID = 0x14; {
t.BlockDescription = BlockType.Pure_Data_Block; BlockID = 0x14,
t.DataPeriods = new List<int>(); BlockDescription = BlockType.Pure_Data_Block,
DataPeriods = new List<int>()
};
int pilotPL = 0; int pilotPL = 0;
int sync1P = 0; int sync1P = 0;
@ -583,10 +587,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
Please use this block only if you cannot use any other block. */ Please use this block only if you cannot use any other block. */
private void ProcessBlockID15(byte[] data) private void ProcessBlockID15(byte[] data)
{ {
TapeDataBlock t = new TapeDataBlock(); var t = new TapeDataBlock
t.BlockID = 0x15; {
t.BlockDescription = BlockType.Direct_Recording; BlockID = 0x15,
t.DataPeriods = new List<int>(); BlockDescription = BlockType.Direct_Recording,
DataPeriods = new List<int>()
};
// get values // get values
int samLen = GetInt32(data, _position + 5); int samLen = GetInt32(data, _position + 5);
@ -632,7 +638,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
} }
} }
// incrememt position // increment position
_position++; _position++;
} }
@ -680,15 +686,17 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
0x01: RLE 0x01: RLE
0x02: Z-RLE 0x02: Z-RLE
0x0A - DWORD Number of stored pulses (after decompression, for validation purposes) 0x0A - DWORD Number of stored pulses (after decompression, for validation purposes)
0x0E - BYTE[N] CSW data, encoded according to the CSW file format specification. 0x0E - BYTE[N] CSW data, encoded according to the CSW file format specification.
This block contains a sequence of raw pulses encoded in CSW format v2 (Compressed Square Wave). */ This block contains a sequence of raw pulses encoded in CSW format v2 (Compressed Square Wave). */
private void ProcessBlockID18(byte[] data) private void ProcessBlockID18(byte[] data)
{ {
TapeDataBlock t = new TapeDataBlock(); TapeDataBlock t = new TapeDataBlock
t.BlockID = 0x18; {
t.BlockDescription = BlockType.CSW_Recording; BlockID = 0x18,
t.DataPeriods = new List<int>(); BlockDescription = BlockType.CSW_Recording,
DataPeriods = new List<int>()
};
int blockLen = GetInt32(data, _position); int blockLen = GetInt32(data, _position);
_position += 4; _position += 4;
@ -710,7 +718,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
byte[] dest = new byte[pulses + 1]; byte[] dest = new byte[pulses + 1];
// process the CSW data // process the CSW data
BizHawk.Emulation.Cores.Computers.SinclairSpectrum.CswConverter.ProcessCSWV2(src, ref dest, compType, pulses); SinclairSpectrum.CswConverter.ProcessCSWV2(src, ref dest, compType, pulses);
// create the periods // create the periods
var rate = (69888 * 50) / sampleRate; var rate = (69888 * 50) / sampleRate;
@ -804,11 +812,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
private void ProcessBlockID19(byte[] data) private void ProcessBlockID19(byte[] data)
{ {
// not currently implemented properly // not currently implemented properly
var t = new TapeDataBlock
TapeDataBlock t = new TapeDataBlock(); {
t.BlockID = 0x19; BlockID = 0x19,
t.BlockDescription = BlockType.Generalized_Data_Block; BlockDescription = BlockType.Generalized_Data_Block,
t.DataPeriods = new List<int>(); DataPeriods = new List<int>()
};
int blockLen = GetInt32(data, _position); int blockLen = GetInt32(data, _position);
_position += 4; _position += 4;
@ -841,16 +850,18 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
#region ID 20 - Pause (silence) or 'Stop the Tape' command #region ID 20 - Pause (silence) or 'Stop the Tape' command
/* length: 02 /* length: 02
Offset Value Type Description Offset Value Type Description
0x00 - WORD Pause duration (ms.) 0x00 - WORD Pause duration (ms.)
This will make a silence (low amplitude level (0)) for a given time in milliseconds. If the value is 0 then the This will make a silence (low amplitude level (0)) for a given time in milliseconds. If the value is 0 then the
emulator or utility should (in effect) STOP THE TAPE, i.e. should not continue loading until the user or emulator requests it. */ emulator or utility should (in effect) STOP THE TAPE, i.e. should not continue loading until the user or emulator requests it. */
private void ProcessBlockID20(byte[] data) private void ProcessBlockID20(byte[] data)
{ {
TapeDataBlock t = new TapeDataBlock(); TapeDataBlock t = new TapeDataBlock
t.BlockID = 0x20; {
t.DataPeriods = new List<int>(); BlockID = 0x20,
t.BlockDescription = BlockType.Pause_or_Stop_the_Tape; DataPeriods = new List<int>(),
BlockDescription = BlockType.Pause_or_Stop_the_Tape
};
int pauseDuration = GetWordValue(data, _position); int pauseDuration = GetWordValue(data, _position);
if (pauseDuration != 0) if (pauseDuration != 0)
@ -907,10 +918,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
For each group start block, there must be a group end block. Nesting of groups is not allowed. */ For each group start block, there must be a group end block. Nesting of groups is not allowed. */
private void ProcessBlockID21(byte[] data) private void ProcessBlockID21(byte[] data)
{ {
TapeDataBlock t = new TapeDataBlock(); var t = new TapeDataBlock
t.BlockID = 0x21; {
t.DataPeriods = new List<int>(); BlockID = 0x21,
t.BlockDescription = BlockType.Group_Start; DataPeriods = new List<int>(),
BlockDescription = BlockType.Group_Start
};
int nameLength = data[_position]; int nameLength = data[_position];
_position++; _position++;
@ -935,13 +948,14 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
This indicates the end of a group. This block has no body. */ This indicates the end of a group. This block has no body. */
private void ProcessBlockID22(byte[] data) private void ProcessBlockID22(byte[] data)
{ {
TapeDataBlock t = new TapeDataBlock(); TapeDataBlock t = new TapeDataBlock
t.BlockID = 0x22; {
t.DataPeriods = new List<int>(); BlockID = 0x22,
t.BlockDescription = BlockType.Group_End; DataPeriods = new List<int>(),
t.Command = TapeCommand.END_GROUP; BlockDescription = BlockType.Group_End,
Command = TapeCommand.END_GROUP,
t.PauseInMS = 0; PauseInMS = 0
};
// add to tape // add to tape
_datacorder.DataBlocks.Add(t); _datacorder.DataBlocks.Add(t);
@ -963,11 +977,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
private void ProcessBlockID23(byte[] data) private void ProcessBlockID23(byte[] data)
{ {
// not implemented properly // not implemented properly
var t = new TapeDataBlock
TapeDataBlock t = new TapeDataBlock(); {
t.BlockID = 0x23; BlockID = 0x23,
t.DataPeriods = new List<int>(); DataPeriods = new List<int>(),
t.BlockDescription = BlockType.Jump_to_Block; BlockDescription = BlockType.Jump_to_Block
};
int relativeJumpValue = GetWordValue(data, _position); int relativeJumpValue = GetWordValue(data, _position);
string result = string.Empty; string result = string.Empty;
@ -1010,10 +1025,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
For simplicity reasons don't nest loop blocks! */ For simplicity reasons don't nest loop blocks! */
private void ProcessBlockID24(byte[] data) private void ProcessBlockID24(byte[] data)
{ {
TapeDataBlock t = new TapeDataBlock(); var t = new TapeDataBlock
t.BlockID = 0x24; {
t.DataPeriods = new List<int>(); BlockID = 0x24,
t.BlockDescription = BlockType.Loop_Start; DataPeriods = new List<int>(),
BlockDescription = BlockType.Loop_Start
};
// loop should start from the next block // loop should start from the next block
int loopStart = _datacorder.DataBlocks.Count() + 1; int loopStart = _datacorder.DataBlocks.Count() + 1;
@ -1047,10 +1064,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
This block has no body. */ This block has no body. */
private void ProcessBlockID25(byte[] data) private void ProcessBlockID25(byte[] data)
{ {
TapeDataBlock t = new TapeDataBlock(); var t = new TapeDataBlock
t.BlockID = 0x25; {
t.DataPeriods = new List<int>(); BlockID = 0x25,
t.BlockDescription = BlockType.Loop_End; DataPeriods = new List<int>(),
BlockDescription = BlockType.Loop_End
};
// get the most recent loop info // get the most recent loop info
var loop = _loopCounter.LastOrDefault(); var loop = _loopCounter.LastOrDefault();
@ -1100,10 +1119,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
private void ProcessBlockID26(byte[] data) private void ProcessBlockID26(byte[] data)
{ {
// block processing not implemented for this - just gets added for informational purposes only // block processing not implemented for this - just gets added for informational purposes only
TapeDataBlock t = new TapeDataBlock(); var t = new TapeDataBlock
t.BlockID = 0x26; {
t.DataPeriods = new List<int>(); BlockID = 0x26,
t.BlockDescription = BlockType.Call_Sequence; DataPeriods = new List<int>(),
BlockDescription = BlockType.Call_Sequence
};
int blockSize = 2 + 2 * GetWordValue(data, _position); int blockSize = 2 + 2 * GetWordValue(data, _position);
t.PauseInMS = 0; t.PauseInMS = 0;
@ -1126,12 +1147,13 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
private void ProcessBlockID27(byte[] data) private void ProcessBlockID27(byte[] data)
{ {
// block processing not implemented for this - just gets added for informational purposes only // block processing not implemented for this - just gets added for informational purposes only
TapeDataBlock t = new TapeDataBlock(); var t = new TapeDataBlock
t.BlockID = 0x27; {
t.DataPeriods = new List<int>(); BlockID = 0x27,
t.BlockDescription = BlockType.Return_From_Sequence; DataPeriods = new List<int>(),
t.PauseInMS = 0; BlockDescription = BlockType.Return_From_Sequence,
PauseInMS = 0
};
// add to tape // add to tape
_datacorder.DataBlocks.Add(t); _datacorder.DataBlocks.Add(t);
@ -1160,10 +1182,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
private void ProcessBlockID28(byte[] data) private void ProcessBlockID28(byte[] data)
{ {
// block processing not implemented for this - just gets added for informational purposes only // block processing not implemented for this - just gets added for informational purposes only
TapeDataBlock t = new TapeDataBlock(); var t = new TapeDataBlock
t.BlockID = 0x28; {
t.DataPeriods = new List<int>(); BlockID = 0x28,
t.BlockDescription = BlockType.Select_Block; DataPeriods = new List<int>(),
BlockDescription = BlockType.Select_Block
};
int blockSize = 2 + GetWordValue(data, _position); int blockSize = 2 + GetWordValue(data, _position);
@ -1187,11 +1211,13 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
This block has no body of its own, but follows the extension rule. */ This block has no body of its own, but follows the extension rule. */
private void ProcessBlockID2A(byte[] data) private void ProcessBlockID2A(byte[] data)
{ {
TapeDataBlock t = new TapeDataBlock(); var t = new TapeDataBlock
t.BlockID = 0x2A; {
t.DataPeriods = new List<int>(); BlockID = 0x2A,
t.BlockDescription = BlockType.Stop_the_Tape_48K; DataPeriods = new List<int>(),
t.Command = TapeCommand.STOP_THE_TAPE_48K; BlockDescription = BlockType.Stop_the_Tape_48K,
Command = TapeCommand.STOP_THE_TAPE_48K
};
int blockSize = 4 + GetWordValue(data, _position); int blockSize = 4 + GetWordValue(data, _position);
@ -1215,12 +1241,13 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
ambiguities, e.g. with custom loaders which are level-sensitive. */ ambiguities, e.g. with custom loaders which are level-sensitive. */
private void ProcessBlockID2B(byte[] data) private void ProcessBlockID2B(byte[] data)
{ {
TapeDataBlock t = new TapeDataBlock(); var t = new TapeDataBlock
t.BlockID = 0x2B; {
t.DataPeriods = new List<int>(); BlockID = 0x2B,
t.BlockDescription = BlockType.Set_Signal_Level; DataPeriods = new List<int>(),
BlockDescription = BlockType.Set_Signal_Level,
t.PauseInMS = 0; PauseInMS = 0
};
// add to tape // add to tape
_datacorder.DataBlocks.Add(t); _datacorder.DataBlocks.Add(t);
@ -1244,10 +1271,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
Please use 'Archive Info' block for title, authors, publisher, etc. */ Please use 'Archive Info' block for title, authors, publisher, etc. */
private void ProcessBlockID30(byte[] data) private void ProcessBlockID30(byte[] data)
{ {
TapeDataBlock t = new TapeDataBlock(); var t = new TapeDataBlock
t.BlockID = 0x30; {
t.DataPeriods = new List<int>(); BlockID = 0x30,
t.BlockDescription = BlockType.Text_Description; DataPeriods = new List<int>(),
BlockDescription = BlockType.Text_Description
};
int textLen = data[_position]; int textLen = data[_position];
_position++; _position++;
@ -1283,11 +1312,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
private void ProcessBlockID31(byte[] data) private void ProcessBlockID31(byte[] data)
{ {
// currently not implemented properly in ZXHawk // currently not implemented properly in ZXHawk
var t = new TapeDataBlock
TapeDataBlock t = new TapeDataBlock(); {
t.BlockID = 0x31; BlockID = 0x31,
t.DataPeriods = new List<int>(); DataPeriods = new List<int>(),
t.BlockDescription = BlockType.Message_Block; BlockDescription = BlockType.Message_Block
};
_position++; _position++;
@ -1344,10 +1374,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
The information about what hardware the tape uses is in the 'Hardware Type' block, so no need for it here. */ The information about what hardware the tape uses is in the 'Hardware Type' block, so no need for it here. */
private void ProcessBlockID32(byte[] data) private void ProcessBlockID32(byte[] data)
{ {
TapeDataBlock t = new TapeDataBlock(); var t = new TapeDataBlock
t.BlockID = 0x32; {
t.DataPeriods = new List<int>(); BlockID = 0x32,
t.BlockDescription = BlockType.Archive_Info; DataPeriods = new List<int>(),
BlockDescription = BlockType.Archive_Info
};
int blockLen = GetWordValue(data, _position); int blockLen = GetWordValue(data, _position);
_position += 2; _position += 2;
@ -1397,8 +1429,6 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
case 0xFF: case 0xFF:
title = "Comment(s): "; title = "Comment(s): ";
break; break;
default:
break;
} }
// add title to description // add title to description
@ -1451,12 +1481,13 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{ {
// currently not implemented properly in ZXHawk // currently not implemented properly in ZXHawk
TapeDataBlock t = new TapeDataBlock(); TapeDataBlock t = new TapeDataBlock
t.BlockID = 0x33; {
t.DataPeriods = new List<int>(); BlockID = 0x33,
t.BlockDescription = BlockType.Hardware_Type; DataPeriods = new List<int>(),
BlockDescription = BlockType.Hardware_Type,
t.PauseInMS = 0; PauseInMS = 0
};
// first byte contains number of HWINFOs // first byte contains number of HWINFOs
int infos = data[_position]; int infos = data[_position];
@ -1485,12 +1516,13 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
extra settings required by a particular emulator, or even poke data. */ extra settings required by a particular emulator, or even poke data. */
private void ProcessBlockID35(byte[] data) private void ProcessBlockID35(byte[] data)
{ {
TapeDataBlock t = new TapeDataBlock(); var t = new TapeDataBlock
t.BlockID = 0x35; {
t.DataPeriods = new List<int>(); BlockID = 0x35,
t.BlockDescription = BlockType.Custom_Info_Block; DataPeriods = new List<int>(),
BlockDescription = BlockType.Custom_Info_Block,
t.PauseInMS = 0; PauseInMS = 0
};
string info = Encoding.ASCII.GetString(data, _position, 0x10); string info = Encoding.ASCII.GetString(data, _position, 0x10);
//t.BlockDescription = "[CUSTOM INFO: " + info + "]"; //t.BlockDescription = "[CUSTOM INFO: " + info + "]";
@ -1520,12 +1552,13 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
ensure that they are both of the higher version number. */ ensure that they are both of the higher version number. */
private void ProcessBlockID5A(byte[] data) private void ProcessBlockID5A(byte[] data)
{ {
TapeDataBlock t = new TapeDataBlock(); var t = new TapeDataBlock
t.BlockID = 0x5A; {
t.DataPeriods = new List<int>(); BlockID = 0x5A,
t.BlockDescription = BlockType.Glue_Block; DataPeriods = new List<int>(),
BlockDescription = BlockType.Glue_Block,
t.PauseInMS = 0; PauseInMS = 0
};
// add to tape // add to tape
_datacorder.DataBlocks.Add(t); _datacorder.DataBlocks.Add(t);
@ -1539,10 +1572,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
private void ProcessUnidentifiedBlock(byte[] data) private void ProcessUnidentifiedBlock(byte[] data)
{ {
TapeDataBlock t = new TapeDataBlock(); var t = new TapeDataBlock
t.BlockID = -2; {
t.DataPeriods = new List<int>(); BlockID = -2,
t.BlockDescription = BlockType.Unsupported; DataPeriods = new List<int>(),
BlockDescription = BlockType.Unsupported
};
//t.BlockDescription = "[UNSUPPORTED - 0x" + data[_position - 1] + "]"; //t.BlockDescription = "[UNSUPPORTED - 0x" + data[_position - 1] + "]";
_position += GetInt32(data, _position) & 0xFFFFFF; _position += GetInt32(data, _position) & 0xFFFFFF;
@ -1564,12 +1599,13 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
private void ProcessBlockID16(byte[] data) private void ProcessBlockID16(byte[] data)
{ {
// zxhawk will not implement this block. it will however handle it so subsequent blocks can be parsed // zxhawk will not implement this block. it will however handle it so subsequent blocks can be parsed
TapeDataBlock t = new TapeDataBlock(); TapeDataBlock t = new TapeDataBlock
t.BlockID = 0x16; {
t.DataPeriods = new List<int>(); BlockID = 0x16,
t.BlockDescription = BlockType.C64_ROM_Type_Data_Block; DataPeriods = new List<int>(),
BlockDescription = BlockType.C64_ROM_Type_Data_Block,
t.PauseInMS = 0; PauseInMS = 0
};
// add to tape // add to tape
_datacorder.DataBlocks.Add(t); _datacorder.DataBlocks.Add(t);
@ -1584,12 +1620,13 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
private void ProcessBlockID17(byte[] data) private void ProcessBlockID17(byte[] data)
{ {
// zxhawk will not implement this block. it will however handle it so subsequent blocks can be parsed // zxhawk will not implement this block. it will however handle it so subsequent blocks can be parsed
TapeDataBlock t = new TapeDataBlock(); var t = new TapeDataBlock
t.BlockID = 0x17; {
t.DataPeriods = new List<int>(); BlockID = 0x17,
t.BlockDescription = BlockType.C64_Turbo_Tape_Data_Block; DataPeriods = new List<int>(),
BlockDescription = BlockType.C64_Turbo_Tape_Data_Block,
t.PauseInMS = 0; PauseInMS = 0
};
// add to tape // add to tape
_datacorder.DataBlocks.Add(t); _datacorder.DataBlocks.Add(t);
@ -1604,11 +1641,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
private void ProcessBlockID34(byte[] data) private void ProcessBlockID34(byte[] data)
{ {
// currently not implemented properly in ZXHawk // currently not implemented properly in ZXHawk
var t = new TapeDataBlock
TapeDataBlock t = new TapeDataBlock(); {
t.BlockID = 0x34; BlockID = 0x34,
t.DataPeriods = new List<int>(); DataPeriods = new List<int>(),
t.BlockDescription = BlockType.Emulation_Info; BlockDescription = BlockType.Emulation_Info
};
// add to tape // add to tape
_datacorder.DataBlocks.Add(t); _datacorder.DataBlocks.Add(t);
@ -1635,10 +1673,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{ {
// currently not implemented properly in ZXHawk // currently not implemented properly in ZXHawk
TapeDataBlock t = new TapeDataBlock(); TapeDataBlock t = new TapeDataBlock
t.BlockID = 0x40; {
t.DataPeriods = new List<int>(); BlockID = 0x40,
t.BlockDescription = BlockType.Snapshot_Block; DataPeriods = new List<int>(),
BlockDescription = BlockType.Snapshot_Block
};
_position++; _position++;
@ -1735,7 +1775,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{ {
// data block // data block
description = "Data Block " + (blockSize - 2) + "bytes"; description = "Data Block " + (blockSize - 2) + "bytes";
block.AddMetaData(BlockDescriptorTitle.Data_Bytes, (blockSize - 2).ToString() + " Bytes"); block.AddMetaData(BlockDescriptorTitle.Data_Bytes, (blockSize - 2) + " Bytes");
} }
else else
{ {
@ -1801,10 +1841,10 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
if (dataBlockType == DataBlockType.Turbo) if (dataBlockType == DataBlockType.Turbo)
block.BlockDescription = BlockType.Turbo_Speed_Data_Block; block.BlockDescription = BlockType.Turbo_Speed_Data_Block;
block.AddMetaData(BlockDescriptorTitle.Pilot_Pulse_Length, pilotToneLength.ToString() + " T-States"); block.AddMetaData(BlockDescriptorTitle.Pilot_Pulse_Length, pilotToneLength + " T-States");
block.AddMetaData(BlockDescriptorTitle.Pilot_Pulse_Count, pilotCount.ToString() + " Pulses"); block.AddMetaData(BlockDescriptorTitle.Pilot_Pulse_Count, pilotCount + " Pulses");
block.AddMetaData(BlockDescriptorTitle.First_Sync_Length, sync1PulseLength.ToString() + " T-States"); block.AddMetaData(BlockDescriptorTitle.First_Sync_Length, sync1PulseLength + " T-States");
block.AddMetaData(BlockDescriptorTitle.Second_Sync_Length, sync2PulseLength.ToString() + " T-States"); block.AddMetaData(BlockDescriptorTitle.Second_Sync_Length, sync2PulseLength + " T-States");
break; break;
case DataBlockType.Pure: case DataBlockType.Pure:
@ -1812,11 +1852,11 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
break; break;
} }
block.AddMetaData(BlockDescriptorTitle.Zero_Bit_Length, bit0PulseLength.ToString() + " T-States"); block.AddMetaData(BlockDescriptorTitle.Zero_Bit_Length, bit0PulseLength + " T-States");
block.AddMetaData(BlockDescriptorTitle.One_Bit_Length, bit1PulseLength.ToString() + " T-States"); block.AddMetaData(BlockDescriptorTitle.One_Bit_Length, bit1PulseLength + " T-States");
block.AddMetaData(BlockDescriptorTitle.Data_Length, blockSize.ToString() + " Bytes"); block.AddMetaData(BlockDescriptorTitle.Data_Length, blockSize + " Bytes");
block.AddMetaData(BlockDescriptorTitle.Bits_In_Last_Byte, bitsInLastByte.ToString() + " Bits"); block.AddMetaData(BlockDescriptorTitle.Bits_In_Last_Byte, bitsInLastByte + " Bits");
block.AddMetaData(BlockDescriptorTitle.Pause_After_Data, pauseAfterBlock.ToString() + " ms"); block.AddMetaData(BlockDescriptorTitle.Pause_After_Data, pauseAfterBlock + " ms");
// calculate period information // calculate period information
List<int> dataPeriods = new List<int>(); List<int> dataPeriods = new List<int>();
@ -1937,19 +1977,21 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
#region Pause Block Creator #region Pause Block Creator
/// <summary> /// <summary>
/// If neccessary a seperate PAUSE block will be created /// If necessary a separate PAUSE block will be created
/// </summary> /// </summary>
private void CreatePauseBlock(TapeDataBlock original) private void CreatePauseBlock(TapeDataBlock original)
{ {
if (original.PauseInMS > 0) if (original.PauseInMS > 0)
{ {
TapeDataBlock pBlock = new TapeDataBlock(); var pBlock = new TapeDataBlock
pBlock.DataPeriods = new List<int>(); {
pBlock.BlockDescription = BlockType.PAUSE_BLOCK; DataPeriods = new List<int>(),
pBlock.PauseInMS = 0; BlockDescription = BlockType.PAUSE_BLOCK,
PauseInMS = 0
};
var pauseInTStates = TranslatePause(original.PauseInMS); var pauseInTStates = TranslatePause(original.PauseInMS);
pBlock.AddMetaData(BlockDescriptorTitle.Block_ID, pauseInTStates.ToString() + " cycles"); pBlock.AddMetaData(BlockDescriptorTitle.Block_ID, pauseInTStates + " cycles");
int by1000 = pauseInTStates / 70000; int by1000 = pauseInTStates / 70000;
int rem1000 = pauseInTStates % 70000; int rem1000 = pauseInTStates % 70000;

View File

@ -1,7 +1,6 @@
using BizHawk.Common; using BizHawk.Common;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
namespace BizHawk.Emulation.Cores.Computers.AmstradCPC namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{ {

View File

@ -37,8 +37,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
/// </summary> /// </summary>
public static RomData InitROM(MachineType machineType, byte[] rom, ROMChipType type, int romPosition = 0) public static RomData InitROM(MachineType machineType, byte[] rom, ROMChipType type, int romPosition = 0)
{ {
RomData RD = new RomData(); RomData RD = new RomData { RomBytes = new byte[rom.Length] };
RD.RomBytes = new byte[rom.Length];
RD.RomBytes = rom; RD.RomBytes = rom;
RD.ROMType = type; RD.ROMType = type;

View File

@ -1,6 +1,4 @@
using System; namespace BizHawk.Emulation.Cores.Computers.Commodore64
namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
public sealed partial class Motherboard public sealed partial class Motherboard
{ {

View File

@ -13,113 +13,111 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
public static CartridgeDevice Load(byte[] crtFile) public static CartridgeDevice Load(byte[] crtFile)
{ {
using (var mem = new MemoryStream(crtFile)) using var mem = new MemoryStream(crtFile);
var reader = new BinaryReader(mem);
if (new string(reader.ReadChars(16)) != "C64 CARTRIDGE ")
{ {
var reader = new BinaryReader(mem); return null;
if (new string(reader.ReadChars(16)) != "C64 CARTRIDGE ")
{
return null;
}
var chipAddress = new List<int>();
var chipBank = new List<int>();
var chipData = new List<int[]>();
var chipType = new List<int>();
var headerLength = ReadCRTInt(reader);
var version = ReadCRTShort(reader);
var mapper = ReadCRTShort(reader);
var exrom = reader.ReadByte() != 0;
var game = reader.ReadByte() != 0;
// reserved
reader.ReadBytes(6);
// cartridge name
reader.ReadBytes(0x20);
// skip extra header bytes
if (headerLength > 0x40)
{
reader.ReadBytes(headerLength - 0x40);
}
// read chips
while (reader.PeekChar() >= 0)
{
if (new string(reader.ReadChars(4)) != "CHIP")
{
break;
}
var chipLength = ReadCRTInt(reader);
chipType.Add(ReadCRTShort(reader));
chipBank.Add(ReadCRTShort(reader));
chipAddress.Add(ReadCRTShort(reader));
var chipDataLength = ReadCRTShort(reader);
chipData.Add(reader.ReadBytes(chipDataLength).Select(x => (int)x).ToArray());
chipLength -= chipDataLength + 0x10;
if (chipLength > 0)
{
reader.ReadBytes(chipLength);
}
}
if (chipData.Count <= 0)
{
return null;
}
CartridgeDevice result;
switch (mapper)
{
case 0x0000: // Standard Cartridge
result = new Mapper0000(chipAddress, chipData, game, exrom);
break;
case 0x0001: // Action Replay (4.2 and up)
result = new Mapper0001(chipAddress, chipBank, chipData);
break;
case 0x0005: // Ocean
result = new Mapper0005(chipAddress, chipBank, chipData);
break;
case 0x0007: // Fun Play
result = new Mapper0007(chipData, game, exrom);
break;
case 0x0008: // SuperGame
result = new Mapper0008(chipData);
break;
case 0x000A: // Epyx FastLoad
result = new Mapper000A(chipData);
break;
case 0x000B: // Westermann Learning
result = new Mapper000B(chipAddress, chipData);
break;
case 0x000F: // C64 Game System / System 3
result = new Mapper000F(chipAddress, chipBank, chipData);
break;
case 0x0011: // Dinamic
result = new Mapper0011(chipAddress, chipBank, chipData);
break;
case 0x0012: // Zaxxon / Super Zaxxon
result = new Mapper0012(chipAddress, chipBank, chipData);
break;
case 0x0013: // Domark
result = new Mapper0013(chipAddress, chipBank, chipData);
break;
case 0x0020: // EasyFlash
result = new Mapper0020(chipAddress, chipBank, chipData);
break;
case 0x002B: // Prophet 64
result = new Mapper002B(chipAddress, chipBank, chipData);
break;
default:
throw new Exception("This cartridge file uses an unrecognized mapper: " + mapper);
}
result.HardReset();
return result;
} }
var chipAddress = new List<int>();
var chipBank = new List<int>();
var chipData = new List<int[]>();
var chipType = new List<int>();
var headerLength = ReadCRTInt(reader);
var version = ReadCRTShort(reader);
var mapper = ReadCRTShort(reader);
var exrom = reader.ReadByte() != 0;
var game = reader.ReadByte() != 0;
// reserved
reader.ReadBytes(6);
// cartridge name
reader.ReadBytes(0x20);
// skip extra header bytes
if (headerLength > 0x40)
{
reader.ReadBytes(headerLength - 0x40);
}
// read chips
while (reader.PeekChar() >= 0)
{
if (new string(reader.ReadChars(4)) != "CHIP")
{
break;
}
var chipLength = ReadCRTInt(reader);
chipType.Add(ReadCRTShort(reader));
chipBank.Add(ReadCRTShort(reader));
chipAddress.Add(ReadCRTShort(reader));
var chipDataLength = ReadCRTShort(reader);
chipData.Add(reader.ReadBytes(chipDataLength).Select(x => (int)x).ToArray());
chipLength -= chipDataLength + 0x10;
if (chipLength > 0)
{
reader.ReadBytes(chipLength);
}
}
if (chipData.Count <= 0)
{
return null;
}
CartridgeDevice result;
switch (mapper)
{
case 0x0000: // Standard Cartridge
result = new Mapper0000(chipAddress, chipData, game, exrom);
break;
case 0x0001: // Action Replay (4.2 and up)
result = new Mapper0001(chipAddress, chipBank, chipData);
break;
case 0x0005: // Ocean
result = new Mapper0005(chipAddress, chipBank, chipData);
break;
case 0x0007: // Fun Play
result = new Mapper0007(chipData, game, exrom);
break;
case 0x0008: // SuperGame
result = new Mapper0008(chipData);
break;
case 0x000A: // Epyx FastLoad
result = new Mapper000A(chipData);
break;
case 0x000B: // Westermann Learning
result = new Mapper000B(chipAddress, chipData);
break;
case 0x000F: // C64 Game System / System 3
result = new Mapper000F(chipAddress, chipBank, chipData);
break;
case 0x0011: // Dinamic
result = new Mapper0011(chipAddress, chipBank, chipData);
break;
case 0x0012: // Zaxxon / Super Zaxxon
result = new Mapper0012(chipAddress, chipBank, chipData);
break;
case 0x0013: // Domark
result = new Mapper0013(chipAddress, chipBank, chipData);
break;
case 0x0020: // EasyFlash
result = new Mapper0020(chipAddress, chipBank, chipData);
break;
case 0x002B: // Prophet 64
result = new Mapper002B(chipAddress, chipBank, chipData);
break;
default:
throw new Exception("This cartridge file uses an unrecognized mapper: " + mapper);
}
result.HardReset();
return result;
} }
private static int ReadCRTShort(BinaryReader reader) private static int ReadCRTShort(BinaryReader reader)

View File

@ -41,10 +41,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cassette
public void SyncState(Serializer ser) public void SyncState(Serializer ser)
{ {
ser.Sync("Connected", ref _connected); ser.Sync("Connected", ref _connected);
if (_device != null) _device?.SyncState(ser);
{
_device.SyncState(ser);
}
} }
public void Connect(CassettePortDevice device) public void Connect(CassettePortDevice device)

View File

@ -32,8 +32,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cassette
public override void SyncState(Serializer ser) public override void SyncState(Serializer ser)
{ {
_tape?.SyncState(ser);
if (_tape != null) { _tape.SyncState(ser); }
} }
public void Insert(Tape tape) public void Insert(Tape tape)
@ -47,19 +46,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cassette
} }
// Exposed for memory domains, should not be used for actual emulation implementation // Exposed for memory domains, should not be used for actual emulation implementation
public override byte[] TapeDataDomain public override byte[] TapeDataDomain => _tape?.TapeDataDomain;
{
get
{
if (_tape != null)
{
return _tape.TapeDataDomain;
}
else
{
return null;
}
}
}
} }
} }

View File

@ -13,11 +13,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
public string Cpu public string Cpu
{ {
get get => "6510";
{
return "6510";
}
set set
{ {
} }

View File

@ -1,7 +1,4 @@
using BizHawk.Common.NumberExtensions; namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
using System;
namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
public sealed partial class Cia public sealed partial class Cia
{ {

View File

@ -146,10 +146,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
public int Attack public int Attack
{ {
get get => _attack;
{
return _attack;
}
set set
{ {
_attack = value & 0xF; _attack = value & 0xF;
@ -160,10 +157,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
public int Decay public int Decay
{ {
get get => _decay;
{
return _decay;
}
set set
{ {
_decay = value & 0xF; _decay = value & 0xF;
@ -174,10 +168,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
public bool Gate public bool Gate
{ {
get get => _gate;
{
return _gate;
}
set set
{ {
var nextGate = value; var nextGate = value;
@ -197,20 +188,11 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
} }
} }
public int Level public int Level => _envCounter;
{
get
{
return _envCounter;
}
}
public int Release public int Release
{ {
get get => _release;
{
return _release;
}
set set
{ {
_release = value & 0xF; _release = value & 0xF;
@ -221,14 +203,8 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
public int Sustain public int Sustain
{ {
get get => _sustain;
{ set => _sustain = value & 0xF;
return _sustain;
}
set
{
_sustain = value & 0xF;
}
} }
// ------------------------------------ // ------------------------------------

View File

@ -179,10 +179,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
public int FrequencyLo public int FrequencyLo
{ {
get get => _frequency & 0xFF;
{
return _frequency & 0xFF;
}
set set
{ {
_frequency &= 0xFF00; _frequency &= 0xFF00;
@ -192,10 +189,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
public int FrequencyHi public int FrequencyHi
{ {
get get => _frequency >> 8;
{
return _frequency >> 8;
}
set set
{ {
_frequency &= 0x00FF; _frequency &= 0x00FF;
@ -205,37 +199,30 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
public int Output(Voice ringModSource) public int Output(Voice ringModSource)
{ {
if (_waveform != 0)
{ {
if (_waveform != 0) _waveformIndex = (_accumulator ^ (ringModSource._accumulator & _ringMsbMask)) >> 12;
_output = _wave[_waveformIndex] & (_noPulse | _pulse) & _noNoiseOrNoise;
if (_waveform > 8)
{ {
_waveformIndex = (_accumulator ^ (ringModSource._accumulator & _ringMsbMask)) >> 12; WriteShiftReg();
_output = _wave[_waveformIndex] & (_noPulse | _pulse) & _noNoiseOrNoise;
if (_waveform > 8)
{
WriteShiftReg();
}
} }
else
{
if (_floatOutputTtl != 0 && --_floatOutputTtl == 0)
{
_output = 0x000;
}
}
_pulse = _accumulator >> 12 >= _pulseWidth ? 0xFFF : 0x000;
return _output;
} }
else
{
if (_floatOutputTtl != 0 && --_floatOutputTtl == 0)
{
_output = 0x000;
}
}
_pulse = _accumulator >> 12 >= _pulseWidth ? 0xFFF : 0x000;
return _output;
} }
public int PulseWidthLo public int PulseWidthLo
{ {
get get => _pulseWidth & 0xFF;
{
return _pulseWidth & 0xFF;
}
set set
{ {
_pulseWidth &= 0x0F00; _pulseWidth &= 0x0F00;
@ -245,11 +232,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
public int PulseWidthHi public int PulseWidthHi
{ {
get get => _pulseWidth >> 8;
{
return _pulseWidth >> 8;
}
set set
{ {
_pulseWidth &= 0x00FF; _pulseWidth &= 0x00FF;
@ -304,6 +287,5 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
_wave = _waveTable[_waveform & 0x07]; _wave = _waveTable[_waveform & 0x07];
} }
} }
} }
} }

View File

@ -102,40 +102,38 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
private static byte[] ConvertSectorToGcr(byte[] source, byte sectorNo, byte trackNo, byte formatA, byte formatB, int gapLength, ErrorType errorType, out int bitsWritten) private static byte[] ConvertSectorToGcr(byte[] source, byte sectorNo, byte trackNo, byte formatA, byte formatB, int gapLength, ErrorType errorType, out int bitsWritten)
{ {
using (var mem = new MemoryStream()) using var mem = new MemoryStream();
using var writer = new BinaryWriter(mem);
if (errorType == ErrorType.IdMismatch)
{ {
var writer = new BinaryWriter(mem); formatA ^= 0xFF;
formatB ^= 0xFF;
if (errorType == ErrorType.IdMismatch)
{
formatA ^= 0xFF;
formatB ^= 0xFF;
}
var headerChecksum = (byte)(sectorNo ^ trackNo ^ formatA ^ formatB ^ (errorType == ErrorType.HeaderChecksumError ? 0xFF : 0x00));
// assemble written data for GCR encoding
var writtenData = new byte[260];
var syncBytes40 = Enumerable.Repeat((byte) (errorType == ErrorType.NoSyncSequence ? 0x00 : 0xFF), 5).ToArray();
Array.Copy(source, 0, writtenData, 1, 256);
writtenData[0] = (byte)(errorType == ErrorType.HeaderNotFound ? 0x00 : 0x07);
writtenData[0x101] = (byte)(Checksum(source) ^ (errorType == ErrorType.DataChecksumError ? 0xFF : 0x00));
writtenData[0x102] = 0x00;
writtenData[0x103] = 0x00;
writer.Write(syncBytes40); // sync
writer.Write(EncodeGcr(new byte[] { (byte)(errorType == ErrorType.DataNotFound ? 0x00 : 0x08), headerChecksum, sectorNo, trackNo, formatA, formatB, 0x0F, 0x0F })); // header
writer.Write(new byte[] { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 }); // gap
writer.Write(syncBytes40); // sync
writer.Write(EncodeGcr(writtenData)); // data
writer.Write(Enumerable.Repeat((byte)0x55, gapLength).ToArray()); // gap
bitsWritten = (int)mem.Length * 8;
writer.Flush();
return mem.ToArray();
} }
var headerChecksum = (byte)(sectorNo ^ trackNo ^ formatA ^ formatB ^ (errorType == ErrorType.HeaderChecksumError ? 0xFF : 0x00));
// assemble written data for GCR encoding
var writtenData = new byte[260];
var syncBytes40 = Enumerable.Repeat((byte) (errorType == ErrorType.NoSyncSequence ? 0x00 : 0xFF), 5).ToArray();
Array.Copy(source, 0, writtenData, 1, 256);
writtenData[0] = (byte)(errorType == ErrorType.HeaderNotFound ? 0x00 : 0x07);
writtenData[0x101] = (byte)(Checksum(source) ^ (errorType == ErrorType.DataChecksumError ? 0xFF : 0x00));
writtenData[0x102] = 0x00;
writtenData[0x103] = 0x00;
writer.Write(syncBytes40); // sync
writer.Write(EncodeGcr(new byte[] { (byte)(errorType == ErrorType.DataNotFound ? 0x00 : 0x08), headerChecksum, sectorNo, trackNo, formatA, formatB, 0x0F, 0x0F })); // header
writer.Write(new byte[] { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 }); // gap
writer.Write(syncBytes40); // sync
writer.Write(EncodeGcr(writtenData)); // data
writer.Write(Enumerable.Repeat((byte)0x55, gapLength).ToArray()); // gap
bitsWritten = (int)mem.Length * 8;
writer.Flush();
return mem.ToArray();
} }
private static byte[] EncodeGcr(byte[] source) private static byte[] EncodeGcr(byte[] source)
@ -144,39 +142,37 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
var gcr = new int[8]; var gcr = new int[8];
var data = new byte[4]; var data = new byte[4];
var count = source.Length; var count = source.Length;
using (var mem = new MemoryStream()) using var mem = new MemoryStream();
var writer = new BinaryWriter(mem);
for (var i = 0; i < count; i += 4)
{ {
var writer = new BinaryWriter(mem); Array.Copy(source, i, data, 0, 4);
gcr[0] = GcrEncodeTable[data[0] >> 4];
gcr[1] = GcrEncodeTable[data[0] & 0xF];
gcr[2] = GcrEncodeTable[data[1] >> 4];
gcr[3] = GcrEncodeTable[data[1] & 0xF];
gcr[4] = GcrEncodeTable[data[2] >> 4];
gcr[5] = GcrEncodeTable[data[2] & 0xF];
gcr[6] = GcrEncodeTable[data[3] >> 4];
gcr[7] = GcrEncodeTable[data[3] & 0xF];
for (var i = 0; i < count; i += 4) // -------- -------- -------- -------- --------
{ // 00000111 11222223 33334444 45555566 66677777
Array.Copy(source, i, data, 0, 4);
gcr[0] = GcrEncodeTable[data[0] >> 4];
gcr[1] = GcrEncodeTable[data[0] & 0xF];
gcr[2] = GcrEncodeTable[data[1] >> 4];
gcr[3] = GcrEncodeTable[data[1] & 0xF];
gcr[4] = GcrEncodeTable[data[2] >> 4];
gcr[5] = GcrEncodeTable[data[2] & 0xF];
gcr[6] = GcrEncodeTable[data[3] >> 4];
gcr[7] = GcrEncodeTable[data[3] & 0xF];
// -------- -------- -------- -------- -------- var outputValue = (gcr[0] << 3) | (gcr[1] >> 2);
// 00000111 11222223 33334444 45555566 66677777 writer.Write((byte)(outputValue & 0xFF));
outputValue = (gcr[1] << 6) | (gcr[2] << 1) | (gcr[3] >> 4);
var outputValue = (gcr[0] << 3) | (gcr[1] >> 2); writer.Write((byte)(outputValue & 0xFF));
writer.Write((byte)(outputValue & 0xFF)); outputValue = (gcr[3] << 4) | (gcr[4] >> 1);
outputValue = (gcr[1] << 6) | (gcr[2] << 1) | (gcr[3] >> 4); writer.Write((byte)(outputValue & 0xFF));
writer.Write((byte)(outputValue & 0xFF)); outputValue = (gcr[4] << 7) | (gcr[5] << 2) | (gcr[6] >> 3);
outputValue = (gcr[3] << 4) | (gcr[4] >> 1); writer.Write((byte)(outputValue & 0xFF));
writer.Write((byte)(outputValue & 0xFF)); outputValue = (gcr[6] << 5) | (gcr[7]);
outputValue = (gcr[4] << 7) | (gcr[5] << 2) | (gcr[6] >> 3); writer.Write((byte)(outputValue & 0xFF));
writer.Write((byte)(outputValue & 0xFF));
outputValue = (gcr[6] << 5) | (gcr[7]);
writer.Write((byte)(outputValue & 0xFF));
}
writer.Flush();
return mem.ToArray();
} }
writer.Flush();
return mem.ToArray();
} }
public static Disk Read(byte[] source) public static Disk Read(byte[] source)
@ -184,73 +180,69 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
var formatB = source[D64_DISK_ID_OFFSET + 0x00]; var formatB = source[D64_DISK_ID_OFFSET + 0x00];
var formatA = source[D64_DISK_ID_OFFSET + 0x01]; var formatA = source[D64_DISK_ID_OFFSET + 0x01];
using (var mem = new MemoryStream(source)) using var mem = new MemoryStream(source);
var reader = new BinaryReader(mem);
var trackDatas = new List<byte[]>();
var trackLengths = new List<int>();
var trackNumbers = new List<int>();
var trackDensities = new List<int>();
var errorType = ErrorType.NoError;
int trackCount;
int errorOffset = -1;
switch (source.Length)
{ {
var reader = new BinaryReader(mem); case 174848: // 35 tracks no errors
var trackDatas = new List<byte[]>(); trackCount = 35;
var trackLengths = new List<int>(); break;
var trackNumbers = new List<int>(); case 175531: // 35 tracks with errors
var trackDensities = new List<int>(); trackCount = 35;
var errorType = ErrorType.NoError; errorOffset = 174848;
int trackCount; break;
int errorOffset = -1; case 196608: // 40 tracks no errors
trackCount = 40;
switch (source.Length) break;
{ case 197376: // 40 tracks with errors
case 174848: // 35 tracks no errors trackCount = 40;
trackCount = 35; errorOffset = 196608;
break; break;
case 175531: // 35 tracks with errors default:
trackCount = 35; throw new Exception("Not able to identify capacity of the D64 file.");
errorOffset = 174848;
break;
case 196608: // 40 tracks no errors
trackCount = 40;
break;
case 197376: // 40 tracks with errors
trackCount = 40;
errorOffset = 196608;
break;
default:
throw new Exception("Not able to identify capacity of the D64 file.");
}
for (var i = 0; i < trackCount; i++)
{
if (errorOffset >= 0)
{
errorType = (ErrorType) source[errorOffset];
errorOffset++;
}
var sectors = SectorsPerTrack[i];
var trackLengthBits = 0;
using (var trackMem = new MemoryStream())
{
for (var j = 0; j < sectors; j++)
{
int bitsWritten;
var sectorData = reader.ReadBytes(256);
var diskData = ConvertSectorToGcr(sectorData, (byte)j, (byte)(i + 1), formatA, formatB, StandardSectorGapLength[DensityTable[i]], errorType, out bitsWritten);
trackMem.Write(diskData, 0, diskData.Length);
trackLengthBits += bitsWritten;
}
var density = DensityTable[i];
// we pad the tracks with extra gap bytes to meet MNIB standards
while (trackMem.Length < StandardTrackLengthBytes[density])
{
trackMem.WriteByte(0x55);
}
trackDatas.Add(trackMem.ToArray());
trackLengths.Add(trackLengthBits);
trackNumbers.Add(i * 2);
trackDensities.Add(DensityTable[i]);
}
}
return new Disk(trackDatas, trackNumbers, trackDensities, 84) {WriteProtected = false};
} }
for (var i = 0; i < trackCount; i++)
{
if (errorOffset >= 0)
{
errorType = (ErrorType) source[errorOffset];
errorOffset++;
}
var sectors = SectorsPerTrack[i];
var trackLengthBits = 0;
using var trackMem = new MemoryStream();
for (var j = 0; j < sectors; j++)
{
int bitsWritten;
var sectorData = reader.ReadBytes(256);
var diskData = ConvertSectorToGcr(sectorData, (byte)j, (byte)(i + 1), formatA, formatB, StandardSectorGapLength[DensityTable[i]], errorType, out bitsWritten);
trackMem.Write(diskData, 0, diskData.Length);
trackLengthBits += bitsWritten;
}
var density = DensityTable[i];
// we pad the tracks with extra gap bytes to meet MNIB standards
while (trackMem.Length < StandardTrackLengthBytes[density])
{
trackMem.WriteByte(0x55);
}
trackDatas.Add(trackMem.ToArray());
trackLengths.Add(trackLengthBits);
trackNumbers.Add(i * 2);
trackDensities.Add(DensityTable[i]);
}
return new Disk(trackDatas, trackNumbers, trackDensities, 84) {WriteProtected = false};
} }
} }
} }

View File

@ -67,11 +67,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
public bool this[int sector] public bool this[int sector]
{ {
get get => (Data & (1 << sector)) != 0;
{
return (Data & (1 << sector)) != 0;
}
set set
{ {
if (value) if (value)

View File

@ -9,59 +9,57 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
{ {
public static Disk Read(byte[] source) public static Disk Read(byte[] source)
{ {
using (var mem = new MemoryStream(source)) using var mem = new MemoryStream(source);
using var reader = new BinaryReader(mem);
var id = new string(reader.ReadChars(8));
var trackDatas = new List<byte[]>();
var trackLengths = new List<int>();
var trackNumbers = new List<int>();
var trackDensities = new List<int>();
if (id == @"GCR-1541")
{ {
var reader = new BinaryReader(mem); reader.ReadByte(); // version
var id = new string(reader.ReadChars(8)); int trackCount = reader.ReadByte();
var trackDatas = new List<byte[]>(); reader.ReadInt16(); // max track size in bytes
var trackLengths = new List<int>();
var trackNumbers = new List<int>();
var trackDensities = new List<int>();
if (id == @"GCR-1541") var trackOffsetTable = new int[trackCount];
var trackSpeedTable = new int[trackCount];
for (var i = 0; i < trackCount; i++)
{ {
reader.ReadByte(); // version trackOffsetTable[i] = reader.ReadInt32();
int trackCount = reader.ReadByte();
reader.ReadInt16(); // max track size in bytes
var trackOffsetTable = new int[trackCount];
var trackSpeedTable = new int[trackCount];
for (var i = 0; i < trackCount; i++)
{
trackOffsetTable[i] = reader.ReadInt32();
}
for (var i = 0; i < trackCount; i++)
{
trackSpeedTable[i] = reader.ReadInt32();
}
for (var i = 0; i < trackCount; i++)
{
if (trackOffsetTable[i] > 0)
{
mem.Position = trackOffsetTable[i];
int trackLength = reader.ReadInt16();
var trackData = reader.ReadBytes(trackLength);
trackDatas.Add(trackData);
trackLengths.Add(trackLength * 8);
trackDensities.Add(trackSpeedTable[i]);
trackNumbers.Add(i);
}
}
if (trackSpeedTable.Any(ts => ts > 3 || ts < 0))
{
throw new Exception("Byte-level speeds are not yet supported in the G64 loader.");
}
return new Disk(trackDatas, trackNumbers, trackDensities, 84) {WriteProtected = true};
} }
return new Disk(84) {WriteProtected = false}; for (var i = 0; i < trackCount; i++)
{
trackSpeedTable[i] = reader.ReadInt32();
}
for (var i = 0; i < trackCount; i++)
{
if (trackOffsetTable[i] > 0)
{
mem.Position = trackOffsetTable[i];
int trackLength = reader.ReadInt16();
var trackData = reader.ReadBytes(trackLength);
trackDatas.Add(trackData);
trackLengths.Add(trackLength * 8);
trackDensities.Add(trackSpeedTable[i]);
trackNumbers.Add(i);
}
}
if (trackSpeedTable.Any(ts => ts > 3 || ts < 0))
{
throw new Exception("Byte-level speeds are not yet supported in the G64 loader.");
}
return new Disk(trackDatas, trackNumbers, trackDensities, 84) {WriteProtected = true};
} }
return new Disk(84) {WriteProtected = false};
} }
public static byte[] Write(IList<byte[]> trackData, IList<int> trackNumbers, IList<int> trackDensities) public static byte[] Write(IList<byte[]> trackData, IList<int> trackNumbers, IList<int> trackDensities)
@ -73,70 +71,68 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
var trackMaxLength = (ushort)Math.Max(7928, trackData.Max(d => d.Length)); var trackMaxLength = (ushort)Math.Max(7928, trackData.Max(d => d.Length));
using (var mem = new MemoryStream()) using var mem = new MemoryStream();
using var writer = new BinaryWriter(mem);
// header ID
writer.Write("GCR-1541".ToCharArray());
// version #
writer.Write(version);
// tracks in the image
writer.Write(trackCount);
// maximum track size in bytes
writer.Write(trackMaxLength);
// combine track data
var offsets = new List<int>();
var densities = new List<int>();
using (var trackMem = new MemoryStream())
{ {
var writer = new BinaryWriter(mem); var trackMemWriter = new BinaryWriter(trackMem);
for (var i = 0; i < trackCount; i++)
// header ID
writer.Write("GCR-1541".ToCharArray());
// version #
writer.Write(version);
// tracks in the image
writer.Write(trackCount);
// maximum track size in bytes
writer.Write(trackMaxLength);
// combine track data
var offsets = new List<int>();
var densities = new List<int>();
using (var trackMem = new MemoryStream())
{ {
var trackMemWriter = new BinaryWriter(trackMem); if (trackNumbers.Contains(i))
for (var i = 0; i < trackCount; i++)
{ {
if (trackNumbers.Contains(i)) var trackIndex = trackNumbers.IndexOf(i);
{ offsets.Add((int)trackMem.Length);
var trackIndex = trackNumbers.IndexOf(i); densities.Add(trackDensities[trackIndex]);
offsets.Add((int)trackMem.Length);
densities.Add(trackDensities[trackIndex]);
var data = trackData[trackIndex]; var data = trackData[trackIndex];
var buffer = Enumerable.Repeat(dataFillerValue, trackMaxLength).ToArray(); var buffer = Enumerable.Repeat(dataFillerValue, trackMaxLength).ToArray();
var dataBytes = data.Select(d => unchecked((byte)d)).ToArray(); var dataBytes = data.Select(d => unchecked((byte)d)).ToArray();
Array.Copy(dataBytes, buffer, dataBytes.Length); Array.Copy(dataBytes, buffer, dataBytes.Length);
trackMemWriter.Write((ushort)dataBytes.Length); trackMemWriter.Write((ushort)dataBytes.Length);
trackMemWriter.Write(buffer); trackMemWriter.Write(buffer);
}
else
{
offsets.Add(-1);
densities.Add(0);
}
} }
trackMemWriter.Flush(); else
// offset table
foreach (var offset in offsets.Select(o => o >= 0 ? o + headerLength + trackCount * 8 : 0))
{ {
writer.Write(offset); offsets.Add(-1);
densities.Add(0);
} }
}
trackMemWriter.Flush();
// speed zone data // offset table
foreach (var density in densities) foreach (var offset in offsets.Select(o => o >= 0 ? o + headerLength + trackCount * 8 : 0))
{ {
writer.Write(density); writer.Write(offset);
}
// track data
writer.Write(trackMem.ToArray());
} }
writer.Flush(); // speed zone data
return mem.ToArray(); foreach (var density in densities)
{
writer.Write(density);
}
// track data
writer.Write(trackMem.ToArray());
} }
writer.Flush();
return mem.ToArray();
} }
} }
} }

View File

@ -12,10 +12,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Serial
string IDisassemblable.Cpu string IDisassemblable.Cpu
{ {
get get => "Disk Drive 6502";
{
return "Disk Drive 6502";
}
set set
{ {

View File

@ -70,7 +70,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Serial
public override void SyncState(Serializer ser) public override void SyncState(Serializer ser)
{ {
ser.BeginSection("Disk"); ser.BeginSection("Disk");
if (_disk != null) { _disk.SyncState(ser); } _disk?.SyncState(ser);
ser.EndSection(); ser.EndSection();
ser.Sync("BitHistory", ref _bitHistory); ser.Sync("BitHistory", ref _bitHistory);

View File

@ -1,6 +1,5 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using BizHawk.Emulation.Common;
using System.Text; using System.Text;
namespace BizHawk.Emulation.Cores.Computers.MSX namespace BizHawk.Emulation.Cores.Computers.MSX

View File

@ -7,13 +7,7 @@ namespace BizHawk.Emulation.Cores.Computers.MSX
{ {
public IEmulatorServiceProvider ServiceProvider { get; } public IEmulatorServiceProvider ServiceProvider { get; }
public ControllerDefinition ControllerDefinition public ControllerDefinition ControllerDefinition => current_controller;
{
get
{
return current_controller;
}
}
public bool FrameAdvance(IController controller, bool render, bool rendersound) public bool FrameAdvance(IController controller, bool render, bool rendersound)
{ {
@ -182,7 +176,7 @@ namespace BizHawk.Emulation.Cores.Computers.MSX
const int blipbuffsize = 4500; const int blipbuffsize = 4500;
public bool CanProvideAsync { get { return false; } } public bool CanProvideAsync => false;
public void SetSyncMode(SyncSoundMode mode) public void SetSyncMode(SyncSoundMode mode)
{ {
@ -197,10 +191,7 @@ namespace BizHawk.Emulation.Cores.Computers.MSX
throw new NotSupportedException("Async not supported"); throw new NotSupportedException("Async not supported");
} }
public SyncSoundMode SyncMode public SyncSoundMode SyncMode => SyncSoundMode.Sync;
{
get { return SyncSoundMode.Sync; }
}
public void GetSamplesSync(out short[] samples, out int nsamp) public void GetSamplesSync(out short[] samples, out int nsamp)
{ {

View File

@ -1,5 +1,4 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;

View File

@ -8,14 +8,7 @@ namespace BizHawk.Emulation.Cores.Computers.MSX
{ {
public byte[] CloneSaveRam() public byte[] CloneSaveRam()
{ {
if (SaveRAM != null) return (byte[]) SaveRAM?.Clone();
{
return (byte[])SaveRAM.Clone();
}
else
{
return null;
}
} }
public void StoreSaveRam(byte[] data) public void StoreSaveRam(byte[] data)

View File

@ -1,8 +1,4 @@
using System; using System.ComponentModel;
using System.ComponentModel;
using Newtonsoft.Json;
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;

View File

@ -1,6 +1,4 @@
using System; using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Computers.MSX namespace BizHawk.Emulation.Cores.Computers.MSX
{ {

View File

@ -77,7 +77,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
get get
{ {
if (_position >= _dataBlocks[_currentDataBlockIndex].DataPeriods.Count) { return 0; } if (_position >= _dataBlocks[_currentDataBlockIndex].DataPeriods.Count) { return 0; }
else { return _position; }
return _position;
} }
} }
@ -85,10 +86,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// Signs whether the tape is currently playing or not /// Signs whether the tape is currently playing or not
/// </summary> /// </summary>
private bool _tapeIsPlaying = false; private bool _tapeIsPlaying = false;
public bool TapeIsPlaying public bool TapeIsPlaying => _tapeIsPlaying;
{
get { return _tapeIsPlaying; }
}
/// <summary> /// <summary>
/// A list of the currently loaded data blocks /// A list of the currently loaded data blocks

View File

@ -5,331 +5,318 @@ using System.Linq;
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{ {
/// <summary> /// <summary>
/// Floppy drive related stuff /// Floppy drive related stuff
/// </summary> /// </summary>
#region Attribution #region Attribution
/* /*
Implementation based on the information contained here: Implementation based on the information contained here:
http://www.cpcwiki.eu/index.php/765_FDC http://www.cpcwiki.eu/index.php/765_FDC
and here: and here:
http://www.cpcwiki.eu/imgs/f/f3/UPD765_Datasheet_OCRed.pdf http://www.cpcwiki.eu/imgs/f/f3/UPD765_Datasheet_OCRed.pdf
*/ */
#endregion #endregion
public partial class NECUPD765 : IFDDHost public partial class NECUPD765 : IFDDHost
{ {
#region Drive State #region Drive State
/// <summary> /// <summary>
/// FDD Flag - motor on/off /// FDD Flag - motor on/off
/// </summary> /// </summary>
public bool FDD_FLAG_MOTOR; public bool FDD_FLAG_MOTOR;
/// <summary> /// <summary>
/// The index of the currently active disk drive /// The index of the currently active disk drive
/// </summary> /// </summary>
public int DiskDriveIndex public int DiskDriveIndex
{ {
get => _diskDriveIndex; get => _diskDriveIndex;
set set
{ {
// when index is changed update the ActiveDrive // when index is changed update the ActiveDrive
_diskDriveIndex = value; _diskDriveIndex = value;
ActiveDrive = DriveStates[_diskDriveIndex]; ActiveDrive = DriveStates[_diskDriveIndex];
} }
} }
private int _diskDriveIndex = 0; private int _diskDriveIndex = 0;
/// <summary> /// <summary>
/// The currently active drive /// The currently active drive
/// </summary> /// </summary>
private DriveState ActiveDrive; private DriveState ActiveDrive;
/// <summary> /// <summary>
/// Array that holds state information for each possible drive /// Array that holds state information for each possible drive
/// </summary> /// </summary>
private DriveState[] DriveStates = new DriveState[4]; private DriveState[] DriveStates = new DriveState[4];
#endregion #endregion
#region FDD Methods #region FDD Methods
/// <summary> /// <summary>
/// Initialization / reset of the floppy drive subsystem /// Initialization / reset of the floppy drive subsystem
/// </summary> /// </summary>
private void FDD_Init() private void FDD_Init()
{ {
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
DriveState ds = new DriveState(i, this); DriveState ds = new DriveState(i, this);
DriveStates[i] = ds; DriveStates[i] = ds;
} }
} }
/// <summary> /// <summary>
/// Searches for the requested sector /// Searches for the requested sector
/// </summary> /// </summary>
private FloppyDisk.Sector GetSector() private FloppyDisk.Sector GetSector()
{ {
FloppyDisk.Sector sector = null; FloppyDisk.Sector sector = null;
// get the current track // get the current track
var trk = ActiveDrive.Disk.DiskTracks[ActiveDrive.TrackIndex]; var trk = ActiveDrive.Disk.DiskTracks[ActiveDrive.TrackIndex];
// get the current sector index // get the current sector index
int index = ActiveDrive.SectorIndex; int index = ActiveDrive.SectorIndex;
// make sure this index exists // make sure this index exists
if (index > trk.Sectors.Length) if (index > trk.Sectors.Length)
{ {
index = 0; index = 0;
} }
// index hole count // index hole count
int iHole = 0; int iHole = 0;
// loop through the sectors in a track // loop through the sectors in a track
// the loop ends with either the sector being found // the loop ends with either the sector being found
// or the index hole being passed twice // or the index hole being passed twice
while (iHole <= 2) while (iHole <= 2)
{ {
// does the requested sector match the current sector // does the requested sector match the current sector
if (trk.Sectors[index].SectorIDInfo.C == ActiveCommandParams.Cylinder && if (trk.Sectors[index].SectorIDInfo.C == ActiveCommandParams.Cylinder &&
trk.Sectors[index].SectorIDInfo.H == ActiveCommandParams.Head && trk.Sectors[index].SectorIDInfo.H == ActiveCommandParams.Head &&
trk.Sectors[index].SectorIDInfo.R == ActiveCommandParams.Sector && trk.Sectors[index].SectorIDInfo.R == ActiveCommandParams.Sector &&
trk.Sectors[index].SectorIDInfo.N == ActiveCommandParams.SectorSize) trk.Sectors[index].SectorIDInfo.N == ActiveCommandParams.SectorSize)
{ {
// sector has been found // sector has been found
sector = trk.Sectors[index]; sector = trk.Sectors[index];
UnSetBit(SR2_BC, ref Status2); UnSetBit(SR2_BC, ref Status2);
UnSetBit(SR2_WC, ref Status2); UnSetBit(SR2_WC, ref Status2);
break; break;
} }
// check for bad cylinder // check for bad cylinder
if (trk.Sectors[index].SectorIDInfo.C == 255) if (trk.Sectors[index].SectorIDInfo.C == 255)
{ {
SetBit(SR2_BC, ref Status2); SetBit(SR2_BC, ref Status2);
} }
// check for no cylinder // check for no cylinder
else if (trk.Sectors[index].SectorIDInfo.C != ActiveCommandParams.Cylinder) else if (trk.Sectors[index].SectorIDInfo.C != ActiveCommandParams.Cylinder)
{ {
SetBit(SR2_WC, ref Status2); SetBit(SR2_WC, ref Status2);
} }
// incrememnt sector index // incrememnt sector index
index++; index++;
// have we reached the index hole? // have we reached the index hole?
if (trk.Sectors.Length <= index) if (trk.Sectors.Length <= index)
{ {
// wrap around // wrap around
index = 0; index = 0;
iHole++; iHole++;
} }
} }
// search loop has completed and the sector may or may not have been found // search loop has completed and the sector may or may not have been found
// bad cylinder detected? // bad cylinder detected?
if (Status2.Bit(SR2_BC)) if (Status2.Bit(SR2_BC))
{ {
// remove WC // remove WC
UnSetBit(SR2_WC, ref Status2); UnSetBit(SR2_WC, ref Status2);
} }
// update sectorindex on drive // update sectorindex on drive
ActiveDrive.SectorIndex = index; ActiveDrive.SectorIndex = index;
return sector; return sector;
} }
#endregion #endregion
#region IFDDHost #region IFDDHost
// IFDDHost methods that fall through to the currently active drive // IFDDHost methods that fall through to the currently active drive
/// <summary> /// <summary>
/// Parses a new disk image and loads it into this floppy drive /// Parses a new disk image and loads it into this floppy drive
/// </summary> /// </summary>
public void FDD_LoadDisk(byte[] diskData) public void FDD_LoadDisk(byte[] diskData)
{ {
// we are only going to load into the first drive // we are only going to load into the first drive
DriveStates[0].FDD_LoadDisk(diskData); DriveStates[0].FDD_LoadDisk(diskData);
} }
/// <summary> /// <summary>
/// Ejects the current disk /// Ejects the current disk
/// </summary> /// </summary>
public void FDD_EjectDisk() public void FDD_EjectDisk()
{ {
DriveStates[0].FDD_EjectDisk(); DriveStates[0].FDD_EjectDisk();
} }
/// <summary> /// <summary>
/// Signs whether the current active drive has a disk inserted /// Signs whether the current active drive has a disk inserted
/// </summary> /// </summary>
public bool FDD_IsDiskLoaded public bool FDD_IsDiskLoaded => DriveStates[DiskDriveIndex].FDD_IsDiskLoaded;
{
get { return DriveStates[DiskDriveIndex].FDD_IsDiskLoaded; }
}
/// <summary> /// <summary>
/// Returns the disk object from drive 0 /// Returns the disk object from drive 0
/// </summary> /// </summary>
public FloppyDisk DiskPointer public FloppyDisk DiskPointer => DriveStates[0].Disk;
{
get { return DriveStates[0].Disk; }
}
public FloppyDisk Disk { get; set; }
#endregion public FloppyDisk Disk { get; set; }
#region Drive Status Class #endregion
/// <summary> #region Drive Status Class
/// Holds specfic state information about a drive
/// </summary>
private class DriveState : IFDDHost
{
#region State
/// <summary> /// <summary>
/// The drive ID from an FDC perspective /// Holds specfic state information about a drive
/// </summary> /// </summary>
public int ID; private class DriveState : IFDDHost
{
#region State
/// <summary> /// <summary>
/// Signs whether this drive ready /// The drive ID from an FDC perspective
/// TRUE if both drive exists and has a disk inserted /// </summary>
/// </summary> public int ID;
public bool FLAG_READY
{
get
{
if (!FDD_IsDiskLoaded || Disk.GetTrackCount() == 0 || !FDC.FDD_FLAG_MOTOR)
return false;
else
return true;
}
}
/// <summary> /// <summary>
/// Disk is write protected (TRUE BY DEFAULT) /// Signs whether this drive ready
/// </summary> /// TRUE if both drive exists and has a disk inserted
public bool FLAG_WRITEPROTECT = false; /// </summary>
public bool FLAG_READY
{
get
{
if (!FDD_IsDiskLoaded || Disk.GetTrackCount() == 0 || !FDC.FDD_FLAG_MOTOR)
return false;
else
return true;
}
}
/// <summary> /// <summary>
/// Storage for seek steps /// Disk is write protected (TRUE BY DEFAULT)
/// One step for each indexpulse (track index) until seeked track /// </summary>
/// </summary> public bool FLAG_WRITEPROTECT = false;
public int SeekCounter;
/// <summary> /// <summary>
/// Seek status /// Storage for seek steps
/// </summary> /// One step for each indexpulse (track index) until seeked track
public int SeekStatus; /// </summary>
public int SeekCounter;
/// <summary> /// <summary>
/// Age counter /// Seek status
/// </summary> /// </summary>
public int SeekAge; public int SeekStatus;
/// <summary> /// <summary>
/// The current side /// Age counter
/// </summary> /// </summary>
public byte CurrentSide; public int SeekAge;
/// <summary> /// <summary>
/// The current track index in the DiskTracks array /// The current side
/// </summary> /// </summary>
public byte TrackIndex; public byte CurrentSide;
/// <summary> /// <summary>
/// The track ID of the current cylinder /// The current track index in the DiskTracks array
/// </summary> /// </summary>
public byte CurrentTrackID public byte TrackIndex;
{
get
{
// default invalid track
int id = 0xff;
if (Disk == null) /// <summary>
return (byte)id; /// The track ID of the current cylinder
/// </summary>
public byte CurrentTrackID
{
get
{
// default invalid track
int id = 0xff;
if (Disk.DiskTracks.Count() == 0) if (Disk == null)
return (byte)id; return (byte)id;
if (TrackIndex >= Disk.GetTrackCount()) if (Disk.DiskTracks.Count() == 0)
TrackIndex = 0; return (byte)id;
else if (TrackIndex < 0)
TrackIndex = 0;
var track = Disk.DiskTracks[TrackIndex]; if (TrackIndex >= Disk.GetTrackCount())
TrackIndex = 0;
else if (TrackIndex < 0)
TrackIndex = 0;
id = track.TrackNumber; var track = Disk.DiskTracks[TrackIndex];
return (byte)id; id = track.TrackNumber;
}
set return (byte)id;
{ }
for (int i = 0; i < Disk.GetTrackCount(); i++) set
{ {
if (Disk.DiskTracks[i].TrackNumber == value) for (int i = 0; i < Disk.GetTrackCount(); i++)
{ {
TrackIndex = (byte)i; if (Disk.DiskTracks[i].TrackNumber == value)
break; {
} TrackIndex = (byte)i;
} break;
} }
} }
}
}
/// <summary> /// <summary>
/// The new track that the drive is seeking to /// The new track that the drive is seeking to
/// (used in seek operations) /// (used in seek operations)
/// </summary> /// </summary>
public int SeekingTrack; public int SeekingTrack;
/// <summary> /// <summary>
/// The current sector index in the Sectors array /// The current sector index in the Sectors array
/// </summary> /// </summary>
public int SectorIndex; public int SectorIndex;
/// <summary> /// <summary>
/// The currently loaded floppy disk /// The currently loaded floppy disk
/// </summary> /// </summary>
public FloppyDisk Disk { get; set; } public FloppyDisk Disk { get; set; }
/// <summary> /// <summary>
/// The parent controller /// The parent controller
/// </summary> /// </summary>
private NECUPD765 FDC; private NECUPD765 FDC;
#endregion #endregion
#region Lookups #region Lookups
/// <summary> /// <summary>
/// TRUE if we are on track 0 /// TRUE if we are on track 0
/// </summary> /// </summary>
public bool FLAG_TRACK0 public bool FLAG_TRACK0 => TrackIndex == 0;
{
get
{
if (TrackIndex == 0) { return true; }
else { return false; }
}
}
#endregion #endregion
#region Public Methods #region Public Methods
/* /*
/// <summary> /// <summary>
/// Moves the head across the disk cylinders /// Moves the head across the disk cylinders
/// </summary> /// </summary>
@ -369,7 +356,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
} }
*/ */
/* /*
/// <summary> /// <summary>
/// Finds a supplied sector /// Finds a supplied sector
@ -524,7 +511,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
} }
*/ */
/* /*
/// <summary> /// <summary>
/// The drive performs a seek operation if necessary /// The drive performs a seek operation if necessary
@ -751,139 +738,139 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
SetBit(SR0_EC, ref IntStatus); SetBit(SR0_EC, ref IntStatus);
} }
*/ */
/* /*
// UnitSelect // UnitSelect
SetUnitSelect(ID, ref IntStatus); SetUnitSelect(ID, ref IntStatus);
// move to none state // move to none state
//CurrentState = DriveMainState.None; //CurrentState = DriveMainState.None;
//SeekState = SeekSubState.SeekCompleted; //SeekState = SeekSubState.SeekCompleted;
// set the seek interrupt flag for this drive // set the seek interrupt flag for this drive
// this will be cleared at the next successful senseint // this will be cleared at the next successful senseint
FLAG_SEEK_INTERRUPT = true; FLAG_SEEK_INTERRUPT = true;
//CurrentState = DriveMainState.None; //CurrentState = DriveMainState.None;
} }
*/ */
#endregion #endregion
#region Construction #region Construction
public DriveState(int driveID, NECUPD765 fdc) public DriveState(int driveID, NECUPD765 fdc)
{ {
ID = driveID; ID = driveID;
FDC = fdc; FDC = fdc;
} }
#endregion #endregion
#region IFDDHost #region IFDDHost
/// <summary> /// <summary>
/// Parses a new disk image and loads it into this floppy drive /// Parses a new disk image and loads it into this floppy drive
/// </summary> /// </summary>
public void FDD_LoadDisk(byte[] diskData) public void FDD_LoadDisk(byte[] diskData)
{ {
// try dsk first // try dsk first
FloppyDisk fdd = null; FloppyDisk fdd = null;
bool found = false; bool found = false;
foreach (DiskType type in Enum.GetValues(typeof(DiskType))) foreach (DiskType type in Enum.GetValues(typeof(DiskType)))
{ {
switch (type) switch (type)
{ {
case DiskType.CPCExtended: case DiskType.CPCExtended:
fdd = new CPCExtendedFloppyDisk(); fdd = new CPCExtendedFloppyDisk();
found = fdd.ParseDisk(diskData); found = fdd.ParseDisk(diskData);
break; break;
case DiskType.CPC: case DiskType.CPC:
fdd = new CPCFloppyDisk(); fdd = new CPCFloppyDisk();
found = fdd.ParseDisk(diskData); found = fdd.ParseDisk(diskData);
break; break;
case DiskType.IPF: case DiskType.IPF:
fdd = new IPFFloppyDisk(); fdd = new IPFFloppyDisk();
found = fdd.ParseDisk(diskData); found = fdd.ParseDisk(diskData);
break; break;
case DiskType.UDI: case DiskType.UDI:
fdd = new UDI1_0FloppyDisk(); fdd = new UDI1_0FloppyDisk();
found = fdd.ParseDisk(diskData); found = fdd.ParseDisk(diskData);
break; break;
} }
if (found) if (found)
{ {
Disk = fdd; Disk = fdd;
break; break;
} }
} }
if (!found) if (!found)
{ {
throw new Exception(this.GetType().ToString() + throw new Exception(this.GetType().ToString() +
"\n\nDisk image file could not be parsed. Potentially an unknown format."); "\n\nDisk image file could not be parsed. Potentially an unknown format.");
} }
} }
/// <summary> /// <summary>
/// Ejects the current disk /// Ejects the current disk
/// </summary> /// </summary>
public void FDD_EjectDisk() public void FDD_EjectDisk()
{ {
Disk = null; Disk = null;
//FLAG_READY = false; //FLAG_READY = false;
} }
/// <summary> /// <summary>
/// Signs whether the current active drive has a disk inserted /// Signs whether the current active drive has a disk inserted
/// </summary> /// </summary>
public bool FDD_IsDiskLoaded public bool FDD_IsDiskLoaded
{ {
get get
{ {
if (Disk != null) if (Disk != null)
return true; return true;
else else
return false; return false;
} }
} }
#endregion #endregion
#region StateSerialization #region StateSerialization
public void SyncState(Serializer ser) public void SyncState(Serializer ser)
{ {
ser.Sync(nameof(ID), ref ID); ser.Sync(nameof(ID), ref ID);
ser.Sync(nameof(FLAG_WRITEPROTECT), ref FLAG_WRITEPROTECT); ser.Sync(nameof(FLAG_WRITEPROTECT), ref FLAG_WRITEPROTECT);
//ser.Sync(nameof(FLAG_DISKCHANGED), ref FLAG_DISKCHANGED); //ser.Sync(nameof(FLAG_DISKCHANGED), ref FLAG_DISKCHANGED);
//ser.Sync(nameof(FLAG_RECALIBRATING), ref FLAG_RECALIBRATING); //ser.Sync(nameof(FLAG_RECALIBRATING), ref FLAG_RECALIBRATING);
//ser.Sync(nameof(FLAG_SEEK_INTERRUPT), ref FLAG_SEEK_INTERRUPT); //ser.Sync(nameof(FLAG_SEEK_INTERRUPT), ref FLAG_SEEK_INTERRUPT);
//ser.Sync(nameof(IntStatus), ref IntStatus); //ser.Sync(nameof(IntStatus), ref IntStatus);
//ser.Sync(nameof(ST0), ref ST0); //ser.Sync(nameof(ST0), ref ST0);
//ser.Sync(nameof(RecalibrationCounter), ref RecalibrationCounter); //ser.Sync(nameof(RecalibrationCounter), ref RecalibrationCounter);
ser.Sync(nameof(SeekCounter), ref SeekCounter); ser.Sync(nameof(SeekCounter), ref SeekCounter);
ser.Sync(nameof(SeekStatus), ref SeekStatus); ser.Sync(nameof(SeekStatus), ref SeekStatus);
ser.Sync(nameof(SeekAge), ref SeekAge); ser.Sync(nameof(SeekAge), ref SeekAge);
ser.Sync(nameof(CurrentSide), ref CurrentSide); ser.Sync(nameof(CurrentSide), ref CurrentSide);
//ser.Sync(nameof(CurrentTrack), ref CurrentTrack); //ser.Sync(nameof(CurrentTrack), ref CurrentTrack);
ser.Sync(nameof(TrackIndex), ref TrackIndex); ser.Sync(nameof(TrackIndex), ref TrackIndex);
ser.Sync(nameof(SeekingTrack), ref SeekingTrack); ser.Sync(nameof(SeekingTrack), ref SeekingTrack);
//ser.Sync(nameof(CurrentSector), ref CurrentSector); //ser.Sync(nameof(CurrentSector), ref CurrentSector);
ser.Sync(nameof(SectorIndex), ref SectorIndex); ser.Sync(nameof(SectorIndex), ref SectorIndex);
//ser.Sync(nameof(RAngles), ref RAngles); //ser.Sync(nameof(RAngles), ref RAngles);
//ser.Sync(nameof(DataPointer), ref DataPointer); //ser.Sync(nameof(DataPointer), ref DataPointer);
//ser.SyncEnum(nameof(CurrentState), ref CurrentState); //ser.SyncEnum(nameof(CurrentState), ref CurrentState);
//ser.SyncEnum(nameof(SeekState), ref SeekState); //ser.SyncEnum(nameof(SeekState), ref SeekState);
//ser.SyncEnum(nameof(SeekIntState), ref SeekIntState); //ser.SyncEnum(nameof(SeekIntState), ref SeekIntState);
} }
#endregion #endregion
} }
#endregion #endregion
} }
} }

View File

@ -51,11 +51,9 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
private ushort _loadBytesResumeAddress; private ushort _loadBytesResumeAddress;
private ushort _loadBytesInvalidHeaderAddress; private ushort _loadBytesInvalidHeaderAddress;
public static RomData InitROM(MachineType machineType, byte[] rom) public static RomData InitROM(MachineType machineType, byte[] rom)
{ {
RomData RD = new RomData(); RomData RD = new RomData { RomBytes = new byte[rom.Length] };
RD.RomBytes = new byte[rom.Length];
RD.RomBytes = rom; RD.RomBytes = rom;
switch (machineType) switch (machineType)

Some files were not shown because too many files have changed in this diff Show More