@gaialabs/core 0.1.17 → 0.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +32 -70
- package/dist/index.d.ts +32 -70
- package/dist/index.js +136 -195
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +138 -196
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,198 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
// src/rom/project.ts
|
|
4
|
-
var QuintetLZ = class _QuintetLZ {
|
|
5
|
-
static {
|
|
6
|
-
this.DICTIONARY_SIZE = 256;
|
|
7
|
-
}
|
|
8
|
-
static {
|
|
9
|
-
this.DICTIONARY_INIT = 32;
|
|
10
|
-
}
|
|
11
|
-
static {
|
|
12
|
-
this.DICTIONARY_OFFSET = 239;
|
|
13
|
-
}
|
|
14
|
-
static {
|
|
15
|
-
this.DEFAULT_PAGE_SIZE = 32768;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Expand (decompress) data using QuintetLZ algorithm
|
|
19
|
-
* @param srcData Source data buffer
|
|
20
|
-
* @param srcPosition Starting position in source data
|
|
21
|
-
* @param srcLen Length of source data to process
|
|
22
|
-
* @returns Expanded data
|
|
23
|
-
*/
|
|
24
|
-
expand(srcData, srcPosition = 0, srcLen = _QuintetLZ.DEFAULT_PAGE_SIZE) {
|
|
25
|
-
const bitStream = new BitStream(srcData, srcPosition);
|
|
26
|
-
const srcStop = srcPosition + srcLen;
|
|
27
|
-
const dictionary = new Uint8Array(_QuintetLZ.DICTIONARY_SIZE);
|
|
28
|
-
dictionary.fill(_QuintetLZ.DICTIONARY_INIT);
|
|
29
|
-
let dictPosition = _QuintetLZ.DICTIONARY_OFFSET;
|
|
30
|
-
let outPosition = 0;
|
|
31
|
-
const dstLen = bitStream.readShort();
|
|
32
|
-
const outBuffer = new Uint8Array(dstLen);
|
|
33
|
-
while (bitStream.currentPosition < srcStop && outPosition < dstLen) {
|
|
34
|
-
if (bitStream.readBit()) {
|
|
35
|
-
const sample = bitStream.readByte();
|
|
36
|
-
if (outPosition < dstLen) {
|
|
37
|
-
outBuffer[outPosition++] = sample;
|
|
38
|
-
}
|
|
39
|
-
dictionary[dictPosition] = sample;
|
|
40
|
-
dictPosition = dictPosition + 1 & 255;
|
|
41
|
-
} else {
|
|
42
|
-
let wordIndex = bitStream.readByte();
|
|
43
|
-
let wordLength = bitStream.readNibble() + 2;
|
|
44
|
-
while (wordLength-- > 0) {
|
|
45
|
-
const sample = dictionary[wordIndex];
|
|
46
|
-
wordIndex = wordIndex + 1 & 255;
|
|
47
|
-
if (outPosition < dstLen) {
|
|
48
|
-
outBuffer[outPosition++] = sample;
|
|
49
|
-
}
|
|
50
|
-
dictionary[dictPosition] = sample;
|
|
51
|
-
dictPosition = dictPosition + 1 & 255;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
if (outPosition < dstLen) {
|
|
56
|
-
return outBuffer.slice(0, outPosition);
|
|
57
|
-
}
|
|
58
|
-
return outBuffer;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Compact (compress) data using QuintetLZ algorithm
|
|
62
|
-
* @param srcData Source data to compress
|
|
63
|
-
* @returns Compressed data
|
|
64
|
-
*/
|
|
65
|
-
compact(srcData) {
|
|
66
|
-
const dictionary = new Uint8Array(_QuintetLZ.DICTIONARY_SIZE);
|
|
67
|
-
dictionary.fill(_QuintetLZ.DICTIONARY_INIT);
|
|
68
|
-
let offset = _QuintetLZ.DICTIONARY_OFFSET;
|
|
69
|
-
let srcIx = 0;
|
|
70
|
-
let dstIx = 0;
|
|
71
|
-
const srcLen = srcData.length;
|
|
72
|
-
const outputBuffer = new Uint8Array(srcLen * 2);
|
|
73
|
-
outputBuffer[dstIx++] = srcLen & 255;
|
|
74
|
-
outputBuffer[dstIx++] = srcLen >> 8 & 255;
|
|
75
|
-
const bitStream = new BitStream(outputBuffer, 2);
|
|
76
|
-
const getCommand = () => {
|
|
77
|
-
const maxLen = Math.min(srcLen - srcIx, 17);
|
|
78
|
-
if (maxLen < 2) {
|
|
79
|
-
return [0, 0];
|
|
80
|
-
}
|
|
81
|
-
let startByte = 0;
|
|
82
|
-
let bestLen = 0;
|
|
83
|
-
let bx = offset;
|
|
84
|
-
for (let i = 0; i < 256; i++, bx = bx + 1 & 255) {
|
|
85
|
-
let size = 0;
|
|
86
|
-
let bix = bx;
|
|
87
|
-
while (size < maxLen && dictionary[bix] === srcData[srcIx + size]) {
|
|
88
|
-
bix = bix + 1 & 255;
|
|
89
|
-
if (bix === offset) {
|
|
90
|
-
bix = bx;
|
|
91
|
-
}
|
|
92
|
-
size++;
|
|
93
|
-
}
|
|
94
|
-
if (size > bestLen) {
|
|
95
|
-
startByte = bx;
|
|
96
|
-
bestLen = size;
|
|
97
|
-
if (bestLen >= maxLen) {
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return [startByte, bestLen];
|
|
103
|
-
};
|
|
104
|
-
while (srcIx < srcLen) {
|
|
105
|
-
const [cmdStart, cmdLen] = getCommand();
|
|
106
|
-
if (cmdLen >= 2) {
|
|
107
|
-
bitStream.writeBit(false);
|
|
108
|
-
bitStream.writeByte(cmdStart);
|
|
109
|
-
bitStream.writeNibble(cmdLen - 2);
|
|
110
|
-
for (let i = 0; i < cmdLen; i++) {
|
|
111
|
-
dictionary[offset] = srcData[srcIx++];
|
|
112
|
-
offset = offset + 1 & 255;
|
|
113
|
-
}
|
|
114
|
-
} else {
|
|
115
|
-
bitStream.writeBit(true);
|
|
116
|
-
const val = srcData[srcIx++];
|
|
117
|
-
bitStream.writeByte(val);
|
|
118
|
-
dictionary[offset] = val;
|
|
119
|
-
offset = offset + 1 & 255;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
bitStream.flush();
|
|
123
|
-
const finalSize = Math.max(dstIx, bitStream.currentPosition);
|
|
124
|
-
return outputBuffer.slice(0, finalSize);
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
function registerCompressionProviders() {
|
|
128
|
-
CompressionRegistry.register("QuintetLZ", () => new QuintetLZ());
|
|
129
|
-
}
|
|
130
|
-
registerCompressionProviders();
|
|
131
|
-
|
|
132
|
-
// src/rom/project.ts
|
|
133
|
-
var ProjectRoot = class _ProjectRoot {
|
|
134
|
-
constructor(config) {
|
|
135
|
-
this.config = config;
|
|
136
|
-
this.name = config.name;
|
|
137
|
-
this.romPath = config.romPath;
|
|
138
|
-
this.baseDir = config.baseDir;
|
|
139
|
-
this.system = config.system;
|
|
140
|
-
this.database = config.database;
|
|
141
|
-
this.flipsPath = config.flipsPath;
|
|
142
|
-
this.resources = config.resources;
|
|
143
|
-
this.databasePath = config.databasePath;
|
|
144
|
-
this.systemPath = config.systemPath;
|
|
145
|
-
this.compression = config.compression;
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Load project from file or directory
|
|
149
|
-
*/
|
|
150
|
-
static async load(path) {
|
|
151
|
-
path = path || "./project.json";
|
|
152
|
-
try {
|
|
153
|
-
const config = await readJsonFile(path);
|
|
154
|
-
if (!config.baseDir) {
|
|
155
|
-
config.baseDir = await getDirectory(path);
|
|
156
|
-
}
|
|
157
|
-
return new _ProjectRoot(config);
|
|
158
|
-
} catch (error) {
|
|
159
|
-
console.warn(`Failed to load project file: ${error}. Using directory-based configuration.`);
|
|
160
|
-
}
|
|
161
|
-
const defaultConfig = {
|
|
162
|
-
name: "GaiaLabs",
|
|
163
|
-
baseDir: path,
|
|
164
|
-
flipsPath: process?.env?.flips_path,
|
|
165
|
-
romPath: process?.env?.rom_path || "",
|
|
166
|
-
database: "us",
|
|
167
|
-
databasePath: `${path}/db/us`,
|
|
168
|
-
systemPath: `${path}/db/snes`,
|
|
169
|
-
resources: {}
|
|
170
|
-
};
|
|
171
|
-
return new _ProjectRoot(defaultConfig);
|
|
172
|
-
}
|
|
173
|
-
// /**
|
|
174
|
-
// * Build the ROM (simplified)
|
|
175
|
-
// */
|
|
176
|
-
// public async build(files: ChunkFile[], entryPoints: DbEntryPoint[]): Promise<void> {
|
|
177
|
-
// // Build ROM using rebuild writer
|
|
178
|
-
// const writer = new RomWriter(entryPoints, this.config.cartName, this.config.makerCode);
|
|
179
|
-
// await writer.repack(files);
|
|
180
|
-
// }
|
|
181
|
-
/**
|
|
182
|
-
* Dump database and extract ROM data with comprehensive assembly processing
|
|
183
|
-
*/
|
|
184
|
-
// public async dumpDatabase(): Promise<ChunkFile[]> {
|
|
185
|
-
// // Load database and ROM data
|
|
186
|
-
// const root = await DbRootUtils.fromFolder(this.databasePath!, this.systemPath!);
|
|
187
|
-
// const rom = await readFileAsBinary(this.romPath);
|
|
188
|
-
// //root.paths = this.resources;
|
|
189
|
-
// const chunkReader = new BlockReader(rom, root);
|
|
190
|
-
// const chunkFiles = chunkReader.analyzeAndResolve();
|
|
191
|
-
// const blockWriter = new BlockWriter(chunkReader);
|
|
192
|
-
// const writtenFiles = blockWriter.generateAllAsm(chunkFiles);
|
|
193
|
-
// return chunkFiles;
|
|
194
|
-
// }
|
|
195
|
-
};
|
|
1
|
+
import { MemberType, Address, AddressSpace, AddressType, RomProcessingConstants, ChunkFileUtils, Op, BitStream, RegisterType, BlockReaderConstants, createTableEntry, ChunkFile, BinType, createChunkFileFromDbFile, createChunkFileFromDbBlock, LocationWrapper, Word, Byte, StatusFlags, CompressionRegistry, TypedNumber, AsmBlock, Long, summaryFromSupabaseByProject, crc32_buffer, DbRootUtils } from '@gaialabs/shared';
|
|
196
2
|
|
|
197
3
|
// src/rom/state.ts
|
|
198
4
|
var RomState = class _RomState {
|
|
@@ -1450,6 +1256,142 @@ var Registers = class {
|
|
|
1450
1256
|
this.stack.reset();
|
|
1451
1257
|
}
|
|
1452
1258
|
};
|
|
1259
|
+
var QuintetLZ = class _QuintetLZ {
|
|
1260
|
+
static {
|
|
1261
|
+
this.DICTIONARY_SIZE = 256;
|
|
1262
|
+
}
|
|
1263
|
+
static {
|
|
1264
|
+
this.DICTIONARY_INIT = 32;
|
|
1265
|
+
}
|
|
1266
|
+
static {
|
|
1267
|
+
this.DICTIONARY_OFFSET = 239;
|
|
1268
|
+
}
|
|
1269
|
+
static {
|
|
1270
|
+
this.DEFAULT_PAGE_SIZE = 32768;
|
|
1271
|
+
}
|
|
1272
|
+
/**
|
|
1273
|
+
* Expand (decompress) data using QuintetLZ algorithm
|
|
1274
|
+
* @param srcData Source data buffer
|
|
1275
|
+
* @param srcPosition Starting position in source data
|
|
1276
|
+
* @param srcLen Length of source data to process
|
|
1277
|
+
* @returns Expanded data
|
|
1278
|
+
*/
|
|
1279
|
+
expand(srcData, srcPosition = 0, srcLen = _QuintetLZ.DEFAULT_PAGE_SIZE) {
|
|
1280
|
+
const bitStream = new BitStream(srcData, srcPosition);
|
|
1281
|
+
const srcStop = srcPosition + srcLen;
|
|
1282
|
+
const dictionary = new Uint8Array(_QuintetLZ.DICTIONARY_SIZE);
|
|
1283
|
+
dictionary.fill(_QuintetLZ.DICTIONARY_INIT);
|
|
1284
|
+
let dictPosition = _QuintetLZ.DICTIONARY_OFFSET;
|
|
1285
|
+
let outPosition = 0;
|
|
1286
|
+
let dstLen = bitStream.readShort();
|
|
1287
|
+
if (dstLen === 0) {
|
|
1288
|
+
return srcData.slice(srcPosition + 2, srcStop);
|
|
1289
|
+
} else if (dstLen & 32768) {
|
|
1290
|
+
dstLen = 65536 - dstLen;
|
|
1291
|
+
}
|
|
1292
|
+
const outBuffer = new Uint8Array(dstLen);
|
|
1293
|
+
while (bitStream.currentPosition < srcStop && outPosition < dstLen) {
|
|
1294
|
+
if (bitStream.readBit()) {
|
|
1295
|
+
const sample = bitStream.readByte();
|
|
1296
|
+
if (outPosition < dstLen) {
|
|
1297
|
+
outBuffer[outPosition++] = sample;
|
|
1298
|
+
}
|
|
1299
|
+
dictionary[dictPosition] = sample;
|
|
1300
|
+
dictPosition = dictPosition + 1 & 255;
|
|
1301
|
+
} else {
|
|
1302
|
+
let wordIndex = bitStream.readByte();
|
|
1303
|
+
let wordLength = bitStream.readNibble() + 2;
|
|
1304
|
+
while (wordLength-- > 0) {
|
|
1305
|
+
const sample = dictionary[wordIndex];
|
|
1306
|
+
wordIndex = wordIndex + 1 & 255;
|
|
1307
|
+
if (outPosition < dstLen) {
|
|
1308
|
+
outBuffer[outPosition++] = sample;
|
|
1309
|
+
}
|
|
1310
|
+
dictionary[dictPosition] = sample;
|
|
1311
|
+
dictPosition = dictPosition + 1 & 255;
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
if (outPosition < dstLen) {
|
|
1316
|
+
return outBuffer.slice(0, outPosition);
|
|
1317
|
+
}
|
|
1318
|
+
return outBuffer;
|
|
1319
|
+
}
|
|
1320
|
+
/**
|
|
1321
|
+
* Compact (compress) data using QuintetLZ algorithm
|
|
1322
|
+
* @param srcData Source data to compress
|
|
1323
|
+
* @returns Compressed data
|
|
1324
|
+
*/
|
|
1325
|
+
compact(srcData) {
|
|
1326
|
+
const dictionary = new Uint8Array(_QuintetLZ.DICTIONARY_SIZE);
|
|
1327
|
+
dictionary.fill(_QuintetLZ.DICTIONARY_INIT);
|
|
1328
|
+
let offset = _QuintetLZ.DICTIONARY_OFFSET;
|
|
1329
|
+
let srcIx = 0;
|
|
1330
|
+
let dstIx = 0;
|
|
1331
|
+
const srcLen = srcData.length;
|
|
1332
|
+
const outputBuffer = new Uint8Array(srcLen * 2);
|
|
1333
|
+
outputBuffer[dstIx++] = srcLen & 255;
|
|
1334
|
+
outputBuffer[dstIx++] = srcLen >> 8 & 255;
|
|
1335
|
+
const bitStream = new BitStream(outputBuffer, 2);
|
|
1336
|
+
const getCommand = () => {
|
|
1337
|
+
const maxLen = Math.min(srcLen - srcIx, 17);
|
|
1338
|
+
if (maxLen < 2) {
|
|
1339
|
+
return [0, 0];
|
|
1340
|
+
}
|
|
1341
|
+
let startByte = 0;
|
|
1342
|
+
let bestLen = 0;
|
|
1343
|
+
let bx = offset;
|
|
1344
|
+
for (let i = 0; i < 256; i++, bx = bx + 1 & 255) {
|
|
1345
|
+
let size = 0;
|
|
1346
|
+
let bix = bx;
|
|
1347
|
+
while (size < maxLen && dictionary[bix] === srcData[srcIx + size]) {
|
|
1348
|
+
bix = bix + 1 & 255;
|
|
1349
|
+
if (bix === offset) {
|
|
1350
|
+
bix = bx;
|
|
1351
|
+
}
|
|
1352
|
+
size++;
|
|
1353
|
+
}
|
|
1354
|
+
if (size > bestLen) {
|
|
1355
|
+
startByte = bx;
|
|
1356
|
+
bestLen = size;
|
|
1357
|
+
if (bestLen >= maxLen) {
|
|
1358
|
+
break;
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
return [startByte, bestLen];
|
|
1363
|
+
};
|
|
1364
|
+
while (srcIx < srcLen) {
|
|
1365
|
+
const [cmdStart, cmdLen] = getCommand();
|
|
1366
|
+
if (cmdLen >= 2) {
|
|
1367
|
+
bitStream.writeBit(false);
|
|
1368
|
+
bitStream.writeByte(cmdStart);
|
|
1369
|
+
bitStream.writeNibble(cmdLen - 2);
|
|
1370
|
+
for (let i = 0; i < cmdLen; i++) {
|
|
1371
|
+
dictionary[offset] = srcData[srcIx++];
|
|
1372
|
+
offset = offset + 1 & 255;
|
|
1373
|
+
}
|
|
1374
|
+
} else {
|
|
1375
|
+
bitStream.writeBit(true);
|
|
1376
|
+
const val = srcData[srcIx++];
|
|
1377
|
+
bitStream.writeByte(val);
|
|
1378
|
+
dictionary[offset] = val;
|
|
1379
|
+
offset = offset + 1 & 255;
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
bitStream.flush();
|
|
1383
|
+
const finalSize = Math.max(dstIx, bitStream.currentPosition);
|
|
1384
|
+
return outputBuffer.slice(0, finalSize);
|
|
1385
|
+
}
|
|
1386
|
+
};
|
|
1387
|
+
|
|
1388
|
+
// src/compression/registry.ts
|
|
1389
|
+
function registerCompressionProviders() {
|
|
1390
|
+
CompressionRegistry.register("QuintetLZ", () => new QuintetLZ());
|
|
1391
|
+
}
|
|
1392
|
+
registerCompressionProviders();
|
|
1393
|
+
|
|
1394
|
+
// src/rom/extraction/blocks.ts
|
|
1453
1395
|
registerCompressionProviders();
|
|
1454
1396
|
var BlockReader = class {
|
|
1455
1397
|
constructor(romData, root) {
|
|
@@ -3992,6 +3934,6 @@ var isPlatformBrowser = typeof window !== "undefined";
|
|
|
3992
3934
|
var isPlatformNode = typeof process !== "undefined" && process.versions?.node;
|
|
3993
3935
|
var isPlatformWebWorker = typeof importScripts !== "undefined";
|
|
3994
3936
|
|
|
3995
|
-
export { AddressingModeHandler, AsmReader, Assembler, AssemblerState, BlockReader, BlockWriter, CopCommandProcessor, GAIA_CORE_VERSION, ObjectType, OperationContext, PostProcessor, ProcessorStateManager,
|
|
3937
|
+
export { AddressingModeHandler, AsmReader, Assembler, AssemblerState, BlockReader, BlockWriter, CopCommandProcessor, GAIA_CORE_VERSION, ObjectType, OperationContext, PostProcessor, ProcessorStateManager, QuintetLZ, ReferenceManager, Registers, RomDataReader, RomGenerator, RomLayout, RomProcessor, RomState, RomStateUtils, RomWriter, SortedMap, SpriteFrame, SpriteGroup, SpriteMap, SpritePart, Stack, StackOperations, StringProcessor, StringReader, TransformProcessor, TypeParser, isPlatformBrowser, isPlatformNode, isPlatformWebWorker, registerCompressionProviders };
|
|
3996
3938
|
//# sourceMappingURL=index.mjs.map
|
|
3997
3939
|
//# sourceMappingURL=index.mjs.map
|