Skip to content

Commit 20edcdd

Browse files
authored
WAITCNT bitfield defintions (#209)
Co-authored-by: lifning <>
1 parent 07cdcbb commit 20edcdd

File tree

2 files changed

+83
-2
lines changed

2 files changed

+83
-2
lines changed

Diff for: src/interrupts.rs

+82-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::macros::{pub_const_fn_new_zeroed, u16_bool_field};
1+
use crate::macros::{pub_const_fn_new_zeroed, u16_bool_field, u16_enum_field};
22

33
/// A function you want called during an interrupt.
44
pub type IrqFn = unsafe extern "C" fn(IrqBits);
@@ -45,5 +45,86 @@ impl IrqBits {
4545
}
4646
}
4747

48+
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
49+
#[repr(transparent)]
50+
pub struct WaitstateControl(pub u16);
51+
impl WaitstateControl {
52+
pub_const_fn_new_zeroed!();
53+
u16_enum_field!(0 - 1: SramFirstAccess, sram, with_sram);
54+
u16_enum_field!(
55+
2 - 3:
56+
Waitstate0FirstAccess,
57+
ws0_first_access,
58+
with_ws0_first_access
59+
);
60+
// true = 2, false = 1
61+
u16_bool_field!(4, ws0_second_access, with_ws0_second_access);
62+
u16_enum_field!(
63+
5 - 6:
64+
Waitstate1FirstAccess,
65+
ws1_first_access,
66+
with_ws1_first_access
67+
);
68+
// true = 4, false = 1
69+
u16_bool_field!(7, ws1_second_access, with_ws1_second_access);
70+
u16_enum_field!(
71+
8 - 9:
72+
Waitstate2FirstAccess,
73+
ws2_first_access,
74+
with_ws2_first_access
75+
);
76+
// true = 8, false = 1
77+
u16_bool_field!(10, ws2_second_access, with_ws2_second_access);
78+
u16_enum_field!(
79+
11 - 12:
80+
PhiTerminalOutput,
81+
phi_terminal_output,
82+
with_phi_terminal_output
83+
);
84+
u16_bool_field!(14, game_pak_prefetch_buffer, with_game_pak_prefetch_buffer);
85+
u16_bool_field!(15, game_pak_is_cgb, with_game_pak_is_cgb);
86+
}
87+
88+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
89+
#[repr(u16)]
90+
pub enum SramFirstAccess {
91+
Cycles4 = 0,
92+
Cycles3 = 1,
93+
Cycles2 = 2,
94+
Cycles8 = 3,
95+
}
96+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
97+
#[repr(u16)]
98+
pub enum Waitstate0FirstAccess {
99+
Cycles4 = 0 << 2,
100+
Cycles3 = 1 << 2,
101+
Cycles2 = 2 << 2,
102+
Cycles8 = 3 << 2,
103+
}
104+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
105+
#[repr(u16)]
106+
pub enum Waitstate1FirstAccess {
107+
Cycles4 = 0 << 5,
108+
Cycles3 = 1 << 5,
109+
Cycles2 = 2 << 5,
110+
Cycles8 = 3 << 5,
111+
}
112+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
113+
#[repr(u16)]
114+
pub enum Waitstate2FirstAccess {
115+
Cycles4 = 0 << 8,
116+
Cycles3 = 1 << 8,
117+
Cycles2 = 2 << 8,
118+
Cycles8 = 3 << 8,
119+
}
120+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
121+
#[repr(u16)]
122+
pub enum PhiTerminalOutput {
123+
Disabled = 0 << 11,
124+
Freq4MHz = 1 << 11,
125+
Freq8MHz = 2 << 11,
126+
Freq16MHz = 3 << 11,
127+
}
128+
48129
// TODO: might want to support bit ops. But it's not super important right now
49130
// since they can't be implented as const traits yet anyway.

Diff for: src/mmio.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def_mmio!(0x0400_0158 = JOYSTAT: VolAddress<u8, Safe, Safe>);
186186

187187
def_mmio!(0x0400_0200 = IE: VolAddress<IrqBits, Safe, Safe>; "Interrupts Enabled: sets which interrupts will be accepted when a subsystem fires an interrupt");
188188
def_mmio!(0x0400_0202 = IF: VolAddress<IrqBits, Safe, Safe>; "Interrupts Flagged: reads which interrupts are pending, writing bit(s) will clear a pending interrupt.");
189-
def_mmio!(0x0400_0204 = WAITCNT: VolAddress<u16, Safe, Unsafe>; "Wait state control for interfacing with the ROM.\n\nThis can make reading the ROM give garbage when it's mis-configured!");
189+
def_mmio!(0x0400_0204 = WAITCNT: VolAddress<WaitstateControl, Safe, Unsafe>; "Wait state control for interfacing with the ROM.\n\nThis can make reading the ROM give garbage when it's mis-configured!");
190190
def_mmio!(0x0400_0208 = IME: VolAddress<bool, Safe, Safe>; "Interrupt Master Enable: Allows turning on/off all interrupts with a single access.");
191191

192192
// mGBA Logging

0 commit comments

Comments
 (0)