*****************************************************************************
*                                                                           * 
*           __ __   __                   __ __ __                           *
*          / // /  / /                  / //_// /__                         *
*         / // /  / /______ ______ ____/ /__ / // / ___                     *
*        / _  |  / // __  // __  // __  // // _  / / o \                    *
*       / / | | / // /_/ // / / // /_/ // // /| | / ___/                    *
*      /_/  |_|/_//_____//_/ /_//_____//_//_/ |_| \____/   Version 1.3      *
*                                                                           *
*                                                                           * 
*  You may modify this source code for personal use ONLY ! You must NOT     *
*  distribute modified versions of Klondike without my written permission.  *
*                                                                           *
*  If any major alterations are made to this code then please send a copy   *
*  of the new source to the author, Peter Wiseman at :                      *
*                                                                           * 
*  30 Coronation Drive, Penketh, Warrington, Cheshire, WA5 2DD, ENGLAND     *
*                                                                           * 
*  and I'll consider releasing the mods (with credit) in a future version.  *
*                                                                           *
*                                                    (Pete 9th Sept 1992)   *
*                                                                           *
*****************************************************************************



** This source was written for use with the Hisoft Devpac assembler **


** Modified 3/8/90 to V1.1 to cope with FastMem **

** Modified 31/3/91 to V1.1b to enable it to run without extra commands in
** the C directory. Number of games played and reset hi-scores also added.
** In V1.1 you could place a column of cards on the foundations - this
** bug has been removed in V1.1b **	

** Modified yet again April 1991 to V1.2 : Merge Hi-Scores & Help menu
** versions menu and all known bugs fixed
** New hi-score of 11449 to beat (Genuine - Honest !) **

** 24th September 1991 - V1.21 fixes a bug in V1.2
** Game End menu was being disabled when the menu bar was removed
** This caused the game to crash occasionally on completing the game

** 17th December 1991 - Jerky card movement with my GVP hard drive !
** The old "flyback" routine has now been altered to use the system
** routine WaitBOVP and this has fixed the problem (V1.22)

** 3rd September 1992 - V1.3 card graphics menus added & a bug fixed **


	incdir ":include/"

	include "exec/exec_lib.i"
	include "intuition/intuition_lib.i"
	include "libraries/dos_lib.i"
	include "graphics/graphics_lib.i"
	include "libraries/dosextens.i"
	include "libraries/dos.i"
	include "workbench/startup.i"

snd0		equ 128		* ( Pointers )
snd1		equ 4840
snd2		equ 5078
snd3		equ 1210
snd4		equ 2550
snd5		equ 19656
soundsize	equ snd0+snd1+snd2+snd3+snd4+snd5
cardmem		equ 8*46*3*56
tablemem	equ 64*10
hiscrsize	equ 500
down 		equ 20
cardx		equ 33		
cardy		equ 140
maxscrheight	equ 258		* display size
deck1x		equ 244		* x position of face down deck
deck2x		equ 318		* x position of face up deck
foundx1		equ 79		* x position of 1st foundation card
foundx2		equ 441		* x position of 3rd foundation card
gap2		equ 11		* pixels between deck face up cards
maxplane	equ (17*7+56)*10	* (17*gap+56)*10
maxname		equ 16		* Maximum number of letters for graphics filenames

	move.l a7,stack
	sub.l a1,a1
	CALLEXEC FindTask
	move.l d0,a4
	tst.l pr_CLI(a4)
	bne CLI
	lea pr_MsgPort(a4),a0
	CALLEXEC WaitPort
	lea pr_MsgPort(a4),a0
	CALLEXEC GetMsg
	move.l d0,_WBenchMsg

** Open DOS library **

	move.l #dosname,a1
	clr.l d0
	CALLEXEC OpenLibrary
	tst.l d0
	beq end
	move.l d0,_DOSBase
	move.l _WBenchMsg,a2
	move.l sm_ArgList(a2),d0
	beq nodir
	move.l d0,a0
	move.l wa_Lock(a0),d1
	CALLDOS CurrentDir
nodir	bra nextlib

CLI	
** Open DOS library **

	move.l #dosname,a1
	clr.l d0
	CALLEXEC OpenLibrary
	tst.l d0
	beq end
	move.l d0,_DOSBase

nextlib

** Open Graphics library **

	move.l #grafname,a1
	clr.l d0
	CALLEXEC OpenLibrary
	tst.l d0
	beq closedos
	move.l d0,_GfxBase


** Open Intuition library **

	move.l #intname,a1
	clr.l d0
	CALLEXEC OpenLibrary
	tst.l d0
	beq closegraf
	move.l d0,_IntuitionBase

* Open audio device *

	move.l #device,a0
	move.l #iorequest,a1
	clr.l d1
	CALLEXEC OpenDevice
	tst.l d0
	bne closeint

** Find this task **

	sub.l a0,a0
	CALLEXEC FindTask
	move.l d0,task

** Allocate a signal bit **

	move.l #-1,d0
	CALLEXEC AllocSignal
	btst #7,d0
	bne closeaudio
	move.b d0,signal

** Open custom hi-res screen **

	move.l #newscreen,a0
	CALLINT OpenScreen
	tst.l d0
	beq freesignal
	move.l d0,screen
	move.l d0,a0	
	add.w #$2c,a0		* sc_Viewport
	move.l a0,viewport
	add.w #$b8-$2c,a0	* sc_Bitmap
	move.l a0,bitmap
	move.l (a0),bitmap2
	move.l 4(a0),bitmap2+4

	bsr setcols		* Blank out display


** Open a full screen size window **

	move.l #newwindow,a0
	CALLINT OpenWindow
	tst.l d0
	beq closescreen
	move.l d0,window
	move.l d0,a0
	move.l $32(a0),rastport
	move.l $56(a0),userport


** Allocate memory for 54 full size cards **

	move.l #cardmem,d0
	move.l #$10003,d1
	CALLEXEC AllocMem
	tst.l d0
	beq closewindow
	move.l d0,cardmemory
	add.l #46*8*3*54,d0
	move.l d0,cardmask
	add.l #46*8,d0
	move.l d0,cardmask2

** Allocate memory for card table **

	move.l #tablemem,d0
	move.l #65537,d1
	CALLEXEC AllocMem
	tst.l d0
	beq freecardmem
	move.l d0,tablememory

** Allocate memory for move card graphics **

	move.l #maxplane*4,d0
	move.l #$10002,d1
	CALLEXEC AllocMem
	tst.l d0
	beq freetablemem
	move.l d0,movememory

** Allocate memory for tempory 3 bitplane screen **

	move.l #bitmap2+8,a5
	move.w #2,d7
nextrast move.l #80*maxscrheight,d0
	move.l #$10002,d1
	CALLEXEC AllocMem
	tst.l d0
	beq freerastermem
	move.l d0,(a5)+
	dbf d7,nextrast

** Allocate memory for hi-scores **

	move.l #hiscrsize,d0
	move.l #$10000,d1
	CALLEXEC AllocMem
	tst.l d0
	beq freerastermem
	move.l d0,himem

** Allocate memory for 2nd rastport **

	move.l #100,d0
	move.l #$10002,d1
	CALLEXEC AllocMem
	tst.l d0
	beq freehimem
	move.l d0,rastport2
	move.l d0,a1
	CALLGRAF InitRastPort
	move.l rastport2,a0
	move.l #bitmap2,4(a0)

** Allocate memory for sounds **

	move.l #soundsize,d0
	move.l #$10002,d1
	CALLEXEC AllocMem
	tst.l d0
	beq freerastport
	move.l d0,soundmem

** Load sounds file onto custom screen **

	bsr loadsounds
	tst.l d0
	bne freesoundmem

	bsr loadscores
	move.l screen,a0
	CALLINT ScreenToFront

** Search for card graphics and create submenus for them **

	bsr graphicsmenus
	tst.l d7
	beq freesoundmem

	bsr cls
	bsr setupgfx
	tst.l d0
	beq freesoundmem

	move.l himem,a4
	btst.b #1,270(a4)
	bne setNTSC
	move.w #ITEMTEXT+HIGHCOMP+ITEMENABLED+CHECKIT+CHECKED,opt1
	move.w #ITEMTEXT+HIGHCOMP+ITEMENABLED+CHECKIT,opt2
	bra donePAL
setNTSC	move.w #ITEMTEXT+HIGHCOMP+ITEMENABLED+CHECKIT+CHECKED,opt2
	move.w #ITEMTEXT+HIGHCOMP+ITEMENABLED+CHECKIT,opt1
donePAL	btst.b #0,270(a4)
	bne bnw2
	bsr setcols
	move.w #ITEMTEXT+HIGHCOMP+ITEMENABLED+CHECKIT+CHECKED,opt3
	move.w #ITEMTEXT+HIGHCOMP+ITEMENABLED+CHECKIT,opt4
	bra fullcol
bnw2	move.l #cols2,a1
	bsr setbnw
	move.w #ITEMTEXT+HIGHCOMP+ITEMENABLED+CHECKIT+CHECKED,opt4
	move.w #ITEMTEXT+HIGHCOMP+ITEMENABLED+CHECKIT,opt3

fullcol	move.w 270(a4),oldstatus
	bsr setmonitor
	
	bsr pointcols
	bsr pointer1	
	move.l window,a0
	move.l #klondike,a1
	CALLINT SetMenuStrip
	bra dontdoscoresagain

****** E V E R Y   E N D   O F   G A M E ******

beginning bsr printhiscores
dontdoscoresagain move.l window,a0
	move.w #33,d0
	CALLINT OffMenu		* "End game"

	move.l window,a0
	move.w #1,d0
	CALLINT OnMenu		* "New game"	

	move.l window,a0
	move.w #$02,d0
	CALLINT OnMenu		* "PAL"

	move.l window,a0
	move.w #$22,d0
	CALLINT OnMenu		* "NTSC"

	move.l window,a0
	move.w #$f882,d0
	CALLINT OnMenu		* "Face Graphics"

	move.l window,a0
	move.w #$f8a2,d0
	CALLINT OnMenu		* "Back Graphics"

	move.l window,a0
	move.w #$f8c2,d0
	CALLINT OnMenu		* "Symbols Graphics"

	move.l window,a0
	move.w #$e2,d0
	CALLINT OnMenu		* "Merge Hi-Scores"

	move.l window,a0
	move.w #$f902,d0
	CALLINT OnMenu		* "Reset Scores"


menuwait bsr testmenus
	bra menuwait

testmenus move.l userport,a0
	CALLEXEC GetMsg	
	tst.l d0
	bne gotmsg
return	rts	
gotmsg	move.l d0,a1
	move.l $14(a1),d4
	move.w $18(a1),d5
	CALLEXEC ReplyMsg
	cmp.w #$0100,d4	* MENUPICK
	bne return
	cmp.w #$ffff,d5	* MENUNULL
	beq return
	move.w d5,d6
	and.w #$7ff,d5
	cmp.w #$60,d5
	beq quit
	cmp.w #$20,d5
	beq versions
	cmp.w #$40,d5
	beq credits
	cmp.w #1,d5
	beq newgame
	cmp.w #$21,d5
	beq endgame
	cmp.w #$02,d5
	beq doPAL
	cmp.w #$22,d5
	beq doNTSC
	cmp.w #$62,d5
	beq bnw
	cmp.w #$42,d5
	beq colour
	cmp.w #$e2,d5
	beq mergethem
	cmp.w #$102,d5
	beq resetscores
	cmp.w #$03,d5
	beq dohelp1
	cmp.w #$23,d5
	beq dohelp2
	cmp.w #$43,d5
	beq dohelp3
	cmp.w #$63,d5
	beq dohelp4
	cmp.w #$82,d5
	beq dofaces
	cmp.w #$a2,d5
	beq dobacks
	cmp.w #$c2,d5
	beq dosymbols
	tst.w d5
	beq doabout

	rts

dofaces	move.w #278,d0
	bra transf
dobacks	move.w #311,d0
	bra transf
dosymbols move.w #344,d0

transf	move.l himem,a5
	add.w d0,a5

	clr.l d0
	move.w d6,d0
	move.l #klondike,a0
	CALLINT ItemAddress

	move.l d0,a0
	move.l 18(a0),a0
	move.l 12(a0),a0
	add.w #2,a0
bungin	move.b (a0)+,(a5)+
	bne bungin

	bsr setupgfx

	move.l himem,a0
	btst.b #0,270(a0)
	bne blacky
	bsr setcols

blacky	rts

dohelp1	move.l #helptext1,a5
	bsr page
	bsr remove
	rts

dohelp2	move.l #helptext2,a5
	bsr page
	bsr remove
	rts

dohelp3	move.l #helptext3,a5
	bsr page
	bsr remove
	rts

dohelp4 move.l #helptext4,a5
	bsr page
	bsr remove
	rts

versions move.l #versionstext,a5
	bsr page
	bsr remove
	rts

credits move.l #creditstext,a5
	bsr page
	bsr remove
	rts

doabout move.l #abouttext,a5
	bsr page
	bsr remove
	rts

bnw	bsr remove
	move.l himem,a0
	bset.b #0,270(a0)
	move.l #cols2,a1
	bsr setbnw
	rts

colour	bsr remove
	move.l himem,a0
	bclr.b #0,270(a0)
	bsr setcols
	rts

doPAL	bsr remove
	move.l himem,a0
	bclr.b #1,270(a0)
	bsr setmonitor
	rts

doNTSC	bsr remove
	move.l himem,a0
	bset.b #1,270(a0)
	bsr setmonitor
	rts

mergethem bsr mergescores
	rts

resetscores bsr newscores
	bsr printhiscores
	bsr savescores
	rts 

quit	bsr remove
	move.l stack,a7
	bra quitgame
newgame	move.l window,a0
	move.w #1,d0
	CALLINT OffMenu		* "New game"	
	move.l window,a0	
	move.l window,a0
	move.w #$02,d0
	CALLINT OffMenu		* "PAL"
	move.l window,a0
	move.w #$22,d0
	CALLINT OffMenu		* "NTSC"
	move.l window,a0
	move.w #$f882,d0
	CALLINT OffMenu		* "Face Graphics"
	move.l window,a0
	move.w #$f8a2,d0
	CALLINT OffMenu		* "Back Graphics"
	move.l window,a0
	move.w #$f8c2,d0
	CALLINT OffMenu		* "Symbols Graphics"
	move.l window,a0
	move.w #$e2,d0
	CALLINT OffMenu		* "Merge Hi-Scores"
	move.l window,a0
	move.w #$f902,d0
	CALLINT OffMenu		* "Reset Scores"
	move.l window,a0
	move.w #33,d0
	CALLINT OnMenu		* "End game"
	bsr remove
	move.l window,a0
	CALLINT ClearMenuStrip
	add.w #4,a7
	bra start
endgame	move.l window,a0
	move.w #33,d0
	CALLINT OffMenu		* "End game"
	bsr remove
	add.w #4,a7
	bra enditnow

remove	move.l userport,a0
	CALLEXEC GetMsg	
	tst.l d0
	bne yes
	rts
yes	move.l d0,a1
	CALLEXEC ReplyMsg
	bra remove

********* E V E R Y   N E W   G A M E *********

start	

again	bsr cls		* clear screen

	clr.w score
	move.w #-3,firstpass	* Decrease score after 3 passes
	bsr printscore

	bsr setup	* set up the screen & card table	

	move.l #seconds,a0
	move.l #micros,a1
	CALLINT CurrentTime
	move.l seconds,oldsecs
	move.l seconds,firsttime

bloop	move.l window,a0
	move.l #klondike,a1
	CALLINT SetMenuStrip

	bsr clear	* clear select bits

	bsr select	* set select bits on cards that can be moved
yak	bsr testmenus
	move.l #seconds,a0
	move.l #micros,a1
	CALLINT CurrentTime
	move.l seconds,d0
	sub.l oldsecs,d0
	bcc notnegs
	neg.l d0
notnegs move.w score,d2
	sub.w d0,d2
	cmp.w #-30000,d2
	ble nosub2
	move.w d2,score
nosub2	move.l seconds,oldsecs
nottime	move.w score,d0
	cmp.w oldscore,d0
	beq notchanged
	bsr printscore
notchanged bsr checkselect	* see if mouse is over a select card	


mouse	andi.b #$40,$bfe001
	bne yak
	
	bsr checkselect
	cmp.l #0,a4
	beq yak

	move.l window,a0
	CALLINT ClearMenuStrip	

	cmp.b #8,4(a4)
	beq decker
	btst.b #0,7(a4)
	beq notfaced
	cmp.b #7,4(a4)
	bls intabby
	bra notfaced
	
	
** Clicked on deck - Turn over next 3 cards **

** Find number of face up deck cards **

decker	move.l tablememory,a0
	clr.w d6
	move.w #63,d1
loopy	cmp.b #9,4(a0)
	bne notdeckup
	cmp.b 5(a0),d6
	bhi notdeckup
	move.b 5(a0),d6
notdeckup add.w #10,a0
	dbf d1,loopy

	tst.b 5(a4)
	bne notturnup
	move.l tablememory,a0
	move.w #63,d0
	sub.l a1,a1
swapcard cmp.b #9,4(a0)
	bne notdecku
	move.b 5(a0),d1
	neg.b d1
	add.b d6,d1
	add.b #1,d1
	move.b d1,5(a0)
	move.w #deck1x,(a0)
	move.b #8,4(a0)
	move.w #1,6(a0)  
	move.l a0,a1

notdecku add.w #10,a0
	dbf d0,swapcard

	cmp.l #0,a1
	beq thatsallfolks
	bsr fromtable
	bsr drawcard

	add.w #1,firstpass
	bmi firstone
	cmp.w #-30000,score
	ble firstone
	sub.w #125,score		* Gone thru deck more than 3 times

