Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Tetris in Basic

865 views
Skip to first unread message

Nama

unread,
Mar 9, 2010, 1:54:07 AM3/9/10
to
I'm looking for a listing of Tetris in Basic. It doesn't have to be
Apple basic, but a classic 80's basic (not anything modern like visual
basic) would be great.

Thanks in advance

Philip

winston...@yahoo.com

unread,
Mar 9, 2010, 2:34:32 AM3/9/10
to
On Mar 9, 1:54 am, Nama <forums6...@mac.com> wrote:
> I'm looking for a listing of Tetris in Basic. It doesn't have to be
> Apple basic, but a classic 80's basic (not anything modern like visual
> basic) would be great.

I could supply one in TI Extended Basic! But realize, like many of
Apple's contemporaries (i.e. C64) it uses character-cell based
graphics.

Nama

unread,
Mar 9, 2010, 2:46:23 AM3/9/10
to
On Mar 9, 4:34 pm, "winston19842...@yahoo.com"

Thanks ,
However I don't want to sound ignorant, but what is 'character-cell
based graphics'
I'm planning on porting this to a version of tinybasic for a very
obscure computer. Do you think this version will be a good candidate?

Phil

winston...@yahoo.com

unread,
Mar 9, 2010, 3:27:55 AM3/9/10
to

You know what a character is, right? On old computers, CHR$(0) through
CHR$(255).

Character-cell based graphics (also called tile-based) is utilizing
these characters, redefining them (choosing which pixels are on and
off) and setting their color attributes. This is much different from
the Apple whose graphic modes are line-based (set a pixel, draw a
line, etc).

Yes, I think it would be a good candidate. TI Extended Basic "graphic"
commands are merely printing characters to the screen. The TI does
have sprites, but I'm pretty sure they were not utilized in this game,
as Tetris is a tile-based game.

And unlike many of the computers of the era whose programs were chock-
full of pokes and peeks (C64 is a good example), the TI uses built-in
commands to do most things, so you won't find many Basic programs that
use poke (CALL LOAD on the TI) or peek (these two commands were not
even available in the TI Basic that was installed in the console).

The version I have was modified to play music in the background, but
this can be easily stripped off. It added some subprograms to load
sound lists into memory to be played by the console interrupt routine
(the only peeks and pokes you will see in the program).

Steve Nickolas

unread,
Mar 9, 2010, 6:44:26 AM3/9/10
to
winston...@yahoo.com wrote:
> Yes, I think it would be a good candidate. TI Extended Basic "graphic"
> commands are merely printing characters to the screen. The TI does
> have sprites, but I'm pretty sure they were not utilized in this game,
> as Tetris is a tile-based game.

I've thought of writing a GR Tetris or Dr. Mario but haven't grasped the
guts yet.

TI BASIC is itself run in an interpreter, not?

-uso.

winston...@yahoo.com

unread,
Mar 9, 2010, 7:28:13 AM3/9/10
to
On Mar 9, 6:44 am, lyricalnan...@dosius.ath.cx (Steve Nickolas) wrote:

Yes, mostly, with some assembly support routines. Written in GPL
(Graphics Programming Language), a low-level interpreter that was
probably developed to ease developers into developing software for the
99/4, which has a TMS9900 processor, unfamiliar to those used to
6502's, Z80's, 808x's and the like. The 9900 was based on the PDP-11.

GPL abstracted working with memory (there are several memory types in
a 99/4, ROM/RAM, GROM, VDP, the last two being port-addressed, auto-
incrementing, but slightly different) and had another small
interpreter built-in for processing display commands (FMT short for
format - nothing spectacular).

Many of the modules (especially early ones) are written in GPL. Some
even contain TI Basic! (Personal Record Keeping, for example).

TI Extended Basic optimized some of the routines to assembly.

Nama

unread,
Mar 9, 2010, 8:13:39 AM3/9/10
to
On Mar 9, 5:27 pm, "winston19842...@yahoo.com"

Ok, I thought that was what character-cell based graphics meant. I
just wanted to makes sure as I hadn't heard that exact expression
before. Coming from the Sinclair world, I have always called them
UDG's or 'user definable graphics', however maybe I have the
terminology confused.

Well, yes indeed, the TI basic does seem like a good candidate for my
port. Would it be possible for you to email me a listing of the game?
Just incase you want to know what computer it is for, you can see the
page on the Aamber Pegasus here:

http://web.mac.com/lord_philip/aamber_pegasus/Aamber_Pegasus.html

Thanks again
Philip

winston...@yahoo.com

unread,
Mar 9, 2010, 11:05:31 AM3/9/10
to

Well, I need to say "mea culpa" here... It "looked" like it used
character-cell totally, but it does use a sprite. The falling object
*is* a sprite, but it moves it 8-pixels at a time (which is the size
of a character!).

It could have been done totally using character, but it may be done
this way so the program doesn't have to erase the old characters after
placing the new.

I'm sure to have a Tetris somewhere that uses all characters, but I
will send this to you just so you can have a taste of TI Extended
Basic.

rich12345

unread,
Mar 9, 2010, 11:17:31 AM3/9/10
to

It would probably be easier to code it yourself rather than port
someone else's source

generate a random piece
display it
allow it to rotate
make it fall
check for collision with walls/ floor
check for solid line
remove it if found


XX
XX

XXXX

X
XXX

X
XXX

XX
XX

XX
XX

X
XXX

there are only 7 possible shapes, (check wikipedia it has a TON of
information)


the most difficult problem will be display and collision detection.
the rest of the code should be very similar between different systems.


mmphosis

unread,
Mar 9, 2010, 9:50:44 PM3/9/10
to
10 GOSUB 1000
100 W = W + 1: IF W > LV THEN W = 0: GOSUB 350
110 K = PEEK (KB): IF K > = H THEN POKE KC,H:K = K - H: GOSUB 300
190 GOTO 100
200 PY = PY * A2: VLIN PY,PY + A1 AT PX: RETURN
225 PY = PY * A2: HLIN X1,X2 AT PY: HLIN X1,X2 AT PY + A1: RETURN

300 ON E(K) GOTO 30000,330,340,350,360,30100
310 RETURN
330 X = X - 1: GOTO 400
340 X = X + 1: GOTO 400
350 DN = 1:Y = Y + 1: GOSUB 400:DN = 0: RETURN
360 S = S + 1: IF S / 4 = INT (S / 4) THEN S = S - 4
400 GOSUB 500
410 GOSUB 800: IF F = 0 THEN X = XX:Y = YY:S = SS: GOSUB 420: IF DN
THEN GOSUB 900
420 COLOR= CF: FOR PP = 1 TO 4:PX = X + X(S,PP):PY = Y + Y(S,PP):
GOSUB 200: NEXT PP:XX =X:YY = Y:SS = S:D = 0: RETURN

500 IF DD THEN RETURN
510 COLOR= CB: FOR PP = 1 TO 4:PX = XX + X(SS,PP):PY = YY +Y(SS,PP):
GOSUB 200: NEXT PP:DD = 0: RETURN

800 F = 1: FOR PP = 1 TO 4:PY = Y + Y(S,PP): ON ( FN PC(X + X(S,PP)) >
0) GOTO 805: NEXTPP: RETURN
805 F = 0: RETURN
850 F = 1: RETURN
900 P = 10: GOSUB 30300
905 RN = 0:Y = YM
910 X = XL
920 PY = Y: IF FN PC(X) = CB THEN950
930 X = X + 1: IF X < = XR THEN920
940 R(RN) = Y:RN = RN + 1
950 Y = Y - 1: IF Y > = 0 THEN 910
960 IF RN THEN GOSUB 30400
970 Y = 0
980 X = INT ((XR - XL) / 2) + XL

985 S = INT ( RND (1) * NS):CF =C(S):S = S * 4
990 GOSUB 800: IF F THEN RETURN
995 GOTO 31000

1000 DIM E(127),X(27,4),Y(27,4),R(40)
1010 TEXT : HOME : GR
1011 PRINT "WELCOME..."
1014 LM = 10
1015 XM = 10:YM = 15
1016 XL = INT ((40 - XM) / 2)
1017 XR = XL + XM - 1
1021 A1 = 1
1022 A2 = 2
1030 DEF FN PC(X) = SCRN( X,PY * A2)
1040 CB = 0
1050 XX = 20:YY = 0:SS = 0

1100 KB = - 16384
1110 KC = - 16368
1120 H = 128
1129 REM KEYBOARD ACTIONS
1130 REM QUIT
1131 E( ASC ("Q")) = 1
1132 E( ASC ("Q") - 64) = 1
1140 REM MOVE LEFT
1141 E(8) = 2
1142 E( ASC (",")) = 2
1150 REM MOVE RIGHT
1151 E(21) = 3
1152 E( ASC (".")) = 3
1160 REM MOVE DOWN
1161 E(32) = 4
1162 E( ASC ("Z")) = 4
1170 REM ROTATE
1171 E( ASC ("R")) = 5
1172 E(13) = 5
1173 E( ASC ("A")) = 5
1179 REM PAUSE GAME
1180 E( ASC ("P")) = 6
1181 E( ASC ("P") - 64) = 6
1185 GOSUB 2000
1186 GOSUB 1300
1190 PRINT "PRESS ANY KEY TO START..."
1191 PRINT
1192 PRINT "PRESS Q TO QUIT."
1193 GOTO 31020

1299 REM DRAW THE GAME
1300 COLOR= 4: FOR I = 0 TO 19:X1 = 0:X2 = 39:PY = I: GOSUB225: NEXT
1320 COLOR= CB: FOR I = 0 TO YM:X1 = XL:X2 = XR:PY = I: GOSUB225:
NEXT
1350 RETURN

1400 DATA 1
1401 DATA 0,0,1,0,0,1,1,1
1402 DATA 0,0,1,0,0,1,1,1
1403 DATA 0,0,1,0,0,1,1,1
1404 DATA 0,0,1,0,0,1,1,1
1410 DATA 2
1411 DATA 0,1,1,1,2,1,3,1
1412 DATA 1,0,1,1,1,2,1,3
1413 DATA 0,1,1,1,2,1,3,1
1414 DATA 1,0,1,1,1,2,1,3
1420 DATA 12
1421 DATA 1,1,0,1,1,0,2,1
1422 DATA 1,1,0,1,1,0,1,2
1423 DATA 1,1,0,1,2,1,1,2
1424 DATA 1,1,1,0,2,1,1,2
1430 DATA 13
1431 DATA 1,1,0,1,2,1,0,2
1432 DATA 1,1,1,0,1,2,2,2
1433 DATA 1,1,0,1,2,1,2,0
1434 DATA 1,1,1,0,1,2,0,0

1440 DATA 9
1441 DATA 1,1,0,1,2,1,2,2
1442 DATA 1,1,1,0,1,2,2,0
1443 DATA 1,1,0,1,2,1,0,0
1444 DATA 1,1,1,0,1,2,0,2
1450 DATA 3
1451 DATA 1,1,1,0,0,0,2,1
1452 DATA 1,1,1,0,0,1,0,2
1453 DATA 1,1,1,0,0,0,2,1
1454 DATA 1,1,1,0,0,1,0,2
1460 DATA 6
1461 DATA 1,1,0,1,1,0,2,0
1462 DATA 1,1,0,1,0,0,1,2
1463 DATA 1,1,0,1,1,0,2,0
1464 DATA 1,1,0,1,0,0,1,2

1990 DATA -1
2000 X = 0:Y = 0
2010 NS = 0
2020 READ C: IF C < > - 1 THENC(NS) = C: FOR J = 0 TO 3: FORI = 1
TO 4: READ X(NS * 4 +J,I): READ Y(NS * 4 + J,I): NEXTI: NEXT J:NS = NS
+ 1: GOTO2020
2030 RETURN
21210 P = 1: RETURN
30000 TEXT : HOME : END
30100 HOME
30110 PRINT "GAME PAUSED. PRESS P TO CONTINUE..."
30120 P = 1
30130 K = PEEK (KB): IF K > = H THEN POKE KC,H:K = K - H:
GOSUB30200
30140 IF P THEN 30130
30150 HOME
30160 PRINT "SCORE ";SC; TAB( 21);"LEVEL ";LM - LV + 1
30170 RETURN

30200 ON E(K) GOTO 30000,30210,30210,30210,30210,30220
30210 RETURN
30220 P = 0
30230 RETURN

30300 SC = SC + P
30310 VTAB 21: HTAB 7
30320 PRINT SC;
30330 RETURN
30400 RN = RN - 1
30410 FOR C = 0 TO 32
30415 COLOR= C
30420 FOR I = 0 TO RN:X1 = XL:X2 = XR:PY = R(I): GOSUB 225: NEXTI
30430 FOR I = 0 TO 2: NEXT I
30440 NEXT C
30450 FOR I = 0 TO RN
30460 Y = R(I) + I
30470 YP = Y - 1: FOR X = XL TO XR:PY = YP: COLOR= FN PC(X):PX = X:PY
= Y: GOSUB 200: NEXTX:Y = Y - 1: IF Y > 0 THEN 30470
30480 P = 100: GOSUB 30300
30490 NEXT I
30495 RETURN
31000 VTAB 22: PRINT
31010 PRINT " GAME OVER"
31020 P = 1
31030 K = PEEK (KB): IF K > = H THEN POKE KC,H:K = K - H:
GOSUB31200
31040 IF P THEN 31030
31050 D = 1
31060 SC = 0:LV = LM
31070 GOSUB 30150
31080 GOSUB 1300
31090 GOTO 905
31200 ON E(K) GOTO 30000
31210 P = 0: RETURN

BLuRry

unread,
Mar 9, 2010, 10:41:19 PM3/9/10
to
wow... that works well! is it possible to print text values instead
of using lo-res drawing routines? Would it be faster? e.g. you could
write these characters as text and they show in lo-res as solid
blocks: ] * ; L n

-Brendan

mmphosis

unread,
Mar 9, 2010, 11:35:07 PM3/9/10
to

Thanks. It works, but it's slow! If my memory serves me, I wrote
this in 1992.

It could definitely be optimized to run faster. The drawing
primitives are at lines 200 and 225. It looks like the subroutine at
line 800 does collision detection.

rich12345

unread,
Mar 10, 2010, 11:23:29 PM3/10/10
to
On Mar 9, 6:50 pm, mmphosis <markwst...@yahoo.com> wrote:
>


I wanted to code this and post it to csa2.programmer


repost to it and see if we can make it faster?


you have good applesoft technique. I never got as far
as putting often routines in < beginning.

rich12345

unread,
Mar 11, 2010, 2:28:54 PM3/11/10
to

with latest applewin, pasting the code in results in several
errors?

is shift-insert now broken?


Rich

schmidtd

unread,
Mar 11, 2010, 2:41:18 PM3/11/10
to
On Mar 11, 2:28 pm, rich12345 <aiiad...@gmail.com> wrote:
> with latest applewin, pasting the code in results in several
> errors?
>
> is shift-insert now broken?

No, but you have to eliminate the line breaks. I brought up the cut/
paste data in Notepad, turned line wrap off, and made sure each line
number had its full line of data behind it. It pasted and ran fine in
AppleWin then.

Allen Bong

unread,
Mar 13, 2010, 9:19:36 PM3/13/10
to

I thought the same as first. But after I see the listing in NotePad,
only the long lines were having problems. So I reinsert the long
lines one at a time and used ESC IJKM to edit and join the broken
lines together.

Then I run it again to see if there were any more syntax error. The
program works very well under Applewin 1.8 thanks to mmphosis. I
think the game can be made to run smoother under Applewin by
increasing the processor speed, but that can only be done after I
understand how the entire program works.

Allen

Bill Garber

unread,
Mar 13, 2010, 10:19:17 PM3/13/10
to

"mmphosis" <markw...@yahoo.com> wrote in message
news:cfd4d7d9-fd56-4625...@q2g2000pre.googlegroups.com...

When my pieces reach the top, it starts me over
again at level one. Doesn't say 'GAME OVER' or
any other kind of warning. This is on AppleWIN,
not sure which version, the one I use, and also
under DOS 3.3, and AppleSoft, of course.

I don't have any real hardware set up ATM, so,
can't try it there as yet. Maybe tomorrow. 8^)

Bill

Tristan

unread,
Mar 23, 2010, 2:41:28 AM3/23/10
to All
On Tue, 09 Mar 2010 05:13:39 -0800, Nama wrote:

I think it lost to Apple because the video display design is horrible. I
am however extremely envious of you.

So, do you need a pixel or cell based implementation?

To be honest you'd probably be better off writing it yourself. A simple
tetris wouldn't be hard at all. If your code is ugly you aren't doing it
wrong. Tetris may be a simple concept but it creates some really awkward
looking code.

Tristan.

D Finnigan

unread,
Mar 23, 2010, 3:41:32 PM3/23/10
to
Tristan wrote:
>
> I think it lost to Apple because the video display design is horrible. I
> am however extremely envious of you.
>
> So, do you need a pixel or cell based implementation?
>

Tetris would make a great candidate for Shape Tables, especially with the
Rotate ability.

Michael J. Mahon

unread,
Mar 23, 2010, 7:29:50 PM3/23/10
to

...and the built-in collision detection.

-michael

NadaNet and AppleCrate II: parallel computing for Apple II computers!
Home page: http://home.comcast.net/~mjmahon

"The wastebasket is our most important design
tool--and it's seriously underused."

0 new messages