From cfdac09529f5bbaae0320c864432c7c50c9ea034 Mon Sep 17 00:00:00 2001 From: Evan Barger Date: Thu, 8 Apr 2021 22:03:15 -0400 Subject: [PATCH] Add timestamps, writer id, placeholder cart id, more accurate slot wiping/filler data --- script/gbnp.js | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/script/gbnp.js b/script/gbnp.js index 504cd2a..42f177c 100644 --- a/script/gbnp.js +++ b/script/gbnp.js @@ -61,8 +61,8 @@ class ROM { this.menuText = this.title; file.seek(0x143); - let cgbByte = file.readByte(); - this.cgb = cgbByte == 0x80 || cgbByte == 0xC0; + this.cgbByte = file.readByte(); + this.cgb = this.cgbByte == 0x80 || this.cgbByte == 0xC0; file.seek(0x147); this.typeByte = file.readByte(); @@ -355,13 +355,19 @@ class Processor { romFile.writeBytes(Array.from(this.tickerBitmap)); } + // timestamp / writer id + const date = (new Date).toISOString().split('.')[0].replace('T', '').replace(/-/g, '/'); + const timestampId = `${date} ORANGE `; // should be 26 bytes + romFile.seek(0x1C1BF); + romFile.writeBytes(stringToCharArray(timestampId)); + let romBase = 0x01; let romFileIndex = 0x1C200; - // disable existing entries + // wipe existing entries for (let i = 0; i < 7; i++) { romFile.seek(romFileIndex + i * 512); - romFile.writeByte(0xFF); + romFile.writeByteUntil(0xFF, romFileIndex + (i+1) * 512); } @@ -371,6 +377,8 @@ class Processor { for (let i = 0; i < this.roms.length; i++) { const rom = this.roms[i]; romFile.seek(romFileIndex); + romFile.writeByteUntil(0, romFileIndex + 512); + romFile.seek(romFileIndex); // rom index romFile.writeByte(i + 1); @@ -390,11 +398,28 @@ class Processor { romFile.writeByte(rom.paddedRamSizeKB() > 0 ? 1 : 0); // true if 8 used romFile.writeByte(rom.paddedRamSizeKB() > 8 ? 1 : 0); // true if 32 used - romFile.seek(romFileIndex + 63); + // game identifier "DMG -TRA - " + romFile.writeBytes( + stringToCharArray(`${rom.cgbByte == 0xC0 ? 'CGB' : 'DMG'} -??? - `) + ); // 12 characters + + // Shift-JIS title (override with ascii) + romFile.seek(romFileIndex + 19); + romFile.writeByteUntil(0, 0x1C23F) // override with zeros + romFile.seek(romFileIndex + 20); // leave first byte emtpy to identify as ascii text + romFile.writeBytes(stringToCharArray(rom.title)); // title bitmap + romFile.seek(romFileIndex + 63); // 0x1C23F romFile.writeBytes(rom.bitmapBuffer); + // timestamp / writer id + romFile.seek(romFileIndex + 0x1BF); //0x1C3BF + romFile.writeBytes(stringToCharArray(timestampId)); + + // final padding + romFile.writeByteUntil(0xFF, romFileIndex + 512); + romFileIndex += 512 // apply iG power cart hack @@ -664,6 +689,10 @@ class FileSeeker { } } +const stringToCharArray = (str) => { + return str.split('').map(c => c.charCodeAt(0)); +} + const FULL_WIDTH_PUNC = { '!': '!', '?': '?', '&': '&', '(': '(', ')': ')', '~': '~', };