@gaialabs/core 0.1.0 → 0.1.1

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 CHANGED
@@ -1,145 +1,4 @@
1
- import { DbRoot, BinType, DbPath, AddressingMode, AddressType, StatusFlags, CopDef, DbStringType, StringWrapper, DbBlock, DbPart, Address } from 'gaia-shared';
2
- export { DbRoot } from 'gaia-shared';
3
-
4
- /**
5
- * Represents a single frame in a sprite animation sequence
6
- */
7
- declare class SpriteFrame {
8
- duration: number;
9
- groupIndex: number;
10
- /**
11
- * Internal offset to the group data (not serialized)
12
- */
13
- groupOffset: number;
14
- constructor(duration?: number, groupIndex?: number, groupOffset?: number);
15
- }
16
-
17
- /**
18
- * Represents a single part/piece of a sprite
19
- */
20
- declare class SpritePart {
21
- isLarge: boolean;
22
- xOffset: number;
23
- xOffsetMirror: number;
24
- yOffset: number;
25
- yOffsetMirror: number;
26
- vMirror: boolean;
27
- hMirror: boolean;
28
- someOffset: number;
29
- paletteIndex: number;
30
- tileIndex: number;
31
- constructor();
32
- }
33
-
34
- /**
35
- * Represents a group of sprite parts that form a complete sprite frame
36
- */
37
- declare class SpriteGroup {
38
- xOffset: number;
39
- xOffsetMirror: number;
40
- yOffset: number;
41
- yOffsetMirror: number;
42
- xRecoilHitboxOffset: number;
43
- yRecoilHitboxOffset: number;
44
- xRecoilHitboxTilesize: number;
45
- yRecoilHitboxTilesize: number;
46
- xHostileHitboxOffset: number;
47
- xHostileHitboxSize: number;
48
- yHostileHitboxOffset: number;
49
- yHostileHitboxSize: number;
50
- parts: SpritePart[];
51
- constructor();
52
- }
53
-
54
- /**
55
- * Represents a complete sprite map with frame sets and groups
56
- */
57
- declare class SpriteMap {
58
- frameSets: SpriteFrame[][];
59
- groups: SpriteGroup[];
60
- constructor();
61
- /**
62
- * Create a SpriteMap from binary data
63
- * @param data Binary data buffer
64
- * @returns SpriteMap instance
65
- */
66
- static fromBytes(data: Uint8Array): SpriteMap;
67
- /**
68
- * Convert this SpriteMap to binary data
69
- * @returns Binary data buffer
70
- */
71
- toBytes(): Uint8Array;
72
- }
73
-
74
- /**
75
- * ROM state management for SNES hardware emulation
76
- * Converted from GaiaLib/Rom/RomState.cs
77
- */
78
- declare class RomState {
79
- readonly cgram: Uint8Array<ArrayBuffer>;
80
- readonly vram: Uint8Array<ArrayBuffer>;
81
- readonly mainTileset: Uint8Array<ArrayBuffer>;
82
- readonly effectTileset: Uint8Array<ArrayBuffer>;
83
- mainTilesetPath?: string;
84
- effectTilesetPath?: string;
85
- mainTilemap: Uint8Array<ArrayBuffer>;
86
- mainTilemapW: number;
87
- mainTilemapH: number;
88
- mainTilemapPath?: string;
89
- effectTilemap: Uint8Array<ArrayBuffer>;
90
- effectTilemapW: number;
91
- effectTilemapH: number;
92
- effectTilemapPath?: string;
93
- static spriteMap: SpriteMap | null;
94
- static spriteMapPath: string | null;
95
- /**
96
- * Strip address space prefixes from names
97
- */
98
- static stripName(name: string): string;
99
- /**
100
- * Create ROM state from scene metadata
101
- * Simplified version of the C# implementation
102
- */
103
- static fromScene(baseDir: string, root: DbRoot, metaFile: string, id: number): Promise<RomState>;
104
- /**
105
- * Process scene command (simplified version)
106
- * TODO: Implement full command processing
107
- */
108
- private static processCommand;
109
- }
110
- /**
111
- * ROM state utilities
112
- */
113
- declare class RomStateUtils {
114
- /**
115
- * Create empty ROM state
116
- */
117
- static createEmpty(): RomState;
118
- /**
119
- * Clear all data in ROM state
120
- */
121
- static clear(state: RomState): void;
122
- }
123
-
124
- /**
125
- * Interface for compression providers
126
- */
127
- interface ICompressionProvider {
128
- /**
129
- * Expand (decompress) data
130
- * @param srcData Source data buffer
131
- * @param srcPosition Starting position in source data
132
- * @param srcLen Length of source data to process
133
- * @returns Expanded data
134
- */
135
- expand(srcData: Uint8Array, srcPosition?: number, srcLen?: number): Uint8Array;
136
- /**
137
- * Compact (compress) data
138
- * @param srcData Source data to compress
139
- * @returns Compressed data
140
- */
141
- compact(srcData: Uint8Array): Uint8Array;
142
- }
1
+ import { ICompressionProvider, BinType, DbPath, StatusFlags, DbRoot, AddressType, DbStringType, StringWrapper, Op, OpCode, ChunkFile, AsmBlock, Address, CopDef, DbEntryPoint } from '@gaialabs/shared';
143
2
 
