File Coverage

blib/lib/CPU/Emulator/DCPU16/Device/Console.pm
Criterion Covered Total %
statement 16 20 80.0
branch 0 4 0.0
condition n/a
subroutine 5 7 71.4
pod 4 4 100.0
total 25 35 71.4


line stmt bran cond sub pod time code
1             package CPU::Emulator::DCPU16::Device::Console;
2 4     4   18 use strict;
  4         8  
  4         135  
3 4     4   20 use base qw(CPU::Emulator::DCPU16::Device);
  4         15  
  4         2312  
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
20              
21             Create a new console
22              
23             =cut
24             sub new {
25 1     1 1 74 my $self = shift->SUPER::new(@_);
26 1         14 $self->{_console} = ""x($self->end-$self->start);
27 1         4 $self;
28             }
29              
30             =head2 set
31              
32             Set the address of the mapped device to value.
33              
34             =cut
35             sub set {
36 84     84 1 131 my $self = shift;
37 84         115 my $addr = shift;
38 84         89 my $val = shift;
39 84         243 substr $self->{_console}, $addr-$self->start, 1, chr($val);
40             }
41              
42             =head2 get
43              
44             Get the value at address of the mapped device.
45              
46             =cut
47             sub get {
48 1     1 1 1 my $self = shift;
49 1         2 my $addr = shift;
50 1         4 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             sub tick {
61 0     0 1   my $self = shift;
62 0 0         print "\r".$self->{_console} if defined $self->{_console};
63             }
64              
65             sub DESTROY {
66 0     0     my $self = shift;
67 0 0         print "\r".$self->{_console}."\n" if defined $self->{_console};
68             }
69              
70             1;