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());
|
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) {
|
inline void putc(uint8_t x, uint8_t y, uint8_t c) {
|
||||||
const auto start = 0x400 + (y * 40 + x);
|
const auto start = 0x400 + (y * 40 + x);
|
||||||
poke(start, c);
|
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 {
|
struct Clock {
|
||||||
using milliseconds = std::chrono::duration<std::uint16_t, std::milli>;
|
using milliseconds = std::chrono::duration<std::uint16_t, std::milli>;
|
||||||
|
|
||||||
@ -83,29 +91,24 @@ int main() {
|
|||||||
/*
|
/*
|
||||||
puts(5, 5, "hello world");
|
puts(5, 5, "hello world");
|
||||||
puts(10, 10, "hellooooo world");
|
puts(10, 10, "hellooooo world");
|
||||||
|
*/
|
||||||
Clock game_clock{};
|
Clock game_clock{};
|
||||||
*/
|
|
||||||
|
|
||||||
std::uint16_t us_elapsed = 0;
|
|
||||||
|
|
||||||
int y = 0;
|
std::uint16_t counter = 0;
|
||||||
|
|
||||||
|
std::uint8_t y = 15;
|
||||||
while (true) {
|
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) {
|
put_hex(5, y, us_elapsed);
|
||||||
const auto nibble = static_cast<std::uint8_t>((us_elapsed >> (i * 4)) & 0xF);
|
put_hex(11, y, counter);
|
||||||
if (nibble <= 9) {
|
|
||||||
putc(6 - i, y, nibble + 48);
|
if (y++ == 20) {
|
||||||
} else {
|
y = 15;
|
||||||
putc(6 - i, y, nibble - 9);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (y++ == 5) {
|
++counter;
|
||||||
y = 0;
|
|
||||||
}
|
|
||||||
++us_elapsed;
|
|
||||||
increment_border_color();
|
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(mos6502::OpCode::bcs, Operand(Operand::Type::literal, new_label_name));
|
||||||
instructions.emplace_back(ASMLine::Type::Directive, new_label_name);
|
instructions.emplace_back(ASMLine::Type::Directive, new_label_name);
|
||||||
return;
|
return;
|
||||||
|
} else {
|
||||||
|
instructions.emplace_back(mos6502::OpCode::bcs, o1);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw std::runtime_error("Unable to handle unknown brsh offset");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case AVR::OpCode::breq: {
|
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.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;
|
instructions[op].comment = instructions[op + 1].comment = instructions[op + 2].comment = comment;
|
||||||
return true;
|
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 {
|
} else {
|
||||||
throw std::runtime_error("Don't know how to reorg this branch: " + instructions[op].to_string());
|
throw std::runtime_error("Don't know how to reorg this branch: " + instructions[op].to_string());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user