OpenCores
URL https://opencores.org/ocsvn/v6502/v6502/trunk

Subversion Repositories v6502

[/] [v6502/] [trunk/] [spr.vhd] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 Valerio63
library IEEE;
2
use IEEE.std_logic_1164.all;  -- defines std_logic types
3
use IEEE.STD_LOGIC_unsigned.all;
4
use IEEE.STD_LOGIC_arith.all;
5
 
6
-- 8/16 bit stack pointer register "S"
7
entity spr is
8
  port(   clk:  in STD_LOGIC;
9
          clr:  in STD_LOGIC;
10
        fwait:  in STD_LOGIC;
11
         ld_l:  in STD_LOGIC;
12
         ld_h:  in STD_LOGIC;
13
            u:  in STD_LOGIC;
14
            d:  in STD_LOGIC;
15
          din:  in STD_LOGIC_VECTOR(7 downto 0);
16
         dout: out STD_LOGIC_VECTOR(15 downto 0)
17
      );
18
end spr;
19
 
20
architecture rtl of spr is
21
constant SP_6502_VALUE:    STD_LOGIC_VECTOR(15 downto 0)  := "0000000111111111"; -- $01FF standard 6502 stack pointer
22
signal   x: STD_LOGIC_VECTOR(3 downto 0);
23
signal reg: STD_LOGIC_VECTOR(15 downto 0);
24
 
25
begin
26
  x(0) <= ld_l;
27
  x(1) <= ld_h;
28
  x(2) <= u;
29
  x(3) <= d;
30
  process(clk)
31
    begin
32
      if (clk'event and clk = '1') then
33
        if fwait = '1' then
34
          reg <= reg;
35
        else
36
          if clr = '1' then
37
            reg <= SP_6502_VALUE;
38
          else
39
            case x is
40
              when "0001"  => reg(7 downto 0)  <= din;
41
                              reg(15 downto 8) <= reg(15 downto 8);
42
              when "0010"  => reg(15 downto 8) <= din;
43
                              reg(7 downto 0)  <= reg(7 downto 0);
44
              when "0100"  => reg <= reg + 1;
45
              when "1000"  => reg <= reg - 1;
46
              when others  => reg <= reg;
47
            end case;
48
          end if;
49
        end if;
50
      end if;
51
  end process;
52
  dout <= reg;
53
end rtl;
54
 
55
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.