1use crate::api::GameBoyAdvanceEmulator;
2use jgenesis_common::debug::DebugMemoryView;
3use jgenesis_common::frontend::Color;
4use jgenesis_proc_macros::EnumAll;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EnumAll)]
7pub enum GbaMemoryArea {
8    CartridgeRom,
9    Ewram,
10    Iwram,
11    Vram,
12    PaletteRam,
13    Oam,
14    BiosRom,
15}
16
17impl GbaMemoryArea {
18    #[must_use]
19    pub fn name(self) -> &'static str {
20        match self {
21            Self::CartridgeRom => "Cartridge ROM",
22            Self::Ewram => "EWRAM",
23            Self::Iwram => "IWRAM",
24            Self::Vram => "VRAM",
25            Self::PaletteRam => "Palette RAM",
26            Self::Oam => "OAM",
27            Self::BiosRom => "BIOS ROM",
28        }
29    }
30}
31
32pub struct GbaDebugView<'emu>(&'emu mut GameBoyAdvanceEmulator);
33
34impl GameBoyAdvanceEmulator {
35    #[must_use]
36    pub fn debug(&mut self) -> GbaDebugView<'_> {
37        GbaDebugView(self)
38    }
39}
40
41impl<'emu> GbaDebugView<'emu> {
42    #[must_use]
43    pub fn memory_view(self, area: GbaMemoryArea) -> Box<dyn DebugMemoryView + 'emu> {
44        match area {
45            GbaMemoryArea::CartridgeRom => Box::new(self.0.bus.cartridge.debug_rom_view()),
46            GbaMemoryArea::Ewram => Box::new(self.0.bus.memory.debug_ewram_view()),
47            GbaMemoryArea::Iwram => Box::new(self.0.bus.memory.debug_iwram_view()),
48            GbaMemoryArea::Vram => Box::new(self.0.bus.ppu.debug_vram_view()),
49            GbaMemoryArea::PaletteRam => Box::new(self.0.bus.ppu.debug_palette_view()),
50            GbaMemoryArea::Oam => Box::new(self.0.bus.ppu.debug_oam_view()),
51            GbaMemoryArea::BiosRom => Box::new(self.0.bus.memory.debug_bios_view()),
52        }
53    }
54
55    pub fn copy_palette_ram(&self, out: &mut [Color]) {
56        self.0.bus.ppu.copy_palette_ram(out);
57    }
58}