1
0
mirror of https://github.com/lefticus/6502-cpp.git synced 2024-10-09 17:56:19 +00:00
6502-cpp/examples/test2.cpp
Jason Turner 5591249f2a Almost working programs with AVR conversion
* need to add a decent header address
 * probably need to fix sbrc and sbrs
2021-04-22 15:52:35 -06:00

50 lines
842 B
C++

#include <cstdint>
enum class Colors : uint8_t
{
WHITE=0x01,
BLACK=0x00
};
inline volatile uint8_t &memory_loc(const uint16_t loc)
{
return *reinterpret_cast<volatile uint8_t *>(loc);
}
inline void decrement_border_color()
{
--memory_loc(0xd020);
}
inline void increment_border_color()
{
++memory_loc(0xd020);
}
inline bool joystick_down()
{
uint8_t joystick_state = memory_loc(0xDC00);
return (joystick_state & 0x2) == 0;
}
int main()
{
const auto background_color = [](Colors col) {
memory_loc(0xd021) = static_cast<uint8_t>(col);
};
const auto border_color = [](Colors col) {
memory_loc(0xd020) = static_cast<uint8_t>(col);
};
background_color(Colors::WHITE);
while(true) {
if (joystick_down()) {
border_color(Colors::WHITE);
} else {
border_color(Colors::BLACK);
}
}
}