!*! Updated on 15-Dec-92 at 11:56 PM by James A. Jarboe I V; edit time: 1:23:30
!*! Created on 15-Oct-91 at 1:16 AM by James A. Jarboe I V; edit time: 0:03:58
!****************************************************************************
! 
! SELFLD.BAS - Sample ESP program to test TOOLBZ.SBR xcall subroutines.
!
!****************************************************************************
! [101] 15-Dec-92 - updated comments and off to AMUS.
! [100] 15-Oct-90 by James A. Jarboe I V
!
! Sample program to show usage of:
! TOOLBZ.SBR - Available on AMUS Network.
! TOOLBZ.BSI - Available on AMUS Network.
! And
! Additional argument value on GTSCR.SBR
!
! This Program uses:
!  SELFLD.SCR - Available on AMUS Network
!  SELFL2.SCR - Available on AMUS Network

++include SYSSTD.BSI 		! ESP standard values.
++include TOOLBZ.BSI		! TOOLBZ.SBR offsets and user flags.

MAP1 SCREEN1$, S, 26, "SELFLD.SCR"
MAP1 SCREEN2$, S, 26, "SELFL2.SCR"

MAP1 SCREEN1, X, 3500		! Main ESP screen buffer.
MAP1 SCREEN2, X, 2500		! SELFL2 screen buffer.

MAP1 SC1'FLDCNT, F		! Screen 1 field count.
MAP1 SC2'FLDCNT, F		! Screen 2 field count.

MAP1 SC1'SCRSIZ, F 	 	! Screen 1 size in bytes.
MAP1 SC2'SCRSIZ, F		! Screen 2 size in bytes.

MAP1 CHAR2,  F			! Screen 2 Character value.
MAP1 FIELD2, F			! Screen 2 Field number.

MAP1 PREVSELECT, F		! Previous selection value.
MAP1 SELVAL, F			! Select value.
MAP1 A, F			! Misc 
MAP1 Z, F			! Misc
MAP1 FFVAL(8), f		! Flag values to match second screen.

! The following are field selection flag values used with GTSCR's extended
! argument field. Usually GTSCR is called.
!
!	XCALL GTSCR, SCREEN, CHAR, FIELD
!
! When using GTSCR as with an additional argument field you can designate
! some Field select options:
!
!	XCALL GTSCR, SCREEN, CHAR, FIELD ,ESP'FLSSEL
! 
! Field Select options. (Defined in TOOLBZ.BSI)
!
!MAP1  ESP'FLSSEL, f, 6		      ! Flag value for Select screen.
!MAP1  ESP'FLSDEC, f, 6,   512*65536   ! Use filler character as edit filler.
!MAP1  ESP'FLSSLA, f, 6,  1024*65536   ! Allow selection of ALL fields.
!MAP1  ESP'FLSNEV, f, 6,  2048*65536   ! DON'T evaluate expressions.
!MAP1  ESP'FLSNRF, f, 6,  4096*65536   ! DON'T print report only fields.
!MAP1  ESP'FLSDSL, f, 6,  8192*65536   ! Disable selection during select mode.
!MAP1  ESP'FLSSLM, f, 6, 16384*65536   ! Select mode enabled.
!MAP1  ESP'FLSDBF, f, 6, 32768*65536   ! Display blanked field(s).

! Returned flag values for TBX'GETFLUF (Get Field User flags.)
! 
! (Defined in TOOLBZ.BSI)
!
!MAP1 FLUF'HIDE,   F, 6, 1    ! Returned if field is hidden.
!MAP1 FLUF'SKIP,   F, 6, 2    ! Returned if field is skipped.
!MAP1 FLUF'SELECT, F, 6, 4    ! Returned if field is Selected.


! Start of SELFLD program Example.
!
SELFLD:
! Always properly init terminal.
!
	XCALL INITRM,"Testing TOOLBZ.SBR", "By James A. Jarboe IV"

! Fetch needed screens.
!
	XCALL FETCH, SCREEN1$, SCREEN1, X
	IF X goto BAD'SCREEN
	XCALL FETCH, SCREEN2$, SCREEN2, X
	IF X goto BAD'SCREEN

! Set up needed situation.
!
	CALL SET'MAIN'SCREEN

! Always properly open screens for windowing.
!
	XCALL OPNSCR, SCREEN1
	FIELD = 1
	CHAR = ESP'BEGLIN

! Main Screen loop
!
GET'SCREEN:

