Talk:PetitEditor/@comment-18762052-20160703234912

ughhhhhhhhhhhhhhhhhhhhhhhhh

gosh dang it

the link is broken

or the thing just stopped being around

GOSH DANG IT

'Randomouscrap98

'November 2013

'Sudoku

@TOP

ACLS:CLEAR

PNLTYPE "OFF"

VISIBLE 1,1,1,1,1,1

GPAGE 0:GPRIO 2

GPAGE 1:GPRIO 2

COLOR 1

VERS$="1.3.1"

VERSDATE$="6/2/2014"

END$="All OK."

DEBUG=0

'Constants

MAXPNT=250

KEEPPNT=9   '15 is a magic number

PUDWIDTH=20

PUDBUTTONS=3

BGPAL=2

BGTIME=1023

PRSCALE=1

NUMDPUZ=99

PUZBYTES=6

NOTERESET$="000000000"

SAVESTART=160

SCROLL=131072

RED=&H61

BLUE=&HE7

LBLUE=&HE0

YELLOW=&H2B

GREEN=&HC1 'C0

GRAY=&HFC

WHITE=&H0F

PURPLE=&HA6 'A7

LPURPLE=&HA7

BROWN=&H17

LBROWN=&H07

GPAGE 0

DIM PUDB$(12)

DIM NUMX(KEEPPNT):DIM NUMY(KEEPPNT)

DIM NUMXT(MAXPNT):DIM NUMYT(MAXPNT)

DIM TNUMX(MAXPNT):DIM TNUMY(MAXPNT)

DIM MNUMX(MAXPNT):DIM MNUMY(MAXPNT)

DIM NUMSX(10,KEEPPNT):DIM NUMSY(10,KEEPPNT)

DIM NUMFX(10,MAXPNT):DIM NUMFY(10,MAXPNT)

DIM NUMFPNT(10)

DIM ERROR(10)

DIM COMPLETE(4,NUMDPUZ)

DIM DATES(4,NUMDPUZ*3)

DIM TIMES(4,NUMDPUZ*3)

DIM SDKUP(9,9)  'Player

DIM SDKUG(9,9)  'Givens

DIM SDKUS(9,9)  'Solution

DIM SDKUN$(9,9) 'Notes

DIM DIFCOL(4,3)

DIFCOL(0,0)=LBLUE:DIFCOL(0,1)=&HBD:DIFCOL(0,2)=&HB8

DIFCOL(1,0)=GREEN:DIFCOL(1,1)=&H9D:DIFCOL(1,2)=&H88

DIFCOL(2,0)=YELLOW:DIFCOL(2,1)=&H5B:DIFCOL(2,2)=&H5F

DIFCOL(3,0)=RED:DIFCOL(3,1)=&H12:DIFCOL(3,2)=&H67

DIM DRAWCOL(3):DRAWCOL(0)=BLUE:DRAWCOL(1)=PURPLE:DRAWCOL(2)=GREEN

DIM DRAWCOL$(3):DRAWCOL$(0)="Blue":DRAWCOL$(1)="Purple":DRAWCOL$(2)="Green"

DIM BGCOLS(3):BGCOLS(0)=2:BGCOLS(1)=15:BGCOLS(2)=9

DIM BGCOLS$(3):BGCOLS$(0)="White":BGCOLS$(1)="Gray":BGCOLS$(2)="Blue"

DIM BBGCOLS(3,6)

'0-Button,1-SubBTN,2-Title,3-5-Load

BBGCOLS(0,0)=BLUE:BBGCOLS(0,1)=LBLUE:BBGCOLS(0,2)=RED

FOR BBGI=0 TO 2:BBGCOLS(0,3+BBGI)=&H44+BBGI:NEXT

BBGCOLS(1,0)=&H11:BBGCOLS(1,1)=&H12:BBGCOLS(1,2)=&H16

FOR BBGI=0 TO 2:BBGCOLS(1,3+BBGI)=&H5A+BBGI:NEXT

BBGCOLS(2,0)=&HD2:BBGCOLS(2,1)=&HAD:BBGCOLS(2,2)=&H9C

FOR BBGI=0 TO 2:BBGCOLS(2,3+BBGI)=&HB7+BBGI:NEXT

DIM NCOUNT(10)

DIM M(128,128)

DIM KEYS$(50)

DIM DIFNAMES$(4)

DIM DIFNAMES0$(4)

DIFNAMESO$(0)="Easy"

DIFNAMESO$(1)="Medium"

DIFNAMESO$(2)="Hard"

DIFNAMESO$(3)="Tough"

NUMKEYS=28:KBW=7:KBKW=26:KBKP=2

KBH=FLOOR(NUMKEYS/KBW)+((NUMKEYS%KBW)>0)

NUMPNT=0

TNUMPNT=0

MNUMPNT=0

@START

'─────────────────────────

GOSUB @DATALOAD

GOSUB @DATAINIT

GOSUB @PRELOAD

GOSUB @LOADINGSHOW

GOSUB @PLAYLOAD

GOSUB @INTROSEQUENCE

GOSUB @FILLBG

GOSUB @LOADINGHIDE

GOSUB @SHOWTITLESCREEN

VSYNC 1:FIRSTCNTL=MAINCNTL

SYNC=1:GOSUB @SVSYNC

IF !REFERENCEFOUND THEN GOSUB @FIRSTRUN

@MAINMENU

'─────────────────────────

GOSUB @RESETTHEMECOLS

GOSUB @SHOWTITLESCREEN

GOSUB @SHOWMAINMENU

IF BMCHOICE==4 THEN GOSUB @ENDPROGRAM

IF BMCHOICE==3 THEN GOSUB @SHOWINFO

IF BMCHOICE==2 THEN GOTO @OPTIONMENU

IF BMCHOICE==1 THEN GOSUB @ASKADDON

IF BMCHOICE==0 THEN GOTO @DIFFICULTYMENU

GOTO @MAINMENU

@OPTIONMENU

'─────────────────────────

GOSUB @SHOWOPTIONMENU

IF BMCHOICE==4 THEN GOTO @MAINMENU

IF BMCHOICE==3 THEN GOTO @GENOPTMENU

IF BMCHOICE==2 THEN GOTO @SDKUOPTMENU

IF BMCHOICE==1 THEN GOSUB @DRAWONEPOPUP

IF BMCHOICE==0 THEN GOSUB @LEARNNUMBERS

GOTO @OPTIONMENU

@GENOPTMENU

'─────────────────────────

GOSUB @SHOWGENOPTMENU

IF BMCHOICE==3 THEN GOTO @OPTIONMENU

IF BMCHOICE==2 THEN GOSUB @BGCHOICE

IF BMCHOICE==1 THEN GOSUB @NOBGSCROLLCHOICE

IF BMCHOICE==0 THEN GOSUB @LEFTYCHOICE

GOTO @GENOPTMENU

@SDKUOPTMENU

'─────────────────────────

GOSUB @SHOWSDKUOPTMENU

IF BMCHOICE==3 THEN GOTO @OPTIONMENU

IF BMCHOICE==2 THEN GOSUB @QTAPCHOICE

IF BMCHOICE==1 THEN GOSUB @PENCHOICE

IF BMCHOICE==0 THEN GOSUB @ZOOMCHOICE

GOTO @SDKUOPTMENU

@DIFFICULTYMENU

'─────────────────────────

GOSUB @SHOWDIFFICULTYM

DIFFICULTY=BMCHOICE

PAGE=0

IF BMCHOICE==4 THEN GOTO @MAINMENU ELSE GOTO @PUZZLELIST

GOTO @DIFFICULTYMENU

'Display a list of puzzles

'AND perform actions

'─────────────────────────

@PUZZLELIST

'─────────────────────────

GOSUB @LOADINGSHOW

GOSUB @BACKLOADSAVEFILE

PPUZZLE=GSPOIT(0,SAVESTART+4*DIFFICULTY)-1

PZTOP=48:PZSIDE=6:PMCL=15

GPAGE 1,2,1:GCLS

FOR PLI=0 TO 9:FOR PLJ=0 TO 9

GBSX=PZSIDE+1+PLJ*18:GBEX=GBSX+15

GBSY=PZTOP+1+PLI*18:GBEY=GBSY+15

GBC=BBGCOLS(BGCOL,0):PRGRP=1

PRGX=GBSX+4:PRGY=GBSY+4:PR$=""

TMPG=DIFCOL(1,BGCOL)

TMPR=DIFCOL(3,BGCOL)

IF PLI==9 AND PLJ==9 THEN GBC=TMPR:PR$="X" ELSE IF COMPLETE(DIFFICULTY,PLJ+PLI*10) THEN GBC=TMPG

IF PPUZZLE==(PLI*10+PLJ) THEN GBC=DIFCOL(2,BGCOL)

GOSUB @GBOX:GOSUB @PR

IF PLI==9 AND PLJ==9 GOTO @PZLISTSKIPMINI

PMX=GBSX+4:PMY=GBSY+5:PMNUM=PLI+(PLJ==9)

GOSUB @PUTMINI

PMX=GBSX+8:PMY=GBSY+5:PMNUM=(PLJ+1)%10

GOSUB @PUTMINI

@PZLISTSKIPMINI

NEXT:NEXT

GBC=DIFCOL(DIFFICULTY,BGCOL)

PR$=DIFNAMES$(DIFFICULTY)

GBSX=96-LEN(PR$)*16/2-4:GBEX=96+LEN(PR$)*16/2+4

GBSY=12:GBEY=34

GOSUB @GBOX

PRGX=96-LEN(PR$)*16/2:PRGY=16:PRGRP=1:PRCOL=1:PRSCALE=2

GOSUB @PR

GPAGE 1,1,1

GCOPY 2,0,0,255,191,0,0,1

GOSUB @LOADINGHIDE

@PUZZLELISTLOOP

SYNC=1:GOSUB @SVSYNC

TCHXT=TCHY:TCHYT=255-TCHX

IF LEFTY THEN TCHXT=191-TCHXT:TCHYT=255-TCHYT

PUZZLE=FLOOR((TCHXT-PZSIDE)/18)+10*FLOOR((TCHYT-PZTOP)/18)

IF !(TCHST AND TCHTIME==1 AND PUZZLE<100 AND PUZZLE>=0) GOTO @PUZZLELISTLOOP

BEEP 9:LOADPUZZLE=0

IF PUZZLE==99 GOTO @DIFFICULTYMENU

GPAGE 1,3,1:GCOPY 1,0,0,255,191,0,0,1:GPAGE 1,1,1

IF !(PPUZZLE>=0 AND PUZZLE!=PPUZZLE) GOTO @NOOVERWRITE