** Clear the three face up deck cards from screen **

firstone move.w #deck2x,d0
	move.w foundy,d1
	bsr setupdraw
	and.w #$f000,d0
	add.w #$b0a,d0
	move.w d0,$040(a5)
	move.w #2,d0
	bsr drawplanes
	move.w #deck2x+gap2*2,d0
	move.w foundy,d1
	bsr setupdraw
	and.w #$f000,d0
	add.w #$b0a,d0
	move.w d0,$040(a5)
	move.w #2,d0
	bsr drawplanes
	bra thatsallfolks

notturnup bsr sound3
	move.w #deck2x+2*gap2,d7
	move.l a4,a1
	move.b 5(a4),d5

	move.w #2,d4
threecards move.w d7,(a1)
	move.w foundy,2(a1)
	move.b #9,4(a1)
	add.b #1,d6
	move.b d6,5(a1)
	clr.w 6(a1)

	bsr fromtable
	bsr flyback
	bsr flyback
	bsr drawcard
	
	subq #1,d5

** Find next card in deck **

	move.l tablememory,a1
	clr.w d0
loopy2	cmp.b #8,4(a1)
	bne notdeckdown
	cmp.b 5(a1),d5
	beq gotgot
notdeckdown add.w #10,a1
	bra loopy2

gotgot	sub.w #gap2,d7
	tst.b d5
	beq endofpile
	dbf d4,threecards

thatsallfolks andi.b #$40,$bfe001
	beq thatsallfolks
	bra bloop

endofpile bsr flyback 
	bsr fromtable
	bsr drawcard
	bsr sound1
	bra thatsallfolks

** The card clicked on is face down and in the tableau - turn it up **

intabby	bsr sound1
	bclr.b #0,7(a4)
	move.l a4,a1
	bsr fromtable
	bsr drawcard
mouseoff andi.b #$40,$bfe001
	beq mouseoff
	
	add.w #25,score		* face down card turned over

	bra bloop


notfaced bsr grabscreen
	bsr pointer2
	bsr gotcard
	bsr select2
	clr.l hilitecard	

mover	bsr newpos

	move.l himem,a4
	btst.b #1,270(a4)
	beq flyPAL
	move.w #70,d6
	move.w #200,d7
	bra fly
flyPAL	move.w #90,d6
	move.w #235,d7
fly	cmp.w newy,d6
	bhi waitforbot

** Wait for raster to reach bottom of ViewPort

	move.l viewport,a0
	CALLGRAF WaitBOVP

	bra gotflyback
waitforbot btst.b #1,270(a4)
	bne nochk
 	btst.b #0,$dff005
	bne gotflyback
nochk	cmp.b $dff006,d7
	bhi waitforbot
gotflyback bsr slaponcards
	bsr background
	bsr checkselect2

** Hilite the card if necessary **

	cmp.l #0,a4
	beq nohilite
	cmp.l hilitecard,a4
	beq alreadyhilited

	cmp.b #7,4(a4)
	bhi notintabl
	tst.b 5(a4)
	beq donthi

notintabl move.w (a4),d0
	move.w 2(a4),d1
	move.l cardmask,a0
	bsr setupdraw
	clr.w d0
	move.l #bitmap2+16,a1	
	bsr drawplanes
	cmp.b #9,4(a4)
	bls notgrey
	tst.b 5(a4)
	bne notgrey
	move.w (a4),d0
	move.w 2(a4),d1
	move.l cardmask,a0
	bsr setupdraw
	clr.w d0
	move.l #bitmap2+8,a1	
	bsr drawplanes
	move.l bitmap2+8,wherefrom
	move.l bitmap,a0
	move.l 8(a0),whereto
	bsr replacehi

notgrey	move.l bitmap2+16,wherefrom
	move.l bitmap,a0
	move.l 16(a0),whereto
	bsr replacehi

donthi	move.l hilitecard,d0
	move.l a4,hilitecard
	tst.l d0
	beq alreadyhilited
	move.l d0,a4
unhilite cmp.b #7,4(a4)
	bhi knot
	tst.b 5(a4)
	beq alreadyhilited

knot	move.l a4,a1
	bsr fromtable
	add.w #8*46*2,a0
	bsr setupdraw
	clr.w d0
	move.l #bitmap2+16,a1	
	bsr drawplanes
	cmp.b #9,4(a4)
	bls notgrey2
	tst.b 5(a4)
	bne notgrey2
	move.l a4,a1
	bsr fromtable
	bsr setupdraw
	clr.w d0
	move.l #bitmap2+8,a1	
	bsr drawplanes
	move.l bitmap2+8,wherefrom
	move.l bitmap,a0
	move.l 8(a0),whereto
	bsr replacehi
	

notgrey2 move.l bitmap2+16,wherefrom
	move.l bitmap,a0
	move.l 16(a0),whereto
	bsr replacehi
	bra alreadyhilited
	
nohilite tst.l hilitecard
	beq alreadyhilited
	move.l hilitecard,a4 
	clr.l hilitecard
	bra unhilite

alreadyhilited

	andi.b #$40,$bfe001
	beq mover
	
	bsr pointer1

	tst.l hilitecard
	bne shiftcol
	move.l movecard,a0
	move.w (a0),d0
	move.w 2(a0),d1
	bsr forcenewpos
	bsr slaponcards
	bsr background
	bra bloop

shiftcol bsr sound1 
	move.l hilitecard,a0
	move.l movecard,a1
	cmp.b #7,4(a0)
	bhi nottotableau	
	cmp.b #9,4(a1)
	bhi fromfoundations
	bne notfromdeck
	add.w #45,score		* From deck to tableau
	bra nosub
fromfoundations cmp.w #-30000,score
	ble notfromdeck
	sub.w #75,score
notfromdeck btst.b #4,7(a1)
	bne minusten
	btst.b #0,7(a0)
	beq nosub
minusten cmp.w #-30000,score
	ble nosub
	sub.w #25,score		* Single card from tableau to tableau
	bra nosub

nottotableau cmp.b #9,4(a1)
	bhi nosub 
	add.w #60,score	* Add card to foundations
nosub	move.w 2(a0),d7
	
ontotable move.b 5(a0),d6
	tst.b d6
	beq space
	cmp.b #9,4(a0)
	bhi space
	move.l a0,a1
	bsr fromtable
	bsr drawcard2
	move.l a1,a0
	add.w gapB,d7
	btst.b #0,7(a0)
	bne space
snotback move.l tablememory,a1
	subq #1,d6
	move.b 4(a0),d0
find1less cmp.b 4(a1),d0
	bne notcolly
	cmp.b 5(a1),d6
	beq got1less
notcolly add.w #10,a1
	bra find1less
got1less tst.b 5(a1)
	beq biggap 
	btst.b #0,7(a1)
	beq space
biggap	add.w #10,d7  
	sub.w gapB,d7

space	move.l movecard,a1
	move.b 5(a0),d6
	move.w (a0),d3
	move.b 4(a0),d2
	btst.b #0,7(a0)
	bne downmore
	tst.b d6
	bne shiftacard
downmore move.w d7,2(a1)
	add.w #10,d7
	bra yaka
shiftacard move.w d7,2(a1)
	add.w gapB,d7
yaka	move.b 4(a1),d4
	move.b 5(a1),d5
	addq #1,d5 
	move.w d3,(a1)
	move.b d2,4(a1)
	addq #1,d6
	move.b d6,5(a1)
	clr.w 6(a1)
	bsr fromtable
	bsr drawcard2	

	move.l tablememory,a1
	move.w #63,d0
find1more cmp.b 4(a1),d4
	bne notsamey
	cmp.b 5(a1),d5
	beq shiftacard
notsamey add.w #10,a1
	dbf d0,find1more

	bsr pushscreen

	move.l tablememory,a0
	move.w #63,d0
	clr.w d1
allthere cmp.b #9,4(a0)
	bls nojoy
	addq #1,d1
nojoy	add.w #10,a0
	dbf d0,allthere
	cmp.b #56,d1
	bne bloop


*** GAME COMPLETED ***

	move.l #seconds,a0
	move.l #micros,a1
	CALLINT CurrentTime
	move.l seconds,d6
	sub.l firsttime,d6
	bcc notnegs2
	neg.l d6
notnegs2 move.w score,d7
	bmi nobonus
	move.w d6,d0
	mulu.w #5,d0
	sub.w d0,d7
	bcs nobonus
	mulu.w #2,d7
	add.w d7,score
	bsr printscore
	bra boney
nobonus	clr.w d7
boney	move.w d6,d0
	move.l #time,a1
	bsr donumber2
	move.b #32,(a1)+
	move.b #115,(a1)+	* s
	move.b #101,(a1)+	* e
	move.b #99,(a1)+	* c
	move.b #115,(a1)+	* s
	clr.b (a1)
	move.l #welldone2,a0
	CALLINT IntuiTextLength
	move.w #fleft+127,d5
	sub.w d0,d5
	lsr.w #1,d5
	move.w d5,welldone2+4
	move.w d7,d0
	move.l #bonus,a1
	bsr donumber2
	clr.b (a1)
	move.l #welldone3,a0
	CALLINT IntuiTextLength
	move.w #fleft+127,d5
	sub.w d0,d5
	lsr.w #1,d5
	move.w d5,welldone3+4

	move.l #welldonereq,a0
	move.l window,a1
	CALLINT Request
	bsr cheers

mouseB	andi.b #$40,$bfe001
	bne mouseB

	move.l #welldonereq,a0
	move.l window,a1
	CALLINT EndRequest

	move.w #ITEMTEXT+HIGHCOMP,game2+12	* "End game" menu off

	move.l window,a0
	move.l #klondike,a1
	CALLINT SetMenuStrip

enditnow
	add.w #1,games
	move.l #lastscr2,a1
	move.w score,d0
	bsr donumber2
	clr.b (a1) 
	move.l himem,a0
	add.w #256,a0
	move.w #14,d7
onhigh	move.w score,d1
	cmp.w 12(a0),d1
	ble nowayhozay
	cmp.b #14,d7
	beq upaplace
	move.w #6,d1
downscore move.w (a0)+,16(a0)
	dbf d1,downscore
	sub.w #14,a0
upaplace sub.w #18,a0
	dbf d7,onhigh

nowayhozay cmp.b #14,d7
	beq noton
	add.w #18,a0

	move.b #$20,(a0)+
	clr.b (a0)
	move.w score,11(a0)
	move.l a0,stringinfo
	clr.w stringinfo+8
	clr.w stringinfo+$0c
	clr.w stringinfo+$10

	clr.w ongadge
	move.l #highreq,a0
	move.l window,a1
	CALLINT Request

	move.l #textgadget,a0
	move.l window,a1
	move.l #highreq,a2
	CALLINT OnGadget

	moveq #5,d1
	CALLDOS Delay

	move.l #textgadget,a0
	move.l window,a1
	move.l #highreq,a2
	CALLINT ActivateGadget

waitgadge move.l userport,a0
	clr.l d1
	move.b $0f(a0),d1
	moveq #1,d0
	asl.l d1,d0
	CALLEXEC Wait
	move.l userport,a0
	CALLEXEC GetMsg
	tst.l d0
	beq waitgadge
	move.l d0,a1
	move.l $14(a1),d4
	CALLEXEC ReplyMsg
	cmp.w #$0100,d4	* MENUPICK
	beq waitgadge	

	move.l #games-142,a0	* test number of games played
	move.w multiples,d0
	add.w #55536+30,d0
	cmp.w 142(a0),d0
	bra savem	* Remove this line for V1.1b & c
	bhi savem
	move.l himem,a0
	add.b #2,d7
	move.b d7,271(a0)	* display message
	bra savem2

savem	move.l stringinfo,a0
	move.b #254,-1(a0)	* Colour name
	bsr printhiscores
	move.l stringinfo,a0
	move.b #254,-1(a0)
savem2	bsr savescores
	move.l himem,a0
	move.w 270(a0),oldstatus
	bra missnoton	

noton	move.l himem,a0
	move.w oldstatus,d0
	cmp.w 270(a0),d0
	beq missnoton
	bra savem
missnoton cmp.w #5,games
	bne beginning
	bsr doabout	
	bra beginning

quitgame bsr savescores

freesoundmem move.l soundmem,a1
	move.l #soundsize,d0
	CALLEXEC FreeMem

freerastport move.l rastport2,a1
	move.l #100,d0
	CALLEXEC FreeMem

freehimem move.l himem,a1 
	move.l #hiscrsize,d0
	CALLEXEC FreeMem
	
freerastermem move.l #bitmap2+8,a5
	move.w #2,d7
rastfree move.l (a5)+,a1
	cmp.l #0,a1
	beq freemovemem
	move.l #80*maxscrheight,d0
	CALLEXEC FreeMem
	dbf d7,rastfree

freemovemem move.l movememory,a1
	move.l #maxplane*4,d0
	CALLEXEC FreeMem

freetablemem move.l tablememory,a1
	move.l #tablemem,d0
	CALLEXEC FreeMem

freecardmem move.l cardmemory,a1
	move.l #cardmem,d0
	CALLEXEC FreeMem

closewindow move.l window,a0
	CALLINT ClearMenuStrip
	move.l window,a0
	CALLINT CloseWindow

freesubmenus move.l #firstsub1,a5
	bsr freesubs
	move.l #firstsub2,a5
	bsr freesubs
	move.l #firstsub3,a5
	bsr freesubs

closescreen move.l screen,a0
	CALLINT CloseScreen

freesignal clr.l d0
	move.b signal,d0
	CALLEXEC FreeSignal

closeaudio move.l #iorequest,a1
	CALLEXEC CloseDevice

closeint move.l _IntuitionBase,a1
	CALLEXEC CloseLibrary


closegraf move.l _GfxBase,a1
	CALLEXEC CloseLibrary

closedos move.l _DOSBase,a1
	CALLEXEC CloseLibrary

end	tst.l _WBenchMsg
	beq notwb
	CALLEXEC Forbid
	move.l _WBenchMsg,a1
	CALLEXEC ReplyMsg
notwb	rts


mousey	andi.b #$40,$bfe001
	bne mousey
	clr.l d0
wait	dbf d0,wait
mousey2	andi.b #$40,$bfe001
	beq mousey2
	rts


    *****************************
    ** S U B - R O U T I N E S **
    *****************************

** Load in the graphics files **

setupgfx move.l rastport2,d7 
	move.w #maxscrheight-10,d6
	bsr cls2
	
	move.l #backdir,d1
	move.w #311,d0
	move.l #firstsub2,a4
	bsr loadgfx

	tst.l d0
	beq cockup

	move.l #symbolsdir,d1
	move.w #344,d0
	move.l #firstsub3,a4
	bsr loadgfx

	tst.l d0
	beq cockup

	move.l #facedir,d1
	move.w #278,d0
	move.l #firstsub1,a4
	bsr loadgfx

	tst.l d0
	beq cockup

	bsr createcards

	move.b #-1,d0

cockup	rts

loadgfx	move.l himem,a5
	add.w d0,a5
	move.l a4,d7

	move.l #ACCESS_READ,d2
	CALLDOS Lock
	tst.l d0
	beq blunder
	move.l d0,lock1

	move.l d0,d1
	CALLDOS CurrentDir
	move.l d0,lock2

seethenext tst.l (a4)
	beq notonlist
	move.l (a4),a4

	move.l 18(a4),a3
	move.l 12(a3),a3
	add.w #2,a3

	move.l a5,a2
comparethem move.b (a3)+,d0
	beq thisistheone
	cmp.b (a2)+,d0
	beq comparethem
	bra seethenext

thisistheone or.w #CHECKED,12(a4)
	bra trytoload	
	
notonlist move.l d7,a4
	move.l (a4),a4
	or.w #CHECKED,12(a4)
	move.l 18(a4),a4
	move.l 12(a4),a4
	add.w #2,a4

	move.l a5,a3
movetext move.b (a4)+,(a3)+
	bne movetext

trytoload bsr loadILBM
	tst.l d0
	beq blooper

	move.l lock2,d1
	CALLDOS CurrentDir
	move.l lock1,d1
	CALLDOS UnLock

	move.b #-1,d0

	rts

blooper move.l lock2,d1
	CALLDOS CurrentDir
	move.l lock1,d1
	CALLDOS UnLock

blunder	clr.l d0
	rts


** Search through graphics drawers for graphics files **
** and add them to the menu lists **

graphicsmenus move.l #fib_SIZEOF,d0
	move.l #$10001,d1
	CALLEXEC AllocMem
	tst.l d0
	bne gotcha
	rts

gotcha move.l d0,buffer

** First set up the card backs sub menus **

	move.l #facedir,d1
	bsr fillfib
	tst.l d0
	beq goawayfib

	move.l #firstsub1,a5
	bsr setupsubs
	tst.l d0
	beq goawayfib

** Now set up the card backs sub menus **

	move.l lock2,d1
	CALLDOS CurrentDir

	move.l lock1,d1
	CALLDOS UnLock

	move.l #backdir,d1
	bsr fillfib
	tst.l d0
	beq goawayfib

	move.l #firstsub2,a5
	bsr setupsubs
	tst.l d0
	beq goawayfib

** Now set up the card symbols sub menus **

	move.l lock2,d1
	CALLDOS CurrentDir

	move.l lock1,d1
	CALLDOS UnLock

	move.l #symbolsdir,d1
	bsr fillfib
	tst.l d0
	beq goawayfib

	move.l #firstsub3,a5
	bsr setupsubs
	tst.l d0
	beq goawayfib

	move.l lock2,d1
	CALLDOS CurrentDir

	move.l lock1,d1
	CALLDOS UnLock

	move.b #-1,d0

goawayfib move.l d0,d7
	move.l #fib_SIZEOF,d0
	move.l buffer,a1
	CALLEXEC FreeMem
	rts


