Skip to content

Commit b757a34

Browse files
author
kirjavascript
committed
p2bin is working
1 parent 4ae12b4 commit b757a34

File tree

5 files changed

+24
-39
lines changed

5 files changed

+24
-39
lines changed

app/components/file/file-object.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,6 @@ export const FileObject = observer(({ obj }) => {
126126
ioWrap(obj.mappings.path, setMappingError, e, async (path) => {
127127
if (!obj.dplcs.enabled) environment.config.dplcsEnabled = false;
128128

129-
if (mappingsASM) {
130-
await assemble(await fs.readFile(path, 'utf8'))
131-
}
132-
133129
const buffer = mappingsASM
134130
? parseASM(await fs.readFile(path, 'utf8'))
135131
: await fs.readFile(path);

app/formats/asm/index.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,48 @@ import asmsg from './messages/as.msg';
44
import ioerrsmsg from './messages/ioerrs.msg';
55
import cmdargmsg from './messages/cmdarg.msg';
66
import p2binmsg from './messages/p2bin.msg';
7+
import toolsmsg from './messages/tools.msg';
78

8-
const messages = {
9+
const asMessages = {
910
asmsg,
1011
ioerrsmsg,
1112
cmdargmsg,
1213
};
1314

15+
const p2binMessages = {
16+
p2binmsg,
17+
ioerrsmsg,
18+
cmdargmsg,
19+
toolsmsg,
20+
};
21+
1422
export async function assemble(
1523
code,
1624
{ filename } = {
1725
filename: 'code.asm',
1826
},
1927
) {
20-
console.time('assemble');
21-
2228
const aslWorker = new Worker('bundles/asl-worker.js');
2329
const asl = Comlink.wrap(aslWorker);
2430

25-
const pFile = await asl.assemble(prelude + code, { messages, filename });
31+
const pFile = await asl.assemble(prelude + code, {
32+
messages: asMessages,
33+
filename,
34+
});
2635
aslWorker.terminate();
2736

28-
console.log(pFile);
29-
3037
const p2binWorker = new Worker('bundles/p2bin-worker.js');
3138
const p2bin = Comlink.wrap(p2binWorker);
3239
const bin = await p2bin.binary(pFile, {
33-
messages: { p2binmsg },
40+
messages: p2binMessages,
3441
});
3542
p2binWorker.terminate();
3643

37-
console.log(bin);
38-
39-
console.timeEnd('assemble');
40-
4144
return bin;
4245
}
4346

4447
const prelude = `SonicMappingsVer := 2
45-
48+
SonicDplcVer = 2
4649
; macro to declare a mappings table (taken from Sonic 2 Hg disassembly)
4750
mappingsTable macro {INTLABEL}
4851
__LABEL__ label *

app/formats/asm/messages/tools.msg

451 Bytes
Binary file not shown.

app/formats/asm/p2bin-worker.js

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,34 @@ import * as Comlink from 'comlink';
22

33
const endStr = '__flex2__done__';
44

5-
const errorList = [];
6-
75
function binary(pFile, { messages }) {
86
return new Promise((resolve, reject) => {
97
self.Module = {
108
locateFile: url => `../wasm/${url}`,
11-
arguments: ['data.p'],
9+
arguments: ['-q', 'data.p'],
1210
print: (text) => {
13-
console.log(1);
14-
if (text === endStr) return handleResult(resolve, reject);
11+
if (text === endStr) return resolve(FS.readFile('data.bin'));
1512
console.log('p2bin: ' + text);
1613
},
1714
printErr: (text) => {
18-
errorList.push(text);
15+
reject({
16+
name: 'P2BinError',
17+
message: text,
18+
});
1919
},
2020
onAbort: console.error,
2121
preInit: () => {
2222
FS.writeFile('p2bin.msg', messages.p2binmsg);
23+
FS.writeFile('ioerrs.msg', messages.ioerrsmsg);
24+
FS.writeFile('cmdarg.msg', messages.cmdargmsg);
25+
FS.writeFile('tools.msg', messages.toolsmsg);
2326
FS.writeFile('data.p', pFile);
24-
console.log(1);
2527
},
2628
};
27-
console.log(1);
2829
importScripts('../wasm/p2bin.js');
2930
});
3031
}
3132

32-
function handleResult(resolve, reject) {
33-
if (errorList.length) return reject({
34-
name: 'P2BinError',
35-
message: '\n\n' + errorList.join('\n')
36-
});
37-
38-
// const outputs = FS.readdir('/').filter(d => d.endsWith('.bin'));
39-
40-
// if (!outputs.length) return reject(new Error('cannot find .bin'));
41-
42-
// const [binPath] = outputs;
43-
44-
// resolve(FS.readFile(binPath));
45-
}
46-
4733
Comlink.expose({
4834
binary,
4935
});

static/wasm/p2bin.wasm

20 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)