Code: Select all
// Compute! maze generator for unexpanded Vic-20
// Chrs: home = 19 clr = 147 rvs = 18 lwr = 14 screen = 7680
#include <stdio.h>
#include <stdlib.h>
signed char peek(unsigned int z) {
return (*(signed char*)(z));
}
void poke(unsigned int q, signed char v) {
(*(signed char*)(q) = (v));
}
void main (void) {
signed char j, c, w = 160, h = 32;
signed char d[] = {2, -44, -2, 44};
unsigned int s = 7680, a = s+45, b;
putchar(147); putchar('\n'); // Clear screen
for (c=1; c<22; c++) {
putchar(18);
puts(" "); // 21 spaces
}
putchar(19); // Home cursor
poke(a, 4);
do{
j = rand()&3;
c = j;
l2:
b = a + d[j];
if(peek(b) == w) {
poke(b, j);
poke(a + (d[j]>>1), h);
a = b;
continue;
}
j=(j+1)*(j<3);
if(j != c) goto l2; // Yuk!
j = peek(a);
poke(a, h);
a -= d[j];
} while(j < 4);
}
Code: Select all
10 d(0)=2:d(1)=-44:d(2)=-2:d(3)=44
20 w=160:h=32:s=7680:a=s+45
30 print"{clear}":fori=1to21
40 print"{rvson} ":next:pokea,4:print"{home}"
50 j=int(rnd(1)*4):c=j
60 b=a+d(j):ifpeek(b)=wthenpokeb,j:pokea+d(j)/2,h:a=b:goto50
70 j=(j+1)*-(j<3):ifj<>cthen60
80 j=peek(a):pokea,h:ifj<4thena=a-d(j):goto50
90 geta$:ifa$=""then90
