Design of sxgo
From Just in Time
This page describes the main design ideas behind sxgo. The implementation of this microcontroller emulator revolves around a few main ideas:
- separation of instruction decoder and instruction implementation
- a meta-programmed list of instructions
- using metaprogramming to create a fast instruction decoder
- precompilation of instructions into 'function pointers'. Actually these would also contain bound arguments (in a similar way to boost.bind).
Instruction Implementation
The idea is to have one class that consists of an SX 'state' (ram, rom, special registers, program counter) and that implements the instruction set. See the snippet below:
<source lang="cpp"> struct sx_controller_impl {
// snip... // note that this is simplified source code, this does not set any // flags yet. void execute( const clr_fr &, int arg_register) { ram( arg_register) = 0; }
void execute( const clr_w &) { w = 0; }
void execute( const mov_w_not_fr &, int arg_register) { w = ~ram( arg_register); }
// etc...
}; </source>