mirror of https://github.com/stenzek/duckstation
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
584 B
C
25 lines
584 B
C
// SPDX-FileCopyrightText: 2019-2026 Connor McLaughlin <stenzek@gmail.com>
|
|
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
|
|
|
|
#pragma once
|
|
|
|
#include "types.h"
|
|
|
|
// BCD helpers
|
|
ALWAYS_INLINE constexpr u8 BinaryToBCD(u8 value)
|
|
{
|
|
return ((value / 10) << 4) + (value % 10);
|
|
}
|
|
ALWAYS_INLINE constexpr u8 PackedBCDToBinary(u8 value)
|
|
{
|
|
return ((value >> 4) * 10) + (value % 16);
|
|
}
|
|
ALWAYS_INLINE constexpr bool IsValidBCDDigit(u8 digit)
|
|
{
|
|
return (digit <= 9);
|
|
}
|
|
ALWAYS_INLINE constexpr bool IsValidPackedBCD(u8 value)
|
|
{
|
|
return IsValidBCDDigit(value & 0x0F) && IsValidBCDDigit(value >> 4);
|
|
}
|