Skip to content

Commit a844928

Browse files
committed
improved asm parsign
1 parent 99b7885 commit a844928

5 files changed

Lines changed: 44 additions & 19 deletions

File tree

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## Flex 2
2+
3+
Flex 2 is a multi-purpose art and mapping editor for the Sega Megadrive. The original Flex was a web app, which gave it several limitations. A full rewrite for desktop opens up the ability to use real project files, as well as various other niceties.
4+
5+
## UI
6+
7+
## Controls
8+
9+
### Inputs
10+
11+
## Mapping Editor
12+
13+
### Drawing Mode
14+
15+
## Palettes
16+
17+
## Sprites
18+
19+
## Importing
20+
21+
## DPLC Optimization
22+
23+
## Mapping Formats
24+
25+
## Download
26+
27+
https://github.com/kirjavascript/Flex2/releases

flex2.idea

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,18 @@ for_window [title="Flex 2"] floating enable border normal
1717
==
1818
V2: sprite rotation http://forums.sonicretro.org/index.php?showtopic=8848&st=0&p=159754&#entry159754
1919
https://yarnpkg.com/en/package/node-vibrant
20-
change sprite scroll speed Set sprite offset based on scroll to increase speed
20+
change sprite scroll speed
2121
drawing mode fill !
2222
S - scroll to sprite
23+
s3k sonic mapping definition / conversion tools
2324
==
2425

2526
check version in documentation tab (move code)
26-
logo
2727
add flex.json to sonic 2 disassembly
28-
counts for commands (wrap all in doAction, remove doAction from others)
29-
real command modes
3028
search (filter)
31-
have default as logo?
32-
input type = color
33-
lil-g/gemini
29+
logo / have default as logo?
30+
counts for commands
31+
real command modes
3432

3533
====
3634

modules/formats/asm.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export function asmToBin(buffer) {
1414

1515
// split into labels/data
1616
// double comment char used to indicate start of line
17-
const sections = (asm
17+
// add starting label to ensure all sections are accounted for
18+
const sections = (('__flex2__internal: \n' + asm)
1819
.replace(/^\S/gm, (d) => `;;${d}`)
1920
.replace(/\n/gm, '') + ';')
2021
.match(/;.*?:.*?;/g)
@@ -53,12 +54,13 @@ export function asmToBin(buffer) {
5354
if (~fragment.indexOf('-')) {
5455
// if data is calculated from labels
5556
const [lVal, rVal] = fragment.split('-');
56-
let pointer = (pointerMap[lVal] - pointerMap[rVal]);
57+
let pointer = (pointerMap[lVal]||0) - (pointerMap[rVal]||0);
5758
let pointerBytes = [];
5859
for (let i = 0; i < size; i++) {
5960
pointerBytes.unshift(pointer & 0xFF);
6061
pointer = pointer >> 8;
6162
}
63+
6264
bytes.push(...pointerBytes);
6365
}
6466
else {
@@ -75,23 +77,21 @@ export function asmToBin(buffer) {
7577
}
7678
});
7779

80+
7881
return bytes;
7982
}
8083

8184
export function stuffToAsm(frames, name, isMapping = false) {
8285
// get real mapping name
83-
const startLabel = name.replace(/[^\w]/g, '');
86+
const startLabel = name.replace(/[^\w]/g, '')
87+
|| 'DATA' + Math.random().toString(36).slice(2).toUpperCase();
8488

8589
let output = `; ${'='.repeat(80)}
8690
; Sprite ${isMapping?'Mappings' : 'DPLCs'} - generated by Flex 2 ${new Date()}
8791
; ${'='.repeat(80)}
8892
93+
${startLabel}:
8994
`;
90-
if (startLabel) {
91-
output += startLabel + ':\n';
92-
}
93-
94-
let mainLabel = startLabel || 'DATA' + Math.random().toString(36).slice(2).toUpperCase();
9595

9696
let dataOutput = '';
9797
let labels = [];
@@ -102,7 +102,7 @@ export function stuffToAsm(frames, name, isMapping = false) {
102102
label = 0;
103103
}
104104
else {
105-
label = `${mainLabel}_${index.toString(16).toUpperCase()}`;
105+
label = `${startLabel}_${index.toString(16).toUpperCase()}`;
106106
const [header, ...data] = arrays;
107107
// header
108108
dataOutput += `${label}: dc.b ${to68kByteStr(header)}\n`;
@@ -122,7 +122,7 @@ export function stuffToAsm(frames, name, isMapping = false) {
122122
chunk(labels, 2)
123123
.forEach((words) => {
124124
output += `\tdc.w ${words.map((word) => (
125-
word == 0 ? '$0' : `${word}-${mainLabel}`
125+
word == 0 ? '$0' : `${word}-${startLabel}`
126126
)).join`, `}\n`;
127127
});
128128

modules/formats/dplc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function bufferToDPLCs(buffer, format) {
2626
let sprites = [];
2727

2828
// prevent crashes from incorrectly read header
29-
if (dplcQty > 0xFF) return;
29+
if (dplcQty > 100) return;
3030

3131
for (let i = 0; i < dplcQty; i++) {
3232
// convert each line to a binary string to easily extract properties

modules/formats/mapping.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function bufferToMappings(buffer, format) {
2727

2828
let sprites = [];
2929

30-
if (mappingQty > 0xFF) return; // prevent crashes
30+
if (mappingQty > 100) return; // prevent crashes
3131

3232
for (let i = 0; i < mappingQty; i++) {
3333
// convert each line to a binary string to easily extract properties

0 commit comments

Comments
 (0)