NAUG Ch19 — Clocks, Timers, CMOS RAM

Holmes & Dickens, The New Advanced User Guide, pp.359-371. Three things bundled together:

  1. System clock + interval timer — two 5-byte software clocks updated 100×/sec by the System VIA T1 IRQ (interrupts).
  2. Master 146818 real-time clock — battery-backed, keeps time across power-off. Compact has no RTC.
  3. CMOS RAM (Master) / EEPROM (Compact) — non-volatile config storage accessed via slow-bus.

System clock + interval timer

Both are 5-byte values, LSB first, in OS workspace around &292-&29F (os-workspace). Incremented every centisecond by the 100 Hz T1 handler.

OSWORDFunctionBlock size
&01Read system clock5 bytes returned
&02Write system clock5 bytes input
&03Read interval timer5 bytes returned
&04Write interval timer5 bytes input

X+Y point to the parameter block in memory.

System clock is what BASIC’s TIME function reads. Interval timer is decremented per tick; when it reaches zero, event 5 fires (events) — useful as a one-shot timer callback.

Dual-clock atomicity

MOS keeps two copies of the system clock (likewise interval timer). They’re incremented alternately so a reader can never catch one mid-increment. OSBYTE &F3 reads which copy is current — returns 5 or 10, an offset from &28D to the current 5-byte clock. Direct readers should:

  1. Read OSBYTE &F3 → offset.
  2. Read 5 bytes from &28D + offset.

Or just use OSWORD &01/&03 which handles this atomically.

Master RTC (146818 CMOS clock)

Master 128 has a Motorola/Hitachi 146818-class RTC chip. Master Compact has no RTC (returns Fri,31 Dec 1999.23:59:59 for *TIME).

OSWORD &0E — Read RTC

XY+0 selects mode:

| XY=0 | Read clock → 24-byte string ddd,nn mmm yyyy.hh:mm:ss\r at XY+0 | | XY=1 | Read clock → 7-byte BCD at XY: year/month/day/dow/hh/mm/ss | | XY=2 | Convert BCD at XY+1..+7 → 24-byte text string back into XY+0..+23 |

OSWORD &0F — Write RTC

XY (first byte) selects mode:

| XY=8 | Time only: hh:mm:ss text at XY+1..+8 | | XY=15 | Date only: ddd,nn mmm yyyy at XY+1..+15 | | XY=24 | Time + date together: full 24-byte text at XY+1..+24 |

CMOS RAM / EEPROM (Master / Compact)

  • Master 128: 50 bytes of battery-backed CMOS RAM in the 146818 chip. Locations 0-13 are the RTC’s time/control regs; locations 14-63 are RAM.
  • Master Compact: 128 or 256 byte EEPROM (write-cycle limited — ~10,000 per location).

Accessed via slow-bus through System VIA. Two OSBYTEs:

OSBYTEFunction
&A1 (161)Read CMOS RAM/EEPROM (X = location, returns byte in Y)
&A2 (162)Write CMOS RAM/EEPROM (X = location, Y = byte)

On Compact, OSBYTE &A1, X=&FF returns Y=0 (no EEPROM), Y=&7F (128B), Y=&FF (256B).

Master CMOS layout (§19.5.1 p357)

AddrFunction
0Econet station number
1File server station number
2File server network number
3Printer server station number
4Printer server network number
5d0-3 default FS ROM, d4-7 default language ROM
6ROMs 0-7 inserted bits
7ROMs 8-15 inserted bits
8EDIT ROM data
9Telecomms reserved
10d0-2 default MODE, d3 shadow, d4 interlace, d5-7 *TV setting
11FDRIVE / CAPS / dir-load / default-drive bits
12Keyboard auto-repeat delay
13Keyboard auto-repeat rate
14Printer ignore character
15Tube selection + baud rate + *FX5
16BEEP loudness + Tube int/ext + scrolling + boot + serial format
17ANFS settings
18Compact joystick settings
19Reserved
20-29Reserved Acorn firmware
30-45Allocated to ROMs 0-15
46-49User applications

*CONFIGURE and *STATUS commands manipulate these — typically the right approach for user-visible config.

146818 hardware registers (Master only, §19.6)

When direct chip access is needed (e.g. for alarm interrupts not exposed by MOS):

AddrFunction
0-9Time/date registers (BCD or binary per DM bit)
10Register A — UIP, divider, periodic interrupt rate
11Register B — SET, PIE, AIE, UIE, SQWE, DM, 24/12, DSE
12Register C — IRQF, PF, AF, UF (read-only, clear on read)
13Register D — VRT (valid RAM and time)
14-6350 bytes user RAM

Three interrupt sources

  • Alarm IRQ (AIE bit) — fires when current time matches alarm time. Alarm bytes can be set to &FF for “don’t care” (e.g. every minute).
  • Periodic IRQ (PIE bit) — rates from 122 µs to 500 ms, selectable via RS3..RS0.
  • Update-ended IRQ (UIE bit) — fires after each 1.984 ms update cycle.

Alarm IRQs are physically disconnected by default — must close link LK4 on the Master mainboard to enable. Otherwise no IRQ reaches the 65C12 regardless of how you program the chip.

Direct chip access via slow-bus

Like the sound chip and keyboard, the CMOS/RTC sits on the System VIA’s slow peripheral bus. PB6 = chip enable, PB7 = address strobe. Worked example in §19.6 (§p362-364) shows a complete IRQ-driven alarm-clock pattern.

OSBYTE summary

OSBYTEFunction
&A1 (161)Read CMOS RAM/EEPROM
&A2 (162)Write CMOS RAM/EEPROM
&F3 (243)Read which clock-copy is current (offset 5 or 10)

Filed into

  • clocks — System clock + interval timer reference.
  • cmos-rtc — 146818 chip + register layout + IRQ sources (Master only).
  • Updates: osword&01-&04, &0E, &0F linked.
  • Updates: osbyte&A1, &A2, &F3 linked.

Open follow-ups

  • Master *CONFIGURE / *STATUS command syntax — only listed at headline level. Would need the Master User Guide for the full per-option enumeration.
  • Compact EEPROM write-cycle wear levelling — none provided by MOS; if heavy-writing apps care, they should implement their own.

This wiki is curated by Claude following the LLM-Wiki methodology — a human curates source documents, the LLM compiles structured cross-linked markdown. Content may contain errors, omissions, or stale claims. For authoritative information refer to the original source documents in the bbc-documents GitHub archive.