| 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 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 24 | template<unsigned base> |
| 25 | uInt8 smartmod(uInt8 x) |
| 26 | { |
| 27 | return x % base; |
| 28 | } |
| 29 | |
| 30 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 31 | template<> |
| 32 | inline uInt8 smartmod<2>(uInt8 x) |
| 33 | { |
| 34 | return x & 0x01; |
| 35 | } |
| 36 | |
| 37 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 38 | template<> |
| 39 | inline uInt8 smartmod<4>(uInt8 x) |
| 40 | { |
| 41 | return x & 0x03; |
| 42 | } |
| 43 | |
| 44 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 45 | template<> |
| 46 | inline uInt8 smartmod<8>(uInt8 x) |
| 47 | { |
| 48 | return x & 0x07; |
| 49 | } |
| 50 | |
| 51 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 52 | template<> |
| 53 | inline uInt8 smartmod<16>(uInt8 x) |
| 54 | { |
| 55 | return x & 0x0F; |
| 56 | } |
| 57 | |
| 58 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 59 | template<> |
| 60 | inline uInt8 smartmod<32>(uInt8 x) |
| 61 | { |
| 62 | return x & 0x1F; |
| 63 | } |
| 64 | |
| 65 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 66 | template<> |
| 67 | inline uInt8 smartmod<64>(uInt8 x) |
| 68 | { |
| 69 | return x & 0x3F; |
| 70 | } |
| 71 | |
| 72 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 73 | template<> |
| 74 | inline uInt8 smartmod<128>(uInt8 x) |
| 75 | { |
| 76 | return x & 0x7F; |
| 77 | } |
| 78 | |
| 79 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 80 | template<> |
| 81 | inline uInt8 smartmod<256>(uInt8 x) |
| 82 | { |
| 83 | return x & 0xFF; |
| 84 | } |
| 85 | |
| 86 | #endif // SMARTMOD_HXX |
| 87 | |