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