From 6f5a36a6474b4cb9fb6b32399542bd4e9b4bd271 Mon Sep 17 00:00:00 2001 From: Thomas Ball Date: Tue, 25 Nov 2025 10:23:42 -0800 Subject: [PATCH 1/2] careful on switching pages --- interpreter.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/interpreter.ts b/interpreter.ts index 5fea5c5e..b6d80a90 100644 --- a/interpreter.ts +++ b/interpreter.ts @@ -496,12 +496,20 @@ namespace microcode { } private switchPage(page: number) { + // need to make sure outstanding events are dropped and no new events + this.eventQueue = [] + this.allowEvents = false + // now stop existing rules this.stopAllRules() // set up new rule closures this.currentPage = page this.program.pages[this.currentPage].rules.forEach((r, index) => { this.ruleClosures.push(new RuleClosure(index, r, this)) }) + // start up timer-based rules (should these be events as well?) + this.ruleClosures.forEach(rc => rc.start(true)) + // restart events + this.allowEvents = true this.addEvent({ kind: MicroCodeEventKind.StartPage, } as StartPageEvent) @@ -510,15 +518,15 @@ namespace microcode { kind: MicroCodeEventKind.StateUpdate, updatedVars: Object.keys(vars2tids), } as StateUpdateEvent) - // start up timer-based rules - this.ruleClosures.forEach(rc => rc.start(true)) } public runAction(ruleIndex: number, action: Tile, param: any) { switch (action) { case Tid.TID_ACTUATOR_SWITCH_PAGE: + // no switch if no param if (param) { - // no switch if no param + // when switching, drop any outstanding events + this.eventQueue = [] this.addEvent({ kind: MicroCodeEventKind.SwitchPage, index: param, @@ -619,10 +627,11 @@ namespace microcode { }) } + private allowEvents = false private eventQueueActive = false private eventQueue: MicroCodeEvent[] = [] public addEvent(event: MicroCodeEvent) { - if (!this.running) return + if (!this.running || !this.allowEvents) return this.eventQueue.push(event) } From bb66d5b0c858effa2831e18db43f3c6a0eef16e7 Mon Sep 17 00:00:00 2001 From: Thomas Ball Date: Fri, 28 Nov 2025 17:05:33 -0800 Subject: [PATCH 2/2] fix up switch page logic --- interpreter.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/interpreter.ts b/interpreter.ts index b6d80a90..7a6223b2 100644 --- a/interpreter.ts +++ b/interpreter.ts @@ -291,11 +291,12 @@ namespace microcode { return undefined } - public runInstant() { + public runInstant(): boolean { const actuator = this.rule.actuators[0] const param = this.getParamInstant() - this.interp.runAction(this.index, actuator, param) + const ok = this.interp.runAction(this.index, actuator, param) this.kill() + return ok } private runAction() { @@ -520,9 +521,9 @@ namespace microcode { } as StateUpdateEvent) } - public runAction(ruleIndex: number, action: Tile, param: any) { + public runAction(ruleIndex: number, action: Tile, param: any): boolean { switch (action) { - case Tid.TID_ACTUATOR_SWITCH_PAGE: + case Tid.TID_ACTUATOR_SWITCH_PAGE: { // no switch if no param if (param) { // when switching, drop any outstanding events @@ -531,17 +532,21 @@ namespace microcode { kind: MicroCodeEventKind.SwitchPage, index: param, } as SwitchPageEvent) + return true } - return + return false + } case Tid.TID_ACTUATOR_CUP_X_ASSIGN: case Tid.TID_ACTUATOR_CUP_Y_ASSIGN: - case Tid.TID_ACTUATOR_CUP_Z_ASSIGN: + case Tid.TID_ACTUATOR_CUP_Z_ASSIGN: { const varName = getParam(action) this.updateState(ruleIndex, varName, param) - return + return true + } default: this.host.execute(action as ActionTid, param) } + return true } private updateState(ruleIndex: number, varName: string, v: number) { @@ -610,8 +615,7 @@ namespace microcode { rc => rc.getOutputResource() == OutputResource.PageCounter ) if (switchPage) { - switchPage.runInstant() - return // others don't get chance to run + if (switchPage.runInstant()) return // others don't get chance to run } const takesTime = live.filter(