# Menu of favorite games
# Jerry Stratton hoboes.com/coco
// superbasic Personal/menu.txt > Personal/MENU.BAS
// superbasic --switch speech Personal/menu.txt > Utilities/AUTOEXEC.BAS
// other switches: christmas, fourth
clear 500
cls

%screenCount% = !DATASETS%

// SECTION TITLE,sectionTitle
// Game Title, location, filename or flash/slot number, filetype
// location=flash, mpi, or disk

# Flash RAM and MPI programs
data maxlines 13
	Radio Shack Carts,sectionTitle
	Multipak Slot 1, mpi, 1
	Multipak Slot 2, mpi, 2
	Multipak Slot 3, mpi, 3
	Space Assault, flash, 1
	Downland, flash, 2
	Canyon Climber, flash, 5
	Checkers, flash, 3
	Dungeons of Daggorath, flash, 6
	Galactic Attack, flash, 4
	Pooyan,cool,POOYAN,1
	Stellar Lifeline, flash, 7
enddata

#IFDEF christmas
	# Christmas Programs
	data maxlines 13
		Merry Christmas!,sectionTitle
		Christmas Star,holidays,XMASSTAR,0
		Do You Hear?,holidays,XMASSONG,0
		Holiday Hearth,holidays,XMASFIRE,0
		Santa's Mission,holidays,SANTA,0
		Seasons Greetings,holidays,GREETING,0
		Winter Wonderland I,rain84,WINTERW,0
		Winter Wonderland II,holidays,WINTER,0
	enddata
#ENDIFDEF

#IFDEF fourth
	# Patriotic Programs
	data maxlines 13
		God Bless America!,sectionTitle
		American Flag,rain87,FLAG,0
		Fourth Celebration,rain84b,FOURTH,0
		Patriotic Songs,holidays,USSONGS,0
		Star-Spangled Banner,holidays,SSBANNER,0
	enddata
#ENDIFDEF

# cool disk games
data maxlines 13
	Rainbow Games,sectionTitle
	Balloon Attack,cool,BALLOON,1
	Bats -n- Bugs,rain84b,BATSBUGS,0
	Bee Zapper,rain87,BEEZAP,0
	Cavern Copter,rain84,CCOPTER,0
	Defend the Bridge,rain86,MORTAR,0
	Eye of the Tiger,cool,BOXING,0
	Gopher It,rain86,GOPHERIT,0
	Laser Evictor,cool,EVICTOR,0
	Parachute Mission,rain87,PARAMISS,0
	Robo Flip,rain87,ROBOFLIP,0
	Super Rooter,cool,ROOTER,1
	Vicious Vic,cool,VICIOUS,0
enddata

# arcade copies
data maxlines 13
	Arcade Copies,sectionTitle
	Pill Pac'em,rain84,PACEM,0
	Q-Nerd!,rain84,QNERD,0
enddata

# games written in modern era
data maxlines 13
	Modern Retro & Others,sectionTitle
	Ladderman II,ladder2,LADDER2,0
	Nightmare Highway,highway,HW,0
	Rally-SG,cool,RALLYSG,1
	//puzzles and games
	Color Code,hotcoco,COLRCODE,0
	Concentration,rain87,MEMOCARD,0
	Jungle Journey,rain84b,JUNGLE,0
	Knight's Tour,hotcoco,KNGHTOUR,0
	Solitaire,cool,SOLTAIRE,0
	Victorian Pegs,hotcoco,PEGS,0
	//less cool games
	Barrel Run,hotcoco,BARELRUN,0
	Gone Fishing,rain84,FISHING,0
	Runner,rain84,RUNNER,1
enddata

# gambling going on here!
data maxlines 13
	Gambling,sectionTitle
	Blackjack 84,rain84,BLACKJAK,0
	Blackjack 87,rain87,BLAKJACK,0
	CoCo Casino Craps,rain84,CRAPS,0
	Five Card CoCo,hotcoco,FIVECARD,0
	Day at the Races,rain84,RACEDAY,0
	Roulette,rain84,ROULETTE,0
	Home Slot Machine,rain84,HOMESLOT,0
enddata

# space games
data maxlines 13
	Space,sectionTitle
	Astronaut Rescue,rain87,RESCUE,0
	Lunar Lander,cool,LANDER,0
	Munchkin Blaster,rain87,BLASTER,0
	Space Hawks,hotcoco,HAWKS,1
	Space Raid,rain86,RAID,0
	Star Lord,cool,STARLORD,1
	Stunt Pilot,rain84,STUNTPLT,0
enddata

# Hartnell games, mostly
data maxlines 13
	Text-based Games,sectionTitle
	Chairman of the Board,hartnell,CHAIRMAN,0
	Chess,hartnell,CHESS,0
	Duke of Dragonfear,hartnell,DRAGONFR,0
	Dwarven Gold,hartnell,DWARVEN,0
	Eliza,hartnell,ELIZA,0
	Hunt the Wumpus,ahl,CWUMPUS,0
	Knightsbridge,hartnell,KNIGHTS,0
	Mistress of Xenophobia,hartnell,MISSXENO,0
	Reversi,hartnell,REVERSI,0
	Shadow Thieves,hartnell,SHADOWS,0
