| 1 | package CPU::Emulator::DCPU16::Device::Console; | ||||||||||
| 2 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 5 | ▶ | use base qw(CPU::Emulator::DCPU16::Device); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | =head1 NAME | ||||||||||
| 6 | |||||||||||
| 7 | CPU::Emulator::DCPU16::Device::Console - mapped console device for the DCPU16 emulator | ||||||||||
| 8 | |||||||||||
| 9 | =head1 SYNOPSIS | ||||||||||
| 10 | |||||||||||
| 11 | $cpu->map_device('CPU::Emulator::DCPU16::Device::Console', $start_addr, $end_addr); | ||||||||||
| 12 | |||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||
| 14 | |||||||||||
| 15 | =head1 METHODS | ||||||||||
| 16 | |||||||||||
| 17 | =cut | ||||||||||
| 18 | |||||||||||
| 19 | =head2 new <memory reference> <start address> <end address> <options> | ||||||||||
| 20 | |||||||||||
| 21 | Create a new console | ||||||||||
| 22 | |||||||||||
| 23 | =cut | ||||||||||
| 24 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 25 | 1 | my $self = shift->SUPER::new(@_); | |||||||||
| 26 | 1 | $self->{_console} = ""x($self->end-$self->start); | |||||||||
| 27 | 1 | $self; | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | =head2 set <address> <value> | ||||||||||
| 31 | |||||||||||
| 32 | Set the address of the mapped device to value. | ||||||||||
| 33 | |||||||||||
| 34 | =cut | ||||||||||
| 35 | 84 | ▶ | sub set { | ||||||||
|
Subroutine
set: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 36 | 84 | my $self = shift; | |||||||||
| 37 | 84 | my $addr = shift; | |||||||||
| 38 | 84 | my $val = shift; | |||||||||
| 39 | 84 | substr $self->{_console}, $addr-$self->start, 1, chr($val); | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | =head2 get <address> | ||||||||||
| 43 | |||||||||||
| 44 | Get the value at address of the mapped device. | ||||||||||
| 45 | |||||||||||
| 46 | =cut | ||||||||||
| 47 | 1 | ▶ | sub get { | ||||||||
|
Subroutine
get: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 48 | 1 | my $self = shift; | |||||||||
| 49 | 1 | my $addr = shift; | |||||||||
| 50 | 1 | ord substr $self->{_console}, $addr-$self->start, 1; | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | =head2 tick | ||||||||||
| 54 | |||||||||||
| 55 | Called after each instruction is called. | ||||||||||
| 56 | |||||||||||
| 57 | Prints out the current console. | ||||||||||
| 58 | |||||||||||
| 59 | =cut | ||||||||||
| 60 | 0 | ▶ | sub tick { | ||||||||
|
Subroutine
tick: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 61 | 0 | my $self = shift; | |||||||||
| 62 | 0 | ▶ | print "\r".$self->{_console} if defined $self->{_console}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 0 | ▶ | sub DESTROY { | ||||||||
|
Subroutine
DESTROY: not called CC=2 SCAR=17.9
| |||||||||||
| 66 | 0 | my $self = shift; | |||||||||
| 67 | 0 | ▶ | print "\r".$self->{_console}."\n" if defined $self->{_console}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | 5 | 1; | |||||||||