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

      PROGRAM MAIN

      INTEGER*4 ORIGINAL, MEM0, MEM1, MEM2
      INTEGER*2 MODE, OLD_MODE
      INTEGER*2 STATUS
      INTEGER*4 FG_MEMAVAIL
      INTEGER*2 FG_ALLOCATE, FG_FREEPAGE
      INTEGER*2 FG_GETMODE, FG_TESTMODE

      WRITE(6,*) 'Which video mode?'
      READ(5,*) MODE

      IF (FG_TESTMODE(MODE,0) .EQ. 0) THEN
         STOP 'Your system does not support that video mode.'
      ELSE IF (FG_TESTMODE(MODE,3) .EQ. 0) THEN
         STOP 'Your system does not have enough memory.'
      END IF

      ORIGINAL = FG_MEMAVAIL()
      OLD_MODE = FG_GETMODE()
      CALL FG_SETMODE(MODE)
      MEM0 = FG_MEMAVAIL()
      STATUS = FG_ALLOCATE(1)
      MEM1 = FG_MEMAVAIL()
      STATUS = FG_ALLOCATE(2)
      MEM2 = FG_MEMAVAIL()

      STATUS = FG_FREEPAGE(1)
      STATUS = FG_FREEPAGE(2)
      CALL FG_SETMODE(OLD_MODE)
      CALL FG_RESET

      WRITE(6,*) 'origanally     =', ORIGINAL
      WRITE(6,*) 'after setmode  =', MEM0
      WRITE(6,*) 'after 1st page =', MEM1
      WRITE(6,*) 'after 2nd page =', MEM2
      WRITE(6,*) 'at end         =', FG_MEMAVAIL()

      STOP ' '
      END
