diff --git a/index.html b/index.html
index 5c80c99..488280d 100644
--- a/index.html
+++ b/index.html
@@ -20,7 +20,6 @@
Data: {{ processor.mapData() }}
-
@@ -36,7 +35,7 @@
diff --git a/script/app.js b/script/app.js
index 732d18d..d628593 100644
--- a/script/app.js
+++ b/script/app.js
@@ -2,20 +2,19 @@ let app = new Vue({
el: '#app',
data: {
roms: [],
- processor: new Processor([])
+ processor: new Processor([]),
+ mapData: ''
},
methods: {
addFile: async function(e) {
- this.roms.push(
- new ROM(
- await e.target.files[0].arrayBuffer()
- )
- );
-
- console.log(this.roms)
+ this.roms.push(new ROM(await e.target.files[0].arrayBuffer()));
this.processor.roms = this.roms;
e.target.value = '';
+ },
+ downloadMapFile: function(e) {
+ if (this.mapData) { URL.revokeObjectURL(this.mapData) }
+ this.mapData = URL.createObjectURL(new Blob([this.processor.mapData()]));
}
}
});
diff --git a/script/gbnp.js b/script/gbnp.js
index 4b59f86..aa607d4 100644
--- a/script/gbnp.js
+++ b/script/gbnp.js
@@ -5,9 +5,8 @@ const CARTRIDGE_TYPES = [
'ROM+RAM', 'ROM+RAM+BATTERY', null, null, null, null, null,
'MBC3+TIMER+BATTERY', 'MBC3+TIMER+RAM+BATTERY', 'MBC3', 'MBC3+RAM', 'MBC3+RAM+BATTERY', null, null, null, null, null,
'MBC5', 'MBC5+RAM', 'MBC5+RAM+BATTERY', 'MBC5+RUMBLE', 'MBC5+RUMBLE+RAM', 'MBC5+RUMBLE+RAM+BATTERY'
-]
-
-const FINAL_BYTES = [0x02, 0x00, 0x30, 0x12, 0x99, 0x11, 0x12, 0x20, 0x37, 0x57, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00]
+];
+const MAP_TRAILER_BYTES = [0x02, 0x00, 0x30, 0x12, 0x99, 0x11, 0x12, 0x20, 0x37, 0x57, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00];
class ROM {
constructor(arrayBuffer) {
@@ -68,10 +67,10 @@ class Processor {
mapData() {
const mapBuffer = new ArrayBuffer(128);
- let map = new FileSeeker(mapBuffer);
+ const mapFile = new FileSeeker(mapBuffer);
// write mbc type, rom size, and ram size for menu
- map.writeBytes([0xA8, 0, 0]);
+ mapFile.writeBytes([0xA8, 0, 0]);
// write mbc type, rom size, and ram size for each rom
let romOffset = 128;
@@ -82,14 +81,14 @@ class Processor {
let bits = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] // 16
// set mbc bits
- let tb = rom.type_byte
- if (tb >= 0x01 || tb <= 0x30) {
+ let tb = rom.typeByte
+ if (tb >= 0x01 && tb <= 0x03) {
bits[15] = 0; bits[14] = 0; bits[13] = 1;
- } else if (tb >= 0x05 || tb <= 0x06) {
+ } else if (tb >= 0x05 && tb <= 0x06) {
bits[15] = 0; bits[14] = 1; bits[13] = 0;
- } else if (tb >= 0xF || tb <= 0x13 ) {
+ } else if (tb >= 0x0F && tb <= 0x13 ) {
bits[15] = 0; bits[14] = 1; bits[13] = 1;
- } else if (tb >= 0x19 || tb <= 0x1E ) {
+ } else if (tb >= 0x19 && tb <= 0x1E ) {
bits[15] = 1; bits[14] = 0; bits[13] = 0;
}
@@ -122,23 +121,27 @@ class Processor {
// rom offset and cart info bits
bits.reverse();
- let bytes = [parseInt(bits.slice(0, 8), 2), parseInt(bits.slice(8, 16), 2)]
+ let bytes = [parseInt(bits.slice(0, 8).join(''), 2), parseInt(bits.slice(8, 16).join(''), 2)]
bytes[1] = bytes[1] | Math.trunc(romOffset / 32);
- console.log(bytes)
- map.writeBytes(bytes)
+ mapFile.writeBytes(bytes)
romOffset += rom.paddedRomSizeKB();
// ram offset
- map.writeByte(Math.trunc(ramOffset / 2));
+ mapFile.writeByte(Math.trunc(ramOffset / 2));
ramOffset += (rom.typeByte == 0x06 || rom.ramSizeKB() < 8) ? 8 : rom.ramSizeKB();
}
// trailer
- map.writeByteUntil(0xFF, 127 - FINAL_BYTES.length);
- map.writeBytes(FINAL_BYTES);
+ mapFile.writeByteUntil(0xFF, 128 - FINAL_BYTES.length);
+ mapFile.writeBytes(FINAL_BYTES);
return new Uint8Array(mapBuffer);
}
+
+ romData() {
+ const romBuffer = new ArrayBuffer(math.pow(1024, 2));
+ const romFile = new FileSeeker(romBuffer);
+ }
}
class FileSeeker {
@@ -170,14 +173,13 @@ class FileSeeker {
}
writeByte(byte) {
- console.log(byte)
this.view.setUint8(this.position, byte);
this.position++;
}
writeBytes(bytes) {
- for (const byte in bytes) {
- this.writeByte(byte);
+ for (let i = 0; i < bytes.length; i++) {
+ this.writeByte(bytes[i]);
}
}