! Set main screen to use the filler character "." to demonstrate.
!
	XCALL GTSCR, SCREEN1, CHAR, FIELD, ESP'FLSDEC+ASC(".")

	IF (CHAR AND 255)=ESP'MENU GOTO ALLDUN
	IF (CHAR AND 255)=ESP'EXECUTE GOTO ALLDUN

	IF (CHAR AND ESP'PREEDIT) THEN call DO'SELECT

	GOTO GET'SCREEN

! End of Processsing.
!
ALLDUN:
	XCALL CLSSCR, SCREEN1
	XCALL INITRM
	END


! Set up second screen for Space bar selection.
!
DO'SELECT:

	! Get Field value from main screen to set second screen select
	!  values accordingly.
	!
	XCALL GETVAL, SCREEN1, 7, PREVSELECT

	! Open Second screen properly.
	!
	XCALL OPNSCR, SCREEN2

	! Set proper fields as selected or unselected.
	!
	A = 2			! Set first value to test for.
	FOR X = 1 to 8
		
		! First always make field as Deselected (Dim)
		!
		XCALL TOOLBZ, TBX'SELFLD, SCREEN2, X, FALSE

		! Get individual screen value using logical AND.
		!
		Z = (PREVSELECT AND A)  

		! If we match flag value make field as Selected (Bright)	
		!
		IF Z > 0   XCALL TOOLBZ, TBX'SELFLD, SCREEN2, X, TRUE 

		A=A*2      ! Bump to next bit.

	NEXT X


! Flags NOT set, so we will not:
! ESP'FLSSLA - Select all fields, (use only those that are NOT display only).
! ESP'FLSNEV - DON'T evaluate expressions. (We will evaluate any expressions).
! ESP'FLSNRF - DON'T print report only fields. (We will print report fields).
! ESP'FLSDSL - Disable selection during select mode. (We are enabling select).
!

! According to FLAG values set below, we will do:
! ESP'FLSDEC - Use default filler character (SPACE).
! ESP'FLSSLM - Enable Select mode.
! ESP'FLSDBF - Also display any blank fields.

	ESP'FLSSEL = ESP'FLSDEC OR ESP'FLSSLM OR ESP'FLSDBF

! Set display all fields in case we enter this screen more than once.
!
	CHAR2  = ESP'DAF        ! Preset Display all fields.
	FIELD2 = 1		! Always set first field.

! Select screen editing with added argument flag.
!
EDIT'SELECT:

	! **NOTE***  
	! This is an example of the extra argument on GTSCR call
	! that allows field selection flags.
	!
	XCALL GTSCR, SCREEN2, CHAR2, FIELD2 ,ESP'FLSSEL

	! If user presses menu on this screen make NO changes.
	!
	IF (CHAR2 AND 255) =ESP'MENU goto CLOSE'1

	! If user presses EXECUTE then collect changes.
	!
	IF (CHAR2 AND 255) = ESP'EXECUTE goto SET'CLOSE'1

	GOTO EDIT'SELECT


! User pressed EXECUTE, they want the change.
!
SET'CLOSE'1:

	! Preclear previous selection flags.
	!
	PREVSELECT = 0

	! First we see what they selected.
	!
	FOR X = 1 to 8
	
		! Get field user flags.
		!
		XCALL TOOLBZ, TBX'GETFLUF, SCREEN2, X, SELVAL	
		
		! If field was selected save selection value.
		!
		IF (SELVAL AND FLUF'SELECT) = FLUF'SELECT then &
			PREVSELECT = PREVSELECT OR FFVAL(X)
	NEXT X

	! Then we set the value in the first screen.
	!
	XCALL SETVAL, SCREEN1, 7, PREVSELECT

! Always close screen properly.
!
CLOSE'1:
	XCALL CLSSCR, SCREEN2
	RETURN


! Set up the main SCREEN.
!
SET'MAIN'SCREEN:

	! Get sequential file size of screens.
	!
	XCALL TOOLBZ, TBX'SQFLSZ, SCREEN1$, SC1'SCRSIZ
	XCALL TOOLBZ, TBX'SQFLSZ, SCREEN2$, SC2'SCRSIZ

	! Get total field count of screens.
	!
	XCALL TOOLBZ, TBX'FLDCNT, SCREEN1, SC1'FLDCNT
	XCALL TOOLBZ, TBX'FLDCNT, SCREEN2, SC2'FLDCNT

	! Set wanted values in First screen.
	!
	XCALL SETVAL, SCREEN1, 1,  SCREEN1$, SC1'SCRSIZ, SC1'FLDCNT, &
				   SCREEN2$, SC2'SCRSIZ, SC2'FLDCNT, 130
	
	
	! Set up appropriate values for selection.
	! This could be set up any number of ways, but for simple
	! testing this is appropriate. It could be gotten from the
	! ESP screen.
	!
	A = 2
	FOR X = 1 to 8
		FFVAL(X) = A
		A=A*2
	NEXT X
	RETURN


BAD'SCREEN:
	XCALL ERRDSP, "ESP Screen problem"
	END

++include ERRSBR

END