@@ -11,38 +11,22 @@ namespace BizHawk.Client.Common
11
11
[ Description ( "Main memory library reads and writes from the Main memory domain (the default memory domain set by any given core)" ) ]
12
12
public sealed class MainMemoryLuaLibrary : LuaLibraryBase
13
13
{
14
- [ RequiredService ]
15
- private IEmulator Emulator { get ; set ; }
16
-
17
- [ OptionalService ]
18
- private IMemoryDomains MemoryDomainCore { get ; set ; }
19
-
20
14
public MainMemoryLuaLibrary ( IPlatformLuaLibEnv luaLibsImpl , ApiContainer apiContainer , Action < string > logOutputCallback )
21
15
: base ( luaLibsImpl , apiContainer , logOutputCallback ) { }
22
16
23
17
public override string Name => "mainmemory" ;
24
18
25
- private MemoryDomain Domain
26
- {
27
- get
28
- {
29
- if ( MemoryDomainCore != null )
30
- {
31
- return MemoryDomainCore . MainMemory ;
32
- }
19
+ private MemoryDomain _mainMemDomain ;
33
20
34
- var error = $ "Error: { Emulator . Attributes ( ) . CoreName } does not implement memory domains" ;
35
- Log ( error ) ;
36
- throw new NotImplementedException ( error ) ;
37
- }
38
- }
21
+ private string _mainMemName ;
22
+
23
+ private MemoryDomain Domain => _mainMemDomain ??= ( ( MemoryApi ) APIs . Memory ) . DomainList [ MainMemName ] ;
24
+
25
+ private string MainMemName => _mainMemName ??= APIs . Memory . MainMemoryName ;
39
26
40
27
[ LuaMethodExample ( "local stmaiget = mainmemory.getname( );" ) ]
41
28
[ LuaMethod ( "getname" , "returns the name of the domain defined as main memory for the given core" ) ]
42
- public string GetName ( )
43
- {
44
- return Domain . Name ;
45
- }
29
+ public string GetName ( ) => MainMemName ;
46
30
47
31
[ LuaMethodExample ( "local uimaiget = mainmemory.getcurrentmemorydomainsize( );" ) ]
48
32
[ LuaMethod ( "getcurrentmemorydomainsize" , "Returns the number of bytes of the domain defined as main memory" ) ]
@@ -53,18 +37,15 @@ public uint GetSize()
53
37
54
38
[ LuaMethodExample ( "local uimairea = mainmemory.readbyte( 0x100 );" ) ]
55
39
[ LuaMethod ( "readbyte" , "gets the value from the given address as an unsigned byte" ) ]
56
- public uint ReadByte ( int addr ) => APIs . Memory . ReadByte ( addr , Domain . Name ) ;
40
+ public uint ReadByte ( int addr ) => APIs . Memory . ReadByte ( addr , MainMemName ) ;
57
41
58
42
[ LuaMethodExample ( "mainmemory.writebyte( 0x100, 1000 );" ) ]
59
43
[ LuaMethod ( "writebyte" , "Writes the given value to the given address as an unsigned byte" ) ]
60
- public void WriteByte ( int addr , uint value ) => APIs . Memory . WriteByte ( addr , value , Domain . Name ) ;
44
+ public void WriteByte ( int addr , uint value ) => APIs . Memory . WriteByte ( addr , value , MainMemName ) ;
61
45
62
46
[ LuaMethodExample ( "local nlmairea = mainmemory.readbyterange( 0x100, 64 );" ) ]
63
47
[ LuaMethod ( "readbyterange" , "Reads the address range that starts from address, and is length long. Returns the result into a table of key value pairs (where the address is the key)." ) ]
64
- public LuaTable ReadByteRange ( int addr , int length )
65
- {
66
- return _th . ListToTable ( APIs . Memory . ReadByteRange ( addr , length , Domain . Name ) ) ;
67
- }
48
+ public LuaTable ReadByteRange ( int addr , int length ) => _th . ListToTable ( APIs . Memory . ReadByteRange ( addr , length , MainMemName ) ) ;
68
49
69
50
/// <remarks>TODO C# version requires a contiguous address range</remarks>
70
51
[ LuaMethodExample ( "" ) ]
@@ -74,7 +55,7 @@ public void WriteByteRange(LuaTable memoryblock)
74
55
#if true
75
56
foreach ( var ( addr , v ) in _th . EnumerateEntries < double , double > ( memoryblock ) )
76
57
{
77
- APIs . Memory . WriteByte ( LuaInt ( addr ) , ( uint ) v , Domain . Name ) ;
58
+ APIs . Memory . WriteByte ( LuaInt ( addr ) , ( uint ) v , MainMemName ) ;
78
59
}
79
60
#else
80
61
var d = Domain ;
@@ -105,223 +86,223 @@ public void WriteByteRange(LuaTable memoryblock)
105
86
public float ReadFloat ( int addr , bool bigendian )
106
87
{
107
88
APIs . Memory . SetBigEndian ( bigendian ) ;
108
- return APIs . Memory . ReadFloat ( addr , Domain . Name ) ;
89
+ return APIs . Memory . ReadFloat ( addr , MainMemName ) ;
109
90
}
110
91
111
92
[ LuaMethodExample ( "mainmemory.writefloat( 0x100, 10.0, false );" ) ]
112
93
[ LuaMethod ( "writefloat" , "Writes the given 32-bit float value to the given address and endian" ) ]
113
94
public void WriteFloat ( int addr , double value , bool bigendian )
114
95
{
115
96
APIs . Memory . SetBigEndian ( bigendian ) ;
116
- APIs . Memory . WriteFloat ( addr , value , Domain . Name ) ;
97
+ APIs . Memory . WriteFloat ( addr , value , MainMemName ) ;
117
98
}
118
99
119
100
[ LuaMethodExample ( "local inmairea = mainmemory.read_s8( 0x100 );" ) ]
120
101
[ LuaMethod ( "read_s8" , "read signed byte" ) ]
121
- public int ReadS8 ( int addr ) => APIs . Memory . ReadS8 ( addr , Domain . Name ) ;
102
+ public int ReadS8 ( int addr ) => APIs . Memory . ReadS8 ( addr , MainMemName ) ;
122
103
123
104
[ LuaMethodExample ( "mainmemory.write_s8( 0x100, 1000 );" ) ]
124
105
[ LuaMethod ( "write_s8" , "write signed byte" ) ]
125
- public void WriteS8 ( int addr , uint value ) => APIs . Memory . WriteS8 ( addr , unchecked ( ( int ) value ) , Domain . Name ) ;
106
+ public void WriteS8 ( int addr , uint value ) => APIs . Memory . WriteS8 ( addr , unchecked ( ( int ) value ) , MainMemName ) ;
126
107
127
108
[ LuaMethodExample ( "local uimairea = mainmemory.read_u8( 0x100 );" ) ]
128
109
[ LuaMethod ( "read_u8" , "read unsigned byte" ) ]
129
- public uint ReadU8 ( int addr ) => APIs . Memory . ReadU8 ( addr , Domain . Name ) ;
110
+ public uint ReadU8 ( int addr ) => APIs . Memory . ReadU8 ( addr , MainMemName ) ;
130
111
131
112
[ LuaMethodExample ( "mainmemory.write_u8( 0x100, 1000 );" ) ]
132
113
[ LuaMethod ( "write_u8" , "write unsigned byte" ) ]
133
- public void WriteU8 ( int addr , uint value ) => APIs . Memory . WriteU8 ( addr , value , Domain . Name ) ;
114
+ public void WriteU8 ( int addr , uint value ) => APIs . Memory . WriteU8 ( addr , value , MainMemName ) ;
134
115
135
116
[ LuaMethodExample ( "local inmairea = mainmemory.read_s16_le( 0x100 );" ) ]
136
117
[ LuaMethod ( "read_s16_le" , "read signed 2 byte value, little endian" ) ]
137
118
public int ReadS16Little ( int addr )
138
119
{
139
120
APIs . Memory . SetBigEndian ( false ) ;
140
- return APIs . Memory . ReadS16 ( addr , Domain . Name ) ;
121
+ return APIs . Memory . ReadS16 ( addr , MainMemName ) ;
141
122
}
142
123
143
124
[ LuaMethodExample ( "mainmemory.write_s16_le( 0x100, -1000 );" ) ]
144
125
[ LuaMethod ( "write_s16_le" , "write signed 2 byte value, little endian" ) ]
145
126
public void WriteS16Little ( int addr , int value )
146
127
{
147
128
APIs . Memory . SetBigEndian ( false ) ;
148
- APIs . Memory . WriteS16 ( addr , value , Domain . Name ) ;
129
+ APIs . Memory . WriteS16 ( addr , value , MainMemName ) ;
149
130
}
150
131
151
132
[ LuaMethodExample ( "local inmairea = mainmemory.read_s16_be( 0x100 );" ) ]
152
133
[ LuaMethod ( "read_s16_be" , "read signed 2 byte value, big endian" ) ]
153
134
public int ReadS16Big ( int addr )
154
135
{
155
136
APIs . Memory . SetBigEndian ( ) ;
156
- return APIs . Memory . ReadS16 ( addr , Domain . Name ) ;
137
+ return APIs . Memory . ReadS16 ( addr , MainMemName ) ;
157
138
}
158
139
159
140
[ LuaMethodExample ( "mainmemory.write_s16_be( 0x100, -1000 );" ) ]
160
141
[ LuaMethod ( "write_s16_be" , "write signed 2 byte value, big endian" ) ]
161
142
public void WriteS16Big ( int addr , int value )
162
143
{
163
144
APIs . Memory . SetBigEndian ( ) ;
164
- APIs . Memory . WriteS16 ( addr , value , Domain . Name ) ;
145
+ APIs . Memory . WriteS16 ( addr , value , MainMemName ) ;
165
146
}
166
147
167
148
[ LuaMethodExample ( "local uimairea = mainmemory.read_u16_le( 0x100 );" ) ]
168
149
[ LuaMethod ( "read_u16_le" , "read unsigned 2 byte value, little endian" ) ]
169
150
public uint ReadU16Little ( int addr )
170
151
{
171
152
APIs . Memory . SetBigEndian ( false ) ;
172
- return APIs . Memory . ReadU16 ( addr , Domain . Name ) ;
153
+ return APIs . Memory . ReadU16 ( addr , MainMemName ) ;
173
154
}
174
155
175
156
[ LuaMethodExample ( "mainmemory.write_u16_le( 0x100, 1000 );" ) ]
176
157
[ LuaMethod ( "write_u16_le" , "write unsigned 2 byte value, little endian" ) ]
177
158
public void WriteU16Little ( int addr , uint value )
178
159
{
179
160
APIs . Memory . SetBigEndian ( false ) ;
180
- APIs . Memory . WriteU16 ( addr , value , Domain . Name ) ;
161
+ APIs . Memory . WriteU16 ( addr , value , MainMemName ) ;
181
162
}
182
163
183
164
[ LuaMethodExample ( "local uimairea = mainmemory.read_u16_be( 0x100 );" ) ]
184
165
[ LuaMethod ( "read_u16_be" , "read unsigned 2 byte value, big endian" ) ]
185
166
public uint ReadU16Big ( int addr )
186
167
{
187
168
APIs . Memory . SetBigEndian ( ) ;
188
- return APIs . Memory . ReadU16 ( addr , Domain . Name ) ;
169
+ return APIs . Memory . ReadU16 ( addr , MainMemName ) ;
189
170
}
190
171
191
172
[ LuaMethodExample ( "mainmemory.write_u16_be( 0x100, 1000 );" ) ]
192
173
[ LuaMethod ( "write_u16_be" , "write unsigned 2 byte value, big endian" ) ]
193
174
public void WriteU16Big ( int addr , uint value )
194
175
{
195
176
APIs . Memory . SetBigEndian ( ) ;
196
- APIs . Memory . WriteU16 ( addr , value , Domain . Name ) ;
177
+ APIs . Memory . WriteU16 ( addr , value , MainMemName ) ;
197
178
}
198
179
199
180
[ LuaMethodExample ( "local inmairea = mainmemory.read_s24_le( 0x100 );" ) ]
200
181
[ LuaMethod ( "read_s24_le" , "read signed 24 bit value, little endian" ) ]
201
182
public int ReadS24Little ( int addr )
202
183
{
203
184
APIs . Memory . SetBigEndian ( false ) ;
204
- return APIs . Memory . ReadS24 ( addr , Domain . Name ) ;
185
+ return APIs . Memory . ReadS24 ( addr , MainMemName ) ;
205
186
}
206
187
207
188
[ LuaMethodExample ( "mainmemory.write_s24_le( 0x100, -1000 );" ) ]
208
189
[ LuaMethod ( "write_s24_le" , "write signed 24 bit value, little endian" ) ]
209
190
public void WriteS24Little ( int addr , int value )
210
191
{
211
192
APIs . Memory . SetBigEndian ( false ) ;
212
- APIs . Memory . WriteS24 ( addr , value , Domain . Name ) ;
193
+ APIs . Memory . WriteS24 ( addr , value , MainMemName ) ;
213
194
}
214
195
215
196
[ LuaMethodExample ( "local inmairea = mainmemory.read_s24_be( 0x100 );" ) ]
216
197
[ LuaMethod ( "read_s24_be" , "read signed 24 bit value, big endian" ) ]
217
198
public int ReadS24Big ( int addr )
218
199
{
219
200
APIs . Memory . SetBigEndian ( ) ;
220
- return APIs . Memory . ReadS24 ( addr , Domain . Name ) ;
201
+ return APIs . Memory . ReadS24 ( addr , MainMemName ) ;
221
202
}
222
203
223
204
[ LuaMethodExample ( "mainmemory.write_s24_be( 0x100, -1000 );" ) ]
224
205
[ LuaMethod ( "write_s24_be" , "write signed 24 bit value, big endian" ) ]
225
206
public void WriteS24Big ( int addr , int value )
226
207
{
227
208
APIs . Memory . SetBigEndian ( ) ;
228
- APIs . Memory . WriteS24 ( addr , value , Domain . Name ) ;
209
+ APIs . Memory . WriteS24 ( addr , value , MainMemName ) ;
229
210
}
230
211
231
212
[ LuaMethodExample ( "local uimairea = mainmemory.read_u24_le( 0x100 );" ) ]
232
213
[ LuaMethod ( "read_u24_le" , "read unsigned 24 bit value, little endian" ) ]
233
214
public uint ReadU24Little ( int addr )
234
215
{
235
216
APIs . Memory . SetBigEndian ( false ) ;
236
- return APIs . Memory . ReadU24 ( addr , Domain . Name ) ;
217
+ return APIs . Memory . ReadU24 ( addr , MainMemName ) ;
237
218
}
238
219
239
220
[ LuaMethodExample ( "mainmemory.write_u24_le( 0x100, 1000 );" ) ]
240
221
[ LuaMethod ( "write_u24_le" , "write unsigned 24 bit value, little endian" ) ]
241
222
public void WriteU24Little ( int addr , uint value )
242
223
{
243
224
APIs . Memory . SetBigEndian ( false ) ;
244
- APIs . Memory . WriteU24 ( addr , value , Domain . Name ) ;
225
+ APIs . Memory . WriteU24 ( addr , value , MainMemName ) ;
245
226
}
246
227
247
228
[ LuaMethodExample ( "local uimairea = mainmemory.read_u24_be( 0x100 );" ) ]
248
229
[ LuaMethod ( "read_u24_be" , "read unsigned 24 bit value, big endian" ) ]
249
230
public uint ReadU24Big ( int addr )
250
231
{
251
232
APIs . Memory . SetBigEndian ( ) ;
252
- return APIs . Memory . ReadU24 ( addr , Domain . Name ) ;
233
+ return APIs . Memory . ReadU24 ( addr , MainMemName ) ;
253
234
}
254
235
255
236
[ LuaMethodExample ( "mainmemory.write_u24_be( 0x100, 1000 );" ) ]
256
237
[ LuaMethod ( "write_u24_be" , "write unsigned 24 bit value, big endian" ) ]
257
238
public void WriteU24Big ( int addr , uint value )
258
239
{
259
240
APIs . Memory . SetBigEndian ( ) ;
260
- APIs . Memory . WriteU24 ( addr , value , Domain . Name ) ;
241
+ APIs . Memory . WriteU24 ( addr , value , MainMemName ) ;
261
242
}
262
243
263
244
[ LuaMethodExample ( "local inmairea = mainmemory.read_s32_le( 0x100 );" ) ]
264
245
[ LuaMethod ( "read_s32_le" , "read signed 4 byte value, little endian" ) ]
265
246
public int ReadS32Little ( int addr )
266
247
{
267
248
APIs . Memory . SetBigEndian ( false ) ;
268
- return APIs . Memory . ReadS32 ( addr , Domain . Name ) ;
249
+ return APIs . Memory . ReadS32 ( addr , MainMemName ) ;
269
250
}
270
251
271
252
[ LuaMethodExample ( "mainmemory.write_s32_le( 0x100, -1000 );" ) ]
272
253
[ LuaMethod ( "write_s32_le" , "write signed 4 byte value, little endian" ) ]
273
254
public void WriteS32Little ( int addr , int value )
274
255
{
275
256
APIs . Memory . SetBigEndian ( false ) ;
276
- APIs . Memory . WriteS32 ( addr , value , Domain . Name ) ;
257
+ APIs . Memory . WriteS32 ( addr , value , MainMemName ) ;
277
258
}
278
259
279
260
[ LuaMethodExample ( "local inmairea = mainmemory.read_s32_be( 0x100 );" ) ]
280
261
[ LuaMethod ( "read_s32_be" , "read signed 4 byte value, big endian" ) ]
281
262
public int ReadS32Big ( int addr )
282
263
{
283
264
APIs . Memory . SetBigEndian ( ) ;
284
- return APIs . Memory . ReadS32 ( addr , Domain . Name ) ;
265
+ return APIs . Memory . ReadS32 ( addr , MainMemName ) ;
285
266
}
286
267
287
268
[ LuaMethodExample ( "mainmemory.write_s32_be( 0x100, -1000 );" ) ]
288
269
[ LuaMethod ( "write_s32_be" , "write signed 4 byte value, big endian" ) ]
289
270
public void WriteS32Big ( int addr , int value )
290
271
{
291
272
APIs . Memory . SetBigEndian ( ) ;
292
- APIs . Memory . WriteS32 ( addr , value , Domain . Name ) ;
273
+ APIs . Memory . WriteS32 ( addr , value , MainMemName ) ;
293
274
}
294
275
295
276
[ LuaMethodExample ( "local uimairea = mainmemory.read_u32_le( 0x100 );" ) ]
296
277
[ LuaMethod ( "read_u32_le" , "read unsigned 4 byte value, little endian" ) ]
297
278
public uint ReadU32Little ( int addr )
298
279
{
299
280
APIs . Memory . SetBigEndian ( false ) ;
300
- return APIs . Memory . ReadU32 ( addr , Domain . Name ) ;
281
+ return APIs . Memory . ReadU32 ( addr , MainMemName ) ;
301
282
}
302
283
303
284
[ LuaMethodExample ( "mainmemory.write_u32_le( 0x100, 1000 );" ) ]
304
285
[ LuaMethod ( "write_u32_le" , "write unsigned 4 byte value, little endian" ) ]
305
286
public void WriteU32Little ( int addr , uint value )
306
287
{
307
288
APIs . Memory . SetBigEndian ( false ) ;
308
- APIs . Memory . WriteU32 ( addr , value , Domain . Name ) ;
289
+ APIs . Memory . WriteU32 ( addr , value , MainMemName ) ;
309
290
}
310
291
311
292
[ LuaMethodExample ( "local uimairea = mainmemory.read_u32_be( 0x100 );" ) ]
312
293
[ LuaMethod ( "read_u32_be" , "read unsigned 4 byte value, big endian" ) ]
313
294
public uint ReadU32Big ( int addr )
314
295
{
315
296
APIs . Memory . SetBigEndian ( ) ;
316
- return APIs . Memory . ReadU32 ( addr , Domain . Name ) ;
297
+ return APIs . Memory . ReadU32 ( addr , MainMemName ) ;
317
298
}
318
299
319
300
[ LuaMethodExample ( "mainmemory.write_u32_be( 0x100, 1000 );" ) ]
320
301
[ LuaMethod ( "write_u32_be" , "write unsigned 4 byte value, big endian" ) ]
321
302
public void WriteU32Big ( int addr , uint value )
322
303
{
323
304
APIs . Memory . SetBigEndian ( ) ;
324
- APIs . Memory . WriteU32 ( addr , value , Domain . Name ) ;
305
+ APIs . Memory . WriteU32 ( addr , value , MainMemName ) ;
325
306
}
326
307
}
327
308
}
0 commit comments