1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.zmpp.base;
24
25 /***
26 * A MemorySection object wraps a reference to a MemoryAccess object, a length
27 * and a start to support subsections within memory.
28 * All access functions will be relative to the initialized start offset
29 * within the global memory.
30 *
31 * @author Wei-ju Wu
32 * @version 1.0
33 */
34 public class MemorySection implements MemoryAccess {
35
36 private MemoryAccess memaccess;
37 private int start;
38 private int length;
39
40 public MemorySection(MemoryAccess memaccess, int start, int length) {
41
42 this.memaccess = memaccess;
43 this.start = start;
44 this.length = length;
45 }
46
47 /***
48 * Returns the length of this object in bytes.
49 *
50 * @return the length in bytes
51 */
52 public int getLength() {
53
54 return length;
55 }
56
57 /***
58 * {@inheritDoc}
59 */
60 public void writeUnsignedShort(int address, int value) {
61
62 memaccess.writeUnsignedShort(address + start, value);
63 }
64
65 /***
66 * {@inheritDoc}
67 */
68 public void writeShort(int address, short value) {
69
70 memaccess.writeShort(address + start, value);
71 }
72
73 /***
74 * {@inheritDoc}
75 */
76 public void writeUnsignedByte(int address, short value) {
77
78 memaccess.writeUnsignedByte(address + start, value);
79 }
80
81 /***
82 * {@inheritDoc}
83 */
84 public void writeByte(int address, byte value) {
85
86 memaccess.writeByte(address + start, value);
87 }
88
89 /***
90 * {@inheritDoc}
91 */
92 public void writeUnsigned32(int address, long value) {
93
94 memaccess.writeUnsigned32(address + start, value);
95 }
96
97 /***
98 * {@inheritDoc}
99 */
100 public long readUnsigned32(int address) {
101
102 return memaccess.readUnsigned32(address + start);
103 }
104
105 /***
106 * {@inheritDoc}
107 */
108 public int readUnsignedShort(int address) {
109
110 return memaccess.readUnsignedShort(address + start);
111 }
112
113 /***
114 * {@inheritDoc}
115 */
116 public short readShort(int address) {
117
118 return memaccess.readShort(address + start);
119 }
120
121 /***
122 * {@inheritDoc}
123 */
124 public short readUnsignedByte(int address) {
125
126 return memaccess.readUnsignedByte(address + start);
127 }
128
129 /***
130 * {@inheritDoc}
131 */
132 public byte readByte(int address) {
133
134 return memaccess.readByte(address + start);
135 }
136 }