Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. package ch.epfl.gameboj.component.memory;
  2.  
  3. import java.util.Arrays;
  4.  
  5. import ch.epfl.gameboj.Preconditions;
  6.  
  7. public final class Ram {
  8.  
  9. private final Byte[] memory;
  10.  
  11. public Ram(int size) throws IllegalArgumentException{
  12. if (size < 0) {
  13. throw new IllegalArgumentException();
  14. }else {
  15. memory = new Byte[size];
  16. }
  17.  
  18. }
  19.  
  20. public int size() {
  21. return memory.length;
  22. }
  23.  
  24. public final int read(int index) throws IndexOutOfBoundsException {
  25. return Byte.toUnsignedInt(memory[java.util.Objects.checkIndex(index,memory.length)]);
  26. }
  27.  
  28. public void write(int index, int value) {
  29. memory[java.util.Objects.checkIndex(index,memory.length)] = (byte) Preconditions.checkBits8(value);
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement