]>
iEval git - clump.git/blob - asm.pm
17 use Device
::SerialPort
;
19 my $port = Device
::SerialPort
->new($ARGV[0] // '/dev/ttyUSB1') or die "$!";
21 #$port->baudrate(4000000);
22 $port->parity('none');
25 $port->handshake('none');
26 $port->read_const_time(2000);
28 $port->write_settings or die "$!";
32 use Time
::HiRes qw
/sleep/;
34 sysopen my $port, '/dev/ttyUSB1', O_SYNC
| O_RDWR
or die "$!";
37 use parent qw
/Exporter/;
38 our @EXPORT = qw
/loada loadb store write_verilog alu_select_a alu_select_b alu_select_f alu_zero flag_zero flag_news alu_xor alu_xnor alu_or alu_of_function aluc_add alus_add aluc_addAF alus_addAF alu2 alu3 add addC/;
39 our @EXPORT_OK = qw
/loada loadb store write_verilog alu_select_a alu_select_b alu_select_f alu_zero flag_zero flag_news alu_xor alu_xnor alu_or alu_of_function aluc_add alus_add aluc_addAF alus_addAF alu2 alu3 add addC/;
41 use File
::Slurp
::Tiny
'write_file';
47 my $binary = pack 'vCC', @cmd{qw
/I mem_addr op/}; # we ignore CS for now
48 my $length = length $binary;
49 my $wrote = syswrite $port, $binary, $length;
51 # say "Wrote $wrote of $length bytes";
52 if ($cmd{op
} == OP_READ
) {
54 my $count_in = sysread $port, $string_in, 2;
55 my @memory = unpack 'v*', $string_in;
64 my ($addr, $flagr, $bsel, $aluc) = @_;
70 { I
=> $I, mem_addr
=> $addr, op
=> OP_LOADA
, CS
=> 0 }
74 my ($addr, $cond, $inv, $alus) = @_;
80 { I
=> $I, mem_addr
=> $addr, op
=> OP_LOADB
, CS
=> 0 }
85 send_
{ I
=> 0, mem_addr
=> $addr, op
=> OP_READ
, CS
=> 1 }
89 my ($addr, $flagw, $edge_, $cube) = @_;
95 { I
=> $I, mem_addr
=> $addr, op
=> OP_STORE
, CS
=> 0 }
101 { I
=> $I, mem_addr
=> $addr, op
=> OP_LOADI
, CS
=> 0 }
106 sub flag_news
{ 8 + $_[0] }
132 sub alu_of_function
(&) {
136 local $a = ($i & 4) >> 2;
137 local $b = ($i & 2) >> 1;
139 $alu += ($fun->() ?
1 : 0) << $i;
144 sub aluc_add
{ alu_of_function
{ ($a + $b + $_) & 2 } }
145 sub alus_add
{ alu_of_function
{ ($a + $b + $_) & 1 } }
147 sub aluc_addAF
{ alu_of_function
{ ($a + $_) & 2 } }
148 sub alus_addAF
{ alu_of_function
{ ($a + $_) & 1 } }
150 sub alu_or
{ alu_of_function
{ $a | $b | $_ } }
153 my ($aluc, $alus, $addrA, $addrB, $flagr, $flagw, $cond, $inv) = @_;
154 loada
$addrA, $flagr, 0, $aluc;
155 loadb
$addrB, $cond, $inv, $alus;
156 store
$addrA, $flagw, 0, 0;
160 my ($aluc, $alus, $addrA, $addrB, $addrC, $flagr, $flagw) = @_;
161 loada
$addrA, $flagr, 0, $aluc;
162 loadb
$addrB, 0, 1, $alus;
163 store
$addrC, $flagw, 0, 0;
167 my ($addrA, $addrB, $addrC, $flag_carry) = @_;
168 alu3 aluc_add
, alus_add
, $addrA, $addrB, $addrC, flag_zero
, $flag_carry;
172 my ($addrA, $addrB, $addrC, $flag_carry) = @_;
173 alu3 aluc_add
, alus_add
, $addrA, $addrB, $addrC, $flag_carry, $flag_carry;
This page took 0.059078 seconds and 5 git commands to generate.