Fix a bunch of analysis issues

This commit is contained in:
Adrian Conlon 2025-04-01 09:32:29 +01:00
parent 820fb707b9
commit 973590690c
4 changed files with 28 additions and 20 deletions

View File

@ -3,13 +3,18 @@
// </copyright>
namespace LR35902
{
using System.Collections.ObjectModel;
public class AbstractColourPalette<T>
{
protected AbstractColourPalette()
{
this.Colours = [.. _colours];
}
protected T[] Colours { get; } = new T[4];
private readonly List<T> _colours = new(4);
protected Collection<T> Colours { get; }
public T Colour(int index) => this.Colours[index];
}

View File

@ -1,13 +0,0 @@
// <copyright file="ColourShades.cs" company="Adrian Conlon">
// Copyright (c) Adrian Conlon. All rights reserved.
// </copyright>
namespace LR35902
{
public enum ColourShades
{
Off,
Light,
Medium,
Dark,
}
}

View File

@ -25,6 +25,8 @@ namespace LR35902
public static string AsFlag(byte value, StatusBits flag, string represents) => AsFlag(value, (byte)flag, represents);
public static string AsFlag(byte value, Interrupts flag, string represents) => AsFlag(value, (byte)flag, represents);
public static string AsFlag(byte value, Bits flag, string represents) => AsFlag(value, (byte)flag, represents);
public static string AsFlags(byte value) =>
@ -37,6 +39,13 @@ namespace LR35902
+ $"{AsFlag(value, Bits.Bit1, "+")}"
+ $"{AsFlag(value, Bits.Bit0, "+")}";
public static string AsInterrupt(byte value) =>
$"{AsFlag(value, Interrupts.KeypadPressed, "K")}"
+ $"{AsFlag(value, Interrupts.SerialTransfer, "S")}"
+ $"{AsFlag(value, Interrupts.TimerOverflow, "T")}"
+ $"{AsFlag(value, Interrupts.DisplayControlStatus, "D")}"
+ $"{AsFlag(value, Interrupts.VerticalBlank, "V")}";
public static string State(LR35902 cpu)
{
ArgumentNullException.ThrowIfNull(cpu);
@ -56,12 +65,18 @@ namespace LR35902
var h = cpu.H;
var l = cpu.L;
var ime = cpu.IME?1:0;
var ie = cpu.IE;
var i_f = cpu.IF;
var masked = cpu.MaskedInterrupts;
return
$"PC={pc.Word:x4} SP={sp.Word:x4} "
$"PC={pc.Word:x4} SP={sp.Word:x4} "
+ $"A={a:x2} F={AsFlags(f)} "
+ $"B={b:x2} C={c:x2} "
+ $"D={d:x2} E={e:x2} "
+ $"H={h:x2} L={l:x2}";
+ $"H={h:x2} L={l:x2} "
+ $"IME={ime} IE={AsInterrupt(ie)} IF={AsInterrupt(i_f)} Masked={AsInterrupt(masked)}";
}
public string Disassemble(LR35902 cpu)

View File

@ -59,6 +59,8 @@ namespace LR35902
set => this.bus.IO.Poke(IoRegisters.IF, value);
}
public byte MaskedInterrupts => (byte)(this.IE & this.IF);
private bool Stopped { get; set; }
#region MWR pin
@ -199,14 +201,13 @@ namespace LR35902
{
this.prefixCB = false;
var masked = (byte)(this.IE & this.IF);
if (masked != 0)
if (this.MaskedInterrupts != 0)
{
if (this.IME)
{
this.IF = 0;
this.LowerINT();
var index = FindFirstSet(masked);
var index = FindFirstSet(this.MaskedInterrupts);
this.Bus.Data = (byte)(0x38 + (index << 3));
}
else
@ -225,7 +226,7 @@ namespace LR35902
}
else if (this.HALT.Lowered())
{
this.Execute(0); // NOP
//this.Execute(0); // NOP
}
else
{