z: initial commit from qkumba

This commit is contained in:
Vince Weaver 2021-08-04 18:48:03 -04:00
parent 7ea2033caf
commit 8e32466246
4 changed files with 175 additions and 0 deletions

30
basic/z/Makefile Normal file
View File

@ -0,0 +1,30 @@
include ../../Makefile.inc
DOS33 = ../../utils/dos33fs-utils/dos33
TOKENIZE = ../../utils/asoft_basic-utils/tokenize_asoft
EMPTY_DISK = ../../empty_disk/empty.dsk
all: z.dsk z
z.dsk: HELLO
cp $(EMPTY_DISK) z.dsk
$(DOS33) -y z.dsk SAVE A HELLO
####
HELLO: hello.bas
$(TOKENIZE) < hello.bas > HELLO
####
z: z.o
$(CC) $(LFLAGS) -o z z.o
z.o: z.c
$(CC) $(CFLAGS) -c z.c
####
clean:
rm -f *~ *.o *.lst HELLO z

90
basic/z/README Normal file
View File

@ -0,0 +1,90 @@
Executable ASCII decoding.
Here's the encoder source.
It requires a 65C02, though, to save one byte. I would like to fix
that somehow.
How it works:
On entry:
- X=$9D;
- Y is the low byte of the CALL target;
- carry is clear;
- $7D-7E is $800;
- $B8-B9 points to the token after the CALL;
- $73-74 points to $9600;
- $6F-70 points to $9600.
dex ca *
dex ca *
dex ca *
dex ca *
dex ca *
dex ca *
Sets X to $97, so we can use it later.
dey 88 GR
Skip the opening quote (it's read backwards) in the 6-bit table.
-- inc $b8 e6 b8 ASC DEF
Skip the opening quote in the 2-bit table.
lda ($21,x) a1 21 POP !
Read from 2-bit table (at $B8).
adc #$5c 69 5c i \
Move into $80+ range, guarantees a bit is set so we don't exit early.
sta $30 85 30 DEL 0
Save for later.
- dey 88 GR
lda ($7d),y b1 7d RETURN }
Read from 6-bit table.
adc #$5c 69 5d i \
Move into $80+ range, always sets V flag because bit 6 and bit 7 are
inverted in our data (V will be cleared when we read a value < $24,
specifically the closing quote).
lsr $30 46 30 F 0
ror 6a j
ror 6a j
ror 6a j
ror 6a j
ror 6a j
ror 6a j
ror 6a j
lsr $30 46 30 F 0
ror 6a j
2-bit table carries bits 7 and 0.
sta ($dc,x) 81 dc FOR LOG
Write through ($73).
inc $73 e6 73 ASC s
Move next.
lda $30 a5 30 ONERR 0
dec 3a :
dec 3a :
bne - d0 e5 = VAL
Loop while a bit is set.
bvs -- 70 db p RND
Loop while our data are read.
jmp ($6f) 6c 6f l o
Jump $9600.

2
basic/z/hello.bas Normal file
View File

@ -0,0 +1,2 @@
5 HOME
10 PRINT CHR$(4);"CATALOG"

53
basic/z/z.c Normal file
View File

@ -0,0 +1,53 @@
#include <fcntl.h>
#include <io.h>
#include <stdio.h>
#include <string.h>
static unsigned char decoder[] = "\"******GRASCDEFPOP!i\\DEL0GRRETURN}i\\F0jjjjjjjF0jFORLOGASCsONERR0::=VALpRNDlo";
void main(int argc, char *argv[])
{
int i, l, j, b2, b6;
unsigned char b[150];
unsigned char bb2[150];
unsigned char bb6[150];
unsigned char call[10];
memset(b, 0, sizeof(b));
i = open(argv[1], O_RDONLY | O_BINARY);
l = read(i, b, sizeof(b));
close(i);
j = 0;
b2 = 0;
b6 = sizeof(bb6);
do
{
unsigned char c;
if (!(j % 3))
{
c = ((((b[j + 0] >> 6) & 2) + (b[j + 0] & 1)) << 0)
+ ((((b[j + 1] >> 6) & 2) + (b[j + 1] & 1)) << 2)
+ ((((b[j + 2] >> 6) & 2) + (b[j + 2] & 1)) << 4)
+ 0x23;
bb2[b2++] = c + (int) !j;
}
c = ((b[j] >> 1) & 0x3f) + 0x23 + (int) !(j % 3);
bb6[--b6] = c;
}
while (++j < l);
sprintf(call, "0CALL%d\"", 2049+10+b2+6+(int)sizeof(bb6)-b6+1);
i = open("out", O_WRONLY | O_BINARY | O_CREAT | O_TRUNC, 0x80);
write(i, call, strlen(call));
write(i, bb2, b2);
write(i, "\r\n1\"", sizeof("\r\n1\"")-1);
write(i, bb6 + b6, sizeof(bb6) - b6);
write(i, decoder, sizeof(decoder)-1);
close(i);
}