﻿ rem ----------------------------------------------------------------------------------------------
 rem --- SillyVenture_2019_Fluid_City_PAL demo - B SIDE, previously unreleased!
 rem --- This demo features:
 rem --- Smooth fluid full screen Animation with the largest text scroller ever on the Atari VCS!
 rem --- Motion Blur Reduction parallel discovery made on Atari as featured on BlurBusters.com 
 rem --- Impressionistic Music Engine changing Tunes and Fx - tune: Impressionism II
 rem -- note: tune is now the B SIDE tune, that's theme5!
 rem ----------------------------------------------------------------------------------------------
 rem --- 20191126 Bugfix fixed debug color tuning via reset and select [do not use]
 rem --- 20191127 Added algorithm to resequence the musical score on all scrolling text screens 
 rem --- 20191202 Tuning the PAL color defaults for best display [some were dropping intermittently]
 rem --- adj tuning; colorizeplayer for 16 inc, also lines 71-2,maintains PAL intensity vals
 rem --- 2011202 Bugfix - found the overcycle spots on the scroller and optimized them!
 rem --- 20210215 Back ported enhancement from SUPERBLITZ - throttle control (makes 60 Hz action playable!)
 rem --- special PlusCart GameModem message version! :)
 rem ----------------------------------------------------------------------------------------------

 rem -- Notes about the Demo:
 rem -- The playable game component is written in 9 lines of BASIC
 rem -- and beat the C64 in the 2016 Vintage BASIC 10 liners contest!

 rem -- the ASCII engine for the large text scroller is the rest of the code,
 rem -- use the bw switch to toggle the Motion Blur Reduction demo during the text scrolling!

 rem --- Destroy the Industrial complex containing a Gravitic Mine that has you 
 rem --- Trapped in orbit around a Moon, before the Mine pulls you down. 
 
 rem Demo activation Controls:
 rem --- select/reset - change ship/city color schemes
 rem --- bw - Activates Warp Drive during play - 60 FPS impossible skill level, with MBR!
 rem --- bw - Toggles motion blur reduction during large text scrolling
 rem --- left difficulty - Advanced/Beginner setting for the Fluid City depth
    
 rem ---init section, runs once: -------------
 scrollvirtualworldtoggle=1
 MUSICINDEX=135:player0y=4
 rem g=2
 rem --- queue intro scene:
 gosub 1: g=2:py=77:gosub setmsg
 e=0
  
 rem ---gameloop subroutine, runs every frame:    ---
 rem bounce camera demo effect added 11/24/2022 for sillyventure rerelease
 rem buggy check unmodified demo soource
 rem if BYTErowoffset=48 then e=0
 rem if BYTErowoffset=0 then e=1
 rem if e=1 then BYTErowoffset=BYTErowoffset+ 12 else BYTErowoffset=BYTErowoffset-12


 if g=2 then goto top_message
 t=1-t:rem toggle
 rem --- check for Winner
 if player0y<3 then CXCLR=0:g=2:for i=0 to 255:AUDF0=i:AUDV0=i:next i:BYTErowoffset=0:py=player0y:gosub setmsg:goto top_message
 if SWCHB|%11110111<>255 or joy0right=1 then scrollvirtualworldtoggle=35:gosub DLI:scrollvirtualworldtoggle=0:goto 0:rem double speed - every frame
 if t=0 then scrollvirtualworldtoggle=35:gosub DLI:scrollvirtualworldtoggle=0:return: rem run this DLI every other frame
 
0 data city 1,4,2,5,3,2,3,1,4,1,5,5,5,2,2,3,1,4,1,4,3,1,4,4,1,1,2,2,3,1,3,4,5,4,4,3,4,5,1,2,4,1,5,2,2,3,1,3,5,1,4,1
 
 rem ------------------------------------------------------------------
 rem 20191025 SillyVenture variable Music Fx Impressionism theme added!
 rem data data data
 rem use player0y/8, 
 rem lsr lsr lsr the player0y val if out of time on calling the slow division routine
 rem load balancing - putting this in top loop 1st: score =player0y/8
 " lda player0y: lsr: lsr: lsr: sta score; faster inline assembly routine than division/8 call"
 if by>score then by=0:SUSTAINFORFRAMES=9:AUDC0=0 else by=by+1
 rem ------------------------------------------------------------------
 rem score=player0y/8: rem 201925 load balancing fast mode, may have to lsr it...



1 if g=0 then for j=0 to 7:player1(j)=189:player0(j)=pl(j):next j:BYTErowoffset=120:COLUPF=$50:COLUP0=$b4:COLUBK=0 else goto 3 
 scrollvirtualworldtoggle=1:g=1
 rem =77:goto bounce_off_this_for_intro:rem queue initial intro scene!!!
2 for j=20 to 71:k=j-20:k=city(k)+14:for i=k to 19:vwpixel(j,i,on):next i,j:player0y=96:player0x=84:COLUP1=$74:y=20
3 AUDV0=0:BITIndex=BITIndex+1:missile0x=missile0x+2:data pl 0,224,127,231,252,192:data P 128,0 
 rem 3 BITIndex=BITIndex+1:missile0x=missile0x+2:data pl 0,224,127,231,252,192:data P 128,0 

 if SWCHB|%11111101=255 then goto dontchangerowcolors
 for i=1 to 8:rem 0 to 9 breaks it???
 score=rowcolors(i)+16:rem not 4, maintaining intensity 
 if score>223 or score<33 then score=38:rem 20191202 brighter intensity seed val for PAL 
 rowcolors(i)=score
 next i
 rem return:rem fixes it?
dontchangerowcolors
 if SWCHB|%11111110<>255 then gosub colorizeplayer 
fix3
 return

top_message rem ------ MESSAGING SUBSYSTEM (top vertical blank)


 rem ------------------------------------------------------------------
 rem g=0 --- can't turn messaging back off here because the bottom blank code will break...
 if bx<>255 then bx=bx+1
65 if var1>0 then VBLANK=2:rem disable TIA output while reguaging display
70 if t=1 then scrollvirtualworldtoggle=32:gosub DLI:scrollvirtualworldtoggle=6:scrollvirtualworldtoggle=0:return
77 if SWCHB|%11110111<>255 then VBLANK=2:rem disable TIA output for 30 HZ view with COLOR switch 
 return


bottom_message rem ------- MESSAGING SUBSYSTEM (bottom vertical blank)
 rem can turn messaging back off here:
 rem queue delay so message isn't instantly stopped



 rem ------------------------------------------------------------------
 rem 20191027 SillyVenture variable Music Fx Impressionism theme, Title Screen remix
 rem seed is 10
 rem if by>8 then by=0:SUSTAINFORFRAMES=9:AUDC0=0 else by=by+1
 if by>23 then by=0:SUSTAINFORFRAMES=23 else by=by+1


 
 rem opt - g is already 2 if program is here...
 rem if g=2 and joy0fire=1 and bx=255 then for i=0 to 239: virtualworld(i)=0:next i:g=0:NUSIZ0=%00000000:REFP0=0:BITIndex=0:BYTErowoffset=120:scrollvirtualworldtoggle=1:CXCLR=0:var2=0:MUSICINDEX=135:return 

 if bx=255 and joy0fire=1 then for i=0 to 239: virtualworld(i)=0:next i:g=0:NUSIZ0=%00000000:REFP0=0:BITIndex=0:BYTErowoffset=120:scrollvirtualworldtoggle=1:CXCLR=0:var2=0:MUSICINDEX=135:return 

 t=1-t: rem s=1-s:rem toggle - s was getting set to 4 sometimes (also flag var)

50 if t=1 then scrollvirtualworldtoggle=35:gosub DLI:scrollvirtualworldtoggle=0:gosub linkplayer:return
 rem if s=1 then scrollvirtualworldtoggle=35:gosub DLI:scrollvirtualworldtoggle=0:vwpixel(70,8,bindplayer0):gosub linkplayer:return


 if BITIndex=0 and BYTErowoffset=0 and var1=7 then scrollvirtualworldtoggle=1: rem gosub drawlettersonscreen
 rem player0x=MUSICINDEX:player0y=MUSICINDEX*2

 rem s=0
 if var1=0 then BITIndex=BITIndex+1 else var1=var1-1
 rem optimization
 if BITIndex<>72 then return
 if BYTErowoffset=120 then BITIndex=0:BYTErowoffset=0:var1=7:return
 if BYTErowoffset=0 then BITIndex=0:BYTErowoffset=120

 rem if BITIndex=72 and BYTErowoffset=120 then BITIndex=0:BYTErowoffset=0:var1=7
 rem if BITIndex=72 and BYTErowoffset=0 then BITIndex=0:BYTErowoffset=120


 return

 rem setmsg2

 rem return

 rem -------------------------------------------------------------
drawlettersonscreen rem ------------------------------------------

 rem ---variables----
 rem ---var1 phrase delay
 rem ---m = block index
 rem ---var2 = target block (0 or 1), up to 512 characters, easily expanded
 rem ---i,j,k,l - loop vars 
 rem ---n = tracker controller
 
 rem for i=0 to 239:virtualworld(i)=0:next i:rem clear virtualworld
 MUSICINDEX=135

 if var2=1 then goto jmpmsgtypes  
 rem if py<15 then goto jmpmsgtypes: rem and m=255 then m=0:goto jmpmsgtypes

 if py<=36 and m>179 then m=120
 if py<=36 then goto jmpmsgtypes

 if py>=53 and m>59 then m=0
 rem if py>=54 then goto jmpmsgtypes

 if py<=52 and m>119 then m=60


jmpmsgtypes
 

 if m=255 then m=0: rem :var2=var2+1:rem next block, first index
 rem if var2=2 then var2=0:rem only 2 blocks (512 characters)
 rem if var2=2 then var2=1:rem only repeat block2 (512 characters)

 v=2
secondpass if v>2 then v=119:rem second pass for bottom of screen
 for j=20 to 84 step 8:k=j+8
 v=v+1:rem starts at 3...goes 9 accross
 for i=j to k
 rem replace this with lookup
 rem l=j-20:l=l+i:l=l-j:rem l=sprites(l) 
 l=m
 rem if v>119 then l=l+48:rem adjust overlap placement for 2nd pass 
 if var2=0 then l=textdata(l)
 if var2=1 then l=text2dat(l)
 if l>60 and l<97 then l=l+32:rem --- filter uppercase 
 if l=48 then l=111: rem 0 maps to O
 if l=49 then l=105: rem 1 maps to i
 if l=56 then l=98: rem 8 maps to B
 if l=53 then l=115: rem 5 maps to S
 if l=50 then l=123: rem 2 maps to z+1
 if l=51 then l=124: rem 3 maps to z+2
 if l=52 then l=125: rem 4 maps to z+3
 if l=54 then l=126: rem 6 maps to z+4
 if l=55 then l=127: rem 7 maps to z+5
 if l=57 then l=128: rem 9 maps to z+6
 if l=33 then l=i-j:l=sprites2(l):goto handel_exclamation_too : rem handle ! while out of space for chars!

 if l=32 then l=0 else l=l-97:l=l*8:l=l+i:l=l-j:l=sprites(l)
handel_exclamation_too
 virtualworld(v)=l
 v=v+12
 next i
 m=m+1: rem next letter
 
 rem save cycles:
 rem v=v-96:rem 12*8; return to the relative top row 
 rem v=v-12:rem why? 
 v=v-108
 next j
 if v<122 then m=m-3: goto secondpass
 return

 data sprites2  %00000000
 data sprites2a %00000000
 data sprites2b %00001100
 data sprites2c %00001100
 data sprites2d %00001100
 data sprites2e %00000100
 data sprites2f %00000000
 data sprites2g %00001100

 rem --- Message Data can be ASCII codes in BASIC data statements ---
 rem --- or direct text in the special format shown! :) ---
 rem data textdata 104,101,108,108,111,32,119,111,114,108,100,32,116,104,105,115,105,115,97,116,101,115,116,111,102,116,104,101,97,116,97,114,105,50,54,48,48,98,105,103,116,101,120,116,115,99,114,111,108,108,101,114,116,104,97,116,114,117,110,115,97,116,54,48,104,122,111,114,51,48,104,122,44,97,110,100,51,48,102,112,115,119,104,105,108,101,114,117,110,110,105,110,103,97,103,97,109,101,97,110,100,112,108,97,121,105,110,103,116,114,97,99,107,101,114,116,117,110,101,115,111,110,115,116,111,99,107,86,67,83,100,111,117,98,108,101,116,114,117,101,100,111,117,98,108,101,116,114,117,101,32,105,115

 rem ---- Plain text (easier) can be added directly like this:

 data textdata   "First playable "
 data tdata9     "60 FPS animated"
 data tdata8     "SuperBlitz with"
 data tdata7     "ThrottleControl"

 data tdata6  "PlusCart club!!"
 data tdataB  "Fun Atari games"
 data tdataC  "play Burgertime"
 data tdatad  "Mr Do an Pacman"
 
 data tdataaa "Now play enduro"
 data tdataa9 "Frostbite and  "
 data tdataa8 "Qbert! Boing! N"
 data tdataa7 "Missle Command!"

 data tdataa6 "secret message!"
 data tdataaB "embedded ASCII!"
 data tdataaC "easter egg fun!"
 data tdataad "I love BASIC an"
 data tdataae "6507 demos! U2?"

 data text2dat  "You Win PLAYAH!"
 data t2dat9 "scene shoutout "
 data t2dat8 "for every coder"
 data t2dat7 "and gamer on   "
 data t2dat6 "gamemodem netwk"
 data t2datB "More fun games "
 data t2datC  "play BattleZone"
 data t2datd  "Robot Tank and "
 data t2data  "Air Sea Battle "
 data t2dat9a "River Raid and "
 data t2dat8a "Air Raid rock! "
 data t2dat7a "Commando Karate"
                    
 data t2datBa "KungFu Ikari an"
 data t2dat6a "Defender2!Atari"
 data t2datCa "has allthe best"
 data t2datda "games 4training"
 data t2datea "StarFighters!!!"

 rem ASCII translation key: -97 to get 0, * 8 to get index, different for 0123456789 (remapped)
 rem -----------------------------------------------------------------

 rem -----------------------------------------------------------------

17 rem ---gameloop2 subroutine, runs every frame:    --
 if g=2 then goto bottom_message
 if SWCHB|%11110111<>255  or joy0right=1 then scrollvirtualworldtoggle=8:gosub DLI:scrollvirtualworldtoggle=0:goto 18:rem double speed - every frame
 
 if t=1 then scrollvirtualworldtoggle=8:gosub DLI:scrollvirtualworldtoggle=0:return: rem run this DLI every other frame
18 rem COLUBK=0

 if s=4 then s=0:vwpixel(x,y,flip):player1x=0:player1y=0:AUDC0=y:y=20:AUDF0=4:AUDV0=15:goto 7

 if joy0fire=1 and y>=20 then AUDF1=6:AUDC1=8:AUDV1=15:x=BITIndex+10:i=96-player0y:i=i/10:y=11+i:goto 5: rem fix3


 rem 5 if y<21 then vwpixel(x,y,bindplayer1):j=y-10:y=y+1:COLUP1=M(j):data M $64,$54,$b4,$a4,$32,$44,$c4,$94,$f4,$54,$24,$42
 if y>19 then goto 7
5 vwpixel(x,y,bindplayer1):j=y-10:y=y+1:COLUP1=M(j):data M $64,$54,$b4,$a4,$32,$44,$c4,$94,$f4,$54,$24,$42
 if vwpixel(x,y,poll)>0 then s=4: rem queue event
   
 rem optimize 6 if y<=19 and vwpixel(x,y,poll)>0 then vwpixel(x,y,flip):player1x=0:player1y=0:AUDC0=y:y=20:AUDF0=4:AUDV0=15  
6 rem if y<20 and vwpixel(x,y,poll)>0 then s=4


