// Original Coco 3 Plus contributions: Copyright (c) 2026 Brian K. Holman. // Original component notices/terms retained; see COPYRIGHT.md and LICENSING.md. // SPDX-License-Identifier: BSD-3-Clause // Instruction-boundary scheduler. icount_tick is PIC input clock /2. // Start-to-start intervals equal reported architectural cycles. An engine or // peripheral response that misses its deadline sets overrun and stops launches. // run may fall during a transaction; quiescent follows its completed budget. module ssc_tms7000_pacer(input wire clk,reset,run,icount_tick, input wire engine_done,input wire [6:0] engine_cycles, output reg step,output wire quiescent,output reg overrun); localparam [1:0] IDLE=0,EXECUTE=1,RELEASE=2,BUDGET=3; reg [1:0] state; reg [7:0] elapsed; reg [6:0] budget; wire [8:0] next_elapsed={1'b0,elapsed}+{8'd0,icount_tick}; assign quiescent=state==IDLE && !step; always @(posedge clk)begin if(reset)begin state<=IDLE;step<=0;overrun<=0;elapsed<=0;budget<=0;end else begin if(state!=IDLE && icount_tick && elapsed!=255)elapsed<=elapsed+8'd1; // A nonresponding bus must be observable even if engine_done never arrives. // Original instructions take at most49 icount ticks. Do not abort a captured // bus operation; latch the fault and require reset if it cannot complete. if(state==EXECUTE && next_elapsed>=9'd127)overrun<=1; case(state) IDLE:if(run && icount_tick && !overrun)begin step<=1;elapsed<=0;state<=EXECUTE;end EXECUTE:if(engine_done)begin step<=0;budget<=engine_cycles;state<=RELEASE; if(next_elapsed>={2'd0,engine_cycles})overrun<=1; end RELEASE:if(!engine_done)begin state<=BUDGET; if(next_elapsed>={2'd0,budget})overrun<=1; end BUDGET:if(icount_tick && next_elapsed>={2'd0,budget})begin if(run && !overrun)begin step<=1;elapsed<=0;state<=EXECUTE;end else state<=IDLE; end default:state<=IDLE; endcase end end endmodule