ecs: automatically init bss when 'start' event

This commit is contained in:
Steven Hugg 2022-02-19 16:53:19 -06:00
parent d96296675b
commit eb30e5cf85
12 changed files with 69 additions and 31 deletions

View File

@ -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) {

View File

@ -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

View File

@ -64,7 +64,6 @@ __BRK:
sta BCDScore6_digits_b0-1,y
dey
bne :-
; initialize data segment
;;; start action FrameLoop 1 start

View File

@ -131,7 +131,6 @@ __BRK:
sta HasBitmap_bitmap_b0-1,y
dey
bne :-
; initialize data segment
;;; start action FrameLoop 1 start

View File

@ -131,7 +131,6 @@ __BRK:
sta HasBitmap_bitmap_b0-1,y
dey
bne :-
; initialize data segment
;;; start action FrameLoop 1 start

View File

@ -643,7 +643,6 @@ __BRK:
sta Location_room_b0-1,y
dey
bne :-
; initialize data segment
;;; start action FrameLoop 1 start

View File

@ -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

View File

@ -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 <Bitmap48_bitmap0_e2_b0
Bitmap48_bitmap0_b8:
@ -834,8 +832,21 @@ Bitmap48_bitmap5_e2_b0:
.byte 24
Bitmap48_height_b0:
.byte 43
Title2__INITDATA:
.byte 16
.byte 48
.byte 48
.byte 48
.byte 80
.byte 236
__Start:
ldy #6
: lda Title2__INITDATA-1,y
sta BGColor_bgcolor_b0-1,y
dey
bne :-
;;; start action FrameLoop 1 start
FrameLoop__start__20__NextFrame:
@ -854,7 +865,7 @@ FrameLoop__start__20__NextFrame:
;;; start action StaticKernel 3 kernelsetup
lda #80
lda BGColor_bgcolor_b0
sta COLUBK
;;; end action StaticKernel 3 kernelsetup
@ -924,7 +935,7 @@ Kernel48Pixel__kernelsetup__28____skipxhi:
cpx #2
jcc Kernel48Pixel__kernelsetup__29____skipxlo
lda #236
lda PFColor_pfcolor_b0
sta COLUP0
sta COLUP1
@ -949,7 +960,7 @@ Kernel48Pixel__kernelsetup__29____skipxhi:
cpx #2
jcc StaticKernel__kernelsetup__31____skipxlo
lda #236
lda PFColor_pfcolor_b0
sta COLUPF
StaticKernel__kernelsetup__31____skipxlo:
@ -1024,6 +1035,16 @@ StaticKernel__kernel__27____exit:
KERNEL_END
;;; start action Colors 4 postframe
inc PFColor_pfcolor_b0
bne :+
inc BGColor_bgcolor_b0+2
inc BGColor_bgcolor_b0+2
:
;;; end action Colors 4 postframe
FRAME_END
jmp FrameLoop__start__20__NextFrame ; loop to next frame

View File

@ -10,7 +10,6 @@ __NMI:
__Reset:
__BRK:
CLEAN_START
{{bss_init}} ; initialize data segment
{{!start}} ; start main routine
.segment "VECTORS"
Return: .word $6060

View File

@ -59,7 +59,6 @@ __BRK:
sta PFColor_pfcolor_b0-1,y
dey
bne :-
; initialize data segment
;;; start action FrameLoop 1 start

View File

@ -11,7 +11,6 @@ __NMI:
__Reset:
__BRK:
CLEAN_START
{{bss_init}} ; initialize data segment
{{!start}} ; start main routine
.segment "VECTORS"
Return: .word $6060

View File

@ -60,7 +60,6 @@ __BRK:
sta PFColor_pfcolor_b0-1,y
dey
bne :-
; initialize data segment
;;; start action FrameLoop 1 start