' This program and the file SHOW512.OBJ are Public Domain
' Use this routine in your GFA-BASIC 2.x/3.x programs to show
' uncompressed GFA-RAYTRACE 512-Color pictures.
'
' 12/18/91  I modified this code to load more than just 'DEMO.SUL' as
' it was in its original crippled state on the Raytrace V2.1 disks. Still
' doesn't handle compressed pics though...  Also via the file selector,
' it can be forced to load any file on disk (How indiscriminate!) - I'm
' too inept to figure out how to prevent that.  It does present a *.SUL
' filemask, but editing it and loading something else may be disastrous!
'
' 12/23/91 v1  TT/16mhz Alert added, Palette is now properly restored.
'              SHOW512.OBJ name changed to RAYVIEW.OBJ
'
' 12/29/91 v2  Removed A: drive letter from file selector, Rayview now
'              defaults to drive it was run from for next pic.
'
' I be interested in any modifications anyone attempts.  A full-blown
' slideshow program is needed.  And I still have hopes for a Raytrace to
' Spectrum/GIF converter...  Nick S. Smith 4406 5th Av S Minneapolis
' GEnie: S.Smith65    Compuserve: 70412,2667             MN   55409
'
' .SUL pictures can be created from within GFA Raytrace by using the save
' screen option when Uncompressed is selected in the STATUS menu.
'
ALERT 3,"Rayview Does Not|Run On A TT/030.|Mega STE's Must|Be Set To 8mhz!",2,"QUIT|VIEW",x
IF x=1
  END
ELSE IF x=2
  RESERVE FRE(0)-21000        ! reserve memory for routines & palettes
  base%=EXEC(3,"rayview.obj","","")     ! load routines
  IF base% AND 1
    ERROR base%
  ENDIF            ! continue only if routines loaded
  @savepal
  @initray         ! initialize routines and Palette-table
entrypoint:
  @loadray         ! load 512-colors picture
  CALL init%       ! Mode ON
  VOID INP(2)      ! Wait for a keypress...
  CALL exit%       ! Mode OFF
  SETCOLOR 0,&H777 ! now restore colors
  SETCOLOR 3,0
  CLS              ! And clear that screen!
  ALERT 2,"|View another |Raytrace pic?",2,"YES|QUIT",button
  IF button=1              ! If yes, then let's
    GOTO entrypoint        ! start at the beginning (eeek! a GOTO!)
  ELSE                     ! Otherwise,
    @terminate             ! Don't forget to clean up
  ENDIF
ENDIF                    ! the mess before you leave!
END                      ! P.S.  Say 'Bye-bye'
'
PROCEDURE savepal
  DIM i$(20),palette%(20)
  FOR i%=0 TO 15
    palette%(i%)=XBIOS(7,W:i%,W:-1)
  NEXT i%
RETURN
'
PROCEDURE loadray
  RESERVE FRE(0)-32000         ! Fileselectors need room to work in
  FILESELECT #"Choose a Raytrace Pic","*.SUL","",name$
  IF RIGHT$(name$)="\"         ! Did bozo select a file?
    ALERT 1,"|Please Choose a | GFA  Raytrace |*.SUL Pic File.",1,"OK",dummy
    @loadray                   ! If so, load it
  ELSE IF name$=""             ! If CANCEL, terminate
    @terminate
  ENDIF
  OPEN "i",#1,name$            ! open file
  SEEK #1,8                    ! skip file-type (used by GFA RAYTRACE)
  BGET #1,XBIOS(3),32000       ! load screen
  BGET #1,palbuf%,18400        ! load palettes in buffer
  CLOSE #1
RETURN
'
PROCEDURE initray
  ADD base%,256
  palbuf%=base%+3000           ! palettes behind routines (see Reserve)
  LPOKE base%,palbuf%          ! start palette-buffer
  init%=LPEEK(base%+4)         ! 512-colors On - routine
  exit%=LPEEK(base%+8)         ! 512-colors Off - routine
RETURN
'
PROCEDURE terminate            ! Restores palette & memory
  FOR i%=0 TO 15
    SETCOLOR i%,palette%(i%)
  NEXT i%
  VOID GEMDOS(73,L:HIMEM)      ! Or when QUIT was selected
  SUB base%,256                ! Was selected in the alert box
  VOID GEMDOS(73,L:base%)
  END
RETURN
