@gaialabs/core 0.1.18 → 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.mjs CHANGED
@@ -1,203 +1,4 @@
1
- import { BitStream, RomProcessingConstants, Op, RegisterType, Address, ChunkFileUtils, BlockReaderConstants, createTableEntry, ChunkFile, BinType, createChunkFileFromDbFile, createChunkFileFromDbBlock, LocationWrapper, CompressionRegistry, Word, Byte, StatusFlags, AddressSpace, AddressType, MemberType, readJsonFile, getDirectory, TypedNumber, AsmBlock, Long, summaryFromSupabaseByProject, crc32_buffer, DbRootUtils } from '@gaialabs/shared';
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
- let dstLen = bitStream.readShort();
32
- if (dstLen === 0) {
33
- return srcData.slice(srcPosition + 2, srcStop);
34
- } else if (dstLen & 32768) {
35
- dstLen = 65536 - dstLen;
36
- }
37
- const outBuffer = new Uint8Array(dstLen);
38
- while (bitStream.currentPosition < srcStop && outPosition < dstLen) {
39
- if (bitStream.readBit()) {
40
- const sample = bitStream.readByte();
41
- if (outPosition < dstLen) {
42
- outBuffer[outPosition++] = sample;
43
- }
44
- dictionary[dictPosition] = sample;
45
- dictPosition = dictPosition + 1 & 255;
46
- } else {
47
- let wordIndex = bitStream.readByte();
48
- let wordLength = bitStream.readNibble() + 2;
49
- while (wordLength-- > 0) {
50
- const sample = dictionary[wordIndex];
51
- wordIndex = wordIndex + 1 & 255;
52
- if (outPosition < dstLen) {
53
- outBuffer[outPosition++] = sample;
54
- }
55
- dictionary[dictPosition] = sample;
56
- dictPosition = dictPosition + 1 & 255;
57
- }
58
- }
59
- }
60
- if (outPosition < dstLen) {
61
- return outBuffer.slice(0, outPosition);
62
- }
63
- return outBuffer;
64
- }
65
- /**
66
- * Compact (compress) data using QuintetLZ algorithm
67
- * @param srcData Source data to compress
68
- * @returns Compressed data
69
- */
70
- compact(srcData) {
71
- const dictionary = new Uint8Array(_QuintetLZ.DICTIONARY_SIZE);
72
- dictionary.fill(_QuintetLZ.DICTIONARY_INIT);
73
- let offset = _QuintetLZ.DICTIONARY_OFFSET;
74
- let srcIx = 0;
75
- let dstIx = 0;
76
- const srcLen = srcData.length;
77
- const outputBuffer = new Uint8Array(srcLen * 2);
78
- outputBuffer[dstIx++] = srcLen & 255;
79
- outputBuffer[dstIx++] = srcLen >> 8 & 255;
80
- const bitStream = new BitStream(outputBuffer, 2);
81
- const getCommand = () => {
82
- const maxLen = Math.min(srcLen - srcIx, 17);
83
- if (maxLen < 2) {
84
- return [0, 0];
85
- }
86
- let startByte = 0;
87
- let bestLen = 0;
88
- let bx = offset;
89
- for (let i = 0; i < 256; i++, bx = bx + 1 & 255) {
90
- let size = 0;
91
- let bix = bx;
92
- while (size < maxLen && dictionary[bix] === srcData[srcIx + size]) {
93
- bix = bix + 1 & 255;
94
- if (bix === offset) {
95
- bix = bx;
96
- }
97
- size++;
98
- }
99
- if (size > bestLen) {
100
- startByte = bx;
101
- bestLen = size;
102
- if (bestLen >= maxLen) {
103
- break;
104
- }
105
- }
106
- }
107
- return [startByte, bestLen];
108
- };
109
- while (srcIx < srcLen) {
110
- const [cmdStart, cmdLen] = getCommand();
111
- if (cmdLen >= 2) {
112
- bitStream.writeBit(false);
113
- bitStream.writeByte(cmdStart);
114
- bitStream.writeNibble(cmdLen - 2);
115
- for (let i = 0; i < cmdLen; i++) {
116
- dictionary[offset] = srcData[srcIx++];
117
- offset = offset + 1 & 255;
118
- }
119
- } else {
120
- bitStream.writeBit(true);
121
- const val = srcData[srcIx++];
122
- bitStream.writeByte(val);
123
- dictionary[offset] = val;
124
- offset = offset + 1 & 255;
125
- }
126
- }
127
- bitStream.flush();
128
- const finalSize = Math.max(dstIx, bitStream.currentPosition);
129
- return outputBuffer.slice(0, finalSize);
130
- }
131
- };
132
- function registerCompressionProviders() {
133
- CompressionRegistry.register("QuintetLZ", () => new QuintetLZ());
134
- }
135
- registerCompressionProviders();
136
-
137
- // src/rom/project.ts
138
- var ProjectRoot = class _ProjectRoot {
139
- constructor(config) {
140
- this.config = config;
141
- this.name = config.name;
142
- this.romPath = config.romPath;
143
- this.baseDir = config.baseDir;
144
- this.system = config.system;
145
- this.database = config.database;
146
- this.flipsPath = config.flipsPath;
147
- this.resources = config.resources;
148
- this.databasePath = config.databasePath;
149
- this.systemPath = config.systemPath;
150
- this.compression = config.compression;
151
- }
152
- /**
153
- * Load project from file or directory
154
- */
155
- static async load(path) {
156
- path = path || "./project.json";
157
- try {
158
- const config = await readJsonFile(path);
159
- if (!config.baseDir) {
160
- config.baseDir = await getDirectory(path);
161
- }
162
- return new _ProjectRoot(config);
163
- } catch (error) {
164
- console.warn(`Failed to load project file: ${error}. Using directory-based configuration.`);
165
- }
166
- const defaultConfig = {
167
- name: "GaiaLabs",
168
- baseDir: path,
169
- flipsPath: process?.env?.flips_path,
170
- romPath: process?.env?.rom_path || "",
171
- database: "us",
172
- databasePath: `${path}/db/us`,
173
- systemPath: `${path}/db/snes`,
174
- resources: {}
175
- };
176
- return new _ProjectRoot(defaultConfig);
177
- }
178
- // /**
179
- // * Build the ROM (simplified)
180
- // */
181
- // public async build(files: ChunkFile[], entryPoints: DbEntryPoint[]): Promise<void> {
182
- // // Build ROM using rebuild writer
183
- // const writer = new RomWriter(entryPoints, this.config.cartName, this.config.makerCode);
184
- // await writer.repack(files);
185
- // }
186
- /**
187
- * Dump database and extract ROM data with comprehensive assembly processing
188
- */
189
- // public async dumpDatabase(): Promise<ChunkFile[]> {
190
- // // Load database and ROM data
191
- // const root = await DbRootUtils.fromFolder(this.databasePath!, this.systemPath!);
192
- // const rom = await readFileAsBinary(this.romPath);
193
- // //root.paths = this.resources;
194
- // const chunkReader = new BlockReader(rom, root);
195
- // const chunkFiles = chunkReader.analyzeAndResolve();
196
- // const blockWriter = new BlockWriter(chunkReader);
197
- // const writtenFiles = blockWriter.generateAllAsm(chunkFiles);
198
- // return chunkFiles;
199
- // }
200
- };
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';
201
2
 
202
3
  // src/rom/state.ts
203
4
  var RomState = class _RomState {
@@ -1455,6 +1256,142 @@ var Registers = class {
1455
1256
  this.stack.reset();
1456
1257
  }
1457
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
1458
1395
  registerCompressionProviders();
1459
1396
  var BlockReader = class {
1460
1397
  constructor(romData, root) {
@@ -3997,6 +3934,6 @@ var isPlatformBrowser = typeof window !== "undefined";
3997
3934
  var isPlatformNode = typeof process !== "undefined" && process.versions?.node;
3998
3935
  var isPlatformWebWorker = typeof importScripts !== "undefined";
3999
3936
 
4000
- export { AddressingModeHandler, AsmReader, Assembler, AssemblerState, BlockReader, BlockWriter, CopCommandProcessor, GAIA_CORE_VERSION, ObjectType, OperationContext, PostProcessor, ProcessorStateManager, ProjectRoot, 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 };
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 };
4001
3938
  //# sourceMappingURL=index.mjs.map
4002
3939
  //# sourceMappingURL=index.mjs.map