7 rem if BITIndex>71 then  
 
 if BITIndex<>72 then missile1x=missile1x+1:missile1y=missile1y+3:goto 8
  BITIndex=0
 rem --- make it easier if difficulty is selected (extra 8 passes)
 rem if player0y<90 then player0y=player0y-2 else player0y=player0y-1
 rem -- allow left difficulty to grant several extra orbits at the beginning if set to B (beginner)!
 if SWCHB & %01000000 = 0 and player0y>89 then  player0y=player0y-1 else player0y=player0y-2

 rem if u = 0 and player0y>88 then  player0y=player0y-1 else player0y=player0y-2

 rem 8 if CXP0FB>126 or player0y=1 then CXCLR=0:g=2:for i=0 to 255:AUDF0=i:AUDV0=i:next i:BYTErowoffset=0:py=player0y:gosub setmsg else missile0y=missile0y+2
8 if CXP0FB=130 then CXCLR=0:g=2:py=player0y:gosub setmsg else missile0y=missile0y+2
 return



linkplayer
 if u=0 then player0y=player0y+2 else player0y=player0y-1
 if player0y>96 then u=1
 if player0y<8 then u=0
 if px=0 then player0x=player0x+2 else player0x=player0x-1
 if player0x>140 then px=1:REFP0=255:return
 if player0x<8 then px=0:REFP0=0:return

 player1x=player1x+1:player1y=player1y+2
 missile1y=missile1y+3:missile1x=missile1x+1
 missile0y=missile0y+2:missile0x=missile0x+1
 return

setmsg rem ---- init score msg based on position
 m=0:bx=0
 rem -- superfluous, already 0! if py >=53 then m=0

 if py =<52 then m=60
 if py <=36 then m=120
 if py <3 then var2=1:m=0 

 rem gosub setmsg2
 rem if m=0 then j=32 else j=m
 rem for i=0 to 9:rowcolors(i)=j+i:next i
 NUSIZ0=%11111111

 return

colorizeplayer for i=0 to 7:player0colors(i)=player0colors(i)+16:next i:return



19 rem ---KITCHENSINK subroutine, runs when scrollvirtualworldtoggle=1
 if g=2 then gosub drawlettersonscreen

 if SWCHB|%11111101=255 then goto skipselect
 px=1-px:rem toggle cycle colors
skipselect
 
 if px=0 then goto skip_cyclecolors
 for i=0 to 9
 
 rem 20191124 PAL demo locking out black rows
 rem rowcolors(i)=rowcolors(i)+16
 j=rowcolors(i)+16
 if i<32 or i>224 then i=168
 rowcolors(i)=j
 next i

skip_cyclecolors



 rem old NTSC
 rem player0colors $3c,$3c,$3a,$3a,$38,$38,$36,$36
 rem rowcolors $72,$62,$52,$54,$56,$46,$44,$42,$42,$46,$44

 rem dimmer PAL
player0colors $a4,$a6,$a8,$a8,$a6,$a4,$a2,$b4
 rem rowcolors $72,$52,$32,$72,$54,$34,$74,$76,$78,$76,$74


 rem PAL [brighter]
 rem player0colors $a4,$a6,$a8,$a8,$a6,$a4,$b4,$b4
 rem rowcolors $54,$34,$74,$74,$56,$36,$76,$96,$94,$b4
rowcolors $72,$54,$34,$74,$54,$34,$74,$76,$78,$76,$74



 rem player0colors 100,255,100,100,200,200,200,200
 rem rowcolors 30,30,30,30,30,30,30,30,70,30

virtualworld
.......................................................................xxxx.................
......................................................................x..x..................
.......................................................................xxxx.................
......................................................................x..x..................
.......................................................................xxxx.................
......................................................................x..x..................
.......................................................................xxxx.................
......................................................................x..x..................
.......................................................................xxxx.................
......................................................................x..x..................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
.......................................................................xxxx.................
......................................................................x..x..................

sprites
........
........
.XXXXXX.
.X....X.
xXXXXXX.
XX....X.
XX....X.
XX....X.

........
........
XXXXXX..
XX...X..
XXXXXXX.
XX....X.
XX....X.
XXXXXXX.

........
........
XXXXXX..
X...XX..
X.......
X.......
X....X..
XXXXXX..

........
........
XXXXXX..
XX....X.
XX....X.
XX....X.
XX....X.
XXXXXX..

........
........
XXXXXXX.
X.......
XXXXXXX.
XX......
XX......
XXXXXXX.

........
........
.XXXXXX.
.XX.....
.XXXXXX.
..X.....
..X.....
..X.....

