home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / RiscOS / APP / DEVS / FORTH / BEETLE / BEETLE.ZIP / Beetle / memoryt.c < prev    next >
C/C++ Source or Header  |  1997-04-22  |  2KB  |  76 lines

  1. /* MEMORYT.C
  2.  
  3.     Vrsn  Date   Comment
  4.     ----|-------|--------------------------------------------------------------
  5.     0.00 23nov94 Test @, !, C@, C!, +!, SP@, SP!, RP@ and RP!.
  6.     0.01 28nov94 Changed reference to b_mem to one to M0.
  7.     0.02 30nov94 Modified so that testing is automatic, and can run with or
  8.                  without debugging information. Modified to give a return value
  9.                  from main.
  10.     0.03 17feb95 Modified to work with new version of storage.c, and use
  11.                  btests.h rather than bintern.h.
  12.     0.04 28feb95 Removed printf format error.
  13.  
  14.     Reuben Thomas
  15.  
  16.  
  17.     Test the memory operators. Also uses previously tested instructions.
  18.     Doesn't test address exception handling, as this is not yet supported.
  19.  
  20. */
  21.  
  22.  
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include "beetle.h"     /* main header */
  27. #include "btests.h"    /* Beetle tests header */
  28. #include "opcodes.h"    /* opcode enumeration */
  29. #include "debug.h"      /* debugging functions */
  30.  
  31.  
  32. char *correct[] = { "", QCELL_W, "16384", "16380", "16380 513",
  33.     "16380 513 16380", "16380", "16380 16380", "16380 513", "16380",
  34.     "16380 16380", "16380 1", "16381", "2", "2 16383", "", "16380", "33554945",
  35.     "", "16128", "", "16384", "", "0", "", "0" };
  36.  
  37.  
  38. int main(void)
  39. {
  40.     int i;
  41.  
  42.     init_beetle((BYTE *)malloc(16384), 4096, 16);
  43.     here = EP;
  44.     S0 = SP;    /* save base of stack */
  45.  
  46.     start_ass();
  47.     ass(O_CELL); ass(O_FETCH); ass(O_MINUSCELL); ass(O_LITERAL); lit(513);
  48.     ass(O_OVER); ass(O_STORE); ass(O_DUP); ass(O_FETCH);
  49.     ass(O_DROP); ass(O_DUP); ass(O_CFETCH); ass(O_PLUS);
  50.     ass(O_CFETCH); ass(O_LITERAL); lit(16383); ass(O_CSTORE); ass(O_LITERAL);
  51.         lit(16380);
  52.     ass(O_FETCH); ass(O_DROP); ass(O_SPFETCH); ass(O_SPSTORE);
  53.     ass(O_RPFETCH); ass(O_DROP); ass(O_ZERO); ass(O_RPSTORE);
  54.     ass(O_RPFETCH);
  55.     end_ass();
  56.  
  57.     NEXT;   /* load first instruction word */
  58.  
  59.     for (i = 0; i <= instrs; i++) {
  60. #ifdef B_DEBUG
  61.         show_data_stack();  printf("Correct stack: %s\n\n", correct[i - i / 5]);
  62. #endif
  63.         if (strcmp(correct[i - i / 5], val_data_stack())) {
  64.             printf("Error in MemoryT: EP = %ld\n", val_EP());
  65.             exit(1);
  66.         }
  67.         single_step();
  68. #ifdef B_DEBUG
  69.         printf("I = %s\n", disass(I));
  70. #endif
  71.     }
  72.  
  73.     printf("MemoryT ran OK\n");
  74.     return 0;
  75. }
  76.