From eb30e5cf857af0b7fb68a574d5226a5fe8587064 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Sat, 19 Feb 2022 16:53:19 -0600 Subject: [PATCH] ecs: automatically init bss when 'start' event --- src/common/ecs/ecs.ts | 10 ++++++--- test/ecs/narrow1.txt | 11 ++++++++++ test/ecs/score.txt | 1 - test/ecs/sprites.txt | 1 - test/ecs/sprites1.txt | 1 - test/ecs/superman.txt | 1 - test/ecs/titles.ecs | 24 +++++++++++++++------- test/ecs/titles.txt | 47 +++++++++++++++++++++++++++++++------------ test/ecs/vcs1.ecs | 1 - test/ecs/vcs1.txt | 1 - test/ecs/vcslib.ecs | 1 - test/ecs/vcslib.txt | 1 - 12 files changed, 69 insertions(+), 31 deletions(-) diff --git a/src/common/ecs/ecs.ts b/src/common/ecs/ecs.ts index 7dd3226a..cd1e4cf6 100644 --- a/src/common/ecs/ecs.ts +++ b/src/common/ecs/ecs.ts @@ -865,9 +865,6 @@ class ActionEval { //this.used.add(`arg_${argindex}_${argvalue}`); return argvalue; } - __bss_init(args: string[]) { - return this.scope.allocateInitData(this.scope.bss); - } wrapCodeInLoop(code: string, action: ActionWithQuery, ents: Entity[], joinfield?: ComponentFieldPair): string { // TODO: check ents // TODO: check segment bounds @@ -1317,7 +1314,13 @@ export class EntityScope implements SourceLocated { this.eventSeq++; // generate code let code = ''; + // is there a label? generate it first if (codelabel) { code += this.dialect.label(codelabel) + '\n'; } + // if "start" event, initialize data segment + if (event == 'start') { + code += this.allocateInitData(this.bss); + } + // iterate all instances and generate matching events let eventCount = 0; let instances = this.instances.filter(inst => systems.includes(inst.system)); for (let inst of instances) { @@ -1446,6 +1449,7 @@ export class EntityScope implements SourceLocated { replaceSubroutines(code: string) { // TODO: bin-packing for critical code // TODO: doesn't work with nested subroutines? + // TODO: doesn't work between scopes let allsubs : string[] = []; for (let stats of Object.values(this.eventStats)) { if (stats.count > 1) { diff --git a/test/ecs/narrow1.txt b/test/ecs/narrow1.txt index 607f1529..3073830d 100644 --- a/test/ecs/narrow1.txt +++ b/test/ecs/narrow1.txt @@ -6,8 +6,19 @@ Xpos_x_b0: .res 1 .res 1 .code +Main__INITDATA: +.byte 0 +.byte 50 +.byte 100 +.byte 150 __Start: + ldy #4 +: lda Main__INITDATA-1,y + sta Xpos_x_b0-1,y + dey + bne :- + ;;; start action move 1 start ldx #0 diff --git a/test/ecs/score.txt b/test/ecs/score.txt index 93907dbb..a9470893 100644 --- a/test/ecs/score.txt +++ b/test/ecs/score.txt @@ -64,7 +64,6 @@ __BRK: sta BCDScore6_digits_b0-1,y dey bne :- - ; initialize data segment ;;; start action FrameLoop 1 start diff --git a/test/ecs/sprites.txt b/test/ecs/sprites.txt index 0f32e4f4..8a5f0186 100644 --- a/test/ecs/sprites.txt +++ b/test/ecs/sprites.txt @@ -131,7 +131,6 @@ __BRK: sta HasBitmap_bitmap_b0-1,y dey bne :- - ; initialize data segment ;;; start action FrameLoop 1 start diff --git a/test/ecs/sprites1.txt b/test/ecs/sprites1.txt index 254293c0..62363c54 100644 --- a/test/ecs/sprites1.txt +++ b/test/ecs/sprites1.txt @@ -131,7 +131,6 @@ __BRK: sta HasBitmap_bitmap_b0-1,y dey bne :- - ; initialize data segment ;;; start action FrameLoop 1 start diff --git a/test/ecs/superman.txt b/test/ecs/superman.txt index 5028993e..e798d8af 100644 --- a/test/ecs/superman.txt +++ b/test/ecs/superman.txt @@ -643,7 +643,6 @@ __BRK: sta Location_room_b0-1,y dey bne :- - ; initialize data segment ;;; start action FrameLoop 1 start diff --git a/test/ecs/titles.ecs b/test/ecs/titles.ecs index 6aa20261..70ab5e7a 100644 --- a/test/ecs/titles.ecs +++ b/test/ecs/titles.ecs @@ -86,7 +86,6 @@ demo TitleDemo system Advance on joybutton do once --- - FRAME_END jmp Title2__Start --- end @@ -166,19 +165,19 @@ demo TitleDemo entity [KernelSection, BGColor] const lines = 60 - const bgcolor = $50 + var bgcolor = 0x10 end entity [KernelSection, BGColor] const lines = 10 - const bgcolor = $52 + var bgcolor = 0x30 end // convert -size 48x -gravity center label:"6502\nECS" pbm: | pnmtopnm -plain entity [KernelSection, BGColor, PFColor, Bitmap48] const lines = 2 - const bgcolor = 0x54 - const pfcolor = 0xec + var pfcolor = 0xec + var bgcolor = 0x30 decode vcs_bitmap48 --- 000000000000000000000000000000000000000000011000 000000000000000000000000000000000000000000011000 @@ -229,14 +228,25 @@ demo TitleDemo entity [KernelSection, BGColor] const lines = 10 - const bgcolor = $52 + var bgcolor = 0x30 end entity [KernelSection, BGColor] const lines = 10 - const bgcolor = $50 + var bgcolor = 0x50 end +system Colors + on postframe do foreach [PFColor] +--- + inc {{set pfcolor}} + bne :+ + inc {{set bgcolor}} + inc {{set bgcolor}} +: +--- +end + end system Demo diff --git a/test/ecs/titles.txt b/test/ecs/titles.txt index fb3d4079..77aab5f8 100644 --- a/test/ecs/titles.txt +++ b/test/ecs/titles.txt @@ -12,7 +12,6 @@ __NMI: __Reset: __BRK: CLEAN_START - ; initialize data segment ;;; start action Demo 1 start @@ -500,7 +499,6 @@ StaticKernel__kernel__10____exit: ;;; start action Advance 5 joybutton - FRAME_END jmp Title2__Start ;;; end action Advance 5 joybutton @@ -519,6 +517,14 @@ JoyButton__postframe__18__NotPressed: Title__Start = Title::__Start .scope Title2 .zeropage +BGColor_bgcolor_b0: +.res 1 +.res 1 +.res 1 +.res 1 +.res 1 +PFColor_pfcolor_b0: +.res 1 TEMP: Kernel48Pixel__2__tmp: .res 1 @@ -530,14 +536,6 @@ KernelSection_lines_b0: .byte 2 .byte 10 .byte 10 -BGColor_bgcolor_b0: -.byte 80 -.byte 82 -.byte 84 -.byte 82 -.byte 80 -PFColor_pfcolor_b0: -.byte 236 Bitmap48_bitmap0_b0: .byte