@@ -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
8184export 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
0 commit comments