mirror of
https://github.com/hoglet67/AtomBusMon.git
synced 2024-09-27 03:54:45 +00:00
R65C02: Whitespace only
Change-Id: I19aa6962d48206dc0eb75cabfa9f230e8872822d
This commit is contained in:
parent
709c73999b
commit
839d510af9
@ -48,9 +48,6 @@ end R65C02;
|
||||
|
||||
architecture Behavioral of R65C02 is
|
||||
|
||||
-- signal counter : unsigned(27 downto 0);
|
||||
-- signal mask_irq : std_logic;
|
||||
-- signal mask_enable : std_logic;
|
||||
-- Statemachine
|
||||
|
||||
type cpuCycles is (
|
||||
@ -74,16 +71,18 @@ architecture Behavioral of R65C02 is
|
||||
cycleJump, -- Last cycle of Jsr, Jmp. Next fetch address is target addr.
|
||||
cycleEnd
|
||||
);
|
||||
|
||||
signal theCpuCycle : cpuCycles;
|
||||
signal nextCpuCycle : cpuCycles;
|
||||
signal updateRegisters : boolean;
|
||||
signal processIrq : std_logic;
|
||||
signal nmiReg: std_logic;
|
||||
signal nmiEdge: std_logic;
|
||||
signal nmiReg : std_logic;
|
||||
signal nmiEdge : std_logic;
|
||||
signal irqReg : std_logic; -- Delay IRQ input with one clock cycle.
|
||||
signal soReg : std_logic; -- SO pin edge detection
|
||||
|
||||
-- Opcode decoding
|
||||
|
||||
constant opcUpdateA : integer := 0;
|
||||
constant opcUpdateX : integer := 1;
|
||||
constant opcUpdateY : integer := 2;
|
||||
@ -112,7 +111,6 @@ architecture Behavioral of R65C02 is
|
||||
constant opcRti : integer := 24;
|
||||
constant opcIRQ : integer := 25;
|
||||
|
||||
|
||||
constant opcInA : integer := 26;
|
||||
constant opcInBrk : integer := 27;
|
||||
constant opcInX : integer := 28;
|
||||
@ -129,7 +127,7 @@ architecture Behavioral of R65C02 is
|
||||
constant aluMode2From : integer := 38;
|
||||
--
|
||||
constant aluMode2To : integer := 40;
|
||||
--
|
||||
|
||||
constant opcInCmp : integer := 41;
|
||||
constant opcInCpx : integer := 42;
|
||||
constant opcInCpy : integer := 43;
|
||||
@ -200,8 +198,6 @@ architecture Behavioral of R65C02 is
|
||||
constant rts : addrDef := "0000101000100100";
|
||||
constant rti : addrDef := "0000111000100010";
|
||||
constant brk : addrDef := "1000111000000001";
|
||||
-- constant irq : addrDef := "0000111000000001";
|
||||
-- constant : unsigned(0 to 0) := "0";
|
||||
constant xxxxxxxx : addrDef := "----------0---00";
|
||||
|
||||
-- A = accu
|
||||
@ -259,9 +255,7 @@ architecture Behavioral of R65C02 is
|
||||
constant aluModeOra : aluMode2 := "101";
|
||||
constant aluModeEor : aluMode2 := "110";
|
||||
constant aluModeNoF : aluMode2 := "111";
|
||||
--aluModeBRK
|
||||
--constant aluBrk : aluMode := aluModeBRK & aluModePss & "---";
|
||||
--constant aluFix : aluMode := aluModeInp & aluModeNoF & "---";
|
||||
|
||||
constant aluInp : aluMode := aluModeInp & aluModePss & "---";
|
||||
constant aluP : aluMode := aluModeP & aluModePss & "---";
|
||||
constant aluInc : aluMode := aluModeInc & aluModePss & "---";
|
||||
@ -285,14 +279,15 @@ architecture Behavioral of R65C02 is
|
||||
|
||||
constant aluXXX : aluMode := (others => '-');
|
||||
|
||||
|
||||
-- Stack operations. Push/Pop/None
|
||||
constant stackInc : unsigned(0 to 0) := "0";
|
||||
constant stackDec : unsigned(0 to 0) := "1";
|
||||
constant stackXXX : unsigned(0 to 0) := "-";
|
||||
|
||||
subtype decodedBitsDef is unsigned(0 to 43);
|
||||
|
||||
type opcodeInfoTableDef is array(0 to 255) of decodedBitsDef;
|
||||
|
||||
constant opcodeInfoTable : opcodeInfoTableDef := (
|
||||
-- +------- Update register A
|
||||
-- |+------ Update register X
|
||||
@ -595,6 +590,7 @@ architecture Behavioral of R65C02 is
|
||||
nextAddrStack,
|
||||
nextAddrRelative
|
||||
);
|
||||
|
||||
signal nextAddr : nextAddrDef;
|
||||
signal myAddr : unsigned(15 downto 0);
|
||||
signal myAddrIncr : unsigned(15 downto 0);
|
||||
@ -607,19 +603,19 @@ architecture Behavioral of R65C02 is
|
||||
-- Buffer register
|
||||
signal T : unsigned(7 downto 0);
|
||||
-- General registers
|
||||
signal A: unsigned(7 downto 0); -- Accumulator
|
||||
signal X: unsigned(7 downto 0); -- Index X
|
||||
signal Y: unsigned(7 downto 0); -- Index Y
|
||||
signal S: unsigned(7 downto 0); -- stack pointer
|
||||
signal A : unsigned(7 downto 0); -- Accumulator
|
||||
signal X : unsigned(7 downto 0); -- Index X
|
||||
signal Y : unsigned(7 downto 0); -- Index Y
|
||||
signal S : unsigned(7 downto 0); -- stack pointer
|
||||
-- Status register
|
||||
signal C: std_logic; -- Carry
|
||||
signal Z: std_logic; -- Zero flag
|
||||
signal I: std_logic; -- Interrupt flag
|
||||
signal D: std_logic; -- Decimal mode
|
||||
signal B: std_logic; -- Break software interrupt
|
||||
signal R: std_logic; -- always 1
|
||||
signal V: std_logic; -- Overflow
|
||||
signal N: std_logic; -- Negative
|
||||
signal C : std_logic; -- Carry
|
||||
signal Z : std_logic; -- Zero flag
|
||||
signal I : std_logic; -- Interrupt flag
|
||||
signal D : std_logic; -- Decimal mode
|
||||
signal B : std_logic; -- Break software interrupt
|
||||
signal R : std_logic; -- always 1
|
||||
signal V : std_logic; -- Overflow
|
||||
signal N : std_logic; -- Negative
|
||||
|
||||
-- ALU
|
||||
-- ALU input
|
||||
@ -632,12 +628,13 @@ architecture Behavioral of R65C02 is
|
||||
signal aluZ : std_logic;
|
||||
signal aluV : std_logic;
|
||||
signal aluN : std_logic;
|
||||
|
||||
-- Indexing
|
||||
signal indexOut : unsigned(8 downto 0);
|
||||
|
||||
signal realbrk : std_logic;
|
||||
begin
|
||||
processAluInput: process(clk, opcInfo, A, X, Y, T, S)
|
||||
|
||||
processAluInput: process(clk, opcInfo, A, X, Y, T, S)
|
||||
variable temp : unsigned(7 downto 0);
|
||||
begin
|
||||
temp := (others => '1');
|
||||
@ -668,7 +665,7 @@ processAluInput: process(clk, opcInfo, A, X, Y, T, S)
|
||||
|
||||
end process;
|
||||
|
||||
processCmpInput: process(clk, opcInfo, A, X, Y)
|
||||
processCmpInput: process(clk, opcInfo, A, X, Y)
|
||||
variable temp : unsigned(7 downto 0);
|
||||
begin
|
||||
temp := (others => '1');
|
||||
@ -704,11 +701,11 @@ processCmpInput: process(clk, opcInfo, A, X, Y)
|
||||
--hardware interrupts IRQ & NMI will push the B flag as being 0.
|
||||
|
||||
|
||||
processAlu: process(clk, opcInfo, aluInput, aluCmpInput, A, T, irqActive, N, V, D, I, Z, C)
|
||||
variable lowBits: unsigned(5 downto 0);
|
||||
variable nineBits: unsigned(8 downto 0);
|
||||
variable rmwBits: unsigned(8 downto 0);
|
||||
variable tsxBits: unsigned(8 downto 0);
|
||||
processAlu: process(clk, opcInfo, aluInput, aluCmpInput, A, T, irqActive, N, V, D, I, Z, C)
|
||||
variable lowBits : unsigned(5 downto 0);
|
||||
variable nineBits : unsigned(8 downto 0);
|
||||
variable rmwBits : unsigned(8 downto 0);
|
||||
variable tsxBits : unsigned(8 downto 0);
|
||||
|
||||
variable varC : std_logic;
|
||||
variable varZ : std_logic;
|
||||
@ -721,7 +718,6 @@ processAlu: process(clk, opcInfo, aluInput, aluCmpInput, A, T, irqActive, N, V,
|
||||
tsxBits := (others => '-');
|
||||
R <= '1';
|
||||
|
||||
|
||||
-- Shift unit
|
||||
case opcInfo(aluMode1From to aluMode1To) is
|
||||
when aluModeInp => rmwBits := C & aluInput;
|
||||
@ -754,10 +750,8 @@ processAlu: process(clk, opcInfo, aluInput, aluCmpInput, A, T, irqActive, N, V,
|
||||
when others => ninebits := rmwBits;
|
||||
end case;
|
||||
|
||||
|
||||
varV := aluInput(6); -- Default for BIT / PLP / RTI
|
||||
|
||||
|
||||
if (opcInfo(aluMode1From to aluMode1To) = aluModeFlg) then
|
||||
varZ := rmwBits(1);
|
||||
elsif (opcInfo(aluMode1From to aluMode1To) = aluModeTSB) or (opcInfo(aluMode1From to aluMode1To) = aluModeTRB) then
|
||||
@ -786,7 +780,6 @@ processAlu: process(clk, opcInfo, aluInput, aluCmpInput, A, T, irqActive, N, V,
|
||||
-- v Set if signed overflow; cleared if valid signed result.
|
||||
-- z Set if result is zero; else cleared.
|
||||
-- c Set if unsigned overflow; cleared if valid unsigned result
|
||||
|
||||
when aluModeAdc =>
|
||||
-- decimal mode low bits correction, is done after setting Z flag.
|
||||
if D = '1' then
|
||||
@ -797,7 +790,8 @@ processAlu: process(clk, opcInfo, aluInput, aluCmpInput, A, T, irqActive, N, V,
|
||||
end if;
|
||||
end if;
|
||||
end if;
|
||||
when others => null;
|
||||
when others =>
|
||||
null;
|
||||
end case;
|
||||
|
||||
case opcInfo(aluMode2From to aluMode2To) is
|
||||
@ -823,7 +817,8 @@ processAlu: process(clk, opcInfo, aluInput, aluCmpInput, A, T, irqActive, N, V,
|
||||
ninebits(8 downto 4) := ninebits(8 downto 4) - 6;
|
||||
end if;
|
||||
end if;
|
||||
when others => null;
|
||||
when others =>
|
||||
null;
|
||||
end case;
|
||||
|
||||
-- fix n and z flag for 65c02 adc sbc instructions in decimal mode
|
||||
@ -846,7 +841,8 @@ processAlu: process(clk, opcInfo, aluInput, aluCmpInput, A, T, irqActive, N, V,
|
||||
end if;
|
||||
varN := ninebits(7);
|
||||
end if;
|
||||
when others => null;
|
||||
when others =>
|
||||
null;
|
||||
end case;
|
||||
|
||||
-- DMB Remove Pipelining
|
||||
@ -861,7 +857,7 @@ processAlu: process(clk, opcInfo, aluInput, aluCmpInput, A, T, irqActive, N, V,
|
||||
|
||||
end process;
|
||||
|
||||
calcInterrupt: process(clk)
|
||||
calcInterrupt: process(clk)
|
||||
begin
|
||||
if rising_edge(clk) then
|
||||
if enable = '1' then
|
||||
@ -895,7 +891,7 @@ calcInterrupt: process(clk)
|
||||
-- end if;
|
||||
-- end process;
|
||||
|
||||
calcNextOpcode: process(clk, di, reset, processIrq)
|
||||
calcNextOpcode: process(clk, di, reset, processIrq)
|
||||
variable myNextOpcode : unsigned(7 downto 0);
|
||||
begin
|
||||
-- Next opcode is read from input unless a reset or IRQ is pending.
|
||||
@ -921,7 +917,7 @@ calcNextOpcode: process(clk, di, reset, processIrq)
|
||||
|
||||
-- Read bits and flags from opcodeInfoTable and store in opcInfo.
|
||||
-- This info is used to control the execution of the opcode.
|
||||
calcOpcInfo: process(clk)
|
||||
calcOpcInfo: process(clk)
|
||||
begin
|
||||
if rising_edge(clk) then
|
||||
if enable = '1' then
|
||||
@ -932,7 +928,7 @@ calcOpcInfo: process(clk)
|
||||
end if;
|
||||
end process;
|
||||
|
||||
calcTheOpcode: process(clk)
|
||||
calcTheOpcode: process(clk)
|
||||
begin
|
||||
if rising_edge(clk) then
|
||||
if enable = '1' then
|
||||
@ -979,18 +975,21 @@ calcTheOpcode: process(clk)
|
||||
|
||||
-- Determine the next cpu cycle. After the last cycle we always
|
||||
-- go to opcodeFetch to get the next opcode.
|
||||
calcNextCpuCycle: process(theCpuCycle, opcInfo, theOpcode, nextOpcode, indexOut, T, N, V, C, Z)
|
||||
calcNextCpuCycle: process(theCpuCycle, opcInfo, theOpcode, nextOpcode, indexOut, T, N, V, C, Z)
|
||||
begin
|
||||
nextCpuCycle <= opcodeFetch;
|
||||
|
||||
case theCpuCycle is
|
||||
|
||||
when opcodeFetch =>
|
||||
if nextOpcode(1 downto 0) = "11" then
|
||||
nextCpuCycle <= opcodeFetch;
|
||||
else
|
||||
nextCpuCycle <= cycle2;
|
||||
end if;
|
||||
when cycle2 => if opcInfo(opcBranch) = '1' then
|
||||
|
||||
when cycle2 =>
|
||||
if opcInfo(opcBranch) = '1' then
|
||||
if (N = theOpcode(5) and theOpcode(7 downto 6) = "00")
|
||||
or (V = theOpcode(5) and theOpcode(7 downto 6) = "01")
|
||||
or (C = theOpcode(5) and theOpcode(7 downto 6) = "10")
|
||||
@ -1031,7 +1030,9 @@ calcNextCpuCycle: process(theCpuCycle, opcInfo, theOpcode, nextOpcode, indexOut,
|
||||
elsif opcInfo(opcJump) = '1' then
|
||||
nextCpuCycle <= cycleJump;
|
||||
end if;
|
||||
when cycle3 => nextCpuCycle <= cycleRead;
|
||||
|
||||
when cycle3 =>
|
||||
nextCpuCycle <= cycleRead;
|
||||
if opcInfo(opcWrite) = '1' then
|
||||
if (opcInfo(indexX) = '1') or (opcInfo(indexY) = '1') then
|
||||
nextCpuCycle <= cyclePreWrite;
|
||||
@ -1046,14 +1047,21 @@ calcNextCpuCycle: process(theCpuCycle, opcInfo, theOpcode, nextOpcode, indexOut,
|
||||
nextCpuCycle <= cycleRead2;
|
||||
end if;
|
||||
end if;
|
||||
when cyclePreIndirect => nextCpuCycle <= cycleIndirect;
|
||||
when cycleIndirect => nextCpuCycle <= cycle3;
|
||||
when cycleBranchTaken => if indexOut(8) /= T(7) then
|
||||
when cyclePreIndirect =>
|
||||
nextCpuCycle <= cycleIndirect;
|
||||
|
||||
when cycleIndirect =>
|
||||
nextCpuCycle <= cycle3;
|
||||
|
||||
when cycleBranchTaken =>
|
||||
if indexOut(8) /= T(7) then
|
||||
nextCpuCycle <= cycleBranchPage;
|
||||
end if;
|
||||
when cyclePreRead => if opcInfo(opcZeroPage) = '1' then
|
||||
when cyclePreRead =>
|
||||
if opcInfo(opcZeroPage) = '1' then
|
||||
nextCpuCycle <= cycleRead2;
|
||||
end if;
|
||||
|
||||
when cycleRead =>
|
||||
if opcInfo(opcJump) = '1' then
|
||||
nextCpuCycle <= cycleJump;
|
||||
@ -1065,45 +1073,64 @@ calcNextCpuCycle: process(theCpuCycle, opcInfo, theOpcode, nextOpcode, indexOut,
|
||||
nextCpuCycle <= cycleRead2;
|
||||
end if;
|
||||
end if;
|
||||
when cycleRead2 => if opcInfo(opcRmw) = '1' then
|
||||
|
||||
when cycleRead2 =>
|
||||
if opcInfo(opcRmw) = '1' then
|
||||
nextCpuCycle <= cycleRmw;
|
||||
end if;
|
||||
when cycleRmw => nextCpuCycle <= cycleWrite;
|
||||
when cyclePreWrite => nextCpuCycle <= cycleWrite;
|
||||
when cycleStack1 => nextCpuCycle <= cycleRead;
|
||||
|
||||
when cycleRmw =>
|
||||
nextCpuCycle <= cycleWrite;
|
||||
|
||||
when cyclePreWrite =>
|
||||
nextCpuCycle <= cycleWrite;
|
||||
|
||||
when cycleStack1 =>
|
||||
nextCpuCycle <= cycleRead;
|
||||
if opcInfo(opcStackAddr) = '1' then
|
||||
nextCpuCycle <= cycleStack2;
|
||||
end if;
|
||||
when cycleStack2 => nextCpuCycle <= cycleStack3;
|
||||
|
||||
when cycleStack2 =>
|
||||
nextCpuCycle <= cycleStack3;
|
||||
if opcInfo(opcRti) = '1' then
|
||||
nextCpuCycle <= cycleRead;
|
||||
end if;
|
||||
if opcInfo(opcStackData) = '0' and opcInfo(opcStackUp) = '1' then
|
||||
nextCpuCycle <= cycleJump;
|
||||
end if;
|
||||
when cycleStack3 => nextCpuCycle <= cycleRead;
|
||||
|
||||
when cycleStack3 =>
|
||||
nextCpuCycle <= cycleRead;
|
||||
if opcInfo(opcStackData) = '0' or opcInfo(opcStackUp) = '1' then
|
||||
nextCpuCycle <= cycleJump;
|
||||
elsif opcInfo(opcStackAddr) = '1' then
|
||||
nextCpuCycle <= cycleStack4;
|
||||
end if;
|
||||
when cycleStack4 => nextCpuCycle <= cycleRead;
|
||||
when cycleJump => if opcInfo(opcIncrAfter) = '1' then
|
||||
|
||||
when cycleStack4 =>
|
||||
nextCpuCycle <= cycleRead;
|
||||
|
||||
when cycleJump =>
|
||||
if opcInfo(opcIncrAfter) = '1' then
|
||||
nextCpuCycle <= cycleEnd;
|
||||
end if;
|
||||
when others => null;
|
||||
|
||||
when others =>
|
||||
null;
|
||||
end case;
|
||||
end process;
|
||||
|
||||
-- -----------------------------------------------------------------------
|
||||
-- T register
|
||||
-- -----------------------------------------------------------------------
|
||||
calcT: process(clk)
|
||||
calcT: process(clk)
|
||||
begin
|
||||
if rising_edge(clk) then
|
||||
if enable = '1' then
|
||||
case theCpuCycle is
|
||||
when cycle2 => T <= di;
|
||||
when cycle2 =>
|
||||
T <= di;
|
||||
when cycleStack1 | cycleStack2 =>
|
||||
if opcInfo(opcStackUp) = '1' then
|
||||
if theOpcode = x"28" or theOpcode = x"40" then -- plp or rti pulling the flags off the stack
|
||||
@ -1112,8 +1139,10 @@ calcT: process(clk)
|
||||
T <= di;
|
||||
end if;
|
||||
end if;
|
||||
when cycleIndirect | cycleRead | cycleRead2 => T <= di;
|
||||
when others => null;
|
||||
when cycleIndirect | cycleRead | cycleRead2 =>
|
||||
T <= di;
|
||||
when others =>
|
||||
null;
|
||||
end case;
|
||||
end if;
|
||||
end if;
|
||||
@ -1204,6 +1233,7 @@ calcT: process(clk)
|
||||
end if;
|
||||
end if;
|
||||
end process;
|
||||
|
||||
-- -----------------------------------------------------------------------
|
||||
-- D flag
|
||||
-- -----------------------------------------------------------------------
|
||||
@ -1271,16 +1301,22 @@ calcT: process(clk)
|
||||
updateFlag := true;
|
||||
end if;
|
||||
|
||||
when cycleStack2 => updateFlag := true;
|
||||
when cycleStack3 => updateFlag := true;
|
||||
when cycleStack4 => updateFlag := true;
|
||||
when cycleRead => if opcInfo(opcRti) = '1' then
|
||||
when cycleStack2 =>
|
||||
updateFlag := true;
|
||||
when cycleStack3 =>
|
||||
updateFlag := true;
|
||||
when cycleStack4 =>
|
||||
updateFlag := true;
|
||||
when cycleRead =>
|
||||
if opcInfo(opcRti) = '1' then
|
||||
updateFlag := true;
|
||||
end if;
|
||||
when cycleWrite => if opcInfo(opcStackData) = '1' then
|
||||
when cycleWrite =>
|
||||
if opcInfo(opcStackData) = '1' then
|
||||
updateFlag := true;
|
||||
end if;
|
||||
when others => null;
|
||||
when others =>
|
||||
null;
|
||||
end case;
|
||||
|
||||
if updateFlag then
|
||||
@ -1301,32 +1337,35 @@ calcT: process(clk)
|
||||
-- -----------------------------------------------------------------------
|
||||
-- Data out
|
||||
-- -----------------------------------------------------------------------
|
||||
calcDo: process(clk)
|
||||
calcDo: process(clk)
|
||||
begin
|
||||
if rising_edge(clk) then
|
||||
if enable = '1' then
|
||||
doReg <= aluRmwOut;
|
||||
case nextCpuCycle is
|
||||
when cycleStack2 => if opcInfo(opcIRQ) = '1' and irqActive = '0' then
|
||||
when cycleStack2 =>
|
||||
if opcInfo(opcIRQ) = '1' and irqActive = '0' then
|
||||
doReg <= myAddrIncr(15 downto 8);
|
||||
else
|
||||
doReg <= PC(15 downto 8);
|
||||
end if;
|
||||
when cycleStack3 => doReg <= PC(7 downto 0);
|
||||
when cycleRmw => doReg <= di; -- Read-modify-write write old value first.
|
||||
when others => null;
|
||||
when cycleStack3 =>
|
||||
doReg <= PC(7 downto 0);
|
||||
when cycleRmw =>
|
||||
doReg <= di; -- Read-modify-write write old value first.
|
||||
when others =>
|
||||
null;
|
||||
end case;
|
||||
end if;
|
||||
end if;
|
||||
end process;
|
||||
|
||||
do <= doReg;
|
||||
|
||||
|
||||
|
||||
-- -----------------------------------------------------------------------
|
||||
-- Write enable
|
||||
-- -----------------------------------------------------------------------
|
||||
calcWe: process(clk)
|
||||
calcWe: process(clk)
|
||||
begin
|
||||
if rising_edge(clk) then
|
||||
if enable = '1' then
|
||||
@ -1340,36 +1379,43 @@ calcWe: process(clk)
|
||||
if opcInfo(opcStackUp) = '0' then
|
||||
theWe <= '0';
|
||||
end if;
|
||||
when cycleRmw => theWe <= '0';
|
||||
when cycleWrite => theWe <= '0';
|
||||
when others => null;
|
||||
when cycleRmw =>
|
||||
theWe <= '0';
|
||||
when cycleWrite =>
|
||||
theWe <= '0';
|
||||
when others =>
|
||||
null;
|
||||
end case;
|
||||
end if;
|
||||
end if;
|
||||
--nwe <= theWe;
|
||||
--nwe <= theWe;
|
||||
end process;
|
||||
nwe <= theWe;
|
||||
|
||||
-- -----------------------------------------------------------------------
|
||||
-- Program counter
|
||||
-- -----------------------------------------------------------------------
|
||||
calcPC: process(clk)
|
||||
calcPC: process(clk)
|
||||
begin
|
||||
if rising_edge(clk) then
|
||||
if enable = '1' then
|
||||
case theCpuCycle is
|
||||
when opcodeFetch => PC <= myAddr;
|
||||
when cycle2 => if irqActive = '0' then
|
||||
when opcodeFetch =>
|
||||
PC <= myAddr;
|
||||
when cycle2 =>
|
||||
if irqActive = '0' then
|
||||
if opcInfo(opcSecondByte) = '1' then
|
||||
PC <= myAddrIncr;
|
||||
else
|
||||
PC <= myAddr;
|
||||
end if;
|
||||
end if;
|
||||
when cycle3 => if opcInfo(opcAbsolute) = '1' then
|
||||
when cycle3 =>
|
||||
if opcInfo(opcAbsolute) = '1' then
|
||||
PC <= myAddrIncr;
|
||||
end if;
|
||||
when others => null;
|
||||
when others =>
|
||||
null;
|
||||
end case;
|
||||
end if;
|
||||
end if;
|
||||
@ -1379,11 +1425,12 @@ calcPC: process(clk)
|
||||
-- -----------------------------------------------------------------------
|
||||
-- Address generation
|
||||
-- -----------------------------------------------------------------------
|
||||
calcNextAddr: process(theCpuCycle, opcInfo, indexOut, T, reset)
|
||||
calcNextAddr: process(theCpuCycle, opcInfo, indexOut, T, reset)
|
||||
begin
|
||||
nextAddr <= nextAddrIncr;
|
||||
case theCpuCycle is
|
||||
when cycle2 => if opcInfo(opcStackAddr) = '1' or opcInfo(opcStackData) = '1' then
|
||||
when cycle2 =>
|
||||
if opcInfo(opcStackAddr) = '1' or opcInfo(opcStackData) = '1' then
|
||||
nextAddr <= nextAddrStack;
|
||||
elsif opcInfo(opcAbsolute) = '1' then
|
||||
nextAddr <= nextAddrIncr;
|
||||
@ -1396,68 +1443,73 @@ calcNextAddr: process(theCpuCycle, opcInfo, indexOut, T, reset)
|
||||
else
|
||||
nextAddr <= nextAddrHold;
|
||||
end if;
|
||||
when cycle3 => if (opcInfo(opcIndirect) = '1') and (opcInfo(indexX) = '1') then
|
||||
when cycle3 =>
|
||||
if (opcInfo(opcIndirect) = '1') and (opcInfo(indexX) = '1') then
|
||||
nextAddr <= nextAddrAbs;
|
||||
else
|
||||
nextAddr <= nextAddrAbsIndexed;
|
||||
end if;
|
||||
when cyclePreIndirect => nextAddr <= nextAddrZPIndexed;
|
||||
when cycleIndirect => nextAddr <= nextAddrIncrL;
|
||||
when cycleBranchTaken => nextAddr <= nextAddrRelative;
|
||||
when cycleBranchPage => if T(7) = '0' then
|
||||
when cyclePreIndirect =>
|
||||
nextAddr <= nextAddrZPIndexed;
|
||||
when cycleIndirect =>
|
||||
nextAddr <= nextAddrIncrL;
|
||||
when cycleBranchTaken =>
|
||||
nextAddr <= nextAddrRelative;
|
||||
when cycleBranchPage =>
|
||||
if T(7) = '0' then
|
||||
nextAddr <= nextAddrIncrH;
|
||||
else
|
||||
nextAddr <= nextAddrDecrH;
|
||||
end if;
|
||||
when cyclePreRead => nextAddr <= nextAddrZPIndexed;
|
||||
when cycleRead => nextAddr <= nextAddrPc;
|
||||
when cyclePreRead =>
|
||||
nextAddr <= nextAddrZPIndexed;
|
||||
when cycleRead =>
|
||||
nextAddr <= nextAddrPc;
|
||||
if opcInfo(opcJump) = '1' then
|
||||
-- Emulate 6510 bug, jmp(xxFF) fetches from same page.
|
||||
-- Replace with nextAddrIncr if emulating 65C02 or later cpu.
|
||||
nextAddr <= nextAddrIncr;
|
||||
--nextAddr <= nextAddrIncrL;
|
||||
elsif indexOut(8) = '1' then
|
||||
nextAddr <= nextAddrIncrH;
|
||||
elsif opcInfo(opcRmw) = '1' then
|
||||
nextAddr <= nextAddrHold;
|
||||
end if;
|
||||
when cycleRead2 => nextAddr <= nextAddrPc;
|
||||
when cycleRead2 =>
|
||||
nextAddr <= nextAddrPc;
|
||||
if opcInfo(opcRmw) = '1' then
|
||||
nextAddr <= nextAddrHold;
|
||||
end if;
|
||||
when cycleRmw => nextAddr <= nextAddrHold;
|
||||
when cyclePreWrite => nextAddr <= nextAddrHold;
|
||||
when cycleRmw =>
|
||||
nextAddr <= nextAddrHold;
|
||||
when cyclePreWrite =>
|
||||
nextAddr <= nextAddrHold;
|
||||
if opcInfo(opcZeroPage) = '1' then
|
||||
nextAddr <= nextAddrZPIndexed;
|
||||
elsif indexOut(8) = '1' then
|
||||
nextAddr <= nextAddrIncrH;
|
||||
end if;
|
||||
when cycleWrite => nextAddr <= nextAddrPc;
|
||||
when cycleStack1 => nextAddr <= nextAddrStack;
|
||||
when cycleStack2 => nextAddr <= nextAddrStack;
|
||||
when cycleStack3 => nextAddr <= nextAddrStack;
|
||||
when cycleWrite =>
|
||||
nextAddr <= nextAddrPc;
|
||||
when cycleStack1 =>
|
||||
nextAddr <= nextAddrStack;
|
||||
when cycleStack2 =>
|
||||
nextAddr <= nextAddrStack;
|
||||
when cycleStack3 =>
|
||||
nextAddr <= nextAddrStack;
|
||||
if opcInfo(opcStackData) = '0' then
|
||||
nextAddr <= nextAddrPc;
|
||||
end if;
|
||||
when cycleStack4 => nextAddr <= nextAddrIrq;
|
||||
when cycleJump => nextAddr <= nextAddrAbs;
|
||||
|
||||
|
||||
when others => null;
|
||||
when cycleStack4 =>
|
||||
nextAddr <= nextAddrIrq;
|
||||
when cycleJump =>
|
||||
nextAddr <= nextAddrAbs;
|
||||
when others =>
|
||||
null;
|
||||
end case;
|
||||
|
||||
if reset = '0' then
|
||||
nextAddr <= nextAddrReset;
|
||||
end if;
|
||||
|
||||
end process;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
indexAlu: process(opcInfo, myAddr, T, X, Y)
|
||||
indexAlu: process(opcInfo, myAddr, T, X, Y)
|
||||
begin
|
||||
if opcInfo(indexX) = '1' then
|
||||
indexOut <= (B"0" & T) + (B"0" & X);
|
||||
@ -1470,33 +1522,46 @@ indexAlu: process(opcInfo, myAddr, T, X, Y)
|
||||
end if;
|
||||
end process;
|
||||
|
||||
calcAddr: process(clk)
|
||||
calcAddr: process(clk)
|
||||
begin
|
||||
if rising_edge(clk) then
|
||||
if enable = '1' then
|
||||
case nextAddr is
|
||||
when nextAddrIncr => myAddr <= myAddrIncr;
|
||||
when nextAddrIncrL => myAddr(7 downto 0) <= myAddrIncr(7 downto 0);
|
||||
when nextAddrIncrH => myAddr(15 downto 8) <= myAddrIncrH;
|
||||
when nextAddrDecrH => myAddr(15 downto 8) <= myAddrDecrH;
|
||||
when nextAddrPc => myAddr <= PC;
|
||||
when nextAddrIrq =>myAddr <= X"FFFE";
|
||||
when nextAddrIncr =>
|
||||
myAddr <= myAddrIncr;
|
||||
when nextAddrIncrL =>
|
||||
myAddr(7 downto 0) <= myAddrIncr(7 downto 0);
|
||||
when nextAddrIncrH =>
|
||||
myAddr(15 downto 8) <= myAddrIncrH;
|
||||
when nextAddrDecrH =>
|
||||
myAddr(15 downto 8) <= myAddrDecrH;
|
||||
when nextAddrPc =>
|
||||
myAddr <= PC;
|
||||
when nextAddrIrq =>
|
||||
myAddr <= X"FFFE";
|
||||
if nmiReg = '0' then
|
||||
myAddr <= X"FFFA";
|
||||
end if;
|
||||
when nextAddrReset => myAddr <= X"FFFC";
|
||||
when nextAddrAbs => myAddr <= di & T;
|
||||
when nextAddrAbsIndexed =>--myAddr <= di & indexOut(7 downto 0);
|
||||
when nextAddrReset =>
|
||||
myAddr <= X"FFFC";
|
||||
when nextAddrAbs =>
|
||||
myAddr <= di & T;
|
||||
when nextAddrAbsIndexed =>
|
||||
if theOpcode = x"7C" then
|
||||
myAddr <= (di & T) + (x"00"& X);
|
||||
else
|
||||
myAddr <= di & indexOut(7 downto 0);
|
||||
end if;
|
||||
when nextAddrZeroPage => myAddr <= "00000000" & di;
|
||||
when nextAddrZPIndexed => myAddr <= "00000000" & indexOut(7 downto 0);
|
||||
when nextAddrStack => myAddr <= "00000001" & S;
|
||||
when nextAddrRelative => myAddr(7 downto 0) <= indexOut(7 downto 0);
|
||||
when others => null;
|
||||
when nextAddrZeroPage =>
|
||||
myAddr <= "00000000" & di;
|
||||
when nextAddrZPIndexed =>
|
||||
myAddr <= "00000000" & indexOut(7 downto 0);
|
||||
when nextAddrStack =>
|
||||
myAddr <= "00000001" & S;
|
||||
when nextAddrRelative =>
|
||||
myAddr(7 downto 0) <= indexOut(7 downto 0);
|
||||
when others =>
|
||||
null;
|
||||
end case;
|
||||
end if;
|
||||
end if;
|
||||
@ -1511,11 +1576,12 @@ calcAddr: process(clk)
|
||||
--
|
||||
-- calcsync: process(clk)
|
||||
-- begin
|
||||
--
|
||||
-- if enable = '1' then
|
||||
-- case theCpuCycle is
|
||||
-- when opcodeFetch => sync <= '1';
|
||||
-- when others => sync <= '0';
|
||||
-- when opcodeFetch =>
|
||||
-- sync <= '1';
|
||||
-- when others =>
|
||||
-- sync <= '0';
|
||||
-- end case;
|
||||
-- end if;
|
||||
-- end process;
|
||||
|
Loading…
Reference in New Issue
Block a user