mirror of
https://github.com/lefticus/6502-cpp.git
synced 2024-12-22 01:30:03 +00:00
Updated 16bit counter example with higher level functions
This commit is contained in:
parent
77c25389aa
commit
ab9dd4e1b7
@ -34,21 +34,29 @@ inline void puts(uint8_t x, uint8_t y, std::string_view str) {
|
||||
str.size());
|
||||
}
|
||||
|
||||
|
||||
inline void put_hex(uint8_t x, uint8_t y, uint8_t value)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
inline void put_hex(uint8_t x, uint8_t y, uint16_t value)
|
||||
{
|
||||
}
|
||||
|
||||
inline void putc(uint8_t x, uint8_t y, uint8_t c) {
|
||||
const auto start = 0x400 + (y * 40 + x);
|
||||
poke(start, c);
|
||||
}
|
||||
|
||||
inline void put_hex(uint8_t x, uint8_t y, uint8_t value) {
|
||||
const auto put_nibble = [](auto x, auto y, uint8_t nibble) {
|
||||
if (nibble <= 9) {
|
||||
putc(x, y, nibble + 48);
|
||||
} else {
|
||||
putc(x, y, nibble - 9);
|
||||
}
|
||||
};
|
||||
|
||||
put_nibble(x + 1, y, 0xF & value);
|
||||
put_nibble(x, y, 0xF & (value >> 4));
|
||||
}
|
||||
|
||||
inline void put_hex(uint8_t x, uint8_t y, uint16_t value) {
|
||||
put_hex(x+2,y, static_cast<std::uint8_t>(0xFF & value));
|
||||
put_hex(x,y, static_cast<std::uint8_t>(0xFF & (value >> 8)));
|
||||
}
|
||||
|
||||
struct Clock {
|
||||
using milliseconds = std::chrono::duration<std::uint16_t, std::milli>;
|
||||
|
||||
@ -83,29 +91,24 @@ int main() {
|
||||
/*
|
||||
puts(5, 5, "hello world");
|
||||
puts(10, 10, "hellooooo world");
|
||||
|
||||
*/
|
||||
Clock game_clock{};
|
||||
*/
|
||||
|
||||
std::uint16_t us_elapsed = 0;
|
||||
|
||||
int y = 0;
|
||||
std::uint16_t counter = 0;
|
||||
|
||||
std::uint8_t y = 15;
|
||||
while (true) {
|
||||
// const auto us_elapsed = game_clock.restart().count();
|
||||
const auto us_elapsed = game_clock.restart().count();
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
const auto nibble = static_cast<std::uint8_t>((us_elapsed >> (i * 4)) & 0xF);
|
||||
if (nibble <= 9) {
|
||||
putc(6 - i, y, nibble + 48);
|
||||
} else {
|
||||
putc(6 - i, y, nibble - 9);
|
||||
}
|
||||
put_hex(5, y, us_elapsed);
|
||||
put_hex(11, y, counter);
|
||||
|
||||
if (y++ == 20) {
|
||||
y = 15;
|
||||
}
|
||||
|
||||
if (y++ == 5) {
|
||||
y = 0;
|
||||
}
|
||||
++us_elapsed;
|
||||
++counter;
|
||||
increment_border_color();
|
||||
}
|
||||
|
||||
|
11
src/main.cpp
11
src/main.cpp
@ -1072,9 +1072,10 @@ void translate_instruction(std::vector<mos6502> &instructions, const AVR::OpCode
|
||||
instructions.emplace_back(mos6502::OpCode::bcs, Operand(Operand::Type::literal, new_label_name));
|
||||
instructions.emplace_back(ASMLine::Type::Directive, new_label_name);
|
||||
return;
|
||||
} else {
|
||||
instructions.emplace_back(mos6502::OpCode::bcs, o1);
|
||||
}
|
||||
|
||||
throw std::runtime_error("Unable to handle unknown brsh offset");
|
||||
}
|
||||
|
||||
case AVR::OpCode::breq: {
|
||||
@ -1568,6 +1569,14 @@ bool fix_long_branches(std::vector<mos6502> &instructions, int &branch_patch_cou
|
||||
instructions.insert(std::next(std::begin(instructions), op + 2), mos6502(ASMLine::Type::Label, new_pos));
|
||||
instructions[op].comment = instructions[op + 1].comment = instructions[op + 2].comment = comment;
|
||||
return true;
|
||||
} else if (instructions[op].opcode == mos6502::OpCode::bcs) {
|
||||
const auto comment = instructions[op].comment;
|
||||
instructions[op] = mos6502(mos6502::OpCode::bcc, Operand(Operand::Type::literal, new_pos));
|
||||
instructions.insert(std::next(std::begin(instructions), op + 1),
|
||||
mos6502(mos6502::OpCode::jmp, Operand(Operand::Type::literal, going_to)));
|
||||
instructions.insert(std::next(std::begin(instructions), op + 2), mos6502(ASMLine::Type::Label, new_pos));
|
||||
instructions[op].comment = instructions[op + 1].comment = instructions[op + 2].comment = comment;
|
||||
return true;
|
||||
} else {
|
||||
throw std::runtime_error("Don't know how to reorg this branch: " + instructions[op].to_string());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user