' This source may not be resold, redistributed, or disfigured for release
' in any way, it is copyright material.  Offenders will be found!
'
' The source is part of the MAGNUM PRO package available only from 
' the F1 Licenceware range.  If you have obtained this through other 
' means you are advised to delete this copy and purchase the original: 
' copies can be changed and could carry viruses and damage your Amiga! 
'
' Considering the low price, there is no excuse for piracy.
'
' (5.2.94) 
'
'
' *** Setup some amos system flags 
' *** Remove AMOS LOCK to enable Amiga-A multi-tasking 
Set Buffer 40
'
'
Amos Lock 
Break Off 
Track Loop On 
Hide 
'
'
' *** Set up the panel gfx by loading it and packing it
'
Load Iff "magnum.panel",0
Screen Hide 0 : Spack 0 To 5 : Screen Close 0
'
'
' *** Load up music, bug in TRACK LOAD extension, needs path tagged on 
'
' MON 1/0 ... music on/off 
' MUZAK ... tracker music present  
If Exist("magnum.music")=-1
   BUG$=Dir$
   Track Load BUG$+"magnum.music",3 : Led Off : MON=1 : MUZAK=True : Track Play 
End If 
'
'
' *** bad loop to load title pics
'
If Exist("magnum.t1")=-1 Then A$="magnum.t1" : Gosub _SHOWPIC
If Exist("magnum.t2")=-1 Then A$="magnum.t2" : Gosub _SHOWPIC
If Exist("magnum.t3")=-1 Then A$="magnum.t3" : Gosub _SHOWPIC
If Exist("magnum.t4")=-1 Then A$="magnum.t4" : Gosub _SHOWPIC
If Exist("magnum.t5")=-1 Then A$="magnum.t5" : Gosub _SHOWPIC
Goto FIN_INTRO
' *** subroutine to fade intro pictures in and out 
_SHOWPIC:
Load Iff A$,0 : Screen Hide 0
GW=Screen Colour : Screen Open 1,100,10,GW,Lowres
Screen Hide 1 : Flash Off : Curs Off 
Get Palette 0
Screen 0 : Fade 1 : Wait 15
Screen Show 0 : Fade 3 To 1 : Wait 45 : Screen Close 1
Wait 220 : Fade 2 : Wait 30 : Screen Close 0
Return 
FIN_INTRO:
'
'
'
' -----------------------------------------------------------------------
'              Define (global) variables for ascii reader
' -----------------------------------------------------------------------
Dim ITEM$(500),BOOT$(500),RGB$(4)
Dim PAGESTART(200),PAGEEND(200),PAGE_PEN(200)
Global CURRENT_PAGE,PAGE_NUM,INDXL,ITEM$(),BOOT$(),TITLE$,RGB$(),POSITION2,NUM
Global FILE_LENGTH,PAGESTART(),PAGEEND(),PAGE_LENGTH,FILE_PRESENT
Global NO_INDEX,CUR_INDEX,PICCY,CUR_PEN,PAGE_PEN(),TXTFADE
FILE_PRESENT=False
CURRENT_PAGE=0
PAGE_LENGTH=24
CUR_INDEX=0
NO_INDEX=1 : Rem 1 page as default
CUR_PEN=1
'
'
' -----------------------------------------------------------------------
MAKE_INDEX : SET_UP_SCREENS : Change Mouse 4 : Show : Screen 2
'
' Loops are here, complicated!  Spaghetti junction...
'
Repeat 
   Do 
      '==========================================================================
      Screen 1
      POSITION1=Mouse Zone
      Screen 2
      '==========================================================================
      If FILE_PRESENT=0 and PICCY=0
         POSER=Mouse Zone
         POSITION2=POSER+(CUR_INDEX*20)
         If POSER and(POSER<>OLD)
            If Left$(BOOT$(POSITION2-9),7)<>"*empty*"
               Locate 0,POSER-6
               Inverse On : Centre ITEM$(POSITION2-9)
            End If 
            If OLD
               Locate 0,OLD-6
               Inverse Off : Centre ITEM$(OLDEN-9)
            End If 
            OLD=POSER
            OLDEN=POSITION2
         End If 
         If POSER=0 and OLD<>0
            Inverse Off 
            Locate 0,OLD-6
            Centre ITEM$(OLDEN-9)
            OLD=0
            OLDEN=0
         End If 
         Inverse Off 
      End If 
      '==========================================================================
      Screen 1
      KEYS$=Inkey$
      If KEYS$<>"" Then Exit 
      Exit If Mouse Click
   Loop 
   '==========================================================================
   If PICCY
      If POSITION1=1 or Key State(69)
         Screen Close 2 : OPEN_HIRES : SET_UP_INDEX : PICCY=0 : POSITION2=0 : OLD=0
         Limit Mouse X Hard(0),Y Hard(0) To X Hard(640),Y Hard(256)
      End If 
      If(KEYS$="" and POSITION1=2) or(Upper$(KEYS$)="S")
         If MUZAK=True
            If MON=1
               MON=0 : Track Stop 
            Else 
               MON=1 : Track Play 
            End If 
         End If 
      End If 
      If POSITION1=6 or((Key Shift=1 or Key Shift=2) and Key State(69))
         End 
      End If 
      Goto ZZTOP
   End If 
   '==========================================================================
   If(KEYS$="" and POSITION1=2) or(Upper$(KEYS$)="S")
      If MUZAK=True
         If MON=1
            MON=0 : Track Stop 
         Else 
            MON=1 : Track Play 
         End If 
      End If 
   End If 
   '  ^- Sound on/off zone
   If((Key Shift=1 or Key Shift=2) and Key State(69))
      End 
   End If 
   '  ^- Quit by SHIFT+ESCAPE 
   If Key State(69) and FILE_PRESENT Then SET_UP_INDEX : POSITION2=0 : OLD=0 : FILE_PRESENT=0
   '  ^- Reset INDEX
   '==========================================================================
   If KEYS$="" Then Goto CHECK_D_ZONES
   If KEYS$=Chr$(28) and FILE_PRESENT Then PAGE_DOWN
   If KEYS$=Chr$(29) and FILE_PRESENT Then PAGE_UP
   If KEYS$=Chr$(30) and FILE_PRESENT Then PAGE_SHOW[0]
   If KEYS$=Chr$(31) and FILE_PRESENT Then PAGE_SHOW[PAGE_NUM-1]
   If KEYS$=Chr$(32) and FILE_PRESENT Then CHOOSE_PAGE
   If KEYS$=Chr$(69) and FILE_PRESENT Then SET_UP_INDEX : POSITION2=0 : OLD=0 : FILE_PRESENT=0
   If KEYS$=Chr$(30) and FILE_PRESENT=0 Then CUR_INDEX=0 : SET_UP_INDEX : POSITION2=0 : OLD=0
   If KEYS$=Chr$(31) and FILE_PRESENT=0 Then CUR_INDEX=NO_INDEX-1 : SET_UP_INDEX : POSITION2=0 : OLD=0
   If KEYS$=Chr$(32) and FILE_PRESENT=0 Then CHOOSE_INDEX : POSITION2=0 : OLD=0
   If KEYS$=Chr$(29) and FILE_PRESENT=0 Then INDEX_UP : POSITION2=0 : OLD=0
   If KEYS$=Chr$(28) and FILE_PRESENT=0 Then INDEX_DOWN : POSITION2=0 : OLD=0
   If POSITION2 and FILE_PRESENT=0 and(KEYS$=Chr$(13)) Then FILE_LOADER[BOOT$(POSITION2-9)]
   Goto ZZTOP
   '==========================================================================
   CHECK_D_ZONES:
   If POSITION1=1 and FILE_PRESENT Then SET_UP_INDEX : POSITION2=0 : OLD=0 : FILE_PRESENT=0
   If POSITION1=3 and FILE_PRESENT Then PAGE_SHOW[0]
   If POSITION1=4 and FILE_PRESENT Then PAGE_SHOW[PAGE_NUM-1]
   If POSITION1=5 and FILE_PRESENT Then CHOOSE_PAGE
   If POSITION1=9 and FILE_PRESENT Then PAGE_SHOW[0]
   If POSITION1=10 and FILE_PRESENT Then PAGE_SHOW[PAGE_NUM-1]
   If POSITION1=6 Then FINISH
   If POSITION1=7 and FILE_PRESENT Then PAGE_UP
   If POSITION1=8 and FILE_PRESENT Then PAGE_DOWN
   If POSITION1=3 and FILE_PRESENT=0 Then CUR_INDEX=0 : SET_UP_INDEX : POSITION2=0 : OLD=0
   If POSITION1=4 and FILE_PRESENT=0 Then CUR_INDEX=NO_INDEX-1 : SET_UP_INDEX : POSITION2=0 : OLD=0
   If POSITION1=5 and FILE_PRESENT=0 Then CHOOSE_INDEX : POSITION2=0 : OLD=0
   If POSITION1=7 and FILE_PRESENT=0 Then INDEX_UP : POSITION2=0 : OLD=0
   If POSITION1=8 and FILE_PRESENT=0 Then INDEX_DOWN : POSITION2=0 : OLD=0
   If POSITION1=9 and FILE_PRESENT=0 Then CUR_INDEX=0 : SET_UP_INDEX : POSITION2=0 : OLD=0
   If POSITION1=10 and FILE_PRESENT=0 Then CUR_INDEX=NO_INDEX-1 : SET_UP_INDEX : POSITION2=0 : OLD=0
   If POSITION2 and FILE_PRESENT=0 Then FILE_LOADER[BOOT$(POSITION2-9)]
   '==========================================================================
   ZZTOP:
   POSER=0
   POSITION1=0
   KEYS$=""
   Clear Key 
   If PICCY
      Screen 0 : Cls 0 : Home : Print ITEM$(POSITION2-9);
      X$="Page 1 of 1" : Locate 79-Len(X$),0 : Print X$;
   End If 
   '==========================================================================
