Skip to content

Commit

Permalink
Handle non-8 and non-16K ROMs
Browse files Browse the repository at this point in the history
Fixes #455
  • Loading branch information
mattgodbolt committed Nov 11, 2024
1 parent 4e5f366 commit d8c07d8
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions 6502.js
Original file line number Diff line number Diff line change
Expand Up @@ -1071,34 +1071,24 @@ export class Cpu6502 extends Base6502 {
if (/\.zip/i.test(name)) {
data = utils.unzipRomImage(data).data;
}
const len = data.length;
if (len !== 16384 && len !== 8192) {
throw new Error("Broken rom file");
}
for (let i = 0; i < len; ++i) {
ramRomOs[offset + i] = data[i];
}
ramRomOs.set(data, offset);
}

async loadOs(os) {
const extraRoms = Array.prototype.slice.call(arguments, 1).concat(this.config.extraRoms);
os = "roms/" + os;
console.log("Loading OS from " + os);
console.log(`Loading OS from ${os}`);
const ramRomOs = this.ramRomOs;
const data = await utils.loadData(os);
const len = data.length;
if (len < 16384 || len & 16383) throw new Error("Broken ROM file (length=" + len + ")");
for (let i = 0; i < 16384; ++i) {
ramRomOs[this.osOffset + i] = data[i];
}
if (len < 16384 || len & 16383) throw new Error(`Broken OS ROM file (length=${len})`);
ramRomOs.set(data, this.osOffset);
const numExtraBanks = (len - 16384) / 16384;
let romIndex = 16 - numExtraBanks;
for (let i_1 = 0; i_1 < numExtraBanks; ++i_1) {
const srcBase = 16384 + 16384 * i_1;
const destBase = this.romOffset + (romIndex + i_1) * 16384;
for (let j = 0; j < 16384; ++j) {
ramRomOs[destBase + j] = data[srcBase + j];
}
ramRomOs.set(data.subarray(srcBase, srcBase + 16384), destBase);
}
const awaiting = [];
for (let i_2 = 0; i_2 < extraRoms.length; ++i_2) {
Expand Down

0 comments on commit d8c07d8

Please sign in to comment.