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
{

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using BizHawk.Emulation.Common;
@ -73,7 +71,7 @@ namespace BizHawk.Emulation.Cores.Components.H6280
public string Name;
public int Offs;
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];

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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

View File

@ -1,5 +1,4 @@
using BizHawk.Common.NumberExtensions;
using System;
namespace BizHawk.Emulation.Cores.Components.LR35902
{
@ -16,7 +15,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
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)
{
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)
{
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]);
}
@ -141,7 +140,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
FlagZ = Regs[src] == 0;
FlagH = false;
FlagN = false;
FlagN = false;
}
public void SRA_Func(ushort src)

View File

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

View File

@ -1,51 +1,58 @@
using System;
namespace BizHawk.Emulation.Cores.Components.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
private void NOP_()
{
cur_instr = new ushort[]
{IDLE,
IDLE,
HALT_CHK,
OP };
cur_instr = new[]
{
IDLE,
IDLE,
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[]
{IDLE,
IDLE,
IDLE,
INC16, src_l, src_h,
IDLE,
IDLE,
HALT_CHK,
OP };
cur_instr = new[]
{
IDLE,
IDLE,
IDLE,
INC16,
srcL,
srcH,
IDLE,
IDLE,
HALT_CHK,
OP
};
}
private void DEC_16(ushort src_l, ushort src_h)
{
cur_instr = new ushort[]
{IDLE,
IDLE,
IDLE,
DEC16, src_l, src_h,
IDLE,
IDLE,
HALT_CHK,
OP };
cur_instr = new[]
{
IDLE,
IDLE,
IDLE,
DEC16,
src_l,
src_h,
IDLE,
IDLE,
HALT_CHK,
OP
};
}
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,
@ -58,7 +65,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
private void REG_OP(ushort operation, ushort dest, ushort src)
{
cur_instr = new ushort[]
cur_instr = new[]
{operation, dest, src,
IDLE,
HALT_CHK,
@ -67,7 +74,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
private void STOP_()
{
cur_instr = new ushort[]
cur_instr = new[]
{RD, Z, PCl, PCh,
INC16, PCl, PCh,
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
// so it just takes 4 cycles longer to reach the next instruction
cur_instr = new ushort[]
cur_instr = new[]
{IDLE,
IDLE,
IDLE,
@ -92,7 +99,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
{ // if interrupts are disabled,
// a glitchy decrement to the program counter happens
{
cur_instr = new ushort[]
cur_instr = new[]
{IDLE,
IDLE,
IDLE,
@ -104,7 +111,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
{
cur_instr = new ushort[]
{
IDLE,
IDLE,
HALT_CHK,
IDLE,
HALT, 0 };
@ -139,7 +146,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
}
else
{
cur_instr = new ushort[]
cur_instr = new[]
{IDLE,
IDLE,
IDLE,
@ -155,7 +162,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
{
if (cond)
{
cur_instr = new ushort[]
cur_instr = new[]
{IDLE,
IDLE,
IDLE,
@ -175,7 +182,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
}
else
{
cur_instr = new ushort[]
cur_instr = new[]
{IDLE,
IDLE,
IDLE,
@ -193,7 +200,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
private void RET_()
{
cur_instr = new ushort[]
cur_instr = new[]
{IDLE,
IDLE,
IDLE,
@ -214,7 +221,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
private void RETI_()
{
cur_instr = new ushort[]
cur_instr = new[]
{IDLE,
IDLE,
IDLE,
@ -238,7 +245,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
{
if (cond)
{
cur_instr = new ushort[]
cur_instr = new[]
{IDLE,
IDLE,
IDLE,
@ -262,7 +269,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
}
else
{
cur_instr = new ushort[]
cur_instr = new[]
{IDLE,
IDLE,
IDLE,
@ -278,7 +285,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
{
if (cond)
{
cur_instr = new ushort[]
cur_instr = new[]
{IDLE,
IDLE,
IDLE,
@ -306,7 +313,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
}
else
{
cur_instr = new ushort[]
cur_instr = new[]
{IDLE,
IDLE,
IDLE,
@ -324,7 +331,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
private void INT_OP(ushort operation, ushort src)
{
cur_instr = new ushort[]
cur_instr = new[]
{operation, src,
IDLE,
HALT_CHK,
@ -333,7 +340,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
private void BIT_OP(ushort operation, ushort bit, ushort src)
{
cur_instr = new ushort[]
cur_instr = new[]
{operation, bit, src,
IDLE,
HALT_CHK,
@ -342,7 +349,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
private void PUSH_(ushort src_l, ushort src_h)
{
cur_instr = new ushort[]
cur_instr = new[]
{IDLE,
IDLE,
IDLE,
@ -368,7 +375,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
{
if (src_l != F)
{
cur_instr = new ushort[]
cur_instr = new[]
{IDLE,
IDLE,
IDLE,
@ -384,7 +391,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
}
else
{
cur_instr = new ushort[]
cur_instr = new[]
{IDLE,
IDLE,
IDLE,
@ -423,7 +430,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
private void PREFIX_()
{
cur_instr = new ushort[]
cur_instr = new[]
{PREFIX,
IDLE,
IDLE,
@ -432,7 +439,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
private void DI_()
{
cur_instr = new ushort[]
cur_instr = new[]
{DI,
IDLE,
HALT_CHK,
@ -441,7 +448,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
private void EI_()
{
cur_instr = new ushort[]
cur_instr = new[]
{EI,
IDLE,
HALT_CHK,
@ -450,7 +457,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
private void JP_HL()
{
cur_instr = new ushort[]
cur_instr = new[]
{TR, PCl, L,
TR, PCh, H,
HALT_CHK,
@ -480,7 +487,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
private void LD_SP_HL()
{
cur_instr = new ushort[]
cur_instr = new[]
{IDLE,
IDLE,
IDLE,
@ -510,7 +517,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902
private void JAM_()
{
cur_instr = new ushort[]
cur_instr = new[]
{JAM,
IDLE,
IDLE,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,4 +1,3 @@
using System;
using BizHawk.Common.NumberExtensions;
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
{
@ -31,40 +30,40 @@ namespace BizHawk.Emulation.Cores.Components.MC6809
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]);
}
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]);
Regs[dest] -= 1;
}
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));
Regs[dest] -= 1;
}
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));
}
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));
Regs[dest]++;
}
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]);
Regs[dest]++;
}
@ -126,7 +125,7 @@ namespace BizHawk.Emulation.Cores.Components.MC6809
FlagZ = Regs[dest] == 0;
FlagV = false;
FlagN = Regs[dest] > 0x7FFF;
FlagN = Regs[dest] > 0x7FFF;
}
// 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];
if ((dest == X) || (dest == Y))
if (dest == X || dest == Y)
{
FlagZ = Regs[dest] == 0;
}

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,3 @@
using System;
namespace BizHawk.Emulation.Cores.Components.Z80A
{
public partial class Z80A
@ -8,7 +6,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A
private int EI_pending;
// 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 EXTDpre = 1;

View File

@ -26,7 +26,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A
return format;
}
static readonly string[] mnemonics = new string[]
static readonly string[] mnemonics =
{
"NOP", "LD BC, nn", "LD (BC), A", "INC BC", //0x04
"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
};
static readonly string[] mnemonicsDD = new string[]
static readonly string[] mnemonicsDD =
{
"NOP", "LD BC, nn", "LD (BC), A", "INC BC", //0x04
"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
};
static readonly string[] mnemonicsFD = new string[]
static readonly string[] mnemonicsFD =
{
"NOP", "LD BC, nn", "LD (BC), A", "INC BC", //0x04
"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
};
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",
"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",
};
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",
"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",
};
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",
"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",
};
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",
@ -439,10 +439,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A
set { }
}
public string PCRegisterName
{
get { return "PC"; }
}
public string PCRegisterName => "PC";
public IEnumerable<string> AvailableCpus
{

View File

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

View File

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

View File

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

View File

@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using BizHawk.Common;
using BizHawk.Emulation.Common;
using BizHawk.Common.NumberExtensions;
@ -306,8 +303,8 @@ namespace BizHawk.Emulation.Cores.Components.Z80A
break;
case OP_F:
// Read the opcode of the next instruction
if (OnExecFetch != null) OnExecFetch(RegPC);
if (TraceCallback != null) TraceCallback(State());
OnExecFetch?.Invoke(RegPC);
TraceCallback?.Invoke(State());
opcode = FetchMemory(RegPC++);
FetchInstruction();
@ -778,10 +775,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A
{
nonMaskableInterruptPending = false;
if (TraceCallback != null)
{
TraceCallback(new TraceInfo { Disassembly = "====NMI====", RegisterInfo = "" });
}
TraceCallback?.Invoke(new TraceInfo { Disassembly = "====NMI====", RegisterInfo = "" });
iff2 = iff1;
iff1 = false;
@ -802,10 +796,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A
iff1 = iff2 = false;
EI_pending = 0;
if (TraceCallback != null)
{
TraceCallback(new TraceInfo { Disassembly = "====IRQ====", RegisterInfo = "" });
}
TraceCallback?.Invoke(new TraceInfo { Disassembly = "====IRQ====", RegisterInfo = "" });
switch (interruptMode)
{
@ -858,10 +849,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A
// tracer stuff
public Action<TraceInfo> TraceCallback;
public string TraceHeader
{
get { return "Z80A: PC, machine code, mnemonic, operands, registers (AF, BC, DE, HL, IX, IY, SP, Cy), flags (CNP3H5ZS)"; }
}
public string TraceHeader => "Z80A: PC, machine code, mnemonic, operands, registers (AF, BC, DE, HL, IX, IY, SP, Cy), flags (CNP3H5ZS)";
public TraceInfo State(bool disassemble = true)
{
@ -906,7 +894,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A
/// <summary>
/// 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,
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>
/// 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,
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
{
ControllerDefinition definition = new ControllerDefinition();
definition.Name = "AmstradCPC Controller";
var definition = new ControllerDefinition
{
Name = "AmstradCPC Controller"
};
// joysticks
List<string> joys1 = new List<string>
var joys1 = new List<string>
{
// P1 Joystick
"P1 Up", "P1 Down", "P1 Left", "P1 Right", "P1 Fire1", "P1 Fire2", "P1 Fire3"
// P1 Joystick
"P1 Up", "P1 Down", "P1 Left", "P1 Right", "P1 Fire1", "P1 Fire2", "P1 Fire3"
};
foreach (var s in joys1)
@ -32,10 +34,10 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
definition.CategoryLabels[s] = "J1";
}
List<string> joys2 = new List<string>
var joys2 = new List<string>
{
// P2 Joystick
"P2 Up", "P2 Down", "P2 Left", "P2 Right", "P2 Fire",
// P2 Joystick
"P2 Up", "P2 Down", "P2 Left", "P2 Right", "P2 Fire",
};
foreach (var s in joys2)
@ -45,25 +47,25 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
}
// 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/File:Grimware_cpc464_version3_case_top.jpg
// 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",
// 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",
// 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",
// 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",
// Keyboard - row 5
"Key SPACE", "Key CONTROL",
// Keyboard - Cursor
"Key CURUP", "Key CURDOWN", "Key CURLEFT", "Key CURRIGHT", "Key COPY",
// 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"
// http://www.cpcwiki.eu/index.php/Programming:Keyboard_scanning
// http://www.cpcwiki.eu/index.php/File:Grimware_cpc464_version3_case_top.jpg
// 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",
// 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",
// 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",
// 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",
// Keyboard - row 5
"Key SPACE", "Key CONTROL",
// Keyboard - Cursor
"Key CURUP", "Key CURDOWN", "Key CURLEFT", "Key CURRIGHT", "Key COPY",
// 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"
};
foreach (var s in keys)
@ -73,10 +75,10 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
}
// Power functions
List<string> power = new List<string>
var power = new List<string>
{
// Power functions
"Reset", "Power"
// Power functions
"Reset", "Power"
};
foreach (var s in power)
@ -86,10 +88,10 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
}
// Datacorder (tape device)
List<string> tape = new List<string>
var tape = new List<string>
{
// Tape functions
"Play Tape", "Stop Tape", "RTZ Tape", "Record Tape", "Insert Next Tape",
// Tape functions
"Play Tape", "Stop Tape", "RTZ Tape", "Record Tape", "Insert Next Tape",
"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)
List<string> disk = new List<string>
var disk = new List<string>
{
// Tape functions
"Insert Next Disk", "Insert Previous Disk", /*"Eject Current Disk",*/ "Get Disk Status"
// Tape functions
"Insert Next Disk", "Insert Previous Disk", /*"Eject Current Disk",*/ "Get Disk Status"
};
foreach (var s in disk)

View File

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

View File

@ -39,9 +39,9 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
if (tmpM != _machineType && _machineType.ToString() != "72")
{
string msg = "SAVESTATE FAILED TO LOAD!!\n\n";
msg += "Current Configuration: " + tmpM.ToString();
msg += "Current Configuration: " + tmpM;
msg += "\n";
msg += "Saved Configuration: " + _machineType.ToString();
msg += "Saved Configuration: " + _machineType;
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.";
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
{

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,7 +1,5 @@
using BizHawk.Common;
using BizHawk.Common.NumberExtensions;
using System;
using System.Collections;
namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{
@ -98,123 +96,57 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
/// <summary>
/// The total frame width (in characters)
/// </summary>
public int FrameWidth
{
get
{
return (int)Regs[HOR_TOTAL] + 1;
}
}
public int FrameWidth => (int)Regs[HOR_TOTAL] + 1;
/// <summary>
/// The total frame height (in scanlines)
/// </summary>
public int FrameHeight
{
get
{
return ((int)Regs[VER_TOTAL] + 1) * ((int)Regs[MAX_RASTER_ADDR] + 1);
}
}
public int FrameHeight => ((int)Regs[VER_TOTAL] + 1) * ((int)Regs[MAX_RASTER_ADDR] + 1);
/// <summary>
/// The total frame height (in scanlines)
/// </summary>
public int FrameHeightInChars
{
get
{
return ((int)Regs[VER_TOTAL] + 1);
}
}
public int FrameHeightInChars => ((int)Regs[VER_TOTAL] + 1);
/// <summary>
/// The width of the display area (in characters)
/// </summary>
public int DisplayWidth
{
get
{
return (int)Regs[HOR_DISPLAYED];
}
}
public int DisplayWidth => (int)Regs[HOR_DISPLAYED];
/// <summary>
/// The width of the display area (in scanlines)
/// </summary>
public int DisplayHeight
{
get
{
return (int)Regs[VER_DISPLAYED] * ((int)Regs[MAX_RASTER_ADDR] + 1);
}
}
public int DisplayHeight => (int)Regs[VER_DISPLAYED] * ((int)Regs[MAX_RASTER_ADDR] + 1);
/// <summary>
/// The width of the display area (in scanlines)
/// </summary>
public int DisplayHeightInChars
{
get
{
return (int)Regs[VER_DISPLAYED];
}
}
public int DisplayHeightInChars => (int)Regs[VER_DISPLAYED];
/// <summary>
/// The character at which to start HSYNC
/// </summary>
public int HorizontalSyncPos
{
get
{
return (int)Regs[HOR_SYNC_POS];
}
}
public int HorizontalSyncPos => (int)Regs[HOR_SYNC_POS];
/// <summary>
/// Width (in characters) of the HSYNC
/// </summary>
public int HorizontalSyncWidth
{
get
{
return HSYNCWidth;
}
}
public int HorizontalSyncWidth => HSYNCWidth;
/// <summary>
/// The vertical scanline at which to start VSYNC
/// </summary>
public int VerticalSyncPos
{
get
{
return (int)Regs[VER_SYNC_POS] * ((int)Regs[MAX_RASTER_ADDR] + 1);
}
}
public int VerticalSyncPos => (int)Regs[VER_SYNC_POS] * ((int)Regs[MAX_RASTER_ADDR] + 1);
/// <summary>
/// Height (in scanlines) of the VSYNC
/// </summary>
public int VerticalSyncHeight
{
get
{
return VSYNCWidth; // * ((int)Regs[MAX_RASTER_ADDR] + 1);
}
}
public int VerticalSyncHeight => VSYNCWidth; // * ((int)Regs[MAX_RASTER_ADDR] + 1);
/// <summary>
/// The number of scanlines in one character (MAXRASTER)
/// </summary>
public int ScanlinesPerCharacter
{
get
{
return (int)Regs[MAX_RASTER_ADDR] + 1;
}
}
public int ScanlinesPerCharacter => (int)Regs[MAX_RASTER_ADDR] + 1;
/// <summary>
/// Returns the starting video page address as specified within R12
@ -236,11 +168,9 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
}
}
public int DStartHigh
{ get { return Regs[DISP_START_ADDR_H]; } }
public int DStartHigh => Regs[DISP_START_ADDR_H];
public int DStartLow
{ get { return Regs[DISP_START_ADDR_L]; } }
public int DStartLow => Regs[DISP_START_ADDR_L];
/// <summary>
/// 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
/// (The defaults values given here are those programmed by the firmware ROM after a cold/warm boot of the CPC/Plus)
/// </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>
/// Register masks
/// 0 = WRITE
/// 1 = READ
/// </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>
/// Horizontal Character Count

View File

@ -1,7 +1,6 @@
using BizHawk.Common;
using System.Collections;
using BizHawk.Common;
using BizHawk.Common.NumberExtensions;
using System;
using System.Collections;
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.
/// The active transition is high-to-low
/// </summary>
public bool CLK { get { return _CLK; } }
public bool CLK => _CLK;
private bool _CLK;
/// <summary>
/// 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.)
/// (C) The CRTC starts the Display operation immediately after the release of RES signal.
/// </summary>
public bool RESET { get { return _RESET; } }
public bool RESET => _RESET;
private bool _RESET;
/// <summary>
/// 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.
/// </summary>
public bool LPSTB { get { return _LPSTB; } }
public bool LPSTB => _LPSTB;
private bool _LPSTB;
#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 signal determines the vertical position of the displayed text.
/// </summary>
public bool VSYNC { get { return _VSYNC; } }
public bool VSYNC => _VSYNC;
private bool _VSYNC;
/// <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 signal determines the horizontal position of the displayed text.
/// </summary>
public bool HSYNC { get { return _HSYNC; } }
public bool HSYNC => _HSYNC;
private bool _HSYNC;
/// <summary>
/// This TTL compatible output is an active high signal which indicates the CRTC is providing addressing in the active Display Area.
/// </summary>
public bool DISPTMG { get { return _DISPTMG; } }
public bool DISPTMG => _DISPTMG;
private bool _DISPTMG;
/// <summary>
/// This TTL compatible output indicates Cursor Display to external Video Processing Logic.Active high signal.
/// </summary>
public bool CUDISP { get { return _CUDISP; } }
public bool CUDISP => _CUDISP;
private bool _CUDISP;
// 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
MAO-MA 13 is a logical "1."
*/
public bool MA0 { get { return LinearAddress.Bit(0); } }
public bool MA1 { get { return LinearAddress.Bit(1); } }
public bool MA2 { get { return LinearAddress.Bit(2); } }
public bool MA3 { get { return LinearAddress.Bit(3); } }
public bool MA4 { get { return LinearAddress.Bit(4); } }
public bool MA5 { get { return LinearAddress.Bit(5); } }
public bool MA6 { get { return LinearAddress.Bit(6); } }
public bool MA7 { get { return LinearAddress.Bit(7); } }
public bool MA8 { get { return LinearAddress.Bit(8); } }
public bool MA9 { get { return LinearAddress.Bit(9); } }
public bool MA10 { get { return 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 MA12 { get { return 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 MA0 => LinearAddress.Bit(0);
public bool MA1 => LinearAddress.Bit(1);
public bool MA2 => LinearAddress.Bit(2);
public bool MA3 => LinearAddress.Bit(3);
public bool MA4 => LinearAddress.Bit(4);
public bool MA5 => LinearAddress.Bit(5);
public bool MA6 => LinearAddress.Bit(6);
public bool MA7 => LinearAddress.Bit(7);
public bool MA8 => LinearAddress.Bit(8);
public bool MA9 => LinearAddress.Bit(9);
public bool MA10 => LinearAddress.Bit(10); // 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 => LinearAddress.Bit(12); // 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
/*
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."
*/
public bool RA0 { get { return RowSelects.Bit(0); } }
public bool RA1 { get { return RowSelects.Bit(1); } }
public bool RA2 { get { return RowSelects.Bit(2); } }
public bool RA3 { get { return 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 RA0 => RowSelects.Bit(0);
public bool RA1 => RowSelects.Bit(1);
public bool RA2 => RowSelects.Bit(2);
public bool RA3 => RowSelects.Bit(3); // 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>
/// 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>
/// Current programmed HSYNC width for Type 0 (HD6845S & UM6845) & Type 1 (UM6845R)
/// </summary>
private int HSYNCWidth_Type0_1
{
get
{
// Bits 3..0 define Horizontal Sync Width.
// If 0 is programmed no HSYNC is generated.
return (Register[SYNC_WIDTHS] >> 0) & 0x0F;
}
}
// Bits 3..0 define Horizontal Sync Width.
// If 0 is programmed no HSYNC is generated.
private int HSYNCWidth_Type0_1 => (Register[SYNC_WIDTHS] >> 0) & 0x0F;
/// <summary>
/// Current programmed HSYNC width for Type 2 (MC6845), 3 (AMS40489) & 4 (pre-ASIC)
@ -727,15 +727,9 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
/// <summary>
/// Current programmed VSYNC width for Type 1 (UM6845R) & 2 (MC6845)
/// </summary>
private int VSYNCWidth_Type1_2
{
get
{
// Bits 7..4 are ignored.
// Vertical Sync is fixed at 16 lines.
return 16;
}
}
// Bits 7..4 are ignored.
// Vertical Sync is fixed at 16 lines.
private int VSYNCWidth_Type1_2 => 16;
#endregion

View File

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

View File

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

View File

@ -1,10 +1,4 @@
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
{
/// <summary>
/// CPC464

View File

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

View File

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

View File

@ -1,10 +1,4 @@
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
{
/// <summary>
/// CPC6128

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,5 @@

using BizHawk.Common.NumberExtensions;
using System;
using System.Collections.Generic;
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
LastFrameStartCPUTick = CPU.TotalExecutedCycles; // - OverFlow;
if (AYDevice != null)
AYDevice.EndFrame();
AYDevice?.EndFrame();
FrameCount++;
@ -185,7 +184,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
// is this a lag frame?
CPC.IsLagFrame = !InputRead;
// FDC debug
// FDC debug
if (UPDDiskDevice != null && UPDDiskDevice.writeDebug)
{
// only write UPD log every second
@ -360,10 +359,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
if (ser.IsReader)
DiskMediaIndex = diskMediaIndex;
if (UPDDiskDevice != null)
{
UPDDiskDevice.SyncState(ser);
}
UPDDiskDevice?.SyncState(ser);
ser.EndSection();
}

View File

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

View File

@ -68,8 +68,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
// check for unformatted track
if (DiskHeader.TrackSizes[i] == 0)
{
DiskTracks[i] = new Track();
DiskTracks[i].Sectors = new Sector[0];
DiskTracks[i] = new Track { Sectors = new Sector[0] };
continue;
}
@ -94,15 +93,16 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
DiskTracks[i].Sectors = new Sector[DiskTracks[i].NumberOfSectors];
for (int s = 0; s < DiskTracks[i].NumberOfSectors; s++)
{
DiskTracks[i].Sectors[s] = new Sector();
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);
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)
};
p += 2;
// 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
if (DiskHeader.TrackSizes[i] == 0)
{
DiskTracks[i] = new Track();
DiskTracks[i].Sectors = new Sector[0];
DiskTracks[i] = new Track { Sectors = new Sector[0] };
continue;
}
@ -94,15 +93,17 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
DiskTracks[i].Sectors = new Sector[DiskTracks[i].NumberOfSectors];
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;
// actualdatabytelength value is calculated now

View File

@ -1,10 +1,4 @@
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
{
/// <summary>
/// This is called first when importing disk images

View File

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

View File

@ -17,31 +17,19 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
/// <summary>
/// Signs whether this class can be used to read the data format
/// </summary>
public virtual bool IsReader
{
get
{
return false;
}
}
public virtual bool IsReader => false;
/// <summary>
/// Signs whether this class can be used to write the data format
/// </summary>
public virtual bool IsWriter
{
get
{
return false;
}
}
public virtual bool IsWriter => false;
/// <summary>
/// Serialization method
/// </summary>
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");
}
@ -50,7 +38,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
/// </summary>
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");
}

View File

@ -6,7 +6,7 @@ using System.Text;
namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{
/// <summary>
/// Reponsible for TZX format serializaton
/// Responsible for TZX format serialization
/// </summary>
public class CdtConverter : MediaConverter
{
@ -14,23 +14,17 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
/// The type of serializer
/// </summary>
private MediaConverterType _formatType = MediaConverterType.CDT;
public override MediaConverterType FormatType
{
get
{
return _formatType;
}
}
public override MediaConverterType FormatType => _formatType;
/// <summary>
/// Signs whether this class can be used to read the data format
/// </summary>
public override bool IsReader { get { return true; } }
public override bool IsReader => true;
/// <summary>
/// Signs whether this class can be used to write the data format
/// </summary>
public override bool IsWriter { get { return false; } }
public override bool IsWriter => false;
/// <summary>
/// Working list of generated tape data blocks
@ -65,14 +59,16 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
/// </summary>
private TapeDataBlock ConvertClock(TapeDataBlock db)
{
TapeDataBlock tb = new TapeDataBlock();
tb.BlockDescription = db.BlockDescription;
tb.BlockID = db.BlockID;
tb.Command = db.Command;
tb.DataPeriods = new List<int>();
tb.InitialPulseLevel = db.InitialPulseLevel;
tb.MetaData = db.MetaData;
tb.PauseInMS = db.PauseInMS;
var tb = new TapeDataBlock
{
BlockDescription = db.BlockDescription,
BlockID = db.BlockID,
Command = db.Command,
DataPeriods = new List<int>(),
InitialPulseLevel = db.InitialPulseLevel,
MetaData = db.MetaData,
PauseInMS = db.PauseInMS
};
double multiplier = 8.0 / 7.0;
//double cycleScale = ((40 << 16) / 35);
@ -172,7 +168,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
if (ident != "ZXTape!" || eotm != 0x1A)
{
// 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");
}
@ -180,7 +176,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
_position = 10;
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++];
// 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. */
private void ProcessBlockID10(byte[] data)
{
TapeDataBlock t = new TapeDataBlock();
t.BlockID = 0x10;
t.BlockDescription = BlockType.Standard_Speed_Data_Block;
t.DataPeriods = new List<int>();
var t = new TapeDataBlock
{
BlockID = 0x10,
BlockDescription = BlockType.Standard_Speed_Data_Block,
DataPeriods = new List<int>()
};
int pauseLen = GetWordValue(data, _position);
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.*/
private void ProcessBlockID11(byte[] data)
{
TapeDataBlock t = new TapeDataBlock();
t.BlockID = 0x11;
t.BlockDescription = BlockType.Turbo_Speed_Data_Block;
t.DataPeriods = new List<int>();
var t = new TapeDataBlock
{
BlockID = 0x11,
BlockDescription = BlockType.Turbo_Speed_Data_Block,
DataPeriods = new List<int>()
};
int pilotPL = GetWordValue(data, _position);
int sync1P = GetWordValue(data, _position + 2);
@ -450,17 +450,18 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{
int blockLen = 4;
TapeDataBlock t = new TapeDataBlock();
t.BlockID = 0x12;
t.BlockDescription = BlockType.Pure_Tone;
t.DataPeriods = new List<int>();
t.PauseInMS = 0;
var t = new TapeDataBlock
{
BlockID = 0x12,
BlockDescription = BlockType.Pure_Tone,
DataPeriods = new List<int>(), PauseInMS = 0
};
// get values
int pulseLength = GetWordValue(data, _position);
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());
// build period information
@ -487,14 +488,15 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
sync tones used by some protection schemes. */
private void ProcessBlockID13(byte[] data)
{
TapeDataBlock t = new TapeDataBlock();
t.BlockID = 0x13;
t.BlockDescription = BlockType.Pulse_Sequence;
t.DataPeriods = new List<int>();
TapeDataBlock t = new TapeDataBlock
{
BlockID = 0x13,
BlockDescription = BlockType.Pulse_Sequence,
DataPeriods = new List<int>(),
PauseInMS = 0
};
t.PauseInMS = 0;
// get pulse count
// get pulse count
int pulseCount = data[_position];
t.AddMetaData(BlockDescriptorTitle.Pulse_Count, pulseCount.ToString());
_position++;
@ -504,7 +506,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{
// get pulse length
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);
}
@ -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. */
private void ProcessBlockID14(byte[] data)
{
TapeDataBlock t = new TapeDataBlock();
t.BlockID = 0x14;
t.BlockDescription = BlockType.Pure_Data_Block;
t.DataPeriods = new List<int>();
TapeDataBlock t = new TapeDataBlock
{
BlockID = 0x14,
BlockDescription = BlockType.Pure_Data_Block,
DataPeriods = new List<int>()
};
int pilotPL = 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. */
private void ProcessBlockID15(byte[] data)
{
TapeDataBlock t = new TapeDataBlock();
t.BlockID = 0x15;
t.BlockDescription = BlockType.Direct_Recording;
t.DataPeriods = new List<int>();
var t = new TapeDataBlock
{
BlockID = 0x15,
BlockDescription = BlockType.Direct_Recording,
DataPeriods = new List<int>()
};
// get values
int samLen = GetInt32(data, _position + 5);
@ -632,7 +638,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
}
}
// incrememt position
// increment position
_position++;
}
@ -680,15 +686,17 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
0x01: RLE
0x02: Z-RLE
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). */
private void ProcessBlockID18(byte[] data)
{
TapeDataBlock t = new TapeDataBlock();
t.BlockID = 0x18;
t.BlockDescription = BlockType.CSW_Recording;
t.DataPeriods = new List<int>();
TapeDataBlock t = new TapeDataBlock
{
BlockID = 0x18,
BlockDescription = BlockType.CSW_Recording,
DataPeriods = new List<int>()
};
int blockLen = GetInt32(data, _position);
_position += 4;
@ -710,7 +718,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
byte[] dest = new byte[pulses + 1];
// 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
var rate = (69888 * 50) / sampleRate;
@ -804,11 +812,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
private void ProcessBlockID19(byte[] data)
{
// not currently implemented properly
TapeDataBlock t = new TapeDataBlock();
t.BlockID = 0x19;
t.BlockDescription = BlockType.Generalized_Data_Block;
t.DataPeriods = new List<int>();
var t = new TapeDataBlock
{
BlockID = 0x19,
BlockDescription = BlockType.Generalized_Data_Block,
DataPeriods = new List<int>()
};
int blockLen = GetInt32(data, _position);
_position += 4;
@ -841,16 +850,18 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
#region ID 20 - Pause (silence) or 'Stop the Tape' command
/* length: 02
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
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)
{
TapeDataBlock t = new TapeDataBlock();
t.BlockID = 0x20;
t.DataPeriods = new List<int>();
t.BlockDescription = BlockType.Pause_or_Stop_the_Tape;
TapeDataBlock t = new TapeDataBlock
{
BlockID = 0x20,
DataPeriods = new List<int>(),
BlockDescription = BlockType.Pause_or_Stop_the_Tape
};
int pauseDuration = GetWordValue(data, _position);
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. */
private void ProcessBlockID21(byte[] data)
{
TapeDataBlock t = new TapeDataBlock();
t.BlockID = 0x21;
t.DataPeriods = new List<int>();
t.BlockDescription = BlockType.Group_Start;
var t = new TapeDataBlock
{
BlockID = 0x21,
DataPeriods = new List<int>(),
BlockDescription = BlockType.Group_Start
};
int nameLength = data[_position];
_position++;
@ -935,13 +948,14 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
This indicates the end of a group. This block has no body. */
private void ProcessBlockID22(byte[] data)
{
TapeDataBlock t = new TapeDataBlock();
t.BlockID = 0x22;
t.DataPeriods = new List<int>();
t.BlockDescription = BlockType.Group_End;
t.Command = TapeCommand.END_GROUP;
t.PauseInMS = 0;
TapeDataBlock t = new TapeDataBlock
{
BlockID = 0x22,
DataPeriods = new List<int>(),
BlockDescription = BlockType.Group_End,
Command = TapeCommand.END_GROUP,
PauseInMS = 0
};
// add to tape
_datacorder.DataBlocks.Add(t);
@ -963,11 +977,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
private void ProcessBlockID23(byte[] data)
{
// not implemented properly
TapeDataBlock t = new TapeDataBlock();
t.BlockID = 0x23;
t.DataPeriods = new List<int>();
t.BlockDescription = BlockType.Jump_to_Block;
var t = new TapeDataBlock
{
BlockID = 0x23,
DataPeriods = new List<int>(),
BlockDescription = BlockType.Jump_to_Block
};
int relativeJumpValue = GetWordValue(data, _position);
string result = string.Empty;
@ -1010,10 +1025,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
For simplicity reasons don't nest loop blocks! */
private void ProcessBlockID24(byte[] data)
{
TapeDataBlock t = new TapeDataBlock();
t.BlockID = 0x24;
t.DataPeriods = new List<int>();
t.BlockDescription = BlockType.Loop_Start;
var t = new TapeDataBlock
{
BlockID = 0x24,
DataPeriods = new List<int>(),
BlockDescription = BlockType.Loop_Start
};
// loop should start from the next block
int loopStart = _datacorder.DataBlocks.Count() + 1;
@ -1047,10 +1064,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
This block has no body. */
private void ProcessBlockID25(byte[] data)
{
TapeDataBlock t = new TapeDataBlock();
t.BlockID = 0x25;
t.DataPeriods = new List<int>();
t.BlockDescription = BlockType.Loop_End;
var t = new TapeDataBlock
{
BlockID = 0x25,
DataPeriods = new List<int>(),
BlockDescription = BlockType.Loop_End
};
// get the most recent loop info
var loop = _loopCounter.LastOrDefault();
@ -1100,10 +1119,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
private void ProcessBlockID26(byte[] data)
{
// block processing not implemented for this - just gets added for informational purposes only
TapeDataBlock t = new TapeDataBlock();
t.BlockID = 0x26;
t.DataPeriods = new List<int>();
t.BlockDescription = BlockType.Call_Sequence;
var t = new TapeDataBlock
{
BlockID = 0x26,
DataPeriods = new List<int>(),
BlockDescription = BlockType.Call_Sequence
};
int blockSize = 2 + 2 * GetWordValue(data, _position);
t.PauseInMS = 0;
@ -1126,12 +1147,13 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
private void ProcessBlockID27(byte[] data)
{
// block processing not implemented for this - just gets added for informational purposes only
TapeDataBlock t = new TapeDataBlock();
t.BlockID = 0x27;
t.DataPeriods = new List<int>();
t.BlockDescription = BlockType.Return_From_Sequence;
t.PauseInMS = 0;
var t = new TapeDataBlock
{
BlockID = 0x27,
DataPeriods = new List<int>(),
BlockDescription = BlockType.Return_From_Sequence,
PauseInMS = 0
};
// add to tape
_datacorder.DataBlocks.Add(t);
@ -1160,10 +1182,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
private void ProcessBlockID28(byte[] data)
{
// block processing not implemented for this - just gets added for informational purposes only
TapeDataBlock t = new TapeDataBlock();
t.BlockID = 0x28;
t.DataPeriods = new List<int>();
t.BlockDescription = BlockType.Select_Block;
var t = new TapeDataBlock
{
BlockID = 0x28,
DataPeriods = new List<int>(),
BlockDescription = BlockType.Select_Block
};
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. */
private void ProcessBlockID2A(byte[] data)
{
TapeDataBlock t = new TapeDataBlock();
t.BlockID = 0x2A;
t.DataPeriods = new List<int>();
t.BlockDescription = BlockType.Stop_the_Tape_48K;
t.Command = TapeCommand.STOP_THE_TAPE_48K;
var t = new TapeDataBlock
{
BlockID = 0x2A,
DataPeriods = new List<int>(),
BlockDescription = BlockType.Stop_the_Tape_48K,
Command = TapeCommand.STOP_THE_TAPE_48K
};
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. */
private void ProcessBlockID2B(byte[] data)
{
TapeDataBlock t = new TapeDataBlock();
t.BlockID = 0x2B;
t.DataPeriods = new List<int>();
t.BlockDescription = BlockType.Set_Signal_Level;
t.PauseInMS = 0;
var t = new TapeDataBlock
{
BlockID = 0x2B,
DataPeriods = new List<int>(),
BlockDescription = BlockType.Set_Signal_Level,
PauseInMS = 0
};
// add to tape
_datacorder.DataBlocks.Add(t);
@ -1244,10 +1271,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
Please use 'Archive Info' block for title, authors, publisher, etc. */
private void ProcessBlockID30(byte[] data)
{
TapeDataBlock t = new TapeDataBlock();
t.BlockID = 0x30;
t.DataPeriods = new List<int>();
t.BlockDescription = BlockType.Text_Description;
var t = new TapeDataBlock
{
BlockID = 0x30,
DataPeriods = new List<int>(),
BlockDescription = BlockType.Text_Description
};
int textLen = data[_position];
_position++;
@ -1283,11 +1312,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
private void ProcessBlockID31(byte[] data)
{
// currently not implemented properly in ZXHawk
TapeDataBlock t = new TapeDataBlock();
t.BlockID = 0x31;
t.DataPeriods = new List<int>();
t.BlockDescription = BlockType.Message_Block;
var t = new TapeDataBlock
{
BlockID = 0x31,
DataPeriods = new List<int>(),
BlockDescription = BlockType.Message_Block
};
_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. */
private void ProcessBlockID32(byte[] data)
{
TapeDataBlock t = new TapeDataBlock();
t.BlockID = 0x32;
t.DataPeriods = new List<int>();
t.BlockDescription = BlockType.Archive_Info;
var t = new TapeDataBlock
{
BlockID = 0x32,
DataPeriods = new List<int>(),
BlockDescription = BlockType.Archive_Info
};
int blockLen = GetWordValue(data, _position);
_position += 2;
@ -1397,8 +1429,6 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
case 0xFF:
title = "Comment(s): ";
break;
default:
break;
}
// add title to description
@ -1451,12 +1481,13 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{
// currently not implemented properly in ZXHawk
TapeDataBlock t = new TapeDataBlock();
t.BlockID = 0x33;
t.DataPeriods = new List<int>();
t.BlockDescription = BlockType.Hardware_Type;
t.PauseInMS = 0;
TapeDataBlock t = new TapeDataBlock
{
BlockID = 0x33,
DataPeriods = new List<int>(),
BlockDescription = BlockType.Hardware_Type,
PauseInMS = 0
};
// first byte contains number of HWINFOs
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. */
private void ProcessBlockID35(byte[] data)
{
TapeDataBlock t = new TapeDataBlock();
t.BlockID = 0x35;
t.DataPeriods = new List<int>();
t.BlockDescription = BlockType.Custom_Info_Block;
t.PauseInMS = 0;
var t = new TapeDataBlock
{
BlockID = 0x35,
DataPeriods = new List<int>(),
BlockDescription = BlockType.Custom_Info_Block,
PauseInMS = 0
};
string info = Encoding.ASCII.GetString(data, _position, 0x10);
//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. */
private void ProcessBlockID5A(byte[] data)
{
TapeDataBlock t = new TapeDataBlock();
t.BlockID = 0x5A;
t.DataPeriods = new List<int>();
t.BlockDescription = BlockType.Glue_Block;
t.PauseInMS = 0;
var t = new TapeDataBlock
{
BlockID = 0x5A,
DataPeriods = new List<int>(),
BlockDescription = BlockType.Glue_Block,
PauseInMS = 0
};
// add to tape
_datacorder.DataBlocks.Add(t);
@ -1539,10 +1572,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
private void ProcessUnidentifiedBlock(byte[] data)
{
TapeDataBlock t = new TapeDataBlock();
t.BlockID = -2;
t.DataPeriods = new List<int>();
t.BlockDescription = BlockType.Unsupported;
var t = new TapeDataBlock
{
BlockID = -2,
DataPeriods = new List<int>(),
BlockDescription = BlockType.Unsupported
};
//t.BlockDescription = "[UNSUPPORTED - 0x" + data[_position - 1] + "]";
_position += GetInt32(data, _position) & 0xFFFFFF;
@ -1564,12 +1599,13 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
private void ProcessBlockID16(byte[] data)
{
// zxhawk will not implement this block. it will however handle it so subsequent blocks can be parsed
TapeDataBlock t = new TapeDataBlock();
t.BlockID = 0x16;
t.DataPeriods = new List<int>();
t.BlockDescription = BlockType.C64_ROM_Type_Data_Block;
t.PauseInMS = 0;
TapeDataBlock t = new TapeDataBlock
{
BlockID = 0x16,
DataPeriods = new List<int>(),
BlockDescription = BlockType.C64_ROM_Type_Data_Block,
PauseInMS = 0
};
// add to tape
_datacorder.DataBlocks.Add(t);
@ -1584,12 +1620,13 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
private void ProcessBlockID17(byte[] data)
{
// zxhawk will not implement this block. it will however handle it so subsequent blocks can be parsed
TapeDataBlock t = new TapeDataBlock();
t.BlockID = 0x17;
t.DataPeriods = new List<int>();
t.BlockDescription = BlockType.C64_Turbo_Tape_Data_Block;
t.PauseInMS = 0;
var t = new TapeDataBlock
{
BlockID = 0x17,
DataPeriods = new List<int>(),
BlockDescription = BlockType.C64_Turbo_Tape_Data_Block,
PauseInMS = 0
};
// add to tape
_datacorder.DataBlocks.Add(t);
@ -1604,11 +1641,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
private void ProcessBlockID34(byte[] data)
{
// currently not implemented properly in ZXHawk
TapeDataBlock t = new TapeDataBlock();
t.BlockID = 0x34;
t.DataPeriods = new List<int>();
t.BlockDescription = BlockType.Emulation_Info;
var t = new TapeDataBlock
{
BlockID = 0x34,
DataPeriods = new List<int>(),
BlockDescription = BlockType.Emulation_Info
};
// add to tape
_datacorder.DataBlocks.Add(t);
@ -1635,10 +1673,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{
// currently not implemented properly in ZXHawk
TapeDataBlock t = new TapeDataBlock();
t.BlockID = 0x40;
t.DataPeriods = new List<int>();
t.BlockDescription = BlockType.Snapshot_Block;
TapeDataBlock t = new TapeDataBlock
{
BlockID = 0x40,
DataPeriods = new List<int>(),
BlockDescription = BlockType.Snapshot_Block
};
_position++;
@ -1735,7 +1775,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{
// data block
description = "Data Block " + (blockSize - 2) + "bytes";
block.AddMetaData(BlockDescriptorTitle.Data_Bytes, (blockSize - 2).ToString() + " Bytes");
block.AddMetaData(BlockDescriptorTitle.Data_Bytes, (blockSize - 2) + " Bytes");
}
else
{
@ -1801,10 +1841,10 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
if (dataBlockType == DataBlockType.Turbo)
block.BlockDescription = BlockType.Turbo_Speed_Data_Block;
block.AddMetaData(BlockDescriptorTitle.Pilot_Pulse_Length, pilotToneLength.ToString() + " T-States");
block.AddMetaData(BlockDescriptorTitle.Pilot_Pulse_Count, pilotCount.ToString() + " Pulses");
block.AddMetaData(BlockDescriptorTitle.First_Sync_Length, sync1PulseLength.ToString() + " T-States");
block.AddMetaData(BlockDescriptorTitle.Second_Sync_Length, sync2PulseLength.ToString() + " T-States");
block.AddMetaData(BlockDescriptorTitle.Pilot_Pulse_Length, pilotToneLength + " T-States");
block.AddMetaData(BlockDescriptorTitle.Pilot_Pulse_Count, pilotCount + " Pulses");
block.AddMetaData(BlockDescriptorTitle.First_Sync_Length, sync1PulseLength + " T-States");
block.AddMetaData(BlockDescriptorTitle.Second_Sync_Length, sync2PulseLength + " T-States");
break;
case DataBlockType.Pure:
@ -1812,11 +1852,11 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
break;
}
block.AddMetaData(BlockDescriptorTitle.Zero_Bit_Length, bit0PulseLength.ToString() + " T-States");
block.AddMetaData(BlockDescriptorTitle.One_Bit_Length, bit1PulseLength.ToString() + " T-States");
block.AddMetaData(BlockDescriptorTitle.Data_Length, blockSize.ToString() + " Bytes");
block.AddMetaData(BlockDescriptorTitle.Bits_In_Last_Byte, bitsInLastByte.ToString() + " Bits");
block.AddMetaData(BlockDescriptorTitle.Pause_After_Data, pauseAfterBlock.ToString() + " ms");
block.AddMetaData(BlockDescriptorTitle.Zero_Bit_Length, bit0PulseLength + " T-States");
block.AddMetaData(BlockDescriptorTitle.One_Bit_Length, bit1PulseLength + " T-States");
block.AddMetaData(BlockDescriptorTitle.Data_Length, blockSize + " Bytes");
block.AddMetaData(BlockDescriptorTitle.Bits_In_Last_Byte, bitsInLastByte + " Bits");
block.AddMetaData(BlockDescriptorTitle.Pause_After_Data, pauseAfterBlock + " ms");
// calculate period information
List<int> dataPeriods = new List<int>();
@ -1937,19 +1977,21 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
#region Pause Block Creator
/// <summary>
/// If neccessary a seperate PAUSE block will be created
/// If necessary a separate PAUSE block will be created
/// </summary>
private void CreatePauseBlock(TapeDataBlock original)
{
if (original.PauseInMS > 0)
{
TapeDataBlock pBlock = new TapeDataBlock();
pBlock.DataPeriods = new List<int>();
pBlock.BlockDescription = BlockType.PAUSE_BLOCK;
pBlock.PauseInMS = 0;
var pBlock = new TapeDataBlock
{
DataPeriods = new List<int>(),
BlockDescription = BlockType.PAUSE_BLOCK,
PauseInMS = 0
};
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 rem1000 = pauseInTStates % 70000;

View File

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

View File

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

View File

@ -13,113 +13,111 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
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);
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;
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;
}
private static int ReadCRTShort(BinaryReader reader)

View File

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

View File

@ -32,8 +32,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cassette
public override void SyncState(Serializer ser)
{
if (_tape != null) { _tape.SyncState(ser); }
_tape?.SyncState(ser);
}
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
public override byte[] TapeDataDomain
{
get
{
if (_tape != null)
{
return _tape.TapeDataDomain;
}
else
{
return null;
}
}
}
public override byte[] TapeDataDomain => _tape?.TapeDataDomain;
}
}

View File

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

View File

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

View File

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

View File

@ -179,10 +179,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
public int FrequencyLo
{
get
{
return _frequency & 0xFF;
}
get => _frequency & 0xFF;
set
{
_frequency &= 0xFF00;
@ -192,10 +189,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
public int FrequencyHi
{
get
{
return _frequency >> 8;
}
get => _frequency >> 8;
set
{
_frequency &= 0x00FF;
@ -205,37 +199,30 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
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;
_output = _wave[_waveformIndex] & (_noPulse | _pulse) & _noNoiseOrNoise;
if (_waveform > 8)
{
WriteShiftReg();
}
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
{
get
{
return _pulseWidth & 0xFF;
}
get => _pulseWidth & 0xFF;
set
{
_pulseWidth &= 0x0F00;
@ -245,11 +232,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
public int PulseWidthHi
{
get
{
return _pulseWidth >> 8;
}
get => _pulseWidth >> 8;
set
{
_pulseWidth &= 0x00FF;
@ -304,6 +287,5 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
_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)
{
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);
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();
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();
}
private static byte[] EncodeGcr(byte[] source)
@ -144,39 +142,37 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
var gcr = new int[8];
var data = new byte[4];
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)
{
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];
// -------- -------- -------- -------- --------
// 00000111 11222223 33334444 45555566 66677777
// -------- -------- -------- -------- --------
// 00000111 11222223 33334444 45555566 66677777
var outputValue = (gcr[0] << 3) | (gcr[1] >> 2);
writer.Write((byte)(outputValue & 0xFF));
outputValue = (gcr[1] << 6) | (gcr[2] << 1) | (gcr[3] >> 4);
writer.Write((byte)(outputValue & 0xFF));
outputValue = (gcr[3] << 4) | (gcr[4] >> 1);
writer.Write((byte)(outputValue & 0xFF));
outputValue = (gcr[4] << 7) | (gcr[5] << 2) | (gcr[6] >> 3);
writer.Write((byte)(outputValue & 0xFF));
outputValue = (gcr[6] << 5) | (gcr[7]);
writer.Write((byte)(outputValue & 0xFF));
}
writer.Flush();
return mem.ToArray();
var outputValue = (gcr[0] << 3) | (gcr[1] >> 2);
writer.Write((byte)(outputValue & 0xFF));
outputValue = (gcr[1] << 6) | (gcr[2] << 1) | (gcr[3] >> 4);
writer.Write((byte)(outputValue & 0xFF));
outputValue = (gcr[3] << 4) | (gcr[4] >> 1);
writer.Write((byte)(outputValue & 0xFF));
outputValue = (gcr[4] << 7) | (gcr[5] << 2) | (gcr[6] >> 3);
writer.Write((byte)(outputValue & 0xFF));
outputValue = (gcr[6] << 5) | (gcr[7]);
writer.Write((byte)(outputValue & 0xFF));
}
writer.Flush();
return mem.ToArray();
}
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 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);
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)
{
case 174848: // 35 tracks no errors
trackCount = 35;
break;
case 175531: // 35 tracks with errors
trackCount = 35;
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};
case 174848: // 35 tracks no errors
trackCount = 35;
break;
case 175531: // 35 tracks with errors
trackCount = 35;
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};
}
}
}

View File

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

View File

@ -9,59 +9,57 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
{
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);
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>();
reader.ReadByte(); // version
int trackCount = reader.ReadByte();
reader.ReadInt16(); // max track size in bytes
if (id == @"GCR-1541")
var trackOffsetTable = new int[trackCount];
var trackSpeedTable = new int[trackCount];
for (var i = 0; i < trackCount; i++)
{
reader.ReadByte(); // version
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};
trackOffsetTable[i] = reader.ReadInt32();
}
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)
@ -73,70 +71,68 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
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);
// 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);
for (var i = 0; i < trackCount; i++)
{
var trackMemWriter = new BinaryWriter(trackMem);
for (var i = 0; i < trackCount; i++)
if (trackNumbers.Contains(i))
{
if (trackNumbers.Contains(i))
{
var trackIndex = trackNumbers.IndexOf(i);
offsets.Add((int)trackMem.Length);
densities.Add(trackDensities[trackIndex]);
var trackIndex = trackNumbers.IndexOf(i);
offsets.Add((int)trackMem.Length);
densities.Add(trackDensities[trackIndex]);
var data = trackData[trackIndex];
var buffer = Enumerable.Repeat(dataFillerValue, trackMaxLength).ToArray();
var dataBytes = data.Select(d => unchecked((byte)d)).ToArray();
Array.Copy(dataBytes, buffer, dataBytes.Length);
trackMemWriter.Write((ushort)dataBytes.Length);
trackMemWriter.Write(buffer);
}
else
{
offsets.Add(-1);
densities.Add(0);
}
var data = trackData[trackIndex];
var buffer = Enumerable.Repeat(dataFillerValue, trackMaxLength).ToArray();
var dataBytes = data.Select(d => unchecked((byte)d)).ToArray();
Array.Copy(dataBytes, buffer, dataBytes.Length);
trackMemWriter.Write((ushort)dataBytes.Length);
trackMemWriter.Write(buffer);
}
trackMemWriter.Flush();
// offset table
foreach (var offset in offsets.Select(o => o >= 0 ? o + headerLength + trackCount * 8 : 0))
else
{
writer.Write(offset);
offsets.Add(-1);
densities.Add(0);
}
}
trackMemWriter.Flush();
// speed zone data
foreach (var density in densities)
{
writer.Write(density);
}
// track data
writer.Write(trackMem.ToArray());
// offset table
foreach (var offset in offsets.Select(o => o >= 0 ? o + headerLength + trackCount * 8 : 0))
{
writer.Write(offset);
}
writer.Flush();
return mem.ToArray();
// speed zone data
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
{
get
{
return "Disk Drive 6502";
}
get => "Disk Drive 6502";
set
{

View File

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

View File

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

View File

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

View File

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

View File

@ -1,8 +1,4 @@
using System;
using System.ComponentModel;
using Newtonsoft.Json;
using System.ComponentModel;
using BizHawk.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
{

View File

@ -77,7 +77,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
get
{
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
/// </summary>
private bool _tapeIsPlaying = false;
public bool TapeIsPlaying
{
get { return _tapeIsPlaying; }
}
public bool TapeIsPlaying => _tapeIsPlaying;
/// <summary>
/// A list of the currently loaded data blocks

View File

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

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