| 1 | package CPU::Emulator::DCPU16::Device; | ||
| 2 | 5 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | |||
| 4 | =head1 NAME | ||
| 5 | |||
| 6 | CPU::Emulator::DCPU16::Device - generic base memory mapped device for the DCPU16 emulator | ||
| 7 | |||
| 8 | =head1 SYNOPSIS | ||
| 9 | |||
| 10 | $cpu->map_device('CPU::Emulator::DCPU16::Device::Console', $start_addr, $end_addr); | ||
| 11 | |||
| 12 | =head1 DESCRIPTION | ||
| 13 | |||
| 14 | This base class should not be used directly - it should be subclassed and get methods should be provided. | ||
| 15 | |||
| 16 | =head1 METHODS | ||
| 17 | |||
| 18 | =cut | ||
| 19 | |||
| 20 | |||
| 21 | =head2 new <memory reference> <start address> <end address> <options> | ||
| 22 | |||
| 23 | Create a new device and map it to the memory. | ||
| 24 | |||
| 25 | =cut | ||
| 26 | 1 | ▶ | sub new { |
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||
| 27 | 1 | my $class = shift; | |
| 28 | 1 | my $mem = shift; | |
| 29 | 1 | my $start = shift; | |
| 30 | 1 | my $end = shift; | |
| 31 | 1 | my %opts = @_; | |
| 32 | 1 | $opts{_start} = $start; | |
| 33 | 1 | $opts{_end} = $end; | |
| 34 | 1 | my $self = bless \%opts, $class; | |
| 35 | 1 | tie $mem->[$_], $class, $_, $self for ($start..$end); | |
| 36 | 1 | $self; | |
| 37 | } | ||
| 38 | |||
| 39 | =head2 start | ||
| 40 | |||
| 41 | Get the start address of this mapped device | ||
| 42 | |||
| 43 | =cut | ||
| 44 | 86 | ▶ | sub start { shift->{_start} } |
|
Subroutine
start: called CC=1 SCAR=0.0
Pod
documented
| |||
| 45 | |||
| 46 | =head2 end | ||
| 47 | |||
| 48 | Get the end address of this mapped device | ||
| 49 | |||
| 50 | =cut | ||
| 51 | 1 | ▶ | sub end { shift->{_end} } |
|
Subroutine
end: called CC=1 SCAR=0.0
Pod
documented
| |||
| 52 | |||
| 53 | =head2 tick | ||
| 54 | |||
| 55 | Called after each instruction is called | ||
| 56 | |||
| 57 | =cut | ||
| 58 | 0 | ▶ | sub tick { |
|
Subroutine
tick: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 59 | 0 | my $self = shift; | |
| 60 | # no-op | ||
| 61 | } | ||
| 62 | |||
| 63 | =head2 set <address> <value> | ||
| 64 | |||
| 65 | Set the address of the mapped device to value. | ||
| 66 | |||
| 67 | =cut | ||
| 68 | 0 | ▶ | sub set { |
|
Subroutine
set: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 69 | 0 | my $self = shift; | |
| 70 | 0 | my $addr = shift; | |
| 71 | 0 | my $val = shift; | |
| 72 | # no-op | ||
| 73 | } | ||
| 74 | |||
| 75 | =head2 get <address> | ||
| 76 | |||
| 77 | Get the value at address of the mapped device. | ||
| 78 | |||
| 79 | =cut | ||
| 80 | 0 | ▶ | sub get { |
|
Subroutine
get: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 81 | 0 | my $self = shift; | |
| 82 | 0 | my $addr = shift; | |
| 83 | # no-op | ||
| 84 | } | ||
| 85 | |||
| 86 | 384 | ▶ | sub TIESCALAR { |
|
Subroutine
TIESCALAR: called CC=1 SCAR=0.0
| |||
| 87 | 384 | my $class = shift; | |
| 88 | 384 | my $addr = shift; | |
| 89 | 384 | my $dev = shift; | |
| 90 | 384 | return bless { address => $addr, device => $dev }, $class; # create a proxy | |
| 91 | } | ||
| 92 | |||
| 93 | 84 | ▶ | sub STORE { |
|
Subroutine
STORE: called CC=1 SCAR=0.0
| |||
| 94 | 84 | my $proxy = shift; | |
| 95 | 84 | my $value = shift; | |
| 96 | 84 | $proxy->{device}->set($proxy->{address}, $value); | |
| 97 | } | ||
| 98 | |||
| 99 | 1 | ▶ | sub FETCH { |
|
Subroutine
FETCH: called CC=1 SCAR=0.0
| |||
| 100 | 1 | my $proxy = shift; | |
| 101 | 1 | $proxy->{device}->get($proxy->{address}); | |
| 102 | } | ||
| 103 | |||
| 104 | |||
| 105 | 5 | 1; | |