Skip to content

Commit 03fd7f7

Browse files
committed
Added E clock falling / rising edge signals
Some code clean up
1 parent dde3889 commit 03fd7f7

1 file changed

Lines changed: 106 additions & 59 deletions

File tree

fx68k.sv

Lines changed: 106 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,44 @@ import fx68k_pkg::*;
2222

2323
module fx68k
2424
(
25-
input clk,
26-
input HALTn, // Used for single step only. Force high if not used
27-
// input logic HALTn = 1'b1, // Not all tools support default port values
28-
25+
input clk, // Master clock
26+
input enPhi1, // Clock enable : next cycle is PHI1 (clock rising edge)
27+
input enPhi2, // Clock enable : next cycle is PHI2 (clock falling edge)
28+
29+
input HALTn, // Used for single step only. Force high if not used
2930
// These two signals don't need to be registered. They are not async reset.
30-
input extReset, // External sync reset on emulated system
31-
input pwrUp, // Asserted together with reset on emulated system coldstart
32-
input enPhi1, enPhi2, // Clock enables. Next cycle is PHI1 or PHI2
33-
34-
output eRWn, output ASn, output LDSn, output UDSn,
35-
output logic E, output VMAn,
36-
output FC0, output FC1, output FC2,
37-
output BGn,
38-
output oRESETn, output oHALTEDn,
39-
input DTACKn, input VPAn,
40-
input BERRn,
41-
input BRn, BGACKn,
42-
input IPL0n, input IPL1n, input IPL2n,
43-
input [15:0] iEdb, output [15:0] oEdb,
31+
input extReset, // External sync reset on emulated system
32+
input pwrUp, // Asserted together with reset on emulated system coldstart
33+
output oRESETn,
34+
output oHALTEDn,
35+
// 6800 peripheral access
36+
output logic E, // E clock
37+
output E_rise, // E clock rising edge
38+
output E_fall, // E clock falling edge
39+
input VPAn, // Valid peripheral address
40+
output VMAn, // Valid memory address
41+
// Control signals
42+
output ASn, // Address strobe
43+
output eRWn, // Read (1) / Write (0)
44+
output LDSn, // Lower data strobe
45+
output UDSn, // Upper data strobe
46+
output FC2, // Function code
47+
output FC1,
48+
output FC0,
49+
input DTACKn, // Data acknowledge
50+
input BERRn, // Bus error
51+
// Bus cycles stealing
52+
input BRn, // Bus request
53+
output BGn, // Bus granted
54+
input BGACKn, // Bus granted acknowledge
55+
// Interrupts requests
56+
input IPL2n, // Interrupt level
57+
input IPL1n,
58+
input IPL0n,
59+
// Data bus
60+
input [15:0] iEdb,
61+
output [15:0] oEdb,
62+
// Address bus
4463
output [31:1] eab
4564
);
4665

@@ -418,7 +437,7 @@ module fx68k
418437

419438
// E clock and counter, VMA
420439
reg [3:0] eCntr;
421-
reg rVma;
440+
reg rVma;
422441

423442
assign VMAn = rVma;
424443

