2022-12-04 11:03:45 +00:00
|
|
|
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com>
|
|
|
|
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
|
|
|
|
2019-09-17 06:26:00 +00:00
|
|
|
#pragma once
|
|
|
|
#include "types.h"
|
|
|
|
|
|
|
|
class StateWrapper;
|
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
class InterruptController final
|
2019-09-17 06:26:00 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr u32 NUM_IRQS = 11;
|
|
|
|
|
|
|
|
enum class IRQ : u32
|
|
|
|
{
|
|
|
|
VBLANK = 0, // IRQ0 - VBLANK
|
|
|
|
GPU = 1, // IRQ1 - GPU via GP0(1Fh)
|
|
|
|
CDROM = 2, // IRQ2 - CDROM
|
|
|
|
DMA = 3, // IRQ3 - DMA
|
|
|
|
TMR0 = 4, // IRQ4 - TMR0 - Sysclk or Dotclk
|
|
|
|
TMR1 = 5, // IRQ5 - TMR1 - Sysclk Hblank
|
|
|
|
TMR2 = 6, // IRQ6 - TMR2 - Sysclk or Sysclk / 8
|
|
|
|
IRQ7 = 7, // IRQ7 - Controller and Memory Card Byte Received
|
|
|
|
SIO = 8, // IRQ8 - SIO
|
|
|
|
SPU = 9, // IRQ9 - SPU
|
|
|
|
IRQ10 = 10 // IRQ10 - Lightpen interrupt, PIO
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
InterruptController();
|
|
|
|
~InterruptController();
|
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
void Initialize();
|
|
|
|
void Shutdown();
|
2019-09-17 06:26:00 +00:00
|
|
|
void Reset();
|
|
|
|
bool DoState(StateWrapper& sw);
|
|
|
|
|
|
|
|
// Should mirror CPU state.
|
2020-07-31 07:09:18 +00:00
|
|
|
ALWAYS_INLINE bool GetIRQLineState() const { return (m_interrupt_status_register != 0); }
|
2019-09-17 06:26:00 +00:00
|
|
|
|
|
|
|
// Interupts are edge-triggered, so if it is masked when TriggerInterrupt() is called, it will be lost.
|
|
|
|
void InterruptRequest(IRQ irq);
|
|
|
|
|
|
|
|
// I/O
|
|
|
|
u32 ReadRegister(u32 offset);
|
|
|
|
void WriteRegister(u32 offset, u32 value);
|
|
|
|
|
|
|
|
private:
|
|
|
|
static constexpr u32 REGISTER_WRITE_MASK = (u32(1) << NUM_IRQS) - 1;
|
2019-09-17 14:22:41 +00:00
|
|
|
static constexpr u32 DEFAULT_INTERRUPT_MASK = 0; //(u32(1) << NUM_IRQS) - 1;
|
2019-09-17 06:26:00 +00:00
|
|
|
|
|
|
|
void UpdateCPUInterruptRequest();
|
|
|
|
|
|
|
|
u32 m_interrupt_status_register = 0;
|
|
|
|
u32 m_interrupt_mask_register = DEFAULT_INTERRUPT_MASK;
|
|
|
|
};
|
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
extern InterruptController g_interrupt_controller;
|