6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 22, 2024 11:13 am

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Fri Jul 12, 2019 5:07 pm 
Offline

Joined: Fri Jul 12, 2019 2:56 pm
Posts: 4
Project URL: https://github.com/JeremyJStarcher/kim1-fpga

I am trying to wire up Arlet Ottens famous 6502 core within my project, but no matter what combo of settings I use, the RESET vector is not being called.

About the hardware:https://github.com/JeremyJStarcher/kim1-fpga
  • Board: RioRand EP2C5T144 Altera Cyclone II
  • High speed soft-clock to drive the display
  • Low speed soft-clock to drive the SPU.
  • MAX719 with bit-banged SPI. Displays current value of the address line.
  • Tiny ROM with just 6502 vectors.
  • No RAM
  • CPU core lifted from: https://github.com/Arlet/verilog-6502

The situation:
It is my understanding that the MOS 6502, upon power up, should do some basic house keeping then preform a JMP($FFFC).

If there is no NMI, it is doing a
Code:
 JMP($FFFE)
. If there NMI is active, it is doing a
Code:
JMP($FFFA).


  • Do I have the CPU wired wrong?
  • Do I have a faulty understanding of how the CPU works?
  • Is there a bug in the CPU code that I can't find mentioned anywhere? (I did lots of googling.)
  • Just a thought -- does the CPU require RAM?
  • Something else?


Short listing:
Code:

   -- Truth table
   -- IRQ  NMI      VECTOR
   --  1    1      0xFFFA 0xFFFB
   --  0    1      oxFFFA 0xFFFB
   --    0    0     0xFFFE 0xFFFF
   --  1    0      0xFFFE 0xFFFF
   
   -- On reset line: 0xFFFE 0xFFFF
   
   IRQ <= '1';
   NMI <= '0';
   RDY <= '1';
   CPURESET <= reset; -- '0';
   
   cpu1: cpu port map(
      clk => tick_clock,
      reset => CPURESET,
      AB   => AB,
      DI   => DI,
      DO   => DO,
      WE => WE,
      IRQ => IRQ,
      NMI => NMI,
      RDY => RDY
   );
   



Complete file:
Code:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;

entity Kim is
port (
   clk   : in std_logic;  -- clock is on 17
   led0   : out std_logic; -- led on 3
   led1   : out std_logic; -- led on 7
   led2   : out std_logic; -- led on 9
   sw0   : in std_logic;   -- switch on 114

   max_din : out std_logic; -- 76
   max_cs  : out std_logic; -- 80
   max_clk : out std_logic -- 86
);
end Kim;

architecture rtl of Kim is
   signal max_d    : std_logic_vector(27 downto 0) := "0000000000000000000000000000";
   signal tt       : std_logic_vector(31 downto 0) := "00000000000000000000000000000000";
   signal Q1      : std_logic_vector(3 downto 0);
   signal reset   : std_logic;

   signal spi_clock : std_logic;
   signal tick_clock : std_logic;

   signal TOP_ROM_DO   : std_logic_vector(7 downto 0);
   signal TOP_ROM_EN : std_logic;

   shared variable   HAB1      : std_logic_vector(15 downto 0);   -- address bus

   signal   AB      : std_logic_vector(15 downto 0);   -- address bus
   signal   DI      : std_logic_vector(7 downto 0);      -- data in, read bus
   shared variable   HDI   : std_logic_vector(7 downto 0);      -- data in, read bus

   signal    DO      : std_logic_vector(7 downto 0);      -- data out, write bus
   signal   WE      : std_logic;                        -- write enable
   signal   IRQ   : std_logic;                        -- interrupt request
   signal   NMI   : std_logic;                        -- non-maskable interrupt request
   signal   RDY   : std_logic;                        -- Ready signal. Pauses CPU when RDY=0
   signal   CPURESET : std_logic;

component Bit4 is
   port(C, CLR : in std_logic;
   Q : out std_logic_vector(3 downto 0));
end component;

component M7219 is
    port (
      clk : in std_logic;
      parallel : in std_logic_vector(31 downto 0);
      clk_out : out std_logic;
      data_out : out std_logic;
      load : out std_logic
    );
end component;

component Clock is
   port(C, CLR : in std_logic;
   spi_clock : out std_logic;
   tick_clock : out std_logic);
end component;

component cpu is
   port(
      clk   : in std_logic;                        -- CPU clock
      reset   : in std_logic;                        -- reset signal
      AB      : out std_logic_vector(15 downto 0);   -- address bus
      DI      : in std_logic_vector(7 downto 0);      -- data in, read bus
      DO      : out std_logic_vector(7 downto 0);      -- data out, write bus
      WE      : out std_logic;                        -- write enable
      IRQ   : in std_logic;                        -- interrupt request
      NMI   : in std_logic;                        -- non-maskable interrupt request
      RDY   : in std_logic);                        -- Ready signal. Pauses CPU when RDY=0
end component;

component top_rom is
generic(
   address_length: natural := 16;
   data_length: natural := 8
);
port(
   clock: in std_logic;
   rom_enable: in std_logic;
   address: in std_logic_vector((address_length - 1) downto 0);
   data_output: out std_logic_vector ((data_length - 1) downto 0)
);
end component;

begin
   c1: Clock port map (C => clk, CLR => reset, spi_clock => spi_clock, tick_clock => tick_clock);
   div1: Bit4 port map (C => tick_clock, CLR => reset, Q => Q1);

   -- Truth table
   -- IRQ  NMI      VECTOR
   --  1    1      0xFFFA 0xFFFB
   --  0    1      oxFFFA 0xFFFB
   --    0    0     0xFFFE 0xFFFF
   --  1    0      0xFFFE 0xFFFF
   
   -- On reset line: 0xFFFE 0xFFFF
   
   IRQ <= '1';
   NMI <= '0';
   RDY <= '1';
   CPURESET <= reset; -- '0';
   
   cpu1: cpu port map(
      clk => tick_clock,
      reset => CPURESET,
      AB   => AB,
      DI   => DI,
      DO   => DO,
      WE => WE,
      IRQ => IRQ,
      NMI => NMI,
      RDY => RDY
   );
   
   max1: M7219 port map (clk => spi_clock,
      parallel => tt,
      clk_out => max_clk,
      load => max_cs,
      data_out => max_din
   );

      tt(31 downto 28)<= AB(15 downto 12); -- "1010";
      tt(27 downto 24)<= AB(11 downto 8); -- )"1011";
      tt(23 downto 20)<= AB(7 downto 4); --)"1100";
      tt(19 downto 16)<= AB(3 downto 0); -- ))"1101";

      -- tt(15 downto 12)<= AB(15 downto 12);
      -- tt(11 downto 8)<= AB(11 downto 8);
      -- tt(7 downto 4)<= AB(7 downto 4); -- ))"1101";
      -- tt(3 downto 0)<= AB(3 downto 0); -- ))"1101";

   rom1: top_rom port map (
      clock => tick_clock,
      rom_enable => TOP_ROM_EN,
      address => AB,
      data_output => TOP_ROM_DO
   );

   led2 <= not Q1(0);
   led1 <= not Q1(1);
   led0 <= not Q1(2);

   process(clk)
   begin
         case HAB1 is
         when x"FFFA"
            | x"FFFB"
            | x"FFFC"
            | x"FFFD"
            | x"FFFE"
            | x"FFFF"   =>
            DI <= TOP_ROM_DO;
         when others =>
            DI <= x"EA"; -- hard wire in a NOP
         end case;
   
   end process;
   
   process(tick_clock)
   begin
      if tick_clock'event and tick_clock='1' then
         HAB1 := AB;

         case HAB1 is
         when x"FFFA"
            | x"FFFB"
            | x"FFFC"
            | x"FFFD"
            | x"FFFE"
            | x"FFFF"   =>
            TOP_ROM_EN <= '1';
            HDI := TOP_ROM_DO;
         when others =>
            HDI := x"EA"; -- hard wire in a NOP
            -- TOP_ROM_EN <= '0';
         end case;
      end if;
            
--      tt(15 downto 12)<=  HDI(7 downto 4);
--      tt(11 downto 8)<=  HDI(3 downto 0);

--      tt(7 downto 4)<= TOP_ROM_DO(7 downto 4); -- ))"1101";
--      tt(3 downto 0)<= TOP_ROM_DO(3 downto 0); -- ))"1101";

   end process;

   process(clk, sw0)

   begin

      if rising_edge(clk) then
         if sw0='0' then
            reset <= '1';
         else
            reset <= '0';
         end if;
      end if;

   end process;

end rtl;


Top
 Profile  
Reply with quote  
PostPosted: Fri Jul 12, 2019 6:31 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1949
Location: Sacramento, CA, USA
Code:
   -- On reset line: 0xFFFE 0xFFFF

Please forgive my ignorance, but could you explain what that means?

_________________
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!

Mike B. (about me) (learning how to github)


Top
 Profile  
Reply with quote  
PostPosted: Fri Jul 12, 2019 6:37 pm 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
'--' starts a comment that lasts until the end of the line in VHDL.

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Top
 Profile  
Reply with quote  
PostPosted: Fri Jul 12, 2019 6:41 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
Yes, a comment -- Arlet talking to himself!

jstarcher wrote:
  • Do I have the CPU wired wrong?
  • Do I have a faulty understanding of how the CPU works?
  • Is there a bug in the CPU code that I can't find mentioned anywhere? (I did lots of googling.)
  • Just a thought -- does the CPU require RAM?
  • Something else?
