Skip to content

Commit ca2df31

Browse files
jecassisjcmoyer
authored andcommitted
Synchronize to 0be4ab0 of 'jcmoyer/Nuked-SC55'
Co-authored-by: J.C. Moyer <jcmoyer32@gmail.com>
1 parent 1ea42b2 commit ca2df31

File tree

18 files changed

+1506
-1061
lines changed

18 files changed

+1506
-1061
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ jobs:
4747
VCPKG_DEFAULT_TRIPLET: ${{ matrix.triplet }}
4848

4949
steps:
50-
- uses: actions/checkout@v5
50+
- uses: actions/checkout@v6
5151
with:
5252
submodules: true
5353

5454
- name: Install CMake
55-
uses: lukka/get-cmake@latest
55+
uses: lukka/get-cmake@v4
5656
with:
5757
cmakeVersion: ~3.31.0
5858
ninjaVersion: latest
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#pragma once
2+
3+
#include <bit>
4+
#include <cassert>
5+
#include <cstddef>
6+
#include <cstdint>
7+
8+
// Implements an ordered set of integers backed by a single word. This is
9+
// functionally equivalent to std::set<unsigned_type>, but flat and
10+
// non-allocating. The tradeoff is that this type only supports values in the
11+
// range 0..63. It is intended to be used with small, contiguous enumerations
12+
// like MCU_Interrupt_Source.
13+
//
14+
// Example usage:
15+
//
16+
// BoundedOrderedBitSet<6> s;
17+
// s.Include(5);
18+
// s.Include(0);
19+
// s.Include(2);
20+
// for (auto val : s)
21+
// printf("%d\n", val);
22+
//
23+
// ==> prints 0, 2, 5
24+
25+
template <size_t Bits>
26+
struct BitsToType;
27+
28+
template <size_t Bits>
29+
requires(0 < Bits && Bits <= 8)
30+
struct BitsToType<Bits>
31+
{
32+
using Type = uint8_t;
33+
};
34+
35+
template <size_t Bits>
36+
requires(8 < Bits && Bits <= 16)
37+
struct BitsToType<Bits>
38+
{
39+
using Type = uint16_t;
40+
};
41+
42+
template <size_t Bits>
43+
requires(16 < Bits && Bits <= 32)
44+
struct BitsToType<Bits>
45+
{
46+
using Type = uint32_t;
47+
};
48+
49+
template <size_t Bits>
50+
requires(32 < Bits && Bits <= 64)
51+
struct BitsToType<Bits>
52+
{
53+
using Type = uint64_t;
54+
};
55+
56+
// Bits: number of bits in the set. The range of elements is 0..Bits - 1.
57+
// AccessType: the type to access bits through. May be an enum.
58+
template <size_t Bits, typename AccessType = typename BitsToType<Bits>::Type>
59+
struct BoundedOrderedBitSet
60+
{
61+
public:
62+
using UnderlyingType = typename BitsToType<Bits>::Type;
63+
64+
int Size() const
65+
{
66+
return std::popcount(m_set);
67+
}
68+
69+
void Include(const AccessType& item)
70+
{
71+
assert(item < Bits);
72+
m_set |= static_cast<UnderlyingType>(1 << item);
73+
}
74+
75+
void Exclude(const AccessType& item)
76+
{
77+
assert(item < Bits);
78+
m_set &= static_cast<UnderlyingType>(~(1 << item));
79+
}
80+
81+
bool Contains(const AccessType& item) const
82+
{
83+
assert(item < Bits);
84+
return m_set & (1 << item);
85+
}
86+
87+
class Iterator
88+
{
89+
public:
90+
Iterator& operator++()
91+
{
92+
m_state &= m_state - 1;
93+
return *this;
94+
}
95+
96+
AccessType operator*() const
97+
{
98+
return static_cast<AccessType>(std::countr_zero(m_state));
99+
}
100+
101+
bool operator==(const Iterator& rhs) const
102+
{
103+
return m_state == rhs.m_state;
104+
}
105+
106+
bool operator!=(const Iterator& rhs) const
107+
{
108+
return !(*this == rhs);
109+
}
110+
111+
private:
112+
Iterator(UnderlyingType state)
113+
: m_state(state)
114+
{
115+
}
116+
117+
UnderlyingType m_state;
118+
119+
friend BoundedOrderedBitSet<Bits, AccessType>;
120+
};
121+
122+
Iterator begin() const
123+
{
124+
return Iterator{m_set};
125+
}
126+
127+
Iterator end() const
128+
{
129+
return Iterator{0};
130+
}
131+
132+
private:
133+
UnderlyingType m_set = 0;
134+
};

src/nuked-sc55/backend/emu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ bool Emulator::LoadRom(RomLocation location, std::span<const uint8_t> source)
251251
//fprintf(stderr, "FATAL: %s requires a power-of-2 size\n", ToCString(location));
252252
return false;
253253
}
254-
GetMCU().rom2_mask = (int)source.size() - 1;
254+
GetMCU().rom2_mask = (uint32_t)source.size() - 1;
255255
}
256256

257257
std::copy(source.begin(), source.end(), buffer.begin());

src/nuked-sc55/backend/lcd.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#include "lcd_font.h"
3939
#include <cstring>
4040

41-
void LCD_Enable(lcd_t& lcd, uint32_t enable)
41+
void LCD_Enable(lcd_t& lcd, bool enable)
4242
{
4343
lcd.enable = enable;
4444
}
@@ -306,7 +306,7 @@ void LCD_FontRenderLR(lcd_t& lcd, uint8_t* LCD_CG, uint8_t ch)
306306
f = &lcd_font[ch - 16][0];
307307
else
308308
f = &LCD_CG[(ch & 7) * 8];
309-
int col;
309+
uint32_t col;
310310
if (f[0] & 1)
311311
{
312312
col = lcd.color1;

src/nuked-sc55/backend/lcd.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ struct lcd_t {
7777
uint8_t LCD_CG[64]{};
7878

7979
// updated by MCU via LCD_Enable
80-
std::atomic<uint8_t> enable = 0;
80+
std::atomic<bool> enable = false;
8181

8282
uint32_t buffer[lcd_height_max][lcd_width_max]{};
8383

@@ -91,5 +91,5 @@ void LCD_Init(lcd_t& lcd, mcu_t& mcu);
9191
bool LCD_Start(lcd_t& lcd);
9292
void LCD_Stop(lcd_t& lcd);
9393
void LCD_Write(lcd_t& lcd, uint32_t address, uint8_t data);
94-
void LCD_Enable(lcd_t& lcd, uint32_t enable);
94+
void LCD_Enable(lcd_t& lcd, bool enable);
9595
void LCD_Render(lcd_t& lcd);

0 commit comments

Comments
 (0)