/******************************************************************************
** Reasm.c
*******************************************************************************
**
** description:
**
** This file contains some subroutines for GALer's reassembler.
**
******************************************************************************/

 




/********************************* includes **********************************/

#include <libraries/mui.h>

#include <exec/memory.h>
#include <libraries/dos.h>
#include <intuition/intuition.h>
#include <intuition/gadgetclass.h>
#include <libraries/gadtools.h>
#include <libraries/locale.h>
#include <ctype.h>
#include <string.h>

#include <proto/locale.h>
#include <proto/intuition.h>
#include <proto/gadtools.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/muimaster.h>

#include "GALer.h"
#include "Localize.h"






/********************************** defines **********************************/

#define RASM_ID01            1       /* gadget IDs and the pin numbers */
#define RASM_ID02            2       /* must be the same               */
#define RASM_ID03            3
#define RASM_ID04            4
#define RASM_ID05            5
#define RASM_ID06            6
#define RASM_ID07            7
#define RASM_ID08            8
#define RASM_ID09            9
#define RASM_ID10            10
#define RASM_ID11            11
#define RASM_ID12            12
#define RASM_ID13            13
#define RASM_ID14            14
#define RASM_ID15            15
#define RASM_ID16            16
#define RASM_ID17            17
#define RASM_ID18            18
#define RASM_ID19            19
#define RASM_ID20            20
#define RASM_ID21            21
#define RASM_ID22            22
#define RASM_ID23            23
#define RASM_ID24            24

#define RASM_OK_ID           30
#define RASM_CANCEL_ID       31
#define RASM_SET_ID          32
#define RASM_CLEAR_ID        33






/******************************** functions **********************************/

static void   SetPinNames(int galtype);

static int    CheckPinNames(int galtype);

static int    PinNameRequester(int galtype);

static int    RowActive(int row, int galtype);

static int    OLMCOutput(int olmc, int mode);

static int    MakeEquation(struct ActBuffer *buff, int olmc, int colsize,
                           int mode, int rowoffset, int numofrows);

static int    Reasm(struct ActBuffer buff);

static void   ReasmError(int errornum, int pinnum);

static char  *PinNamePtr(int pinnum);
 





/******************************** variables **********************************/

extern  struct  AppString { LONG   as_ID;
                            STRPTR as_Str;
                          };

extern  struct  AppString AppStrings[];

extern  int OLMCSize22V10[];

extern  int ToOLMC20RA10[];


extern  char    path[];
extern  int     JedecGALType;
extern  char    filename[];                     /*Puffer für Filenamen*/
extern  struct  JedecStruct     Jedec;
extern  struct  Catalog         *catalog;

extern  APTR    app;




                                        /* this vectors show which column of */
                                        /* the logic array is connected to   */
                                        /* which pin                         */
int FuseToPin16Mode1[] = { 2,1,3,19,4,18,5,17,6,14,7,13,8,12,9,11 };
int FuseToPin16Mode2[] = { 2,1,3,18,4,17,5,16,6,15,7,14,8,13,9,11 };
int FuseToPin16Mode3[] = { 2,19,3,18,4,17,5,16,6,15,7,14,8,13,9,12 };

int FuseToPin20Mode1[] = { 2,1,3,23,4,22,5,21,6,20,7,17,8,16,9,15,10,14,11,13 };
int FuseToPin20Mode2[] = { 2,1,3,23,4,21,5,20,6,19,7,18,8,17,9,16,10,14,11,13 };
int FuseToPin20Mode3[] = { 2,23,3,22,4,21,5,20,6,19,7,18,8,17,9,16,10,15,11,14 };

int FuseToPin22V10[]   = { 1,23,2,22,3,21,4,20,5,19,6,18,7,17,8,16,9,15,10,14,11,13 };

int FuseToPin20RA10[]  = { 2,23,3,22,4,21,5,20,6,19,7,18,8,17,9,16,10,15,11,14 };


                                        /* this vector shows which OLMC is */
                                        /* connected to which row          */

int OLMCToRow22V10[]   = { 1, 10, 21, 34, 49, 66, 83, 98, 111, 122 };


                                        /* pin names for 20 pins package */

char  ReAsmPinNames20[20][10] = { "P1",  "P2",  "P3",  "P4",
                                  "P5",  "P6",  "P7",  "P8",
                                  "P9",  "GND", "P11", "P12",
                                  "P13", "P14", "P15", "P16",
                                  "P17", "P18", "P19", "VCC"
                                };

                                        /* pin names for 24 pins package */

char  ReAsmPinNames24[24][10] = { "P1",  "P2",  "P3",  "P4",
                                  "P5",  "P6",  "P7",  "P8",
                                  "P9",  "P10", "P11", "GND",
                                  "P13", "P14", "P15", "P16",
                                  "P17", "P18", "P19", "P20",
                                  "P21", "P22", "P23", "VCC",
                                };
 
APTR    strng_gad[24];








/******************************************************************************
** SetPinNames()
*******************************************************************************
** input:   galtype     type of GAL
**
** output:  none
**
** remarks: This function does initialize the strings of the string gadgets
**          of the reassembler requester.
******************************************************************************/
 
static void SetPinNames(int galtype)
{
    int     n, num_of_pins;

    char    name[4], numstrng[3];



    if (galtype == GAL16V8)                     /* get number of pins */
        num_of_pins = 20;
    else
        num_of_pins = 24;


    for (n = 1; n <= num_of_pins; n++)          /* set the pin names to */
    {                                           /* there defaults       */
        if (n == num_of_pins/2)
        {
            set(strng_gad[n-1], MUIA_String_Contents, "GND");
        }
        else
        {
            if (n == num_of_pins)
            {
                set(strng_gad[n-1], MUIA_String_Contents, "VCC");
            }
            else
            {
                name[0] = 'P';
                name[1] = (char)0;

                sprintf(numstrng, "%d", n);         /* make the pin number  */

                strcat(name, numstrng);             /* add it to the string */

                set(strng_gad[n-1], MUIA_String_Contents, name);
            }
        }
    }

}





/******************************************************************************
** PinNamePtr()
*******************************************************************************
** input:   pinnum      pin number
**                      whether it is a valid number or not will NOT be
**                      checked!
**
** output:  none
**
** remarks: This function returns a pointer to the pin name of the pin
**          with the pin number "pinnum". The returned string must not be
**          changed!
******************************************************************************/
 
static char *PinNamePtr(int pinnum)
{
    char  *name;


    if (JedecGALType == GAL16V8)
        name = &ReAsmPinNames20[pinnum - 1][0];     /* 20 pins package */
    else
        name = &ReAsmPinNames24[pinnum - 1][0];     /* 24 pins package */
 

    return name;
}
 
 



/******************************************************************************
** CheckPinNames()
*******************************************************************************
** input:   galtype     type of GAL
**
** output:    0: o.k.
**          <>0: error occured
**
** remarks: checks syntax of the pinnames
******************************************************************************/

static int CheckPinNames(int galtype)
{
    char    *name;
    int     numofpins, i, j, l, n;



    if (JedecGALType == GAL16V8)
        numofpins = 20;
    else
        numofpins = 24;


                                        /*** check the pin names ***/
    for (n = 0; n < numofpins; n++)
    {

                                    /* get a pointer to the */
        name = PinNamePtr(n + 1);   /* pin name             */
 

                                            /* are all characters of the */
                                            /* pin name allowed?         */
        if (*name == '/')
            name++;

        if (!*name)
        {                                   /* no characters? => error */
            ReasmError(4, n+1);
            return(4);
        }

                                                 /* set pointer to next    */
        while (isalpha(*name) || isdigit(*name)) /* character which is not */
            name++;                              /* a digit or a letter    */


        if (*name == '/')                   /* negation within the string? */
        {                                   /* this is illegal!            */
            ReasmError(6, n+1);
            return(6);
        }

        if (*name)                          /* any illegal character */
        {
            ReasmError(3, n+1);
            return(3);
        }

                                            /* check whether some pin names */
        for (l = 0; l < n; l++)             /* are defined twice or not     */
        {

            if (strcmp(PinNamePtr(l + 1), "NC")) /* NC is allowed to occure */
            {                                    /* several times           */
                i = j = 0;

                if (*(PinNamePtr(l + 1)) == '/')      /* skip the negations */
                    i = 1;

                if (*(PinNamePtr(n + 1)) == '/')
                    j = 1;

                if (!strcmp(PinNamePtr(l + 1) + i, PinNamePtr(n + 1) + j))
                {
                    ReasmError(2, n + 1);      /* pin name is defined twice */
                    return(2);
                }
            }
        }

                                          /*GND as pin name at GAL's GND pin?*/

        if (!strcmp(PinNamePtr(n+1), "GND"))
        {
            if (n + 1 != numofpins/2)
            {
                ReasmError(5, n + 1);
                return(5);
            }
        }

        if (n + 1 == numofpins/2)
        {
            if (strcmp(PinNamePtr(n + 1), "GND"))
            {
                ReasmError(7, n + 1);
                return(7);
            }
        }
                                          /*VCC as pin name at GAL's VCC pin?*/

        if (!strcmp(PinNamePtr(n + 1), "VCC"))
        {
            if (n + 1 != numofpins)
            {
                ReasmError(5, n+1);
                return(5);
            }
        }

        if (n + 1 == numofpins)
        {
            if (strcmp(PinNamePtr(n + 1), "VCC"))
            {
                ReasmError(8, n+1);
                return(8);
            }
        }
                                          /* AR and SP are key words for 22V10 */
                                          /* they are not allowed in the pin   */
                                          /* declaration                       */
        if (JedecGALType == GAL22V10)
        {
            if (!strcmp(PinNamePtr(n + 1), "AR"))
            {
                ReasmError(9, n + 1);
                return(9);
            }

            if (!strcmp(PinNamePtr(n + 1), "SP"))
            {
                ReasmError(10, n+1);
                return(10);
            }
        }
    }


    return(0);
}





/******************************************************************************
** PinNameRequester()
*******************************************************************************
** input:   galtype     type of GAL
**
** output:  TRUE:  continue selected
**          FALSE: cancel selected or error
**
** remarks: brings up a requester in which the names of the pins can be edited
******************************************************************************/

static int PinNameRequester(int galtype)
{
    int     n, open, done, result, num_of_pins;

    ULONG   id, signals;

    APTR    win;
    APTR    ok_gad, cancel_gad, set_gad, clear_gad;

    STRPTR  *str;




    set(app, MUIA_Application_Sleep, TRUE);     /* deactivate application */

                                                /* make window object */

    if (galtype == GAL16V8)                     /* 20 pin package */
    {

        num_of_pins = 20;
 
        win = WindowObject,
            MUIA_Window_Title, "Reassembler",
            MUIA_Window_CloseGadget, FALSE,
            MUIA_Window_NoMenus, TRUE,
            MUIA_HelpNode, "MenReAsm",

            WindowContents, GroupObject,

                Child, ColGroup(4), GroupFrameT("GAL"),
                    MUIA_Group_VertSpacing, 0,

                                                /* pins 1 and 20 */
                    Child, strng_gad[0] = StringObject, StringFrame,
                             MUIA_String_MaxLen, 10,
                             MUIA_String_Contents, &ReAsmPinNames20[0][0],
                             MUIA_String_Format, MUIV_String_Format_Right,
                             End,
                    Child, Label2("1"),

                    Child, Label2("20"),
                    Child, strng_gad[19] = String(&ReAsmPinNames20[19][0], 10),

                                                /* pins 2 and 19 */
                    Child, strng_gad[1] = StringObject, StringFrame,
                             MUIA_String_MaxLen, 10,
                             MUIA_String_Contents, &ReAsmPinNames20[1][0],
                             MUIA_String_Format, MUIV_String_Format_Right,
                             End,
                    Child, Label2("2"),

                    Child, Label2("19"),
                    Child, strng_gad[18] = String(&ReAsmPinNames20[18][0], 10),
 
                                                /* pins 3 and 18 */
                    Child, strng_gad[2] = StringObject, StringFrame,
                             MUIA_String_MaxLen, 10,
                             MUIA_String_Contents, &ReAsmPinNames20[2][0],
                             MUIA_String_Format, MUIV_String_Format_Right,
                             End, 
                    Child, Label2("3"),

                    Child, Label2("18"),
                    Child, strng_gad[17] = String(&ReAsmPinNames20[17][0], 10),

                                                /* pins 4 and 17 */
                    Child, strng_gad[3] = StringObject, StringFrame,
                             MUIA_String_MaxLen, 10,
                             MUIA_String_Contents, &ReAsmPinNames20[3][0],
                             MUIA_String_Format, MUIV_String_Format_Right,
                             End, 
                    Child, Label2("4"),

                    Child, Label2("17"),
                    Child, strng_gad[16] = String(&ReAsmPinNames20[16][0], 10),

                                                /* pins 5 and 16 */
                    Child, strng_gad[4] = StringObject, StringFrame,
                             MUIA_String_MaxLen, 10,
                             MUIA_String_Contents, &ReAsmPinNames20[4][0],
                             MUIA_String_Format, MUIV_String_Format_Right,
                             End, 
                    Child, Label2("5"),

                    Child, Label2("16"),
                    Child, strng_gad[15] = String(&ReAsmPinNames20[15][0], 10),

                                                /* pins 6 and 15 */
                    Child, strng_gad[5] = StringObject, StringFrame,
                             MUIA_String_MaxLen, 10,
                             MUIA_String_Contents, &ReAsmPinNames20[5][0],
                             MUIA_String_Format, MUIV_String_Format_Right,
                             End, 
                    Child, Label2("6"),

                    Child, Label2("15"),
                    Child, strng_gad[14] = String(&ReAsmPinNames20[14][0], 10),

                                                /* pins 7 and 14 */
                    Child, strng_gad[6] = StringObject, StringFrame,
                             MUIA_String_MaxLen, 10,
                             MUIA_String_Contents, &ReAsmPinNames20[6][0],
                             MUIA_String_Format, MUIV_String_Format_Right,
                             End, 
                    Child, Label2("7"),

                    Child, Label2("14"),
                    Child, strng_gad[13] = String(&ReAsmPinNames20[13][0], 10),

                                                /* pins 8 and 13 */
                    Child, strng_gad[7] = StringObject, StringFrame,
                             MUIA_String_MaxLen, 10,
                             MUIA_String_Contents, &ReAsmPinNames20[7][0],
                             MUIA_String_Format, MUIV_String_Format_Right,
                             End, 
                    Child, Label2("8"),

                    Child, Label2("13"),
                    Child, strng_gad[12] = String(&ReAsmPinNames20[12][0], 10),

                                                /* pins 9 and 12 */
                    Child, strng_gad[8] = StringObject, StringFrame,
                             MUIA_String_MaxLen, 10,
                             MUIA_String_Contents, &ReAsmPinNames20[8][0],
                             MUIA_String_Format, MUIV_String_Format_Right,
                             End, 
                    Child, Label2("9"),

                    Child, Label2("12"),
                    Child, strng_gad[11] = String(&ReAsmPinNames20[11][0], 10),

                                                /* pins 10 and 11 */
                    Child, strng_gad[9] = StringObject, StringFrame,
                             MUIA_String_MaxLen, 10,
                             MUIA_String_Contents, &ReAsmPinNames20[9][0],
                             MUIA_String_Format, MUIV_String_Format_Right,
                             End, 
                    Child, Label2("10"),

                    Child, Label2("11"),
                    Child, strng_gad[10] = String(&ReAsmPinNames20[10][0], 10),
 
                    End,
     
                Child, HGroup,
                    Child, ok_gad = SimpleButton(AppStrings[MSG_OK_GAD].as_Str),

                    Child, set_gad = SimpleButton(AppStrings[MSG_SET_GAD].as_Str),

                    Child, clear_gad = SimpleButton(AppStrings[MSG_CLEAR_GAD].as_Str),

                    Child, cancel_gad = SimpleButton(AppStrings[MSG_CANCEL_GAD].as_Str),
 
                    End,
                End,
            End;
    }
    else
    {
        num_of_pins = 24;

        win = WindowObject,
            MUIA_Window_Title, "Reassembler",
            MUIA_Window_CloseGadget, FALSE,
            MUIA_Window_NoMenus, TRUE,

            WindowContents, GroupObject,

                Child, ColGroup(4), GroupFrameT("GAL"),
                    MUIA_Group_VertSpacing, 0,
     
                                                /* pins 1 and 24 */
                    Child, strng_gad[0] = StringObject, StringFrame,
                             MUIA_String_MaxLen, 10,
                             MUIA_String_Contents, &ReAsmPinNames24[0][0],
                             MUIA_String_Format, MUIV_String_Format_Right,
                             End, 
                    Child, Label2("1"),

                    Child, Label2("24"),
                    Child, strng_gad[23] = String(&ReAsmPinNames24[23][0], 10),

                                                /* pins 2 and 23 */
                    Child, strng_gad[1] = StringObject, StringFrame,
                             MUIA_String_MaxLen, 10,
                             MUIA_String_Contents, &ReAsmPinNames24[1][0],
                             MUIA_String_Format, MUIV_String_Format_Right,
                             End, 
                    Child, Label2("2"),

                    Child, Label2("23"),
                    Child, strng_gad[22] = String(&ReAsmPinNames24[22][0], 10),
 
                                                /* pins 3 and 22 */
                    Child, strng_gad[2] = StringObject, StringFrame,
                             MUIA_String_MaxLen, 10,
                             MUIA_String_Contents, &ReAsmPinNames24[2][0],
                             MUIA_String_Format, MUIV_String_Format_Right,
                             End, 
                    Child, Label2("3"),

                    Child, Label2("22"),
                    Child, strng_gad[21] = String(&ReAsmPinNames24[21][0], 10),

                                                /* pins 4 and 21 */
                    Child, strng_gad[3] = StringObject, StringFrame,
                             MUIA_String_MaxLen, 10,
                             MUIA_String_Contents, &ReAsmPinNames24[3][0],
                             MUIA_String_Format, MUIV_String_Format_Right,
                             End, 
                    Child, Label2("4"),

                    Child, Label2("21"),
                    Child, strng_gad[20] = String(&ReAsmPinNames24[20][0], 10),

                                                /* pins 5 and 20 */
                    Child, strng_gad[4] = StringObject, StringFrame,
                             MUIA_String_MaxLen, 10,
                             MUIA_String_Contents, &ReAsmPinNames24[4][0],
                             MUIA_String_Format, MUIV_String_Format_Right,
                             End, 
                    Child, Label2("5"),

                    Child, Label2("20"),
                    Child, strng_gad[19] = String(&ReAsmPinNames24[19][0], 10),

                                                /* pins 6 and 19 */
                    Child, strng_gad[5] = StringObject, StringFrame,
                             MUIA_String_MaxLen, 10,
                             MUIA_String_Contents, &ReAsmPinNames24[5][0],
                             MUIA_String_Format, MUIV_String_Format_Right,
                             End, 
                    Child, Label2("6"),

                    Child, Label2("19"),
                    Child, strng_gad[18] = String(&ReAsmPinNames24[18][0], 10),

                                                /* pins 7 and 18 */
                    Child, strng_gad[6] = StringObject, StringFrame,
                             MUIA_String_MaxLen, 10,
                             MUIA_String_Contents, &ReAsmPinNames24[6][0],
                             MUIA_String_Format, MUIV_String_Format_Right,
                             End, 
                    Child, Label2("7"),

                    Child, Label2("18"),
                    Child, strng_gad[17] = String(&ReAsmPinNames24[17][0], 10),

                                                /* pins 8 and 17 */
                    Child, strng_gad[7] = StringObject, StringFrame,
                             MUIA_String_MaxLen, 10,
                             MUIA_String_Contents, &ReAsmPinNames24[7][0],
                             MUIA_String_Format, MUIV_String_Format_Right,
                             End, 
                    Child, Label2("8"),

                    Child, Label2("17"),
                    Child, strng_gad[16] = String(&ReAsmPinNames24[16][0], 10),

                                                /* pins 9 and 16 */
                    Child, strng_gad[8] = StringObject, StringFrame,
                             MUIA_String_MaxLen, 10,
                             MUIA_String_Contents, &ReAsmPinNames24[8][0],
                             MUIA_String_Format, MUIV_String_Format_Right,
                             End, 
                    Child, Label2("9"),

                    Child, Label2("16"),
                    Child, strng_gad[15] = String(&ReAsmPinNames24[15][0], 10),

                                                /* pins 10 and 15 */
                    Child, strng_gad[9] = StringObject, StringFrame,
                             MUIA_String_MaxLen, 10,
                             MUIA_String_Contents, &ReAsmPinNames24[9][0],
                             MUIA_String_Format, MUIV_String_Format_Right,
                             End, 
                    Child, Label2("10"),

                    Child, Label2("15"),
                    Child, strng_gad[14] = String(&ReAsmPinNames24[14][0], 10),

                                                /* pins 11 and 14 */
                    Child, strng_gad[10] = StringObject, StringFrame,
                             MUIA_String_MaxLen, 10,
                             MUIA_String_Contents, &ReAsmPinNames24[10][0],
                             MUIA_String_Format, MUIV_String_Format_Right,
                             End, 
                    Child, Label2("11"),

                    Child, Label2("14"),
                    Child, strng_gad[13] = String(&ReAsmPinNames24[13][0], 10),

                                                /* pins 12 and 13 */
                    Child, strng_gad[11] = StringObject, StringFrame,
                             MUIA_String_MaxLen, 10,
                             MUIA_String_Contents, &ReAsmPinNames24[11][0],
                             MUIA_String_Format, MUIV_String_Format_Right,
                             End, 
                    Child, Label2("12"),

                    Child, Label2("13"),
                    Child, strng_gad[12] = String(&ReAsmPinNames24[12][0], 10),
 
                    End,
     
                Child, HGroup,
                    Child, ok_gad = SimpleButton(AppStrings[MSG_OK_GAD].as_Str),

                    Child, set_gad = SimpleButton(AppStrings[MSG_SET_GAD].as_Str),

                    Child, clear_gad = SimpleButton(AppStrings[MSG_CLEAR_GAD].as_Str),

                    Child, cancel_gad = SimpleButton(AppStrings[MSG_CANCEL_GAD].as_Str),
 
                    End,
                End,
            End;
    }


                                        /* set gadget IDs */

    DoMethod(ok_gad, MUIM_Notify, MUIA_Pressed, FALSE,
             app, 2, MUIM_Application_ReturnID, RASM_OK_ID);

    DoMethod(set_gad, MUIM_Notify, MUIA_Pressed, FALSE,
             app, 2, MUIM_Application_ReturnID, RASM_SET_ID);

    DoMethod(clear_gad, MUIM_Notify, MUIA_Pressed, FALSE,
             app, 2, MUIM_Application_ReturnID, RASM_CLEAR_ID);
 
    DoMethod(cancel_gad, MUIM_Notify, MUIA_Pressed, FALSE,
             app, 2, MUIM_Application_ReturnID, RASM_CANCEL_ID);


    for (n = 0; n < num_of_pins; n++)
        DoMethod(strng_gad[n], MUIM_Notify, MUIA_Pressed, FALSE,
                 app, 2, MUIM_Application_ReturnID, RASM_ID01 + n);
 


                                        /* init cycle chain */

    if (num_of_pins == 20)
        DoMethod(win, MUIM_Window_SetCycleChain,
                 strng_gad[ 0], strng_gad[ 1], strng_gad[ 2], strng_gad[ 3],
                 strng_gad[ 4], strng_gad[ 5], strng_gad[ 6], strng_gad[ 7],
                 strng_gad[ 8], strng_gad[ 9], strng_gad[10], strng_gad[11],
                 strng_gad[12], strng_gad[13], strng_gad[14], strng_gad[15],
                 strng_gad[16], strng_gad[17], strng_gad[18], strng_gad[19],
                 ok_gad, set_gad, clear_gad, cancel_gad, NULL);
    else
        DoMethod(win, MUIM_Window_SetCycleChain,
                 strng_gad[ 0], strng_gad[ 1], strng_gad[ 2], strng_gad[ 3],
                 strng_gad[ 4], strng_gad[ 5], strng_gad[ 6], strng_gad[ 7],
                 strng_gad[ 8], strng_gad[ 9], strng_gad[10], strng_gad[11],
                 strng_gad[12], strng_gad[13], strng_gad[14], strng_gad[15],
                 strng_gad[16], strng_gad[17], strng_gad[18], strng_gad[19],
                 strng_gad[20], strng_gad[21], strng_gad[22], strng_gad[23],
                 ok_gad, set_gad, clear_gad, cancel_gad, NULL);
 
 
 

    if (win)                    /* window object created? */
    {
        DoMethod(app, OM_ADDMEMBER, win);       /* add win to application */

        set(win, MUIA_Window_Open, TRUE);       /* open window */
        get(win, MUIA_Window_Open, &open);

        if (open)                               /* is window opened? */
        {


            done = FALSE;

            while (!done)
            {
                id = DoMethod(app, MUIM_Application_Input, &signals);


                switch (id)
                {
                    case RASM_OK_ID:            /* OK selected */

                                            /* copy names into buffers */

                        for (n = 0; n < num_of_pins; n++)
                        {
                            get(strng_gad[n], MUIA_String_Contents, &str);

                            if (num_of_pins == 20)  /* 20 pins package? */
                                strcpy(ReAsmPinNames20[n], (const char *)str);
                            else
                                strcpy(ReAsmPinNames24[n], (const char *)str);
                        }

                                       /* check the syntax of the pin names */

                        if (!CheckPinNames(galtype))
                        {
                            result = TRUE;
                            done   = TRUE;      /* that's it  */
                        }

                        break;


                    case RASM_CANCEL_ID:

                        result = FALSE;         /* Cancel selected */
                        done   = TRUE;          /* that's it */

                        break;


                    case RASM_CLEAR_ID:         /* clear pin names */

                        for (n = 0; n < num_of_pins; n++)
                            set(strng_gad[n], MUIA_String_Contents, "");

                        break;

                    case RASM_SET_ID:           /* set pin names */

                        SetPinNames(galtype);
                        break;

                }


                if (!done && signals)
                    Wait(signals);              /* wait for the next event */
            }
 

           set(win, MUIA_Window_Open, FALSE);   /* close window */
  
        }

        DoMethod(app, OM_REMMEMBER, win);       /* remove win from app. */

        MUI_DisposeObject(win);                 /* delete window object */
    }



    set(app, MUIA_Application_Sleep, FALSE);    /* reactivate application */
 

    return result;

}





/******************************************************************************
** RowActive()
*******************************************************************************
** input:   row         row which should be tested
**          galtype     type of GAL
**
** ouput:   0:          row is not active
**          1:          row is active
**          2:          row is active but includes only "1" (means VCC)
**
** remarks: This function tests whether or not a row of the logic array is
**          active (checks PT bits of the GAL16V8 and GAL20V8 and searchs
**          for the expression A * /A).
******************************************************************************/

static int RowActive(int row, int galtype)
{
    int n, colsize, flag;


    switch (galtype)
    {                                       /* get number of columns */
        case GAL16V8:
            colsize = MAX_FUSE_ADR16 + 1;
            break;

        case GAL20V8:
            colsize = MAX_FUSE_ADR20 + 1;
            break;

        case GAL22V10:
            colsize = MAX_FUSE_ADR22V10 + 1;
            break;

        case GAL20RA10:
            colsize = MAX_FUSE_ADR20RA10 + 1;
            break;
    }


    if (galtype == GAL16V8 || galtype == GAL20V8)
        if (!Jedec.GALPT[row])              /* check PT-bit which     */
            return(0);                      /* enables/disables a row */


    flag = 0;

    for (n = 0; n < colsize; n++)
    {                                       /* search for "A * /A" */
        if (!Jedec.GALLogic[row*colsize + n])
        {
            flag = 1;

            if (!(n % 2))
                if (!Jedec.GALLogic[row*colsize + n + 1])
                    return(0);
        }
    }

    if (flag)
        return(1);
    else
        return(2);
}





/******************************************************************************
** OLMCOutput()
*******************************************************************************
** input:   olmc    OLMC which should be tested
**          mode    mode of the GAL (only when 16V8/20V8)
**
** output:      0: no output
**              1: output (there is an equation which describes this
**                 output pin)
**
** remarks: checks whether or not an OLMC pin is programmed as an output
******************************************************************************/

static int OLMCOutput(int olmc, int mode)
{
    int n, flag;


    flag = 0;

    if (JedecGALType == GAL16V8 || JedecGALType == GAL20V8)
    {
        if (mode == 1 && Jedec.GALAC1[olmc])
            return(0);

        for (n = 0; n < 8; n++)
        {
            if (!n && ((mode == 2) || ((mode == 3) && Jedec.GALAC1[olmc])))
            {
                if (!RowActive(olmc*8, JedecGALType)) /*tristate enable = GND?*/
                    return(0);                        /*yes, then input pin   */
            }
            else
            {
                if (RowActive(olmc*8 + n, JedecGALType))
                    flag = 1;
            }
        }
    }


    if (JedecGALType == GAL22V10)           /* pin is an output when tristate */
        if (RowActive(OLMCToRow22V10[olmc], JedecGALType)) /* can be HIGH/LOW */
            return(1);

    if (JedecGALType == GAL20RA10)          /* pin is an output when tristate */
        if (RowActive(olmc*8, JedecGALType))               /* can be HIGH/LOW */
            return(1);


    return(flag);
}





/******************************************************************************
** MakeEquation()
*******************************************************************************
** input:   buff      pointer to the ActBuffer structure
**          olmc      number of the OLMC
**          colsize   number of columns
**          mode      mode of GAL
**                      0: no mode used
**                      1: combinational (only for GAL16V8/GAL20V8)
**                      2: tristate      (only for GAL16V8/GAL20V8)
**                      3: register      (only for GAL16V8/GAL20V8)
**                      4: asynchronous reset   (only for GAL22V10)
**                      5: snychronous  preset  (only for GAL22V10
**          rowoffset where to start to build the equation
**          numofrows number of rows from which the equation should be build
**
** output:      0:    no errors
**             -1:    error occured (out of memory)
**
** remarks: This function examines the rows of an OLMC and generates the
**          equation.
******************************************************************************/
 
static int MakeEquation(struct ActBuffer *buff, int olmc, int colsize, int mode,
                        int rowoffset, int numofrows)
{

    int     ORflag, ANDflag, pin, m, n, result, numofchar;
    int     offset, row;

    struct  ActBuffer  startbuff;




    startbuff = *buff;                            /* save pointer*/

    numofchar = 8;
    ORflag    = 0;

    n = rowoffset;

    while (n < rowoffset + numofrows)
    {

        if (JedecGALType == GAL22V10)
        {                                       /* 22V10 => different sizes */
                                                /* of OLMCs and additional  */
            row = OLMCToRow22V10[olmc];         /* AS and RS rows           */

            if (mode == 4)
                row = 0;                        /* asynch. reset */
            else
                if (mode == 5)
                    row = 131;                  /* synch. preset */
        }
        else
            row = olmc*8;                   /* 16V8,20V8,20RA10: OLMC size */
                                            /* is constant (=8)            */

        result = RowActive(row + n, JedecGALType);


        if (result == 1)
        {                                   /* is row active? */

            if (ORflag)
            {                               /* yes, then OR */
                if (AddString(buff, (UBYTE *)" + "))
                    return(-1);

                numofchar += 3;             /* count characters */
            }


            ORflag  = 1;
            ANDflag = 0;

            for (m = 0; m < colsize; m++)
            {

                if (JedecGALType == GAL22V10)
                {                               /* 22V10 => different sizes */
                                                /* of OLMCs and additional  */
                                                /* AS and RS rows           */

                    offset = (OLMCToRow22V10[olmc] + n)*colsize;

                    if (mode == 4)
                        offset = 0;                     /* asynch. reset */
                    else
                        if (mode == 5)
                            offset = 5764;              /* synch. preset */
                }
                else
                    offset = (olmc*8 + n)*colsize;  /* 16V8,20V8,20RA10: OLMC */
                                                    /* size is constant (=8)  */

                if (!Jedec.GALLogic[offset + m])
                {                                   /* fuse = 0? */

                    if (ANDflag)
                    {
                        if (AddByte(buff, (UBYTE)'*')) /* evaluate prod. term */
                            return(-1);

                        numofchar++;
                    }

                    ANDflag = 1;
                                            /*** GAL16V8 ***/

                    if (JedecGALType == GAL16V8)
                    {
                        if (mode == 1)                      /* get pin number */
                            pin = FuseToPin16Mode1[m/2];

                        if (mode == 2)
                            pin = FuseToPin16Mode2[m/2];

                        if (mode == 3)
                            pin = FuseToPin16Mode3[m/2];
                                                    /* was there a negation in */
                                                    /* in the declaration?     */
                        if (((*PinNamePtr(pin) == '/') && !(m % 2)) ||
                            ((*PinNamePtr(pin) != '/') &&  (m % 2)))
                        {
                            if (AddByte(buff, (UBYTE)'/'))
                                return(-1);

                            numofchar++;
                        }
                                           /* write pin name without '/' */
                        if (*PinNamePtr(pin) == '/')
                        {
                            if (AddString(buff, (PinNamePtr(pin) + 1L)))
                                return(-1);
                        }
                        else
                        {
                            if (AddString(buff, PinNamePtr(pin)))
                                return(-1);
                        }

                        numofchar += (int)strlen(PinNamePtr(pin));
                    }
                    else
                    {                        /*** GAL20V8, 22V10, 20RA10 ***/

                        if (JedecGALType == GAL20V8)
                        {
                            if (mode == 1)               /* get pin number */
                                pin = FuseToPin20Mode1[m/2];

                            if (mode == 2)
                                pin = FuseToPin20Mode2[m/2];

                            if (mode == 3)
                                pin = FuseToPin20Mode3[m/2];
                        }

                        if (JedecGALType == GAL22V10)
                            pin = FuseToPin22V10[m/2];

                        if (JedecGALType == GAL20RA10)
                            pin = FuseToPin20RA10[m/2];

                                          /* handle the negation sign */
                        if (JedecGALType == GAL22V10 &&
                            pin >= 14 && pin <= 23   &&
                            !Jedec.GALS1[23 - pin])
                        {          /* registered 22V10 OLMC:          */
                                   /* sign of feedback is contrary to */
                                   /* that of other GALs and/or modes */

                            if (((*PinNamePtr(pin) == '/') &&  (m % 2))  ||
                                ((*PinNamePtr(pin) != '/') && !(m % 2)))
                            {
                                if (AddByte(buff, (UBYTE)'/'))
                                    return(-1);

                                numofchar++;
                            }
                        }
                        else
                        {                      /* was there a negation in */
                                               /* the pin declaration?    */

                            if (((*PinNamePtr(pin) == '/') && !(m % 2))  ||
                                ((*PinNamePtr(pin) != '/') &&  (m % 2)))
                            {
                                if (AddByte(buff, (UBYTE)'/'))
                                    return(-1);

                                numofchar++;
                            }
                        }
                                               /* add pin name without */
                                               /* leading '/'          */
                        if (*PinNamePtr(pin) == '/')
                        {
                            if (AddString(buff, PinNamePtr(pin) + 1L))
                                return(-1);
                        }
                        else
                        {
                            if (AddString(buff, PinNamePtr(pin)))
                                return(-1);
                        }

                        numofchar += (int)strlen(PinNamePtr(pin));
                    }


                    if (numofchar > 60)
                    {                                         /* new line? */
                        if (AddString(buff, (UBYTE *)"\n        "))
                            return(-1);

                        numofchar = 8;
                    }
                }
            }
        }

        if (result == 2)
        {                                       /* only '1' in all rows? */
            *buff = startbuff;                  /* then VCC              */

            if (AddString(buff, (UBYTE *)"VCC"))
                return(-1);

            break;
        }

        n++;
    }

    if (AddString(buff, (UBYTE *)"\n\n"))         /* end of the equation */
        return(-1);

    return(0);
}





/******************************************************************************
** Reasm()
*******************************************************************************
** input:   buff    buffer in which the source file should be stored
**
** output:     0:   no errors
**           <>0:   error
**
** remarks: This function reassembles a JEDEC file and gernerates the
**          appropriate source file. The source file is stored in the buffer
**          described by "buff".
******************************************************************************/
 
static int Reasm(struct ActBuffer buff)
{
    int     mode, n, numofpins, byte, tricon;
    int     firstOLMC, olmc, colsize, numofOLMCs;
    UBYTE   *ptr;

                                        /*** write type of GAL ***/
    switch (JedecGALType)
    {
        case GAL16V8:
                if (AddString(&buff, (UBYTE *)"GAL16V8\n"))
                    return(-1);

                numofpins  = 20;
                numofOLMCs = 8;
                firstOLMC  = 19;
                colsize    = MAX_FUSE_ADR16 + 1;
                break;
               
        case GAL20V8:
                if (AddString(&buff, (UBYTE *)"GAL20V8\n"))
                    return(-1);

                numofpins  = 24;
                numofOLMCs = 8;
                firstOLMC  = 22;
                colsize    = MAX_FUSE_ADR20 + 1;
                break;

        case GAL22V10:
                if (AddString(&buff, (UBYTE *)"GAL22V10\n"))
                    return(-1);

                numofpins  = 24;
                numofOLMCs = 10;
                firstOLMC  = 23;
                colsize    = MAX_FUSE_ADR22V10 + 1;
                break;

        case GAL20RA10:
                if (AddString(&buff, (UBYTE *)"GAL20RA10\n"))
                    return(-1);

                numofpins  = 24;
                numofOLMCs = 10;
                firstOLMC  = 23;
                colsize    = MAX_FUSE_ADR20RA10 + 1;
                break;
    }



    byte = 0;                             /*** write signature ***/

    for (n = 0; n < SIG_SIZE; n++)
    {
        byte |= Jedec.GALSig[n];                /* put 8 bits to one byte */
                                                /* together               */
        if (!((n+1)%8))
        {
            if (!isprint(byte))
                byte = '.';

            if (AddByte(&buff, (UBYTE)byte))
                return(-1);

            byte = 0;
        }

        byte <<= 1;
    }

    if (AddString(&buff, (UBYTE *)"\n\n"))        /* new lines */
        return(-1);


                                        /*** write pin declaration ***/
    for (n = 1; n <= numofpins; n++)
    {
        if (JedecGALType == GAL16V8)
        {
            if (AddString(&buff, PinNamePtr(n)))
                return(-1);
        }
        else
            if (AddString(&buff, PinNamePtr(n)))
                return(-1);

        if (n == numofpins/2)
        {
            if (AddString(&buff, (UBYTE *)"\n"))
                return(-1);
        }
        else
        {
            if (AddString(&buff, (UBYTE *)" "))
                return(-1);
        }
    }

    if (AddString(&buff, (UBYTE *)"\n\n"))
        return(-1);


    mode = 0;

    if (JedecGALType == GAL16V8 || JedecGALType == GAL20V8)
    {

        if (!Jedec.GALAC0 && !Jedec.GALSYN)
        {                                   /* check mode of GAL  */
            ReasmError(1, 0);               /* error? then return */
            return(1);
        }
                                                /* get mode of GAL */
        if (!Jedec.GALSYN)
        {                        /* if SYN = 0 then mode 3 */
            mode = 3;            /* (register)             */
        }
        else
        {
            if (Jedec.GALSYN && Jedec.GALAC0)
                mode = 2;                           /* tristate mode */
            else
                mode = 1;                           /* combinational mode */
        }
    }

                                        /*** generate the equations ***/

    for (olmc = 0; olmc < numofOLMCs; olmc++)
    {                                               /* all OLMCs */

        tricon = 0;

        if (OLMCOutput(olmc, mode))             /* is OLMC an output? */
        {
                                                /* is there a negation in */
                                                /* the pin declaration    */

            if (((*PinNamePtr(firstOLMC - olmc) == '/') &&  Jedec.GALXOR[olmc]) ||
                ((*PinNamePtr(firstOLMC - olmc) != '/') && !Jedec.GALXOR[olmc]))
            {
                if (AddByte(&buff, (UBYTE)'/'))
                    return(-1);
            }
                                            /* write pin name without '/' */
            if (*PinNamePtr(firstOLMC - olmc) == '/')
            {
                if (AddString(&buff, ptr = PinNamePtr(firstOLMC - olmc) + 1L))
                    return(-1);
            }
            else
            {
                if (AddString(&buff, ptr = PinNamePtr(firstOLMC - olmc)))
                    return(-1);
            }

                                        /*** get type of output ***/

            if (JedecGALType == GAL16V8 || JedecGALType == GAL20V8)
            {

                if (mode == 2 || (mode == 3 && Jedec.GALAC1[olmc]))
                {
                    if (AddString(&buff, (UBYTE *)".T"))
                        return(-1);

                    tricon = 1;             /* there is a tristate output, */
                }                           /* so set tricon flag          */

                if (mode == 3 && !Jedec.GALAC1[olmc])
                    if (AddString(&buff, (UBYTE *)".R"))
                        return(-1);

                if (AddString(&buff, (UBYTE *)" = "))
                    return(-1);

                n = 0;                   /* if there is a tristate control */

                if (mode == 2 || (mode == 3 && Jedec.GALAC1[olmc]))
                    n++;                 /* skip first row of OLMC */

                if (MakeEquation(&buff, olmc, colsize, mode, n, 8 - n))
                    return(-1);

                                            /* write the equation      */
                if (tricon)                 /* of the tristate control */
                {
                                            /* write pin name with leading */
                                            /* '/' if there is one         */
                    if (AddString(&buff, PinNamePtr(firstOLMC - olmc)))
                        return(-1);

                    if (AddString(&buff, (UBYTE *)".E = ")) /*tristate enable*/
                        return(-1);
                                                            /* write equation*/
                    if (MakeEquation(&buff, olmc, colsize, mode, 0, 1))
                        return(-1);
                }

            }



            if (JedecGALType == GAL22V10)
            {

                if (Jedec.GALS1[olmc])
                {                                   /* get type of output */
                    if (AddString(&buff, (UBYTE *)".T = "))
                        return(-1);
                }
                else
                    if (AddString(&buff, (UBYTE *)".R = "))
                        return(-1);

                                                /* write output's equation */
                if (MakeEquation(&buff, olmc, colsize, 0, 1,
                                 OLMCSize22V10[olmc] - 1))
                    return(-1);
                                                /* write equation of */
                                                /* tristate control  */

                                        /* write pin name with leading */
                                        /* '/' if there is one         */
                if (AddString(&buff, PinNamePtr(firstOLMC - olmc)))
                    return(-1);

                if (AddString(&buff, (UBYTE *)".E = ")) /* tristate enable */
                    return(-1);

                                                /* write equation */

                if (MakeEquation(&buff, olmc, colsize, 0, 0, 1))
                    return(-1); 


            }



            if (JedecGALType == GAL20RA10)
            {
                                                /* write equation of output */
                if (RowActive(ToOLMC20RA10[9 - olmc] + 2, JedecGALType) == 2 &&
                    RowActive(ToOLMC20RA10[9 - olmc] + 3, JedecGALType) == 2)
                {
                    if (AddString(&buff, (UBYTE *)" = "))/* if ARST and APRST */
                        return(-1);                      /* = VCC, then       */
                }                                        /* tristate output   */
                else
                {
                    if (AddString(&buff, (UBYTE *)".R = "))
                        return(-1);
                }

                if (MakeEquation(&buff, olmc, colsize, 0, 4, 4))
                    return(-1);

                                        /* write pin name with leading */
                                        /* '/' if there is one         */
                if (AddString(&buff, PinNamePtr(firstOLMC - olmc)))
                    return(-1);

                if (AddString(&buff, (UBYTE *)".E = "))
                    return(-1);

                if (MakeEquation(&buff, olmc, colsize, 0, 0, 1))
                    return(-1);


                if (RowActive(olmc * 8 + 1, JedecGALType))
                {
                    if (AddString(&buff, ptr))      /* write equation of */
                        return(-1);                 /* Clock             */

                    if (AddString(&buff, (UBYTE *)".CLK = "))
                        return(-1);

                    if (MakeEquation(&buff, olmc, colsize, 0, 1, 1))
                        return(-1);
                }


                if (RowActive(olmc*8 + 2, JedecGALType))
                {
                    if (AddString(&buff, ptr))        /* write equation of  */
                        return(-1);                   /* asynchronous reset */

                    if (AddString(&buff, (UBYTE *)".ARST = "))
                        return(-1);

                    if (MakeEquation(&buff, olmc, colsize, 0, 2, 1))
                        return(-1);
                }


                if (RowActive(olmc*8 + 3, JedecGALType))
                {
                    if (AddString(&buff, ptr))         /* write equation of   */
                        return(-1);                    /* asynchronous preset */

                    if (AddString(&buff, (UBYTE *)".APRST = "))
                        return(-1);

                    if (MakeEquation(&buff, olmc, colsize, 0, 3, 1))
                        return(-1);
                }
            }
        }
    }


                                        /*** write asynchronous reset and ***/
                                        /*** synchronous preset           ***/
    if (JedecGALType == GAL22V10)
    {

        if (RowActive(0, JedecGALType))
        {
            if (AddString(&buff, (UBYTE *)"AR = "))     /* asyn. reset */
                return(-1);

            if (MakeEquation(&buff, olmc, colsize, 4, 0, 1))
                return(-1);
        }

        if (RowActive(131, JedecGALType))
        {
            if (AddString(&buff, (UBYTE *)"SP = "))     /* synch. preset */
                return(-1);

            if (MakeEquation(&buff, olmc, colsize, 5, 0, 1))
                return(-1);
        }

    }

                                        /*** write ending text ***/

    if (AddString(&buff,"DESCRIPTION:\nThis is a reassembled file. Used JEDEC file: '"))
        return(-1);

    if (AddString(&buff, (UBYTE *)&filename[0]))
        return(-1);

    if (AddString(&buff, (UBYTE *)"'\n\n"))
        return(-1);


    return(0);                            /* no errors, finish*/
}





