Real-Time Clock: Difference between revisions

From WSdev Wiki
Jump to navigationJump to search
(get something here)
 
 
(2 intermediate revisions by 2 users not shown)
Line 5: Line 5:
== Internal operation ==
== Internal operation ==
The RTC consists of 10 total bytes of user-visible state.
The RTC consists of 10 total bytes of user-visible state.
* Configuration
* Alarm configuration (2 bytes)
The following are always interpreted as 2 digit packed BCD.
The following are always interpreted as 2 digit packed BCD.
* Year (always assumes 00 is a leap year)
* Year (always assumes 00 is a leap year)
Line 10: Line 12:
* Day-of-month (1-indexed)
* Day-of-month (1-indexed)
* Day-of-week (0-indexed and free-running, no predefined mapping of number to legal day)
* Day-of-week (0-indexed and free-running, no predefined mapping of number to legal day)
* Hour
* Hour (0x80s bit is 12/24 state)
* Minute
* Minute
* Second
* Second
* Configuration
* Alarm configuration


=== Configuration ===
=== Configuration ===
Line 78: Line 77:


As such, the only choices are:
As such, the only choices are:
* all communication to the 2003 happens while Cassette interrupts are disabled, or
* all communication to the 2003 happens while cartridge IRQs are disabled, or
* the only thing the interrupt handler can do is [[Interrupts#Interrupt_Enable|mask]] the interrupt and then [[Interrupts#Interrupt_Acknowledge|acknowledge]] it, and only afterwards handle any subsequent communication.
* the only thing the interrupt handler can do is [[Interrupts#Interrupt_Enable|mask]] the interrupt and then [[Interrupts#Interrupt_Acknowledge|acknowledge]] it, and only afterwards handle any subsequent communication.

Latest revision as of 17:41, 24 August 2023

The 2003 mapper provides a special-purpose interface to interact with Seiko's S-3511A RTC chip.

This page will cover how games expect to interact with it; not the low-level protocol specifics. (For that see the datasheet and the Timing section of this wiki)

Internal operation

The RTC consists of 10 total bytes of user-visible state.

  • Configuration
  • Alarm configuration (2 bytes)

The following are always interpreted as 2 digit packed BCD.

  • Year (always assumes 00 is a leap year)
  • Month (1=January)
  • Day-of-month (1-indexed)
  • Day-of-week (0-indexed and free-running, no predefined mapping of number to legal day)
  • Hour (0x80s bit is 12/24 state)
  • Minute
  • Second

Configuration

7  bit  0
P2A0 M0F0
|||| ||||
|||+--+-+--- always 0
||+--+-+---- IRQ mode
|+---------- 1: 24 hour mode   0: 12 hour mode
+----------- power failure occurred

Sending the Reset or Read Configuration commands clear the "power failure" bit.

Interrupts:

AMF
000 -- "No interrupts" - continuously deasserts /IRQ pin
100 -- "Alarm" - Treat "alarm configuration" as packed BCD HHMM. Assert /IRQ during that hour and minute. Hour encoding must match 12/24 bit setting.
x10 -- "Per-minute edge" - Asserts /IRQ during the first 10 ms of each minute. During following 990ms, /IRQ can be deasserted by reading the configuration register.
x11 -- "Per-minute steady" - Asserts /IRQ during the first 10ms of each minute. De-asserts /IRQ at the 30th second.
x01 -- "Frequency" - subsecond prescaler is bitwise inverted, bitwise ANDed with the lower 15 bits of the "alarm configuration" register, then all fifteen bits are NORed together. This signal directly drives the /IRQ pin.

Reset RTC ($10, $11)

Writing $10 or $11 to port $CA will send the "reset" command to the RTC. The S-3511A will then reset the year, month, day-of-month, day-of-week, hour, minute, second, config, and alarm registers. It is unknown if it resets the sub-second prescaler.

Write Configuration ($12)

Writing $12 to port $CA will send the "set configuration" command to the RTC. The 2003 expects that $CB contains valid contents by the time the 2003 sends that register's contents.

Read Configuration ($13)

Writing $13 to port $CA will send the "get configuration" command to the RTC.

Write current YMDdHMS ($14)

Writing $14 will set the current Year, Month, Day-of-Month, Day-of-Week, Hour, Minute, and Second.

Read current YMDdHMS ($15)

Writing $15 will get the current Year, Month, Day-of-Month, Day-of-Week, Hour, Minute, and Second.

Write current HMS ($16)

Writing $16 will set the current Hour, Minute, and Second.

These are the same as command $14.

Read current HMS ($17)

Writing $17 will get the current Hour, Minute, and Second.

Write alarm configuration ($18)

Writing $18 will set the current alarm configuration. The interpretation of these two bytes depend on the Configuration register

Nonsense alarm configuration ($19)

Writing $19 will set the current alarm configuration to $FFFF. The 2003 thinks it's reading from the S-3511A, but the S-3511A disagrees. $FFFF will be read back by the 2003.

Write nonsense ($1A)

Writing $1A expects to send 2 bytes to the RTC. The S-3511A ignores them.

Read nonsense ($1B)

Writing $1B expects to read 2 bytes from the RTC. The S-3511A leaves its output high, returning $FFFF.

Interrupts

The 2003 and S-3511A do not provide a thread-safe way to acknowledge the IRQ. Since the 2003 only holds one byte at a time, an interrupt can be fired in the middle of a multi-byte read or write without knowing what needs to be done for the rest of the command, nor how to safely restart that command when exiting the interrupt.

As such, the only choices are:

  • all communication to the 2003 happens while cartridge IRQs are disabled, or
  • the only thing the interrupt handler can do is mask the interrupt and then acknowledge it, and only afterwards handle any subsequent communication.