** Search for ILBM files & set up submenus **

setupsubs move.w #5,d7
	move.l #$fffffffe,d5
lookforanother move.w d7,-(sp)
	bsr findilbmfile
	move.w (sp)+,d7
	tst.l d0
	beq endofdir
	move.l d0,a4	

	bsr allocsubmenu
	tst.l d0
	beq mess2
	move.l d0,(a5)
	move.l d0,a5

	move.l a5,-(sp)
	clr.l (a5)+
	move.w #148,(a5)+
	move.w d7,(a5)+
	add.w #9,d7
	move.l #((maxname+3)*8+4)*65536+9,(a5)+
	move.w #ITEMTEXT+ITEMENABLED+HIGHCOMP+CHECKIT,(a5)+
	move.l d5,(a5)
	rol.l #1,d5
	add.w #20,a5
	move.l a5,-16(a5)

	move.l #$07000000,(a5)+
	move.l #$00050000,(a5)+
	add.w #12,a5
	move.l a5,-8(a5)

	move.w #$2020,(a5)+
	move.w #15,d0
fillinname move.b (a4)+,(a5)+
	dbf d0,fillinname
	
	move.l (sp)+,a5
	bra lookforanother

endofdir move.b #-1,d0	
mess2 rts


** Fill in fileinfoblock **

fillfib	move.l #ACCESS_READ,d2
	CALLDOS Lock
	tst.l d0
	beq mess

	move.l d0,lock1
	move.l d0,d1
	CALLDOS CurrentDir
	move.l d0,lock2

	move.l lock1,d1
	move.l buffer,d2
	CALLDOS Examine

mess rts

** Search for next ilbm file given a lock **

findilbmfile move.l lock1,d1
	move.l buffer,d2
	CALLDOS ExNext
	tst.l d0
	beq ioerror
	
	move.l buffer,a0
	tst.l fib_EntryType(a0)
	bpl findilbmfile	* Directory
	
	move.l a0,d1
	add.l #fib_FileName,d1
	move.l d1,d6
	move.l #1005,d2
	CALLDOS Open
	tst.l d0
	beq findilbmfile
	move.l d0,d7	

	move.l #loadbuffer,d2
	move.l #12,d3
	move.l d7,d1
	CALLDOS Read

	move.l d7,d1
	CALLDOS Close

	cmp.l #$494c424d,loadbuffer+8	* ILBM ?
	bne findilbmfile

	move.l d6,d0

	rts	

ioerror CALLDOS IoErr
	cmp.l #ERROR_NO_MORE_ENTRIES,d0
	bne findilbmfile
	clr.l d0
	rts

** Allocate memory for a submenu **

allocsubmenu move.l #34+20+maxname+3,d0
	move.l #$10001,d1
	CALLEXEC AllocMem
	rts

** Free memory for submenus **

freesubs tst.l (a5)
	beq endoflist
	move.l (a5),a5
freenextsub	move.l a5,a1
	move.l (a5),a5
	move.l #34+20+maxname+3,d0
	CALLEXEC FreeMem
	move.l a5,d0
	tst.l d0
	bne freenextsub

endoflist rts

** Call this routine to set PAL or NTSC mode **

setmonitor move.l himem,a0
	btst.b #1,270(a0)
	beq displayPAL
	
   ** set up NTSC screen **

     ** card positions

	move.w #208,scrheight
	move.w #6,gapA
	move.w #4,gapB
	move.w #71,topy
	move.w #12,foundy
	move.w #61,scorepos

     ** high score table

	move.w #11,htop
	move.w #hhiteN,hhite
	move.l #boxN,boxloc
	move.w #7,y1
	move.w #6,y2
	move.w #166,y3
	move.w #165,y4
	move.w #176,y5
	move.w #175,y6
	move.w #28,name1pos	
	clr.w name2down

     ** text pages

	move.w #184,y7
	move.w #184,y8
	move.w #whiteN,white
	move.l #boxN2,boxloc2

	bra newdisplay

displayPAL move.w #258,scrheight
	move.w #7,gapA
	move.w #7,gapB
	move.w #80,topy
	move.w #17,foundy
	move.w #68,scorepos
	move.w #20,htop
	move.w #hhiteP,hhite
	move.l #boxP,boxloc
	move.w #12,y1
	move.w #11,y2
	move.w #190,y3
	move.w #189,y4
	move.w #201,y5
	move.w #200,y6
	move.w #39,name1pos	
	move.w #8,name2down
	move.w #226,y7
	move.w #226,y8
	move.w #whiteP,white
	move.l #boxP2,boxloc2

newdisplay bsr cls 
	bsr printhiscores
	rts
	

** Merge another disk's Hi-Scores with those already in memory **

mwidth	equ 360
mhite	equ 140
mtop	equ 50
mleft	equ 320-mwidth/2

mergescores move.l window,a0
	CALLINT ClearMenuStrip
	bsr grabscreen

	move.l rastport,a5
	
	clr.w d0
	move.l a5,a1
	CALLGRAF SetDrMd	* Set JAM1
	move.l a5,a1
	move.w #1,d0
	CALLGRAF SetAPen
	move.l a5,a1
	clr.w d1
	CALLGRAF SetBPen

	move.l a5,a1
	move.w #mleft,d0
	move.w #mtop,d1
	move.w #mleft+mwidth-1,d2
	move.w #mtop+mhite-1,d3
	CALLGRAF RectFill

	move.l a5,a0
	move.l #mbox1,a1
	move.w #mleft,d0
	move.w #mtop,d1
	CALLINT DrawBorder

	move.l a5,a0
	move.l #mtext1,a1
	move.w #mleft,d0
	move.w #mtop,d1
	CALLINT PrintIText

** double the height of "Merge Hi-Scores"

	move.l bitmap,a0
	move.w #80*10,d0
	move.w #(mtop+18)*80+26,d1
	move.l 8(a0),a1
	add.w d1,a1
	move.l a1,a4
	sub.w d0,a4
	move.l 12(a0),a2
	add.w d1,a2
	move.l a2,a5
	sub.w d0,a5
	move.l 16(a0),a3
	add.w d1,a3
	move.l a3,a6
	sub.w d0,a6

	move.w #9,d0
double3	move.w #26,d1
double4	move.b (a1),(a4)+
	move.b (a1)+,79(a4)
	move.b (a2),(a5)+
	move.b (a2)+,79(a5)
	move.b (a3),(a6)+
	move.b (a3)+,79(a6)
	dbf d1,double4
	add.w #53,a1
	add.w #53,a2
	add.w #53,a3
	add.w #53+80,a4
	add.w #53+80,a5
	add.w #53+80,a6

	dbf d0,double3

	move.l #mtextJ,gadtext
	move.l #mtextI,gadtext2
	move.w #1002,mtype
	move.w #1003,mtype2	
	bsr gadgetson

waitgadgey2 move.l userport,a0
	clr.l d1
	move.b $0f(a0),d1
	moveq #1,d0
	asl.l d1,d0
	CALLEXEC Wait
	move.l userport,a0
	CALLEXEC GetMsg
	tst.l d0
	beq waitgadgey2
	move.l d0,a1
	move.l $14(a1),d4
	move.l $1c(a1),a4
	CALLEXEC ReplyMsg
	cmp.w #$0100,d4	* MENUPICK
	beq waitgadgey2	

	cmp.w #1003,38(a4)	* PANIC - Display help page
	beq panic
	bsr gadgetsoff	
	move.l #mtextM,gadtext2

	move.l rastport,a0
	move.l #mtext3,a1
	move.w #mleft,d0
	move.w #mtop,d1
	CALLINT PrintIText

	move.l rastport,a0
	move.l #mbox3,a1
	move.w #mleft,d0
	move.w #mtop,d1
	CALLINT DrawBorder

	move.l window,a0
	move.l #mgadg,a1
	move.w #-1,d0
	CALLINT AddGadget

	move.l #mgadg,a0
	move.l window,a1
	sub.l a2,a2
	CALLINT OnGadget


msearch	move.l #mtextD,a0
	bsr filemess		* searching.....

** try to Lock selected directory

	move.l #mergename,d1
	move.w #-1,d2
	CALLDOS Lock
	tst.l d0
	bne founddir

	move.l #mtextE,a0
	bsr filemess		* Can't find directory
	move.l #mtextO,gadtext
	move.w #1004,mtype
	bsr gadgetson

	bra input
	
founddir move.l d0,lock1	* remember Lock
	move.l d0,d1
	CALLDOS CurrentDir
	move.l d0,lock2

** try to Lock Hi-Scores file

	move.l #filename2,d1
	move.w #-1,d2
	CALLDOS Lock
	tst.l d0
	bne foundHighs 
	move.l #mtextF,a0	* Can't find file
	bsr filemess
	move.l #mtextO,gadtext
	move.w #1004,mtype
	bsr gadgetson
	move.l lock1,d1
	CALLDOS UnLock		* Unlock directory
	move.l lock2,d1
	CALLDOS CurrentDir	* replace current directory
	bra input	

foundHighs move.l d0,d1
	CALLDOS UnLock
	move.l #mtextG,a0
	bsr filemess		* Found file
	move.l #mtextK,gadtext
	move.w #1002,mtype

** Load in the hi-scores

	move.l #bitmap2,a5
	move.l 8(a5),a5
	move.l a5,d4		* use bitplane 0 as a buffer
	move.l #filename2,d1
	move.l #300,d3
	bsr load
	bne readerror

	move.l a5,a0
	bsr unscramble2
	move.l a5,a0
	bsr checksum2
	cmp.l 272(a5),d1
	bne readerror
		
	bra displaygadg

readerror move.l #mtextN,a0
	bsr filemess
	move.l #mtextO,gadtext
	move.w #1004,mtype

displaygadg move.l lock1,d1
	CALLDOS UnLock		* Unlock directory
	move.l lock2,d1
	CALLDOS CurrentDir	* replace current directory

	bsr gadgetson
	bra waitgadgey

input	
	move.l #mgadg,a0
	move.l window,a1
	sub.l a2,a2
	CALLINT ActivateGadget

waitgadgey move.l userport,a0
	clr.l d1
	move.b $0f(a0),d1
	moveq #1,d0
	asl.l d1,d0
	CALLEXEC Wait
	move.l userport,a0
	CALLEXEC GetMsg
	tst.l d0
	beq waitgadgey
	move.l d0,a1
	move.l $14(a1),d4
	move.l $1c(a1),a4
	CALLEXEC ReplyMsg
	cmp.w #$0100,d4	* MENUPICK
	beq waitgadgey	

	move.w 38(a4),d7

	cmp.w #1001,d7		* text gadget4
	beq msearch
	cmp.w #1003,d7		* Cancel
	beq finit
	cmp.w #1004,d7		* Retry
	beq msearch
	cmp.w #1005,d7		* Done it
	beq cancel1
	cmp.w #1002,d7		* Merge
	bne waitgadgey
	
** Cancel any identical entries

	move.l #bitmap2,a0
	move.l 8(a0),a0
	add.w #4,a0
	move.w #14,d2
mcancel1 move.l himem,a1
	add.w #4,a1
	move.w #14,d0
mcancel2 move.l a0,a2
	move.l a1,a3
	move.w #6,d1
mcheck1	move.w (a1)+,d3
	cmp.w (a0)+,d3
	bne mnotsame
	dbf d1,mcheck1
	clr.w -2(a0)	* Cancel score
mnotsame move.l a2,a0
	move.l a3,a1
	add.w #18,a1
	dbf d0,mcancel2
	add.w #18,a0
	dbf d2,mcancel1

** Merge the high scores

	move.l #bitmap2,a5
	move.l 8(a5),a5
	add.w #256,a5 
	move.w #14,d6
all15	move.l himem,a0
	add.w #256,a0
	move.w #14,d7
monhigh	move.w 12(a5),d1
	cmp.w 12(a0),d1
	ble mnowayhozay
	cmp.b #14,d7
	beq mupaplace
	move.w #6,d1
mdownscore move.w (a0)+,16(a0)
	dbf d1,mdownscore
	sub.w #14,a0
mupaplace sub.w #18,a0
	dbf d7,monhigh

mnowayhozay cmp.b #14,d7
	beq mnoton
	add.w #18,a0

	move.w #6,d1
transfer move.w (a5)+,(a0)+
	dbf d1,transfer
	move.b #255,-14(a0)	* so can change colour
	sub.w #14,a5
mnoton	sub.w #18,a5
	dbf d6,all15
	move.w #1002,d7

finit	move.l window,a0
	move.l #mgadg,a1
	CALLINT RemoveGadget

	bsr gadgetsoff

	move.l rastport,a1
	move.w #mleft+6,d0
	move.w #mtop+40,d1
	move.w #mleft+mwidth-7,d2
	move.w #mtop+mhite-5,d3
	CALLGRAF RectFill

	cmp.w #1002,d7		* Merge
	bne notext1
	
	move.l rastport,a0
	move.l #mtext12,a1
	move.w #mleft,d0
	move.w #mtop,d1
	CALLINT PrintIText

notext1	move.l rastport,a0
	move.l #mtext11,a1
	move.w #mleft,d0
	move.w #mtop,d1
	CALLINT PrintIText

	move.l #mtextJ,gadtext
	move.l #mtextJ,gadtext2
	move.w #1005,mtype
	move.w #1005,mtype2
	bsr gadgetson

	bra waitgadgey

cancel1	bsr gadgetsoff
	
	bsr pushscreen
finitos	bsr printhiscores
	move.l window,a0
	move.l #klondike,a1
	CALLINT SetMenuStrip

	rts

panic	bsr gadgetsoff
	bsr pushscreen
	move.l window,a0
	move.l #klondike,a1
	CALLINT SetMenuStrip
	bsr dohelp4
	bra finitos

** Add and display the two merge scores gadgets 

gadgetson move.l window,a0
	move.l #mgadg2,a1
	move.w #-1,d0
	CALLINT AddGadget

	move.l window,a0
	move.l #mgadg3,a1
	move.w #-1,d0
	CALLINT AddGadget

	move.l #mgadg2,a0
	move.l window,a1
	sub.l a2,a2
	CALLINT OnGadget

	move.l #mgadg3,a0
	move.l window,a1
	sub.l a2,a2
	CALLINT OnGadget

	rts

** And remove them 

gadgetsoff move.l window,a0
	move.l #mgadg2,a1
	CALLINT RemoveGadget
	
	move.l window,a0
	move.l #mgadg3,a1
	CALLINT RemoveGadget

	rts

** Print file message in the merge hi-scores requester **

filemess move.w #mleft,d0
	move.w #mtop,d1
	move.l a0,messg
	move.l rastport,a0
	move.l #mtext7,a1
	CALLINT PrintIText

	move.l screen,a0
	CALLINT ScreenToFront

	rts


*****  Set pointer colours *****

pointcols move.l #pointpens,a4
	move.w #17,d7
nextpen	move.w d7,d0
	move.b (a4)+,d1
	move.b (a4)+,d2
	move.b (a4)+,d3
	move.l viewport,a0
	CALLGRAF SetRGB4
	add.w #1,d7
	cmp.b #19,d7
	bls nextpen
	rts

*****  Set pointy finger pointer *****

pointer1 move.l soundmem,a1
	bra dopointer

*****  Set flat hand pointer *****

pointer2 move.l soundmem,a1
	add.w #64,a1

dopointer move.l window,a0
	move.w #14,d0
	move.w #16,d1
	move.w #-1,d2
	move.w #-1,d3
	CALLINT SetPointer
	rts


*****  Play the sound  *****

sound1	move.l #snd3,d0 * sound of 1 card turnover
	move.l #snd0+snd1+snd2,d1
	move.w #20,d2
	bra play
	
sound3	move.l #snd4,d0	* sound of 3 cards turnover
	move.l #snd0+snd1+snd2+snd3,d1
	move.w #20,d2
	bra play

cheers	move.l #snd5,d0
	move.l #snd0+snd1+snd2+snd3+snd4,d1
	move.w #64,d2
	move.w #550,iorequest+$2a
	bra play2

play	move.w #450,iorequest+$2a
play2	move.w d2,iorequest+$2c
	move.l #iorequest,a1
	move.l soundmem,a0
	add.l d1,a0
	move.w #8,$1c(a1)	* CMD_FLUSH
	move.l a0,$22(a1)
	move.l d0,$26(a1)
	move.w #1,$2e(a1)

	CALLEXEC SendIO	

	move.l #iorequest,a1
	move.b #$10,$1e(a1)
	move.w #3,$1c(a1)

	move.l $14(a1),a6
	jsr -$1e(a6)	* BEGINIO

	rts

***** Draw a window and display pages of text starting in a5 *****

whiteN	equ 189
whiteP	equ 229
wtop	equ 10
wwidth	equ 640
wleft	equ (640-wwidth)/2	

page	move.l window,a0
	move.w #$7e1,d0
	CALLINT OffMenu		* Options menu
	move.l window,a0
	move.w #$7e2,d0
	CALLINT OffMenu		* game menu
	move.l window,a0
	move.w #$7e3,d0
	CALLINT OffMenu		* Help menu
	move.l window,a0
	move.w #0,d0
	CALLINT OffMenu
	move.l window,a0
	move.w #$20,d0
	CALLINT OffMenu
	move.l window,a0
	move.w #$40,d0
	CALLINT OffMenu

	bsr grabscreen

page2	move.l #text16,more+12

	move.w #0,d0
	move.l rastport,a1
	CALLGRAF SetDrMd	* Set JAM1
	move.l rastport,a1
	move.w #7,d0
	CALLGRAF SetAPen

newpage	move.l rastport,a1
	move.w #wleft,d0
	move.w #wtop,d1
	move.w #wleft+wwidth-1,d2
	move.w #wtop,d3
	add.w white,d3
	CALLGRAF RectFill

	move.l rastport,a0
	move.l #borderA,a1
	move.w #wleft,d0
	move.w #wtop,d1
	CALLINT DrawBorder

	move.w #wtop+8,d7
eachrow	move.l a5,lineoftext+12
	move.w #(wwidth-32)/8,d0
lookforspace cmp.b #254,(a5)
	bne notdn
	add.w #2,a5
	move.l himem,a0
	btst.b #1,270(a0)
	bne eachrow
	add.w #9,d7
	bra eachrow		
notdn	cmp.b #32,(a5)+
	bne notendofword
	tst.b (a5)
	beq there
	move.l a5,a0
notendofword dbf d0,lookforspace
	move.l a0,a5
there	clr.b -1(a5)
	move.w #wleft+20,d0
	move.w d7,d1
	move.l rastport,a0
	move.l #lineoftext,a1
	CALLINT PrintIText
	move.b #32,-1(a5)
	add.w #9,d7
		
	tst.b (a5)
	bne eachrow

	cmp.b #255,1(a5)		* NTSC smaller screen
	bne bigscreen1
	add.w #1,a5
	move.l himem,a0
	btst.b #1,270(a0)
	bne nottheend

bigscreen1 add.w #1,a5
	tst.b (a5)
	bne eachrow

	tst.b 1(a5)
	bne nottheend
	tst.b 2(a5)
	beq finito
	move.l #text18,more+12
nottheend move.l window,a0
	move.l #moregadget,a1
	move.l #-1,d0
	CALLINT AddGadget
	move.l window,a0
	move.l #cancelgadget,a1
	move.l #-1,d0
	CALLINT AddGadget

	move.l #moregadget,a0
	move.l window,a1
	sub.l a2,a2
	CALLINT RefreshGadgets
	
waitgg	move.l userport,a0
	clr.l d1
	move.b $0f(a0),d1
	moveq #1,d0
	asl.l d1,d0
	CALLEXEC Wait
	move.l userport,a0
	CALLEXEC GetMsg
	tst.l d0
	beq waitgg
	move.l d0,a1
	move.l $14(a1),d4
	move.w $18(a1),d5
	move.l $1c(a1),a4
	CALLEXEC ReplyMsg
	cmp.w #$0100,d4	* MENUPICK
	bne gad
	cmp.w #$ffff,d5	* MENUNULL
	beq waitgg
	and.w #$7ff,d5
	cmp.w #$60,d5
	beq quit
	bra waitgg
gad	cmp.w #1,38(a4)
	beq gotmore
	cmp.w #2,38(a4)
	bne waitgg
	bra gotcancel
gotmore bsr gogadgetgo
	add.w #1,a5
	tst.b (a5)
	bne newpage
	bra gotcancel	

gogadgetgo move.l window,a0
	move.l #moregadget,a1
	CALLINT RemoveGadget
	move.l window,a0
	move.l #cancelgadget,a1
	CALLINT RemoveGadget

finito	rts

gotcancel bsr gogadgetgo

	move.l window,a0
	move.w #$7e1,d0
	CALLINT OnMenu		* Options menu
	move.l window,a0
	move.w #$7e2,d0
	CALLINT OnMenu		* game menu
	move.l window,a0
	move.w #$7e3,d0
	CALLINT OnMenu		* Help menu
	move.l window,a0
	move.w #0,d0
	CALLINT OnMenu
	move.l window,a0
	move.w #$20,d0
	CALLINT OnMenu
	move.l window,a0
	move.w #$40,d0
	CALLINT OnMenu

	bsr pushscreen
	move.l window,a0
	move.l #klondike,a1
	CALLINT SetMenuStrip

	move.l #seconds,a0
	move.l #micros,a1
	CALLINT CurrentTime
	move.l seconds,oldsecs
	
	rts


***** Display the hi-scores *****

hleft	equ 204
hhiteP	equ 220
hhiteN	equ 188
hwidth	equ 232

printhiscores 

	move.l himem,a0

	clr.w d0
	move.b 271(a0),d0
	tst.b d0
	bra keeplaying		* Delete line for V1.1b & c
	beq keeplaying
	
** insert last name entered into text

	mulu.w #18,d0
	sub.w #13,d0
	add.w d0,a0
	move.l #guilty1+66,a1
	move.l #guilty2+21,a2
	move.w #9,d1
insert	move.b (a0),(a1)+
	move.b (a0)+,(a2)+
	dbf d1,insert
	
	move.l #message,a5
	move.l himem,a0
	btst.b #1,270(a0)
	beq PALmessage
	move.l #message2,a5
PALmessage bsr page2
	rts

keeplaying move.l #lastscore,a0
	CALLINT IntuiTextLength
	move.w #hleft+30,d5
	sub.w d0,d5
	lsr.w #1,d5
	move.w d5,lastscore+4
	subq #2,d5
	move.w d5,lastscore2+4

	move.l #gamespld2,a1
	move.w games,d0
	bsr donumber2
	clr.b (a1) 

	move.l #gamesdone,a0
	CALLINT IntuiTextLength
	move.w #hleft+30,d5
	sub.w d0,d5
	lsr.w #1,d5
	move.w d5,gamesdone+4
	subq #2,d5
	move.w d5,gamesdone2+4

	clr.w d0
	move.l rastport2,a1
	CALLGRAF SetDrMd	* Set JAM1
	move.l rastport2,a1
	clr.w d0
	CALLGRAF SetAPen

	move.l rastport2,a1
	move.w #hleft,d0
	move.w htop,d1
	move.w #hleft+hwidth-1,d2
	move.w htop,d3
	add.w hhite,d3
	subq #1,d3
	CALLGRAF RectFill

	move.l rastport2,a0
	move.l #border,a1
	move.w #hleft,d0
	move.w htop,d1
	CALLINT DrawBorder

	move.l rastport2,a0
	move.l #titler,a1
	move.w #hleft,d0
	move.w htop,d1
	CALLINT PrintIText
	
	move.l himem,a4
	move.b #32,4(a4)
	move.w name1pos,d7
	move.w #14,d6
	move.b #4,name
	move.l #font2,fontys
	move.l #namea,nextname
dothem	move.w 16(a4),d0
	bsr donumber
	clr.b (a1)
	cmp.b #14,d6
	bne missth
	move.l #storage,namepos
	move.l #name,a0
	CALLINT IntuiTextLength
	move.w #64,d5
	sub.w d0,d5
	lsr.w #1,d5
missth	move.w d5,d0
	move.w d7,d1
	add.w htop,d1
	move.l rastport2,a0
	move.l #name,a1
	move.l a4,namepos
	move.l a4,namepos2
	CALLINT PrintIText
	
	move.l rastport2,a0
	move.l #name,a1
	move.w #129,d0
	cmp.w #14,d6
	bne yobo
	move.w #160,d0
yobo	add.w d5,d0
	move.w d7,d1
	add.w htop,d1
	move.l #storage,namepos
	move.l #storage,namepos2
	CALLINT PrintIText

	move.w #36,d5
	move.l #font,fontys
	clr.l nextname
	
	cmp.w #14,d6
	bne notdown2
	add.w name2down,d7

	move.l #bitmap2,a0
	move.l 16(a0),a2
	move.w htop,d0
	add.w name1pos,d0
	mulu.w #80,d0
	add.w #26,d0
	add.w d0,a2
	move.l a2,a3
	sub.w #80*10,a3
	move.l 12(a0),a0
	add.w d0,a0
	move.l a0,a1
	sub.w #80*10,a1

	move.w #8,d0
double1	move.w #26,d1
double2	move.b (a0),(a1)+
	move.b (a0)+,79(a1)
	move.b (a2),(a3)+
	move.b (a2)+,79(a3)
	dbf d1,double2
	add.w #53,a0
	add.w #53+80,a1
	add.w #53,a2
	add.w #53+80,a3

	dbf d0,double1

notdown2 add.w #18,a4
	move.b #1,name
	cmp.b #32,4(a4)
	beq normalcol
	move.b #32,4(a4)
	move.b #2,name		* change colour
normalcol add.w #9,d7
	dbf d6,dothem

	move.l #bitmap2,a0
	move.w #hleft,d0
	move.w htop,d1
	move.l rastport,a1
	move.w d0,d2
	move.w d1,d3
	move.w #hwidth,d4
	move.w hhite,d5
	move.w #$c0,d6
	CALLGRAF BltBitMapRastPort

	rts


***** replace 3rd bitplane of card in A4 clipping out move card *****

replacehi bsr ownblitter
	move.l #$dff000,a5
	move.l #$09f00000,$040(a5)
	move.l #-1,$044(a5)

	move.w (a4),d0
	move.w 2(a4),d1
	mulu.w #80,d1
	move.w d0,d2
	lsr.w #3,d2
	bclr #0,d2
	add.w d2,d1	* d1=offset into bitplane
	move.w d1,hiliteoffset

	move.w #46,d7
	move.w hiliteoffset,d6
	move.w newy,d0
	sub.w 2(a4),d0
	beq notys
	bcs aboves
	cmp.w #46,d0
	bls goodsize
	move.w #46,d0
goodsize sub.w d0,d7
	move.w d0,d1
	mulu.w #80,d1
	add.w d1,d6 
	move.w hiliteoffset,d1 
	bra drawhorz

aboves	neg.w d0
	cmp.w #46,d0
	bls goodsize2
	move.w #46,d0
goodsize2 move.w #46,d1
	sub.w d0,d7
	sub.w d0,d1
	mulu.w #80,d1
	add.w hiliteoffset,d1
drawhorz move.l #$00460046,$064(a5)
	move.l wherefrom,a0
	move.l whereto,a1
	add.w d1,a0
	move.l a0,$050(a5)
	add.w d1,a1
	move.l a1,$054(a5)
	mulu.w #64,d0
	add.w #5,d0
	move.w d0,$058(a5)
	bsr waitblit


notys	move.w (a4),d0
	and.w #$fff0,d0
	sub.w newx,d0
	beq notxs
	bcc leftie
	neg.w d0
	lsr.w #4,d0
	cmp.w #5,d0
	bls goodsize3
	move.w #5,d0
goodsize3 mulu.w #64,d7
	beq notxs
	add.w d0,d7
	lsl.w #1,d0
	neg.w d0
	add.w #80,d0
	move.w d0,$064(a5)
	move.w d0,$066(a5)
	bra drawvert

leftie	lsr.w #4,d0
	cmp.w #5,d0
	bls goodsize4
	move.w #5,d0
goodsize4 mulu.w #64,d7
	beq notxs
	add.w d0,d7
	lsl.w #1,d0
	neg.w d0
	add.w #10,d0
	add.w d0,d6
	add.w #70,d0
	move.w d0,$064(a5)
	move.w d0,$066(a5)
drawvert move.l wherefrom,a0
	move.l whereto,a1
	add.w d6,a0
	move.l a0,$050(a5)
	add.w d6,a1
	move.l a1,$054(a5)
	move.w d7,$058(a5)
	bsr waitblit

notxs	CALLGRAF DisownBlitter

	rts


***** Calculate the height of the selected column (a4=table) *****

gotcard	move.l tablememory,a0
	clr.w d0
	move.b 4(a4),d1
	move.w #63,d2
last	cmp.b 4(a0),d1
	bne nottcol	
	cmp.b 5(a0),d0
	bhi nottcol
	move.b 5(a0),d0
	move.l a0,a1	
nottcol add.w #10,a0
	dbf d2,last

* a1=last card in column

	clr.w d0
	move.b 5(a1),d0
	sub.b 5(a4),d0	* no. of cards to shift-1
	move.w d0,numcards
	move.w #46,d1
	tst.b d0
	beq gothite
	add.w #10,d1
	subq #1,d0
	beq gothite
	mulu.w gapB,d0
	add.w d0,d1
gothite move.w d1,moveheight		* Height

** create the mask for height in moveheight **

	move.l a4,movecard
	move.l movememory,a0
	move.l cardmask2,a1
	move.l (a1)+,(a0)+
	move.l (a1)+,(a0)+
	move.l (a1)+,(a0)+
	move.l (a1)+,(a0)+
	move.l (a1)+,(a0)+
	move.l (a1)+,(a0)+
	move.l (a1)+,d1
	move.l (a1),d2
	move.w moveheight,d0
	sub.w #7,d0
middle	move.l d1,(a0)+
	move.l d2,(a0)+
	dbf d0,middle
	add.w #316,a1
	move.l (a1)+,(a0)+
	move.l (a1)+,(a0)+
	move.l (a1)+,(a0)+
	move.l (a1)+,(a0)+
	move.l (a1)+,(a0)+
	move.l (a1)+,(a0)+


** grab the cards using the mask **	

	bsr ownblitter
	move.l #$dff000,a5

	move.w (a4),d0
	move.w 2(a4),d1
	move.w d1,newy

	mulu.w #80,d1
	move.w d0,d2
	lsr.w #3,d2
	bclr #0,d2
	add.w d2,d1	* d1=offset into bitplane
	move.w d1,moveoffset
	lsl.w #3,d2
	move.w d0,d3
	move.w d2,newx
	sub.w d2,d3
	lsl.w #4,d3
	lsl.w #8,d3
	move.w d3,moveshift
	
	sub.w d0,d2	* d0=pixels to shift right
	add.w #16,d2	

	lsl.w #4,d2
	lsl.w #8,d2

	add.w #$ba0,d2		* use A,C & D	
	move.w d2,$040(a5)	* Control 0
	clr.w $042(a5)		* Control 1		

	move.l bitmap,a1
	add.w #8,a1
	clr.w $066(a5)		* D modulo
	move.w #-2,$060(a5)	* C modulo
	move.w #70,$064(a5)	* A modulo
	move.l #-1,$044(a5)	* Masks

	move.w #2,d0	
	move.w moveheight,d2
	mulu.w #64,d2
	add.w #5,d2	
	move.l movememory,a0
	move.l a0,a3
	sub.w #2,a3
	add.l #maxplane,a0

loop1	move.l (a1)+,a2
	add.w d1,a2
	move.l a2,$050(a5)	* Source A
	move.l a3,$048(a5)	* Source C (mask)
	move.l a0,$054(a5)	* Destination
	add.l #maxplane,a0	

	move.w d2,$058(a5)	 * Blit a bitplane
	bsr waitblit
	dbf d0,loop1

** Clear the column selected **

	move.w #-2,$064(a5)	* A modulo
	move.w #70,$060(a5)	* C modulo
	move.w #70,$066(a5)	* D modulo
	move.w moveshift,d0
	add.w #$b0a,d0
	move.w d0,$040(a5)
	clr.w $042(a5)
	move.l #$ffff0000,$044(a5)	* mask

	move.w moveheight,d0
	mulu.w #64,d0
	add.w #5,d0
	move.w d0,movesize
	move.l #bitmap2+8,a0
	move.w #2,d1
ridit	move.l (a0)+,a1
	add.w moveoffset,a1
	move.l a1,$048(a5)
	move.l a1,$054(a5)
	move.l movememory,$050(a5)
	move.w d0,$058(a5)
	bsr waitblit
	dbf d1,ridit

	CALLGRAF DisownBlitter

** find the previous card in the pile **

	move.l movecard,a0
	move.b 5(a0),d1
	move.b d1,d5
	cmp.b #9,4(a0)
	bne nobby
	cmp.b #1,d1
	beq redrawn
	move.b #1,d1
	bra notaspc
nobby	sub.b #1,d1
	bne notaspc
	cmp.b #9,4(a0)
	bls redrawn
notaspc	move.b 4(a0),d0
	move.l tablememory,a1
previous cmp.b 5(a1),d1
	bne nextplease		* not one less 
	cmp.b 4(a1),d0
	beq foundit		* same column
nextplease add.w #10,a1
	bra previous

foundit cmp.b #9,4(a1)
	bne onlyone
	move.b d1,d6
drawthem move.l bitmap,d7
	move.l #bitmap2,bitmap * Use other screen
	bsr fromtable		* get a0 value
	bsr drawcard		* Draw card
	move.l d7,bitmap
	addq #1,d6
	move.l tablememory,a1
morer	cmp.b 5(a1),d6
	bne nextyes		* not one more
	cmp.b #9,4(a1)
	beq foundd		* same column
nextyes	add.w #10,a1
	bra morer
foundd	cmp.b 5(a1),d5
	bne drawthem
	bra redrawn

onlyone	move.l bitmap,d7
	move.l #bitmap2,bitmap * Use other screen
	bsr fromtable		* get a0 value
	bsr drawcard		* Draw card
	move.l d7,bitmap

redrawn 
	rts


***** Draw the column of cards at position in moveoffset *****

slaponcards bsr ownblitter
	move.l #$dff000,a5

	move.w moveshift,d0
	move.w d0,$042(a5)	* Control 1

	add.w #$0fca,d0	* use A,B,C & D	
	move.w d0,$040(a5)	* Control 0
		
	move.l bitmap,a1
	add.w #8,a1
	move.w #70,$060(a5)	* C modulo
	move.w #70,$066(a5)	* D modulo
	move.l #$0000fffe,$062(a5)	* A & B modulos
	move.l #$ffff0000,$044(a5)	* Masks

	move.w #2,d0	
	move.l movememory,a0
	add.w #maxplane+2,a0
	move.l #bitmap2+8,a3

slap	move.l movememory,$050(a5) * Source A (mask)
	move.l a0,$04c(a5)	* Source B
	add.w #maxplane,a0
	move.l (a3)+,a2
	add.w moveoffset,a2
	move.l a2,$048(a5)	* Source C
	move.l (a1)+,a2
	add.w moveoffset,a2
	move.l a2,$054(a5)	* Destination
	
	move.w movesize,$058(a5) * Blit a bitplane
	bsr waitblit
	dbf d0,slap

	CALLGRAF DisownBlitter
	
	rts



***** Calculate the columns new position *****

newpos	move.l window,a0
	move.w $0e(a0),d0	* wd_mouseX
	move.w $0c(a0),d1	* wd_mouseY
	sub.w movex,d0
	bcc notooleft
	clr.w d0
notooleft cmp.w #640-56,d0
	bls notoorite
	move.w #640-56,d0
notoorite sub.w movey,d1
	bcs tooup
	cmp.w #11,d1
	bhi notooup
tooup	move.w #11,d1
notooup move.w d1,d2
	add.w moveheight,d2
	move.w scrheight,d3
	subq #1,d3
	cmp.w d3,d2
	bls forcenewpos
	move.w d3,d1
	sub.w moveheight,d1
forcenewpos move.w newx,oldx
	move.w newy,oldy
	move.w d1,newy
	move.w d0,properx
	mulu.w #80,d1
	move.w d0,d2
	lsr.w #3,d2
	bclr #0,d2
	add.w d2,d1	* d1=offset into bitplane
	move.w moveoffset,oldoffset
	move.w d1,moveoffset
	lsl.w #3,d2
	move.w d2,newx
	sub.w d2,d0
	lsl.w #4,d0
	lsl.w #8,d0
	move.w d0,moveshift
	rts
	

***** Copy the whole screen onto bitmap2 *****

grabscreen move.l bitmap,a0
	move.l rastport2,a1
	bra movescreen

***** Replace the whole screen back to bitmap *****

pushscreen move.l #bitmap2,a0
	move.l rastport,a1
movescreen clr.w d0
	move.w #10,d1
	clr.w d2
	move.w d1,d3
	move.w #640,d4
	move.w #maxscrheight-10,d5
	move.w #$c0,d6
	CALLGRAF BltBitMapRastPort
	rts


***** Replace the background *****

background bsr ownblitter
	move.l #$dff000,a5
	
	move.w moveheight,d7
	move.w oldoffset,d6
	move.w newy,d1
	sub.w oldy,d1
	beq noychange
	bcs goneup
	move.w oldoffset,d2
	cmp.w moveheight,d1
	bls notoobig
	move.w moveheight,d1
notoobig move.w d1,d4
	mulu.w #80,d4
	add.w d4,d6
	bra replace	

goneup	neg.w d1
	cmp.w moveheight,d1
	bls notoohigh
	move.w moveheight,d1
notoohigh move.w moveheight,d2
	sub.w d1,d2
	mulu.w #80,d2
	add.w oldoffset,d2

replace	sub.w d1,d7 
	beq fullone
	bcc notfull
fullone	clr.w d7
notfull	mulu.w #64,d1
	add.w #5,d1
	move.w #70,$066(a5)		* D modulo
	move.w #70,$064(a5)		* A modulo
	move.l #$09f00000,$040(a5)	* Controls
	move.l #-1,$044(a5)		* masks

	move.l bitmap,a0
	add.w #8,a0
	move.w #2,d0
	move.l #bitmap2+8,a1
pushback move.l (a0)+,a2
	add.w d2,a2
	move.l a2,$054(a5)	* Destination
	move.l (a1)+,a2
	add.w d2,a2
	move.l a2,$050(a5)	* Source A
	move.w d1,$058(a5)
	bsr waitblit
	dbf d0,pushback

noychange move.w newx,d0
	sub.w oldx,d0
	beq noxmove
	bcs goesleft

	lsr.w #4,d0
	cmp.w #5,d0
	bls nottoobigg
	move.w #5,d0
nottoobigg mulu.w #64,d7
	beq noxmove
	add.w d0,d7
	lsl.w #1,d0
	neg.w d0
	add.w #80,d0

	bra replace2

goesleft neg.w d0
	lsr.w #4,d0
	cmp.w #5,d0
	bls nottoobiggg
	move.w #5,d0
nottoobiggg mulu.w #64,d7	
	beq noxmove
	add.w d0,d7
	lsl.w #1,d0
	neg.w d0
	add.w #10,d0
	add.w d0,d6
	add.w #70,d0
	bra replace2

replace2 move.w d0,$066(a5)		* D modulo
	move.w d0,$064(a5)		* A modulo
	move.l #$09f00000,$040(a5)	* Controls
	move.l #-1,$044(a5)		* masks

	move.l bitmap,a0
	add.w #8,a0
	move.w #2,d0
	move.l #bitmap2+8,a1
pushback2 move.l (a0)+,a2
	add.w d6,a2
	move.l a2,$054(a5)	* Destination
	move.l (a1)+,a2
	add.w d6,a2
	move.l a2,$050(a5)	* Source A
	move.w d7,$058(a5)
	bsr waitblit
	dbf d0,pushback2
	
noxmove

	CALLGRAF DisownBlitter
	
	rts


***** Find last card & 1st upturned cards in column & set select bits *****

select	move.w #1,d0
findlast2 move.l tablememory,a0
	clr.w d1
	clr.w d2
	move.w #63,d3
findlast cmp.b 4(a0),d0
	bne notincol	
	cmp.b 5(a0),d1
	bhi noupdate
	move.b 5(a0),d1
	move.l a0,a1	
noupdate cmp.b 5(a0),d2
	bhi notincol
	btst.b #0,7(a0)
	beq notincol
	move.b 5(a0),d2
notincol add.w #10,a0
	dbf d3,findlast

* a1=last card in column
* d2=number of face downs in column

	tst.b 5(a1)
	bne notlast
	cmp.b #8,4(a1) 
	bne noneincol
notlast	bset.b #1,7(a1)
	cmp.b #7,d0
	bhi noneincol

	move.l tablememory,a0
	add.b #1,d2
	move.w #63,d3
lookfor cmp.b 4(a0),d0
	bne nothere
	cmp.b 5(a0),d2
	beq yahoo
nothere	add.w #10,a0
	dbf d3,lookfor
	bra noneincol
yahoo	btst.b #0,7(a0)
	bne noneincol
	btst.b #1,7(a0)
	bne noneincol
	bset.b #2,7(a0)
	bset.b #4,7(a1)

noneincol addq #1,d0
	cmp.b #13,d0
	bls findlast2

	rts



***** Find last card in columns *****

select2	move.l movecard,a4
	move.w #1,d0
	move.b 8(a4),d2
	add.b #1,d2

findlasty2 move.l tablememory,a0
	clr.w d1
	move.w #63,d3
findlasty cmp.b 4(a0),d0
	bne noupdated
	cmp.b 5(a0),d1
	bhi noupdated
	move.b 5(a0),d1
	move.l a0,a1	
noupdated add.w #10,a0
	dbf d3,findlasty

* a1=last card in column

	cmp.b #7,d0
	bls tableau
** a1 is top of a foundation **

	move.b 8(a4),d1
	subq #1,d1
	cmp.b 8(a1),d1
	bne cantgohere
	tst.b d1
	beq setbitt
	move.b 9(a4),d1
	cmp.b 9(a1),d1
	bne cantgohere
	tst.w numcards	* columns of cards can't go on foundations
	bne cantgohere
	bra setbitt

tableau	tst.b 5(a1)
	beq IsitaKing
	cmp.b 8(a1),d2
	bne cantgohere
	btst.b #0,9(a4)
	bne selred
	btst.b #0,9(a1)
	beq cantgohere
	bra setbitt

selred	btst.b #0,9(a1)
	bne cantgohere

setbitt	btst.b #0,7(a1)
	bne cantgohere
	bset.b #3,7(a1)
	bra cantgohere

IsitaKing cmp.b #13,8(a4)
	beq setbitt

cantgohere addq #1,d0
	cmp.b #7,d0
	bls findlasty2
	cmp.b #8,d0
	bne noskip
	move.b #10,d0
noskip	cmp.b #13,d0
	bls findlasty2

	rts



***** Check if mouse is over a select card *****

checkselect move.l window,a0
	move.w $0e(a0),d0	* wd_mouseX
	move.w $0c(a0),d1	* wd_mouseY
	move.l tablememory,a0
	move.w #63,d2
findsel move.b 7(a0),d3
	and.b #6,d3
	beq notsel
	cmp.w (a0),d0
	bls notsel
	move.w (a0),d4
	add.w #52,d4
	cmp.w d4,d0
	bhi notsel
	
	cmp.w 2(a0),d1
	bls notsel
	move.w 2(a0),d4
	add.w #10,d4
	btst.b #2,7(a0)
	bne colo
	add.w #34,d4
colo	cmp.w d4,d1
	bhi notsel
	move.l a0,a4	* a4 points to card selected
	move.w d0,d2
	sub.w (a4),d2
	move.w d2,movex
	move.w d1,d2
	sub.w 2(a4),d2
	move.w d2,movey
	bra doneok

notsel	add.w #10,a0
	dbf d2,findsel
	sub.l a4,a4	* a4 is zero - not over card

doneok
	rts



***** Check if mouse can put card down *****

checkselect2 move.w properx,d0
	move.w newy,d1
	clr.w d6
	move.l tablememory,a0
	move.w #63,d2
finddown btst.b #3,7(a0)
	beq notsel2
	move.w (a0),d4
	cmp.w d0,d4
	bls torite
	move.w d0,d5
	add.w #52,d5
	sub.w d4,d5
	bcs notsel2
	bra gotxval
torite	move.w d4,d5
	add.w #52,d5
	sub.w d0,d5
	bcs notsel2

gotxval	move.w 2(a0),d4
	sub.w #44,d4
	bcs misss
	cmp.w d4,d1
	bls notsel2
misss	move.w 2(a0),d4
	add.w #43,d4
	cmp.w d4,d1
	bhi notsel2

	cmp.w d5,d6
	bhi notsel2
	move.w d5,d6
	move.l a0,a4	* a4 points to card selected

notsel2	add.w #10,a0
	dbf d2,finddown
	tst.w d6
	bne gotone
	sub.l a4,a4	* a4 is zero - not over card
gotone

	rts


***** Save the hi-scores *****

savescores bsr checksum
	move.l himem,a0
	move.l d1,272(a0)
	move.w games,276(a0)
	bsr scramble
	
	move.l #filename2,d1
	move.l #1006,d2
	CALLDOS Open
	tst.l d0
	beq savefail1
	move.l d0,file

	move.l file,d1
	move.l himem,d2
	move.l #hiscrsize,d3
	CALLDOS Write
	cmp.l d0,d3
	bne savefail2

savefail2 move.l file,d1
	CALLDOS Close
	
savefail1 bsr unscramble
	move.l screen,a0
	CALLINT ScreenToFront

	rts

***** Load the sounds file into memory *****

loadsounds move.l #filename3,d1
	move.l soundmem,d4
	move.l #soundsize,d3
	bra load
	

***** Load the hi-scores into memory *****

loadscores move.l himem,d4
	move.l #filename2,d1
	move.l #hiscrsize,d3
	bsr load
	bne loaderror

	bsr unscramble
	bsr checksum
	move.l himem,a0
	cmp.l 272(a0),d1
	bne loaderror
	move.w 276(a0),games
	moveq #0,d0
	rts

newscores	* reset hiscores

loaderror move.l #hiscores,a0
	move.l himem,a1
	move.b 270(a1),d7
	move.w #138,d0
newscores2 move.w (a0)+,(a1)+
	dbf d0,newscores2
	move.l himem,a1
	move.b d7,270(a1)
	clr.w games
	moveq #1,d0
	rts


scramble move.l himem,a0
	move.w #134,d0
scram1	move.w 2(a0),d1
	eor.w d1,(a0)+
	dbf d0,scram1
	rts

unscramble move.l himem,a0
unscramble2 add.w #270,a0 
	move.w #134,d0
scram2	move.w (a0),d1
	eor.w d1,-(a0)
	dbf d0,scram2
	rts

load	move.l #1005,d2
	CALLDOS Open
	tst.l d0
	beq openfail2
	move.l d0,file

	move.l file,d1
	move.l d4,d2

	CALLDOS Read
	cmp.l d0,d3
	bne readfail2
	
	move.l file,d1
	CALLDOS Close
	
	moveq #0,d0
	rts

readfail2 move.l file,d1
	CALLDOS Close
openfail2 moveq #1,d0
	rts


checksum move.l himem,a0
checksum2 move.w #67,d0
	clr.l d1
checkit add.l (a0)+,d1
	dbf d0,checkit
	rts


** Load ILBM file **


loadILBM move.l a5,d1
 	move.l #1005,d2
 	CALLDOS Open
 	tst.l d0
 	beq goodbye
 	move.l d0,file

* Read 8 bytes to check file is type ILBM

read move.l file,d1
	move.l #loadbuffer,d2
	move.l #12,d3
	CALLDOS Read
	cmp d3,d0
	bne lderror

	cmp.l #$494c424d,loadbuffer+8	* Test for letters ILBM
	bne notilbm

* Get chunk name/length

chunkloop

	move.l file,d1
	move.l #loadbuffer,d2
	move.l #8,d3
	CALLDOS Read
	cmp d3,d0
	bne lderror
	
	move.l loadbuffer+4,d0
	move.l #$10001,d1
	CALLEXEC AllocMem
	tst.l d0
	beq lderror
	move.l d0,buffer

	move.l file,d1
	move.l buffer,d2
	move.l loadbuffer+4,d3
	CALLDOS Read
	cmp d3,d0
	bne lderror

	cmp.l #$424d4844,loadbuffer		* "BMHD" ?
	bne nobitmaphead
	
* Get info about screen

	move.l buffer,a1
	cmp.w #640,(a1)
	bne lderror
	move.w (a1),iwidth
	move.w 2(a1),iheight

	move.b 8(a1),d3
	andi.w #$ff,d3
	move.w d3,idepth
	cmp.w #3,d3
	bne lderror

	move.b 10(a1),d0
	andi.w #$ff,d0
	move.w d0,icompr
 
	clr.l d0
	move.w iwidth,d0
	divu #8,d0
	move.w d0,irowbytes

	bra nextchunkloop

nobitmaphead cmpi.l #$434d4150,loadbuffer	* CMAP ?
	bne nocolormap

	move.l buffer,a1
	move.l #cols,a2	

* Build colour table

	move.w #7,d2

makecols clr.w d0
	move.b (a1)+,d0
	mulu.w #16,d0
	add.b (a1)+,d0
	clr.l d1
	move.b (a1)+,d1
	divu.w #16,d1
	add.b d1,d0
	move.w d0,(a2)+
	dbf d2,makecols

	bra nextchunkloop
	
nocolormap cmpi.l #$424f4459,loadbuffer		* "BODY" ?
	bne nextchunkloop

	cmp.w #1,icompr
	bhi lderror	* unknown compression algorithm

compression move.w #52,d4	
	move.l #down*80,d7
	move.l buffer,a3

loop7	move.l #bitmap2+8,a5

	move.w idepth,d6
	subq #1,d6	

loop3	move.l (a5)+,a4
	add.l d7,a4
	move.l a4,d5	
	
	tst.w icompr
	bne loop4
	move.w irowbytes,d0	* no compression
	subq #1,d0
	bra notsame

loop4	tst.b (a3)
	bmi compressed
	
	clr.w d0
	move.b (a3)+,d0
notsame	move.b (a3)+,d1
	or.b d1,(a4)+
	dbf d0,notsame
	bra okay
	
compressed clr.w d0
	move.b (a3)+,d0
	neg.b d0
	move.b (a3)+,d1
samebytes or.b d1,(a4)+
	dbf d0,samebytes
	
okay	move.l a4,d0
	sub.l d5,d0
	cmp.w irowbytes,d0
	blt loop4
	
	dbf d6,loop3

	add.w irowbytes,d7
	dbf d4,loop7
	
	bra goodload

nextchunkloop move.l buffer,a1
	move.l loadbuffer+4,d0
	CALLEXEC FreeMem
	
	bra chunkloop


goodload bsr freebuff
	move.l file,d1
	CALLDOS Close 

	move.b #-1,d0

	rts

notilbm

lderror bsr freebuff

closeILBM move.l file,d1
	CALLDOS Close

goodbye clr.l d0
	rts

freebuff move.l buffer,a1
	move.l loadbuffer+4,d0
	CALLEXEC FreeMem
	rts


** Create the card table and set up screen for a new game **

setup	move.w #foundx1,d0
	move.w foundy,d1
	move.l cardmemory,a0
	add.l #46*8*3*53,a0	* Card outline
	bsr drawcard
	add.w #64,d0
	bsr drawcard
	move.w #foundx2,d0
	bsr drawcard
	add.w #64,d0
	bsr drawcard
	
	move.l #snd1,d0
	move.l #snd0,d1
	move.w #50,d2
	bsr play

	move.l tablememory,a0
	add.w #550,a0
	move.l a0,buffer
	move.w #52,d0
pack	move.b d0,(a0)+
	dbf d0,pack	* Create a new pack of cards

	move.w #300,d0	* Go through pack this many times
	move.l buffer,a0
shuffle1 move.w #51,d1	* Swapping each card
shuffle2 bsr random
	move.b randy+1,d2
	and.w #63,d2
	cmp.b #51,d2
	bls inlimits
	sub.b #30,d2
inlimits move.b 0(a0,d1),d3
	move.b 0(a0,d2),0(a0,d1)
	move.b d3,0(a0,d2)
	dbf d1,shuffle2
	dbf d0,shuffle1

	move.l #snd2,d0
	move.l #snd0+snd1,d1
	move.w #45,d2
	bsr play


** Draw the plateau and initialize card table **

	move.l tablememory,a2
	move.l buffer,a1
	
	move.w topy,d1
	move.w #1,d2
	move.w #1,d3
	move.w #6,d6
card1	clr.w 6(a2)		* Status - Card face up	
	clr.w d4
	move.b (a1),d4
	subq #1,d4
	bra card3
card2	move.w #1,6(a2)		* Status - Card face down
	move.w #52,d4
card3	mulu.w #46*8*3,d4
	move.l cardmemory,a0
	add.l d4,a0
	move.w d2,d0
	mulu.w #64,d0
	add.w #37,d0
	move.w d0,(a2)		* Left x value
	move.w d1,2(a2)		* Top y value
	move.b d2,4(a2)		* Column card is in
	move.b d3,5(a2)		* Number in pile
	bsr suitin

	bsr flyback
	bsr flyback
	bsr drawcard

	add.w #10,a2
	addq #1,d2
	cmp.b #7,d2
	bls card2	* next in column

	sub.w d6,d2
	subq #1,d6
	add.w gapA,d1
	addq #1,d3
	cmp.b #7,d3
	bls card1	* next row
	
** Store rest of cards in table as deck **

	move.w #24,d0
deck	move.w #deck1x,(a2)
	move.w foundy,2(a2)
	move.b #8,4(a2)
	move.b d0,5(a2)
	move.w #1,6(a2)
	bsr suitin
	add.w #10,a2
	dbf d0,deck
	clr.l -4(a2)	

	move.w #deck1x,d0
	move.w foundy,d1
	move.l cardmemory,a0
	add.l #46*8*3*52,a0
	bsr drawcard		* Draw deck

** Do the 7 bases and 4 foundations
	
	move.w #101,d0
	move.w topy,d1
	move.b #1,d2
foundations move.w d0,(a2)
	move.w d1,2(a2)
	move.b d2,4(a2)
	clr.b 5(a2)
	clr.w 6(a2)
	clr.w 8(a2)
	add.w #64,d0
	add.w #10,a2
	add.b #1,d2
	cmp.b #8,d2
	bne notfounds1
	move.w #foundx1,d0
	move.w foundy,d1
	move.b #10,d2
notfounds1 cmp.b #12,d2
	bne notfounds2
	move.w #foundx2,d0
notfounds2 cmp.b #13,d2
	bls foundations

	rts



** Put card & suit values into table from 1-52 value in d4 **

suitin	move.b (a1)+,d4
	clr.b d5
calcard cmp.b #13,d4
	bls gotit
	sub.b #13,d4
	addq #1,d5
	bra calcard
gotit	move.b d4,8(a2)		* Card value
	move.b d5,9(a2)		* Suit value
	rts



***** Set the colours for this display *****

setcols	move.l #cols,a1
setbnw	move.l viewport,a0
	move.l #8,d0
	CALLGRAF LoadRGB4

	rts



***** Clear the window *****

cls	move.l rastport,d7
	move.w #maxscrheight-1,d6

cls2	clr.w d0
	move.l d7,a1
	CALLGRAF SetDrMd	* Set JAM1
	move.l d7,a1
	move.w #1,d0
	CALLGRAF SetAPen
	move.l d7,a1
	clr.w d0
	move.w #8,d1
	CALLGRAF Move
	move.l d7,a1
	move.w #3,d0
	move.w #8,d1
	CALLGRAF Draw

	move.l d7,a1
	move.w #640,d0
	move.w #8,d1
	CALLGRAF Move
	move.l d7,a1
	move.w #564,d0
	move.w #8,d1
	CALLGRAF Draw

	move.l d7,a1
	clr.w d0
	CALLGRAF SetAPen
	
	clr.w d0
	move.w #9,d1
	move.w #640,d2
	move.w d6,d3
	move.l d7,a1
	CALLGRAF RectFill

	rts


***** Clear status bits 1 to 3 in the card table *****

clear	move.l tablememory,a0
	move.w #63,d0
clearit	and.w #$fff1,6(a0)
	add.w #10,a0
	dbf d0,clearit

	rts



***** Create the cards *****

createcards move.w #1,d7
	move.l cardmemory,a4
nextcard
	move.w #457,d0
	move.w #7,d1
	clr.w d2
	clr.w d3
	move.w #54,d4
	move.w #46,d5

	cmp.b #53,d7
	beq doback
	cmp.b #56,d7
	beq redeal
	cmp.b #54,d7
	bne doblank
	move.w #565,d0
	bsr block	* Draw card outline
	bra storecard
redeal	move.w #500,d0
	move.w #100,d1
	bsr block	* Blank out card
	move.w #457,d0
	move.w #10,d1
	move.w #23,d5
	move.w #8,d3
	bsr block	* Draw redeal sign
	bra storecard
doback	move.w #511,d0
	bsr block	* Draw card back
	bra storecard

doblank	bsr block	* Draw blank card

	move.w #33,d1
	move.w #11,d5
	move.w #3,d3
	bsr block	* Blank out redeal
	move.w #12,d5
	move.w #14,d3
	bsr block	* Blank out redeal

	cmp.b #55,d7
	beq storecard

	move.w d7,d6
	clr.w d5
findsuit cmp.w #13,d6
	bls gotsuit
	addq #1,d5
	sub.w #13,d6
	bra findsuit

gotsuit	move.w #416,d0
	move.w d5,suit+2
	mulu #18,d5
	add.w d5,d0
	move.w d0,suit	* Store pos of large suit symbol
	
	move.w d6,d0
	mulu.w #32,d0
	sub.w #32,d0
	btst.b #0,suit+3
	beq black
	add.w #16,d0
black	clr.w d1
	move.w #1,d2
	move.w #3,d3
	move.w #8,d4
	move.w #6,d5
	bsr block	* draw top left number

	add.w #8,d0
	move.w #45,d2
	move.w #37,d3
	bsr block	* draw bottom right number

	move.w suit+2,d0
	mulu #5,d0
	add.w #488,d0
	move.w #3,d2
	cmp.b #9,d6
	bls notpic1
	subq #1,d2
notpic1 move.w #10,d3
	move.w #5,d4
	move.w #3,d5
	bsr block	* draw top left symbol

	add.w #3,d1
	move.w #46,d2
	cmp.b #9,d6
	bls notpic2
	addq #1,d2
notpic2	move.w #33,d3
	bsr block	* draw bottom right symbol

	cmp.w #1,d7
	bne notacespade
	move.l #421,d0
	bra picture	* Draw ace of spades
notacespade cmp.w #10,d6
	bls notpiccy
	move.w d6,d0
	mulu.w #140,d0
	sub.w #1540,d0
	move.w suit+2,d5
	mulu.w #35,d5
	add.w d5,d0
	bra picture	* Draw picture card

notpiccy move.l #symbols,a5
findnum cmp.b #255,(a5)+
	bne findnum
	cmp.b (a5)+,d6
	bne findnum

drawsymbols move.w suit,d0
	clr.w d1
	clr.w d2
	move.b (a5)+,d2
	cmp.b #255,d2
	beq storecard
	clr.w d3
	move.b (a5)+,d3
	tst.b (a5)+
	beq pointsup
	add.w #9,d0
pointsup move.w #9,d4
	move.w #7,d5
	bsr block
	bra drawsymbols

picture	move.w #7,d1
	move.w #9,d2
	move.w #5,d3
	move.w #36,d4
	move.w #36,d5
	bsr block

** Store the card drawn as 3 bitplanes of 8*46 bytes **

storecard move.l #bitmap2+8,a0
	move.w #2,d0
column	move.w #45,d1
	move.l (a0)+,a1
	add.w #140*80+4,a1	* Top left word of card
store	move.l (a1)+,(a4)+
	move.l (a1),(a4)+
	add.w #76,a1
	dbf d1,store
	dbf d0,column

	add.b #1,d7
	cmp.b #56,d7
	bls nextcard

** Create the 2nd card mask (with righthand blank edge)

	move.l cardmask2,a0
	move.l cardmask,a1
	move.w #5,d0
threel	move.l (a1)+,(a0)+
	dbf d0,threel

	move.w #40,d0
middlebit move.l #$ffffffff,(a0)+
	move.l #$ffffff00,(a0)+
	dbf d0,middlebit
	move.l #$7fffffff,(a0)+
	move.l #$fffffe00,(a0)+
	move.l #$0fffffff,(a0)+
	move.l #$fffff000,(a0)+

	rts



** Move a rectangle **

block	movem.l d0-d6/a0-a2,-(sp)
	add.l #down,d1
	add.l #cardx,d2
	add.l #cardy,d3
	move.w #$c0,d6
	move.l #bitmap2,a0
	move.l rastport2,a1
	CALLGRAF BltBitMapRastPort
	movem.l (sp)+,d0-d6/a0-a2
	rts



***** Call drawcard routine for card from table in a1 *****

fromtable move.l d2,-(sp)
	move.w (a1),d0
	move.w 2(a1),d1
	clr.w d2
	btst.b #0,7(a1)
	beq faceisup
	move.b #52,d2
	bra mult	* card back
faceisup cmp.b #9,4(a1)
	bls notfdtions
	tst.b 5(a1)
	bne notfdtions
	move.b #53,d2
	bra mult	* card outline
notfdtions cmp.b #8,4(a1)
	bne notdecks
	tst.b 5(a1)
	bne notdecks
	move.b #55,d2
	bra mult
notdecks move.b 9(a1),d2
	mulu.w #13,d2
	add.b 8(a1),d2
	subq #1,d2
mult	mulu.w #8*46*3,d2
	move.l cardmemory,a0
	add.l d2,a0
	move.l (sp)+,d2
	rts



***** Draw a card at x=d0,y=d1,a0=first word *****

drawcard movem.l d0-d7/a0-a7,-(sp) 
	bsr setupdraw
	move.w #2,d0	
	bsr drawplanes
	movem.l (sp)+,d0-d7/a0-a7
	rts



***** Same as drawcard routine but on bitmap2 *****

drawcard2 movem.l d0-d7/a0-a7,-(sp) 
	bsr setupdraw
	move.w #2,d0
	move.l #bitmap2+8,a1	
	bsr drawplanes
	movem.l (sp)+,d0-d7/a0-a7
	rts


** This routine sets up registers for drawcard **

setupdraw bsr ownblitter
	move.l #$dff000,a5

	mulu.w #80,d1
	move.w d0,d2
	lsr.w #3,d2
	bclr #0,d2
	add.w d2,d1	* d1=offset into bitplane
	lsl.w #3,d2
	sub.w d2,d0	* d0=pixels to shift right
	lsl.w #4,d0
	lsl.w #8,d0
	move.w d0,$042(a5)	* Control 1

	add.w #$0fca,d0	* use A,B,C & D	
	move.w d0,$040(a5)	* Control 0
		
	move.l bitmap,a1
	add.w #8,a1
	move.w #70,$060(a5)	* C modulo
	move.w #70,$066(a5)	* D modulo
	move.l #$fffefffe,$062(a5)	* A & B modulos
	move.l #$ffff0000,$044(a5)	* Masks

	rts

** This routine is part of drawcard **

drawplanes move.l cardmask2,$050(a5) * Source A (mask)
	move.l a0,$04c(a5)	* Source B
	add.w #46*8,a0
	move.l (a1)+,a2
	add.w d1,a2
	move.l a2,$048(a5)	* Source C
	move.l a2,$054(a5)	* Destination
	
	move.w #46*64+5,$058(a5) * Blit a bitplane
	bsr waitblit
	dbf d0,drawplanes

	CALLGRAF DisownBlitter
	
	rts



***** I want to use the blitter *****

ownblitter CALLGRAF OwnBlitter
	CALLGRAF WaitBlit
	move.w #$8440,$dff096	* Blitter DMA enable
	rts


***** Wait for the blitter to complete operation *****

waitblit btst.b #6,$dff002
	bne waitblit
	rts


***** Wait for frame flyback *****

flyback	move.w #$8420,$dff09a
	move.w #$0020,$dff09c
waitfly	btst.b #5,$dff01f
	beq waitfly
	rts

***** Uses raster beam position to update random number in randy *****

random	move.w d0,-(sp)
	move.w randy,d0
	add.w d0,d0
	add.w d0,d0
	add.w d0,d0
	add.w d0,d0
	add.w d0,d0
	add.w d0,d0
	add.w d0,d0
	add.w d0,d0
	add.w randy,d0
	move.w d0,randy
	move.w $dff006,d0
	lsr.w #1,d0
	sub.w d0,randy
	move.w (sp)+,d0
	rts



***** First convert score into ASCII then print it *****

printscore move.w score,d0
	move.w d0,oldscore	
	bsr donumber
	move.b #32,(a1)+
	move.b #32,(a1)+
	move.b #32,(a1)+
	move.b #32,(a1)+
	move.b #32,(a1)+
	clr.b (a1)

	move.l rastport,a0
	move.l #scoreitext,a1
	clr.w d0
	clr.w d1
	CALLINT PrintIText

	rts

donumber move.l #storage,a1
donumber2 move.l #multiples,a0
	clr.b d4
	tst.w d0
	bpl nextdigit
	move.b #45,(a1)+
	neg.w d0

nextdigit move.w (a0)+,d1
	beq completed
	clr.b d2
	
notfounddigit cmp.w d0,d1
	bhi founddigit
	sub.w d1,d0
	addq #1,d2
	bra notfounddigit
	
founddigit tst.b d2
	bne notnort
	tst.b d4
	beq nextdigit
notnort	add.b #48,d2
	addq #1,d4
	move.b d2,(a1)+
	bra nextdigit
	
completed add.b #48,d0
	move.b d0,(a1)+
	
	rts



******************************

foundy	dc.w 0
gapA	dc.w 0
gapB	dc.w 0
topy	dc.w 0
scrheight dc.w 0
htop	dc.w 0
hhite	dc.w 0
white	dc.w 0
name1pos dc.w 0
name2down dc.w 0

stack	dc.l 0
suit	dc.l 0
file 	dc.l 0
randy	dc.w 0
window	dc.l 0
bitmap	dc.l 0
buffer	dc.l 0
score	dc.w 0
oldscore dc.w 0
_WBenchMsg dc.l 0
viewport dc.l 0
rastport dc.l 0
rastport2 dc.l 0
cardmask dc.l 0
cardmask2 dc.l 0
himem dc.l 0
soundmem dc.l 0
movememory dc.l 0
numcards dc.w 0
cardmemory dc.l 0
firstpass dc.w 0
oldx dc.w 0
oldy dc.w 0
newx dc.w 0
newy dc.w 0
movex dc.w 0
movey dc.w 0
movesize dc.w 0
movecard dc.l 0
moveshift dc.w 0
moveheight dc.w 0
oldoffset dc.w 0
moveoffset dc.w 0
yposition dc.w 0
games	dc.w 0
tablememory dc.l 0
properx dc.w 0
hilitecard dc.l 0
hiliteoffset dc.w 0
wherefrom dc.l 0
whereto	dc.l 0
userport dc.l 0
firsttime dc.l 0
seconds dc.l 0
oldsecs dc.l 0
micros dc.l 0
oldstatus dc.w 0

iwidth dc.w 0
iheight dc.w 0
idepth dc.w 0
icompr dc.w 0
irowbytes dc.w 0

_DOSBase dc.l 0
_GfxBase dc.l 0
_IntuitionBase dc.l 0

bitmap2 ds.l 10

lock1	dc.l 0
lock2	dc.l 0
lock3	dc.l 0


mgadg	dc.l 0
	dc.w mleft+(mwidth-320)/2,mtop+67,320,8
	dc.w 0,1,4
	dc.l mbox4,0,0,0,infostring
	dc.w 1001,0,0

mgadg2	dc.l mgadg3
	dc.w mleft+40,mtop+115,110,13
	dc.w 0,1,1
	dc.l mbox5,0,mtext9,0,0
mtype	dc.w 1002,0,0

mgadg3	dc.l 0
	dc.w mleft+mwidth-150,mtop+115,110,13
	dc.w 0,1,1
	dc.l mbox5,0,mtext10,0,0
mtype2	dc.w 1003,0,0


infostring dc.l mergename,0
	dc.w 12,50,0,0,12,32,0,0
	dc.l 0,0,0

mbox1	dc.w 0,0
	dc.b 0,0,0,10
	dc.l mboxA,mbox2

mbox2	dc.w 4,2
	dc.b 7,0,0,10
	dc.l mboxB,0

mbox3	dc.w 15,40
	dc.b 7,0,0,12
	dc.l mboxC,0

mbox4	dc.w 0,-1
	dc.b 0,0,0,2
	dc.l mboxD,0

mbox5	dc.w 0,0
	dc.b 4,0,0,10
	dc.l mboxE,mbox6

mbox6	dc.w -4,-2
	dc.b 7,0,0,10
	dc.l mboxF,0

mboxA	dc.w 0,0,mwidth-1,0,mwidth-1,mhite-1
	dc.w mwidth-2,mhite-1,mwidth-2,0,mwidth-2,mhite-1
	dc.w 0,mhite-1,0,0,1,0,1,mhite-1

mboxB	dc.w 0,0,mwidth-9,0,mwidth-9,mhite-5
	dc.w mwidth-10,mhite-5,mwidth-10,0,mwidth-10,mhite-5
	dc.w 0,mhite-5,0,0,1,0,1,mhite-5

mboxC	dc.w 0,0,mwidth-31,0,mwidth-31,36
	dc.w mwidth-32,36,mwidth-32,0,mwidth-32,36
	dc.w 0,36,0,0,1,0,1,36,1,24,mwidth-32,24

mboxD	dc.w 0,0,320,0

mboxE	dc.w 0,0,109,0,109,1,0,1,0,2,109,2,109,11,0,11,0,12,109,12
mboxF	dc.w 0,0,117,0,117,16,116,16,116,0,116,16,0,16,0,0,1,0,1,16


	even


mtext1	dc.b 2,0,0,0
	dc.w (mwidth-206)/2,21
	dc.l font2,mtextA,mtext2

mtext2	dc.b 4,0,0,0
	dc.w (mwidth-210)/2,20
	dc.l font2,mtextA,mtext8

