-
-
Notifications
You must be signed in to change notification settings - Fork 125
Update MBC3.md #637
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
base: master
Are you sure you want to change the base?
Update MBC3.md #637
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,15 @@ | ||
| # MBC3 | ||
|
|
||
| (max 2MByte ROM and/or 32KByte RAM and Timer) | ||
| (max 4 MiB ROM, 64 KiB RAM, and timer) | ||
|
|
||
| Beside for the ability to access up to 2MB ROM (128 banks), and 32KB RAM | ||
| (4 banks), the MBC3 also includes a built-in Real Time Clock (RTC). The | ||
| RTC requires an external 32.768 kHz Quartz Oscillator, and an external | ||
| battery (if it should continue to tick when the Game Boy is turned off). | ||
| Beside for the ability to access up to 4 MiB ROM (256 banks) and 64 KiB RAM | ||
| (8 banks), the MBC3 also includes a built-in Real Time Clock (RTC), sometimes referred to as the timer. The | ||
| RTC requires an external 32.768 kHz quartz crystal oscillator, and an external | ||
| battery (if it should continue to tick when the Game Boy is turned off). All official MBC3 releases utilize cartridge RAM and a battery, but a few DMG games don't use the timer and therefore lack the crystal. | ||
|
|
||
| There are (at least) four different versions of this MBC that can be distinguished by the print on the chip itself: MBC3, MBC3A, MBC3B and MBC30. Only the latter supports the full 4 MiB of ROM and 64 KiB of RAM whereas the other three can only access half of that. The MBC30 is only found in the Japanese _Pocket Monsters: Crystal Version_, which is also the only release with the full 64 KiB of RAM (8 banks). No game uses the full 4 MiB. | ||
|
|
||
| The different versions of the chip are not distinguished in the cartridge header, not even the MBC30. | ||
|
|
||
| ## Memory | ||
|
|
||
|
|
@@ -58,11 +62,25 @@ Controls what is mapped into memory at A000-BFFF. | |
|
|
||
| ### 6000-7FFF - Latch Clock Data (Write Only) | ||
|
|
||
| When writing $00, and then $01 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 $00-\>$01 | ||
| procedure. This provides a way to read the RTC registers while the | ||
| clock keeps ticking. | ||
| Latching makes a static copy of the current timestamp available in the clock counter registers while the clock keeps running in the background. This makes sure that your reads from the counter registers will be consistent, since any counter overflowing while you read the different parts can have you read an incorrect value (e.g. reading the minute at 11:59 and the hour at 12:00 will give 12:59.) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These sections should start with the basic technical information about the register itself.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Latching is a rather technical term. I felt that it was more appropriate to describe this first, instead of writing "The latch clock data register can latch clock data." as the first sentence.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not and would not suggest including "The latch clock data register can latch clock data." as the first (or any) sentence. You can see what I suggested should be the first thing in the section in my comment above. I understood what you wrote and I did read the whole thing before choosing to submit the review including this comment. I agree that an explanation of the purpose of the latching feature is necessary. But I don't think that should be the first thing under this heading. (Like all the other comments, the relevant line here is the bottom one. The three above came for free.) |
||
|
|
||
| The exact behavior of this register varies depending on hardware: | ||
|
|
||
| MBC3B provides a running clock on power-on and after writing any even value to this register. It is still recommended to latch the clock by writing any odd value. MBC3B can only latch while it provides a running clock, so you must write an even value before you can write an odd value again. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think the two versions of this chip are mentioned before this point? I'd suggest adding a paragraph explaining this in the intro section.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are at least 4 versions of the chip to be clear: MBC3, MBC3A, MBC3B, and MBC30. Only MBC3A and MBC3B have been tested for latching quirks (so far). |
||
|
|
||
| MBC3A's clock counters are indeterminate by default. Writing any value to this register latches the clock. MBC3A cannot provide a running clock. Naturally, it can latch repeatedly. | ||
|
||
|
|
||
| **tl;dr:** Write $00 then $01 to this register to safely trigger latching on all versions of the chip. | ||
|
||
|
|
||
| :::tip | ||
|
|
||
| **Help wanted** | ||
|
|
||
| The exact latching behavior of MBC3 and MBC30 has not been tested and the sample size could be improved even for the MBC3A and MBC3B. | ||
|
|
||
| If you would like to help, have a flashcart and any official RTC cartridge, please reach out to us on gbdev Discord so you can be given the test ROMs. | ||
|
|
||
| ::: | ||
|
|
||
| ### Clock Counter Registers | ||
| | Register | Name | Description | Range | | ||
|
|
@@ -73,8 +91,13 @@ clock keeps ticking. | |
| | $0B | RTC DL | Lower 8 bits of Day Counter | ($00-$FF) | | ||
| | $0C | RTC DH | Upper 1 bit of Day Counter, Carry Bit, Halt Flag. <br>Bit 0: Most significant bit (Bit 8) of Day Counter<br>Bit 6: Halt (0=Active, 1=Stop Timer)<br>Bit 7: Day Counter Carry Bit (1=Counter Overflow) | | | ||
|
|
||
| The Halt Flag is supposed to be set before **writing** to the RTC | ||
| Registers. | ||
| The Halt Flag is supposed to be set before **writing** to the RTC Registers. This makes sure no register overflows while you write the different parts. The MBC3 chip however does not require you to halt or latch the clock before you write to the counter registers. Note that latching also prevents you from seeing your writes reflected immediately. | ||
nummacway marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Bits that are not required to store the above information will be ignored and always read 0. | ||
|
|
||
| You can write values larger than the ones mentioned above (up to 63 for seconds and minutes, and up to 31 for hours). Invalid values will then continue incrementing like a valid value and will only overflow once the available bits no longer suffice. This overflow however will not cause a carry, neither does writing 60 or 24 directly. For example, if you write 30:59:63 (and clear the Halt Flag), it will be 30:59:00 one second later, and 31:00:00 one minute after that. | ||
|
|
||
| Writing to the seconds register also resets the inaccessible sub-second counter. | ||
|
|
||
| ### The Day Counter | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only place I've seen it referred to as the timer is in this file. Adding the alternative terminology makes it less clear what it is, which is an RTC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both Pan Docs and RGBLINK exclusively use "timer". Only this file uses RTC. This is because it isn't a real-time clock as it cannot tell you the date. It has the days past since a certain period in time. It's simply a persistent timer. Using the hours, minutes, seconds counter as a clock is simply a feature that could be added easily.