-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rom.java
53 lines (46 loc) · 1.3 KB
/
Rom.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
/**
* @author Clément Petit (282626)
* @author Yanis Berkani (271348)
*/
package ch.epfl.gameboj.component.memory;
import java.util.Arrays;
import java.util.Objects;
public final class Rom {
private final byte[] rom;
/**
* builds the read-only memory which content and size are those of the
* parameter.
*
* @param data
* the array that provides the size and the content of the ROM
* (must not be null)
* @throw the exception NullPointerException if it is null
*/
public Rom(byte[] data) {
Objects.requireNonNull(data);
rom = Arrays.copyOf(data, data.length);
}
/**
* return the size of the memory in bytes.
*
* @return the size of the memory in bytes
*/
public int size() {
return rom.length;
}
/**
* return the byte located at the index given.
*
* @param index
* the index (must be included between 0 and FF)
* @throws IndexOutOfBoundsException
* if the index is invalid
* @return the byte located at the index given
*/
public int read(int index) {
if (index < 0 || index >= rom.length) {
throw new IndexOutOfBoundsException();
}
return Byte.toUnsignedInt(rom[index]);
}
}