#!/usr/bin/perl

use v5.26;
use warnings;

use Device::Chip::BV4243;
use Device::Chip::Adapter;

use Future::AsyncAwait;
use Getopt::Long;

GetOptions(
   'adapter|A=s' => \my $ADAPTER,
) or exit 1;

my $chip = Device::Chip::BV4243->new;
await $chip->mount(
   Device::Chip::Adapter->new_from_description( $ADAPTER )
);

foreach my $row ( 0 .. 15 ) {
   my @bytes;
   foreach my $col ( 0 .. 15 ) {
      push @bytes, await $chip->eeprom_read( $row*16 + $col );
   }

   printf "%02X: ", $row*16;
   printf "%02X ", $_ for @bytes;
   print " | ";
   print $_ >= 0x20 && $_ < 0x80 ? chr $_ : "." for @bytes;
   print "\n";
}