ecs: C export if no system instances
This commit is contained in:
parent
73c74c519e
commit
d5460c991f
|
@ -417,6 +417,9 @@ export class Dialect_CA65 {
|
||||||
label(sym: string) {
|
label(sym: string) {
|
||||||
return `${sym}:`;
|
return `${sym}:`;
|
||||||
}
|
}
|
||||||
|
export(sym: string) {
|
||||||
|
return `.export _${sym} = ${sym}`;
|
||||||
|
}
|
||||||
byte(b: number | ConstByte | undefined) {
|
byte(b: number | ConstByte | undefined) {
|
||||||
if (b === undefined) {
|
if (b === undefined) {
|
||||||
return `.res 1`
|
return `.res 1`
|
||||||
|
@ -523,13 +526,15 @@ class DataSegment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dump(file: SourceFileExport, dialect: Dialect_CA65) {
|
dump(file: SourceFileExport, dialect: Dialect_CA65, doExport: boolean) {
|
||||||
// TODO: fewer lines
|
// TODO: fewer lines
|
||||||
for (let i = 0; i < this.size; i++) {
|
for (let i = 0; i < this.size; i++) {
|
||||||
let syms = this.ofs2sym.get(i);
|
let syms = this.ofs2sym.get(i);
|
||||||
if (syms) {
|
if (syms) {
|
||||||
for (let sym of syms)
|
for (let sym of syms) {
|
||||||
|
if (doExport) file.line(dialect.export(sym)); // TODO: this is a hack for C export
|
||||||
file.line(dialect.label(sym));
|
file.line(dialect.label(sym));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
file.line(dialect.byte(this.initdata[i]));
|
file.line(dialect.byte(this.initdata[i]));
|
||||||
}
|
}
|
||||||
|
@ -1683,13 +1688,15 @@ export class EntityScope implements SourceLocated {
|
||||||
this.allocateSegment(this.rodata, false, 'const'); // constants
|
this.allocateSegment(this.rodata, false, 'const'); // constants
|
||||||
this.allocateROData(this.rodata);
|
this.allocateROData(this.rodata);
|
||||||
}
|
}
|
||||||
|
private isMainScope() {
|
||||||
|
return this.parent == null;
|
||||||
|
}
|
||||||
private generateCode() {
|
private generateCode() {
|
||||||
this.eventSeq = 0;
|
this.eventSeq = 0;
|
||||||
this.eventCodeStats = {};
|
this.eventCodeStats = {};
|
||||||
let isMainScope = this.parent == null;
|
|
||||||
let start;
|
let start;
|
||||||
let initsys = this.em.getSystemByName('Init');
|
let initsys = this.em.getSystemByName('Init');
|
||||||
if (isMainScope && initsys) {
|
if (this.isMainScope() && initsys) {
|
||||||
this.newSystemInstanceWithDefaults(initsys); //TODO: what if none?
|
this.newSystemInstanceWithDefaults(initsys); //TODO: what if none?
|
||||||
start = this.generateCodeForEvent('main_init');
|
start = this.generateCodeForEvent('main_init');
|
||||||
} else {
|
} else {
|
||||||
|
@ -1759,12 +1766,13 @@ export class EntityScope implements SourceLocated {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private dumpCodeTo(file: SourceFileExport) {
|
private dumpCodeTo(file: SourceFileExport) {
|
||||||
|
let shouldExport = this.instances.length == 0;
|
||||||
let dialect = this.dialect;
|
let dialect = this.dialect;
|
||||||
file.line(dialect.startScope(this.name));
|
file.line(dialect.startScope(this.name));
|
||||||
file.line(dialect.segment('bss'));
|
file.line(dialect.segment('bss'));
|
||||||
this.bss.dump(file, dialect);
|
this.bss.dump(file, dialect, shouldExport);
|
||||||
file.line(dialect.segment('code')); // TODO: rodata for aligned?
|
file.line(dialect.segment('code')); // TODO: rodata for aligned?
|
||||||
this.rodata.dump(file, dialect);
|
this.rodata.dump(file, dialect, shouldExport);
|
||||||
//file.segment(`${this.name}_CODE`, 'code');
|
//file.segment(`${this.name}_CODE`, 'code');
|
||||||
file.line(dialect.label('__Start'));
|
file.line(dialect.label('__Start'));
|
||||||
this.code.dump(file);
|
this.code.dump(file);
|
||||||
|
|
|
@ -1,21 +1,27 @@
|
||||||
.scope Main
|
.scope Main
|
||||||
.zeropage
|
.zeropage
|
||||||
.code
|
.code
|
||||||
|
.export _Room_fgcolor_b0 = Room_fgcolor_b0
|
||||||
Room_fgcolor_b0:
|
Room_fgcolor_b0:
|
||||||
.byte 12
|
.byte 12
|
||||||
.byte 12
|
.byte 12
|
||||||
|
.export _Room_bgcolor_b0 = Room_bgcolor_b0
|
||||||
Room_bgcolor_b0:
|
Room_bgcolor_b0:
|
||||||
.byte 18
|
.byte 18
|
||||||
.byte 18
|
.byte 18
|
||||||
|
.export _Room_north_b0 = Room_north_b0
|
||||||
Room_north_b0:
|
Room_north_b0:
|
||||||
.byte 0
|
.byte 0
|
||||||
.byte 0
|
.byte 0
|
||||||
|
.export _Room_east_b0 = Room_east_b0
|
||||||
Room_east_b0:
|
Room_east_b0:
|
||||||
.byte 1
|
.byte 1
|
||||||
.byte 0
|
.byte 0
|
||||||
|
.export _Room_south_b0 = Room_south_b0
|
||||||
Room_south_b0:
|
Room_south_b0:
|
||||||
.byte 0
|
.byte 0
|
||||||
.byte 0
|
.byte 0
|
||||||
|
.export _Room_west_b0 = Room_west_b0
|
||||||
Room_west_b0:
|
Room_west_b0:
|
||||||
.byte 0
|
.byte 0
|
||||||
.byte 1
|
.byte 1
|
||||||
|
|
Loading…
Reference in New Issue