?login_element?

Subversion Repositories NedoOS

Rev

Rev 1464 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.  
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <oscalls.h>
  6. #include <intrz80.h>
  7. #include <terminal.c>
  8. #define COMMANDLINE 0x0080
  9.  
  10.  
  11.  
  12. /* Accuracy of timings and human fatigue controlled by next two lines */
  13. //#define LOOPS 5000            /* Use this for slow or 16 bit machines */
  14. #define LOOPS   50000           /* Use this for slow or 16 bit machines */
  15. //#define LOOPS 500000          /* Use this for faster machines */
  16.  
  17. /* Compiler dependent options */
  18. //#undef        NOENUM                  /* Define if compiler has no enum's */
  19. //#undef        NOSTRUCTASSIGN          /* Define if compiler can't assign structures */
  20.  
  21. /* define only one of the next three defines */
  22. //#define GETRUSAGE             /* Use getrusage(2) time function */
  23. //#define TIMES                 /* Use times(2) time function */
  24. #define TIME                    /* Use time(2) time function */
  25. //#define TIME_EVO_IAR                  /* Use time(2) time function */
  26.  
  27.  
  28. /* define the granularity of your times(2) function (when used) */
  29. //#define HZ    60              /* times(2) returns 1/60 second (most) */
  30. //#define HZ    100             /* times(2) returns 1/100 second (WECo) */
  31. #define HZ      50              /* times(2) returns 1/50 second (ZX-Evo) */
  32. //#define HZ    1               /* for time(2) */
  33.  
  34. /* for compatibility with goofed up version */
  35. //#define GOOF                  /* Define if you want the goofed up version */
  36.  
  37. #ifdef GOOF
  38. char    Version[] = "1.0";
  39. #else
  40. char    Version[] = "1.1";
  41. #endif
  42.  
  43. #ifdef  NOSTRUCTASSIGN
  44. #define structassign(d, s)      memcpy(&(d), &(s), sizeof(d))
  45. #else
  46. #define structassign(d, s)      d = s
  47. #endif
  48.  
  49. #ifdef  NOENUM
  50. #define Ident1  1
  51. #define Ident2  2
  52. #define Ident3  3
  53. #define Ident4  4
  54. #define Ident5  5
  55. typedef int     Enumeration;
  56. #else
  57. typedef enum    {Ident1, Ident2, Ident3, Ident4, Ident5} Enumeration;
  58. #endif
  59.  
  60. typedef int     OneToThirty;
  61. typedef int     OneToFifty;
  62. typedef char    CapitalLetter;
  63. typedef char    String30[31];
  64. typedef int     Array1Dim[51];
  65. typedef int     Array2Dim[51][51];
  66.  
  67. struct  Record
  68. {
  69.         struct Record           *PtrComp;
  70.         Enumeration             Discr;
  71.         Enumeration             EnumComp;
  72.         OneToFifty              IntComp;
  73.         String30                StringComp;
  74. };
  75.  
  76. typedef struct Record   RecordType;
  77. typedef RecordType *    RecordPtr;
  78. typedef int             boolean;
  79.  
  80. //#define       NULL            0
  81. #define TRUE            1
  82. #define FALSE           0
  83.  
  84. #ifndef REG
  85. #define REG
  86. #endif
  87.  
  88. #ifdef TIMES
  89. #include <sys/param.h>
  90. #include <sys/types.h>
  91. #include <sys/times.h>
  92. #endif
  93. #ifdef GETRUSAGE
  94. #include <sys/time.h>
  95. #include <sys/resource.h>
  96. #endif
  97. #ifdef TIME_EVO_IAR
  98. #include <string.h>
  99. #include <intrz80.h>
  100. #include <stdio.h>
  101. #include "conio.h"
  102. #endif
  103.  
  104.  
  105. /*
  106.  * Package 1
  107.  */
  108. int             IntGlob;
  109. boolean         BoolGlob;
  110. char            Char1Glob;
  111. char            Char2Glob;
  112. Array1Dim       Array1Glob;
  113. Array2Dim       Array2Glob;
  114. RecordPtr       PtrGlb;
  115. RecordPtr       PtrGlbNext;
  116. void Proc4(void );
  117. void Proc5(void );
  118. Enumeration Func1(CapitalLetter CharPar1,CapitalLetter  CharPar2);
  119. boolean Func2(String30  StrParI1,String30       StrParI2);
  120. void Proc1(REG RecordPtr        PtrParIn);
  121. void Proc2(OneToFifty   *IntParIO);
  122. void Proc3(RecordPtr    *PtrParOut);
  123. void Proc6(REG Enumeration      EnumParIn, REG Enumeration      *EnumParOut);
  124. void Proc7(OneToFifty   IntParI1, OneToFifty    IntParI2, OneToFifty    *IntParOut);
  125. void Proc8(Array1Dim    Array1Par,Array2Dim     Array2Par,OneToFifty    IntParI1,OneToFifty     IntParI2);
  126. boolean Func3(REG Enumeration   EnumParIn);
  127.  
  128. void Proc0(void )
  129. {
  130.         OneToFifty              IntLoc1;
  131.         REG OneToFifty          IntLoc2;
  132.         OneToFifty              IntLoc3;
  133.         REG char                CharLoc;
  134.         REG char                CharIndex;
  135.         Enumeration             EnumLoc;
  136.         String30                String1Loc;
  137.         String30                String2Loc;
  138.         RecordType _GlbNext;
  139.         RecordType _Glb;
  140.  
  141.         register unsigned int   i;
  142. #ifdef TIME
  143.         long                    time(void);
  144.         long                    starttime;
  145.         long                    benchtime;
  146.         long                    nulltime;
  147.  
  148.         starttime = time(/* (long *) 0*/);
  149.         for (i = 0; i < LOOPS; ++i);
  150.         nulltime = time(/* (long *) 0*/) - starttime; /* Computes o'head of loop */
  151. #endif
  152. #ifdef TIMES
  153.         time_t                  starttime;
  154.         time_t                  benchtime;
  155.         time_t                  nulltime;
  156.         struct tms              tms;
  157.  
  158.         times(&tms); starttime = tms.tms_utime;
  159.         for (i = 0; i < LOOPS; ++i);
  160.         times(&tms);
  161.         nulltime = tms.tms_utime - starttime; /* Computes overhead of looping */
  162. #endif
  163. #ifdef TIME_EVO_IAR
  164.         extern long     int_timer;
  165.         long                    starttime;
  166.         long                    benchtime;
  167.         long                    nulltime;
  168.        
  169.         MCU_Init();
  170.  
  171.         textbackground(BLUE);
  172.         clrscr();
  173.         textcolor(BLACK);
  174.         textbackground(CYAN);
  175.         enable_interrupt();
  176.         halt();
  177.         starttime = int_timer;
  178.         for (i = 0; i < LOOPS; ++i);
  179.         halt();
  180.         nulltime = int_timer - starttime; /* Computes overhead of looping */
  181. #endif
  182. #ifdef GETRUSAGE
  183.         struct rusage starttime;
  184.         struct rusage endtime;
  185.         struct timeval nulltime;
  186.  
  187.         getrusage(RUSAGE_SELF, &starttime);
  188.         for (i = 0; i < LOOPS; ++i);
  189.         getrusage(RUSAGE_SELF, &endtime);
  190.         nulltime.tv_sec  = endtime.ru_utime.tv_sec  - starttime.ru_utime.tv_sec;
  191.         nulltime.tv_usec = endtime.ru_utime.tv_usec - starttime.ru_utime.tv_usec;
  192. #endif
  193.  
  194.         PtrGlbNext = &_GlbNext;
  195.         PtrGlb = &_Glb;
  196.         PtrGlb->PtrComp = PtrGlbNext;
  197.         PtrGlb->Discr = Ident1;
  198.         PtrGlb->EnumComp = Ident3;
  199.         PtrGlb->IntComp = 40;
  200.         strcpy(PtrGlb->StringComp, "DHRYSTONE PROGRAM, SOME STRING");
  201. #ifndef GOOF
  202.         strcpy(String1Loc, "DHRYSTONE PROGRAM, 1'ST STRING");   /*GOOF*/
  203. #endif
  204.         Array2Glob[8][7] = 10;  /* Was missing in published program */
  205.  
  206. /*****************
  207. -- Start Timer --
  208. *****************/
  209. #ifdef TIME
  210.         starttime = time(/* (long *) 0*/);
  211. #endif
  212. #ifdef TIMES
  213.         times(&tms); starttime = tms.tms_utime;
  214. #endif
  215. #ifdef TIME_EVO_IAR
  216.         halt();
  217.         starttime = int_timer;
  218. #endif
  219. #ifdef GETRUSAGE
  220.         getrusage (RUSAGE_SELF, &starttime);
  221. #endif
  222.         for (i = 0; i < LOOPS; ++i)
  223.         {
  224.  
  225.                 Proc5();
  226.                 Proc4();
  227.                 IntLoc1 = 2;
  228.                 IntLoc2 = 3;
  229.                 strcpy(String2Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
  230.                 EnumLoc = Ident2;
  231.                 BoolGlob = ! Func2(String1Loc, String2Loc);
  232.                 while (IntLoc1 < IntLoc2)
  233.                 {
  234.                         IntLoc3 = 5 * IntLoc1 - IntLoc2;
  235.                         Proc7(IntLoc1, IntLoc2, &IntLoc3);
  236.                         ++IntLoc1;
  237.                 }
  238.                 Proc8(Array1Glob, Array2Glob, IntLoc1, IntLoc3);
  239.                 Proc1(PtrGlb);
  240.                 for (CharIndex = 'A'; CharIndex <= Char2Glob; ++CharIndex)
  241.                         if (EnumLoc == Func1(CharIndex, 'C'))
  242.                                 Proc6(Ident1, &EnumLoc);
  243.                 IntLoc3 = IntLoc2 * IntLoc1;
  244.                 IntLoc2 = IntLoc3 / IntLoc1;
  245.                 IntLoc2 = 7 * (IntLoc3 - IntLoc2) - IntLoc1;
  246.                 Proc2(&IntLoc1);
  247.         }
  248.  
  249. /*****************
  250. -- Stop Timer --
  251. *****************/
  252.  
  253. #ifdef TIME
  254.         benchtime = time(/* (long *) 0*/) - starttime - nulltime;
  255.         printf("Dhrystone(%s) time for %ld passes = %ld\r\n",
  256.                 Version,
  257.                 (long) LOOPS, benchtime/HZ);
  258.         printf("This machine benchmarks at %ld dhrystones/second\r\n",
  259.                 ((long) LOOPS) * HZ / benchtime);
  260. #endif
  261. #ifdef TIMES
  262.         times(&tms);
  263.         benchtime = tms.tms_utime - starttime - nulltime;
  264.         printf("Dhrystone(%s) time for %ld passes = %ld\r\n",
  265.                 Version,
  266.                 (long) LOOPS, benchtime/HZ);
  267.         printf("This machine benchmarks at %ld dhrystones/second\r\n",
  268.                 ((long) LOOPS) * HZ / benchtime);
  269. #endif
  270. #ifdef TIME_EVO_IAR
  271.         halt();
  272.         benchtime = int_timer - starttime - nulltime;
  273.         printf("Dhrystone(%s) time for %ld passes = %ld\r\n",
  274.                 Version,
  275.                 (long) LOOPS, benchtime/HZ);
  276.         printf("This machine benchmarks at %ld dhrystones/second\r\n",
  277.                 ((long) LOOPS) * HZ / benchtime);
  278. #endif
  279. #ifdef GETRUSAGE
  280.         getrusage(RUSAGE_SELF, &endtime);
  281.         {
  282.             double t = (double)(endtime.ru_utime.tv_sec
  283.                                 - starttime.ru_utime.tv_sec
  284.                                 - nulltime.tv_sec)
  285.                      + (double)(endtime.ru_utime.tv_usec
  286.                                 - starttime.ru_utime.tv_usec
  287.                                 - nulltime.tv_usec) * 1e-6;
  288.             printf("Dhrystone(%s) time for %ld passes = %.1f\r\n",
  289.                    Version,
  290.                    (long)LOOPS,
  291.                    t);
  292.             printf("This machine benchmarks at %.0f dhrystones/second\r\n",
  293.                    (double)LOOPS / t);
  294.         }
  295. #endif
  296.  
  297. }
  298.  
  299. void Proc1(REG RecordPtr        PtrParIn)
  300. {
  301. #define NextRecord      (*(PtrParIn->PtrComp))
  302.  
  303.         structassign(NextRecord, *PtrGlb);
  304.         PtrParIn->IntComp = 5;
  305.         NextRecord.IntComp = PtrParIn->IntComp;
  306.         NextRecord.PtrComp = PtrParIn->PtrComp;
  307.         Proc3(&NextRecord.PtrComp);
  308.         if (NextRecord.Discr == Ident1)
  309.         {
  310.                 NextRecord.IntComp = 6;
  311.                 Proc6(PtrParIn->EnumComp, &NextRecord.EnumComp);
  312.                 NextRecord.PtrComp = PtrGlb->PtrComp;
  313.                 Proc7(NextRecord.IntComp, 10, &NextRecord.IntComp);
  314.         }
  315.         else
  316.                 structassign(*PtrParIn, NextRecord);
  317.  
  318. #undef  NextRecord
  319. }
  320.  
  321. void Proc2(OneToFifty   *IntParIO)
  322. {
  323.         REG OneToFifty          IntLoc;
  324.         REG Enumeration         EnumLoc;
  325.  
  326.         IntLoc = *IntParIO + 10;
  327.         for(;;)
  328.         {
  329.                 if (Char1Glob == 'A')
  330.                 {
  331.                         --IntLoc;
  332.                         *IntParIO = IntLoc - IntGlob;
  333.                         EnumLoc = Ident1;
  334.                 }
  335.                 if (EnumLoc == Ident1)
  336.                         break;
  337.         }
  338. }
  339.  
  340. void Proc3(RecordPtr    *PtrParOut)
  341. {
  342.         if (PtrGlb != NULL)
  343.                 *PtrParOut = PtrGlb->PtrComp;
  344.         else
  345.                 IntGlob = 100;
  346.         Proc7(10, IntGlob, &PtrGlb->IntComp);
  347. }
  348.  
  349. void Proc4(void )
  350. {
  351.         REG boolean     BoolLoc;
  352.  
  353.         BoolLoc = Char1Glob == 'A';
  354.         BoolLoc |= BoolGlob;
  355.         Char2Glob = 'B';
  356. }
  357.  
  358. void Proc5(void )
  359. {
  360.         Char1Glob = 'A';
  361.         BoolGlob = FALSE;
  362. }
  363.  
  364. void Proc6(REG Enumeration      EnumParIn, REG Enumeration      *EnumParOut)
  365. {
  366.         *EnumParOut = EnumParIn;
  367.         if (! Func3(EnumParIn) )
  368.                 *EnumParOut = Ident4;
  369.         switch (EnumParIn)
  370.         {
  371.         case Ident1:    *EnumParOut = Ident1; break;
  372.         case Ident2:    if (IntGlob > 100) *EnumParOut = Ident1;
  373.                         else *EnumParOut = Ident4;
  374.                         break;
  375.         case Ident3:    *EnumParOut = Ident2; break;
  376.         case Ident4:    break;
  377.         case Ident5:    *EnumParOut = Ident3;
  378.         }
  379. }
  380.  
  381. void Proc7(OneToFifty   IntParI1, OneToFifty    IntParI2, OneToFifty    *IntParOut)
  382. {
  383.         REG OneToFifty  IntLoc;
  384.  
  385.         IntLoc = IntParI1 + 2;
  386.         *IntParOut = IntParI2 + IntLoc;
  387. }
  388.  
  389. void Proc8(Array1Dim    Array1Par,Array2Dim     Array2Par,OneToFifty    IntParI1,OneToFifty     IntParI2)
  390. {
  391.         REG OneToFifty  IntLoc;
  392.         REG OneToFifty  IntIndex;
  393.  
  394.         IntLoc = IntParI1 + 5;
  395.         Array1Par[IntLoc] = IntParI2;
  396.         Array1Par[IntLoc+1] = Array1Par[IntLoc];
  397.         Array1Par[IntLoc+30] = IntLoc;
  398.         for (IntIndex = IntLoc; IntIndex <= (IntLoc+1); ++IntIndex)
  399.                 Array2Par[IntLoc][IntIndex] = IntLoc;
  400.         ++Array2Par[IntLoc][IntLoc-1];
  401.         Array2Par[IntLoc+20][IntLoc] = Array1Par[IntLoc];
  402.         IntGlob = 5;
  403. }
  404.  
  405. Enumeration Func1(CapitalLetter CharPar1,CapitalLetter  CharPar2)
  406. {
  407.         REG CapitalLetter       CharLoc1;
  408.         REG CapitalLetter       CharLoc2;
  409.  
  410.         CharLoc1 = CharPar1;
  411.         CharLoc2 = CharLoc1;
  412.         if (CharLoc2 != CharPar2)
  413.                 return (Ident1);
  414.         else
  415.                 return (Ident2);
  416. }
  417.  
  418. boolean Func2(String30  StrParI1,String30       StrParI2)
  419. {
  420.         REG OneToThirty         IntLoc;
  421.         REG CapitalLetter       CharLoc;
  422.  
  423.         IntLoc = 1;
  424.         while (IntLoc <= 1)
  425.                 if (Func1(StrParI1[IntLoc], StrParI2[IntLoc+1]) == Ident1)
  426.                 {
  427.                         CharLoc = 'A';
  428.                         ++IntLoc;
  429.                 }
  430.         if (CharLoc >= 'W' && CharLoc <= 'Z')
  431.                 IntLoc = 7;
  432.         if (CharLoc == 'X')
  433.                 return(TRUE);
  434.         else
  435.         {
  436.                 if (strcmp(StrParI1, StrParI2) > 0)
  437.                 {
  438.                         IntLoc += 7;
  439.                         return (TRUE);
  440.                 }
  441.                 else
  442.                         return (FALSE);
  443.         }
  444. }
  445.  
  446. boolean Func3(REG Enumeration   EnumParIn)
  447. {
  448.         REG Enumeration EnumLoc;
  449.  
  450.         EnumLoc = EnumParIn;
  451.         if (EnumLoc == Ident3) return (TRUE);
  452.         return (FALSE);
  453. }
  454.  
  455. int main(void)
  456. {
  457.        
  458.     os_initstdio(); //Alone Coder
  459.         Proc0();
  460.         return 0; //while(1); //Alone Coder
  461. }
  462. #ifdef  NOSTRUCTASSIGN
  463. memcpy(d, s, l)
  464. register char   *d;
  465. register char   *s;
  466. register int    l;
  467. {
  468.         while (l--) *d++ = *s++;
  469. }
  470. #endif
  471. /* ---------- */
  472.  
  473.