home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / hard / misc / galer / source / galertest / galertest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-21  |  13.5 KB  |  674 lines

  1. /****************************************************************/
  2. /*                                */
  3. /* GALerTest - testprogram for the hardware            */
  4. /*                                */
  5. /* Soft- and Hardware  copyright (c)1991            */
  6. /*     by Christian Habermann                    */
  7. /*        Asamstr. 17                        */
  8. /*        85356 Freising                    */
  9. /*        Germany                        */
  10. /*                                */
  11. /* used Compiler: SAS-C 6.0                    */
  12. /*                                */
  13. /****************************************************************/
  14.  
  15.  
  16.  
  17. #include <exec/memory.h>
  18. #include <exec/ports.h>
  19. #include <exec/types.h>
  20. #include <intuition/intuition.h>
  21. #include <libraries/locale.h>
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25.  
  26. #include <proto/locale.h>
  27. #include <proto/graphics.h>
  28. #include <proto/intuition.h>
  29. #include <proto/exec.h>
  30.  
  31. #include "GALer.h"
  32. #include "LocGT.h"
  33.  
  34.  
  35. #ifdef LATTICE
  36. int CXBRK(void)    { return(0); }  /* Disable Lattice CTRL/C handling */
  37. int chkabort(void) { return(0); }  /* really */
  38. #endif
  39.  
  40.  
  41.  
  42. #define     YPOS    30
  43.  
  44.  
  45.  
  46. void Clear(void);
  47.  
  48. void Print(UBYTE *text);
  49.  
  50. void WaitForAction(void);
  51.  
  52. void closestuff(void);
  53.  
  54. void openstuff(void);
  55.  
  56. int  GetTimer(void);
  57.  
  58. void FreeTimer(void);
  59.  
  60.  
  61.  
  62. struct    MsgPort        *timeport;
  63. struct    timerequest    *timereq;
  64. struct    LocaleBase    *LocaleBase;
  65. struct    IntuitionBase    *IntuitionBase;
  66. struct    GfxBase        *GfxBase;
  67. struct    IntuiMessage    *message;
  68. struct    Window        *window;
  69. struct    RastPort    *rp;
  70. struct    TextFont    *txtfont;
  71. struct    TextAttr    txtattr;
  72. struct    Catalog        *catalog;
  73.  
  74.  
  75.  
  76. SHORT BorderVectors1a[] = { 0,15,81,15,81,0 };
  77. SHORT BorderVectors1b[] = { 0,15,0,0,81,0 };
  78.  
  79. struct Border Border1b    = { -1,-1,2,0,JAM1,3,BorderVectors1b,NULL };
  80. struct Border Border1a    = { -1,-1,1,0,JAM1,3,BorderVectors1a,&Border1b };
  81.  
  82.  
  83.  
  84. struct IntuiText GadIText3 = { 1, 0, JAM2, 4, 4, &txtattr, NULL, NULL };
  85.  
  86. struct IntuiText GadIText2 = { 1, 0, JAM2, 4, 4, &txtattr, NULL, NULL };
  87.  
  88. struct IntuiText GadIText1 = { 1, 0, JAM2, 8, 4, &txtattr, NULL, NULL };
  89.  
  90.  
  91.  
  92. struct Gadget CancelGad = { NULL, 522, 180, 80, 14,
  93.                 NULL,
  94.                 RELVERIFY,
  95.                 BOOLGADGET+REQGADGET,
  96.                 (APTR)&Border1a,NULL,
  97.                 &GadIText2,NULL,NULL,1,NULL };
  98.  
  99. struct Gadget ContGad   = { &CancelGad, 40, 180, 80, 14,
  100.                 NULL,
  101.                 RELVERIFY,
  102.                 BOOLGADGET+REQGADGET,
  103.                 (APTR)&Border1a,NULL,
  104.                 &GadIText1,NULL,NULL,0,NULL };
  105.  
  106.  
  107.  
  108.  
  109. struct NewWindow MyWin =  { 0,0,640,200,
  110.                 0,1,
  111.                 CLOSEWINDOW|GADGETUP,
  112.                 ACTIVATE|WINDOWCLOSE|WINDOWDRAG|WINDOWDEPTH,
  113.                 &ContGad,NULL,
  114.                 (UBYTE *)"GALerTest  (c) 1993 by Christian Habermann",
  115.                 NULL,NULL,
  116.                 0,0,0,0,
  117.                 WBENCHSCREEN
  118.               };
  119.  
  120.  
  121.  
  122.  
  123. int    prog_volt = 0;            /* Dummy for port.o module */
  124.  
  125. int    GALType, outIC1, outIC3, outIC4, outIC5;
  126.  
  127. int    ytxt = YPOS;
  128.  
  129.  
  130.  
  131.  
  132. void main(void)
  133. {
  134.  
  135. int errorIC6, errorIC7;
  136.  
  137.  
  138.   openstuff();
  139.  
  140.   if (GetTimer()) {                /* get timer*/
  141.     puts(GetCatalogStr(catalog, MSG_ERR_TIMER, "can't get timer"));
  142.     closestuff();
  143.     exit(FALSE);    
  144.    }
  145.  
  146.  
  147.   rp = window -> RPort;
  148.  
  149.   SetAPen(rp, 1L);
  150.   SetFont(rp, txtfont);                /* get font */
  151.  
  152.  
  153.  
  154.   InitParPort();                /* set CIAs */
  155.  
  156.   InitGALer();
  157.  
  158.   Print(GetCatalogStr(catalog, MSG_INTRO_TXT,
  159.     "This is a program for testing the hardware V1.2 of the GALer project.\n"
  160.     "You need this program to adjust the trimpots R40-44 too.\n"
  161.     "IMPORTANT: There must be no GAL in the Textool socket now!\n\n"
  162.     "If the hardware works not as the test program demands, then\n"
  163.     "you should cancel 'GALerTest' immediately and try to remove the\n"
  164.     "bug in your hardware.\n\n"
  165.     "Please select the 'Continue' gadget to start the test."
  166.   ));
  167.   WaitForAction();
  168.  
  169.  
  170.   Clear();
  171.   Print(GetCatalogStr(catalog, MSG_TEST1_TXT,
  172.     "Now the LED should be off and all pins of the Textool socket should\n"
  173.     "be set at LOW level (about 0 volt).\n\n"
  174.     "Please select 'Continue'!"
  175.   ));
  176.   EnableOutput();
  177.   WriteByte(0x00,IC3);
  178.   WriteByte(0x00,IC4);
  179.   WriteByte(0x00,IC5);
  180.   WaitForAction();
  181.  
  182.  
  183.   Clear();
  184.   Print(GetCatalogStr(catalog, MSG_TEST2_TXT,
  185.     "Now the LED should be on.\n\n"
  186.     "Please select 'Continue'!"
  187.   ));
  188.   LED(ON);
  189.   WaitForAction();
  190.  
  191.  
  192.   Clear();
  193.   Print(GetCatalogStr(catalog, MSG_TEST3_TXT,
  194.     "Now the LED should be off again.\n\n"
  195.     "Please select 'Continue'!"
  196.   ));
  197.   LED(OFF);
  198.   WaitForAction();
  199.  
  200.  
  201.   Clear();
  202.   Print(GetCatalogStr(catalog, MSG_TEST4_TXT,
  203.     "At pin 24 of the Textool socket should be a HIGH level (about 5 volt).\n\n"
  204.     "Please select 'Continue'!"
  205.   ));
  206.   SetGAL(GAL20V8);
  207.   EnableVcc();
  208.   WaitForAction();
  209.  
  210.  
  211.   Clear();
  212.   Print(GetCatalogStr(catalog, MSG_TEST5_TXT,
  213.     "At pin 22 of the Textool socket should be a HIGH level too.\n\n"
  214.     "Please select 'Continue'!"
  215.   ));
  216.   DisableVcc();
  217.   SetGAL(GAL16V8);
  218.   EnableVcc();
  219.   WaitForAction();
  220.  
  221.  
  222.   Clear();
  223.   Print(GetCatalogStr(catalog, MSG_TEST6_TXT,
  224.     "At all pins should be a HIGH level with exception of pin 12.\n"
  225.     "Pin 12 is GND.\n\n"
  226.     "Please select 'Continue'!"
  227.   ));
  228.   InitGALer();
  229.   EnableOutput();
  230.   WriteByte(0xff,IC3);
  231.   WriteByte(0xff,IC4);
  232.   WriteByte(0xff,IC5);
  233.   WaitForAction();
  234.  
  235.  
  236.   Clear();
  237.   Print(GetCatalogStr(catalog, MSG_TEST7_TXT,
  238.     "At pins 1, 3, 5, 7, 9, 11, 14, 16, 18, 20, 22, 24 should be a HIGH level.\n"
  239.     "All other pins should be LOW.\n\n"
  240.     "Please select 'Continue'!"
  241.   ));
  242.   SetGAL(GAL20V8);
  243.   EnableVcc();
  244.   WriteByte(0x55,IC3);
  245.   WriteByte(0x55,IC4);
  246.   WriteByte(0x55,IC5);
  247.   WaitForAction();
  248.  
  249.  
  250.   Clear();
  251.   Print(GetCatalogStr(catalog, MSG_TEST8_TXT,
  252.     "Now at pins 2, 4, 6, 8, 10, 13, 15, 17, 19, 21, 23 should be a HIGH level.\n"
  253.     "All other pins should be LOW.\n\n"
  254.     "Please select 'Continue'!"
  255.   ));
  256.   DisableVcc();
  257.   WriteByte(0xaa,IC3);
  258.   WriteByte(0xaa,IC4);
  259.   WriteByte(0xaa,IC5);
  260.   WaitForAction();
  261.  
  262.   DisableVcc();
  263.   InitGALer();
  264.   EnableOutput();
  265.   VeditOn();
  266.  
  267.  
  268.   Clear();
  269.   Print(GetCatalogStr(catalog, MSG_TEST9_TXT,
  270.     "***************************************************************************\n"
  271.     "Now you have to adjust the trimpots R40-R44.\n"
  272.     "If this does not work, check IC 9, IC 10, T3, T4.\n\n"
  273.     "Use trimpot R40 to adjust the voltage at pin 2 to exactly 16.5V.\n"
  274.     "Please select 'Continue'!\n\n"
  275.   ));
  276.   SetVolt(0);
  277.   SetGAL(GAL20V8);
  278.   EnableVEdit();
  279.   WaitForAction();
  280.  
  281.  
  282.   Print(GetCatalogStr(catalog, MSG_TEST10_TXT,
  283.     "Use trimpot R41 to adjust the voltage at pin 2 to exactly 15.75V.\n"
  284.     "Please select 'Continue'!\n\n"
  285.   ));
  286.   SetVolt(1);
  287.   WaitForAction();
  288.  
  289.  
  290.   Print(GetCatalogStr(catalog, MSG_TEST11_TXT,
  291.     "Use trimpot R42 to adjust the voltage at pin 2 to exactly 14.5V.\n"
  292.     "Please select 'Continue'!\n\n"
  293.   ));
  294.   SetVolt(2);
  295.   WaitForAction();
  296.   Print("");
  297.  
  298.  
  299.   Print(GetCatalogStr(catalog, MSG_TEST12_TXT,
  300.     "Use trimpot R43 to adjust the voltage at pin 2 to exactly 14.0V.\n"
  301.     "Please select 'Continue'!\n\n"
  302.   ));
  303.   SetVolt(3);
  304.   WaitForAction();
  305.   Print("");
  306.  
  307.  
  308.   Print(GetCatalogStr(catalog, MSG_TEST13_TXT,
  309.     "Use trimpot R44 to adjust the voltage at pin 2 to exactly 12.0V.\n"
  310.     "Please select 'Continue'!\n\n"
  311.   ));
  312.   SetVolt(4);
  313.   WaitForAction();
  314.  
  315.  
  316.   Print(GetCatalogStr(catalog, MSG_TEST14_TXT,
  317.     "O.K., now all voltages are adjusted. Let me do some other tests.\n"
  318.     "Please select 'Continue'!\n"
  319.     "***************************************************************************"
  320.   ));
  321.   WaitForAction();
  322.   Clear();
  323.  
  324.  
  325.   Print(GetCatalogStr(catalog, MSG_TEST15_TXT,
  326.     "Now at pin 4 should be a voltage of 12.0V and pin 2 should be\n"
  327.     "at LOW level. If this does not work, check T1, T2.\n\n"
  328.     "Please select 'Continue'!"
  329.   ));
  330.   DisableVEdit();
  331.   SetGAL(GAL16V8);
  332.   EnableVEdit();
  333.   WaitForAction();
  334.   Clear();
  335.  
  336.  
  337.  
  338.  
  339.                 /* check GALer's read functions */
  340.   Print(GetCatalogStr(catalog, MSG_TEST16_TXT,
  341.     "Now I'm trying to read pins 14-22 of the Textool socket...\n"
  342.   ));
  343.   SetGAL(GAL20V8);
  344.   InitGALer();
  345.   EnableVcc();
  346.   EnableOutput();
  347.                 /*IC6a testen*/
  348.   errorIC6 = errorIC7 = 0;
  349.   WriteByte(0x40,IC3);
  350.   if (!ReadByte(IC6))
  351.     errorIC6 = 1;
  352.  
  353.   WriteByte(0x00,IC3);
  354.   if (ReadByte(IC6))
  355.     errorIC6 = 1;
  356.                 /*IC7 testen*/
  357.   WriteByte(0x00,IC5);
  358.   if (ReadByte(IC7))
  359.     errorIC7 = 1;
  360.  
  361.   WriteByte(0x2A,IC3);
  362.   WriteByte(0x20,IC5);
  363.   if (ReadByte(IC7) != 0xAA)
  364.     errorIC7 = 1;
  365.  
  366.   WriteByte(0x15,IC3);
  367.   WriteByte(0x10,IC5);
  368.   if (ReadByte(IC7) != 0x55)
  369.     errorIC7 = 1;
  370.  
  371.   DisableVcc();
  372.   DisableOutput(); 
  373.  
  374.   if (errorIC6 || errorIC7) {
  375.  
  376.     Print(GetCatalogStr(catalog, MSG_TEST17_TXT,
  377.       " ERROR!!!\n"
  378.       "   There must be an error at the BUSY line, R27, IC8, IC6a, IC6b, IC7\n"
  379.       "   or R13. Please check this components.\n\n"
  380.       " Description of error:\n"
  381.     ));
  382.  
  383.     if (errorIC6 && !errorIC7) {
  384.       Print(GetCatalogStr(catalog, MSG_TEST18_TXT,
  385.         "  I can't read pin 22 through the BUSY line of the parallel port."
  386.       ));
  387.     }
  388.  
  389.     if (!errorIC6 && errorIC7) {
  390.       Print(GetCatalogStr(catalog, MSG_TEST19_TXT,
  391.         "  I can't read pins 14-21 through the BUSY line of the parallel port."
  392.       ));
  393.     }
  394.  
  395.     if  (errorIC6 && errorIC7) {
  396.       Print(GetCatalogStr(catalog, MSG_TEST20_TXT,
  397.         "  I can't read pins 14-21 and pin 22 through the BUSY line of the\n"
  398.         "  parallel port."
  399.       ));
  400.     }
  401.  
  402.   }
  403.   else {
  404.  
  405.     Print(GetCatalogStr(catalog, MSG_TEST21_TXT,
  406.       "O.K., no error found (you have a lot going for you).\n\n"
  407.       "If you have found no errors and if you have adjusted all voltages\n"
  408.       "(12V, 14V, 14.5V, 15.75V and 16.5V), GALer works fine.\n\n"
  409.       "Now you can read/program GALs by using the software called GALer."
  410.     ));
  411.   }
  412.  
  413.   CancelGad.GadgetText = &GadIText3;
  414.   OffGadget(&ContGad, window, NULL);
  415.   RefreshGList(&ContGad, window, NULL, -1);
  416.  
  417.   WaitForAction();
  418.  
  419.  
  420.   RestoreParPort();
  421.  
  422.   FreeTimer();
  423.  
  424.   closestuff();
  425. }
  426.  
  427.  
  428.  
  429.  
  430.  
  431. /* get timer
  432. */
  433. int GetTimer(void)
  434. {
  435.  
  436.  timeport = CreatePort(0L,0L);
  437.  if (timeport == NULL)
  438.    return(-1);
  439.  
  440.  timereq=(struct timerequest *)AllocMem(
  441.             (long)sizeof(struct timerequest),MEMF_PUBLIC);
  442.  if (timereq == NULL) {
  443.    DeletePort(timeport);
  444.    return(-1);
  445.   }
  446.  
  447.  timereq->tr_node.io_Message.mn_Node.ln_Type=NT_MESSAGE;
  448.  timereq->tr_node.io_Message.mn_Node.ln_Pri=0;
  449.  timereq->tr_node.io_Message.mn_ReplyPort=timeport;
  450.  
  451.  if (OpenDevice(TIMERNAME, UNIT_MICROHZ, (struct IORequest *)timereq, 0L)) {
  452.    FreeMem(&timereq, (long)sizeof(struct timerequest));
  453.    DeletePort (timeport);
  454.    return(-1);
  455.   }
  456.  
  457.  return(0);
  458. }
  459.  
  460.  
  461.  
  462.  
  463. /* free timer
  464. */
  465. void FreeTimer(void)
  466. {
  467.  CloseDevice((struct IORequest *)timereq);
  468.  
  469.  FreeMem(timereq, (long)sizeof(struct timerequest));
  470.  
  471.  DeletePort(timeport);
  472. }
  473.  
  474.  
  475.  
  476. /*micro: microsec. to wait
  477.   secs: seconds to wait
  478. */
  479. void WaitForTimer(ULONG micro)
  480. {
  481.  
  482.   timereq->tr_node.io_Command=TR_ADDREQUEST;
  483.   timereq->tr_time.tv_secs=0;
  484.   timereq->tr_time.tv_micro=micro;
  485.  
  486.   DoIO((struct IORequest *)timereq);
  487.  
  488. }
  489.  
  490.  
  491.  
  492.  
  493. /* clear window
  494. */
  495. void Clear(void)
  496. {
  497.  
  498.   ytxt = YPOS;
  499.  
  500.   SetAPen(rp, 0L);
  501.  
  502.   RectFill(rp, 10L, 22L, 630L, 170L);
  503.  
  504.   SetAPen(rp, 1L);
  505.  
  506. }
  507.  
  508.  
  509.  
  510.  
  511. /* print text
  512. */
  513. void Print(UBYTE *text)
  514. {
  515. UBYTE *ptr;
  516. int   notready;
  517.  
  518.  
  519.   ptr = text;
  520.  
  521.   notready = 1;
  522.  
  523.   while (notready) {
  524.                         /* search CR or end of */
  525.     while ((*ptr != 0x00) && (*ptr != 0x0A))    /* string              */
  526.       ptr++;
  527.  
  528.  
  529.     if (ytxt < 160)
  530.       ytxt += 10;
  531.     else
  532.       ScrollRaster(rp,0L,10L,10L,22L,630L,170L);
  533.  
  534.  
  535.     if (*text != 0x0A) {
  536.       Move(rp, 20L, (long)ytxt);        /* print string */
  537.       Text(rp, text, (long)(ptr - text));
  538.     }
  539.  
  540.     if (!*ptr)
  541.       notready = 0;
  542.  
  543.     text = ++ptr;
  544.  
  545.   }
  546.  
  547. }
  548.  
  549.  
  550.  
  551.  
  552.  
  553. /* wait until gadget is selected
  554. */
  555. void WaitForAction(void)
  556. {
  557. ULONG    class;
  558. USHORT    code,gadID;
  559.  
  560.  for(;;) {
  561.  
  562.    Wait(1L << window->UserPort->mp_SigBit);
  563.  
  564.    if (message = (struct IntuiMessage *)GetMsg(window->UserPort)) {
  565.  
  566.      class = message -> Class;
  567.      code  = message -> Code;
  568.  
  569.      if (class == GADGETUP)
  570.        gadID = ((struct Gadget *)message->IAddress)->GadgetID;
  571.  
  572.      ReplyMsg((struct Message *)message);
  573.  
  574.      switch(class) {
  575.  
  576.     case CLOSEWINDOW: closestuff();        /* exit GALerTest */
  577.               FreeTimer();
  578.               RestoreParPort();
  579.               exit(0);
  580.               break;
  581.  
  582.     case GADGETUP:    if (!gadID)
  583.                 return;                
  584.               else {        /* cancel selected */
  585.                 closestuff();
  586.                 FreeTimer();
  587.                 RestoreParPort();
  588.                 exit (0);
  589.               }
  590.               break;
  591.      }
  592.    }
  593.  }
  594. }
  595.  
  596.  
  597.  
  598.  
  599.  
  600. /* close window, libs...
  601. */
  602. void closestuff(void)
  603. {
  604.   if (window) CloseWindow(window);
  605.  
  606.   if (GfxBase) CloseLibrary((struct Library *)GfxBase);
  607.  
  608.   if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
  609.  
  610.   if (LocaleBase) CloseLibrary((struct Library *)LocaleBase);
  611.  
  612. }
  613.  
  614.  
  615.  
  616.  
  617. /* open window, libs...
  618. */
  619. void openstuff(void)
  620. {
  621.  
  622.   if (!(LocaleBase = (struct LocaleBase *)OpenLibrary("locale.library", 38L))) {
  623.     puts("can't open locale.library version 38");
  624.     exit(FALSE);
  625.   }
  626.  
  627.   catalog = OpenCatalog(NULL, (STRPTR)"GALerTest.catalog", OC_Version, 1, TAG_DONE);
  628.  
  629.  
  630.   if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 37L))) {
  631.     puts (GetCatalogStr(catalog, MSG_ERR_INTLIB, "can't open intuition.library V37"));
  632.     closestuff();
  633.     exit(FALSE);
  634.   }
  635.  
  636.   if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 37L))) {
  637.     puts (GetCatalogStr(catalog, MSG_ERR_GRAPHLIB, "can't open graphics.library V37"));
  638.     closestuff();
  639.     exit(FALSE);
  640.   }
  641.  
  642.  
  643.   txtattr.ta_Name  = (STRPTR)"topaz.font";        /* get font */
  644.   txtattr.ta_YSize = 8;
  645.   txtattr.ta_Style = 0;
  646.   txtattr.ta_Flags = 0;
  647.  
  648.   if (!(txtfont = (struct TextFont *)OpenFont(&txtattr))) {
  649.     puts(GetCatalogStr(catalog, MSG_ERR_FONT, "can't get topaz.font 8"));
  650.     closestuff();
  651.     exit(FALSE);
  652.   }
  653.  
  654.  
  655.                 /* localize gadgets */
  656.  
  657.   GadIText3.IText = GetCatalogStr(catalog, MSG_END_GAD, "   END   ");
  658.  
  659.   GadIText2.IText = GetCatalogStr(catalog, MSG_CANCEL_GAD, " Cancel");
  660.  
  661.   GadIText1.IText = GetCatalogStr(catalog, MSG_CONT_GAD, "Continue");
  662.  
  663.  
  664.   if (!(window = (struct Window *)OpenWindow(&MyWin))) {
  665.     puts (GetCatalogStr(catalog, MSG_ERR_WIN, "can't open window"));
  666.     closestuff();
  667.     exit(FALSE);
  668.   }
  669. }
  670.  
  671.  
  672.  
  673.  
  674.