-
Notifications
You must be signed in to change notification settings - Fork 0
/
Component.java
54 lines (46 loc) · 1.55 KB
/
Component.java
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
/**
* @author Clément Petit (282626)
* @author Yanis Berkani (271348)
*/
package ch.epfl.gameboj.component;
import ch.epfl.gameboj.Bus;
public interface Component {
/**
* constant used in the method read of a component to indicate there is no
* data at the given address as it is an invalid byte.
*/
public static final int NO_DATA = 0x100;
/**
* return the byte stored at the given address by the component or NO_DATA
* if the component doesn't contain any value at this address.
*
* @param address
* the address (must be a value of 16 bits)
* @throws IllegalArgumentException
* if the address is invalid
* @return the byte stored at the given address by the component or NO_DATA
* if the component doesn't contain any value at this address
*/
public abstract int read(int address);
/**
* stores the value given at the given address in the component or does
* nothing if the component doesn't allow to store values at this address.
*
* @param address
* the address (must be a value of 16 bits)
* @param data
* the data (must be a value of 8 bits)
* @throws IllegalArgumentException
* if the address or the data are invalid
*/
public abstract void write(int address, int data);
/**
* attaches the component to the given bus.
*
* @param bus
* the bus
*/
public default void attachTo(Bus bus) {
bus.attach(this);
}
}