Until False
'
'
'
'
' -----------------------------------------------------------------------
'                           Procedures are here
' -----------------------------------------------------------------------
Procedure FINISH
   Timer=0
   Repeat 
      If Mouse Click and Mouse Zone=6 Then End 
   Until Timer>45
End Proc
' -----------------------------------------------------------------------
Procedure PAGE_UP
   If CURRENT_PAGE>0
      Dec CURRENT_PAGE
      PAGE_SHOW[CURRENT_PAGE]
   End If 
End Proc
' -----------------------------------------------------------------------
Procedure PAGE_DOWN
   If CURRENT_PAGE<PAGE_NUM-1
      Inc CURRENT_PAGE
      PAGE_SHOW[CURRENT_PAGE]
   End If 
End Proc
' -----------------------------------------------------------------------
Procedure INDEX_UP
   If CUR_INDEX>0
      Dec CUR_INDEX
      SET_UP_INDEX
   End If 
End Proc
' -----------------------------------------------------------------------
Procedure INDEX_DOWN
   If CUR_INDEX<NO_INDEX-1
      Inc CUR_INDEX
      SET_UP_INDEX
   End If 
End Proc
' -----------------------------------------------------------------------
Procedure FILE_LOADER[F$]
   TEMP=0
   On Error Goto FATEL_ERROR4
   If Left$(F$,7)="*empty*" Then Goto RECOVER_4
   If Left$(F$,5)<>"*iff*" Then Goto TESTLOAD2
   F$=F$-"*iff*"
   Open In 1,F$
   FILE_LENGTH=Lof(1)
   Close 1
   Erase 10
   If Chip Free+Fast Free>FILE_LENGTH+1024
      Load Iff F$,2
      Screen Display 2,,56,,200
      PICCY=True
   End If 
   Goto RECOVER_4
   '
   TESTLOAD2:
   If Left$(F$,7)<>"*music*" Then Goto TXT
   F$=F$-"*music*"
   If Exist(F$)=-1
      Track Stop : Erase 3 : Track Load F$,3 : Track Play 
      MUZAK=1
   End If 
   Goto RECOVER_4
   '
   TXT:
   Open In 1,F$
   FILE_LENGTH=Lof(1)
   Close 1
   Erase 10
   If Chip Free+Fast Free>FILE_LENGTH+1024
      Reserve As Work 10,FILE_LENGTH
      Bload F$,10
      FILE_PROCESS
      FILE_PRESENT=True
   End If 
   RECOVER_4:
   Close 
   Pop Proc
   FATEL_ERROR4:
   TEMP=1
   Resume RECOVER_4
End Proc[TEMP]
' -----------------------------------------------------------------------
Procedure SET_UP_SCREENS
   OPEN_HIRES
   OPEN_TELETEXT
   Unpack 5 To 1 : Erase 5
   Screen Display 1,,259,,
   Restore POSITION_OF_ZONES
   Reserve Zone 10
   For LOP=1 To 8
      Read X1,X2
      If LOP<7
         Set Zone LOP,X1,6 To X2,33
      Else 
         Set Zone LOP,X1,14 To X2,24
      End If 
   Next LOP
   Set Zone 9,295,4 To 306,14
   Set Zone 10,295,24 To 306,34
   Screen 0
   Limit Mouse X Hard(0),Y Hard(0) To X Hard(640),Y Hard(256)
   SET_UP_INDEX
   For I=0 To 2
      Screen I
      Colour 18,Val("$"+RGB$(2))
      Colour 19,Val("$"+RGB$(3))
   Next I
   POSITION_OF_ZONES:
   Data 5,48,52,93,97,138,142,183,187,228,232,274,285,294,307,316
End Proc
'
' By writing an editor or just changing the zone sizes etc. and the panel you
' can create a much better user interface.  Originally I styled it on
' GrapeVine (Hi LSD!) which led to some people thinking GV was coded with
' Magnum...  It wasn't but if it was I would be wanting royalty payments off 
' LSD at this stage! 
' -----------------------------------------------------------------------
Procedure OPEN_HIRES
   Screen Open 2,640,200,8,Hires
   Screen Hide 2
   Screen Display 2,,56,,
   Curs Off : Flash Off : Cls 0
   Palette $0,$EEE,$C00,$CC0,$C0,$CC,$C,$C0C
   Paper 0
   If PICCY
      Colour 18,Val("$"+RGB$(2))
      Colour 19,Val("$"+RGB$(3))
   End If 
   Screen Show 2
End Proc
' -----------------------------------------------------------------------
Procedure OPEN_TELETEXT
   Screen Open 0,640,9,2,Hires
   Screen Hide 0
   Screen Display 0,,44,,
   Curs Off 
   Colour 0,Val("$"+RGB$(0))
   Colour 1,Val("$"+RGB$(1))
   Paper 0
   Pen 1
   Set Curs 255,255,255,255,255,255,255,255
   Screen Show 0
End Proc
' -----------------------------------------------------------------------
Procedure SET_UP_INDEX
   Screen 0 : Cls 0 : Home 
   Pen 1
   Print "Index";
   X$="Page"+Str$(CUR_INDEX+1)+" of"+Str$(NO_INDEX)
   Locate 79-Len(X$),0 : Print X$;
   '
   Screen 2 : Palette 0,0,0,0,0,0,0,0 : Cls 0
   Pen 1 : Home : Print TITLE$
   Zoom 2,0,0,240,8 To 2,0,8,640,16
   Pen 0 : Home : Print TITLE$ : Cdown : Cdown : Pen 1
   '
   ' This creates the larger text by stretching it
   '
   STA=CUR_INDEX*20
   If NO_INDEX>CUR_INDEX+1
      FIN=STA+19
   Else 
      FIN=INDXL-1
      Q=FIN-STA
      If Q>19
         Q=Q-19
         FIN=FIN-Q
      End If 
   End If 
   '
   Reserve Zone 28
   Z=0
   For I=STA To FIN
      If ITEM$(I)<>""
         If ITEM$(I)<>"*empty*"
            Centre Zone$(ITEM$(I),Z+9)
         End If 
      End If 
      Inc Z
      Cdown 
   Next I
   Fade 1,0,$EEE,$C00,$CC0,$C0,$CC,$C,$C0C
   Wait 15
   TXTFADE=0 : Rem Turn off textfading
End Proc
' -----------------------------------------------------------------------
Procedure CHOOSE_PAGE
   Screen 0 : Cls 0 : Clear Key : Pen 1
   Input "Please enter page number to access:";A
   Curs Off 
   If A<1 or A>PAGE_NUM
      Print "No such page."; : Wait 45
      Cls 0 : Home 
      Print ITEM$(POSITION2-9);
      X$="Page"+Str$(NUM+1)+" of"+Str$(PAGE_NUM)
      Locate 79-Len(X$),0 : Print X$;
      Screen 1
      Pop Proc
   End If 
   PAGE_SHOW[A-1]
   CURRENT_PAGE=A-1
   Screen 1
End Proc
' -----------------------------------------------------------------------
Procedure CHOOSE_INDEX
   Screen 0 : Cls 0 : Clear Key : Pen 1
   Input "Please enter page number to access:";A
   Curs Off 
   If A<1 or A>NO_INDEX
      Print "No such page."; : Wait 45
      Cls 0 : Home 
      Print "Index";
      X$="Page"+Str$(CUR_INDEX+1)+" of"+Str$(NO_INDEX)
      Locate 79-Len(X$),0 : Print X$;
      Screen 1
      Pop Proc
   End If 
   CUR_INDEX=A-1
   SET_UP_INDEX
   Screen 1
End Proc
' -----------------------------------------------------------------------
Procedure MAKE_INDEX
   ' Be sure to understand this first!  It loads in the index file and
   ' processes it, writing the user text into relevant strings. 
   ' Be careful!
   '
   Open In 1,"magnum.index"
   Z=0
   For I=0 To 3
      Repeat 
         X$=Input$(1,1)
         If Asc(X$)=10 Then Exit 
         RGB$(I)=RGB$(I)+X$
      Until Eof(1)=-1
   Next I
   Repeat 
      X$=Input$(1,1)
      If Asc(X$)=10 Then Exit 
      TITLE$=TITLE$+X$
   Until Eof(1)=-1
   '************************
   Repeat 
      Repeat 
         X$=Input$(1,1)
         If Asc(X$)=10 Then Exit 
         ITEM$(Z)=ITEM$(Z)+X$
      Until Eof(1)=-1
      Repeat 
         If Left$(ITEM$(Z),7)="*empty*" Then BOOT$(Z)="*empty*" : Exit 
         X$=Input$(1,1)
         If Asc(X$)=10 Then Exit 
         BOOT$(Z)=BOOT$(Z)+X$
      Until Eof(1)=-1
      Inc ZAP
      If ZAP=21 Then ZAP=0 : Inc NO_INDEX
      Inc Z
      If Z=200 Then Exit 
   Until Lof(1)-Pof(1)<2
   Close 1
   INDXL=Z
End Proc
' -----------------------------------------------------------------------
Procedure FILE_PROCESS
   CUR_PEN=1
   '  ^-------------------------------- PEN COLOUR RESET
   '
   ' I pinched some of these bits from the _old_ ASCII reader in the AMOS 
   ' package.  I was going to do my own then I noticed everyone was using 
   ' _this_ same routine so why not join the band wagon eh? 
   '
   PAGE_NUM=0
   LINES=-1
   TEMP=0
   COUNT=0
   '   CONVERT
   ST=Start(10)
   EN=Start(10)+FILE_LENGTH
   COUNT=ST
   Repeat 
      If PAGE_NUM=0
         PAGESTART(PAGE_NUM)=ST
      Else 
         PAGESTART(PAGE_NUM)=COUNT+1
      End If 
      LINES=0
      Repeat 
         Inc LINES
         Inc COUNT
         TEMP=False
         Repeat 
            A=Hunt(COUNT To EN,Chr$(10))
            If(A-COUNT>79) or A=0
               Add COUNT,79
               TEMP=True
            Else 
               COUNT=A
            End If 
         Until COUNT=>EN or A<>0 or TEMP=True
      Until LINES=PAGE_LENGTH or COUNT=>EN
      PAGEEND(PAGE_NUM)=COUNT
      Inc PAGE_NUM
   Until COUNT=>EN or PAGE_NUM=200
   PAGEEND(PAGE_NUM-1)=EN
   '------------------------------------------- cols
   For ZQ=0 To PAGE_NUM-1
      C_ST=PAGESTART(ZQ) : C_EN=PAGEEND(ZQ)
      Do 
         A=Hunt(C_ST To C_EN,"@")
         If A
            B=A
            A=Peek(B+1)
            If A>=49 and A<=55
               PAGE_PEN(ZQ)=A-48
               CRAPPY=True
            End If 
            C_ST=B+1
         Else 
            If CRAPPY=False
               PAGE_PEN(ZQ)=1
            End If 
            Exit 
         End If 
      Loop 
      CRAPPY=False
   Next ZQ
   '------------------------------------------- end cols  
   Screen 0
   Cls 0 : Home 
   Print ITEM$(POSITION2-9);
   PAGE_SHOW[0]
   CURRENT_PAGE=0
   Screen 1
End Proc
' -----------------------------------------------------------------------
Procedure PAGE_SHOW[NUM]
   Screen 2
   If TXTFADE=-1
      Fade 1,0,0,0,0,0,0,0,0
      Wait 15
   Else 
      Palette 0,0,0,0,0,0,0
   End If 
   Cls 0
   '----------------------------------------------- finds text col
   If NUM=0 Then CUR_PEN=1 Else CUR_PEN=PAGE_PEN(NUM-1)
   Pen CUR_PEN
   '
   Home 
   Inverse Off 
   For I=PAGESTART(NUM) To PAGEEND(NUM)
      A=Peek(I)
      If Chr$(A)="@"
         A=Peek(I+1)
         If A>=49 and A<=55
            Pen A-48 : CUR_PEN=A-48 : Inc I
         Else 
            If A=102
               TXTFADE=-1 : Inc I
            Else 
               Print "@";
            End If 
         End If 
      Else 
         Print Chr$(A);
         If A=10
            Print Chr$(13);
         End If 
      End If 
   Next I
   If TXTFADE=-1
      Fade 1,0,$EEE,$C00,$CC0,$C0,$CC,$C,$C0C
      Wait 15
   Else 
      Palette 0,$EEE,$C00,$CC0,$C0,$CC,$C,$C0C
   End If 
   Screen 0
   Cls 0 : Home 
   Print ITEM$(POSITION2-9);
   X$="Page"+Str$(NUM+1)+" of"+Str$(PAGE_NUM)
   Locate 79-Len(X$),0 : Print X$;
   Screen 1
   CURRENT_PAGE=NUM
End Proc