........
........
XXXXXXX.
XX...XX.
XX......
XX...XX.
XX....X.
XXXXXXX.

........
........
X.....X.
X.....X.
XXXXXXX.
XX....X.
XX....X.
XX....X.

........
........
...XX...
...XX...
...XX...
..XXX...
..XXX...
..XXX...

........
........
.....X..
.....X..
.....X..
.....XX.
XX...XX.
XXXXXXX.

........
........
X..X....
X.X.....
XXXXXX..
XX..XX..
XX..XX..
XX..XX..

........
........
.X......
.X......
.X......
XX......
XX......
XXXXXX..

........
........
XXX.XXX.
X..X.XX.
X....XX.
X....XX.
X.XX.XX.
X.XX.XX.

........
........
XX....X.
X.X...X.
X..X..X.
X...X.X.
X.X..XX.
X.XX..X.

........
........
XXXXXXX.
X.....X.
X....XX.
X....XX.
X....XX.
XXXXXXX.

........
........
XXXXXXX.
X.....X.
XXXXXXX.
XX......
XX......
XX......

........
........
XXXXXXX.
X.....X.
XX....X.
XX....X.
XX..X.X.
XXXXXXX.

........
........
XXXXXx..
X....X..
XXXXXX..
XX...XX.
XX...XX.
XX...XX.

........
........
XXXXXXX.
X.......
XXXXXXX.
......X.
XX....X.
XXXXXXX.

........
........
XXXXXXX.
...XX...
...XX...
...XX...
...XX...
...XX...

........
........
X....XX.
X....XX.
X....XX.
X....XX.
X....XX.
XXXXXXX.

........
........
X....XX.
X....XX.
X....XX.
X....XX.
.X...X..
..XXX...


........
........
XX.XX.X.
XX.XX.X.
XX....X.
XX.X..X.
XXX.X.X.
XX...XX.


........
........
XX...XX.
.XX.XX..
..XXX...
..XXX...
.XX.XX..
XX...XX.

........
........
X.....X.
X.....X.
.X...X..
..XXX...
..XXX...
..XXX...

........
........
XXXXXXX.
X...XX..
...XX...
..XX....
.XX..XX.
XXXXXXX.

........
........
.XXXXXX.
......X.
.XXXXXX.
.X......
.X......
.XXXXXX.

........
........
.XXXXX..
.....X..
.XXXXXX.
.....XX.
.....XX.
.XXXXXX.

........
........
XX......
XX......
XX......
XX...XX.
XXXXXXX.
.....XX.

........
........
XXXXXX..
X....X..
X.......
XXXXXXX.
X.....X.
XXXXXXX.

........
........
XXXXXXX.
XX...X..
....X...
...X....
...X....
...X....

........
........
XXXXXXX.
X....XX.
XXXXXXX.
.....XX.
.....XX.
.....XX.


chiptunes
4,19,4,19,8
4,17,4,17,8
4,15,4,15,8
4,14,4,14,16
4,19,4,19,8
4,14,4,14,16
4,19,4,19,8
4,14,4,14,16
4,19,4,19,8
4,14,4,14,8
4,14,4,14,8
4,15,4,15,8
4,17,4,17,8
4,19,4,19,16
4,26,4,26,8
4,19,4,19,16
4,26,4,26,8 
4,19,4,19,16
4,26,4,26,8
4,19,4,19,8
4,19,4,19,8
4,17,4,17,8
4,15,4,15,8
4,14,4,9,32
0,0,0,0,48
6,30,6,30,8
6,27,6,27,8
6,24,6,24,8
6,22,6,22,8
6,30,6,30,16
6,22,6,22,8
6,30,6,30,16
6,22,6,22,8
6,30,6,30,16
6,22,6,22,8
6,22,6,22,8
6,24,6,24,8
6,27,6,27,8
6,30,6,30,8   
1,5,1,5,16
6,30,6,30,8   
1,5,1,5,16
6,30,6,30,8   
1,5,1,5,16
6,30,6,30,8
1,5,1,5,16
0,0,0,0,64
0,0,0,0,0
7,30,7,30,24
7,24,7,24,24
0,0,0,0,0                                        