144
3
  /**
145
4
  * QuintetLZ compression algorithm implementation
@@ -166,6 +25,11 @@ declare class QuintetLZ implements ICompressionProvider {
166
25
  compact(srcData: Uint8Array): Uint8Array;
167
26
  }
168
27
 
28
+ /**
29
+ * Register compression providers with the global registry
30
+ */
31
+ declare function registerCompressionProviders(): void;
32
+
169
33
  /**
170
34
  * Main project management class
171
35
  * Converted from GaiaLib/ProjectRoot.cs
@@ -198,257 +62,89 @@ declare class ProjectRoot {
198
62
  systemPath?: string;
199
63
  compression?: string;
200
64
  constructor(config: ProjectConfig);
201
- /**
202
- * Get compression provider
203
- */
204
- getCompression(): ICompressionProvider;
205
65
  /**
206
66
  * Load project from file or directory
207
67
  */
208
68
  static load(path?: string): Promise<ProjectRoot>;
209
- /**
210
- * Build the ROM (simplified)
211
- */
212
- build(): Promise<void>;
213
- /**
214
- * Dump database and extract ROM data
215
- */
216
- dumpDatabase(): Promise<DbRoot>;
217
69
  }
218
70
 
219
71
  /**
220
- * Unified ROM processor providing high-level APIs for common ROM processing workflows
221
- * This is the main entry point for ROM processing operations
72
+ * Lightweight ROM state placeholder used during early development.
73
+ * This stub will be expanded as the ROM extraction pipeline matures.
222
74
  */
