io: i really ought to be working on the ppu and apu by now

Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2024-06-13 03:53:25 +05:30
parent 933b622493
commit 08cc582f23
17 changed files with 1751 additions and 78 deletions

32
include/io/io.hh Normal file
View File

@@ -0,0 +1,32 @@
#pragma once
#include "lcd.hh"
#include "sound.hh"
#include <cstdint>
namespace matar {
class IoDevices {
public:
uint8_t read_byte(uint32_t) const;
void write_byte(uint32_t, uint8_t);
uint32_t read_word(uint32_t) const;
void write_word(uint32_t, uint32_t);
uint16_t read_halfword(uint32_t) const;
void write_halfword(uint32_t, uint16_t);
private:
struct {
using u16 = uint16_t;
bool post_boot_flag;
bool interrupt_master_enabler;
u16 interrupt_enable;
u16 interrupt_request_flags;
u16 waitstate_control;
bool low_power_mode;
} system = {};
struct lcd lcd = {};
struct sound sound = {};
};
}

84
include/io/lcd.hh Normal file
View File

@@ -0,0 +1,84 @@
#include <cstdint>
// NOLINTBEGIN(cppcoreguidelines-avoid-c-arrays)
/*
4000000h 2 R/W DISPCNT LCD Control
4000002h 2 R/W - Undocumented - Green Swap
4000004h 2 R/W DISPSTAT General LCD Status (STAT,LYC)
4000006h 2 R VCOUNT Vertical Counter (LY)
4000008h 2 R/W BG0CNT BG0 Control
400000Ah 2 R/W BG1CNT BG1 Control
400000Ch 2 R/W BG2CNT BG2 Control
400000Eh 2 R/W BG3CNT BG3 Control
4000010h 2 W BG0HOFS BG0 X-Offset
4000012h 2 W BG0VOFS BG0 Y-Offset
4000014h 2 W BG1HOFS BG1 X-Offset
4000016h 2 W BG1VOFS BG1 Y-Offset
4000018h 2 W BG2HOFS BG2 X-Offset
400001Ah 2 W BG2VOFS BG2 Y-Offset
400001Ch 2 W BG3HOFS BG3 X-Offset
400001Eh 2 W BG3VOFS BG3 Y-Offset
4000020h 2 W BG2PA BG2 Rotation/Scaling Parameter A (dx)
4000022h 2 W BG2PB BG2 Rotation/Scaling Parameter B (dmx)
4000024h 2 W BG2PC BG2 Rotation/Scaling Parameter C (dy)
4000026h 2 W BG2PD BG2 Rotation/Scaling Parameter D (dmy)
4000028h 4 W BG2X BG2 Reference Point X-Coordinate
400002Ch 4 W BG2Y BG2 Reference Point Y-Coordinate
4000030h 2 W BG3PA BG3 Rotation/Scaling Parameter A (dx)
4000032h 2 W BG3PB BG3 Rotation/Scaling Parameter B (dmx)
4000034h 2 W BG3PC BG3 Rotation/Scaling Parameter C (dy)
4000036h 2 W BG3PD BG3 Rotation/Scaling Parameter D (dmy)
4000038h 4 W BG3X BG3 Reference Point X-Coordinate
400003Ch 4 W BG3Y BG3 Reference Point Y-Coordinate
4000040h 2 W WIN0H Window 0 Horizontal Dimensions
4000042h 2 W WIN1H Window 1 Horizontal Dimensions
4000044h 2 W WIN0V Window 0 Vertical Dimensions
4000046h 2 W WIN1V Window 1 Vertical Dimensions
4000048h 2 R/W WININ Inside of Window 0 and 1
400004Ah 2 R/W WINOUT Inside of OBJ Window & Outside of Windows
400004Ch 2 W MOSAIC Mosaic Size
400004Eh - - Not used
4000050h 2 R/W BLDCNT Color Special Effects Selection
4000052h 2 R/W BLDALPHA Alpha Blending Coefficients
4000054h 2 W BLDY Brightness (Fade-In/Out) Coefficient
4000056h - - Not used
*/
struct lcd {
using u16 = uint16_t;
u16 lcd_control;
u16 general_lcd_status;
u16 vertical_counter;
u16 bg0_control;
u16 bg1_control;
u16 bg2_control;
u16 bg3_control;
u16 bg0_x_offset;
u16 bg0_y_offset;
u16 bg1_x_offset;
u16 bg1_y_offset;
u16 bg2_x_offset;
u16 bg2_y_offset;
u16 bg3_x_offset;
u16 bg3_y_offset;
u16 bg2_rot_scaling_parameters[4];
u16 bg2_reference_x[2];
u16 bg2_reference_y[2];
u16 bg3_rot_scaling_parameters[4];
u16 bg3_reference_x[2];
u16 bg3_reference_y[2];
u16 win0_horizontal_dimensions;
u16 win1_horizontal_dimensions;
u16 win0_vertical_dimensions;
u16 win1_vertical_dimensions;
u16 inside_win_0_1;
u16 outside_win;
u16 mosaic_size;
u16 color_special_effects_selection;
u16 alpha_blending_coefficients;
u16 brightness_coefficient;
};
// NOLINTEND(cppcoreguidelines-avoid-c-arrays)