@@ -432,24 +451,24 @@ module fx68k
432451
eCntr <= 4'd0;
433452
rVma <= 1'b1;
434453
end
454+
455+
// Cycles counter
435456
if (Clks.enPhi2) begin
436-
if (eCntr == 4'd9)
437-
E <= 1'b0;
438-
else if (eCntr == 4'd5)
439-
E <= 1'b1;
440-
441-
if (eCntr == 4'd9)
442-
eCntr <= 4'd0;
443-
else
444-
eCntr <= eCntr + 4'd1;
457+
eCntr <= (eCntr == 4'd9) ? 4'd0 : eCntr + 4'd1;
445458
end
459+
460+
// E clock generation
461+
E <= (E | E_rise) & ~E_fall;
446462

447463
if (Clks.enPhi2 & addrOe & ~Vpai & (eCntr == 4'd3))
448464
rVma <= 1'b0;
449465
else if (Clks.enPhi1 & eCntr == 4'd0)
450466
rVma <= 1'b1;
451467
end
452468

469+
assign E_rise = (eCntr == 4'd5) ? Clks.enPhi2 : 1'b0;
470+
assign E_fall = (eCntr == 4'd9) ? Clks.enPhi2 : 1'b0;
471+
453472
always_ff @(posedge clk) begin
454473

455474
// This timing is critical to stop the clock phases at the exact point on bus/addr error.
@@ -1480,7 +1499,7 @@ localparam
14801499
end
14811500
end
14821501

1483-
assign eab = aob[31:1];
1502+
assign eab = aob[31:1];
14841503
assign aob0 = aob[0];
14851504

14861505
// AU
@@ -2751,31 +2770,48 @@ endmodule
27512770
//
27522771

27532772
`ifdef FX68K_TEST
2754-
module fx68kTop( input clk32,
2755-
input extReset,
2756-
// input pwrUp,
2757-
2758-
input DTACKn, input VPAn,
2759-
input BERRn,
2760-
input BRn, BGACKn,
2761-
input IPL0n, input IPL1n, input IPL2n,
2762-
input [15:0] iEdb,
2763-
2773+
module fx68kTop
2774+
(
2775+
input clk32,
2776+
input extReset,
2777+
output oRESETn,
2778+
output oHALTEDn,
2779+
//
2780+
output E,
2781+
output E_rise,
2782+
output E_fall,
2783+
input VPAn,
2784+
output VMAn,
2785+
//
2786+
output ASn,
2787+
output eRWn,
2788+
output LDSn,
2789+
output UDSn,
2790+
output FC2,
2791+
output FC1,
2792+
output FC0,
2793+
input DTACKn,
2794+
input BERRn,
2795+
//
2796+
input BRn,
2797+
output BGn,
2798+
input BGACKn,
2799+
//
2800+
input IPL2n,
2801+
input IPL1n,
2802+
input IPL0n,
2803+
//
2804+
input [15:0] iEdb,
27642805
output [15:0] oEdb,
2765-
output eRWn, output ASn, output LDSn, output UDSn,
2766-
output logic E, output VMAn,
2767-
output FC0, output FC1, output FC2,
2768-
output BGn,
2769-
output oRESETn, output oHALTEDn,
27702806
output [31:1] eab
2771-
);
2807+
);
27722808

27732809
// Clock must be at least twice the desired frequency. A 32 MHz clock means a maximum 16 MHz effective frequency.
27742810
// In this example we divide the clock by 4. Resulting on an effective processor running at 8 MHz.
27752811

2776-
reg [1:0] clkDivisor = '0;
2812+
reg [1:0] clkDivisor = 2'd0;
27772813
always @( posedge clk32) begin
2778-
clkDivisor <= clkDivisor + 1'b1;
2814+
clkDivisor <= clkDivisor + 2'd1;
27792815
end
27802816

27812817
/*
@@ -2784,23 +2820,34 @@ module fx68kTop( input clk32,
27842820
There can be any number of cycles, or none, even variable non constant cycles, between each pulse.
27852821
*/
27862822

2787-
wire enPhi1 = (clkDivisor == 2'b11);
2788-
wire enPhi2 = (clkDivisor == 2'b01);
2789-
2823+
wire enPhi1 = (clkDivisor == 2'd3) ? 1'b1 : 1'b0;
2824+
wire enPhi2 = (clkDivisor == 2'd1) ? 1'b1 : 1'b0;
27902825

2791-
fx68k fx68k( .clk( clk32),
2792-
.extReset, .pwrUp( extReset), .enPhi1, .enPhi2,
27932826

2794-
.DTACKn, .VPAn, .BERRn, .BRn, .BGACKn,
2827+
fx68k fx68k
2828+
(
2829+
.clk (clk32),
2830+
.enPhi1,
2831+
.enPhi2,
2832+
2833+
.extReset,
2834+
.pwrUp (extReset),
2835+
.oRESETn, .oHALTEDn,
2836+
2837+
.E, .E_rise, .E_fall,
2838+
.VPAn, .VMAn,
2839+
2840+
.ASn, .eRWn, .LDSn, .UDSn,
2841+
.FC2, .FC1, .FC0,
2842+
.DTACKn, .BERRn,
2843+
2844+
.BRn, .BGn, .BGACKn,
27952845
.IPL0n, .IPL1n, .IPL2n,
2846+
27962847
.iEdb,
2797-
27982848
.oEdb,
2799-
.eRWn, .ASn, .LDSn, .UDSn,
2800-
.E, .VMAn,
2801-
.FC0, .FC1, .FC2,
2802-
.BGn,
2803-
.oRESETn, .oHALTEDn, .eab);
2849+
.eab
2850+
);
28042851

28052852
endmodule
28062853
`endif

0 commit comments

Comments
 (0)