From e007e1c95912e17f33ed135b4b69d293076a7017 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Sun, 14 Nov 2021 13:56:59 +0000 Subject: [PATCH] Add a ZX81 port. 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 | 1 + Makefile | 8 ++++++++ gluep | 43 +++++++++++++++++++++++++++++++++++++++++++ zx81-loader.p | Bin 0 -> 929 bytes zx81.s | 25 +++++++++++++++++++++++++ 5 files changed, 77 insertions(+) create mode 100755 gluep create mode 100644 zx81-loader.p create mode 100644 zx81.s diff --git a/.gitignore b/.gitignore index 6477f1c..aff1ece 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.img /spectrum-fizzbuzz.tap +/zx81-fizzbuzz.p diff --git a/Makefile b/Makefile index 0af35b7..40594c4 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,14 @@ spectrum-fizzbuzz.tap: tapify spectrum-loader.tap spectrum-fb.img ./tapify 3 fb 0x7000 0x8000 $@.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 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 index 0000000000000000000000000000000000000000..77d7287a0c990384cbcf4563a98318527d86395d GIT binary patch literal 929 zcmZQzVCZ+4;IP7(fnlZdb|AUKd51GYtOElR1H=FS|IPay7(k$x2TU>SQIu$auyB)Q w5UCa*)v^GqGA=%bpI78ml$7P_`V)XE%Ai`XDh3OVDu9H|XgG|laA^1e04Ka4pa1{> literal 0 HcmV?d00001 diff --git a/zx81.s b/zx81.s new file mode 100644 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: -- 2.11.0