Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement MBC3 Real Time Clock in TPakio and gb mmu #13

Open
joeldipops opened this issue May 23, 2019 · 1 comment
Open

Implement MBC3 Real Time Clock in TPakio and gb mmu #13

joeldipops opened this issue May 23, 2019 · 1 comment
Labels
enhancement New feature or request

Comments

@joeldipops
Copy link
Owner

Here's the relevant section from http://gbdev.gg8.se/wiki/articles/Memory_Bank_Controllers

4000-5FFF - RAM Bank Number - or - RTC Register Select (Write Only)
As for the MBC1s RAM Banking Mode, writing a value in range for 00h-07h maps the corresponding external RAM Bank (if any) into memory at A000-BFFF. When writing a value of 08h-0Ch, this will map the corresponding RTC register into memory at A000-BFFF. That register could then be read/written by accessing any address in that area, typically that is done by using address A000.

6000-7FFF - Latch Clock Data (Write Only)
When writing 00h, and then 01h to this register, the current time becomes latched into the RTC registers. The latched data will not change until it becomes latched again, by repeating the write 00h->01h procedure. This is supposed for from the RTC registers. This can be proven by reading the latched (frozen) time from the RTC registers, and then unlatch the registers to show the clock itself continues to tick in background.

The Clock Counter Registers
08h RTC S Seconds 0-59 (0-3Bh)
09h RTC M Minutes 0-59 (0-3Bh)
0Ah RTC H Hours 0-23 (0-17h)
0Bh RTC DL Lower 8 bits of Day Counter (0-FFh)
0Ch RTC DH Upper 1 bit of Day Counter, Carry Bit, Halt Flag
Bit 0 Most significant bit of Day Counter (Bit 8)
Bit 6 Halt (0=Active, 1=Stop Timer)
Bit 7 Day Counter Carry Bit (1=Counter Overflow)
The Halt Flag is supposed to be set before to the RTC Registers.

The Day Counter
The total 9 bits of the Day Counter allow to count days in range from 0-511 (0-1FFh). The Day Counter Carry Bit becomes set when this value overflows. In that case the Carry Bit remains set until the program does reset it. Note that you can store an offset to the Day Counter in battery RAM. For example, every time you read a non-zero Day Counter, add this Counter to the offset in RAM, and reset the Counter to zero. This method allows to count any number of days, making your program Year-10000-Proof, provided that the cartridge gets used at least every 511 days.

@joeldipops joeldipops added the enhancement New feature or request label Jul 28, 2019
@joeldipops
Copy link
Owner Author

Have got the basic implementation in place, but it definitely has some bugs.

However, it's quite hard to test, so going to wait and see if mooneye-gb adds some tests for it before going further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant