;*************************** AMUS Program Label ******************************
; Filename: GETFPN.M68                                      Date: 12/13/92
; Category: ESP          Hash Code: 217-644-640-325      Version: 1.0(100)
; Initials: GR           Name: JAMES A. JARBOE IV
; Company: EDUCATIONAL VIDEO NETWORK, INC          Telephone #: 4092955767
; Related Files: GETFPN.BAS, GETFPN.SCR
; Min. Op. Sys.: 1.3D                          Expertise Level: BEG
; Special: Must have TOOLBX.SYS installed on your system
; Description: Gets an ESP Screen's field's PERMANENT FIELD NUMBER of the
; requested ESP screen's FIELD NUMBER. See GETFPN.BAS and GETFPN.M68 for
; usage.
;*****************************************************************************
;*; Updated on 13-Dec-92 at 11:43 PM by James A. Jarboe I V; edit time: 0:30:47
;*; Created on 13-Dec-92 at 6:16 PM by James A. Jarboe I V; edit time: 0:29:15
;***************************************************************************
;*                                                                         *
;*                              GETFPN.M68                                 *
;*                                                                         *
;*                     Written By: James A. Jarboe IV                      *
;*                            1401 19th Street                             *
;*                          Huntsville, TX 77340                           *
;*                              409-295-5767                               *
;*                                                                         *
;*                               13-Dec-92                                 *
;*                                 GR/AM                                   *
;***************************************************************************
;*                Copyright (c) 1992 - James A. Jarboe IV                  *
;*                   Unpublished - All rights reserved.                    *
;***************************************************************************
; GET Field's Permanent Number.
;
; Description: - AlphaBASIC interface to find an ESP Field's PERMANENT
;                ID number using the field's current FIELD NUMBER
;                and return the Permanaent field number.
;                Each field in an ESP screen has a permanent ID number
;                or what is called a Field ID (FL.FID). Once a field
;                is created in ESP it will always retain this field ID
;                number as a permanent value.  This is NOT to be confused
;                with the FIELD NUMBER as indicated as the first field
;                in CHANGE mode in SEDIT. The FIELD NUMBER can be
;                set to a different value which is the Sequence number
;                that the field accessed by. The FIELD ID (Permanent ID)
;                is the field's permanent number. An ESP field's
;                Permanent ID never changes once it is created.
;
; USAGE:
;
;       XCALL GETFPN, SCREEN, FIELD'NUMBER, PERM'FIELD
;
; Where:
;       SCREEN          = ESP screen to access.
;       FIELD'NUM       = Current Field number to access.
;       PERM'FIELD      = Contains the current field's PERMANENT ID NUMBER.
;
;
; Notes:
;    This subroutine is a completment to GETFID.SBR.
;    The purpose of this routine is to return to the user an ESP screen
;    field's PERMANENT ID FIELD NUMBER of the requested ESP screen's
;    FIELD NUMBER.  This is so that proper values can be set or get even
;    if a user changes the FIELD NUMBER Sequence for whatever reaseon.
;    SEE GETFPN.BAS for specific examples.
;
; Edit History:
;
;[100] 13-Dec-92 Created by James A. Jarboe IV.
;                GETFID needed a complement.
;

       PAGE
;***************************************************************************
;                                                                          *
;                            S Y M B O L I C S                             *
;                                                                          *
;***************************************************************************
;

       SEARCH  SYS                     ; Std AM defs, etc.
       SEARCH  SYSSYM                  ; More Am defs, etc.
       SEARCH  TOOLBX                  ; Tool Box interface defs, etc.


;***************************************************************************
;                                                                          *
;                              V E R S I O N                               *
;                                                                          *
;***************************************************************************
;
       VMAJOR  =       1               ; Major versoin number.
       VMINOR  =       0               ; Minor version number.
       VEDIT   =       100.            ; Edit level number.

       OBJNAM  0, 0, [SBR]             ; Becomes xxxxxx.SBR

       S..ARG  =       3.              ; Minimum argument count.

IF NDF, FL.FID, FL.FID  =       30.     ; Permanent Field ID offset.

;***********
;  GETFPN  *
;***********
; Returns a field's PERMANENT ID NUMBER using the field's current FIELD NUMBER..
;
; Incoming:
;               A3 -> Indexes Xcall variable address.
; Outgoing:
;               A3 -> Indexes Xcall variable address.
;               Z = Set if field's Permanent ID is found.
;                   Cleared if not found.
;
GETFPN: PHDR    -1, 0, PH$REE!PH$REU    ; SBR is reentrant & reusable.

; Check number of arguments.
;
       MOVW    ARGCNT(A3), D7          ; Get argument count.
       CMPW    D7, #S..ARG             ; Right number of arguments.
       BNE     99$                     ; No..so quit.

; Index screen and test for reasonably sized variable.
;
       MOV     A1.ADR(A3), A1          ; Index the screen buffer.
       CMP     A1.LEN(A3), #40.        ; Test for reasonable screen size.
       BLO     99$                     ;  Unreasonably small, forget it.

; Get the field number user wants us to get the Permanent ID number of.
;
       MOV     #A2.TYP, D1             ; Indicate the FIELD argument.
       TOOLBX  TBX$GTARG               ; Get the field number.
       BNE     99$                     ; Opps..field not there..quit.

; Get the field's Permanent Field number using current field number.
; Use undocumented FLDIDX Toolbox call to index the requested field.
;
       MOV     D1, D6                  ; Set field to find perm id.
       CLR     D1                      ; Preset 0 field number.
       PUSH    A3                      ; Save XCALL address.
       TOOLBX  TBX$FLDIDX,SJT,A6       ; Get index to requested field.
       MOV     A3, A6                  ; Save field address.
       POP     A3                      ; Restore XCALL address.
       BNE     80$                     ; Opps..field not found.

; Get Permanent field number from offset of current field.
;
       MOVW    FL.FID(A6), D6          ; Get field's perm id number.
       MOV     D6, D1                  ; Set field's Permanent ID number.

; Return permanent field number. If there was an error, field 0 is returned.
; Otherwise the current requested field's PERMANENT ID NUMBER is returned.
;
80$:    MOV     #A3.TYP, D6             ; Get return argument type.
       TOOLBX  TBX$RTARG, SJT          ; Return value to variable.
99$:    RTN                             ; All done.return to basic.

       END