Tidy 6809 implementation. I don't think there's enough information available for me to implement a 6309

This commit is contained in:
Adrian Conlon committed 2026-06-08 22:07:20 +01:00
1 parent ff31ac05de
commit 323dff84a4
2 files changed
+198 -1132

No files matched your search

-976
View File
@@ -1,976 +0,0 @@
// <copyright file="HD6309.cs" company="Adrian Conlon">
// Copyright (c) Adrian Conlon. All rights reserved.
// </copyright>
namespace MC6809
{
using EightBit;
using System.Diagnostics;
// HD6309 - Hitachi CMOS implementation of the MC6809
// References:
// https://colorcomputerarchive.com/repo/Documents/Books/Motorola%206809%20and%20Hitachi%206309%20Programming%20Reference%20(Darren%20Atkinson).pdf
// http://www.6809.org.uk/dragon/hd6309.shtml
public sealed class HD6309(Bus bus) : MC6809(bus)
{
// MD register bits
private const byte MD_NATIVE = 0x01; // Native mode (vs 6809 emulation)
private const byte MD_FIRQ = 0x02; // FIRQ uses entire register save
private const byte MD_ILL = 0x40; // Illegal instruction flag
private const byte MD_DIV0 = 0x80; // Division by zero flag
private byte _md;
#region Registers
public Register16 W { get; } = new();
public ref byte E => ref this.W.High;
public ref byte F => ref this.W.Low;
public Register16 V { get; } = new();
public ref byte MD => ref this._md;
public uint Q
{
get => Chip.MakeInteger(this.W.Joined, this.D.Joined);
set
{
this.D.Joined = Chip.HighShort(value);
this.W.Joined = Chip.LowShort(value);
}
}
public bool NativeMode => (this._md & MD_NATIVE) != 0;
#endregion
#region Register transfer extensions
protected override Register16 ReferenceTransfer16(int specifier)
{
return specifier switch
{
0b0110 => this.W,
0b0111 => this.V,
_ => base.ReferenceTransfer16(specifier),
};
}
protected override ref byte ReferenceTransfer8(int specifier)
{
switch (specifier)
{
case 0b1110:
return ref this.E;
case 0b1111:
return ref this.F;
default:
return ref base.ReferenceTransfer8(specifier);
}
}
#endregion
#region Instruction dispatch overrides
protected override void ExecuteUnprefixed()
{
switch (this.OpCode)
{
// OIM (OR immediate with memory)
case 0x01: this.OIM_Direct(); break; // OIM direct
case 0x61: this.OIM_Indexed(); break; // OIM indexed
case 0x71: this.OIM_Extended(); break; // OIM extended
// AIM (AND immediate with memory)
case 0x02: this.AIM_Direct(); break; // AIM direct
case 0x62: this.AIM_Indexed(); break; // AIM indexed
case 0x72: this.AIM_Extended(); break; // AIM extended
// EIM (EOR immediate with memory)
case 0x05: this.EIM_Direct(); break; // EIM direct
case 0x65: this.EIM_Indexed(); break; // EIM indexed
case 0x75: this.EIM_Extended(); break; // EIM extended
// TIM (test immediate with memory, no write-back)
case 0x0B: this.TIM_Direct(); break; // TIM direct
case 0x6B: this.TIM_Indexed(); break; // TIM indexed
case 0x7B: this.TIM_Extended(); break; // TIM extended
default:
base.ExecuteUnprefixed();
break;
}
}
protected override void Execute10()
{
switch (this.OpCode)
{
// Register-to-register operations (postbyte encodes source:destination)
case 0x30: this.ImmediateByte(); this.ADDR(); Debug.Assert(this.Cycles == 4); break; // ADDR
case 0x31: this.ImmediateByte(); this.ADCR(); Debug.Assert(this.Cycles == 4); break; // ADCR
case 0x32: this.ImmediateByte(); this.SUBR(); Debug.Assert(this.Cycles == 4); break; // SUBR
case 0x33: this.ImmediateByte(); this.SBCR(); Debug.Assert(this.Cycles == 4); break; // SBCR
case 0x34: this.ImmediateByte(); this.ANDR(); Debug.Assert(this.Cycles == 4); break; // ANDR
case 0x35: this.ImmediateByte(); this.ORR(); Debug.Assert(this.Cycles == 4); break; // ORR
case 0x36: this.ImmediateByte(); this.EORR(); Debug.Assert(this.Cycles == 4); break; // EORR
case 0x37: this.ImmediateByte(); this.CMPR(); Debug.Assert(this.Cycles == 4); break; // CMPR
// W register stack operations
case 0x38: this.SwallowCurrent(); this.PSHSW(); Debug.Assert(this.Cycles == 6); break; // PSHSW
case 0x39: this.SwallowCurrent(); this.PULSW(); Debug.Assert(this.Cycles == 6); break; // PULSW
case 0x3A: this.SwallowCurrent(); this.PSHUW(); Debug.Assert(this.Cycles == 6); break; // PSHUW
case 0x3B: this.SwallowCurrent(); this.PULUW(); Debug.Assert(this.Cycles == 6); break; // PULUW
// E register operations (inherent)
case 0x40: this.SwallowCurrent(); this.NEGE(); Debug.Assert(this.Cycles == 3); break;
case 0x43: this.SwallowCurrent(); this.COME(); Debug.Assert(this.Cycles == 3); break;
case 0x44: this.SwallowCurrent(); this.LSRE(); Debug.Assert(this.Cycles == 3); break;
case 0x46: this.SwallowCurrent(); this.RORE(); Debug.Assert(this.Cycles == 3); break;
case 0x47: this.SwallowCurrent(); this.ASRE(); Debug.Assert(this.Cycles == 3); break;
case 0x48: this.SwallowCurrent(); this.ASLE(); Debug.Assert(this.Cycles == 3); break;
case 0x49: this.SwallowCurrent(); this.ROLE(); Debug.Assert(this.Cycles == 3); break;
case 0x4A: this.SwallowCurrent(); this.DECE(); Debug.Assert(this.Cycles == 3); break;
case 0x4C: this.SwallowCurrent(); this.INCE(); Debug.Assert(this.Cycles == 3); break;
case 0x4D: this.SwallowCurrent(); this.TSTE(); Debug.Assert(this.Cycles == 3); break;
case 0x4F: this.SwallowCurrent(); this.CLRE(); Debug.Assert(this.Cycles == 3); break;
// F register operations (inherent)
case 0x50: this.SwallowCurrent(); this.NEGF(); Debug.Assert(this.Cycles == 3); break;
case 0x53: this.SwallowCurrent(); this.COMF(); Debug.Assert(this.Cycles == 3); break;
case 0x54: this.SwallowCurrent(); this.LSRF(); Debug.Assert(this.Cycles == 3); break;
case 0x56: this.SwallowCurrent(); this.RORF(); Debug.Assert(this.Cycles == 3); break;
case 0x57: this.SwallowCurrent(); this.ASRF(); Debug.Assert(this.Cycles == 3); break;
case 0x58: this.SwallowCurrent(); this.ASLF(); Debug.Assert(this.Cycles == 3); break;
case 0x59: this.SwallowCurrent(); this.ROLF(); Debug.Assert(this.Cycles == 3); break;
case 0x5A: this.SwallowCurrent(); this.DECF(); Debug.Assert(this.Cycles == 3); break;
case 0x5C: this.SwallowCurrent(); this.INCF(); Debug.Assert(this.Cycles == 3); break;
case 0x5D: this.SwallowCurrent(); this.TSTF(); Debug.Assert(this.Cycles == 3); break;
case 0x5F: this.SwallowCurrent(); this.CLRF(); Debug.Assert(this.Cycles == 3); break;
// W register load/store/arithmetic
case 0x80: this.ImmediateShort(); this.SUBW(); Debug.Assert(this.Cycles == 5); break; // SUBW immediate
case 0x81: this.ImmediateShort(); this.CMPW(); Debug.Assert(this.Cycles == 5); break; // CMPW immediate
case 0x86: this.ImmediateShort(); this.LDW(); Debug.Assert(this.Cycles == 4); break; // LDW immediate
case 0x8B: this.ImmediateShort(); this.ADDW(); Debug.Assert(this.Cycles == 5); break; // ADDW immediate
case 0x90: this.DirectShort(); this.SUBW(); Debug.Assert(this.Cycles == 7); break; // SUBW direct
case 0x91: this.DirectShort(); this.CMPW(); Debug.Assert(this.Cycles == 7); break; // CMPW direct
case 0x96: this.DirectShort(); this.LDW(); Debug.Assert(this.Cycles == 6); break; // LDW direct
case 0x97: this.DirectAddress(); this.STW(); Debug.Assert(this.Cycles == 6); break; // STW direct
case 0x9B: this.DirectShort(); this.ADDW(); Debug.Assert(this.Cycles == 7); break; // ADDW direct
case 0xA0: this.IndexedShort(); this.SUBW(); Debug.Assert(this.Cycles >= 7); break; // SUBW indexed
case 0xA1: this.IndexedShort(); this.CMPW(); Debug.Assert(this.Cycles >= 7); break; // CMPW indexed
case 0xA6: this.IndexedShort(); this.LDW(); Debug.Assert(this.Cycles >= 6); break; // LDW indexed
case 0xA7: this.IndexedAddress(); this.STW(); Debug.Assert(this.Cycles >= 6); break; // STW indexed
case 0xAB: this.IndexedShort(); this.ADDW(); Debug.Assert(this.Cycles >= 7); break; // ADDW indexed
case 0xB0: this.ExtendedShort(); this.SUBW(); Debug.Assert(this.Cycles == 8); break; // SUBW extended
case 0xB1: this.ExtendedShort(); this.CMPW(); Debug.Assert(this.Cycles == 8); break; // CMPW extended
case 0xB6: this.ExtendedShort(); this.LDW(); Debug.Assert(this.Cycles == 7); break; // LDW extended
case 0xB7: this.ExtendedAddress(); this.STW(); Debug.Assert(this.Cycles == 7); break; // STW extended
case 0xBB: this.ExtendedShort(); this.ADDW(); Debug.Assert(this.Cycles == 8); break; // ADDW extended
// Q register load/store
case 0xCD: this.LDQ_Immediate(); break; // LDQ immediate
case 0xDC: this.DirectShort(); this.LDQ_Lower(); break; // LDQ direct
case 0xEC: this.IndexedShort(); this.LDQ_Lower(); break; // LDQ indexed
case 0xFC: this.ExtendedShort(); this.LDQ_Lower(); break; // LDQ extended
case 0xDD: this.DirectAddress(); this.STQ(); break; // STQ direct
case 0xED: this.IndexedAddress(); this.STQ(); break; // STQ indexed
case 0xFD: this.ExtendedAddress(); this.STQ(); break; // STQ extended
default:
base.Execute10();
break;
}
}
protected override void Execute11()
{
switch (this.OpCode)
{
// Block transfers (TFM) — $11,38-$11,3B
case 0x38: this.ImmediateByte(); this.TFM_IncrBoth(); break; // TFM R0+,R1+
case 0x39: this.ImmediateByte(); this.TFM_DecrBoth(); break; // TFM R0-,R1-
case 0x3A: this.ImmediateByte(); this.TFM_IncrSrc(); break; // TFM R0+,R1
case 0x3B: this.ImmediateByte(); this.TFM_IncrDst(); break; // TFM R0,R1+
// LDMD — $11,3D immediate
case 0x3D: this.ImmediateByte(); this.LDMD(); break; // LDMD immediate
// Bit manipulation instructions — $11,30-$11,37
case 0x30: this.ImmediateByte(); this.BAND(); break; // BAND
case 0x31: this.ImmediateByte(); this.BIAND(); break; // BIAND
case 0x32: this.ImmediateByte(); this.BOR(); break; // BOR
case 0x33: this.ImmediateByte(); this.BIOR(); break; // BIOR
case 0x34: this.ImmediateByte(); this.BEOR(); break; // BEOR
case 0x35: this.ImmediateByte(); this.BIEOR(); break; // BIEOR
case 0x36: this.ImmediateByte(); this.LDBT(); break; // LDBT
case 0x37: this.ImmediateByte(); this.STBT(); break; // STBT
// E register operations
case 0x80: this.ImmediateByte(); this.SUBE(); Debug.Assert(this.Cycles == 3); break; // SUBE immediate
case 0x81: this.ImmediateByte(); this.CMPE(); Debug.Assert(this.Cycles == 3); break; // CMPE immediate
case 0x86: this.ImmediateByte(); this.LDE(); Debug.Assert(this.Cycles == 2); break; // LDE immediate
case 0x8B: this.ImmediateByte(); this.ADDE(); Debug.Assert(this.Cycles == 3); break; // ADDE immediate
case 0x90: this.DirectByte(); this.SUBE(); Debug.Assert(this.Cycles == 5); break; // SUBE direct
case 0x91: this.DirectByte(); this.CMPE(); Debug.Assert(this.Cycles == 5); break; // CMPE direct
case 0x96: this.DirectByte(); this.LDE(); Debug.Assert(this.Cycles == 4); break; // LDE direct
case 0x97: this.DirectAddress(); this.STE(); Debug.Assert(this.Cycles == 4); break; // STE direct
case 0x9B: this.DirectByte(); this.ADDE(); Debug.Assert(this.Cycles == 5); break; // ADDE direct
case 0xA0: this.IndexedByte(); this.SUBE(); Debug.Assert(this.Cycles >= 5); break; // SUBE indexed
case 0xA1: this.IndexedByte(); this.CMPE(); Debug.Assert(this.Cycles >= 5); break; // CMPE indexed
case 0xA6: this.IndexedByte(); this.LDE(); Debug.Assert(this.Cycles >= 4); break; // LDE indexed
case 0xA7: this.IndexedAddress(); this.STE(); Debug.Assert(this.Cycles >= 4); break; // STE indexed
case 0xAB: this.IndexedByte(); this.ADDE(); Debug.Assert(this.Cycles >= 5); break; // ADDE indexed
case 0xB0: this.ExtendedByte(); this.SUBE(); Debug.Assert(this.Cycles == 6); break; // SUBE extended
case 0xB1: this.ExtendedByte(); this.CMPE(); Debug.Assert(this.Cycles == 6); break; // CMPE extended
case 0xB6: this.ExtendedByte(); this.LDE(); Debug.Assert(this.Cycles == 5); break; // LDE extended
case 0xB7: this.ExtendedAddress(); this.STE(); Debug.Assert(this.Cycles == 5); break; // STE extended
case 0xBB: this.ExtendedByte(); this.ADDE(); Debug.Assert(this.Cycles == 6); break; // ADDE extended
// F register operations
case 0xC0: this.ImmediateByte(); this.SUBF(); Debug.Assert(this.Cycles == 3); break; // SUBF immediate
case 0xC1: this.ImmediateByte(); this.CMPF(); Debug.Assert(this.Cycles == 3); break; // CMPF immediate
case 0xC6: this.ImmediateByte(); this.LDF(); Debug.Assert(this.Cycles == 2); break; // LDF immediate
case 0xCB: this.ImmediateByte(); this.ADDF(); Debug.Assert(this.Cycles == 3); break; // ADDF immediate
case 0xD0: this.DirectByte(); this.SUBF(); Debug.Assert(this.Cycles == 5); break; // SUBF direct
case 0xD1: this.DirectByte(); this.CMPF(); Debug.Assert(this.Cycles == 5); break; // CMPF direct
case 0xD6: this.DirectByte(); this.LDF(); Debug.Assert(this.Cycles == 4); break; // LDF direct
case 0xD7: this.DirectAddress(); this.STF(); Debug.Assert(this.Cycles == 4); break; // STF direct
case 0xDB: this.DirectByte(); this.ADDF(); Debug.Assert(this.Cycles == 5); break; // ADDF direct
case 0xE0: this.IndexedByte(); this.SUBF(); Debug.Assert(this.Cycles >= 5); break; // SUBF indexed
case 0xE1: this.IndexedByte(); this.CMPF(); Debug.Assert(this.Cycles >= 5); break; // CMPF indexed
case 0xE6: this.IndexedByte(); this.LDF(); Debug.Assert(this.Cycles >= 4); break; // LDF indexed
case 0xE7: this.IndexedAddress(); this.STF(); Debug.Assert(this.Cycles >= 4); break; // STF indexed
case 0xEB: this.IndexedByte(); this.ADDF(); Debug.Assert(this.Cycles >= 5); break; // ADDF indexed
case 0xF0: this.ExtendedByte(); this.SUBF(); Debug.Assert(this.Cycles == 6); break; // SUBF extended
case 0xF1: this.ExtendedByte(); this.CMPF(); Debug.Assert(this.Cycles == 6); break; // CMPF extended
case 0xF6: this.ExtendedByte(); this.LDF(); Debug.Assert(this.Cycles == 5); break; // LDF extended
case 0xF7: this.ExtendedAddress(); this.STF(); Debug.Assert(this.Cycles == 5); break; // STF extended
case 0xFB: this.ExtendedByte(); this.ADDF(); Debug.Assert(this.Cycles == 6); break; // ADDF extended
// Extended arithmetic
case 0x8D: this.ImmediateByte(); this.DIVD(); break; // DIVD immediate
case 0x9D: this.DirectByte(); this.DIVD(); break; // DIVD direct
case 0xAD: this.IndexedByte(); this.DIVD(); break; // DIVD indexed
case 0xBD: this.ExtendedByte(); this.DIVD(); break; // DIVD extended
case 0x8E: this.ImmediateShort(); this.MULD(); break; // MULD immediate
case 0x9E: this.DirectShort(); this.MULD(); break; // MULD direct
case 0xAE: this.IndexedShort(); this.MULD(); break; // MULD indexed
case 0xBE: this.ExtendedShort(); this.MULD(); break; // MULD extended
default:
base.Execute11();
break;
}
}
#endregion
#region OIM / AIM / EIM / TIM - immediate-with-memory operations
private void OIM_Direct()
{
this.FetchByte();
var mask = this.Bus.Data;
this.DirectByte();
this.MemoryWrite(this.EA, this.Or(mask));
}
private void OIM_Indexed()
{
this.FetchByte();
var mask = this.Bus.Data;
this.IndexedByte();
this.MemoryWrite(this.EA, this.Or(mask));
}
private void OIM_Extended()
{
this.FetchByte();
var mask = this.Bus.Data;
this.ExtendedByte();
this.MemoryWrite(this.EA, this.Or(mask));
}
private void AIM_Direct()
{
this.FetchByte();
var mask = this.Bus.Data;
this.DirectByte();
this.MemoryWrite(this.EA, this.And(mask));
}
private void AIM_Indexed()
{
this.FetchByte();
var mask = this.Bus.Data;
this.IndexedByte();
this.MemoryWrite(this.EA, this.And(mask));
}
private void AIM_Extended()
{
this.FetchByte();
var mask = this.Bus.Data;
this.ExtendedByte();
this.MemoryWrite(this.EA, this.And(mask));
}
private void EIM_Direct()
{
this.FetchByte();
var mask = this.Bus.Data;
this.DirectByte();
this.MemoryWrite(this.EA, this.ExclusiveOr(mask));
}
private void EIM_Indexed()
{
this.FetchByte();
var mask = this.Bus.Data;
this.IndexedByte();
this.MemoryWrite(this.EA, this.ExclusiveOr(mask));
}
private void EIM_Extended()
{
this.FetchByte();
var mask = this.Bus.Data;
this.ExtendedByte();
this.MemoryWrite(this.EA, this.ExclusiveOr(mask));
}
private void TIM_Direct()
{
this.FetchByte();
var mask = this.Bus.Data;
this.DirectByte();
this.And(mask);
this.SwallowRead(2);
}
private void TIM_Indexed()
{
this.FetchByte();
var mask = this.Bus.Data;
this.IndexedByte();
this.And(mask);
this.SwallowRead(2);
}
private void TIM_Extended()
{
this.FetchByte();
var mask = this.Bus.Data;
this.ExtendedByte();
this.And(mask);
this.SwallowRead(2);
}
#endregion
#region Register-to-register operations
private void ADDR()
{
var post = this.Bus.Data;
var sourceSpecification = HighNibble(post);
var destinationSpecification = LowNibble(post);
this.SwallowRead(2);
var sourceType = sourceSpecification & 0x8;
var destinationType = destinationSpecification & 0x8;
if (sourceType == 0 && destinationType == 0)
{
var source = this.ReferenceTransfer16(sourceSpecification);
var destination = this.ReferenceTransfer16(destinationSpecification);
this.Add(destination, source, destination);
}
else if (sourceType != 0 && destinationType != 0)
{
ref var source = ref this.ReferenceTransfer8(sourceSpecification);
ref var destination = ref this.ReferenceTransfer8(destinationSpecification);
destination = this.Add(destination, source);
}
}
private void ADCR()
{
var post = this.Bus.Data;
var sourceSpecification = HighNibble(post);
var destinationSpecification = LowNibble(post);
this.SwallowRead(2);
var sourceType = sourceSpecification & 0x8;
var destinationType = destinationSpecification & 0x8;
if (sourceType == 0 && destinationType == 0)
{
var source = this.ReferenceTransfer16(sourceSpecification);
var destination = this.ReferenceTransfer16(destinationSpecification);
this.Add(destination, source, this.CarryFlag, destination);
}
else if (sourceType != 0 && destinationType != 0)
{
ref var source = ref this.ReferenceTransfer8(sourceSpecification);
ref var destination = ref this.ReferenceTransfer8(destinationSpecification);
destination = this.Add(destination, source, this.CarryFlag);
}
}
private void SUBR()
{
var post = this.Bus.Data;
var sourceSpecification = HighNibble(post);
var destinationSpecification = LowNibble(post);
this.SwallowRead(2);
var sourceType = sourceSpecification & 0x8;
var destinationType = destinationSpecification & 0x8;
if (sourceType == 0 && destinationType == 0)
{
var source = this.ReferenceTransfer16(sourceSpecification);
var destination = this.ReferenceTransfer16(destinationSpecification);
this.Subtract(destination, source, destination);
}
else if (sourceType != 0 && destinationType != 0)
{
ref var source = ref this.ReferenceTransfer8(sourceSpecification);
ref var destination = ref this.ReferenceTransfer8(destinationSpecification);
destination = this.Subtract(destination, source);
}
}
private void SBCR()
{
var post = this.Bus.Data;
var sourceSpecification = HighNibble(post);
var destinationSpecification = LowNibble(post);
this.SwallowRead(2);
var sourceType = sourceSpecification & 0x8;
var destinationType = destinationSpecification & 0x8;
if (sourceType == 0 && destinationType == 0)
{
var source = this.ReferenceTransfer16(sourceSpecification);
var destination = this.ReferenceTransfer16(destinationSpecification);
this.Subtract(destination, source, this.CarryFlag, destination);
}
else if (sourceType != 0 && destinationType != 0)
{
ref var source = ref this.ReferenceTransfer8(sourceSpecification);
ref var destination = ref this.ReferenceTransfer8(destinationSpecification);
destination = this.Subtract(destination, source, this.CarryFlag);
}
}
private void ANDR()
{
var post = this.Bus.Data;
var sourceSpecification = HighNibble(post);
var destinationSpecification = LowNibble(post);
this.SwallowRead(2);
var sourceType = sourceSpecification & 0x8;
var destinationType = destinationSpecification & 0x8;
if (sourceType == 0 && destinationType == 0)
{
var source = this.ReferenceTransfer16(sourceSpecification);
var destination = this.ReferenceTransfer16(destinationSpecification);
this.And(destination, source, destination);
}
else if (sourceType != 0 && destinationType != 0)
{
ref var source = ref this.ReferenceTransfer8(sourceSpecification);
ref var destination = ref this.ReferenceTransfer8(destinationSpecification);
destination = this.And(destination, source);
}
}
private void ORR()
{
var post = this.Bus.Data;
var sourceSpecification = HighNibble(post);
var destinationSpecification = LowNibble(post);
this.SwallowRead(2);
var sourceType = sourceSpecification & 0x8;
var destinationType = destinationSpecification & 0x8;
if (sourceType == 0 && destinationType == 0)
{
var source = this.ReferenceTransfer16(sourceSpecification);
var destination = this.ReferenceTransfer16(destinationSpecification);
this.Or(destination, source, destination);
}
else if (sourceType != 0 && destinationType != 0)
{
ref var source = ref this.ReferenceTransfer8(sourceSpecification);
ref var destination = ref this.ReferenceTransfer8(destinationSpecification);
destination = this.Or(destination, source);
}
}
private void EORR()
{
var post = this.Bus.Data;
var sourceSpecification = HighNibble(post);
var destinationSpecification = LowNibble(post);
this.SwallowRead(2);
var sourceType = sourceSpecification & 0x8;
var destinationType = destinationSpecification & 0x8;
if (sourceType == 0 && destinationType == 0)
{
var source = this.ReferenceTransfer16(sourceSpecification);
var destination = this.ReferenceTransfer16(destinationSpecification);
this.ExclusiveOr(destination, source, destination);
}
else if (sourceType != 0 && destinationType != 0)
{
ref var source = ref this.ReferenceTransfer8(sourceSpecification);
ref var destination = ref this.ReferenceTransfer8(destinationSpecification);
destination = this.ExclusiveOr(destination, source);
}
}
private void CMPR()
{
var immediate = this.Bus.Data;
var sourceSpecification = HighNibble(immediate);
var destinationSpecification = LowNibble(immediate);
this.SwallowRead(2);
var sourceType = sourceSpecification & 0x8;
var destinationType = destinationSpecification & 0x8;
if (sourceType == 0 && destinationType == 0)
{
var source = this.ReferenceTransfer16(sourceSpecification);
var destination = this.ReferenceTransfer16(destinationSpecification);
this.Compare(destination, source);
}
else if (sourceType != 0 && destinationType != 0)
{
ref var source = ref this.ReferenceTransfer8(sourceSpecification);
ref var destination = ref this.ReferenceTransfer8(destinationSpecification);
this.Compare(destination, source);
}
}
#endregion
#region W register stack operations
private void PSHSW()
{
this.SwallowRead(3);
this.Push(this.S, this.W);
}
private void PULSW()
{
this.SwallowRead(3);
this.W.Assign(this.PopWord(this.S));
}
private void PSHUW()
{
this.SwallowRead(3);
this.Push(this.U, this.W);
}
private void PULUW()
{
this.SwallowRead(3);
this.W.Assign(this.PopWord(this.U));
}
#endregion
#region E register operations
private void NEGE() => this.E = this.Negate(this.E);
private void NEGF() => this.F = this.Negate(this.F);
private void COME() => this.E = this.Complement(this.E);
private void LSRE() => this.E = this.LogicalShiftRight(this.E);
private void RORE() => this.E = this.RotateRight(this.E);
private void ASRE() => this.E = this.ArithmeticShiftRight(this.E);
private void ASLE() => this.E = this.ArithmeticShiftLeft(this.E);
private void ROLE() => this.E = this.RotateLeft(this.E);
private void DECE() => this.E = this.Decrement(this.E);
private void INCE() => this.E = this.Increment(this.E);
private void TSTE() => this.Through(this.E);
private void CLRE() => this.E = this.Clear();
private void LDE() => this.E = this.Through(this.Bus.Data);
private void STE() => this.MemoryWrite(this.EA, this.Through(this.E));
private void ADDE() => this.E = this.Add(this.E, this.Bus.Data);
private void SUBE() => this.E = this.Subtract(this.E, this.Bus.Data);
private void CMPE() => this.Compare(this.E, this.Bus.Data);
#endregion
#region F register operations
private void COMF() => this.F = this.Complement(this.F);
private void LSRF() => this.F = this.LogicalShiftRight(this.F);
private void RORF() => this.F = this.RotateRight(this.F);
private void ASRF() => this.F = this.ArithmeticShiftRight(this.F);
private void ASLF() => this.F = this.ArithmeticShiftLeft(this.F);
private void ROLF() => this.F = this.RotateLeft(this.F);
private void DECF() => this.F = this.Decrement(this.F);
private void INCF() => this.F = this.Increment(this.F);
private void TSTF() => this.Through(this.F);
private void CLRF() => this.F = this.Clear();
private void LDF() => this.F = this.Through(this.Bus.Data);
private void STF() => this.MemoryWrite(this.EA, this.Through(this.F));
private void ADDF() => this.F = this.Add(this.F, this.Bus.Data);
private void SUBF() => this.F = this.Subtract(this.F, this.Bus.Data);
private void CMPF() => this.Compare(this.F, this.Bus.Data);
#endregion
#region W register operations
private void LDW()
{
this.W.Assign(this.Through(this.Intermediate));
}
private void STW()
{
this.SetShort(this.EA, this.Through(this.W));
}
private void CMPW()
{
this.Subtract(this.W, this.Intermediate, this.Intermediate);
}
private void ADDW()
{
this.Add(this.W, this.Intermediate, this.W);
}
private void SUBW()
{
this.Subtract(this.W, this.Intermediate, this.W);
}
#endregion
#region Q register operations
private void LDQ_Immediate()
{
this.FetchInto(this.D);
this.FetchInto(this.W);
this.Through(this.Q != 0 ? (byte)1 : (byte)0);
}
private void LDQ_Lower()
{
// Intermediate holds upper word (D); read the lower word (W) from the next address
this.D.Assign(this.Intermediate);
this.Bus.Address.Joined += 2;
this.GetInto(this.W);
this.Through(this.Q != 0 ? (byte)1 : (byte)0);
}
private void STQ()
{
// Write D then W to consecutive memory locations
this.SetShort(this.EA, this.D);
this.Bus.Address.Joined += 2;
this.SetShort(this.W);
this.Through(this.D.NonZero || this.W.NonZero ? (byte)1 : (byte)0);
}
#endregion
#region Bit manipulation instructions
// postbyte: bits 7:6 = register (CC=00, A=01, B=10), bits 5:3 = destination bit, bits 2:0 = source bit
// followed by a direct-page address
private void BAND()
{
var immediate = this.Bus.Data;
this.DirectByte();
var result = this.BitTransfer(immediate, this.Bus.Data, (s, d) => (byte)(d & s));
this.ApplyBitTransfer(immediate, result);
}
private void BIAND()
{
var immediate = this.Bus.Data;
this.DirectByte();
var result = this.BitTransfer(immediate, this.Bus.Data, (s, d) => (byte)(d & ~s));
this.ApplyBitTransfer(immediate, result);
}
private void BOR()
{
var immediate = this.Bus.Data;
this.DirectByte();
var result = this.BitTransfer(immediate, this.Bus.Data, (s, d) => (byte)(d | s));
this.ApplyBitTransfer(immediate, result);
}
private void BIOR()
{
var immediate = this.Bus.Data;
this.DirectByte();
var result = this.BitTransfer(immediate, this.Bus.Data, (s, d) => (byte)(d | ~s));
this.ApplyBitTransfer(immediate, result);
}
private void BEOR()
{
var immediate = this.Bus.Data;
this.DirectByte();
var result = this.BitTransfer(immediate, this.Bus.Data, (s, d) => (byte)(d ^ s));
this.ApplyBitTransfer(immediate, result);
}
private void BIEOR()
{
var immediate = this.Bus.Data;
this.DirectByte();
var result = this.BitTransfer(immediate, this.Bus.Data, (s, d) => (byte)(d ^ ~s));
this.ApplyBitTransfer(immediate, result);
}
private void LDBT()
{
// Load a single bit from memory into a register bit
var immediate = this.Bus.Data;
this.DirectByte();
var memBit = (immediate >> 0) & 0x07;
var regBit = (immediate >> 3) & 0x07;
var regSelect = (immediate >> 6) & 0x03;
var memVal = (this.Bus.Data >> memBit) & 1;
ref byte reg = ref this.BitRegister(regSelect);
if (memVal != 0)
reg |= (byte)(1 << regBit);
else
reg &= (byte)~(1 << regBit);
}
private void STBT()
{
// Store a single register bit into a memory bit
var immediate = this.Bus.Data;
this.DirectAddress();
var memBit = (immediate >> 0) & 0x07;
var regBit = (immediate >> 3) & 0x07;
var regSelect = (immediate >> 6) & 0x03;
ref byte reg = ref this.BitRegister(regSelect);
var regVal = (reg >> regBit) & 1;
this.MemoryRead(this.EA);
byte mem = this.Bus.Data;
if (regVal != 0)
mem |= (byte)(1 << memBit);
else
mem &= (byte)~(1 << memBit);
this.MemoryWrite(this.EA, mem);
}
private ref byte BitRegister(int sel)
{
switch (sel)
{
case 1: return ref this.A;
case 2: return ref this.B;
default: return ref this.CC;
}
}
// Returns the new value of the destination bit in position 0
private byte BitTransfer(byte postbyte, byte memByte, Func<byte, byte, byte> op)
{
var srcBit = (postbyte >> 0) & 0x07;
var dstBit = (postbyte >> 3) & 0x07;
var regSelect = (postbyte >> 6) & 0x03;
ref byte reg = ref this.BitRegister(regSelect);
var s = (byte)((memByte >> srcBit) & 1);
var d = (byte)((reg >> dstBit) & 1);
return op(s, d);
}
private void ApplyBitTransfer(byte postbyte, byte bitValue)
{
var dstBit = (postbyte >> 3) & 0x07;
var regSelect = (postbyte >> 6) & 0x03;
ref byte reg = ref this.BitRegister(regSelect);
if ((bitValue & 1) != 0)
reg |= (byte)(1 << dstBit);
else
reg &= (byte)~(1 << dstBit);
}
#endregion
#region Block transfer (TFM)
// TFM register specifiers: D=0, X=1, Y=2, U=3, S=4
private Register16 TFMRegister(int spec)
{
return spec switch
{
0x0000 => this.D,
0x0001 => this.X,
0x0010 => this.Y,
0x0011 => this.U,
0x0100 => this.S,
_ => throw new ArgumentOutOfRangeException(nameof(spec), spec, "Invalid TFM register specifier"),
};
}
// TFM R0+,R1+: transfer bytes from R0 to R1, incrementing both
private void TFM_IncrBoth()
{
var immediate = this.Bus.Data;
this.SwallowRead(6);
while (this.W.NonZero)
{
var sourceSpecifier = HighNibble(immediate);
var source = this.TFMRegister(sourceSpecifier);
this.MemoryRead(source);
source.Increment();
var destinationSpecifier = LowNibble(immediate);
var destination = this.TFMRegister(destinationSpecifier);
this.MemoryWrite(destination, this.Bus.Data);
destination.Increment();
this.W.Decrement();
this.SwallowRead(3);
}
}
// TFM R0-,R1-: transfer bytes from R0 to R1, decrementing both
private void TFM_DecrBoth()
{
var immediate = this.Bus.Data;
this.SwallowRead(6);
while (this.W.NonZero)
{
var sourceSpecifier = HighNibble(immediate);
var source = this.TFMRegister(sourceSpecifier);
this.MemoryRead(source);
source.Decrement();
var destinationSpecifier = LowNibble(immediate);
var destination = this.TFMRegister(destinationSpecifier);
this.MemoryWrite(destination, this.Bus.Data);
destination.Decrement();
this.W.Decrement();
this.SwallowRead(3);
}
}
// TFM R0+,R1: transfer from incrementing R0 to fixed R1
private void TFM_IncrSrc()
{
var immediate = this.Bus.Data;
this.SwallowRead(6);
while (this.W.NonZero)
{
var sourceSpecifier = HighNibble(immediate);
var source = this.TFMRegister(sourceSpecifier);
this.MemoryRead(source);
source.Increment();
var destinationSpecifier = LowNibble(immediate);
var destination = this.TFMRegister(destinationSpecifier);
this.MemoryWrite(destination, this.Bus.Data);
this.W.Decrement();
this.SwallowRead(3);
}
}
// TFM R0,R1+: transfer from fixed R0 to incrementing R1
private void TFM_IncrDst()
{
var immediate = this.Bus.Data;
this.SwallowRead(6);
while (this.W.NonZero)
{
var sourceSpecifier = HighNibble(immediate);
var source = this.TFMRegister(sourceSpecifier);
this.MemoryRead(source);
var destinationSpecifier = LowNibble(immediate);
var destination = this.TFMRegister(destinationSpecifier);
this.MemoryWrite(destination, this.Bus.Data);
destination.Increment();
this.W.Decrement();
this.SwallowRead(3);
}
}
#endregion
#region Extended arithmetic (MULD, DIVD)
private void MULD()
{
// Q = D * operand (signed 16x16 → 32-bit)
this.SwallowRead(26);
this.Q = (uint)((short)this.D.Joined * (short)this.Intermediate.Joined);
this.Through(this.D);
this.CC = ClearBit(this.CC, (byte)StatusBits.CF);
}
private void DIVD()
{
// D / operand (byte): B = quotient, A = remainder
this.SwallowRead(22);
var divisor = (sbyte)this.Bus.Data;
if (divisor == 0)
{
this._md |= MD_DIV0;
return;
}
var dividend = (short)this.D.Joined;
var quotient = dividend / divisor;
var remainder = dividend % divisor;
if (quotient > 127 || quotient < -128)
{
this.CC = SetBit(this.CC, (byte)StatusBits.VF);
return;
}
this.B = this.Through((byte)quotient);
this.A = (byte)remainder;
this.CC = SetBit(this.CC, (byte)StatusBits.CF, this.B & (byte)Bits.Bit0);
}
#endregion
#region Mode register
private void LDMD() => this._md = this.Bus.Data;
#endregion
}
}
+198 -156
View File
@@ -25,7 +25,7 @@ namespace MC6809
|-------|-------|-----------------------------------|
*/
public class MC6809 : BigEndianProcessor
public sealed class MC6809 : BigEndianProcessor
{
private const byte _vectorRESET = 0xfe; // RESET vector
private const byte _vectorNMI = 0xfc; // NMI vector
@@ -352,7 +352,7 @@ namespace MC6809
public Register16 S { get; } = new();
protected Register16 EA { get; } = new();
private Register16 EA { get; } = new();
public ref byte DP => ref this._dp;
@@ -418,49 +418,49 @@ namespace MC6809
private static byte ClearBit(byte f, StatusBits flag, int condition) => ClearBit(f, (byte)flag, condition);
protected byte AdjustZero(byte datum) => ClearBit(this.CC, StatusBits.ZF, datum);
private byte AdjustZero(byte datum) => ClearBit(this.CC, StatusBits.ZF, datum);
protected byte AdjustZero(ushort datum) => ClearBit(this.CC, StatusBits.ZF, datum);
private byte AdjustZero(ushort datum) => ClearBit(this.CC, StatusBits.ZF, datum);
protected byte AdjustZero(Register16 datum)
private byte AdjustZero(Register16 datum)
{
Debug.Assert(datum is not null);
return this.AdjustZero(datum.Joined);
}
protected byte AdjustNegative(byte datum) => SetBit(this.CC, StatusBits.NF, datum & (byte)Bits.Bit7);
private byte AdjustNegative(byte datum) => SetBit(this.CC, StatusBits.NF, datum & (byte)Bits.Bit7);
protected byte AdjustNegative(ushort datum) => SetBit(this.CC, StatusBits.NF, datum & (ushort)Bits.Bit15);
private byte AdjustNegative(ushort datum) => SetBit(this.CC, StatusBits.NF, datum & (ushort)Bits.Bit15);
protected byte AdjustNZ(byte datum)
private byte AdjustNZ(byte datum)
{
this.CC = this.AdjustZero(datum);
return this.AdjustNegative(datum);
}
protected byte AdjustNZ(ushort datum)
private byte AdjustNZ(ushort datum)
{
this.CC = this.AdjustZero(datum);
return this.AdjustNegative(datum);
}
protected byte AdjustNZ(Register16 datum)
private byte AdjustNZ(Register16 datum)
{
Debug.Assert(datum is not null);
return this.AdjustNZ(datum.Joined);
}
protected byte AdjustCarry(ushort datum) => SetBit(this.CC, StatusBits.CF, datum & (ushort)Bits.Bit8); // 8-bit addition
private byte AdjustCarry(ushort datum) => SetBit(this.CC, StatusBits.CF, datum & (ushort)Bits.Bit8); // 8-bit addition
protected byte AdjustCarry(uint datum) => SetBit(this.CC, StatusBits.CF, (int)(datum & (uint)Bits.Bit16)); // 16-bit addition
private byte AdjustCarry(uint datum) => SetBit(this.CC, StatusBits.CF, (int)(datum & (uint)Bits.Bit16)); // 16-bit addition
protected byte AdjustCarry(Register16 datum)
private byte AdjustCarry(Register16 datum)
{
Debug.Assert(datum is not null);
return this.AdjustCarry(datum.Joined);
}
protected byte AdjustOverflow(byte before, byte data, Register16 after)
private byte AdjustOverflow(byte before, byte data, Register16 after)
{
Debug.Assert(after is not null);
var lowAfter = after.Low;
@@ -468,16 +468,16 @@ namespace MC6809
return SetBit(this.CC, StatusBits.VF, (before ^ data ^ lowAfter ^ highAfter << 7) & (int)Bits.Bit7);
}
protected byte AdjustOverflow(ushort before, ushort data, uint after)
private byte AdjustOverflow(ushort before, ushort data, uint after)
{
var lowAfter = (ushort)(after & (uint)Mask.Sixteen);
var highAfter = (ushort)(after >> 16);
return SetBit(this.CC, StatusBits.VF, (before ^ data ^ lowAfter ^ highAfter << 15) & (int)Bits.Bit15);
}
protected byte AdjustHalfCarry(byte before, byte data, byte after) => SetBit(this.CC, StatusBits.HF, (before ^ data ^ after) & (int)Bits.Bit4);
private byte AdjustHalfCarry(byte before, byte data, byte after) => SetBit(this.CC, StatusBits.HF, (before ^ data ^ after) & (int)Bits.Bit4);
protected byte AdjustAddition(byte before, byte data, Register16 after)
private byte AdjustAddition(byte before, byte data, Register16 after)
{
Debug.Assert(after is not null);
var result = after.Low;
@@ -487,7 +487,7 @@ namespace MC6809
return this.AdjustHalfCarry(before, data, result);
}
protected byte AdjustAddition(ushort before, ushort data, uint after)
private byte AdjustAddition(ushort before, ushort data, uint after)
{
this.Intermediate.Joined = (ushort)after;
this.CC = this.AdjustNZ(this.Intermediate.Joined);
@@ -495,14 +495,14 @@ namespace MC6809
return this.AdjustOverflow(before, data, after);
}
protected byte AdjustAddition(Register16 before, Register16 data, uint after)
private byte AdjustAddition(Register16 before, Register16 data, uint after)
{
Debug.Assert(before is not null);
Debug.Assert(data is not null);
return this.AdjustAddition(before.Joined, data.Joined, after);
}
protected byte AdjustSubtraction(byte before, byte data, Register16 after)
private byte AdjustSubtraction(byte before, byte data, Register16 after)
{
Debug.Assert(after is not null);
var result = after.Low;
@@ -511,7 +511,7 @@ namespace MC6809
return this.AdjustOverflow(before, data, after);
}
protected byte AdjustSubtraction(ushort before, ushort data, uint after)
private byte AdjustSubtraction(ushort before, ushort data, uint after)
{
this.Intermediate.Joined = (ushort)after;
this.CC = this.AdjustNZ(this.Intermediate.Joined);
@@ -519,7 +519,7 @@ namespace MC6809
return this.AdjustOverflow(before, data, after);
}
protected byte AdjustSubtraction(Register16 before, Register16 data, uint after)
private byte AdjustSubtraction(Register16 before, Register16 data, uint after)
{
Debug.Assert(before is not null);
Debug.Assert(data is not null);
@@ -622,7 +622,7 @@ namespace MC6809
protected override void Push(byte value) => this.PushS(value);
protected void Push(Register16 stack, byte value)
private void Push(Register16 stack, byte value)
{
Debug.Assert(stack is not null);
stack.Decrement();
@@ -631,7 +631,7 @@ namespace MC6809
private void PushS(byte value) => this.Push(this.S, value);
protected void Push(Register16 stack, Register16 value)
private void Push(Register16 stack, Register16 value)
{
Debug.Assert(stack is not null);
Debug.Assert(value is not null);
@@ -639,7 +639,7 @@ namespace MC6809
this.Push(stack, value.High);
}
protected void Pop(Register16 stack)
private void Pop(Register16 stack)
{
Debug.Assert(stack is not null);
this.MemoryRead(stack);
@@ -648,7 +648,7 @@ namespace MC6809
private void PopS() => this.Pop(this.S);
protected Register16 PopWord(Register16 stack)
private Register16 PopWord(Register16 stack)
{
this.Pop(stack);
this.Intermediate.High = this.Bus.Data;
@@ -661,41 +661,43 @@ namespace MC6809
#region Addressing modes
#region Address resolution
protected override void ImmediateAddress()
{
this.EA.Assign(this.PC);
this.PC.Increment();
}
protected void RelativeByteAddress()
private void RelativeByteAddress()
{
this.FetchByte();
var offset = (sbyte)this.Bus.Data;
this.EA.Joined = (ushort)(this.PC.Joined + offset);
}
protected void RelativeWordAddress()
private void RelativeWordAddress()
{
this.FetchShort();
var offset = (short)this.Intermediate.Joined;
this.EA.Joined = (ushort)(this.PC.Joined + offset);
}
protected void DirectAddress()
private void DirectAddress()
{
this.FetchByte();
this.EA.Assign(this.Bus.Data, this.DP);
this.SwallowRead();
}
protected void ExtendedAddress()
private void ExtendedAddress()
{
this.FetchInto(this.Intermediate);
this.EA.Assign(this.Intermediate);
this.SwallowRead();
}
protected Register16 RR(int which)
private Register16 RR(int which)
{
return which switch
{
@@ -707,7 +709,7 @@ namespace MC6809
};
}
protected void IndexedAddress()
private void IndexedAddress()
{
this.FetchByte();
var type = this.Bus.Data;
@@ -807,7 +809,13 @@ namespace MC6809
}
}
protected void ImmediateByte()
#endregion
#region Address and read
#region Address and read byte
private void ImmediateByte()
{
this.ImmediateAddress();
this.MemoryRead(this.EA);
@@ -818,39 +826,43 @@ namespace MC6809
this.ImmediateByte();
}
protected void DirectByte()
private void DirectByte()
{
this.DirectAddress();
this.MemoryRead(this.EA);
}
protected void IndexedByte()
private void IndexedByte()
{
this.IndexedAddress();
this.MemoryRead(this.EA);
}
protected void ExtendedByte()
private void ExtendedByte()
{
this.ExtendedAddress();
this.MemoryRead(this.EA);
}
protected void ImmediateShort() => this.FetchShort();
#endregion
protected void DirectShort()
#region Address and read word
private void ImmediateWord() => this.FetchShort();
private void DirectWord()
{
this.DirectAddress();
this.GetShort(this.EA);
}
protected void IndexedShort()
private void IndexedWord()
{
this.IndexedAddress();
this.GetShort(this.EA);
}
protected void ExtendedShort()
private void ExtendedWord()
{
this.ExtendedAddress();
this.GetShort(this.EA);
@@ -858,19 +870,43 @@ namespace MC6809
#endregion
#endregion
#endregion
#region Load/store 8 or 16-bit data
private byte Through(byte data)
{
this.CC = ClearBit(this.CC, StatusBits.VF);
this.CC = this.AdjustNZ(data);
return data;
}
private ushort Through(ushort data)
{
this.CC = ClearBit(this.CC, StatusBits.VF);
this.CC = this.AdjustNZ(data);
return data;
}
private Register16 Through(Register16 data)
{
this.CC = ClearBit(this.CC, StatusBits.VF);
this.CC = this.AdjustNZ(data);
return data;
}
#region Load byte
private void LDA() => this.Assign(ref this.A);
private void LDB() => this.Assign(ref this.B);
private void Assign(ref byte destination) => destination = this.Through(this.Bus.Data);
protected byte Through(byte data)
{
this.CC = ClearBit(this.CC, StatusBits.VF);
this.CC = this.AdjustNZ(data);
return data;
}
#endregion
#region Load word
private void LDD() => this.Assign(this.D);
private void LDS() => this.Assign(this.S);
@@ -878,27 +914,25 @@ namespace MC6809
private void LDX() => this.Assign(this.X);
private void LDY() => this.Assign(this.Y);
private void Assign(Register16 destination) => destination.Assign(this.Through(this.Intermediate));
protected ushort Through(ushort data)
private void Assign(Register16 destination)
{
this.CC = ClearBit(this.CC, StatusBits.VF);
this.CC = this.AdjustNZ(data);
return data;
Debug.Assert(destination is not null);
destination.Assign(this.Through(this.Intermediate));
}
protected Register16 Through(Register16 data)
{
Debug.Assert(data is not null);
this.Through(data.Joined);
return data;
}
#endregion
#region Store byte
private void STA() => this.Store(this.A);
private void STB() => this.Store(this.B);
private void Store(byte data) => this.MemoryWrite(this.EA, this.Through(data));
#endregion
#region Store word
private void STD() => this.Store(this.D);
private void STU() => this.Store(this.U);
private void STS() => this.Store(this.S);
@@ -909,6 +943,8 @@ namespace MC6809
#endregion
#endregion
#region Branching
private void LBSR()
@@ -1016,7 +1052,7 @@ namespace MC6809
this.PSH(stack, control);
}
protected void PSH(Register16 stack, byte control)
private void PSH(Register16 stack, byte control)
{
// Reverse order of PUL
@@ -1077,7 +1113,7 @@ namespace MC6809
this.SwallowPop(stack);
}
protected void PUL(Register16 stack, byte control)
private void PUL(Register16 stack, byte control)
{
// Reverse order of PSH
@@ -1135,7 +1171,7 @@ namespace MC6809
#region 8-bit register transfers
protected virtual ref byte ReferenceTransfer8(int specifier)
private ref byte ReferenceTransfer8(int specifier)
{
switch (specifier)
{
@@ -1152,7 +1188,7 @@ namespace MC6809
}
}
protected virtual Register16 ReferenceTransfer16(int specifier)
private Register16 ReferenceTransfer16(int specifier)
{
return specifier switch
{
@@ -1252,7 +1288,7 @@ namespace MC6809
#region Cycle wastage
protected void SwallowRead(int ticks = 1)
private void SwallowRead(int ticks = 1)
{
for (int i = 0; i < ticks; i++)
{
@@ -1260,7 +1296,7 @@ namespace MC6809
}
}
protected void SwallowCurrent(int ticks = 1)
private void SwallowCurrent(int ticks = 1)
{
for (int i = 0; i < ticks; i++)
{
@@ -1268,11 +1304,11 @@ namespace MC6809
}
}
protected void SwallowPop(Register16 stack) => this.MemoryRead(stack);
private void SwallowPop(Register16 stack) => this.MemoryRead(stack);
protected void SwallowEffectiveAddress() => this.MemoryRead(this.EA);
private void SwallowEffectiveAddress() => this.MemoryRead(this.EA);
protected void SwallowSpin(int ticks = 1)
private void SwallowSpin(int ticks = 1)
{
for (int i = 0; i < ticks; i++)
{
@@ -1335,7 +1371,7 @@ namespace MC6809
#region Instruction dispatching
protected virtual void ExecuteUnprefixed()
private void ExecuteUnprefixed()
{
switch (this.OpCode)
{
@@ -1367,10 +1403,10 @@ namespace MC6809
case 0xeb: this.IndexedByte(); this.ADDB(); Debug.Assert(this.Cycles >= 4); break; // ADD (ADDB indexed)
case 0xfb: this.ExtendedByte(); this.ADDB(); Debug.Assert(this.Cycles == 5); break; // ADD (ADDB extended)
case 0xc3: this.ImmediateShort(); this.ADDD(); Debug.Assert(this.Cycles == 4); break; // ADD (ADDD immediate)
case 0xd3: this.DirectShort(); this.ADDD(); Debug.Assert(this.Cycles == 6); break; // ADD (ADDD direct)
case 0xe3: this.IndexedShort(); this.ADDD(); Debug.Assert(this.Cycles >= 6); break; // ADD (ADDD indexed)
case 0xf3: this.ExtendedShort(); this.ADDD(); Debug.Assert(this.Cycles == 7); break; // ADD (ADDD extended)
case 0xc3: this.ImmediateWord(); this.ADDD(); Debug.Assert(this.Cycles == 4); break; // ADD (ADDD immediate)
case 0xd3: this.DirectWord(); this.ADDD(); Debug.Assert(this.Cycles == 6); break; // ADD (ADDD direct)
case 0xe3: this.IndexedWord(); this.ADDD(); Debug.Assert(this.Cycles >= 6); break; // ADD (ADDD indexed)
case 0xf3: this.ExtendedWord(); this.ADDD(); Debug.Assert(this.Cycles == 7); break; // ADD (ADDD extended)
// AND
case 0x84: this.ImmediateByte(); this.ANDA(); Debug.Assert(this.Cycles == 2); break; // AND (ANDA immediate)
@@ -1432,10 +1468,10 @@ namespace MC6809
case 0xf1: this.ExtendedByte(); this.CMPB(); Debug.Assert(this.Cycles == 5); break; // CMP (CMPB, extended)
// CMPX
case 0x8c: this.ImmediateShort(); this.CMPX(); Debug.Assert(this.Cycles == 4); break; // CMP (CMPX, immediate)
case 0x9c: this.DirectShort(); this.CMPX(); Debug.Assert(this.Cycles == 6); break; // CMP (CMPX, direct)
case 0xac: this.IndexedShort(); this.CMPX(); Debug.Assert(this.Cycles >= 6); break; // CMP (CMPX, indexed)
case 0xbc: this.ExtendedShort(); this.CMPX(); Debug.Assert(this.Cycles == 7); break; // CMP (CMPX, extended)
case 0x8c: this.ImmediateWord(); this.CMPX(); Debug.Assert(this.Cycles == 4); break; // CMP (CMPX, immediate)
case 0x9c: this.DirectWord(); this.CMPX(); Debug.Assert(this.Cycles == 6); break; // CMP (CMPX, direct)
case 0xac: this.IndexedWord(); this.CMPX(); Debug.Assert(this.Cycles >= 6); break; // CMP (CMPX, indexed)
case 0xbc: this.ExtendedWord(); this.CMPX(); Debug.Assert(this.Cycles == 7); break; // CMP (CMPX, extended)
// COM
case 0x03: this.DirectByte(); this.COM(); Debug.Assert(this.Cycles == 6); break; // COM (direct)
@@ -1506,22 +1542,22 @@ namespace MC6809
case 0xf6: this.ExtendedByte(); this.LDB(); Debug.Assert(this.Cycles == 5); break; // LD (LDB extended)
// LDD
case 0xcc: this.ImmediateShort(); this.LDD(); Debug.Assert(this.Cycles == 3); break; // LD (LDD immediate)
case 0xdc: this.DirectShort(); this.LDD(); Debug.Assert(this.Cycles == 5); break; // LD (LDD direct)
case 0xec: this.IndexedShort(); this.LDD(); Debug.Assert(this.Cycles >= 5); break; // LD (LDD indexed)
case 0xfc: this.ExtendedShort(); this.LDD(); Debug.Assert(this.Cycles == 6); break; // LD (LDD extended)
case 0xcc: this.ImmediateWord(); this.LDD(); Debug.Assert(this.Cycles == 3); break; // LD (LDD immediate)
case 0xdc: this.DirectWord(); this.LDD(); Debug.Assert(this.Cycles == 5); break; // LD (LDD direct)
case 0xec: this.IndexedWord(); this.LDD(); Debug.Assert(this.Cycles >= 5); break; // LD (LDD indexed)
case 0xfc: this.ExtendedWord(); this.LDD(); Debug.Assert(this.Cycles == 6); break; // LD (LDD extended)
// LDU
case 0xce: this.ImmediateShort(); this.LDU(); Debug.Assert(this.Cycles == 3); break; // LD (LDU immediate)
case 0xde: this.DirectShort(); this.LDU(); Debug.Assert(this.Cycles == 5); break; // LD (LDU direct)
case 0xee: this.IndexedShort(); this.LDU(); Debug.Assert(this.Cycles >= 5); break; // LD (LDU indexed)
case 0xfe: this.ExtendedShort(); this.LDU(); Debug.Assert(this.Cycles == 6); break; // LD (LDU extended)
case 0xce: this.ImmediateWord(); this.LDU(); Debug.Assert(this.Cycles == 3); break; // LD (LDU immediate)
case 0xde: this.DirectWord(); this.LDU(); Debug.Assert(this.Cycles == 5); break; // LD (LDU direct)
case 0xee: this.IndexedWord(); this.LDU(); Debug.Assert(this.Cycles >= 5); break; // LD (LDU indexed)
case 0xfe: this.ExtendedWord(); this.LDU(); Debug.Assert(this.Cycles == 6); break; // LD (LDU extended)
// LDX
case 0x8e: this.ImmediateShort(); this.LDX(); Debug.Assert(this.Cycles == 3); break; // LD (LDX immediate)
case 0x9e: this.DirectShort(); this.LDX(); Debug.Assert(this.Cycles == 5); break; // LD (LDX direct)
case 0xae: this.IndexedShort(); this.LDX(); Debug.Assert(this.Cycles >= 5); break; // LD (LDX indexed)
case 0xbe: this.ExtendedShort(); this.LDX(); Debug.Assert(this.Cycles == 6); break; // LD (LDX extended)
case 0x8e: this.ImmediateWord(); this.LDX(); Debug.Assert(this.Cycles == 3); break; // LD (LDX immediate)
case 0x9e: this.DirectWord(); this.LDX(); Debug.Assert(this.Cycles == 5); break; // LD (LDX direct)
case 0xae: this.IndexedWord(); this.LDX(); Debug.Assert(this.Cycles >= 5); break; // LD (LDX indexed)
case 0xbe: this.ExtendedWord(); this.LDX(); Debug.Assert(this.Cycles == 6); break; // LD (LDX extended)
// LEA
case 0x30: this.IndexedAddress(); this.LEAX(); Debug.Assert(this.Cycles >= 4); break; // LEA (LEAX indexed)
@@ -1653,10 +1689,10 @@ namespace MC6809
case 0xf0: this.ExtendedByte(); this.SUBB(); Debug.Assert(this.Cycles == 5); break; // SUB (SUBB extended)
// SUBD
case 0x83: this.ImmediateShort(); this.SUBD(); Debug.Assert(this.Cycles == 4); break; // SUB (SUBD immediate)
case 0x93: this.DirectShort(); this.SUBD(); Debug.Assert(this.Cycles == 6); break; // SUB (SUBD direct)
case 0xa3: this.IndexedShort(); this.SUBD(); Debug.Assert(this.Cycles >= 6); break; // SUB (SUBD indexed)
case 0xb3: this.ExtendedShort(); this.SUBD(); Debug.Assert(this.Cycles == 7); break; // SUB (SUBD extended)
case 0x83: this.ImmediateWord(); this.SUBD(); Debug.Assert(this.Cycles == 4); break; // SUB (SUBD immediate)
case 0x93: this.DirectWord(); this.SUBD(); Debug.Assert(this.Cycles == 6); break; // SUB (SUBD direct)
case 0xa3: this.IndexedWord(); this.SUBD(); Debug.Assert(this.Cycles >= 6); break; // SUB (SUBD indexed)
case 0xb3: this.ExtendedWord(); this.SUBD(); Debug.Assert(this.Cycles == 7); break; // SUB (SUBD extended)
// SWI
case 0x3f: this.SwallowCurrent(); this.SWI(); Debug.Assert(this.Cycles == 19); break; // SWI (inherent)
@@ -1701,37 +1737,37 @@ namespace MC6809
}
}
protected virtual void Execute10()
private void Execute10()
{
switch (this.OpCode)
{
// CMP
// CMPD
case 0x83: this.ImmediateShort(); this.CMPD(); Debug.Assert(this.Cycles == 5); break; // CMP (CMPD, immediate)
case 0x93: this.DirectShort(); this.CMPD(); Debug.Assert(this.Cycles == 7); break; // CMP (CMPD, direct)
case 0xa3: this.IndexedShort(); this.CMPD(); Debug.Assert(this.Cycles >= 7); break; // CMP (CMPD, indexed)
case 0xb3: this.ExtendedShort(); this.CMPD(); Debug.Assert(this.Cycles == 8); break; // CMP (CMPD, extended)
case 0x83: this.ImmediateWord(); this.CMPD(); Debug.Assert(this.Cycles == 5); break; // CMP (CMPD, immediate)
case 0x93: this.DirectWord(); this.CMPD(); Debug.Assert(this.Cycles == 7); break; // CMP (CMPD, direct)
case 0xa3: this.IndexedWord(); this.CMPD(); Debug.Assert(this.Cycles >= 7); break; // CMP (CMPD, indexed)
case 0xb3: this.ExtendedWord(); this.CMPD(); Debug.Assert(this.Cycles == 8); break; // CMP (CMPD, extended)
// CMPY
case 0x8c: this.ImmediateShort(); this.CMPY(); Debug.Assert(this.Cycles == 5); break; // CMP (CMPY, immediate)
case 0x9c: this.DirectShort(); this.CMPY(); Debug.Assert(this.Cycles == 7); break; // CMP (CMPY, direct)
case 0xac: this.IndexedShort(); this.CMPY(); Debug.Assert(this.Cycles >= 7); break; // CMP (CMPY, indexed)
case 0xbc: this.ExtendedShort(); this.CMPY(); Debug.Assert(this.Cycles == 8); break; // CMP (CMPY, extended)
case 0x8c: this.ImmediateWord(); this.CMPY(); Debug.Assert(this.Cycles == 5); break; // CMP (CMPY, immediate)
case 0x9c: this.DirectWord(); this.CMPY(); Debug.Assert(this.Cycles == 7); break; // CMP (CMPY, direct)
case 0xac: this.IndexedWord(); this.CMPY(); Debug.Assert(this.Cycles >= 7); break; // CMP (CMPY, indexed)
case 0xbc: this.ExtendedWord(); this.CMPY(); Debug.Assert(this.Cycles == 8); break; // CMP (CMPY, extended)
// LD
// LDS
case 0xce: this.ImmediateShort(); this.LDS(); Debug.Assert(this.Cycles == 4); break; // LD (LDS immediate)
case 0xde: this.DirectShort(); this.LDS(); Debug.Assert(this.Cycles == 6); break; // LD (LDS direct)
case 0xee: this.IndexedShort(); this.LDS(); Debug.Assert(this.Cycles >= 6); break; // LD (LDS indexed)
case 0xfe: this.ExtendedShort(); this.LDS(); Debug.Assert(this.Cycles == 7); break; // LD (LDS extended)
case 0xce: this.ImmediateWord(); this.LDS(); Debug.Assert(this.Cycles == 4); break; // LD (LDS immediate)
case 0xde: this.DirectWord(); this.LDS(); Debug.Assert(this.Cycles == 6); break; // LD (LDS direct)
case 0xee: this.IndexedWord(); this.LDS(); Debug.Assert(this.Cycles >= 6); break; // LD (LDS indexed)
case 0xfe: this.ExtendedWord(); this.LDS(); Debug.Assert(this.Cycles == 7); break; // LD (LDS extended)
// LDY
case 0x8e: this.ImmediateShort(); this.LDY(); Debug.Assert(this.Cycles == 4); break; // LD (LDY immediate)
case 0x9e: this.DirectShort(); this.LDY(); Debug.Assert(this.Cycles == 6); break; // LD (LDY direct)
case 0xae: this.IndexedShort(); this.LDY(); Debug.Assert(this.Cycles >= 6); break; // LD (LDY indexed)
case 0xbe: this.ExtendedShort(); this.LDY(); Debug.Assert(this.Cycles == 7); break; // LD (LDY extended)
case 0x8e: this.ImmediateWord(); this.LDY(); Debug.Assert(this.Cycles == 4); break; // LD (LDY immediate)
case 0x9e: this.DirectWord(); this.LDY(); Debug.Assert(this.Cycles == 6); break; // LD (LDY direct)
case 0xae: this.IndexedWord(); this.LDY(); Debug.Assert(this.Cycles >= 6); break; // LD (LDY indexed)
case 0xbe: this.ExtendedWord(); this.LDY(); Debug.Assert(this.Cycles == 7); break; // LD (LDY extended)
// Branching
case 0x21: this.RelativeWordAddress(); this.LBRN(); Debug.Assert(this.Cycles == 5); break; // BRN (LBRN relative)
@@ -1768,23 +1804,23 @@ namespace MC6809
}
}
protected virtual void Execute11()
private void Execute11()
{
switch (this.OpCode)
{
// CMP
// CMPU
case 0x83: this.ImmediateShort(); this.CMPU(); Debug.Assert(this.Cycles == 5); break; // CMP (CMPU, immediate)
case 0x93: this.DirectShort(); this.CMPU(); Debug.Assert(this.Cycles == 7); break; // CMP (CMPU, direct)
case 0xa3: this.IndexedShort(); this.CMPU(); Debug.Assert(this.Cycles >= 7); break; // CMP (CMPU, indexed)
case 0xb3: this.ExtendedShort(); this.CMPU(); Debug.Assert(this.Cycles == 8); break; // CMP (CMPU, extended)
case 0x83: this.ImmediateWord(); this.CMPU(); Debug.Assert(this.Cycles == 5); break; // CMP (CMPU, immediate)
case 0x93: this.DirectWord(); this.CMPU(); Debug.Assert(this.Cycles == 7); break; // CMP (CMPU, direct)
case 0xa3: this.IndexedWord(); this.CMPU(); Debug.Assert(this.Cycles >= 7); break; // CMP (CMPU, indexed)
case 0xb3: this.ExtendedWord(); this.CMPU(); Debug.Assert(this.Cycles == 8); break; // CMP (CMPU, extended)
// CMPS
case 0x8c: this.ImmediateShort(); this.CMPS(); Debug.Assert(this.Cycles == 5); break; // CMP (CMPS, immediate)
case 0x9c: this.DirectShort(); this.CMPS(); Debug.Assert(this.Cycles == 7); break; // CMP (CMPS, direct)
case 0xac: this.IndexedShort(); this.CMPS(); Debug.Assert(this.Cycles >= 7); break; // CMP (CMPS, indexed)
case 0xbc: this.ExtendedShort(); this.CMPS(); Debug.Assert(this.Cycles == 8); break; // CMP (CMPS, extended)
case 0x8c: this.ImmediateWord(); this.CMPS(); Debug.Assert(this.Cycles == 5); break; // CMP (CMPS, immediate)
case 0x9c: this.DirectWord(); this.CMPS(); Debug.Assert(this.Cycles == 7); break; // CMP (CMPS, direct)
case 0xac: this.IndexedWord(); this.CMPS(); Debug.Assert(this.Cycles >= 7); break; // CMP (CMPS, indexed)
case 0xbc: this.ExtendedWord(); this.CMPS(); Debug.Assert(this.Cycles == 8); break; // CMP (CMPS, extended)
// SWI
case 0x3f: this.SwallowCurrent(); this.SWI3(); Debug.Assert(this.Cycles == 20); break; // SWI (SWI3 inherent)
@@ -1813,16 +1849,18 @@ namespace MC6809
private byte Add(byte operand) => this.Add(operand, this.Bus.Data);
protected byte Add(byte operand, byte data, int carry = 0)
private byte Add(byte operand, byte data, int carry = 0)
{
this.Intermediate.Joined = (ushort)(operand + data + carry);
this.CC = this.AdjustAddition(operand, data, this.Intermediate);
return this.Intermediate.Low;
}
private void ADDD() => this.Add(this.D, this.Intermediate, this.D);
private void ADDD() => this.AddWord(this.D);
protected void Add(Register16 operand, Register16 data, int carry, Register16 result)
private void AddWord(Register16 operand) => this.Add(operand, this.Intermediate, operand);
private void Add(Register16 operand, Register16 data, int carry, Register16 result)
{
Debug.Assert(operand is not null);
Debug.Assert(data is not null);
@@ -1833,7 +1871,7 @@ namespace MC6809
this.SwallowRead();
}
protected void Add(Register16 operand, Register16 data, Register16 result) => this.Add(operand, data, 0, result);
private void Add(Register16 operand, Register16 data, Register16 result) => this.Add(operand, data, 0, result);
private void ANDCC()
{
@@ -1844,9 +1882,9 @@ namespace MC6809
private void ANDA() => this.A = this.And(this.A);
private void ANDB() => this.B = this.And(this.B);
protected ushort And(ushort operand, ushort data) => this.Through((ushort)(operand & data));
private ushort And(ushort operand, ushort data) => this.Through((ushort)(operand & data));
protected void And(Register16 operand, Register16 data, Register16 destination)
private void And(Register16 operand, Register16 data, Register16 destination)
{
Debug.Assert(operand is not null);
Debug.Assert(data is not null);
@@ -1854,9 +1892,9 @@ namespace MC6809
destination.Joined = this.And(operand.Joined, data.Joined);
}
protected byte And(byte operand, byte data) => this.Through((byte)(operand & data));
private byte And(byte operand, byte data) => this.Through((byte)(operand & data));
protected byte And(byte operand) => this.And(operand, this.Bus.Data);
private byte And(byte operand) => this.And(operand, this.Bus.Data);
private void ASLA() => this.A = this.ArithmeticShiftLeft(this.A);
@@ -1869,7 +1907,7 @@ namespace MC6809
this.MemoryWrite(result);
}
protected byte ArithmeticShiftLeft(byte operand)
private byte ArithmeticShiftLeft(byte operand)
{
this.CC = SetBit(this.CC, StatusBits.CF, operand & (byte)Bits.Bit7);
this.CC = this.AdjustNZ(operand <<= 1);
@@ -1889,7 +1927,7 @@ namespace MC6809
this.MemoryWrite(result);
}
protected byte ArithmeticShiftRight(byte operand)
private byte ArithmeticShiftRight(byte operand)
{
this.CC = SetBit(this.CC, StatusBits.CF, operand & (byte)Bits.Bit0);
var result = (byte)(operand >> 1 | (operand & (byte)Bits.Bit7));
@@ -1914,25 +1952,27 @@ namespace MC6809
this.MemoryWrite(result);
}
protected byte Clear()
private byte Clear()
{
this.CC = ClearBit(this.CC, StatusBits.CF);
return this.Through((byte)0U);
}
private void CMPA() => this.Compare(this.A, this.Bus.Data);
private void CMPB() => this.Compare(this.B, this.Bus.Data);
private void CMPA() => this.Compare(this.A);
private void CMPB() => this.Compare(this.B);
protected void Compare(ushort operand, ushort data) => this.Subtract(operand, data);
private void Compare(ushort operand, ushort data) => this.Subtract(operand, data);
protected void Compare(Register16 operand, Register16 data)
private void Compare(Register16 operand, Register16 data)
{
Debug.Assert(operand is not null);
Debug.Assert(data is not null);
this.Compare(operand.Joined, data.Joined);
}
protected void Compare(byte operand, byte data) => this.Subtract(operand, data);
private void Compare(byte operand, byte data) => this.Subtract(operand, data);
private void Compare(byte operand) => this.Subtract(operand, this.Bus.Data);
private void CMPU() => this.Compare(this.U);
private void CMPS() => this.Compare(this.S);
@@ -1940,7 +1980,7 @@ namespace MC6809
private void CMPX() => this.Compare(this.X);
private void CMPY() => this.Compare(this.Y);
protected void Compare(Register16 operand) => this.Subtract(operand, this.Intermediate, this.Intermediate);
private void Compare(Register16 operand) => this.Subtract(operand, this.Intermediate, this.Intermediate);
private void COMA() => this.A = this.Complement(this.A);
@@ -1953,7 +1993,7 @@ namespace MC6809
this.MemoryWrite(result);
}
protected byte Complement(byte operand)
private byte Complement(byte operand)
{
this.CC = SetBit(this.CC, StatusBits.CF);
return this.Through((byte)~operand);
@@ -1999,9 +2039,9 @@ namespace MC6809
private void EORA() => this.A = this.ExclusiveOr(this.A);
private void EORB() => this.B = this.ExclusiveOr(this.B);
protected ushort ExclusiveOr(ushort operand, ushort data) => this.Through((ushort)(operand ^ data));
private ushort ExclusiveOr(ushort operand, ushort data) => this.Through((ushort)(operand ^ data));
protected void ExclusiveOr(Register16 operand, Register16 data, Register16 destination)
private void ExclusiveOr(Register16 operand, Register16 data, Register16 destination)
{
Debug.Assert(operand is not null);
Debug.Assert(data is not null);
@@ -2009,9 +2049,9 @@ namespace MC6809
destination.Joined = this.ExclusiveOr(operand.Joined, data.Joined);
}
protected byte ExclusiveOr(byte operand, byte data) => this.Through((byte)(operand ^ data));
private byte ExclusiveOr(byte operand, byte data) => this.Through((byte)(operand ^ data));
protected byte ExclusiveOr(byte operand) => this.ExclusiveOr(operand, this.Bus.Data);
private byte ExclusiveOr(byte operand) => this.ExclusiveOr(operand, this.Bus.Data);
private void DECA() => this.A = this.Decrement(this.A);
@@ -2024,7 +2064,7 @@ namespace MC6809
this.MemoryWrite(result);
}
protected byte Decrement(byte operand)
private byte Decrement(byte operand)
{
this.Intermediate.Joined = (ushort)(operand - 1);
var result = this.Intermediate.Low;
@@ -2044,7 +2084,7 @@ namespace MC6809
this.MemoryWrite(result);
}
protected byte Increment(byte operand)
private byte Increment(byte operand)
{
this.Intermediate.Joined = (ushort)(operand + 1);
var result = this.Intermediate.Low;
@@ -2073,7 +2113,7 @@ namespace MC6809
this.MemoryWrite(result);
}
protected byte LogicalShiftRight(byte operand)
private byte LogicalShiftRight(byte operand)
{
this.CC = SetBit(this.CC, StatusBits.CF, operand & (byte)Bits.Bit0);
this.CC = this.AdjustNZ(operand >>= 1);
@@ -2099,7 +2139,7 @@ namespace MC6809
this.MemoryWrite(result);
}
protected byte Negate(byte operand)
private byte Negate(byte operand)
{
this.CC = SetBit(this.CC, StatusBits.VF, operand == (byte)Bits.Bit7);
this.Intermediate.Joined = (ushort)(~operand + 1);
@@ -2118,9 +2158,9 @@ namespace MC6809
private void ORA() => this.A = this.Or(this.A);
private void ORB() => this.B = this.Or(this.B);
protected ushort Or(ushort operand, ushort data) => this.Through((ushort)(operand | data));
private ushort Or(ushort operand, ushort data) => this.Through((ushort)(operand | data));
protected void Or(Register16 operand, Register16 data, Register16 destination)
private void Or(Register16 operand, Register16 data, Register16 destination)
{
Debug.Assert(operand is not null);
Debug.Assert(data is not null);
@@ -2128,9 +2168,9 @@ namespace MC6809
destination.Joined = this.Or(operand.Joined, data.Joined);
}
protected byte Or(byte operand, byte data) => this.Through((byte)(operand | data));
private byte Or(byte operand, byte data) => this.Through((byte)(operand | data));
protected byte Or(byte operand) => this.Or(operand, this.Bus.Data);
private byte Or(byte operand) => this.Or(operand, this.Bus.Data);
private void ROLA() => this.A = this.RotateLeft(this.A);
@@ -2143,7 +2183,7 @@ namespace MC6809
this.MemoryWrite(result);
}
protected byte RotateLeft(byte operand)
private byte RotateLeft(byte operand)
{
var carryIn = this.CarryFlag;
this.CC = SetBit(this.CC, StatusBits.CF, operand & (byte)Bits.Bit7);
@@ -2164,7 +2204,7 @@ namespace MC6809
this.MemoryWrite(result);
}
protected byte RotateRight(byte operand)
private byte RotateRight(byte operand)
{
var carryIn = this.CarryFlag;
this.CC = SetBit(this.CC, StatusBits.CF, operand & (byte)Bits.Bit0);
@@ -2195,16 +2235,18 @@ namespace MC6809
private byte Subtract(byte operand) => this.Subtract(operand, this.Bus.Data);
protected byte Subtract(byte operand, byte data, int carry = 0)
private byte Subtract(byte operand, byte data, int carry = 0)
{
this.Intermediate.Joined = (ushort)(operand - data - carry);
this.CC = this.AdjustSubtraction(operand, data, this.Intermediate);
return this.Intermediate.Low;
}
private void SUBD() => this.Subtract(this.D, this.Intermediate, this.D);
private void SUBD() => this.SubtractWord(this.D);
protected ushort Subtract(ushort operand, ushort data, int carry = 0)
private void SubtractWord(Register16 operand) => this.Subtract(operand, this.Intermediate, operand);
private ushort Subtract(ushort operand, ushort data, int carry = 0)
{
var subtraction = operand - data - carry;
this.CC = this.AdjustSubtraction(operand, data, (uint)subtraction);
@@ -2212,7 +2254,7 @@ namespace MC6809
return (ushort)subtraction;
}
protected void Subtract(Register16 operand, Register16 data, int carry, Register16 result)
private void Subtract(Register16 operand, Register16 data, int carry, Register16 result)
{
Debug.Assert(operand is not null);
Debug.Assert(data is not null);
@@ -2220,7 +2262,7 @@ namespace MC6809
result.Joined = this.Subtract(operand.Joined, data.Joined, carry);
}
protected void Subtract(Register16 operand, Register16 data, Register16 result) => this.Subtract(operand, data, 0, result);
private void Subtract(Register16 operand, Register16 data, Register16 result) => this.Subtract(operand, data, 0, result);
private void SEX() => this.A = this.SEX(this.B);
@@ -2298,7 +2340,7 @@ namespace MC6809
this.SwallowRead();
}
protected void LEA(Register16 register)
private void LEA(Register16 register)
{
Debug.Assert(register is not null);
register.Assign(this.EA);