Skip to content

Commit

Permalink
[#13] Have a fake emulator to review resulting assembly code.
Browse files Browse the repository at this point in the history
  • Loading branch information
kosarev committed Jul 3, 2021
1 parent 71f64ff commit e21e6b3
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
assembly_review.s
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
set(EXAMPLES
accessing_state
adding_memory
assembly_review
benchmark
custom_state
hello
Expand Down
57 changes: 57 additions & 0 deletions examples/assembly_review.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

// A fake emulator implementation used to review resulting
// assembly code for various instructions.

#include "z80.h"

using z80::fast_u8;
using z80::fast_u16;

using z80::least_u8;

using z80::reg;

template<typename B>
class emulator : public B {
public:
typedef B base;

emulator() {}

fast_u8 on_read(fast_u16 addr) {
assert(addr < z80::address_space_size);
return memory[addr];
}

void on_write(fast_u16 addr, fast_u8 n) {
assert(addr < z80::address_space_size);
memory[addr] = static_cast<least_u8>(n);
}

private:
least_u8 memory[z80::address_space_size] = {};
};

class i8080_emulator : public emulator<z80::i8080_cpu<i8080_emulator>>
{};

class z80_emulator : public emulator<z80::z80_cpu<z80_emulator>>
{};

extern reg r1;
reg r1 = reg::a;

extern reg r2;
reg r2 = reg::a;

void foo(i8080_emulator &e);
void foo(i8080_emulator &e) {
// e.on_decode(0x01);
// e.on_nop();
e.on_ld_r_r(r1, r2);
}

int main() {
i8080_emulator e;
foo(e);
}
6 changes: 6 additions & 0 deletions examples/assembly_review.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
set -e
clang++ -I.. -DNDEBUG -O3 -c -S \
-fstrict-aliasing -fverbose-asm \
-o assembly_review.t assembly_review.cpp
expand assembly_review.t >assembly_review.s
rm assembly_review.t

0 comments on commit e21e6b3

Please sign in to comment.