Tron – Remembering old Commodore days

A couple of days ago, I found in Amazon the book “A commodore 64 Walkabout by Robinson Mason”, so I had no choice but buy it.

As many other nowadays developers, in the eighties I was the owner of a fantastic Commodore Vic-20, a real cool computer, the real programmer teacher for many of us.

After reading no more than twenty pages, I had to download the VICE emulator and as if it was an old ritual, I began to type the game of TRON, a clasic game that I have developed in every computer platform that I have owned, and in every programming language that I have learned.

Here is the code I have been able to develop in a couple of hours of remembering CBM Basic. The code works ok in the Commodore Vic-20 emulation of VICE. Enjoy it.

10 : rem TRON   :::::
12 : rem by     :::::
14 : rem F.G.Huerta :

20 rem ::::::init vars
25 rem n => (x, y, ix, iy, color)
30 dim p%(1,4)
40 for pn=0 to 1
50  for i=0 to 4
60   read a: p%(pn,i)=a
70  next i
80 next pn

90 :::::::rem velocity
100 v=1

110 rem ::::::::sprite
120 s=asc("*")

130 rem screen & color
140 ms=7680: mc=38400

150 :::rem init screen
160 print chr$(147)

170 :::::rem main loop
180 get k$
190 if k$="x" then msg$="bye":goto 1600: rem salir

200 :::::rem player ia
210 if k$="a" then p%(0,2)=-v:p%(0,3)=0
220 if k$="d" then p%(0,2)=v :p%(0,3)=0
230 if k$="w" then p%(0,3)=-v:p%(0,2)=0
240 if k$="s" then p%(0,3)=v :p%(0,2)=0

300 :::::::rem comp ia
310 x=p%(1,0)+p%(1,2):y=p%(1,1)+p%(1,3)
320 gosub 1000: rem get char
330 if z<>s then goto 400
340 if p%(1,2)<>0 then p%(1,2)=0:p%(1,3)=1: goto 400
350 p%(1,2)=1:p%(1,3)=0

400 :::::::rem phisics
410 for pn=0 to 1
420   gosub 1100: rem p to vars
430   gosub 1200: rem move
440   gosub 1300: rem vars to p
450 next pn

500 :::::::rem chk fin
510 if p%(0,0)=p%(1,0) and p%(0,1)=p%(1,1) then 1400: rem empate
520 for pn=0 to 1
530   gosub 1100: rem p to vars
540   gosub 1000: rem get char
550   if z=s then 1500: rem winner
560 next

600 ::::::::rem pintar
610 for pn=0 to 1
620   q=p%(pn,1)*22+p%(pn,0)
630   poke mc+q,p%(pn,4)
640   poke ms+q,s
650 next

700 ::::::rem end loop
710 goto 170

1000 ::::::rem get char
1010 q=y*22+x
1020 z=peek(ms+q)
1030 return

1100 :::::rem p to vars
1110 x = p%(pn,0): y = p%(pn,1)
1120 ix= p%(pn,2): iy= p%(pn,3)
1130 return

1200 ::::::::: rem move
1210 x=x+ix: y=y+iy
1220 if x<1  then x=21
1230 if x>21 then x=0
1240 if y<1  then y=21
1250 if y>21 then y=0
1260 return

1300 :::::rem vars to p
1310 p%(pn,0)=x
1320 p%(pn,1)=y
1330 return

1400 ::::::: rem empate
1410 msg$="draw"
1420 gosub 1700: rem efectos especiales
1420 goto 1600: rem salir

1500 :::::::rem winner
1510 msg$="human win"
1520 if pn=0 then msg$="computer win"
1530 gosub 1700: rem efectos especiales

1600 ::::::::rem salir
1610 print msg$
1620 end

1700 :::rem efecto fin
1710 for n=1 to 10
1720  for m=10 to 14
1730   poke36864,m
1740  next m
1750 next n
1760 return 

2000 :::::::::rem data
2010 data 9, 11, 0, 1, 7
2020 data 11, 11, 0, 1, 2

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>