C****************************************************************************\
C                                                                            *
C  EXAMPLE.FOR                                                               *
C                                                                            *
C  This program illustrates how to use the DAC register values generated by  *
C  the GrabRGB routine.                                                      *
C                                                                            *
C****************************************************************************/

$INCLUDE: 'C:\FG\INTRFACE.FOR'

      PROGRAM MAIN

      CHARACTER*13 IMAGE_FILE
      INTEGER*2 RGB(93)
      INTEGER*2 I
      INTEGER*2 INDEX, RED, GREEN, BLUE
      INTEGER*2 OLD_MODE
      INTEGER*2 FG_GETMODE, FG_TESTMODE

C  The following values were obtained from a file (GRABRGB.nnn) created
C  when pressing the GrabRGB hot key while displaying a 256-color image.
C  Each DAC register is represented by four values:  the register index,
C  the red component, the green component, and the blue component.  The
C  DAC registers that used their default RGB components aren't included
C  in this list.

      DATA RGB /
     +   33,63,63,63,  34,21,21,21,  35,54,63,63,  36,48,48,48,
     +   37,38,38,38,  38,45,45,45,  39,35,35,35,  40,31,31,31,
     +   41,21,63,63,  42,42,42,42,  43, 8, 8, 8,  44,55,55,55,
     +   45,63,63,54,  66,59,59,59,  80, 0,16,16,  81,14,14,14,
     +  241, 0, 0,42, 242, 0,42, 0, 243, 0,42,42, 244,42, 0, 0,
     +  245,42, 0,42, 246,42,21, 0, 247,42,42,42,  -1/

C  Replace the value of IMAGE_FILE with the name of a 256-color standard
C  pixel run file.

      IMAGE_FILE = 'SNAPSHOT.000' // CHAR(0)

C  Make sure we can use the 256-color MCGA graphics mode.

      IF (FG_TESTMODE(19,1) .EQ. 0) THEN
         STOP 'This program requires a 256-color graphics mode.'
      END IF

C  Establish the video mode.

      OLD_MODE = FG_GETMODE()
      CALL FG_SETMODE(19)

C  Display the image using the default RGB components for each DAC.

      CALL FG_MOVE(0,199)
      CALL FG_DISPFILE(IMAGE_FILE,320,0)
      CALL FG_WAITKEY

C  Now change the components for each DAC in the RGB array.

      I = 1
10    IF (RGB(I) .GT. 0) THEN
         INDEX = RGB(I)
         I = I + 1
         RED   = RGB(I)
         I = I + 1
         GREEN = RGB(I)
         I = I + 1
         BLUE  = RGB(I)
         I = I + 1
         CALL FG_SETRGB(INDEX,RED,GREEN,BLUE)
         GO TO 10
      END IF
      CALL FG_WAITKEY

C  Restore the original video mode and screen attributes.

      CALL FG_SETMODE(OLD_MODE)
      CALL FG_RESET

      STOP ' '
      END