mtext3	dc.b 0,0,1,0
	dc.w (mwidth-320)/2,42
	dc.l font2,mtextC,mtext4

mtext4	dc.b 0,0,1,0
	dc.w (mwidth-320)/2,54
	dc.l font2,mtextC,mtext5

mtext5	dc.b 7,0,1,0
	dc.w (mwidth-320)/2,49
	dc.l font2,mtextB,mtext6

mtext6	dc.b 1,0,0,0
	dc.w (mwidth-324)/2,48
	dc.l font2,mtextB,0

mtext7	dc.b 7,1,1,0
	dc.w (mwidth-200)/2,86
	dc.l font2
messg	dc.l 0,0

mtext8	dc.b 7,0,0,0
	dc.w (mwidth-320)/2,49
	dc.l font2,mtextH,0

mtext9	dc.b 1,4,1,0
	dc.w 0,3
	dc.l font2
gadtext	dc.l 0,0

mtext10	dc.b 1,4,1,0
	dc.w 0,3
	dc.l font2
gadtext2 dc.l 0,0

mtext11	dc.b 7,0,0,0
	dc.w (mwidth-320)/2,65
	dc.l font2,mtextP,0

mtext12	dc.b 7,1,1,0
	dc.w (mwidth-210)/2,45
	dc.l font2,mtextQ,0


newscreen dc.w 0,0,640,maxscrheight,3
	dc.b 7,1
	dc.w $8000		* V_HIRES
	dc.w $000f		* CUSTOMSCREEN
	dc.l font,0,0,0

font	dc.l fontype
	dc.w 8		* TOPAZ_EIGHTY
	dc.b 0,1	* FS_NORMAL,FPF_ROMFONT

font2	dc.l fontype
	dc.w 9		* TOPAZ_SIXTY
	dc.b 0,1	* FS_NORMAL,FPF_ROMFONT

newwindow dc.w 0,0,640,maxscrheight
	dc.b 7,1
	dc.l $0140	* MENUPICK+GADGETUP
	dc.l $1800	* ACTIVATE+BORDERLESS
	dc.l 0,0,wndtitle
screen	dc.l 0,0
	dc.w 0,0,0,0,$000f	* CUSTOMSCREEN

	even

scoreitext dc.b 1,0,1,0
	dc.w 280
scorepos dc.w 68
	dc.l font,scoretext,0

cols	ds.w 8
cols2	dc.w $000,$fff,$ccc,$222,$888,$777,$aaa,$000
pointpens dc.b 0,0,0,8,8,8,31,31,31

symbols	dc.b 255,1,23,19,0
	dc.b 255,2,23,7,0,23,33,1
	dc.b 255,3,23,6,0,23,20,0,23,34,1
	dc.b 255,4,11,5,0,34,5,0,11,33,1,34,33,1
	dc.b 255,5,11,6,0,34,6,0,11,34,1,34,34,1,23,20,0
	dc.b 255,6,11,6,0,34,6,0,11,34,1,34,34,1,11,20,0,34,20,0
	dc.b 255,7,11,6,0,34,6,0,11,34,1,34,34,1,11,20,0,34,20,0,23,13,0
	dc.b 255,8,11,6,0,34,6,0,11,34,1,34,34,1,11,20,0
	dc.b 34,20,0,23,13,0,23,27,1
	dc.b 255,9,11,6,0,34,6,0,11,16,0,34,16,0,23,20,0
	dc.b 11,25,1,34,25,1,11,35,1,34,35,1
	dc.b 255,10,11,6,0,34,6,0,23,12,0,11,16,0,34,16,0
	dc.b 11,25,1,34,25,1,23,29,1,11,35,1,34,35,1,255
	
	Even

multiples dc.w 10000
	dc.w 1000
	dc.w 100
	dc.w 10
	dc.w 0

MENUENABLED	equ $0001
MIDRAWN		equ $0100
CHECKIT		equ $0001
ITEMTEXT	equ $0002
COMMSEQ		equ $0004
MENUTOGGLE	equ $0008
ITEMENABLED	equ $0010
HIGHFLAGS	equ $00C0
HIGHIMAGE	equ $0000
HIGHCOMP	equ $0040
HIGHBOX		equ $0080
HIGHNONE	equ $00C0
CHECKED		equ $0100

klondike dc.l game
	dc.w 8,0,78,0,MENUENABLED
	dc.l name1
	dc.l klondike1
	dc.w 0,0,0,0

game	dc.l options
	dc.w 104,0,46,0,MENUENABLED
	dc.l name2
	dc.l game1
	dc.w 0,0,0,0

options	dc.l help
	dc.w 168,0,70,0,MENUENABLED
	dc.l name3
	dc.l options1
	dc.w 0,0,0,0

help	dc.l 0
	dc.w 256,0,54,0,MENUENABLED
	dc.l name4
	dc.l help1
	dc.w 0,0,0,0


klondike1 dc.l klondike2
	dc.w 0,0,74,8,ITEMTEXT+ITEMENABLED+HIGHCOMP
	dc.l 0,intext1,0
	dc.b 0,0
	dc.l 0
	dc.w 0

klondike2 dc.l klondike3
	dc.w 0,10,74,8,ITEMTEXT+ITEMENABLED+HIGHCOMP
	dc.l 0,intext1b,0
	dc.b 0,0
	dc.l 0
	dc.w 0

klondike3 dc.l klondike4
	dc.w 0,20,74,8,ITEMTEXT+ITEMENABLED+HIGHCOMP
	dc.l 0,intext1c,0
	dc.b 0,0
	dc.l 0
	dc.w 0

klondike4 dc.l 0
	dc.w 0,30,74,8,ITEMTEXT+ITEMENABLED+HIGHCOMP
	dc.l 0,intext2,0
	dc.b 0,0
	dc.l 0
	dc.w 0

game1	dc.l game2
	dc.w 0,0,80,8,ITEMTEXT+ITEMENABLED+HIGHCOMP
	dc.l 0,intext3,0
	dc.b 0,0
	dc.l 0
	dc.w 0

game2	dc.l 0
	dc.w 0,10,80,8,ITEMTEXT+HIGHCOMP
	dc.l 0,intext4,0
	dc.b 0,0
	dc.l 0
	dc.w 0

options1 dc.l options2
	dc.w 0,0,152,8
opt1	dc.w 0
	dc.l 2,intext6e,0
	dc.b 0,0
	dc.l 0
	dc.w 0

options2 dc.l options3
	dc.w 0,10,152,8
opt2	dc.w 0
	dc.l 1,intext6f,0
	dc.b 0,0
	dc.l 0
	dc.w 0

options3 dc.l options4
	dc.w 0,20,152,8
opt3	dc.w 0
	dc.l 8,intext5,0
	dc.b 0,0
	dc.l 0
	dc.w 0

options4 dc.l options5
	dc.w 0,30,152,8
opt4	dc.w 0
	dc.l 4,intext6,0
	dc.b 0,0
	dc.l 0
	dc.w 0

options5 dc.l options6
	dc.w 0,40,152,8,ITEMTEXT+ITEMENABLED+HIGHCOMP
	dc.l 0,intext6g,0
	dc.b 0,0
firstsub1 dc.l 0
	dc.w 0

options6 dc.l options7
	dc.w 0,50,152,8,ITEMTEXT+ITEMENABLED+HIGHCOMP
	dc.l 0,intext6h,0
	dc.b 0,0
firstsub2 dc.l 0
	dc.w 0

options7 dc.l options8
	dc.w 0,60,152,8,ITEMTEXT+ITEMENABLED+HIGHCOMP
	dc.l 0,intext6i,0
	dc.b 0,0
firstsub3 dc.l 0
	dc.w 0


options8 dc.l options9
	dc.w 0,70,152,8,ITEMTEXT+ITEMENABLED+HIGHCOMP
	dc.l 0,intext6d,0
	dc.b 0,0
	dc.l 0
	dc.w 0

options9 dc.l 0
	dc.w 0,80,152,8,ITEMTEXT+ITEMENABLED+HIGHCOMP
	dc.l 0,intext6b,0
	dc.b 0,0
	dc.l subitem1
	dc.w 0

subitem1 dc.l 0
	dc.w 148,5,72,8,ITEMTEXT+ITEMENABLED+HIGHCOMP
	dc.l 0,intext6c,0
	dc.b 0,0
	dc.l 0
	dc.w 0

help1	dc.l help2
	dc.w 0,0,144,8,ITEMTEXT+ITEMENABLED+HIGHCOMP
	dc.l 0,intext7,0
	dc.b 0,0
	dc.l 0
	dc.w 0

help2	dc.l help3
	dc.w 0,10,144,8,ITEMTEXT+ITEMENABLED+HIGHCOMP
	dc.l 0,intext8,0
	dc.b 0,0
	dc.l 0
	dc.w 0

help3	dc.l help4
	dc.w 0,20,144,8,ITEMTEXT+ITEMENABLED+HIGHCOMP
	dc.l 0,intext9,0
	dc.b 0,0
	dc.l 0
	dc.w 0

help4	dc.l 0
	dc.w 0,30,144,8,ITEMTEXT+ITEMENABLED+HIGHCOMP
	dc.l 0,intext10,0
	dc.b 0,0
	dc.l 0
	dc.w 0

	even

intext1 dc.b 7,0,0,0
	dc.w 8,0
	dc.l 0,text1,0

intext1b dc.b 7,0,0,0
	dc.w 8,0
	dc.l 0,text1b,0

intext1c dc.b 7,0,0,0
	dc.w 8,0
	dc.l 0,text1c,0

intext2	dc.b 7,0,0,0
	dc.w 8,0
	dc.l 0,text2,0

intext3	dc.b 7,0,0,0
	dc.w 8,0
	dc.l 0,text3,0

intext4	dc.b 7,0,0,0
	dc.w 8,0
	dc.l 0,text4,0

intext5	dc.b 7,0,0,0
	dc.w 8,0
	dc.l 0,text5,0

intext6	dc.b 7,0,0,0
	dc.w 8,0
	dc.l 0,text6,0

intext6b dc.b 7,0,0,0
	dc.w 8,0
	dc.l 0,text6b,0

intext6c dc.b 7,0,0,0
	dc.w 5,0
	dc.l 0,text6c,0

intext6d dc.b 7,0,0,0
	dc.w 8,0
	dc.l 0,text6d,0

intext6e dc.b 7,0,0,0
	dc.w 8,0
	dc.l 0,text6e,0

intext6f dc.b 7,0,0,0
	dc.w 8,0
	dc.l 0,text6f,0

intext6g dc.b 7,0,0,0
	dc.w 8,0
	dc.l 0,text6g,0

intext6h dc.b 7,0,0,0
	dc.w 8,0
	dc.l 0,text6h,0

intext6i dc.b 7,0,0,0
	dc.w 8,0
	dc.l 0,text6i,0

intext7	dc.b 7,0,0,0
	dc.w 8,0
	dc.l 0,text7,0

intext8	dc.b 7,0,0,0
	dc.w 8,0
	dc.l 0,text8,0

intext9	dc.b 7,0,0,0
	dc.w 8,0
	dc.l 0,text9,0

intext10 dc.b 7,0,0,0
	dc.w 8,0
	dc.l 0,text9b,0

titler	dc.b 7,0,0,0
	dc.w 27
y1	dc.w 12
	dc.l font2,text10,titler2

titler2	dc.b 1,0,0,0
	dc.w 25
y2	dc.w 11
	dc.l font2,text10,lastscore

lastscore dc.b 7,0,0,0
	dc.w 0
y3	dc.w 190
	dc.l font2,lastscr,lastscore2

lastscore2 dc.b 1,0,0,0
	dc.w 0
y4	dc.w 189
	dc.l font2,lastscr,gamesdone

gamesdone dc.b 7,0,0,0
	dc.w 0
y5	dc.w 201
	dc.l font2,gamespld,gamesdone2

gamesdone2 dc.b 1,0,0,0
	dc.w 0
y6	dc.w 200
	dc.l font2,gamespld,0


textspace dc.b 0,0,1,0
	dc.w 80,0
	dc.l 0,spc,0

spc	dc.b 32,0

name	dc.b 4,0,0,0
	dc.w hleft,1
fontys	dc.l 0
namepos	dc.l 0
nextname dc.l namea

namea	dc.b 2,0,0,0
	dc.w hleft-2,0
	dc.l font2
namepos2 dc.l 0,0


border	dc.w 2,1
	dc.b 1,0,0,10
boxloc	dc.l boxP,0

borderA	dc.w 2,1
	dc.b 1,0,0,10
boxloc2	dc.l boxP2,0


boxP2	dc.w 0,0,wwidth-5,0,wwidth-5,whiteP-2
	dc.w wwidth-6,whiteP-2,wwidth-6,0,wwidth-6,whiteP-2
	dc.w 0,whiteP-2,0,0,1,0,1,whiteP-2

boxN2	dc.w 0,0,wwidth-5,0,wwidth-5,whiteN-2
	dc.w wwidth-6,whiteN-2,wwidth-6,0,wwidth-6,whiteN-2
	dc.w 0,whiteN-2,0,0,1,0,1,whiteN-2


boxP	dc.w 0,0,hwidth-5,0,hwidth-5,hhiteP-3
	dc.w hwidth-6,hhiteP-3,hwidth-6,0,hwidth-6,hhiteP-3
	dc.w 0,hhiteP-3,0,0,1,0,1,hhiteP-3

boxN	dc.w 0,0,hwidth-5,0,hwidth-5,hhiteN-3
	dc.w hwidth-6,hhiteN-3,hwidth-6,0,hwidth-6,hhiteN-3
	dc.w 0,hhiteN-3,0,0,1,0,1,hhiteN-3


box2	dc.w 0,0
	dc.b 0,0,0,10
	dc.l box4,box3

box3	dc.w 4,2
	dc.b 7,0,0,10
	dc.l box5,0

boxA	dc.w 2,1
	dc.b 7,0,0,10
	dc.l box8,0


gadgebox dc.w -4,-2
	dc.b 7,0,0,10
	dc.l box6,gadgebox2

gadgebox2 dc.w -2,-1
	dc.b 0,0,0,10
	dc.l box7,0

boxit	dc.w -2,-1
	dc.b 1,0,0,10
	dc.l boxX,0


box6	dc.w 0,0,95,0,95,11,94,11,94,0,94,11,0,11,0,0,1,0,1,11
box7	dc.w 0,0,91,0,91,9,90,9,90,0,90,9,0,9,0,0,1,0,1,9
boxX	dc.w 0,0,83,0,83,10,82,10,82,0,82,10,0,10,0,0,1,0,1,10

box4	dc.w 0,0,rwidth-1,0,rwidth-1,rhite-1
	dc.w rwidth-2,rhite-1,rwidth-2,0,rwidth-2,rhite-1
	dc.w 0,rhite-1,0,0,1,0,1,rhite-1

box5	dc.w 0,0,rwidth-9,0,rwidth-9,rhite-5
	dc.w rwidth-10,rhite-5,rwidth-10,0,rwidth-10,rhite-5
	dc.w 0,rhite-5,0,0,1,0,1,rhite-5

box8	dc.w 0,0,fwidth-5,0,fwidth-5,fhite-3
	dc.w fwidth-6,fhite-3,fwidth-6,0,fwidth-6,fhite-3
	dc.w 0,fhite-3,0,0,1,0,1,fhite-3


	even

reqtext1 dc.b 7,0,0,0
	dc.w 20,10
	dc.l font2,text11,reqtext2

reqtext2 dc.b 7,0,0,0
	dc.w 20,30
	dc.l font2,text12,0

welldone1 dc.b 3,0,0,0
	dc.w 46,10
	dc.l font2,text13,welldone2

welldone2 dc.b 7,0,0,0
	dc.w 0,29
	dc.l font2,text14,welldone3

welldone3 dc.b 7,0,0,0
	dc.w 0,45
	dc.l font2,text15,0

more	dc.b 1,4,1,0
	dc.w 0,0
	dc.l font2,text16,0

cancel	dc.b 1,4,1,0
	dc.w 0,0
	dc.l font2,text17,0


lineoftext dc.b 1,0,0,0
	dc.w 0,0
	dc.l 0,0,0


textgadget dc.l 0
	dc.w 81,50,96,8
ongadge	dc.w 0,$0005,$1004	* STRGADGET
	dc.l gadgebox,0,textspace,0,stringinfo
	dc.w 0,0,0

stringinfo dc.l 0,0
	dc.w 0,11,0,0,0,10,0,0
	dc.l 0,0,0

moregadget dc.l 0
	dc.w 70
y7	dc.w 226,80,9
	dc.w 0,$0001,$0001	* RELVERIFY,BOOLGADGET
	dc.l boxit,0,more,0,0
	dc.w 1,0,0

cancelgadget dc.l 0
	dc.w 490
y8	dc.w 226,80,9
	dc.w 0,$0001,$0001	* RELVERIFY,BOOLGADGET
	dc.l boxit,0,cancel,0,0
	dc.w 2,0,0
 

rleft	equ 181
rtop	equ 90
rwidth	equ 278
rhite	equ 82

highreq	dc.l 0
	dc.w rleft,rtop,rwidth,rhite,0,0
	dc.l textgadget
	dc.l box2
	dc.l reqtext1
	dc.w 0
	dc.b 1,0
	dc.l 0
	ds.b 32
	dc.l 0,0
	ds.b 36

fleft	equ 171
ftop	equ 90
fwidth	equ 298
fhite	equ 62


welldonereq dc.l 0
	dc.w fleft,ftop,fwidth,fhite,0,0
	dc.l 0
	dc.l boxA
	dc.l welldone1
	dc.w 0
	dc.b 1,0
	dc.l 0
	ds.b 32
	dc.l 0,0
	ds.b 36

iorequest dc.l 0,0
	dc.b 5,127
	dc.l 0

	dc.l replyport
	dc.w 0

	dc.l 0,0
	dc.w 0
	dc.b 0,0

	dc.w 0
	dc.l data
	dc.l 4
	dc.w 0,0,0
	ds.b $14

data	dc.b 3,5,10,12

replyport dc.l 0,0
	dc.b 4,0
	dc.l 0

	dc.b 0
signal	dc.b 0
task	dc.l 0

first	dc.l next
next	dc.l 0
	dc.l first
	dc.b 0,0
	
	even

hiscores
	dc.b " 1st ** Pete **",0,$2c,$b9
	dc.b " 2nd Chris     ",0,$1f,$e9
	dc.b " 3rd Mac.A     ",0,$0d,$91
	dc.b " 4th Plake     ",0,$09,$70
	dc.b " 5th Mike.T    ",0,$06,$73
	dc.b " 6th Moguls    ",0,$05,$bd
	dc.b " 7th Arnie     ",0,$05,$6e
	dc.b " 8th Lloydy    ",0,$04,$e2
	dc.b " 9th Ruthie    ",0,$03,$d9
	dc.b "10th Michaela  ",0,$02,$86
	dc.b "11th Rich      ",0,$02,$18
	dc.b "12th Farmerama ",0,$01,$ee
	dc.b "13th Helmet    ",0,$01,$8b
	dc.b "14th Brian     ",0,$01,$1b
	dc.b "15th Monster   ",0,$00,$7f
	ds.b 30



lastscr	dc.b "Last score "
lastscr2 dc.b "0",0,0,0,0,0,0

gamespld dc.b "Games played "
gamespld2 dc.b "0",0,0,0,0,0,0

loadbuffer ds.l 3
name1	dc.b "Klondike",0
name2	dc.b "Game",0
name3	dc.b "Options",0
name4	dc.b "Help!",0

text1	dc.b "About",0
text1b	dc.b "Versions",0
text1c	dc.b "Credits",0
text2	dc.b "Quit",0
text3	dc.b "New game",0
text4	dc.b "End game",0
text5	dc.b "  Colour monitor",0
text6	dc.b "  Mono monitor",0
text6b	dc.b "  Reset Hi-Scores",0
text6c	dc.b " Sure ? ",0
text6d	dc.b "  Merge Hi-Scores",0
text6e	dc.b "  PAL",0
text6f	dc.b "  NTSC",0
text6g	dc.b "  Face Graphics",0
text6h	dc.b "  Back Graphics",0
text6i	dc.b "  Symbol Graphics",0
text7	dc.b "Klondike rules",0
text8	dc.b "Playing the game",0
text9	dc.b "Scoring",0
text9b	dc.b "Hi-Score merging",0
text10	dc.b "Klondike Champions",0
text11	dc.b "G R E A T   S C O R E",0
text12	dc.b "Please type your name",0
text13	dc.b "N I C E   O N E   ! !",0
text14	dc.b "Time taken = "
time	ds.b 12
text15	dc.b "Bonus = "
bonus	ds.b 7
text16	dc.b "  More  ",0
text17	dc.b " Cancel ",0
text18	dc.b "  Done  ",0
mtextA	dc.b "** Merge Hi-Scores **",0
mtextB	dc.b " Location of ",34,"Hi-Scores",34," file : ",0
mtextC	dc.b "                                ",0
mergename dc.b "df0:Klondike",0
	ds.b 38		* 50-length of above text
mtextD	dc.b "    Searching....   ",0
mtextE	dc.b "Can't find directory",0
mtextF	dc.b "  Can't find file   ",0
mtextG	dc.b "     Found file     ",0
mtextH	dc.b "Insert disk containing Hi-Scores",0
mtextI	dc.b "   PANIC   ",0
mtextJ	dc.b " Done it ! ",0
mtextK	dc.b "  Merge !  ",0
mtextL	dc.b " Give up ! ",0
mtextM	dc.b "  Cancel!  ",0
mtextN	dc.b "Aaaargh Read Error !",0
mtextO	dc.b "   Retry   ",0
mtextP	dc.b "Replace original Klondike disk !",0
mtextQ	dc.b "Merging is complete !",0

fontype dc.b "topaz.font",0
wndtitle dc.b "         ** Klondike Version 1.3 - Written by Peter Wiseman (C) 1992 **",0
scoretext dc.b "Score "
storage	ds.b 12

dosname dc.b "dos.library",0
intname dc.b "intuition.library",0
grafname dc.b "graphics.library",0

device	dc.b "audio.device",0
filename1 dc.b "CardGraphics",0
filename2 dc.b "Hi-Scores",0
filename3 dc.b "Sounds",0
facedir	dc.b "Card Faces",0
backdir	dc.b "Card Backs",0
symbolsdir dc.b "Card Symbols",0

helptext1	
	dc.b 32,0,"                *****   K L O N D I K E   R U L E S   ***** ",0,32,0
	dc.b "      Games of patience are known in  America as  solitaires, a "
	dc.b "much better name, as they are meant to be played by a single player."
	dc.b " There are hundreds of different games of  card patience.  One of the "
	dc.b "most popular is Klondike, so much so that to most people the word "
	dc.b "patience means Klondike. ",0,32,0
	dc.b "      The game is played  with a standard pack of 52 cards.  A row of seven "
	dc.b "cards is dealt face down followed by a row of six, five and so on "
	dc.b "producing seven columns consisting of one , two , three , four , five , "
	dc.b "six and seven cards.  The top card in each column is turned face up, "
	dc.b "the rest remain face down. These 28 cards make up what is known "
	dc.b "as the tableau. ",0,0
	dc.b "      The game now commences.  Any face up aces are placed  somewhere"
	dc.b " above the tableau to form the  foundations.  Foundations are built "
	dc.b "on by cards of ascending value  and of similar suits.  For example "
	dc.b " once the ace of hearts has been placed above the tableau as a "
	dc.b "foundation  the two of hearts can be placed on top of it if available "
	dc.b "followed by the three of hearts and so on. The game is won  if all "
	dc.b "four foundations  are built up to their  respective suits kings. ",0,32,0

	dc.b "     There are two ways in which cards can be moved from the tableau. "
	dc.b "First the lowest face up card in each of the seven columns can be played "
	dc.b "onto the foundations or "
	dc.b "to another column  creating a series of alternating  colours and decreasing "
	dc.b "values. For examples a six of hearts or diamonds (red suits) can be "
	dc.b "placed on a seven of spades or clubs (black suits)  or a black queen "
	dc.b "can be played onto a red king. Secondly a whole column of face up cards "
	dc.b "can by moved as a single unit providing its destination column retains "
	dc.b "its red, black, red ascending values sequence.  Face down tableau "
	dc.b "cards uncovered by  movement of a single card or column  are turned face up."
	dc.b "  Kings or columns headed by kings can be moved into empty columns. ",0,0

	dc.b "     When no more columns or single cards can be repositioned , three cards"
	dc.b " from the deck are turn face up onto a  ",34,"waste pile",34,".  The uppermost card of" 
	dc.b " this pile may be  played onto the  tableau  or  foundations making the card"
	dc.b " below available.  Another three cards are turned over from the deck when no"
	dc.b " more cards can be played followed by another three  until the deck has been"
	dc.b " passed.   At this point the whole  ",34,"waste pile",34,"  is turned over and redealt"
	dc.b " three at a time. ",0,32,0

	dc.b "   The game is over when the deck has been passed without playing a card."

	dc.b 32,0,0,0

helptext2 dc.b 254,0,"              *****   P L A Y I N G   T H E   G A M E   ***** ",0,32,0
	dc.b "    To start the game press the right mouse button and select NEW GAME from"
	dc.b " the GAME menu.  The pack will then be shuffled and  28 cards  dealt to form"
	dc.b " the tableau.  The rest of the pack is displayed face down above the tableau"
	dc.b " with outlines of the empty foundations to either side. ",0,32,0
	
	dc.b "    Amiga  Klondike  is entirely mouse controlled  resulting in a very fast"
	dc.b " and user-friendly method of moving cards.   This is achieved by positioning"
	dc.b " the pointer over a card , pressing the left mouse button and whilst keeping"
	dc.b " the button pressed the card can be dragged around the screen. When the card"
	dc.b " touches a valid destination it is highlighted in grey  and on releasing the"
	dc.b " mouse button the card is repositioned.If you are dragging a card and decide"
	dc.b " you don't  really want to move it  then find a position  where no cards are"
	dc.b " highlighted  and release the mouse button.  The card will then jump back to"
	dc.b " its original position. ",0,0
	dc.b 254,0,"    Whole columns may be moved  by clicking on the highest upturned card and"
	dc.b " dragging.  Any face down  tableau cards  revealed by moving other cards are"
	dc.b " turned over by clicking on them once.Clicking is also used to turn the next"
	dc.b " three cards in the deck or to redeal after each pass. ",0,32,0

	dc.b "    If you are still unsure about the rules of Klondike then the best thing"
	dc.b " to do is simply start up a new game. The computer won't let you do anything"
	dc.b " illegal so you'll soon get the hang of how to play. Refer to the HELP menus"
	dc.b " if you're unsure about anything. ",0,32,0
	dc.b "    Unlike normal Klondike , Amiga Klondike is played against the clock. As"
	dc.b " the seconds tick by your score decreases. The bonus awarded for a completed"
	dc.b " game is also based on the time taken resulting in more skill being required"
	dc.b " as you race against the clock.  When you decide  that no more cards  can be" 
	dc.b " played you must select  END GAME  from under the  GAME menu as the computer" 
	dc.b " can't make this decision for you.  Enjoy playing Klondike ! ",0,0,0

helptext3 dc.b 254,0,"                      *****   S C O R I N G   ***** ",0,32,0
	dc.b "Turning over a face down tableau card ........  + 25 Points  ( Max = 525 )"
	dc.b " Playing a card from the deck to tableau ......  + 45 Points  ( Max = 1080 )"
	dc.b " Adding a card to the foundations .............  + 60 Points  ( Max = 3120 ) ",0,254,0,32,0
	dc.b "Every second of elapsed time .................................   - 1 Point"
	dc.b " Moving one card from a face up column to another column ......  - 25 Points"
	dc.b " Moving a foundation card back to the tableau .................  - 75 Points"
	dc.b " Each pass through the deck after the third pass .............. - 125 Points ",0,254,0,32,0

	dc.b "If the game is completed , a bonus is calculated in the following way : ",0,32,0
	dc.b "Bonus = [ End of game score - ( Time taken * 5 ) ] * 2 ",0,32,0
	dc.b "Since the maximum end of game score possible is 4725 then assuming no time"
	dc.b " was taken , the largest bonus would be 9450 ! ",0,0,0

helptext4	
	dc.b 254,0,"             *****   M E R G I N G   H I - S C O R E S   ***** ",0,254,0,32,0
	dc.b "    To increase the playability of Klondike a ",34,"Merge Hi-Scores",34," feature has ",0
	dc.b " been added. This enables scores saved on another disk ( eg a friend's ) to ",0
	dc.b " be merged into your own hi-score table. ",0,32,0
	dc.b " The proceedure is quite simple : ",0,32,0
	dc.b "    [1] Select ",34,"MERGE HI-SCORES",34," from under the ",34,"OPTIONS",34," menu. ",0
	dc.b "    [2] Replace your Klondike disk with a friends Klondike disk. ",0
	dc.b "    [3] Click in the ",34,"Done it",34," box. ",0
	dc.b "    [4] The computer will attempt to load the ",34,"Hi-Scores",34," file and if ",0
	dc.b "        successful will prompt you to select the ",34,"MERGE",34," box to proceed. ",0
	dc.b "    [5] Replace your Klondike disk so the new hi-score table can be saved. ",0,32,0
	dc.b " The above assumes the  ",34,"Hi-Scores",34,"  file to be merged  is located in its ",0
	dc.b " usual directory ",34,"df0:Klondike",34,". If not you will have to edit the textbox ",0
	dc.b " to let the computer know where it is located. ",0,0,0

versionstext
	dc.b 32,0,254,0,"             *****   K L O N D I K E   V E R S I O N S   ***** ",0,32,0,32,0
	dc.b 254,0,"V1.0  : The first complete version of Klondike. I only had 1/2 meg then and ",0
	dc.b "        was soon informed that this version didn't work on expanded Amigas. ",0,32,0
	dc.b "V1.1  : Modified to work on expanded Amigas. ",0,32,0
	dc.b "V1.1b : All relevent files are now in the ",34,"Klondike",34," directory (No need for ",0
	dc.b "        Xicon, Run, EndCli etc in the 'C' directory).  The program searches ",0
	dc.b "        for files in its own  directory  so there is no need to use ASSIGN. ",0
	dc.b "        ",34,"Clear Hi-Scores",34," menu and "
	dc.b 34,"number of games played",34,"  feature added. ",0
	dc.b "        Minor bug fixed to prevent a column being placed on the foundations ",0,32,0
	dc.b "V1.1c : NTSC option added for USA. Credits menu added. ",0,0
	dc.b 32,0,32,0,"V1.2  : ",34,"Merge Hi-Scores",34," menu with Help page and this screen added. ",0
	dc.b "        A new Hi-Score of 11449 to beat (Genuine , honest !) ",0,32,0
	dc.b "V1.21 : Bug fixed occurring in V1.2 that caused the game to crash ",0
	dc.b "        occasionally on completing the game. ",0,32,0
	dc.b "V1.22 : Jerky card movement, when booting from my hard drive, fixed. ",0,32,0
	dc.b "V1.3  : Options to load different card graphics added. ",0,32,0,32,0
	dc.b "              Latest version released on 3rd September 1992. ",0,0,0 



creditstext dc.b 254,0,254,0,"                       *****   C R E D I T S   ***** ",0,32,0,254,0
	dc.b "      The Amiga versions of Klondike were written by : ",0,32,0
	dc.b "                       Peter Wiseman, ",0
	dc.b "                        30 Coronation Drive, ",0
	dc.b "                         Penketh, ",0
	dc.b "                          Warrington, ",0
	dc.b "                           Cheshire, ",0
	dc.b "                            WA5 2DD, ",0
	dc.b "                             ENGLAND. ",0,32,0,254,0
	dc.b "      Special thanks go to Michael Casteel of SunnyVale, California for ",0
	dc.b "      the idea from his shareware version of Klondike on the Apple Mac. ",0,32,0
	dc.b "      Dankeschoen to Tobias Ferber from Baden-Baden, Germany for his ",0
	dc.b "      card graphics and inspiring the modifications in version 1.3. ",0,0,0


abouttext
	dc.b 32,0,"        Klondike was written by Peter Wiseman a poor , penniless student ",0
	dc.b "   his feeble grant spent , beer glass empty  and in desperate need of a ",0
	dc.b "   few notes.So if you like this game then please show your appreciation ",0
	dc.b "   by sending a small donation to the  ",34,"Help a Skint Student Fund",34," whose ",0
	dc.b "   address will be revealed below , and maybe I'll be motivated to write ",0
	dc.b "   some more stunning Amiga programs.   Any amount will help remedy this ",0
	dc.b "   pitiful situation: one pound, five pounds; foreign currency will also ",0
	dc.b "   be gratefully received  and in  return  I'll have a really wild night ",0
	dc.b "   out !   I'll also send you some PD software and any new card graphics ",0
	dc.b "   that I have, including the stunning ",34,"Lemmings",34," card set. ",0
	dc.b "   Please tell the truck driver carrying your wads of dosh to deliver to ",0,32,0
	dc.b "   30 Coronation Drive, Penketh, Warrington, Cheshire, WA5 2DD, England. ",0,255,32,0
	dc.b "   If you don't like this game then you bloody well should do.  I didn't ",0
	dc.b "   spend all those hundreds of hours trying to understand the garbage in ",0
	dc.b "   over a hundred quids worth of  Rom Kernal  Manuals  so you could moan ",0
	dc.b "   about how you dont like card games and prefer a good game of Kick Off ",0
	dc.b "   So how about it ?  Go on , dig deep and be generous ..... ",0,32,0
	dc.b "                                            ..... Signed Pete the Scav. ",0,0,0

message	dc.b "                     H.M. GOVERNMENT HEALTH WARNING ! : ",0
	dc.b "                KLONDIKE CAN SERIOUSLY DAMAGE YOUR HEALTH ! ",0,32,0
message2 dc.b "ADDICTION (a'-dikt-shon) n. the condition of being abnormally dependent on ",0
	dc.b "some habit  esp. compulsive  dependency on computer  card games written by ",0
	dc.b "poor skint students. ",0,32,0
	dc.b "   The author is aware of the dangerously high level of addiction Klondike ",0
guilty1	dc.b "can cause in certain susceptible individuals and has noticed that            ",0
	dc.b "is rapidly approaching a state of hopeless addiction ! ",0,254,0
	dc.b "   Governent Health Officials  have traced the permanent hi-score table to ",0
	dc.b "be responsible for this  desperate  situation  and as a result it has been ",0
	dc.b "removed from view.  This may cause an initial feeling  of emptiness but it ",0
guilty2	dc.b "is for your own good             ",0
	dc.b "   Sweaty palms,sulking,digging out old packs of playing cards and frantic ",0
	dc.b "pawing at the screen mumbling ",34,"Just one more go",34,"  are all classic klondike ",0
	dc.b "withdrawal symptoms. If any of these persist for more than three days then ",0
	dc.b "you will need to seek help from Klondikers Anonymous. Send donations to : ",0,32,0
	dc.b "PETER WISEMAN : 30 CORONATION DRIVE, PENKETH, WARRINGTON, WA5 2DD, ENGLAND ",0,32,0
	dc.b "and in return  you will  receive the full game which  doesn't include this ",0 
	dc.b "annoying message and you can play to your heart's content ! ",0,0,0,0


