Real Time Clock Programming
This page was last modified 01:24, 17 March 2023 by Gdx. Based on work by Mars2000you and Aoineko.

Contents

Usage

MSX2 standard computers and newer use a real time clock mainly to generate the time and date. It is also used to store some system parameters that are restored when the computer is turned on.

These functions are handled by the Ricoh RP-5C01 chip or compatible.

It can also support timer or alarm but this must be managed by software because the pin that controls the alarm has never been used on any machine.

Registers

This chip has four register blocks of 4 bits registers. Each block contains 13 registers (0~12) + 3 registers (13 to 15)

Note: Several bits are not used by the clock nor the system.

Block 0

This block stores the current time, day of the week and date.

Register Bit 3 Bit 2 Bit 1 Bit 0
0 Units counter for seconds
1 0 Tens counter for seconds
2 Units counter for minutes
3 0 Tens counter for minutes
4 Units counter for hours
5 0 0 Tens counter for hours
6 0 Weekday counter
7 Units counter for days of the month
8 0 0 Tens counter for days of the month
9 Units counter for months
10 0 0 0 Tens counter for months
11 Units counter for years
12 Tens counter for years
  • All these registers are updated in real time as long as the chip is powered by the battery.

Related MSX-BASIC instructions: SET DATE, SET TIME.

Block 1

This block is used to set the alarm or the timer. Some bits are also used to select the 12/24 hour time mode and indicate the leap year. The alarm function is an optional function not used by MSX computers.

Register Bit 3 Bit 2 Bit 1 Bit 0
0 0 0 0 0
1 0 0 0 0
2 Minutes digit
3 0 Tens minutes digit
4 Hours digit
5 0 0 Tens hours digit
6 0 Weekday
7 Month day digit
8 0 0 Tens month day digit
9 0 0 0 0
10 0 0 Morning/Afternoon 12/24 hour
11 0 0 Leap year counter
12 0 0 0 0
  • "Morning/Afternoon" bit is not taken in account when "12/24 hour" bit is set.
  • The timer starts when the bit "Timer Enable" is set, otherwise, registers 2 to 8 operate in alarm mode.
  • Bits marked as 0 are not just unused, they are unusable (no write possible).
  • The game Fire Hawk - Thexder The Second Contact saves the player progression into this block when it does not detect a PAC compatible cartridge. It uses the register 2 to store the stage number to start.

Related MSX-BASIC instructions: SET DATE, SET TIME.

Block 2

The system uses this block to store several parameters it uses for initialization.

Register Bit 3 Bit 2 Bit 1 Bit 0
0 10 if registers are OK
1 X-Adjust (-7 to 8)
2 Y-Adjust (-7 to 8)
3 Unused Alternating even/uneven Interlacing SCREEN 0 / 1
4 Least significant 4 bits of WIDTH value
5 Unused Most significant 3 bits of WIDTH value
6 Initial text color
7 Initial background color
8 Initial border color
9 Transfer speed
0 = 1200 baud
1 = 2400 baud
0 = MSX Printer
1 = Non-MSX Printer
Keyclick KEY OFF/ON
10 BEEP timbre BEEP volume
11 Unused Startup logo screen colors
12 Area code:
0 = Japan; 1 = US; 2 = International; 3 = Great Britain; 4 = France;
5 = Germany; 6 = Italy; 7 = Spain; 8 = Arab Emirates; 9 = Korea; 10 = USSR;
11 ~ 15 = Undefined (as of 02/05/1986)
  • Register 0 needs to have the value 10 (0Ah). It indicates to the computer that the Real Time Clock is working and that the values stored in the next bytes need to be used. In case of power failure of this chip, the value will become 00h and the computer will use the default parameters that are included in the extension rom (or subrom). In this case, the content of Block 3 will be erased.
  • In principle, the Area code (register 12) is conceived to correspond to the main language used in the area where the computer was officially sold.
    However, it was not respected by several manufacturers outside Japan. It is the case for Arabic, French and Korean machines. In addition, the Sony HB-F9S and HB-F9P use this register to store the firmware language. Four languages are available and used codes are different (4 = English, 5 = Spanish or Dutch, 6 = French and 7 = Italian).
  • The Novaxis SCSI Disk-ROM uses the bits 3-2 of the register 3 and 11 to store the Target ID and two parameters for Driver and Multiple HDD support. The bits 2-0 of the register 12 are also used to store the parameters for the Extended Partitions support and the host ID.

