-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1240 from ogamespec/master
Core6502 decoder.v
- Loading branch information
Showing
6 changed files
with
365 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.csv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
iverilog -D ICARUS -o decoder_test.run ../../../Common/*.v ../../../Core6502/*.v decoder_test.v | ||
vvp decoder_test.run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Go through all 6502 decoder values and output them to CSV. | ||
|
||
`timescale 1ns/1ns | ||
|
||
module Decoder_Run (); | ||
|
||
reg CLK; | ||
integer f; | ||
|
||
always #1 CLK = ~CLK; | ||
|
||
reg [13:0] Decoder_cnt; // The counter acts as an enumerator for all decoder inputs | ||
|
||
wire [129:0] Decoder_out; | ||
|
||
wire n_T0; | ||
wire n_T1X; | ||
wire n_T2; | ||
wire n_T3; | ||
wire n_T4; | ||
wire n_T5; | ||
wire IR01; | ||
wire [7:0] IR; | ||
|
||
// Assign the decoder inputs. | ||
// The lower six bits represent the Tx. The remaining high bits are IR. | ||
|
||
assign n_T0 = ~Decoder_cnt[0]; | ||
assign n_T1X = ~Decoder_cnt[1]; | ||
assign n_T2 = ~Decoder_cnt[2]; | ||
assign n_T3 = ~Decoder_cnt[3]; | ||
assign n_T4 = ~Decoder_cnt[4]; | ||
assign n_T5 = ~Decoder_cnt[5]; | ||
assign IR = Decoder_cnt[13:6]; | ||
assign IR01 = IR[0]|IR[1]; | ||
|
||
Decoder dec ( | ||
.n_T0(n_T0), .n_T1X(n_T1X), | ||
.n_T2(n_T2), .n_T3(n_T3), .n_T4(n_T4), .n_T5(n_T5), | ||
.IR01(IR01), | ||
.IR(IR), .n_IR(~IR), | ||
.X(Decoder_out) ); | ||
|
||
always @(posedge CLK) begin | ||
$fwrite (f, "%b,%b\n", Decoder_cnt, Decoder_out); | ||
Decoder_cnt = Decoder_cnt + 1; | ||
end | ||
|
||
initial begin | ||
|
||
$dumpfile("decoder_test.vcd"); | ||
$dumpvars(0, Decoder_Run); | ||
|
||
f = $fopen("decoder_6502.csv","w"); | ||
$fwrite(f, "inputs,outputs\n"); | ||
|
||
Decoder_cnt <= 0; | ||
CLK <= 1'b0; | ||
|
||
repeat (1<<14) @ (posedge CLK); | ||
$fclose (f); | ||
$finish; | ||
end | ||
|
||
endmodule // Decoder_Run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
''' | ||
Script for automatic generation of NOR decoders. | ||
''' | ||
|
||
import os | ||
import sys | ||
|
||
def Main (decoder_txt): | ||
print (f"Using {decoder_txt} as bitmask"); | ||
|
||
bitmask_dump = open(decoder_txt, 'r') | ||
lines = bitmask_dump.readlines() | ||
|
||
decoder_out = 0 | ||
for line in lines: | ||
decoder_in = 0 | ||
first = True | ||
print (f"assign dec_out[{decoder_out}] = ~|{{", end = '') # Reducing nor | ||
for bit in line[::-1]: # msb first in input vector, need to reverse string | ||
if (bit == '0' or bit == '1'): | ||
if (bit == '1'): | ||
if (not first): print (",", end = '') | ||
print (f"d[{decoder_in}]", end = '') | ||
first = False | ||
decoder_in += 1 | ||
print ("};") | ||
decoder_out += 1 | ||
|
||
if __name__ == '__main__': | ||
if (len(sys.argv) < 2): | ||
print ("Use: python3 decoder.py <decoder.txt>") | ||
else: | ||
Main(sys.argv[1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
000101100000100100000 | ||
000000010110001000100 | ||
000000011010001001000 | ||
010100011001100100000 | ||
010101011010100100000 | ||
010110000001100100000 | ||
000000100010000001000 | ||
000001000000100010000 | ||
000000010101001001000 | ||
010101011001100010000 | ||
010110011001100010000 | ||
011010000001100100000 | ||
000101000000100010000 | ||
010101011010100010000 | ||
011001000000100010000 | ||
100110011001100010000 | ||
101010011001100100000 | ||
011001011010100010000 | ||
100100011001100100000 | ||
011001100000100100000 | ||
011001000001100100000 | ||
011001010101010100000 | ||
000101010101010100001 | ||
010100011001010100000 | ||
001010010101010100010 | ||
001000011001010100100 | ||
000110010101010100001 | ||
001010000000010010000 | ||
000000000000000001000 | ||
010110000000011000000 | ||
000010101001010100000 | ||
000000101001000001000 | ||
010101000000011000000 | ||
000000000100000001000 | ||
010000000000000000000 | ||
000000010001010101000 | ||
000000000001010100100 | ||
000001010101010100010 | ||
000110010101010100010 | ||
000000010101001000100 | ||
000000010110001000010 | ||
000000010110001001000 | ||
000000001010000000100 | ||
001000011001010100000 | ||
001010000000100010000 | ||
000000010101001000010 | ||
000000010110001000100 | ||
000010010101010100000 | ||
001001010101010101000 | ||
010010000001100100000 | ||
010110000000101000000 | ||
011010000000101000000 | ||
011010000000001000000 | ||
001001000000010010000 | ||
000010101001010100100 | ||
000001000000010010000 | ||
001001010101010100001 | ||
000000010001010101000 | ||
010101011010100100000 | ||
100000000000011000000 | ||
101010000000001000000 | ||
100000011001010010000 | ||
010101011001100010000 | ||
011010011001010100000 | ||
011001000000101000000 | ||
010000000000001000000 | ||
011001011001100100000 | ||
010000011001010010000 | ||
011001011001100010000 | ||
011001100001010100000 | ||
011001000000011000000 | ||
000000001010000000010 | ||
000000010110001000001 | ||
010000010110000100000 | ||
000110011001010101000 | ||
010010011001010010000 | ||
000010000000010010000 | ||
000101010101010101000 | ||
001001010101010100100 | ||
000101000000101000000 | ||
000000010110000101000 | ||
000000100100000001000 | ||
000000010100001001000 | ||
000000001000000001000 | ||
001010010101010100001 | ||
000000000000000000010 | ||
000000000000000000100 | ||
010100010101010100000 | ||
010010101001010100000 | ||
000000010101001000001 | ||
000000001000000000100 | ||
000000010110001000010 | ||
000000001010000000100 | ||
000000010110000100100 | ||
000100010101010100000 | ||
001001010101010100000 | ||
000010101001010100000 | ||
000101000000100000000 | ||
000101010101010100010 | ||
000101011001010101000 | ||
000100011001010101000 | ||
000010101001010100010 | ||
000010010101010100001 | ||
001001010101010100001 | ||
000110101001010101000 | ||
001000011001010100100 | ||
000010000000000010000 | ||
000001000000010010000 | ||
010010011010010100000 | ||
101001100001010100000 | ||
010001011010010100000 | ||
000000100110000000100 | ||
101010000000001000000 | ||
011001100001010100000 | ||
011001011001010100000 | ||
000110010101010100010 | ||
100110000000101000000 | ||
100010101001100100000 | ||
100001011001010010000 | ||
100010000101100100000 | ||
010010011010100100000 | ||
000001000000000000000 | ||
000000101001000000100 | ||
000000100101000001000 | ||
000000010100001000001 | ||
000000001010000000010 | ||
000000000000010000000 | ||
001001011010100100000 | ||
000000011000000000000 | ||
000000011001010100000 |