blob: 555c8cb83f995cade4667f3282b33e6c816632e2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
// license:BSD-3-Clause
// copyright-holders:Aaron Giles,smf
/***************************************************************************
timehelp.h
Assorted shared functionality between timekeeping chips and RTCs.
***************************************************************************/
#ifndef MAME_MACHINE_TIMEHELP_H
#define MAME_MACHINE_TIMEHELP_H
#pragma once
class time_helper
{
public:
static inline uint8_t make_bcd(uint8_t data)
{
return (((data / 10) % 10) << 4) + (data % 10);
}
static inline uint8_t from_bcd(uint8_t data)
{
return (((data >> 4) & 15) * 10) + (data & 15);
}
static int inc_bcd(uint8_t *data, int mask, int min, int max, bool *tens_carry = nullptr)
{
int bcd = (*data + 1) & mask;
int carry = 0;
if ((bcd & 0x0f) > 9)
{
if (tens_carry)
*tens_carry = true;
bcd &= 0xf0;
bcd += 0x10;
}
else if (tens_carry)
{
*tens_carry = false;
}
if (bcd > max)
{
bcd = min;
carry = 1;
}
*data = (*data & ~mask) | (bcd & mask);
return carry;
}
};
#endif // MAME_MACHINE_TIMEHELP_H
|