Related MSX-BASIC instructions: SET ADJUST, SET BEEP, SET SCREEN, SET TITLE.

Block 3

The system uses this block to store the characters used for the password, the prompt or the title.

Register Bit 3 Bit 2 Bit 1 Bit 0
0 Data type (0~15):
0 = Title; 1 = Password; 2 = Prompt; 3 to 15 = Undefined as of 02/05/1986
1 4 LSb of 1st character, or 1 when used for the password
2 4 MSb of 1st character, or 2 when used for the password
3 4 LSb of 2nd character, or 3 when used for the password
4 4 MSb of 2nd character, or compressed password data
5 4 LSb of 3rd character, or compressed password data
6 4 MSb of 3rd character, or compressed password data
7 4 LSb of 4th character, or compressed password data
8 4 MSb of 4th character, or key cartridge presence flag
9 4 LSb of 5th character, or key cartridge value
10 4 MSb of 5th character, or key cartridge value
11 4 LSb of 6th character, or key cartridge value
12 4 MSb of 6th character, or key cartridge value
  • Stored prompt and title characters are ASCII code.
  • Concerning the key cartridge: When the flag value is different from 00, the computer will read the optional 'key cartridge value' (a 16 bit password) via I/0 port 7F and compare it with the contents of registers 9 to 12 (See also this thread)
  • MSXgl allows the programmer to save up to 6 bytes data in this block 3. It defines 2 new data types: 6=Save data, 7=Save data with signature. In the case of a save with signature, the ID of the application is stored in the 22 bits of Block 1 and allows to validate that the content of Block 3 belongs to the current application.

Related MSX-BASIC instructions: SET PASSWORD, SET PROMPT, SET TITLE.

Registers 13 to 15

These registers are commands to select a registers block to use and perform some other functions.

Register Bit 3 Bit 2 Bit 1 Bit 0
13 Timer Enable Alarm Output Enable Register-block number to select
14 Test 3 (day) Test 2 (hour) Test 1 (minute) Test 0 (second)
15 1Hz 16Hz Timer Reset Alarm Reset
  • Registers 14 and 15 are not readable.
  • The bits 1Hz, 16Hz and Alarm output enable are not used on MSX computers
  • The user is not supposed to use the test register.

I/O Ports

Port 0B4h allows you to specify the RTC register (0-15) to access, and port 0B5h allows you to read or write data in the specified register. Bits 4 to 7 of these ports are not used.

Sub-ROM BIOS Routines

The MSX standard does not recommend to use directly the I/O ports. It's better to use the two following routines. Note that only registers from blocks are accessible via these routines.

REDCLK (Sub-ROM at 01F5H)

Function: Reading a register of the internal clock (RTC).
Entry: C = block number (bits 5-4) and register (bits 3-0) to read.
Output: A = 4 least significant bits content of the register read.
Modify: AF
Note: See register block for details.

Example of use in assembler:

EXTROMequ0015fh REDCLKequ001f5h  	org0c000h DEBUT: ldc,02ch; Block 2, register 12 (0Ch) ldix,REDCLK callEXTROM ret; A = 2 if international

WRTCLK (Sub-ROM at 01F9H)

Function: Writing in a register of the internal clock (RTC).
Entry: C = block number (bits 5-4) and register (bits 3-0).
A = data to write. (4 least significant bits)
Output: None.
Modify: F
Note: See register block for details.

Use of the CMOS by software

You can use the unused memory space in the RTC to save data that persists even after the MSX is turned off.

Unused bits:

  • 22 bits in Block 1 (corresponding to the alarm configuration)
  • 4 bits in Block 2
  • 48 bits (6 bytes) in Block 3 (excluding register 0 which contains the identifier of the data type contained in this block)

However, be careful because some hardware and software use them (See the notes of the corresponding blocks).

Links