1//============================================================================
2//
3// SSSS tt lll lll
4// SS SS tt ll ll
5// SS tttttt eeee ll ll aaaa
6// SSSS tt ee ee ll ll aa
7// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
8// SS SS tt ee ll ll aa aa
9// SSSS ttt eeeee llll llll aaaaa
10//
11// Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony
12// and the Stella Team
13//
14// See the file "License.txt" for information on usage and redistribution of
15// this file, and for a DISCLAIMER OF ALL WARRANTIES.
16//============================================================================
17
18#ifndef SMARTMOD_HXX
19#define SMARTMOD_HXX
20
21#include "bspf.hxx"
22
23// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
24template<unsigned base>
25uInt8 smartmod(uInt8 x)
26{
27 return x % base;
28}
29
30// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
31template<>
32inline uInt8 smartmod<2>(uInt8 x)
33{
34 return x & 0x01;
35}
36
37// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
38template<>
39inline uInt8 smartmod<4>(uInt8 x)
40{
41 return x & 0x03;
42}
43
44// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
45template<>
46inline uInt8 smartmod<8>(uInt8 x)
47{
48 return x & 0x07;
49}
50
51// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
52template<>
53inline uInt8 smartmod<16>(uInt8 x)
54{
55 return x & 0x0F;
56}
57
58// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
59template<>
60inline uInt8 smartmod<32>(uInt8 x)
61{
62 return x & 0x1F;
63}
64
65// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
66template<>
67inline uInt8 smartmod<64>(uInt8 x)
68{
69 return x & 0x3F;
70}
71
72// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
73template<>
74inline uInt8 smartmod<128>(uInt8 x)
75{
76 return x & 0x7F;
77}
78
79// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
80template<>
81inline uInt8 smartmod<256>(uInt8 x)
82{
83 return x & 0xFF;
84}
85
86#endif // SMARTMOD_HXX
87