-------------------------------------------------------------------------
-- Project: JCPU, a portable 8-bit RISC CPU written in VHDL
-- This file: The ROM file for use in your VHDL design
--
-- Copyright (C) 2007 J. Ahrensfeld
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
--
-- For questions and ideas, please contact the author at jens@jayfield.org
--
--------------------------------------------------------------------------

LIBRARY ieee;
use IEEE.STD_LOGIC_1164.ALL;
USE ieee.numeric_std.ALL;

library work;
use work.cpu_pkg.all;

-- JASM_ROM_INSERT_HERE
ENTITY irom IS
	Port (
	clk			: in  STD_LOGIC;
	ce			: in  STD_LOGIC;
	addr		: in  inst_addr_t;
	dout		: out inst_t
	);
END irom;

ARCHITECTURE mul8x8 OF irom IS 

	type imem_rom_t is array (0 to 26) of inst_t;

	-- Assembled from mul8x8.jsm
	constant imem_rom : imem_rom_t :=
	(
		"110000" & X"001", -- 0x000: JMP 0x001
		"000011" & X"450", -- 0x001: MOV R00, 0x45
		"000011" & X"F51", -- 0x002: MOV R01, 0xF5
		"111011" & X"005", -- 0x003: CALL 0x005
		"110000" & X"004", -- 0x004: JMP 0x004
		"111100" & X"002", -- 0x005: PUSH R02
		"111100" & X"003", -- 0x006: PUSH R03
		"111100" & X"004", -- 0x007: PUSH R04
		"000010" & X"014", -- 0x008: MOV R04, R01
		"000011" & X"001", -- 0x009: MOV R01, 0x00
		"000011" & X"002", -- 0x00A: MOV R02, 0x00
		"000011" & X"003", -- 0x00B: MOV R03, 0x00
		"001111" & X"014", -- 0x00C: CMP R04, 0x01
		"111001" & X"015", -- 0x00D: JEQ 0x015
		"011111" & X"004", -- 0x00E: SHR R04
		"110100" & X"012", -- 0x00F: JNC 0x012
		"010000" & X"002", -- 0x010: ADD R02, R00
		"010010" & X"013", -- 0x011: ADDC R03, R01
		"011110" & X"000", -- 0x012: SHL R00
		"100010" & X"001", -- 0x013: ROLC R01
		"110000" & X"00C", -- 0x014: JMP 0x00C
		"010000" & X"020", -- 0x015: ADD R00, R02
		"010010" & X"031", -- 0x016: ADDC R01, R03
		"111101" & X"004", -- 0x017: POP R04
		"111101" & X"003", -- 0x018: POP R03
		"111101" & X"002", -- 0x019: POP R02
		"111110" & X"000"  -- 0x01A: RET
	);

begin

PROM_READ:
	process(clk, ce)
	begin
		if rising_edge(clk) and ce = '1' then
			dout <= imem_rom(to_integer(addr));
		end if;
	end process;

end mul8x8;

