	.title life demo in supermac
	;author  T. Weslowski   24-oct-81


	; This program demonstrates the game of life
	; while running on an intertube.

dead = 0
alive = 1

rowmax = 25.
colmax = 25.

life:	.blkw rowmax*colmax
next:	.blkw rowmax*colmax

; array vector

addr = life

av:	.rept rowmax
		addr
		addr = addr + <2 * colmax>
	.endr

row:	.blkw 1
col:	.blkw 1

procedure subscript ; with r5 (row,col)

; leaves address pointer in r5

push r0,r1
let r0 := @(r5)+	;fetch row
let r0 := r0 - #1 l.shift 1 + #av ; make into address
let r1 := @(r5)+	;fetch column
let r1 := r1 - #1 l.shift 1 + (r0)
let 4(sp) := r1		;save on stack
pop r1,r0
return with r5

procedure settozero ;<#array> sets array to zero

push r1
let r1 := #rowmax*colmax
thru r1 do
let (r0)+ := #0
end
pop r1
return

msg1:.ascii/ Enter row col coordinates/ <15><12>
     .asciz/ I will stop whn you enter 0 0/ <7><7><15><12>
msg2:.asciz/ Illegal row or column /
.even
procedure init ; initializes life
call settozero < #life >
call settozero < #next >
print msg1
readln row,col
while row <> #0 and col <> #0 do
if row > #0 and row <= #rowmax and col > #0 and col <= #colmax then
call subscript with r5 (row,col)
let (r5) := #alive
else
print msg2
fi
readln row,col
end ; while
return

nul=0
esc=27.+128.

oray:	.byte esc,'Y,0,0
.blkb 10.
procedure printat; <row,col,dataaddress>
;let r0 := (r0)
;let r1 := (r1)
if r0 > #80. then
let r0 := #80.
else
if r0 < #0 then
let r0 := #0
fi
fi
if r1 > #24. then
let r1 := #24.
else
if r1 < #0 then
let r1 := #0
fi
fi
let r0 := r0 + #32.
let r1 := r1 + #32.
letb oray+2 := r0
letb oray+3 := r1
let r0 := #oray+4
repeat
letb (r0)+ := (r2)+
untilb (r2) is #<nul>
print oray
return

;****** the mainline ******

msg3:.asciz/How many generations?/
msg4:.asciz/Generation/
.even
sum:.blkw 1
j:	.blkw 1
k:	.blkw 1
rm1:	.blkw 1
rp1:	.blkw 1
cm1:	.blkw 1
cp1:	.blkw 1
n:	.blkw 1
maxnogen:.blkw 1

begin:
call init
print msg3
readln maxnogen
let n := #1
while n < maxnogen do
call printat < #0, #0,msg1 >
writeln n
for row := #2 to #rowmax-1 
for col := #2 to #colmax-1
let sum := #0
let rm1 := row - #1
let rp1 := row + #1
let cm1 := col - #1
let cp1 := col + #1

for j := rm1 to rp1
for k := cm1 to cp1

call subscript with r5 ( j,k )
if (r5) is #alive then
let sum := sum + #1
fi
end ; for k
end ; for j

call subscript with r5 (row,col)
if (r5) is #dead then
case sum of
md,md,md
ma
md,md,md,md,md
end ; case
else
let sum := sum - #1
case sum of
md1,md1,ma1,ma1
md1,md1,md1,md1,md1
end ; case of sum-1
fi
end ; for row
end; for col
call copymatrix
let n := n + #1
end ; while n < maxnogen
.exit
procedure copymatrix
let r0 := #0
let r1 := #rowmax*colmax
thru r1 do
let life(r0) := next(r0)
let r0 := r0 + #2
end
return
line: .byte esc,'0,'P,'*,esc,'0,'@,0
procedure md
let r5 := r5 - #life + #next
let (r5) := #dead
return
procedure ma
let r5 := r5 - #life + #next
let (r5) := #alive
let tp := row l.shift 1
call printat <tp,col,line>
return
space:	.asciz / /
critter:.asciz /*/
.even
tp:.blkw 1
procedure md1
let r5 := r5 - #life + #next
let (r5) := #dead
let tp := row l.shift 1
call printat <tp,col,space>
return
procedure ma1
let r5 := r5 - #life + #next
let (r5) := #alive
let tp := row l.shift 1
call printat <tp,col,critter>
return
.end begin
