Nugget
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
msf.hh
Go to the documentation of this file.
1/*
2
3MIT License
4
5Copyright (c) 2022 PCSX-Redux authors
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26
27#pragma once
28
29#include <stdint.h>
30
31#include <compare>
32
33namespace psyqo {
34
35static inline constexpr uint8_t btoi(uint8_t b) { return ((b / 16) * 10) + (b % 16); }
36static inline constexpr uint8_t itob(uint8_t i) { return ((i / 10) * 16) + (i % 10); }
37
38struct MSF {
39 MSF() : m(0), s(0), f(0) {}
40 MSF(uint8_t m, uint8_t s, uint8_t f) : m(m), s(s), f(f) {}
41 explicit MSF(uint32_t lba);
42 auto operator<=>(const MSF &other) const;
43 bool operator==(const MSF &other) const { return m == other.m && s == other.s && f == other.f; }
44 MSF &operator++();
46 MSF tmp = *this;
47 ++(*this);
48 return tmp;
49 }
50 constexpr uint32_t toLBA() const { return (m * 60 + s) * 75 + f; }
51 constexpr void toBCD(uint8_t *dst) const {
52 dst[0] = itob(m);
53 dst[1] = itob(s);
54 dst[2] = itob(f);
55 }
56 constexpr void fromBCD(const uint8_t *src) {
57 m = btoi(src[0]);
58 s = btoi(src[1]);
59 f = btoi(src[2]);
60 }
61 void reset() { m = s = f = 0; }
62 union {
63 struct {
64 uint8_t m;
65 uint8_t s;
66 uint8_t f;
67 uint8_t pad;
68 };
69 uint8_t data[4];
71 };
72};
73
74} // namespace psyqo
Definition cdrom-loader.hh:39
char b[9]
Definition string.c:47
Definition msf.hh:38
void reset()
Definition msf.hh:61
uint8_t data[4]
Definition msf.hh:69
uint32_t full
Definition msf.hh:70
uint8_t f
Definition msf.hh:66
MSF operator++(int)
Definition msf.hh:45
MSF()
Definition msf.hh:39
auto operator<=>(const MSF &other) const
Definition msf.cpp:37
MSF(uint8_t m, uint8_t s, uint8_t f)
Definition msf.hh:40
constexpr void fromBCD(const uint8_t *src)
Definition msf.hh:56
uint8_t s
Definition msf.hh:65
constexpr uint32_t toLBA() const
Definition msf.hh:50
constexpr void toBCD(uint8_t *dst) const
Definition msf.hh:51
uint8_t m
Definition msf.hh:64
uint8_t pad
Definition msf.hh:67
MSF & operator++()
Definition msf.cpp:43
bool operator==(const MSF &other) const
Definition msf.hh:43
static const char * src
Definition syscalls.h:79
void uint32_t(classId, spec)