PUD$="You have another puzzle saved. You can only save one puzzle at a time, and "

PUD$=PUD$+"if you save this new puzzle, your old one will be cleared. "

PUD$=PUD$+"Are you sure you want to start a new game?"

PUDB$(0)="Cancel"

PUDB$(1)="No"

PUDB$(2)="Yes"

GOSUB @P1POPUPDIALOG

SYNC=1:GOSUB @SVSYNC

IF PUDCHOICE!=2 THEN GCOPY 3,0,0,255,191,0,0,1:GOTO @PUZZLELISTLOOP

@NOOVERWRITE

IF !(PPUZZLE>=0 AND PPUZZLE==PUZZLE) GOTO @SUDOKUSETUP

PUD$="You have save data for this puzzle. Would you like to continue?"

PUDB$(0)="Cancel"

PUDB$(1)="New"

PUDB$(2)="Cont."

GOSUB @P1POPUPDIALOG

SYNC=1:GOSUB @SVSYNC

IF PUDCHOICE==0 THEN GCOPY 3,0,0,255,191,0,0,1:GOTO @PUZZLELISTLOOP

IF PUDCHOICE==1 THEN LOADPUZZLE=0

IF PUDCHOICE==2 THEN LOADPUZZLE=1

GOTO @SUDOKUSETUP

END

'Initialize a Sudoku game

'─────────────────────────

@SUDOKUSETUP

'─────────────────────────

GOSUB @LOADINGSHOW

GOSUB @SUDOKUNEW

GOSUB @LOADSUDOKUBRD

FOR SSI=0 TO 8

FOR SSJ=0 TO 8

SDKUP(SSI,SSJ)=SDKUG(SSI,SSJ)

NEXT

NEXT

IF LOADPUZZLE AND PPUZZLE==PUZZLE THEN GOSUB @LOADGAME

COLREAD("GRP",DRAWCOL(PENCOL)),R,G,B

COLSET "SP",&HBF,HEX$(R,2)+HEX$(G,2)+HEX$(B,2)

GPAGE 0:COLSET "GRP",&HBF,HEX$(R,2)+HEX$(G,2)+HEX$(B,2)

GOSUB @SUDOKUINITDRAW

GOSUB @LOADINGHIDE

GOTO @SUDOKUPLAY

@SUDOKUNEW

'─────────────────────────

FOR SNI=0 TO 8

FOR SNJ=0 TO 8

SDKUP(SNI,SNJ)=0

SDKUN$(SNI,SNJ)=NOTERESET$

NEXT

NEXT

RETURN

@LOADSUDOKUBRD

'─────────────────────────

GOSUB @BACKLOADSAVEFILE

LSSTART=81*(DIFFICULTY*NUMDPUZ+PUZZLE)

FOR LSI=0 TO 80

LVAL=GSPOIT((LSSTART+LSI)%256,FLOOR((LSSTART+LSI)/256))

SDKUS(LSI%9,FLOOR(LSI/9))=LVAL%16

SDKUG(LSI%9,FLOOR(LSI/9))=FLOOR(LVAL/16)

NEXT

RETURN

'Draw the original sudoku

'board on the back buffer

'─────────────────────────

@SUDOKUINITDRAW

'─────────────────────────

BRDEDGE=3:BRDDIV=2

BRDSUBDIV=1:BRDCELL=18

BRDWIDTH=BRDCELL*9+BRDSUBDIV*6+BRDDIV*2+BRDEDGE*2

BRDSIDE=(192-BRDWIDTH)/2:BRDTOP=39:BRD2TOP=54

GPAGE 1,3,1:GCLS

PR$="Quit":PRSCALE=2:PRCOL=15:PRGRP=1

PRGY=230:PRGX=96-LEN(PR$)*8*PRSCALE/2

BTNTOP=PRGY-4:BTNBOTTOM=PRGY+8*PRSCALE+2

BTNLEFT=PRGX-4:BTNRIGHT=191-BTNLEFT-2

GBSX=BTNLEFT:GBEX=BTNRIGHT

GBSY=BTNTOP:GBEY=BTNBOTTOM

GBC=BBGCOLS(BGCOL,0):GOSUB @GBOX:GOSUB @PR

GOSUB @DRAWSDKUINFO:GOTO @SKIPDRINF

@DRAWSDKUINFO

'─────────────────────────

PR$=DIFNAMES$(DIFFICULTY)

PR$=PR$+" "+STR$(PUZZLE+1)

PRSCALE=2:PRCOL=1:PRGRP=1

PRGY=10:PRGX=96-LEN(PR$)*8*PRSCALE/2

GBSX=PRGX-4:GBEX=191-GBSX-2

GBSY=PRGY-4:GBEY=PRGY+2+8*PRSCALE

GBC=DIFCOL(DIFFICULTY,BGCOL):GOSUB @GBOX:GOSUB @PR

RETURN

@SKIPDRINF

GBSX=BRDSIDE:GBEX=BRDSIDE+BRDWIDTH-1

GBSY=BRDTOP:GBEY=BRDTOP+BRDWIDTH-1

GBC=GRAY:GOSUB @GBOX

FOR GBX=0 TO 8

FOR GBY=0 TO 8

SDKUX=GBX:SDKUY=GBY

GOSUB @REFRESHCELL

NEXT

NEXT

GPAGE 1,1,1

RETURN

'Draw the special boxes in

'GRP 2 for box labeling

'─────────────────────────

@DRAWBACKBRD

'─────────────────────────

GPAGE 1,2,1:GCLS

FOR DBBY=0 TO 8

FOR DBBX=0 TO 8

BRDX=DBBX:BRDY=DBBY

GOSUB @BRD2GRP

GBSX=GRPX:GBSY=GRPY

GBEX=GBSX+BRDCELL-1:GBEY=GBSY+BRDCELL-1

GBC=1+(DBBX+9*DBBY):GOSUB @GBOX

NEXT

NEXT

GPAGE 1,1,1

RETURN

'Convert Board coordinates to

'GRP (screen) coordinates

'─────────────────────────

@BRD2GRP

'─────────────────────────

GRPX=BRDEDGE+BRDSIDE+(BRDSUBDIV+BRDCELL)*BRDX+(BRDDIV-BRDSUBDIV)*(FLOOR(BRDX/3))

GRPY=BRDEDGE+BRDTOP+(BRDSUBDIV+BRDCELL)*BRDY+(BRDDIV-BRDSUBDIV)*(FLOOR(BRDY/3))

RETURN

'GSPOIT for vertical screen

'─────────────────────────

@GSPOIT

'─────────────────────────

GSPXT=255-GSPY:GSPYT=GSPX

IF LEFTY THEN GSPXT=255-GSPXT:GSPYT=191-GSPYT

GSP=GSPOIT(GSPXT,GSPYT)

RETURN

'Draw a big number in cell

'SDKUX,SDKUY

'─────────────────────────

@SDKUNUM

'─────────────────────────

IF !SDKUNUM THEN RETURN

PCCH=SDKUNUM

PCCL=11:PCS=1

IF SDKUGIVE THEN PCCL=1

BRDX=SDKUX:BRDY=SDKUY

GOSUB @BRD2GRP

PCX=GRPX+1:PCY=GRPY+1

GOSUB @PUTCHR

SDKUGIVE=0

RETURN

'The MAIN GAME LOOP! ИИИ

'─────────────────────────

@SUDOKUPLAY

'─────────────────────────

SYNC=1:GOSUB @SVSYNC

MODE=0  'Zoom or not

GOSUB @SUDOKUREFRESH

@PLAYLOOP

SYNC=1:GOSUB @SVSYNC

BTR=BTRIG

TCHXT=TCHY:TCHYT=255-TCHX

IF LEFTY THEN TCHXT=191-TCHXT:TCHYT=255-TCHYT

QUICKTCH=TCHST AND TCHTIME==1

TCHBTN=0

IF TCHXT>BTNLEFT AND TCHXTBTNTOP AND TCHYT0 AND MODE==0 AND QUICKTCH THEN GOSUB @MODE1:GOTO @PLAYLOOP

IF (BTR AND (768+255*ALLZOOM))>0 AND MODE==1 THEN GOSUB @MODE0

IF HASWON THEN HASWON=0:GOTO @MAINMENU

TCHTL=(TCHXT0)

TCHTR=(TCHXT>REALDW+BRDCELL*ZM AND TCHST) OR (!ALLZOOM AND (BTR AND 66)>0)

TCHTT=(TCHYT0)

TCHTB=(TCHYT>REALDH+BRDCELL*ZM AND TCHST) OR (!ALLZOOM AND (BTR AND 20)>0)

MVTCH=TCHTL OR TCHTR OR TCHTT OR TCHTB

IF MVTCH AND MODE==1 AND (QUICKTCH OR BTR>0) THEN GOSUB @SLIDEBRD

IF !MVTCH AND MODE==1 AND QUICKTCH THEN GOSUB @SDKURECOG

GOTO @PLAYLOOP

@QUITCHECK

PUD$="Do you want to save before you quit?"

PUDB$(0)="Cancel"

PUDB$(1)="No"

PUDB$(2)="Yes"

GOSUB @P1POPUPDIALOG

IF PUDCHOICE==0 THEN GOSUB @SUDOKUREFRESH:GOTO @PLAYLOOP

IF PUDCHOICE==1 GOTO @QUITAGAIN

GOSUB @LOADINGSHOW

GPAGE 1,1,1

GCOPY 3,0,0,255,191,0,0,1

GOSUB @SAVEGAME

GPAGE 1,3,1

GOSUB @LOADINGHIDE

IF RESULT!=TRUE THEN GCOPY 1,0,0,255,191,0,0,1:GOSUB @SUDOKUREFRESH:GOTO @PLAYLOOP

GOTO @MAINMENU

@QUITAGAIN

PUDPAGE=1

PUD$="WARNING: Your progress will be lost. Really quit without saving?

PUDB$(0)="Cancel"

PUDB$(1)="No"

PUDB$(2)="Yes"

GOSUB @POPUPDIALOG

IF PUDCHOICE==0 THEN GOSUB @SUDOKUREFRESH:GOTO @PLAYLOOP

IF PUDCHOICE==1 GOTO @QUITCHECK

GOTO @MAINMENU

GOTO @MAINMENU

'The main drawing/recognition

'function

'─────────────────────────

@SDKURECOG

'─────────────────────────

IF SDKUG(ZOOMX,ZOOMY) THEN RETURN

DCOL=DRAWCOL(PENCOL)

GOSUB @DRAWNUM

DCXT=DYMIN+(DYMAX-DYMIN)/2

DCYT=255-(DXMIN+(DXMAX-DXMIN)/2)

IF LEFTY THEN DCXT=191-DCXT:DCYT=255-DCYT

DCELLX=FLOOR((DCXT-REALDW)/(BRDCELL*ZM)*3)

DCELLY=FLOOR((DCYT-REALDH)/(BRDCELL*ZM)*3)

IF DCELLX<0 THEN DCELLX=0

IF DCELLY<0 THEN DCELLY=0

IF DCELLX>2 THEN DCELLX=2

IF DCELLY>2 THEN DCELLY=2

NTS$=SDKUN$(ZOOMX,ZOOMY)

NOTETAPPED=(DRAWERROR>0) AND (DYMAX-DYMIN<8) AND (DXMAX-DXMIN<8) AND TAPNOTE

NOTETAPPED=NOTETAPPED AND (SDKUP(ZOOMX,ZOOMY)==0)

TNOTE=DCELLX+3*DCELLY+1

TAPON=VAL(MID$(NTS$,TNOTE-1,1))==0

WASNOTE=((DXMAX-DXMIN)0 AND !NOTETAPPED) OR (WASNOTE AND SDKUP(ZOOMX,ZOOMY)!=0)

IF WASERROR THEN BGMPLAY DRAWERRORNOISE:GCOPY 2,0,0,255,191,0,0,1:RETURN

GOSUB @LOADINGSHOW

IF !DRAWERROR THEN GOSUB @RECOGNIZENUM ELSE RECOGNUM=TNOTE*TAPON

IF WASNOTE THEN SDKUN$(ZOOMX,ZOOMY)=SUBST$(NTS$,DCELLX+3*DCELLY,1,STR$(RECOGNUM))

IF !WASNOTE THEN SDKUP(ZOOMX,ZOOMY)=RECOGNUM:IF RECOGNUM==0 THEN SDKUN$(ZOOMX,ZOOMY)=NOTERESET$

SDKUX=ZOOMX:SDKUY=ZOOMY

GOSUB @REFRESHCELL

GOSUB @DRAWBACKZOOM

GCOPY 2,0,0,255,191,0,0,1

GOSUB @DRAWSIDEBRD

PLAYNOISE=DRAWDONENOISE

IF WASNOTE THEN PLAYNOISE=DRAWDONENOISE2

IF RECOGNUM==0 THEN PLAYNOISE=DRAWDONENOISE3

BGMPLAY 1,PLAYNOISE,127-50*WASNOTE

GOSUB @LOADINGHIDE

RETURN

'HASWON=TRUE if winner

'─────────────────────────

@CHECKWIN

'─────────────────────────

HASWON=1

FOR CWX=0 TO 8

FOR CWY=0 TO 8

IF SDKUP(CWX,CWY)!=SDKUS(CWX,CWY) THEN HASWON=0

NEXT

NEXT

RETURN

'─────────────────────────

@WINGAME

'─────────────────────────

GPAGE 1,1,1:GCLS

GOSUB @DRAWSDKUINFO

PUDPAGE=1

PUD$="You've beaten this puzzle!"

PUDB$(0)="Hooray!"

BGMPLAY WINNOISE

GOSUB @POPUPDIALOG

COMPLETE(DIFFICULTY,PUZZLE)=1

CMPNUM=CMPNUM+1

GOSUB @LOADINGSHOW

IF PPUZZLE==PUZZLE THEN ERASESAVE=1:GOSUB @SAVEGAME ELSE GOSUB @PLAYSAVE

GOSUB @LOADINGHIDE

RETURN

'Entirely redraw a single cell

'─────────────────────────

@REFRESHCELL

'─────────────────────────

SDKUGIVE=SDKUG(SDKUX,SDKUY)>0

SDKUNUM=SDKUP(SDKUX,SDKUY)

BRDX=SDKUX:BRDY=SDKUY

GOSUB @BRD2GRP

GPAGE 1,3,1

GBSX=GRPX:GBSY=GRPY

GBEX=GRPX+BRDCELL-1:GBEY=GRPY+BRDCELL-1

GBC=WHITE:GOSUB @GBOX

GOSUB @SDKUNUM

IF SDKUP(SDKUX,SDKUY)!=0 GOTO @REFRESHCELLDONE

FOR RCI=0 TO 8

NOTENUM=VAL(MID$(SDKUN$(SDKUX,SDKUY),RCI,1))

PMCL=11:PMX=GRPX+2+5*(RCI%3):PMY=GRPY+2+5*FLOOR(RCI/3)

PMNUM=NOTENUM

IF NOTENUM THEN GOSUB @PUTSUPERMINI

NEXT

@REFRESHCELLDONE

GPAGE 1,1,1

RETURN

'Assuming the board is already

'set up, enable mode 0

'─────────────────────────

@MODE0

'─────────────────────────

GOSUB @CHECKWIN

IF HASWON THEN GOSUB @WINGAME:RETURN

GPAGE 0,0,0

GBSX=BRDSIDE:GBSY=BRD2TOP

GBEX=GBSX+BRDWIDTH:GBEY=GBSY+BRDWIDTH

GBC=0:GOSUB @GBOX

GPAGE 1,1,1

GOSUB @SUDOKUREFRESH

MODE=0

BGMPLAY ZOOMOUTNOISE

RETURN

'Assuming the board is already

'set up, enable mode 1

'─────────────────────────

@MODE1

'─────────────────────────

ZOOMX=(BRDBOX-1)%9:ZOOMY=FLOOR((BRDBOX-1)/9)

GOSUB @DRAWSIDEBRD

BGMPLAY ZOOMINNOISE

GOSUB @DRAWBACKZOOM

GCOPY 2,0,0,255,191,0,0,1

MODE=1

RETURN

'The board that shows up on

'the side when zoomed in

'─────────────────────────

@DRAWSIDEBRD

'─────────────────────────

GPAGE 0,0,0

M1TOP=BRDTOP:M2TOP=255-(BRD2TOP+BRDWIDTH)

IF LEFTY THEN M1TOP=255-M1TOP:M2TOP=BRD2TOP

GCOPY 3,M1TOP,BRDSIDE,M1TOP+BRDWIDTH*(1-2*LEFTY),BRDSIDE+BRDWIDTH,M2TOP,BRDSIDE,0

BRDX=ZOOMX:BRDY=ZOOMY

GOSUB @BRD2GRP:GBC=RED

GRPY=GRPY+BRD2TOP-BRDTOP+1

GBSX=GRPX-2:GBEX=GRPX-1

GBSY=GRPY-2:GBEY=GRPY+BRDCELL+1

GOSUB @GBOX

GBEX=GRPX+BRDCELL+1:GBEY=GRPY-1

GOSUB @GBOX

GBSX=GRPX+BRDCELL:GBSY=GRPY+BRDCELL+1

GOSUB @GBOX

GBEX=GRPX-2:GBEY=GRPY+BRDCELL

GOSUB @GBOX

GPAGE 1,1,1

RETURN

'Based on ZOOMX and ZOOMY,

'draw the zoomed in area

'─────────────────────────

@DRAWBACKZOOM

'─────────────────────────

GPAGE 1,3,1

ZM=8

DW=192/ZM-1

DH=256/ZM-1

REALDW=(DW-BRDCELL)*ZM/2

REALDH=(DH-BRDCELL)*ZM/2

BRDX=ZOOMX

BRDY=ZOOMY

GOSUB @BRD2GRP

DE=GRPX-(DW+1-BRDCELL)/2

DT=GRPY-(DH+1-BRDCELL)/2

IF LEFTY GOTO @LEFTYDBD

TT=255-DT

FOR DY=0 TO DH

FOR DX=0 TO DW

M(DX,DY)=GSPOIT(TT-DY,DE+DX)

NEXT

NEXT

GOTO @DBDSTART

@LEFTYDBD

TT=191-DE

FOR DY=0 TO DH

FOR DX=0 TO DW

M(DX,DY)=GSPOIT(DT+DY,TT-DX)

NEXT

NEXT

@DBDSTART

GPAGE 1,2,1

GOSUB @GWHITE

GBH=ZM:GBW=ZM

IF LEFTY GOTO @LEFTYDBDD

T1=255-ZM+1

T2=255-ZM+GBW

T3=GBH-1

FOR DY=0 TO DH

FOR DX=0 TO DW

IF M(DX,DY)==15 GOTO @SDR

GFILL T1-DY*ZM,DX*ZM,T2-DY*ZM,DX*ZM+T3,M(DX,DY)

@SDR

NEXT

NEXT

GOTO @DBDEND

@LEFTYDBDD

T1=ZM-1

T2=ZM-GBW

T3=191-GBH+1

FOR DY=0 TO DH

FOR DX=0 TO DW

IF M(DX,DY)==15 GOTO @SDL

GFILL DY*ZM+T1,191-DX*ZM,DY*ZM+T2,T3-DX*ZM,M(DX,DY)

@SDL

NEXT

NEXT

@DBDEND

GPAGE 1,1,1

DW=DW+1:DH=DH+1

RETURN

'Slide to next area

'─────────────────────────

@SLIDEBRD

'─────────────────────────

OZOOMX=ZOOMX:OZOOMY=ZOOMY

IF TCHTL AND ZOOMX>0 THEN ZOOMX=ZOOMX-1

IF TCHTR AND ZOOMX<8 THEN ZOOMX=ZOOMX+1

IF TCHTT AND ZOOMY>0 THEN ZOOMY=ZOOMY-1

IF TCHTB AND ZOOMY<8 THEN ZOOMY=ZOOMY+1

IF OZOOMX==ZOOMX AND OZOOMY==ZOOMY THEN RETURN

BGMPLAY SLIDENOISE

GOSUB @DRAWSIDEBRD

GOSUB @DRAWBACKZOOM

GCOPY 2,0,0,255,191,0,0,1

RETURN

'Bring the original sudoku

'screen back to the front

'─────────────────────────

@SUDOKUREFRESH

'─────────────────────────

GPAGE 1,1,1

GOSUB @RESETTHEMECOLS

GCOPY 3,0,0,255,192,0,0,1

GOSUB @DRAWCOMPLETES

GOSUB @DRAWBACKBRD

RETURN

'─────────────────────────

@DRAWCOMPLETES

'─────────────────────────

FOR DCOMI=0 TO 9

NCOUNT(DCOMI)=0

NEXT

FOR DCOMI=0 TO 8

FOR DCOMJ=0 TO 8

NCOUNT(SDKUP(DCOMI,DCOMJ))=NCOUNT(SDKUP(DCOMI,DCOMJ))+1

NEXT

NEXT

DCOMH=19:DCOMW=163 '181

DCOMX=14:DCOMY=0

GPAGE 0,2,0

GBSY=DCOMY:GBEY=DCOMY+DCOMH

GBSX=DCOMX:GBEX=DCOMX+DCOMW

GBC=&HFC:GOSUB @GBOX

GBSY=DCOMY+2:GBEY=DCOMY+DCOMH-2

FOR LDI=1 TO 9

LDC=1+(NCOUNT(LDI)==9)+12*(NCOUNT(LDI)>9)

GBSX=DCOMX+2+(LDI-1)*18:GBEX=GBSX+15:GBC=&H1E+(LDC==2)*&HDA:GOSUB @GBOX

PCX=GBSX:PCY=DCOMY+2:PCS=1

PCCH=LDI:PCCL=LDC:GOSUB @PUTCHR

NEXT

GPAGE 0,0,0

IF LEFTY THEN GCOPY 2,DCOMY,191-DCOMX,DCOMY+DCOMH,191-(DCOMX+DCOMW),128-DCOMH/2,DCOMX,0

IF !LEFTY THEN GCOPY 2,255-(DCOMH+DCOMY),DCOMX,255-DCOMY,DCOMX+DCOMW,128-DCOMH/2,DCOMX,0

RETURN

'Save a sudoku game

'─────────────────────────

@SAVEGAME

'─────────────────────────

GOSUB @BACKLOADSAVEFILE

GP=(SAVESTART+4*DIFFICULTY)*256

GPSET GP%256,FLOOR(GP/256),(PUZZLE+1)*(!ERASESAVE)

GP=GP+1

FOR SGI=0 TO 80

GPSET GP%256,FLOOR(GP/256),SDKUP(SGI%9,FLOOR(SGI/9))

GP=GP+1

NEXT

FOR SGI=0 TO 80

FOR SGJ=0 TO 8

GPSET GP%256,FLOOR(GP/256),VAL(MID$(SDKUN$(SGI%9,FLOOR(SGI/9)),SGJ,1))

GP=GP+1

NEXT

NEXT

BACKLOADED=1

GOSUB @PLAYSAVE

GPAGE 1,1,1

ERASESAVE=0

RETURN

'Load an old paused game

'─────────────────────────

@LOADGAME

'─────────────────────────

GOSUB @BACKLOADSAVEFILE

GP=(SAVESTART+4*DIFFICULTY)*256+1

FOR SGI=0 TO 80

SDKUP(SGI%9,FLOOR(SGI/9))=GSPOIT(GP%256,FLOOR(GP/256))

GP=GP+1

NEXT

FOR SGI=0 TO 80

SDKT$=""

FOR SGJ=0 TO 8

SDKT$=SDKT$+STR$(GSPOIT(GP%256,FLOOR(GP/256)))

GP=GP+1

NEXT

SDKUN$(SGI%9,FLOOR(SGI/9))=SDKT$

NEXT

GPAGE 1,1,1

RETURN

'Print out dialog and perform

'actions for choosing lefty mode

'─────────────────────────

@LEFTYCHOICE

'─────────────────────────

PUD$="Lefty mode is enabled. Would you like to disable it?"

IF !LEFTY THEN PUD$="Would you like to enable lefty mode?"

PUD$=PUD$+" Game will restart, and numbers have to be redrawn."

PUDB$(0)="Cancel"

PUDB$(1)="No"

PUDB$(2)="Yes"

GOSUB @P1POPUPDIALOG

IF PUDCHOICE<2 THEN RETURN

DELETE "GRP:DRAWNUMS"

PUD$="Error: You must delete the file."

PUDB$(0)="OK"

IF RESULT!=TRUE THEN GOSUB @POPUPDIALOG:RETURN

LEFTY=!LEFTY

GOSUB @LSPLAYSAVE

GOTO @TOP

'Dialog and setup for BG

'scroll (animation) option

'─────────────────────────

@NOBGSCROLLCHOICE

'─────────────────────────

PUD$="The background is currently set to animate. Would you like to turn it off?"

IF NOBGSCROLL THEN PUD$="The background is not animated. Turn it on?"

PUDB$(0)="Cancel"

PUDB$(1)="No"

PUDB$(2)="Yes"

GOSUB @P1POPUPDIALOG

IF PUDCHOICE<2 THEN RETURN

NOBGSCROLL=!NOBGSCROLL

GOSUB @SCROLLBG

GOSUB @LSPLAYSAVE

RETURN

'Which buttons cause unzoom

'─────────────────────────

@ZOOMCHOICE

'─────────────────────────

PUD$="Unzoom is set to Кн. Would you like to use ALL the buttons instead?"

IF ALLZOOM THEN PUD$="Unzoom is set to ALL buttons. Would you like to use Кн instead?"

PUDB$(0)="Cancel"

PUDB$(1)="No"

PUDB$(2)="Yes"

GOSUB @P1POPUPDIALOG

IF PUDCHOICE<2 THEN RETURN

ALLZOOM=!ALLZOOM

GOSUB @LSPLAYSAVE

RETURN

'─────────────────────────

@PENCHOICE

'─────────────────────────

PUD$="Pen color set to "+DRAWCOL$(PENCOL)+". Which color would you like?"

FOR PCI=0 TO 2

PUDB$(PCI)=DRAWCOL$(PCI)

NEXT

GOSUB @P1POPUPDIALOG

PENCOL=PUDCHOICE

GOSUB @LSPLAYSAVE

RETURN

'─────────────────────────

@BGCHOICE

'─────────────────────────

PUD$="Color theme set to "+BGCOLS$(BGCOL)+". "

PUD$=PUD$+"Which color would you like?"

FOR PCI=0 TO 2

PUDB$(PCI)=BGCOLS$(PCI)

NEXT

GOSUB @P1POPUPDIALOG

BGCOL=PUDCHOICE

GOSUB @RESETTHEMECOLS

GOSUB @RESETLOADCOLS

GOSUB @LOADINGSHOW

GOSUB @SHOWTITLESCREEN

GOSUB @FILLBG

GOSUB @LSPLAYSAVE

RETURN

'─────────────────────────

@QTAPCHOICE

'─────────────────────────

PUD$="Quicktap allows you to tap in one of the 9 note spaces to toggle a note. This can speed up "

PUD$=PUD$+"gameplay. Quicktap is currently "

IF !TAPNOTE THEN PUD$=PUD$+"disabled. Enable it?" ELSE PUD$=PUD$+"enabled. Disable it?"

PUDB$(0)="Cancel"

PUDB$(1)="No"

PUDB$(2)="Yes"

GOSUB @P1POPUPDIALOG

IF PUDCHOICE<2 THEN RETURN

TAPNOTE=!TAPNOTE

GOSUB @LSPLAYSAVE

RETURN

@DRAWNUM

'─────────────────────────

NUMPNT=0

DXMIN=500:DYMIN=500

DXMAX=-1:DYMAX=-1

DRAWERROR=0

BGMPLAY 1,PENCILNOISE,0

@DRAWNUMLOOP

NUMXT(NUMPNT)=TCHX

NUMYT(NUMPNT)=TCHY

IF STORENUM AND NUMXT(NUMPNT)>255-24 THEN NUMXT(NUMPNT)=255-24

DX=NUMXT(NUMPNT)

DY=NUMYT(NUMPNT)

IF DXDXMAX THEN DXMAX=DX

IF DYDYMAX THEN DYMAX=DY

IF NUMPNT==0 GOTO @SKIPDRAWNUMLINE

DXO=NUMXT(NUMPNT-1)

DYO=NUMYT(NUMPNT-1)

VD=FLOOR(POW(DXO-DX,2)+POW(DYO-DY,2))

IF VD>127 THEN VD=127

BGMVOL 1,VD

IF DX==DXO AND DY==DYO THEN NUMPNT=NUMPNT-1

GLINE DXO,DYO,DX,DY,DCOL

GLINE DXO-1,DYO,DX-1,DY,DCOL

GLINE DXO,DYO-1,DX,DY-1,DCOL

@SKIPDRAWNUMLINE

NUMPNT=NUMPNT+1

SYNC=1:GOSUB @SVSYNC

IF TCHST AND NUMPNT2 THEN DRAWERROR=2:RETURN

GOSUB @TRANSFORMNUMBER

RETURN

@TRANSFORMNUMBER

'─────────────────────────

GOSUB @SHRINKDRAWN

'GPAGE 0

'GCLS

'FOR DNI=1 TO KEEPPNT-1

' GLINE NUMX(DNI-1),NUMY(DNI-1),NUMX(DNI),NUMY(DNI),13

'NEXT

'GPAGE 1

SCALE=192/(DXMAX-DXMIN)

SHIFTX=NUMX(0)*SCALE

SHIFTY=NUMY(0)*SCALE

NUMX(0)=0:NUMY(0)=0

FOR DNI=1 TO KEEPPNT-1

NUMX(DNI)=NUMX(DNI)*SCALE-SHIFTX

NUMY(DNI)=NUMY(DNI)*SCALE-SHIFTY

NEXT

IF !STORENUM THEN RETURN

FOR DNI=0 TO NUMPNT-1

NUMFX(DRAWNUM,DNI)=NUMXT(DNI)

NUMFY(DRAWNUM,DNI)=NUMYT(DNI)

NEXT

NUMFPNT(DRAWNUM)=NUMPNT

FOR DNI=0 TO KEEPPNT-1

NUMSX(DRAWNUM,DNI)=NUMX(DNI)

NUMSY(DRAWNUM,DNI)=NUMY(DNI)

NEXT

RETURN

@SHRINKDRAWN

'─────────────────────────

SSR=(NUMPNT-1)/(KEEPPNT-1)

SSM=0

FOR SDI=0 TO KEEPPNT-1

SSMF=FLOOR(SSM)

NUMX(SDI)=NUMXT(SSMF)*(SSMF+1-SSM)+NUMXT(SSMF+1)*(SSM-SSMF)

NUMY(SDI)=NUMYT(SSMF)*(SSMF+1-SSM)+NUMYT(SSMF+1)*(SSM-SSMF)

SSM=SSM+SSR

NEXT

RETURN

@RECOGNIZENUM

'─────────────────────────

TIME=MAINCNTL

PRY=0:PRX=0

MINERR=500000

MINERRI=-1

'For each number

FOR RNI=0 TO 9

ERROR(RNI)=0

'For each point in number

FOR RNJ=1 TO KEEPPNT-1

EUCLID=SQR(POW(NUMSX(RNI,RNJ)-NUMX(RNJ),2)+POW(NUMSY(RNI,RNJ)-NUMY(RNJ),2))

TVX=NUMSX(RNI,RNJ)-NUMSX(RNI,RNJ-1)

TVY=NUMSY(RNI,RNJ)-NUMSY(RNI,RNJ-1)

MVX=NUMX(RNJ)-NUMX(RNJ-1)

MVY=NUMY(RNJ)-NUMY(RNJ-1)

DENOM=SQR(TVX*TVX+TVY*TVY)*SQR(MVX*MVX+MVY*MVY)

IF DENOM==0 THEN PR$="?"+STR$(RNJ):GOTO @SKIPSLOWERR

ERROR(RNI)=ERROR(RNI)+ABS(((TVX*MVX+TVY*MVY)/DENOM)-1)*EUCLID

@SKIPSLOWERR

NEXT

IF ERROR(RNI)<MINERR THEN MINERR=ERROR(RNI):MINERRI=RNI

'PR$=STR$(RNI)+":"+STR$(ERROR(RNI)):GOSUB @PR

NEXT

'TIME=MAINCNTL-TIME

'PR$="---":GOSUB @PR

'PR$="Guess: "+STR$(MINERRI):GOSUB @PR

'PR$="Time: "+STR$(TIME)+" frames":GOSUB @PR

'PR$="---":GOSUB @PR

RECOGNUM=MINERRI

RETURN

'Fill with white (whatever)

'─────────────────────────

@GWHITE

'─────────────────────────

GFILL 0,0,255,192,WHITE

RETURN

'Print text in PR$ on console

'or GRP Options:

'-PRGRP: Sets GRP mode

'-PRX/PRY: Console point

'-PRGX/PRGY: GRP point

'-PRSCALE: GRP letter scale

'-PRCOL: Text color (0-15)

'─────────────────────────

@PR

'─────────────────────────

PRGYT=PRGY+8*PRSCALE-1

PRYT=PRY:PRXT=PRX:PRGXT=PRGX

IF LEFTY THEN PRYT=31-PRYT:PRXT=23-PRXT:PRGXT=191-PRGXT-8*PRSCALE+1:PRGYT=255-PRGYT+8*PRSCALE-1

FOR PRI=0 TO LEN(PR$)-1

PRIT=PRI*(1-2*LEFTY)

IF !PRGRP THEN LOCATE 31-PRYT,(PRXT+PRIT)%24:?MID$(PR$,PRI,1);

IF PRGRP THEN GPUTCHR 255-PRGYT,PRGXT+8*PRIT*PRSCALE,"BGF",ASC(MID$(PR$,PRI,1)),PRCOL,PRSCALE

'IF PRI>0 AND (PRXT+PRIT)%24==0 THEN PRY=PRY+1:PRYT=PRYT+(1-2*LEFTY)

NEXT

PRY=(PRY+1)%32

PRGY=(PRGY+8*PRSCALE)%256

PRGRP=0

PRSCALE=1

PRCOL=0

RETURN

'Draw a box on the GRP.

'Accounts for LEFTY mode,

'so same coordinates can be

'repeated for both modes

'─────────────────────────

@GBOX

'─────────────────────────

GBSYT=GBSY:GBEYT=GBEY:GBSXT=GBSX:GBEXT=GBEX

IF LEFTY THEN GBSYT=255-GBSYT:GBEYT=255-GBEYT:GBSXT=191-GBSXT:GBEXT=191-GBEXT

GFILL 255-GBSYT,GBSXT,255-GBEYT,GBEXT,GBC

RETURN

'Use width instead of height.

'Parameters not guaranteed

'to stay the same

'─────────────────────────

@GBOXFAST

'─────────────────────────

IF LEFTY THEN GBSY=255-GBSY:GBSX=191-GBSX:GBW=-(GBW-2):GBH=-(GBH-2)

GFILL 255-GBSY,GBSX,255-GBSY+GBH-1,GBSX+GBW-1,GBC

RETURN

@DATALOAD

'─────────────────────────

REFERENCEFOUND=0

SYSBEEP=FALSE

LOAD "BGF:BGFROTAT",FALSE

LOAD "BGFL:BGFROTAT",FALSE

LOAD "BGU0:SUDOKUBG",FALSE

LOAD "BGU0L:SUDOKUBG",FALSE

LOAD "SPU0:SUDOKU",FALSE

SPPAGE 1

LOAD "SPS0:SUDOKU",FALSE

SPPAGE 0

LOAD "GRP3:DRAWNUMS",FALSE

IF RESULT==TRUE THEN REFERENCEFOUND=1:GOSUB @LOADNUMBERS

SYSBEEP=TRUE

PENCILNOISE=128

BGMCLEAR PENCILNOISE:BGMSETD PENCILNOISE,@PENCILNOISE

ZOOMINNOISE=129

BGMCLEAR ZOOMINNOISE:BGMSETD ZOOMINNOISE,@ZOOMINNOISE

ZOOMOUTNOISE=130

BGMCLEAR ZOOMOUTNOISE:BGMSETD ZOOMOUTNOISE,@ZOOMOUTNOISE

SLIDENOISE=131

BGMCLEAR SLIDENOISE:BGMSETD SLIDENOISE,@SLIDENOISE

DRAWDONENOISE=132

BGMCLEAR DRAWDONENOISE:BGMSETD DRAWDONENOISE,@DRAWDONENOISE

DRAWDONENOISE2=133

BGMCLEAR DRAWDONENOISE2:BGMSETD DRAWDONENOISE2,@DRAWDONENOISE2

DRAWDONENOISE3=134

BGMCLEAR DRAWDONENOISE3:BGMSETD DRAWDONENOISE3,@DRAWDONENOISE3

DRAWERRORNOISE=135

BGMCLEAR DRAWERRORNOISE:BGMSETD DRAWERRORNOISE,@DRAWERRORNOISE

WINNOISE=136

BGMCLEAR WINNOISE:BGMSETD WINNOISE,@WINNOISE

RETURN

'─────────────────────────

@DATAINIT

'─────────────────────────

FOR PUDI=0 TO 11

PUDB$(PUDI)="В"

NEXT

FOR BMI=0 TO 9

BM$(BMI)="В"

NEXT

FOR KBI=0 TO 25

KEYS$(KBI)=CHR$(ASC("A")+KBI)

NEXT

KEYS$(26)="_"

KEYS$(27)="м"

SPPAGE 1

SPSET 99,48,0,0,0,0

SPANIM 99,16,2

GOSUB @LOADINGHIDE

GPAGE 0:COLSET "GRP",YELLOW,"F7BE01"

GPAGE 1:COLSET "GRP",YELLOW,"F7BE01"

SPPAGE 0

COLREAD("GRP",BLUE),R,G,B

COLSET "SP",&HBF,HEX$(R,2)+HEX$(G,2)+HEX$(B,2)

GPAGE 0:COLSET "GRP",&HBF,HEX$(R,2)+HEX$(G,2)+HEX$(B,2)

COLREAD("GRP",RED),R,G,B

COLSET "SP",&HDF,HEX$(R,2)+HEX$(G,2)+HEX$(B,2)

COLREAD("GRP",&HC4),R,G,B

BGPAGE 0:COLSET "BG",&H9D,HEX$(R,2)+HEX$(G,2)+HEX$(B,2)

BGPAGE 1:COLSET "BG",&H9D,HEX$(R,2)+HEX$(G,2)+HEX$(B,2)

COLREAD("GRP",&HE2),R,G,B

BGPAGE 0:COLSET "BG",&H9C,HEX$(R,2)+HEX$(G,2)+HEX$(B,2)

BGPAGE 1:COLSET "BG",&H9C,HEX$(R,2)+HEX$(G,2)+HEX$(B,2)

COLREAD("GRP",&HDA),R,G,B

BGPAGE 0:COLSET "BG",&H9F,HEX$(R,2)+HEX$(G,2)+HEX$(B,2)

BGPAGE 1:COLSET "BG",&H9F,HEX$(R,2)+HEX$(G,2)+HEX$(B,2)

COLREAD("GRP",&HFE),R,G,B

BGPAGE 0:COLSET "BG",&HFC,HEX$(R,2)+HEX$(G,2)+HEX$(B,2)

BGPAGE 1:COLSET "BG",&HFC,HEX$(R,2)+HEX$(G,2)+HEX$(B,2)

RETURN

'Flip letters (+ sprites)

'upside down for lefties

'─────────────────────────

@FLIPLETTERS

'─────────────────────────

BGPAGE 0

FOR FLI=0 TO 255

CHRREAD("BGF",FLI),C$

CHRREAD("SPU0",FLI),CS$

A$="":AS$=""

FOR FLJ=0 TO 63

A$=A$+MID$(C$,63-FLJ,1)

AS$=AS$+MID$(CS$,63-FLJ,1)

NEXT

CHRSET "BGF",FLI,A$

CHRSET "BGFL",FLI,A$

IF FLI<64 THEN CHRSET "SPU0",FLI,AS$

NEXT

FOR FLI=0 TO 39 STEP 4

CHRREAD("SPU0",FLI),C$

CHRREAD("SPU0",FLI+1),C2$

CHRREAD("SPU0",FLI+2),C3$

CHRREAD("SPU0",FLI+3),C4$

CHRSET "SPU0",FLI+3,C$

CHRSET "SPU0",FLI+2,C2$

CHRSET "SPU0",FLI+1,C3$

CHRSET "SPU0",FLI,C4$

NEXT

RETURN

'Only load the important info

'─────────────────────────

@PRELOAD

'─────────────────────────

COLOR 9

GOSUB @LOADWHICHGRP

GOSUB @BACKLOADSAVEFILE

LEFTY=GSPOIT(0,181)

BGCOL=GSPOIT(9,181)

GOSUB @RESETLOADCOLS

RETURN

@LOADINGSHOW

'─────────────────────────

LSX=10:LSY=10

IF LEFTY THEN LSX=255-LSX-16:

'LSY=191-LSY-16

SPPAGE 1

SPOFS 99,LSX,LSY

SPPAGE 0

RETURN

@LOADINGHIDE

'─────────────────────────

SPPAGE 1

SPOFS 99,-100,-100

SPPAGE 0

RETURN

@BACKLOADSAVEFILE

'─────────────────────────

GPAGE 1,3,1

GFILL 0,0,256,192,0

SYSBEEP=FALSE

LOAD "GRP3:"+LOADGRP$,FALSE

IF RESULT==TRUE GOTO @ALLGOODLOAD

COLOR 15

END$="Error: You need to download the GRP:SUDOKU puzzle file!"

BEEP 4

GOTO @ENDPROGRAM

@ALLGOODLOAD

SYSBEEP=TRUE

RETURN

'─────────────────────────

@LOADWHICHGRP

'─────────────────────────

LOADGRP$="SUDOKU"

GOSUB @BACKLOADSAVEFILE

LOADGRP$=""

FOR PLI=0 TO 7

PLT=GSPOIT(248+PLI,181)

IF PLT THEN LOADGRP$=LOADGRP$+CHR$(PLT)

NEXT

IF LOADGRP$=="" THEN LOADGRP$="SUDOKU"

SYSBEEP=FALSE

LOAD "GRP3:"+LOADGRP$,FALSE

SYSBEEP=TRUE

PUD$="Add-on missing. Defaulting to original file. Some settings and progress may be lost."

PUDB$(0)="OK"

IF RESULT!=TRUE THEN GOSUB @P1POPUPDIALOG:LOADGRP$="SUDOKU":GOSUB @SAVEWHICHGRP

RETURN

'Save ONLY which addon they're

'using. Will fail if SUDOKU

'doesn't exist

'─────────────────────────

@SAVEWHICHGRP

'─────────────────────────

LOADGRPR$=LOADGRP$

LOADGRP$="SUDOKU"

GOSUB @BACKLOADSAVEFILE

LOADGRP$=LOADGRPR$

FOR PLI=0 TO 7

PLT=0

IF PLI<LEN(LOADGRP$) THEN PLT=ASC(MID$(LOADGRP$,PLI,1))

GPSET PLI+248,181,PLT

NEXT

SAVE "GRP3:SUDOKU"

RETURN

'Load player completion data

'─────────────────────────

@PLAYLOAD

'─────────────────────────

GOSUB @BACKLOADSAVEFILE

FOR PLI=0 TO 3

FOR PLJ=0 TO NUMDPUZ-1

FOR PLK=0 TO PUZBYTES-1

PLT=256*192-(PLK+PLJ*PUZBYTES+PLI*NUMDPUZ*PUZBYTES)-1

PLV=GSPOIT(PLT%256,FLOOR(PLT/256))

ON FLOOR(PLK/3) GOSUB @PLTIME,@PLDATE

NEXT

NEXT

NEXT

LEFTY=GSPOIT(0,181)

NOBGSCROLL=GSPOIT(1,181)

PSECS=GSPOIT(2,181)

PMINS=GSPOIT(3,181)

PHOURS=GSPOIT(4,181)

PHOURS2=GSPOIT(5,181)

ALLZOOM=GSPOIT(6,181)

PENCOL=GSPOIT(7,181)

TAPNOTE=GSPOIT(8,181)

BGCOL=GSPOIT(9,181)

CMPNUM=256*GSPOIT(11,181)+GSPOIT(10,181)

FOR PLI=0 TO 3

PLT$=""

FOR PLJ=0 TO 7

PLT=GSPOIT(PLI*8+PLJ,180)

IF PLT THEN PLT$=PLT$+CHR$(PLT)

NEXT

DIFNAMES$(PLI)=PLT$

IF PLT$=="" THEN DIFNAMES$(PLI)=DIFNAMESO$(PLI)

NEXT

GOSUB @RESETLOADCOLS

IF LEFTY AND !SKIPFLIP THEN GOSUB @FLIPLETTERS

GPAGE 1,1,1

SKIPFLIP=0

RETURN

@PLTIME

IF PLK==0 THEN COMPLETE(PLI,PLJ)=FLOOR(PLV/128)

TIMES(PLI,PLJ*3+PLK%3)=PLV AND 127

RETURN

@PLDATE

DATES(PLI,PLJ*3+PLK%3)=PLV

RETURN

'Save player completion data

'─────────────────────────

@PLAYSAVE

'─────────────────────────

IF !BACKLOADED THEN GOSUB @BACKLOADSAVEFILE

IF SKIPPUZZLESAVE GOTO @SKIPPUZZLESAVE

FOR PLSD=0 TO 3

FOR PLSP=0 TO NUMDPUZ-1

FOR PLB=0 TO PUZBYTES-1

PLT=256*192-(PLB+PLSP*PUZBYTES+PLSD*NUMDPUZ*PUZBYTES)-1

ON FLOOR(PLB/3) GOSUB @PLSTIME,@PLSDATE

GPSET (PLT%256),FLOOR(PLT/256),PLV

NEXT

NEXT

NEXT

@SKIPPUZZLESAVE

GPSET 0,181,LEFTY

GPSET 1,181,NOBGSCROLL

GPSET 2,181,PSECS

GPSET 3,181,PMINS

GPSET 4,181,PHOURS

GPSET 5,181,PHOURS2

GPSET 6,181,ALLZOOM

GPSET 7,181,PENCOL

GPSET 8,181,TAPNOTE

GPSET 9,181,BGCOL

GPSET 10,181,CMPNUM%256

GPSET 11,181,FLOOR(CMPNUM/256)

SAVE "GRP3:"+LOADGRP$

GPAGE 1,1,1

BACKLOADED=FALSE

SKIPPUZZLESAVE=0

RETURN

@PLSTIME

PLV=TIMES(PLSD,PLSP*3+PLB%3)

IF PLB==0 THEN PLV=PLV+128*COMPLETE(PLSD,PLSP)

RETURN

@PLSDATE

PLV=DATES(PLSD,PLSP*3+PLB%3)

RETURN

'Does PLAYSAVE but with the

'loading sprite

'─────────────────────────

@LSPLAYSAVE

'─────────────────────────

GOSUB @LOADINGSHOW

GOSUB @PLAYSAVE

GOSUB @LOADINGHIDE

RETURN

'The fade-in/out name at

'the beginning

'─────────────────────────

@INTROSEQUENCE

'─────────────────────────

GPAGE 0

COLREAD("GRP",15),R,G,B

PRGX=36:PRGY=118:PRGRP=1:PRCOL=1

PR$="Randomouscrap98":GOSUB @PR

PRGX=80:PRGY=130:PRGRP=1:PRCOL=1

PR$="2014":GOSUB @PR

FOR J=0 TO 1

FOR I=44*J TO 44-44*J STEP 1-2*J

CD=I/44

COLSET "GRP",31,HEX$(FLOOR(R*CD),2)+HEX$(FLOOR(G*CD),2)+HEX$(FLOOR(B*CD),2)

VSYNC 1

NEXT

VSYNC 20

NEXT

GCLS

RETURN

'Fill the BG with the

'decorative grid tiles

'─────────────────────────

@FILLBG

'─────────────────────────

VISIBLE 1,1,0,0,1,1

BGPAGE 0

FOR I=0 TO 63

FOR J=0 TO 63

BGPUT 1,J,I,16+J%2+2*(I%2),BGCOLS(BGCOL),1,0

NEXT

NEXT

BGPAGE 1

FOR I=0 TO 63

FOR J=0 TO 63

BGPUT 1,J,I,16+J%2+2*(I%2),BGCOLS(BGCOL),1,0

NEXT

NEXT

VISIBLE 1,1,1,1,1,1

RETURN

'A VSYNC that also updates

'the background

'─────────────────────────

@SVSYNC

'─────────────────────────

FFRAME=MAINCNTL

FOR SVI=1 TO SYNC

IF DEBUG AND BTRIG==1024 THEN GOSUB @ENDPROGRAM

IF MAINCNTL=60 THEN PFRAMES=PFRAMES-60:PSECS=PSECS+1

IF PSECS>=60 THEN PSECS=PSECS-60:PMINS=PMINS+1

IF PMINS>=60 THEN PMINS=PMINS-60:PHOURS=PHOURS+1

IF PHOURS>=256 THEN PHOURS=PHOURS-256:PHOURS2=PHOURS2+1

RETURN

'Reset and restart the BG

'animation.

'─────────────────────────

@SCROLLBG

'─────────────────────────

BGSA=SCROLL

'IF LEFTY THEN BGSA=-511

BGPAGE 0:BGOFS 1,0,0,0

IF !NOBGSCROLL THEN BGOFS 1,BGSA,BGSA,BGSA*2

BGPAGE 1:BGOFS 1,0,0,0

IF !NOBGSCROLL THEN BGOFS 1,BGSA,BGSA,BGSA*2

RETURN

'Pretty obvious

'─────────────────────────

@SHOWTITLESCREEN

'─────────────────────────

GPAGE 0

COLOR 1

PRX=3:PRY=2

PR$="┗┏┓     ┛   ┛     ":GOSUB @PR

PR$="┫┠ ┛ ┛┗┏┛┗┏┓┛┳━┛ ┛":GOSUB @PR

PR$="┓ ┛┛ ┛┛ ┛┛ ┛┯┫ ┛ ┛":GOSUB @PR

PR$="┃┏ ┃┏ ┃┏━┃┏ ━ ━┃┏ ":GOSUB @PR

GCLS

GBSX=20:GBEX=166:GBC=BBGCOLS(BGCOL,2)

GBSY=12:GBEY=47:GOSUB @GBOX

PR$=" Randomouscrap98 - 2014 "

PRX=0:PRY=30:GOSUB @PR

RETURN

'Also obvious

'─────────────────────────

@ENDPROGRAM

'─────────────────────────

BGPAGE 1:CHRINIT "BGF"

BGPAGE 0:SPPAGE 0:GPAGE 0

CHRINIT "BGF"

COLINIT "BG":COLINIT "SP":COLINIT "GRP"

ACLS:COLOR 15

PRINT END$

END

@POPUPDIALOG

'─────────────────────────

PUDPLACE=-1

GOSUB @POPUPONLY

GOTO @POPUPBUTTON

@POPUPONLY

PUDLINES=1

PUDLO$=PUD$+" "

PUDCURWIDTH=0

PUDTOTAL=0

@PUDLINECOUNT

NEXTSPACE=INSTR(PUDLO$," ")

IF !(NEXTSPACE+PUDCURWIDTH>PUDWIDTH) GOTO @PUDLINECONTINUE

PUDLINES=PUDLINES+1

PUD$=SUBST$(PUD$,PUDTOTAL-1,1,"↓")

PUDCURWIDTH=0

@PUDLINECONTINUE

PUDCURWIDTH=PUDCURWIDTH+NEXTSPACE+1

PUDTOTAL=PUDTOTAL+NEXTSPACE+1

PUDLO$=RIGHT$(PUDLO$,LEN(PUDLO$)-NEXTSPACE-1)

IF LEN(PUDLO$)!=0 GOTO @PUDLINECOUNT

GPAGE PUDPAGE,2,PUDPAGE

PUDTOP=FLOOR((32-5-PUDLINES)/2)

IF PUDPLACE!=-1 THEN PUDTOP=PUDPLACE

GBSX=8:GBEX=183:GBC=BBGCOLS(BGCOL,0)

GBSY=PUDTOP*8+1:GBEY=(PUDTOP+2+PUDLINES)*8-2

GCLS:GOSUB @GBOX

PRGX=16:PRGY=(PUDTOP+1)*8

PUDLO$=PUD$+"↓"

@PUDPRINT

PR$=LEFT$(PUDLO$,INSTR(PUDLO$,"↓"))

PRGRP=1:GOSUB @PR

PUDLO$=RIGHT$(PUDLO$,LEN(PUDLO$)-INSTR(PUDLO$,"↓")-1)

IF LEN(PUDLO$)!=0 GOTO @PUDPRINT

PUDPLACE=-1

RETURN

@POPUPBUTTON

PUDBNUM=0

FOR PUDI=0 TO 11:IF PUDB$(PUDI)!="В" THEN PUDBNUM=PUDI+1:NEXT

IF PUDBNUM==0 THEN GPAGE PUDPAGE,PUDPAGE,PUDPAGE:GCOPY 2,0,0,255,192,0,0,0:GOTO @PUDDONE

PUDBWIDTH=(168-4*(PUDBNUM-1))/PUDBNUM

FOR PUDI=0 TO PUDBNUM-1

GBSX=12+PUDI*(PUDBWIDTH+4)

GBEX=GBSX+PUDBWIDTH-1

GBSY=(PUDTOP+2+PUDLINES)*8+4

GBEY=GBSY+16:GBC=BBGCOLS(BGCOL,1)  'C3

GOSUB @GBOX

PRGX=GBSX+(PUDBWIDTH-LEN(PUDB$(PUDI))*8)/2

PRGY=GBSY+5:PRGRP=1

PR$=PUDB$(PUDI):GOSUB @PR

NEXT

GPAGE PUDPAGE,PUDPAGE,PUDPAGE

GCOPY 2,0,0,255,192,0,0,0

PUDBD=-1:PUDBU=-2

@PUDBLOOP

TCHBX=TCHY

TCHBY=255-TCHX

IF LEFTY THEN TCHBY=255-TCHBY:TCHBX=191-TCHBX

IF !TCHST OR TCHTIME!=1 OR TCHBYGBEY+1 GOTO @PUDBNOTOUCH

IF TCHBX<12 OR TCHBX>180 GOTO @PUDBNOTOUCH

BEEP 9

PUDBD=FLOOR((TCHBX-12)/(PUDBWIDTH+4))

IF PUDBD<0 OR PUDBD>=PUDBNUM THEN PUDBD=-1

PUDBU=PUDBD

@PUDBNOTOUCH

SYNC=1:GOSUB @SVSYNC

IF PUDBD!=PUDBU GOTO @PUDBLOOP

PUDCHOICE=PUDBD

GCLS

@PUDDONE

FOR PUDI=0 TO 11:PUDB$(PUDI)="В":NEXT

RETURN

'─────────────────────────

@P1POPUPDIALOG

'─────────────────────────

GPAGE 1:GCLS:PUDPAGE=1

GOSUB @POPUPDIALOG

RETURN

@FIRSTRUN

'─────────────────────────

PUDPAGE=1

@FIRSTRUN1

PUD$="Before we begin, I need to learn your handwriting. Don't worry, it won't take long!"

PUDB$(1)="Continue"

PUDB$(0)="Quit"

GOSUB @POPUPDIALOG

IF PUDCHOICE==0 THEN GOSUB @ENDPROGRAM

@FIRSTRUN2

PUD$="Oh, but before you start drawing your numbers, there are some things you should keep "

PUD$=PUD$+"in mind if you want to have a smooth experience."

PUDB$(1)="Continue"

PUDB$(0)="Back"

GOSUB @POPUPDIALOG

IF PUDCHOICE==0 GOTO @FIRSTRUN1

@FIRSTRUN3

PUD$="First, make sure that you write your numbers slowly and carefully while "

PUD$=PUD$+"I'm learning, but don't write too slowly! Once I learn them, you can write "

PUD$=PUD$+"at a normal speed again."

PUDB$(1)="Continue"

PUDB$(0)="Back"

GOSUB @POPUPDIALOG

IF PUDCHOICE==0 GOTO @FIRSTRUN2

@FIRSTRUN4

PUD$="Second (and this is the most important step), make sure you write the number "

PUD$=PUD$+"in ONE stroke. This means that you cannot lift the stylus while you are writing. "

PUD$=PUD$+"For numbers like 5, this means you might have to change the way you "

PUD$=PUD$+"write them.

PUDB$(1)="Continue"

PUDB$(0)="Back"

GOSUB @POPUPDIALOG

IF PUDCHOICE==0 GOTO @FIRSTRUN3

PUD$="Well, let's get started then!"

PUDB$(1)="OK!"

PUDB$(0)="Back"

GOSUB @POPUPDIALOG

IF PUDCHOICE==0 GOTO @FIRSTRUN4

GOSUB @LEARNNUMBERS

RETURN

@LEARNNUMBERS

'─────────────────────────

PUDPAGE=0

PUD$="Press any button to accept the current drawing. "

PUD$=PUD$+"Remember, draw your numbers in ONE stroke!"

GOSUB @POPUPDIALOG

IF !DRAWONE THEN DRAWNUM=0

TDRAWNUM=0

GPAGE 1:GOSUB @GWHITE

ACCEPTABLE=0:STORENUM=1

@LEARNLOOP

GBSX=0:GBEX=191

GBSY=24:GBEY=255

GBC=WHITE:GOSUB @GBOX

GOSUB @LEARNDRAW

@LLINPUTLOOP

GBSX=0:GBEX=191

GBSY=24:GBEY=255

GBC=WHITE

IF ACCEPTABLE THEN B=BTRIG ELSE B=0

IF !(TCHST AND TCHTIME==1) GOTO @LLNOTOUCH

GOSUB @GBOX

DCOL=1

GOSUB @DRAWNUM

ACCEPTABLE=!DRAWERROR

GOSUB @LEARNDRAW

@LLNOTOUCH

SYNC=1:GOSUB @SVSYNC

IF B==0 GOTO @LLINPUTLOOP

ACCEPTABLE=0

DRAWNUM=DRAWNUM+1

IF DRAWNUM>TDRAWNUM THEN TDRAWNUM=DRAWNUM

IF TDRAWNUM<10 AND !DRAWONE GOTO @LEARNLOOP

STORENUM=0

GPAGE 1,3,1:GCLS

GOSUB @SAVENUMBERS

GPAGE 1,1,1

SAVE "GRP3:DRAWNUMS"

GOSUB @SHOWTITLESCREEN

RETURN

@LEARNDRAW

'─────────────────────────

GPAGE 1,2,1

GCLS

GBSY=4:GBEY=23

GBSX=5:GBEX=186

GBC=&HFC:GOSUB @GBOX

GBSX=GBSX+DRAWNUM*18:GBEX=GBSX+19

IF !ACCEPTABLE THEN GBC=RED ELSE GBC=BLUE

GOSUB @GBOX

GBSY=6:GBEY=21

FOR LDI=0 TO 9

LDC=1+(LDI>TDRAWNUM) '*(!REFERENCEFOUND)

IF DRAWONE THEN IF LDI==DRAWNUM THEN LDC=1 ELSE LDC=2

GBSX=7+LDI*18:GBEX=GBSX+15:GBC=&H1E+(LDC-1)*&HDA:GOSUB @GBOX

PCX=GBSX:PCY=6:PCS=1

PCCH=LDI:PCCL=LDC:GOSUB @PUTCHR

NEXT

GPAGE 1,1,1

GCOPY 2,0,0,255,192,0,0,0

RETURN

'─────────────────────────

@RESETLOADCOLS

'─────────────────────────

SPPAGE 1

COLREAD("SP",BBGCOLS(BGCOL,3)),R,G,B

COLSET "SP",&H04,HEX$(R,2)+HEX$(G,2)+HEX$(B,2)

COLREAD("SP",BBGCOLS(BGCOL,4)),R,G,B

COLSET "SP",&H05,HEX$(R,2)+HEX$(G,2)+HEX$(B,2)

COLREAD("SP",BBGCOLS(BGCOL,5)),R,G,B

COLSET "SP",&H06,HEX$(R,2)+HEX$(G,2)+HEX$(B,2)

RETURN

'─────────────────────────

@RESETTHEMECOLS

'─────────────────────────

FOR PCC=0 TO 3

COLINIT "GRP",DIFCOL(PCC,BGCOL)

NEXT

COLINIT "GRP",GRAY

COLINIT "GRP",BLUE

COLINIT "GRP",PURPLE

RETURN

@PUTCHR

'─────────────────────────

IF LEFTY THEN PCY=255-PCY-15:PCX=191-PCX-15

GPUTCHR 255-PCY-15,PCX,"SPU0",PCCH*4,PCCL,PCS

GPUTCHR 255-PCY-15+8,PCX,"SPU0",PCCH*4+1,PCCL,PCS

GPUTCHR 255-PCY-15,PCX+8,"SPU0",PCCH*4+2,PCCL,PCS

GPUTCHR 255-PCY-15+8,PCX+8,"SPU0",PCCH*4+3,PCCL,PCS

GOSUB @RESETTHEMECOLS

RETURN

@PUTMINI

'─────────────────────────

IF LEFTY THEN PMY=255-PMY-7:PMX=191-PMX-7

GPUTCHR 255-PMY-7,PMX,"SPU0",PMNUM+40,PMCL,1

'GOSUB @RESETTHEMECOLS

RETURN

@PUTSUPERMINI

'─────────────────────────

IF LEFTY THEN PMY=255-PMY-7:PMX=191-PMX-7

GPUTCHR 255-PMY-7,PMX,"SPU0",PMNUM+52,PMCL,1

'GOSUB @RESETTHEMECOLS

RETURN

@SAVENUMBERS

'─────────────────────────

FOR SNI=0 TO 9

FOR SNJ=0 TO NUMFPNT(SNI)-1

GPSET SNJ,SNI*2,NUMFX(SNI,SNJ)

GPSET SNJ,SNI*2+1,NUMFY(SNI,SNJ)

NEXT

GPSET 255,SNI*2,NUMFPNT(SNI)

NEXT

RETURN

@LOADNUMBERS

'─────────────────────────

GPAGE 1,3,1

STORENUM=1

FOR LNI=0 TO 9

NUMPNT=GSPOIT(255,LNI*2)

DXMIN=500:DXMAX=0

DYMIN=500:DYMAX=0

FOR LNJ=0 TO NUMPNT-1

NUMXT(LNJ)=GSPOIT(LNJ,LNI*2)

NUMYT(LNJ)=GSPOIT(LNJ,LNI*2+1)

IF NUMXT(LNJ)DXMAX THEN DXMAX=NUMXT(LNJ)

IF NUMYT(LNJ)>DYMAX THEN DYMAX=NUMYT(LNJ)

NEXT

DRAWNUM=LNI

GOSUB @TRANSFORMNUMBER

NEXT

STORENUM=0

GPAGE 1,1,1

RETURN

'─────────────────────────

@ASKADDON

'─────────────────────────

KBTITLE$="You are currently using the "+LOADGRP$

KBTITLE$=KBTITLE$+" pack. Which pack would you like to switch to? "

KBTITLE$=KBTITLE$+"Enter SUDOKU for the default pack, or leave empty to quit."

GOSUB @KEYBOARDINPUT

IF KBENTRY$=="" THEN RETURN

SYSBEEP=FALSE

LOAD "GRP3:"+KBENTRY$,FALSE

SYSBEEP=TRUE

IF RESULT==TRUE GOTO @ADDONSETUP

PUD$="Sorry, I couldn't find that addon."

PUDB$(0)="OK"

GOSUB @P1POPUPDIALOG

GOTO @ASKADDON

@ADDONSETUP

LOADGRP$=KBENTRY$

PUD$=LOADGRP$+" found. The game will now switch to this puzzle set."

PUDB$(0)="Cancel"

PUDB$(1)="OK"

GOSUB @P1POPUPDIALOG

IF PUDCHOICE==0 THEN RETURN

SKIPPUZZLESAVE=1

GOSUB @LSPLAYSAVE

PUD$="The add-on installation was cancelled.":PUDB$(0)="OK"

IF RESULT!=TRUE THEN GOSUB @P1POPUPDIALOG:RETURN

GOSUB @SAVEWHICHGRP

PUD$="The add-on installation was cancelled.":PUDB$(0)="OK"

IF RESULT!=TRUE THEN GOSUB @P1POPUPDIALOG:RETURN

GOSUB @LOADINGSHOW

SKIPFLIP=1

GOSUB @PLAYLOAD

GOSUB @LOADINGHIDE

RETURN

'Use KBTITLE$ to specify the

'title of the keyboard input

'─────────────────────────

@KEYBOARDINPUT

'─────────────────────────

GPAGE 1,2,1:GCLS

PUD$=KBTITLE$:PUDPAGE=1

PUDPLACE=2:GOSUB @POPUPONLY

KBENTRY$=""

PRCOL=0

KBN=0:KBJ=0

KBS=(192-KBW*KBKW)/2

KBT=256-KBS-KBH*KBKW

@KBDLOOP

FOR KBI=0 TO KBW-1

GBSX=KBS+KBKW*KBI+KBKP:GBEX=GBSX+KBKW-2*KBKP

GBSY=KBT+KBKW*KBJ+KBKP:GBEY=GBSY+KBKW-2*KBKP

GBC=BBGCOLS(BGCOL,0)

IF KBN==NUMKEYS-1 THEN GBC=DIFCOL(3,BGCOL)

PR$=KEYS$(KBN):PRGRP=1:PRSCALE=2

PRGX=GBSX+(GBEX-GBSX-8*PRSCALE)/2+1

PRGY=GBSY+(GBEY-GBSY-8*PRSCALE)/2+1

GOSUB @GBOX:GOSUB @PR

KBN=KBN+1

NEXT

KBJ=KBJ+1

IF KBN=KBT) GOTO @KBLOOPEND

KBX=FLOOR((TCHXT-KBS)/KBKW)

KBY=FLOOR((TCHYT-KBT)/KBKW)

IF KBX<0 OR KBY<0 OR KBX>=KBW OR KBY>=KBH THEN GOTO @KBLOOPEND

BEEP 9

KBN=KBX+KBW*KBY:KBDEL=(KBN==NUMKEYS-1)

IF KBDEL THEN IF LEN(KBENTRY$)>0 THEN KBENTRY$=LEFT$(KBENTRY$,LEN(KBENTRY$)-1) ELSE GOTO @KBEND

IF !KBDEL THEN KBENTRY$=LEFT$(KBENTRY$+KEYS$(KBN),8)

GOSUB @KBENTRYSHOW

@KBLOOPEND

IF !(BTRIG AND 1023) GOTO @KBLOOP

@KBEND

GCLS

RETURN

'─────────────────────────

@KBENTRYSHOW

'─────────────────────────

PR$=KBENTRY$:PRSCALE=2:PRGRP=1

KBET=KBT-KBKP*4-8*PRSCALE-KBKP*2:KBES=96-(8*PRSCALE*8+KBKP*4)/2

GBSX=KBES:GBEX=192-GBSX

GBSY=KBET:GBEY=GBSY+KBKP*4+8*PRSCALE

PRGX=KBES+KBKP*2+1:PRGY=KBET+KBKP*2+1

GBC=BBGCOLS(BGCOL,1)

GOSUB @GBOX:GOSUB @PR

RETURN

@BUTTONMENU

'─────────────────────────

NUMBM=0

FOR BMI=0 TO 9

IF BM$(BMI)!="В" THEN NUMBM=BMI+1

NEXT

IF NUMBM==0 THEN BEEP:RETURN

BMS=FLOOR((256-32*NUMBM-8*(NUMBM-1))/2)

GPAGE 1,2,1:GCLS

GBSX=16:GBEX=175

FOR BMI=0 TO NUMBM-1

GBSY=BMS+BMI*40-2:GBEY=GBSY+31:GBC=BBGCOLS(BGCOL,0)

GOSUB @GBOX

PRSCALE=2:PRGX=FLOOR((192-LEN(BM$(BMI))*16)/2)

PRGY=GBSY+8:PRGRP=1

PR$=BM$(BMI)

GOSUB @PR

NEXT

GPAGE 1,1,1

SYNC=1:GOSUB @SVSYNC

GCOPY 2,0,0,255,191,0,0,1

BMCHOICE=-1

@BMLOOP

SYNC=1:GOSUB @SVSYNC

TCHXT=TCHX

IF LEFTY THEN TCHXT=255-TCHXT

IF TCHST AND TCHTIME==1 AND TCHY>15 AND TCHY<176 THEN BMCHOICE=FLOOR((255-TCHXT-BMS)/40)

IF BMCHOICE<0 OR BMCHOICE>NUMBM-1 THEN BMCHOICE=-1

IF BMCHOICE==-1 GOTO @BMLOOP

BEEP 9

FOR BMI=0 TO 9

BM$(BMI)="В"

NEXT

RETURN

@SHOWMAINMENU

'─────────────────────────

BM$(0)="Play"

BM$(1)="Add-Ons"

BM$(2)="Options"

BM$(3)="Info"

BM$(4)="Quit"

GOSUB @BUTTONMENU

RETURN

@SHOWOPTIONMENU

'─────────────────────────

BM$(0)="Draw All"

BM$(1)="Draw One"

BM$(2)="Sudoku"

BM$(3)="General"

BM$(4)="Back"

GOSUB @BUTTONMENU

RETURN

@SHOWGENOPTMENU

'─────────────────────────

BM$(0)="Lefty  "

IF LEFTY THEN BM$(0)=BM$(0)+"■" ELSE BM$(0)=BM$(0)+"□"

BM$(1)="No BG  "

IF NOBGSCROLL THEN BM$(1)=BM$(1)+"■" ELSE BM$(1)=BM$(1)+"□"

BM$(2)="Theme "+LEFT$(BGCOLS$(BGCOL),2)

BM$(3)="Back"

GOSUB @BUTTONMENU

RETURN

@SHOWSDKUOPTMENU

'─────────────────────────

BM$(0)="Zoom "

IF ALLZOOM THEN BM$(0)=BM$(0)+"All" ELSE BM$(0)=BM$(0)+" Кн"

BM$(1)="Pen   "+LEFT$(DRAWCOL$(PENCOL),2)

BM$(2)="QkTap  "

IF TAPNOTE THEN BM$(2)=BM$(2)+"■" ELSE BM$(2)=BM$(2)+"□"

BM$(3)="Back"

GOSUB @BUTTONMENU

RETURN

@SHOWDIFFICULTYM

'─────────────────────────

FOR SDMI=0 TO 3

BM$(SDMI)=DIFNAMES$(SDMI)

NEXT

BM$(4)="Back"

GOSUB @BUTTONMENU

RETURN

@DRAWONEPOPUP

'─────────────────────────

PUD$="Which number would you like to redraw?"

FOR DOI=0 TO 9:PUDB$(DOI+1)=STR$(DOI):NEXT

PUDB$(0)="X"

GOSUB @P1POPUPDIALOG

IF PUDCHOICE==0 THEN RETURN

DRAWONE=1:DRAWNUM=PUDCHOICE-1

GOSUB @LEARNNUMBERS

DRAWONE=0

RETURN

@UNIMPLEMENTED

'─────────────────────────

PUD$="That feature isn't implemented yet. Sorry!"

PUDB$(0)="OK"

GOSUB @P1POPUPDIALOG

RETURN

'Show game information

'─────────────────────────

@SHOWINFO

'─────────────────────────

PUD$="Version: "+VERS$+" Release: "+VERSDATE$+" ──────────────────── Play time: "

PUD$=PUD$+STR$(PHOURS2*256+PHOURS)+":"+RIGHT$("0"+STR$(PMINS),2)

PUD$=PUD$+" Puzzles done: "+STR$(CMPNUM)

PUDB$(0)="OK"

GOSUB @P1POPUPDIALOG

RETURN

@PENCILNOISE

'─────────────────────────

DATA ":0@151O8T60V40"

DATA "@E40,0,127,127B1&B1&B1

DATA 0

@ZOOMINNOISE

'─────────────────────────

DATA ":0@151O6T150V50

DATA "@E115,0,127,120L16C_<GC"

DATA ":0@151O8T150V50

DATA "@E115,0,127,120L16C_>>C"

DATA 0

@SLIDENOISE

'─────────────────────────

'DATA ":0@115O4T120V110"

'DATA "L32G"

DATA ":0@151O7T120V50

DATA "@E115,0,127,125L64C_>G"

DATA 0

@DRAWDONENOISE

'─────────────────────────

DATA ":0@115O5T120V127"

DATA "L32C>G"

DATA 0

@DRAWDONENOISE2

'─────────────────────────

DATA ":0@115O4T120V127"

DATA "L32GC"

DATA 0

@DRAWDONENOISE3

'─────────────────────────

DATA ":0@115O4T120V127"

DATA "L48CGC"

DATA 0

@DRAWERRORNOISE

'─────────────────────────

DATA ":0@115O3T120V127"

DATA "L32GG

DATA 0

@WINNOISE

'─────────────────────────

DATA ":0@115O4T120V127"

DATA "L32CEG>C

DATA 0

my life.