From 41b4ba6d09903c55e8e937d5ac1dc747a4624f84 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Fri, 12 Jun 2026 21:51:10 +0100 Subject: [PATCH] Regionalise some flag manipulation in 6809 --- MC6809/MC6809.cs | 72 +++++++++++++++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 26 deletions(-) diff --git a/MC6809/MC6809.cs b/MC6809/MC6809.cs index af0602f..e910441 100644 --- a/MC6809/MC6809.cs +++ b/MC6809/MC6809.cs @@ -362,39 +362,49 @@ namespace MC6809 #region Status (etc.) bit twiddling + #region Status bits + + public int CarryFlag => this.CC & (byte)StatusBits.CF; + + public int OverflowFlag => this.CC & (byte)StatusBits.VF; + + public int ZeroFlag => this.CC & (byte)StatusBits.ZF; + + public int NegativeFlag => this.CC & (byte)StatusBits.NF; + + public int InterruptMaskedFlag => this.CC & (byte)StatusBits.IF; + + public int HalfCarryFlag => this.CC & (byte)StatusBits.HF; + + public int FastInterruptMaskedFlag => this.CC & (byte)StatusBits.FF; + public int EntireRegisterSetFlag => this.CC & (byte)StatusBits.EF; + #endregion + + #region Status bits as booleans + + public bool Carry => this.CarryFlag != 0; + + public bool Overflow => this.OverflowFlag != 0; + + public bool Zero => this.ZeroFlag != 0; + + public bool Negative => this.NegativeFlag != 0; + + public bool InterruptMasked => this.InterruptMaskedFlag != 0; + + public bool HalfCarry => this.HalfCarryFlag != 0; + + public bool FastInterruptMasked => this.FastInterruptMaskedFlag != 0; + public bool EntireRegisterSet => this.EntireRegisterSetFlag != 0; public bool EntireFlag => this.EntireRegisterSet; - public int FastInterruptMaskedFlag => this.CC & (byte)StatusBits.FF; + #endregion - public bool FastInterruptMasked => this.FastInterruptMaskedFlag != 0; - - public int HalfCarryFlag => this.CC & (byte)StatusBits.HF; - - public bool HalfCarry => this.HalfCarryFlag != 0; - - public int InterruptMaskedFlag => this.CC & (byte)StatusBits.IF; - - public bool InterruptMasked => this.InterruptMaskedFlag != 0; - - public int NegativeFlag => this.CC & (byte)StatusBits.NF; - - public bool Negative => this.NegativeFlag != 0; - - public int ZeroFlag => this.CC & (byte)StatusBits.ZF; - - public bool Zero => this.ZeroFlag != 0; - - public int OverflowFlag => this.CC & (byte)StatusBits.VF; - - public bool Overflow => this.OverflowFlag != 0; - - public int CarryFlag => this.CC & (byte)StatusBits.CF; - - public bool Carry => this.CarryFlag != 0; + #region Branch flag synthesis private bool LS => this.Carry || this.Zero; // (C OR Z) @@ -408,6 +418,10 @@ namespace MC6809 private bool GT => !this.LE; // !(Z OR (N XOR V)) + #endregion + + #region Status bits to int overloads + private static byte SetBit(byte f, StatusBits flag) => SetBit(f, (byte)flag); private static byte SetBit(byte f, StatusBits flag, int condition) => SetBit(f, (byte)flag, condition); @@ -418,6 +432,10 @@ namespace MC6809 private static byte ClearBit(byte f, StatusBits flag, int condition) => ClearBit(f, (byte)flag, condition); + #endregion + + #region Higher-level status bit adjustments + private byte AdjustZero(byte datum) => ClearBit(this.CC, StatusBits.ZF, datum); private byte AdjustZero(ushort datum) => ClearBit(this.CC, StatusBits.ZF, datum); @@ -521,6 +539,8 @@ namespace MC6809 #endregion + #endregion + #region Interrupt etc. handlers protected override void HandleRESET()