Some hc08 related updates that I missed earlier
[fw/sdcc] / sim / ucsim / sim.src / test_mem_speed.cc
index d2359fdf51cd947b1d2ef322e9bceeb846ce4263..5f40e9ebfed9d89d4e5c388412380be5aa62f64e 100644 (file)
@@ -3,6 +3,9 @@
 #include <stdio.h>
 
 #include "memcl.h"
+#include "hwcl.h"
+
+#include "newcmdcl.h"
 
 static int go;
 
@@ -13,54 +16,83 @@ alarmed(int sig)
   signal(sig, alarmed);
 }
 
-int
-main(void)
+class cl_hw_test: public cl_hw
 {
-  class cl_mem *mem;
-  class cl_m   *m2;
+public:
+  cl_hw_test(void): cl_hw(0, HW_PORT, 0, "0") {}
+  virtual t_mem r(class cl_cell *cell, t_addr addr);
+  virtual void write(class cl_mem *mem, t_addr addr, t_mem *val);
+};
+
+t_mem
+cl_hw_test::r(class cl_cell *cell, t_addr addr)
+{
+  return(cell->get());
+}
+
+void
+cl_hw_test::write(class cl_mem *mem, t_addr addr, t_mem *val)
+{
+}
+
+double
+do_rw_test(class cl_mem *mem, int time)
+{
+  double counter;
   t_addr a;
   t_mem d;
-  double counter;
 
-  signal(SIGALRM, alarmed);
-
-  mem= new cl_mem(MEM_SFR, "egy", 0x10000, 8);
   go= 1;
   counter= 0;
-  alarm(10);
+  alarm(time);
   while (go)
     for (a= 0; go && a < mem->size; a++)
       {
        t_mem d2;
-       for (d2= 0; d2 <= 255; d2++)
+       for (d2= 0; go && d2 <= 255; d2++)
          {
-           mem->write(a, &d2);
+           d2= mem->write(a, d2);
            d= mem->read(a);
            if (d != d2)
-             printf("%ld written to mem and %ld read back!\n", d2, d);
+             printf("%"_M_"d written to mem and %"_M_"d read back!\n", d2, d);
            counter+= 1;
          }
       }
-  printf("%g operations on classic memory within 10 sec\n", counter);
+  return(counter);
+}
 
-  m2= new cl_m(0x10000, 8);
-  go= 1;
-  counter= 0;
-  alarm(10);
-  while (go)
-    for (a= 0; go && a < m2->size; a++)
-      {
-       t_mem d2;
-       for (d2= 0; d2 <= 255; d2++)
-         {
-           m2->write(a, &d2);
-           d= m2->read(a);
-           if (d != d2)
-             printf("%ld written to m2 and %ld read back!\n", d2, d);
-           counter+= 1;
-         }
-      }
-  printf("%g operations on new memory within 10 sec\n", counter);
+int
+main(void)
+{
+  int i;
+  class cl_mem *mem;
+  class cl_m *m2;
+  class cl_console *con;
+
+  signal(SIGALRM, alarmed);
+  con= new cl_console(stdin, stdout, 0);
+
+  mem= new cl_mem(MEM_SFR, "egy", 0x10000, 8);
+  mem->init();
+  printf("%g operations on classic memory within 5 sec\n",
+        do_rw_test(mem, 5));
+  //mem->dump(con);
+
+  m2= new cl_m(MEM_TYPES, "test", 0x10000, 8);
+  m2->init();
+  printf("%g operations on new memory within 5 sec\n",
+        do_rw_test(m2, 5));
+
+  class cl_hw_test *hw= new cl_hw_test();
+  for (i= 0; i < 0x10000; i++)
+    {
+      class cl_cell *c= m2->get_cell(i);
+      if (c)
+       c->add_hw(hw);
+    }
+  printf("%g operations on new memory within 5 sec with hw read\n",
+        do_rw_test(m2, 5));
+  //m2->dump(con);
 
   return(0);
 }