Add a ZX81 port.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 14 Nov 2021 13:56:59 +0000 (13:56 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 14 Nov 2021 14:00:58 +0000 (14:00 +0000)
It seems that ZX81 emulators are awful.  This hack is the best I could
come up with.

Since I wrote the thing in ZX BASIC in an emulator, I guess
`zx81-loader.p' file is the preferred form for modification.

.gitignore
Makefile
gluep [new file with mode: 0755]
zx81-loader.p [new file with mode: 0644]
zx81.s [new file with mode: 0644]

index 6477f1c..aff1ece 100644 (file)
@@ -1,2 +1,3 @@
 *.img
 /spectrum-fizzbuzz.tap
+/zx81-fizzbuzz.p
index 0af35b7..40594c4 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -16,6 +16,14 @@ spectrum-fizzbuzz.tap: tapify spectrum-loader.tap spectrum-fb.img
          ./tapify 3 fb 0x7000 0x8000 <spectrum-fb.img; } \
                >$@.new && mv $@.new $@
 
+CLEANFILES             += zx81-fb.img
+zx81-fb.img: zx81.s fizzbuzz.s
+       z80asm -o $@ $^
+
+TARGETS                        += zx81-fizzbuzz.p
+zx81-fizzbuzz.p: gluep zx81-loader.p zx81-fb.img
+       ./gluep 0x4009:zx81-loader.p 0x7000:zx81-fb.img >$@.new && mv $@.new $@
+
 all: $(TARGETS)
 
 clean::; rm -f $(CLEANFILES)
diff --git a/gluep b/gluep
new file mode 100755 (executable)
index 0000000..504c779
--- /dev/null
+++ b/gluep
@@ -0,0 +1,43 @@
+#! /usr/bin/perl
+
+use autodie;
+
+sub intify ($) {
+  my ($n) = @_;
+  if ($n =~ /^0/) { $n = oct $n; }
+  return $n;
+}
+
+my $MEM = "";
+my $BASE = 0x4009;
+my $LIMIT = 0x8000;
+
+for my $a (@ARGV) {
+  $a =~ /^(\w+):(.*)$/ or die "bad spec ADDR:FILE";
+  my $addr = intify $1;
+  my $file = $2;
+
+  my $body = "";
+  open my $fh, "<", $file;
+  READ: for (;;) {
+    sysread $fh, my $buf, 4096;
+    last READ unless length $buf;
+    $body .= $buf;
+  }
+  close $fh;
+
+  $addr >= $BASE && $LIMIT >= $addr + length $body
+    or die "out of bounds";
+
+  $addr -= $BASE;
+  my $end = $addr + length $body;
+  my $before = $addr > length $MEM
+    ? $MEM . "\0" x ($addr - length $MEM)
+    : substr $MEM, 0, $addr;
+  my $after = $end <= length $MEM
+    ? ""
+    : substr $MEM, $end;
+  $MEM = $before . $body . $after;
+}
+
+syswrite STDOUT, $MEM;
diff --git a/zx81-loader.p b/zx81-loader.p
new file mode 100644 (file)
index 0000000..77d7287
Binary files /dev/null and b/zx81-loader.p differ
diff --git a/zx81.s b/zx81.s
new file mode 100644 (file)
index 0000000..8efe185
--- /dev/null
+++ b/zx81.s
@@ -0,0 +1,25 @@
+;;; -*-asm-*-
+
+       org     0x7000
+
+spc:   equ     0
+
+fixdig:        macro
+       add     a, 0x1c
+       endm
+
+print_a: macro
+       rst     0x10
+       endm
+
+endstr:        equ     0x7a
+endstrp: macro
+       cp      endstr
+       endm
+
+       jr      begin
+
+fizz:  db      0x2b, 0x2e, 0x3f, 0x3f, endstr
+buzz:  db      0x27, 0x3a, 0x3f, 0x3f, endstr
+
+begin: