Gameboy Development Forum

Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)

You are not logged in.

#1 2024-02-10 14:26:31

Vini Ness
New member
Registered: 2024-02-10
Posts: 1

Recreat a MBC3 RTC in VHDL

Hi guys

I'm trying to recreat a MBC3 RTC
I divide in steps
• Read a fixed Value when the time is request
• Write to a Buffer/Latch then read back again
• Conect to a external RTC

I'm using this rom to do the tests
https://github.com/meithecatte/mbc3-fiddle

The code reads the fixed number fine, but i can't write to a buffer

The rest of the code (RAM/ROM access) Works fine, just the RTC
Here the parts of the code, that works when the CPU reads the RTC

Code:

ARCHITECTURE HARDWARE OF GBC_MBCx IS

SIGNAL RAM_RTC_ENA    :    STD_LOGIC;
SIGNAL ROM_BANK    :     STD_LOGIC_VECTOR (6 DOWNTO 0) := "0000001";
SIGNAL RAM_BANK    :    STD_LOGIC_VECTOR (1 DOWNTO 0);
SIGNAL RTC_REG        :    STD_LOGIC_VECTOR (7 DOWNTO 0);
SIGNAL RTC_TIME    :    STD_LOGIC_VECTOR (7 DOWNTO 0);
SIGNAL CLK_HALT    :    STD_LOGIC_VECTOR (1 DOWNTO 0) := "00";
SIGNAL RAM_REG        :    STD_LOGIC;

SIGNAL SEGUNDOS    :    STD_LOGIC_VECTOR (7 DOWNTO 0) := x"00";
SIGNAL MINUTOS        :    STD_LOGIC_VECTOR (7 DOWNTO 0) := x"15";
SIGNAL HORAS        :    STD_LOGIC_VECTOR (7 DOWNTO 0) := x"05";
SIGNAL DIAS0        :    STD_LOGIC_VECTOR (7 DOWNTO 0) := x"01";
SIGNAL DIAS1        :    STD_LOGIC_VECTOR (7 DOWNTO 0) := x"00";

SIGNAL RTC_SEC        :    STD_LOGIC_VECTOR (7 DOWNTO 0);
SIGNAL RTC_MIN        :    STD_LOGIC_VECTOR (7 DOWNTO 0);
SIGNAL RTC_HORA     :    STD_LOGIC_VECTOR (7 DOWNTO 0);
SIGNAL RTC_DIAS0    :    STD_LOGIC_VECTOR (7 DOWNTO 0);
SIGNAL RTC_DIAS1    :    STD_LOGIC_VECTOR (7 DOWNTO 0);

BEGIN

Code:

WHEN "010" => --$4000 ~ $5FFF (RAM Bank/RTC Register)
                    CASE GBC_DATA (3 DOWNTO 0)IS
                    ---------SRAM----------
                        WHEN "0000" =>
                            RAM_BANK <= "00";
                            RAM_REG <= '1'; 
                        WHEN "0001" =>
                            RAM_BANK <= "01";
                            RAM_REG <= '1';
                        WHEN "0010" =>
                            RAM_BANK <= "10";
                            RAM_REG <= '1';
                        WHEN "0011" =>
                            RAM_BANK <= "11";
                            RAM_REG <= '1';
                    
                    ----------RTC-----------
                        WHEN "1000" => --$08 SEGUNDOS
                            RTC_REG <= x"08";
                            RAM_REG <= '0';
                        WHEN "1001" => --$09 MINUTOS
                            RTC_REG <= x"09";--MINUTOS;
                            RAM_REG <= '0';
                        WHEN "1010" => --$0A HORAS
                            RTC_REG <= x"0A";--HORAS;
                            RAM_REG <= '0';
                        WHEN "1011" => --$0B DIAS
                            RTC_REG <= x"0B";--DIAS;
                            RAM_REG <= '0';
                        WHEN "1100" => --$0C
                            RTC_REG <= x"0C";--DIAS1;
                            RAM_REG <= '0';
                        WHEN OTHERS => NULL;
                    END CASE;                
                WHEN OTHERS => NULL;
            END CASE;

Code:

    
        GBC_DATA <= RTC_SEC WHEN GBC_ADDRESS(15 DOWNTO 13) = "101" AND RAM_RTC_ENA = '1' AND RTC_REG = x"08" AND RAM_REG = '0' ELSE "ZZZZZZZZ";
    GBC_DATA <= RTC_MIN WHEN GBC_ADDRESS(15 DOWNTO 13) = "101" AND RAM_RTC_ENA = '1' AND RTC_REG = x"09" AND RAM_REG = '0' ELSE "ZZZZZZZZ";
    GBC_DATA <= RTC_HORA WHEN GBC_ADDRESS(15 DOWNTO 13) = "101" AND RAM_RTC_ENA = '1' AND RTC_REG = x"0A" AND RAM_REG = '0' ELSE "ZZZZZZZZ";
    GBC_DATA <= RTC_DIAS0 WHEN GBC_ADDRESS(15 DOWNTO 13) = "101" AND RAM_RTC_ENA = '1' AND RTC_REG = x"0B" AND RAM_REG = '0' ELSE "ZZZZZZZZ";
    GBC_DATA <= RTC_DIAS1 WHEN GBC_ADDRESS(15 DOWNTO 13) = "101" AND RAM_RTC_ENA = '1' AND RTC_REG = x"0C" AND RAM_REG = '0' ELSE "ZZZZZZZZ";
    
    CLK_WAIT:PROCESS(GBC_CLK)
        BEGIN
            IF RISING_EDGE (GBC_CLK) THEN
                CLK_HALT <= CLK_HALT + 1;
            END IF;
        END PROCESS;
    
    RTC_RD:PROCESS(RTC_REG, GBC_ADDRESS, RAM_RTC_ENA, SEGUNDOS, CLK_HALT)--, MINUTOS, HORAS, DIAS, DIAS1)
        BEGIN 
            IF GBC_ADDRESS(15 DOWNTO 13) = "101" AND RAM_RTC_ENA = '1' AND GBC_CS = '1' AND GBC_WR = '1' AND CLK_HALT = "11" THEN
                CASE RTC_REG IS
                    WHEN x"08" => -- SEGUNDOS
                        RTC_SEC  <= SEGUNDOS;
                    WHEN x"09" =>
                        RTC_MIN  <= MINUTOS;
                    WHEN x"0A" =>
                        RTC_HORA  <= HORAS;
                    WHEN x"0B" =>
                        RTC_DIAS0 <= DIAS0;
                    WHEN x"0C" =>
                        RTC_DIAS1 <= DIAS1;
                    WHEN OTHERS => 
                        GBC_DATA <= "ZZZZZZZZ";
                END CASE;
            END IF;
    END PROCESS;

Huge thanks for the support

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson