From: Mark Wooding Date: Sun, 14 Nov 2021 13:56:59 +0000 (+0000) Subject: Add a ZX81 port. X-Git-Url: https://git.distorted.org.uk/~mdw/zx-fizzbuzz/commitdiff_plain/e007e1c95912e17f33ed135b4b69d293076a7017?hp=64b6fca5f33b619e9c38778000f5192521a57cf6 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. --- 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 0000000..77d7287 Binary files /dev/null and b/zx81-loader.p differ 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: