gosub initialise
gosub mainloop
exit

rem ##################################
label mainloop
 repeat

rem Insertion Point 25
  gosub titlescreen
  gosub mainmenu
 until (1=2)
return

rem Insertion Point 26
rem #####################################################
label titlescreen
 oldjoypad=joypad
 cont=0
 fade=0:fadedir=10
 poke "textalign","cc"
 for a=1 to numtgem
  tgemx(a)=ran(580)
  tgemy(a)=ran(400)-400
  tgemp(a)=int(ran(4))+1

  tgems(a)=int(ran(5))+2
 next a

 repeat
  gosub flipscreen
  gosub background

  for a=1 to numtgem
   x1=tgemx(a)
   y1=tgemy(a)
   piece=tgemp(a)
   gosub drawpiece
   y1=y1+tgems(a)
   if y1>560 then
    y1=y1-600
    tgemx(a)=ran(580)
    tgemp(a)=int(ran(4))+1
    tgems(a)=int(ran(5))+2
   fi
   tgemy(a)=y1
  next a

  setrgb 1,0,0,0
  for x=-2 to 2 step 4
   for y=-2 to 2 step 4
    text 320+x,256+y,"'Gemocide'"
    text 320+x,290+y,"(c) Marc Gale (Xalthorn) 2002"
   next y
  next x
  setrgb 1,255,255,255
  text 320,256,"'Gemocide'"
  text 320,290,"(c) Marc Gale (Xalthorn) 2002"

  setrgb 1,fade,fade,fade
  text 320,324,"Press any button to start"
  joypad=peek("port1")
  if joypad<>oldjoypad then
   if joypad>0 then
    cont=1
   else
    oldjoypad=joypad
   fi
  fi

  fade=fade+fadedir
  if fade>255 or fade<0 then fadedir=-fadedir fi
 until (cont=1)
return

rem Insertion Point 22
rem #####################################################
label mainmenu
 oldjoypad=joypad
 cont=0
 option=1
 poke "textalign","cc"
 repeat
  gosub flipscreen
  gosub background

  x1=290:y1=option*50+165
  piece=option
  gosub drawpiece

  setrgb 1,0,0,0
  for x=-2 to 2 step 4
   for y=-2 to 2 step 4
    text 320+x,40+y,"'Gemocide'"
    text 320+x,70+y,"(c) Marc Gale (Xalthorn) 2002"
    text 320+x,200+y,"Return to Title Screen"
    text 320+x,250+y,"Instructions"
    text 320+x,300+y,"Start Game"
   next y
  next x
  setrgb 1,255,255,255
  text 320,40,"'Gemocide'"
  text 320,70,"(c) Marc Gale (Xalthorn) 2002"
  text 320,200,"Return to Title Screen"
  text 320,250,"Instructions"
  text 320,300,"Start Game"

  joypad=peek("port1")
  if joypad<>oldjoypad then
   if and(joypad,16384)>0 then
    if option=1 then
     cont=1
    fi
    if option=2 then
     gosub instructions
    fi
    if option=3 then
     gosub gameloop
    fi
    poke "textalign","cc"
    oldjoypad=joypad
   else
    if and(joypad,16)>0 and option>1 then
     option=option-1
    fi
    if and(joypad,64)>0 and option<3 then
     option=option+1
    fi
    oldjoypad=joypad
   fi
  fi
 until (cont=1)
return

rem #####################################################
label instructions
  poke "textalign","lb"
  setdispbuf curbuf
  setdrawbuf curbuf

  gosub background

  setrgb 1,0,0,0
  line 50,60 to 600,60

  setrgb 1,0,0,0
  for x=-1 to 1 step 2
   for y=-1 to 1 step 2
    text 50+x,50+y,"Gemocide - Copyright Marc Gale (Xalthorn) 2002"
   next y
  next x
  setrgb 1,255,255,255
  text 50,50,"Gemocide - Copyright Marc Gale (Xalthorn) 2002"

  for a=1 to instructlines
    if in$(a)<>"" then
      for b=1 to len(in$(a))
        setrgb 1,100,50,0
        for x=-1 to 1 step 2
         for y=-1 to 1 step 2
          text b*12+50+x,a*18+70+y,mid$(in$(a),b,1)
         next y
        next x
        setrgb 1,200,200,0
        text b*12+50,a*18+70,mid$(in$(a),b,1)
        buttons=or(peek("port1"),peek("port2"))
        if buttons=0 then
          wait 0.1
        fi
        if buttons=4096 then
         a=instructlines
         b=len(in$(a))
        fi
      next b
    fi
  next a

  setrgb 1,255,255,255
  text 320,490,"Press the X button for the main menu","cc"

  repeat
   joypad=peek("port1")
  until (joypad=0)
  repeat
    joypad=peek("port1")
  until (and(joypad,16384)=16384)
return

rem #####################################################
label setupinstructions
 instructlines=22
 dim in$(instructlines)
 for a=1 to instructlines
  in$(a)=""
 next a

 in$(1)="The aim of Gemocide is to place a gem into "
 in$(2)="each of the gem receptacles (wireframe gems)."
 in$(3)="The gems are selected by moving the flashing"
 in$(4)="cursor over the gem and pressing the X button."
 in$(5)="When a gem is selected, the flashing cursor "
 in$(6)="changes colour to match the gem.  To unselect"
 in$(7)="a gem, press X again."
 in$(9)="To move a gem, select it and then press one of "
 in$(10)="the direction buttons.  The gem will then "
 in$(11)="move across the board until it hits something"
 in$(12)="or the edge of the board."
 in$(14)="When a gem collides with something else, it "
 in$(15)="might cause an effect.  All of the effects can"
 in$(16)="be shown whilst playing by pressing the L1 "
 in$(17)="button, but a quick summary follows."
 in$(19)="Gem hits another gem of the same colour, the "
 in$(20)="target gem is upgraded, and the original gem"
 in$(21)="is destroyed.  The upgrade order is yellow to"
 in$(22)="green to red to blue to yellow."
return


rem #####################################################
label startmenu
 choice=1:done=0
 repeat
  gosub flipscreen
  setrgb 1,0,0,255
  setrgb 2,100,100,255
  setrgb 3,100,100,255
  gtriangle 200,400 to 200,100 to 450,100
  setrgb 3,0,0,255
  gtriangle 200,400 to 450,100 to 450,400
  setrgb 1,0,0,0
  rectangle 200,100 to 450,400

  x1=290:y1=choice*50+165
  piece=choice
  gosub drawpiece

  setrgb 1,0,0,0
  for x=-2 to 2 step 4
   for y=-2 to 2 step 4
    text 320+x,200+y,"Return to Game"
    text 320+x,250+y,"Restart Level"
    text 320+x,300+y,"Quit Game"
   next y
  next x
  setrgb 1,255,255,255
  text 320,200,"Return to Game"
  text 320,250,"Restart Level"
  text 320,300,"Quit Game"

  joypad=peek("port1")
  if joypad<>oldjoypad then
   if and(joypad,16384)>0 then
    if choice=1 then
     done=1
    fi
    if choice=2 then
     gosub buildlevel
     done=1
    fi
    if choice=3 then
     quit=1
     done=1
    fi
    oldjoypad=joypad
   else
    if and(joypad,16)>0 and choice>1 then
     choice=choice-1
    fi
    if and(joypad,64)>0 and choice<3 then
     choice=choice+1
    fi
    oldjoypad=joypad
   fi
  fi
 until (done=1)
return

rem #####################################################
label gameloop
 level=1
 quit=0
 repeat
  gosub buildlevel
  repeat
   gosub flipscreen
   gosub background
   gosub drawboard

   poke "textalign","cc"
   setrgb 1,255,255,255

   text 320,450,l$

   cb=cb+cbd
   if cb<0 or cb>255 then cbd=-cbd fi

   if slide=0 then
    gosub processinput
   else
    gosub movepiece
   fi
   if moved=0 then
    cdelay=cdelaybase
    cwait=0
   fi
   if cwait>0 then cwait=cwait-1 fi
  until (numout=0 or quit=1)
  if numout=0 then
   gosub background
   cx=0:cy=0
   gosub drawboard
   repeat
    joypad=peek("port1")
   until (joypad=0)
   poke "textalign","cc"
   setrgb 1,255,255,255
   leveldone(level)=moves
   g$="Well done, you completed the level in "
   g$=g$+str$(leveldone(level))
   g$=g$+" moves."
   text 320,475,g$
   text 320,500,"Press any button for the next level"
   setdispbuf curbuf
   repeat
    joypad=peek("port1")
   until (joypad>0)
  fi
  level=level+1
  if level>maxlevels then
   level=1
  fi
 until (quit=1)
return


rem ##################################
label background
 setrgb 1,0,0,255
 setrgb 2,100,100,255
 setrgb 3,100,100,255
 gtriangle 0,512 to 0,0 to 640,0
 setrgb 3,0,0,255
 gtriangle 0,512 to 640,0 to 640,512
return

rem Insertion Point 19
rem #####################################################
label buildlevel
 l$="Level "+str$(level)+" of "+str$(maxlevels)
 if leveldone(level)>0 then
  l$=l$+" (Completed in "+str$(leveldone(level))+" moves)"
 fi

 moves=0
 numcom=levelc(level)
 for y=1 to 10
  for x=1 to 10
   board(x,y)=0
  next x
 next y

 numout=0
 for a=1 to numcom
  x=levels(level,a,1)
  y=levels(level,a,2)
  p=levels(level,a,3)
  board(x,y)=p
  if p>100 then
   numout=numout+1
  fi
 next a

 cx=5:cy=5
return
rem Insertion Point 17
rem #####################################################
label collision
 target=board(ttx,tty)

 if piece=target then
  board(tx,ty)=0
  target=target+1
  if target=5 then target=1 fi
  board(ttx,tty)=target
  cx=ttx:cy=tty
  return
 fi

 if piece=target-100 then
  board(tx,ty)=0
  board(ttx,tty)=0
  numout=numout-1
  cx=ttx:cy=tty
  return
 fi

 if piece=1 and target<100 then
  board(tx,ty)=0
  target=target-1
  board(ttx,tty)=target
  cx=ttx:cy=tty
  return
 fi

 if piece=2 and target<100 then
  board(tx,ty)=board(ttx,tty)
  board(ttx,tty)=piece
  cx=ttx:cy=tty
  return
 fi

 if piece=3 and target=100 then
  board(tx,ty)=0
  board(ttx,tty)=0
  cx=ttx:cy=tty
  return
 fi

 if piece=4 and target<100 then
  board(tx,ty)=target
  return
 fi
return

rem #####################################################
label movepiece
 piece=board(tx,ty)
 ttx=tx+txd:tty=ty+tyd
 if ttx<1 or ttx>10 or tty<1 or tty>10 then
  slide=0
  cx=tx:cy=ty
  selection=0
  return
 fi

 if board(ttx,tty)>0 then
  slide=0
  cx=tx:cy=ty
  selection=0
  gosub collision
  return
 fi

 board(tx,ty)=0
 board(ttx,tty)=piece
 tx=ttx:ty=tty
return
rem Insertion Point 16
rem #####################################################
label processinput
 joypad=peek("port1")
 moved=0

 if and(joypad,16)>0 and cy<10 then
  if cwait>0 then
   cwait=cwait-1
   cdelay=cdelay-1
   moved=1
  else
   if selection=0 then
    cy=cy+1
    moved=1
    cwait=cdelay
   else
    tx=cx:ty=cy:cx=0:cy=0
    slide=1:moves=moves+1
    txd=0:tyd=1
   fi
  fi
 fi

 if and(joypad,32)>0 and cx<10 then
  if cwait>0 then
   cwait=cwait-1
   cdelay=cdelay-1
   moved=1
  else
   if selection=0 then
    cx=cx+1
    moved=1
    cwait=cdelay
   else
    tx=cx:ty=cy:cx=0:cy=0
    slide=1:moves=moves+1
    txd=1:tyd=0
   fi
  fi
 fi

 if and(joypad,64)>0 and cy>1 then
  if cwait>0 then
   cwait=cwait-1
   cdelay=cdelay-1
   moved=1
  else
   if selection=0 then
    cy=cy-1
    moved=1
    cwait=cdelay
   else
    tx=cx:ty=cy:cx=0:cy=0
    slide=1:moves=moves+1
    txd=0:tyd=-1
   fi
  fi
 fi

 if and(joypad,128)>0 and cx>1 then
  if cwait>0 then
   cwait=cwait-1
   cdelay=cdelay-1
   moved=1
  else
   if selection=0 then
    cx=cx-1
    moved=1
    cwait=cdelay
   else
    tx=cx:ty=cy:cx=0:cy=0
    slide=1:moves=moves+1
    txd=-1:tyd=0
   fi
  fi
 fi

rem Insertion Point 18
 if and(joypad,16384)>0 then
  if selection>0 then 
   selection=0
  else
   if board(cx,cy)>0 and board(cx,cy)<100 then
    selection=board(cx,cy)
   fi
  fi
  repeat
   joypad=peek("port1")
  until (and(joypad,16384)=0)
 fi

rem Insertion Point 20
 if and(joypad,1024)>0 then
  gosub showhelp
  return
 fi
rem Insertion Point 23
 if and(joypad,8)>0 then
  gosub startmenu
  return
 fi
return

rem Insertion Point 21
rem #####################################################
label showhelp
 gosub background
 x1=20:y1=80:piece=1:gosub drawpiece
 x1=90:gosub drawpiece
 x1=160:piece=2:gosub drawpiece

 x1=20:y1=140:piece=2:gosub drawpiece
 x1=90:gosub drawpiece
 x1=160:piece=3:gosub drawpiece

 x1=20:y1=200:piece=3:gosub drawpiece
 x1=90:gosub drawpiece
 x1=160:piece=4:gosub drawpiece

 x1=20:y1=260:piece=4:gosub drawpiece
 x1=90:gosub drawpiece
 x1=160:piece=1:gosub drawpiece

 x1=20:y1=320:piece=1:gosub drawpiece
 x1=90:piece=2:gosub drawpiece
 x1=160:piece=1:gosub drawpiece

 x1=20:y1=380:piece=1:gosub drawpiece
 x1=90:piece=3:gosub drawpiece
 x1=160:piece=2:gosub drawpiece

 x1=20:y1=440:piece=1:gosub drawpiece
 x1=90:piece=4:gosub drawpiece
 x1=160:piece=3:gosub drawpiece

 x1=320:y1=80:piece=4:gosub drawpiece
 x1=390:piece=1:gosub drawpiece
 x1=460:gosub drawpiece
 x1=510:gosub drawpiece

 x1=320:y1=140:piece=4:gosub drawpiece
 x1=390:piece=2:gosub drawpiece
 x1=460:gosub drawpiece
 x1=510:gosub drawpiece

 x1=320:y1=200:piece=4:gosub drawpiece
 x1=390:piece=3:gosub drawpiece
 x1=460:gosub drawpiece
 x1=510:gosub drawpiece

 x1=320:y1=260:piece=2:gosub drawpiece
 x1=390:piece=1:gosub drawpiece
 x1=460:gosub drawpiece
 x1=510:piece=2:gosub drawpiece

 x1=320:y1=320:piece=2:gosub drawpiece
 x1=390:piece=3:gosub drawpiece
 x1=460:gosub drawpiece
 x1=510:piece=2:gosub drawpiece

 x1=320:y1=380:piece=2:gosub drawpiece
 x1=390:piece=4:gosub drawpiece
 x1=460:gosub drawpiece
 x1=510:piece=2:gosub drawpiece

 x1=320:y1=440:piece=3:gosub drawpiece
 x1=390:piece=100:gosub drawpiece
 x1=460:gosub drawpiece

 x1=20:y1=500:piece=1:gosub drawpiece
 x1=90:piece=101:gosub drawpiece

 x1=180:y1=500:piece=2:gosub drawpiece
 x1=250:piece=102:gosub drawpiece

 x1=340:y1=500:piece=3:gosub drawpiece
 x1=410:piece=103:gosub drawpiece

 x1=500:y1=500:piece=4:gosub drawpiece
 x1=570:piece=104:gosub drawpiece

 setrgb 1,255,255,255
 text 118,65,"+      ="
 text 118,125,"+      ="
 text 118,185,"+      ="
 text 118,245,"+      ="
 text 118,305,"+      ="
 text 118,365,"+      ="
 text 118,425,"+      ="
 text 418,65,"+      ="
 text 418,125,"+      ="
 text 418,185,"+      ="
 text 418,245,"+      ="
 text 418,305,"+      ="
 text 418,365,"+      ="
 text 418,425,"+      ="
 text 495,435,"X"
 text 85,485,"to"
 text 245,485,"to"
 text 405,485,"to"
 text 565,485,"to"

 setrgb 1,0,0,0
 line 0,460 to 640,460
 setdispbuf curbuf
 repeat
  joypad=peek("port1")
 until (joypad=0)
return
rem Insertion Point 8
rem #####################################################
label drawboxback
 cbr=selectr(selection)
 cbg=selectg(selection)
 cbb=selectb(selection)
 setrgb 1,cb*cbr,cb*cbg,cb*cbb
 fill triangle x1,y1 to x1,y1-40 to x1+30,y1-55
 fill triangle x1,y1 to x1+30,y1-55 to x1+30,y1-15
 fill triangle x1+30,y1-15 to x1+30,y1-55 to x1+60,y1-40
 fill triangle x1+30,y1-15 to x1+60,y1-40 to x1+60,y1

 setrgb 1,0,0,0
 line x1,y1 to x1+30,y1-15
 line x1+30,y1-15 to x1+60,y1
 line x1+30,y1-25 to x1+30,y1-55
 line x1,y1-40 to x1+30,y1-55
 line x1+30,y1-55 to x1+60,y1-40
return

rem #####################################################
label drawboxfront
 setrgb 1,0,0,0
 line x1,y1 to x1,y1-40
 line x1+60,y1 to x1+60,y1-40
 line x1+30,y1+25 to x1+30,y1-25
 line x1,y1-40 to x1+30,y1-25
 line x1+30,y1-25 to x1+60,y1-40
return
rem Insertion Point 1
rem #####################################################
label drawgem
 setrgb 1,r1,g1,b1
 fill triangle x1+30,y1 to x1+22,y1-20 to x1+38,y1-20
 setrgb 1,r2,g2,b2
 fill triangle x1+30,y1 to x1+10,y1-25 to x1+22,y1-20
 setrgb 1,r3,g3,b3
 fill triangle x1+30,y1 to x1+50,y1-25 to x1+38,y1-20
 setrgb 1,r4,g4,b4
 fill triangle x1+10,y1-25 to x1+15,y1-33 to x1+25,y1-28
 fill triangle x1+10,y1-25 to x1+25,y1-28 to x1+22,y1-20
 setrgb 1,r5,g5,b5
 fill triangle x1+38,y1-20 to x1+35,y1-28 to x1+45,y1-33
 fill triangle x1+38,y1-20 to x1+45,y1-33 to x1+50,y1-25
 setrgb 1,r6,g6,b6
 fill triangle x1+22,y1-20 to x1+25,y1-28 to x1+35,y1-28
 fill triangle x1+22,y1-20 to x1+35,y1-28 to x1+38,y1-20
 setrgb 1,r7,g7,b7
 fill triangle x1+15,y1-33 to x1+25,y1-28 to x1+25,y1-36
 fill triangle x1+25,y1-28 to x1+25,y1-36 to x1+35,y1-36
 fill triangle x1+25,y1-28 to x1+35,y1-36 to x1+35,y1-28
 fill triangle x1+35,y1-28 to x1+35,y1-36 to x1+45,y1-33
return

rem Insertion Point 5
rem #####################################################
label drawsolid
  fill triangle x1+30,y1 to x1+10,y1-25 to x1+50,y1-25
  fill triangle x1+10,y1-25 to x1+15,y1-33 to x1+50,y1-25
  fill triangle x1+15,y1-33 to x1+25,y1-36 to x1+50,y1-25
  fill triangle x1+25,y1-36 to x1+35,y1-36 to x1+50,y1-25
  fill triangle x1+35,y1-36 to x1+45,y1-33 to x1+50,y1-25
return

rem #####################################################
label drawgemout
  triangle x1+30,y1 to x1+22,y1-20 to x1+38,y1-20
  triangle x1+30,y1 to x1+10,y1-25 to x1+22,y1-20
  triangle x1+30,y1 to x1+50,y1-25 to x1+38,y1-20
  line x1+10,y1-25 to x1+15,y1-33
  line to x1+25,y1-28
  line to x1+22,y1-20

  line x1+25,y1-28 to x1+35,y1-28
  line to x1+38,y1-20

  line x1+35,y1-28 to x1+45,y1-33
  line to x1+50,y1-25

  line x1+15,y1-33 to x1+25,y1-36
  line to x1+35,y1-36
  line to x1+45,y1-33
return

rem #####################################################
label drawblock
 setrgb 1,80,50,50
 fill triangle x1,y1 to x1,y1-25 to x1+30,y1-10
 fill triangle x1,y1 to x1+30,y1-10 to x1+30,y1+15

 setrgb 1,100,70,70
 fill triangle x1+30,y1+15 to x1+30,y1-10 to x1+60,y1-25
 fill triangle x1+30,y1+15 to x1+60,y1-25 to x1+60,y1

 setrgb 1,120,90,90
 fill triangle x1,y1-25 to x1+30,y1-40 to x1+30,y1-10
 fill triangle x1+30,y1-10 to x1+30,y1-40 to x1+60,y1-25
return

rem #####################################################
label drawpiece
 if piece=1 then
  r1=200:g1=200:b1=0
  r2=100:g2=100:b2=0
  r3=255:g3=255:b3=100
  r4=100:g4=100:b4=50
  r5=255:g5=255:b5=150
  r6=200:g6=200:b6=50
  r7=200:g7=200:b7=100
  gosub drawgem
  return
 fi

 if piece=2 then
  r1=0:g1=180:b1=0
  r2=0:g2=100:b2=0
  r3=100:g3=255:b3=100
  r4=50:g4=100:b4=50
  r5=150:g5=255:b5=150
  r6=50:g6=200:b6=50
  r7=100:g7=200:b7=100
  gosub drawgem
  return
 fi

 if piece=3 then
  r1=200:g1=0:b1=0
  r2=100:g2=0:b2=0
  r3=255:g3=100:b3=100
  r4=100:g4=50:b4=50
  r5=255:g5=150:b5=150
  r6=200:g6=50:b6=50
  r7=200:g7=100:b7=100
  gosub drawgem
  return
 fi

 if piece=4 then
  r1=0:g1=0:b1=200
  r2=0:g2=0:b2=100
  r3=100:g3=100:b3=255
  r4=50:g4=50:b4=100
  r5=150:g5=150:b5=255
  r6=50:g6=50:b6=200
  r7=100:g7=100:b7=200
  gosub drawgem
  return
 fi

rem Insertion Point 6
 if piece=100 then
  gosub drawblock
  return
 fi

 if piece=101 then
  setrgb 1,100,100,0
  gosub drawsolid
  setrgb 1,255,255,0
  gosub drawgemout
  return
 fi

 if piece=102 then
  setrgb 1,0,100,0
  gosub drawsolid
  setrgb 1,0,255,0
  gosub drawgemout
  return
 fi

 if piece=103 then
  setrgb 1,100,0,0
  gosub drawsolid
  setrgb 1,255,0,0
  gosub drawgemout
  return
 fi

 if piece=104 then
  setrgb 1,0,0,100
  gosub drawsolid
  setrgb 1,0,0,255
  gosub drawgemout
  return
 fi

return

rem ##################################
label drawboard
 for y=10 to 1 step -1
  for x=1 to 10

rem Insertion Point 9
   cursor=0
   if cx=x and cy=y then cursor=1 fi

   x1=x*30+y*30-40
   y1=x*15-y*15+250
   if mod(x+y,2)=0 then
    setrgb 1,150,150,150
   else
    setrgb 1,50,50,100
   fi

rem Insertion Point 10
   if cursor=1 then
    cbr=selectr(selection)
    cbg=selectg(selection)
    cbb=selectb(selection)
    setrgb 1,cb*cbr,cb*cbg,cb*cbb
   fi

   fill triangle x1,y1 to x1+30,y1-15 to x1+60,y1
   fill triangle x1,y1 to x1+60,y1 to x1+30,y1+15

rem Insertion Point 11
   if cursor=1 then
    gosub drawboxback
   fi
rem Insertion Point 2
   piece=board(x,y)
   if piece>0 then
    gosub drawpiece
   fi
rem Insertion Point 12
   if cursor=1 then
    gosub drawboxfront
   fi

  next x
 next y

 setrgb 1,50,50,100
 setrgb 2,50,50,100
 setrgb 3,0,0,50
 gtriangle 20,250 to 320,400 to 20,270
 gtriangle 320,400 to 620,250 to 320,420
 setrgb 1,0,0,50
 gtriangle 20,270 to 320,400 to 320,420
 gtriangle 320,420 to 620,250 to 620,270
return

rem ##################################
label flipscreen
 setdispbuf curbuf 
 curbuf=1-curbuf
 setdrawbuf curbuf
return

rem ##################################
label initialise
 curbuf=0
 open window 640,512

rem Insertion Point 3
 dim board(10,10)
 restore levels
 read maxlevels
 dim levels(maxlevels,100,3)
 dim levelc(maxlevels)
 dim leveldone(maxlevels)
 for level=1 to maxlevels
  read numpiece
  levelc(level)=numpiece
  for a=1 to numpiece
   for b=1 to 3
    read levels(level,a,b)
   next b
  next a
 next level

rem Insertion Point 13
 cb=0:cbd=20
 dim selectr(4)
 dim selectg(4)
 dim selectb(4)
 restore cursorcolours
 for a=0 to 4
  read selectr(a)
  read selectg(a)
  read selectb(a)
 next a
 cdelaybase=10:cdelay=cdelaybase:cwait=0
 cx=5:cy=5
 slide=0
rem Insertion Point 24
 gosub setupinstructions

rem Insertion Point 27
 numtgem=4
 dim tgemx(numtgem)
 dim tgemy(numtgem)
 dim tgemp(numtgem)
 dim tgems(numtgem)
return

rem Insertion Point 4


rem Insertion Point 14
label cursorcolours
data 1,1,1
data 1,1,0
data 0,1,0
data 1,0,0
data 0,0,1


label levels
data 4                : rem how many levels
data 10               : rem how many pieces
data 1,1,104          : rem x, y, piece number
data 9,1,100
data 10,1,100
data 9,2,100
data 9,3,100
data 10,3,100
data 10,2,4
data 10,4,1
data 4,6,1
data 6,3,2

data 5
data 1,1,103
data 7,2,4
data 9,3,4
data 6,6,1
data 10,10,103

data 10
data 1,1,1
data 9,1,100
data 10,1,103
data 9,2,100
data 9,3,100
data 10,3,100
data 10,2,4
data 10,4,1
data 4,6,1
data 6,3,2

data 24
data 4,2,2
data 8,4,4
data 2,7,2
data 7,7,2
data 1,9,100
data 2,9,100
data 3,9,100
data 4,9,100
data 5,9,100
data 6,9,100
data 7,9,100
data 8,9,100
data 9,9,100
data 1,8,100
data 2,8,100
data 1,10,103
data 2,10,4
data 3,10,100
data 4,10,1
data 5,10,100
data 6,10,2
data 7,10,100
data 8,10,4
data 9,10,100
 
