-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#13] Have a fake emulator to review resulting assembly code.
- Loading branch information
Showing
4 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
assembly_review.s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
set(EXAMPLES | ||
accessing_state | ||
adding_memory | ||
assembly_review | ||
benchmark | ||
custom_state | ||
hello | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |