Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 100 gosub 7000:print chr$(147);chr$(5);
- 105 print "2016-July basic month: terraspin"
- 110 print "http://reddit.com/r/retrobattlestations"
- 115 print "written by fozztexx - commodore 64 port by fozztexx"
- 120 print "commodore 64 basic has bitwise operators so much of the line"
- 125 print "clipping logic is simplified compared to the apple ii version"
- 130 print "the commodore 64 has *no* graphics commands at all"
- 135 print "all graphics has to be done using peeks and pokes"
- 140 print "line drawing is handled by a complicated routine at 1500"
- 145 print "individual pixels are then plotted with the routine at 1700"
- 150 print "2016-07-10 alvalongo"
- 155 print "optimized plotting using variables"
- 160 print "and constants"
- 170 print "========================================"
- 199 :
- 200 rem === initialize variables
- 210 sw=320:sh=200:xs=sw/1000:ys=(sh*4)/(1000*3):k1=1:e=1
- 220 sw=sw-k1:sh=sh-k1:dg=360:k7=7:k8=8:z0=0:sid=54296
- 230 p8={pi}/180:rem pi is a c64 constant
- 235 dim b(7),c(39),l(199):rem bitmask, column offset, line
- 240 gosub 7100
- 250 rem === set turtle start at center of screen pointing up, pen up
- 260 tx=500:ty=sh/ys/2:ta=90:tp=z0
- 265 :
- 300 rem === get command to execute
- 301 rem numeric values will be pushed onto a stack
- 302 rem a command will pop off a value and then execute
- 303 rem d - lower the pen
- 304 rem u - raise the pen
- 305 rem m - move
- 306 rem t - turn
- 307 rem ======================
- 310 cm$="d 20 m 90 t 40 m 90 t 60 m 90 t 80 m"
- 311 cm$=cm$+" 90 t 100 m 90 t 120 m 90 t 140 m 90 t 160 m 90 t 180 m"
- 312 cm$=cm$+" 90 t 200 m 90 t 220 m 90 t 240 m 90 t 260 m 90 t 280 m"
- 313 cm$=cm$+" 90 t 300 m 90 t 320 m 90 t 340 m 90 t 360 m 90 t 380 m"
- 314 cm$=cm$+" 90 t 400 m 90 t 420 m 90 t 440 m 90 t 460 m"
- 315 c1$=" 90 t 480 m"
- 316 c1$=c1$+" 90 t 500 m 90 t 520 m 90 t 540 m 90 t 560 m 90 t 580 m"
- 317 c1$=c1$+" 90 t 600 m 90 t 620 m 90 t 640 m 90 t 660 m 90 t 680 m"
- 318 c1$=c1$+" 90 t 700 m 90 t 720 m 90 t 740 m"
- 390 :
- 460 rem ### if the program crashes it will
- 470 rem ### be stuck in graphics mode.
- 480 rem ### type run 900 to get back to text.
- 490 gosub 6000:gosub 6100
- 495 :
- 500 rem === command interpreter
- 510 ip=k1:sp=z0
- 520 c$=mid$(cm$,ip,k1)
- 530 if c$=" " then ip=ip+k1:goto 520
- 535 print ip;",";tx;",";ty;",";ta;",";tp;",";c$
- 540 if c$>="-" and c$<="9" then v=val(mid$(cm$,ip)):gosub 1010:gosub 1210
- 550 if c$="(" then v=ip:gosub 1010
- 560 if c$=")" then gosub 2010
- 570 if c$="m" then gosub 2510
- 580 if c$="t" then gosub 3010
- 590 if c$="u" then gosub 3510
- 600 if c$="d" then gosub 4010
- 610 ip=ip+k1
- 620 if ip<=len(cm$) then 520
- 630 if e<2 then e=2:cm$=c1$:goto 510
- 700 get k$:if k$="" then gosub 7200:goto 700
- 900 print "End"
- 910 gosub 7000
- 990 end
- 1000 rem === push onto stack
- 1010 sp=sp+k1:sk(sp)=v
- 1020 return
- 1025 :
- 1100 rem === pop from stack
- 1110 v=sk(sp):sp=sp-k1
- 1120 return
- 1125 :
- 1200 rem === skip over number
- 1210 ip=ip+k1
- 1220 if ip>len(cm$) then 1250
- 1230 c2$=mid$(cm$, ip, k1)
- 1240 if c2$>="-" and c2$<="9" then goto 1210
- 1250 ip=ip-k1
- 1260 return
- 1265 :
- 1500 rem === plot a line
- 1510 x1%=x1:x2%=x2:y1%=y1:y2%=y2
- 1520 dx%=abs(x2%-x1%):sx%=-k1:if x1%<x2% then sx%=k1
- 1530 dy%=abs(y2%-y1%):sy%=-k1:if y1%<y2% then sy%=k1
- 1540 er%=-dy%:if dx%>dy% then er%=dx%
- 1550 er%=er%/2
- 1560 gosub 1710
- 1570 if x1%=x2% and y1%=y2% then return
- 1580 e2%=er%
- 1590 if e2%>-dx% then er%=er%-dy%:x1%=x1%+sx%
- 1600 if x1%=x2% and y1%=y2% then return
- 1610 if e2%<dy% then er%=er%+dx%:y1%=y1%+sy%
- 1620 if x1%=x2% and y1%=y2% then return
- 1630 goto 1560
- 1640 :
- 1700 rem === plot a point ===========
- 1710 by=l(y1%)+c(x1%/k8)
- 1730 poke by,peek(by) or b(x1% and k7)
- 1740 return
- 1750 :
- 2000 rem === loop instruction end
- 2010 gosub 1110:bp=v
- 2020 gosub 1110:lr=v
- 2030 lr=lr-k1
- 2040 if lr<k1 then return
- 2050 v=lr:gosub 1010
- 2060 v=bp:gosub 1010
- 2070 ip=bp
- 2080 return
- 2085 :
- 2500 rem === move
- 2510 gosub 1110
- 2520 lx=v*cos((dg-ta)*p8):ly=v*sin((dg-ta)*p8)
- 2530 if tp>z0 then x1=tx:y1=ty:x2=x1+lx:y2=y1+ly:gosub 4510
- 2540 tx=tx+lx:ty=ty+ly
- 2550 return
- 2555 :
- 3000 rem === turn
- 3010 gosub 1110
- 3020 ta=ta-v
- 3030 if ta<z0 then ta=ta+dg:goto 3030
- 3040 if ta>=dg then ta=ta-dg:goto 3040
- 3050 return
- 3055 :
- 3500 rem === pen up
- 3510 tp=k0
- 3520 return
- 3525 :
- 4000 rem === pen down
- 4010 tp=k1
- 4020 return
- 4025:
- 4500 rem === draw line, clipping if needed
- 4510 x1=x1*xs:x2=x2*xs:y1=y1*ys:y2=y2*ys
- 4520 x=x1:y=y1:gosub 5010:c1=c
- 4530 x=x2:y=y2:gosub 5010:c2=c
- 4540 if c1=z0 and c2=z0 then gosub 1510:return
- 4550 if c1 and c2 then return
- 4560 c=c1:if c=z0 then c=c2
- 4570 if c and 1 then x=x1+(x2-x1)*(sh-y1)/(y2-y1):y=sh:goto 4610
- 4580 if c and 2 then x=x1+(x2-x1)*(z0-y1)/(y2-y1):y=z0:goto 4610
- 4590 if c and 4 then y=y1+(y2-y1)*(sw-x1)/(x2-x1):x=sw:goto 4610
- 4600 if c and 8 then y=y1+(y2-y1)*(z0-x1)/(x2-x1):x=z0:goto 4610
- 4610 if c=c1 then x1=x:y1=y:goto 4630
- 4620 x2=x:y2=y
- 4630 goto 4520
- 5000 rem === calculate region code
- 5010 c=z0
- 5020 if y>sh then c=c or k1
- 5030 if y<z0 then c=c or 2
- 5040 if x>sw then c=c or 4
- 5050 if x<z0 then c=c or k8
- 5060 return
- 5065 :
- 6000 rem === enable hi-res 320x200 screen
- 6010 poke 56576,(peek(56576)and 252)or 2:rem video bank 1 at $4000
- 6015 poke 53272,0+128:rem offset $0000 (hires)+$2000(color)
- 6020 poke 53265,peek(53265) or 32:rem hires-on
- 6030 bm=16384:rem bitmap memory at $4000
- 6040 cm=24576:rem color memory at $6000
- 6050 for x=0 to 7:b(x)=2^(k7-(x and k7)):next x:rem bit mask
- 6060 for x=0 to 39:c(x)=k8*x:next x:rem column offset
- 6070 for y=0 to 199:l(y)=bm+320*int(y/k8)+(y and k7):next y:rem line
- 6080 return
- 6095 :
- 6100 rem === clear hires screen
- 6110 for i=cm to cm+999:poke i,3:next:rem color
- 6120 sys 49152:rem clear hires
- 6130 return
- 6135 :
- 7000 rem === enable text screen ===
- 7010 poke 56576,(peek(56576)and 252)or 3:rem video bank 0 at $0000
- 7015 poke 53272,16+6:rem offset $0400+$1800
- 7020 poke 53265,peek(53265) and 223:rem text
- 7030 return
- 7100 rem === clear hires screen assembler
- 7110 s=z0:for by=49152 to 49176
- 7120 read a:poke by,a:s=s+a:next by
- 7130 read a:if s<>a then print "error assembly":end
- 7140 data 169,0,133,251,169,64,133,252
- 7150 data 162,32,160,0,169,0,145,251
- 7160 data 136,208,251,230,252,202,208
- 7170 data 246,96,3919
- 7180 return
- 7195 :
- 7200 rem --- beep
- 7210 poke 54296,15
- 7220 tz=ti+80
- 7230 if ti<tz then 7230
- 7240 poke 54296,z0
- 7250 return
Add Comment
Please, Sign In to add comment