CPU::Emulator::DCPU16 - an emulator for Notch's DCPU-16 virtual CPU for the game 0x10c
open(my $fh, ">:raw", $file) || die "Couldn't read file $file: $!"; my $program = do { local $/=undef; <$fh> }; $program = CPU::Emulator::DCPU16::Assembler->assemble($program) if $file =~ /\.dasm(16)?$/; # Create a new CPU and load a file my $cpu = CPU::Emulator::DCPU16->new(); $cpu->load($program); # Run it ... $cpu->run; # ... which is basically the same as do { $cpu->step } until $cpu->halt;
DCPU-16 is a spec for a virtual CPU by Notch from Mojang (of Minecraft fame).
The spec is available here
http://0x10c.com/doc/dcpu-16.txt
Create a new CPU.
Load a program. Forces as re-init of the CPU.
You can also do
my $cpu = CPU::Emulator::DCPU16->load($program, %opts);
which is exactly the same as
my $cpu = CPU::Emulator::DCPU16->new(%opts); $cpu->load($program);
Turn a scalar of bytes into an array of words
Map a device of the given class to these addresses
Run CPU until completion.
Options available are:
Whether or not we should print debug information and at what level.
Default is 0 (no debug output).
Maxinum number of instructions to execute.
Default is 0 (no limit).
The time penalty for each instruction cycle in milliseconds.
Default is 0 (no penalty)
Allow the PC to continue past the last instruction of the program (i.e the program_top).
This would allow programs to rewrite themselves into a larger program.
Default is 0 (no access)
Run a single clock cycle of the CPU.
Takes the same options as run.
run
The current program counter.
The current stack pointer.
The current overflow.
Halt the CPU or check to see whether it's halted.
The address of the first memory location after the loaded program.
Get or set the value of a register.
Get or set the value of a memory location.
CPU::Emulator::DCPU16::Assembler
CPU::Emulator::DCPU16::Disassembler
Implementation inspiration came from:
Simon Wistow <simon@thegestalt.org>
Copyright 2011 - Simon Wistow
Released under the same terms as Perl itself.
Latest development version available from
https://github.com/simonwistow/CPU-Emulator-DCPU16
To install CPU::Emulator::DCPU16, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CPU::Emulator::DCPU16
CPAN shell
perl -MCPAN -e shell install CPU::Emulator::DCPU16
For more information on module installation, please visit the detailed CPAN module installation guide.