aboutsummaryrefslogtreecommitdiffstats
path: root/bin/dcpu16-asm
blob: 1245236782fdcbc700ed0408c3cf5d17b0c2a5a3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env perl
use strict;
use warnings;

use Games::Emulation::DCPU16::Assembler;
use Getopt::Long;

my $out = 'a.out';
GetOptions(
    'output=s' => \$out,
);

my $file = $ARGV[0];
open my $fh, '<', $file or die "Couldn't open $file for reading: $!";
my $script = do { local $/; <$fh> };

my $assembler = Games::Emulation::DCPU16::Assembler->new;
my $bin = $assembler->assemble($script);

open my $outfh, '>', $out or die "Couldn't open $out for writing: $!";
print $outfh $bin;
close $outfh or die "Couldn't close $out: $!";