enddata

# Text and almost text adventures
data maxlines 13
	Adventures,sectionTitle
	The Bannochburn Legacy,hartnell,BANNOCH,0
	Binary Adventure,cool,BINARY,0
	Chateau Gaillard,hartnell,CHATEAU,0
	Citadel of Pershu,hartnell,PERSHU,0
	The Coco Zone,cocozone,BOOT,0
	The Crown of Merro,rain84,MERRO,0
	Graphics Adventure,rain84,GRPHVNTR,0
	Hogs in Space,hogs,HOGSPACE,0
	Le Lutin,rain87,LE LUTIN,0
	Princess and Witch,baker,PUZZLE,0
	Werewolves & Wanderer,hartnell,WEREWOLF,0
	Where's Tom Sawyer,hotcoco,SAWYER,0
enddata

# One-liners and two-liners
data maxlines 13
	Shorties,sectionTitle
	Arrow Catcher,rain86,ARROWS,0
	Backstabber,cool,BACKSTAB,0
	Gravity Skier,rain87,GSKI,0
	Hand Off,rain87,HAND OFF,0
	Horse Race,rain86,HORSES,0
	Night Strike,rain86,NITSTRIK,0
	Pop the Balloons,rain86,BALLOONS,0
	Radar Treasure,rain87,TREASURE,0
	Rotations,rain87,ROTATION,0
	Ski Racer,cool,SKIRACER,0
	//longer shorties
	Blue Block Blues,rain87,BLUEBLCK,0
	Speedster,rain87,SPEEDSTR,0
enddata

#graphics
data maxlines 13
	Graphics,sectionTitle
	Biorhythms,utility,biorhyth,0
	CoCoDraw,editors,COCODRAW,0
	Color-O-Scope,rain84,COSCOPE,0
	Create-a-Face,hotcoco,CREATFAC,0
	Devil Bird,hotcoco,DEVLBIRD,0
	Dripping Faucet,rain87,FAUCET,0
	The Flying Walloons,rugg,WALLOONS,0
	GraphIt,rain87,GRAPHIT,0
	Kaleidoscope,rain86,KALEIDO,0
	Maze Maker,hotcoco,MAZEMAKR,0
	Paint King,hotcoco,PAINTKNG,0
	Trigonometry,rain87,TRIG,0
enddata

#sound
data maxlines 13
	Sound,sectionTitle
	Music+,rain84,MUSIC+,0
	Piano,editors,PIANO,0
	Rockfest,rain84,ROCKFEST,0
	Singing with Bird,rain87,YARDBIRD,0
	Sound Processor,editors,SOUNDP,0
	Talking CoCo Cathead,rain87,CATHEAD,0
enddata

# utilities
data maxlines 13
	Utilities,sectionTitle
	Clock,utility,CLOCK,0
	CoCo Calculator,utility,COCOCALC,0
	HomeSpread,hotcoco,HOMESPRD,0
	MoCalc,rain84,MOCALC,0
	Keyboard & Joystick Test,utility,INPUTS,0
	Keytone,hotcoco,KEYTONE,1
	Read Program,utility,READPROG,0
	SDCard Explorer,utility,SDCX,0
enddata

#end of all data
data
	XSTOPX
enddata

#IFDEF speech
	#INCLUDE speech.bas
	%speech$ = "Greetings, Professor."
	gosub speakSpeech
#ENDIFDEF

gosub getGameScreens
%currentScreen% = 1

#IFDEF speech
	%speech$ = "Shall we play a gayme?"
	gosub speakSpeech
#ENDIFDEF

loop
	cls
	%nextScreen% = %currentScreen%+1
	if %nextScreen% > %screenCount% then %nextScreen% = 1
	%nextScreen$ = %screenTitles$(%nextScreen%)
	gosub displayGames
endloop

sub displayGames
	%centering% = int((32-len(%screenTitles$(%currentScreen%)))/2)
	print@%centering%,%screenTitles$(%currentScreen%);

	%itemCount% = %gameCounts%(%currentScreen%)
	if (%itemCount% > 14) then
		%displayOffset% = 0
	else
		%displayOffset% = 1
	endif

	for %item%=1 to %itemCount%
		%title$ = %titles$(%currentScreen%,%item%-1)
		%displayLine% = %item% + %displayOffset%
		gosub displayItem
	next %item%

	%nextBlurb$ = "\^Lclear\^Q for " + %nextScreen$
	%centering% = int((32-len(%nextBlurb$))/2)
	print@(15*32)+%centering%,%nextBlurb$;

	gosub userChoice

	#clear switches screens
	switch
	case (chr$(12)=%choice$)
		%currentScreen%=%nextScreen%
		return
	case (chr$(92)=%choice$)
		%currentScreen%--
		if %currentScreen% < 1 then %currentScreen% = %screenCount%
		return
	endswitch

	%location$ = %locations$(%currentScreen%,%choice%-1)
	%filename$ = %filenames$(%currentScreen%,%choice%-1)

	switch
	case (%location$="mpi")
		%slot% = val(%filename$)
		gosub runFromMPI
		break
	case (%location$="flash")
		%slot% = val(%filename$)
		gosub runFromFlash
		break
	case (default)
		%filetype% = %filetypes%(%currentScreen%,%choice%-1)
		gosub runFromDisk
	endswitch
endsub

sub runFromDisk
	if %location$ = "utility" then %drive%=1 else %drive%=0
	drive %drive%, %location$ + ".dsk"
	drive %drive%

	#BASIC code
	if %filetype%=0 then load %filename$,r

	#Binary code
	cls
	print "Type \^Lexec\^Q and press \^Lenter\^Q"
	print "Ignore any errors"

	loadm %filename$
	exec
	new
endsub

sub runFromMPI
	#IFDEF speech
		gosub disableSpeech
	#ENDIFDEF

	poke 65407,(%slot%-1)*17
	exec &HC000
endsub

sub runFromFlash
	run@%slot%
endsub

sub displayItem
	print@(%displayLine%)*32+3,"";
	print using "## ";%item%;
	print %title$;
endsub

sub userChoice
	#need to read joystick a few times to get it to work
	gosub readStickVertical
	gosub readStickVertical

	%choice%=int(%itemCount%/2)

	loop
		#mark current choice
		print@(%choice%+%displayOffset%)*32+5,">";
		print@(%choice%+%displayOffset%)*32+31,"<";

		loop
			#check joystick button
			%stickButton%=peek(65280)
			if %stickButton%=125 or %stickButton%=126 or %stickButton%=253 or %stickButton%=254 then return

			#check user input
			%newChoice%=0
			%choice$=inkey$
			
			switch
			case (%choice$="")
				gosub readStickVertical
				break
			case (%choice$="^" and %choice%>1)
				%newChoice%=%choice%-1
				break
			case (asc(%choice$)=10 and %choice%<%itemCount%)
				%newChoice%=%choice%+1
				break
			case (asc(%choice$)=95)
				%newChoice%=1
				break
			case (asc(%choice$)=91)
				%newChoice%=%itemCount%
				break
			case (%choice$>="1" and %choice$<="9" and val(%choice$)<=%itemCount%)
				%newChoice%=val(%choice$)
				break
			case (%choice$="0" and %itemCount%>9)
				%newChoice%=10
				break
			case (%choice$=":" and %itemCount%>10)
				%newChoice%=11
				break
			case (%choice$="-" and %itemCount%>11)
				%newChoice%=12
				break
			//13=ENTER 12=CLEAR 92=SHIFT-CLEAR
			case (asc(%choice$)=13 or asc(%choice$)=12 or asc(%choice$)=92)
				return
			endswitch
		endloop unless (%newChoice%=0 or %newChoice%=%choice%)

		#clear previous choice
		print@(%choice%+%displayOffset%)*32+5," ";
		print@(%choice%+%displayOffset%)*32+31," ";
		%choice%=%newChoice%
	endloop
endsub

sub readStickVertical
	#enable joysticks
	k=joystk(0)
	for k=1 to 50:next k

	switch
	case (%rightStickVertical%<>joystk(1))
		%rightStickVertical%=joystk(1)
		%stickValue%=%rightStickVertical%
		break
	case (%leftStickVertical%<>joystk(3))
		%leftStickVertical%=joystk(3)
		%stickValue%=%leftStickVertical%
		break
	case (default)
		return
	endswitch

	#convert stick value to item
	%newChoice%=int(%stickValue%/(63/%itemCount%))
endsub

sub getGameScreens
	#initialize screen arrays
	dim %screenTitles$(%screenCount%)
	dim %gameCounts%(%screenCount%)
	dim %titles$(%screenCount%, 12)
	dim %locations$(%screenCount%, 12)
	dim %filenames$(%screenCount%, 12)
	dim %filetypes%(%screenCount%,12)

	#read screens
	restore
	loop
		read %title$
		break if (%title$ = "XSTOPX")
		read %location$
		switch
		case (%location$="sectionTitle")
			%gameCounts%(%currentScreen%)=%currentGame%
			%currentScreen%++
			%currentGame%=0
			%screenTitles$(%currentScreen%) = %title$
			break
		case (%location$="flash" or %location$="mpi")
			read %filename$
		case (%location$<>"flash" and %location$<>"mpi")
			read %filename$, %filetype%
			%filetypes%(%currentScreen%, %currentGame%) = %filetype%
		case (default)
			%titles$(%currentScreen%, %currentGame%) = %title$
			%locations$(%currentScreen%, %currentGame%) = %location$
			%filenames$(%currentScreen%, %currentGame%) = %filename$
			%currentGame%++
		endswitch
	endloop
	%gameCounts%(%currentScreen%)=%currentGame%
endsub
