DEFINT A-Z

DECLARE SUB DrawBack ()
DECLARE SUB DrawWindow (YPos%, XPos%, YSize%, XSize%, Caption AS STRING, TextLine%)
DECLARE FUNCTION GetExitNoSave% ()
DECLARE FUNCTION GetExitSave% ()
DECLARE FUNCTION GetQuality% ()
DECLARE FUNCTION GetOS% ()

CONST PROGRAMNAME = "DS4QB++ v1.2 Test"

' WARNING: CRAPPY CODING ALEART!!

DIM OnOff$(1)

Handle = FREEFILE
OPEN "SOUNDSYS.CFG" FOR BINARY AS #Handle
 IF LOF(Handle) THEN
   GET #Handle, , OS
   GET #Handle, , xSound
   GET #Handle, , xMusic
   GET #Handle, , Quality&
  ELSE
   FirstRun = -1
 END IF
CLOSE #Handle

IF FirstRun THEN
 KILL "SOUNDSYS.CFG"
 OS = 0
 xSound = 1
 xMusic = 1
 Quality& = 44050
END IF

OnOff$(0) = "OFF."
OnOff$(1) = "ON. "

Title$ = " þ " + PROGRAMNAME + " - Sound setup þ "
PSNX = 40 - (LEN(Title$) \ 2)

SCREEN 0, , 2, 0: CLS

DrawBack
COLOR 0, 7
LOCATE 1, 1: PRINT SPACE$(PSNX) + Title$ + SPACE$(80 - PSNX - LEN(Title$));

DrawWindow 3, 10, 19, 60, "Main menu", 11

 LOCATE 5, 13: PRINT "Welcome! Use the arrow keys to select the item you wish "
 LOCATE 6, 13: PRINT "to edit, and then [ENTER] or [SPACE] to confirm that    "
 LOCATE 7, 13: PRINT "selection.     "

 COLOR 15, 1
 LOCATE 9, 13: PRINT "NOTE:";
 COLOR 7, 1
 PRINT " In order to get the best sound quality, it is     "
LOCATE 10, 13: PRINT "HIGHLY advised that you disable any virus scanners, or  "
LOCATE 11, 13: PRINT "other TSR's that slow down your hard-drive's performance "
LOCATE 12, 13: PRINT "before running " + PROGRAMNAME + "!"

Sel = 1

SCREEN 0, , 1, 0

DO
 SELECT CASE Key$
  CASE CHR$(0) + "H": Sel = Sel - 1
  CASE CHR$(0) + "P": Sel = Sel + 1
  CASE CHR$(27): Sel = 6
  CASE CHR$(13), CHR$(32):
   SELECT CASE Sel
    CASE 1
     Temp = GetOS
     IF Temp THEN
      SELECT CASE Temp
       CASE 1 TO 3: OS = 1
       CASE 4 TO 7: OS = 0
      END SELECT
     END IF
    CASE 2
     Temp = GetQuality
     IF Temp THEN
      SELECT CASE Temp
       CASE 1: Quality& = 44050
       CASE 2: Quality& = 22025
       CASE 3: Quality& = 11012
      END SELECT
     END IF
    CASE 3: xSound = (xSound + 1) AND 1
    CASE 4: xMusic = (xMusic + 1) AND 1
    CASE 5:
     Temp = GetExitSave
     IF Temp = 1 THEN EXIT DO
    CASE 6
     Temp = GetExitNoSave
     IF Temp = 1 THEN EXIT DO
   END SELECT
   SCREEN 0, , 1, 0
 END SELECT

 IF Sel > 6 THEN Sel = 6
 IF Sel < 1 THEN Sel = 1

 PCOPY 2, 1

 IF Sel = 1 THEN COLOR 15, 7 ELSE COLOR 15, 1
 LOCATE 16, 13: PRINT " Select operation system                                "
 IF Sel = 2 THEN COLOR 15, 7 ELSE COLOR 15, 1
 LOCATE 17, 13: PRINT " Select playback quality                                "
 IF Sel = 3 THEN COLOR 15, 7 ELSE COLOR 15, 1
 LOCATE 18, 13: PRINT " Sounds are " + OnOff$(xSound AND 1) + "                                        "
 IF Sel = 4 THEN COLOR 15, 7 ELSE COLOR 15, 1
 LOCATE 19, 13: PRINT " Music is " + OnOff$(xMusic AND 1) + "                                          "
 IF Sel = 5 THEN COLOR 15, 7 ELSE COLOR 15, 1
 LOCATE 20, 13: PRINT " Save and exit setup                                    "
 IF Sel = 6 THEN COLOR 15, 7 ELSE COLOR 15, 1
 LOCATE 21, 13: PRINT " Exit without saving                                    "

 PCOPY 1, 0

 DO
  Key$ = UCASE$(INKEY$)
 LOOP UNTIL LEN(Key$)
LOOP

SCREEN 0, , 0, 0: CLS

IF Sel = 5 THEN
  Handle = FREEFILE
  OPEN "SOUNDSYS.CFG" FOR BINARY AS #Handle
   PUT #Handle, , OS
   PUT #Handle, , xSound
   PUT #Handle, , xMusic
   PUT #Handle, , Quality&
  CLOSE #Hanlde
  PRINT "Changes have been saved."
 ELSEIF Sel = 6 THEN
  PRINT "Exited without saving."
END IF

SUB DrawBack
 Unf$ = STRING$(80, "²")

 COLOR 7, 8
 FOR I = 1 TO 25
  LOCATE I, 1: PRINT Unf$;
 NEXT
END SUB

SUB DrawWindow (YPos, XPos, YSize, XSize, Caption AS STRING, TextLine)
 Text$ = " þ " + Caption + " þ "
 CPos = (XSize \ 2) - (LEN(Text$) \ 2)
 COLOR 15, 1: LOCATE YPos, XPos: PRINT "Ú" + STRING$(CPos, "Ä") + Text$ + STRING$(XSize - CPos - LEN(Text$), "Ä");
 COLOR 7, 1: PRINT "¿"
 FOR Y = YPos + 1 TO YPos + YSize
  COLOR 15, 1: LOCATE Y, XPos: PRINT "³" + SPACE$(XSize);
  COLOR 7, 1: PRINT "³";
 NEXT Y
 COLOR 15, 1
 LOCATE Y, XPos: PRINT "À";
 COLOR 7, 1: PRINT STRING$(XSize, "Ä") + "Ù";
 COLOR 15, 1: LOCATE YPos + TextLine, XPos + 2: PRINT STRING$(XSize - 2, "Ä");

 COLOR 8, 0:
 FOR X = XPos + 1 TO XPos + XSize + 2
  LOCATE YPos + YSize + 2, X: PRINT CHR$(SCREEN(YPos + YSize + 2, X));
 NEXT

 FOR Y = YPos + 1 TO YPos + YSize + 1
  LOCATE Y, XPos + XSize + 2: PRINT CHR$(SCREEN(Y, XPos + XSize + 2));
 NEXT
 COLOR 7, 1
END SUB

FUNCTION GetExitNoSave
 DrawWindow 8, 27, 10, 26, "Are you sure?", 6

 LOCATE 10, 30: PRINT "Any changes you have"
 LOCATE 11, 30: PRINT "just made will be lost"
 LOCATE 12, 30: PRINT "if you exit now!"

 PCOPY 1, 3
 Sel = 1

 SCREEN 0, , 3, 0

 DO
  SELECT CASE Key$
   CASE CHR$(0) + "H": Sel = Sel - 1
   CASE CHR$(0) + "P": Sel = Sel + 1
   CASE CHR$(27): EXIT FUNCTION
   CASE CHR$(13), CHR$(32): EXIT DO
  END SELECT

  IF Sel > 2 THEN Sel = 2
  IF Sel < 1 THEN Sel = 1

  IF Sel = 1 THEN COLOR 15, 7 ELSE COLOR 15, 1
  LOCATE 16, 30: PRINT " Yes                  "
  IF Sel = 2 THEN COLOR 15, 7 ELSE COLOR 15, 1
  LOCATE 17, 30: PRINT " No                   "

  PCOPY 3, 0

  DO
   Key$ = UCASE$(INKEY$)
  LOOP UNTIL LEN(Key$)
 LOOP
 GetExitNoSave = Sel
END FUNCTION

FUNCTION GetExitSave
 DrawWindow 8, 27, 10, 26, "Are you sure?", 6

 LOCATE 10, 30: PRINT "Any old settings will"
 LOCATE 11, 30: PRINT "be written over if you"
 LOCATE 12, 30: PRINT "save these."

 PCOPY 1, 3
 Sel = 1

 SCREEN 0, , 3, 0

 DO
  SELECT CASE Key$
   CASE CHR$(0) + "H": Sel = Sel - 1
   CASE CHR$(0) + "P": Sel = Sel + 1
   CASE CHR$(27): EXIT FUNCTION
   CASE CHR$(13), CHR$(32): EXIT DO
  END SELECT

  IF Sel > 2 THEN Sel = 2
  IF Sel < 1 THEN Sel = 1

  IF Sel = 1 THEN COLOR 15, 7 ELSE COLOR 15, 1
  LOCATE 16, 30: PRINT " Yes                  "
  IF Sel = 2 THEN COLOR 15, 7 ELSE COLOR 15, 1
  LOCATE 17, 30: PRINT " No                   "

  PCOPY 3, 0

  DO
   Key$ = UCASE$(INKEY$)
  LOOP UNTIL LEN(Key$)
 LOOP
 GetExitSave = Sel
END FUNCTION

FUNCTION GetOS
 DrawWindow 5, 20, 15, 40, "Select operating system", 6
 
 LOCATE 7, 23: PRINT "Please select the operating system"
 LOCATE 8, 23: PRINT "which you are currently running from"
 LOCATE 9, 23: PRINT "the list below."
 
 PCOPY 1, 3
 Sel = 1

 SCREEN 0, , 3, 0

 DO
  SELECT CASE Key$
   CASE CHR$(0) + "H": Sel = Sel - 1
   CASE CHR$(0) + "P": Sel = Sel + 1
   CASE CHR$(27): EXIT FUNCTION
   CASE CHR$(13), CHR$(32): EXIT DO
  END SELECT
 
  IF Sel > 7 THEN Sel = 7
  IF Sel < 1 THEN Sel = 1
 
  IF Sel = 1 THEN COLOR 15, 7 ELSE COLOR 15, 1
  LOCATE 13, 23: PRINT " Windows 95                         "
  IF Sel = 2 THEN COLOR 15, 7 ELSE COLOR 15, 1
  LOCATE 14, 23: PRINT " Windows 98                         "
  IF Sel = 3 THEN COLOR 15, 7 ELSE COLOR 15, 1
  LOCATE 15, 23: PRINT " Windows ME                         "
  IF Sel = 4 THEN COLOR 15, 7 ELSE COLOR 15, 1
  LOCATE 16, 23: PRINT " Windows NT                         "
  IF Sel = 5 THEN COLOR 15, 7 ELSE COLOR 15, 1
  LOCATE 17, 23: PRINT " Windows 2000                       "
  IF Sel = 6 THEN COLOR 15, 7 ELSE COLOR 15, 1
  LOCATE 18, 23: PRINT " Windows XP                         "
  IF Sel = 7 THEN COLOR 15, 7 ELSE COLOR 15, 1
  LOCATE 19, 23: PRINT " I don't know                       "

  PCOPY 3, 0

  DO
   Key$ = UCASE$(INKEY$)
  LOOP UNTIL LEN(Key$)
 LOOP
 GetOS = Sel
END FUNCTION

FUNCTION GetQuality
 DrawWindow 5, 21, 14, 38, "Select playback quality", 9

 LOCATE 7, 24: PRINT "Please select the playback quality"
 LOCATE 8, 24: PRINT "you would like to use. Remeber:"
 LOCATE 9, 24: PRINT "Low quality will play the fastest,"
LOCATE 10, 24: PRINT "but sound the worst. High quality"
LOCATE 11, 24: PRINT "will play the slowest, but sound"
LOCATE 12, 24: PRINT "the best."

 PCOPY 1, 3
 Sel = 1

 SCREEN 0, , 3, 0

 DO
  SELECT CASE Key$
   CASE CHR$(0) + "H": Sel = Sel - 1
   CASE CHR$(0) + "P": Sel = Sel + 1
   CASE CHR$(27): EXIT FUNCTION
   CASE CHR$(13), CHR$(32): EXIT DO
  END SELECT

  IF Sel > 3 THEN Sel = 3
  IF Sel < 1 THEN Sel = 1

  IF Sel = 1 THEN COLOR 15, 7 ELSE COLOR 15, 1
  LOCATE 16, 24: PRINT " High quality (44,050Hz)          "
  IF Sel = 2 THEN COLOR 15, 7 ELSE COLOR 15, 1
  LOCATE 17, 24: PRINT " Medium quality (22,025Hz)        "
  IF Sel = 3 THEN COLOR 15, 7 ELSE COLOR 15, 1
  LOCATE 18, 24: PRINT " Low quality (11,012Hz)           "

  PCOPY 3, 0

  DO
   Key$ = UCASE$(INKEY$)
  LOOP UNTIL LEN(Key$)
 LOOP
 GetQuality = Sel
END FUNCTION

