-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathexample.js
51 lines (46 loc) · 1.25 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const fs = require('node:fs');
const process = require('node:process');
const debug = require('debug')('wpcemu:index');
const Emulator = require('./lib/emulator');
const romGamePath = process.argv[2] || 'rom/HURCNL_2.ROM';
if (!romGamePath) {
console.error('Parameter [GAME_ROM_PATH]');
throw new Error('MISSING_PARAMETER');
}
function loadFile(fileName) {
debug('loadFile', fileName);
return new Promise((resolve, reject) => {
fs.readFile(fileName, (error, data) => {
if (error) {
return reject(error);
}
resolve(new Uint8Array(data));
});
});
}
function runWpsMainloop(wpcSystem) {
setInterval(() => {
wpcSystem.executeCycle(34482, 16);
}, 16);
}
loadFile(romGamePath)
.then((u06Rom) => {
const romData = {
u06: u06Rom,
};
const metaData = {
features: ['wpcDmd'], //'securityPic', 'wpc95', 'wpcFliptronics', 'wpcDmd', 'wpcSecure', 'wpcAlphanumeric'
fileName: romGamePath,
skipWpcRomCheck: true,
};
return Emulator.initVMwithRom(romData, metaData);
})
.then((wpcSystem) => {
debug('WPC System initialized');
wpcSystem.start();
runWpsMainloop(wpcSystem);
})
.catch((error) => {
console.log('EXCEPTION!', error.message);
console.log(error.stack);
});