From 19acdc79da1267839fc6f115463f39117fe41d49 Mon Sep 17 00:00:00 2001 From: edo999 Date: Sat, 25 May 2024 11:42:01 +0100 Subject: [PATCH] =?UTF-8?q?Move=20tileset=20and=20palette=20out=20of=20nam?= =?UTF-8?q?etable=20object=20=F0=9F=9A=AA.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/RoomGfx.js | 9 +- src/containers/GfxCanvasContainer.js | 2 +- src/containers/RoomsContainer.js | 15 +- src/containers/ScreenCanvasContainer.js | 8 +- src/containers/TitlesContainer.js | 16 +- src/lib/parser/parsePalette.js | 24 ++ src/lib/parser/parseRooms.js | 26 +- src/lib/parser/parseTitles.js | 36 +-- src/lib/parser/room/parseRoomNametable.js | 34 +-- .../serialiser/room/serialiseRoomNametable.js | 13 +- src/lib/serialiser/serialisePalette.js | 13 + test/parsePalette.test.js | 52 ++++ test/parseRoomNametable.test.js | 155 ++++++------ test/serialisePalette.test.js | 37 +++ test/serialiseRoomNametable.test.js | 224 +++++++++--------- 15 files changed, 387 insertions(+), 277 deletions(-) create mode 100644 src/lib/parser/parsePalette.js create mode 100644 src/lib/serialiser/serialisePalette.js create mode 100644 test/parsePalette.test.js create mode 100644 test/serialisePalette.test.js diff --git a/src/components/RoomGfx.js b/src/components/RoomGfx.js index 99bf4f3..1d002f9 100644 --- a/src/components/RoomGfx.js +++ b/src/components/RoomGfx.js @@ -3,6 +3,7 @@ import GfxCanvasContainer from '../containers/GfxCanvasContainer'; const RoomGfx = ({ baseTiles, + tileset, nametable, objectImages, roomgfc, @@ -27,12 +28,8 @@ const RoomGfx = ({ ) : null} - Tileset {nametable.tileset} ({roomgfc.gfx.length / 8 / 2} tiles) + to={type === 'room' ? `/roomgfx/${tileset}` : `/titlegfx/${tileset}`}> + Tileset {tileset} ({roomgfc.gfx.length / 8 / 2} tiles) objectImages.tiles) .filter(Boolean) diff --git a/src/containers/RoomsContainer.js b/src/containers/RoomsContainer.js index d030a49..eb8e442 100644 --- a/src/containers/RoomsContainer.js +++ b/src/containers/RoomsContainer.js @@ -24,9 +24,7 @@ const RoomsContainer = ({ rooms, titles, roomgfx, globdata }) => { const currentId = typeof id === 'undefined' ? null : parseInt(id, 10); const baseTiles = roomgfx?.find(({ metadata }) => metadata.id === 0); - let roomgfc = roomgfx?.find( - ({ metadata }) => metadata.id === room?.nametable?.tileset, - ); + let roomgfc = roomgfx?.find(({ metadata }) => metadata.id === room?.tileset); useEffect(() => { const room = @@ -56,16 +54,16 @@ const RoomsContainer = ({ rooms, titles, roomgfx, globdata }) => { }; const updatePalette = (i, colourId) => { - const newRoom = structuredClone(room); + const newScreen = structuredClone(room); if (i % 4 === 0) { // Keep the first colours in sync. for (let i = 0; i < 16; i += 4) { - newRoom.nametable.palette[i] = colourId; + newScreen.palette[i] = colourId; } } else { - newRoom.nametable.palette[i] = colourId; + newScreen.palette[i] = colourId; } - setRoom(newRoom); + setRoom(newScreen); }; if (room && !room.header) { @@ -125,13 +123,14 @@ const RoomsContainer = ({ rooms, titles, roomgfx, globdata }) => { /> {currentTab === 'Palettes' && ( )} {currentTab === 'Tilesets' && ( { const { width, height } = room.header; - const { palette } = room.nametable; + const { palette } = room; const baseTilesNum = baseTiles?.gfx?.length / 8 / 2; - const nametableObj = structuredClone(room.nametable.nametableObj); + const nametable = structuredClone(room.nametable); const attributes = structuredClone(room.attributes); // Overwrite tiles and palette with selected object. @@ -78,7 +78,7 @@ const draw = ( for (let j = 0; j < objectImage.tiles.length; j++) { for (let i = 0; i < objectImage.tiles[j].length; i++) { - nametableObj[y + j][x + i + 2] = objectImage.tiles[j][i]; + nametable[y + j][x + i + 2] = objectImage.tiles[j][i]; } } @@ -121,7 +121,7 @@ const draw = ( // Now generate the image of the room. for (let sprY = 0; sprY < height; sprY++) { for (let sprX = 0; sprX < 62; sprX++) { - let tile = nametableObj[sprY][sprX]; + let tile = nametable[sprY][sprX]; let gfx = baseTiles?.gfx; if (tile >= baseTilesNum) { diff --git a/src/containers/TitlesContainer.js b/src/containers/TitlesContainer.js index e802589..2bb679d 100644 --- a/src/containers/TitlesContainer.js +++ b/src/containers/TitlesContainer.js @@ -28,26 +28,21 @@ const TitlesContainer = ({ rooms, titles }) => { width: title.width, height: title.height, }; - title.nametable = { - tileset: id, - palette: title.palette, - nametableObj: title.nametableObj, - }; setTitle(title); }, [id, titles]); const updatePalette = (i, colourId) => { - const newRoom = structuredClone(title); + const newScreen = structuredClone(title); if (i % 4 === 0) { // Keep the first colours in sync. for (let i = 0; i < 16; i += 4) { - newRoom.nametable.palette[i] = colourId; + newScreen.palette[i] = colourId; } } else { - newRoom.nametable.palette[i] = colourId; + newScreen.palette[i] = colourId; } - setTitle(newRoom); + setTitle(newScreen); }; if (!title) { @@ -87,13 +82,14 @@ const TitlesContainer = ({ rooms, titles }) => { /> {currentTab === 'Palettes' && ( )} {currentTab === 'Tilesets' && ( { + const parser = new Parser(arrayBuffer); + + const palette = Array(16); + for (let i = 0; i < 16; i++) { + palette[i] = parser.getUint8(); + } + + const paletteMap = { + type: 'palette', + from: offset, + to: offset + 16, + }; + + return { + palette, + paletteMap, + }; +}; + +export default parsePalette; diff --git a/src/lib/parser/parseRooms.js b/src/lib/parser/parseRooms.js index 333919f..2766d51 100644 --- a/src/lib/parser/parseRooms.js +++ b/src/lib/parser/parseRooms.js @@ -1,6 +1,7 @@ import Parser from './parser.js'; import parseRoomHeader from './room/parseRoomHeader.js'; import parseRoomNametable from './room/parseRoomNametable.js'; +import parsePalette from './parsePalette.js'; import parseRoomAttributes from './room/parseRoomAttributes.js'; import parseRoomBoxes from './room/parseRoomBoxes.js'; import parseRoomMatrix from './room/parseRoomMatrix.js'; @@ -61,10 +62,29 @@ const parseRooms = (arrayBuffer, i = 0, offset = 0, characters = {}) => { }); } + // Parse the tileset id. + const tilesetParser = new Parser( + arrayBuffer.slice(nametableOffs, nametableOffs + 1), + ); + const tileset = tilesetParser.getUint8(); + map.push({ + type: 'tileset', + from: nametableOffs, + to: nametableOffs, + }); + + // Parse the palette. + const { palette, paletteMap } = parsePalette( + arrayBuffer.slice(nametableOffs + 1, nametableOffs + 17), + nametableOffs + 1, + ); + + map.push(paletteMap); + // Parse gfx nametable. const { nametable, nametableMap } = parseRoomNametable( - arrayBuffer.slice(nametableOffs, attrOffs), - nametableOffs, + arrayBuffer.slice(nametableOffs + 17, attrOffs), + nametableOffs + 17, width, ); @@ -396,6 +416,8 @@ const parseRooms = (arrayBuffer, i = 0, offset = 0, characters = {}) => { boxes, matrixUnks, matrix, + tileset, + palette, nametable, attributes, masktable, diff --git a/src/lib/parser/parseTitles.js b/src/lib/parser/parseTitles.js index 5c2e400..7012f82 100644 --- a/src/lib/parser/parseTitles.js +++ b/src/lib/parser/parseTitles.js @@ -1,4 +1,5 @@ import Parser from './parser.js'; +import parsePalette from './parsePalette.js'; const assert = console.assert; @@ -10,6 +11,7 @@ const parseTitles = (arrayBuffer, i = 0, offset = 0) => { size: arrayBuffer.byteLength, // decompressedSize: 0, // Commented out until the buffer size is known. }; + const map = []; const unk1 = parser.getUint16(); // Probably the chunk length unused in titles. const unk2 = parser.getUint16(); @@ -51,26 +53,26 @@ const parseTitles = (arrayBuffer, i = 0, offset = 0) => { assert(width === 32, 'Title width is not 32.'); assert(height === 30, 'Title height is not 30.'); - const nametable = Array(width * height); + const nametableTmp = Array(width * height); n = 0; - while (n < nametable.length) { + while (n < nametableTmp.length) { const loop = parser.getUint8(); if (loop & 0x80) { for (let j = 0; j < (loop & 0x7f); j++) { - nametable[n++] = parser.getUint8(); + nametableTmp[n++] = parser.getUint8(); } } else { const data = parser.getUint8(); for (let j = 0; j < (loop & 0x7f); j++) { - nametable[n++] = data; + nametableTmp[n++] = data; } } } - // Slice the nametableObj so it is formatted like rooms'. - const nametableObj = new Array(height); + // Slice the nametable so it is formatted like rooms'. + const nametable = new Array(height); for (let i = 0; i < height; i++) { - nametableObj[i] = nametable.slice(i * width, (i + 1) * width); + nametable[i] = nametableTmp.slice(i * width, (i + 1) * width); } // Parse gfx attrtable. @@ -100,17 +102,22 @@ const parseTitles = (arrayBuffer, i = 0, offset = 0) => { } } - // Parse palette. const stepNum = parser.getUint8(); assert(stepNum === 3, 'stepNum is not 3.'); - const palette = []; - for (let i = 0; i < 16; i++) { - palette[i] = parser.getUint8(); - } + // Parse the palette. + const { palette, paletteMap } = parsePalette( + arrayBuffer.slice(parser.pointer, parser.pointer + 16), + parser.pointer, + ); - const endOfData = parser.getUint8(); + map.push(paletteMap); + + const endOfDataParser = new Parser( + arrayBuffer.slice(parser.pointer + 16, parser.pointer + 17), + ); + const endOfData = endOfDataParser.getUint8(); assert(endOfData === 0xff, 'endOfData is not 0xff.'); @@ -123,7 +130,7 @@ const parseTitles = (arrayBuffer, i = 0, offset = 0) => { gfx, width, height, - nametableObj, + nametable, attrWidth, attrHeight, attributes, @@ -136,6 +143,7 @@ const parseTitles = (arrayBuffer, i = 0, offset = 0) => { unk4, unk5, unk6, + map, }; }; diff --git a/src/lib/parser/room/parseRoomNametable.js b/src/lib/parser/room/parseRoomNametable.js index 44c7d6d..28b73c1 100644 --- a/src/lib/parser/room/parseRoomNametable.js +++ b/src/lib/parser/room/parseRoomNametable.js @@ -4,25 +4,19 @@ const assert = console.assert; const parseRoomNametable = (arrayBuffer, offset = 0, width = 0) => { const parser = new Parser(arrayBuffer); - const tileset = parser.getUint8(); - const palette = []; - for (let i = 0; i < 16; i++) { - palette[i] = parser.getUint8(); - } - - const nametableObj = Array(16); - for (let i = 0; i < nametableObj.length; i++) { - nametableObj[i] = Array(64).fill(0); - nametableObj[i][0] = 0; - nametableObj[i][1] = 0; + const nametable = Array(16); + for (let i = 0; i < nametable.length; i++) { + nametable[i] = Array(64).fill(0); + nametable[i][0] = 0; + nametable[i][1] = 0; assert( - nametableObj[i][0] === 0, + nametable[i][0] === 0, 'Gfx nametable strip does not start with 0x00 0x00.', ); assert( - nametableObj[i][1] === 0, + nametable[i][1] === 0, 'Gfx nametable strip does not start with 0x00 0x00.', ); @@ -31,22 +25,22 @@ const parseRoomNametable = (arrayBuffer, offset = 0, width = 0) => { const loop = parser.getUint8(); if (loop & 0x80) { for (let j = 0; j < (loop & 0x7f); j++) { - nametableObj[i][2 + n++] = parser.getUint8(); + nametable[i][2 + n++] = parser.getUint8(); } } else { const data = parser.getUint8(); for (let j = 0; j < (loop & 0x7f); j++) { - nametableObj[i][2 + n++] = data; + nametable[i][2 + n++] = data; } } } assert( - nametableObj[i][62] === 0, + nametable[i][62] === 0, 'Gfx nametable strip does not end with 0x00 0x00.', ); assert( - nametableObj[i][63] === 0, + nametable[i][63] === 0, 'Gfx nametable strip does not end with 0x00 0x00.', ); } @@ -58,11 +52,7 @@ const parseRoomNametable = (arrayBuffer, offset = 0, width = 0) => { }; return { - nametable: { - tileset, - palette, - nametableObj, - }, + nametable, nametableMap, }; }; diff --git a/src/lib/serialiser/room/serialiseRoomNametable.js b/src/lib/serialiser/room/serialiseRoomNametable.js index 5ad6169..ad974c7 100644 --- a/src/lib/serialiser/room/serialiseRoomNametable.js +++ b/src/lib/serialiser/room/serialiseRoomNametable.js @@ -1,18 +1,11 @@ import Serialiser from '../serialiser.js'; import { compress } from '../serialiserUtils.js'; -const serialiseRoomNametable = (nametable = {}) => { +const serialiseRoomNametable = (nametable = []) => { const serialiser = new Serialiser(); - const { tileset, palette, nametableObj } = nametable; - serialiser.setUint8(tileset); - - for (let i = 0; i < 16; i++) { - serialiser.setUint8(palette[i]); - } - - for (let i = 0; i < nametableObj.length; i++) { - compress(serialiser, nametableObj[i].slice(2, 62)); + for (let i = 0; i < nametable.length; i++) { + compress(serialiser, nametable[i].slice(2, 62)); } return serialiser.buffer; diff --git a/src/lib/serialiser/serialisePalette.js b/src/lib/serialiser/serialisePalette.js new file mode 100644 index 0000000..74c28e6 --- /dev/null +++ b/src/lib/serialiser/serialisePalette.js @@ -0,0 +1,13 @@ +import Serialiser from './serialiser.js'; + +const serialisePalette = (palette = []) => { + const serialiser = new Serialiser(); + + for (let i = 0; i < 16; i++) { + serialiser.setUint8(palette[i]); + } + + return serialiser.buffer; +}; + +export default serialisePalette; diff --git a/test/parsePalette.test.js b/test/parsePalette.test.js new file mode 100644 index 0000000..4bc8263 --- /dev/null +++ b/test/parsePalette.test.js @@ -0,0 +1,52 @@ +import { describe, it } from 'node:test'; +import assert from 'node:assert/strict'; +import parsePalette from '../src/lib/parser/parsePalette.js'; +import serialisePalette from '../src/lib/serialiser/serialisePalette.js'; + +const paletteEmptyBuffer = () => { + return new ArrayBuffer(16); +}; + +const paletteBuffer = () => { + const array = [ + 0x0d, 0x07, 0x27, 0x3c, 0x0d, 0x17, 0x2a, 0x3a, 0x0d, 0x0d, 0x2a, 0x28, + 0x0d, 0x0d, 0x37, 0x20, + ]; + const buffer = new ArrayBuffer(array.length); + const view = new DataView(buffer); + array.forEach((v, i) => view.setUint8(i, v)); + return buffer; +}; + +describe('parsePalette', () => { + it('should return an array.', () => { + const { palette } = parsePalette(paletteEmptyBuffer()); + + assert.ok(Array.isArray(palette)); + assert.equal(palette.length, 16); + assert.equal(palette[0], 0); + }); + + it('should return a map object.', () => { + const { paletteMap } = parsePalette(paletteEmptyBuffer()); + + assert.equal(typeof paletteMap, 'object'); + assert.equal(paletteMap.from, 0); + assert.equal(paletteMap.to, 16); + }); + + it('should return a map object with a start offset.', () => { + const { paletteMap } = parsePalette(paletteEmptyBuffer(), 0xabc); + + assert.equal(paletteMap.from, 0xabc); + assert.equal(paletteMap.to, 0xacc); + }); + + it('should be the inverse of serialisePalette.', () => { + const initialBuffer = paletteBuffer(); + const { palette } = parsePalette(initialBuffer); + const buffer = serialisePalette(palette); + + assert.deepEqual(initialBuffer, buffer); + }); +}); diff --git a/test/parseRoomNametable.test.js b/test/parseRoomNametable.test.js index 0f98bbb..770f71b 100644 --- a/test/parseRoomNametable.test.js +++ b/test/parseRoomNametable.test.js @@ -3,73 +3,69 @@ import assert from 'node:assert/strict'; import parseRoomNametable from '../src/lib/parser/room/parseRoomNametable.js'; import serialiseRoomNametable from '../src/lib/serialiser/room/serialiseRoomNametable.js'; -const roomNametableEmptyBuffer = (tileset) => { - const buffer = new ArrayBuffer(1 + 16); - const view = new DataView(buffer); - view.setUint8(0x00, tileset); // Set the value of tileset. - return buffer; +const roomNametableEmptyBuffer = () => { + return new ArrayBuffer(1); }; const roomNametableBuffer = () => { const array = [ - 0x01, 0x0d, 0x07, 0x27, 0x3c, 0x0d, 0x17, 0x2a, 0x3a, 0x0d, 0x0d, 0x2a, - 0x28, 0x0d, 0x0d, 0x37, 0x20, 0x87, 0x01, 0x01, 0x62, 0x01, 0x63, 0x01, - 0x64, 0x03, 0x65, 0x82, 0x63, 0x64, 0x04, 0x65, 0x82, 0x63, 0x64, 0x09, - 0x65, 0x81, 0x63, 0x05, 0x65, 0x82, 0x63, 0x64, 0x03, 0x65, 0x83, 0x01, - 0x63, 0x74, 0x05, 0x01, 0x81, 0x62, 0x05, 0x01, 0x84, 0x74, 0x01, 0x01, - 0x74, 0x04, 0x01, 0x93, 0x01, 0x62, 0x62, 0x01, 0x63, 0x01, 0x64, 0x66, - 0x67, 0x68, 0x63, 0x66, 0x67, 0x68, 0x65, 0x66, 0x63, 0x68, 0x69, 0x06, - 0x6a, 0x8f, 0x6b, 0x66, 0x63, 0x68, 0x65, 0x66, 0x67, 0x68, 0x63, 0x66, - 0x67, 0x68, 0x65, 0x01, 0x63, 0x0c, 0x01, 0x88, 0x62, 0x01, 0x01, 0x62, - 0x01, 0x01, 0x62, 0x74, 0x04, 0x01, 0xa4, 0x63, 0x01, 0x64, 0x6c, 0x01, - 0x6d, 0x63, 0x6c, 0x01, 0x6d, 0x65, 0x6c, 0x63, 0x6d, 0x6e, 0x36, 0x39, - 0x37, 0x36, 0x39, 0x37, 0x6f, 0x6c, 0x63, 0x6d, 0x65, 0x6c, 0x01, 0x6d, - 0x63, 0x6c, 0x01, 0x6d, 0x65, 0x01, 0x63, 0x03, 0x01, 0x87, 0x74, 0x01, - 0x01, 0x62, 0x01, 0x01, 0x74, 0x04, 0x01, 0x86, 0x74, 0x01, 0x01, 0x74, - 0x01, 0x01, 0x81, 0x62, 0x03, 0x01, 0xa5, 0x63, 0x01, 0x64, 0x70, 0x71, - 0x72, 0x63, 0x70, 0x71, 0x72, 0x65, 0x70, 0x63, 0x72, 0x6e, 0x3e, 0x73, - 0x40, 0x3b, 0x73, 0x3c, 0x6f, 0x70, 0x63, 0xb4, 0x65, 0x70, 0xb5, 0xb4, - 0x63, 0x70, 0xb5, 0xb4, 0x65, 0x01, 0x63, 0x62, 0x13, 0x01, 0xa8, 0x01, - 0x62, 0x01, 0x74, 0x63, 0x01, 0x64, 0x6c, 0x01, 0x6d, 0x63, 0x6c, 0x01, - 0x6d, 0x65, 0x6c, 0x63, 0x6d, 0x6e, 0x3b, 0x3d, 0x40, 0x3b, 0x3d, 0x40, - 0x6f, 0x6c, 0x63, 0x6d, 0x65, 0x6c, 0x01, 0x6d, 0x63, 0x6c, 0x01, 0x6d, - 0x65, 0x01, 0x63, 0x03, 0x01, 0x83, 0x62, 0x01, 0x74, 0x03, 0x01, 0x81, - 0x62, 0x04, 0x01, 0x83, 0x62, 0x01, 0x74, 0x03, 0x01, 0x04, 0x01, 0xa4, - 0x63, 0x01, 0x64, 0x75, 0x76, 0x77, 0x63, 0x75, 0x76, 0x77, 0x65, 0x75, - 0x63, 0x77, 0x6e, 0x3b, 0x3d, 0x40, 0x3b, 0x3d, 0x40, 0x78, 0x75, 0x63, - 0x77, 0x65, 0x75, 0x76, 0x77, 0x63, 0x75, 0x76, 0x77, 0x65, 0x01, 0x63, - 0x0b, 0x01, 0x81, 0x74, 0x08, 0x01, 0x87, 0x62, 0x01, 0x01, 0x79, 0x7a, - 0x7b, 0x7c, 0x03, 0x7d, 0x82, 0x7a, 0x7c, 0x04, 0x7d, 0x8c, 0x7a, 0x64, - 0x6e, 0x3b, 0x3d, 0x49, 0x49, 0x3d, 0x40, 0x6f, 0x65, 0x7a, 0x05, 0x7d, - 0x81, 0x7a, 0x04, 0x7d, 0x83, 0x7b, 0x7a, 0xb6, 0x03, 0x01, 0x82, 0x74, - 0x62, 0x03, 0x01, 0x81, 0x62, 0x08, 0x01, 0x82, 0x62, 0x01, 0xab, 0x01, - 0x74, 0x01, 0x7e, 0x63, 0x01, 0x7f, 0x64, 0x7f, 0x64, 0x7f, 0x64, 0x7f, - 0x64, 0x7f, 0x64, 0x7f, 0x64, 0x6e, 0x3b, 0x3d, 0x40, 0x3b, 0x3d, 0x40, - 0x6f, 0x65, 0x7f, 0x64, 0x7f, 0x64, 0x7f, 0x64, 0x7f, 0x64, 0x7f, 0x64, - 0x7f, 0x01, 0x63, 0x7e, 0x01, 0x74, 0x03, 0x01, 0x84, 0x74, 0x01, 0xb7, - 0x62, 0x0a, 0xb7, 0x03, 0x01, 0xb4, 0x80, 0x63, 0x01, 0x81, 0x64, 0x81, - 0x64, 0x81, 0x64, 0x81, 0x64, 0x81, 0x64, 0x81, 0x64, 0x6e, 0x3e, 0x3d, - 0x40, 0x3b, 0x3d, 0x3c, 0x6f, 0x65, 0x81, 0x64, 0x81, 0x64, 0x81, 0x64, - 0x81, 0x64, 0x81, 0x64, 0x81, 0x01, 0x63, 0x80, 0x01, 0x62, 0x01, 0x01, - 0x62, 0x01, 0x01, 0xb8, 0xb9, 0xb8, 0xb8, 0xba, 0xb8, 0xb8, 0x05, 0xba, - 0xb7, 0x62, 0x01, 0x01, 0x82, 0x82, 0x83, 0x82, 0x84, 0x82, 0x84, 0x82, - 0x84, 0x82, 0x84, 0x82, 0x84, 0x82, 0x64, 0x6e, 0x41, 0x43, 0x44, 0x41, - 0x43, 0x44, 0x6f, 0x65, 0x82, 0x84, 0xbb, 0x84, 0xbb, 0x84, 0xbb, 0x84, - 0xbb, 0x84, 0xbb, 0x83, 0xbb, 0xbb, 0x01, 0xc4, 0xc5, 0x01, 0xc4, 0xc5, - 0x01, 0xc4, 0xc5, 0xbc, 0xbc, 0xbd, 0xbc, 0xbc, 0x05, 0xbd, 0x84, 0x85, - 0x86, 0x87, 0x01, 0x0d, 0x88, 0x82, 0x89, 0x84, 0x06, 0x8a, 0x83, 0x84, - 0x8b, 0x88, 0x0c, 0xbe, 0x8a, 0x01, 0x01, 0xc7, 0xc7, 0x01, 0xc7, 0xc7, - 0x01, 0xc7, 0xc7, 0x04, 0xbd, 0x82, 0xbf, 0xc0, 0x04, 0xbd, 0x84, 0x8c, - 0x8d, 0x8e, 0x01, 0x08, 0x8f, 0x04, 0x90, 0x82, 0x91, 0x92, 0x08, 0x93, - 0x82, 0x94, 0x91, 0x04, 0xce, 0x08, 0x8f, 0x8b, 0x01, 0x62, 0xbf, 0xc0, - 0x01, 0xbf, 0xc0, 0x01, 0xbf, 0xc0, 0xbc, 0x05, 0xbd, 0x81, 0xbc, 0x03, - 0xbd, 0x84, 0x01, 0x95, 0x01, 0x01, 0x06, 0x8f, 0x88, 0x96, 0x96, 0x97, - 0x98, 0x97, 0x98, 0x99, 0x9a, 0x08, 0x9b, 0x86, 0x9c, 0x9d, 0x97, 0xcf, - 0x97, 0xcf, 0x08, 0x8f, 0x14, 0xc1, 0x84, 0x9e, 0x9f, 0x9e, 0x9e, 0x08, - 0x90, 0x85, 0xa0, 0xa1, 0xa0, 0xa1, 0x82, 0x0a, 0x84, 0x85, 0x82, 0xa0, - 0xd1, 0xa0, 0xd1, 0x08, 0xc2, 0x14, 0x3d, 0x88, 0x3d, 0xa2, 0x3d, 0x3d, - 0xa3, 0xa4, 0xa4, 0xa5, 0x16, 0x3d, 0x81, 0xc6, 0x1d, 0x3d, 0x88, 0x3d, - 0xa2, 0x3d, 0x3d, 0xa6, 0xa7, 0xa8, 0xa7, 0x34, 0x3d, + 0x87, 0x01, 0x01, 0x62, 0x01, 0x63, 0x01, 0x64, 0x03, 0x65, 0x82, 0x63, + 0x64, 0x04, 0x65, 0x82, 0x63, 0x64, 0x09, 0x65, 0x81, 0x63, 0x05, 0x65, + 0x82, 0x63, 0x64, 0x03, 0x65, 0x83, 0x01, 0x63, 0x74, 0x05, 0x01, 0x81, + 0x62, 0x05, 0x01, 0x84, 0x74, 0x01, 0x01, 0x74, 0x04, 0x01, 0x93, 0x01, + 0x62, 0x62, 0x01, 0x63, 0x01, 0x64, 0x66, 0x67, 0x68, 0x63, 0x66, 0x67, + 0x68, 0x65, 0x66, 0x63, 0x68, 0x69, 0x06, 0x6a, 0x8f, 0x6b, 0x66, 0x63, + 0x68, 0x65, 0x66, 0x67, 0x68, 0x63, 0x66, 0x67, 0x68, 0x65, 0x01, 0x63, + 0x0c, 0x01, 0x88, 0x62, 0x01, 0x01, 0x62, 0x01, 0x01, 0x62, 0x74, 0x04, + 0x01, 0xa4, 0x63, 0x01, 0x64, 0x6c, 0x01, 0x6d, 0x63, 0x6c, 0x01, 0x6d, + 0x65, 0x6c, 0x63, 0x6d, 0x6e, 0x36, 0x39, 0x37, 0x36, 0x39, 0x37, 0x6f, + 0x6c, 0x63, 0x6d, 0x65, 0x6c, 0x01, 0x6d, 0x63, 0x6c, 0x01, 0x6d, 0x65, + 0x01, 0x63, 0x03, 0x01, 0x87, 0x74, 0x01, 0x01, 0x62, 0x01, 0x01, 0x74, + 0x04, 0x01, 0x86, 0x74, 0x01, 0x01, 0x74, 0x01, 0x01, 0x81, 0x62, 0x03, + 0x01, 0xa5, 0x63, 0x01, 0x64, 0x70, 0x71, 0x72, 0x63, 0x70, 0x71, 0x72, + 0x65, 0x70, 0x63, 0x72, 0x6e, 0x3e, 0x73, 0x40, 0x3b, 0x73, 0x3c, 0x6f, + 0x70, 0x63, 0xb4, 0x65, 0x70, 0xb5, 0xb4, 0x63, 0x70, 0xb5, 0xb4, 0x65, + 0x01, 0x63, 0x62, 0x13, 0x01, 0xa8, 0x01, 0x62, 0x01, 0x74, 0x63, 0x01, + 0x64, 0x6c, 0x01, 0x6d, 0x63, 0x6c, 0x01, 0x6d, 0x65, 0x6c, 0x63, 0x6d, + 0x6e, 0x3b, 0x3d, 0x40, 0x3b, 0x3d, 0x40, 0x6f, 0x6c, 0x63, 0x6d, 0x65, + 0x6c, 0x01, 0x6d, 0x63, 0x6c, 0x01, 0x6d, 0x65, 0x01, 0x63, 0x03, 0x01, + 0x83, 0x62, 0x01, 0x74, 0x03, 0x01, 0x81, 0x62, 0x04, 0x01, 0x83, 0x62, + 0x01, 0x74, 0x03, 0x01, 0x04, 0x01, 0xa4, 0x63, 0x01, 0x64, 0x75, 0x76, + 0x77, 0x63, 0x75, 0x76, 0x77, 0x65, 0x75, 0x63, 0x77, 0x6e, 0x3b, 0x3d, + 0x40, 0x3b, 0x3d, 0x40, 0x78, 0x75, 0x63, 0x77, 0x65, 0x75, 0x76, 0x77, + 0x63, 0x75, 0x76, 0x77, 0x65, 0x01, 0x63, 0x0b, 0x01, 0x81, 0x74, 0x08, + 0x01, 0x87, 0x62, 0x01, 0x01, 0x79, 0x7a, 0x7b, 0x7c, 0x03, 0x7d, 0x82, + 0x7a, 0x7c, 0x04, 0x7d, 0x8c, 0x7a, 0x64, 0x6e, 0x3b, 0x3d, 0x49, 0x49, + 0x3d, 0x40, 0x6f, 0x65, 0x7a, 0x05, 0x7d, 0x81, 0x7a, 0x04, 0x7d, 0x83, + 0x7b, 0x7a, 0xb6, 0x03, 0x01, 0x82, 0x74, 0x62, 0x03, 0x01, 0x81, 0x62, + 0x08, 0x01, 0x82, 0x62, 0x01, 0xab, 0x01, 0x74, 0x01, 0x7e, 0x63, 0x01, + 0x7f, 0x64, 0x7f, 0x64, 0x7f, 0x64, 0x7f, 0x64, 0x7f, 0x64, 0x7f, 0x64, + 0x6e, 0x3b, 0x3d, 0x40, 0x3b, 0x3d, 0x40, 0x6f, 0x65, 0x7f, 0x64, 0x7f, + 0x64, 0x7f, 0x64, 0x7f, 0x64, 0x7f, 0x64, 0x7f, 0x01, 0x63, 0x7e, 0x01, + 0x74, 0x03, 0x01, 0x84, 0x74, 0x01, 0xb7, 0x62, 0x0a, 0xb7, 0x03, 0x01, + 0xb4, 0x80, 0x63, 0x01, 0x81, 0x64, 0x81, 0x64, 0x81, 0x64, 0x81, 0x64, + 0x81, 0x64, 0x81, 0x64, 0x6e, 0x3e, 0x3d, 0x40, 0x3b, 0x3d, 0x3c, 0x6f, + 0x65, 0x81, 0x64, 0x81, 0x64, 0x81, 0x64, 0x81, 0x64, 0x81, 0x64, 0x81, + 0x01, 0x63, 0x80, 0x01, 0x62, 0x01, 0x01, 0x62, 0x01, 0x01, 0xb8, 0xb9, + 0xb8, 0xb8, 0xba, 0xb8, 0xb8, 0x05, 0xba, 0xb7, 0x62, 0x01, 0x01, 0x82, + 0x82, 0x83, 0x82, 0x84, 0x82, 0x84, 0x82, 0x84, 0x82, 0x84, 0x82, 0x84, + 0x82, 0x64, 0x6e, 0x41, 0x43, 0x44, 0x41, 0x43, 0x44, 0x6f, 0x65, 0x82, + 0x84, 0xbb, 0x84, 0xbb, 0x84, 0xbb, 0x84, 0xbb, 0x84, 0xbb, 0x83, 0xbb, + 0xbb, 0x01, 0xc4, 0xc5, 0x01, 0xc4, 0xc5, 0x01, 0xc4, 0xc5, 0xbc, 0xbc, + 0xbd, 0xbc, 0xbc, 0x05, 0xbd, 0x84, 0x85, 0x86, 0x87, 0x01, 0x0d, 0x88, + 0x82, 0x89, 0x84, 0x06, 0x8a, 0x83, 0x84, 0x8b, 0x88, 0x0c, 0xbe, 0x8a, + 0x01, 0x01, 0xc7, 0xc7, 0x01, 0xc7, 0xc7, 0x01, 0xc7, 0xc7, 0x04, 0xbd, + 0x82, 0xbf, 0xc0, 0x04, 0xbd, 0x84, 0x8c, 0x8d, 0x8e, 0x01, 0x08, 0x8f, + 0x04, 0x90, 0x82, 0x91, 0x92, 0x08, 0x93, 0x82, 0x94, 0x91, 0x04, 0xce, + 0x08, 0x8f, 0x8b, 0x01, 0x62, 0xbf, 0xc0, 0x01, 0xbf, 0xc0, 0x01, 0xbf, + 0xc0, 0xbc, 0x05, 0xbd, 0x81, 0xbc, 0x03, 0xbd, 0x84, 0x01, 0x95, 0x01, + 0x01, 0x06, 0x8f, 0x88, 0x96, 0x96, 0x97, 0x98, 0x97, 0x98, 0x99, 0x9a, + 0x08, 0x9b, 0x86, 0x9c, 0x9d, 0x97, 0xcf, 0x97, 0xcf, 0x08, 0x8f, 0x14, + 0xc1, 0x84, 0x9e, 0x9f, 0x9e, 0x9e, 0x08, 0x90, 0x85, 0xa0, 0xa1, 0xa0, + 0xa1, 0x82, 0x0a, 0x84, 0x85, 0x82, 0xa0, 0xd1, 0xa0, 0xd1, 0x08, 0xc2, + 0x14, 0x3d, 0x88, 0x3d, 0xa2, 0x3d, 0x3d, 0xa3, 0xa4, 0xa4, 0xa5, 0x16, + 0x3d, 0x81, 0xc6, 0x1d, 0x3d, 0x88, 0x3d, 0xa2, 0x3d, 0x3d, 0xa6, 0xa7, + 0xa8, 0xa7, 0x34, 0x3d, ]; const buffer = new ArrayBuffer(array.length); const view = new DataView(buffer); @@ -79,45 +75,30 @@ const roomNametableBuffer = () => { describe('parseRoomNametable', () => { it('should return a non empty object.', () => { - const { nametable } = parseRoomNametable(roomNametableEmptyBuffer(0)); - - assert.equal(typeof nametable, 'object'); - assert.deepEqual(Object.keys(nametable), [ - 'tileset', - 'palette', - 'nametableObj', - ]); - assert.ok(Number.isInteger(nametable.tileset)); - assert.ok(Array.isArray(nametable.palette)); - assert.equal(nametable.palette.length, 16); - assert.ok(Array.isArray(nametable.nametableObj)); - assert.equal(nametable.nametableObj.length, 16); - assert.ok(Array.isArray(nametable.nametableObj[0])); - assert.equal(nametable.nametableObj[0].length, 64); - }); - - it('should parse the tileset.', () => { - const { nametable } = parseRoomNametable(roomNametableEmptyBuffer(5)); + const { nametable } = parseRoomNametable(roomNametableEmptyBuffer()); - assert.equal(nametable.tileset, 5); + assert.ok(Array.isArray(nametable)); + assert.equal(nametable.length, 16); + assert.ok(Array.isArray(nametable[0])); + assert.equal(nametable[0].length, 64); }); it('should return a map object.', () => { - const { nametableMap } = parseRoomNametable(roomNametableEmptyBuffer(0)); + const { nametableMap } = parseRoomNametable(roomNametableEmptyBuffer()); assert.equal(typeof nametableMap, 'object'); assert.equal(nametableMap.from, 0); - assert.equal(nametableMap.to, 17); + assert.equal(nametableMap.to, 0); }); it('should return a map object with a start offset.', () => { const { nametableMap } = parseRoomNametable( - roomNametableEmptyBuffer(0), + roomNametableEmptyBuffer(), 0xabc, ); assert.equal(nametableMap.from, 0xabc); - assert.equal(nametableMap.to, 0xacd); + assert.equal(nametableMap.to, 0xabc); }); it('should be the inverse of serialiseRoomNametable.', () => { diff --git a/test/serialisePalette.test.js b/test/serialisePalette.test.js new file mode 100644 index 0000000..9a59862 --- /dev/null +++ b/test/serialisePalette.test.js @@ -0,0 +1,37 @@ +import { describe, it } from 'node:test'; +import assert from 'node:assert/strict'; +import serialisePalette from '../src/lib/serialiser/serialisePalette.js'; +import parsePalette from '../src/lib/parser/parsePalette.js'; + +const paletteFixture = [ + 0x0d, 0x07, 0x27, 0x3c, 0x0d, 0x17, 0x2a, 0x3a, 0x0d, 0x0d, 0x2a, 0x28, 0x0d, + 0x0d, 0x37, 0x20, +]; + +describe('serialisePalette', () => { + it('should return an instance of ArrayBuffer.', () => { + const buffer = serialisePalette(paletteFixture); + assert.ok(buffer instanceof ArrayBuffer); + }); + + it('should serialise a palette.', () => { + const buffer = serialisePalette(paletteFixture); + const view = new DataView(buffer); + + assert.equal(view.getUint8(0x00), 0x0d); + assert.equal(view.getUint8(0x01), 0x07); + assert.equal(view.getUint8(0x02), 0x27); + assert.equal(view.getUint8(0x03), 0x3c); + assert.equal(view.getUint8(0x04), 0x0d); + assert.equal(view.getUint8(0x08), 0x0d); + assert.equal(view.getUint8(0x0c), 0x0d); + assert.equal(buffer.byteLength, 16); + }); + + it('should be the inverse of parseRoomHeader.', () => { + const buffer = serialisePalette(paletteFixture); + const { palette } = parsePalette(buffer); + + assert.deepEqual(paletteFixture, palette); + }); +}); diff --git a/test/serialiseRoomNametable.test.js b/test/serialiseRoomNametable.test.js index 024f7fa..769c1ec 100644 --- a/test/serialiseRoomNametable.test.js +++ b/test/serialiseRoomNametable.test.js @@ -3,114 +3,107 @@ import assert from 'node:assert/strict'; import serialiseRoomNametable from '../src/lib/serialiser/room/serialiseRoomNametable.js'; import parseRoomNametable from '../src/lib/parser/room/parseRoomNametable.js'; -const roomNametable = { - tileset: 187, - palette: [ - 114, 133, 23, 173, 185, 114, 141, 63, 109, 172, 188, 114, 230, 23, 230, 23, - ], - nametableObj: [ - [ - 0, 0, 1, 1, 98, 1, 99, 1, 100, 101, 101, 101, 99, 100, 101, 101, 101, 101, - 99, 100, 101, 101, 101, 101, 101, 101, 101, 101, 101, 99, 101, 101, 101, - 101, 101, 99, 100, 101, 101, 101, 1, 99, 116, 1, 1, 1, 1, 1, 98, 1, 1, 1, - 1, 1, 116, 1, 1, 116, 1, 1, 1, 1, 0, 0, - ], - [ - 0, 0, 1, 98, 98, 1, 99, 1, 100, 102, 103, 104, 99, 102, 103, 104, 101, - 102, 99, 104, 105, 106, 106, 106, 106, 106, 106, 107, 102, 99, 104, 101, - 102, 103, 104, 99, 102, 103, 104, 101, 1, 99, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 98, 1, 1, 98, 1, 1, 98, 116, 0, 0, - ], - [ - 0, 0, 1, 1, 1, 1, 99, 1, 100, 108, 1, 109, 99, 108, 1, 109, 101, 108, 99, - 109, 110, 54, 57, 55, 54, 57, 55, 111, 108, 99, 109, 101, 108, 1, 109, 99, - 108, 1, 109, 101, 1, 99, 1, 1, 1, 116, 1, 1, 98, 1, 1, 116, 1, 1, 1, 1, - 116, 1, 1, 116, 1, 1, 0, 0, - ], - [ - 0, 0, 98, 1, 1, 1, 99, 1, 100, 112, 113, 114, 99, 112, 113, 114, 101, 112, - 99, 114, 110, 62, 115, 64, 59, 115, 60, 111, 112, 99, 180, 101, 112, 181, - 180, 99, 112, 181, 180, 101, 1, 99, 98, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, - ], - [ - 0, 0, 1, 98, 1, 116, 99, 1, 100, 108, 1, 109, 99, 108, 1, 109, 101, 108, - 99, 109, 110, 59, 61, 64, 59, 61, 64, 111, 108, 99, 109, 101, 108, 1, 109, - 99, 108, 1, 109, 101, 1, 99, 1, 1, 1, 98, 1, 116, 1, 1, 1, 98, 1, 1, 1, 1, - 98, 1, 116, 1, 1, 1, 0, 0, - ], - [ - 0, 0, 1, 1, 1, 1, 99, 1, 100, 117, 118, 119, 99, 117, 118, 119, 101, 117, - 99, 119, 110, 59, 61, 64, 59, 61, 64, 120, 117, 99, 119, 101, 117, 118, - 119, 99, 117, 118, 119, 101, 1, 99, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 116, - 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, - ], - [ - 0, 0, 98, 1, 1, 121, 122, 123, 124, 125, 125, 125, 122, 124, 125, 125, - 125, 125, 122, 100, 110, 59, 61, 73, 73, 61, 64, 111, 101, 122, 125, 125, - 125, 125, 125, 122, 125, 125, 125, 125, 123, 122, 182, 1, 1, 1, 116, 98, - 1, 1, 1, 98, 1, 1, 1, 1, 1, 1, 1, 1, 98, 1, 0, 0, - ], - [ - 0, 0, 1, 116, 1, 126, 99, 1, 127, 100, 127, 100, 127, 100, 127, 100, 127, - 100, 127, 100, 110, 59, 61, 64, 59, 61, 64, 111, 101, 127, 100, 127, 100, - 127, 100, 127, 100, 127, 100, 127, 1, 99, 126, 1, 116, 1, 1, 1, 116, 1, - 183, 98, 183, 183, 183, 183, 183, 183, 183, 183, 183, 183, 0, 0, - ], - [ - 0, 0, 1, 1, 1, 128, 99, 1, 129, 100, 129, 100, 129, 100, 129, 100, 129, - 100, 129, 100, 110, 62, 61, 64, 59, 61, 60, 111, 101, 129, 100, 129, 100, - 129, 100, 129, 100, 129, 100, 129, 1, 99, 128, 1, 98, 1, 1, 98, 1, 1, 184, - 185, 184, 184, 186, 184, 184, 186, 186, 186, 186, 186, 0, 0, - ], - [ - 0, 0, 98, 1, 1, 130, 130, 131, 130, 132, 130, 132, 130, 132, 130, 132, - 130, 132, 130, 100, 110, 65, 67, 68, 65, 67, 68, 111, 101, 130, 132, 187, - 132, 187, 132, 187, 132, 187, 132, 187, 131, 187, 187, 1, 196, 197, 1, - 196, 197, 1, 196, 197, 188, 188, 189, 188, 188, 189, 189, 189, 189, 189, - 0, 0, - ], - [ - 0, 0, 133, 134, 135, 1, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 137, 132, 138, 138, 138, 138, 138, 138, 132, 139, 136, 190, - 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, 1, 1, 199, 199, 1, - 199, 199, 1, 199, 199, 189, 189, 189, 189, 191, 192, 189, 189, 189, 189, - 0, 0, - ], - [ - 0, 0, 140, 141, 142, 1, 143, 143, 143, 143, 143, 143, 143, 143, 144, 144, - 144, 144, 145, 146, 147, 147, 147, 147, 147, 147, 147, 147, 148, 145, 206, - 206, 206, 206, 143, 143, 143, 143, 143, 143, 143, 143, 1, 98, 191, 192, 1, - 191, 192, 1, 191, 192, 188, 189, 189, 189, 189, 189, 188, 189, 189, 189, - 0, 0, - ], - [ - 0, 0, 1, 149, 1, 1, 143, 143, 143, 143, 143, 143, 150, 150, 151, 152, 151, - 152, 153, 154, 155, 155, 155, 155, 155, 155, 155, 155, 156, 157, 151, 207, - 151, 207, 143, 143, 143, 143, 143, 143, 143, 143, 193, 193, 193, 193, 193, - 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, - 0, 0, - ], - [ - 0, 0, 158, 159, 158, 158, 144, 144, 144, 144, 144, 144, 144, 144, 160, - 161, 160, 161, 130, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 130, - 160, 209, 160, 209, 194, 194, 194, 194, 194, 194, 194, 194, 61, 61, 61, - 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 0, 0, - ], - [ - 0, 0, 61, 162, 61, 61, 163, 164, 164, 165, 61, 61, 61, 61, 61, 61, 61, 61, - 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 198, 61, 61, 61, - 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, - 61, 61, 61, 61, 61, 61, 61, 61, 0, 0, - ], - [ - 0, 0, 61, 162, 61, 61, 166, 167, 168, 167, 61, 61, 61, 61, 61, 61, 61, 61, - 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, - 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, - 61, 61, 61, 61, 61, 61, 61, 61, 0, 0, - ], - ], -}; +const roomNametable = [ + [ + 0, 0, 1, 1, 98, 1, 99, 1, 100, 101, 101, 101, 99, 100, 101, 101, 101, 101, + 99, 100, 101, 101, 101, 101, 101, 101, 101, 101, 101, 99, 101, 101, 101, + 101, 101, 99, 100, 101, 101, 101, 1, 99, 116, 1, 1, 1, 1, 1, 98, 1, 1, 1, 1, + 1, 116, 1, 1, 116, 1, 1, 1, 1, 0, 0, + ], + [ + 0, 0, 1, 98, 98, 1, 99, 1, 100, 102, 103, 104, 99, 102, 103, 104, 101, 102, + 99, 104, 105, 106, 106, 106, 106, 106, 106, 107, 102, 99, 104, 101, 102, + 103, 104, 99, 102, 103, 104, 101, 1, 99, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 98, 1, 1, 98, 1, 1, 98, 116, 0, 0, + ], + [ + 0, 0, 1, 1, 1, 1, 99, 1, 100, 108, 1, 109, 99, 108, 1, 109, 101, 108, 99, + 109, 110, 54, 57, 55, 54, 57, 55, 111, 108, 99, 109, 101, 108, 1, 109, 99, + 108, 1, 109, 101, 1, 99, 1, 1, 1, 116, 1, 1, 98, 1, 1, 116, 1, 1, 1, 1, 116, + 1, 1, 116, 1, 1, 0, 0, + ], + [ + 0, 0, 98, 1, 1, 1, 99, 1, 100, 112, 113, 114, 99, 112, 113, 114, 101, 112, + 99, 114, 110, 62, 115, 64, 59, 115, 60, 111, 112, 99, 180, 101, 112, 181, + 180, 99, 112, 181, 180, 101, 1, 99, 98, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 0, 0, + ], + [ + 0, 0, 1, 98, 1, 116, 99, 1, 100, 108, 1, 109, 99, 108, 1, 109, 101, 108, 99, + 109, 110, 59, 61, 64, 59, 61, 64, 111, 108, 99, 109, 101, 108, 1, 109, 99, + 108, 1, 109, 101, 1, 99, 1, 1, 1, 98, 1, 116, 1, 1, 1, 98, 1, 1, 1, 1, 98, + 1, 116, 1, 1, 1, 0, 0, + ], + [ + 0, 0, 1, 1, 1, 1, 99, 1, 100, 117, 118, 119, 99, 117, 118, 119, 101, 117, + 99, 119, 110, 59, 61, 64, 59, 61, 64, 120, 117, 99, 119, 101, 117, 118, 119, + 99, 117, 118, 119, 101, 1, 99, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 116, 1, 1, + 1, 1, 1, 1, 1, 1, 0, 0, + ], + [ + 0, 0, 98, 1, 1, 121, 122, 123, 124, 125, 125, 125, 122, 124, 125, 125, 125, + 125, 122, 100, 110, 59, 61, 73, 73, 61, 64, 111, 101, 122, 125, 125, 125, + 125, 125, 122, 125, 125, 125, 125, 123, 122, 182, 1, 1, 1, 116, 98, 1, 1, 1, + 98, 1, 1, 1, 1, 1, 1, 1, 1, 98, 1, 0, 0, + ], + [ + 0, 0, 1, 116, 1, 126, 99, 1, 127, 100, 127, 100, 127, 100, 127, 100, 127, + 100, 127, 100, 110, 59, 61, 64, 59, 61, 64, 111, 101, 127, 100, 127, 100, + 127, 100, 127, 100, 127, 100, 127, 1, 99, 126, 1, 116, 1, 1, 1, 116, 1, 183, + 98, 183, 183, 183, 183, 183, 183, 183, 183, 183, 183, 0, 0, + ], + [ + 0, 0, 1, 1, 1, 128, 99, 1, 129, 100, 129, 100, 129, 100, 129, 100, 129, 100, + 129, 100, 110, 62, 61, 64, 59, 61, 60, 111, 101, 129, 100, 129, 100, 129, + 100, 129, 100, 129, 100, 129, 1, 99, 128, 1, 98, 1, 1, 98, 1, 1, 184, 185, + 184, 184, 186, 184, 184, 186, 186, 186, 186, 186, 0, 0, + ], + [ + 0, 0, 98, 1, 1, 130, 130, 131, 130, 132, 130, 132, 130, 132, 130, 132, 130, + 132, 130, 100, 110, 65, 67, 68, 65, 67, 68, 111, 101, 130, 132, 187, 132, + 187, 132, 187, 132, 187, 132, 187, 131, 187, 187, 1, 196, 197, 1, 196, 197, + 1, 196, 197, 188, 188, 189, 188, 188, 189, 189, 189, 189, 189, 0, 0, + ], + [ + 0, 0, 133, 134, 135, 1, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 137, 132, 138, 138, 138, 138, 138, 138, 132, 139, 136, 190, + 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, 1, 1, 199, 199, 1, + 199, 199, 1, 199, 199, 189, 189, 189, 189, 191, 192, 189, 189, 189, 189, 0, + 0, + ], + [ + 0, 0, 140, 141, 142, 1, 143, 143, 143, 143, 143, 143, 143, 143, 144, 144, + 144, 144, 145, 146, 147, 147, 147, 147, 147, 147, 147, 147, 148, 145, 206, + 206, 206, 206, 143, 143, 143, 143, 143, 143, 143, 143, 1, 98, 191, 192, 1, + 191, 192, 1, 191, 192, 188, 189, 189, 189, 189, 189, 188, 189, 189, 189, 0, + 0, + ], + [ + 0, 0, 1, 149, 1, 1, 143, 143, 143, 143, 143, 143, 150, 150, 151, 152, 151, + 152, 153, 154, 155, 155, 155, 155, 155, 155, 155, 155, 156, 157, 151, 207, + 151, 207, 143, 143, 143, 143, 143, 143, 143, 143, 193, 193, 193, 193, 193, + 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, + 0, 0, + ], + [ + 0, 0, 158, 159, 158, 158, 144, 144, 144, 144, 144, 144, 144, 144, 160, 161, + 160, 161, 130, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, 130, 160, + 209, 160, 209, 194, 194, 194, 194, 194, 194, 194, 194, 61, 61, 61, 61, 61, + 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 0, 0, + ], + [ + 0, 0, 61, 162, 61, 61, 163, 164, 164, 165, 61, 61, 61, 61, 61, 61, 61, 61, + 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 198, 61, 61, 61, 61, + 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, + 61, 61, 61, 61, 61, 61, 0, 0, + ], + [ + 0, 0, 61, 162, 61, 61, 166, 167, 168, 167, 61, 61, 61, 61, 61, 61, 61, 61, + 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, + 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, + 61, 61, 61, 61, 61, 61, 0, 0, + ], +]; describe('serialiseRoomNametable', () => { it('should return an instance of ArrayBuffer.', () => { @@ -122,11 +115,16 @@ describe('serialiseRoomNametable', () => { const buffer = serialiseRoomNametable(roomNametable); const view = new DataView(buffer); - assert.equal(view.getUint8(0x00), 187); - assert.equal(view.getUint8(0x01), 114); - assert.equal(view.getUint8(0x05), 185); - assert.equal(view.getUint8(0x09), 109); - assert.equal(view.getUint8(0x0d), 230); + assert.equal(view.getUint8(0x00), 0x87); // 7 times different bytes. + assert.equal(view.getUint8(0x01), 1); + assert.equal(view.getUint8(0x02), 1); + assert.equal(view.getUint8(0x03), 98); + assert.equal(view.getUint8(0x04), 1); + assert.equal(view.getUint8(0x05), 99); + assert.equal(view.getUint8(0x06), 1); + assert.equal(view.getUint8(0x07), 100); + assert.equal(view.getUint8(0x08), 0x3); // 3 times the following bytes. + assert.equal(view.getUint8(0x09), 101); }); it('should be the inverse of parseRoomNametable.', () => {