-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterrupt.rs
74 lines (64 loc) · 1.36 KB
/
interrupt.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use bitfield::bitfield;
#[derive(Debug)]
pub(crate) struct Interrupt {
pub(crate) flag: InterruptFlag,
pub(crate) enable: InterruptEnable,
}
impl Default for Interrupt {
fn default() -> Self {
Self {
flag: InterruptFlag(0),
enable: InterruptEnable(0),
}
}
}
bitfield! {
pub struct InterruptEnable(u8);
impl Debug;
pub vblank, set_vblank: 0;
pub lcd_stat, set_lcd_stat: 1;
pub timer, set_timer: 2;
pub serial, set_serial: 3;
pub joypad, set_joypad: 4;
}
impl Copy for InterruptEnable {}
impl Clone for InterruptEnable {
fn clone(&self) -> Self {
*self
}
}
impl From<u8> for InterruptEnable {
fn from(byte: u8) -> Self {
Self(byte)
}
}
impl From<InterruptEnable> for u8 {
fn from(enable: InterruptEnable) -> Self {
enable.0
}
}
bitfield! {
pub struct InterruptFlag(u8);
impl Debug;
pub vblank, set_vblank: 0;
pub lcd_stat, set_lcd_stat: 1;
pub timer, set_timer: 2;
pub serial, set_serial: 3;
pub joypad, set_joypad: 4;
}
impl Copy for InterruptFlag {}
impl Clone for InterruptFlag {
fn clone(&self) -> Self {
*self
}
}
impl From<u8> for InterruptFlag {
fn from(byte: u8) -> Self {
Self(byte)
}
}
impl From<InterruptFlag> for u8 {
fn from(flag: InterruptFlag) -> Self {
flag.0
}
}