Tetris for Apple ][ lo-res mode is now complete

This commit is contained in:
Bobbi Webber-Manners 2018-05-18 20:14:41 -04:00 committed by GitHub
parent 5dc202ec2a
commit 76ef797854
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

326
tetris.8b
View File

@ -3,64 +3,112 @@
word addrs[24]={$400,$480,$500,$580,$600,$680,$700,$780,$428,$4a8,$528,$5a8,$628,$6a8,$728,$7a8,$450,$4d0,$550,$5d0,$650,$6d0,$750,$7d0}
' Size of playfield
const lhs=14
const rhs=lhs+11
const top=10
const bttm=top+22
const strow=8
const stcol=18
' Apple II specific addresses
const spkr=$c030
const kbdata=$c000
const kbstrb=$c010
const hpos=36
const rnd=$4e
byte col=18
byte row=5
' ASCII
const beep=7
const clrscr=12
' Position of piece
byte col=stcol
byte row=strow
byte rot=0
byte key=0
byte ocol=18
byte orow=5
' Previous col, row, rotation
byte ocol=stcol
byte orow=strow
byte orot=0
byte key=0
byte piece=0
byte done=0
word score=0
byte canl=1
byte canr=1
' Seed the PRNG
word rr=$4e
call lores()
call clrlo()
call frame()
' Left, right, rotate permitted?
byte lok=1
byte rok=1
byte rotok=1
' First run
byte first=1
call prng()
piece=rr%5
call loresmix()
while 1
key=getkey()
orow=row;ocol=col;orot=rot
if key=='s'
if rot==3
rot=0
pr.ch clrscr
call clrlomix()
call frame()
call printnewlines()
if first
call printintro()
kbd.ch &key
call clearintro()
first=0
endif
call printtext()
call printscore()
call playgame()
kbd.ch &key
endwhile
end
sub playgame()
score=0
while 1
key=getkey()
orow=row;ocol=col;orot=rot
if key=='s'&&rotok
if rot==3
rot=0
else
rot=rot+1
endif
else
rot=rot+1
endif
else
if (key=='a')&&canl
col=col-1
else
if (key=='d')&&canr
col=col+1
if (key=='a')&&lok
col=col-1
else
if (key=='d')&&rok
col=col+1
endif
endif
endif
endif
key=^spkr
row=row+1
canl=1
canr=1
call drawPiece(ocol,orow,orot,1); 'Erase
if drawPiece(col,row,rot,0)
call checkframe(row)
col=18;row=5;rot=0
piece=piece+1
if piece==4
piece=0
key=^spkr
row=row+1
lok=1
rok=1
rotok=1
call drawPiece(ocol,orow,orot,1); 'Erase
if drawPiece(col,row,rot,0)
if row==strow+1
call loser()
return 0
else
call checkframe(row)
col=stcol;row=strow;rot=0
call prng()
piece=rr%5
endif
endif
endif
endwhile
call text()
end
endwhile
endsub
sub getkey()
if ^kbdata<128
@ -99,6 +147,21 @@ sub clrlo()
endfor
endsub
sub clrlomix()
byte r=0
byte c=0
for r=0:19
for c=0:39
^(addrs[r]+c)=0
endfor
endfor
for r=20:23
for c=0:39
^(addrs[r]+c)=' '+128
endfor
endfor
endsub
sub plot(byte c,byte r,byte color)
word a=addrs[r/2]+c
if r%2
@ -141,12 +204,14 @@ sub drawPiece(byte c,byte r,byte rot,byte erase)
if piece==0
return drawT(c,r,rot,erase)
else; if piece==1
return drawZ(c,r,rot,erase)
return drawL(c,r,rot,erase)
else; if piece==2
return drawZ(c,r,rot,erase)
else; if piece==3
return drawSq(c,r,rot,erase)
else
return drawI(c,r,rot,erase)
endif;endif;endif
endif;endif;endif;endif
endsub
sub drawT(byte c,byte r,byte rot,byte erase)
@ -159,8 +224,12 @@ sub drawT(byte c,byte r,byte rot,byte erase)
call plot(c+1,r+1,color)
call plot(c+2,r+1,color)
call plot(c+1,r+2,color)
canl=!(readpix(c-1,r+1)||readpix(c,r+2))
canr=!(readpix(c+3,r+1)||readpix(c+2,r+2))
if erase
return 0
endif
lok=!(readpix(c-1,r+2)||readpix(c,r+2)||readpix(c,r+3))
rok=!(readpix(c+2,r+2)||readpix(c+3,r+2)||readpix(c+2,r+3))
rotok=!(readpix(c,r+2)||readpix(c+1,r+3))
return readpix(c,r+2)||readpix(c+1,r+3)||readpix(c+2,r+2)
else
if rot==1
@ -168,8 +237,12 @@ sub drawT(byte c,byte r,byte rot,byte erase)
call plot(c,r+1,color)
call plot(c+1,r+1,color)
call plot(c+1,r+2,color)
canl=!(readpix(c,r)||readpix(c-1,r+1)||readpix(c,r+2))
canr=!(readpix(c+2,r)||readpix(c+2,r+1)||readpix(c+2,r+2))
if erase
return 0
endif
lok=!(readpix(c-1,r+2)||readpix(c,r+2)||readpix(c,r+3))
rok=!(readpix(c+2,r+1)||readpix(c+2,r+2)||readpix(c+2,r+3))
rotok=!(readpix(c,r+2)||readpix(c+2,r+2))
return readpix(c,r+2)||readpix(c+1,r+3)
else
if rot==2
@ -177,8 +250,12 @@ sub drawT(byte c,byte r,byte rot,byte erase)
call plot(c,r+1,color)
call plot(c+1,r+1,color)
call plot(c+2,r+1,color)
canl=!(readpix(c,r)||readpix(c-1,r+1))
canr=!(readpix(c+2,r)||readpix(c+3,r+1))
if erase
return 0
endif
lok=!(readpix(c-1,r+2)||readpix(c,r+2)||readpix(c+1,r+2))
rok=!(readpix(c+1,r+2)||readpix(c+2,r+2)||readpix(c+3,r+2))
rotok=!(readpix(c+1,r+2)||readpix(c+2,r+2)||readpix(c+1,r+3))
return readpix(c,r+2)||readpix(c+1,r+2)||readpix(c+2,r+2)
else
if rot==3
@ -186,8 +263,12 @@ sub drawT(byte c,byte r,byte rot,byte erase)
call plot(c+1,r+1,color)
call plot(c+2,r+1,color)
call plot(c+1,r+2,color)
canl=!(readpix(c,r)||readpix(c,r+1)||readpix(c,r+2))
canr=!(readpix(c+2,r)||readpix(c+3,r+1)||readpix(c+2,r+2))
if erase
return 0
endif
lok=!(readpix(c,r+1)||readpix(c,r+2)||readpix(c,r+3))
rok=!(readpix(c+2,r+2)||readpix(c+3,r+2)||readpix(c+2,r+3))
rotok=!(readpix(c,r+2)||readpix(c+2,r+2)||readpix(c+1,r+3))
return readpix(c+1,r+3)||readpix(c+2,r+2)
endif
endif
@ -195,6 +276,68 @@ sub drawT(byte c,byte r,byte rot,byte erase)
endif
endsub
sub drawL(byte c,byte r,byte rot,byte erase)
byte color=8
if erase
color=0
endif
if rot==0
call plot(c+1,r,color)
call plot(c+1,r+1,color)
call plot(c+1,r+2,color)
call plot(c+2,r+2,color)
if erase
return 0
endif
lok=!(readpix(c,r+1)||readpix(c,r+2)||readpix(c,r+3)||readpix(c+1,r+3))
rok=!(readpix(c+2,r+1)||readpix(c+2,r+3)||readpix(c+3,r+3))
rotok=!(readpix(c,r+2)||readpix(c+2,r+1))
return readpix(c+1,r+3)||readpix(c+2,r+3)
else
if rot==1
call plot(c+2,r,color)
call plot(c,r+1,color)
call plot(c+1,r+1,color)
call plot(c+2,r+1,color)
if erase
return 0
endif
lok=!(readpix(c-1,r+2)||readpix(c,r+2)||readpix(c+1,r+2))
rok=!(readpix(c+1,r+2)||readpix(c+2,r+2)||readpix(c+3,r+2)||readpix(c+3,r+1))
rotok=!(readpix(c+2,r+2)||readpix(c+2,r+3))
return readpix(c,r+2)||readpix(c+1,r+2)||readpix(c+2,r+2)
else
if rot==2
call plot(c+1,r,color)
call plot(c+2,r,color)
call plot(c+2,r+1,color)
call plot(c+2,r+2,color)
if erase
return 0
endif
lok=!(readpix(c,r+1)||readpix(c+1,r+1)||readpix(c+1,r+2)||readpix(c+1,r+3))
rok=!(readpix(c+3,r+1)||readpix(c+3,r+2)||readpix(c+3,r+3))
rotok=!(readpix(c+1,r+1)||readpix(c+1,r+2)||readpix(c+3,r+1))
return readpix(c+1,r+1)||readpix(c+2,r+3)
else
if rot==3
call plot(c+1,r,color)
call plot(c+2,r,color)
call plot(c+3,r,color)
call plot(c+1,r+1,color)
if erase
return 0
endif
lok=!(readpix(c,r+1)||readpix(c,r+2))
rok=!(readpix(c+2,r+1)||readpix(c+3,r+1)||readpix(c+4,r+1)||readpix(c+2,r+2))
rotok=!(readpix(c+2,r+1)||readpix(c+2,r+2)||readpix(c+2,r+3)||readpix(c+3,r+3))
return readpix(c+1,r+2)||readpix(c+2,r+1)||readpix(c+3,r+1)
endif
endif
endif
endif
endsub
sub drawZ(byte c,byte r,byte rot,byte erase)
byte color=2
if erase
@ -205,18 +348,26 @@ sub drawZ(byte c,byte r,byte rot,byte erase)
call plot(c+1,r+1,color)
call plot(c+2,r+1,color)
call plot(c+2,r+2,color)
canl=!(readpix(c,r)||readpix(c,r+1)||readpix(c,r+2))
canr=!(readpix(c+2,r)||readpix(c+3,r+1)||readpix(c+3,r+2))
return readpix(c+2,r+3)
if erase
return 0
endif
lok=!(readpix(c,r+1)||readpix(c,r+2)||readpix(c+1,r+2)||readpix(c+1,r+3))
rok=!(readpix(c+3,r+2)||readpix(c+3,r+3))
rotok=!(readpix(c,r+3)||readpix(c+1,r+3)||readpix(c+1,r+2))
return readpix(c+1,r+2)||readpix(c+2,r+3)
else
if (rot==1)||(rot==3)
call plot(c+1,r+1,color)
call plot(c+2,r+1,color)
call plot(c,r+2,color)
call plot(c+1,r+2,color)
canl=!(readpix(c,r+1)||readpix(c-1,r+2))
canr=!(readpix(c+3,r+1)||readpix(c+2,r+2))
return readpix(c,r+3)||readpix(c+1,r+3)
if erase
return 0
endif
lok=!(readpix(c-1,r+3)||readpix(c,r+3)||readpix(c+2,r+2))
rok=!(readpix(c+1,r+3)||readpix(c+2,r+3)||readpix(c+2,r+2)||readpix(c+3,r+2))
rotok=!(readpix(c+2,r+2)||readpix(c+2,r+3))
return readpix(c,r+3)||readpix(c+1,r+3)
endif
endif
endsub
@ -231,8 +382,12 @@ sub drawI(byte c,byte r,byte rot,byte erase)
call plot(c+1,r+2,color)
call plot(c+2,r+2,color)
call plot(c+3,r+2,color)
canl=!readpix(c-1,r+2)
canr=!readpix(c+4,r+2)
if erase
return 0
endif
lok=!readpix(c-1,r+3)
rok=!readpix(c+4,r+3)
rotok=!(readpix(c+2,r+3)||readpix(c+2,r+4))
return readpix(c,r+3)||readpix(c+1,r+3)||readpix(c+2,r+3)||readpix(c+3,r+3)
else
if (rot==1)||(rot==3)
@ -240,8 +395,12 @@ sub drawI(byte c,byte r,byte rot,byte erase)
call plot(c+2,r+1,color)
call plot(c+2,r+2,color)
call plot(c+2,r+3,color)
canl=!(readpix(c+1,r)||readpix(c+1,r+1)||readpix(c+1,r+2)||readpix(c+1,r+3))
canr=!(readpix(c+3,r)||readpix(c+3,r+1)||readpix(c+3,r+2)||readpix(c+3,r+3))
if erase
return 0
endif
lok=!(readpix(c+1,r+1)||readpix(c+1,r+2)||readpix(c+1,r+3)||readpix(c+1,r+4))
rok=!(readpix(c+3,r+1)||readpix(c+3,r+2)||readpix(c+3,r+3)||readpix(c+3,r+4))
rotok=!(readpix(c,r+3)||readpix(c+1,r+3)||readpix(c+3,r+3))
return readpix(c+2,r+4)
endif
endif
@ -256,8 +415,12 @@ sub drawSq(byte c,byte r,byte rot,byte erase)
call plot(c+2,r+1,color)
call plot(c+1,r+2,color)
call plot(c+2,r+2,color)
canl=!(readpix(c,r+1)||readpix(c,r+2))
canr=!(readpix(c+3,r+1)||readpix(c+3,r+2))
if erase
return 0
endif
lok=!(readpix(c,r+2)||readpix(c,r+3))
rok=!(readpix(c+3,r+2)||readpix(c+3,r+3))
rotok=1
return readpix(c+1,r+3)||readpix(c+2,r+3)
endsub
@ -268,7 +431,7 @@ sub checkframe(byte r)
endif
while rr>=r
if checkline(rr)
pr.ch 7; 'Beep
pr.ch beep
else
rr=rr-1
endif
@ -283,6 +446,8 @@ sub checkline(byte r)
endif
endfor
call deleterow(r)
score=score+1
call printscore()
return 1
endsub
@ -304,3 +469,40 @@ sub deleterow(byte r)
endwhile
endsub
sub printnewlines()
byte i=0
for i=0:19
pr.nl
endfor
endsub
sub printintro()
^hpos=10
pr.msg "TETRIS - PRESS ANY KEY"
endsub
sub clearintro()
^hpos=10
pr.msg " "
endsub
sub printtext()
^hpos=10
pr.msg "SCORE: "
endsub
sub printscore()
^hpos=17
pr.dec score
endsub
sub loser()
^hpos=10
pr.msg "GAME OVER - SCORE WAS "
pr.dec score
endsub
sub prng()
rr=rr*8191+7; ' Mersenne prime
endsub