223
- declare class RomProcessor {
224
- private projectRoot;
225
- private dbRoot;
226
- private romData;
227
- private romState;
228
- constructor(projectConfig: ProjectConfig);
229
- /**
230
- * Create ROM processor from project file or directory
231
- */
232
- static fromProject(path?: string): Promise<RomProcessor>;
233
- /**
234
- * Load ROM data from file or URL
235
- */
236
- loadRom(romPath?: string): Promise<void>;
237
- /**
238
- * Initialize database and load ROM metadata
239
- */
240
- initialize(): Promise<void>;
241
- /**
242
- * Analyze ROM structure and extract metadata
243
- */
244
- analyze(): Promise<RomAnalysisResult>;
245
- /**
246
- * Extract files from ROM data
247
- */
248
- extract(outputDir: string): Promise<ExtractionResult>;
249
- /**
250
- * Process scene data for a specific scene ID
251
- */
252
- processScene(sceneId: number, metaFile: string): Promise<RomState>;
253
- /**
254
- * Build ROM from extracted files
255
- */
256
- build(outputPath: string): Promise<BuildResult>;
257
- /**
258
- * Get compression provider for the project
259
- */
260
- getCompression(): QuintetLZ;
261
- /**
262
- * Get current ROM state
263
- */
264
- getRomState(): RomState | null;
265
- /**
266
- * Get database root
267
- */
268
- getDatabase(): DbRoot | null;
75
+ declare class RomState {
76
+ readonly cgram: Uint8Array<ArrayBuffer>;
77
+ readonly vram: Uint8Array<ArrayBuffer>;
269
78
  /**
270
- * Get project configuration
79
+ * Create ROM state from scene metadata.
80
+ * Parameters are currently unused but kept for future implementation.
271
81
  */
272
- getProject(): ProjectRoot;
273
- private analyzeHeader;
274
- private detectCompression;
275
- private analyzeOpcodes;
276
- }
277
- interface RomAnalysisResult {
278
- romSize: number;
279
- headerInfo: RomHeaderInfo;
280
- entryPoints: any[];
281
- fileCount: number;
282
- blockCount: number;
283
- compressionUsed: boolean;
284
- spriteMapFound: boolean;
285
- opcodeStats: OpcodeStats;
286
- }
287
- interface RomHeaderInfo {
288
- title: string;
289
- mapMode: number;
290
- cartridgeType: number;
291
- romSize: number;
292
- ramSize: number;
293
- isValid: boolean;
294
- }
295
- interface ExtractionResult {
296
- extractedFiles: string[];
297
- errors: string[];
298
- totalSize: number;
82
+ static fromScene(_baseDir: string, _root: unknown, _metaFile: string, _id: number): Promise<RomState>;
299
83
  }
300
- interface BuildResult {
301
- success: boolean;
302
- outputPath: string;
303
- romSize: number;
304
- errors: string[];
305
- }
306
- interface OpcodeStats {
307
- totalOpcodes: number;
308
- uniqueOpcodes: number;
309
- coverage: number;
310
- }
311
-
312
84
  /**
313
- * Project lifecycle management events
85
+ * Utility helpers for working with RomState.
314
86
  */
315
- interface ProjectEvents {
316
- onLoadStart?: () => void;
317
- onLoadComplete?: (processor: RomProcessor) => void;
318
- onLoadError?: (error: Error) => void;
319
- onAnalysisStart?: () => void;
320
- onAnalysisComplete?: (results: any) => void;
321
- onExtractionStart?: () => void;
322
- onExtractionComplete?: (results: any) => void;
323
- onBuildStart?: () => void;
324
- onBuildComplete?: (results: any) => void;
325
- }
326
- /**
327
- * Project status tracking
328
- */
329
- interface ProjectStatus {
330
- isLoaded: boolean;
331
- isAnalyzed: boolean;
332
- isExtracted: boolean;
333
- canBuild: boolean;
334
- lastError?: Error;
335
- progress: number;
336
- currentTask?: string;
87
+ declare class RomStateUtils {
88
+ /** Create an empty ROM state */
89
+ static createEmpty(): RomState;
90
+ /** Clear all data in the given ROM state */
91
+ static clear(state: RomState): void;
337
92
  }
93
+
338
94
  /**
339
- * Unified project manager for complete project lifecycle management
340
- * This is the highest-level API for managing ROM hacking projects
95
+ * Represents the stack for the 65816 processor
341
96
  */
342
- declare class ProjectManager {
343
- private processor;
344
- private status;
345
- private events;
346
- constructor(events?: ProjectEvents);
347
- /**
348
- * Create project manager from existing project configuration
349
- */
350
- static fromConfig(config: ProjectConfig, events?: ProjectEvents): Promise<ProjectManager>;
351
- /**
352
- * Create project manager from project file or directory
353
- */
354
- static fromPath(path: string, events?: ProjectEvents): Promise<ProjectManager>;
355
- /**
356
- * Load project from configuration
357
- */
358
- loadProject(config: ProjectConfig): Promise<void>;
359
- /**
360
- * Load project from file or directory path
361
- */
362
- loadProjectFromPath(path: string): Promise<void>;
363
- /**
364
- * Analyze ROM structure and extract metadata
365
- */
366
- analyzeRom(): Promise<any>;
367
- /**
368
- * Extract files from ROM
369
- */
370
- extractFiles(outputDir: string): Promise<any>;
371
- /**
372
- * Build ROM from extracted files
373
- */
374
- buildRom(outputPath: string): Promise<any>;
375
- /**
376
- * Process specific scene
377
- */
378
- processScene(sceneId: number, metaFile: string): Promise<RomState>;
379
- /**
380
- * Get current project status
381
- */
382
- getStatus(): ProjectStatus;
97
+ declare class Stack {
98
+ bytes: Uint8Array;
99
+ location: number;
100
+ constructor();
383
101
  /**
384
- * Get the ROM processor instance
102
+ * Push a byte onto the stack
385
103
  */
386
- getProcessor(): RomProcessor | null;
104
+ push(value: number): void;
387
105
  /**
388
- * Get project configuration
106
+ * Push a 16-bit value onto the stack (little-endian)
389
107
  */
390
- getProjectConfig(): ProjectConfig | null;
108
+ pushUInt16(value: number): void;
391
109
  /**
392
- * Get database root
110
+ * Pop a byte from the stack
393
111
  */
394
- getDatabase(): DbRoot | null;
112
+ popByte(): number;
395
113
  /**
396
- * Get ROM state
114
+ * Pop a 16-bit value from the stack (little-endian)
397
115
  */
398
- getRomState(): RomState | null;
116
+ popUInt16(): number;
399
117
  /**
400
- * Reset project to initial state
118
+ * Reset the stack to initial state
401
119
  */
402
120
  reset(): void;
403
- /**
404
- * Complete workflow: load, analyze, extract, and build
405
- */
406
- completeWorkflow(projectPath: string, outputDir: string, outputRomPath: string): Promise<any>;
407
- private updateStatus;
408
121
  }
409
122
 
410
123
  /**
411
- * Represents a 65816 processor opcode
412
- */
413
- declare class OpCode {
414
- code: number;
415
- mnem: string;
416
- mode: AddressingMode;
417
- size: number;
418
- constructor(code: number, mnem: string, mode: AddressingMode, size: number);
419
- }
420
- /**
421
- * Complete 65816 instruction set lookup table
422
- */
423
- declare const ALL_OPCODES: Record<number, OpCode>;
424
- /**
425
- * Grouped opcodes by mnemonic
426
- */
427
- declare const GROUPED_OPCODES: Record<string, OpCode[]>;
428
- /**
429
- * Regular expressions for parsing addressing modes
430
- */
431
- declare const ADDRESSING_REGEX: Record<AddressingMode, RegExp>;
432
- /**
433
- * Hex character validation regex
434
- */
435
- declare const HEX_REGEX: RegExp;
436
- /**
437
- * Utility methods for OpCode class
124
+ * Manages the 65816 processor registers and status flags
438
125
  */
439
- declare class OpCodeUtils {
126
+ declare class Registers {
127
+ accumulatorFlag?: boolean;
128
+ indexFlag?: boolean;
129
+ direct?: number;
130
+ dataBank?: number;
131
+ accumulator?: number;
132
+ xIndex?: number;
133
+ yIndex?: number;
134
+ stack: Stack;
135
+ constructor();
440
136
  /**
441
- * Get all available opcodes
137
+ * Get the current status flags
442
138
  */
443
- static getAllOpcodes(): OpCode[];
139
+ get statusFlags(): StatusFlags;
444
140
  /**
445
- * Get opcodes by mnemonic
141
+ * Set the status flags
446
142
  */
447
- static getByMnemonic(mnemonic: string): OpCode[];
143
+ set statusFlags(value: StatusFlags);
448
144
  /**
449
- * Find opcode by hex value
145
+ * Reset all registers to initial state
450
146
  */
451
- static findByCode(code: number): OpCode | undefined;
147
+ reset(): void;
452
148
  }
453
149
 
454
150
  /**
@@ -464,7 +160,7 @@ declare class ProcessorStateManager {
464
160
  * Hydrate processor registers with stored state
465
161
  * Uses Registers from gaia-core/assembly for processor state management
466
162
  */
467
- hydrateRegisters(position: number, reg: any): void;
163
+ hydrateRegisters(position: number, reg: Registers): void;
468
164
  getAccumulatorFlag(location: number): boolean | null | undefined;
469
165
  setAccumulatorFlag(location: number, value: boolean | null): void;
470
166
  tryAddAccumulatorFlag(location: number, value: boolean | null): boolean;
@@ -536,78 +232,6 @@ declare class ReferenceManager {
536
232
  private processClosestMatch;
537
233
  }
538
234
 
539
- /**
540
- * Represents the stack for the 65816 processor
541
- */
542
- declare class Stack {
543
- bytes: Uint8Array;
544
- location: number;
545
- constructor();
546
- /**
547
- * Push a byte onto the stack
548
- */
549
- push(value: number): void;
550
- /**
551
- * Push a 16-bit value onto the stack (little-endian)
552
- */
553
- pushUInt16(value: number): void;
554
- /**
555
- * Pop a byte from the stack
556
- */
557
- popByte(): number;
558
- /**
559
- * Pop a 16-bit value from the stack (little-endian)
560
- */
561
- popUInt16(): number;
562
- /**
563
- * Reset the stack to initial state
564
- */
565
- reset(): void;
566
- }
567
-
568
- /**
569
- * Manages the 65816 processor registers and status flags
570
- */
571
- declare class Registers {
572
- accumulatorFlag?: boolean;
573
- indexFlag?: boolean;
574
- direct?: number;
575
- dataBank?: number;
576
- accumulator?: number;
577
- xIndex?: number;
578
- yIndex?: number;
579
- stack: Stack;
580
- constructor();
581
- /**
582
- * Get the current status flags
583
- */
584
- get statusFlags(): StatusFlags;
585
- /**
586
- * Set the status flags
587
- */
588
- set statusFlags(value: StatusFlags);
589
- /**
590
- * Reset all registers to initial state
591
- */
592
- reset(): void;
593
- }
594
-
595
- /**
596
- * Represents a single assembly operation/instruction
597
- */
598
- declare class Op {
599
- code: OpCode;
600
- location: number;
601
- operands: unknown[];
602
- size: number;
603
- copDef?: CopDef;
604
- constructor(code: OpCode, location?: number, operands?: unknown[], size?: number);
605
- /**
606
- * Get the formatted string representation of this operation
607
- */
608
- toString(): string;
609
- }
610
-
611
235
  /**
612
236
  * Reads and processes strings from ROM data
613
237
  * Converted from GaiaLib/Rom/Extraction/StringReader.cs
@@ -633,9 +257,10 @@ declare class StringReader {
633
257
  * Converted from GaiaLib/Rom/Extraction/AsmReader.cs
634
258
  */
635
259
  declare class AsmReader {
260
+ private static readonly PROCESSOR_FLAG_MASK;
636
261
  private static readonly ACCUMULATOR_OP_MASK;
637
262
  private static readonly ACCUMULATOR_OP_VALUE;
638
- private static readonly VARIABLE_SIZE_INDICATOR;
263
+ static readonly VARIABLE_SIZE_INDICATOR = -2;
639
264
  private static readonly TWO_BYTES_SIZE;
640
265
  private static readonly THREE_BYTES_SIZE;
641
266
  private readonly _blockReader;
@@ -694,9 +319,10 @@ declare class BlockReader {
694
319
  get _structTable(): Map<number, string>;
695
320
  get _markerTable(): Map<number, number>;
696
321
  get _nameTable(): Map<number, string>;
697
- _currentBlock: DbBlock;
698
- _currentPart: DbPart | null;
699
322
  _partEnd: number;
323
+ _currentChunk: ChunkFile | null;
324
+ _currentAsmBlock: AsmBlock | null;
325
+ _enrichedChunks: ChunkFile[];
700
326
  constructor(romData: Uint8Array, root: DbRoot);
701
327
  /**
702
328
  * Processes predefined overrides for registers and bank notes
@@ -731,14 +357,10 @@ declare class BlockReader {
731
357
  * Checks if processing of the current part can continue
732
358
  */
733
359
  partCanContinue(): boolean;
734
- /**
735
- * Main analysis entry point
736
- */
737
- analyzeAndResolve(): void;
360
+ analyzeAndResolve(): ChunkFile[];
738
361
  /**
739
362
  * Analyzes all blocks in the ROM
740
363
  */
741
- private analyzeBlocks;
742
364
  /**
743
365
  * Initializes blocks and parts with base references
744
366
  */
@@ -756,7 +378,27 @@ declare class BlockReader {
756
378
  */
757
379
  private processNewEntry;
758
380
  /**
759
- * Resolves all references after analysis
381
+ * Creates ChunkFile objects from database structure
382
+ */
383
+ private createChunkFilesFromDatabase;
384
+ /**
385
+ * Creates binary ChunkFiles from DbFiles (enriched with rawData)
386
+ */
387
+ private createChunkFilesFromSfx;
388
+ /**
389
+ * Creates binary ChunkFiles from DbFiles (enriched with rawData)
390
+ */
391
+ private createChunkFilesFromDbFiles;
392
+ /**
393
+ * Creates assembly ChunkFiles from DbBlocks (enriched with parts)
394
+ */
395
+ private createChunkFilesFromDbBlocks;
396
+ /**
397
+ * Analyzes only assembly ChunkFiles (those with parts from DbBlocks)
398
+ */
399
+ private analyzeChunkFiles;
400
+ /**
401
+ * Resolves references in assembly ChunkFiles only
760
402
  */
761
403
  private resolveReferences;
762
404
  /**
@@ -775,10 +417,6 @@ declare class BlockReader {
775
417
  * Hydrates registers with stored state
776
418
  */
777
419
  hydrateRegisters(reg: Registers): void;
778
- /**
779
- * PascalCase wrapper for hydrateRegisters (for C# compatibility)
780
- */
781
- HydrateRegisters(reg: Registers): void;
782
420
  }
783
421
 
784
422
  /**
@@ -815,7 +453,7 @@ declare class OperationContext {
815
453
  nextAddress: number;
816
454
  xForm1: string | null;
817
455
  xForm2: string | null;
818
- copDef: any;
456
+ copDef: CopDef | null;
819
457
  }
820
458
  /**
821
459
  * Handles different addressing modes for assembly instructions
@@ -863,56 +501,6 @@ declare class StackOperations {
863
501
  private handleExchangeBytes;
864
502
  }
865
503
 
866
- /**
867
- * Reads and extracts SFX data from ROM
868
- * Converted from GaiaLib/Rom/Extraction/SfxReader.cs
869
- */
870
- declare class SfxReader {
871
- private readonly _romData;
872
- private readonly _dbRoot;
873
- private _location;
874
- private _count;
875
- constructor(romData: Uint8Array, dbRoot: DbRoot);
876
- /**
877
- * Reads a byte from the rom data
878
- */
879
- private readByte;
880
- /**
881
- * Reads a short from the rom data
882
- */
883
- private readShort;
884
- /**
885
- * Extracts the sfx from the rom data to the given output path
886
- */
887
- extract(outPath: string): Promise<void>;
888
- /**
889
- * Gets the path information for a binary type
890
- * TODO: This should be implemented in DbRoot
891
- */
892
- private getPath;
893
- }
894
-
895
- /**
896
- * Reads and extracts files from ROM
897
- * Converted from GaiaLib/Rom/Extraction/FileReader.cs
898
- */
899
- declare class FileReader {
900
- static readonly PALETTE_MIN_SIZE = 512;
901
- private readonly _romData;
902
- private readonly _dbRoot;
903
- private readonly _compression;
904
- constructor(romData: Uint8Array, dbRoot: DbRoot, provider: ICompressionProvider);
905
- /**
906
- * Extracts all files from the ROM to the given output path
907
- */
908
- extract(outPath: string): Promise<void>;
909
- private processFileData;
910
- /**
911
- * Gets the path information for a binary type from DbRoot configuration
912
- */
913
- private getPath;
914
- }
915
-
916
504
  /**
917
505
  * Handles COP (Coprocessor) command processing
918
506
  * Converted from GaiaLib/Rom/Extraction/CopCommandProcessor.cs
@@ -953,8 +541,8 @@ declare class BlockWriter {
953
541
  private _isInline;
954
542
  private _currentPart;
955
543
  constructor(reader: BlockReader);
956
- writeBlocks(outPath: string): Promise<void>;
957
- generateAsm(block: DbBlock): string;
544
+ generateAllAsm(chunkFiles: ChunkFile[]): any[];
545
+ generateAsm(block: ChunkFile): string;
958
546
  private getMnemonicsForBlock;
959
547
  private resolveOperand;
960
548
  private getObjectType;
@@ -981,15 +569,295 @@ declare class PostProcessor {
981
569
  /**
982
570
  * Execute post process directive on a block if present.
983
571
  */
984
- process(block: DbBlock): void;
572
+ process(block: ChunkFile): void;
985
573
  /**
986
574
  * Builds a lookup table from struct entries.
987
575
  * Equivalent to PostProcessor.Lookup in C# implementation.
988
576
  */
989
- Lookup(block: DbBlock, keyIx: string, valueIx: string): void;
577
+ Lookup(block: ChunkFile, keyIx: string, valueIx: string): void;
990
578
  }
991
579
 
992
- declare const ROM_REBUILD_MODULE = "gaia-core/rom/rebuild";
580
+ /**
581
+ * ROM layout planner
582
+ * Converted from ext/GaiaLib/Rom/Rebuild/RomLayout.cs
583
+ */
584
+ declare class RomLayout {
585
+ private static readonly MIN_ACCEPTED_REMAINING;
586
+ readonly unmatchedFiles: ChunkFile[];
587
+ private readonly bestResult;
588
+ private readonly bestSample;
589
+ private currentBank;
590
+ private currentUpper;
591
+ private bestDepth;
592
+ private bestOffset;
593
+ private bestRemain;
594
+ constructor(files: Iterable<ChunkFile>);
595
+ organize(): void;
596
+ private testDepth;
597
+ private commitPage;
598
+ }
599
+
600
+ /**
601
+ * ROM writer (binary)
602
+ * Converted from ext/GaiaLib/Rom/Rebuild/RomWriter.cs (subset: binary write only)
603
+ */
604
+ declare class RomWriter {
605
+ bpsPath?: string;
606
+ readonly outBuffer: Uint8Array;
607
+ readonly entryPoints: DbEntryPoint[];
608
+ readonly cartName: string;
609
+ readonly makerCode: string;
610
+ constructor(entryPoints: DbEntryPoint[], cartName: string, makerCode: string);
611
+ repack(files: ChunkFile[]): Promise<Uint8Array>;
612
+ writeHeader(): void;
613
+ writeChecksum(): void;
614
+ writeEntryPoints(asmFiles: ChunkFile[]): void;
615
+ writeTransform(location: number, value: number, size?: number): void;
616
+ writeFile(file: ChunkFile, _chunkLookup: Map<string, number>): Promise<number>;
617
+ private writeAscii;
618
+ /**
619
+ * Parse assembly blocks and write binary data to output buffer
620
+ * Converted from ext/GaiaLib/Rom/Rebuild/RomWriter.cs ParseAssembly method
621
+ */
622
+ private parseAssembly;
623
+ /**
624
+ * Helper method to find index of any character from an array in a string
625
+ */
626
+ private indexOfAny;
627
+ /**
628
+ * Helper method to check if an object is a StringMarker
629
+ */
630
+ private isStringMarker;
631
+ private isTableEntry;
632
+ }
633
+
634
+ /**
635
+ * ROM rebuild processor
636
+ * Converted from ext/GaiaLib/Rom/Rebuild/RomProcessor.cs
637
+ */
638
+ declare class RomProcessor {
639
+ private readonly writer;
640
+ constructor(writer: RomWriter);
641
+ repack(allFiles: ChunkFile[]): Promise<void>;
642
+ static applyPatches(asmFiles: ChunkFile[], patches: ChunkFile[]): void;
643
+ }
644
+
645
+ /**
646
+ * Shared context interface for assembler components
647
+ * This eliminates circular dependencies between Assembler, AssemblerState, and StringProcessor
648
+ */
649
+ interface AssemblerContext {
650
+ readonly root: DbRoot;
651
+ readonly stringProcessor: StringProcessor;
652
+ currentBlock: AsmBlock | null;
653
+ lineBuffer: string;
654
+ blockIndex: number;
655
+ lastDelimiter: number | null;
656
+ blocks: AsmBlock[];
657
+ eof: boolean;
658
+ lineCount: number;
659
+ getLine(): boolean;
660
+ processRawData(): void;
661
+ parseOperand(operand: string): unknown;
662
+ }
663
+
664
+ /**
665
+ * String processor for assembly parsing
666
+ * Converted from GaiaLib/Rom/Rebuild/StringProcessor.cs
667
+ */
668
+ declare class StringProcessor {
669
+ private readonly memBuffer;
670
+ private readonly context;
671
+ private readonly root;
672
+ constructor(context: AssemblerContext);
673
+ dispose(): void;
674
+ consumeString(): void;
675
+ private flushBuffer;
676
+ private processString;
677
+ private applyLayers;
678
+ private applyMap;
679
+ private processStringCommand;
680
+ private getShiftUp;
681
+ }
682
+
683
+ /**
684
+ * A map that sorts keys by length in descending order, then alphabetically
685
+ * This is used for tag replacement where longer tags should be replaced first
686
+ * to avoid conflicts (e.g., "ABCD" should be replaced before "ABC")
687
+ */
688
+ declare class SortedMap<V> {
689
+ private map;
690
+ private _keys;
691
+ get size(): number;
692
+ set(key: string, value: V): this;
693
+ get(key: string): V | undefined;
694
+ has(key: string): boolean;
695
+ delete(key: string): boolean;
696
+ clear(): void;
697
+ keys(): string[];
698
+ values(): V[];
699
+ entries(): [string, V][];
700
+ [Symbol.iterator](): Generator<[string, V], void, unknown>;
701
+ private sortKeys;
702
+ }
703
+
704
+ /**
705
+ * Main assembler class for parsing assembly files
706
+ * Converted from GaiaLib/Rom/Rebuild/Assembler.cs
707
+ */
708
+ declare class Assembler implements AssemblerContext {
709
+ readonly root: DbRoot;
710
+ private readonly lines;
711
+ private currentLineIndex;
712
+ readonly stringProcessor: StringProcessor;
713
+ lineBuffer: string;
714
+ includes: Set<string>;
715
+ blocks: AsmBlock[];
716
+ tags: SortedMap<string | null>;
717
+ currentBlock: AsmBlock | null;
718
+ lineCount: number;
719
+ blockIndex: number;
720
+ lastDelimiter: number | null;
721
+ reqBank: number | null;
722
+ eof: boolean;
723
+ constructor(dbRoot: DbRoot, textData: string);
724
+ dispose(): void;
725
+ parseAssembly(): {
726
+ blocks: AsmBlock[];
727
+ includes: Set<string>;
728
+ reqBank: number | null;
729
+ };
730
+ getLine(): boolean;
731
+ private trimComments;
732
+ private processDirectives;
733
+ private processTags;
734
+ private resolveTags;
735
+ parseOperand(opnd: string): unknown;
736
+ processRawData(): void;
737
+ private hexStringToBytes;
738
+ }
739
+
740
+ /**
741
+ * Assembler state machine for processing assembly text
742
+ * Converted from GaiaLib/Rom/Rebuild/AssemblerState.cs
743
+ */
744
+ declare class AssemblerState {
745
+ private readonly dbStruct;
746
+ private readonly parentStruct;
747
+ private readonly root;
748
+ private readonly discriminator;
749
+ private delimiter;
750
+ private memberOffset;
751
+ private dataOffset;
752
+ private readonly memberTypes;
753
+ private currentType;
754
+ private readonly context;
755
+ constructor(context: AssemblerContext, structType?: string | null, saveDelimiter?: boolean);
756
+ private checkDisc;
757
+ private advancePart;
758
+ private processOrigin;
759
+ private static doMath;
760
+ private tryCreateLabel;
761
+ processText(openTag?: string): void;
762
+ private hexStringToBytes;
763
+ }
764
+
765
+ declare class RomGenerator {
766
+ private readonly moduleLookup;
767
+ private readonly moduleList;
768
+ private readonly sourceData;
769
+ private readonly patchFiles;
770
+ private chunkFiles;
771
+ private asmFiles;
772
+ private dbRoot;
773
+ constructor(modules: string[], sourceData: Uint8Array);
774
+ generateProject(projectName: string): Promise<Uint8Array>;
775
+ private initializeDatabase;
776
+ private initializeChunks;
777
+ private writeScriptTexts;
778
+ private applyBaseRom;
779
+ private applyProjectInit;
780
+ private applySelectedModules;
781
+ private assembleCodeFromText;
782
+ private applyCodePatches;
783
+ private calculateSizes;
784
+ private performLayout;
785
+ private rebaseAssemblies;
786
+ private generateAsmIncludeLookups;
787
+ applyPatchFile(chunkFile: ChunkFile): void;
788
+ private generateBlockLookup;
789
+ private writeRom;
790
+ }
791
+
792
+ /**
793
+ * Represents a single frame in a sprite animation sequence
794
+ */
795
+ declare class SpriteFrame {
796
+ duration: number;
797
+ groupIndex: number;
798
+ /**
799
+ * Internal offset to the group data (not serialized)
800
+ */
801
+ groupOffset: number;
802
+ constructor(duration?: number, groupIndex?: number, groupOffset?: number);
803
+ }
804
+
805
+ /**
806
+ * Represents a single part/piece of a sprite
807
+ */
808
+ declare class SpritePart {
809
+ isLarge: boolean;
810
+ xOffset: number;
811
+ xOffsetMirror: number;
812
+ yOffset: number;
813
+ yOffsetMirror: number;
814
+ vMirror: boolean;
815
+ hMirror: boolean;
816
+ someOffset: number;
817
+ paletteIndex: number;
818
+ tileIndex: number;
819
+ constructor();
820
+ }
821
+
822
+ /**
823
+ * Represents a group of sprite parts that form a complete sprite frame
824
+ */
825
+ declare class SpriteGroup {
826
+ xOffset: number;
827
+ xOffsetMirror: number;
828
+ yOffset: number;
829
+ yOffsetMirror: number;
830
+ xRecoilHitboxOffset: number;
831
+ yRecoilHitboxOffset: number;
832
+ xRecoilHitboxTilesize: number;
833
+ yRecoilHitboxTilesize: number;
834
+ xHostileHitboxOffset: number;
835
+ xHostileHitboxSize: number;
836
+ yHostileHitboxOffset: number;
837
+ yHostileHitboxSize: number;
838
+ parts: SpritePart[];
839
+ constructor();
840
+ }
841
+
842
+ /**
843
+ * Represents a complete sprite map with frame sets and groups
844
+ */
845
+ declare class SpriteMap {
846
+ frameSets: SpriteFrame[][];
847
+ groups: SpriteGroup[];
848
+ constructor();
849
+ /**
850
+ * Create a SpriteMap from binary data
851
+ * @param data Binary data buffer
852
+ * @returns SpriteMap instance
853
+ */
854
+ static fromBytes(data: Uint8Array): SpriteMap;
855
+ /**
856
+ * Convert this SpriteMap to binary data
857
+ * @returns Binary data buffer
858
+ */
859
+ toBytes(): Uint8Array;
860
+ }
993
861
 
994
862
  /**
995
863
  * GaiaCore - Universal ROM processing engine
@@ -1012,4 +880,4 @@ declare const isPlatformBrowser: boolean;
1012
880
  declare const isPlatformNode: string | false;
1013
881
  declare const isPlatformWebWorker: boolean;
1014
882
 
1015
- export { ADDRESSING_REGEX, ALL_OPCODES, AddressingModeHandler, AsmReader, BlockReader, BlockWriter, type BuildResult, CopCommandProcessor, type ExtractionResult, FileReader, GAIA_CORE_VERSION, GROUPED_OPCODES, HEX_REGEX, type ICompressionProvider, ObjectType, Op, OpCode, OpCodeUtils, type OpcodeStats, OperationContext, PostProcessor, ProcessorStateManager, type ProjectConfig, type ProjectEvents, ProjectManager, ProjectRoot, type ProjectStatus, QuintetLZ, ROM_REBUILD_MODULE, ReferenceManager, Registers, type RomAnalysisResult, RomDataReader, type RomHeaderInfo, RomProcessor, RomState, RomStateUtils, SfxReader, SpriteFrame, SpriteGroup, SpriteMap, SpritePart, Stack, StackOperations, StringReader, TransformProcessor, TypeParser, isPlatformBrowser, isPlatformNode, isPlatformWebWorker };
883
+ export { AddressingModeHandler, AsmReader, Assembler, type AssemblerContext, AssemblerState, BlockReader, BlockWriter, CopCommandProcessor, GAIA_CORE_VERSION, ObjectType, OperationContext, PostProcessor, ProcessorStateManager, type ProjectConfig, 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 };