mirror of
https://github.com/TomHarte/CLK.git
synced 2025-01-11 08:30:55 +00:00
Clean up repetition.
This commit is contained in:
parent
fbfa26ad5e
commit
1c6a0ad3f7
@ -805,71 +805,20 @@ void Base<personality>::commit_register(int reg, uint8_t value) {
|
||||
// i.e. scrolling.
|
||||
break;
|
||||
|
||||
case 32:
|
||||
Storage<personality>::command_context_.source_x =
|
||||
(Storage<personality>::command_context_.source_x & ~0xff) |
|
||||
value;
|
||||
break;
|
||||
case 33:
|
||||
Storage<personality>::command_context_.source_x =
|
||||
(Storage<personality>::command_context_.source_x & ~0x100) |
|
||||
((value & 1) << 8);
|
||||
break;
|
||||
case 32: Storage<personality>::command_context_.source.template set<0, false>(value); break;
|
||||
case 33: Storage<personality>::command_context_.source.template set<0, true>(value); break;
|
||||
case 34: Storage<personality>::command_context_.source.template set<1, false>(value); break;
|
||||
case 35: Storage<personality>::command_context_.source.template set<1, true>(value); break;
|
||||
|
||||
case 34:
|
||||
Storage<personality>::command_context_.source_y =
|
||||
(Storage<personality>::command_context_.source_y & ~0xff) |
|
||||
value;
|
||||
break;
|
||||
case 35:
|
||||
Storage<personality>::command_context_.source_y =
|
||||
(Storage<personality>::command_context_.source_y & ~0x300) |
|
||||
((value & 3) << 8);
|
||||
break;
|
||||
case 36: Storage<personality>::command_context_.destination.template set<0, false>(value); break;
|
||||
case 37: Storage<personality>::command_context_.destination.template set<0, true>(value); break;
|
||||
case 38: Storage<personality>::command_context_.destination.template set<1, false>(value); break;
|
||||
case 39: Storage<personality>::command_context_.destination.template set<1, true>(value); break;
|
||||
|
||||
case 36:
|
||||
Storage<personality>::command_context_.destination_x =
|
||||
(Storage<personality>::command_context_.destination_x & ~0xff) |
|
||||
value;
|
||||
break;
|
||||
case 37:
|
||||
Storage<personality>::command_context_.destination_x =
|
||||
(Storage<personality>::command_context_.destination_x & ~0x100) |
|
||||
((value & 1) << 8);
|
||||
break;
|
||||
|
||||
case 38:
|
||||
Storage<personality>::command_context_.destination_y =
|
||||
(Storage<personality>::command_context_.destination_y & ~0xff) |
|
||||
value;
|
||||
break;
|
||||
case 39:
|
||||
Storage<personality>::command_context_.destination_y =
|
||||
(Storage<personality>::command_context_.destination_y & ~0x300) |
|
||||
((value & 3) << 8);
|
||||
break;
|
||||
|
||||
case 40:
|
||||
Storage<personality>::command_context_.size_x =
|
||||
(Storage<personality>::command_context_.size_x & ~0xff) |
|
||||
value;
|
||||
break;
|
||||
case 41:
|
||||
Storage<personality>::command_context_.size_x =
|
||||
(Storage<personality>::command_context_.size_x & ~0x100) |
|
||||
((value & 1) << 8);
|
||||
break;
|
||||
|
||||
case 42:
|
||||
Storage<personality>::command_context_.size_y =
|
||||
(Storage<personality>::command_context_.size_y & ~0xff) |
|
||||
value;
|
||||
break;
|
||||
case 43:
|
||||
Storage<personality>::command_context_.size_y =
|
||||
(Storage<personality>::command_context_.size_y & ~0x300) |
|
||||
((value & 3) << 8);
|
||||
break;
|
||||
case 40: Storage<personality>::command_context_.size.template set<0, false>(value); break;
|
||||
case 41: Storage<personality>::command_context_.size.template set<0, true>(value); break;
|
||||
case 42: Storage<personality>::command_context_.size.template set<1, false>(value); break;
|
||||
case 43: Storage<personality>::command_context_.size.template set<1, true>(value); break;
|
||||
|
||||
case 44:
|
||||
Storage<personality>::command_context_.colour = value;
|
||||
|
@ -16,10 +16,26 @@ namespace TMS {
|
||||
|
||||
// MARK: - Generics.
|
||||
|
||||
struct Vector {
|
||||
int v[2]{};
|
||||
|
||||
template <int offset, bool high> void set(uint8_t value) {
|
||||
constexpr uint8_t mask = high ? (offset ? 0x3 : 0x1) : 0xff;
|
||||
constexpr int shift = high ? 8 : 0;
|
||||
v[offset] = (v[offset] & ~(mask << shift)) | (value << shift);
|
||||
}
|
||||
|
||||
Vector & operator += (const Vector &rhs) {
|
||||
v[0] += rhs.v[0];
|
||||
v[1] += rhs.v[1];
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
struct CommandContext {
|
||||
int source_x = 0, source_y = 0;
|
||||
int destination_x = 0, destination_y = 0;
|
||||
int size_x = 0, size_y = 0;
|
||||
Vector source;
|
||||
Vector destination;
|
||||
Vector size;
|
||||
uint8_t colour = 0;
|
||||
uint8_t arguments = 0;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user