/******************************************************************************
** Reassembler()
*******************************************************************************
** input:   none
** output:  none
**
** remarks: reassembles a JEDEC file and writes the source file
******************************************************************************/

void Reassembler(void)
{
    struct  Buffer          *reasm_buff;
    struct  ActBuffer       mybuff;
    BPTR    fh;
    UBYTE   *filebuffer, *filebuffer2;
    int     result;


    if (MyFileReq(AppStrings[MSG_LOADJED].as_Str, ".jed", YES, LOAD))
    {
        if (!(GetJedec((UBYTE *)&path[0])))
        {                                   /* get the JEDEC file */

            if (!PinNameRequester(JedecGALType))
                return;


            if (!(reasm_buff = (struct Buffer *)
                  AllocMem((long)sizeof(struct Buffer),MEMF_PUBLIC|MEMF_CLEAR)))
            {
                ErrorReq(2);        /* out of memory */
                return;
            }

            mybuff.ThisBuff = reasm_buff;
            mybuff.Entry    = (UBYTE *)(&reasm_buff->Entries[0]);
            mybuff.BuffEnd  = (UBYTE *)reasm_buff + (long)sizeof(struct Buffer);


            if (!Reasm(mybuff) && MyFileReq(AppStrings[MSG_WRITE_SOURCE].as_Str,
                                            ".pld", YES, SAVE))
            {
                PrintText(AppStrings[MSG_WRITING_SOURCE].as_Str, 1);

                if ((fh = Open(&path[0], (long)MODE_NEWFILE)))
                {
                    for (;;)
                    {
                        filebuffer = filebuffer2 = mybuff.Entry;

                        while (filebuffer2 < mybuff.BuffEnd)
                        {                   /* get buffer size */
                            if (!*filebuffer2)
                                break;

                            filebuffer2++;
                        }
                                                /* write buffer */
                        result = Write(fh, (char *)filebuffer,
                                       (long)(filebuffer2-filebuffer));

                        if (result == -1L)
                        {                       /* write error?        */
                            Close(fh);          /* yes, then shut down */
                            FreeBuffer(reasm_buff);
                            PrintText(AppStrings[MSG_ERROR].as_Str, 0);
                            ErrorReq(13);
                            return;
                        }

                        if (!mybuff.ThisBuff->Next) /* if there is no more */
                            break;                  /* buffer, break loop  */

                        mybuff.ThisBuff = mybuff.ThisBuff->Next;
                        mybuff.Entry    = (UBYTE *)(&mybuff.ThisBuff->Entries[0]);
                        mybuff.BuffEnd  = (UBYTE *)mybuff.ThisBuff +
                                          (long)sizeof(struct Buffer);
                    }

                    Close(fh);
                }
                else
                {
                    FreeBuffer(reasm_buff);         /*error?, then cancel */
                    PrintText(AppStrings[MSG_ERROR].as_Str, 0);
                    ErrorReq(13);                  /* can't open file     */
                    return;
                }

                PrintText(AppStrings[MSG_LOWER_OK].as_Str, 0);
            }

            FreeBuffer(reasm_buff);         /* free allocated memory */
        }
    }
}





/******************************************************************************
** ReasmError()
*******************************************************************************
** input:   errornum    error number to be printed
**          pinnum      pinnumber to be printed
**
** output:  none
**
** remarks: prints an error messages
******************************************************************************/

static void ReasmError(int errornum, int pinnum)
{
#define PINNUM_POS 7

    char    string[40];

    switch (errornum)
    {
        case  1:
             TxtRequest(AppStrings[MSG_REASM_ERR].as_Str,
                        AppStrings[MSG_CANCEL_GAD].as_Str, NULL);

             PrintText(AppStrings[MSG_ERR_REASM1].as_Str, 1);
             break;

        case  2:
            strcpy(string, AppStrings[MSG_ERR_REASM2].as_Str);
            sprintf(&string[PINNUM_POS], "%2d", pinnum);
            string[PINNUM_POS + 2] = ':';
            TxtRequest(string, AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
            break;

        case  3:
            strcpy(string, AppStrings[MSG_ERR_REASM3].as_Str);
            sprintf(&string[PINNUM_POS], "%2d", pinnum);
            string[PINNUM_POS + 2] = ':';
            TxtRequest(string, AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
            break;

        case  4:
            strcpy(string, AppStrings[MSG_ERR_REASM4].as_Str);
            sprintf(&string[PINNUM_POS], "%2d", pinnum);
            string[PINNUM_POS + 2] = ':';
            TxtRequest(string, AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
            break;

        case  5:
            strcpy(string, AppStrings[MSG_ERR_REASM5].as_Str);
            sprintf(&string[PINNUM_POS], "%2d", pinnum);
            string[PINNUM_POS + 2] = ':';
            TxtRequest(string, AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
            break;

        case  6:
            strcpy(string, AppStrings[MSG_ERR_REASM6].as_Str);
            sprintf(&string[PINNUM_POS], "%2d", pinnum);
            string[PINNUM_POS + 2] = ':';
            TxtRequest(string, AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
            break;

        case  7:
            strcpy(string, AppStrings[MSG_ERR_REASM7].as_Str);
            sprintf(&string[PINNUM_POS], "%2d", pinnum);
            string[PINNUM_POS + 2] = ':';
            TxtRequest(string, AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
            break;

        case  8:
            strcpy(string, AppStrings[MSG_ERR_REASM8].as_Str);
            sprintf(&string[PINNUM_POS], "%2d", pinnum);
            string[PINNUM_POS + 2] = ':';
            TxtRequest(string, AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
            break;

        case  9:
            strcpy(string, AppStrings[MSG_ERR_REASM9].as_Str);
            sprintf(&string[PINNUM_POS], "%2d", pinnum);
            string[PINNUM_POS + 2] = ':';
            TxtRequest(string, AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
            break;

        case 10:
            strcpy(string, AppStrings[MSG_ERR_REASM10].as_Str);
            sprintf(&string[PINNUM_POS], "%2d", pinnum);
            string[PINNUM_POS + 2] = ':';
            TxtRequest(string, AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
            break;

    }
}





/* EOF */
