├── .gitignore ├── LICENSE ├── README.md ├── app.js ├── maps └── index.js ├── package.json ├── pal.png └── sourceroms └── alterDark.nes /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Rachel Simone Weil 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ad-API 2 | Alter Dark API 3 | 4 | ## Usage 5 | `GET https://alterdark.azurewebsites.net/api/` with parameters listed in maps below. 6 | 7 | ## Maps 8 | - [Alter Dark](#alter-dark-map) 9 | 10 | ### Alter Dark map 11 | | param | example value | notes | 12 | | ----------- | ------------- | ----------------------- | 13 | | "bgpala0"
...
"bgpalh3" | 0x3C | see palette param naming convention below.
![pal](pal.png)
first row (a0 through d3) contains background colors; second row (e0 through h3) contains sprite colors. all x0 colors (a0, b0, h0, etc.) must be the same value. e0, f0, g0, and h0 represent transparency and will not be visible. | 14 | | "anim" | 0x01 | 0x00 = none, 0x01 = aliens, 0x02 = hearts | 15 | | "animspeed" | 0x01 | 0x01 = slow, 0x02 = med, 0x04 = fast | 16 | | "randomseed1"
"randomseed2" | 0xFA | used for generating random colors and positions in nes rom. generate in javascript: `randomseed1 = Math.floor(Math.random() * 256);` | 17 | | "text1_1"
...
"text2_28" | "H" | supports ascii values 0x20 through 0x7E. see [ascii-table.com](http://ascii-table.com/). | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | const { join } = require('path') 2 | const express = require('express') 3 | const app = express() 4 | const fs = require('fs') 5 | const romMaps = require(join(__dirname, 'maps')) 6 | const romsPath = join(__dirname, 'sourceroms') 7 | const cors = require('cors') 8 | const pump = require('pump') 9 | const through2 = require('through2') 10 | 11 | app.use(cors()) 12 | 13 | app.get('/api/:id', function (req, res) { 14 | // ROM name comes from the path parameter, example: /api/alterDark 15 | let romid = req.params.id 16 | let query = req.query 17 | let memMap = romMaps[romid] 18 | 19 | // return an error if there is no rom map 20 | if (!memMap) { 21 | return res.status(400).json({ 22 | message: `No map to rom ${romid}` 23 | }) 24 | } 25 | // create a write stream of the base ROM file 26 | let rom = fs.createReadStream( 27 | join(romsPath, `${romid}.nes`) 28 | // { highWaterMark: 1024 * 8 } // quarter chunk size, just to play with 29 | ) 30 | 31 | // this is the "chunk size" we need in order to offset the index for multiple chunks 32 | let chunkSize = rom._readableState.highWaterMark 33 | let chunk = 0 34 | 35 | let transform = through2(function (romData, enc, callback) { 36 | // keeping track of the chunk number so we can offset the map keys 37 | let offset = chunkSize * chunk 38 | Object.keys(query).forEach(addr => { 39 | let mapAddr = memMap[addr] + offset 40 | let newAddr = Number(query[addr]) 41 | if (romData.indexOf(mapAddr) > -1) { 42 | romData[mapAddr] = newAddr 43 | } 44 | }) 45 | this.push(romData) 46 | chunk++ 47 | callback() 48 | }) 49 | 50 | res.type('application/octet-stream') 51 | // we use pump to take the rom file, put it through our transform, then pipe to the client so we can take advantage of streaming 52 | pump(rom, transform, res) 53 | }) 54 | 55 | app.listen(process.env.PORT || 3000, function () { 56 | console.log('Listening!') 57 | }) 58 | -------------------------------------------------------------------------------- /maps/index.js: -------------------------------------------------------------------------------- 1 | exports.alterDark = { 2 | 'bgpala0': 0x0010, 3 | 'bgpala1': 0x0011, 4 | 'bgpala2': 0x0012, 5 | 'bgpala3': 0x0013, 6 | 'bgpalb0': 0x0014, 7 | 'bgpalb1': 0x0015, 8 | 'bgpalb2': 0x0016, 9 | 'bgpalb3': 0x0017, 10 | 'bgpalc0': 0x0018, 11 | 'bgpalc1': 0x0019, 12 | 'bgpalc2': 0x001A, 13 | 'bgpalc3': 0x001B, 14 | 'bgpald0': 0x001C, 15 | 'bgpald1': 0x001D, 16 | 'bgpald2': 0x001E, 17 | 'bgpald3': 0x001F, 18 | 'bgpale0': 0x0020, 19 | 'bgpale1': 0x0021, 20 | 'bgpale2': 0x0022, 21 | 'bgpale3': 0x0023, 22 | 'bgpalf0': 0x0024, 23 | 'bgpalf1': 0x0025, 24 | 'bgpalf2': 0x0026, 25 | 'bgpalf3': 0x0027, 26 | 'bgpalg0': 0x0028, 27 | 'bgpalg1': 0x0029, 28 | 'bgpalg2': 0x002A, 29 | 'bgpalg3': 0x002B, 30 | 'bgpalh0': 0x002C, 31 | 'bgpalh1': 0x002D, 32 | 'bgpalh2': 0x002E, 33 | 'bgpalh3': 0x002F, 34 | 'bgimg': 0x0030, 35 | 'anim': 0x0031, 36 | 'animspeed': 0x0032, 37 | 'randomseed1': 0x0033, 38 | 'text1_1': 0x0034, 39 | 'text1_2': 0x0035, 40 | 'text1_3': 0x0036, 41 | 'text1_4': 0x0037, 42 | 'text1_5': 0x0038, 43 | 'text1_6': 0x0039, 44 | 'text1_7': 0x003A, 45 | 'text1_8': 0x003B, 46 | 'text1_9': 0x003C, 47 | 'text1_10': 0x003D, 48 | 'text1_11': 0x003E, 49 | 'text1_12': 0x003F, 50 | 'text1_13': 0x0040, 51 | 'text1_14': 0x0041, 52 | 'text1_15': 0x0042, 53 | 'text1_16': 0x0043, 54 | 'text1_17': 0x0044, 55 | 'text1_18': 0x0045, 56 | 'text1_19': 0x0046, 57 | 'text1_20': 0x0047, 58 | 'text1_21': 0x0048, 59 | 'text1_22': 0x0049, 60 | 'text1_23': 0x004A, 61 | 'text1_24': 0x004B, 62 | 'text1_25': 0x004C, 63 | 'text1_26': 0x004D, 64 | 'text1_27': 0x004E, 65 | 'text1_28': 0x004F, 66 | 'text2_1': 0x0050, 67 | 'text2_2': 0x0051, 68 | 'text2_3': 0x0052, 69 | 'text2_4': 0x0053, 70 | 'text2_5': 0x0054, 71 | 'text2_6': 0x0055, 72 | 'text2_7': 0x0056, 73 | 'text2_8': 0x0057, 74 | 'text2_9': 0x0058, 75 | 'text2_10': 0x0059, 76 | 'text2_11': 0x005A, 77 | 'text2_12': 0x005B, 78 | 'text2_13': 0x005C, 79 | 'text2_14': 0x005D, 80 | 'text2_15': 0x005E, 81 | 'text2_16': 0x005F, 82 | 'text2_17': 0x0060, 83 | 'text2_18': 0x0061, 84 | 'text2_19': 0x0062, 85 | 'text2_20': 0x0063, 86 | 'text2_21': 0x0064, 87 | 'text2_22': 0x0065, 88 | 'text2_23': 0x0066, 89 | 'text2_24': 0x0067, 90 | 'text2_25': 0x0068, 91 | 'text2_26': 0x0069, 92 | 'text2_27': 0x006A, 93 | 'text2_28': 0x006B, 94 | 'randomseed2': 0x006C 95 | } 96 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "alterdark-api", 3 | "version": "1.0.0", 4 | "description": "alterdark api", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/hxlnt/alterdark-api.git" 12 | }, 13 | "author": "rachel weil", 14 | "license": "ISC", 15 | "bugs": { 16 | "url": "https://github.com/hxlnt/alterdark-api/issues" 17 | }, 18 | "homepage": "https://github.com/hxlnt/alterdark-api#readme", 19 | "dependencies": { 20 | "cors": "~2.8.4", 21 | "express": "~4.16.2", 22 | "pump": "~1.0.2", 23 | "through2": "~2.0.3" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /pal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alterdark/ad-API/32a807cf5ce8e31bd1a58fd15a7cbd4deeb2e0a9/pal.png -------------------------------------------------------------------------------- /sourceroms/alterDark.nes: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alterdark/ad-API/32a807cf5ce8e31bd1a58fd15a7cbd4deeb2e0a9/sourceroms/alterDark.nes --------------------------------------------------------------------------------