OXYGENHUB
◆ main enhanced-x16-emulator / src / rtc.h
1.6 KiB · Objective-C · last changed chore(): initial commit 25 days ago source blame history raw
9120e874 Andy McCall 1
// Commander X16 Emulator
2
// Copyright (c) 2021 Michael Steil
3
// All rights reserved. License: 2-clause BSD
4
5
#ifndef _RTC_H_
6
#define _RTC_H_
7
8
#include <stdint.h>
9
#include <stdbool.h>
10
11
#ifdef __cplusplus
12
extern "C" {
13
#endif
14
15
void rtc_i2c_data(uint8_t v);
16
void rtc_init(bool set_system_time);
17
void rtc_set_system_time();
18
void rtc_step(int c);
19
uint8_t rtc_read();
20
void rtc_write();
21
22
// ─── Debugger accessor ───────────────────────────────────────────────────────
23
// Side-effect-free snapshot of RTC state. Safe to call every frame from the
24
// debugger while the emulation is running.
25
//
26
// Calendar fields are plain integers (not BCD). `nvram` is a copy of the
27
// 64-byte battery-backed NVRAM owned by the RTC.
28
29
typedef struct {
30
	bool    running;        // oscillator is running (ST bit)
31
	bool    h24;            // 24-hour mode (true) vs 12-hour AM/PM mode (false)
32
	int     seconds;        // 0-59
33
	int     minutes;        // 0-59
34
	int     hours;          // 0-23 (always stored as 24h internally)
35
	int     day_of_week;    // 1-7 (1=Monday per MCP7940N convention)
36
	int     day;            // 1-31
37
	int     month;          // 1-12
38
	int     year;           // 0-99 (years since 2000)
39
	uint8_t i2c_data_pos;   // write position in the internal I2C data buffer
40
	uint8_t nvram[0x40];    // copy of the 64-byte NVRAM (battery-backed)
41
	bool    nvram_dirty;    // NVRAM has been written since last save
42
} rtc_debug_state_t;
43
44
void rtc_debug_get_state(rtc_debug_state_t *out);
45
46
#ifdef __cplusplus
47
}
48
#endif
49
50
#endif