Skip to content

Commit 10585c9

Browse files
committed
mapmacros custom asm output
1 parent f0cb5f3 commit 10585c9

File tree

5 files changed

+90
-28
lines changed

5 files changed

+90
-28
lines changed

TODO

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ redo tile rendering
2222
remove rotsprite
2323

2424
ROADMAP
25+
2526
drawing mode bugs
2627
disable mapping editing
2728
improve undo/redo when drawing pixels / moving things
@@ -32,9 +33,6 @@ animation editor
3233
BUGS
3334

3435
TODO: load / save / load broken in sonic CD
35-
36-
saving 0 tile as nemesis crashes
37-
saving ArtC42 at all crashes
3836
pink surrounding tiles sometimes breaks
3937

4038
FEATURES
@@ -45,8 +43,6 @@ select multiple sprites at once to reorder
4543
copy / paste mappings
4644
time travel for undo/redo
4745
import palette from spritesheet https://yarnpkg.com/en/package/node-vibrant
48-
==
49-
Speaking of Flex2, will there be a way for sprite sheets to not load already compressed tiles? It seems like every time I add new sprites, it makes duplicates of the same tiles leading me to manually remove it myself or overlap the mappings.
5046

5147

5248
22:04 <+dIRCord> <M​ainMemory> > Art is easy ␤> Each byte encodes one pixel, both nybbles have the color index ␤> And then each column is stored all in one go, no breaking into tiles ␤> In other words, it's pretty much a headerless 8bpp bitmap ␤> I think the color index is duplicated over both nybbles for speed, but I never looked at the algorithm

app/components/file/file-object.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,18 @@ export const FileObject = observer(({ obj }) => {
161161
function saveMappings(e) {
162162
ioWrap(obj.mappings.path, setMappingError, e, async (path) => {
163163
const mappings = script.writeMappings(environment.mappings);
164-
console.log(mappings);
165164
if (mappings.error) throw mappings.error;
166165
if (!mappingsASM) {
167166
await fs.writeFile(path, writeBIN(mappings));
168167
} else {
169168
const label = obj.mappings.label || 'Map_' + uuid().slice(0, 4);
170-
await fs.writeFile(path, writeASM(label, mappings));
169+
const asmOutput = script.generateMappingsASM({
170+
label,
171+
listing: mappings,
172+
sprites: environment.sprites,
173+
});
174+
175+
await fs.writeFile(path, asmOutput);
171176
}
172177
});
173178
}

app/components/ui/input/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export const Input = observer(class Input extends Component {
7272
</span>}
7373
<input
7474
style={color && {color: SVARS[color]}}
75-
value={store[accessor] || ''}
75+
value={store[accessor] ?? ''}
7676
onChange={this.onChange}
7777
onKeyDown={this.onKeyDown}
7878
ref={this.inputRef}

app/formats/scripts/run-script.js

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { loadScript, scriptDir } from './file';
2+
import { writeASM } from '#formats/scripts';
23
import { logger } from './debug';
34
import { toJS } from 'mobx';
45
import fs from 'fs';
@@ -26,7 +27,6 @@ export const constants = {
2627
endSection,
2728
};
2829

29-
3030
function useDef() {
3131
let def = [];
3232
return [
@@ -243,6 +243,8 @@ export default catchFunc((file) => {
243243
};
244244

245245
const createWriter = (sectionList = []) => catchFunc((mappings) => {
246+
// mapping output format is [type, size, data]
247+
246248
const global = { cleanup: [] };
247249
const sections = sectionList.map(([, writeFrame]) => {
248250
const spriteList = toJS(mappings);
@@ -326,6 +328,7 @@ export default catchFunc((file) => {
326328
});
327329
}
328330

331+
329332
const asm = {
330333
basic: false,
331334
prelude: `
@@ -339,6 +342,9 @@ paddingSoFar set paddingSoFar+1
339342
};
340343

341344
if (asmArgs[0]) {
345+
const [writeMappingsArgs, writeMappingsFunc] = useDef();
346+
const [writeDPLCsArgs, writeDPLCsFunc] = useDef();
347+
342348
function basic() {
343349
asm.basic = true;
344350
}
@@ -354,25 +360,52 @@ paddingSoFar set paddingSoFar+1
354360
}
355361
}
356362

357-
function writeMappings(func) {
358-
return func()
359-
}
360-
361-
function writeDPLCs() {
362-
363-
}
364-
// export function writeASM(baseLabel, { sections }) {
365-
366363
asmArgs[0]({
367364
basic,
368365
addScript,
369366
importScript,
370-
writeMappings,
371-
writeDPLCs,
367+
writeMappings: writeMappingsFunc,
368+
writeDPLCs: writeDPLCsFunc,
372369
});
370+
371+
if (writeMappingsArgs[0]) {
372+
asm.writeMappings = writeMappingsArgs[0];
373+
}
374+
375+
if (writeDPLCsArgs[0]) {
376+
asm.writeDPLCs = writeDPLCs[0];
377+
}
373378
}
374379

375380
exports.asm = asm;
376381

382+
const renderHex = num => {
383+
let out = '';
384+
if (num < 0) out += '-';
385+
num = Math.abs(num);
386+
if (num > 9) out += '$';
387+
out += num.toString(16).toUpperCase();
388+
return out;
389+
};
390+
391+
exports.generateMappingsASM = function({
392+
label,
393+
sprites,
394+
listing,
395+
}) {
396+
if (!asm.writeMappings) {
397+
return writeASM(label, listing);
398+
}
399+
400+
return asm.writeMappings({
401+
label, sprites, listing,
402+
renderHex,
403+
});
404+
};
405+
406+
exports.generateDPLCsASM = function() {
407+
408+
};
409+
377410
return exports;
378411
});

scripts/Sonic 2.js

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,47 @@ dplcs([
8383
],
8484
]);
8585

86-
asm(({ addScript, importScript }) => {
86+
asm(({ addScript, importScript, writeMappings }) => {
8787
addScript(`
8888
SonicMappingsVer := 2
8989
SonicDplcVer = 2
9090
`);
9191
importScript('MapMacros.asm');
9292

93-
// writeMappings(({ sprite }) => {
93+
writeMappings(({ label, sprites, renderHex }) => {
94+
const list = [];
9495

95-
// // write(dc.w, sprite.length);
96-
// // return ({ mapping }) => {
97-
// // write(nybble, mapping.size - 1);
98-
// // write(nybble * 3, mapping.art);
99-
// // };
100-
// });
96+
list.push(`${label}: mappingsTable`);
97+
sprites.forEach((_, i) => {
98+
list.push(`\tmappingsTableEntry.w\tMap_Sonic_${i}`);
99+
});
100+
list.push('');
101+
102+
sprites.forEach((sprite, i) => {
103+
list.push(`${label}_${i}:\tspriteHeader`);
104+
105+
sprite.mappings.forEach(mapping => {
106+
const pieceInfo = [
107+
mapping.left,
108+
mapping.top,
109+
mapping.width,
110+
mapping.height,
111+
mapping.art,
112+
mapping.hflip,
113+
mapping.vflip,
114+
mapping.palette,
115+
mapping.priority,
116+
].map(renderHex).join(', ');
117+
118+
list.push(` spritePiece ${pieceInfo}`);
119+
});
120+
121+
list.push(`${label}_${i}_End`);
122+
list.push('');
123+
});
124+
125+
list.push('\teven');
126+
127+
return list.join('\n');
128+
});
101129
});

0 commit comments

Comments
 (0)