mirror of
https://github.com/lefticus/6502-cpp.git
synced 2024-10-15 00:24:24 +00:00
Initial support for __mulhi3
This commit is contained in:
parent
468e794d5e
commit
49cf9cc32d
35
include/lib1funcs.hpp
Normal file
35
include/lib1funcs.hpp
Normal file
@ -0,0 +1,35 @@
|
||||
|
||||
static constexpr std::string_view __mulhi3 =
|
||||
R"(
|
||||
;;; based on protocol from gcc's calling conventions for AVR
|
||||
|
||||
;;; R25:R24 = R23:R22 * R25:R24
|
||||
;;; Clobbers: __tmp_reg__, R21..R23
|
||||
|
||||
__mulhi3:
|
||||
mov __temp_reg__,r24
|
||||
mov r21,r25
|
||||
ldi r25,0
|
||||
ldi r24,0
|
||||
cp __temp_reg__,__zero_reg__
|
||||
cpc r21,__zero_reg__
|
||||
breq .__mulhi3_L5
|
||||
.__mulhi3_L4:
|
||||
sbrs __temp_reg__,0
|
||||
rjmp .__mulhi3_L3
|
||||
add r24,r22
|
||||
adc r25,r23
|
||||
.__mulhi3_L3:
|
||||
lsr r21
|
||||
ror __temp_reg__
|
||||
lsl r22
|
||||
rol r23
|
||||
cp __temp_reg__,__zero_reg__
|
||||
cpc r21,__zero_reg__
|
||||
brne .__mulhi3_L4
|
||||
ret
|
||||
.__mulhi3_L5:
|
||||
ret
|
||||
)";
|
||||
|
||||
|
3315
lib1funcs.S
3315
lib1funcs.S
File diff suppressed because it is too large
Load Diff
@ -16,10 +16,10 @@
|
||||
|
||||
#include "include/6502.hpp"
|
||||
#include "include/assembly.hpp"
|
||||
#include "include/lib1funcs.hpp"
|
||||
#include "include/optimizer.hpp"
|
||||
#include "include/personalities/c64.hpp"
|
||||
|
||||
|
||||
int to_int(const std::string_view sv)
|
||||
{
|
||||
int result{};
|
||||
@ -875,9 +875,7 @@ std::vector<mos6502> run(const Personality &personality, std::istream &input)
|
||||
|
||||
std::vector<AVR> instructions;
|
||||
|
||||
while (input.good()) {
|
||||
std::string line;
|
||||
getline(input, line);
|
||||
const auto parse_line = [&](const auto &line) {
|
||||
try {
|
||||
std::smatch match;
|
||||
if (std::regex_match(line, match, Label)) {
|
||||
@ -902,6 +900,29 @@ std::vector<mos6502> run(const Personality &personality, std::istream &input)
|
||||
}
|
||||
|
||||
++lineno;
|
||||
};
|
||||
|
||||
const auto parse_stream = [&](auto &stream) {
|
||||
while (stream.good()) {
|
||||
std::string line;
|
||||
getline(stream, line);
|
||||
parse_line(line);
|
||||
}
|
||||
};
|
||||
|
||||
const auto parse_string = [&](const auto &string) {
|
||||
std::stringstream ss{std::string(string)};
|
||||
parse_stream(ss);
|
||||
};
|
||||
|
||||
parse_stream(input);
|
||||
|
||||
const bool needs_mulhi3 = std::any_of(begin(instructions), end(instructions), [](const AVR &instruction) {
|
||||
return instruction.line_text.find("__mulhi3") != std::string::npos;
|
||||
});
|
||||
|
||||
if (needs_mulhi3) {
|
||||
parse_string(__mulhi3);
|
||||
}
|
||||
|
||||
std::set<std::string> labels;
|
||||
@ -910,7 +931,7 @@ std::vector<mos6502> run(const Personality &personality, std::istream &input)
|
||||
if (i.type == ASMLine::Type::Label) { labels.insert(i.text); }
|
||||
}
|
||||
|
||||
std::set<std::string> used_labels{ "main", "__udivmodhi4", "__mulhi3" };
|
||||
std::set<std::string> used_labels{ "main" };
|
||||
|
||||
for (const auto &i : instructions) {
|
||||
const auto check_label = [&](const std::string &value) {
|
||||
@ -963,7 +984,6 @@ std::vector<mos6502> run(const Personality &personality, std::istream &input)
|
||||
i.text = new_labels.at(i.text);
|
||||
} catch (...) {
|
||||
spdlog::warn("Unused label: '{}', consider making function static until we remove unused functions", i.text);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user