@gaialabs/core 0.2.14 → 0.2.15
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.cjs +130 -60
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +10 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +130 -60
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -936,7 +936,7 @@ var RomDataReader = class {
|
|
|
936
936
|
romData;
|
|
937
937
|
position;
|
|
938
938
|
offset;
|
|
939
|
-
constructor(romData, offset
|
|
939
|
+
constructor(romData, offset) {
|
|
940
940
|
if (!romData) throw new Error("romData cannot be null");
|
|
941
941
|
this.romData = romData;
|
|
942
942
|
this.position = 0;
|
|
@@ -1130,6 +1130,7 @@ let AddressType = /* @__PURE__ */ function(AddressType) {
|
|
|
1130
1130
|
AddressType["Relative"] = "Relative";
|
|
1131
1131
|
AddressType["WRelative"] = "WRelative";
|
|
1132
1132
|
AddressType["Location"] = "Location";
|
|
1133
|
+
AddressType["OddLocation"] = "OddLocation";
|
|
1133
1134
|
return AddressType;
|
|
1134
1135
|
}({});
|
|
1135
1136
|
/**
|
|
@@ -1220,6 +1221,7 @@ var Address = class Address {
|
|
|
1220
1221
|
case "@": return AddressType.Address;
|
|
1221
1222
|
case "*": return AddressType.WBank;
|
|
1222
1223
|
case "%": return AddressType.Location;
|
|
1224
|
+
case "!": return AddressType.OddLocation;
|
|
1223
1225
|
default: return AddressType.Unknown;
|
|
1224
1226
|
}
|
|
1225
1227
|
}
|
|
@@ -1230,6 +1232,7 @@ var Address = class Address {
|
|
|
1230
1232
|
case AddressType.Address: return "@";
|
|
1231
1233
|
case AddressType.WBank: return "*";
|
|
1232
1234
|
case AddressType.Location: return "%";
|
|
1235
|
+
case AddressType.OddLocation: return "!";
|
|
1233
1236
|
default: return null;
|
|
1234
1237
|
}
|
|
1235
1238
|
}
|
|
@@ -1674,6 +1677,7 @@ var ChunkFile = class {
|
|
|
1674
1677
|
scene;
|
|
1675
1678
|
base;
|
|
1676
1679
|
referenceManager;
|
|
1680
|
+
isFile;
|
|
1677
1681
|
constructor(type, name, size = 0, location = 0) {
|
|
1678
1682
|
this.type = type;
|
|
1679
1683
|
this.name = name;
|
|
@@ -1681,6 +1685,7 @@ var ChunkFile = class {
|
|
|
1681
1685
|
this.location = location;
|
|
1682
1686
|
this.mnemonics = {};
|
|
1683
1687
|
this.compressed = type.compressed;
|
|
1688
|
+
this.isFile = !type.isBlock;
|
|
1684
1689
|
}
|
|
1685
1690
|
enrichWithRawDataFromDbFile(file, rom, compression) {
|
|
1686
1691
|
this.upper = file.upper ?? this.upper;
|
|
@@ -1689,7 +1694,8 @@ var ChunkFile = class {
|
|
|
1689
1694
|
this.base = file.base ?? this.type.base ?? this.base;
|
|
1690
1695
|
this.group = file.group ?? this.group;
|
|
1691
1696
|
this.scene = file.scene ?? this.scene;
|
|
1692
|
-
this.compressed = file.compressed;
|
|
1697
|
+
this.compressed = file.compressed ?? this.type.compressed ?? this.compressed;
|
|
1698
|
+
this.isFile = true;
|
|
1693
1699
|
let start = this.location;
|
|
1694
1700
|
let header = null;
|
|
1695
1701
|
const fileType = this.type;
|
|
@@ -1715,6 +1721,8 @@ var ChunkFile = class {
|
|
|
1715
1721
|
enrichWithAsmBlocksFromDbBlock(block, memoryMode) {
|
|
1716
1722
|
this.group = block.group;
|
|
1717
1723
|
this.scene = block.scene;
|
|
1724
|
+
this.base = block.base;
|
|
1725
|
+
this.isFile = false;
|
|
1718
1726
|
this.parts = [];
|
|
1719
1727
|
this.size = 0;
|
|
1720
1728
|
if (!block.parts?.length) throw new Error(`Block ${block.name} has no parts`);
|
|
@@ -1932,14 +1940,23 @@ var ReferenceManager = class {
|
|
|
1932
1940
|
this.root = root;
|
|
1933
1941
|
}
|
|
1934
1942
|
tryGetStruct(location) {
|
|
1935
|
-
|
|
1943
|
+
let chunkType = this.structTable.get(location);
|
|
1944
|
+
const found = chunkType !== void 0;
|
|
1945
|
+
let isSoft;
|
|
1946
|
+
if (chunkType) if (chunkType[0] === "~") {
|
|
1947
|
+
isSoft = true;
|
|
1948
|
+
chunkType = chunkType.substring(1);
|
|
1949
|
+
} else isSoft = false;
|
|
1936
1950
|
return {
|
|
1937
|
-
found
|
|
1938
|
-
chunkType
|
|
1951
|
+
found,
|
|
1952
|
+
chunkType,
|
|
1953
|
+
isSoft
|
|
1939
1954
|
};
|
|
1940
1955
|
}
|
|
1941
1956
|
tryAddStruct(location, chunkType) {
|
|
1942
|
-
|
|
1957
|
+
const existingStruct = this.tryGetStruct(location);
|
|
1958
|
+
const isSoft = chunkType[0] === "~";
|
|
1959
|
+
if (existingStruct.isSoft === false || existingStruct.found && isSoft) return false;
|
|
1943
1960
|
this.structTable.set(location, chunkType);
|
|
1944
1961
|
return true;
|
|
1945
1962
|
}
|
|
@@ -1947,14 +1964,23 @@ var ReferenceManager = class {
|
|
|
1947
1964
|
return this.structTable.has(location);
|
|
1948
1965
|
}
|
|
1949
1966
|
tryGetName(location) {
|
|
1950
|
-
|
|
1967
|
+
let referenceName = this.nameTable.get(location);
|
|
1968
|
+
const found = referenceName !== void 0;
|
|
1969
|
+
let isSoft;
|
|
1970
|
+
if (referenceName) if (referenceName[0] === "~") {
|
|
1971
|
+
isSoft = true;
|
|
1972
|
+
referenceName = referenceName.substring(1);
|
|
1973
|
+
} else isSoft = false;
|
|
1951
1974
|
return {
|
|
1952
|
-
found
|
|
1953
|
-
referenceName
|
|
1975
|
+
found,
|
|
1976
|
+
referenceName,
|
|
1977
|
+
isSoft
|
|
1954
1978
|
};
|
|
1955
1979
|
}
|
|
1956
1980
|
tryAddName(location, referenceName) {
|
|
1957
|
-
|
|
1981
|
+
const existingName = this.tryGetName(location);
|
|
1982
|
+
const isSoft = referenceName[0] === "~";
|
|
1983
|
+
if (existingName.isSoft === false || existingName.found && isSoft) return false;
|
|
1958
1984
|
this.nameTable.set(location, referenceName);
|
|
1959
1985
|
return true;
|
|
1960
1986
|
}
|
|
@@ -1975,6 +2001,7 @@ var ReferenceManager = class {
|
|
|
1975
2001
|
}
|
|
1976
2002
|
createTypeName(type, location) {
|
|
1977
2003
|
let name = type.toLowerCase();
|
|
2004
|
+
if (type[0] === "~") name = name.substring(1);
|
|
1978
2005
|
if (name === "branch") name = "loc";
|
|
1979
2006
|
while (name.length > 0 && BlockReaderConstants.POINTER_CHARACTERS.includes(name[0])) name = name.substring(1) + "_list";
|
|
1980
2007
|
return `${name}_${location.toString(16).toUpperCase().padStart(6, "0")}`;
|
|
@@ -1995,8 +2022,8 @@ var ReferenceManager = class {
|
|
|
1995
2022
|
}
|
|
1996
2023
|
resolveName(location, type, isBranch) {
|
|
1997
2024
|
const prefix = Address.codeFromType(type);
|
|
1998
|
-
let name
|
|
1999
|
-
let label
|
|
2025
|
+
let name;
|
|
2026
|
+
let label;
|
|
2000
2027
|
let resolvedLocation = location;
|
|
2001
2028
|
const rewrite = this.root.rewrites[location];
|
|
2002
2029
|
if (rewrite !== void 0) {
|
|
@@ -2004,7 +2031,7 @@ var ReferenceManager = class {
|
|
|
2004
2031
|
resolvedLocation = result.location;
|
|
2005
2032
|
label = result.label;
|
|
2006
2033
|
}
|
|
2007
|
-
name = this.
|
|
2034
|
+
name = this.tryGetName(resolvedLocation).referenceName;
|
|
2008
2035
|
if (!name) name = isBranch ? this.createBranchLabel(resolvedLocation) : this.findClosestReference(resolvedLocation) || this.createFallbackName(resolvedLocation);
|
|
2009
2036
|
return `${prefix || ""}${name}${label || ""}`;
|
|
2010
2037
|
}
|
|
@@ -2027,8 +2054,8 @@ var ReferenceManager = class {
|
|
|
2027
2054
|
const offset = location - rewrite;
|
|
2028
2055
|
const cmd = offset < 0 ? "-" : "+";
|
|
2029
2056
|
const absOffset = Math.abs(offset);
|
|
2030
|
-
let label
|
|
2031
|
-
if (this.
|
|
2057
|
+
let label;
|
|
2058
|
+
if (this.tryGetStruct(rewrite).chunkType === BlockReaderConstants.WIDE_STRING_TYPE) {
|
|
2032
2059
|
this.markerTable.set(rewrite, absOffset);
|
|
2033
2060
|
this.markerTable.set(location, absOffset);
|
|
2034
2061
|
label = cmd === "-" ? BlockReaderConstants.NEGATIVE_MARKER_FORMAT : BlockReaderConstants.MARKER_FORMAT;
|
|
@@ -2041,7 +2068,7 @@ var ReferenceManager = class {
|
|
|
2041
2068
|
processClosestMatch(location, closestName, closestLocation, closestDistance) {
|
|
2042
2069
|
if (!closestName || closestLocation === null) return null;
|
|
2043
2070
|
let result = closestName;
|
|
2044
|
-
if (this.
|
|
2071
|
+
if (this.tryGetStruct(closestLocation).chunkType === BlockReaderConstants.WIDE_STRING_TYPE) {
|
|
2045
2072
|
this.markerTable.set(closestLocation, closestDistance);
|
|
2046
2073
|
this.markerTable.set(location, closestDistance);
|
|
2047
2074
|
result += BlockReaderConstants.MARKER_FORMAT;
|
|
@@ -2109,7 +2136,7 @@ var StackOperations = class {
|
|
|
2109
2136
|
break;
|
|
2110
2137
|
case "RTL":
|
|
2111
2138
|
case "RTS":
|
|
2112
|
-
this._blockReader._referenceManager.tryAddStruct(this._blockReader._romDataReader.position, "Code");
|
|
2139
|
+
this._blockReader._referenceManager.tryAddStruct(this._blockReader._romDataReader.position, "~Code");
|
|
2113
2140
|
break;
|
|
2114
2141
|
}
|
|
2115
2142
|
}
|
|
@@ -2366,7 +2393,7 @@ var AddressingModeHandler = class {
|
|
|
2366
2393
|
}
|
|
2367
2394
|
handlePCRelativeMode(operands, nextAddress, reg, isLong) {
|
|
2368
2395
|
const relative = isLong ? nextAddress + this._dataReader.readShort() : nextAddress + this._dataReader.readSByte();
|
|
2369
|
-
this._blockReader._referenceManager.tryAddStruct(relative, "Branch");
|
|
2396
|
+
this._blockReader._referenceManager.tryAddStruct(relative, "~Branch");
|
|
2370
2397
|
this._blockReader.updateRegisterState(relative, reg);
|
|
2371
2398
|
operands.push(new LocationWrapper(relative, isLong ? AddressType.WRelative : AddressType.Relative));
|
|
2372
2399
|
}
|
|
@@ -2397,7 +2424,7 @@ var AddressingModeHandler = class {
|
|
|
2397
2424
|
if (isJump) {
|
|
2398
2425
|
const type = isIndexedIndirect ? "&Code" : "Code";
|
|
2399
2426
|
const name = this._blockReader.noteType(wrapper.location, type, isPush, registers);
|
|
2400
|
-
if (mnemonic === "JMP") this._blockReader._referenceManager.tryAddStruct(this._dataReader.position, "Code");
|
|
2427
|
+
if (mnemonic === "JMP") this._blockReader._referenceManager.tryAddStruct(this._dataReader.position, "~Code");
|
|
2401
2428
|
if (isPush) {
|
|
2402
2429
|
operands.push(`&${name}-1`);
|
|
2403
2430
|
return;
|
|
@@ -3148,27 +3175,33 @@ var TypeParser = class {
|
|
|
3148
3175
|
this._stringReader = blockReader._stringReader;
|
|
3149
3176
|
this._stringTypes = blockReader._root.stringTypes;
|
|
3150
3177
|
}
|
|
3151
|
-
parseType(typeName, reg, depth, bank) {
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
const
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
const startIx = typeName.indexOf("(");
|
|
3160
|
-
fixedTypeName = typeName.substring(0, startIx);
|
|
3161
|
-
fixedSize = parseInt(typeName.substring(startIx + 1, typeName.length - 1), 10);
|
|
3178
|
+
parseType(typeName, reg, depth, bank, single) {
|
|
3179
|
+
const objects = [];
|
|
3180
|
+
const arrayIx = typeName.indexOf("[");
|
|
3181
|
+
const arrayCount = arrayIx !== -1 ? parseInt(typeName.substring(arrayIx + 1, typeName.length - 1), 16) : 0;
|
|
3182
|
+
const arrayTypeName = arrayIx !== -1 ? typeName.substring(0, arrayIx) : typeName;
|
|
3183
|
+
if (arrayCount > 0) {
|
|
3184
|
+
for (let i = 0; i < arrayCount; i++) objects.push(this.parseType(arrayTypeName, reg, depth + 1, bank, true));
|
|
3185
|
+
return objects;
|
|
3162
3186
|
}
|
|
3187
|
+
const isSoft = arrayTypeName[0] === "~";
|
|
3188
|
+
const realTypeName = isSoft ? arrayTypeName.substring(1) : arrayTypeName;
|
|
3189
|
+
const fixedIx = realTypeName.indexOf("(");
|
|
3190
|
+
const fixedSize = fixedIx !== -1 ? parseInt(realTypeName.substring(fixedIx + 1, realTypeName.length - 1), 16) : 0;
|
|
3191
|
+
const fixedTypeName = fixedIx !== -1 ? realTypeName.substring(0, fixedIx) : realTypeName;
|
|
3163
3192
|
const stringType = this._stringTypes[fixedTypeName];
|
|
3164
3193
|
if (stringType) return this._stringReader.parseString(stringType, fixedSize);
|
|
3194
|
+
if (fixedTypeName[0] === "&") return this.parseLocation(this._romDataReader.readUShort(), bank, fixedTypeName.substring(1), AddressType.Offset, isSoft);
|
|
3195
|
+
if (fixedTypeName[0] === "@") return this.parseLocation(this._romDataReader.readUShort(), this._romDataReader.readByte(), fixedTypeName.substring(1), AddressType.Address, isSoft);
|
|
3196
|
+
if (fixedTypeName[0] === "%") return this.parseLocation(this._romDataReader.readUShort(), this._romDataReader.readByte(), fixedTypeName.substring(1), AddressType.Location, isSoft);
|
|
3197
|
+
if (fixedTypeName[0] === "!") return this.parseLocation(this._romDataReader.readUShort(), this._romDataReader.readByte(), fixedTypeName.substring(1), AddressType.OddLocation, isSoft);
|
|
3165
3198
|
const mType = this.tryParseMemberType(fixedTypeName);
|
|
3166
3199
|
if (mType !== null) switch (mType) {
|
|
3167
3200
|
case MemberType.Byte: return new Byte(this._romDataReader.readByte());
|
|
3168
3201
|
case MemberType.Word: return new Word(this.parseWordSafe());
|
|
3169
|
-
case MemberType.Offset: return this.parseLocation(this._romDataReader.readUShort(), bank, null, AddressType.Offset);
|
|
3170
|
-
case MemberType.Address: return this.parseLocation(this._romDataReader.readUShort(), this._romDataReader.readByte(), null, AddressType.Address);
|
|
3171
|
-
case MemberType.Location: return this.parseLocation(this._romDataReader.readUShort(), this._romDataReader.readByte(), null, AddressType.Location);
|
|
3202
|
+
case MemberType.Offset: return this.parseLocation(this._romDataReader.readUShort(), bank, null, AddressType.Offset, isSoft);
|
|
3203
|
+
case MemberType.Address: return this.parseLocation(this._romDataReader.readUShort(), this._romDataReader.readByte(), null, AddressType.Address, isSoft);
|
|
3204
|
+
case MemberType.Location: return this.parseLocation(this._romDataReader.readUShort(), this._romDataReader.readByte(), null, AddressType.Location, isSoft);
|
|
3172
3205
|
case MemberType.Binary: return this.parseBinary(fixedSize);
|
|
3173
3206
|
case MemberType.Code:
|
|
3174
3207
|
case MemberType.Branch: return this.parseCode(reg);
|
|
@@ -3179,8 +3212,8 @@ var TypeParser = class {
|
|
|
3179
3212
|
const delimiter = parentType.delimiter;
|
|
3180
3213
|
const discOffset = parentType.discriminator;
|
|
3181
3214
|
const discLogic = parentType.discriminatorLogic;
|
|
3215
|
+
const discSize = parentType.discriminatorSize ?? 1;
|
|
3182
3216
|
const nullValue = parentType.null;
|
|
3183
|
-
const objects = [];
|
|
3184
3217
|
if (delimiter === void 0 && this._blockReader.delimiterReached(nullValue)) {
|
|
3185
3218
|
objects.push({
|
|
3186
3219
|
name: parentType.name,
|
|
@@ -3199,12 +3232,17 @@ var TypeParser = class {
|
|
|
3199
3232
|
else {
|
|
3200
3233
|
if (discOffset !== void 0) {
|
|
3201
3234
|
const discPosition = this._romDataReader.position + discOffset;
|
|
3202
|
-
const
|
|
3203
|
-
|
|
3204
|
-
|
|
3235
|
+
const disc = this._romDataReader.romData[discPosition];
|
|
3236
|
+
const disc16 = this._romDataReader.romData[discPosition + 1] << 8 | disc;
|
|
3237
|
+
const matchedStruct = Object.values(this._blockReader._root.structs).find((x) => x.parent === fixedTypeName && (discLogic === "&" ? ((x.discriminator ?? 0) & disc) !== 0 : (x.discriminator ?? 0) >= 256 ? x.discriminator === disc16 : x.discriminator === disc));
|
|
3238
|
+
targetType = matchedStruct || parentType;
|
|
3239
|
+
if (discOffset === 0 && parentType != targetType && discLogic === "=") {
|
|
3240
|
+
this._romDataReader.position++;
|
|
3241
|
+
if (discSize > 1 || (matchedStruct?.discriminator ?? 0) >= 256) this._romDataReader.position++;
|
|
3242
|
+
}
|
|
3205
3243
|
}
|
|
3206
3244
|
const types = targetType.types;
|
|
3207
|
-
if (types
|
|
3245
|
+
if (types) {
|
|
3208
3246
|
const memberCount = types.length;
|
|
3209
3247
|
const prevPosition = this._romDataReader.position;
|
|
3210
3248
|
const parts = new Array(memberCount);
|
|
@@ -3213,7 +3251,10 @@ var TypeParser = class {
|
|
|
3213
3251
|
parts
|
|
3214
3252
|
};
|
|
3215
3253
|
for (let i = 0; i < memberCount; i++) parts[i] = this.parseType(types[i], reg, depth + 1, bank);
|
|
3216
|
-
if (discOffset !== void 0 && discOffset === this._romDataReader.position - prevPosition)
|
|
3254
|
+
if (discOffset !== void 0 && discOffset === this._romDataReader.position - prevPosition && types?.length > 0) {
|
|
3255
|
+
this._romDataReader.position++;
|
|
3256
|
+
if (discSize > 1) this._romDataReader.position++;
|
|
3257
|
+
}
|
|
3217
3258
|
objects.push(def);
|
|
3218
3259
|
} else this._romDataReader.position++;
|
|
3219
3260
|
}
|
|
@@ -3227,9 +3268,11 @@ var TypeParser = class {
|
|
|
3227
3268
|
}
|
|
3228
3269
|
if (!this._blockReader.partCanContinue()) break;
|
|
3229
3270
|
if (nullValue !== void 0) break;
|
|
3271
|
+
if (single) break;
|
|
3230
3272
|
}
|
|
3231
3273
|
if (delReached && depth === 0) this._referenceManager.tryAddStruct(this._romDataReader.position, typeName);
|
|
3232
|
-
return objects;
|
|
3274
|
+
if (single) return objects[0];
|
|
3275
|
+
else return objects;
|
|
3233
3276
|
}
|
|
3234
3277
|
tryParseMemberType(memberTypeName) {
|
|
3235
3278
|
const upperName = memberTypeName.toUpperCase();
|
|
@@ -3250,22 +3293,41 @@ var TypeParser = class {
|
|
|
3250
3293
|
for (let i = 0; i < len; i++) outBuffer[i] = this._romDataReader.romData[startPosition + i];
|
|
3251
3294
|
return outBuffer;
|
|
3252
3295
|
}
|
|
3253
|
-
parseLocation(offset, bank, typeName, addrType) {
|
|
3254
|
-
if ((bank === void 0 || bank === null) && offset === 0) return new Word(offset);
|
|
3255
|
-
|
|
3296
|
+
parseLocation(offset, bank, typeName, addrType, isSoft = false) {
|
|
3297
|
+
if ((bank === void 0 || bank === null) && (offset === 0 || offset === 65535)) return new Word(offset);
|
|
3298
|
+
const hasOffset = this._romDataReader.offset !== void 0;
|
|
3299
|
+
if (hasOffset) offset -= this._romDataReader.offset;
|
|
3256
3300
|
let adrs;
|
|
3257
3301
|
let loc;
|
|
3258
|
-
if (addrType === AddressType.Location ||
|
|
3259
|
-
|
|
3302
|
+
if (addrType === AddressType.Location || hasOffset) {
|
|
3303
|
+
loc = offset | bank << 16;
|
|
3304
|
+
if (hasOffset && !this._blockReader._currentChunk.isFile) loc += this._blockReader._currentChunk.location;
|
|
3305
|
+
} else {
|
|
3306
|
+
if (addrType === AddressType.OddLocation) {
|
|
3307
|
+
const bankFlag = this._blockReader._root.config.cpuMode === CpuMode.Fast ? 128 : 0;
|
|
3308
|
+
const bankReal = this._romDataReader.position >> 16;
|
|
3309
|
+
const isVeryOdd = !this._blockReader._root.config.oddLocationBase || bankReal < this._blockReader._root.config.oddLocationBase;
|
|
3310
|
+
const bankBase = (isVeryOdd ? 64 : 0) + bankReal | bankFlag;
|
|
3311
|
+
const bankMax = this._romDataReader.romData.length >> 16 | bankFlag;
|
|
3312
|
+
const bankSpan = isVeryOdd ? 0 : (64 | bankFlag) - bankMax;
|
|
3313
|
+
const hiOffset = offset >> 8 & 127;
|
|
3314
|
+
const hiAdjust = (hiOffset ^ (offset >> 8 | bank << 8)) << 1 | 128 | hiOffset;
|
|
3315
|
+
const hiBank = (hiAdjust >> 8) + bankBase;
|
|
3316
|
+
offset = (hiAdjust & 255) << 8 | offset & 255;
|
|
3317
|
+
bank = hiBank;
|
|
3318
|
+
if (hiBank >= bankMax) {
|
|
3319
|
+
bank += bankSpan;
|
|
3320
|
+
offset &= 32767;
|
|
3321
|
+
}
|
|
3322
|
+
}
|
|
3260
3323
|
adrs = new Address(bank ?? Address.resolveBank(this._romDataReader.position, this._blockReader._root.config.memoryMode), offset, this._blockReader._root.config.memoryMode);
|
|
3261
3324
|
if (!adrs.isROM) return adrs;
|
|
3262
3325
|
loc = adrs.toLocation();
|
|
3263
3326
|
}
|
|
3264
|
-
if (typeName && (
|
|
3265
|
-
|
|
3266
|
-
if (!oldStruct || oldStruct === "Branch") this._referenceManager.structTable.set(loc, typeName);
|
|
3327
|
+
if (typeName && (hasOffset || !this._blockReader._root.rewrites[loc])) {
|
|
3328
|
+
this._referenceManager.tryAddStruct(loc, isSoft ? "~" + typeName : typeName);
|
|
3267
3329
|
const referenceName = `${typeName.toLowerCase()}_${loc.toString(16).toUpperCase().padStart(6, "0")}`;
|
|
3268
|
-
this._referenceManager.tryAddName(loc, referenceName);
|
|
3330
|
+
this._referenceManager.tryAddName(loc, isSoft ? "~" + referenceName : referenceName);
|
|
3269
3331
|
}
|
|
3270
3332
|
return new LocationWrapper(loc, addrType);
|
|
3271
3333
|
}
|
|
@@ -3275,8 +3337,8 @@ var TypeParser = class {
|
|
|
3275
3337
|
while (this._romDataReader.position < this._blockReader._partEnd) {
|
|
3276
3338
|
if (first) first = false;
|
|
3277
3339
|
else {
|
|
3278
|
-
const struct = this._referenceManager.
|
|
3279
|
-
if (struct && struct !== "Branch") break;
|
|
3340
|
+
const struct = this._referenceManager.tryGetStruct(this._romDataReader.position);
|
|
3341
|
+
if (struct.found && struct.chunkType !== "Branch") break;
|
|
3280
3342
|
}
|
|
3281
3343
|
if (reg) this._blockReader.hydrateRegisters(reg);
|
|
3282
3344
|
const op = this._blockReader._asmReader.parseAsm(reg);
|
|
@@ -3516,13 +3578,13 @@ var BlockReader = class {
|
|
|
3516
3578
|
* Notes a type at a location and manages chunk references
|
|
3517
3579
|
*/
|
|
3518
3580
|
noteType(loc, type, silent = false, reg) {
|
|
3519
|
-
const
|
|
3520
|
-
|
|
3581
|
+
const isSoft = type[0] === "~";
|
|
3582
|
+
this._referenceManager.tryAddStruct(loc, type);
|
|
3521
3583
|
const nameResult = this._referenceManager.tryGetName(loc);
|
|
3522
3584
|
let name;
|
|
3523
3585
|
if (!nameResult.found) {
|
|
3524
3586
|
name = this._referenceManager.createTypeName(type, loc);
|
|
3525
|
-
this._referenceManager.tryAddName(loc, name);
|
|
3587
|
+
this._referenceManager.tryAddName(loc, isSoft ? "~" + name : name);
|
|
3526
3588
|
} else name = nameResult.referenceName;
|
|
3527
3589
|
if (!silent && type === BlockReaderConstants.CODE_TYPE && reg) this.updateRegisterState(loc, reg);
|
|
3528
3590
|
return name;
|
|
@@ -3624,7 +3686,7 @@ var BlockReader = class {
|
|
|
3624
3686
|
*/
|
|
3625
3687
|
processNewEntry(current, reg, bank, last) {
|
|
3626
3688
|
let res = this._typeParser.parseType(current, reg, 0, bank);
|
|
3627
|
-
if (BlockReaderConstants.POINTER_CHARACTERS.includes(current[0]) && !Array.isArray(res)) res = [res];
|
|
3689
|
+
if (current.indexOf("[") !== -1 || BlockReaderConstants.POINTER_CHARACTERS.includes(current[0]) && !Array.isArray(res)) res = [res];
|
|
3628
3690
|
last.object = res;
|
|
3629
3691
|
}
|
|
3630
3692
|
/**
|
|
@@ -3713,6 +3775,7 @@ var BlockReader = class {
|
|
|
3713
3775
|
if (!chunkFile.type.isBlock) continue;
|
|
3714
3776
|
chunkFile.referenceManager = this._referenceManager;
|
|
3715
3777
|
this._currentChunk = chunkFile;
|
|
3778
|
+
this._romDataReader.offset = chunkFile.base;
|
|
3716
3779
|
for (const asmBlock of chunkFile.parts || []) {
|
|
3717
3780
|
this._currentAsmBlock = asmBlock;
|
|
3718
3781
|
this.processPart(asmBlock);
|
|
@@ -3728,7 +3791,7 @@ var BlockReader = class {
|
|
|
3728
3791
|
chunkFile.parts = [asmBlock];
|
|
3729
3792
|
this._currentAsmBlock = asmBlock;
|
|
3730
3793
|
this._referenceManager = chunkFile.referenceManager = new ReferenceManager(this._root);
|
|
3731
|
-
this._romDataReader = new RomDataReader(chunkFile.rawData, chunkFile.base
|
|
3794
|
+
this._romDataReader = new RomDataReader(chunkFile.rawData, chunkFile.base);
|
|
3732
3795
|
this._typeParser = new TypeParser(this);
|
|
3733
3796
|
this.processPart(asmBlock);
|
|
3734
3797
|
}
|
|
@@ -4597,7 +4660,7 @@ var RomWriter = class RomWriter {
|
|
|
4597
4660
|
}
|
|
4598
4661
|
} else if (file.parts && file.parts.length > 0) {
|
|
4599
4662
|
if (file.parts[0].location !== file.location && (file.location || 0) !== 0) throw new Error("Assembly was not based properly");
|
|
4600
|
-
RomWriter.parseAssembly(this.root, file.parts, fileLookup, file.includeLookup, this.outBuffer,
|
|
4663
|
+
RomWriter.parseAssembly(this.root, file.parts, fileLookup, file.includeLookup, this.outBuffer, file.base);
|
|
4601
4664
|
}
|
|
4602
4665
|
return pos - start;
|
|
4603
4666
|
}
|
|
@@ -4612,6 +4675,7 @@ var RomWriter = class RomWriter {
|
|
|
4612
4675
|
static parseAssembly(root, blocks, fileLookup, includeLookup, outBuffer, addrOffset) {
|
|
4613
4676
|
if (!blocks) throw new Error("Assembly has not been parsed");
|
|
4614
4677
|
let bix = 0;
|
|
4678
|
+
const rootLoc = blocks[0].location;
|
|
4615
4679
|
for (const block of blocks) {
|
|
4616
4680
|
let position = block.location;
|
|
4617
4681
|
const objList = block.objList;
|
|
@@ -4699,8 +4763,10 @@ var RomWriter = class RomWriter {
|
|
|
4699
4763
|
break;
|
|
4700
4764
|
} else markerOffset += RomProcessingConstants.getSize(part);
|
|
4701
4765
|
}
|
|
4702
|
-
if (addrOffset !== void 0)
|
|
4703
|
-
|
|
4766
|
+
if (addrOffset !== void 0) {
|
|
4767
|
+
loc += addrOffset;
|
|
4768
|
+
if (fileLookup?.size) loc -= rootLoc;
|
|
4769
|
+
} else if (!isRelative && type !== AddressType.Location) loc = Address.fromLocation(loc, root.config.memoryMode, root.config.cpuMode).toInt();
|
|
4704
4770
|
switch (type) {
|
|
4705
4771
|
case AddressType.Offset:
|
|
4706
4772
|
case AddressType.WRelative:
|
|
@@ -4815,7 +4881,7 @@ var RomProcessor = class RomProcessor {
|
|
|
4815
4881
|
for (const b of file.parts) if (b.label) file.includeLookup.set(b.label.toUpperCase(), b);
|
|
4816
4882
|
file.rawData = void 0;
|
|
4817
4883
|
file.rawData = new Uint8Array(ChunkFileUtils.calculateSize(file));
|
|
4818
|
-
RomWriter.parseAssembly(this.writer.root, file.parts, dummyMap, file.includeLookup, file.rawData, file.type.base
|
|
4884
|
+
RomWriter.parseAssembly(this.writer.root, file.parts, dummyMap, file.includeLookup, file.rawData, file.type.base);
|
|
4819
4885
|
}
|
|
4820
4886
|
}
|
|
4821
4887
|
for (const file of allFiles) if (file.compressed === true && canCompress) if (this.writer.root.config.uncompress) file.compressed = false;
|
|
@@ -5566,6 +5632,7 @@ var DbBlock = class {
|
|
|
5566
5632
|
transforms;
|
|
5567
5633
|
postProcess;
|
|
5568
5634
|
order;
|
|
5635
|
+
base;
|
|
5569
5636
|
constructor(data) {
|
|
5570
5637
|
this.name = data.name ?? "";
|
|
5571
5638
|
this.movable = data.movable ?? false;
|
|
@@ -5577,6 +5644,7 @@ var DbBlock = class {
|
|
|
5577
5644
|
this.transforms = data.transforms ?? [];
|
|
5578
5645
|
this.postProcess = data.postProcess ?? void 0;
|
|
5579
5646
|
this.order = data.order ?? void 0;
|
|
5647
|
+
this.base = data.base ?? void 0;
|
|
5580
5648
|
if (!this.name) throw new Error("Name is required");
|
|
5581
5649
|
}
|
|
5582
5650
|
};
|
|
@@ -5648,6 +5716,7 @@ var DbStruct = class {
|
|
|
5648
5716
|
delimiter;
|
|
5649
5717
|
discriminator;
|
|
5650
5718
|
discriminatorLogic;
|
|
5719
|
+
discriminatorSize;
|
|
5651
5720
|
null;
|
|
5652
5721
|
constructor(data) {
|
|
5653
5722
|
this.name = data.name ?? "";
|
|
@@ -5656,6 +5725,7 @@ var DbStruct = class {
|
|
|
5656
5725
|
this.delimiter = data.delimiter ?? void 0;
|
|
5657
5726
|
this.discriminator = data.discriminator ?? void 0;
|
|
5658
5727
|
this.discriminatorLogic = data.discriminatorLogic ?? (this.discriminator !== void 0 ? "=" : void 0);
|
|
5728
|
+
this.discriminatorSize = data.discriminatorSize ?? void 0;
|
|
5659
5729
|
this.null = data.null ?? void 0;
|
|
5660
5730
|
if (!this.name) throw new Error("Name is required");
|
|
5661
5731
|
}
|