3
include/io/meson.build Normal file
View File

@@ -0,0 +1,3 @@
headers += files(
'io.hh'
)

66
include/io/sound.hh Normal file
View File

@@ -0,0 +1,66 @@
#include <cstdint>
// NOLINTBEGIN(cppcoreguidelines-avoid-c-arrays)
/*
4000060h 2 R/W SOUND1CNT_L Channel 1 Sweep register (NR10)
4000062h 2 R/W SOUND1CNT_H Channel 1 Duty/Length/Envelope (NR11, NR12)
4000064h 2 R/W SOUND1CNT_X Channel 1 Frequency/Control (NR13, NR14)
4000066h - - Not used
4000068h 2 R/W SOUND2CNT_L Channel 2 Duty/Length/Envelope (NR21, NR22)
400006Ah - - Not used
400006Ch 2 R/W SOUND2CNT_H Channel 2 Frequency/Control (NR23, NR24)
400006Eh - - Not used
4000070h 2 R/W SOUND3CNT_L Channel 3 Stop/Wave RAM select (NR30)
4000072h 2 R/W SOUND3CNT_H Channel 3 Length/Volume (NR31, NR32)
4000074h 2 R/W SOUND3CNT_X Channel 3 Frequency/Control (NR33, NR34)
4000076h - - Not used
4000078h 2 R/W SOUND4CNT_L Channel 4 Length/Envelope (NR41, NR42)
400007Ah - - Not used
400007Ch 2 R/W SOUND4CNT_H Channel 4 Frequency/Control (NR43, NR44)
400007Eh - - Not used
4000080h 2 R/W SOUNDCNT_L Control Stereo/Volume/Enable (NR50, NR51)
4000082h 2 R/W SOUNDCNT_H Control Mixing/DMA Control
4000084h 2 R/W SOUNDCNT_X Control Sound on/off (NR52)
4000086h - - Not used
4000088h 2 BIOS SOUNDBIAS Sound PWM Control
400008Ah .. - - Not used
4000090h 2x10h R/W WAVE_RAM Channel 3 Wave Pattern RAM (2 banks!!)
40000A0h 4 W FIFO_A Channel A FIFO, Data 0-3
40000A4h 4 W FIFO_B Channel B FIFO, Data 0-3
*/
struct sound{
using u16 = uint16_t;
// channel 1
u16 ch1_sweep;
u16 ch1_duty_length_env;
u16 ch1_freq_control;
// channel 2
u16 ch2_duty_length_env;
u16 ch2_freq_control;
// channel 3
u16 ch3_stop_wave_ram_select;
u16 ch3_length_volume;
u16 ch3_freq_control;
u16 ch3_wave_pattern[8];
// channel 4
u16 ch4_length_env;
u16 ch4_freq_control;
// control
u16 ctrl_stereo_volume;
u16 ctrl_mixing;
u16 ctrl_sound_on_off;
u16 pwm_control;
// fifo
u16 fifo_a[2];
u16 fifo_b[2];
};
// NOLINTEND(cppcoreguidelines-avoid-c-arrays)