fix djn again, and pre-dec / post-inc; few other changes
This commit is contained in:
parent
e56afe8885
commit
28e855f542
13 changed files with 145 additions and 91 deletions
|
@ -63,7 +63,7 @@ bench_window::bench_window()
|
||||||
|
|
||||||
target_core_rate_scale.signal_value_changed().connect(sigc::mem_fun(*this, &bench_window::on_target_core_rate_changed));
|
target_core_rate_scale.signal_value_changed().connect(sigc::mem_fun(*this, &bench_window::on_target_core_rate_changed));
|
||||||
|
|
||||||
target_core_rate_scale.set_range(0.0, 3.0);
|
target_core_rate_scale.set_range(0.0, 4.0);
|
||||||
target_core_rate_scale.set_value(std::log10(20.0));
|
target_core_rate_scale.set_value(std::log10(20.0));
|
||||||
|
|
||||||
control_box.append(new_round_button);
|
control_box.append(new_round_button);
|
||||||
|
|
|
@ -70,13 +70,8 @@ namespace lib94 {
|
||||||
|
|
||||||
for (size_t i = 0; i < count; ++i) {
|
for (size_t i = 0; i < count; ++i) {
|
||||||
const warrior *w = warriors[i];
|
const warrior *w = warriors[i];
|
||||||
unsigned tries = 0;
|
|
||||||
|
|
||||||
new_place_at:
|
new_place_at:
|
||||||
if (tries > 1000)
|
|
||||||
return false;
|
|
||||||
++tries;
|
|
||||||
|
|
||||||
number_t place_at = i == 0 ? 0 : number(prng);
|
number_t place_at = i == 0 ? 0 : number(prng);
|
||||||
|
|
||||||
for (std::pair<number_t, number_t> &other : placements)
|
for (std::pair<number_t, number_t> &other : placements)
|
||||||
|
@ -194,7 +189,8 @@ namespace lib94 {
|
||||||
|
|
||||||
case A_DECREMENT:
|
case A_DECREMENT:
|
||||||
secondary = core + (program_counter + n) % LIB94_CORE_SIZE;
|
secondary = core + (program_counter + n) % LIB94_CORE_SIZE;
|
||||||
ptr = (n + --secondary->anumber) % LIB94_CORE_SIZE;
|
secondary->anumber = (secondary->anumber + LIB94_CORE_SIZE - 1) % LIB94_CORE_SIZE;
|
||||||
|
ptr = (n + secondary->anumber) % LIB94_CORE_SIZE;
|
||||||
instr = core[(program_counter + ptr) % LIB94_CORE_SIZE];
|
instr = core[(program_counter + ptr) % LIB94_CORE_SIZE];
|
||||||
add_read_instruction(secondary);
|
add_read_instruction(secondary);
|
||||||
add_written_instruction(secondary);
|
add_written_instruction(secondary);
|
||||||
|
@ -202,7 +198,8 @@ namespace lib94 {
|
||||||
|
|
||||||
case B_DECREMENT:
|
case B_DECREMENT:
|
||||||
secondary = core + (program_counter + n) % LIB94_CORE_SIZE;
|
secondary = core + (program_counter + n) % LIB94_CORE_SIZE;
|
||||||
ptr = (n + --secondary->bnumber) % LIB94_CORE_SIZE;
|
secondary->bnumber = (secondary->bnumber + LIB94_CORE_SIZE - 1) % LIB94_CORE_SIZE;
|
||||||
|
ptr = (n + secondary->bnumber) % LIB94_CORE_SIZE;
|
||||||
instr = core[(program_counter + ptr) % LIB94_CORE_SIZE];
|
instr = core[(program_counter + ptr) % LIB94_CORE_SIZE];
|
||||||
add_read_instruction(secondary);
|
add_read_instruction(secondary);
|
||||||
add_written_instruction(secondary);
|
add_written_instruction(secondary);
|
||||||
|
@ -212,7 +209,7 @@ namespace lib94 {
|
||||||
secondary = core + (program_counter + n) % LIB94_CORE_SIZE;
|
secondary = core + (program_counter + n) % LIB94_CORE_SIZE;
|
||||||
ptr = (n + secondary->anumber) % LIB94_CORE_SIZE;
|
ptr = (n + secondary->anumber) % LIB94_CORE_SIZE;
|
||||||
instr = core[(program_counter + ptr) % LIB94_CORE_SIZE];
|
instr = core[(program_counter + ptr) % LIB94_CORE_SIZE];
|
||||||
++secondary->anumber;
|
secondary->anumber = (secondary->anumber + 1) % LIB94_CORE_SIZE;
|
||||||
add_read_instruction(secondary);
|
add_read_instruction(secondary);
|
||||||
add_written_instruction(secondary);
|
add_written_instruction(secondary);
|
||||||
break;
|
break;
|
||||||
|
@ -221,7 +218,7 @@ namespace lib94 {
|
||||||
secondary = core + (program_counter + n) % LIB94_CORE_SIZE;
|
secondary = core + (program_counter + n) % LIB94_CORE_SIZE;
|
||||||
ptr = (n + secondary->bnumber) % LIB94_CORE_SIZE;
|
ptr = (n + secondary->bnumber) % LIB94_CORE_SIZE;
|
||||||
instr = core[(program_counter + ptr) % LIB94_CORE_SIZE];
|
instr = core[(program_counter + ptr) % LIB94_CORE_SIZE];
|
||||||
++secondary->bnumber;
|
secondary->bnumber = (secondary->bnumber + 1) % LIB94_CORE_SIZE;
|
||||||
add_read_instruction(secondary);
|
add_read_instruction(secondary);
|
||||||
add_written_instruction(secondary);
|
add_written_instruction(secondary);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -37,7 +37,8 @@ namespace lib94 {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool dec_not_zero() {
|
inline bool dec_not_zero() {
|
||||||
return --*ptr != 0;
|
*ptr = (*ptr + LIB94_CORE_SIZE - 1) % LIB94_CORE_SIZE;
|
||||||
|
return *ptr != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool equal_to(const single_target &other) {
|
inline bool equal_to(const single_target &other) {
|
||||||
|
@ -78,8 +79,8 @@ namespace lib94 {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool dec_not_zero() {
|
inline bool dec_not_zero() {
|
||||||
--*ptr1;
|
*ptr1 = (*ptr1 + LIB94_CORE_SIZE - 1) % LIB94_CORE_SIZE;
|
||||||
--*ptr2;
|
*ptr2 = (*ptr2 + LIB94_CORE_SIZE - 1) % LIB94_CORE_SIZE;
|
||||||
return *ptr1 != 0 || *ptr2 != 0;
|
return *ptr1 != 0 || *ptr2 != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,8 +123,8 @@ namespace lib94 {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool dec_not_zero() {
|
inline bool dec_not_zero() {
|
||||||
--instr->anumber;
|
instr->anumber = (instr->anumber + LIB94_CORE_SIZE - 1) % LIB94_CORE_SIZE;
|
||||||
--instr->bnumber;
|
instr->bnumber = (instr->bnumber + LIB94_CORE_SIZE - 1) % LIB94_CORE_SIZE;
|
||||||
return instr->anumber != 0 || instr->bnumber != 0;
|
return instr->anumber != 0 || instr->bnumber != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -566,7 +566,7 @@ namespace lib94 {
|
||||||
if (org.has_value()) {
|
if (org.has_value()) {
|
||||||
std::optional<number_t> org_number = org.value()->to_number(label_offsets, macro_values, org_offset);
|
std::optional<number_t> org_number = org.value()->to_number(label_offsets, macro_values, org_offset);
|
||||||
if (org_number.has_value())
|
if (org_number.has_value())
|
||||||
w->org = org_number.value() + org_offset;
|
w->org = real_mod(org_number.value() + org_offset);
|
||||||
else
|
else
|
||||||
return std::string("bad expression on line ") + std::to_string(org_source_line);
|
return std::string("bad expression on line ") + std::to_string(org_source_line);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,20 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
[[noreturn]] void usage(const char *argv0) {
|
[[noreturn]] void usage(const char *argv0) {
|
||||||
std::cerr << "usage: " << argv0 << " <first warrior> <second warrior> <number of rounds> <steps until tie>\n";
|
std::cout << "usage: " << argv0 << " <first warrior> <second warrior> <number of rounds> <steps until tie>\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print_warrior(const lib94::warrior *w) {
|
||||||
|
std::cerr << ";name " << w->name << '\n';
|
||||||
|
std::cerr << ";author " << w->author << '\n';
|
||||||
|
if (w->org != 0)
|
||||||
|
std::cerr << "org " << w->org << '\n';
|
||||||
|
for (const auto &i : w->instructions)
|
||||||
|
std::cerr << lib94::instruction_to_string(i) << '\n';
|
||||||
|
std::cerr << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, const char **argv) {
|
int main(int argc, const char **argv) {
|
||||||
if (argc != 5)
|
if (argc != 5)
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
|
@ -37,12 +47,12 @@ int main(int argc, const char **argv) {
|
||||||
auto w2 = lib94::compile_warrior(source2);
|
auto w2 = lib94::compile_warrior(source2);
|
||||||
|
|
||||||
if (std::holds_alternative<std::string>(w1)) {
|
if (std::holds_alternative<std::string>(w1)) {
|
||||||
std::cerr << "error compiling " << argv[1] << ": " << std::get<std::string>(w1) << '\n';
|
std::cout << "error compiling " << argv[1] << ": " << std::get<std::string>(w1) << '\n';
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (std::holds_alternative<std::string>(w2)) {
|
if (std::holds_alternative<std::string>(w2)) {
|
||||||
std::cerr << "error compiling " << argv[2] << ": " << std::get<std::string>(w2) << '\n';
|
std::cout << "error compiling " << argv[2] << ": " << std::get<std::string>(w2) << '\n';
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +60,9 @@ int main(int argc, const char **argv) {
|
||||||
ws[0] = std::get<lib94::warrior *>(w1);
|
ws[0] = std::get<lib94::warrior *>(w1);
|
||||||
ws[1] = std::get<lib94::warrior *>(w2);
|
ws[1] = std::get<lib94::warrior *>(w2);
|
||||||
|
|
||||||
|
print_warrior(ws[0]);
|
||||||
|
print_warrior(ws[1]);
|
||||||
|
|
||||||
unsigned w1_wins = 0;
|
unsigned w1_wins = 0;
|
||||||
unsigned w2_wins = 0;
|
unsigned w2_wins = 0;
|
||||||
|
|
||||||
|
@ -57,6 +70,8 @@ int main(int argc, const char **argv) {
|
||||||
|
|
||||||
for (unsigned round_number = 0; round_number < round_count; ++round_number) {
|
for (unsigned round_number = 0; round_number < round_count; ++round_number) {
|
||||||
|
|
||||||
|
std::cerr << "round " << round_number + 1 << "\x1b[0G";
|
||||||
|
|
||||||
lib94::clear_core({
|
lib94::clear_core({
|
||||||
.op = lib94::DAT, .mod = lib94::F,
|
.op = lib94::DAT, .mod = lib94::F,
|
||||||
.amode = lib94::DIRECT, .bmode = lib94::DIRECT,
|
.amode = lib94::DIRECT, .bmode = lib94::DIRECT,
|
||||||
|
|
|
@ -1,20 +1,14 @@
|
||||||
;author blah
|
;author Benji Dial
|
||||||
;name big nothing
|
;name Big Nothing
|
||||||
|
|
||||||
start:
|
start:
|
||||||
nop
|
nop
|
||||||
nop
|
nop
|
||||||
nop
|
nop
|
||||||
nop
|
nop
|
||||||
nop
|
nop
|
||||||
nop
|
nop
|
||||||
nop
|
nop
|
||||||
nop
|
nop
|
||||||
nop
|
nop
|
||||||
nop
|
jmp start
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
jmp start
|
|
||||||
|
|
55
warriors/dwarf-replicator.red
Normal file
55
warriors/dwarf-replicator.red
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
;author Benji Dial
|
||||||
|
;name Dwarf Replicator
|
||||||
|
|
||||||
|
;not a particularly good warrior, but is sufficient to test a few things
|
||||||
|
|
||||||
|
start:
|
||||||
|
mov 0, 2908
|
||||||
|
nop }start, >start
|
||||||
|
jmp 2
|
||||||
|
|
||||||
|
dat
|
||||||
|
|
||||||
|
seq.a #end - start, start
|
||||||
|
jmp start
|
||||||
|
jmp 2
|
||||||
|
|
||||||
|
dat
|
||||||
|
|
||||||
|
sub.ab #end - start, start
|
||||||
|
spl @start
|
||||||
|
jmp 2, <start
|
||||||
|
|
||||||
|
dat
|
||||||
|
|
||||||
|
dwarf:
|
||||||
|
mov end, end + 4
|
||||||
|
add.ab #4, dwarf
|
||||||
|
jmp 2
|
||||||
|
|
||||||
|
dat
|
||||||
|
|
||||||
|
seq.ab #start + 723 - dwarf, dwarf
|
||||||
|
jmp dwarf
|
||||||
|
jmp 2
|
||||||
|
|
||||||
|
dat
|
||||||
|
|
||||||
|
core_clear:
|
||||||
|
mov end, end + 1
|
||||||
|
add.ab #1, 0-1
|
||||||
|
jmp 2
|
||||||
|
|
||||||
|
dat
|
||||||
|
|
||||||
|
seq.a #0-1, core_clear
|
||||||
|
jmp core_clear
|
||||||
|
jmp 2
|
||||||
|
|
||||||
|
dat
|
||||||
|
|
||||||
|
mov.ab #end + 1, core_clear
|
||||||
|
jmp core_clear
|
||||||
|
dat
|
||||||
|
|
||||||
|
end:
|
|
@ -1,10 +1,6 @@
|
||||||
;author standard
|
;author Standard
|
||||||
;name dwarf
|
;name Dwarf
|
||||||
|
|
||||||
;assert (0 - bomb_step) % bomb_step == 0
|
mov 3, 7
|
||||||
|
add.ab #4, 0-1
|
||||||
bomb_step equ 4
|
|
||||||
|
|
||||||
mov 0-1, 3
|
|
||||||
add.ab #bomb_step, 0-1
|
|
||||||
jmp 0-2
|
jmp 0-2
|
||||||
|
|
42
warriors/epson.red
Normal file
42
warriors/epson.red
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
;author Benji Dial
|
||||||
|
;name Epson
|
||||||
|
|
||||||
|
period equ 10
|
||||||
|
|
||||||
|
scan_init equ end - (end - scan) % period + period
|
||||||
|
|
||||||
|
scan:
|
||||||
|
seq.i 0 - period, scan_init
|
||||||
|
jmp found
|
||||||
|
|
||||||
|
found_ret:
|
||||||
|
add.ab #period, scan
|
||||||
|
seq.ab scan, scan
|
||||||
|
jmp scan
|
||||||
|
|
||||||
|
add.f scan_add, scan
|
||||||
|
jmn.a scan, scan
|
||||||
|
|
||||||
|
clear:
|
||||||
|
mov end, 0 - 1
|
||||||
|
sub.ab #2, clear
|
||||||
|
|
||||||
|
seq.ab #end - clear - (end - clear) % 2 + 3, clear
|
||||||
|
jmp clear
|
||||||
|
|
||||||
|
mov.ab #0 - 1, clear
|
||||||
|
jmp clear
|
||||||
|
|
||||||
|
scan_add:
|
||||||
|
dat 2, period + scan_init + 2
|
||||||
|
|
||||||
|
found:
|
||||||
|
mov bomb, >scan
|
||||||
|
mov bomb + 1, @scan
|
||||||
|
jmp found_ret, <scan
|
||||||
|
|
||||||
|
bomb:
|
||||||
|
spl 1
|
||||||
|
jmp bomb
|
||||||
|
|
||||||
|
end:
|
|
@ -1,4 +0,0 @@
|
||||||
;author standard
|
|
||||||
;name imp
|
|
||||||
|
|
||||||
mov 0, 1
|
|
|
@ -1,9 +0,0 @@
|
||||||
;name simple core clear
|
|
||||||
;author blah
|
|
||||||
|
|
||||||
start:
|
|
||||||
mov background, background + 1
|
|
||||||
sne.ab #0-1, start
|
|
||||||
mov.ab #background - start, start
|
|
||||||
jmp start, >start
|
|
||||||
background:
|
|
|
@ -1,5 +0,0 @@
|
||||||
;author blah
|
|
||||||
;name splitter
|
|
||||||
|
|
||||||
spl 0
|
|
||||||
jmp 0-1
|
|
|
@ -1,28 +0,0 @@
|
||||||
;author benji
|
|
||||||
;name trap
|
|
||||||
|
|
||||||
org start
|
|
||||||
|
|
||||||
trap:
|
|
||||||
spl 1
|
|
||||||
jmp trap
|
|
||||||
|
|
||||||
start:
|
|
||||||
mov.i bomb, bomb + 8
|
|
||||||
add.ab #8, start
|
|
||||||
sub.ab #8, bomb
|
|
||||||
sne.ab #bomb - 8 - start, start
|
|
||||||
jmp core_clear
|
|
||||||
jmp start
|
|
||||||
|
|
||||||
bomb:
|
|
||||||
jmp trap - 8
|
|
||||||
|
|
||||||
core_clear:
|
|
||||||
mov background, background + 1
|
|
||||||
add.ab #1, core_clear
|
|
||||||
jnz.b core_clear, core_clear
|
|
||||||
mov.ab #background + 1 - core_clear, core_clear
|
|
||||||
jmp core_clear
|
|
||||||
|
|
||||||
background:
|
|
Loading…
Add table
Reference in a new issue