home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / MoreHardware / GALer20.lha / GALer20 / Source / GALerTest / GALerTest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-05  |  33.3 KB  |  1,250 lines

  1. /******************************************************************************
  2. ** GALerTest.c
  3. *******************************************************************************
  4. **
  5. ** author:   Christian Habermann, (c)1991-96 by Christian Habermann
  6. **           Asamstr. 17
  7. **           85356 Freising
  8. **           Germany
  9. ** version:  2.0
  10. ** date:     07.02.1995
  11. **
  12. ** used compiler: SAS-C 6.51
  13. **
  14. *******************************************************************************
  15. **
  16. ** description:
  17. ** This is a program for testing GALer's hardware.
  18. **
  19. *******************************************************************************
  20. **
  21. ** changes:
  22. ** date     |     author     |  comment
  23. **          |                |
  24. **          |                |
  25. ******************************************************************************/
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33. /********************************* includes **********************************/
  34.  
  35.  
  36. #define  STRINGARRAY    1
  37.  
  38. #include <libraries/mui.h>
  39.  
  40. #include <dos/dos.h>
  41. #include <graphics/gfxmacros.h>
  42. #include <workbench/workbench.h>
  43. #include <exec/memory.h>
  44. #include <exec/ports.h>
  45. #include <exec/types.h>
  46. #include <exec/interrupts.h>
  47. #include <intuition/intuition.h>
  48. #include <libraries/locale.h>
  49. #include <resources/misc.h>
  50. #include <resources/cia.h>
  51. #include <hardware/cia.h>
  52.  
  53. #include <clib/alib_protos.h>
  54. #include <proto/asl.h>
  55. #include <proto/dos.h>
  56. #include <proto/exec.h>
  57. #include <proto/intuition.h>
  58. #include <proto/locale.h>
  59. #include <proto/muimaster.h>
  60. #include <proto/reqtools.h> 
  61. #include <proto/misc.h>
  62. #include <proto/cia.h>
  63.  
  64.  
  65. #include <stdlib.h>
  66. #include <stdio.h>
  67. #include <string.h>
  68. #include <ctype.h>
  69.  
  70. #include "GALer.h"
  71. #include "LocGT.h"
  72.  
  73.  
  74.  
  75.  
  76.  
  77. /********************************* defines ***********************************/
  78.  
  79. #ifndef MAKE_ID
  80. #define MAKE_ID(a,b,c,d)\
  81.            ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
  82. #endif
  83.  
  84.  
  85. #define GADID_CONT    1
  86. #define GADID_CANCEL  2
  87. #define GADID_VER_OK  3
  88.  
  89.  
  90. #define ciaa  (*((struct CIA *)0xbfe001))
  91. #define ciab  (*((struct CIA *)0xbfd000))
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98. /******************************** functions **********************************/
  99.  
  100. static void  Clear(void);
  101. static void  OpenStuff(void);
  102. static void  CloseStuff(void);
  103. static int   GetTimer(void);
  104. static void  FreeTimer(void);
  105. static void  Print(UBYTE *text);
  106. static int   GetParPort(void);
  107. static void  FreeParPort(void);
  108. static int   GetCIATimer(void);
  109. static void  FreeCIATimer(void);
  110. static void  dummy_interrupt(void);
  111. static int   GetHardwareVersion(void);
  112. static void  WaitForAction(void);
  113.  
  114. void  main(void);
  115.  
  116.  
  117. #ifdef LATTICE
  118. int CXBRK(void)    { return(0); }  /* disable Lattice CTRL/C handling */
  119. int chkabort(void) { return(0); }
  120. #endif
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127. /******************************** variables **********************************/
  128.  
  129. extern  int     hw_version;
  130.  
  131. extern  struct  Library *SysBase;
  132.  
  133. extern  char    *cia_timer_low, *cia_timer_high, *cia_timer_cr;
  134.  
  135. extern  char    cia_timer_start, cia_timer_stop;
  136.  
  137.  
  138. struct  MsgPort         *timeport;
  139. struct  timerequest     *timereq;
  140. struct  Library         *LocaleBase;
  141. struct  Library         *MiscBase; 
  142. struct  Library         *CIABase; 
  143. struct  Library         *MUIMasterBase;
  144. struct  IntuiMessage    *message;
  145. struct  Catalog         *catalog;
  146.  
  147. WORD    selected_timer;
  148.  
  149. int     prog_volt = 0;                  /* dummy for port.o module */
  150.  
  151. int     GALType, outIC1, outIC2, outIC3, outIC4, outIC5;
  152.  
  153. LONG    __stack = 8192;
  154.  
  155. static  APTR  app, main_win, version_win;
  156. static  APTR  BT_cont, BT_cancel, BT_ok;
  157. static  APTR  LV_text;
  158. static  APTR  RD_version;
  159.  
  160.  
  161. static const char *RD_entries[] = { "V1.0 / V1.1",
  162.                                     "V1.2",
  163.                                     "V1.3",
  164.                                     NULL
  165.                                   };
  166.  
  167.  
  168. static struct Interrupt CIATimerInterrupt =
  169.               {{0, 0, NT_INTERRUPT, 0, "GALerTest"}, NULL, &dummy_interrupt};
  170.  
  171.  
  172.  
  173. static UBYTE prog_name[] = "GALerTest";
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181. /******************************************************************************
  182. ** main()
  183. *******************************************************************************
  184. ** input:   none
  185. ** output:  none
  186. ** remarks: this is the main function
  187. ******************************************************************************/
  188.  
  189. void main(void)
  190. {
  191.  
  192.     int errorIC6a, errorIC6c, errorIC7;
  193.  
  194.  
  195.  
  196.     OpenStuff();
  197.  
  198.  
  199.     if (!GetParPort())                      /* get parallel port */
  200.     {
  201.         puts((char *)AppStrings[MSG_ERR_PARPORT].as_Str);
  202.         CloseStuff();
  203.         exit(20);
  204.     }
  205.  
  206.  
  207.                                             /* get any CIA timer */
  208.     if (!GetCIATimer())
  209.     {
  210.         RestoreParPort();
  211.         FreeParPort();
  212.         puts((char *)AppStrings[MSG_ERR_CIATIMER].as_Str);
  213.         CloseStuff();
  214.         exit(20);
  215.     }
  216.                                             /* open timer device */
  217.  
  218.  
  219.     if (!GetTimer())
  220.     {
  221.         RestoreParPort();
  222.         FreeParPort();
  223.         FreeCIATimer();
  224.         puts((char *)AppStrings[MSG_ERR_TIMER].as_Str);
  225.         CloseStuff();
  226.         exit(20);
  227.     }
  228.  
  229.  
  230.  
  231.  
  232.     Print(AppStrings[MSG_INTRO_TXT].as_Str);
  233.     WaitForAction();
  234.  
  235.  
  236.                                         /* get hardware version */
  237.  
  238.     set(main_win, MUIA_Window_Sleep, TRUE);     /* deactivate main window */
  239.  
  240.     if (!GetHardwareVersion())                  /* open version window */
  241.     {
  242.         FreeTimer();                            /* if failed, free resources */
  243.         CloseStuff();
  244.         puts(AppStrings[MSG_ERR_WIN].as_Str);
  245.         exit(20);
  246.     }
  247.  
  248.     set(main_win, MUIA_Window_Sleep, FALSE);    /* activate main window */
  249.  
  250.  
  251.  
  252.  
  253.     InitParPort();                              /* set CIAs */
  254.  
  255.     InitHardware();                             /* initialize GALer */
  256.  
  257.  
  258.     Clear();
  259.     Print(AppStrings[MSG_TEST1_TXT].as_Str);
  260.     EnableOutput();
  261.     WriteByte(0x00, IC3);
  262.     WriteByte(0x00, IC4);
  263.     WriteByte(0x00, IC5);
  264.     WaitForAction();
  265.  
  266.  
  267.     Clear();
  268.     Print(AppStrings[MSG_TEST2_TXT].as_Str);
  269.     LED(ON);
  270.     WaitForAction();
  271.  
  272.  
  273.     Clear();
  274.     Print(AppStrings[MSG_TEST3_TXT].as_Str);
  275.     LED(OFF);
  276.     WaitForAction();
  277.  
  278.  
  279.     Clear();
  280.     Print(AppStrings[MSG_TEST4_TXT].as_Str);
  281.     SetGAL(GAL20V8);
  282.     EnableVcc();
  283.     WaitForAction();
  284.  
  285.  
  286.     Clear();
  287.     Print(AppStrings[MSG_TEST5_TXT].as_Str);
  288.     DisableVcc();
  289.     SetGAL(GAL16V8);
  290.     EnableVcc();
  291.     WaitForAction();
  292.  
  293.  
  294.     Clear();
  295.     Print(AppStrings[MSG_TEST6_TXT].as_Str);
  296.     InitHardware();
  297.     EnableOutput();
  298.     WriteByte(0xff, IC3);
  299.     WriteByte(0xff, IC4);
  300.     WriteByte(0xff, IC5);
  301.     WaitForAction();
  302.  
  303.  
  304.     Clear();
  305.     Print(AppStrings[MSG_TEST7_TXT].as_Str);
  306.     SetGAL(GAL20V8);
  307.     EnableVcc();
  308.     WriteByte(0x55, IC3);
  309.     WriteByte(0x55, IC4);
  310.     WriteByte(0x55, IC5);
  311.     WaitForAction();
  312.  
  313.  
  314.     Clear();
  315.     Print(AppStrings[MSG_TEST8_TXT].as_Str);
  316.     DisableVcc();
  317.     WriteByte(0xaa, IC3);
  318.     WriteByte(0xaa, IC4);
  319.     WriteByte(0xaa, IC5);
  320.     WaitForAction();
  321.  
  322.     DisableVcc();
  323.     InitHardware();
  324.     EnableOutput();
  325.     VeditOn();
  326.  
  327.  
  328.                                                   /* adjust edit voltages */
  329.     switch (hw_version)
  330.     {
  331.         case HW_GALER_1_2:
  332.         case HW_GALER_1_3:
  333.  
  334.             Clear();
  335.             Print(AppStrings[MSG_TEST9_TXT].as_Str);
  336.             SetVolt(0);
  337.             SetGAL(GAL20V8);
  338.             EnableVEdit();
  339.             WaitForAction();
  340.  
  341.             Clear();
  342.             Print(AppStrings[MSG_TEST10_TXT].as_Str);
  343.             SetVolt(1);
  344.             WaitForAction();
  345.  
  346.             Clear();
  347.             Print(AppStrings[MSG_TEST11_TXT].as_Str);
  348.             SetVolt(2);
  349.             WaitForAction();
  350.  
  351.             Clear();
  352.             Print(AppStrings[MSG_TEST12_TXT].as_Str);
  353.             SetVolt(3);
  354.             WaitForAction();
  355.  
  356.             Clear();
  357.             Print(AppStrings[MSG_TEST13_TXT].as_Str);
  358.             SetVolt(4);
  359.             WaitForAction();
  360.  
  361.             Print(AppStrings[MSG_TEST14_TXT].as_Str);
  362.             WaitForAction();
  363.  
  364.             Clear();
  365.             Print(AppStrings[MSG_TEST15_TXT].as_Str);
  366.             DisableVEdit();
  367.             SetGAL(GAL16V8);
  368.             EnableVEdit();
  369.             WaitForAction();
  370.  
  371.             break;
  372.  
  373.  
  374.         case HW_GALER_1_0:
  375.  
  376.             Clear();
  377.             Print(AppStrings[MSG_TEST22_TXT].as_Str);
  378.             SetVolt(0);
  379.             SetGAL(GAL20V8);
  380.             EnableVEdit();
  381.             WaitForAction();
  382.  
  383.             Clear();
  384.             Print(AppStrings[MSG_TEST23_TXT].as_Str);
  385.             DisableVEdit();
  386.             SetGAL(GAL16V8);
  387.             EnableVEdit();
  388.             WaitForAction();
  389.  
  390.             break;
  391.     }
  392.  
  393.  
  394.                                   /* check GALer's read functions */
  395.     Clear();
  396.  
  397.     if (hw_version >= HW_GALER_1_3)
  398.         Print(AppStrings[MSG_TEST16_TXT].as_Str);
  399.     else
  400.         Print(AppStrings[MSG_TEST25_TXT].as_Str);
  401.  
  402.     SetGAL(GAL20V8);
  403.     InitHardware();
  404.     EnableVcc();
  405.     EnableOutput();
  406.  
  407.     errorIC6a = errorIC6c = errorIC7 = 0;
  408.  
  409.                                           /* test IC6a */
  410.     WriteByte(0x40, IC3);
  411.     if (!ReadByte(IC6a))
  412.         errorIC6a = 1;
  413.  
  414.     WriteByte(0x00, IC3);
  415.      if (ReadByte(IC6a))
  416.        errorIC6a = 1;
  417.  
  418.  
  419.                                           /* test IC6c */
  420.     if (hw_version >= HW_GALER_1_3)
  421.     {
  422.         WriteByte(0x80, IC3);
  423.         if (!ReadByte(IC6c))
  424.             errorIC6c = 1;
  425.  
  426.         WriteByte(0x00, IC3);
  427.         if (ReadByte(IC6c))
  428.             errorIC6c = 1;
  429.     }
  430.  
  431.  
  432.                                           /* test IC7 */
  433.     WriteByte(0x00, IC5);
  434.     if (ReadByte(IC7))
  435.         errorIC7 = 1;
  436.  
  437.     WriteByte(0x2A, IC3);
  438.     WriteByte(0x20, IC5);
  439.     if (ReadByte(IC7) != 0xAA)
  440.         errorIC7 = 1;
  441.  
  442.     WriteByte(0x15, IC3);
  443.     WriteByte(0x10, IC5);
  444.     if (ReadByte(IC7) != 0x55)
  445.         errorIC7 = 1;
  446.  
  447.  
  448.  
  449.     DisableVcc();
  450.     DisableOutput();
  451.  
  452.  
  453.  
  454.  
  455.     if (errorIC6c || errorIC6a || errorIC7)
  456.     {
  457.  
  458.         Print(AppStrings[MSG_TEST17_TXT].as_Str);
  459.  
  460.         if (errorIC6a)
  461.             Print(AppStrings[MSG_TEST18_TXT].as_Str);
  462.  
  463.  
  464.         if (errorIC7)
  465.             Print(AppStrings[MSG_TEST19_TXT].as_Str);
  466.  
  467.  
  468.         if (errorIC6c)
  469.             Print(AppStrings[MSG_TEST20_TXT].as_Str);
  470.     }
  471.     else
  472.     {
  473.         if (hw_version == HW_GALER_1_0)
  474.             Print(AppStrings[MSG_TEST24_TXT].as_Str);
  475.         else
  476.             Print(AppStrings[MSG_TEST21_TXT].as_Str);
  477.     }
  478.  
  479.  
  480.                                             /* rename cancel-gadget to */
  481.                                             /* -> end-gadget           */
  482.     set(BT_cancel, MUIA_Text_Contents, AppStrings[MSG_END_GAD].as_Str);
  483.  
  484.  
  485.     set(BT_cont, MUIA_Disabled, TRUE);      /* disable cont-gadget */
  486.  
  487.  
  488.     WaitForAction();
  489.  
  490.  
  491.     RestoreParPort();                       /* shut down */
  492.  
  493.     FreeParPort();
  494.  
  495.     FreeCIATimer();
  496.  
  497.     FreeTimer();
  498.  
  499.     CloseStuff();
  500.  
  501.     exit(0);                                /* that's it */
  502. }
  503.  
  504.  
  505.  
  506.  
  507.  
  508. /******************************************************************************
  509. ** GetParPort()
  510. *******************************************************************************
  511. ** input:   none
  512. **
  513. ** output:  TRUE:  ok
  514. **          FALSE: parallel port in use
  515. **
  516. ** remarks: allocate Amiga's parallel port
  517. ******************************************************************************/
  518.  
  519. static int GetParPort(void)
  520. {
  521.  
  522.                                         /* get parallel port */
  523.  
  524.     if (!(MiscBase = (struct Library *)OpenResource(MISCNAME)))
  525.     {
  526.         return FALSE;
  527.     }
  528.  
  529.  
  530.     if (AllocMiscResource(MR_PARALLELPORT, prog_name))
  531.     {
  532.         return FALSE;
  533.     }
  534.  
  535.  
  536.     if (AllocMiscResource(MR_PARALLELBITS, prog_name))
  537.     {
  538.         FreeMiscResource(MR_PARALLELPORT);
  539.         return FALSE;
  540.     }
  541.  
  542.  
  543.  
  544.     InitParPort();                      /* init data direction register */
  545.  
  546.     return TRUE;
  547. }
  548.  
  549.  
  550.  
  551.  
  552.  
  553. /******************************************************************************
  554. ** FreeParPort()
  555. *******************************************************************************
  556. ** input:   none
  557. ** output:  none
  558. **
  559. ** remarks: free Amiga's parallel port
  560. ******************************************************************************/
  561.  
  562. static void FreeParPort(void)
  563. {
  564.  
  565.     RestoreParPort();                       /* restore the state of the */
  566.                                             /* parallel port            */
  567.  
  568.     FreeMiscResource(MR_PARALLELBITS);      /* free parallel port */
  569.     FreeMiscResource(MR_PARALLELPORT);
  570.  
  571. }
  572.  
  573.  
  574.  
  575.  
  576.  
  577. /******************************************************************************
  578. ** GetCIATimer()
  579. *******************************************************************************
  580. ** input:   none
  581. ** output:  TRUE:  o.k.
  582. **          FALSE: failed to get any CIA timer
  583. **
  584. ** remarks: try to get one of the four CIA timers and initialize it
  585. ******************************************************************************/
  586.  
  587. static int GetCIATimer(void)
  588. {
  589.  
  590.  
  591.                             /* at first try to get one of the CIA-A timers */
  592.  
  593.     if ((CIABase = (struct Library *)OpenResource(CIAANAME)))
  594.     {
  595.                                             /* try to get timer A          */
  596.                                             /* (interrupt is just a dummy) */
  597.  
  598.         if (!(AddICRVector(CIABase, CIAICRB_TA, &CIATimerInterrupt)))
  599.         {
  600.             AbleICR(CIABase, CIAICRB_TA);       /* disable timer A interrupt */
  601.  
  602.             selected_timer = CIAICRB_TA;
  603.  
  604.             cia_timer_low  = &ciaa.ciatalo;     /* init some variables */
  605.             cia_timer_high = &ciaa.ciatahi;
  606.             cia_timer_cr   = &ciaa.ciacra;
  607.  
  608.             cia_timer_start = ciaa.ciacra & (CIACRAF_SPMODE | CIACRAF_TODIN) |
  609.                               CIACRAF_START | CIACRAF_LOAD;
  610.  
  611.             cia_timer_stop  = cia_timer_start & ~CIACRAF_START;
  612.  
  613.             return TRUE;
  614.         }
  615.                                             /* try to get timer B */
  616.  
  617.         if (!(AddICRVector(CIABase, CIAICRB_TB, &CIATimerInterrupt)))
  618.         {
  619.             AbleICR(CIABase, CIAICRB_TB);       /* disable timer B interrupt */
  620.  
  621.             selected_timer = CIAICRB_TB;
  622.  
  623.             cia_timer_low  = &ciaa.ciatblo;     /* init some variables */
  624.             cia_timer_high = &ciaa.ciatbhi;
  625.             cia_timer_cr   = &ciaa.ciacrb;
  626.  
  627.             cia_timer_start = ciaa.ciacrb & CIACRBF_ALARM |
  628.                               CIACRBF_START | CIACRBF_LOAD;
  629.  
  630.             cia_timer_stop  = cia_timer_start & ~CIACRBF_START;
  631.  
  632.             return TRUE;
  633.         }
  634.  
  635.     }
  636.  
  637.  
  638.                             /* now try to get one of the CIA-B timers */
  639.  
  640.     if ((CIABase = (struct Library *)OpenResource(CIABNAME)))
  641.     {
  642.                                             /* try to get timer A          */
  643.  
  644.         if (!(AddICRVector(CIABase, CIAICRB_TA, &CIATimerInterrupt)))
  645.         {
  646.             AbleICR(CIABase, CIAICRB_TA);       /* disable timer A interrupt */
  647.  
  648.             selected_timer = CIAICRB_TA;
  649.  
  650.             cia_timer_low  = &ciab.ciatalo;     /* init some variables */
  651.             cia_timer_high = &ciab.ciatahi;
  652.             cia_timer_cr   = &ciab.ciacra;
  653.  
  654.             cia_timer_start = ciab.ciacra & (CIACRAF_SPMODE | CIACRAF_TODIN) |
  655.                               CIACRAF_START | CIACRAF_LOAD;
  656.  
  657.             cia_timer_stop  = cia_timer_start & ~CIACRAF_START;
  658.  
  659.             return TRUE;
  660.         }
  661.                                             /* try to get timer B */
  662.  
  663.         if (!(AddICRVector(CIABase, CIAICRB_TB, &CIATimerInterrupt)))
  664.         {
  665.             AbleICR(CIABase, CIAICRB_TB);       /* disable timer B interrupt */
  666.  
  667.             selected_timer = CIAICRB_TB;
  668.  
  669.             cia_timer_low  = &ciab.ciatblo;     /* init some variables */
  670.             cia_timer_high = &ciab.ciatbhi;
  671.             cia_timer_cr   = &ciab.ciacrb;
  672.  
  673.             cia_timer_start = ciab.ciacrb & CIACRBF_ALARM |
  674.                               CIACRBF_START | CIACRBF_LOAD;
  675.  
  676.             cia_timer_stop  = cia_timer_start & ~CIACRBF_START;
  677.  
  678.             return TRUE;
  679.         }
  680.  
  681.     }
  682.  
  683.  
  684.     return FALSE;
  685. }
  686.  
  687.  
  688.  
  689.  
  690.  
  691. /******************************************************************************
  692. ** FreeCIATimer()
  693. *******************************************************************************
  694. ** input:   none
  695. ** output:  none
  696. **
  697. ** remarks: free CIA timer
  698. ******************************************************************************/
  699.  
  700. static void FreeCIATimer(void)
  701. {
  702.  
  703.     RemICRVector(CIABase, selected_timer, &CIATimerInterrupt);
  704.  
  705. }
  706.  
  707.  
  708.  
  709.  
  710.  
  711. /******************************************************************************
  712. ** dummy_interrupt()
  713. *******************************************************************************
  714. ** input:   none
  715. ** output:  none
  716. **
  717. ** remarks: This is just a dummy function. It's needed for the interrupt
  718. **          structure necessary to test whether or not a CIA timer is free.
  719. **          __interrupt is a SAS-C keyword. This keyword turns off stack
  720. **          checking.
  721. ******************************************************************************/
  722.  
  723. __interrupt static void dummy_interrupt(void)
  724. {
  725.     return;
  726. }
  727.  
  728.  
  729.  
  730.  
  731.  
  732.  
  733. /******************************************************************************
  734. ** GetTimer()
  735. *******************************************************************************
  736. ** input:   none
  737. ** output:  TRUE:  ok
  738. **          FALSE: failed to open device
  739. **
  740. ** remarks: open timer device
  741. ******************************************************************************/
  742.  
  743. static int GetTimer(void)
  744. {
  745.  
  746.     timeport = CreatePort(0L,0L);
  747.  
  748.     if (timeport == NULL)
  749.         return FALSE;
  750.  
  751.     timereq = (struct timerequest *)AllocMem(
  752.                             (long)sizeof(struct timerequest), MEMF_PUBLIC);
  753.  
  754.     if (timereq == NULL)
  755.     {
  756.         DeletePort(timeport);
  757.         return FALSE;
  758.     }
  759.  
  760.  
  761.     timereq->tr_node.io_Message.mn_Node.ln_Type = NT_MESSAGE;
  762.     timereq->tr_node.io_Message.mn_Node.ln_Pri  = 0;
  763.     timereq->tr_node.io_Message.mn_ReplyPort    = timeport;
  764.  
  765.  
  766.     if (OpenDevice(TIMERNAME, UNIT_MICROHZ, (struct IORequest *)timereq, 0L))
  767.     {
  768.         FreeMem(&timereq, (long)sizeof(struct timerequest));
  769.         DeletePort(timeport);
  770.         return FALSE;
  771.     }
  772.  
  773.  
  774.     return TRUE;
  775. }
  776.  
  777.  
  778.  
  779.  
  780.  
  781. /******************************************************************************
  782. ** FreeTimer()
  783. *******************************************************************************
  784. ** input:   none
  785. ** output:  none
  786. ** remarks: free timer device
  787. ******************************************************************************/
  788.  
  789. static void FreeTimer(void)
  790. {
  791.  
  792.     CloseDevice((struct IORequest *)timereq);
  793.  
  794.     FreeMem(timereq, (long)sizeof(struct timerequest));
  795.  
  796.     DeletePort(timeport);
  797. }
  798.  
  799.  
  800.  
  801.  
  802.  
  803. /******************************************************************************
  804. ** WaitForTimer()
  805. *******************************************************************************
  806. ** input:   micro      time in micro seconds
  807. ** output:  none
  808. **
  809. ** remarks: wait "micro" micro seconds
  810. ******************************************************************************/
  811.  
  812. void WaitForTimer(ULONG micro)
  813. {
  814.  
  815.     timereq->tr_node.io_Command = TR_ADDREQUEST;
  816.     timereq->tr_time.tv_secs    = 0;
  817.     timereq->tr_time.tv_micro   = micro;
  818.  
  819.     DoIO((struct IORequest *)timereq);
  820. }
  821.  
  822.  
  823.  
  824.  
  825.  
  826. /******************************************************************************
  827. ** Clear()
  828. *******************************************************************************
  829. ** input:   none
  830. ** output:  none
  831. **
  832. ** remarks: clears listview's list
  833. ******************************************************************************/
  834.  
  835. static void Clear(void)
  836. {                                                          
  837.  
  838.     DoMethod(LV_text, MUIM_List_Clear);    /* clear list */
  839.  
  840. }
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847. /******************************************************************************
  848. ** Print()
  849. *******************************************************************************
  850. ** input:   *txt     pointer to text
  851. ** output:  none
  852. **
  853. ** remarks: This function adds a string to the list of the
  854. **          listview. CRs within the string are allowed.
  855. ******************************************************************************/
  856.  
  857. static void Print(UBYTE *txt)
  858. {
  859.     #define LINE_LENGTH  82                 /* max. length of string */
  860.  
  861.     int    cntr;
  862.     char   line[LINE_LENGTH];
  863.  
  864.  
  865.  
  866.     for(;;)
  867.     {
  868.         line[0] = 0;
  869.         cntr    = 0;                        /* search CR or end of */
  870.                                             /* string              */
  871.         while (*txt != 0x00 && *txt != 0x0A && cntr < LINE_LENGTH)
  872.         {
  873.             line[cntr++] = *txt++;             /* copy line into line-array */
  874.         }
  875.  
  876.  
  877.         line[cntr] = 0;                        /* set end of line */
  878.  
  879.  
  880.         DoMethod(LV_text, MUIM_List_InsertSingle,  /* add line to  */
  881.                  line, MUIV_List_Insert_Bottom);   /* the listview */
  882.  
  883.         if (!*txt)                             /* end of string reached? */
  884.             break;
  885.  
  886.         txt++;
  887.     }
  888.  
  889.  
  890.     DoMethod(LV_text, MUIM_List_Jump, 0);     /* make first entry visible */
  891. }
  892.  
  893.  
  894.  
  895.  
  896.  
  897. /******************************************************************************
  898. ** WaitForAction()
  899. *******************************************************************************
  900. ** input:   none
  901. ** output:  none
  902. **
  903. ** remarks: This function does wait for any action done by the user
  904. **          and executes the according function.
  905. ******************************************************************************/
  906.  
  907. static void WaitForAction(void)
  908. {
  909.     ULONG signal;
  910.  
  911.  
  912.     for(;;)
  913.     {
  914.         switch (DoMethod(app, MUIM_Application_Input, &signal))
  915.         {
  916.                                                 /* exit GALerTest */
  917.             case MUIV_Application_ReturnID_Quit:    /* close  gadget */
  918.             case GADID_CANCEL:                      /* cancel gadget */
  919.                 DisableVcc();
  920.                 DisableOutput();
  921.                 LED(OFF);
  922.                 CloseStuff();
  923.                 RestoreParPort();
  924.                 FreeParPort();
  925.                 FreeCIATimer();
  926.                 FreeTimer();
  927.                 exit(0);
  928.                 break;
  929.  
  930.  
  931.             case GADID_CONT:            /* continue... */
  932.                 return;
  933.                 break;
  934.        }
  935.  
  936.  
  937.        if (signal)
  938.           Wait(signal);
  939.  
  940.     }
  941. }
  942.  
  943.  
  944.  
  945.  
  946.  
  947. /******************************************************************************
  948. ** GetHardwareVersion()
  949. *******************************************************************************
  950. ** input:   none
  951. ** output:  TRUE:  all ok
  952. **          FALSE: failed to open window
  953. **
  954. ** remarks: This function opens the version window and deals with
  955. **          user's inputs.
  956. ******************************************************************************/
  957.  
  958. static int GetHardwareVersion(void)
  959. {
  960.     ULONG signal, radio;
  961.     LONG  result;
  962.  
  963.  
  964.     set(version_win, MUIA_Window_Open, TRUE);    /* open version window */
  965.     get(version_win, MUIA_Window_Open, &result);
  966.  
  967.     if (!result)
  968.         return FALSE;
  969.  
  970.                                 /* wait for selection of OK */
  971.     for(;;)
  972.     {
  973.         switch (DoMethod(app, MUIM_Application_Input, &signal))
  974.         {
  975.             case MUIV_Application_ReturnID_Quit:   /* close gadget   */
  976.             case GADID_VER_OK:                     /* OK is selected */
  977.  
  978.                 get(RD_version, MUIA_Radio_Active, &radio);
  979.  
  980.                 switch(radio)
  981.                 {
  982.                     case 0:
  983.                         hw_version = HW_GALER_1_0;
  984.                         break;
  985.  
  986.                     case 1:
  987.                         hw_version = HW_GALER_1_2;
  988.                         break;
  989.  
  990.                     case 2:
  991.                         hw_version = HW_GALER_1_3;
  992.                         break;
  993.                 }
  994.  
  995.                 set(version_win, MUIA_Window_Open, FALSE);
  996.  
  997.                 return TRUE;
  998.                 break;
  999.         }
  1000.  
  1001.  
  1002.        if (signal)                      /* wait for the next action */
  1003.           Wait(signal);
  1004.  
  1005.     } 
  1006.  
  1007. }
  1008.  
  1009.  
  1010.  
  1011.  
  1012.  
  1013. /******************************************************************************
  1014. ** openstruff()
  1015. *******************************************************************************
  1016. ** input:   none
  1017. ** output:  none
  1018. **
  1019. ** remarks: This function does open all libraries and the MUI
  1020. **          application.
  1021. ******************************************************************************/
  1022.  
  1023. static void OpenStuff(void)
  1024. {
  1025.     LONG result;
  1026.  
  1027.  
  1028.  
  1029.     if (LocaleBase = OpenLibrary("locale.library", 38L))
  1030.         catalog = OpenCatalog(NULL, (STRPTR)"GALerTest.catalog",
  1031.                               OC_Version, 2, TAG_DONE);
  1032.  
  1033.     LocalizeText();
  1034.  
  1035.  
  1036.     if (!(MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN)))
  1037.     {
  1038.  
  1039.         puts(AppStrings[MSG_ERR_MUILIB].as_Str);
  1040.         CloseStuff();
  1041.         exit(20);
  1042.     }
  1043.  
  1044.  
  1045.                                 /* create application window, gadgets...*/
  1046.  
  1047.                                             /* main window */
  1048.     app = ApplicationObject,
  1049.             MUIA_Application_Title,       "GALerTest",
  1050.             MUIA_Application_Version,     "$VER: GALerTest 2.0 (17.03.96)",
  1051.             MUIA_Application_Copyright,   "©1991-96, Christian Habermann",
  1052.             MUIA_Application_Author,      "Christian Habermann",
  1053.             MUIA_Application_Description, "Program for testing GALer's hardware.",
  1054.             MUIA_Application_Base,        "GALERTEST",
  1055.  
  1056.             SubWindow, main_win = WindowObject,
  1057.                 MUIA_Window_Title, "GALerTest V2.0, ©1991-96 by Christian Habermann",
  1058.                 MUIA_Window_ID   , MAKE_ID('G','A','T','S'),
  1059.  
  1060.                 WindowContents, GroupObject,
  1061.                     Child, LV_text = ListviewObject,
  1062.                         MUIA_Listview_Input, FALSE,
  1063.                         MUIA_Listview_List, ListObject,
  1064.                         MUIA_List_ConstructHook, MUIV_List_ConstructHook_String,
  1065.                         MUIA_List_DestructHook, MUIV_List_DestructHook_String,
  1066.                         ReadListFrame,
  1067.                         End,
  1068.                     End,
  1069.  
  1070.                     Child, GroupObject,
  1071.                         MUIA_Group_Horiz, TRUE,
  1072.                         MUIA_Group_SameWidth, TRUE,
  1073.                         Child, BT_cont = SimpleButton(AppStrings[MSG_CONT_GAD].as_Str),
  1074.                                MUIA_Text_SetMax, TRUE,
  1075.                         Child, BT_cancel = SimpleButton(AppStrings[MSG_CANCEL_GAD].as_Str),
  1076.                                MUIA_Text_SetMax, TRUE,
  1077.                         End,
  1078.                     End,
  1079.                 End,
  1080.  
  1081.                                             /* hardware version window */
  1082.  
  1083.             SubWindow, version_win = WindowObject,
  1084.                 MUIA_Window_Title, "GALerTest",
  1085.                 MUIA_Window_ID   , MAKE_ID('V','E','R','S'),
  1086.  
  1087.                 WindowContents, GroupObject,
  1088.                     Child, TextObject, GroupFrame,
  1089.                            MUIA_Background, MUII_SHADOWFILL,
  1090.                            MUIA_Text_Contents, AppStrings[MSG_SELVER_TXT].as_Str,
  1091.                            End,
  1092.  
  1093.                     Child, RD_version = Radio(AppStrings[MSG_VERSION_TXT].as_Str, RD_entries),
  1094.  
  1095.                     Child, BT_ok = SimpleButton("_OK"),
  1096.                            MUIA_Text_SetMax, TRUE,
  1097.                     End,
  1098.                 End,
  1099.             End;
  1100.  
  1101.  
  1102.  
  1103.     if (!app)
  1104.     {
  1105.         CloseStuff();
  1106.         puts(AppStrings[MSG_ERR_MUIAPP].as_Str);
  1107.         exit(20);
  1108.     }
  1109.  
  1110.  
  1111.                                             /* set notifies */
  1112.  
  1113.     DoMethod(main_win, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
  1114.              app, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
  1115.  
  1116.     DoMethod(version_win, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
  1117.              app, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
  1118.  
  1119.  
  1120.  
  1121.     DoMethod(BT_cont ,MUIM_Notify, MUIA_Pressed, FALSE,
  1122.              app, 2, MUIM_Application_ReturnID, GADID_CONT);
  1123.  
  1124.     DoMethod(BT_cancel ,MUIM_Notify, MUIA_Pressed, FALSE,
  1125.              app, 2, MUIM_Application_ReturnID, GADID_CANCEL);
  1126.  
  1127.  
  1128.     DoMethod(BT_ok ,MUIM_Notify, MUIA_Pressed, FALSE,
  1129.              app, 2, MUIM_Application_ReturnID, GADID_VER_OK);
  1130.  
  1131.  
  1132.  
  1133.                                             /* set TAB cycle chain */
  1134.  
  1135.     DoMethod(main_win, MUIM_Window_SetCycleChain, BT_cont, BT_cancel, NULL);
  1136.     DoMethod(version_win, MUIM_Window_SetCycleChain, RD_version, BT_ok, NULL);
  1137.  
  1138.     set(RD_version ,MUIA_Radio_Active, 2);  /* default version 1.3 */
  1139.  
  1140.  
  1141.  
  1142.     set(main_win, MUIA_Window_Open, TRUE);  /* open application window...*/
  1143.     get(main_win, MUIA_Window_Open, &result);
  1144.  
  1145.     if (!result)
  1146.     {
  1147.         CloseStuff();
  1148.         puts(AppStrings[MSG_ERR_WIN].as_Str);
  1149.         exit(20);
  1150.     }
  1151.  
  1152. }
  1153.  
  1154.  
  1155.  
  1156.  
  1157.  
  1158. /******************************************************************************
  1159. ** CloseStuff()
  1160. *******************************************************************************
  1161. ** input:   none
  1162. ** output:  none
  1163. **
  1164. ** remarks: closes the MUI application and all libraries
  1165. ******************************************************************************/
  1166.  
  1167. static void CloseStuff(void)
  1168. {
  1169.  
  1170.     if (app)
  1171.         MUI_DisposeObject(app);
  1172.  
  1173.  
  1174.     if (LocaleBase)
  1175.     {
  1176.         CloseCatalog(catalog);
  1177.         CloseLibrary((struct Library *)LocaleBase);
  1178.     }
  1179.  
  1180.  
  1181.     if (MUIMasterBase)
  1182.         CloseLibrary(MUIMasterBase);
  1183.  
  1184. }
  1185.  
  1186.  
  1187.  
  1188.  
  1189.  
  1190. /******************************************************************************
  1191. ** LocalizeText()
  1192. *******************************************************************************
  1193. ** input:   none
  1194. ** output:  none
  1195. **
  1196. ** remarks: localizes all strings
  1197. ******************************************************************************/
  1198.  
  1199. void LocalizeText(void)
  1200. {
  1201.  
  1202.     if (LocaleBase && catalog)
  1203.     {
  1204.  
  1205.         AppStrings[MSG_END_GAD].as_Str = GetCatalogStr(catalog, MSG_END_GAD, AppStrings[MSG_END_GAD].as_Str);
  1206.         AppStrings[MSG_CANCEL_GAD].as_Str = GetCatalogStr(catalog, MSG_CANCEL_GAD, AppStrings[MSG_CANCEL_GAD].as_Str);
  1207.         AppStrings[MSG_CONT_GAD].as_Str = GetCatalogStr(catalog, MSG_CONT_GAD, AppStrings[MSG_CONT_GAD].as_Str);
  1208.         AppStrings[MSG_ERR_TIMER].as_Str = GetCatalogStr(catalog, MSG_ERR_TIMER, AppStrings[MSG_ERR_TIMER].as_Str);
  1209.         AppStrings[MSG_ERR_CIATIMER].as_Str = GetCatalogStr(catalog, MSG_ERR_CIATIMER, AppStrings[MSG_ERR_CIATIMER].as_Str);
  1210.         AppStrings[MSG_ERR_PARPORT].as_Str = GetCatalogStr(catalog, MSG_ERR_PARPORT, AppStrings[MSG_ERR_PARPORT].as_Str);
  1211.         AppStrings[MSG_ERR_MUILIB].as_Str = GetCatalogStr(catalog, MSG_ERR_MUILIB, AppStrings[MSG_ERR_MUILIB].as_Str);
  1212.         AppStrings[MSG_ERR_MUIAPP].as_Str = GetCatalogStr(catalog, MSG_ERR_MUIAPP, AppStrings[MSG_ERR_MUIAPP].as_Str);
  1213.         AppStrings[MSG_ERR_WIN].as_Str = GetCatalogStr(catalog, MSG_ERR_WIN, AppStrings[MSG_ERR_WIN].as_Str);
  1214.         AppStrings[MSG_SELVER_TXT].as_Str = GetCatalogStr(catalog, MSG_SELVER_TXT, AppStrings[MSG_SELVER_TXT].as_Str);
  1215.         AppStrings[MSG_VERSION_TXT].as_Str = GetCatalogStr(catalog, MSG_VERSION_TXT, AppStrings[MSG_VERSION_TXT].as_Str);
  1216.         AppStrings[MSG_INTRO_TXT].as_Str = GetCatalogStr(catalog, MSG_INTRO_TXT, AppStrings[MSG_INTRO_TXT].as_Str);
  1217.         AppStrings[MSG_TEST1_TXT].as_Str = GetCatalogStr(catalog, MSG_TEST1_TXT, AppStrings[MSG_TEST1_TXT].as_Str);
  1218.         AppStrings[MSG_TEST2_TXT].as_Str = GetCatalogStr(catalog, MSG_TEST2_TXT, AppStrings[MSG_TEST2_TXT].as_Str);
  1219.         AppStrings[MSG_TEST3_TXT].as_Str = GetCatalogStr(catalog, MSG_TEST3_TXT, AppStrings[MSG_TEST3_TXT].as_Str);
  1220.         AppStrings[MSG_TEST4_TXT].as_Str = GetCatalogStr(catalog, MSG_TEST4_TXT, AppStrings[MSG_TEST4_TXT].as_Str);
  1221.         AppStrings[MSG_TEST5_TXT].as_Str = GetCatalogStr(catalog, MSG_TEST5_TXT, AppStrings[MSG_TEST5_TXT].as_Str);
  1222.         AppStrings[MSG_TEST6_TXT].as_Str = GetCatalogStr(catalog, MSG_TEST6_TXT, AppStrings[MSG_TEST6_TXT].as_Str);
  1223.         AppStrings[MSG_TEST7_TXT].as_Str = GetCatalogStr(catalog, MSG_TEST7_TXT, AppStrings[MSG_TEST7_TXT].as_Str);
  1224.         AppStrings[MSG_TEST8_TXT].as_Str = GetCatalogStr(catalog, MSG_TEST8_TXT, AppStrings[MSG_TEST8_TXT].as_Str);
  1225.         AppStrings[MSG_TEST9_TXT].as_Str = GetCatalogStr(catalog, MSG_TEST9_TXT, AppStrings[MSG_TEST9_TXT].as_Str);
  1226.         AppStrings[MSG_TEST10_TXT].as_Str = GetCatalogStr(catalog, MSG_TEST10_TXT, AppStrings[MSG_TEST10_TXT].as_Str);
  1227.         AppStrings[MSG_TEST11_TXT].as_Str = GetCatalogStr(catalog, MSG_TEST11_TXT, AppStrings[MSG_TEST11_TXT].as_Str);
  1228.         AppStrings[MSG_TEST12_TXT].as_Str = GetCatalogStr(catalog, MSG_TEST12_TXT, AppStrings[MSG_TEST12_TXT].as_Str);
  1229.         AppStrings[MSG_TEST13_TXT].as_Str = GetCatalogStr(catalog, MSG_TEST13_TXT, AppStrings[MSG_TEST13_TXT].as_Str);
  1230.         AppStrings[MSG_TEST14_TXT].as_Str = GetCatalogStr(catalog, MSG_TEST14_TXT, AppStrings[MSG_TEST14_TXT].as_Str);
  1231.         AppStrings[MSG_TEST15_TXT].as_Str = GetCatalogStr(catalog, MSG_TEST15_TXT, AppStrings[MSG_TEST15_TXT].as_Str);
  1232.         AppStrings[MSG_TEST16_TXT].as_Str = GetCatalogStr(catalog, MSG_TEST16_TXT, AppStrings[MSG_TEST16_TXT].as_Str);
  1233.         AppStrings[MSG_TEST17_TXT].as_Str = GetCatalogStr(catalog, MSG_TEST17_TXT, AppStrings[MSG_TEST17_TXT].as_Str);
  1234.         AppStrings[MSG_TEST18_TXT].as_Str = GetCatalogStr(catalog, MSG_TEST18_TXT, AppStrings[MSG_TEST18_TXT].as_Str);
  1235.         AppStrings[MSG_TEST19_TXT].as_Str = GetCatalogStr(catalog, MSG_TEST19_TXT, AppStrings[MSG_TEST19_TXT].as_Str);
  1236.         AppStrings[MSG_TEST20_TXT].as_Str = GetCatalogStr(catalog, MSG_TEST20_TXT, AppStrings[MSG_TEST20_TXT].as_Str);
  1237.         AppStrings[MSG_TEST21_TXT].as_Str = GetCatalogStr(catalog, MSG_TEST21_TXT, AppStrings[MSG_TEST21_TXT].as_Str);
  1238.         AppStrings[MSG_TEST22_TXT].as_Str = GetCatalogStr(catalog, MSG_TEST22_TXT, AppStrings[MSG_TEST22_TXT].as_Str);
  1239.         AppStrings[MSG_TEST23_TXT].as_Str = GetCatalogStr(catalog, MSG_TEST23_TXT, AppStrings[MSG_TEST23_TXT].as_Str);
  1240.         AppStrings[MSG_TEST24_TXT].as_Str = GetCatalogStr(catalog, MSG_TEST24_TXT, AppStrings[MSG_TEST24_TXT].as_Str);
  1241.         AppStrings[MSG_TEST25_TXT].as_Str = GetCatalogStr(catalog, MSG_TEST25_TXT, AppStrings[MSG_TEST25_TXT].as_Str);
  1242.  
  1243.     }
  1244.  
  1245. }
  1246.  
  1247.  
  1248.  
  1249. /* EOF */
  1250.