Maybe, maybe, maybe, yes and maybe! :)
Without RAM, the CPU has no stack (for use for subroutine calls, etc)

cheers
Jeff

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Top
 Profile  
Reply with quote  
PostPosted: Fri Jul 12, 2019 7:05 pm 
Offline

Joined: Fri Jul 12, 2019 2:56 pm
Posts: 4
Dr Jefyll wrote:
Yes, a comment -- Arlet talking to himself!

jstarcher wrote:
  • Do I have the CPU wired wrong?
  • Do I have a faulty understanding of how the CPU works?
  • Is there a bug in the CPU code that I can't find mentioned anywhere? (I did lots of googling.)
  • Just a thought -- does the CPU require RAM?
  • Something else?
Maybe, maybe, maybe, yes and maybe! :)
Without RAM, the CPU has no stack (for use for subroutine calls, etc)

cheers
Jeff


Oh yes, I know that I will need RAM. The only opcodes it is running is a hard-coded NOP. I'm just trying to get it booting to the right place.


Top
 Profile  
Reply with quote  
PostPosted: Fri Jul 12, 2019 7:31 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8543
Location: Southern California
I'm not into programmable logic (actually I started into VHDL for a work project 20 years ago, but it was canceled before I got to actually programming a CPLD) but this:
Quote:
It is my understanding that the MOS 6502, upon power up, should do some basic housekeeping then perform a JMP($FFFC).
and a few other things make me suspect a faulty understanding of how the CPU works. The reset\ line needs to remain low a minimum of seven full clock cycles after the power is up and stable and after the clock signal is too. Then you can let the reset\ line up, with a clean edge. (Some manufacturers' parts will have trouble if you just have an RxC on there and the line is allowed to float up slowly. Others have a Schmitt-trigger input, IIRC.) The IRQ\ line is level-sensitive, but the NMI\ line is edge-sensitive. The processor's reset sequence includes setting the interrupt-disable bit I; so initially IRQ\ interrupts will get ignored anyway. Further, any interrupt sources you have will also generally be reset by the reset\ signal, and they will not be generating any interrupts until your software sets them up for it.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Fri Jul 12, 2019 8:32 pm 
Offline
User avatar

Joined: Sun Dec 29, 2002 8:56 pm
Posts: 460
Location: Canada
What vector looks like it's running? What are the contents of the ROM? It looks like the entire address bus is passed to the ROM. Is there a select circuit in the ROM to disable it where ram and I/O are desired? I might guess an issue with the ROM select?

_________________
http://www.finitron.ca


Top
 Profile  
Reply with quote  
PostPosted: Fri Jul 12, 2019 9:25 pm 
Offline

Joined: Fri Jul 12, 2019 2:56 pm
Posts: 4
Rob Finch wrote:
What vector looks like it's running? What are the contents of the ROM? It looks like the entire address bus is passed to the ROM. Is there a select circuit in the ROM to disable it where ram and I/O are desired? I might guess an issue with the ROM select?


I was trying hard not to dump too much info. The system is indeed getting the correct *value* from the ROM, but I have the wrong address on the data bus.

If I physically get into cpu.v and hard-wire the `res` variable (which is different from reset) then it correctly loads.




Code:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;

entity top_rom is
generic(
   address_length: natural := 16;
   data_length: natural := 8
);
port(
   clock: in std_logic;
   rom_enable: in std_logic;
   address: in std_logic_vector((address_length - 1) downto 0);
   data_output: out std_logic_vector ((data_length - 1) downto 0)
);
end top_rom;

architecture arch of top_rom is
   signal z : std_logic := '0';
begin

process(clock) is
begin
   if(rising_edge(clock) and rom_enable = '1') then
      case address is
         when x"FFFA" => data_output <= x"1C"; -- NMI
         when x"FFFB" => data_output <= x"1C"; -- NMI
         when x"FFFC" => data_output <= x"22"; -- RESET
         when x"FFFD" => data_output <= x"1C"; -- RESET
         when x"FFFE" => data_output <= x"1F"; -- IRQ/BRK
         when x"FFFF" => data_output <= x"1C"; -- IRQ/BRK
         when others => z <= '1';
      end case;

   end if;
end process;

end arch;


Top
 Profile  
Reply with quote  
PostPosted: Fri Jul 12, 2019 11:02 pm 
Offline

Joined: Fri Jul 12, 2019 2:56 pm
Posts: 4
GARTHWILSON wrote:
The reset\ line needs to remain low a minimum of seven full clock cycles after the power is up and stable and after the clock signal is too. Then you can let the reset\ line up, with a clean edge


By jove that was it!

I wired a delay into my boot process and, low and behold, I got the correct vector.

Now to wire that delay into my button too.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: