TARGETS =
CLEANFILES = $(TARGETS)
-TARGETS += spectrum-fb.img
+CLEANFILES += spectrum-fb.img
spectrum-fb.img: fizzbuzz.s
z80asm -o $@ $^
+TARGETS += spectrum-fizzbuzz.tap
+spectrum-fizzbuzz.tap: tapify spectrum-loader.tap spectrum-fb.img
+ { cat spectrum-loader.tap; \
+ ./tapify 3 fb 0x7000 0x8000 <spectrum-fb.img; } \
+ >$@.new && mv $@.new $@
+
all: $(TARGETS)
clean::; rm -f $(CLEANFILES)
--- /dev/null
+#! /usr/bin/perl
+
+use autodie;
+
+sub intify ($) {
+ my ($n) = @_;
+ if ($n =~ /^0/) { $n = oct $n; }
+ return $n;
+}
+
+sub frame ($$) {
+ my ($flag, $d) = @_;
+ my $a = $flag;
+ for (my $i = 0; $i < length $d; $i++) { $a ^= ord substr $d, $i, 1; }
+ return pack("S< C", 2 + length $d, $flag) . $d . chr($a);
+}
+
+@ARGV == 4 or die "usage: $0 TY NAME P1 P2";
+my ($ty, $name, $p1, $p2) = @ARGV;
+
+my $body = "";
+READ: for (;;) {
+ sysread STDIN, my $buf, 4096;
+ last READ unless length $buf;
+ $body .= $buf;
+}
+
+my $tap = "";
+$tap .= frame 0, pack "C A10 S< S< S<",
+ $ty, $name, length $body, intify $p1, intify $p2;
+$tap .= frame 255, $body;
+
+syswrite STDOUT, $tap;