@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.d.mts +32 -70
- package/dist/index.d.ts +32 -70
- package/dist/index.js +136 -200
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +138 -201
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,72 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* QuintetLZ compression algorithm implementation
|
|
5
|
-
* Dictionary-based compression used in Quintet games
|
|
6
|
-
*/
|
|
7
|
-
declare class QuintetLZ implements ICompressionProvider {
|
|
8
|
-
static readonly DICTIONARY_SIZE = 256;
|
|
9
|
-
static readonly DICTIONARY_INIT = 32;
|
|
10
|
-
static readonly DICTIONARY_OFFSET = 239;
|
|
11
|
-
private static readonly DEFAULT_PAGE_SIZE;
|
|
12
|
-
/**
|
|
13
|
-
* Expand (decompress) data using QuintetLZ algorithm
|
|
14
|
-
* @param srcData Source data buffer
|
|
15
|
-
* @param srcPosition Starting position in source data
|
|
16
|
-
* @param srcLen Length of source data to process
|
|
17
|
-
* @returns Expanded data
|
|
18
|
-
*/
|
|
19
|
-
expand(srcData: Uint8Array, srcPosition?: number, srcLen?: number): Uint8Array;
|
|
20
|
-
/**
|
|
21
|
-
* Compact (compress) data using QuintetLZ algorithm
|
|
22
|
-
* @param srcData Source data to compress
|
|
23
|
-
* @returns Compressed data
|
|
24
|
-
*/
|
|
25
|
-
compact(srcData: Uint8Array): Uint8Array;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Register compression providers with the global registry
|
|
30
|
-
*/
|
|
31
|
-
declare function registerCompressionProviders(): void;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Main project management class
|
|
35
|
-
* Converted from GaiaLib/ProjectRoot.cs
|
|
36
|
-
*/
|
|
37
|
-
interface ProjectConfig {
|
|
38
|
-
name: string;
|
|
39
|
-
romPath: string;
|
|
40
|
-
baseDir: string;
|
|
41
|
-
system?: string;
|
|
42
|
-
database: string;
|
|
43
|
-
flipsPath?: string;
|
|
44
|
-
resources: Record<BinType, DbPath>;
|
|
45
|
-
databasePath?: string;
|
|
46
|
-
systemPath?: string;
|
|
47
|
-
compression?: string;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Project root management
|
|
51
|
-
*/
|
|
52
|
-
declare class ProjectRoot {
|
|
53
|
-
config: ProjectConfig;
|
|
54
|
-
name: string;
|
|
55
|
-
romPath: string;
|
|
56
|
-
baseDir: string;
|
|
57
|
-
system?: string;
|
|
58
|
-
database: string;
|
|
59
|
-
flipsPath?: string;
|
|
60
|
-
resources: Record<BinType, DbPath>;
|
|
61
|
-
databasePath?: string;
|
|
62
|
-
systemPath?: string;
|
|
63
|
-
compression?: string;
|
|
64
|
-
constructor(config: ProjectConfig);
|
|
65
|
-
/**
|
|
66
|
-
* Load project from file or directory
|
|
67
|
-
*/
|
|
68
|
-
static load(path?: string): Promise<ProjectRoot>;
|
|
69
|
-
}
|
|
1
|
+
import { StatusFlags, DbRoot, AddressType, DbStringType, StringWrapper, Op, OpCode, ChunkFile, AsmBlock, Address, CopDef, DbEntryPoint, ICompressionProvider } from '@gaialabs/shared';
|
|
70
2
|
|
|
71
3
|
/**
|
|
72
4
|
* Lightweight ROM state placeholder used during early development.
|
|
@@ -779,6 +711,36 @@ declare class RomGenerator {
|
|
|
779
711
|
private writeRom;
|
|
780
712
|
}
|
|
781
713
|
|
|
714
|
+
/**
|
|
715
|
+
* QuintetLZ compression algorithm implementation
|
|
716
|
+
* Dictionary-based compression used in Quintet games
|
|
717
|
+
*/
|
|
718
|
+
declare class QuintetLZ implements ICompressionProvider {
|
|
719
|
+
static readonly DICTIONARY_SIZE = 256;
|
|
720
|
+
static readonly DICTIONARY_INIT = 32;
|
|
721
|
+
static readonly DICTIONARY_OFFSET = 239;
|
|
722
|
+
private static readonly DEFAULT_PAGE_SIZE;
|
|
723
|
+
/**
|
|
724
|
+
* Expand (decompress) data using QuintetLZ algorithm
|
|
725
|
+
* @param srcData Source data buffer
|
|
726
|
+
* @param srcPosition Starting position in source data
|
|
727
|
+
* @param srcLen Length of source data to process
|
|
728
|
+
* @returns Expanded data
|
|
729
|
+
*/
|
|
730
|
+
expand(srcData: Uint8Array, srcPosition?: number, srcLen?: number): Uint8Array;
|
|
731
|
+
/**
|
|
732
|
+
* Compact (compress) data using QuintetLZ algorithm
|
|
733
|
+
* @param srcData Source data to compress
|
|
734
|
+
* @returns Compressed data
|
|
735
|
+
*/
|
|
736
|
+
compact(srcData: Uint8Array): Uint8Array;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
/**
|
|
740
|
+
* Register compression providers with the global registry
|
|
741
|
+
*/
|
|
742
|
+
declare function registerCompressionProviders(): void;
|
|
743
|
+
|
|
782
744
|
/**
|
|
783
745
|
* Represents a single frame in a sprite animation sequence
|
|
784
746
|
*/
|
|
@@ -870,4 +832,4 @@ declare const isPlatformBrowser: boolean;
|
|
|
870
832
|
declare const isPlatformNode: string | false;
|
|
871
833
|
declare const isPlatformWebWorker: boolean;
|
|
872
834
|
|
|
873
|
-
export { AddressingModeHandler, AsmReader, Assembler, type AssemblerContext, AssemblerState, BlockReader, BlockWriter, CopCommandProcessor, GAIA_CORE_VERSION, ObjectType, OperationContext, PostProcessor, ProcessorStateManager,
|
|
835
|
+
export { AddressingModeHandler, AsmReader, Assembler, type AssemblerContext, 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,72 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* QuintetLZ compression algorithm implementation
|
|
5
|
-
* Dictionary-based compression used in Quintet games
|
|
6
|
-
*/
|
|
7
|
-
declare class QuintetLZ implements ICompressionProvider {
|
|
8
|
-
static readonly DICTIONARY_SIZE = 256;
|
|
9
|
-
static readonly DICTIONARY_INIT = 32;
|
|
10
|
-
static readonly DICTIONARY_OFFSET = 239;
|
|
11
|
-
private static readonly DEFAULT_PAGE_SIZE;
|
|
12
|
-
/**
|
|
13
|
-
* Expand (decompress) data using QuintetLZ algorithm
|
|
14
|
-
* @param srcData Source data buffer
|
|
15
|
-
* @param srcPosition Starting position in source data
|
|
16
|
-
* @param srcLen Length of source data to process
|
|
17
|
-
* @returns Expanded data
|
|
18
|
-
*/
|
|
19
|
-
expand(srcData: Uint8Array, srcPosition?: number, srcLen?: number): Uint8Array;
|
|
20
|
-
/**
|
|
21
|
-
* Compact (compress) data using QuintetLZ algorithm
|
|
22
|
-
* @param srcData Source data to compress
|
|
23
|
-
* @returns Compressed data
|
|
24
|
-
*/
|
|
25
|
-
compact(srcData: Uint8Array): Uint8Array;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Register compression providers with the global registry
|
|
30
|
-
*/
|
|
31
|
-
declare function registerCompressionProviders(): void;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Main project management class
|
|
35
|
-
* Converted from GaiaLib/ProjectRoot.cs
|
|
36
|
-
*/
|
|
37
|
-
interface ProjectConfig {
|
|
38
|
-
name: string;
|
|
39
|
-
romPath: string;
|
|
40
|
-
baseDir: string;
|
|
41
|
-
system?: string;
|
|
42
|
-
database: string;
|
|
43
|
-
flipsPath?: string;
|
|
44
|
-
resources: Record<BinType, DbPath>;
|
|
45
|
-
databasePath?: string;
|
|
46
|
-
systemPath?: string;
|
|
47
|
-
compression?: string;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Project root management
|
|
51
|
-
*/
|
|
52
|
-
declare class ProjectRoot {
|
|
53
|
-
config: ProjectConfig;
|
|
54
|
-
name: string;
|
|
55
|
-
romPath: string;
|
|
56
|
-
baseDir: string;
|
|
57
|
-
system?: string;
|
|
58
|
-
database: string;
|
|
59
|
-
flipsPath?: string;
|
|
60
|
-
resources: Record<BinType, DbPath>;
|
|
61
|
-
databasePath?: string;
|
|
62
|
-
systemPath?: string;
|
|
63
|
-
compression?: string;
|
|
64
|
-
constructor(config: ProjectConfig);
|
|
65
|
-
/**
|
|
66
|
-
* Load project from file or directory
|
|
67
|
-
*/
|
|
68
|
-
static load(path?: string): Promise<ProjectRoot>;
|
|
69
|
-
}
|
|
1
|
+
import { StatusFlags, DbRoot, AddressType, DbStringType, StringWrapper, Op, OpCode, ChunkFile, AsmBlock, Address, CopDef, DbEntryPoint, ICompressionProvider } from '@gaialabs/shared';
|
|
70
2
|
|
|
71
3
|
/**
|
|
72
4
|
* Lightweight ROM state placeholder used during early development.
|
|
@@ -779,6 +711,36 @@ declare class RomGenerator {
|
|
|
779
711
|
private writeRom;
|
|
780
712
|
}
|
|
781
713
|
|
|
714
|
+
/**
|
|
715
|
+
* QuintetLZ compression algorithm implementation
|
|
716
|
+
* Dictionary-based compression used in Quintet games
|
|
717
|
+
*/
|
|
718
|
+
declare class QuintetLZ implements ICompressionProvider {
|
|
719
|
+
static readonly DICTIONARY_SIZE = 256;
|
|
720
|
+
static readonly DICTIONARY_INIT = 32;
|
|
721
|
+
static readonly DICTIONARY_OFFSET = 239;
|
|
722
|
+
private static readonly DEFAULT_PAGE_SIZE;
|
|
723
|
+
/**
|
|
724
|
+
* Expand (decompress) data using QuintetLZ algorithm
|
|
725
|
+
* @param srcData Source data buffer
|
|
726
|
+
* @param srcPosition Starting position in source data
|
|
727
|
+
* @param srcLen Length of source data to process
|
|
728
|
+
* @returns Expanded data
|
|
729
|
+
*/
|
|
730
|
+
expand(srcData: Uint8Array, srcPosition?: number, srcLen?: number): Uint8Array;
|
|
731
|
+
/**
|
|
732
|
+
* Compact (compress) data using QuintetLZ algorithm
|
|
733
|
+
* @param srcData Source data to compress
|
|
734
|
+
* @returns Compressed data
|
|
735
|
+
*/
|
|
736
|
+
compact(srcData: Uint8Array): Uint8Array;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
/**
|
|
740
|
+
* Register compression providers with the global registry
|
|
741
|
+
*/
|
|
742
|
+
declare function registerCompressionProviders(): void;
|
|
743
|
+
|
|
782
744
|
/**
|
|
783
745
|
* Represents a single frame in a sprite animation sequence
|
|
784
746
|
*/
|
|
@@ -870,4 +832,4 @@ declare const isPlatformBrowser: boolean;
|
|
|
870
832
|
declare const isPlatformNode: string | false;
|
|
871
833
|
declare const isPlatformWebWorker: boolean;
|
|
872
834
|
|
|
873
|
-
export { AddressingModeHandler, AsmReader, Assembler, type AssemblerContext, AssemblerState, BlockReader, BlockWriter, CopCommandProcessor, GAIA_CORE_VERSION, ObjectType, OperationContext, PostProcessor, ProcessorStateManager,
|
|
835
|
+
export { AddressingModeHandler, AsmReader, Assembler, type AssemblerContext, 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 };
|
package/dist/index.js
CHANGED
|
@@ -2,205 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
var shared = require('@gaialabs/shared');
|
|
4
4
|
|
|
5
|
-
// src/rom/project.ts
|
|
6
|
-
var QuintetLZ = class _QuintetLZ {
|
|
7
|
-
static {
|
|
8
|
-
this.DICTIONARY_SIZE = 256;
|
|
9
|
-
}
|
|
10
|
-
static {
|
|
11
|
-
this.DICTIONARY_INIT = 32;
|
|
12
|
-
}
|
|
13
|
-
static {
|
|
14
|
-
this.DICTIONARY_OFFSET = 239;
|
|
15
|
-
}
|
|
16
|
-
static {
|
|
17
|
-
this.DEFAULT_PAGE_SIZE = 32768;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Expand (decompress) data using QuintetLZ algorithm
|
|
21
|
-
* @param srcData Source data buffer
|
|
22
|
-
* @param srcPosition Starting position in source data
|
|
23
|
-
* @param srcLen Length of source data to process
|
|
24
|
-
* @returns Expanded data
|
|
25
|
-
*/
|
|
26
|
-
expand(srcData, srcPosition = 0, srcLen = _QuintetLZ.DEFAULT_PAGE_SIZE) {
|
|
27
|
-
const bitStream = new shared.BitStream(srcData, srcPosition);
|
|
28
|
-
const srcStop = srcPosition + srcLen;
|
|
29
|
-
const dictionary = new Uint8Array(_QuintetLZ.DICTIONARY_SIZE);
|
|
30
|
-
dictionary.fill(_QuintetLZ.DICTIONARY_INIT);
|
|
31
|
-
let dictPosition = _QuintetLZ.DICTIONARY_OFFSET;
|
|
32
|
-
let outPosition = 0;
|
|
33
|
-
let dstLen = bitStream.readShort();
|
|
34
|
-
if (dstLen === 0) {
|
|
35
|
-
return srcData.slice(srcPosition + 2, srcStop);
|
|
36
|
-
} else if (dstLen & 32768) {
|
|
37
|
-
dstLen = 65536 - dstLen;
|
|
38
|
-
}
|
|
39
|
-
const outBuffer = new Uint8Array(dstLen);
|
|
40
|
-
while (bitStream.currentPosition < srcStop && outPosition < dstLen) {
|
|
41
|
-
if (bitStream.readBit()) {
|
|
42
|
-
const sample = bitStream.readByte();
|
|
43
|
-
if (outPosition < dstLen) {
|
|
44
|
-
outBuffer[outPosition++] = sample;
|
|
45
|
-
}
|
|
46
|
-
dictionary[dictPosition] = sample;
|
|
47
|
-
dictPosition = dictPosition + 1 & 255;
|
|
48
|
-
} else {
|
|
49
|
-
let wordIndex = bitStream.readByte();
|
|
50
|
-
let wordLength = bitStream.readNibble() + 2;
|
|
51
|
-
while (wordLength-- > 0) {
|
|
52
|
-
const sample = dictionary[wordIndex];
|
|
53
|
-
wordIndex = wordIndex + 1 & 255;
|
|
54
|
-
if (outPosition < dstLen) {
|
|
55
|
-
outBuffer[outPosition++] = sample;
|
|
56
|
-
}
|
|
57
|
-
dictionary[dictPosition] = sample;
|
|
58
|
-
dictPosition = dictPosition + 1 & 255;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
if (outPosition < dstLen) {
|
|
63
|
-
return outBuffer.slice(0, outPosition);
|
|
64
|
-
}
|
|
65
|
-
return outBuffer;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Compact (compress) data using QuintetLZ algorithm
|
|
69
|
-
* @param srcData Source data to compress
|
|
70
|
-
* @returns Compressed data
|
|
71
|
-
*/
|
|
72
|
-
compact(srcData) {
|
|
73
|
-
const dictionary = new Uint8Array(_QuintetLZ.DICTIONARY_SIZE);
|
|
74
|
-
dictionary.fill(_QuintetLZ.DICTIONARY_INIT);
|
|
75
|
-
let offset = _QuintetLZ.DICTIONARY_OFFSET;
|
|
76
|
-
let srcIx = 0;
|
|
77
|
-
let dstIx = 0;
|
|
78
|
-
const srcLen = srcData.length;
|
|
79
|
-
const outputBuffer = new Uint8Array(srcLen * 2);
|
|
80
|
-
outputBuffer[dstIx++] = srcLen & 255;
|
|
81
|
-
outputBuffer[dstIx++] = srcLen >> 8 & 255;
|
|
82
|
-
const bitStream = new shared.BitStream(outputBuffer, 2);
|
|
83
|
-
const getCommand = () => {
|
|
84
|
-
const maxLen = Math.min(srcLen - srcIx, 17);
|
|
85
|
-
if (maxLen < 2) {
|
|
86
|
-
return [0, 0];
|
|
87
|
-
}
|
|
88
|
-
let startByte = 0;
|
|
89
|
-
let bestLen = 0;
|
|
90
|
-
let bx = offset;
|
|
91
|
-
for (let i = 0; i < 256; i++, bx = bx + 1 & 255) {
|
|
92
|
-
let size = 0;
|
|
93
|
-
let bix = bx;
|
|
94
|
-
while (size < maxLen && dictionary[bix] === srcData[srcIx + size]) {
|
|
95
|
-
bix = bix + 1 & 255;
|
|
96
|
-
if (bix === offset) {
|
|
97
|
-
bix = bx;
|
|
98
|
-
}
|
|
99
|
-
size++;
|
|
100
|
-
}
|
|
101
|
-
if (size > bestLen) {
|
|
102
|
-
startByte = bx;
|
|
103
|
-
bestLen = size;
|
|
104
|
-
if (bestLen >= maxLen) {
|
|
105
|
-
break;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return [startByte, bestLen];
|
|
110
|
-
};
|
|
111
|
-
while (srcIx < srcLen) {
|
|
112
|
-
const [cmdStart, cmdLen] = getCommand();
|
|
113
|
-
if (cmdLen >= 2) {
|
|
114
|
-
bitStream.writeBit(false);
|
|
115
|
-
bitStream.writeByte(cmdStart);
|
|
116
|
-
bitStream.writeNibble(cmdLen - 2);
|
|
117
|
-
for (let i = 0; i < cmdLen; i++) {
|
|
118
|
-
dictionary[offset] = srcData[srcIx++];
|
|
119
|
-
offset = offset + 1 & 255;
|
|
120
|
-
}
|
|
121
|
-
} else {
|
|
122
|
-
bitStream.writeBit(true);
|
|
123
|
-
const val = srcData[srcIx++];
|
|
124
|
-
bitStream.writeByte(val);
|
|
125
|
-
dictionary[offset] = val;
|
|
126
|
-
offset = offset + 1 & 255;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
bitStream.flush();
|
|
130
|
-
const finalSize = Math.max(dstIx, bitStream.currentPosition);
|
|
131
|
-
return outputBuffer.slice(0, finalSize);
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
function registerCompressionProviders() {
|
|
135
|
-
shared.CompressionRegistry.register("QuintetLZ", () => new QuintetLZ());
|
|
136
|
-
}
|
|
137
|
-
registerCompressionProviders();
|
|
138
|
-
|
|
139
|
-
// src/rom/project.ts
|
|
140
|
-
var ProjectRoot = class _ProjectRoot {
|
|
141
|
-
constructor(config) {
|
|
142
|
-
this.config = config;
|
|
143
|
-
this.name = config.name;
|
|
144
|
-
this.romPath = config.romPath;
|
|
145
|
-
this.baseDir = config.baseDir;
|
|
146
|
-
this.system = config.system;
|
|
147
|
-
this.database = config.database;
|
|
148
|
-
this.flipsPath = config.flipsPath;
|
|
149
|
-
this.resources = config.resources;
|
|
150
|
-
this.databasePath = config.databasePath;
|
|
151
|
-
this.systemPath = config.systemPath;
|
|
152
|
-
this.compression = config.compression;
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Load project from file or directory
|
|
156
|
-
*/
|
|
157
|
-
static async load(path) {
|
|
158
|
-
path = path || "./project.json";
|
|
159
|
-
try {
|
|
160
|
-
const config = await shared.readJsonFile(path);
|
|
161
|
-
if (!config.baseDir) {
|
|
162
|
-
config.baseDir = await shared.getDirectory(path);
|
|
163
|
-
}
|
|
164
|
-
return new _ProjectRoot(config);
|
|
165
|
-
} catch (error) {
|
|
166
|
-
console.warn(`Failed to load project file: ${error}. Using directory-based configuration.`);
|
|
167
|
-
}
|
|
168
|
-
const defaultConfig = {
|
|
169
|
-
name: "GaiaLabs",
|
|
170
|
-
baseDir: path,
|
|
171
|
-
flipsPath: process?.env?.flips_path,
|
|
172
|
-
romPath: process?.env?.rom_path || "",
|
|
173
|
-
database: "us",
|
|
174
|
-
databasePath: `${path}/db/us`,
|
|
175
|
-
systemPath: `${path}/db/snes`,
|
|
176
|
-
resources: {}
|
|
177
|
-
};
|
|
178
|
-
return new _ProjectRoot(defaultConfig);
|
|
179
|
-
}
|
|
180
|
-
// /**
|
|
181
|
-
// * Build the ROM (simplified)
|
|
182
|
-
// */
|
|
183
|
-
// public async build(files: ChunkFile[], entryPoints: DbEntryPoint[]): Promise<void> {
|
|
184
|
-
// // Build ROM using rebuild writer
|
|
185
|
-
// const writer = new RomWriter(entryPoints, this.config.cartName, this.config.makerCode);
|
|
186
|
-
// await writer.repack(files);
|
|
187
|
-
// }
|
|
188
|
-
/**
|
|
189
|
-
* Dump database and extract ROM data with comprehensive assembly processing
|
|
190
|
-
*/
|
|
191
|
-
// public async dumpDatabase(): Promise<ChunkFile[]> {
|
|
192
|
-
// // Load database and ROM data
|
|
193
|
-
// const root = await DbRootUtils.fromFolder(this.databasePath!, this.systemPath!);
|
|
194
|
-
// const rom = await readFileAsBinary(this.romPath);
|
|
195
|
-
// //root.paths = this.resources;
|
|
196
|
-
// const chunkReader = new BlockReader(rom, root);
|
|
197
|
-
// const chunkFiles = chunkReader.analyzeAndResolve();
|
|
198
|
-
// const blockWriter = new BlockWriter(chunkReader);
|
|
199
|
-
// const writtenFiles = blockWriter.generateAllAsm(chunkFiles);
|
|
200
|
-
// return chunkFiles;
|
|
201
|
-
// }
|
|
202
|
-
};
|
|
203
|
-
|
|
204
5
|
// src/rom/state.ts
|
|
205
6
|
var RomState = class _RomState {
|
|
206
7
|
constructor() {
|
|
@@ -1457,6 +1258,142 @@ var Registers = class {
|
|
|
1457
1258
|
this.stack.reset();
|
|
1458
1259
|
}
|
|
1459
1260
|
};
|
|
1261
|
+
var QuintetLZ = class _QuintetLZ {
|
|
1262
|
+
static {
|
|
1263
|
+
this.DICTIONARY_SIZE = 256;
|
|
1264
|
+
}
|
|
1265
|
+
static {
|
|
1266
|
+
this.DICTIONARY_INIT = 32;
|
|
1267
|
+
}
|
|
1268
|
+
static {
|
|
1269
|
+
this.DICTIONARY_OFFSET = 239;
|
|
1270
|
+
}
|
|
1271
|
+
static {
|
|
1272
|
+
this.DEFAULT_PAGE_SIZE = 32768;
|
|
1273
|
+
}
|
|
1274
|
+
/**
|
|
1275
|
+
* Expand (decompress) data using QuintetLZ algorithm
|
|
1276
|
+
* @param srcData Source data buffer
|
|
1277
|
+
* @param srcPosition Starting position in source data
|
|
1278
|
+
* @param srcLen Length of source data to process
|
|
1279
|
+
* @returns Expanded data
|
|
1280
|
+
*/
|
|
1281
|
+
expand(srcData, srcPosition = 0, srcLen = _QuintetLZ.DEFAULT_PAGE_SIZE) {
|
|
1282
|
+
const bitStream = new shared.BitStream(srcData, srcPosition);
|
|
1283
|
+
const srcStop = srcPosition + srcLen;
|
|
1284
|
+
const dictionary = new Uint8Array(_QuintetLZ.DICTIONARY_SIZE);
|
|
1285
|
+
dictionary.fill(_QuintetLZ.DICTIONARY_INIT);
|
|
1286
|
+
let dictPosition = _QuintetLZ.DICTIONARY_OFFSET;
|
|
1287
|
+
let outPosition = 0;
|
|
1288
|
+
let dstLen = bitStream.readShort();
|
|
1289
|
+
if (dstLen === 0) {
|
|
1290
|
+
return srcData.slice(srcPosition + 2, srcStop);
|
|
1291
|
+
} else if (dstLen & 32768) {
|
|
1292
|
+
dstLen = 65536 - dstLen;
|
|
1293
|
+
}
|
|
1294
|
+
const outBuffer = new Uint8Array(dstLen);
|
|
1295
|
+
while (bitStream.currentPosition < srcStop && outPosition < dstLen) {
|
|
1296
|
+
if (bitStream.readBit()) {
|
|
1297
|
+
const sample = bitStream.readByte();
|
|
1298
|
+
if (outPosition < dstLen) {
|
|
1299
|
+
outBuffer[outPosition++] = sample;
|
|
1300
|
+
}
|
|
1301
|
+
dictionary[dictPosition] = sample;
|
|
1302
|
+
dictPosition = dictPosition + 1 & 255;
|
|
1303
|
+
} else {
|
|
1304
|
+
let wordIndex = bitStream.readByte();
|
|
1305
|
+
let wordLength = bitStream.readNibble() + 2;
|
|
1306
|
+
while (wordLength-- > 0) {
|
|
1307
|
+
const sample = dictionary[wordIndex];
|
|
1308
|
+
wordIndex = wordIndex + 1 & 255;
|
|
1309
|
+
if (outPosition < dstLen) {
|
|
1310
|
+
outBuffer[outPosition++] = sample;
|
|
1311
|
+
}
|
|
1312
|
+
dictionary[dictPosition] = sample;
|
|
1313
|
+
dictPosition = dictPosition + 1 & 255;
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
if (outPosition < dstLen) {
|
|
1318
|
+
return outBuffer.slice(0, outPosition);
|
|
1319
|
+
}
|
|
1320
|
+
return outBuffer;
|
|
1321
|
+
}
|
|
1322
|
+
/**
|
|
1323
|
+
* Compact (compress) data using QuintetLZ algorithm
|
|
1324
|
+
* @param srcData Source data to compress
|
|
1325
|
+
* @returns Compressed data
|
|
1326
|
+
*/
|
|
1327
|
+
compact(srcData) {
|
|
1328
|
+
const dictionary = new Uint8Array(_QuintetLZ.DICTIONARY_SIZE);
|
|
1329
|
+
dictionary.fill(_QuintetLZ.DICTIONARY_INIT);
|
|
1330
|
+
let offset = _QuintetLZ.DICTIONARY_OFFSET;
|
|
1331
|
+
let srcIx = 0;
|
|
1332
|
+
let dstIx = 0;
|
|
1333
|
+
const srcLen = srcData.length;
|
|
1334
|
+
const outputBuffer = new Uint8Array(srcLen * 2);
|
|
1335
|
+
outputBuffer[dstIx++] = srcLen & 255;
|
|
1336
|
+
outputBuffer[dstIx++] = srcLen >> 8 & 255;
|
|
1337
|
+
const bitStream = new shared.BitStream(outputBuffer, 2);
|
|
1338
|
+
const getCommand = () => {
|
|
1339
|
+
const maxLen = Math.min(srcLen - srcIx, 17);
|
|
1340
|
+
if (maxLen < 2) {
|
|
1341
|
+
return [0, 0];
|
|
1342
|
+
}
|
|
1343
|
+
let startByte = 0;
|
|
1344
|
+
let bestLen = 0;
|
|
1345
|
+
let bx = offset;
|
|
1346
|
+
for (let i = 0; i < 256; i++, bx = bx + 1 & 255) {
|
|
1347
|
+
let size = 0;
|
|
1348
|
+
let bix = bx;
|
|
1349
|
+
while (size < maxLen && dictionary[bix] === srcData[srcIx + size]) {
|
|
1350
|
+
bix = bix + 1 & 255;
|
|
1351
|
+
if (bix === offset) {
|
|
1352
|
+
bix = bx;
|
|
1353
|
+
}
|
|
1354
|
+
size++;
|
|
1355
|
+
}
|
|
1356
|
+
if (size > bestLen) {
|
|
1357
|
+
startByte = bx;
|
|
1358
|
+
bestLen = size;
|
|
1359
|
+
if (bestLen >= maxLen) {
|
|
1360
|
+
break;
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
return [startByte, bestLen];
|
|
1365
|
+
};
|
|
1366
|
+
while (srcIx < srcLen) {
|
|
1367
|
+
const [cmdStart, cmdLen] = getCommand();
|
|
1368
|
+
if (cmdLen >= 2) {
|
|
1369
|
+
bitStream.writeBit(false);
|
|
1370
|
+
bitStream.writeByte(cmdStart);
|
|
1371
|
+
bitStream.writeNibble(cmdLen - 2);
|
|
1372
|
+
for (let i = 0; i < cmdLen; i++) {
|
|
1373
|
+
dictionary[offset] = srcData[srcIx++];
|
|
1374
|
+
offset = offset + 1 & 255;
|
|
1375
|
+
}
|
|
1376
|
+
} else {
|
|
1377
|
+
bitStream.writeBit(true);
|
|
1378
|
+
const val = srcData[srcIx++];
|
|
1379
|
+
bitStream.writeByte(val);
|
|
1380
|
+
dictionary[offset] = val;
|
|
1381
|
+
offset = offset + 1 & 255;
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
bitStream.flush();
|
|
1385
|
+
const finalSize = Math.max(dstIx, bitStream.currentPosition);
|
|
1386
|
+
return outputBuffer.slice(0, finalSize);
|
|
1387
|
+
}
|
|
1388
|
+
};
|
|
1389
|
+
|
|
1390
|
+
// src/compression/registry.ts
|
|
1391
|
+
function registerCompressionProviders() {
|
|
1392
|
+
shared.CompressionRegistry.register("QuintetLZ", () => new QuintetLZ());
|
|
1393
|
+
}
|
|
1394
|
+
registerCompressionProviders();
|
|
1395
|
+
|
|
1396
|
+
// src/rom/extraction/blocks.ts
|
|
1460
1397
|
registerCompressionProviders();
|
|
1461
1398
|
var BlockReader = class {
|
|
1462
1399
|
constructor(romData, root) {
|
|
@@ -4011,7 +3948,6 @@ exports.ObjectType = ObjectType;
|
|
|
4011
3948
|
exports.OperationContext = OperationContext;
|
|
4012
3949
|
exports.PostProcessor = PostProcessor;
|
|
4013
3950
|
exports.ProcessorStateManager = ProcessorStateManager;
|
|
4014
|
-
exports.ProjectRoot = ProjectRoot;
|
|
4015
3951
|
exports.QuintetLZ = QuintetLZ;
|
|
4016
3952
|
exports.ReferenceManager = ReferenceManager;
|
|
4017
3953
|
exports.Registers = Registers;
|